1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
from __future__ import annotations
import numpy as np
import pytest
from pytest import approx
import boost_histogram as bh
hypothesis = pytest.importorskip("hypothesis")
nst = pytest.importorskip("hypothesis.extra.numpy")
@hypothesis.given(
nst.arrays(
float,
(4,),
elements={
"min_value": 1,
"max_value": 100,
"exclude_min": True,
"allow_nan": False,
},
),
nst.arrays(
float, (4,), elements={"min_value": -100, "max_value": 100, "allow_nan": False}
),
nst.arrays(
float,
(4,),
elements={
"min_value": 0,
"max_value": 100,
"allow_nan": False,
"exclude_min": True,
},
),
)
def test_variance_setting(cnt, val, var):
h = bh.Histogram(bh.axis.Regular(4, 0, 1), storage=bh.storage.Mean())
h[...] = np.stack([cnt, val, var * cnt], axis=-1)
assert h.counts() == approx(cnt)
assert h.values() == approx(val)
assert h.variances() == approx(var) # , abs=1e-3, rel=1e-3)
|