ArrayInterface.jl icon indicating copy to clipboard operation
ArrayInterface.jl copied to clipboard

Some reshapes of subarrays are strided, but `StrideIndex` fails.

Open chriselrod opened this issue 3 years ago • 2 comments

julia> ix = 2;

julia> A = rand(7, 5, 6);

julia> src = view(view(A,ix, :, :),:);

julia> ArrayInterface.StrideIndex(src)
ERROR: TypeError: in typeassert, expected Tuple{Int64}, got a value of type Nothing
Stacktrace:
 [1] (ArrayInterface.StrideIndex{1, nothing, nothing})(s::Tuple{StaticInt{1}}, o::Tuple{StaticInt{1}})
   @ ArrayInterface ~/.julia/dev/ArrayInterface/src/array_index.jl:197
 [2] (ArrayInterface.StrideIndex{1, nothing, nothing})(a::SubArray{Float64, 1, Base.ReshapedArray{Float64, 1, SubArray{Float64, 2, Array{Float64, 3}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, Tuple{}}, Tuple{Base.Slice{Base.OneTo{Int64}}}, true})
   @ ArrayInterface ~/.julia/dev/ArrayInterface/src/array_index.jl:200
 [3] ArrayInterface.StrideIndex(a::SubArray{Float64, 1, Base.ReshapedArray{Float64, 1, SubArray{Float64, 2, Array{Float64, 3}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, Tuple{}}, Tuple{Base.Slice{Base.OneTo{Int64}}}, true})
   @ ArrayInterface ~/.julia/dev/ArrayInterface/src/array_index.jl:203
 [4] top-level scope
   @ REPL[25]:1

julia> ArrayInterface.StrideIndex(vec(view(A,ix,:,:)))
ERROR: TypeError: in typeassert, expected Tuple{Int64}, got a value of type Nothing
Stacktrace:
 [1] (ArrayInterface.StrideIndex{1, nothing, nothing})(s::Tuple{StaticInt{1}}, o::Tuple{StaticInt{1}})
   @ ArrayInterface ~/.julia/dev/ArrayInterface/src/array_index.jl:197
 [2] (ArrayInterface.StrideIndex{1, nothing, nothing})(a::Base.ReshapedArray{Float64, 1, SubArray{Float64, 2, Array{Float64, 3}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, Tuple{}})
   @ ArrayInterface ~/.julia/dev/ArrayInterface/src/array_index.jl:200
 [3] ArrayInterface.StrideIndex(a::Base.ReshapedArray{Float64, 1, SubArray{Float64, 2, Array{Float64, 3}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, Tuple{}})
   @ ArrayInterface ~/.julia/dev/ArrayInterface/src/array_index.jl:203
 [4] top-level scope
   @ REPL[26]:1

Basically, if collapsed dims are dense with respect to one another, collapsing them presevers strided-ness.

We should also redefine dense dims as necessary to be a statement only about that dim.

julia> ArrayInterface.dense_dims(view(A,ix,:,:))
(static(false), static(false))

So that the first dim is not dense, but the second one still is w/ respect to the first.

chriselrod avatar Nov 17 '21 18:11 chriselrod

Would fix: https://github.com/JuliaSIMD/LoopVectorization.jl/issues/365

chriselrod avatar Nov 17 '21 19:11 chriselrod

So could we solve this by just fixing dense_dims?

Tokazama avatar Nov 20 '21 02:11 Tokazama