Skip to content

Commit fda9321

Browse files
araujomsdkarrasch
andauthored
stdlib: make dot product of Hermitian matrices real (#52318)
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
1 parent 12c5d2d commit fda9321

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

stdlib/LinearAlgebra/src/symmetric.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,17 @@ for (T, trans, real) in [(:Symmetric, :transpose, :identity), (:(Hermitian{<:Uni
461461
throw(DimensionMismatch("A has dimensions $(size(A)) but B has dimensions $(size(B))"))
462462
end
463463

464-
dotprod = zero(dot(first(A), first(B)))
464+
dotprod = $real(zero(dot(first(A), first(B))))
465465
@inbounds if A.uplo == 'U' && B.uplo == 'U'
466466
for j in 1:n
467467
for i in 1:(j - 1)
468468
dotprod += 2 * $real(dot(A.data[i, j], B.data[i, j]))
469469
end
470-
dotprod += dot(A[j, j], B[j, j])
470+
dotprod += $real(dot(A[j, j], B[j, j]))
471471
end
472472
elseif A.uplo == 'L' && B.uplo == 'L'
473473
for j in 1:n
474-
dotprod += dot(A[j, j], B[j, j])
474+
dotprod += $real(dot(A[j, j], B[j, j]))
475475
for i in (j + 1):n
476476
dotprod += 2 * $real(dot(A.data[i, j], B.data[i, j]))
477477
end
@@ -481,11 +481,11 @@ for (T, trans, real) in [(:Symmetric, :transpose, :identity), (:(Hermitian{<:Uni
481481
for i in 1:(j - 1)
482482
dotprod += 2 * $real(dot(A.data[i, j], $trans(B.data[j, i])))
483483
end
484-
dotprod += dot(A[j, j], B[j, j])
484+
dotprod += $real(dot(A[j, j], B[j, j]))
485485
end
486486
else
487487
for j in 1:n
488-
dotprod += dot(A[j, j], B[j, j])
488+
dotprod += $real(dot(A[j, j], B[j, j]))
489489
for i in (j + 1):n
490490
dotprod += 2 * $real(dot(A.data[i, j], $trans(B.data[j, i])))
491491
end

0 commit comments

Comments
 (0)