Skip to content

Commit

Permalink
spezialized conj of Transpose/Adjoint (#33609)
Browse files Browse the repository at this point in the history
* specialized conj for Adjoint/Transpose

* add tests

* implement @dkarrasch's suggestions

* add test case where M' != Adjoint(M)
  • Loading branch information
simeonschaub authored and andreasnoack committed Oct 28, 2019
1 parent df8c52a commit 54b212c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,7 @@ pinv(v::TransposeAbsVec, tol::Real = 0) = pinv(conj(v.parent)).parent
/(u::TransposeAbsVec, A::AbstractMatrix) = transpose(transpose(A) \ u.parent)
/(u::AdjointAbsVec, A::Transpose{<:Any,<:AbstractMatrix}) = adjoint(conj(A.parent) \ u.parent) # technically should be adjoint(copy(adjoint(copy(A))) \ u.parent)
/(u::TransposeAbsVec, A::Adjoint{<:Any,<:AbstractMatrix}) = transpose(conj(A.parent) \ u.parent) # technically should be transpose(copy(transpose(copy(A))) \ u.parent)

## complex conjugate
conj(A::Transpose) = adjoint(A.parent)
conj(A::Adjoint) = transpose(A.parent)
21 changes: 21 additions & 0 deletions stdlib/LinearAlgebra/test/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,25 @@ using .Main.OffsetArrays
@test_throws BoundsError s[1, 4]
end

@testset "specialized conj of Adjoint/Transpose" begin
realmat = [1 2; 3 4]
complexmat = ComplexF64[1+im 2; 3 4-im]
nested = [[complexmat] [-complexmat]; [0complexmat] [3complexmat]]
@testset "AdjOrTrans{...,$(typeof(i))}" for i in (
realmat, vec(realmat),
complexmat, vec(complexmat),
nested, vec(nested),
)
for (t,type) in ((transpose, Adjoint), (adjoint, Transpose))
M = t(i)
@test conj(M) isa type
@test conj(M) == conj(collect(M))
@test conj(conj(M)) === M
end
end
# test if `conj(transpose(::Hermitian))` is a no-op
hermitian = Hermitian([1 2+im; 2-im 3])
@test conj(transpose(hermitian)) === hermitian
end

end # module TestAdjointTranspose

0 comments on commit 54b212c

Please sign in to comment.