From b2b07c131c11864beb5b7b1714e5b755e11b06f1 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 14:39:50 +0530 Subject: [PATCH 1/4] Use axes function instead of field access --- src/fillalgebra.jl | 6 +++--- src/fillbroadcast.jl | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 5a5897ef..2bd46e2e 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -8,11 +8,11 @@ vec(a::AbstractFill) = fillsimilar(a, length(a)) transpose(a::Union{AbstractOnesMatrix, AbstractZerosMatrix}) = fillsimilar(a, reverse(axes(a))) adjoint(a::Union{AbstractOnesMatrix, AbstractZerosMatrix}) = fillsimilar(a, reverse(axes(a))) -transpose(a::FillMatrix{T}) where T = Fill{T}(transpose(a.value), reverse(a.axes)) -adjoint(a::FillMatrix{T}) where T = Fill{T}(adjoint(a.value), reverse(a.axes)) +transpose(a::FillMatrix{T}) where T = Fill{T}(transpose(a.value), reverse(axes(a))) +adjoint(a::FillMatrix{T}) where T = Fill{T}(adjoint(a.value), reverse(axes(a))) permutedims(a::AbstractFillVector) = fillsimilar(a, (1, length(a))) -permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(a.axes)) +permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(axes(a))) function permutedims(B::AbstractFill, perm) dimsB = size(B) diff --git a/src/fillbroadcast.jl b/src/fillbroadcast.jl index b2cb0755..d286418a 100644 --- a/src/fillbroadcast.jl +++ b/src/fillbroadcast.jl @@ -85,10 +85,10 @@ broadcasted(::DefaultArrayStyle, ::typeof(+), r::AbstractOnes) = r broadcasted(::DefaultArrayStyle{N}, ::typeof(conj), r::AbstractZeros{T,N}) where {T,N} = r broadcasted(::DefaultArrayStyle{N}, ::typeof(conj), r::AbstractOnes{T,N}) where {T,N} = r -broadcasted(::DefaultArrayStyle{N}, ::typeof(real), r::AbstractZeros{T,N}) where {T,N} = Zeros{real(T)}(r.axes) -broadcasted(::DefaultArrayStyle{N}, ::typeof(real), r::AbstractOnes{T,N}) where {T,N} = Ones{real(T)}(r.axes) -broadcasted(::DefaultArrayStyle{N}, ::typeof(imag), r::AbstractZeros{T,N}) where {T,N} = Zeros{real(T)}(r.axes) -broadcasted(::DefaultArrayStyle{N}, ::typeof(imag), r::AbstractOnes{T,N}) where {T,N} = Zeros{real(T)}(r.axes) +broadcasted(::DefaultArrayStyle{N}, ::typeof(real), r::AbstractZeros{T,N}) where {T,N} = Zeros{real(T)}(axes(r)) +broadcasted(::DefaultArrayStyle{N}, ::typeof(real), r::AbstractOnes{T,N}) where {T,N} = Ones{real(T)}(axes(r)) +broadcasted(::DefaultArrayStyle{N}, ::typeof(imag), r::AbstractZeros{T,N}) where {T,N} = Zeros{real(T)}(axes(r)) +broadcasted(::DefaultArrayStyle{N}, ::typeof(imag), r::AbstractOnes{T,N}) where {T,N} = Zeros{real(T)}(axes(r)) ### Binary broadcasting From cd4106e1ed9b9689f9c1ad3a22e8eb104d275b8b Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 14:42:13 +0530 Subject: [PATCH 2/4] Don't change for FillMatrix --- src/fillalgebra.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 2bd46e2e..9d67ea50 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -8,8 +8,8 @@ vec(a::AbstractFill) = fillsimilar(a, length(a)) transpose(a::Union{AbstractOnesMatrix, AbstractZerosMatrix}) = fillsimilar(a, reverse(axes(a))) adjoint(a::Union{AbstractOnesMatrix, AbstractZerosMatrix}) = fillsimilar(a, reverse(axes(a))) -transpose(a::FillMatrix{T}) where T = Fill{T}(transpose(a.value), reverse(axes(a))) -adjoint(a::FillMatrix{T}) where T = Fill{T}(adjoint(a.value), reverse(axes(a))) +transpose(a::FillMatrix{T}) where T = Fill{T}(transpose(a.value), reverse(a.axes)) +adjoint(a::FillMatrix{T}) where T = Fill{T}(adjoint(a.value), reverse(a.axes)) permutedims(a::AbstractFillVector) = fillsimilar(a, (1, length(a))) permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(axes(a))) From 2dfac1dbd115f521f6b123d2ce1673d006e6aa88 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 21:15:35 +0530 Subject: [PATCH 3/4] Add tests for custom structs --- test/runtests.jl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index d7a6aca1..f6d7f85c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1894,6 +1894,33 @@ end @test FillArrays.getindex_value(transpose(a)) == FillArrays.unique_value(transpose(a)) == 2.0 + im @test convert(Fill, transpose(a)) ≡ Fill(2.0+im,1,5) end + + @testst "custom AbstractFill types" begin + # implicit axes + struct StaticZerosVec{L,T} <: FillArrays.AbstractZeros{T,1,Tuple{SOneTo{L}}} end + Base.size(::StaticZerosVec{L}) where {L} = (L,) + Base.axes(::StaticZerosVec{L}) where {L} = (SOneTo(L),) + S = StaticZerosVec{3,Int}() + @test real.(S) == S + @test imag.(S) == S + + struct StaticOnesVec{L,T} <: FillArrays.AbstractOnes{T,1,Tuple{SOneTo{L}}} end + Base.size(::StaticOnesVec{L}) where {L} = (L,) + Base.axes(::StaticOnesVec{L}) where {L} = (SOneTo(L),) + S = StaticOnesVec{3,Int}() + @test real.(S) == S + @test imag.(S) == zero(S) + + struct StaticFill{S1,S2,T} <: FillArrays.AbstractFill{T,2,Tuple{SOneTo{S1},SOneTo{S2}}} + x :: T + end + StaticFill{S1,S2}(x::T) where {S1,S2,T} = StaticFill{S1,S2,T}(x) + Base.size(::StaticFill{S1,S2}) where {S1,S2} = (S1,S2) + Base.axes(::StaticFill{S1,S2}) where {S1,S2} = (SOneTo(S1), SOneTo(S2)) + FillArrays.getindex_value(S::StaticFill) = S.x + S = StaticFill{2,3}(2) + @test permutedims(S) == Fill(2, reverse(size(S))) + end end @testset "Statistics" begin From edd35561abef5492c82b3e1e32c264e1eac6d1d8 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 21:15:45 +0530 Subject: [PATCH 4/4] Typo --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index f6d7f85c..00bfe14f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1895,7 +1895,7 @@ end @test convert(Fill, transpose(a)) ≡ Fill(2.0+im,1,5) end - @testst "custom AbstractFill types" begin + @testset "custom AbstractFill types" begin # implicit axes struct StaticZerosVec{L,T} <: FillArrays.AbstractZeros{T,1,Tuple{SOneTo{L}}} end Base.size(::StaticZerosVec{L}) where {L} = (L,)