silence compiler warnings
This commit is contained in:
@ -91,10 +91,10 @@ public:
|
||||
int getNumArguments() const {
|
||||
return numArgs;
|
||||
}
|
||||
double evaluate(const double* arguments) const {
|
||||
double evaluate(const double* ) const {
|
||||
return 0.0;
|
||||
}
|
||||
double evaluateDerivative(const double* arguments, const int* derivOrder) const {
|
||||
double evaluateDerivative(const double* , const int* ) const {
|
||||
return 0.0;
|
||||
}
|
||||
CustomFunction* clone() const {
|
||||
|
||||
@ -177,7 +177,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Constant(value);
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* , const std::map<std::string, double>& ) const {
|
||||
return value;
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -208,7 +208,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Variable(name);
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* , const std::map<std::string, double>& variables) const {
|
||||
std::map<std::string, double>::const_iterator iter = variables.find(name);
|
||||
if (iter == variables.end())
|
||||
throw Exception("No value specified for variable "+name);
|
||||
@ -253,7 +253,7 @@ public:
|
||||
clone->derivOrder = derivOrder;
|
||||
return clone;
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
if (isDerivative)
|
||||
return function->evaluateDerivative(args, &derivOrder[0]);
|
||||
return function->evaluate(args);
|
||||
@ -289,7 +289,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Add();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]+args[1];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -317,7 +317,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Subtract();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]-args[1];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -342,7 +342,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Multiply();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]*args[1];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -370,7 +370,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Divide();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]/args[1];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -395,7 +395,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Power();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::pow(args[0], args[1]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -420,7 +420,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Negate();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return -args[0];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -442,7 +442,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Sqrt();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::sqrt(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -464,7 +464,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Exp();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::exp(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -486,7 +486,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Log();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::log(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -508,7 +508,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Sin();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::sin(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -530,7 +530,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Cos();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::cos(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -552,7 +552,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Sec();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return 1.0/std::cos(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -574,7 +574,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Csc();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return 1.0/std::sin(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -596,7 +596,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Tan();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::tan(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -618,7 +618,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Cot();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return 1.0/std::tan(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -640,7 +640,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Asin();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::asin(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -662,7 +662,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Acos();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::acos(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -684,7 +684,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Atan();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::atan(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -706,7 +706,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Atan2();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::atan2(args[0], args[1]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -728,7 +728,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Sinh();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::sinh(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -750,7 +750,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Cosh();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::cosh(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -772,7 +772,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Tanh();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::tanh(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -834,7 +834,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Step();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return (args[0] >= 0.0 ? 1.0 : 0.0);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -856,7 +856,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Delta();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return (args[0] == 0.0 ? 1.0 : 0.0);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -878,7 +878,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Square();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]*args[0];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -900,7 +900,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Cube();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]*args[0]*args[0];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -922,7 +922,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Reciprocal();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return 1.0/args[0];
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -946,7 +946,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new AddConstant(value);
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]+value;
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -979,7 +979,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new MultiplyConstant(value);
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return args[0]*value;
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -1014,7 +1014,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new PowerConstant(value);
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
if (isIntPower) {
|
||||
// Integer powers can be computed much more quickly by repeated multiplication.
|
||||
|
||||
@ -1069,7 +1069,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Min();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
// parens around (std::min) are workaround for horrible microsoft max/min macro trouble
|
||||
return (std::min)(args[0], args[1]);
|
||||
}
|
||||
@ -1092,7 +1092,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Max();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
// parens around (std::min) are workaround for horrible microsoft max/min macro trouble
|
||||
return (std::max)(args[0], args[1]);
|
||||
}
|
||||
@ -1115,7 +1115,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Abs();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::abs(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -1138,7 +1138,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Floor();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::floor(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -1160,7 +1160,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Ceil();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>& ) const {
|
||||
return std::ceil(args[0]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
@ -1182,7 +1182,7 @@ public:
|
||||
Operation* clone() const {
|
||||
return new Select();
|
||||
}
|
||||
double evaluate(double* args, const std::map<std::string, double>& variables) const {
|
||||
double evaluate(double* args, const std::map<std::string, double>&) const {
|
||||
return (args[0] != 0.0 ? args[1] : args[2]);
|
||||
}
|
||||
ExpressionTreeNode differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const;
|
||||
|
||||
@ -88,7 +88,7 @@ void CompiledExpression::compileExpression(const ExpressionTreeNode& node, vecto
|
||||
// Process the child nodes.
|
||||
|
||||
vector<int> args;
|
||||
for (int i = 0; i < node.getChildren().size(); i++) {
|
||||
for (int i = 0; i < (int)node.getChildren().size(); i++) {
|
||||
compileExpression(node.getChildren()[i], temps);
|
||||
args.push_back(findTempIndex(node.getChildren()[i], temps));
|
||||
}
|
||||
@ -110,7 +110,7 @@ void CompiledExpression::compileExpression(const ExpressionTreeNode& node, vecto
|
||||
// If the arguments are sequential, we can just pass a pointer to the first one.
|
||||
|
||||
bool sequential = true;
|
||||
for (int i = 1; i < args.size(); i++)
|
||||
for (int i = 1; i < (int)args.size(); i++)
|
||||
if (args[i] != args[i-1]+1)
|
||||
sequential = false;
|
||||
if (sequential)
|
||||
@ -167,17 +167,17 @@ double CompiledExpression::evaluate() const {
|
||||
#ifdef LEPTON_USE_JIT
|
||||
return jitCode();
|
||||
#else
|
||||
for (int i = 0; i < variablesToCopy.size(); i++)
|
||||
for (int i = 0; i < (int)variablesToCopy.size(); i++)
|
||||
*variablesToCopy[i].first = *variablesToCopy[i].second;
|
||||
|
||||
// Loop over the operations and evaluate each one.
|
||||
|
||||
for (int step = 0; step < operation.size(); step++) {
|
||||
for (int step = 0; step < (int)operation.size(); step++) {
|
||||
const vector<int>& args = arguments[step];
|
||||
if (args.size() == 1)
|
||||
workspace[target[step]] = operation[step]->evaluate(&workspace[args[0]], dummyVariables);
|
||||
else {
|
||||
for (int i = 0; i < args.size(); i++)
|
||||
for (int i = 0; i < (int)args.size(); i++)
|
||||
argValues[i] = workspace[args[i]];
|
||||
workspace[target[step]] = operation[step]->evaluate(&argValues[0], dummyVariables);
|
||||
}
|
||||
|
||||
@ -37,25 +37,25 @@ using namespace LMP_Lepton;
|
||||
using namespace std;
|
||||
|
||||
ExpressionTreeNode::ExpressionTreeNode(Operation* operation, const vector<ExpressionTreeNode>& children) : operation(operation), children(children) {
|
||||
if (operation->getNumArguments() != children.size())
|
||||
if (operation->getNumArguments() != (int)children.size())
|
||||
throw Exception("wrong number of arguments to function: "+operation->getName());
|
||||
}
|
||||
|
||||
ExpressionTreeNode::ExpressionTreeNode(Operation* operation, const ExpressionTreeNode& child1, const ExpressionTreeNode& child2) : operation(operation) {
|
||||
children.push_back(child1);
|
||||
children.push_back(child2);
|
||||
if (operation->getNumArguments() != children.size())
|
||||
if (operation->getNumArguments() != (int)children.size())
|
||||
throw Exception("wrong number of arguments to function: "+operation->getName());
|
||||
}
|
||||
|
||||
ExpressionTreeNode::ExpressionTreeNode(Operation* operation, const ExpressionTreeNode& child) : operation(operation) {
|
||||
children.push_back(child);
|
||||
if (operation->getNumArguments() != children.size())
|
||||
if (operation->getNumArguments() != (int)children.size())
|
||||
throw Exception("wrong number of arguments to function: "+operation->getName());
|
||||
}
|
||||
|
||||
ExpressionTreeNode::ExpressionTreeNode(Operation* operation) : operation(operation) {
|
||||
if (operation->getNumArguments() != children.size())
|
||||
if (operation->getNumArguments() != (int)children.size())
|
||||
throw Exception("wrong number of arguments to function: "+operation->getName());
|
||||
}
|
||||
|
||||
|
||||
@ -37,25 +37,25 @@
|
||||
using namespace LMP_Lepton;
|
||||
using namespace std;
|
||||
|
||||
double Operation::Erf::evaluate(double* args, const map<string, double>& variables) const {
|
||||
double Operation::Erf::evaluate(double* args, const map<string, double>& ) const {
|
||||
return erf(args[0]);
|
||||
}
|
||||
|
||||
double Operation::Erfc::evaluate(double* args, const map<string, double>& variables) const {
|
||||
double Operation::Erfc::evaluate(double* args, const map<string, double>& ) const {
|
||||
return erfc(args[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Constant::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Constant::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& , const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Constant(0.0));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Variable::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Variable::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& , const std::string& variable) const {
|
||||
if (variable == name)
|
||||
return ExpressionTreeNode(new Operation::Constant(1.0));
|
||||
return ExpressionTreeNode(new Operation::Constant(0.0));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Custom::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Custom::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
if (function->getNumArguments() == 0)
|
||||
return ExpressionTreeNode(new Operation::Constant(0.0));
|
||||
ExpressionTreeNode result = ExpressionTreeNode(new Operation::Multiply(), ExpressionTreeNode(new Operation::Custom(*this, 0), children), childDerivs[0]);
|
||||
@ -67,21 +67,21 @@ ExpressionTreeNode Operation::Custom::differentiate(const std::vector<Expression
|
||||
return result;
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Add::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Add::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Add(), childDerivs[0], childDerivs[1]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Subtract::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Subtract::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Subtract(), childDerivs[0], childDerivs[1]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Multiply::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Multiply::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Add(),
|
||||
ExpressionTreeNode(new Operation::Multiply(), children[0], childDerivs[1]),
|
||||
ExpressionTreeNode(new Operation::Multiply(), children[1], childDerivs[0]));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Divide::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Divide::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Divide(),
|
||||
ExpressionTreeNode(new Operation::Subtract(),
|
||||
ExpressionTreeNode(new Operation::Multiply(), children[1], childDerivs[0]),
|
||||
@ -89,7 +89,7 @@ ExpressionTreeNode Operation::Divide::differentiate(const std::vector<Expression
|
||||
ExpressionTreeNode(new Operation::Square(), children[1]));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Power::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Power::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Add(),
|
||||
ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Multiply(),
|
||||
@ -104,11 +104,11 @@ ExpressionTreeNode Operation::Power::differentiate(const std::vector<ExpressionT
|
||||
childDerivs[1]));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Negate::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Negate::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Negate(), childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Sqrt::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Sqrt::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::MultiplyConstant(0.5),
|
||||
ExpressionTreeNode(new Operation::Reciprocal(),
|
||||
@ -116,32 +116,32 @@ ExpressionTreeNode Operation::Sqrt::differentiate(const std::vector<ExpressionTr
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Exp::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Exp::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Exp(), children[0]),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Log::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Log::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Reciprocal(), children[0]),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Sin::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Sin::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Cos(), children[0]),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Cos::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Cos::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Negate(),
|
||||
ExpressionTreeNode(new Operation::Sin(), children[0])),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Sec::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Sec::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Sec(), children[0]),
|
||||
@ -149,7 +149,7 @@ ExpressionTreeNode Operation::Sec::differentiate(const std::vector<ExpressionTre
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Csc::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Csc::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Negate(),
|
||||
ExpressionTreeNode(new Operation::Multiply(),
|
||||
@ -158,14 +158,14 @@ ExpressionTreeNode Operation::Csc::differentiate(const std::vector<ExpressionTre
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Tan::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Tan::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Square(),
|
||||
ExpressionTreeNode(new Operation::Sec(), children[0])),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Cot::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Cot::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Negate(),
|
||||
ExpressionTreeNode(new Operation::Square(),
|
||||
@ -173,7 +173,7 @@ ExpressionTreeNode Operation::Cot::differentiate(const std::vector<ExpressionTre
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Asin::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Asin::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Reciprocal(),
|
||||
ExpressionTreeNode(new Operation::Sqrt(),
|
||||
@ -183,7 +183,7 @@ ExpressionTreeNode Operation::Asin::differentiate(const std::vector<ExpressionTr
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Acos::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Acos::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Negate(),
|
||||
ExpressionTreeNode(new Operation::Reciprocal(),
|
||||
@ -194,7 +194,7 @@ ExpressionTreeNode Operation::Acos::differentiate(const std::vector<ExpressionTr
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Atan::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Atan::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Reciprocal(),
|
||||
ExpressionTreeNode(new Operation::AddConstant(1.0),
|
||||
@ -202,7 +202,7 @@ ExpressionTreeNode Operation::Atan::differentiate(const std::vector<ExpressionTr
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Atan2::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Atan2::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Divide(),
|
||||
ExpressionTreeNode(new Operation::Subtract(),
|
||||
ExpressionTreeNode(new Operation::Multiply(), children[1], childDerivs[0]),
|
||||
@ -212,21 +212,21 @@ ExpressionTreeNode Operation::Atan2::differentiate(const std::vector<ExpressionT
|
||||
ExpressionTreeNode(new Operation::Square(), children[1])));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Sinh::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Sinh::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Cosh(),
|
||||
children[0]),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Cosh::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Cosh::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Sinh(),
|
||||
children[0]),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Tanh::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Tanh::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Subtract(),
|
||||
ExpressionTreeNode(new Operation::Constant(1.0)),
|
||||
@ -235,7 +235,7 @@ ExpressionTreeNode Operation::Tanh::differentiate(const std::vector<ExpressionTr
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Erf::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Erf::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Constant(2.0/sqrt(M_PI))),
|
||||
@ -245,7 +245,7 @@ ExpressionTreeNode Operation::Erf::differentiate(const std::vector<ExpressionTre
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Erfc::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Erfc::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Constant(-2.0/sqrt(M_PI))),
|
||||
@ -255,29 +255,29 @@ ExpressionTreeNode Operation::Erfc::differentiate(const std::vector<ExpressionTr
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Step::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Step::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& , const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Constant(0.0));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Delta::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Delta::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& , const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Constant(0.0));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Square::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Square::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::MultiplyConstant(2.0),
|
||||
children[0]),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Cube::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Cube::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::MultiplyConstant(3.0),
|
||||
ExpressionTreeNode(new Operation::Square(), children[0])),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Reciprocal::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Reciprocal::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::Negate(),
|
||||
ExpressionTreeNode(new Operation::Reciprocal(),
|
||||
@ -285,16 +285,16 @@ ExpressionTreeNode Operation::Reciprocal::differentiate(const std::vector<Expres
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::AddConstant::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::AddConstant::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return childDerivs[0];
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::MultiplyConstant::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::MultiplyConstant::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::MultiplyConstant(value),
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::PowerConstant::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::PowerConstant::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
ExpressionTreeNode(new Operation::MultiplyConstant(value),
|
||||
ExpressionTreeNode(new Operation::PowerConstant(value-1),
|
||||
@ -302,7 +302,7 @@ ExpressionTreeNode Operation::PowerConstant::differentiate(const std::vector<Exp
|
||||
childDerivs[0]);
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Min::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Min::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
ExpressionTreeNode step(new Operation::Step(),
|
||||
ExpressionTreeNode(new Operation::Subtract(), children[0], children[1]));
|
||||
return ExpressionTreeNode(new Operation::Subtract(),
|
||||
@ -311,7 +311,7 @@ ExpressionTreeNode Operation::Min::differentiate(const std::vector<ExpressionTre
|
||||
ExpressionTreeNode(new Operation::AddConstant(-1), step)));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Max::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Max::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
ExpressionTreeNode step(new Operation::Step(),
|
||||
ExpressionTreeNode(new Operation::Subtract(), children[0], children[1]));
|
||||
return ExpressionTreeNode(new Operation::Subtract(),
|
||||
@ -320,7 +320,7 @@ ExpressionTreeNode Operation::Max::differentiate(const std::vector<ExpressionTre
|
||||
ExpressionTreeNode(new Operation::AddConstant(-1), step)));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Abs::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Abs::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
ExpressionTreeNode step(new Operation::Step(), children[0]);
|
||||
return ExpressionTreeNode(new Operation::Multiply(),
|
||||
childDerivs[0],
|
||||
@ -328,15 +328,15 @@ ExpressionTreeNode Operation::Abs::differentiate(const std::vector<ExpressionTre
|
||||
ExpressionTreeNode(new Operation::MultiplyConstant(2), step)));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Floor::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Floor::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& , const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Constant(0.0));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Ceil::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Ceil::differentiate(const std::vector<ExpressionTreeNode>& , const std::vector<ExpressionTreeNode>& , const std::string& ) const {
|
||||
return ExpressionTreeNode(new Operation::Constant(0.0));
|
||||
}
|
||||
|
||||
ExpressionTreeNode Operation::Select::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& variable) const {
|
||||
ExpressionTreeNode Operation::Select::differentiate(const std::vector<ExpressionTreeNode>& children, const std::vector<ExpressionTreeNode>& childDerivs, const std::string& ) const {
|
||||
vector<ExpressionTreeNode> derivChildren;
|
||||
derivChildren.push_back(children[0]);
|
||||
derivChildren.push_back(childDerivs[1]);
|
||||
|
||||
@ -288,11 +288,13 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
|
||||
{
|
||||
if (children[0].getOperation().getId() == Operation::SQUARE) // sqrt(square(x)) = abs(x)
|
||||
return ExpressionTreeNode(new Operation::Abs(), children[0].getChildren()[0]);
|
||||
break;
|
||||
}
|
||||
case Operation::SQUARE:
|
||||
{
|
||||
if (children[0].getOperation().getId() == Operation::SQRT) // square(sqrt(x)) = x
|
||||
return children[0].getChildren()[0];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
@ -178,7 +178,7 @@ ParsedExpression Parser::parse(const string& expression, const map<string, Custo
|
||||
vector<ParseToken> tokens = tokenize(subexpressions[i].substr(equalsPos+1));
|
||||
int pos = 0;
|
||||
subexpDefs[name] = parsePrecedence(tokens, pos, customFunctions, subexpDefs, 0);
|
||||
if (pos != tokens.size())
|
||||
if (pos != (int)tokens.size())
|
||||
throw Exception("unexpected text at end of subexpression: "+tokens[pos].getText());
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ ParsedExpression Parser::parse(const string& expression, const map<string, Custo
|
||||
vector<ParseToken> tokens = tokenize(primaryExpression);
|
||||
int pos = 0;
|
||||
ExpressionTreeNode result = parsePrecedence(tokens, pos, customFunctions, subexpDefs, 0);
|
||||
if (pos != tokens.size())
|
||||
if (pos != (int)tokens.size())
|
||||
throw Exception("unexpected text at end of expression: "+tokens[pos].getText());
|
||||
return ParsedExpression(result);
|
||||
}
|
||||
@ -198,7 +198,7 @@ ParsedExpression Parser::parse(const string& expression, const map<string, Custo
|
||||
|
||||
ExpressionTreeNode Parser::parsePrecedence(const vector<ParseToken>& tokens, int& pos, const map<string, CustomFunction*>& customFunctions,
|
||||
const map<string, ExpressionTreeNode>& subexpressionDefs, int precedence) {
|
||||
if (pos == tokens.size())
|
||||
if (pos == (int)tokens.size())
|
||||
throw Exception("unexpected end of expression");
|
||||
|
||||
// Parse the next value (number, variable, function, parenthesized expression)
|
||||
@ -224,7 +224,7 @@ ExpressionTreeNode Parser::parsePrecedence(const vector<ParseToken>& tokens, int
|
||||
else if (token.getType() == ParseToken::LeftParen) {
|
||||
pos++;
|
||||
result = parsePrecedence(tokens, pos, customFunctions, subexpressionDefs, 0);
|
||||
if (pos == tokens.size() || tokens[pos].getType() != ParseToken::RightParen)
|
||||
if (pos == (int)tokens.size() || tokens[pos].getType() != ParseToken::RightParen)
|
||||
throw Exception("unbalanced parentheses");
|
||||
pos++;
|
||||
}
|
||||
@ -238,7 +238,7 @@ ExpressionTreeNode Parser::parsePrecedence(const vector<ParseToken>& tokens, int
|
||||
if (moreArgs)
|
||||
pos++;
|
||||
} while (moreArgs);
|
||||
if (pos == tokens.size() || tokens[pos].getType() != ParseToken::RightParen)
|
||||
if (pos == (int)tokens.size() || tokens[pos].getType() != ParseToken::RightParen)
|
||||
throw Exception("unbalanced parentheses");
|
||||
pos++;
|
||||
Operation* op = getFunctionOperation(token.getText(), customFunctions);
|
||||
|
||||
Reference in New Issue
Block a user