From a1876b9535d0cbb674110aef83a6b96d239ceb0e Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Fri, 13 Nov 2020 16:49:26 +0000 Subject: [PATCH 1/2] layout_getindex now works with Fill --- Project.toml | 2 +- src/memorylayout.jl | 6 ++++++ test/test_layouts.jl | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 217aed0..dc29985 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ArrayLayouts" uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" authors = ["Sheehan Olver "] -version = "0.4.10" +version = "0.4.11" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/src/memorylayout.jl b/src/memorylayout.jl index 60a1e1a..a9678c7 100644 --- a/src/memorylayout.jl +++ b/src/memorylayout.jl @@ -530,7 +530,13 @@ sublayout(L::AbstractFillLayout, inds::Type) = L reshapedlayout(L::AbstractFillLayout, _) = L adjointlayout(::Type, L::AbstractFillLayout) = L transposelayout(L::AbstractFillLayout) = L +# TODO: Move to FillArrays.jl +_getindex_value(V::SubArray) = getindex_value(parent(V)) +_getindex_value(V) = getindex_value(V) +sub_materialize(::AbstractFillLayout, V, ax) = Fill(_getindex_value(V), ax) +sub_materialize(::ZerosLayout, V, ax) = Zeros(ax) +sub_materialize(::OnesLayout, V, ax) = Ones(ax) abstract type AbstractBandedLayout <: MemoryLayout end abstract type AbstractTridiagonalLayout <: AbstractBandedLayout end diff --git a/test/test_layouts.jl b/test/test_layouts.jl index 2b88627..8e76e11 100644 --- a/test/test_layouts.jl +++ b/test/test_layouts.jl @@ -294,6 +294,10 @@ struct FooNumber <: Number end @test MemoryLayout(Fill(1+0im,10)') == DualLayout{FillLayout}() @test MemoryLayout(Adjoint(Fill(1+0im,10,2))) == FillLayout() @test MemoryLayout(Transpose(Fill(1+0im,10,2))) == FillLayout() + + @test layout_getindex(Fill(1,10), 1:3) ≡ Fill(1,3) + @test layout_getindex(Ones(1,10), 1, 1:3) ≡ Ones(3) + @test layout_getindex(Zeros(5,10,12), 1, 1:3,4:6) ≡ Zeros(3,3) end @testset "Triangular col/rowsupport" begin From 5e71f8aa74a4df3db3a898e21fdb0cba0bcf5e90 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Fri, 13 Nov 2020 21:31:56 +0000 Subject: [PATCH 2/2] Update memorylayout.jl --- src/memorylayout.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/memorylayout.jl b/src/memorylayout.jl index a9678c7..0638e48 100644 --- a/src/memorylayout.jl +++ b/src/memorylayout.jl @@ -532,7 +532,6 @@ adjointlayout(::Type, L::AbstractFillLayout) = L transposelayout(L::AbstractFillLayout) = L # TODO: Move to FillArrays.jl _getindex_value(V::SubArray) = getindex_value(parent(V)) -_getindex_value(V) = getindex_value(V) sub_materialize(::AbstractFillLayout, V, ax) = Fill(_getindex_value(V), ax) sub_materialize(::ZerosLayout, V, ax) = Zeros(ax)