From cf8c78d3d184ffa175442b0df1d89754d3dcfaa3 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 6 Dec 2023 04:24:22 +0530 Subject: [PATCH] Fix recursive adjoint/transpose (#322) * fix recursive adjoint/transpose * Bump version to v1.9.2 --- Project.toml | 2 +- src/fillalgebra.jl | 15 +++++++++++---- test/runtests.jl | 13 +++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 5365dbe7..b221840d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "1.9.1" +version = "1.9.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 5a5897ef..c849ac22 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -6,10 +6,17 @@ vec(a::AbstractFill) = fillsimilar(a, length(a)) # cannot do this for vectors since that would destroy scalar dot product -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)) +for OP in (:transpose, :adjoint) + @eval begin + function $OP(a::AbstractZerosMatrix) + v = getindex_value(a) + T = typeof($OP(v)) + Zeros{T}(reverse(axes(a))) + end + $OP(a::AbstractOnesMatrix) = fillsimilar(a, reverse(axes(a))) + $OP(a::FillMatrix) = Fill($OP(a.value), reverse(a.axes)) + end +end permutedims(a::AbstractFillVector) = fillsimilar(a, (1, length(a))) permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(a.axes)) diff --git a/test/runtests.jl b/test/runtests.jl index d7a6aca1..7ef4b1a8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1394,6 +1394,19 @@ end @test permutedims(Ones(2,4,5), [3,2,1]) ≡ Ones(5,4,2) @test permutedims(Zeros(2,4,5), [3,2,1]) ≡ Zeros(5,4,2) @test permutedims(Fill(2.0,2,4,5), [3,2,1]) ≡ Fill(2.0,5,4,2) + + @testset "recursive" begin + S = SMatrix{2,3}(1:6) + Z = Zeros(typeof(S), 2, 3) + Y = zeros(typeof(S), 2, 3) + @test Z' == Y' + @test transpose(Z) == transpose(Y) + + F = Fill(S, 2, 3) + G = fill(S, 2, 3) + @test F' == G' + @test transpose(F) == transpose(G) + end end @testset "reverse" begin