@@ -1926,3 +1926,33 @@ def test_xH_x():
19261926 assert_eq (Ysp .conj ().T @ Y , Y .conj ().T @ Y )
19271927 assert_eq (Ysp .conj ().T @ Ysp , Y .conj ().T @ Y )
19281928 assert_eq (Y .conj ().T @ Ysp .conj ().T , Y .conj ().T @ Y .conj ().T )
1929+
1930+
1931+ def test_repeat_invalid_input ():
1932+ a = np .eye (3 )
1933+ with pytest .raises (TypeError , match = "`a` must be a SparseArray" ):
1934+ sparse .repeat (a , repeats = 2 )
1935+ with pytest .raises (ValueError , match = "`repeats` must be an integer" ):
1936+ sparse .repeat (COO .from_numpy (a ), repeats = [2 , 2 , 2 ])
1937+
1938+
1939+ @pytest .mark .parametrize ("ndim" , range (1 , 5 ))
1940+ @pytest .mark .parametrize ("repeats" , [1 , 2 , 3 ])
1941+ def test_repeat (ndim , repeats ):
1942+ rng = np .random .default_rng ()
1943+ shape = tuple (rng .integers (1 , 4 ) for _ in range (ndim ))
1944+ a = rng .integers (1 , 10 , size = shape )
1945+ sparse_a = COO .from_numpy (a )
1946+ for axis in [* range (- ndim , ndim ), None ]:
1947+ expected = np .repeat (a , repeats = repeats , axis = axis )
1948+ result_sparse = sparse .repeat (sparse_a , repeats = repeats , axis = axis )
1949+ actual = result_sparse .todense ()
1950+ assert actual .shape == expected .shape , f"Shape mismatch on axis { axis } : { actual .shape } vs { expected .shape } "
1951+ np .testing .assert_array_equal (actual , expected )
1952+
1953+ expected = np .repeat (a , repeats = repeats , axis = None )
1954+ result_sparse = sparse .repeat (sparse_a , repeats = repeats , axis = None )
1955+ actual = result_sparse .todense ()
1956+ print (f"Expected: { expected } , Actual: { actual } " )
1957+ assert actual .shape == expected .shape
1958+ np .testing .assert_array_equal (actual , expected )
0 commit comments