Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
PLMD::lepton::CompiledExpression Class Reference

A CompiledExpression is a highly optimized representation of an expression for cases when you want to evaluate it many times as quickly as possible. More...

#include <CompiledExpression.h>

Public Member Functions

 CompiledExpression ()
 
 CompiledExpression (const CompiledExpression &expression)
 
 ~CompiledExpression ()
 
double evaluate () const
 Evaluate the expression. More...
 
double & getVariableReference (const std::string &name)
 Get a reference to the memory location where the value of a particular variable is stored. More...
 
const std::set< std::string > & getVariables () const
 Get the names of all variables used by this expression. More...
 
CompiledExpressionoperator= (const CompiledExpression &expression)
 
void setVariableLocations (std::map< std::string, double *> &variableLocations)
 You can optionally specify the memory locations from which the values of variables should be read. More...
 

Private Member Functions

 CompiledExpression (const ParsedExpression &expression)
 
void compileExpression (const ExpressionTreeNode &node, std::vector< std::pair< ExpressionTreeNode, int > > &temps)
 
int findTempIndex (const ExpressionTreeNode &node, std::vector< std::pair< ExpressionTreeNode, int > > &temps)
 
void generateJitCode ()
 

Private Attributes

std::vector< std::vector< int > > arguments
 
std::vector< double > argValues
 
std::vector< double > constants
 
std::map< std::string, double > dummyVariables
 
void * jitCode
 
std::vector< Operation * > operation
 
AsmJitRuntimePtr runtimeptr
 
std::vector< int > target
 
std::map< std::string, int > variableIndices
 
std::set< std::string > variableNames
 
std::map< std::string, double * > variablePointers
 
std::vector< std::pair< double *, double * > > variablesToCopy
 
std::vector< double > workspace
 

Friends

class ParsedExpression
 

Detailed Description

A CompiledExpression is a highly optimized representation of an expression for cases when you want to evaluate it many times as quickly as possible.

You should treat it as an opaque object; none of the internal representation is visible.

A CompiledExpression is created by calling createCompiledExpression() on a ParsedExpression.

WARNING: CompiledExpression is NOT thread safe. You should never access a CompiledExpression from two threads at the same time.

Constructor & Destructor Documentation

◆ CompiledExpression() [1/3]

PLMD::CompiledExpression::CompiledExpression ( )

◆ CompiledExpression() [2/3]

PLMD::CompiledExpression::CompiledExpression ( const CompiledExpression expression)

◆ ~CompiledExpression()

PLMD::CompiledExpression::~CompiledExpression ( )

◆ CompiledExpression() [3/3]

PLMD::CompiledExpression::CompiledExpression ( const ParsedExpression expression)
private

Member Function Documentation

◆ compileExpression()

void PLMD::CompiledExpression::compileExpression ( const ExpressionTreeNode node,
std::vector< std::pair< ExpressionTreeNode, int > > &  temps 
)
private

◆ evaluate()

double PLMD::CompiledExpression::evaluate ( ) const

Evaluate the expression.

The values of all variables should have been set before calling this.

◆ findTempIndex()

int PLMD::CompiledExpression::findTempIndex ( const ExpressionTreeNode node,
std::vector< std::pair< ExpressionTreeNode, int > > &  temps 
)
private

◆ generateJitCode()

void PLMD::lepton::CompiledExpression::generateJitCode ( )
private

◆ getVariableReference()

double & PLMD::CompiledExpression::getVariableReference ( const std::string &  name)

Get a reference to the memory location where the value of a particular variable is stored.

This can be used to set the value of the variable before calling evaluate().

◆ getVariables()

const set< string > & PLMD::CompiledExpression::getVariables ( ) const

Get the names of all variables used by this expression.

◆ operator=()

CompiledExpression & PLMD::CompiledExpression::operator= ( const CompiledExpression expression)

◆ setVariableLocations()

void PLMD::CompiledExpression::setVariableLocations ( std::map< std::string, double *> &  variableLocations)

You can optionally specify the memory locations from which the values of variables should be read.

This is useful, for example, when several expressions all use the same variable. You can then set the value of that variable in one place, and it will be seen by all of them.

Friends And Related Function Documentation

◆ ParsedExpression

friend class ParsedExpression
friend

Member Data Documentation

◆ arguments

std::vector<std::vector<int> > PLMD::lepton::CompiledExpression::arguments
private

◆ argValues

std::vector<double> PLMD::lepton::CompiledExpression::argValues
mutableprivate

◆ constants

std::vector<double> PLMD::lepton::CompiledExpression::constants
private

◆ dummyVariables

std::map<std::string, double> PLMD::lepton::CompiledExpression::dummyVariables
private

◆ jitCode

void* PLMD::lepton::CompiledExpression::jitCode
private

◆ operation

std::vector<Operation*> PLMD::lepton::CompiledExpression::operation
private

◆ runtimeptr

AsmJitRuntimePtr PLMD::lepton::CompiledExpression::runtimeptr
private

◆ target

std::vector<int> PLMD::lepton::CompiledExpression::target
private

◆ variableIndices

std::map<std::string, int> PLMD::lepton::CompiledExpression::variableIndices
private

◆ variableNames

std::set<std::string> PLMD::lepton::CompiledExpression::variableNames
private

◆ variablePointers

std::map<std::string, double*> PLMD::lepton::CompiledExpression::variablePointers
private

◆ variablesToCopy

std::vector<std::pair<double*, double*> > PLMD::lepton::CompiledExpression::variablesToCopy
private

◆ workspace

std::vector<double> PLMD::lepton::CompiledExpression::workspace
mutableprivate

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