File: test_pbt.py

package info (click to toggle)
python-boost-histogram 1.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,236 kB
  • sloc: python: 7,940; cpp: 3,243; makefile: 22; sh: 1
file content (44 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download
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)