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()) {
83std::set<SeExpr2::DExpression *> tmpOperandExprs;
84std::set<SeExpr2::GlobalVal *> tmpOperandVars;
97 else if (type.isString())
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();
std::set< DExpression * > operandExprs
ExprVarRef * resolveVar(const std::string &name) const
const std::string & name() const
DExpression(const std::string &varName, Expressions &context, const std::string &e, const ExprType &type=ExprType().FP(3), EvaluationStrategy be=defaultEvaluationStrategy)
std::set< GlobalVal * > operandVars
bool isFP() const
Direct is predicate checks.
abstract class for implementing variable references
virtual ExprType type() const
returns (current) type
EvaluationStrategy
Types of evaluation strategies that are available.
const char * evalStr(VarBlock *varBlock=nullptr) const
void addError(const std::string &error, const int startPos, const int endPos) const
const double * evalFP(VarBlock *varBlock=nullptr) const
ExprType _desiredReturnType
void prepIfNeeded() const
VariableSetHandle getLoopVarSetHandle(VariableHandle vh)
const std::vector< double > & evalFP(ExprEvalHandle eeh)
void setLoopVariable(VariableSetHandle handle, double *values, unsigned dim)
std::set< GlobalVal * > AllExternalVars
ExprEvalHandle getExprEvalHandle(ExprHandle eh)
ExprHandle addExpression(const std::string &varName, ExprType seTy, const std::string &expr)
std::set< DExpression * > exprEvaled
const char * evalStr(ExprEvalHandle eeh)
std::set< DExpression * > exprToEval
void setVariable(VariableHandle handle, double *values, unsigned dim)
std::set< DExpression * > AllExprs
VariableHandle addExternalVariable(const std::string &variableName, ExprType seTy)
GlobalVal(const std::string &varName, const SeExpr2::ExprType &et)
std::set< DExpression * > users
you may not use this file except in compliance with the License and the following modification to it
std::set< GlobalVal * >::iterator VariableSetHandle
std::set< GlobalVal * >::iterator VariableHandle
std::pair< ExprHandle, std::vector< DExpression * > > ExprEvalHandle
std::set< DExpression * >::iterator ExprHandle
void eval(const char **result)
std::vector< double > val
GlobalFP(const std::string &varName, int dim)
void eval(double *result)
returns this variable's value by setting result
void eval(const char **result)
void eval(double *result)
returns this variable's value by setting result
GlobalStr(const std::string &varName)
</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")
If a scalar is used in a vector context