BUG: Use -0. as initial value for summation (internal only) #21218
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Technically, we should ensure that we do all summations starting with
-0 unless there is nothing to sum (in which case the result is clearly
0).
This is a start, since the initial value is still filled in as 0 by
the reduce machinery. However, it fixes the odd case where an
inplace addition:
x1 = np.array(-0.0)
x2 = np.array(-0.0)
x1 += x2
May go into the reduce code path (becaus strides are 0). We could
avoid the reduce path there, but -0 here is strictly correct anyway
and also a necessary step towards fixing
sum([-0., -0., -0.])which still requires
initial=-0.0to be passed manually right now.There are new
xfailmarked tests also checking the path withoutinitial. Presumably, we should be using -0.0 as initial value,
but 0.0 as default (if an array is empty) here.
This may be more reasonably possible after gh-20970.
Closes gh-21213, gh-21212