Skip to content

Commit 3dc5550

Browse files
committed
Add tests
1 parent 1c6f53c commit 3dc5550

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

stdlib/LinearAlgebra/test/triangular.jl

+28-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ debug = false
66
using Test, LinearAlgebra, Random
77
using LinearAlgebra: BlasFloat, errorbounds, full!, transpose!,
88
UnitUpperTriangular, UnitLowerTriangular,
9-
mul!, rdiv!, rmul!, lmul!
9+
mul!, rdiv!, rmul!, lmul!, BandIndex
1010

1111
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
1212

@@ -1228,4 +1228,31 @@ end
12281228
end
12291229
end
12301230

1231+
@testset "indexing with a BandIndex" begin
1232+
# these tests should succeed even if the linear index along
1233+
# the band isn't a constant, or type-inferred at all
1234+
M = rand(Int,2,2)
1235+
f(A,j, v::Val{n}) where {n} = Val(A[BandIndex(n,j)])
1236+
function common_tests(M, ind)
1237+
j = ind[]
1238+
@test @inferred(f(UpperTriangular(M), j, Val(-1))) == Val(0)
1239+
@test @inferred(f(UnitUpperTriangular(M), j, Val(-1))) == Val(0)
1240+
@test @inferred(f(UnitUpperTriangular(M), j, Val(0))) == Val(1)
1241+
@test @inferred(f(LowerTriangular(M), j, Val(1))) == Val(0)
1242+
@test @inferred(f(UnitLowerTriangular(M), j, Val(1))) == Val(0)
1243+
@test @inferred(f(UnitLowerTriangular(M), j, Val(0))) == Val(1)
1244+
end
1245+
common_tests(M, Any[1])
1246+
1247+
M = Diagonal(Int[1,2])
1248+
common_tests(M, Any[1])
1249+
# extra tests for banded structure of the parent
1250+
for T in (UpperTriangular, UnitUpperTriangular)
1251+
@test @inferred(f(T(M), 1, Val(1))) == Val(0)
1252+
end
1253+
for T in (LowerTriangular, UnitLowerTriangular)
1254+
@test @inferred(f(T(M), 1, Val(-1))) == Val(0)
1255+
end
1256+
end
1257+
12311258
end # module TestTriangular

0 commit comments

Comments
 (0)