@@ -6,7 +6,7 @@ debug = false
6
6
using Test, LinearAlgebra, Random
7
7
using LinearAlgebra: BlasFloat, errorbounds, full!, transpose!,
8
8
UnitUpperTriangular, UnitLowerTriangular,
9
- mul!, rdiv!, rmul!, lmul!
9
+ mul!, rdiv!, rmul!, lmul!, BandIndex
10
10
11
11
const BASE_TEST_PATH = joinpath (Sys. BINDIR, " .." , " share" , " julia" , " test" )
12
12
@@ -1228,4 +1228,31 @@ end
1228
1228
end
1229
1229
end
1230
1230
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
+
1231
1258
end # module TestTriangular
0 commit comments