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));
128 addError(name +
" fail resolveVar", 0, 0);
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 = 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());
238 it = std::set_intersection(all.begin(), all.end(),
exprToEval.begin(),
exprToEval.end(), ret1.begin());
239 ret1.resize(it - ret1.begin());
241 std::vector<DExpression *> ret2(ret1.size());
242 it = std::set_difference(ret1.begin(), ret1.end(),
exprEvaled.begin(),
exprEvaled.end(), ret2.begin());
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();
void prepIfNeeded() const
std::set< DExpression * > operandExprs
EvaluationStrategy
Types of evaluation strategies that are available.
void eval(const char **result)
GlobalVal(const std::string &varName, const SeExpr2::ExprType &et)
</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")
VariableHandle addExternalVariable(const std::string &variableName, ExprType seTy)
void addError(const std::string &error, const int startPos, const int endPos) const
void setVariable(VariableHandle handle, double *values, unsigned dim)
bool isFP() const
Direct is predicate checks.
std::set< GlobalVal * > AllExternalVars
std::set< DExpression * > users
std::pair< ExprHandle, std::vector< DExpression * > > ExprEvalHandle
ExprHandle addExpression(const std::string &varName, ExprType seTy, const std::string &expr)
std::set< GlobalVal * >::iterator VariableHandle
std::set< DExpression * > exprToEval
std::set< DExpression * > exprEvaled
void setLoopVariable(VariableSetHandle handle, double *values, unsigned dim)
ExprType _desiredReturnType
const char * evalStr(ExprEvalHandle eeh)
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
std::set< DExpression * >::iterator ExprHandle
ExprEvalHandle getExprEvalHandle(ExprHandle eh)
DExpression(const std::string &varName, Expressions &context, const std::string &e, const ExprType &type=ExprType().FP(3), EvaluationStrategy be=defaultEvaluationStrategy)
If a scalar is used in a vector context
const double * evalFP(VarBlock *varBlock=nullptr) const
< b ></b >< br >< b ></b ></td >< td > vector constructor< br > vector component access n must be
const char * evalStr(VarBlock *varBlock=nullptr) const
GlobalStr(const std::string &varName)
const std::string & name() const
std::set< GlobalVal * >::iterator VariableSetHandle
virtual ExprType type() const
returns (current) type
std::set< GlobalVal * > operandVars
VariableSetHandle getLoopVarSetHandle(VariableHandle vh)
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)
abstract class for implementing variable references
const std::vector< double > & evalFP(ExprEvalHandle eeh)
ExprVarRef * resolveVar(const std::string &name) const
std::set< DExpression * > AllExprs
std::vector< double > val