Ejemplo n.º 1
0
def test_obj_3D_rectangular(use_weights):
    x = da.random.standard_normal(size=(2000, 3), chunks=(400, 3))
    if use_weights:
        weights = da.random.uniform(0.5,
                                    0.75,
                                    size=x.shape[0],
                                    chunks=x.chunksize[0])
        storage = dhb.storage.Weight()
    else:
        weights = None
        storage = dhb.storage.Double()

    h = dhb.Histogram(
        dhb.axis.Regular(8, -3.5, 3.5),
        dhb.axis.Regular(7, -3.3, 3.3),
        dhb.axis.Regular(9, -3.2, 3.2),
        storage=storage,
    )
    h.fill(x, weight=weights)
    h.compute()

    control = bh.Histogram(*h.axes, storage=h._storage_type())
    if use_weights:
        control.fill(*(x.compute().T), weight=weights.compute())
    else:
        control.fill(*(x.compute().T))

    assert np.allclose(h.counts(), control.counts())
    if use_weights:
        assert np.allclose(h.variances(), control.variances())
Ejemplo n.º 2
0
def test_clear_fills():
    x = da.random.standard_normal(size=(8, 2), chunks=(4, 2))
    h = dhb.Histogram(
        dhb.axis.Regular(8, -3.5, 3.5),
        dhb.axis.Regular(9, -3.2, 3.2),
    )
    h.fill(x)
    assert h.staged_fills()
    h.clear_fills()
    assert not h.staged_fills()
Ejemplo n.º 3
0
def test_to_da(flow):
    x = da.random.standard_normal(size=(3_000, ), chunks=500)
    h1 = dhb.Histogram(dhb.axis.Regular(10, -3, 3))
    h2 = bh.Histogram(bh.axis.Regular(10, -3, 3))
    h1.fill(x)
    h2.fill(x.compute())
    h1c, h1e = h1.to_dask_array(dd=True, flow=flow)
    h2c, h2e = h2.to_numpy(dd=True, flow=flow)
    np.testing.assert_array_almost_equal(h1c.compute(), h2c)
    np.testing.assert_array_almost_equal(h1e[0].compute(), h2e[0])
Ejemplo n.º 4
0
def test_to_delayed():
    x = da.random.standard_normal(size=(2_000, 3), chunks=(500, 3))
    bins = [
        [-3, -2.2, 0, 1.1, 2.2, 3.3],
        [-4, -1.1, 0, 2.2, 3.3, 4.4],
        [-2, -0.9, 0, 0.3, 2.2],
    ]
    dh = dhb.Histogram(
        dhb.axis.Variable(bins[0]),
        dhb.axis.Variable(bins[1]),
        dhb.axis.Variable(bins[2]),
    )
    dh.fill(x)
    dh.compute()
    dh.fill(x)
    ch = dhc.clone(dh)
    ch.fill(*(x.compute().T))
    ch.fill(*(x.compute().T))
    np.testing.assert_array_almost_equal(
        dh.to_delayed().compute().to_numpy()[0],
        ch.to_numpy()[0])
Ejemplo n.º 5
0
def test_obj_1D(use_weights):
    x = da.random.standard_normal(size=(2000, ), chunks=(400, ))
    if use_weights:
        weights = da.random.uniform(0.5, 0.75, size=x.shape, chunks=x.chunks)
        storage = dhb.storage.Weight()
    else:
        weights = None
        storage = dhb.storage.Double()

    h = dhb.Histogram(dhb.axis.Regular(12, -3, 3), storage=storage)
    h.fill(x, weight=weights)
    h.compute()

    control = bh.Histogram(*h.axes, storage=h._storage_type())
    if use_weights:
        control.fill(x.compute(), weight=weights.compute())
    else:
        control.fill(x.compute())

    assert np.allclose(h.counts(), control.counts())
    if use_weights:
        assert np.allclose(h.variances(), control.variances())
Ejemplo n.º 6
0
def test_concrete_fill():
    x = da.random.standard_normal(size=(500, 2), chunks=(4, 2))
    h = dhb.Histogram(
        dhb.axis.Regular(8, -3.5, 3.5),
        dhb.axis.Regular(9, -3.2, 3.2),
    )

    h.fill(x)
    material_x = x.compute()
    h.fill(*material_x.T)
    h.compute()

    h2 = bh.Histogram(*h.axes)
    h2.fill(*material_x.T)
    h2.fill(*material_x.T)

    np.testing.assert_array_almost_equal(h2.values(), h.values())

    with pytest.raises(
            TypeError,
            match="concrete_fill does not support Dask collections, "
            "only materialized data; use the Histogram.fill method.",
    ):
        h.concrete_fill(x)