Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib: make dot product of Hermitian matrices real #52318

Merged
merged 6 commits into from
Feb 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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