1- #include < experimental /mdspan>
1+ #include < mdspan /mdspan.hpp >
22#include < array>
33#include < iostream>
44#include < tuple>
55#include < type_traits>
66
7- namespace stdex = std::experimental;
8-
97// There's no separate feature test macro for the C++20 feature
108// of lambdas with named template parameters (P0428R2).
119#if __cplusplus >= 202002L
@@ -80,11 +78,11 @@ auto print_pack = []<class ... InputTypes>(InputTypes&& ... input) {
8078// This example shows that you can do
8179// index arithmetic on an index sequence.
8280template <class IndexType , std::size_t ... Extents>
83- auto right_extents ( stdex ::extents<IndexType, Extents...> e )
81+ auto right_extents ( Kokkos ::extents<IndexType, Extents...> e )
8482{
8583 static_assert (sizeof ...(Extents) != 0 );
8684 return [&]<std::size_t ... Indices>( std::index_sequence<Indices...> ) {
87- return stdex ::extents<IndexType, e.static_extent (Indices + 1 )...>{
85+ return Kokkos ::extents<IndexType, e.static_extent (Indices + 1 )...>{
8886 e.extent (Indices + 1 )...
8987 };
9088 }( std::make_index_sequence<sizeof ...(Extents) - 1 >() );
@@ -101,10 +99,10 @@ auto right_extents( stdex::extents<IndexType, Extents...> e )
10199// This needs to be a lambda or function object,
102100// not a templated function.
103101auto split_extents_at_leftmost =
104- []<class IndexType , std::size_t ... Extents>(stdex ::extents<IndexType, Extents...> e)
102+ []<class IndexType , std::size_t ... Extents>(Kokkos ::extents<IndexType, Extents...> e)
105103{
106104 static_assert (sizeof ...(Extents) != 0 );
107- stdex ::extents<IndexType, e.static_extent (0 )> left_ext (
105+ Kokkos ::extents<IndexType, e.static_extent (0 )> left_ext (
108106 e.extent (0 ));
109107 return std::tuple{left_ext, right_extents (e)};
110108};
@@ -116,22 +114,22 @@ auto split_extents_at_leftmost =
116114// Returns a new extents object representing
117115// all but the rightmost extent of e.
118116template <class IndexType , std::size_t ... Extents>
119- auto left_extents ( stdex ::extents<IndexType, Extents...> e )
117+ auto left_extents ( Kokkos ::extents<IndexType, Extents...> e )
120118{
121119 static_assert (sizeof ...(Extents) != 0 );
122120 return [&]<std::size_t ... Indices>( std::index_sequence<Indices...> ) {
123- return stdex ::extents<IndexType, e.static_extent (Indices)...>{
121+ return Kokkos ::extents<IndexType, e.static_extent (Indices)...>{
124122 e.extent (Indices)...
125123 };
126124 }( std::make_index_sequence<sizeof ...(Extents) - 1 >() );
127125}
128126
129127// This needs to be a lambda or function object, not a templated function.
130128auto split_extents_at_rightmost =
131- []<class IndexType , std::size_t ... Extents>(stdex ::extents<IndexType, Extents...> e)
129+ []<class IndexType , std::size_t ... Extents>(Kokkos ::extents<IndexType, Extents...> e)
132130{
133131 static_assert (sizeof ...(Extents) != 0 );
134- stdex ::extents<IndexType, e.static_extent (e.rank () - 1 )> right_ext (
132+ Kokkos ::extents<IndexType, e.static_extent (e.rank () - 1 )> right_ext (
135133 e.extent (e.rank () - 1 ));
136134 return std::tuple{left_extents (e), right_ext};
137135};
@@ -149,10 +147,10 @@ auto split_extents_at_rightmost =
149147// optimization information -- e.g., whether we want
150148// to apply "#pragma omp simd" to a particular extent.
151149template <class Callable , class IndexType , std::size_t Extent>
152- void for_each_one_extent (Callable&& callable, stdex ::extents<IndexType, Extent> ext)
150+ void for_each_one_extent (Callable&& callable, Kokkos ::extents<IndexType, Extent> ext)
153151{
154152 // If it's a run-time extent, do a run-time loop.
155- if constexpr (ext.static_extent (0 ) == stdex ::dynamic_extent) {
153+ if constexpr (ext.static_extent (0 ) == Kokkos ::dynamic_extent) {
156154 for (IndexType index = 0 ; index < ext.extent (0 ); ++index) {
157155 std::forward<Callable>(callable)(index);
158156 }
@@ -176,7 +174,7 @@ void for_each_one_extent(Callable&& callable, stdex::extents<IndexType, Extent>
176174template <class Callable , class IndexType , std::size_t ... Extents>
177175void for_each_in_extents_row_major (
178176 Callable&& callable,
179- stdex ::extents<IndexType, Extents...> ext)
177+ Kokkos ::extents<IndexType, Extents...> ext)
180178{
181179 if constexpr (ext.rank () == 0 ) {
182180 return ;
@@ -203,12 +201,12 @@ void for_each_in_extents_row_major(
203201// The implementation differs in only two places from the row-major version.
204202// This suggests a way to generalize.
205203//
206- // Overloading on stdex:: extents<IndexType, LeftExtents..., RightExtent>
204+ // Overloading on extents<IndexType, LeftExtents..., RightExtent>
207205// works fine for the row major case, but not for the column major case.
208206template <class Callable , class IndexType , std::size_t ... Extents>
209207void for_each_in_extents_col_major (
210208 Callable&& callable,
211- stdex ::extents<IndexType, Extents...> ext)
209+ Kokkos ::extents<IndexType, Extents...> ext)
212210{
213211 if constexpr (ext.rank () == 0 ) {
214212 return ;
@@ -242,7 +240,7 @@ void for_each_in_extents_col_major(
242240template <class Callable , class IndexType , std::size_t ... Extents,
243241 class ExtentsReorderer , class ExtentsSplitter , class IndicesReorderer >
244242void for_each_in_extents_impl (Callable&& callable,
245- stdex ::extents<IndexType, Extents...> ext,
243+ Kokkos ::extents<IndexType, Extents...> ext,
246244 ExtentsReorderer reorder_extents,
247245 ExtentsSplitter split_extents,
248246 IndicesReorderer reorder_indices)
@@ -280,18 +278,18 @@ void for_each_in_extents_impl(Callable&& callable,
280278}
281279
282280auto extents_identity = []<class IndexType , std::size_t ... Extents>(
283- stdex ::extents<IndexType, Extents...> ext)
281+ Kokkos ::extents<IndexType, Extents...> ext)
284282{
285283 return ext;
286284};
287285
288286auto extents_reverse = []<class IndexType , std::size_t ... Extents>(
289- stdex ::extents<IndexType, Extents...> ext)
287+ Kokkos ::extents<IndexType, Extents...> ext)
290288{
291289 constexpr std::size_t N = ext.rank ();
292290
293291 return [&]<std::size_t ... Indices>( std::index_sequence<Indices...> ) {
294- return stdex ::extents<
292+ return Kokkos ::extents<
295293 IndexType,
296294 ext.static_extent (N - 1 - Indices)...
297295 >{ ext.extent (N - 1 - Indices)... };
@@ -325,8 +323,8 @@ auto indices_reverse = [](auto... args) {
325323// Row-major iteration
326324template <class Callable , class IndexType , std::size_t ... Extents>
327325void for_each_in_extents (Callable&& callable,
328- stdex ::extents<IndexType, Extents...> ext,
329- stdex ::layout_right)
326+ Kokkos ::extents<IndexType, Extents...> ext,
327+ Kokkos ::layout_right)
330328{
331329 for_each_in_extents_impl (std::forward<Callable>(callable), ext,
332330 extents_identity, split_extents_at_leftmost, indices_identity);
@@ -335,8 +333,8 @@ void for_each_in_extents(Callable&& callable,
335333// Column-major iteration
336334template <class Callable , class IndexType , std::size_t ... Extents>
337335void for_each_in_extents (Callable&& callable,
338- stdex ::extents<IndexType, Extents...> ext,
339- stdex ::layout_left)
336+ Kokkos ::extents<IndexType, Extents...> ext,
337+ Kokkos ::layout_left)
340338{
341339 for_each_in_extents_impl (std::forward<Callable>(callable), ext,
342340 extents_reverse, split_extents_at_rightmost, indices_reverse);
@@ -349,7 +347,7 @@ int main() {
349347#if ! defined(__clang__) && defined(MDSPAN_EXAMPLE_CAN_USE_LAMBDA_TEMPLATE_PARAM_LIST)
350348 // The functions work for any combination
351349 // of compile-time or run-time extents.
352- stdex ::extents<int , 3 , stdex ::dynamic_extent, 5 > e{4 };
350+ Kokkos ::extents<int , 3 , Kokkos ::dynamic_extent, 5 > e{4 };
353351
354352 std::cout << " \n Row major:\n " ;
355353 for_each_in_extents_row_major (print_pack, e);
@@ -358,10 +356,10 @@ int main() {
358356 for_each_in_extents_col_major (print_pack, e);
359357
360358 std::cout << " \n for_each_in_extents: row major:\n " ;
361- for_each_in_extents (print_pack, e, stdex ::layout_right{});
359+ for_each_in_extents (print_pack, e, Kokkos ::layout_right{});
362360
363361 std::cout << " \n for_each_in_extents: column major:\n " ;
364- for_each_in_extents (print_pack, e, stdex ::layout_left{});
362+ for_each_in_extents (print_pack, e, Kokkos ::layout_left{});
365363#endif // defined(MDSPAN_EXAMPLE_CAN_USE_LAMBDA_TEMPLATE_PARAM_LIST)
366364
367365 return 0 ;
0 commit comments