Skip to content

Commit

Permalink
add indexed apply
Browse files Browse the repository at this point in the history
  • Loading branch information
ikbuibui committed Feb 3, 2025
1 parent 9a2a904 commit 7574c6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
7 changes: 3 additions & 4 deletions include/picongpu/plugins/binning/BinningFunctors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ namespace picongpu

auto binsDataspace = pmacc::DataSpace<T_nAxes>{};
bool validIdx = true;
binning::apply(
[&](auto const&... tupleArgs)
binning::applyIndexed(
[&](auto const& tuple, auto... idxs)
{
uint32_t i = 0;
// This assumes n_bins and getBinIdx exist
((binsDataspace[i++] = tupleArgs.getBinIdx(domainInfo, worker, particle, validIdx)), ...);
((binsDataspace[idxs] = pmacc::memory::tuple::get<idxs>(tuple).getBinIdx(domainInfo, worker, particle, validIdx)), ...);
},
std::move(axes));

Expand Down
26 changes: 23 additions & 3 deletions include/picongpu/plugins/binning/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,43 @@ namespace picongpu
namespace detail
{
template<typename TFunc, typename TPmaccTuple, std::size_t... Is>
HDINLINE constexpr auto apply_impl(TFunc&& f, TPmaccTuple&& t, std::index_sequence<Is...>)
HDINLINE constexpr auto applyImpl(TFunc&& f, TPmaccTuple&& t, std::index_sequence<Is...>)
{
// @todo give Is as a param to f, so compiler has knowledge
return std::forward<TFunc>(f)(pmacc::memory::tuple::get<Is>(std::forward<TPmaccTuple>(t))...);
}

template<typename TFunc, typename TPmaccTuple, std::size_t... Is>
HDINLINE constexpr auto applyIdxImpl(TFunc&& f, TPmaccTuple&& t, std::index_sequence<Is...>)
{
return std::forward<TFunc>(f)(
std::forward<TPmaccTuple>(t),
std::integral_constant<std::size_t, Is>{}...);
}


} // namespace detail

// takes pmacc::memory::tuple::Tuple
template<typename TFunc, typename TPmaccTuple>
HDINLINE constexpr auto apply(TFunc&& f, TPmaccTuple&& t)
{
return detail::apply_impl(
return detail::applyImpl(
std::forward<TFunc>(f),
std::forward<TPmaccTuple>(t),
std::make_index_sequence<pmacc::memory::tuple::tuple_size_v<TPmaccTuple>>{});
}

// takes pmacc::memory::tuple::Tuple
template<typename TFunc, typename TPmaccTuple>
HDINLINE constexpr auto applyIndexed(TFunc&& f, TPmaccTuple&& t)
{
return detail::applyIdxImpl(
std::forward<TFunc>(f),
std::forward<TPmaccTuple>(t),
std::make_index_sequence<pmacc::memory::tuple::tuple_size_v<TPmaccTuple>>{});
}


namespace detail
{
template<size_t... Is, typename... Args, typename Functor>
Expand Down

0 comments on commit 7574c6d

Please sign in to comment.