@@ -2318,6 +2318,93 @@ end
23182318 @test mul! (C, O, D, 2 , 2 ) == 2 * O * D .+ 2
23192319 end
23202320 end
2321+ @testset " array elements" begin
2322+ A = [SMatrix {2,3} (1 : 6 )* (i+ j) for i in 1 : 3 , j in 1 : 2 ]
2323+ @testset " StridedMatrix * OneElementMatrix" begin
2324+ B = OneElement (SMatrix {3,2} (1 : 6 ), (size (A,2 ),2 ), (size (A,2 ),4 ))
2325+ C = [SMatrix {2,2} (1 : 4 ) for i in axes (A,1 ), j in axes (B,2 )]
2326+ @test mul! (copy (C), A, B) == A * B
2327+ @test mul! (copy (C), A, B, 2 , 2 ) == 2 * A * B + 2 * C
2328+ end
2329+ @testset " StridedMatrix * OneElementVector" begin
2330+ B = OneElement (SMatrix {3,2} (1 : 6 ), (size (A,2 ),), (size (A,2 ),))
2331+ C = [SMatrix {2,2} (1 : 4 ) for i in axes (A,1 )]
2332+ @test mul! (copy (C), A, B) == A * B
2333+ @test mul! (copy (C), A, B, 2 , 2 ) == 2 * A * B + 2 * C
2334+ end
2335+
2336+ A = OneElement (SMatrix {3,2} (1 : 6 ), (3 ,2 ), (5 ,4 ))
2337+ @testset " OneElementMatrix * StridedMatrix" begin
2338+ B = [SMatrix {2,3} (1 : 6 )* (i+ j) for i in axes (A,2 ), j in 1 : 2 ]
2339+ C = [SMatrix {3,3} (1 : 9 ) for i in axes (A,1 ), j in axes (B,2 )]
2340+ @test mul! (copy (C), A, B) == A * B
2341+ @test mul! (copy (C), A, B, 2 , 2 ) == 2 * A * B + 2 * C
2342+ end
2343+ @testset " OneElementMatrix * StridedVector" begin
2344+ B = [SMatrix {2,3} (1 : 6 )* i for i in axes (A,2 )]
2345+ C = [SMatrix {3,3} (1 : 9 ) for i in axes (A,1 )]
2346+ @test mul! (copy (C), A, B) == A * B
2347+ @test mul! (copy (C), A, B, 2 , 2 ) == 2 * A * B + 2 * C
2348+ end
2349+ @testset " OneElementMatrix * OneElementMatrix" begin
2350+ B = OneElement (SMatrix {2,3} (1 : 6 ), (2 ,4 ), (size (A,2 ), 3 ))
2351+ C = [SMatrix {3,3} (1 : 9 ) for i in axes (A,1 ), j in axes (B,2 )]
2352+ @test mul! (copy (C), A, B) == A * B
2353+ @test mul! (copy (C), A, B, 2 , 2 ) == 2 * A * B + 2 * C
2354+ end
2355+ @testset " OneElementMatrix * OneElementVector" begin
2356+ B = OneElement (SMatrix {2,3} (1 : 6 ), 2 , size (A,2 ))
2357+ C = [SMatrix {3,3} (1 : 9 ) for i in axes (A,1 )]
2358+ @test mul! (copy (C), A, B) == A * B
2359+ @test mul! (copy (C), A, B, 2 , 2 ) == 2 * A * B + 2 * C
2360+ end
2361+ end
2362+ @testset " non-commutative" begin
2363+ A = OneElement (quat (rand (4 )... ), (2 ,3 ), (3 ,4 ))
2364+ for (B,C) in (
2365+ # OneElementMatrix * OneElementVector
2366+ (OneElement (quat (rand (4 )... ), 3 , size (A,2 )),
2367+ [quat (rand (4 )... ) for i in axes (A,1 )]),
2368+
2369+ # OneElementMatrix * OneElementMatrix
2370+ (OneElement (quat (rand (4 )... ), (3 ,2 ), (size (A,2 ), 4 )),
2371+ [quat (rand (4 )... ) for i in axes (A,1 ), j in 1 : 4 ]),
2372+ )
2373+ @test mul! (copy (C), A, B) ≈ A * B
2374+ α, β = quat (0 ,0 ,1 ,0 ), quat (1 ,0 ,1 ,0 )
2375+ @test mul! (copy (C), A, B, α, β) ≈ mul! (copy (C), A, Array (B), α, β) ≈ A * B * α + C * β
2376+ end
2377+
2378+ A = [quat (rand (4 )... )* (i+ j) for i in 1 : 2 , j in 1 : 3 ]
2379+ for (B,C) in (
2380+ # StridedMatrix * OneElementVector
2381+ (OneElement (quat (rand (4 )... ), 1 , size (A,2 )),
2382+ [quat (rand (4 )... ) for i in axes (A,1 )]),
2383+
2384+ # StridedMatrix * OneElementMatrix
2385+ (OneElement (quat (rand (4 )... ), (2 ,2 ), (size (A,2 ), 4 )),
2386+ [quat (rand (4 )... ) for i in axes (A,1 ), j in 1 : 4 ]),
2387+ )
2388+ @test mul! (copy (C), A, B) ≈ A * B
2389+ α, β = quat (0 ,0 ,1 ,0 ), quat (1 ,0 ,1 ,0 )
2390+ @test mul! (copy (C), A, B, α, β) ≈ mul! (copy (C), A, Array (B), α, β) ≈ A * B * α + C * β
2391+ end
2392+
2393+ A = OneElement (quat (rand (4 )... ), (2 ,2 ), (3 , 4 ))
2394+ for (B,C) in (
2395+ # OneElementMatrix * StridedMatrix
2396+ ([quat (rand (4 )... ) for i in axes (A,2 ), j in 1 : 3 ],
2397+ [quat (rand (4 )... ) for i in axes (A,1 ), j in 1 : 3 ]),
2398+
2399+ # OneElementMatrix * StridedVector
2400+ ([quat (rand (4 )... ) for i in axes (A,2 )],
2401+ [quat (rand (4 )... ) for i in axes (A,1 )]),
2402+ )
2403+ @test mul! (copy (C), A, B) ≈ A * B
2404+ α, β = quat (0 ,0 ,1 ,0 ), quat (1 ,0 ,1 ,0 )
2405+ @test mul! (copy (C), A, B, α, β) ≈ mul! (copy (C), A, Array (B), α, β) ≈ A * B * α + C * β
2406+ end
2407+ end
23212408 end
23222409
23232410 @testset " multiplication/division by a number" begin
0 commit comments