@@ -33,14 +33,18 @@ arrayts = (Array,)
3333 a[1 , 2 ] = 12
3434 @test a isa SparseArrayDOK{elt,2 }
3535 @test size (a) == (2 , 2 )
36+ @test a[1 ] == 0
3637 @test a[1 , 1 ] == 0
3738 @test a[1 , 1 , 1 ] == 0
39+ @test a[3 ] == 12
3840 @test a[1 , 2 ] == 12
3941 @test a[1 , 2 , 1 ] == 12
4042 @test storedlength (a) == 1
43+ @test_throws BoundsError a[5 ]
44+ @test_throws BoundsError a[1 , 3 ]
4145
4246 a = SparseArrayDOK {elt} (undef, 2 , 2 )
43- a[1 , 2 ] = 12
47+ a[3 ] = 12
4448 for b in (similar (a, Float32, (3 , 3 )), similar (a, Float32, Base. OneTo .((3 , 3 ))))
4549 @test b isa SparseArrayDOK{Float32,2 }
4650 @test b == zeros (Float32, 3 , 3 )
@@ -59,16 +63,19 @@ arrayts = (Array,)
5963 # isstored
6064 a = SparseArrayDOK {elt} (undef, 4 , 4 )
6165 a[2 , 3 ] = 23
62- for I in CartesianIndices (a)
66+ for (I, i) in zip ( CartesianIndices (a), LinearIndices (a) )
6367 if I == CartesianIndex (2 , 3 )
6468 @test isstored (a, I)
6569 @test isstored (a, Tuple (I)... )
70+ @test isstored (a, i)
6671 else
6772 @test ! isstored (a, I)
6873 @test ! isstored (a, Tuple (I)... )
74+ @test ! isstored (a, i)
6975 end
7076 end
7177
78+
7279 # isstored SubArray
7380 a′ = SparseArrayDOK {elt} (undef, 4 , 4 )
7481 a′[2 , 3 ] = 23
@@ -83,12 +90,21 @@ arrayts = (Array,)
8390 end
8491 end
8592
93+ # vector
94+ a = SparseArrayDOK {elt} (undef, 2 )
95+ a[2 ] = 12
96+ @test b[1 ] == 0
97+ @test a[2 ] == 12
98+ @test storedlength (a) == 1
99+
86100 a = SparseArrayDOK {elt} (undef, 3 , 3 , 3 )
87101 a[1 , 2 , 3 ] = 123
88102 b = permutedims (a, (2 , 3 , 1 ))
89103 @test b isa SparseArrayDOK{elt,3 }
90104 @test b[2 , 3 , 1 ] == 123
91105 @test storedlength (b) == 1
106+ @test b[1 ] == 0
107+ @test b[LinearIndices (b)[2 , 3 , 1 ]] == 123
92108
93109 a = SparseArrayDOK {elt} (undef, 2 , 2 )
94110 a[1 , 2 ] = 12
0 commit comments