From 13ac670f0befaaa21523ec6817da68d829f9e6dc Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Wed, 14 Apr 2021 15:35:32 -0400 Subject: [PATCH] cleaning --- setup.py | 3 --- src/pygram11/_bh.py | 20 ------------------- src/pygram11/_hist.py | 25 ----------------------- tests/test_bh.py | 46 ------------------------------------------- 4 files changed, 94 deletions(-) delete mode 100644 src/pygram11/_bh.py delete mode 100644 tests/test_bh.py diff --git a/setup.py b/setup.py index b080412..3776f44 100644 --- a/setup.py +++ b/setup.py @@ -183,9 +183,6 @@ def get_extensions(): extras_require = { - "bh": [ - "boost-histogram", - ], "test": [ "pytest", ], diff --git a/src/pygram11/_bh.py b/src/pygram11/_bh.py deleted file mode 100644 index 8e9f629..0000000 --- a/src/pygram11/_bh.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import Optional - -import numpy as np - -try: - import boost_histogram as bh -except ImportError: - raise ImportError("Install boost-histogram to use bh=... feature") - - -def store_results_in_bh( - h: bh.Histogram, - counts: np.ndarray, - variances: Optional[np.ndarray] = None, -) -> None: - if variances is None: - h[...] = counts - else: - h.view()["value"] = counts - h.view()["variance"] = variances diff --git a/src/pygram11/_hist.py b/src/pygram11/_hist.py index c90a541..4dff1ea 100644 --- a/src/pygram11/_hist.py +++ b/src/pygram11/_hist.py @@ -140,7 +140,6 @@ def fix1d( density: bool = False, flow: bool = False, cons_var: bool = False, - bh: Optional[Any] = None, ) -> Tuple[np.ndarray, Union[np.ndarray, None]]: r"""Histogram data with fixed (uniform) bin widths. @@ -164,9 +163,6 @@ def fix1d( cons_var : bool If ``True``, conserve the variance rather than return the standard error (square root of the variance). - bh : boost_histogram.Histogram, optional - Pass a boost_histogram.Histogram object to store the resulting - counts and variances. Raises ------ @@ -208,10 +204,6 @@ def fix1d( if density: width = (xmax - xmin) / bins result = _densify_fixed_counts(result, width) - if bh is not None: - from ._bh import store_results_in_bh - - store_results_in_bh(bh, result) return result, None if np.shape(x) != np.shape(weights): @@ -223,11 +215,6 @@ def fix1d( result = _densify_fixed_weighted_counts(result, width) counts, variances = result - if bh is not None: - from ._bh import store_results_in_bh - - store_results_in_bh(bh, counts, variances) - if cons_var: return counts, variances return counts, np.sqrt(variances) @@ -497,7 +484,6 @@ def fix2d( weights: Optional[np.ndarray] = None, flow: bool = False, cons_var: bool = False, - bh: Optional[Any] = None, ) -> Tuple[np.ndarray, Optional[np.ndarray]]: r"""Histogram two dimensional data with fixed (uniform) binning. @@ -524,9 +510,6 @@ def fix2d( cons_var : bool If ``True``, conserve the variance rather than return the standard error (square root of the variance). - bh : boost_histogram.Histogram, optional - Pass a boost_histogram.Histogram object to store the resulting - counts and variances. Raises ------ @@ -578,20 +561,12 @@ def fix2d( if weights is None: result = _f2d(x, y, int(nx), xmin, xmax, int(ny), ymin, ymax, flow) - if bh is not None: - from ._bh import store_results_in_bh - - store_results_in_bh(bh, result) return result, None counts, variances = _f2dw( x, y, weights, int(nx), xmin, xmax, int(ny), ymin, ymax, flow ) - if bh is not None: - from ._bh import store_results_in_bh - - store_results_in_bh(bh, counts, variances) if cons_var: return counts, variances return counts, np.sqrt(variances) diff --git a/tests/test_bh.py b/tests/test_bh.py deleted file mode 100644 index e981e1c..0000000 --- a/tests/test_bh.py +++ /dev/null @@ -1,46 +0,0 @@ -import numpy as np -import boost_histogram as bh - -import pygram11 as pg -import pygram11._bh as pgbh - -RNG = np.random.default_rng(123) - - -def test_f1d(): - x = RNG.standard_normal(size=(20000,)) - w = RNG.uniform(0.25, 1.1, size=x.shape) - bins = 12 - range = (-3.1, 3.1) - h1 = bh.Histogram( - bh.axis.Regular(bins, range[0], range[1]), storage=bh.storage.Weight() - ) - counts, variances = pg.fix1d( - x, bins=bins, range=range, weights=w, cons_var=True, bh=h1 - ) - assert np.allclose(h1.counts(), counts) - assert np.allclose(h1.variances(), variances) - - -def test_f2d(): - x = RNG.standard_normal(size=(20000,)) - y = RNG.standard_normal(size=(20000,)) - w = RNG.uniform(0.25, 1.1, size=x.shape) - bins = (12, 14) - range = ((-3.1, 3.1), (-2.99, 2.99)) - h1 = bh.Histogram( - bh.axis.Regular(bins[0], range[0][0], range[0][1]), - bh.axis.Regular(bins[1], range[1][0], range[1][1]), - storage=bh.storage.Weight(), - ) - counts, variances = pg.fix2d( - x, - y, - bins=bins, - range=range, - weights=w, - cons_var=True, - bh=h1, - ) - assert np.allclose(h1.counts(), counts) - assert np.allclose(h1.variances(), variances)