-
Notifications
You must be signed in to change notification settings - Fork 44
rework OffsetArrays constructor #148
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
Changes from all commits
67977d8
07f9b3c
9166dfc
622c487
5a804c9
88061ad
ffebce9
b88fb74
6469a8c
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
### Low-level utilities ### | ||
|
||
_indexoffset(r::AbstractRange) = first(r) - 1 | ||
_indexoffset(i::Integer) = 0 | ||
_indexoffset(i::Colon) = 0 | ||
_indexlength(r::AbstractRange) = length(r) | ||
_indexlength(i::Integer) = i | ||
_indexlength(i::Colon) = Colon() | ||
|
||
_offset(axparent::AbstractUnitRange, ax::AbstractUnitRange) = first(ax) - first(axparent) | ||
_offset(axparent::AbstractUnitRange, ax::CartesianIndices) = _offset(axparent, first(ax.indices)) | ||
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'm not sure I understand the justification here, and the fact that it's flagged by codecov is interesting. 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. Given that I still leave it here for potential future usage. |
||
_offset(axparent::AbstractUnitRange, ax::Integer) = 1 - first(axparent) | ||
|
||
_uncolonindices(A::AbstractArray{<:Any,N}, inds::NTuple{N,Any}) where {N} = _uncolonindices(axes(A), inds) | ||
_uncolonindices(ax::Tuple, inds::Tuple) = (first(inds), _uncolonindices(tail(ax), tail(inds))...) | ||
_uncolonindices(ax::Tuple, inds::Tuple{Colon, Vararg{Any}}) = (first(ax), _uncolonindices(tail(ax), tail(inds))...) | ||
_uncolonindices(::Tuple{}, ::Tuple{}) = () | ||
|
||
_expandCartesianIndices(inds::Tuple{<:CartesianIndices, Vararg{Any}}) = (convert(Tuple{Vararg{AbstractUnitRange{Int}}}, inds[1])..., _expandCartesianIndices(Base.tail(inds))...) | ||
_expandCartesianIndices(inds::Tuple{Any,Vararg{Any}}) = (inds[1], _expandCartesianIndices(Base.tail(inds))...) | ||
_expandCartesianIndices(::Tuple{}) = () |
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.
For reference,
Personally I like the DimensionMismatch better. If this were to get fixed in Julia I'd suggest deferring to that error, but since it's not good now and won't be fixable on earlier releases, this seem like the right choice.