mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-09 23:04:07 +00:00
rename binary to boolean (#126)
This commit is contained in:
parent
4736fe761f
commit
5e60e86d3c
@ -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
|
||||
|
@ -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
|
||||
|
@ -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())));
|
||||
}
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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 ;
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
@ -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<
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
@ -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); }
|
||||
|
||||
@ -39,12 +40,12 @@ public:
|
||||
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);
|
||||
}
|
||||
|
||||
@ -55,15 +56,15 @@ public:
|
||||
|
||||
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
|
||||
|
||||
@ -71,4 +72,4 @@ binary(M)->binary<detail::replace_type<std::decay_t<M>, const char*, std::string
|
||||
} // namespace histogram
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_HISTOGRAM_AXIS_BINARY_HPP
|
||||
#endif // BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP
|
@ -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 << ")";
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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 ]
|
||||
|
@ -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>
|
||||
@ -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;
|
||||
@ -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();
|
||||
}
|
@ -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>() +
|
||||
@ -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));
|
||||
|
@ -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>);
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user