-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Delete unused arguments in subarray code #30789
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,26 +191,26 @@ end | |
|
||
AbstractZeroDimArray{T} = AbstractArray{T, 0} | ||
|
||
reindex(V, ::Tuple{}, ::Tuple{}) = () | ||
reindex(@nospecialize(V), ::Tuple{}, ::Tuple{}) = () | ||
|
||
# Skip dropped scalars, so simply peel them off the parent indices and continue | ||
reindex(V, idxs::Tuple{ScalarIndex, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) = | ||
reindex(@nospecialize(V), idxs::Tuple{ScalarIndex, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) = | ||
(@_propagate_inbounds_meta; (idxs[1], reindex(V, tail(idxs), subidxs)...)) | ||
|
||
# Slices simply pass their subindices straight through | ||
reindex(V, idxs::Tuple{Slice, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) = | ||
reindex(@nospecialize(V), idxs::Tuple{Slice, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) = | ||
(@_propagate_inbounds_meta; (subidxs[1], reindex(V, tail(idxs), tail(subidxs))...)) | ||
|
||
# Re-index into parent vectors with one subindex | ||
reindex(V, idxs::Tuple{AbstractVector, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) = | ||
reindex(@nospecialize(V), idxs::Tuple{AbstractVector, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) = | ||
(@_propagate_inbounds_meta; (idxs[1][subidxs[1]], reindex(V, tail(idxs), tail(subidxs))...)) | ||
|
||
# Parent matrices are re-indexed with two sub-indices | ||
reindex(V, idxs::Tuple{AbstractMatrix, Vararg{Any}}, subidxs::Tuple{Any, Any, Vararg{Any}}) = | ||
reindex(@nospecialize(V), idxs::Tuple{AbstractMatrix, Vararg{Any}}, subidxs::Tuple{Any, Any, Vararg{Any}}) = | ||
(@_propagate_inbounds_meta; (idxs[1][subidxs[1], subidxs[2]], reindex(V, tail(idxs), tail(tail(subidxs)))...)) | ||
|
||
# In general, we index N-dimensional parent arrays with N indices | ||
@generated function reindex(V, idxs::Tuple{AbstractArray{T,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {T,N} | ||
@generated function reindex(@nospecialize(V), idxs::Tuple{AbstractArray{T,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {T,N} | ||
if length(subidxs.parameters) >= N | ||
subs = [:(subidxs[$d]) for d in 1:N] | ||
tail = [:(subidxs[$d]) for d in N+1:length(subidxs.parameters)] | ||
|
@@ -302,11 +302,11 @@ IndexStyle(::Type{<:SubArray}) = IndexCartesian() | |
strides(V::SubArray) = substrides(V.parent, V.indices) | ||
|
||
substrides(parent, I::Tuple) = substrides(parent, strides(parent), I) | ||
substrides(parent, strds::Tuple{}, ::Tuple{}) = () | ||
substrides(parent, strds::NTuple{N,Int}, I::Tuple{ScalarIndex, Vararg{Any}}) where N = (substrides(parent, tail(strds), tail(I))...,) | ||
substrides(parent, strds::NTuple{N,Int}, I::Tuple{Slice, Vararg{Any}}) where N = (first(strds), substrides(parent, tail(strds), tail(I))...) | ||
substrides(parent, strds::NTuple{N,Int}, I::Tuple{AbstractRange, Vararg{Any}}) where N = (first(strds)*step(I[1]), substrides(parent, tail(strds), tail(I))...) | ||
substrides(parent, strds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("strides is invalid for SubArrays with indices of type $(typeof(I[1]))")) | ||
substrides(@nospecialize(parent), strds::Tuple{}, ::Tuple{}) = () | ||
substrides(@nospecialize(parent), strds::NTuple{N,Int}, I::Tuple{ScalarIndex, Vararg{Any}}) where N = (substrides(parent, tail(strds), tail(I))...,) | ||
substrides(@nospecialize(parent), strds::NTuple{N,Int}, I::Tuple{Slice, Vararg{Any}}) where N = (first(strds), substrides(parent, tail(strds), tail(I))...) | ||
substrides(@nospecialize(parent), strds::NTuple{N,Int}, I::Tuple{AbstractRange, Vararg{Any}}) where N = (first(strds)*step(I[1]), substrides(parent, tail(strds), tail(I))...) | ||
substrides(@nospecialize(parent), strds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("strides is invalid for SubArrays with indices of type $(typeof(I[1]))")) | ||
|
||
stride(V::SubArray, d::Integer) = d <= ndims(V) ? strides(V)[d] : strides(V)[end] * size(V)[end] | ||
|
||
|
@@ -395,9 +395,9 @@ end | |
# Since bounds-checking is performance-critical and uses | ||
# indices, it's worth optimizing these implementations thoroughly | ||
axes(S::SubArray) = (@_inline_meta; _indices_sub(S, S.indices...)) | ||
_indices_sub(S::SubArray) = () | ||
_indices_sub(S::SubArray, ::Real, I...) = (@_inline_meta; _indices_sub(S, I...)) | ||
function _indices_sub(S::SubArray, i1::AbstractArray, I...) | ||
_indices_sub(@nospecialize(S::SubArray)) = () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this argument can just be removed completely? I don't see it used anywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first argument to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's there in case anyone wants to extend this for another array type? CC @mbauman. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's just historical cruft in all these cases. I think when I was writing these methods I started out thinking I'd need it and then never culled things back down. |
||
_indices_sub(@nospecialize(S::SubArray), ::Real, I...) = (@_inline_meta; _indices_sub(S, I...)) | ||
function _indices_sub(@nospecialize(S::SubArray), i1::AbstractArray, I...) | ||
@_inline_meta | ||
(unsafe_indices(i1)..., _indices_sub(S, I...)...) | ||
end | ||
|
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.
I guess in this case we do use
V
to throw an error message — but it's an error message that should never occur because it should get caught at construction time. Edit: so I think it'd be just fine to throw a slightly less helpful error. Heck, the message even implores for a bug report which I've never seen.