Skip to content

Commit ae44b98

Browse files
stevengjdkarrasch
andauthored
bugfix for dot of Hermitian{noncommutative} (#52333)
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
1 parent cc95725 commit ae44b98

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/symmetric.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ function triu(A::Symmetric, k::Integer=0)
453453
end
454454
end
455455

456-
for (T, trans, real) in [(:Symmetric, :transpose, :identity), (:Hermitian, :adjoint, :real)]
456+
for (T, trans, real) in [(:Symmetric, :transpose, :identity), (:(Hermitian{<:Union{Real,Complex}}), :adjoint, :real)]
457457
@eval begin
458458
function dot(A::$T, B::$T)
459459
n = size(A, 2)

test/symmetric.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ module TestSymmetric
44

55
using Test, LinearAlgebra, Random
66

7+
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
8+
9+
isdefined(Main, :Quaternions) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Quaternions.jl"))
10+
using .Main.Quaternions
11+
712
Random.seed!(1010)
813

914
@testset "Pauli σ-matrices: " for σ in map(Hermitian,
@@ -462,6 +467,17 @@ end
462467
end
463468
end
464469

470+
# bug identified in PR #52318: dot products of quaternionic Hermitian matrices,
471+
# or any number type where conj(a)*conj(b) ≠ conj(a*b):
472+
@testset "dot Hermitian quaternion #52318" begin
473+
A, B = [Quaternion.(randn(3,3), randn(3, 3), randn(3, 3), randn(3,3)) |> t -> t + t' for i in 1:2]
474+
@test A == Hermitian(A) && B == Hermitian(B)
475+
@test dot(A, B) dot(Hermitian(A), Hermitian(B))
476+
A, B = [Quaternion.(randn(3,3), randn(3, 3), randn(3, 3), randn(3,3)) |> t -> t + transpose(t) for i in 1:2]
477+
@test A == Symmetric(A) && B == Symmetric(B)
478+
@test dot(A, B) dot(Symmetric(A), Symmetric(B))
479+
end
480+
465481
#Issue #7647: test xsyevr, xheevr, xstevr drivers.
466482
@testset "Eigenvalues in interval for $(typeof(Mi7647))" for Mi7647 in
467483
(Symmetric(diagm(0 => 1.0:3.0)),

0 commit comments

Comments
 (0)