| |
- pybind11_builtins.pybind11_object(builtins.object)
-
- CRuntimeCompiledExpression
class CRuntimeCompiledExpression(pybind11_builtins.pybind11_object) |
|
A wrapper of `exprtk` runtime expression compiler: it takes a string
representing an expression (from a simple mathematical formula to a complete
program), compiles it and evaluates its result as many times as required. The
result will change as the "variables" appearing in the expression (hold and
managed by the user of this object) change.
Refer to [exprtk documentation](https://github.com/ArashPartow/exprtk) for
reference on supported formulas, control flow instructions, etc.
This wrapper is provided to reduce the (very large) compilation time and
memory required by the original library, at the cost of only exposing the
most commonly used part of its API:
- Only expressions returning `double` are supported.
- Variables must be provided via a `std::map` container **or** pointers to
user-stored variables.
- Custom user-defined functions taking 0-3 arguments (New in MRPT 2.5.8).
See examples of usage in the [unit test
file](https://github.com/MRPT/mrpt/blob/master/libs/base/src/math/CRuntimeCompiledExpression_unittest.cpp).
If the environment variable `MRPT_EXPR_VERBOSE=1` is defined, debug
information will be dumped to std::cout explaining the values of **all** the
involved variables upon each call to `eval()`.
Alternatively, the env var `MRPT_EXPR_VERBOSE` can be set to a list of
terms split by `|`, and only those formulas that match (i.e. contain as
substrings) any of the terms will be traced.
Example: `MRPT_EXPR_VERBOSE="cos|sin|speed|if (x>0)"`.
(New in MRPT 1.5.0)
(`MRPT_EXPR_VERBOSE` new in MRPT 1.5.7) |
|
- Method resolution order:
- CRuntimeCompiledExpression
- pybind11_builtins.pybind11_object
- builtins.object
Methods defined here:
- __init__(...)
- __init__(*args, **kwargs)
Overloaded function.
1. __init__(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression) -> None
2. __init__(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, arg0: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression) -> None
- assign(...)
- assign(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, : mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression) -> mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression
C++: mrpt::expr::CRuntimeCompiledExpression::operator=(const class mrpt::expr::CRuntimeCompiledExpression &) --> class mrpt::expr::CRuntimeCompiledExpression &
- compile(...)
- compile(*args, **kwargs)
Overloaded function.
1. compile(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, expression: str) -> None
2. compile(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, expression: str, variables: Dict[str, float]) -> None
3. compile(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, expression: str, variables: Dict[str, float], expr_name_for_error_reporting: str) -> None
Initializes the object by compiling an expression.
std::runtime_error On any syntax error or undefined symbol
while compiling the expression. The `e.what()` message describes what is
exactly the problem.
register_symbol_table()
C++: mrpt::expr::CRuntimeCompiledExpression::compile(const std::string &, const class std::map<std::string, double> &, const std::string &) --> void
- eval(...)
- eval(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression) -> float
Evaluates the current value of the precompiled formula.
std::runtime_error If the formula has not been compiled yet.
C++: mrpt::expr::CRuntimeCompiledExpression::eval() const --> double
- get_original_expression(...)
- get_original_expression(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression) -> str
Returns the original formula passed to compile(), or an empty string if
still not compiled.
C++: mrpt::expr::CRuntimeCompiledExpression::get_original_expression() const --> const std::string &
- is_compiled(...)
- is_compiled(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression) -> bool
Returns true if compile() was called and ended without errors.
C++: mrpt::expr::CRuntimeCompiledExpression::is_compiled() const --> bool
- register_function(...)
- register_function(*args, **kwargs)
Overloaded function.
1. register_function(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, name: str, func: std::function<double ()>) -> None
Register a user-defined nullary function. (New in MRPT 2.5.8)
C++: mrpt::expr::CRuntimeCompiledExpression::register_function(const std::string &, const class std::function<double (void)> &) --> void
2. register_function(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, name: str, func: std::function<double (double)>) -> None
Register a user-defined unary function. (New in MRPT 2.5.8)
C++: mrpt::expr::CRuntimeCompiledExpression::register_function(const std::string &, const class std::function<double (double)> &) --> void
3. register_function(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, name: str, func: std::function<double (double, double)>) -> None
Register a user-defined binary function. (New in MRPT 2.5.8)
C++: mrpt::expr::CRuntimeCompiledExpression::register_function(const std::string &, const class std::function<double (double, double)> &) --> void
4. register_function(self: mrpt.pymrpt.mrpt.expr.CRuntimeCompiledExpression, name: str, func: std::function<double (double, double, double)>) -> None
Register a user-defined ternary function. (New in MRPT 2.5.8)
C++: mrpt::expr::CRuntimeCompiledExpression::register_function(const std::string &, const class std::function<double (double, double, double)> &) --> void
Static methods inherited from pybind11_builtins.pybind11_object:
- __new__(*args, **kwargs) from pybind11_builtins.pybind11_type
- Create and return a new object. See help(type) for accurate signature.
| |