From 03da363cd56c32bf4c65b9724e4a5d699551c109 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Wed, 2 Jun 2021 13:24:25 +0200 Subject: [PATCH] fix dense_dims for reshaped views of abstract vectors, cf. #157 --- src/stridelayout.jl | 3 +++ test/runtests.jl | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/stridelayout.jl b/src/stridelayout.jl index 64f6c4c82..2a5e4e167 100644 --- a/src/stridelayout.jl +++ b/src/stridelayout.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 0b169996d..b6ec9b148 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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, :) @@ -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