Skip to content

Commit

Permalink
Merge 0a1a83a into 4736fe7
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Jun 24, 2020
2 parents 4736fe7 + 0a1a83a commit d6fbecf
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 42 deletions.
7 changes: 7 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ install:
- sh: rm -rf libs/histogram ; mv $APPVEYOR_BUILD_FOLDER libs/histogram
- sh: python3 tools/boostdep/depinst/depinst.py --git_args "--depth 5 --jobs 2" histogram

# use hdembinski/serialization due to frequent errors in boostorg/serialization
- cd libs/serialization
- git remote add patch https://github.com/HDembinski/serialization.git
- git fetch patch
- git checkout patch/boost_histogram
- cd ../..

# prepare Boost build
- cmd: cmd /c bootstrap & b2 headers & cd libs\histogram
- sh: ./bootstrap.sh; ./b2 headers; cd libs/histogram
Expand Down
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ matrix:
- mv $TRAVIS_BUILD_DIR libs/histogram
- python3 tools/boostdep/depinst/depinst.py --git_args "--depth 5 --jobs 3" histogram

# use hdembinski/serialization due to frequent errors in boostorg/serialization
- cd libs/serialization
- git remote add patch https://github.com/HDembinski/serialization.git
- git fetch patch
- git checkout patch/boost_histogram
- cd ../..

# prepare build
- ./bootstrap.sh
- ./b2 headers
Expand Down
6 changes: 3 additions & 3 deletions benchmark/axis_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static void category(benchmark::State& state) {
for (auto _ : state) benchmark::DoNotOptimize(a.index(gen()));
}

static void binary(benchmark::State& state) {
auto a = axis::binary<>();
static void boolean(benchmark::State& state) {
auto a = axis::boolean<>();
generator<uniform_int> gen(1);
for (auto _ : state) benchmark::DoNotOptimize(a.index(static_cast<bool>(gen())));
}
Expand All @@ -74,4 +74,4 @@ BENCHMARK_TEMPLATE(integer, double, normal);
BENCHMARK_TEMPLATE(variable, uniform)->RangeMultiplier(10)->Range(10, 10000);
BENCHMARK_TEMPLATE(variable, normal)->RangeMultiplier(10)->Range(10, 10000);
BENCHMARK(category)->RangeMultiplier(10)->Range(10, 10000);
BENCHMARK(binary);
BENCHMARK(boolean);
10 changes: 5 additions & 5 deletions benchmark/axis_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ int main() {
using variable = axis::variable<>;
using integer = axis::integer<>;
using category = axis::category<>;
using binary = axis::binary<>;
using binary_no_metadata = axis::binary<axis::null_type>;
using variant = axis::variant<regular, circular, variable, integer, category, binary>;
using boolean = axis::boolean<>;
using boolean_no_metadata = axis::boolean<axis::null_type>;
using variant = axis::variant<regular, circular, variable, integer, category, boolean>;

SHOW_SIZE(regular);
SHOW_SIZE(regular_float);
Expand All @@ -32,7 +32,7 @@ int main() {
SHOW_SIZE(variable);
SHOW_SIZE(integer);
SHOW_SIZE(category);
SHOW_SIZE(binary);
SHOW_SIZE(binary_no_metadata);
SHOW_SIZE(boolean);
SHOW_SIZE(boolean_no_metadata);
SHOW_SIZE(variant);
}
2 changes: 1 addition & 1 deletion doc/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ doxygen reference

actions doxygen-postprocessing
{
python $(THIS_PATH)/doxygen_postprocessing.py "$(>)"
python3 $(THIS_PATH)/doxygen_postprocessing.py "$(>)"
}

notfile reference-pp : @doxygen-postprocessing : reference.xml ;
Expand Down
1 change: 1 addition & 0 deletions doc/concepts/Axis.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ An [*Axis] maps input values to indices. It holds state specific to that axis, l

[heading Models]

* [classref boost::histogram::axis::boolean]
* [classref boost::histogram::axis::category]
* [classref boost::histogram::axis::integer]
* [classref boost::histogram::axis::regular]
Expand Down
10 changes: 9 additions & 1 deletion doc/guide.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ The library provides a number of useful axis types. The builtin axis types can b
Axis over an integer sequence [i, i+1, i+2, ...]. It can be configured to handle real input values, too, and then acts like a fast regular axis with a fixed bin width of 1. Value-to-index conversion is O(1) and faster than for the [classref boost::histogram::axis::regular regular] axis. Does not allocate memory dynamically. Use this when your input consists of an integer range or pre-digitized values with low dynamic range, like pixel values for individual colours in an image.
]
]
[
[
[classref boost::histogram::axis::boolean boolean]
]
[
Axis over the two values [false, true]. It is a common specialization of the [classref boost::histogram::axis::regular regular] axis. Value-to-index conversion is a pass-through operation, so this is the fastest possible axis. The axis has no state other than the metadata (which can be stateless). Does not allocate memory dynamically. Use this when your input consists of binary categories, like signal and background.
]
]
[
[
[classref boost::histogram::axis::category category]
Expand Down Expand Up @@ -341,7 +349,7 @@ boost::histogram::histogram<
, boost::histogram::default_storage
>
```
* Histogram with variable axis types:
* Histogram with variable axis types:
```
boost::histogram::histogram<
std::vector<
Expand Down
2 changes: 1 addition & 1 deletion include/boost/histogram/axis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[1]: histogram/reference.html#header.boost.histogram.axis.ostream_hpp
*/

#include <boost/histogram/axis/binary.hpp>
#include <boost/histogram/axis/boolean.hpp>
#include <boost/histogram/axis/category.hpp>
#include <boost/histogram/axis/integer.hpp>
#include <boost/histogram/axis/regular.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_HISTOGRAM_AXIS_BINARY_HPP
#define BOOST_HISTOGRAM_AXIS_BINARY_HPP
#ifndef BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP
#define BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP

#include <boost/core/nvp.hpp>
#include <boost/histogram/axis/iterator.hpp>
Expand All @@ -20,13 +20,14 @@ namespace histogram {
namespace axis {

template <class MetaData>
class binary : public iterator_mixin<binary<MetaData>>, public metadata_base_t<MetaData> {
class boolean : public iterator_mixin<boolean<MetaData>>,
public metadata_base_t<MetaData> {
using value_type = bool;
using metadata_base = metadata_base_t<MetaData>;
using metadata_type = typename metadata_base::metadata_type;

public:
explicit binary(metadata_type meta = {}) : metadata_base(std::move(meta)) {}
explicit boolean(metadata_type meta = {}) : metadata_base(std::move(meta)) {}

index_type index(value_type x) const noexcept { return static_cast<index_type>(x); }

Expand All @@ -39,12 +40,12 @@ class binary : public iterator_mixin<binary<MetaData>>, public metadata_base_t<M
static constexpr bool inclusive() noexcept { return true; }

template <class M>
bool operator==(const binary<M>& o) const noexcept {
bool operator==(const boolean<M>& o) const noexcept {
return detail::relaxed_equal{}(this->metadata(), o.metadata());
}

template <class M>
bool operator!=(const binary<M>& o) const noexcept {
bool operator!=(const boolean<M>& o) const noexcept {
return !operator==(o);
}

Expand All @@ -55,20 +56,20 @@ class binary : public iterator_mixin<binary<MetaData>>, public metadata_base_t<M

private:
template <class M>
friend class binary;
friend class boolean;
};

#if __cpp_deduction_guides >= 201606

binary()->binary<null_type>;
boolean()->boolean<null_type>;

template <class M>
binary(M)->binary<detail::replace_type<std::decay_t<M>, const char*, std::string>>;
boolean(M) -> boolean<detail::replace_type<std::decay_t<M>, const char*, std::string>>;

#endif

} // namespace axis
} // namespace histogram
} // namespace boost

#endif // BOOST_HISTOGRAM_AXIS_BINARY_HPP
#endif // BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP
5 changes: 3 additions & 2 deletions include/boost/histogram/axis/ostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ std::basic_ostream<Ts...>& operator<<(std::basic_ostream<Ts...>& os,
}

template <class... Ts, class M>
std::basic_ostream<Ts...>& operator<<(std::basic_ostream<Ts...>& os, const binary<M>& a) {
os << "binary(";
std::basic_ostream<Ts...>& operator<<(std::basic_ostream<Ts...>& os,
const boolean<M>& a) {
os << "boolean(";
detail::ostream_metadata(os, a.metadata(), "");
return os << ")";
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/histogram/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ template <class Value = int, class MetaData = use_default, class Options = use_d
class category;

template <class MetaData = use_default>
class binary;
class boolean;

template <class... Ts>
class variant;
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ boost_test(TYPE run SOURCES algorithm_project_test.cpp)
boost_test(TYPE run SOURCES algorithm_reduce_test.cpp)
boost_test(TYPE run SOURCES algorithm_sum_test.cpp)
boost_test(TYPE run SOURCES algorithm_empty_test.cpp)
boost_test(TYPE run SOURCES axis_binary_test.cpp)
boost_test(TYPE run SOURCES axis_boolean_test.cpp)
boost_test(TYPE run SOURCES axis_category_test.cpp)
boost_test(TYPE run SOURCES axis_integer_test.cpp)
boost_test(TYPE run SOURCES axis_option_test.cpp)
Expand Down
2 changes: 1 addition & 1 deletion test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ alias cxx14 :
[ run algorithm_reduce_test.cpp ]
[ run algorithm_sum_test.cpp ]
[ run algorithm_empty_test.cpp ]
[ run axis_binary_test.cpp ]
[ run axis_boolean_test.cpp ]
[ run axis_category_test.cpp ]
[ run axis_integer_test.cpp ]
[ run axis_option_test.cpp ]
Expand Down
20 changes: 10 additions & 10 deletions test/axis_binary_test.cpp → test/axis_boolean_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/core/lightweight_test.hpp>
#include <boost/histogram/axis/binary.hpp>
#include <boost/histogram/axis/boolean.hpp>
#include <boost/histogram/axis/ostream.hpp>
#include <limits>
#include <sstream>
Expand All @@ -18,12 +18,12 @@
int main() {
using namespace boost::histogram;

BOOST_TEST(std::is_nothrow_move_assignable<axis::binary<>>::value);
BOOST_TEST(std::is_nothrow_move_constructible<axis::binary<>>::value);
BOOST_TEST(std::is_nothrow_move_assignable<axis::boolean<>>::value);
BOOST_TEST(std::is_nothrow_move_constructible<axis::boolean<>>::value);

// axis::integer with double type
{
axis::binary<> a{"foo"};
axis::boolean<> a{"foo"};
BOOST_TEST_EQ(a.metadata(), "foo");
a.metadata() = "bar";
const auto& cref = a;
Expand All @@ -36,24 +36,24 @@ int main() {
BOOST_TEST_EQ(a.index(1), 1);
BOOST_TEST_EQ(a.index(0), 0);

BOOST_TEST_CSTR_EQ(str(a).c_str(), "binary(metadata=\"foo\")");
BOOST_TEST_CSTR_EQ(str(a).c_str(), "boolean(metadata=\"foo\")");

axis::binary<> b;
BOOST_TEST_CSTR_EQ(str(b).c_str(), "binary()");
axis::boolean<> b;
BOOST_TEST_CSTR_EQ(str(b).c_str(), "boolean()");

BOOST_TEST_NE(a, b);
b = a;
BOOST_TEST_EQ(a, b);
axis::binary<> c = std::move(b);
axis::boolean<> c = std::move(b);
BOOST_TEST_EQ(c, a);
axis::binary<> d;
axis::boolean<> d;
BOOST_TEST_NE(c, d);
d = std::move(c);
BOOST_TEST_EQ(d, a);
}

// iterators
test_axis_iterator(axis::binary<>(), 0, 2);
test_axis_iterator(axis::boolean<>(), 0, 2);

return boost::report_errors();
}
6 changes: 3 additions & 3 deletions test/axis_variant_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int main() {
test(axis::regular<>{2, -1, 1, "foo"},
"regular(2, -1, 1, metadata=\"foo\", options=underflow | overflow)");

test(axis::binary<>{"bar"}, "binary(metadata=\"bar\")");
test(axis::boolean<>{"bar"}, "boolean(metadata=\"bar\")");

struct user_defined {};
const auto ref = "integer(-1, 1, metadata=" + detail::type_name<user_defined>() +
Expand All @@ -154,13 +154,13 @@ int main() {
enum { A, B, C };
using variant =
axis::variant<axis::regular<>, axis::regular<double, axis::transform::pow>,
axis::category<>, axis::integer<>, axis::binary<>>;
axis::category<>, axis::integer<>, axis::boolean<>>;
std::vector<variant> axes;
axes.push_back(axis::regular<>{2, -1, 1});
axes.push_back(axis::regular<double, tr::pow>{tr::pow{0.5}, 2, 1, 4});
axes.push_back(axis::category<>{A, B, C});
axes.push_back(axis::integer<>{-1, 1});
axes.push_back(axis::binary<>{});
axes.push_back(axis::boolean<>{});
for (const auto& a : axes) {
BOOST_TEST_NE(a, variant{});
BOOST_TEST_EQ(a, variant(a));
Expand Down
6 changes: 3 additions & 3 deletions test/deduction_guides_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ int main() {
}

{
using axis::binary;
BOOST_TEST_TRAIT_SAME(decltype(binary{}), binary<null_type>);
BOOST_TEST_TRAIT_SAME(decltype(binary{"foo"}), binary<std::string>);
using axis::boolean;
BOOST_TEST_TRAIT_SAME(decltype(boolean{}), boolean<null_type>);
BOOST_TEST_TRAIT_SAME(decltype(boolean{"foo"}), boolean<std::string>);
}

{
Expand Down

0 comments on commit d6fbecf

Please sign in to comment.