/
ArborX_DetailsLegacy.hpp
145 lines (125 loc) · 4.31 KB
/
ArborX_DetailsLegacy.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/****************************************************************************
* Copyright (c) 2023 by the ArborX authors *
* All rights reserved. *
* *
* This file is part of the ArborX library. ArborX is *
* distributed under a BSD 3-clause license. For the licensing terms see *
* the LICENSE file in the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
#ifndef ARBORX_DETAILS_LEGACY_HPP
#define ARBORX_DETAILS_LEGACY_HPP
#include <ArborX_AccessTraits.hpp>
#include <ArborX_PairValueIndex.hpp>
namespace ArborX::Details
{
template <typename Primitives, typename BoundingVolume>
class LegacyValues
{
Primitives _primitives;
using Access = AccessTraits<Primitives, PrimitivesTag>;
public:
using memory_space = typename Access::memory_space;
using index_type = unsigned;
using value_type = PairValueIndex<BoundingVolume, index_type>;
using size_type =
Kokkos::detected_t<Details::AccessTraitsSizeArchetypeExpression, Access,
Primitives>;
LegacyValues(Primitives const &primitives)
: _primitives(primitives)
{}
KOKKOS_FUNCTION
auto operator()(size_type i) const
{
using Primitive = std::decay_t<decltype(Access::get(_primitives, i))>;
if constexpr (std::is_same_v<BoundingVolume, Primitive>)
{
return value_type{Access::get(_primitives, i), (index_type)i};
}
else
{
BoundingVolume bounding_volume{};
expand(bounding_volume, Access::get(_primitives, i));
return value_type{bounding_volume, (index_type)i};
}
}
KOKKOS_FUNCTION
size_type size() const { return Access::size(_primitives); }
};
template <typename Primitives, typename BoundingVolume>
class AccessValuesI<LegacyValues<Primitives, BoundingVolume>, PrimitivesTag>
: public LegacyValues<Primitives, BoundingVolume>
{
public:
using self_type = LegacyValues<Primitives, BoundingVolume>;
};
template <typename Callback>
struct LegacyCallbackWrapper
{
Callback _callback;
template <typename Predicate, typename Value, typename Index>
KOKKOS_FUNCTION auto
operator()(Predicate const &predicate,
PairValueIndex<Value, Index> const &value) const
{
return _callback(predicate, value.index);
}
template <typename Predicate, typename Value, typename Index, typename Output>
KOKKOS_FUNCTION void operator()(Predicate const &predicate,
PairValueIndex<Value, Index> const &value,
Output const &out) const
{
_callback(predicate, value.index, out);
}
};
struct LegacyDefaultCallback
{
template <typename Query, typename Value, typename Index,
typename OutputFunctor>
KOKKOS_FUNCTION void operator()(Query const &,
PairValueIndex<Value, Index> const &value,
OutputFunctor const &output) const
{
output(value.index);
}
};
struct LegacyDefaultTemplateValue
{};
} // namespace ArborX::Details
template <>
struct ArborX::GeometryTraits::dimension<
ArborX::Details::LegacyDefaultTemplateValue>
{
static constexpr int value = 3;
};
template <>
struct ArborX::GeometryTraits::tag<ArborX::Details::LegacyDefaultTemplateValue>
{
using type = BoxTag;
};
template <>
struct ArborX::GeometryTraits::coordinate_type<
ArborX::Details::LegacyDefaultTemplateValue>
{
using type = float;
};
template <typename Primitives, typename BoundingVolume>
struct ArborX::AccessTraits<
ArborX::Details::LegacyValues<Primitives, BoundingVolume>,
ArborX::PrimitivesTag>
{
using Values = ArborX::Details::LegacyValues<Primitives, BoundingVolume>;
using memory_space = typename Values::memory_space;
using size_type = typename Values::size_type;
using value_type = typename Values::value_type;
KOKKOS_FUNCTION static size_type size(Values const &values)
{
return values.size();
}
KOKKOS_FUNCTION static decltype(auto) get(Values const &values, size_type i)
{
return values(i);
}
};
#endif