1
1
using ArrayInterface, Test
2
+ using Base: setindex
2
3
import ArrayInterface: has_sparsestruct, findstructralnz
3
4
@test ArrayInterface. ismutable (rand (3 ))
4
5
@@ -71,4 +72,50 @@ BBB=BandedBlockBandedMatrix(dense, ([4, 4] ,[4, 4]), (1, 1), (1, 1))
71
72
rowind,colind= findstructralnz (BBB)
72
73
@test [BBB[rowind[i],colind[i]] for i in 1 : length (rowind)]==
73
74
[1 ,2 ,3 ,1 ,2 ,3 ,4 ,2 ,3 ,4 ,5 ,6 ,7 ,5 ,6 ,7 ,8 ,6 ,7 ,8 ,
74
- 1 ,2 ,3 ,1 ,2 ,3 ,4 ,2 ,3 ,4 ,5 ,6 ,7 ,5 ,6 ,7 ,8 ,6 ,7 ,8 ]
75
+ 1 ,2 ,3 ,1 ,2 ,3 ,4 ,2 ,3 ,4 ,5 ,6 ,7 ,5 ,6 ,7 ,8 ,6 ,7 ,8 ]
76
+
77
+ @testset " setindex" begin
78
+ @testset " $(typeof (x)) " for x in [
79
+ zeros (3 ),
80
+ falses (3 ),
81
+ spzeros (3 ),
82
+ ]
83
+ y = setindex (x, true , 1 )
84
+ @test iszero (x) # x is not mutated
85
+ @test y[1 ] == true
86
+ @test iszero (x[CartesianIndices (size (x)) .== [CartesianIndex (1 )]])
87
+
88
+ y2 = setindex (x, one .(x), :)
89
+ @test iszero (x)
90
+ @test all (isone, y2)
91
+ end
92
+
93
+ @testset " $(typeof (x)) " for x in [
94
+ zeros (3 , 3 ),
95
+ falses (3 , 3 ),
96
+ spzeros (3 , 3 ),
97
+ ]
98
+ y = setindex (x, true , 1 , 1 )
99
+ @test iszero (x) # x is not mutated
100
+ @test y[1 , 1 ] == true
101
+ @test iszero (x[CartesianIndices (size (x)) .== [CartesianIndex (1 , 1 )]])
102
+
103
+ y2 = setindex (x, one .(x), :, :)
104
+ @test iszero (x)
105
+ @test all (isone, y2)
106
+ end
107
+
108
+ @testset " $(typeof (x)) " for x in [
109
+ zeros (3 , 3 , 3 ),
110
+ falses (3 , 3 , 3 ),
111
+ ]
112
+ y = setindex (x, true , 1 , 1 , 1 )
113
+ @test iszero (x) # x is not mutated
114
+ @test y[1 , 1 , 1 ] == true
115
+ @test iszero (x[CartesianIndices (size (x)) .== [CartesianIndex (1 , 1 , 1 )]])
116
+
117
+ y2 = setindex (x, one .(x), :, :, :)
118
+ @test iszero (x)
119
+ @test all (isone, y2)
120
+ end
121
+ end
0 commit comments