13#include <pybind11/embed.h>
18namespace codac2::symbolic::detail
96 static std::string make_symbol_name(Index flat_index);
107 std::vector<std::string> _names;
108 std::unordered_map<std::string,ScalarExpr> _codac_scalars;
135 pybind11::object export_node(
const std::shared_ptr<ExprBase>& e)
const;
136 pybind11::object export_vector_component(
const std::shared_ptr<ExprBase>& e, Index i)
const;
137 pybind11::object export_matrix_component(
const std::shared_ptr<ExprBase>& e, Index i, Index j)
const;
138 static double scalar_const_value(
const ConstValueExpr<ScalarType>& c);
139 static std::shared_ptr<ExprBase> child_at(
const std::vector<std::shared_ptr<ExprBase>>& children, Index i);
168 ScalarExpr import_add(
const pybind11::handle& obj)
const;
169 ScalarExpr import_mul(
const pybind11::handle& obj)
const;
170 ScalarExpr import_pow(
const pybind11::handle& obj)
const;
171 ScalarExpr import_function(
const pybind11::handle& obj)
const;
180 const pybind11::object&,
const pybind11::object&,
const FlatSymbolTable&)>;
201 const pybind11::object&
sympy()
const;
287 pybind11::object
normalize_sympy_expr(
const pybind11::object& sympy, pybind11::object expr,
bool do_expand =
true);
302 bool do_expand =
true);
A class representing a unique identifier for expressions.
Definition codac2_ExprBase.h:34
A container class to manage a collection of function arguments.
Definition codac2_FunctionArgsList.h:25
Symbol table associated with a flattened analytic input domain.
Definition codac2_sympy_bridge.h:28
pybind11::object for_scalar_var(const ScalarVar &x) const
Returns the SymPy symbol associated with a scalar variable.
ScalarExpr codac_expr_by_name(const std::string &name) const
Returns the Codac scalar expression associated with a symbol name.
pybind11::object by_flat_index(Index k) const
Returns the SymPy symbol associated with a flat input index.
FlatSymbolTable(const FunctionArgsList &args)
Builds the symbol table associated with a function argument list.
pybind11::object for_vector_component(const VectorVar &x, Index i) const
Returns the SymPy symbol associated with a vector component.
Index size() const
Returns the number of scalar entries in the flattened input domain.
pybind11::object for_matrix_component(const MatrixVar &x, Index i, Index j) const
Returns the SymPy symbol associated with a matrix component.
ScalarExpr transform_scalar_expr(const ScalarExpr &y, const SympyTransform &transform, bool do_expand=true) const
Applies a SymPy transformation to a Codac scalar expression.
pybind11::object export_scalar(const ScalarExpr &y) const
Exports a Codac scalar expression to SymPy.
ScalarExpr import_scalar(const pybind11::handle &obj) const
Imports a SymPy scalar expression into Codac.
const pybind11::object & sympy() const
Returns the imported SymPy module.
ScalarBridgeContext(const FunctionArgsList &args)
Builds a scalar bridge context for a given function argument list.
const FlatSymbolTable & symbols() const
Returns the associated flat symbol table.
Exports Codac scalar expressions to SymPy expressions.
Definition codac2_sympy_bridge.h:115
SympyExporter(const FlatSymbolTable &symbols)
Builds an exporter associated with a symbol table.
pybind11::object export_scalar(const ScalarExpr &e) const
Exports a Codac scalar expression to SymPy.
Imports SymPy scalar expressions into Codac scalar expressions.
Definition codac2_sympy_bridge.h:148
SympyImporter(const FlatSymbolTable &symbols)
Builds an importer associated with a symbol table.
ScalarExpr import_scalar(const pybind11::handle &obj) const
Imports a SymPy scalar expression.
pybind11::object normalize_sympy_expr(const pybind11::object &sympy, pybind11::object expr, bool do_expand=true)
Normalizes a SymPy expression before import into Codac.
const pybind11::object & import_polyfuncs()
Imports the SymPy polyfuncs module.
const pybind11::object & import_module(const char *module_name)
Imports a Python module.
std::function< pybind11::object( const pybind11::object &, const pybind11::object &, const FlatSymbolTable &)> SympyTransform
SymPy transformation applied to an exported scalar expression.
Definition codac2_sympy_bridge.h:179
const pybind11::object & import_builtins()
Imports the Python builtins module.
ScalarExpr transform_scalar_expr(const FunctionArgsList &args, const ScalarExpr &y, const SympyTransform &transform, bool do_expand=true)
Applies a SymPy transformation to a Codac scalar expression.
const pybind11::object & import_sympy()
Imports the SymPy module.
void ensure_python_runtime()
Ensures that the embedded Python runtime is initialized.