Skip to content

Commit

Permalink
Merge pull request #1193 from aprokop/move_legacy_default_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop authored Nov 23, 2024
2 parents ec6e245 + f124970 commit c4653c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
11 changes: 5 additions & 6 deletions examples/simple_intersection/example_intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ int main(int argc, char *argv[])

ExecutionSpace space;

using Value = ArborX::PairValueIndex<Box>;

ArborX::BoundingVolumeHierarchy const tree(
space, ArborX::Experimental::attach_indices(boxes));

// The query will resize values and offsets accordingly
Kokkos::View<Value *, MemorySpace> values("Example::values", 0);
Kokkos::View<typename decltype(tree)::value_type *, MemorySpace> values(
"Example::values", 0);
Kokkos::View<int *, MemorySpace> offsets("Example::offsets", 0);
tree.query(space, queries, values, offsets);

Expand All @@ -73,9 +72,9 @@ int main(int argc, char *argv[])
std::copy(offsets_host.data(), offsets_host.data() + offsets.size(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << "\nindices:";
for (int i = 0; i < values_host.extent_int(0); ++i)
std::cout << " " << values_host(i).index;
std::cout << '\n';
std::transform(values_host.data(), values_host.data() + values.size(),
std::ostream_iterator<int>(std::cout, " "),
[](auto value) { return value.index; });

return 0;
}
15 changes: 8 additions & 7 deletions examples/triangle_intersection/triangle_intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ int main(int argc, char *argv[])
space, ArborX::Experimental::attach_indices(triangles));

// The query will resize indices and offsets accordingly
Kokkos::View<unsigned *, MemorySpace> indices("Example::indices", 0);
Kokkos::View<typename decltype(tree)::value_type *, MemorySpace> values(
"Example::values", 0);
Kokkos::View<int *, MemorySpace> offsets("Example::offsets", 0);
tree.query(space, queries, ArborX::Details::LegacyDefaultCallback{}, indices,
offsets);
tree.query(space, queries, values, offsets);

auto offsets_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, offsets);
auto indices_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, indices);
auto values_host =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, values);

// Expected output:
// offsets: 0 1 2 3 4
Expand All @@ -105,8 +105,9 @@ int main(int argc, char *argv[])
std::copy(offsets_host.data(), offsets_host.data() + offsets.size(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << "\nindices: ";
std::copy(indices_host.data(), indices_host.data() + indices.size(),
std::ostream_iterator<int>(std::cout, " "));
std::transform(values_host.data(), values_host.data() + values.size(),
std::ostream_iterator<int>(std::cout, " "),
[](auto value) { return value.index; });
std::cout << "\n";

return 0;
Expand Down
15 changes: 0 additions & 15 deletions src/spatial/detail/ArborX_Callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ struct DefaultCallback
}
};

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
{
// APIv1 callback has the signature operator()(Query, int)
// As we store PairValueIndex with potentially non int index (like
// unsigned), we explicitly cast it here.
output((int)value.index);
}
};

// archetypal alias for a 'tag' type member in user callbacks
template <typename Callback>
using CallbackTagArchetypeAlias = typename Callback::tag;
Expand Down
8 changes: 6 additions & 2 deletions test/ArborXTest_LegacyTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ class LegacyTree : public Tree
query(ExecutionSpace const &space, Predicates const &predicates, View &&view,
Args &&...args) const
{
Tree::query(space, predicates, ArborX::Details::LegacyDefaultCallback{},
Tree::query(space, predicates,
LegacyCallbackWrapper<ArborX::Details::DefaultCallback>{
ArborX::Details::DefaultCallback{}},
std::forward<View>(view), std::forward<Args>(args)...);
}

Expand All @@ -159,7 +161,9 @@ class LegacyTree : public Tree
{
Kokkos::View<int *, typename Tree::memory_space> indices(
"Testing::indices", 0);
Tree::query(space, predicates, ArborX::Details::LegacyDefaultCallback{},
Tree::query(space, predicates,
LegacyCallbackWrapper<ArborX::Details::DefaultCallback>{
ArborX::Details::DefaultCallback{}},
indices, std::forward<OffsetView>(offset),
std::forward<Args>(args)...);
callback(predicates, std::forward<OffsetView>(offset), indices,
Expand Down

0 comments on commit c4653c5

Please sign in to comment.