MCPcopy
hub / github.com/dask/dask / test_array_broadcasting

Function test_array_broadcasting

dask/array/tests/test_random.py:260–295  ·  view source on GitHub ↗
(generator_class)

Source from the content-addressed store, hash-verified

258 not hasattr(np, "broadcast_to"), reason='requires numpy 1.10 method "broadcast_to"'
259)
260def test_array_broadcasting(generator_class):
261 arr = np.arange(6).reshape((2, 3))
262 daones = da.ones((2, 3, 4), chunks=3)
263 assert generator_class().poisson(arr, chunks=3).compute().shape == (2, 3)
264
265 for x in (arr, daones):
266 y = generator_class().normal(x, 2, chunks=3)
267 assert y.shape == x.shape
268 assert y.compute().shape == x.shape
269
270 y = generator_class().normal(daones, 2, chunks=3)
271 assert set(daones.dask).issubset(set(y.dask))
272
273 assert generator_class().normal(
274 np.ones((1, 4)), da.ones((2, 3, 4), chunks=(2, 3, 4)), chunks=(2, 3, 4)
275 ).compute().shape == (2, 3, 4)
276 assert generator_class().normal(
277 scale=np.ones((1, 4)),
278 loc=da.ones((2, 3, 4), chunks=(2, 3, 4)),
279 size=(2, 2, 3, 4),
280 chunks=(2, 2, 3, 4),
281 ).compute().shape == (2, 2, 3, 4)
282
283 with pytest.raises(ValueError):
284 generator_class().normal(arr, np.ones((3, 1)), size=(2, 3, 4), chunks=3)
285
286 for o in (np.ones(100), da.ones(100, chunks=(50,)), 1):
287 a = generator_class().normal(1000 * o, 0.01, chunks=(50,))
288 assert 800 < a.mean().compute() < 1200
289
290 # ensure that mismatched chunks align well
291 x = np.arange(10) ** 3
292 y = da.from_array(x, chunks=(1,))
293 z = generator_class().normal(y, 0.01, chunks=(10,))
294
295 assert 0.8 < z.mean().compute() / x.mean() < 1.2
296
297
298def test_multinomial(generator_class):

Callers

nothing calls this directly

Calls 9

generator_classFunction · 0.85
setClass · 0.85
reshapeMethod · 0.80
arangeMethod · 0.45
onesMethod · 0.45
computeMethod · 0.45
poissonMethod · 0.45
normalMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…