Convert range type in reduced_index
#34770
Merged
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.
BACKPORTING NOTE: consensus is to backport the first commit but not the second.
The
reduced_indices
andreduced_indices0
methods sometimes assert that the return axes type is the same as the input. Consequently, the implementation ofreduced_index
had better return a range of the same type as the input.This corrects the error in JuliaArrays/OffsetArrays.jl#92. I'll put a workaround in OffsetArrays.jl too.
The second commit consistently asserts type-equality in
reduced_indices
. This is a bit more aggressive, and if we backport it's possible we should backport the first but not the second. The potential problem is that it makes these methods more fragile in cases wherereduced_index
is broken. IMO, this is a good thing because it increases the odds that errors will be caught early. Moreover, it ensures that the return type is inferrable in cases where the reduction is over the first dimension but constant-propagation fails to detect this. However, for the LTS release this should be tested for trouble.