6#ifndef IPPL_VIEW_UTILS_H
7#define IPPL_VIEW_UTILS_H
9#include <Kokkos_Core.hpp>
31 template <
unsigned Dim,
unsigned Current = 0,
class BeginFunctor,
class EndFunctor,
32 class Functor,
typename Check = std::nullptr_t>
33 constexpr void nestedLoop(BeginFunctor&& begin, EndFunctor&& end, Functor&& body,
34 Check&& check =
nullptr) {
35 for (
size_t i = begin(Current); i < end(Current); ++i) {
36 if constexpr (
Dim - 1 == Current) {
39 auto inner = [i, &body](
auto... args) {
45 if constexpr (!std::is_null_pointer_v<std::decay_t<Check>>) {
61 template <
typename View,
class Functor,
typename Check = std::
nullptr_t>
63 Check&& check =
nullptr) {
69 return view.extent(d) - shift;
83 template <
typename T,
unsigned Dim,
class... Properties>
85 std::ostream& out = std::cout) {
87 typename view_type::HostMirror hview = Kokkos::create_mirror_view(view);
88 Kokkos::deep_copy(hview, view);
92 [&]<
typename... Args>(Args&&... args) {
93 out << hview(args...) <<
" ";
96 if (axis + 1 >= 2 || axis == 0) {
105 template <
typename View,
size_t... Idx>
107 const std::index_sequence<Idx...>&) {
108 using view_type =
typename Kokkos::View<
typename View::data_type, Kokkos::LayoutLeft,
109 typename View::memory_space>::uniform_type;
110 return view_type(label, (view.extent(Idx) - 2 * nghost)...);
121 template <
typename View>
122 decltype(
auto)
shrinkView(std::string label,
const View& view,
int nghost) {
123 return shrinkView_impl(label, view, nghost, std::make_index_sequence<View::rank>{});
typename ippl::detail::ViewType< ippl::Vector< double, Dim >, 1 >::view_type view_type
decltype(auto) shrinkView(std::string label, const View &view, int nghost)
void write(const typename ViewType< T, Dim, Properties... >::view_type &view, std::ostream &out=std::cout)
constexpr void nestedViewLoop(View &view, int shift, Functor &&body, Check &&check=nullptr)
decltype(auto) shrinkView_impl(std::string label, const View &view, int nghost, const std::index_sequence< Idx... > &)
constexpr void nestedLoop(BeginFunctor &&begin, EndFunctor &&end, Functor &&body, Check &&check=nullptr)
Kokkos::View< typename NPtr< T, Dim >::type, Properties... > view_type