[ https://issues.apache.org/jira/browse/MATH373?page=com.atlassian.jira.plugin.system.issuetabpanels:commenttabpanel&focusedCommentId=12876512#action_12876512
]
Bill Barker commented on MATH373:

I agree with the reasoning here, and we should do it this way in 3.0. However it is an incompatible
change to do in a point release, so I'm going to wait for more feed back from other developers
before I make any changes to the current code.
I'm thinking that adding a method to AbstractUnivariateStatistic that looks like:
protected boolean test( final double[] values, final int begin, final int length, final
boolean allowEmpty)
that would have the test:
if(length == 0 && !allowEmpty)
return false;
The current test method can call the new one with allowEmpty=false for backwards compatibility.
Then we can decide on which statistics should have a zero value on the empty set.
> StatUtils.sum returns NaN for zerolength arrays
> 
>
> Key: MATH373
> URL: https://issues.apache.org/jira/browse/MATH373
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 2.1
> Reporter: Roman Werpachowski
>
> StatUtils.sum returns NaN for zerolength arrays, which is:
> 1. inconsistent with the mathematical notion of sum: in maths, sum_{i=0}^{N1} a_i will
be 0 for N=0. In particular, the identity
> sum_{i=0}^{k1} a_i + sum_{i=k}^{N1} = sum_{i=0}^{N1}
> is broken for k = 0, since NaN + x = NaN, not x.
> 2. introduces hard to debug erros (returning a NaN is one of the worst forms of reporting
an exceptional condition, as NaNs propagate silently and require manual tracing during the
debugging)
> 3. enforces "special case" handling when the user expects that the summed array can have
a zero length.
> The correct behaviour is, in my opinion, to return 0.0, not NaN in the above case.

This message is automatically generated by JIRA.

You can reply to this email to add a comment to the issue online.
