@@ -33,14 +33,18 @@ arrayts = (Array,)
33
33
a[1 , 2 ] = 12
34
34
@test a isa SparseArrayDOK{elt,2 }
35
35
@test size (a) == (2 , 2 )
36
+ @test a[1 ] == 0
36
37
@test a[1 , 1 ] == 0
37
38
@test a[1 , 1 , 1 ] == 0
39
+ @test a[3 ] == 12
38
40
@test a[1 , 2 ] == 12
39
41
@test a[1 , 2 , 1 ] == 12
40
42
@test storedlength (a) == 1
43
+ @test_throws BoundsError a[5 ]
44
+ @test_throws BoundsError a[1 , 3 ]
41
45
42
46
a = SparseArrayDOK {elt} (undef, 2 , 2 )
43
- a[1 , 2 ] = 12
47
+ a[3 ] = 12
44
48
for b in (similar (a, Float32, (3 , 3 )), similar (a, Float32, Base. OneTo .((3 , 3 ))))
45
49
@test b isa SparseArrayDOK{Float32,2 }
46
50
@test b == zeros (Float32, 3 , 3 )
@@ -59,13 +63,15 @@ arrayts = (Array,)
59
63
# isstored
60
64
a = SparseArrayDOK {elt} (undef, 4 , 4 )
61
65
a[2 , 3 ] = 23
62
- for I in CartesianIndices (a)
66
+ for (I, i) in zip ( CartesianIndices (a), LinearIndices (a) )
63
67
if I == CartesianIndex (2 , 3 )
64
68
@test isstored (a, I)
65
69
@test isstored (a, Tuple (I)... )
70
+ @test isstored (a, i)
66
71
else
67
72
@test ! isstored (a, I)
68
73
@test ! isstored (a, Tuple (I)... )
74
+ @test ! isstored (a, i)
69
75
end
70
76
end
71
77
@@ -83,12 +89,21 @@ arrayts = (Array,)
83
89
end
84
90
end
85
91
92
+ # vector
93
+ a = SparseArrayDOK {elt} (undef, 2 )
94
+ a[2 ] = 12
95
+ @test b[1 ] == 0
96
+ @test a[2 ] == 12
97
+ @test storedlength (a) == 1
98
+
86
99
a = SparseArrayDOK {elt} (undef, 3 , 3 , 3 )
87
100
a[1 , 2 , 3 ] = 123
88
101
b = permutedims (a, (2 , 3 , 1 ))
89
102
@test b isa SparseArrayDOK{elt,3 }
90
103
@test b[2 , 3 , 1 ] == 123
91
104
@test storedlength (b) == 1
105
+ @test b[1 ] == 0
106
+ @test b[LinearIndices (b)[2 , 3 , 1 ]] == 123
92
107
93
108
a = SparseArrayDOK {elt} (undef, 2 , 2 )
94
109
a[1 , 2 ] = 12
0 commit comments