Whether ``obj`` is a SciPy or CuPy sparse container. Both the sparse matrix (``*_matrix``) and the sparse array (``*_array``) families are recognized. The check is done on the type's module so that it also covers formats whose concrete class lives in a submodule, e.g. ``scipy.sparse
(obj)
| 443 | |
| 444 | |
| 445 | def _is_sparse_container(obj) -> bool: |
| 446 | """Whether ``obj`` is a SciPy or CuPy sparse container. |
| 447 | |
| 448 | Both the sparse matrix (``*_matrix``) and the sparse array (``*_array``) |
| 449 | families are recognized. The check is done on the type's module so that it |
| 450 | also covers formats whose concrete class lives in a submodule, e.g. |
| 451 | ``scipy.sparse._csr.csr_array``. |
| 452 | """ |
| 453 | module = type(obj).__module__ |
| 454 | return any( |
| 455 | module == prefix or module.startswith(f"{prefix}.") |
| 456 | for prefix in _SPARSE_CONTAINER_MODULES |
| 457 | ) |
| 458 | |
| 459 | |
| 460 | def _array_like_safe(np_func, da_func, a, like, **kwargs): |
no test coverage detected