Skip to content

Commit 50a2f2f

Browse files
authored
chore: example of Boost.Histogram build for quick testing (#591)
* fix: add a little extra testing for repr and empty axes * chore: supply a little helper for checking C++ boost-histogram * style: run pre-commit
1 parent 573c024 commit 50a2f2f

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ repos:
7474
- id: mypy
7575
files: src
7676
args: []
77-
additional_dependencies: [numpy==1.20.1, uhi==0.2.1, types-dataclasses==0.1.3]
77+
additional_dependencies: [numpy, uhi, types-dataclasses]
7878

7979
- repo: https://github.com/mgedmin/check-manifest
8080
rev: "0.46"

examples/cpp/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file lets you quickly build projects with the exact same boost-histogram
2+
# settings that the Python bindings use.
3+
4+
cmake_minimum_required(VERSION 3.14...3.20)
5+
6+
project(BOOST_HISTOGRAM_CPP LANGUAGES CXX)
7+
8+
add_library(boost_histogram_cpp IMPORTED INTERFACE)
9+
10+
# these are the boost header-only libraries required by boost::histogram
11+
target_include_directories(
12+
boost_histogram_cpp
13+
INTERFACE ../../extern/assert/include
14+
../../extern/config/include
15+
../../extern/core/include
16+
../../extern/histogram/include
17+
../../extern/mp11/include
18+
../../extern/throw_exception/include
19+
../../extern/variant2/include)
20+
21+
target_compile_options(
22+
boost_histogram_cpp INTERFACE $<IF:$<CXX_COMPILER_ID:MSVC>,/fp:fast,-funsafe-math-optimizations>)
23+
24+
target_compile_features(boost_histogram_cpp INTERFACE cxx_std_14)
25+
26+
if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
27+
add_executable(simple simple.cpp)
28+
target_link_libraries(simple PRIVATE boost_histogram_cpp)
29+
endif()

examples/cpp/simple.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <boost/histogram.hpp>
2+
#include <iostream>
3+
4+
int main() {
5+
namespace bh = boost::histogram;
6+
7+
auto h = bh::make_histogram(bh::axis::category<int>{});
8+
9+
std::cout << bh::algorithm::sum(h) << std::endl;
10+
}

tests/test_axis.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
(bh.axis.Integer, (1, 2), "", {"circular": True}),
3636
(bh.axis.IntCategory, ((1, 2, 3),), "", {}),
3737
(bh.axis.IntCategory, ((1, 2, 3),), "g", {}),
38+
(bh.axis.IntCategory, ((),), "g", {}),
3839
(bh.axis.StrCategory, (tuple("ABC"),), "", {}),
3940
(bh.axis.StrCategory, (tuple("ABC"),), "g", {}),
41+
(bh.axis.StrCategory, ((),), "g", {}),
4042
],
4143
)
4244
def test_metadata(axis, args, opt, kwargs):

tests/test_histogram.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,3 +1234,13 @@ def test_np_scalars():
12341234

12351235
hist /= np.float64(2.0)
12361236
assert hist[bh.loc(7)] == 1.0
1237+
1238+
1239+
def test_sum_empty_axis():
1240+
hist = bh.Histogram(
1241+
bh.axis.StrCategory("", growth=True),
1242+
bh.axis.Regular(10, 0, 1),
1243+
storage=bh.storage.Weight(),
1244+
)
1245+
assert hist.sum().value == 0
1246+
assert "Str" in repr(hist)

0 commit comments

Comments
 (0)