diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt index 92525b05..7f94c103 100644 --- a/CMake/CMakeLists.txt +++ b/CMake/CMakeLists.txt @@ -12,7 +12,7 @@ find_package(Numpy) # optional include_directories(include ${Boost_INCLUDE_DIRS}) add_definitions(-DBOOST_TEST_DYN_LINK) # for unit_test_framework -set(LIBRARIES stdc++ ${Boost_LIBRARIES}) +set(LIBRARIES stdc++ m ${Boost_LIBRARIES}) if(Boost_PYTHON_FOUND AND PYTHONLIBS_FOUND) set(USE_PYTHON True) @@ -75,6 +75,11 @@ add_executable(zero_suppression_test target_link_libraries(zero_suppression_test histogram ${LIBRARIES}) add_test(zero_suppression_test zero_suppression_test) +add_executable(histogram_test + test/histogram_test.cpp) +target_link_libraries(histogram_test histogram ${LIBRARIES}) +add_test(histogram_test histogram_test) + if(Boost_PYTHON_FOUND) add_custom_target(python_suite_test ALL cp ${CMAKE_SOURCE_DIR}/test/python_suite_test.py .) diff --git a/examples/speed_vs_root.cpp b/examples/speed_vs_root.cpp index 499edb87..4ce0c8a2 100644 --- a/examples/speed_vs_root.cpp +++ b/examples/speed_vs_root.cpp @@ -124,13 +124,13 @@ void compare_6d(unsigned n) regular_axis(10, 0, 1), regular_axis(10, 0, 1), regular_axis(10, 0, 1)); - boost::array y; + double y[6]; t = clock(); for (unsigned i = 0; i < n; ++i) { for (unsigned k = 0; k < 6; ++k) y[k] = r[6 * i + k]; - h.fill(y); + h.fill(6, y); } t = clock() - t; best_boost = std::min(best_boost, double(t) / CLOCKS_PER_SEC); diff --git a/include/boost/histogram/histogram.hpp b/include/boost/histogram/histogram.hpp index 41d82e54..ed817406 100644 --- a/include/boost/histogram/histogram.hpp +++ b/include/boost/histogram/histogram.hpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -28,15 +30,16 @@ public: // generates constructors taking 1 to AXIS_LIMIT arguments BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil) - template - inline - void fill(const Container& v) - { - BOOST_ASSERT(v.size() == dim()); - const size_type k = pos(v); - if (k != uintmax_t(-1)) - data_.increase(k); - } + // template + // inline + // void + // fill(const C& v) + // { + // BOOST_ASSERT(v.size() == dim()); + // const size_type k = pos(v); + // if (k != uintmax_t(-1)) + // data_.increase(k); + // } // C-style call inline @@ -59,15 +62,15 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil // generates fill functions taking 1 to AXIS_LIMT arguments BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_FILL, nil) - template - inline - void wfill(const Container& v, double w) - { - BOOST_ASSERT(v.size() == dim()); - const size_type k = pos(v); - if (k != uintmax_t(-1)) - data_.increase(k, w); - } + // template + // inline + // void wfill(const Container& v, double w) + // { + // BOOST_ASSERT(v.size() == dim()); + // const size_type k = pos(v); + // if (k != uintmax_t(-1)) + // data_.increase(k, w); + // } // C-style call inline @@ -90,14 +93,14 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_FILL, nil // generates wfill functions taking 1 to AXIS_LIMT arguments BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, nil) - template - inline - double value(const Container& idx) - const - { - BOOST_ASSERT(idx.size() == dim()); - return data_.value(linearize(idx)); - } + // template + // inline + // double value(const Container& idx) + // const + // { + // BOOST_ASSERT(idx.size() == dim()); + // return data_.value(linearize(idx)); + // } // C-style call inline @@ -120,14 +123,14 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, ni // generates value functions taking 1 to AXIS_LIMT arguments BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VALUE, nil) - template - inline - double variance(const Container& idx) - const - { - BOOST_ASSERT(idx.size() == dim()); - return data_.variance(linearize(idx)); - } + // template + // inline + // double variance(const Container& idx) + // const + // { + // BOOST_ASSERT(idx.size() == dim()); + // return data_.variance(linearize(idx)); + // } // C-style call inline diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp new file mode 100644 index 00000000..fb7d862a --- /dev/null +++ b/test/histogram_test.cpp @@ -0,0 +1,81 @@ +#include +#define BOOST_TEST_MODULE histogram_test +#include +#include +#include +using namespace boost::assign; +using namespace boost::histogram; +namespace tt = boost::test_tools; + +BOOST_AUTO_TEST_CASE(init_0) +{ + histogram(); +} + +BOOST_AUTO_TEST_CASE(init_1) +{ + histogram(regular_axis(3, -1, 1)); +} + +BOOST_AUTO_TEST_CASE(init_2) +{ + histogram(regular_axis(3, -1, 1), + integer_axis(-1, 1)); +} + +BOOST_AUTO_TEST_CASE(init_3) +{ + histogram(regular_axis(3, -1, 1), + integer_axis(-1, 1), + polar_axis(3)); +} + +BOOST_AUTO_TEST_CASE(init_4) +{ + std::vector x; + x += -1, 0, 1; + histogram(regular_axis(3, -1, 1), + integer_axis(-1, 1), + polar_axis(3), + variable_axis(x)); +} + +BOOST_AUTO_TEST_CASE(init_5) +{ + std::vector x; + x += -1, 0, 1; + histogram(regular_axis(3, -1, 1), + integer_axis(-1, 1), + polar_axis(3), + variable_axis(x), + category_axis("A;B;C")); +} + +BOOST_AUTO_TEST_CASE(init_15) +{ + std::vector x; + x += -1, 0, 1, 2, 3; + histogram(regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1), + regular_axis(1, -1, 1)); +} + +BOOST_AUTO_TEST_CASE(fill_1) +{ + histogram h(regular_axis(3, -1, 1)); + h.fill(1); +}