Skip to content

Commit 8721d04

Browse files
henryiiiHDembinski
authored andcommitted
Rename accumulators
1 parent bdcb10e commit 8721d04

File tree

6 files changed

+38
-28
lines changed

6 files changed

+38
-28
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ counts = hist.view()
9393
* `bh.storage.Mean()`: Accepts a sample and computes the mean of the samples (profile). (`.view` not yet supported)
9494
* `bh.storage.WeightedMean()`: Accepts a sample and a weight. It computes the weighted mean of the samples. (`.view` not yet supported)
9595
* Accumulators
96-
* `bh.accumulator.sum`: High accuracy sum (Neumaier) - used by the sum method when summing a numerical histogram
97-
* `bh.accumulator.weighted_sum`: Tracks a weighted sum and variance
98-
* `bh.accumulator.weighted_mean`: Tracks a weighted sum, mean, and variance (West's incremental algorithm)
99-
* `bh.accumulator.mean`: Running count, mean, and variance (Welfords's incremental algorithm)
96+
* `bh.accumulator.Sum`: High accuracy sum (Neumaier) - used by the sum method when summing a numerical histogram
97+
* `bh.accumulator.WeightedSum`: Tracks a weighted sum and variance
98+
* `bh.accumulator.Mean`: Running count, mean, and variance (Welfords's incremental algorithm)
99+
* `bh.accumulator.WeightedMean`: Tracks a weighted sum, mean, and variance (West's incremental algorithm)
100100
* Histogram operations
101101
* `h.fill(arr, ..., weight=...)` Fill with N arrays or single values
102102
* `h.rank`: The number of dimensions

boost_histogram/accumulators.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22

33
del absolute_import, division, print_function
44

5-
from ._core.accumulators import sum, mean, weighted_sum, weighted_mean
5+
from ._core.accumulators import (
6+
sum as Sum,
7+
mean as Mean,
8+
weighted_sum as WeightedSum,
9+
weighted_mean as WeightedMean,
10+
)

boost_histogram/cpp/accumulators.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22

33
del absolute_import, division, print_function
44

5-
from ..accumulators import sum, mean, weighted_sum, weighted_mean
5+
from ..accumulators import (
6+
Sum as sum,
7+
Mean as mean,
8+
WeightedSum as weighted_sum,
9+
WeightedMean as weighted_mean,
10+
)

tests/test_accumulators.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def test_weighted_sum():
9-
a = bh.accumulators.weighted_sum(1.5, 2.5)
9+
a = bh.accumulators.WeightedSum(1.5, 2.5)
1010

1111
assert a.value == 1.5
1212
assert a.variance == 2.5
@@ -19,61 +19,61 @@ def test_weighted_sum():
1919
vals = [1, 2, 3]
2020
vari = [4, 5, 6]
2121

22-
a = bh.accumulators.weighted_sum()
22+
a = bh.accumulators.WeightedSum()
2323
for val, var in zip(vals, vari):
24-
a += bh.accumulators.weighted_sum(val, variance=var)
24+
a += bh.accumulators.WeightedSum(val, variance=var)
2525

2626
assert a.value == 6
2727
assert a.variance == 15
2828

29-
a2 = bh.accumulators.weighted_sum().fill(vals, variance=vari)
29+
a2 = bh.accumulators.WeightedSum().fill(vals, variance=vari)
3030
assert a == a2
3131

32-
assert a == bh.accumulators.weighted_sum(6, 15)
32+
assert a == bh.accumulators.WeightedSum(6, 15)
3333

3434

3535
def test_sum():
3636
vals = [1, 2, 3]
37-
a = bh.accumulators.sum()
37+
a = bh.accumulators.Sum()
3838
for val in vals:
3939
a += val
4040

4141
assert a.value == 6
4242

43-
a2 = bh.accumulators.sum().fill(vals)
43+
a2 = bh.accumulators.Sum().fill(vals)
4444
assert a == a2
4545

46-
assert a == bh.accumulators.sum(6)
46+
assert a == bh.accumulators.Sum(6)
4747

4848

4949
def test_weighted_mean():
5050
vals = [4, 1]
5151
weights = [1, 2]
52-
a = bh.accumulators.weighted_mean()
52+
a = bh.accumulators.WeightedMean()
5353
for v, w in zip(vals, weights):
5454
a(v, weight=w)
5555

5656
assert a.sum_of_weights == 3.0
5757
assert a.variance == 4.5
5858
assert a.value == 2.0
5959

60-
a2 = bh.accumulators.weighted_mean().fill(vals, weight=weights)
60+
a2 = bh.accumulators.WeightedMean().fill(vals, weight=weights)
6161
assert a == a2
6262

63-
assert a == bh.accumulators.weighted_mean(3, 5, 2, 4.5)
63+
assert a == bh.accumulators.WeightedMean(3, 5, 2, 4.5)
6464

6565

6666
def test_mean():
6767
vals = [1, 2, 3]
68-
a = bh.accumulators.mean()
68+
a = bh.accumulators.Mean()
6969
for val in vals:
7070
a(val)
7171

7272
assert a.count == 3
7373
assert a.value == 2
7474
assert a.variance == 1
7575

76-
a2 = bh.accumulators.mean().fill([1, 2, 3])
76+
a2 = bh.accumulators.Mean().fill([1, 2, 3])
7777
assert a == a2
7878

79-
assert a == bh.accumulators.mean(3, 2, 1)
79+
assert a == bh.accumulators.Mean(3, 2, 1)

tests/test_pickle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
)
1919

2020
accumulators = (
21-
(bh.accumulators.sum, (12,)),
22-
(bh.accumulators.weighted_sum, (1.5, 2.5)),
23-
(bh.accumulators.mean, (5, 1.5, 2.5)),
24-
(bh.accumulators.weighted_mean, (1.5, 2.5, 3.5, 4.5)),
21+
(bh.accumulators.Sum, (12,)),
22+
(bh.accumulators.WeightedSum, (1.5, 2.5)),
23+
(bh.accumulators.Mean, (5, 1.5, 2.5)),
24+
(bh.accumulators.WeightedMean, (1.5, 2.5, 3.5, 4.5)),
2525
)
2626

2727
storages = (

tests/test_public_hist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,10 @@ def ar(*args):
695695
a.fill(v, weight=w)
696696
a.fill((0, 1), weight=(2, 3))
697697

698-
assert a[bh.underflow] == bh.accumulators.weighted_sum(2, 4)
699-
assert a[0] == bh.accumulators.weighted_sum(5, 13)
700-
assert a[1] == bh.accumulators.weighted_sum(7, 25)
701-
assert a[2] == bh.accumulators.weighted_sum(5, 25)
698+
assert a[bh.underflow] == bh.accumulators.WeightedSum(2, 4)
699+
assert a[0] == bh.accumulators.WeightedSum(5, 13)
700+
assert a[1] == bh.accumulators.WeightedSum(7, 25)
701+
assert a[2] == bh.accumulators.WeightedSum(5, 25)
702702

703703
assert a[bh.underflow].value == 2
704704
assert a[0].value == 5

0 commit comments

Comments
 (0)