-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce PairValueIndex and AttachIndices
There are two use cases that are currently mixed when using LegacyValues: 1) Legacy classes use LegacyValues to pass to the new interface 2) User wants to attach indices to the passed primitives without constructing them themselves The difference is that 1) should not be exposed to a user, while 2) is intended to. With the introduction of the RangeTraits in the future, the use cases diverge: 1) will still use AccessTraits for backwards compatibility, while 2) will switch to using RangeTraits. This patch separates the two. They still share a lot of commonalities at the moment, but that will change with RangeTraits. In addition, the order is swapped between value and index in the struct. The reason being is that it is easer to align an index (likely 4-byte int) than a value (which could be a 12-byte point, 24-byte box, or whatever).
- Loading branch information
Showing
14 changed files
with
114 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/**************************************************************************** | ||
* 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_PAIR_VALUE_INDEX_HPP | ||
#define ARBORX_PAIR_VALUE_INDEX_HPP | ||
|
||
#include <ArborX_AccessTraits.hpp> | ||
|
||
#include <Kokkos_Macros.hpp> | ||
|
||
namespace ArborX::Details | ||
{ | ||
|
||
template <class Value, typename Index = unsigned> | ||
struct PairValueIndex | ||
{ | ||
static_assert(std::is_integral_v<Index>); | ||
|
||
Value value; | ||
Index index; | ||
}; | ||
|
||
template <typename Values, typename Index = unsigned> | ||
class AttachIndices | ||
{ | ||
private: | ||
using Data = AccessValues<Values>; | ||
|
||
public: | ||
Data _data; | ||
|
||
using memory_space = typename Data::memory_space; | ||
using value_type = Details::PairValueIndex<typename Data::value_type>; | ||
|
||
AttachIndices(Values const &values) | ||
: _data{values} | ||
{} | ||
|
||
KOKKOS_FUNCTION | ||
auto operator()(int i) const { return value_type{_data(i), Index(i)}; } | ||
|
||
KOKKOS_FUNCTION | ||
auto size() const { return _data.size(); } | ||
}; | ||
|
||
} // namespace ArborX::Details | ||
|
||
template <typename Values, typename Index> | ||
struct ArborX::AccessTraits<ArborX::Details::AttachIndices<Values, Index>, | ||
ArborX::PrimitivesTag> | ||
{ | ||
using Self = ArborX::Details::AttachIndices<Values, Index>; | ||
|
||
using memory_space = typename Self::memory_space; | ||
using value_type = typename Self::value_type; | ||
|
||
KOKKOS_FUNCTION static auto size(Self const &values) { return values.size(); } | ||
KOKKOS_FUNCTION static decltype(auto) get(Self const &values, int i) | ||
{ | ||
return values(i); | ||
} | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters