@@ -178,65 +178,95 @@ def test_add(rng, dtype):
178178
179179@parametrize_dtypes
180180def test_csf_format (dtype ):
181+ format = sparse .levels .get_storage_format (
182+ levels = (
183+ sparse .levels .Level (sparse .levels .LevelFormat .Dense ),
184+ sparse .levels .Level (sparse .levels .LevelFormat .Compressed ),
185+ sparse .levels .Level (sparse .levels .LevelFormat .Compressed ),
186+ ),
187+ order = "C" ,
188+ pos_width = 64 ,
189+ crd_width = 64 ,
190+ dtype = sparse .asdtype (dtype ),
191+ owns_memory = False ,
192+ )
193+
181194 SHAPE = (2 , 2 , 4 )
182195 pos_1 , crd_1 , pos_2 , crd_2 , data = get_exampe_csf_arrays (dtype )
183- csf = [ pos_1 , crd_1 , pos_2 , crd_2 , data ]
196+ constituent_arrays = ( pos_1 , crd_1 , pos_2 , crd_2 , data )
184197
185- csf_tensor = sparse .asarray ( csf , shape = SHAPE , dtype = sparse . asdtype ( dtype ), format = "csf" )
186- result = csf_tensor . to_scipy_sparse ()
187- for actual , expected in zip (result , csf , strict = False ):
198+ csf_array = sparse .from_constituent_arrays ( format = format , arrays = constituent_arrays , shape = SHAPE )
199+ result_arrays = csf_array . get_constituent_arrays ()
200+ for actual , expected in zip (result_arrays , constituent_arrays , strict = True ):
188201 np .testing .assert_array_equal (actual , expected )
189202
190- res_tensor = sparse .add (csf_tensor , csf_tensor ). to_scipy_sparse ()
191- csf_2 = [ pos_1 , crd_1 , pos_2 , crd_2 , data * 2 ]
192- for actual , expected in zip (res_tensor , csf_2 , strict = False ):
203+ res_arrays = sparse .add (csf_array , csf_array ). get_constituent_arrays ()
204+ expected_arrays = ( pos_1 , crd_1 , pos_2 , crd_2 , data * 2 )
205+ for actual , expected in zip (res_arrays , expected_arrays , strict = True ):
193206 np .testing .assert_array_equal (actual , expected )
194207
195208
196209@parametrize_dtypes
197210def test_coo_3d_format (dtype ):
211+ format = sparse .levels .get_storage_format (
212+ levels = (
213+ sparse .levels .Level (sparse .levels .LevelFormat .Compressed , sparse .levels .LevelProperties .NonUnique ),
214+ sparse .levels .Level (sparse .levels .LevelFormat .Singleton , sparse .levels .LevelProperties .NonUnique ),
215+ sparse .levels .Level (sparse .levels .LevelFormat .Singleton , sparse .levels .LevelProperties .NonUnique ),
216+ ),
217+ order = "C" ,
218+ pos_width = 64 ,
219+ crd_width = 64 ,
220+ dtype = sparse .asdtype (dtype ),
221+ owns_memory = False ,
222+ )
223+
198224 SHAPE = (2 , 2 , 4 )
199225 pos = np .array ([0 , 7 ])
200226 crd = np .array ([[0 , 1 , 0 , 0 , 1 , 1 , 0 ], [1 , 3 , 1 , 0 , 0 , 1 , 0 ], [3 , 1 , 1 , 0 , 1 , 1 , 1 ]])
201227 data = np .array ([1 , 2 , 3 , 4 , 5 , 6 , 7 ], dtype = dtype )
202- coo = [ pos , crd , data ]
228+ carrs = ( pos , crd , data )
203229
204- coo_tensor = sparse .asarray ( coo , shape = SHAPE , dtype = sparse . asdtype ( dtype ), format = "coo" )
205- result = coo_tensor . to_scipy_sparse ()
206- for actual , expected in zip (result , coo , strict = False ):
230+ coo_array = sparse .from_constituent_arrays ( format = format , arrays = carrs , shape = SHAPE )
231+ result = coo_array . get_constituent_arrays ()
232+ for actual , expected in zip (result , carrs , strict = True ):
207233 np .testing .assert_array_equal (actual , expected )
208234
209235 # NOTE: Blocked by https://github.com/llvm/llvm-project/pull/109135
210- # res_tensor = sparse.add(coo_tensor, coo_tensor).to_scipy_sparse ()
211- # coo_2 = [ pos, crd, data * 2]
212- # for actual, expected in zip(res_tensor, coo_2 , strict=False):
236+ # res_arrays = sparse.add(coo_array, coo_array).get_constituent_arrays ()
237+ # res_expected = ( pos, crd, data * 2)
238+ # for actual, expected in zip(res_arrays, res_expected , strict=False):
213239 # np.testing.assert_array_equal(actual, expected)
214240
215241
216242@parametrize_dtypes
217243def test_sparse_vector_format (dtype ):
244+ format = sparse .levels .get_storage_format (
245+ levels = (sparse .levels .Level (sparse .levels .LevelFormat .Compressed ),),
246+ order = "C" ,
247+ pos_width = 64 ,
248+ crd_width = 64 ,
249+ dtype = sparse .asdtype (dtype ),
250+ owns_memory = False ,
251+ )
252+
218253 SHAPE = (10 ,)
219254 pos = np .array ([0 , 6 ])
220255 crd = np .array ([0 , 1 , 2 , 6 , 8 , 9 ])
221256 data = np .array ([1 , 2 , 3 , 4 , 5 , 6 ], dtype = dtype )
222- sparse_vector = [ pos , crd , data ]
257+ carrs = ( pos , crd , data )
223258
224- sv_tensor = sparse .asarray (
225- sparse_vector ,
226- shape = SHAPE ,
227- dtype = sparse .asdtype (dtype ),
228- format = "sparse_vector" ,
229- )
230- result = sv_tensor .to_scipy_sparse ()
231- for actual , expected in zip (result , sparse_vector , strict = False ):
259+ sv_array = sparse .from_constituent_arrays (format = format , arrays = carrs , shape = SHAPE )
260+ result = sv_array .get_constituent_arrays ()
261+ for actual , expected in zip (result , carrs , strict = True ):
232262 np .testing .assert_array_equal (actual , expected )
233263
234- res_tensor = sparse .add (sv_tensor , sv_tensor ). to_scipy_sparse ()
235- sparse_vector_2 = [ pos , crd , data * 2 ]
236- for actual , expected in zip (res_tensor , sparse_vector_2 , strict = False ):
264+ res_arrs = sparse .add (sv_array , sv_array ). get_constituent_arrays ()
265+ sv2_expected = ( pos , crd , data * 2 )
266+ for actual , expected in zip (res_arrs , sv2_expected , strict = True ):
237267 np .testing .assert_array_equal (actual , expected )
238268
239269 dense = np .array ([1 , 2 , 3 , 0 , 0 , 0 , 4 , 0 , 5 , 6 ], dtype = dtype )
240- dense_tensor = sparse .asarray (dense )
241- res_tensor = sparse .add (dense_tensor , sv_tensor ). to_scipy_sparse ( )
242- np .testing .assert_array_equal (res_tensor , dense * 2 )
270+ dense_array = sparse .asarray (dense )
271+ res = sparse .to_numpy ( sparse . add (dense_array , sv_array ) )
272+ np .testing .assert_array_equal (res , dense * 2 )
0 commit comments