From a1dcb7afd570824987be666121e4763ac47bc7a3 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 16 Jun 2021 16:25:58 -0400 Subject: [PATCH 1/3] fix: add a little extra testing for repr and empty axes --- .pre-commit-config.yaml | 2 +- tests/test_axis.py | 2 ++ tests/test_histogram.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cdb398ec8..461a6201e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -74,7 +74,7 @@ repos: - id: mypy files: src args: [] - additional_dependencies: [numpy==1.20.1, uhi==0.2.1, types-dataclasses==0.1.3] + additional_dependencies: [numpy, uhi, types-dataclasses] - repo: https://github.com/mgedmin/check-manifest rev: "0.46" diff --git a/tests/test_axis.py b/tests/test_axis.py index b72c90939..2b89b0c95 100644 --- a/tests/test_axis.py +++ b/tests/test_axis.py @@ -35,8 +35,10 @@ (bh.axis.Integer, (1, 2), "", {"circular": True}), (bh.axis.IntCategory, ((1, 2, 3),), "", {}), (bh.axis.IntCategory, ((1, 2, 3),), "g", {}), + (bh.axis.IntCategory, ((),), "g", {}), (bh.axis.StrCategory, (tuple("ABC"),), "", {}), (bh.axis.StrCategory, (tuple("ABC"),), "g", {}), + (bh.axis.StrCategory, ((),), "g", {}), ], ) def test_metadata(axis, args, opt, kwargs): diff --git a/tests/test_histogram.py b/tests/test_histogram.py index c4a849cd3..d2bea341b 100644 --- a/tests/test_histogram.py +++ b/tests/test_histogram.py @@ -1234,3 +1234,13 @@ def test_np_scalars(): hist /= np.float64(2.0) assert hist[bh.loc(7)] == 1.0 + + +def test_sum_empty_axis(): + hist = bh.Histogram( + bh.axis.StrCategory("", growth=True), + bh.axis.Regular(10, 0, 1), + storage=bh.storage.Weight(), + ) + assert hist.sum().value == 0 + assert "Str" in repr(hist) From 7d7d22783b66cb15e817d91bb284155daf6b9b8b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 16 Jun 2021 16:52:46 -0400 Subject: [PATCH 2/3] chore: supply a little helper for checking C++ boost-histogram --- examples/cpp/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ examples/cpp/simple.cpp | 11 +++++++++++ 2 files changed, 42 insertions(+) create mode 100644 examples/cpp/CMakeLists.txt create mode 100644 examples/cpp/simple.cpp diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt new file mode 100644 index 000000000..d4251f86f --- /dev/null +++ b/examples/cpp/CMakeLists.txt @@ -0,0 +1,31 @@ +# This file lets you quickly build projects with the exact same boost-histogram +# settings that the Python bindings use. + +cmake_minimum_required(VERSION 3.14...3.20) + +project(BOOST_HISTOGRAM_CPP LANGUAGES CXX) + + +add_library(boost_histogram_cpp IMPORTED INTERFACE) + +# these are the boost header-only libraries required by boost::histogram +target_include_directories( + boost_histogram_cpp + INTERFACE ../../extern/assert/include + ../../extern/config/include + ../../extern/core/include + ../../extern/histogram/include + ../../extern/mp11/include + ../../extern/throw_exception/include + ../../extern/variant2/include) + + +target_compile_options(boost_histogram_cpp + INTERFACE $,/fp:fast,-funsafe-math-optimizations>) + +target_compile_features(boost_histogram_cpp INTERFACE cxx_std_14) + +if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) + add_executable(simple simple.cpp) + target_link_libraries(simple PRIVATE boost_histogram_cpp) +endif() diff --git a/examples/cpp/simple.cpp b/examples/cpp/simple.cpp new file mode 100644 index 000000000..68ff758b8 --- /dev/null +++ b/examples/cpp/simple.cpp @@ -0,0 +1,11 @@ +#include +#include + +int main() { + namespace bh = boost::histogram; + + auto h = bh::make_histogram(bh::axis::category{}); + + std::cout << bh::algorithm::sum(h) << std::endl; +} + From cd646a2dbf2e527eaf4b08066ee1ddc23acf179b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 16 Jun 2021 22:25:30 -0400 Subject: [PATCH 3/3] style: run pre-commit --- examples/cpp/CMakeLists.txt | 6 ++---- examples/cpp/simple.cpp | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index d4251f86f..21f4987dd 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -5,7 +5,6 @@ cmake_minimum_required(VERSION 3.14...3.20) project(BOOST_HISTOGRAM_CPP LANGUAGES CXX) - add_library(boost_histogram_cpp IMPORTED INTERFACE) # these are the boost header-only libraries required by boost::histogram @@ -19,9 +18,8 @@ target_include_directories( ../../extern/throw_exception/include ../../extern/variant2/include) - -target_compile_options(boost_histogram_cpp - INTERFACE $,/fp:fast,-funsafe-math-optimizations>) +target_compile_options( + boost_histogram_cpp INTERFACE $,/fp:fast,-funsafe-math-optimizations>) target_compile_features(boost_histogram_cpp INTERFACE cxx_std_14) diff --git a/examples/cpp/simple.cpp b/examples/cpp/simple.cpp index 68ff758b8..3189b4e2a 100644 --- a/examples/cpp/simple.cpp +++ b/examples/cpp/simple.cpp @@ -2,10 +2,9 @@ #include int main() { - namespace bh = boost::histogram; + namespace bh = boost::histogram; - auto h = bh::make_histogram(bh::axis::category{}); + auto h = bh::make_histogram(bh::axis::category{}); - std::cout << bh::algorithm::sum(h) << std::endl; + std::cout << bh::algorithm::sum(h) << std::endl; } -