Accept more general Integer sizes in reshape #55521
Open
+64
−10
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.
This PR generalizes the
reshape
methods to acceptInteger
s instead ofInt
s, and adds a_reshape_uncolon
method forInteger
arguments. The current_reshape_uncolon
method that acceptsInt
s is left unchanged to ensure that the inferred types are not impacted. I've also tried to ensure that mostInteger
subtypes inBase
that may be safely converted toInt
s pass through that method. I don't particularly like this hard-coding of types, and a better solution is welcome.The call sequence would now go like this:
This lets packages define
reshape(A::CustomArray, ::Tuple{Integer, Vararg{Integer}})
without having to implement_reshape_uncolon
by themselves (or having to call internalBase
functions, as in JuliaArrays/FillArrays.jl#373).reshape
calls involving aColon
would convert this to anInteger
inBase
, and then pass theInteger
sizes to the custom method defined in the package.This PR does not resolve issues like #40076 because this still converts
Integer
s toInt
s in the actual reshaping step. However,BigInt
sizes that may be converted toInt
s will work now:Note that the reshape method with
Integer
sizes explicitly converts these toInt
s to avoid self-recursion (as opposed to callingto_shape
to carry out the conversion implicitly). In the future, we may want to decide what to do with types or values that can't be converted to anInt
.