Go to the documentation of this file.
34 std::vector<double>
val;
35 void eval(
double *result) {
36 for (
int i = 0; i <
type().
dim(); i++) result[i] =
val[i];
38 void eval(
const char **result) { assert(
false); }
46 void eval(
double *result) { assert(
false); }
47 void eval(
const char **result) { *result =
val; }
55 std::set<SeExpr2::DExpression *> ret;
57 std::set<SeExpr2::DExpression *> workList = gv->
users;
58 while (workList.size()) {
69 std::set<SeExpr2::DExpression *> ret;
71 std::set<SeExpr2::DExpression *> workList;
72 workList.insert(
expr);
73 while (workList.size()) {
83 std::set<SeExpr2::DExpression *> tmpOperandExprs;
84 std::set<SeExpr2::GlobalVal *> tmpOperandVars;
115 if ((*I)->name() ==
name) {
116 tmpOperandExprs.insert(*I);
117 (*I)->val->users.insert(
const_cast<DExpression *
>(
this));
122 if ((*I)->varName ==
name) {
123 tmpOperandVars.insert(*I);
124 (*I)->users.insert(
const_cast<DExpression *
>(
this));
134 const double *ret =
evalFP();
136 fpVal->
val.assign(ret, ret + fpVal->
val.size());
146 for (std::set<DExpression *>::iterator I =
AllExprs.begin(), E =
AllExprs.end(); I != E; ++I)
delete *I;
152 std::pair<std::set<GlobalVal *>::iterator,
bool> ret;
165 std::pair<std::set<DExpression *>::iterator,
bool> ret;
172 unsigned initSize =
static_cast<unsigned>(thisvar->
users.size());
175 std::set<DExpression *> ret = getAffectedExpr(thisvar);
185 assert(thisvar &&
"set value to variable with incompatible types.");
187 assert(dim == thisvar->
val.size());
188 for (
unsigned i = 0; i < dim; ++i) thisvar->
val[i] = values[i];
195 assert(thisvar &&
"set value to variable with incompatible types.");
196 thisvar->
val = values;
201 assert(thisvar &&
"set value to variable with incompatible types.");
203 assert(dim == thisvar->
val.size());
204 for (
unsigned i = 0; i < dim; ++i) thisvar->
val[i] = values[i];
207 std::set<DExpression *> ret = getAffectedExpr(thisvar);
208 for (std::set<DExpression *>::iterator I = ret.begin(), E = ret.end(); I != E; ++I) (*I)->eval();
213 assert(thisvar &&
"set value to variable with incompatible types.");
214 thisvar->
val = values;
217 std::set<DExpression *> ret = getAffectedExpr(thisvar);
218 for (std::set<DExpression *>::iterator I = ret.begin(), E = ret.end(); I != E; ++I) (*I)->eval();
223 for (std::set<DExpression *>::const_iterator I =
AllExprs.begin(), E =
AllExprs.end(); I != E; ++I)
224 ret &= (*I)->isValid();
232 std::set<DExpression *> all = getTransitiveOperandExpr(de);
235 std::vector<DExpression *>::iterator
it;
237 std::vector<DExpression *> ret1(all.size());
239 ret1.resize(
it - ret1.begin());
241 std::vector<DExpression *> ret2(ret1.size());
243 ret2.resize(
it - ret2.begin());
248 return std::make_pair(eh, ret2);
253 for (std::vector<DExpression *>::iterator I = eeh.second.begin(), E = eeh.second.end(); I != E; ++I) (*I)->eval();
264 for (std::vector<DExpression *>::iterator I = eeh.second.begin(), E = eeh.second.end(); I != E; ++I) (*I)->eval();
const char * evalStr(ExprEvalHandle eeh)
DExpression(const std::string &varName, Expressions &context, const std::string &e, const ExprType &type=ExprType().FP(3), EvaluationStrategy be=defaultEvaluationStrategy)
GlobalVal(const std::string &varName, const SeExpr2::ExprType &et)
void eval(double *result)
returns this variable's value by setting result
ExprEvalHandle getExprEvalHandle(ExprHandle eh)
const char * evalStr(VarBlock *varBlock=nullptr) const
GlobalStr(const std::string &varName)
std::set< DExpression * > users
std::pair< ExprHandle, std::vector< DExpression * > > ExprEvalHandle
std::set< GlobalVal * > operandVars
ExprType _desiredReturnType
void eval(double *result)
returns this variable's value by setting result
void prepIfNeeded() const
const std::vector< double > & evalFP(ExprEvalHandle eeh)
std::set< GlobalVal * >::iterator VariableHandle
ExprVarRef * resolveVar(const std::string &name) const
VariableSetHandle getLoopVarSetHandle(VariableHandle vh)
std::set< DExpression * > operandExprs
you may not use this file except in compliance with the License and the following modification to it
GlobalFP(const std::string &varName, int dim)
const std::string & name() const
std::set< DExpression * > AllExprs
bool isFP() const
Direct is predicate checks.
void setVariable(VariableHandle handle, double *values, unsigned dim)
< b ></b >< br >< b ></b ></td >< td > vector constructor< br > vector component access n must be
std::vector< double > val
void eval(const char **result)
VariableHandle addExternalVariable(const std::string &variableName, ExprType seTy)
std::set< DExpression * >::iterator ExprHandle
std::set< GlobalVal * > AllExternalVars
EvaluationStrategy
Types of evaluation strategies that are available.
std::set< DExpression * > exprEvaled
std::set< DExpression * > exprToEval
ExprHandle addExpression(const std::string &varName, ExprType seTy, const std::string &expr)
const double * evalFP(VarBlock *varBlock=nullptr) const
std::set< GlobalVal * >::iterator VariableSetHandle
void setLoopVariable(VariableSetHandle handle, double *values, unsigned dim)
void addError(const std::string &error, const int startPos, const int endPos) const
void eval(const char **result)
abstract class for implementing variable references
virtual ExprType type() const
returns (current) type
If a scalar is used in a vector context
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar() function as follows</pre >< h3 > Variable setting</h3 > Next we need to make a way of setting the variable As the controlling code will use the expression it will repeatedly alternate between setting the independent variables that are used and calling evaluate(). What it has to do depends very much on the application. In this case we only need to set the independent variable x as</pre >< h2 > Evaluating expressions</h2 > Evaluating an expression is pretty easy But before we can do that we need to make an instance< pre > GrapherExpr expr("x+x^2")