-
-
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
RFC: Add similar for PermutedDimsArray #23263
base: master
Are you sure you want to change the base?
Conversation
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.
Good idea
PermutedDimsArray{S,N,perm,iperm,typeof(new_parent)}(new_parent) | ||
end | ||
|
||
function Base.similar(a::PermutedDimsArray{T,N,perm,iperm}, ::Type{S}, dims::Dims{N}) where {T,S,N,perm,iperm} |
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.
Do you need to define any more than this one definition? (Do fallbacks not handle the rest?)
end | ||
|
||
function Base.similar(a::PermutedDimsArray{T,N,perm,iperm}, ::Type{S}, dims::Dims{N}) where {T,S,N,perm,iperm} | ||
new_parent = similar(a.parent, S, ntuple(i->dims[perm[i]], N)) |
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.
Is this inferrable? (Do we need ntuple(f, Val{N})
?)
Hmm... here was about to use Is there a convenient way to get a "similar" array that strips the |
Does |
Well, it would work when you want What I really want (and will implement separately to None of this means this PR is bad. But when I implement function Base.similar(a::PermutedDimsArray, ::Type{T}, dims::Dims) where {T}
similar(a.parent, T, dims)
end |
Maybe time to start implementing the |
This allows you to do things like:
In particular I wanted for collecting into an array from an iterator that yielded its elements in transposed order, but it seems like a sensible definition regardless.