Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 $<IF:$<CXX_COMPILER_ID:MSVC>,/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()
10 changes: 10 additions & 0 deletions examples/cpp/simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <boost/histogram.hpp>
#include <iostream>

int main() {
namespace bh = boost::histogram;

auto h = bh::make_histogram(bh::axis::category<int>{});

std::cout << bh::algorithm::sum(h) << std::endl;
}
2 changes: 2 additions & 0 deletions tests/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)