| 977 | @pytest.mark.parametrize("weights", [True, False]) |
| 978 | @pytest.mark.parametrize("density", [True, False]) |
| 979 | def test_histogram2d_array_bins(weights, density): |
| 980 | rng = da.random.default_rng() |
| 981 | n = 800 |
| 982 | xbins = [0.0, 0.2, 0.6, 0.9, 1.0] |
| 983 | ybins = [0.0, 0.1, 0.4, 0.5, 1.0] |
| 984 | b = [xbins, ybins] |
| 985 | x = rng.uniform(0, 1, size=(n,), chunks=(200,)) |
| 986 | y = rng.uniform(0, 1, size=(n,), chunks=(200,)) |
| 987 | w = rng.uniform(0.2, 1.1, size=(n,), chunks=(200,)) if weights else None |
| 988 | a1, b1x, b1y = da.histogram2d(x, y, bins=b, density=density, weights=w) |
| 989 | a2, b2x, b2y = np.histogram2d(x, y, bins=b, density=density, weights=w) |
| 990 | a3, b3x, b3y = np.histogram2d( |
| 991 | x.compute(), |
| 992 | y.compute(), |
| 993 | bins=b, |
| 994 | density=density, |
| 995 | weights=w.compute() if weights else None, |
| 996 | ) |
| 997 | assert_eq(a1, a2) |
| 998 | assert_eq(a1, a3) |
| 999 | if not (weights or density): |
| 1000 | assert a1.sum() == n |
| 1001 | assert a2.sum() == n |
| 1002 | assert same_keys( |
| 1003 | da.histogram2d(x, y, bins=b, density=density, weights=w)[0], |
| 1004 | a1, |
| 1005 | ) |
| 1006 | assert a1.compute().shape == a3.shape |
| 1007 | |
| 1008 | |
| 1009 | def test_histogramdd(): |