Modify semantics of ExprNode::countDiffs()

Previously, this function was counting the total number of diff() operators in
an expression. But this is not very useful, and is potentially misleading,
because in practice we use this function to compute the maximum lag on
variables in levels.

This function now returns the maximum number of nested diffs.

For example, on diff(x)+diff(diff(y)), this function was returning 3, and it
now returns 2.
parent 66a766b0
......@@ -5323,7 +5323,7 @@ BinaryOpNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &no
BinaryOpNode::countDiffs() const
return arg1->countDiffs() + arg2->countDiffs();
return max(arg1->countDiffs(), arg2->countDiffs());
......@@ -6585,7 +6585,7 @@ TrinaryOpNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &n
TrinaryOpNode::countDiffs() const
return arg1->countDiffs() + arg2->countDiffs() + arg3->countDiffs();
return max(arg1->countDiffs(), max(arg2->countDiffs(), arg3->countDiffs()));
......@@ -7069,7 +7069,7 @@ AbstractExternalFunctionNode::countDiffs() const
int ndiffs = 0;
for (auto argument : arguments)
ndiffs += argument->countDiffs();
ndiffs = max(ndiffs, argument->countDiffs());
return ndiffs;
......@@ -518,7 +518,7 @@ class ExprNode
//! Returns true if the expression contains one or several exogenous variable
virtual bool containsExogenous() const = 0;
//! Returns the number of diffs present
//! Returns the maximum number of nested diffs in the expression
virtual int countDiffs() const = 0;
//! Return true if the nodeID is a variable withe a type equal to type_arg, a specific variable id aqual to varfiable_id and a lag equal to lag_arg and false otherwise
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment