Skip to content

Commit

Permalink
stdlib: make dot product of Hermitian matrices real (#52318)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Karrasch <[email protected]>
  • Loading branch information
araujoms and dkarrasch authored Feb 3, 2024
1 parent 12c5d2d commit fda9321
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,17 @@ for (T, trans, real) in [(:Symmetric, :transpose, :identity), (:(Hermitian{<:Uni
throw(DimensionMismatch("A has dimensions $(size(A)) but B has dimensions $(size(B))"))
end

dotprod = zero(dot(first(A), first(B)))
dotprod = $real(zero(dot(first(A), first(B))))
@inbounds if A.uplo == 'U' && B.uplo == 'U'
for j in 1:n
for i in 1:(j - 1)
dotprod += 2 * $real(dot(A.data[i, j], B.data[i, j]))
end
dotprod += dot(A[j, j], B[j, j])
dotprod += $real(dot(A[j, j], B[j, j]))
end
elseif A.uplo == 'L' && B.uplo == 'L'
for j in 1:n
dotprod += dot(A[j, j], B[j, j])
dotprod += $real(dot(A[j, j], B[j, j]))
for i in (j + 1):n
dotprod += 2 * $real(dot(A.data[i, j], B.data[i, j]))
end
Expand All @@ -481,11 +481,11 @@ for (T, trans, real) in [(:Symmetric, :transpose, :identity), (:(Hermitian{<:Uni
for i in 1:(j - 1)
dotprod += 2 * $real(dot(A.data[i, j], $trans(B.data[j, i])))
end
dotprod += dot(A[j, j], B[j, j])
dotprod += $real(dot(A[j, j], B[j, j]))
end
else
for j in 1:n
dotprod += dot(A[j, j], B[j, j])
dotprod += $real(dot(A[j, j], B[j, j]))
for i in (j + 1):n
dotprod += 2 * $real(dot(A.data[i, j], $trans(B.data[j, i])))
end
Expand Down

0 comments on commit fda9321

Please sign in to comment.