piranha
0.10
|
Functor interface for piranha::math::evaluate(). More...
#include <piranha/lambdify.hpp>
Public Types | |
using | eval_type = decltype(math::evaluate(std::declval< const T & >(), std::declval< const symbol_fmap< U > & >())) |
Evaluation type. More... | |
using | extra_map_type = std::unordered_map< std::string, std::function< U(const std::vector< U > &)> > |
The map type for the custom evaluation of symbols. More... | |
Public Member Functions | |
lambdified (const T &x, const std::vector< std::string > &names, extra_map_type extra_map={}) | |
Constructor. More... | |
lambdified (T &&x, const std::vector< std::string > &names, extra_map_type extra_map={}) | |
Constructor (move overload). More... | |
lambdified (const lambdified &other) | |
Copy constructor. More... | |
lambdified (lambdified &&other) | |
Move constructor. More... | |
eval_type | operator() (const std::vector< U > &values) |
Evaluation. More... | |
const T & | get_evaluable () const |
Get evaluation object. More... | |
const std::vector< std::string > & | get_names () const |
Get evaluation names. More... | |
std::vector< std::string > | get_extra_names () const |
Get names of the symbols in the extra map. More... | |
Functor interface for piranha::math::evaluate().
This class exposes a function-like interface for the evaluation of instances of type T
with objects of type U
. The class acts as a small wrapper for piranha::math::evaluate() which replaces the interface based on std::unordered_map
with an interface based on vectors and positional arguments.
The convenience function piranha::math::lambdify() can be used to easily construct objects of this class.
T
and U
must be the same as their decay types,T
must be evaluable with objects of type U
,T
must be copy and move constructible.Unless otherwise specified, this class provides the strong exception safety guarantee for all operations.
After a move operation, an object of this class is destructible.
Definition at line 88 of file lambdify.hpp.
using piranha::math::lambdified< T, U >::eval_type = decltype(math::evaluate(std::declval<const T &>(), std::declval<const symbol_fmap<U> &>())) |
Evaluation type.
This is the type resulting from evaluating objects of type T
with objects of type U
via piranha::math::evaluate().
Definition at line 150 of file lambdify.hpp.
using piranha::math::lambdified< T, U >::extra_map_type = std::unordered_map<std::string, std::function<U(const std::vector<U> &)> > |
The map type for the custom evaluation of symbols.
See the constructor documentation for an explanation of how this type is used.
Definition at line 155 of file lambdify.hpp.
|
inlineexplicit |
Constructor.
This constructor will create an internal copy of x
, the object that will be evaluated by successive calls to operator()(). The vector of string names
establishes the correspondence between symbols and the values with which the symbols will be replaced when operator()() is called. That is, the values in the vector passed to operator()() are associated to the symbols in names
at the corresponding positions.
The optional argument extra_map
can be used to specify how to evaluate specific symbols. That is, extra_map
associates symbol names to functions of signature
When operator()() is called with a vector of values v
, for each symbol s
in extra_map
the associated function is called with v
as an argument, and the return value is used as evaluation value for s
in the subsequent call to math::evaluate(). extra_map
must not contain symbol names appearing in names
.
x | the object that will be evaluated by operator()(). |
names | the list of symbols to which the values passed to operator()() will be mapped. |
extra_map | the custom symbol evaluation map. |
std::invalid_argument | if names contains duplicates or if extra_map contains symbol names already present in names . |
unspecified | any exception thrown by:
|
Definition at line 187 of file lambdify.hpp.
|
inlineexplicit |
Constructor (move overload).
This constructor is equivalent to the other constructor, the only difference being that x
is used to move-construct (instead of copy-construct) the internal instance of T
.
x | the object that will be evaluated by operator()(). |
names | the list of symbols to which the values passed to operator()() will be mapped. |
extra_map | the custom symbol evaluation map. |
std::invalid_argument | if names contains duplicates or if extra_map contains symbol names already present in names . |
unspecified | any exception thrown by:
|
Definition at line 209 of file lambdify.hpp.
|
inline |
Copy constructor.
other | copy argument. |
unspecified | any exception thrown by the copy constructor of the internal members. |
Definition at line 220 of file lambdify.hpp.
|
inline |
Move constructor.
other | move argument. |
unspecified | any exception thrown by the move constructor of the internal members. |
Definition at line 231 of file lambdify.hpp.
|
inline |
Get evaluation object.
T
created upon construction. Definition at line 304 of file lambdify.hpp.
|
inline |
Get names of the symbols in the extra map.
extra_map
used during construction.unspecified | any exception thrown by memory errors in standard containers. |
Definition at line 322 of file lambdify.hpp.
|
inline |
Get evaluation names.
Definition at line 312 of file lambdify.hpp.
|
inline |
Evaluation.
The call operator will first associate the elements of values
to the vector of names used to construct this
, and it will then call piranha::math::evaluate() on the stored internal instance of the object of type T
used during construction.
If a non-empty extra_map
parameter was used during construction, the symbols in it are evaluated according to the mapped functions before being passed down in the evaluation dictionary to piranha::math::evaluate().
Note that this function needs to modify the internal state of the object, and thus it is not const and it is not thread-safe.
values | the values that will be used for evaluation. |
T
stored internally.std::invalid_argument | if the size of values is not equal to the size of the vector of names used during construction. |
unspecified | any exception raised by:
|
Definition at line 269 of file lambdify.hpp.