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.
issue#70
Sébastien Villemot 2018-12-05 12:38:46 +01:00
parent 66a766b0b7
commit fe6d4e9bca
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 4 additions and 4 deletions

View File

@ -5323,7 +5323,7 @@ BinaryOpNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &no
int
BinaryOpNode::countDiffs() const
{
return arg1->countDiffs() + arg2->countDiffs();
return max(arg1->countDiffs(), arg2->countDiffs());
}
expr_t
@ -6585,7 +6585,7 @@ TrinaryOpNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &n
int
TrinaryOpNode::countDiffs() const
{
return arg1->countDiffs() + arg2->countDiffs() + arg3->countDiffs();
return max(arg1->countDiffs(), max(arg2->countDiffs(), arg3->countDiffs()));
}
expr_t
@ -7069,7 +7069,7 @@ AbstractExternalFunctionNode::countDiffs() const
{
int ndiffs = 0;
for (auto argument : arguments)
ndiffs += argument->countDiffs();
ndiffs = max(ndiffs, argument->countDiffs());
return ndiffs;
}

View File

@ -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