Skip to content

Commit

Permalink
fix dense_dims for reshaped views of abstract vectors, cf. JuliaArray…
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Jun 2, 2021
1 parent fe4dc89 commit 03da363
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/stridelayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ function _reshaped_dense_dims(dense::D, ::True, ::Val{N}, ::Val{0}) where {D,N}
return nothing
end
end
function _reshaped_dense_dims(dense::Tuple{Static.False}, ::True, ::Val{N}, ::Val{0}) where {N}
return return ntuple(_ -> False(), Val{N}())
end

"""
known_strides(::Type{T}[, dim]) -> Tuple
Expand Down
10 changes: 7 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,6 @@ end
end

@testset "Reshaped views" begin
# See
# https://github.com/JuliaArrays/ArrayInterface.jl/issues/160
# https://github.com/JuliaArrays/ArrayInterface.jl/issues/157
u_base = randn(10, 10)
u_view = view(u_base, 3, :)
u_reshaped_view1 = reshape(u_view, 1, :)
Expand All @@ -724,10 +721,17 @@ end
@test @inferred(ArrayInterface.defines_strides(u_reshaped_view1))
@test @inferred(ArrayInterface.defines_strides(u_reshaped_view2))

# See https://github.com/JuliaArrays/ArrayInterface.jl/issues/160
@test @inferred(ArrayInterface.strides(u_base)) == (StaticInt(1), 10)
@test @inferred(ArrayInterface.strides(u_view)) == (10,)
@test @inferred(ArrayInterface.strides(u_reshaped_view1)) == (10, 10)
@test @inferred(ArrayInterface.strides(u_reshaped_view2)) == (10, 20)

# See https://github.com/JuliaArrays/ArrayInterface.jl/issues/157
@test @inferred(ArrayInterface.dense_dims(u_base)) == (True(), True())
@test @inferred(ArrayInterface.dense_dims(u_view)) == (False(),)
@test @inferred(ArrayInterface.dense_dims(u_reshaped_view1)) == (False(), False())
@test @inferred(ArrayInterface.dense_dims(u_reshaped_view2)) == (False(), False())
end

@test ArrayInterface.can_avx(ArrayInterface.can_avx) == false
Expand Down

0 comments on commit 03da363

Please sign in to comment.