Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## UPCOMING

* Fix scaling a weighted storage [#559][]
* Support running type checking from Python < 3.8 [#542][]

[#542]: https://github.com/scikit-hep/boost-histogram/pull/542
[#559]: https://github.com/scikit-hep/boost-histogram/pull/559

## Version 1.0

Expand Down
4 changes: 4 additions & 0 deletions src/boost_histogram/_internal/hist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import logging
import threading
import typing
import warnings
Expand Down Expand Up @@ -49,6 +50,8 @@
_core.hist.any_weighted_mean,
}

logger = logging.getLogger(__name__)


CppAxis = NewType("CppAxis", object)

Expand Down Expand Up @@ -772,6 +775,7 @@ def __getitem__( # noqa: C901
assert isinstance(stop, int)
slices.append(_core.algorithm.slice_and_rebin(i, start, stop, merge))

logger.debug("Reduce with %s", slices)
reduced = self._hist.reduce(*slices)

if not integrations:
Expand Down
4 changes: 2 additions & 2 deletions src/boost_histogram/_internal/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ def __array_ufunc__(
ufunc(input_0["value"], input_1, out=result["value"], **kwargs)
ufunc(
input_0["variance"],
np.abs(input_1),
input_1 ** 2,
out=result["variance"],
**kwargs,
)
else:
ufunc(input_0, input_1["value"], out=result["value"], **kwargs)
ufunc(
np.abs(input_0),
input_0 ** 2,
input_1["variance"],
out=result["variance"],
**kwargs,
Expand Down
15 changes: 9 additions & 6 deletions src/register_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ void register_algorithms(py::module& algorithm) {
using range_t = bh::algorithm::reduce_command::range_t;

if(self.range != range_t::none) {
const char* suffix = self.merge > 0 ? "_and_rebin" : "";
const char* start = self.iaxis == bh::algorithm::reduce_command::unset
? ""
: "iaxis={0}, ";
const char* merge = self.merge > 0 ? ", merge={3}" : "";
const char* suffix = self.merge > 0 ? "_and_rebin" : "";
const char* c_start = self.iaxis == bh::algorithm::reduce_command::unset
? ""
: "iaxis={0}, ";
const char* c_merge = self.merge > 0 ? ", merge={0}" : "";

py::str start = py::str(c_start).format(self.iaxis);
py::str merge = py::str(c_merge).format(self.merge);

if(self.range == range_t::indices) {
return py::str("reduce_command(slice{0}({1}, begin={2}, "
return py::str("reduce_command(slice{0}({1}begin={2}, "
"end={3}{4}, mode={5}))")
.format(suffix,
start,
Expand Down
14 changes: 7 additions & 7 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ def test_basic_view(v):
def test_view_mul(v):
v2 = v * 2
assert_allclose(v2.value, [0, 6, 4, 2])
assert_allclose(v2.variance, [0, 6, 4, 2])
assert_allclose(v2.variance, [0, 12, 8, 4])

v2 = 2 * v
assert_allclose(v2.value, [0, 6, 4, 2])
assert_allclose(v2.variance, [0, 6, 4, 2])
assert_allclose(v2.variance, [0, 12, 8, 4])

v2 = v * (-2)
assert_allclose(v2.value, [0, -6, -4, -2])
assert_allclose(v2.variance, [0, 6, 4, 2])
assert_allclose(v2.variance, [0, 12, 8, 4])

v *= 2
assert_allclose(v.value, [0, 6, 4, 2])
assert_allclose(v.variance, [0, 6, 4, 2])
assert_allclose(v.variance, [0, 12, 8, 4])


def test_view_div(v):
v2 = v / 2
assert_allclose(v2.value, [0, 1.5, 1, 0.5])
assert_allclose(v2.variance, [0, 1.5, 1, 0.5])
assert_allclose(v2.variance, [0, 0.75, 0.5, 0.25])

v2 = v / (-0.5)
assert_allclose(v2.value, [0, -6, -4, -2])
assert_allclose(v2.variance, [0, 6, 4, 2])
assert_allclose(v2.variance, [0, 12, 8, 4])

v2 = 1 / v[1:]
assert_allclose(v2.value, [1 / 3, 1 / 2, 1])
assert_allclose(v2.variance, [1 / 3, 1 / 2, 1])

v /= 0.5
assert_allclose(v.value, [0, 6, 4, 2])
assert_allclose(v.variance, [0, 6, 4, 2])
assert_allclose(v.variance, [0, 12, 8, 4])


def test_view_add(v):
Expand Down