Skip to content

Commit

Permalink
Simplify using APIv1 through APIv2 interface in BVH
Browse files Browse the repository at this point in the history
Right now, it is inconvenient to get the old behavior. One has to write
```c++
ArborX::BVH<MemorySpace, ArborX::PairValueIndex<Box>>
  tree(space, ArborX::Experimental::attach_indices(boxes));
tree.query(space, queries, ArborX::LegacyDefaultCallback{}, indices, offsets);
```
The presence of the `LegacyDefaultCallback` is really annoying.

This patch changes this. It automatically adds LegacyDefaultCallback
if the following 3 conditions are satisfied:
1. A user does not provide a callback
2. The index is constructed on PairValueIndex
2. The output value_type matches the index_type in the PairValueIndex.
  • Loading branch information
aprokop committed Apr 8, 2024
1 parent bf6f89b commit c14a9e8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/ArborX_LinearBVH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,39 @@ class BoundingVolumeHierarchy
using Predicates = Details::AccessValues<UserPredicates, PredicatesTag>;
using Tag = typename Predicates::value_type::Tag;

Details::CrsGraphWrapperImpl::queryDispatch(
Tag{}, *this, space, Predicates{user_predicates},
std::forward<CallbackOrView>(callback_or_view),
std::forward<View>(view), std::forward<Args>(args)...);
// Automatically add LegacyDefaultCallback if
// 1. A user does not provide a callback
// 2. The index is constructed on PairValueIndex
// 3. The output value_type matches the index_type in the PairValueIndex
constexpr bool use_convenient_shortcut = []() {
if constexpr (!Kokkos::is_view_v<std::decay_t<CallbackOrView>>)
return false;
else if constexpr (!Details::is_pair_value_index_v<value_type>)
return false;
else
{
return std::is_same_v<typename std::decay_t<CallbackOrView>::value_type,
typename value_type::index_type>;
}
}();

if constexpr (use_convenient_shortcut)
{
// Simplified way to get APIv1 result using APIv2 interface
Details::CrsGraphWrapperImpl::queryDispatch(
Tag{}, *this, space, Predicates{user_predicates},
Details::LegacyDefaultCallback{},
std::forward<CallbackOrView>(callback_or_view),
std::forward<View>(view), std::forward<Args>(args)...);
return;
}
else
{
Details::CrsGraphWrapperImpl::queryDispatch(
Tag{}, *this, space, Predicates{user_predicates},
std::forward<CallbackOrView>(callback_or_view),
std::forward<View>(view), std::forward<Args>(args)...);
}
}

template <typename Predicate, typename Callback>
Expand Down
15 changes: 15 additions & 0 deletions src/details/ArborX_PairValueIndex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ struct PairValueIndex
Index index;
};

namespace Details
{
template <typename T>
struct is_pair_value_index : public std::false_type
{};

template <typename Value, typename Index>
struct is_pair_value_index<PairValueIndex<Value, Index>> : public std::true_type
{};

template <typename T>
inline constexpr bool is_pair_value_index_v = is_pair_value_index<T>::value;

} // namespace Details

} // namespace ArborX

#endif

0 comments on commit c14a9e8

Please sign in to comment.