Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursive adjoint/transpose #322

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
15 changes: 11 additions & 4 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down