Merge branch 'main' of github.com:Rconybea/xo-pyexpression

This commit is contained in:
Roland Conybeare 2024-07-02 12:27:56 -04:00
commit db02e7c08c

View file

@ -55,6 +55,7 @@ namespace xo {
py::class_<Expression,
rp<Expression>>(m, "Expression")
.def_property_readonly("extype", &Expression::extype)
.def_property_readonly("valuetype", &Expression::valuetype)
.def("get_free_variables", &Expression::get_free_variables)
.def("__repr__", &Expression::display_string);
;
@ -103,26 +104,49 @@ namespace xo {
py::doc("number of arguments to this function (not counting return value)"))
;
using Fn_dbl_dbl_type = double (*)(double);
using int32_t = std::int32_t;
m.def("make_sqrt_pm", []() { return make_primitive<Fn_dbl_dbl_type>("sqrt", sqrt, false /*!explicit*/, llvmintrinsic::invalid); },
py::doc("create primitive representing the ::sqrt() function"));
m.def("make_sin_pm", []() { return make_primitive<Fn_dbl_dbl_type>("sin", ::sin, false /*!explicit*/, llvmintrinsic::invalid); },
py::doc("create primitive representing the ::sin() function"));
m.def("make_cos_pm", []() { return make_primitive<Fn_dbl_dbl_type>("cos", ::cos, false /*!explicit*/, llvmintrinsic::invalid); },
py::doc("create primitive representing the ::cos() function"));
m.def("make_pow_pm", []() { return make_primitive<double (*)(double, double)>("pow", ::pow, false /*!explicit*/, llvmintrinsic::invalid); },
py::doc("create primitive representing the ::pow() function"));
py::class_<Primitive<int32_t (*)(int32_t, int32_t)>,
PrimitiveInterface,
rp<Primitive<int32_t (*)(int32_t, int32_t)>>>(m, "Primitive_i32_i32")
;
py::class_<Primitive<double (*)(double)>,
PrimitiveInterface,
rp<Primitive<double (*)(double)>>>(m, "Primitive_double_double")
;
using Fn_dbl_dbl_type = double (*)(double);
m.def("make_sqrt_pm", []() { return make_primitive<double (*)(double)>("sqrt",
::sqrt,
false /*!explicit_symbol_def*/,
llvmintrinsic::fp_sqrt); },
py::doc("create primitive representing the ::sqrt() function"));
m.def("make_sin_pm",
[]() { return make_primitive<Fn_dbl_dbl_type>("sin",
::sin,
false /*!explicit_symbol_def*/,
llvmintrinsic::fp_sin); },
py::doc("create primitive representing the ::sin() function"));
m.def("make_cos_pm",
[]() { return make_primitive<Fn_dbl_dbl_type>("cos",
::cos,
false /*!explicit_symbol_def*/,
llvmintrinsic::fp_cos); },
py::doc("create primitive representing the ::cos() function"));
py::class_<Primitive<double (*)(double, double)>,
PrimitiveInterface,
rp<Primitive<double (*)(double, double)>>>(m, "Primitive_double_double_double")
;
m.def("make_pow_pm",
[]() { return make_primitive<double (*)(double, double)>("pow",
::pow,
false /*!explicit_symbol_def*/,
llvmintrinsic::fp_pow); },
py::doc("create primitive representing the ::pow() function"));
// ----- Apply -----
py::class_<Apply, Expression, rp<Apply>>(m, "Apply")
@ -138,7 +162,9 @@ namespace xo {
.def_property_readonly("name", &Variable::name, py::doc("variable name"))
;
m.def("make_var", &make_var);
m.def("make_var", &make_var,
py::arg("name"),
py::arg("var_type"));
// ----- Lambdas -----