-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
stack
errors when inner or outer array uses custom indices
#48736
Comments
As this functionality was seemingly designed mostly for OffsetArrays.jl: Lines 839 to 844 in ce292c1
it should be noted that this does not produce an error when OffsetArrays.jl is loaded and it's type pirated methods are available. julia> using OffsetArrays
julia> stack(A2)
4×3×2 OffsetArray(::Array{Float64, 3}, 1:4, 1:3, 1:2) with eltype Float64 with indices 1:4×1:3×1:2:
[:, :, 1] =
0.488586 -1.93562 -0.225797
-0.307972 -1.7415 0.316024
0.0702133 1.00626 1.00785
-0.72046 -0.679983 0.00612942
[:, :, 2] =
-1.59223 0.291592 1.48481
-1.87154 -0.727295 0.378543
-1.08153 1.35971 1.63377
0.819348 -0.132509 -1.36885
julia> stack(A3)
4×3×2 OffsetArray(::Array{Float64, 3}, 1:4, 1:3, 1:2) with eltype Float64 with indices 1:4×1:3×1:2:
[:, :, 1] =
-1.13547 0.695512 -0.0426222
0.296079 1.85618 -0.247409
-0.879178 -0.417559 -0.447225
-0.791633 0.283552 -0.221949
[:, :, 2] =
-0.76631 0.116022 1.31183
-1.00218 2.7132 0.148179
0.0976066 0.551973 -1.16329
-0.966548 0.382295 0.341279 Meaning e.g. DimensionalData.jl tests on |
With the above MyArray type, julia> let x = MyArrayType.MyArray([1,2,3])
similar(x, Int, axes(x)..., axes([4,5])...) # dispatches to Base's mix-of-ranges-and-Int method
end
ERROR: MethodError: no method matching similar(::Main.MyArrayType.MyArray{Int64, 1}, ::Type{Int64}, ::Tuple{Base.Slice{Main.MyArrayType.URange{Int64}}, Int64})
Stacktrace:
[1] similar(::Main.MyArrayType.MyArray{Int64, 1}, ::Type{Int64}, ::Base.Slice{Main.MyArrayType.URange{Int64}}, ::Base.OneTo{Int64})
@ Base ./abstractarray.jl:838
[2] top-level scope
@ REPL[4]:2
julia> using OffsetArrays # this supplies the missing method, so exactly the same code now runs:
julia> let x = MyArrayType.MyArray([1,2,3])
similar(x, Int, axes(x)..., axes([4,5])...)
end
3×2 OffsetArray(::Matrix{Int64}, 1:3, 1:2) with eltype Int64 with indices 1:3×1:2:
5648757792 0
0 5648757760
4780822496 0 If you want Adding ever more methods to |
When arrays that use custom index types as suggested in the docs are passed to
stack
, everything works if the wrapped array uses the same custom index type. However, if the inner and outer arrays have different index types, an error is raised on this line:julia/base/abstractarray.jl
Line 2792 in ce292c1
This calls the following
similar
fallback, which replacesBase.OneTo
axes withInt
s, creating a mixture ofInt
s and custom indices for which nosimilar
method is defined:julia/base/abstractarray.jl
Lines 839 to 844 in ce292c1
(it seems that following the instructions in the comment would both be type-piracy and create ambiguities)
Here's an minimal example where we define a custom array type that uses custom indices as defined in CustomUnitRanges.jl and then call
stack
on these arrays:The text was updated successfully, but these errors were encountered: