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

Function test_arr_like

dask/array/tests/test_creation.py:46–92  ·  view source on GitHub ↗
(
    funcname, shape, cast_shape, dtype, cast_chunks, chunks, name, order, backend
)

Source from the content-addressed store, hash-verified

44@pytest.mark.parametrize("order", ["C", "F"])
45@pytest.mark.parametrize("dtype", ["i4"])
46def test_arr_like(
47 funcname, shape, cast_shape, dtype, cast_chunks, chunks, name, order, backend
48):
49 backend_lib = pytest.importorskip(backend)
50 with dask.config.set({"array.backend": backend}):
51 np_func = getattr(backend_lib, funcname)
52 da_func = getattr(da, funcname)
53 shape = cast_shape(shape)
54 chunks = cast_chunks(chunks)
55
56 if "full" in funcname:
57 old_np_func = np_func
58 old_da_func = da_func
59
60 np_func = lambda *a, **k: old_np_func(*a, fill_value=5, **k)
61 da_func = lambda *a, **k: old_da_func(*a, fill_value=5, **k)
62
63 dtype = np.dtype(dtype)
64
65 if "like" in funcname:
66 a = backend_lib.random.randint(0, 10, shape).astype(dtype)
67
68 np_r = np_func(a, order=order)
69 da_r = da_func(a, order=order, chunks=chunks, name=name)
70 else:
71 np_r = np_func(shape, order=order, dtype=dtype)
72 da_r = da_func(shape, order=order, dtype=dtype, chunks=chunks, name=name)
73
74 assert np_r.shape == da_r.shape
75 assert np_r.dtype == da_r.dtype
76
77 # Make sure we are using the desired backend
78 assert isinstance(da_r._meta, backend_lib.ndarray)
79 assert isinstance(da_r.compute(), backend_lib.ndarray)
80
81 if "empty" not in funcname:
82 assert_eq(np_r, da_r)
83
84 if name is None:
85 assert funcname.split("_")[0] in da_r.name
86 else:
87 assert da_r.name == name
88
89 if "order" == "F": # FIXME: this is clearly a bug! # noqa: PLR0133
90 assert da_r.compute().flags.fnc
91 else:
92 assert not da_r.compute().flags.fnc
93
94
95@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 7

assert_eqFunction · 0.90
setMethod · 0.80
splitMethod · 0.80
dtypeMethod · 0.45
astypeMethod · 0.45
randintMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected