/
usr
/
include
/
boost
/
histogram
/
detail
/
/usr/include/boost/histogram/detail
mkdir
upload
Name
Size
Mode
Actions
accumulator_traits.hpp
2812
0644
edit
dl
rm
args_type.hpp
1546
0644
edit
dl
rm
argument_traits.hpp
2548
0644
edit
dl
rm
array_wrapper.hpp
2050
0644
edit
dl
rm
axes.hpp
13362
0644
edit
dl
rm
common_type.hpp
1335
0644
edit
dl
rm
convert_integer.hpp
566
0644
edit
dl
rm
counting_streambuf.hpp
1923
0644
edit
dl
rm
detect.hpp
8320
0644
edit
dl
rm
fill.hpp
12609
0644
edit
dl
rm
fill_n.hpp
13696
0644
edit
dl
rm
index_translator.hpp
3437
0644
edit
dl
rm
iterator_adaptor.hpp
4484
0644
edit
dl
rm
large_int.hpp
6543
0644
edit
dl
rm
limits.hpp
986
0644
edit
dl
rm
linearize.hpp
4482
0644
edit
dl
rm
make_default.hpp
710
0644
edit
dl
rm
mutex_base.hpp
1228
0644
edit
dl
rm
nonmember_container_access.hpp
1448
0644
edit
dl
rm
operators.hpp
4494
0644
edit
dl
rm
optional_index.hpp
1426
0644
edit
dl
rm
priority.hpp
593
0644
edit
dl
rm
reduce_command.hpp
2541
0644
edit
dl
rm
relaxed_equal.hpp
1217
0644
edit
dl
rm
relaxed_tuple_size.hpp
956
0644
edit
dl
rm
replace_type.hpp
818
0644
edit
dl
rm
safe_comparison.hpp
2519
0644
edit
dl
rm
span.hpp
9048
0644
edit
dl
rm
static_if.hpp
1477
0644
edit
dl
rm
sub_array.hpp
3577
0644
edit
dl
rm
try_cast.hpp
1575
0644
edit
dl
rm
tuple_slice.hpp
1019
0644
edit
dl
rm
type_name.hpp
1083
0644
edit
dl
rm
variant_proxy.hpp
2430
0644
edit
dl
rm
Edit:
/usr/include/boost/histogram/detail/linearize.hpp
(4482B)
// Copyright 2019 Hans Dembinski // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_HISTOGRAM_DETAIL_LINEARIZE_HPP #define BOOST_HISTOGRAM_DETAIL_LINEARIZE_HPP #include <boost/histogram/axis/option.hpp> #include <boost/histogram/axis/traits.hpp> #include <boost/histogram/axis/variant.hpp> #include <boost/histogram/detail/optional_index.hpp> #include <boost/histogram/fwd.hpp> #include <boost/histogram/multi_index.hpp> #include <cassert> namespace boost { namespace histogram { namespace detail { // initial offset to out must be set template <class Index, class Opts> std::size_t linearize(Opts, Index& out, const std::size_t stride, const axis::index_type size, const axis::index_type idx) { constexpr bool u = Opts::test(axis::option::underflow); constexpr bool o = Opts::test(axis::option::overflow); // must be non-const to avoid if constexpr warning from msvc bool fast_track = std::is_same<Index, std::size_t>::value || (u && o); if (fast_track) { assert(idx >= (u ? -1 : 0)); assert(idx < (o ? size + 1 : size)); assert(idx >= 0 || static_cast<std::size_t>(-idx * stride) <= out); out += idx * stride; } else { assert(idx >= -1); assert(idx < size + 1); // must be non-const to avoid if constexpr warning from msvc bool is_valid = (u || idx >= 0) && (o || idx < size); if (is_valid) out += idx * stride; else out = invalid_index; } return size + u + o; } template <class Index, class Axis, class Value> std::size_t linearize(Index& out, const std::size_t stride, const Axis& ax, const Value& v) { // mask options to reduce no. of template instantiations constexpr auto opts = axis::traits::get_options<Axis>{} & (axis::option::underflow | axis::option::overflow); return linearize(opts, out, stride, ax.size(), axis::traits::index(ax, v)); } // initial offset of out must be zero template <class Index, class Axis, class Value> std::size_t linearize_growth(Index& out, axis::index_type& shift, const std::size_t stride, Axis& a, const Value& v) { axis::index_type idx; std::tie(idx, shift) = axis::traits::update(a, v); constexpr bool u = axis::traits::get_options<Axis>::test(axis::option::underflow); if (u) ++idx; if (std::is_same<Index, std::size_t>::value) { assert(idx < axis::traits::extent(a)); out += idx * stride; } else { if (0 <= idx && idx < axis::traits::extent(a)) out += idx * stride; else out = invalid_index; } return axis::traits::extent(a); } // initial offset of out must be zero template <class A> std::size_t linearize_index(optional_index& out, const std::size_t stride, const A& ax, const axis::index_type idx) noexcept { const auto opt = axis::traits::get_options<A>(); const axis::index_type begin = opt & axis::option::underflow ? -1 : 0; const axis::index_type end = opt & axis::option::overflow ? ax.size() + 1 : ax.size(); const axis::index_type extent = end - begin; // i may be arbitrarily out of range if (begin <= idx && idx < end) out += (idx - begin) * stride; else out = invalid_index; return extent; } template <class A, std::size_t N> optional_index linearize_indices(const A& axes, const multi_index<N>& indices) noexcept { assert(axes_rank(axes) == detail::size(indices)); optional_index idx{0}; // offset not used by linearize_index auto stride = static_cast<std::size_t>(1); using std::begin; auto i = begin(indices); for_each_axis(axes, [&](const auto& a) { stride *= linearize_index(idx, stride, a, *i++); }); return idx; } template <class Index, class... Ts, class Value> std::size_t linearize(Index& o, const std::size_t s, const axis::variant<Ts...>& a, const Value& v) { return axis::visit([&o, &s, &v](const auto& a) { return linearize(o, s, a, v); }, a); } template <class Index, class... Ts, class Value> std::size_t linearize_growth(Index& o, axis::index_type& sh, const std::size_t st, axis::variant<Ts...>& a, const Value& v) { return axis::visit([&](auto& a) { return linearize_growth(o, sh, st, a, v); }, a); } } // namespace detail } // namespace histogram } // namespace boost #endif // BOOST_HISTOGRAM_DETAIL_LINEARIZE_HPP
Save
cmd:
run