Skip to content

Commit eeb0b69

Browse files
authored
Fix typos in 2x2 matmatmul (#50362)
1 parent 0e8af1c commit eeb0b69

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

stdlib/LinearAlgebra/src/matmul.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,18 +1008,18 @@ function matmul2x2!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMat
10081008
# TODO making these lazy could improve perf
10091009
B11 = copy(B[1,1]'); B12 = copy(B[2,1]')
10101010
B21 = copy(B[1,2]'); B22 = copy(B[2,2]')
1011-
elseif tA == 'S'
1012-
B11 = symmetric(A[1,1], :U); B12 = A[1,2]
1013-
B21 = copy(transpose(A[1,2])); B22 = symmetric(A[2,2], :U)
1014-
elseif tA == 's'
1015-
B11 = symmetric(A[1,1], :L); B12 = copy(transpose(A[2,1]))
1016-
B21 = A[2,1]; B22 = symmetric(A[2,2], :L)
1017-
elseif tA == 'H'
1018-
B11 = hermitian(A[1,1], :U); B12 = A[1,2]
1019-
B21 = copy(adjoint(A[1,2])); B22 = hermitian(A[2,2], :U)
1020-
else # if tA == 'h'
1021-
B11 = hermitian(A[1,1], :L); B12 = copy(adjoint(A[2,1]))
1022-
B21 = A[2,1]; B22 = hermitian(A[2,2], :L)
1011+
elseif tB == 'S'
1012+
B11 = symmetric(B[1,1], :U); B12 = B[1,2]
1013+
B21 = copy(transpose(B[1,2])); B22 = symmetric(B[2,2], :U)
1014+
elseif tB == 's'
1015+
B11 = symmetric(B[1,1], :L); B12 = copy(transpose(B[2,1]))
1016+
B21 = B[2,1]; B22 = symmetric(B[2,2], :L)
1017+
elseif tB == 'H'
1018+
B11 = hermitian(B[1,1], :U); B12 = B[1,2]
1019+
B21 = copy(adjoint(B[1,2])); B22 = hermitian(B[2,2], :U)
1020+
else # if tB == 'h'
1021+
B11 = hermitian(B[1,1], :L); B12 = copy(adjoint(B[2,1]))
1022+
B21 = B[2,1]; B22 = hermitian(B[2,2], :L)
10231023
end
10241024
_modify!(_add, A11*B11 + A12*B21, C, (1,1))
10251025
_modify!(_add, A11*B12 + A12*B22, C, (1,2))

stdlib/LinearAlgebra/test/matmul.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ module TestMatmul
44

55
using Base: rtoldefault
66
using Test, LinearAlgebra, Random
7-
using LinearAlgebra: mul!
7+
using LinearAlgebra: mul!, Symmetric, Hermitian
88

99
## Test Julia fallbacks to BLAS routines
1010

11+
mul_wrappers = [
12+
m -> m,
13+
m -> Symmetric(m, :U),
14+
m -> Symmetric(m, :L),
15+
m -> Hermitian(m, :U),
16+
m -> Hermitian(m, :L),
17+
m -> adjoint(m),
18+
m -> transpose(m)]
19+
1120
@testset "matrices with zero dimensions" begin
1221
for (dimsA, dimsB, dimsC) in (
1322
((0, 5), (5, 3), (0, 3)),
@@ -42,6 +51,9 @@ end
4251
@test *(adjoint(Ai), adjoint(Bi)) == [-28.25-66im 9.75-58im; -26-89im 21-73im]
4352
@test_throws DimensionMismatch [1 2; 0 0; 0 0] * [1 2]
4453
end
54+
for wrapper_a in mul_wrappers, wrapper_b in mul_wrappers
55+
@test wrapper_a(AA) * wrapper_b(BB) == Array(wrapper_a(AA)) * Array(wrapper_b(BB))
56+
end
4557
@test_throws DimensionMismatch mul!(Matrix{Float64}(undef, 3, 3), AA, BB)
4658
end
4759
@testset "3x3 matmul" begin
@@ -62,6 +74,9 @@ end
6274
@test *(adjoint(Ai), adjoint(Bi)) == [1+2im 20.75+9im -44.75+42im; 19.5+17.5im -54-36.5im 51-14.5im; 13+7.5im 11.25+31.5im -43.25-14.5im]
6375
@test_throws DimensionMismatch [1 2 3; 0 0 0; 0 0 0] * [1 2 3]
6476
end
77+
for wrapper_a in mul_wrappers, wrapper_b in mul_wrappers
78+
@test wrapper_a(AA) * wrapper_b(BB) == Array(wrapper_a(AA)) * Array(wrapper_b(BB))
79+
end
6580
@test_throws DimensionMismatch mul!(Matrix{Float64}(undef, 4, 4), AA, BB)
6681
end
6782

0 commit comments

Comments
 (0)