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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I think reducing over an empty container is well-defined: just return the neutral element.
reduce_funcshould be trusted to do the right thing. What was the reasoning for putting in this error message? Basically, what I'm pushing for is to get rid of it and returnreduce_func([])instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
reduce_funcworked for an empty list, I think this PR wouldn't be needed, right?The motivation for this was for things like
actx.np.maxwherereduce_funcdoesn't (currently) behave nicely for empty inputs. Should that maybe be fixed instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, calling
np.maxon an empty list raisesand requires specifying an initial value with
np.max([], initial=np.inf). We should probably do something like that inactx.nptoo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point. I had not thought far enough to realize that, but I agree now.
I think that's exactly what we should do.
I agree. While I wasn't loving numpy's interface of "no implicit neutral" element at first, I think it makes sense from the perspective of integers. I think we should aim to replicate this, both at the level of
actx.np, and for the array container reductions under discussion here.One subtlety is the
ValueErrorfor empty arrays. For symbolically-shapedpytatoarrays, it may not be possible to do a perfect job.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some work towards that:
ReductionOperationclass, accept 'initial' in reductions pytato#238That latter PR needs some more work done to it. @majosm, could you take a look?