Skip to content

Commit

Permalink
Fix recursive adjoint/transpose (#322)
Browse files Browse the repository at this point in the history
* fix recursive adjoint/transpose

* Bump version to v1.9.2
  • Loading branch information
jishnub authored Dec 5, 2023
1 parent 6c3d030 commit cf8c78d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
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

2 comments on commit cf8c78d

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96572

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.9.2 -m "<description of version>" cf8c78d3d184ffa175442b0df1d89754d3dcfaa3
git push origin v1.9.2

Please sign in to comment.