Line data Source code
1 : // SPDX-License-Identifier: BSD-3-Clause
2 : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3 : /// @file
4 : /// @author Simon Heybrock
5 : #pragma once
6 :
7 : #include "scipp/common/overloaded.h"
8 : #include "scipp/core/element/arg_list.h"
9 : #include "scipp/core/subbin_sizes.h"
10 : #include "scipp/core/transform_common.h"
11 :
12 : namespace scipp::core::element {
13 :
14 : template <class Coord, class Edge>
15 : using bin_range_arg =
16 : std::tuple<scipp::index, scipp::index, Coord, scipp::span<const Edge>>;
17 :
18 : static constexpr auto bin_range_common = overloaded{
19 : arg_list<bin_range_arg<double, double>, bin_range_arg<double, float>,
20 : bin_range_arg<double, int32_t>, bin_range_arg<double, int64_t>,
21 : bin_range_arg<float, double>, bin_range_arg<float, float>,
22 : bin_range_arg<float, int32_t>, bin_range_arg<float, int64_t>,
23 : bin_range_arg<int32_t, double>, bin_range_arg<int32_t, float>,
24 : bin_range_arg<int32_t, int32_t>, bin_range_arg<int32_t, int64_t>,
25 : bin_range_arg<int64_t, double>, bin_range_arg<int64_t, float>,
26 : bin_range_arg<int64_t, int32_t>, bin_range_arg<int64_t, int64_t>,
27 : bin_range_arg<time_point, time_point>>,
28 : transform_flags::expect_no_variance_arg<2>};
29 :
30 : static constexpr auto begin_edge =
31 32250 : overloaded{bin_range_common, [](auto &bin, auto &index, const auto &coord,
32 : const auto &edges) {
33 50237 : while (bin + 2 < scipp::size(edges) && edges[bin + 1] <= coord)
34 17987 : ++bin;
35 32250 : index = bin;
36 32250 : }};
37 :
38 : static constexpr auto end_edge =
39 15397 : overloaded{bin_range_common, [](auto &bin, auto &index, const auto &coord,
40 : const auto &edges) {
41 28476 : while (bin + 2 < scipp::size(edges) && edges[bin + 1] < coord)
42 13079 : ++bin;
43 15397 : index = bin + 2;
44 15397 : }};
45 :
46 : constexpr auto subbin_sizes_exclusive_scan = overloaded{
47 50504 : arg_list<SubbinSizes>, [](auto &sum, auto &x) { sum.exclusive_scan(x); }};
48 :
49 : constexpr auto subbin_sizes_add_intersection =
50 : overloaded{arg_list<SubbinSizes>,
51 15332 : overloaded{[](units::Unit &a, const units::Unit &b) { a += b; },
52 125266 : [](auto &a, auto &b) { a.add_intersection(b); }}};
53 :
54 : } // namespace scipp::core::element
|