Skip to content

Commit

Permalink
Fix typos in 2x2 matmatmul (#50362)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Jun 30, 2023
1 parent 0e8af1c commit eeb0b69
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
24 changes: 12 additions & 12 deletions stdlib/LinearAlgebra/src/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1008,18 +1008,18 @@ function matmul2x2!(C::AbstractMatrix, tA, tB, A::AbstractMatrix, B::AbstractMat
# TODO making these lazy could improve perf
B11 = copy(B[1,1]'); B12 = copy(B[2,1]')
B21 = copy(B[1,2]'); B22 = copy(B[2,2]')
elseif tA == 'S'
B11 = symmetric(A[1,1], :U); B12 = A[1,2]
B21 = copy(transpose(A[1,2])); B22 = symmetric(A[2,2], :U)
elseif tA == 's'
B11 = symmetric(A[1,1], :L); B12 = copy(transpose(A[2,1]))
B21 = A[2,1]; B22 = symmetric(A[2,2], :L)
elseif tA == 'H'
B11 = hermitian(A[1,1], :U); B12 = A[1,2]
B21 = copy(adjoint(A[1,2])); B22 = hermitian(A[2,2], :U)
else # if tA == 'h'
B11 = hermitian(A[1,1], :L); B12 = copy(adjoint(A[2,1]))
B21 = A[2,1]; B22 = hermitian(A[2,2], :L)
elseif tB == 'S'
B11 = symmetric(B[1,1], :U); B12 = B[1,2]
B21 = copy(transpose(B[1,2])); B22 = symmetric(B[2,2], :U)
elseif tB == 's'
B11 = symmetric(B[1,1], :L); B12 = copy(transpose(B[2,1]))
B21 = B[2,1]; B22 = symmetric(B[2,2], :L)
elseif tB == 'H'
B11 = hermitian(B[1,1], :U); B12 = B[1,2]
B21 = copy(adjoint(B[1,2])); B22 = hermitian(B[2,2], :U)
else # if tB == 'h'
B11 = hermitian(B[1,1], :L); B12 = copy(adjoint(B[2,1]))
B21 = B[2,1]; B22 = hermitian(B[2,2], :L)
end
_modify!(_add, A11*B11 + A12*B21, C, (1,1))
_modify!(_add, A11*B12 + A12*B22, C, (1,2))
Expand Down
17 changes: 16 additions & 1 deletion stdlib/LinearAlgebra/test/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ module TestMatmul

using Base: rtoldefault
using Test, LinearAlgebra, Random
using LinearAlgebra: mul!
using LinearAlgebra: mul!, Symmetric, Hermitian

## Test Julia fallbacks to BLAS routines

mul_wrappers = [
m -> m,
m -> Symmetric(m, :U),
m -> Symmetric(m, :L),
m -> Hermitian(m, :U),
m -> Hermitian(m, :L),
m -> adjoint(m),
m -> transpose(m)]

@testset "matrices with zero dimensions" begin
for (dimsA, dimsB, dimsC) in (
((0, 5), (5, 3), (0, 3)),
Expand Down Expand Up @@ -42,6 +51,9 @@ end
@test *(adjoint(Ai), adjoint(Bi)) == [-28.25-66im 9.75-58im; -26-89im 21-73im]
@test_throws DimensionMismatch [1 2; 0 0; 0 0] * [1 2]
end
for wrapper_a in mul_wrappers, wrapper_b in mul_wrappers
@test wrapper_a(AA) * wrapper_b(BB) == Array(wrapper_a(AA)) * Array(wrapper_b(BB))
end
@test_throws DimensionMismatch mul!(Matrix{Float64}(undef, 3, 3), AA, BB)
end
@testset "3x3 matmul" begin
Expand All @@ -62,6 +74,9 @@ end
@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]
@test_throws DimensionMismatch [1 2 3; 0 0 0; 0 0 0] * [1 2 3]
end
for wrapper_a in mul_wrappers, wrapper_b in mul_wrappers
@test wrapper_a(AA) * wrapper_b(BB) == Array(wrapper_a(AA)) * Array(wrapper_b(BB))
end
@test_throws DimensionMismatch mul!(Matrix{Float64}(undef, 4, 4), AA, BB)
end

Expand Down

0 comments on commit eeb0b69

Please sign in to comment.