-
Notifications
You must be signed in to change notification settings - Fork 37
Fix getindex
with additional inds
#312
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #312 +/- ##
==========================================
+ Coverage 91.49% 91.79% +0.29%
==========================================
Files 9 9
Lines 1399 1413 +14
==========================================
+ Hits 1280 1297 +17
+ Misses 119 116 -3
Continue to review full report at Codecov.
|
Reshape to get the right sized output? |
Thanks for your suggestion @ChrisRackauckas, but I found that the main reason of the problem is that the additional ArrayInterface.jl/src/indexing.jl Lines 381 to 387 in d9b5089
But if I defined to_index(::LinearIndices{0,Tuple{}}, ::Colon) = Slice(static(1):static(1))
to_index(::CartesianIndices{0,Tuple{}}, ::Colon) = Slice(static(1):static(1)) the julia> ArrayInterface.getindex(CartesianIndices((3, 3)), 1, 1, 1)
CartesianIndex(1, 1, 1)
julia> Base.getindex(CartesianIndices((3, 3)), 1, 1, 1)
CartesianIndex(1, 1)
julia> ArrayInterface.getindex(CartesianIndices((3, 3)), 1, :)
1×3 CartesianIndices{2, Tuple{ArrayInterface.OptionallyStaticUnitRange{StaticInt{1}, Int64}, Base.OneTo{Int64}}} with indices 1:1:1×Base.OneTo(3):
CartesianIndex(1, 1) CartesianIndex(1, 2) CartesianIndex(1, 3)
julia> Base.getindex(CartesianIndices((3, 3)), 1, :)
3-element Vector{CartesianIndex{2}}:
CartesianIndex(1, 1)
CartesianIndex(1, 2)
CartesianIndex(1, 3) I'm not sure if it is designed in purpose or not? |
There is a commit 4334830 which make |
A lot of this was designed with the goal to avoid allocating new arrays whenever possible, but there's been a lot of work over the years on improving |
I revert to construct a Besides, construct with |
What we really need is our own |
@wangl-cc , it looks like all tests are passing and the changes seem reasonable to me. There's certainly more we can do related to this but that may be a lot for a single PR. Let me know if you're comfortable with the state of this PR and I can merge it. I'd of course be happy to review more |
I may not have enough time on this PR this week, so merge this PR now is okay for me. If it's possible, I can do more related works on this weekend, maybe a new PR? @Tokazama |
Only works after `JuliaArrays/ArrayInterface.jl#312`, which is not released currently, update compat is required after the release. BREAKING: `FunctionIndices.to_index` now accept different args now.
Cuurently,
getindex(A, inds...)
withinds
whose length is larger thanndims(A)
will cause a error, but it is allowed forBase.getindex
:The reason is
to_axes
only workslength(inds) == ndims(A)
currently,This PR fixes it with
_maybe_first
and_maybe_tail
.However, the behavior for
CartesianIndices
is different, which works currently but ignores additional indsHow can I fix it or ignore it?