Skip to content

Commit 3f6b2b2

Browse files
andreasnoacktkelman
authored andcommitted
Define conj and conj! for for Symmetric and Hermitian. (#17827)
Fixes #17780
1 parent 35df9b8 commit 3f6b2b2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

base/linalg/symmetric.jl

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ end
114114
ctranspose(A::Hermitian) = A
115115
trace(A::Hermitian) = real(trace(A.data))
116116

117+
Base.conj(A::HermOrSym) = typeof(A)(conj(A.data), A.uplo)
118+
Base.conj!(A::HermOrSym) = typeof(A)(conj!(A.data), A.uplo)
119+
117120
#tril/triu
118121
function tril(A::Hermitian, k::Integer=0)
119122
if A.uplo == 'U' && k <= 0

test/linalg/symmetric.jl

+14
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,17 @@ let A = Symmetric(randn(5,5))
236236
B = -A
237237
@test A + B zeros(5,5)
238238
end
239+
240+
# 17780
241+
let a = randn(2,2)
242+
a = a'a
243+
b = complex(a,a)
244+
c = Symmetric(b)
245+
@test conj(c) == conj(Array(c))
246+
cc = copy(c)
247+
@test conj!(c) == conj(Array(cc))
248+
c = Hermitian(b + b')
249+
@test conj(c) == conj(Array(c))
250+
cc = copy(c)
251+
@test conj!(c) == conj(Array(c))
252+
end

0 commit comments

Comments
 (0)