@@ -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,16 +63,19 @@ 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
78
+
72
79
# isstored SubArray
73
80
a′ = SparseArrayDOK {elt} (undef, 4 , 4 )
74
81
a′[2 , 3 ] = 23
@@ -83,12 +90,21 @@ arrayts = (Array,)
83
90
end
84
91
end
85
92
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
+
86
100
a = SparseArrayDOK {elt} (undef, 3 , 3 , 3 )
87
101
a[1 , 2 , 3 ] = 123
88
102
b = permutedims (a, (2 , 3 , 1 ))
89
103
@test b isa SparseArrayDOK{elt,3 }
90
104
@test b[2 , 3 , 1 ] == 123
91
105
@test storedlength (b) == 1
106
+ @test b[1 ] == 0
107
+ @test b[LinearIndices (b)[2 , 3 , 1 ]] == 123
92
108
93
109
a = SparseArrayDOK {elt} (undef, 2 , 2 )
94
110
a[1 , 2 ] = 12
0 commit comments