MCPcopy Create free account
hub / github.com/dask/dask / test_scipy_sparse_concatenate

Function test_scipy_sparse_concatenate

dask/array/tests/test_array_core.py:5622–5646  ·  view source on GitHub ↗
(axis, container)

Source from the content-addressed store, hash-verified

5620 "container", [pytest.param("array", marks=skip_if_no_sparray()), "matrix"]
5621)
5622def test_scipy_sparse_concatenate(axis, container):
5623 pytest.importorskip("scipy.sparse")
5624 import scipy.sparse
5625
5626 cls = scipy.sparse.csr_matrix if container == "matrix" else scipy.sparse.csr_array
5627
5628 rng = da.random.default_rng()
5629
5630 xs = []
5631 for _ in range(2):
5632 x = rng.random((1000, 10), chunks=(100, 10))
5633 x[x < 0.9] = 0
5634 xs.append(x)
5635
5636 with assert_scipy_sparse_matrix_deprecated(container == "matrix"):
5637 ys = [x.map_blocks(cls) for x in xs]
5638 z = da.concatenate(ys, axis=axis).compute()
5639
5640 if axis == 0:
5641 sp_concatenate = scipy.sparse.vstack
5642 elif axis == 1:
5643 sp_concatenate = scipy.sparse.hstack
5644 z_expected = sp_concatenate([cls(e.compute()) for e in xs])
5645
5646 assert (z != z_expected).nnz == 0
5647
5648
5649@pytest.mark.parametrize("func", [da.asarray, da.asanyarray])

Callers

nothing calls this directly

Calls 4

randomMethod · 0.45
map_blocksMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected