26 iscomplex =
v2.iscomplex;
27 int hdim = iscomplex ? 2*dim : dim;
28 data =
new double[
hdim];
36 iscomplex =
v2.iscomplex;
37 int hdim = iscomplex ? 2*dim : dim;
38 data =
new double[
hdim];
45 int hdim = iscomplex ? 2*dim : dim;
46 data =
new double[
hdim];
55 iscomplex =
v2.iscomplex;
56 int hdim = iscomplex ? 2*dim : dim;
58 data =
new double[
hdim];
64 int Dimension()
const {
return dim; }
65 bool IsComplex ()
const {
return iscomplex; }
67 double & ValueDouble(
int i = 0) {
return data[
i]; }
69 {
return reinterpret_cast<std::complex<double>*
>(data)[
i]; }
71 const double & ValueDouble(
int i = 0)
const {
return data[
i]; }
72 const std::complex<double> & ValueComplex (
int i = 0)
const
76 template <
typename SCAL>
SCAL Value (
int i)
const;
80 inline double GenericVariable::Value<double> (
int i)
const
82 if (iscomplex)
throw Exception (
"Value<double> called for complex variable");
86 inline std::complex<double> GenericVariable::Value<std::complex<double>> (
int i)
const
89 return complex<double> (data[2*i], data[2*i+1]);
91 return complex<double> (data[i]);
95 inline ostream &
operator<< (ostream & ost,
const GenericVariable & var)
98 for (
int i = 0; i < var.Dimension(); i++)
99 ost << var.ValueComplex(i) <<
", ";
101 for (
int i = 0; i < var.Dimension(); i++)
102 ost << var.ValueDouble(i) <<
", ";
126 ADD =
'+', SUB =
'-', MULT =
'*', DIV =
'/', LP =
'(', RP =
')',
129 VEC_ADD, VEC_SUB, VEC_SCAL_MULT, SCAL_VEC_MULT, VEC_VEC_MULT, VEC_SCAL_DIV, VEC_ELEM, VEC_DIM,
130 AND, OR, NOT, GREATER, LESS, GREATEREQUAL, LESSEQUAL, EQUAL,
131 CONSTANT, IMAG, VARIABLE, FUNCTION, GLOBVAR, GLOBGENVAR, END, STRING,
132 SIN, COS, TAN, ATAN, ATAN2, EXP, LOG, ABS, SIGN, SQRT, STEP,
133 BESSELJ0, BESSELY0, BESSELJ1, BESSELY1
173 template <typename TIN>
174 void Eval (const TIN * x, complex<double> * y, int ydim) const;
176 template <
typename TIN,
typename TCALC>
196 { program.Append (
step (val)); }
200 { program.Append (
step(varnum)); }
204 { program.Append (
step(
dp)); }
208 { program.Append (
step(
dp)); }
212 { program.Append (
step(op)); }
216 { program.Append (
step(fun)); }
268 step (
const double * aglobvar)
274 step (
const GenericVariable * aglobvar)
280 step (
double (*fun) (
double))
297 : vecdim(1), isbool(
false), iscomplex(
false)
323 char string_value[1000];
325 int var_num, var_dim;
354 : argnum(-1), dim(1), iscomplex(
false) { ; }
367 {
return num_value; }
375 bool GetVariableIsComplex()
const
376 {
return var_iscomplex; }
380 {
return string_value; }
386 bool ToBool (
double x)
const {
return x > eps; }
388 double CheckReal (
double x)
const {
return x; }
391 if (
x.imag() != 0)
cerr <<
"illegal complex value" <<
endl;
395 double Abs (
double x)
const {
return std::fabs(
x); }
Datatype for automatic differentiation.
Definition autodiff.hpp:26
AutoDiffVec()=default
elements are undefined
Definition evalfunc.hpp:291
one step of evaluation
Definition evalfunc.hpp:224
short int vecdim
dimension of vector
Definition evalfunc.hpp:246
Numerical expression parser.
Definition evalfunc.hpp:121
ResultType ParseSubExpression()
parsing expression (standard parsing grammar)
void ReadNext(bool optional=true)
read next token
void Eval(const complex< double > *x, double *y, int ydim) const
evaluate multi-value complex function with real result
void Print(ostream &ost) const
print expression
ResultType ParsePrimary()
parsing expression (standard parsing grammar)
int GetVariableDimension() const
returns dimension of variable of last token
Definition evalfunc.hpp:373
EVAL_TOKEN GetToken() const
returns last token
Definition evalfunc.hpp:362
ResultType ParseExpression()
parsing expression (standard parsing grammar)
void AddGlobVariable(const double *dp)
push pointer to global double value.
Definition evalfunc.hpp:203
static SymbolTable< TFUNP > functions
registered functions
Definition evalfunc.hpp:335
EvalFunction(istream &aist)
parse from input stream
SymbolTable< double * > globvariables
registered variables
Definition evalfunc.hpp:341
EvalFunction(const string &str)
parse from string
void DefineGlobalVariable(const string &name, GenericVariable *var)
define constant
void DefineGlobalVariable(const string &name, double *var)
define constant
void DefineArgument(const string &name, int num, int vecdim=1, bool iscomplex=false)
define arguments
void AddGlobVariable(const GenericVariable *dp)
push pointer to global double value.
Definition evalfunc.hpp:207
void Eval(const double *x, double *y, int ydim) const
evaluate multi-value function
double GetNumValue() const
returns num_value of last token
Definition evalfunc.hpp:366
int Dimension() const
vector dimension of result
Definition evalfunc.hpp:192
void AddVariable(int varnum)
push variable x[varnum-1].
Definition evalfunc.hpp:199
void AddFunction(double(*fun)(double))
push function call.
Definition evalfunc.hpp:215
void Eval(const complex< double > *x, complex< double > *y, int ydim) const
evaluate multi-value complex function
istream * ist
parse from stream
Definition evalfunc.hpp:316
const char * GetStringValue() const
returns identifier of last token
Definition evalfunc.hpp:379
double EvalConstant() const
evaluate the constant value
bool Parse(istream &aist)
parse from stream
void AddOperation(EVAL_TOKEN op)
push operation.
Definition evalfunc.hpp:211
bool IsResultComplex() const
is expression complex valued ?
Definition evalfunc.hpp:184
bool IsComplex() const
is expression complex valued ?
double Eval(const double *x=NULL) const
evaluate function
void AddConstant(double val)
push constant on stack.
Definition evalfunc.hpp:195
void DefineConstant(const string &name, double val)
define constant
Array< step > program
the evaluation sequence
Definition evalfunc.hpp:288
int GetVariableNumber() const
returns variable number of last token
Definition evalfunc.hpp:370
SymbolTable< GenericVariable * > genericvariables
registered variables
Definition evalfunc.hpp:343
ResultType ParseCommaExpression()
parsing expression (standard parsing grammar)
complex< double > Eval(const complex< double > *x=NULL) const
evaluate function
SymbolTable< double > constants
registered constants
Definition evalfunc.hpp:338
ResultType ParseTerm()
parsing expression (standard parsing grammar)
bool IsConstant() const
is expression a constant ?
Definition evalfunc.hpp:18
namespace for standard data types and algorithms.
Definition ngstd.hpp:42
ostream & operator<<(ostream &ost, const AutoDiffDiff< D, SCAL > &x)
Prints AudoDiffDiff.
Definition autodiffdiff.hpp:256
the arguments passed to the function
Definition evalfunc.hpp:348
the data
Definition evalfunc.hpp:230
int varnum
the input argument number varnum
Definition evalfunc.hpp:238
const GenericVariable * globgenvar
a pointer to a global variable
Definition evalfunc.hpp:236
double val
a constant value
Definition evalfunc.hpp:232
double(* fun)(double)
a pointer to a unary function
Definition evalfunc.hpp:240
const double * globvar
a pointer to a global variable
Definition evalfunc.hpp:234