Skip to content

Commit

Permalink
Adjoint/transpose for OneElementMatrix preserves type (#258)
Browse files Browse the repository at this point in the history
* Adjoint/transpose for OneElementMatrix preserves type

* tests for vector adjoint/transpose
  • Loading branch information
jishnub authored Jun 13, 2023
1 parent 2a56fbd commit 39234a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/oneelement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,8 @@ end
function mul!(C::AbstractMatrix, A::AbstractFillMatrix, B::OneElementMatrix, alpha::Number, beta::Number)
_mulonel!(C, A, B, alpha, beta)
end

# adjoint/transpose

adjoint(A::OneElementMatrix) = OneElement(adjoint(A.val), reverse(A.ind), reverse(A.axes))
transpose(A::OneElementMatrix) = OneElement(transpose(A.val), reverse(A.ind), reverse(A.axes))
22 changes: 22 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,28 @@ end
@test Base.setindex(Zeros(5,3), 2, 2, 3) OneElement(2.0, (2,3), (5,3))
@test_throws BoundsError Base.setindex(Zeros(5), 2, 6)

@testset "adjoint/transpose" begin
A = OneElement(3im, (2,4), (4,6))
@test A' === OneElement(-3im, (4,2), (6,4))
@test transpose(A) === OneElement(3im, (4,2), (6,4))

A = OneElement(3im, 2, 3)
@test A' isa Adjoint
@test transpose(A) isa Transpose
@test A' == OneElement(-3im, (1,2), (1,3))
@test transpose(A) == OneElement(3im, (1,2), (1,3))

A = OneElement(3, (2,2), (4,4))
@test adjoint(A) === A
@test transpose(A) === A

A = OneElement(3, 2, 4)
@test transpose(A) isa Transpose
@test adjoint(A) isa Adjoint
@test transpose(A) == OneElement(3, (1,2), (1,4))
@test adjoint(A) == OneElement(3, (1,2), (1,4))
end

@testset "matmul" begin
A = reshape(Float64[1:9;], 3, 3)
testinds(w::AbstractArray) = testinds(size(w))
Expand Down

2 comments on commit 39234a3

@jishnub
Copy link
Member Author

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/85569

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.2.0 -m "<description of version>" 39234a3ee3ac346ec66a2e659842ae8b336f447d
git push origin v1.2.0

Please sign in to comment.