Skip to content

Commit 902e8a7

Browse files
ranochaN5N3
andauthored
fix 5-arg mul! for vectors of vectors (#47665)
Co-authored-by: N5N3 <[email protected]>
1 parent ea23403 commit 902e8a7

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

stdlib/LinearAlgebra/src/matmul.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ function generic_matvecmul!(C::AbstractVector{R}, tA, A::AbstractVecOrMat, B::Ab
807807
end
808808
for k = 1:mB
809809
aoffs = (k-1)*Astride
810-
b = _add(B[k], false)
810+
b = _add(B[k])
811811
for i = 1:mA
812812
C[i] += A[aoffs + i] * b
813813
end

stdlib/LinearAlgebra/test/matmul.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,58 @@ end
156156
end
157157
end
158158

159+
@testset "generic_matvecmul for vectors of vectors" begin
160+
@testset "matrix of scalars" begin
161+
u = [[1, 2], [3, 4]]
162+
A = [1 2; 3 4]
163+
v = [[0, 0], [0, 0]]
164+
Au = [[7, 10], [15, 22]]
165+
@test A * u == Au
166+
mul!(v, A, u)
167+
@test v == Au
168+
mul!(v, A, u, 2, -1)
169+
@test v == Au
170+
end
171+
172+
@testset "matrix of matrices" begin
173+
u = [[1, 2], [3, 4]]
174+
A = Matrix{Matrix{Int}}(undef, 2, 2)
175+
A[1, 1] = [1 2; 3 4]
176+
A[1, 2] = [5 6; 7 8]
177+
A[2, 1] = [9 10; 11 12]
178+
A[2, 2] = [13 14; 15 16]
179+
v = [[0, 0], [0, 0]]
180+
Au = [[44, 64], [124, 144]]
181+
@test A * u == Au
182+
mul!(v, A, u)
183+
@test v == Au
184+
mul!(v, A, u, 2, -1)
185+
@test v == Au
186+
end
187+
end
188+
189+
@testset "generic_matmatmul for matrices of vectors" begin
190+
B = Matrix{Vector{Int}}(undef, 2, 2)
191+
B[1, 1] = [1, 2]
192+
B[2, 1] = [3, 4]
193+
B[1, 2] = [5, 6]
194+
B[2, 2] = [7, 8]
195+
A = [1 2; 3 4]
196+
C = Matrix{Vector{Int}}(undef, 2, 2)
197+
AB = Matrix{Vector{Int}}(undef, 2, 2)
198+
AB[1, 1] = [7, 10]
199+
AB[2, 1] = [15, 22]
200+
AB[1, 2] = [19, 22]
201+
AB[2, 2] = [43, 50]
202+
@test A * B == AB
203+
mul!(C, A, B)
204+
@test C == AB
205+
mul!(C, A, B, 2, -1)
206+
@test C == AB
207+
LinearAlgebra._generic_matmatmul!(C, 'N', 'N', A, B, LinearAlgebra.MulAddMul(2, -1))
208+
@test C == AB
209+
end
210+
159211
@testset "fallbacks & such for BlasFloats" begin
160212
AA = rand(Float64, 6, 6)
161213
BB = rand(Float64, 6, 6)

0 commit comments

Comments
 (0)