-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept more general Integer sizes in reshape #55521
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes #17372 |
nsajko
reviewed
Aug 31, 2024
Gentle bump |
2 similar comments
Gentle bump |
Gentle bump |
oscardssmith
approved these changes
Nov 12, 2024
@nsajko Could you suggest a way to simplify the methods here without widening the inference results? In particular, what were the type-assertions in |
jishnub
force-pushed
the
jishnub/reshape_integer
branch
from
November 27, 2024 09:47
a0fe172
to
4afd217
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.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
.