@@ -4,15 +4,20 @@ using JLArrays: JLArray, @allowscalar
44using  SparseArraysBase: 
55  SparseArraysBase,
66  SparseArrayDOK,
7+   SparseMatrixDOK,
78  eachstoredindex,
89  getstoredindex,
910  getunstoredindex,
1011  isstored,
1112  setstoredindex!,
1213  setunstoredindex!,
14+   sparse,
15+   sparserand,
16+   sparsezeros,
1317  storedlength,
1418  storedpairs,
1519  storedvalues
20+ using  StableRNGs:  StableRNG
1621using  Test:  @test , @testset 
1722
1823elts =  (Float32, Float64, Complex{Float32}, Complex{Float64})
@@ -216,4 +221,53 @@ arrayts = (Array,)
216221  @test  storedlength (r1) ==  2 
217222  @test  a ==  [11  12 ; 12  22 ]
218223  @test  storedlength (a) ==  4 
224+ 
225+   d =  Dict ([CartesianIndex (1 , 2 ) =>  elt (12 ), CartesianIndex (2 , 1 ) =>  elt (21 )])
226+   for  a in  (
227+     sparse (d, 2 , 2 ),
228+     sparse (d, 2 , 2 ; getunstored= Returns (zero (elt))),
229+     sparse (d, (2 , 2 )),
230+     sparse (d, (2 , 2 ); getunstored= Returns (zero (elt))),
231+   )
232+     @test  ! iszero (a)
233+     @test  iszero (a[1 , 1 ])
234+     @test  a[2 , 1 ] ==  elt (21 )
235+     @test  a[1 , 2 ] ==  elt (12 )
236+     @test  iszero (a[2 , 2 ])
237+     @test  size (a) ==  (2 , 2 )
238+     @test  storedlength (a) ==  2 
239+     @test  eltype (a) ===  elt
240+     @test  a isa  SparseMatrixDOK{elt}
241+   end 
242+ 
243+   for  (a, elt′) in  (
244+     (sparsezeros (elt, 2 , 2 ), elt),
245+     (sparsezeros (elt, 2 , 2 ; getunstored= Returns (zero (elt))), elt),
246+     (sparsezeros (elt, (2 , 2 )), elt),
247+     (sparsezeros (elt, (2 , 2 ); getunstored= Returns (zero (elt))), elt),
248+     (sparsezeros (2 , 2 ), Float64),
249+     (sparsezeros (2 , 2 ; getunstored= Returns (zero (Float64))), Float64),
250+     (sparsezeros ((2 , 2 )), Float64),
251+     (sparsezeros ((2 , 2 ); getunstored= Returns (zero (Float64))), Float64),
252+   )
253+     @test  iszero (a)
254+     @test  size (a) ==  (2 , 2 )
255+     @test  storedlength (a) ==  0 
256+     @test  eltype (a) ===  elt′
257+     @test  a isa  SparseMatrixDOK{elt′}
258+   end 
259+ 
260+   rng =  StableRNG (123 )
261+   for  (a, elt′) in  (
262+     (sparserand (rng, elt, 20 , 20 ; density= 0.5 ), elt),
263+     (sparserand (rng, elt, (20 , 20 ); density= 0.5 ), elt),
264+     (sparserand (rng, 20 , 20 ; density= 0.5 ), Float64),
265+     (sparserand (rng, (20 , 20 ); density= 0.5 ), Float64),
266+   )
267+     @test  ! iszero (a)
268+     @test  size (a) ==  (20 , 20 )
269+     @test  ! iszero (storedlength (a))
270+     @test  eltype (a) ===  elt′
271+     @test  a isa  SparseMatrixDOK{elt′}
272+   end 
219273end 
0 commit comments