/
ArborX_DetailsPermutedData.hpp
76 lines (61 loc) · 2.49 KB
/
ArborX_DetailsPermutedData.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
/****************************************************************************
* Copyright (c) 2017-2022 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_PERMUTED_DATA_HPP
#define ARBORX_DETAILS_PERMUTED_DATA_HPP
#include <ArborX_AccessTraits.hpp>
namespace ArborX
{
namespace Details
{
template <typename Data, typename Permute, bool AttachIndices = false>
struct PermutedData
{
using memory_space = typename Data::memory_space;
using value_type = typename Data::value_type;
Data _data;
Permute _permute;
KOKKOS_FUNCTION decltype(auto) operator()(int i) const
{
return _data(_permute(i));
}
KOKKOS_FUNCTION auto size() const { return _data.size(); }
};
} // namespace Details
template <typename Predicates, typename Permute, bool AttachIndices>
struct AccessTraits<Details::PermutedData<Predicates, Permute, AttachIndices>,
PredicatesTag>
{
using PermutedPredicates =
Details::PermutedData<Predicates, Permute, AttachIndices>;
using memory_space = typename Predicates::memory_space;
KOKKOS_FUNCTION static std::size_t
size(PermutedPredicates const &permuted_predicates)
{
return permuted_predicates._data.size();
}
template <bool _Attach = AttachIndices>
KOKKOS_FUNCTION static auto get(PermutedPredicates const &permuted_predicates,
std::enable_if_t<_Attach, std::size_t> index)
{
auto const permuted_index = permuted_predicates._permute(index);
return attach(permuted_predicates._data(permuted_index), (int)index);
}
template <bool _Attach = AttachIndices>
KOKKOS_FUNCTION static decltype(auto)
get(PermutedPredicates const &permuted_predicates,
std::enable_if_t<!_Attach, std::size_t> index)
{
auto const permuted_index = permuted_predicates._permute(index);
return permuted_predicates._data(permuted_index);
}
};
} // namespace ArborX
#endif