Monte Carlo Integration Library 1.0
High-performance Monte Carlo methods for numerical integration and optimization
Public Member Functions | Static Public Member Functions | List of all members
mc::utils::muParserXInterface< N, ArgumentType > Class Template Reference

#include <muParserXInterface.hpp>

Collaboration diagram for mc::utils::muParserXInterface< N, ArgumentType >:

Public Member Functions

 muParserXInterface ()
 Default constructor.
 
 muParserXInterface (const std::string expression)
 Constructor that takes a string containing muParserX expression.
 
 muParserXInterface (muParserXInterface const &mpi)
 
muParserXInterface operator= (muParserXInterface const &mpi)
 
void set_expression (const std::string &e)
 Sets the muparserX expression.
 
auto operator() (ArgumentType const &x) const
 

Static Public Member Functions

static muParserXInterface fromFile (const std::string &filename)
 

Detailed Description

template<int N, class ArgumentType = std::array<double, N>>
class mc::utils::muParserXInterface< N, ArgumentType >

An interface to MuParserX to define a function

It define a functor representing a function \( R^N \) to \( R\) The input variables are defined as x[0] x[1] etc and one can use the muparserX syntax to create the expression.

I assume that at compile time we know the size of the argument of the function and I keep the return value as template parameter. By default both input and output are arrays. The input variables are indicated by x[]. An example of a valid expression: sin(x[0])+x[1]*x[2]

Template Parameters
NThe number of arguments of the function we want to represent
ArgumentTypeany type that support the addressing ([]) operator

Definition at line 30 of file muParserXInterface.hpp.

Constructor & Destructor Documentation

◆ muParserXInterface() [1/3]

template<int N, class ArgumentType = std::array<double, N>>
mc::utils::muParserXInterface< N, ArgumentType >::muParserXInterface ( )
inline

Default constructor.

mup::pckALL_NON_COMPLEX|mup::pckMATRIX means that I do not want the module for complex numbers but I want to treat arrays and matrices in muparserX expressions

Definition at line 38 of file muParserXInterface.hpp.

◆ muParserXInterface() [2/3]

template<int N, class ArgumentType = std::array<double, N>>
mc::utils::muParserXInterface< N, ArgumentType >::muParserXInterface ( const std::string  expression)
inline

Constructor that takes a string containing muParserX expression.

Definition at line 45 of file muParserXInterface.hpp.

◆ muParserXInterface() [3/3]

template<int N, class ArgumentType = std::array<double, N>>
mc::utils::muParserXInterface< N, ArgumentType >::muParserXInterface ( muParserXInterface< N, ArgumentType > const &  mpi)
inline

The copy constructor

MuparserX has a particular design, which obliges to define a special copy constructor The reson is that a muparser engine stores the address of the variables. So a normal copy would do a shallow copy, which is NOT what you want. Moreover, because of a poor design, you may loose the expression. That's why I keep a copy in the class as a string and a redefine in in the muparser engine.

Parameters
mpithe muParserXInterface to be copied

Definition at line 63 of file muParserXInterface.hpp.

Member Function Documentation

◆ fromFile()

template<int N, class ArgumentType = std::array<double, N>>
static muParserXInterface mc::utils::muParserXInterface< N, ArgumentType >::fromFile ( const std::string &  filename)
inlinestatic

Factory method to create an interface from a text file. Reads the first line of the file as the expression.

Parameters
filenamePath to the file containing the expression
Returns
A constructed muParserXInterface object

Definition at line 100 of file muParserXInterface.hpp.

Here is the call graph for this function:

◆ operator()()

template<int N, class ArgumentType = std::array<double, N>>
auto mc::utils::muParserXInterface< N, ArgumentType >::operator() ( ArgumentType const &  x) const
inline

Definition at line 141 of file muParserXInterface.hpp.

◆ operator=()

template<int N, class ArgumentType = std::array<double, N>>
muParserXInterface mc::utils::muParserXInterface< N, ArgumentType >::operator= ( muParserXInterface< N, ArgumentType > const &  mpi)
inline

The copy assignment operator

MuparserX has a particular design, which obliges to define a special copy assignement

Parameters
mpithe muParserXInterface to be copied The copy constructor

Definition at line 79 of file muParserXInterface.hpp.

◆ set_expression()

template<int N, class ArgumentType = std::array<double, N>>
void mc::utils::muParserXInterface< N, ArgumentType >::set_expression ( const std::string &  e)
inline

Sets the muparserX expression.

Beware, the input variables are indicated by x[]. example of a valid expression: sin(x[0])+x[1]*x[2]

e The expression

Definition at line 134 of file muParserXInterface.hpp.


The documentation for this class was generated from the following file: