diff --git a/README.md b/README.md index dbf4b9e7..db5f9f30 100644 --- a/README.md +++ b/README.md @@ -71,15 +71,15 @@ Example 1: Fill a 1d-histogram in C++ auto h = bh::make_static_histogram(bh::regular_axis(10, -1.0, 2.0, "x")); // fill histogram with data - h.fill(-1.5); // put in underflow bin - h.fill(-1.0); // included in first bin, bin interval is semi-open - h.fill(-0.5); - h.fill(1.1); - h.fill(0.3); - h.fill(1.7); - h.fill(2.0); // put in overflow bin, bin interval is semi-open - h.fill(20.0); // put in overflow bin - h.wfill(0.1, 5.0); // fill with a weighted entry, weight is 5.0 + h.increment(-1.5); // put in underflow bin + h.increment(-1.0); // included in first bin, bin interval is semi-open + h.increment(-0.5); + h.increment(1.1); + h.increment(0.3); + h.increment(1.7); + h.increment(2.0); // put in overflow bin, bin interval is semi-open + h.increment(20.0); // put in overflow bin + h.wincrement(0.1, 5.0); // fill with a weighted entry, weight is 5.0 // access histogram counts, loop includes under- and overflow bin const auto& a = h.axis<0>(); @@ -132,7 +132,7 @@ Example 2: Fill a 2d-histogram in Python with data in Numpy arrays rphi[:, 1] = np.arctan2(y, x) # compute phi # fill histogram with numpy array - h.fill(rphi) + h.increment(rphi) # access histogram counts (no copy) count_matrix = np.asarray(h) diff --git a/doc/rationale.qbk b/doc/rationale.qbk index 3e9c5c04..96e5a07b 100644 --- a/doc/rationale.qbk +++ b/doc/rationale.qbk @@ -21,7 +21,7 @@ Properties Getter/setter-like functions are wrapped as properties. Keyword-based parameters - C++ member functions :cpp:func:`histogram::fill` and :cpp:func:`histogram::wfill` are wrapped by the single Python member function :py:func:`histogram.fill` with an optional keyword parameter `w` to pass a weight. + C++ member functions :cpp:func:`histogram::fill` and :cpp:func:`histogram::wfill` are wrapped by the single Python member function :py:func:`histogram.increment` with an optional keyword parameter `w` to pass a weight. [endsect] diff --git a/doc/tutorial.qbk b/doc/tutorial.qbk index e51119ee..c3eba018 100644 --- a/doc/tutorial.qbk +++ b/doc/tutorial.qbk @@ -26,14 +26,14 @@ How to make a 1d-histogram in C++ and to fill it: * axis are placed in the overflow and underflow bins. * Normally you would loop over a source of values. */ - h.fill(-1.5); // put in underflow bin - h.fill(-0.5); - h.fill(1.1); - h.fill(-1.0); // included, interval is semi-open - h.fill(0.3); - h.fill(1.7); - h.fill(2.0); // put in overflow bin, interval is semi-open - h.fill(20.0); // put in overflow bin + h.increment(-1.5); // put in underflow bin + h.increment(-0.5); + h.increment(1.1); + h.increment(-1.0); // included, interval is semi-open + h.increment(0.3); + h.increment(1.7); + h.increment(2.0); // put in overflow bin, interval is semi-open + h.increment(20.0); // put in overflow bin /* Fill histogram with a weighted count. This increases the * bin counter not by one, but by the specified weight. @@ -46,7 +46,7 @@ How to make a 1d-histogram in C++ and to fill it: * * Use wfill(...) if you have to, else prefer fill(...). */ - h.wfill(0.1, 5.0); + h.wincrement(0.1, 5.0); /* Print a table representation of the histogram showing the bin * value and a estimate of the standard deviation. Overflow and @@ -111,7 +111,7 @@ How to make a 2d-histogram in Python and to fill it using a Numpy array: rphi = np.empty((1000, 2)) rphi[:, 0] = (x ** 2 + y ** 2) ** 0.5 # compute radius rphi[:, 1] = np.arctan2(y, x) # compute phi - h.fill(rphi) + h.increment(rphi) # access counts as a numpy array (no data is copied) count_matrix = np.asarray(h) diff --git a/examples/example_1d.py b/examples/example_1d.py index 38ec73e6..e0e7eff5 100644 --- a/examples/example_1d.py +++ b/examples/example_1d.py @@ -3,7 +3,7 @@ import numpy as np import matplotlib.pyplot as plt h = hg.histogram(hg.regular_axis(10, -3, 3)) -h.fill(np.random.randn(1000)) +h.increment(np.random.randn(1000)) bins = h.axis(0).bins diff --git a/examples/example_2d.py b/examples/example_2d.py index b2e98e1b..4fdfb2f1 100644 --- a/examples/example_2d.py +++ b/examples/example_2d.py @@ -6,7 +6,7 @@ h = hg.histogram(hg.regular_axis(10, -3, 3, uoflow=False), hg.regular_axis(10, -3, 3, uoflow=False)) xy = np.random.randn(2000).reshape((1000, 2)) xy[:,1] *= 0.5 -h.fill(xy) +h.increment(xy) bins = h.axis(0).bins diff --git a/include/boost/histogram/dynamic_histogram.hpp b/include/boost/histogram/dynamic_histogram.hpp index 8056ff4f..e0e3ca4f 100644 --- a/include/boost/histogram/dynamic_histogram.hpp +++ b/include/boost/histogram/dynamic_histogram.hpp @@ -133,7 +133,7 @@ public: } template - void fill(Values... values) + void increment(Values... values) { BOOST_ASSERT_MSG(sizeof...(values) == dim(), "number of arguments does not match histogram dimension"); @@ -145,7 +145,7 @@ public: template > - void fill(Iterator begin, Iterator end) + void increment(Iterator begin, Iterator end) { BOOST_ASSERT_MSG(std::distance(begin, end) == dim(), "number of arguments does not match histogram dimension"); @@ -157,16 +157,16 @@ public: template > - void fill(const Sequence& values) + void increment(const Sequence& values) { - fill(std::begin(values), std::end(values)); + increment(std::begin(values), std::end(values)); } template - void wfill(value_type w, Values... values) + void wincrement(value_type w, Values... values) { static_assert(detail::has_weight_support::value, - "wfill only supported for adaptive_storage"); + "wincrement only supported for adaptive_storage"); BOOST_ASSERT_MSG(sizeof...(values) == dim(), "number of arguments does not match histogram dimension"); detail::linearize_x lin; @@ -177,10 +177,10 @@ public: template > - void wfill(value_type w, Iterator begin, Iterator end) + void wincrement(value_type w, Iterator begin, Iterator end) { static_assert(detail::has_weight_support::value, - "wfill only supported for adaptive_storage"); + "wincrement only supported for adaptive_storage"); BOOST_ASSERT_MSG(std::distance(begin, end) == dim(), "iterator range does not match histogram dimension"); detail::linearize_x lin; @@ -191,9 +191,9 @@ public: template > - void wfill(value_type w, const Sequence& values) + void wincrement(value_type w, const Sequence& values) { - wfill(w, std::begin(values), std::end(values)); + wincrement(w, std::begin(values), std::end(values)); } template diff --git a/include/boost/histogram/static_histogram.hpp b/include/boost/histogram/static_histogram.hpp index 6d2f6ec7..e3df6eb5 100644 --- a/include/boost/histogram/static_histogram.hpp +++ b/include/boost/histogram/static_histogram.hpp @@ -103,7 +103,7 @@ public: } template - void fill(Values... values) + void increment(Values... values) { static_assert(sizeof...(values) == dim(), "number of arguments does not match histogram dimension"); @@ -115,7 +115,7 @@ public: template > - void fill(Iterator begin, Iterator end) + void increment(Iterator begin, Iterator end) { BOOST_ASSERT_MSG(std::distance(begin, end) == dim(), "iterator range does not match histogram dimension"); @@ -127,16 +127,16 @@ public: template > - void fill(const Sequence& values) + void increment(const Sequence& values) { - fill(std::begin(values), std::end(values)); + increment(std::begin(values), std::end(values)); } template - void wfill(value_type w, Values... values) + void wincrement(value_type w, Values... values) { static_assert(detail::has_weight_support::value, - "wfill only supported for adaptive_storage"); + "wincrement only supported for adaptive_storage"); static_assert(sizeof...(values) == dim(), "number of arguments does not match histogram dimension"); detail::linearize_x lin; @@ -147,10 +147,10 @@ public: template > - void wfill(value_type w, Iterator begin, Iterator end) + void wincrement(value_type w, Iterator begin, Iterator end) { static_assert(detail::has_weight_support::value, - "wfill only supported for adaptive_storage"); + "wincrement only supported for adaptive_storage"); BOOST_ASSERT_MSG(std::distance(begin, end) == dim(), "iterator range does not match histogram dimension"); detail::linearize_x lin; @@ -161,9 +161,9 @@ public: template > - void wfill(value_type w, const Sequence& values) + void wincrement(value_type w, const Sequence& values) { - wfill(w, std::begin(values), std::end(values)); + wincrement(w, std::begin(values), std::end(values)); } template diff --git a/src/python/histogram.cpp b/src/python/histogram.cpp index c3864c20..5f367c1d 100644 --- a/src/python/histogram.cpp +++ b/src/python/histogram.cpp @@ -75,7 +75,7 @@ histogram_init(python::tuple args, python::dict kwargs) { } python::object -histogram_fill(python::tuple args, python::dict kwargs) { +histogram_increment(python::tuple args, python::dict kwargs) { using namespace python; const unsigned nargs = len(args); @@ -143,7 +143,7 @@ histogram_fill(python::tuple args, python::dict kwargs) { for (unsigned i = 0; i < dims[0]; ++i) { double* v = reinterpret_cast(PyArray_GETPTR1(a, i) ); double* w = reinterpret_cast(PyArray_GETPTR1(aw, i)); - self.wfill(*w, v, v+self.dim()); + self.wincrement(*w, v, v+self.dim()); } Py_DECREF(aw); @@ -154,7 +154,7 @@ histogram_fill(python::tuple args, python::dict kwargs) { } else { for (unsigned i = 0; i < dims[0]; ++i) { double* v = reinterpret_cast(PyArray_GETPTR1(a, i)); - self.fill(v, v+self.dim()); + self.increment(v, v+self.dim()); } } @@ -175,11 +175,11 @@ histogram_fill(python::tuple args, python::dict kwargs) { v[i] = extract(args[1 + i]); if (ow.is_none()) { - self.fill(v, v+self.dim()); + self.increment(v, v+self.dim()); } else { const double w = extract(ow); - self.wfill(w, v, v+self.dim()); + self.wincrement(w, v, v+self.dim()); } return object(); @@ -293,10 +293,10 @@ void register_histogram() ":param int i: index of the axis\n" ":returns: axis object for axis i", (arg("self"), arg("i") = 0)) - .def("fill", raw_function(histogram_fill), + .def("increment", raw_function(histogram_increment), "Pass a sequence of values with a length n is" "\nequal to the dimensions of the histogram," - "\nand optionally a weight w for this fill" + "\nand optionally a weight w for this increment" "\n(*int* or *float*)." "\n" "\nIf Numpy support is enabled, values may also" diff --git a/test/dynamic_histogram_test.cpp b/test/dynamic_histogram_test.cpp index afb3c5f7..4c58be69 100644 --- a/test/dynamic_histogram_test.cpp +++ b/test/dynamic_histogram_test.cpp @@ -125,7 +125,7 @@ int main() { { auto h = make_dynamic_histogram_with>(integer_axis(0, 1), integer_axis(0, 2)); - h.fill(0, 0); + h.increment(0, 0); auto h2 = decltype(h)(h); BOOST_TEST(h2 == h); auto h3 = dynamic_histogram< @@ -139,7 +139,7 @@ int main() { { auto h = make_dynamic_histogram_with>(integer_axis(0, 1), integer_axis(0, 2)); - h.fill(0, 0); + h.increment(0, 0); auto h2 = decltype(h)(); BOOST_TEST(!(h == h2)); h2 = h; @@ -159,7 +159,7 @@ int main() { { auto h = make_dynamic_histogram(integer_axis(0, 1), integer_axis(0, 2)); - h.fill(0, 0); + h.increment(0, 0); const auto href = h; decltype(h) h2(std::move(h)); BOOST_TEST_EQ(h.dim(), 0u); @@ -195,13 +195,13 @@ int main() { auto d = make_dynamic_histogram(regular_axis(2, 0, 1)); BOOST_TEST(!(c == d)); BOOST_TEST(!(d == c)); - c.fill(0); + c.increment(0); BOOST_TEST(!(a == c)); BOOST_TEST(!(c == a)); - a.fill(0); + a.increment(0); BOOST_TEST(a == c); BOOST_TEST(c == a); - a.fill(0); + a.increment(0); BOOST_TEST(!(a == c)); BOOST_TEST(!(c == a)); } @@ -209,10 +209,10 @@ int main() { // d1 { auto h = make_dynamic_histogram(integer_axis(0, 1)); - h.fill(0); - h.fill(0); - h.fill(-1); - h.fill(10); + h.increment(0); + h.increment(0); + h.increment(-1); + h.increment(10); BOOST_TEST_EQ(h.dim(), 1u); BOOST_TEST_EQ(bins(h.axis(0)), 2); @@ -237,10 +237,10 @@ int main() { // d1_2 { auto h = make_dynamic_histogram(integer_axis(0, 1, "", false)); - h.fill(0); - h.fill(-0); - h.fill(-1); - h.fill(10); + h.increment(0); + h.increment(-0); + h.increment(-1); + h.increment(10); BOOST_TEST_EQ(h.dim(), 1u); BOOST_TEST_EQ(bins(h.axis(0)), 2); @@ -261,11 +261,11 @@ int main() { // d1w { auto h = make_dynamic_histogram(regular_axis(2, -1, 1)); - h.fill(0); - h.wfill(2, -1.0); - h.fill(-1.0); - h.fill(-2.0); - h.wfill(5, 10); + h.increment(0); + h.wincrement(2, -1.0); + h.increment(-1.0); + h.increment(-2.0); + h.wincrement(5, 10); BOOST_TEST_EQ(h.sum(), 10.0); @@ -284,12 +284,12 @@ int main() { { auto h = make_dynamic_histogram(regular_axis(2, -1, 1), integer_axis(-1, 1, nullptr, false)); - h.fill(-1, -1); - h.fill(-1, 0); + h.increment(-1, -1); + h.increment(-1, 0); std::array ai = {{-1., -10.}}; - h.fill(ai); + h.increment(ai); double in[2] = {-10., 0.}; - h.fill(in, in+2); + h.increment(in, in+2); BOOST_TEST_EQ(h.dim(), 2u); BOOST_TEST_EQ(bins(h.axis(0)), 2); @@ -335,10 +335,10 @@ int main() { { auto h = make_dynamic_histogram(regular_axis(2, -1, 1), integer_axis(-1, 1, nullptr, false)); - h.fill(-1, 0); // -> 0, 1 - h.wfill(10, -1, -1); // -> 0, 0 - h.wfill(5, -1, -10); // is ignored - h.wfill(7, -10, 0); // -> -1, 1 + h.increment(-1, 0); // -> 0, 1 + h.wincrement(10, -1, -1); // -> 0, 0 + h.wincrement(5, -1, -10); // is ignored + h.wincrement(7, -10, 0); // -> -1, 1 BOOST_TEST_EQ(h.sum(), 18.0); @@ -384,7 +384,7 @@ int main() { for (auto j = 0; j < bins(h.axis(1)); ++j) for (auto k = 0; k < bins(h.axis(2)); ++k) { - h.wfill(i+j+k, i, j, k); + h.wincrement(i+j+k, i, j, k); } for (auto i = 0; i < bins(h.axis(0)); ++i) @@ -412,8 +412,8 @@ int main() { mpl::vector, container_storage> >(integer_axis(-1, 1)); - a.fill(-1); - b.fill(1); + a.increment(-1); + b.increment(1); auto c = a; c += b; BOOST_TEST_EQ(c.value(-1), 0); @@ -435,8 +435,8 @@ int main() { auto a = make_dynamic_histogram(integer_axis(-1, 1)); auto b = make_dynamic_histogram(integer_axis(-1, 1)); - a.fill(0); - b.wfill(3, -1); + a.increment(0); + b.wincrement(3, -1); auto c = a; c += b; BOOST_TEST_EQ(c.value(-1), 0); @@ -457,8 +457,8 @@ int main() { { auto a = make_dynamic_histogram_with>>(integer_axis(-1, 1)); auto b = make_dynamic_histogram_with>>(integer_axis(-1, 1)); - a.fill(-1); - b.fill(1); + a.increment(-1); + b.increment(1); auto c = a; c += b; BOOST_TEST_EQ(c.value(-1), 0u); @@ -501,7 +501,7 @@ int main() { variable_axis({0.1, 0.2, 0.3, 0.4, 0.5}, "v"), category_axis{"A", "B", "C"}, integer_axis(0, 1, "i")); - a.fill(0.5, 0.1, 0.25, 1, 0); + a.increment(0.5, 0.1, 0.25, 1, 0); std::string buf; { std::ostringstream os; diff --git a/test/python_suite_test.py.in b/test/python_suite_test.py.in index d7ae9358..a6688154 100755 --- a/test/python_suite_test.py.in +++ b/test/python_suite_test.py.in @@ -349,17 +349,17 @@ class histogramest(unittest.TestCase): h1 = histogram(integer_axis(-1, 1, uoflow=True)) for h in (h0, h1): with self.assertRaises(RuntimeError): - h.fill() + h.increment() with self.assertRaises(RuntimeError): - h.fill(1, 2) - h.fill(-10) - h.fill(-1) - h.fill(-1) - h.fill(0) - h.fill(1) - h.fill(1) - h.fill(1) - h.fill(10) + h.increment(1, 2) + h.increment(-10) + h.increment(-1) + h.increment(-1) + h.increment(0) + h.increment(1) + h.increment(1) + h.increment(1) + h.increment(10) self.assertEqual(h0.sum, 6) self.assertEqual(h0.axis(0).shape, 3) self.assertEqual(h1.sum, 8) @@ -386,14 +386,14 @@ class histogramest(unittest.TestCase): def test_growth(self): h = histogram(integer_axis(-1, 1)) - h.fill(-1) - h.fill(1) - h.fill(1) + h.increment(-1) + h.increment(1) + h.increment(1) for i in range(255): - h.fill(0) - h.fill(0) + h.increment(0) + h.increment(0) for i in range(1000-256): - h.fill(0) + h.increment(0) self.assertEqual(h.value(-1), 0) self.assertEqual(h.value(0), 1) self.assertEqual(h.value(1), 1000) @@ -404,17 +404,17 @@ class histogramest(unittest.TestCase): for uoflow in (False, True): h = histogram(integer_axis(-1, 1, uoflow=uoflow), regular_axis(4, -2, 2, uoflow=uoflow)) - h.fill(-1, -2) - h.fill(-1, -1) - h.fill(0, 0) - h.fill(0, 1) - h.fill(1, 0) - h.fill(3, -1) - h.fill(0, -3) + h.increment(-1, -2) + h.increment(-1, -1) + h.increment(0, 0) + h.increment(0, 1) + h.increment(1, 0) + h.increment(3, -1) + h.increment(0, -3) with self.assertRaises(Exception): - h.fill(1) + h.increment(1) with self.assertRaises(Exception): - h.fill(1, 2, 3) + h.increment(1, 2, 3) m = [[1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 1], @@ -429,13 +429,13 @@ class histogramest(unittest.TestCase): for uoflow in (False, True): h = histogram(integer_axis(-1, 1, uoflow=uoflow), regular_axis(4, -2, 2, uoflow=uoflow)) - h.fill(-1, -2) - h.fill(-1, -1) - h.fill(0, 0) - h.fill(0, 1) - h.fill(1, 0) - h.fill(3, -1) - h.fill(0, -3) + h.increment(-1, -2) + h.increment(-1, -1) + h.increment(0, 0) + h.increment(0, 1) + h.increment(1, 0) + h.increment(3, -1) + h.increment(0, -3) m = [[1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 1], @@ -460,13 +460,13 @@ class histogramest(unittest.TestCase): for uoflow in (False, True): h = histogram(integer_axis(-1, 1, uoflow=uoflow), regular_axis(4, -2, 2, uoflow=uoflow)) - h.fill(-1, -2) - h.fill(-1, -1) - h.fill(0, 0) - h.fill(0, 1) - h.fill(1, 0) - h.fill(3, -1) - h.fill(0, -3) + h.increment(-1, -2) + h.increment(-1, -1) + h.increment(0, 0) + h.increment(0, 1) + h.increment(1, 0) + h.increment(3, -1) + h.increment(0, -3) m = [[1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 0, 1], @@ -476,7 +476,7 @@ class histogramest(unittest.TestCase): h2 = histogram(integer_axis(-1, 1, uoflow=uoflow), regular_axis(4, -2, 2, uoflow=uoflow)) - h2.fill(0, 0, w=0) + h2.increment(0, 0, w=0) h2 += h h2 += h @@ -495,15 +495,15 @@ class histogramest(unittest.TestCase): variable_axis(0.0, 1.0, 2.0), polar_axis(4, label='pa')) for i in range(a.axis(0).bins): - a.fill(i, 0, 0, 0, 0) + a.increment(i, 0, 0, 0, 0) for j in range(a.axis(1).bins): - a.fill(i, j, 0, 0, 0) + a.increment(i, j, 0, 0, 0) for k in range(a.axis(2).bins): - a.fill(i, j, k, 0, 0) + a.increment(i, j, k, 0, 0) for l in range(a.axis(3).bins): - a.fill(i, j, k, l, 0) + a.increment(i, j, k, l, 0) for m in range(a.axis(4).bins): - a.fill(i, j, k, l, m * 0.5 * pi) + a.increment(i, j, k, l, m * 0.5 * pi) io = BytesIO() pickle.dump(a, io) @@ -525,13 +525,13 @@ class histogramest(unittest.TestCase): regular_axis(4, 0.0, 4.0, uoflow=False), variable_axis(0.0, 1.0, 2.0)) for i in range(a.axis(0).bins): - a.fill(i, 0, 0, 0, w=3) + a.increment(i, 0, 0, 0, w=3) for j in range(a.axis(1).bins): - a.fill(i, j, 0, 0, w=10) + a.increment(i, j, 0, 0, w=10) for k in range(a.axis(2).bins): - a.fill(i, j, k, 0, w=2) + a.increment(i, j, k, 0, w=2) for l in range(a.axis(3).bins): - a.fill(i, j, k, l, w=5) + a.increment(i, j, k, l, w=5) io = BytesIO() pickle.dump(a, io) @@ -550,7 +550,7 @@ class histogramest(unittest.TestCase): def test_numpy_conversion_0(self): a = histogram(integer_axis(0, 2, uoflow=False)) for i in range(100): - a.fill(1) + a.increment(1) c = numpy.array(a) # a copy v = numpy.asarray(a) # a view @@ -559,12 +559,12 @@ class histogramest(unittest.TestCase): self.assertTrue(numpy.all(t == numpy.array((0, 100, 0)))) for i in range(100): - a.fill(1) + a.increment(1) self.assertTrue(numpy.all(c == numpy.array((0, 100, 0)))) self.assertTrue(numpy.all(v == numpy.array((0, 200, 0)))) for i in range(100): - a.fill(1) + a.increment(1) c = numpy.array(a) self.assertEqual(c.dtype, numpy.uint16) self.assertTrue(numpy.all(c == numpy.array((0, 300, 0)))) @@ -575,7 +575,7 @@ class histogramest(unittest.TestCase): def test_numpy_conversion_1(self): a = histogram(integer_axis(0, 2)) for i in range(10): - a.fill(1, w=3) + a.increment(1, w=3) c = numpy.array(a) # a copy v = numpy.asarray(a) # a view self.assertEqual(c.dtype, numpy.float64) @@ -592,7 +592,7 @@ class histogramest(unittest.TestCase): for j in range(a.axis(1).bins): for k in range(a.axis(2).bins): for m in range(i+j+k): - a.fill(i, j, k) + a.increment(i, j, k) r[i,j,k] = i+j+k c = numpy.array(a) # a copy v = numpy.asarray(a) # a view @@ -616,7 +616,7 @@ class histogramest(unittest.TestCase): for i in range(a.axis(0).bins): for j in range(a.axis(1).bins): for k in range(a.axis(2).bins): - a.fill(i, j, k, w=i+j+k) + a.increment(i, j, k, w=i+j+k) r[0, i, j, k] = i+j+k r[1, i, j, k] = (i+j+k)**2 c = numpy.array(a) # a copy @@ -636,7 +636,7 @@ class histogramest(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_bad_numpy_conversion(self): a = histogram(integer_axis(0, 0)) - a.fill(0) + a.increment(0) for i in xrange(80): a += a # a now holds a multiprecision type @@ -646,36 +646,36 @@ class histogramest(unittest.TestCase): @unittest.skipUnless(have_numpy, "requires build with numpy-support") def test_fill_with_numpy_array_0(self): a = histogram(integer_axis(0, 2, uoflow=False)) - a.fill(numpy.array([-1, 0, 1, 2, 1, 4])) - a.fill((-1, 0)) - a.fill([1, 2]) + a.increment(numpy.array([-1, 0, 1, 2, 1, 4])) + a.increment((-1, 0)) + a.increment([1, 2]) self.assertEqual(a.value(0), 2) self.assertEqual(a.value(1), 3) self.assertEqual(a.value(2), 2) with self.assertRaises(ValueError): - a.fill(numpy.empty((2, 2))) + a.increment(numpy.empty((2, 2))) with self.assertRaises(ValueError): - a.fill(numpy.empty((1, 2, 2))) + a.increment(numpy.empty((1, 2, 2))) with self.assertRaises(RuntimeError): - a.fill(numpy.empty((2, 1)), 1) + a.increment(numpy.empty((2, 1)), 1) with self.assertRaises(ValueError): - a.fill("abc") + a.increment("abc") a = histogram(integer_axis(0, 1, uoflow=False), regular_axis(2, 0, 2, uoflow=False)) - a.fill(numpy.array([[-1., -1.], [0., 1.], [1., 0.1]])) + a.increment(numpy.array([[-1., -1.], [0., 1.], [1., 0.1]])) self.assertEqual(a.value(0, 0), 0) self.assertEqual(a.value(0, 1), 1) self.assertEqual(a.value(1, 0), 1) self.assertEqual(a.value(1, 1), 0) with self.assertRaises(ValueError): - a.fill((1, 2, 3)) + a.increment((1, 2, 3)) a = histogram(integer_axis(0, 2, uoflow=False)) - a.fill([0, 0, 1, 2]) - a.fill((1, 0, 2, 2)) + a.increment([0, 0, 1, 2]) + a.increment((1, 0, 2, 2)) self.assertEqual(a.value(0), 3) self.assertEqual(a.value(1), 2) self.assertEqual(a.value(2), 3) @@ -686,8 +686,8 @@ class histogramest(unittest.TestCase): a = histogram(integer_axis(0, 2, uoflow=True)) v = numpy.array([-1, 0, 1, 2, 3, 4]) w = numpy.array([ 2, 3, 4, 5, 6, 7]) - a.fill(v, w=w) - a.fill([0, 1], w=[2.0, 3.0]) + a.increment(v, w=w) + a.increment([0, 1], w=[2.0, 3.0]) self.assertEqual(a.value(-1), 2) self.assertEqual(a.value(0), 5) self.assertEqual(a.value(1), 7) @@ -698,28 +698,28 @@ class histogramest(unittest.TestCase): self.assertEqual(a.variance(2), 25) with self.assertRaises(RuntimeError): - a.fill([1, 2], foo=[1, 1]) + a.increment([1, 2], foo=[1, 1]) with self.assertRaises(ValueError): - a.fill([1, 2], w=[1]) + a.increment([1, 2], w=[1]) with self.assertRaises(ValueError): - a.fill([1, 2], w="ab") + a.increment([1, 2], w="ab") with self.assertRaises(ValueError): - a.fill([1, 2], w=1) + a.increment([1, 2], w=1) with self.assertRaises(RuntimeError): - a.fill([1, 2], w=[1, 1], foo=1) + a.increment([1, 2], w=[1, 1], foo=1) with self.assertRaises(ValueError): - a.fill([1, 2], w=[[1, 1], [2, 2]]) + a.increment([1, 2], w=[[1, 1], [2, 2]]) a = histogram(integer_axis(0, 1, uoflow=False), regular_axis(2, 0, 2, uoflow=False)) - a.fill(numpy.array([[-1., -1.], [0., 1.], [1., 0.1]])) + a.increment(numpy.array([[-1., -1.], [0., 1.], [1., 0.1]])) self.assertEqual(a.value(0, 0), 0) self.assertEqual(a.value(0, 1), 1) self.assertEqual(a.value(1, 0), 1) self.assertEqual(a.value(1, 1), 0) a = histogram(integer_axis(0, 2, uoflow=False)) - a.fill([0, 0, 1, 2]) - a.fill((1, 0, 2, 2)) + a.increment([0, 0, 1, 2]) + a.increment((1, 0, 2, 2)) self.assertEqual(a.value(0), 3) self.assertEqual(a.value(1), 2) self.assertEqual(a.value(2), 3) diff --git a/test/speed_cpp.cpp b/test/speed_cpp.cpp index 3710c49b..e52339d6 100644 --- a/test/speed_cpp.cpp +++ b/test/speed_cpp.cpp @@ -46,7 +46,7 @@ double compare_1d(unsigned n, int distrib) auto h = Histogram(regular_axis(100, 0, 1)); auto t = clock(); for (unsigned i = 0; i < n; ++i) - h.fill(r[i]); + h.increment(r[i]); t = clock() - t; best = std::min(best, double(t) / CLOCKS_PER_SEC); } @@ -66,7 +66,7 @@ double compare_3d(unsigned n, int distrib) regular_axis(100, 0, 1)); auto t = clock(); for (unsigned i = 0; i < n; ++i) - h.fill(r[3 * i], r[3 * i + 1], r[3 * i + 2]); + h.increment(r[3 * i], r[3 * i + 1], r[3 * i + 2]); t = clock() - t; best = std::min(best, double(t) / CLOCKS_PER_SEC); } @@ -94,7 +94,7 @@ double compare_6d(unsigned n, int distrib) for (unsigned i = 0; i < n; ++i) { for (unsigned k = 0; k < 6; ++k) x[k] = r[6 * i + k]; - h.fill(x[0], x[1], x[2], x[3], x[4], x[5]); + h.increment(x[0], x[1], x[2], x[3], x[4], x[5]); } t = clock() - t; best = std::min(best, double(t) / CLOCKS_PER_SEC); diff --git a/test/speed_vs_numpy.py b/test/speed_vs_numpy.py index 169d34d3..fb5ff32b 100755 --- a/test/speed_vs_numpy.py +++ b/test/speed_vs_numpy.py @@ -26,7 +26,7 @@ def compare_1d(n, distrib): h = histogram(regular_axis(100, 0, 1)) t = timer() - h.fill(r) + h.increment(r) t = timer() - t best_boost = min(t, best_boost) assert(np.all(w == np.array(h)[:-2])) @@ -57,7 +57,7 @@ def compare_3d(n, distrib): regular_axis(100, 0, 1), regular_axis(100, 0, 1)) t = timer() - h.fill(r) + h.increment(r) t = timer() - t best_boost = min(t, best_boost) assert(np.all(w == np.array(h)[:-2,:-2,:-2])) @@ -95,7 +95,7 @@ def compare_6d(n, distrib): regular_axis(10, 0, 1), regular_axis(10, 0, 1)) t = timer() - h.fill(r) + h.increment(r) t = timer() - t best_boost = min(t, best_boost) assert(np.all(w == np.array(h)[:-2,:-2,:-2,:-2,:-2,:-2])) diff --git a/test/static_histogram_test.cpp b/test/static_histogram_test.cpp index 0a5a8897..725f088f 100644 --- a/test/static_histogram_test.cpp +++ b/test/static_histogram_test.cpp @@ -113,7 +113,7 @@ int main() { { auto h = make_static_histogram(integer_axis(0, 1), integer_axis(0, 2)); - h.fill(0, 0); + h.increment(0, 0); auto h2 = decltype(h)(h); BOOST_TEST(h2 == h); auto h3 = static_histogram< @@ -127,7 +127,7 @@ int main() { { auto h = make_static_histogram(integer_axis(0, 1), integer_axis(0, 2)); - h.fill(0, 0); + h.increment(0, 0); auto h2 = decltype(h)(); BOOST_TEST(!(h == h2)); h2 = h; @@ -147,7 +147,7 @@ int main() { { auto h = make_static_histogram(integer_axis(0, 1), integer_axis(0, 2)); - h.fill(0, 0); + h.increment(0, 0); const auto href = h; decltype(h) h2(std::move(h)); BOOST_TEST_EQ(h.dim(), 2); @@ -176,13 +176,13 @@ int main() { auto d = make_static_histogram(regular_axis(2, 0, 1)); BOOST_TEST(!(c == d)); BOOST_TEST(!(d == c)); - c.fill(0); + c.increment(0); BOOST_TEST(!(a == c)); BOOST_TEST(!(c == a)); - a.fill(0); + a.increment(0); BOOST_TEST(a == c); BOOST_TEST(c == a); - a.fill(0); + a.increment(0); BOOST_TEST(!(a == c)); BOOST_TEST(!(c == a)); } @@ -190,10 +190,10 @@ int main() { // d1 { auto h = make_static_histogram(integer_axis(0, 1)); - h.fill(0); - h.fill(0); - h.fill(-1); - h.fill(10); + h.increment(0); + h.increment(0); + h.increment(-1); + h.increment(10); BOOST_TEST_EQ(h.dim(), 1); BOOST_TEST_EQ(bins(h.axis<0>()), 2); @@ -218,10 +218,10 @@ int main() { // d1_2 { auto h = make_static_histogram(integer_axis(0, 1, "", false)); - h.fill(0); - h.fill(-0); - h.fill(-1); - h.fill(10); + h.increment(0); + h.increment(-0); + h.increment(-1); + h.increment(10); BOOST_TEST_EQ(h.dim(), 1); BOOST_TEST_EQ(bins(h.axis<0>()), 2); @@ -242,11 +242,11 @@ int main() { // d1w { auto h = make_static_histogram(regular_axis(2, -1, 1)); - h.fill(0); - h.wfill(2.0, -1.0); - h.fill(-1.0); - h.fill(-2.0); - h.wfill(5.0, 10.0); + h.increment(0); + h.wincrement(2.0, -1.0); + h.increment(-1.0); + h.increment(-2.0); + h.wincrement(5.0, 10.0); BOOST_TEST_EQ(h.sum(), 10); @@ -265,12 +265,12 @@ int main() { { auto h = make_static_histogram(regular_axis(2, -1, 1), integer_axis(-1, 1, "", false)); - h.fill(-1, -1); - h.fill(-1, 0); + h.increment(-1, -1); + h.increment(-1, 0); std::array ai = {{-1., -10.}}; - h.fill(ai); + h.increment(ai); double in[2] = {-10., 0.}; - h.fill(in, in+2); + h.increment(in, in+2); BOOST_TEST_EQ(h.dim(), 2); BOOST_TEST_EQ(bins(h.axis<0>()), 2); @@ -316,10 +316,10 @@ int main() { { auto h = make_static_histogram(regular_axis(2, -1, 1), integer_axis(-1, 1, "", false)); - h.fill(-1, 0); // -> 0, 1 - h.wfill(10, -1, -1); // -> 0, 0 - h.wfill(5, -1, -10); // is ignored - h.wfill(7, -10, 0); // -> -1, 1 + h.increment(-1, 0); // -> 0, 1 + h.wincrement(10, -1, -1); // -> 0, 0 + h.wincrement(5, -1, -10); // is ignored + h.wincrement(7, -10, 0); // -> -1, 1 BOOST_TEST_EQ(h.sum(), 18); @@ -365,7 +365,7 @@ int main() { for (auto j = 0; j < bins(h.axis<1>()); ++j) for (auto k = 0; k < bins(h.axis<2>()); ++k) { - h.wfill(i+j+k, i, j, k); + h.wincrement(i+j+k, i, j, k); } for (auto i = 0; i < bins(h.axis<0>()); ++i) @@ -382,8 +382,8 @@ int main() { auto b = make_static_histogram_with< container_storage> >(integer_axis(-1, 1)); - a.fill(-1); - b.fill(1); + a.increment(-1); + b.increment(1); auto c = a; c += b; BOOST_TEST_EQ(c.value(-1), 0); @@ -409,8 +409,8 @@ int main() { adaptive_storage<> >(integer_axis(-1, 1)); - a.fill(0); - b.wfill(3, -1); + a.increment(0); + b.wincrement(3, -1); auto c = a; c += b; BOOST_TEST_EQ(c.value(-1), 0); @@ -435,8 +435,8 @@ int main() { auto b = make_static_histogram_with< container_storage> >(integer_axis(-1, 1)); - a.fill(-1); - b.fill(1); + a.increment(-1); + b.increment(1); auto c = a; c += b; BOOST_TEST_EQ(c.value(-1), 0); @@ -478,15 +478,15 @@ int main() { auto h = bh::make_static_histogram(bh::regular_axis(10, -1.0, 2.0, "x")); // fill histogram with data - h.fill(-1.5); // put in underflow bin - h.fill(-1.0); // included in first bin, bin interval is semi-open - h.fill(-0.5); - h.fill(1.1); - h.fill(0.3); - h.fill(1.7); - h.fill(2.0); // put in overflow bin, bin interval is semi-open - h.fill(20.0); // put in overflow bin - h.wfill(5.0, 0.1); // fill with a weighted entry, weight is 5.0 + h.increment(-1.5); // put in underflow bin + h.increment(-1.0); // included in first bin, bin interval is semi-open + h.increment(-0.5); + h.increment(1.1); + h.increment(0.3); + h.increment(1.7); + h.increment(2.0); // put in overflow bin, bin interval is semi-open + h.increment(20.0); // put in overflow bin + h.wincrement(5.0, 0.1); // fill with a weighted entry, weight is 5.0 std::ostringstream os1; // access histogram counts @@ -522,7 +522,7 @@ int main() { variable_axis({0.1, 0.2, 0.3, 0.4, 0.5}, "v"), category_axis{"A", "B", "C"}, integer_axis(0, 1, "i")); - a.fill(0.5, 0.1, 0.25, 1, 0); + a.increment(0.5, 0.1, 0.25, 1, 0); std::string buf; { std::ostringstream os;