-
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.
Merge pull request #1036 from aprokop/attach_indices
Make attach_indices work for both primitives and predicates
- Loading branch information
Showing
9 changed files
with
190 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/**************************************************************************** | ||
* 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_ATTACH_INDICES_HPP | ||
#define ARBORX_DETAILS_ATTACH_INDICES_HPP | ||
|
||
#include <ArborX_AccessTraits.hpp> | ||
#include <ArborX_PairValueIndex.hpp> | ||
#include <ArborX_Predicates.hpp> | ||
|
||
namespace ArborX | ||
{ | ||
|
||
namespace Experimental | ||
{ | ||
template <typename Values, typename Index> | ||
struct AttachIndices | ||
{ | ||
Values _values; | ||
}; | ||
|
||
// Make sure the default Index matches the default in PairValueIndex | ||
template <typename Index = typename PairValueIndex<int>::index_type, | ||
typename Values = void> | ||
auto attach_indices(Values const &values) | ||
{ | ||
return AttachIndices<Values, Index>{values}; | ||
} | ||
} // namespace Experimental | ||
|
||
} // namespace ArborX | ||
|
||
template <typename Values, typename Index> | ||
struct ArborX::AccessTraits<ArborX::Experimental::AttachIndices<Values, Index>, | ||
ArborX::PrimitivesTag> | ||
{ | ||
private: | ||
using Self = ArborX::Experimental::AttachIndices<Values, Index>; | ||
using Access = AccessTraits<Values, ArborX::PrimitivesTag>; | ||
using value_type = ArborX::PairValueIndex< | ||
std::decay_t<Kokkos::detected_t< | ||
ArborX::Details::AccessTraitsGetArchetypeExpression, Access, Values>>, | ||
Index>; | ||
|
||
public: | ||
using memory_space = typename Access::memory_space; | ||
|
||
KOKKOS_FUNCTION static auto size(Self const &self) | ||
{ | ||
return Access::size(self._values); | ||
} | ||
KOKKOS_FUNCTION static auto get(Self const &self, int i) | ||
{ | ||
return value_type{Access::get(self._values, i), Index(i)}; | ||
} | ||
}; | ||
template <typename Values, typename Index> | ||
struct ArborX::AccessTraits<ArborX::Experimental::AttachIndices<Values, Index>, | ||
ArborX::PredicatesTag> | ||
{ | ||
private: | ||
using Self = ArborX::Experimental::AttachIndices<Values, Index>; | ||
using Access = AccessTraits<Values, ArborX::PredicatesTag>; | ||
|
||
public: | ||
using memory_space = typename Access::memory_space; | ||
|
||
KOKKOS_FUNCTION static auto size(Self const &self) | ||
{ | ||
return Access::size(self._values); | ||
} | ||
KOKKOS_FUNCTION static auto get(Self const &self, int i) | ||
{ | ||
return attach(Access::get(self._values, i), Index(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/**************************************************************************** | ||
* 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 * | ||
****************************************************************************/ | ||
|
||
#include <ArborX_AccessTraits.hpp> | ||
#include <ArborX_AttachIndices.hpp> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
BOOST_AUTO_TEST_SUITE(AttachIndices) | ||
|
||
BOOST_AUTO_TEST_CASE(attach_indices_to_primitives) | ||
{ | ||
using ArborX::Details::AccessValues; | ||
using ArborX::Experimental::attach_indices; | ||
|
||
Kokkos::View<ArborX::Point *, Kokkos::HostSpace> p("Testing::p", 10); | ||
auto p_with_indices = attach_indices(p); | ||
AccessValues<decltype(p_with_indices), ArborX::PrimitivesTag> p_values{ | ||
p_with_indices}; | ||
static_assert(std::is_same_v<decltype(p_values(0).index), unsigned>); | ||
BOOST_TEST(p_values(0).index == 0); | ||
BOOST_TEST(p_values(9).index == 9); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(attach_indices_to_predicates) | ||
{ | ||
using ArborX::Details::AccessValues; | ||
using ArborX::Experimental::attach_indices; | ||
|
||
using IntersectsPredicate = decltype(ArborX::intersects(ArborX::Point{})); | ||
Kokkos::View<IntersectsPredicate *, Kokkos::HostSpace> q("Testing::q", 10); | ||
auto q_with_indices = attach_indices<long>(q); | ||
AccessValues<decltype(q_with_indices), ArborX::PredicatesTag> q_values{ | ||
q_with_indices}; | ||
BOOST_TEST(ArborX::getData(q_values(0)) == 0); | ||
BOOST_TEST(ArborX::getData(q_values(9)) == 9); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
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
Oops, something went wrong.