def test_indexing(matrix_type, idx): a = assparsearray( matrix_type(sparse.random(50, 100, format="csr", density=0.4))) true_result = a.value.toarray()[idx] curr_result = a[idx] np.testing.assert_array_equal(asnparray(curr_result), true_result)
def test_union(matrix_type, matrix_type2): a = matrix_type(sparse.random(1000, 1000, density=0.2, dtype=bool)) b = matrix_type2(sparse.random(1000, 1000, density=0.2, dtype=bool)) truth = a + b test = op_union_indices(njit(lambda x, y: x | y), a, b) assert (truth != test).sum() == 0 a = matrix_type(sparse.random(1000, 1000, density=0.2)) b = matrix_type2(sparse.random(1000, 1000, density=0.2)) truth = a + b test = op_union_indices(njit(lambda x, y: x + y), a, b) assert (truth != test).sum() == 0
def test_symdifference(matrix_type, matrix_type2): a = np.random.randint(2, size=(100, 100), dtype=bool) b = np.random.randint(2, size=(100, 100), dtype=bool) truth = a ^ b test = symdifference_indices(matrix_type(a), matrix_type2(b)) assert (truth != test).sum() == 0
def test_difference(matrix_type, matrix_type2): a = matrix_type(sparse.random(1000, 1000, density=0.2, dtype=bool)) b = matrix_type2(sparse.random(1000, 1000, density=0.2, dtype=bool)) truth = a > b test = difference_indices(a, b) assert (truth != test).sum() == 0
def test_intersect(matrix_type, matrix_type2): a = matrix_type(sparse.random(1000, 1000, density=0.2)) b = matrix_type2(sparse.random(1000, 1000, density=0.2)) truth = a.multiply(b) test = op_intersect_indices(njit(lambda x, y: x * y), a, b) assert (truth != test).sum() == 0
def test_boolean_op(matrix_type, another_matrix_type, boolean_op, alternate_form): if boolean_op in SCIPYSPARSE_NOT_IMPLEMENTED and alternate_form == asspmatrix: pytest.skip("Not supported") sarr1 = assparsearray(matrix_type(ss.random(100, 100, dtype=bool))) sarr2 = assparsearray(another_matrix_type(ss.random(100, 100, dtype=bool))) alt1, alt2 = alternate_form(sarr1), alternate_form(sarr2) sarr_res = boolean_op(sarr1, sarr2) alt_res = boolean_op(alt1, alt2) assert not np.any(sarr_res != alt_res)
def test_matmul(matrix_type, another_matrix_type): mtx1 = matrix_type(ss.random(100, 100)) mtx2 = another_matrix_type(ss.random(100, 100)) arr1, arr2 = assparsearray(mtx1), assparsearray(mtx2) assert np.all(arr1 @ arr2 == mtx1 @ mtx2)
def test_divide_scalar(matrix_type): mtx = matrix_type(ss.random(100, 100)) arr = assparsearray(mtx) assert np.all(arr / 2 == mtx / 2)
def test_subtract(matrix_type, another_matrix_type): mtx1 = matrix_type(ss.random(100, 100)) mtx2 = another_matrix_type(ss.random(100, 100)) arr1, arr2 = assparsearray(mtx1), assparsearray(mtx2) assert np.all(arr1 - arr2 == mtx1 - mtx2)
def test_any(matrix_type): assert not np.any(assparsearray(matrix_type(np.zeros((100, 100))))) assert np.any(assparsearray(matrix_type(np.eye(100))))
def test_all(matrix_type): mtx = matrix_type(np.eye(100)) arr = assparsearray(mtx) assert not np.all(arr) assert np.all(assparsearray(matrix_type(np.ones((10, 10))))) is npTrue