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_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_equality(): mtx = ss.random(100, 100, format="csr") arr = assparsearray(mtx) assert np.all(arr == arr.copy()) is np.bool_(True) # assert np.all(mtx == arr) # TODO assert np.all(arr == mtx)
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