Skip to content

Commit 446cfe9

Browse files
committed
Add tests
1 parent b55338e commit 446cfe9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

stdlib/LinearAlgebra/test/diagonal.jl

+8
Original file line numberDiff line numberDiff line change
@@ -1235,4 +1235,12 @@ end
12351235
end
12361236
end
12371237

1238+
@testset "avoid matmul ambiguities with ::MyMatrix * ::AbstractMatrix" begin
1239+
A = [i+j for i in 1:2, j in 1:2]
1240+
S = SizedArrays.SizedArray{(2,2)}(A)
1241+
D = Diagonal([1:2;])
1242+
@test S * D == A * D
1243+
@test D * S == D * A
1244+
end
1245+
12381246
end # module TestDiagonal

stdlib/LinearAlgebra/test/triangular.jl

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ using LinearAlgebra: BlasFloat, errorbounds, full!, transpose!,
88
UnitUpperTriangular, UnitLowerTriangular,
99
mul!, rdiv!, rmul!, lmul!
1010

11+
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
12+
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
13+
using .Main.SizedArrays
14+
1115
debug && println("Triangular matrices")
1216

1317
n = 9
@@ -866,4 +870,12 @@ end
866870
end
867871
end
868872

873+
@testset "avoid matmul ambiguities with ::MyMatrix * ::AbstractMatrix" begin
874+
A = [i+j for i in 1:2, j in 1:2]
875+
S = SizedArrays.SizedArray{(2,2)}(A)
876+
U = UpperTriangular(ones(2,2))
877+
@test S * U == A * U
878+
@test U * S == U * A
879+
end
880+
869881
end # module TestTriangular

test/testhelpers/SizedArrays.jl

+5
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ function *(S1::SizedArrayLike, S2::SizedArrayLike)
4646
SZ = ndims(data) == 1 ? (size(S1, 1), ) : (size(S1, 1), size(S2, 2))
4747
SizedArray{SZ}(data)
4848
end
49+
50+
# deliberately wide method defintion to ensure that this doesn't lead to ambiguities with
51+
# structured matrices
52+
*(S1::SizedArrayLike, M::AbstractMatrix) = _data(S1) * M
53+
4954
end

0 commit comments

Comments
 (0)