sparse.tests.test_base

Test functions for sparse matrices. Each class in the “Matrix class based tests” section become subclasses of the classes in the “Generic tests” section. This is done by the functions in the “Tailored base class for generic tests” section.

Module Contents

Functions

assert_in(member,collection,msg=None)
with_64bit_maxval_limit(maxval_limit=None,random=False,fixed_dtype=None,downcast_maxval=None,assert_32bit=False) Monkeypatch the maxval threshold at which scipy.sparse switches to
todense(a)
check_remains_sorted(X) Checks that sorted indices property is retained through an operation
_possibly_unimplemented(cls,require=True) Construct a class that either runs tests as usual (require=True),
sparse_test_class(getset=True,slicing=True,slicing_assign=True,fancy_indexing=True,fancy_assign=True,fancy_multidim_indexing=True,fancy_multidim_assign=True,minmax=True,nnz_axis=True) Construct a base class, optionally converting some of the tests in
_same_sum_duplicate(data,*inds,**kwargs) Duplicates entries to produce the same matrix
cases_64bit()
assert_in(member, collection, msg=None)
class _UFuncCheck
__array__()
__numpy_ufunc__(*a, **kwargs)
with_64bit_maxval_limit(maxval_limit=None, random=False, fixed_dtype=None, downcast_maxval=None, assert_32bit=False)

Monkeypatch the maxval threshold at which scipy.sparse switches to 64-bit index arrays, or make it (pseudo-)random.

todense(a)
class BinopTester
__add__(mat)
__mul__(mat)
__sub__(mat)
__radd__(mat)
__rmul__(mat)
__rsub__(mat)
__matmul__(mat)
__rmatmul__(mat)
class BinopTester_with_shape(shape)
__init__(shape)
shape()
ndim()
__add__(mat)
__mul__(mat)
__sub__(mat)
__radd__(mat)
__rmul__(mat)
__rsub__(mat)
__matmul__(mat)
__rmatmul__(mat)
class _TestCommon

test common functionality shared by all sparse formats

init_class()
test_bool()
test_bool_rollover()
test_eq()
test_ne()
test_lt()
test_gt()
test_le()
test_ge()
test_empty()
test_count_nonzero()
test_invalid_shapes()
test_repr()
test_str()
test_empty_arithmetic()
test_abs()
test_elementwise_power()
test_neg()
test_real()
test_imag()
test_diagonal()
test_setdiag_comprehensive()
test_setdiag()
test_nonzero()
test_numpy_nonzero()
test_getrow()
test_getcol()
test_sum()
test_sum_invalid_params()
test_sum_dtype()
test_sum_out()
test_numpy_sum()
test_mean()
test_mean_invalid_params()
test_mean_dtype()
test_mean_out()
test_numpy_mean()
test_expm()
test_inv()
test_from_array()
test_from_matrix()
test_from_list()
test_from_sparse()
test_todense()
test_toarray()
test_astype()
test_asfptype()
test_mul_scalar()
test_rmul_scalar()
test_add()
test_radd()
test_sub()
test_rsub()
test_add0()
test_elementwise_multiply()
test_elementwise_multiply_broadcast()
test_elementwise_divide()
test_pow()
test_rmatvec()
test_small_multiplication()
test_binop_custom_type()
test_binop_custom_type_with_shape()
test_matmul()
test_matvec()
test_matmat_sparse()
test_matmat_dense()
test_sparse_format_conversions()
test_tobsr()
test_transpose()
test_add_dense()
test_sub_dense()
test_maximum_minimum()
test_copy()
test_iterator()
test_size_zero_matrix_arithmetic()
test_size_zero_conversions()
test_pickle()
test_unary_ufunc_overrides()
test_binary_ufunc_overrides()
test_ufunc_object_array()
class _TestInplaceArithmetic
test_inplace_dense()
test_imul_scalar()
test_idiv_scalar()
test_inplace_success()
class _TestGetSet
test_getelement()
test_setelement()
test_negative_index_assignment()
test_scalar_assign_2()
test_index_scalar_assign()
class _TestSolve
test_solve()
class _TestSlicing
test_dtype_preservation()
test_get_horiz_slice()
test_get_vert_slice()
test_get_slices()
test_non_unit_stride_2d_indexing()
test_slicing_2()
test_slicing_3()
test_ellipsis_slicing()
test_multiple_ellipsis_slicing()
class _TestSlicingAssign
test_slice_scalar_assign()
test_slice_assign_2()
test_self_self_assignment()
test_slice_assignment()
test_sparsity_modifying_assignment()
test_set_slice()
class _TestFancyIndexing

Tests fancy indexing features. The tests for any matrix formats that implement these features should derive from this class.

test_bad_index()
test_fancy_indexing()
test_fancy_indexing_randomized()
test_fancy_indexing_boolean()
test_fancy_indexing_sparse_boolean()
test_fancy_indexing_regression_3087()
test_fancy_indexing_seq_assign()
test_fancy_indexing_empty()
check_remains_sorted(X)

Checks that sorted indices property is retained through an operation

class _TestFancyIndexingAssign
test_bad_index_assign()
test_fancy_indexing_set()
test_fancy_assignment_dtypes()
test_sequence_assignment()
test_fancy_assign_empty()
class _TestFancyMultidim
test_fancy_indexing_ndarray()
class _TestFancyMultidimAssign
test_fancy_assign_ndarray()
test_fancy_indexing_multidim_set()
test_fancy_assign_list()
test_fancy_assign_slice()
class _TestArithmetic

Test real/complex arithmetic

__arith_init()
test_add_sub()
test_mu()
class _TestMinMax
test_minmax()
test_minmax_axis()
test_minmax_invalid_params()
test_numpy_minmax()
test_argmax()
class _TestGetNnzAxis
test_getnnz_axis()
_possibly_unimplemented(cls, require=True)

Construct a class that either runs tests as usual (require=True), or each method skips if it encounters a common error.

sparse_test_class(getset=True, slicing=True, slicing_assign=True, fancy_indexing=True, fancy_assign=True, fancy_multidim_indexing=True, fancy_multidim_assign=True, minmax=True, nnz_axis=True)

Construct a base class, optionally converting some of the tests in the suite to check that the feature is not implemented.

class TestCSR
spmatrix(*args, **kwargs)
test_constructor1()
test_constructor2()
test_constructor3()
test_constructor4()
test_constructor5()
test_constructor6()
test_sort_indices()
test_eliminate_zeros()
test_ufuncs()
test_unsorted_arithmetic()
test_fancy_indexing_broadcast()
test_has_sorted_indices()

“Ensure has_sorted_indices memoizes sorted state for sort_indices”

test_has_canonical_format()

“Ensure has_canonical_format memoizes state for sum_duplicates”

test_scalar_idx_dtype()
class TestCSC
spmatrix(*args, **kwargs)
test_constructor1()
test_constructor2()
test_constructor3()
test_constructor4()
test_constructor5()
test_constructor6()
test_eliminate_zeros()
test_sort_indices()
test_ufuncs()
test_unsorted_arithmetic()
test_fancy_indexing_broadcast()
test_scalar_idx_dtype()
class TestDOK
test_mult()
test_add_nonzero()
test_dok_divide_scalar()
test_convert()
test_ctor()
test_resize()
test_ticket1160()
class TestLIL
test_dot()
test_scalar_mul()
test_reshape()
test_inplace_ops()
test_lil_iteration()
test_lil_from_csr()
test_fancy_indexing_lil()
test_point_wise_multiply()
test_lil_multiply_removal()
class TestCOO
test_constructor1()
test_constructor2()
test_constructor3()
test_constructor4()
test_iterator()
test_todia_all_zeros()
test_sum_duplicates()
test_todok_duplicates()
test_eliminate_zeros()
class TestDIA
test_constructor1()
test_iterator()
test_setdiag_dtype()
test_getnnz_axis()
class TestBSR
test_constructor1()
test_constructor2()
test_constructor3()
test_constructor4()
test_eliminate_zeros()
test_bsr_matvec()
test_bsr_matvecs()
test_iterator()
test_setdiag()
test_setdiag_comprehensive()
test_scalar_idx_dtype()
_same_sum_duplicate(data, *inds, **kwargs)

Duplicates entries to produce the same matrix

class _NonCanonicalMixin
spmatrix(D, sorted_indices=False, **kwargs)

Replace D with a non-canonical equivalent: containing duplicate elements and explicit zeros

test_bool()
test_getnnz_axis()
test_empty()
test_unary_ufunc_overrides()
class _NonCanonicalCompressedMixin
_arg1_for_noncanonical(M, sorted_indices=False)

Return non-canonical constructor arg1 equivalent to M

_insert_explicit_zero(M, i, j)
class _NonCanonicalCSMixin
test_getelement()
test_setitem_sparse()
test_inv()
test_solve()
class TestCSRNonCanonical
class TestCSCNonCanonical
class TestBSRNonCanonical
_insert_explicit_zero(M, i, j)
test_diagonal()
test_expm()
class TestCOONonCanonical
_arg1_for_noncanonical(M, sorted_indices=None)

Return non-canonical constructor arg1 equivalent to M

_insert_explicit_zero(M, i, j)
test_setdiag_noncanonical()
cases_64bit()
class Test64Bit
_create_some_matrix(mat_cls, m, n)
_compare_index_dtype(m, dtype)
test_decorator_maxval_limit()
test_decorator_maxval_random()
_check_resiliency(cls, method_name, **kw)
test_resiliency_limit_10(cls, method_name)
test_resiliency_random(cls, method_name)
test_resiliency_all_32(cls, method_name)
test_resiliency_all_64(cls, method_name)
test_no_64(cls, method_name)
test_downcast_intp()