46#if defined(__cplusplus)
68template<
class T,
int N, layout L = layout::right>
78 template<
class _T_,
int _N_, layout _L_>
friend class array;
100 template<
typename... Args>
108 check_operator_args_(indices...);
109 set_size_(indices...);
142 set_size_(other._extent);
190 swap(first._extent, second._extent);
191 swap(first._offset, second._offset);
192 swap(first._size, second._size);
193 swap(first._data, second._data);
209 for (
int i = 0; i < N; i++) {
210 _extent[i] = other._extent[i];
211 _offset[i] = other._offset[i];
272 template<
typename Id1>
275 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
281 check_operator_args_(i);
293 template<
typename Id1>
296 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
302 check_operator_args_(i);
314 template<
typename Id1,
typename Id2>
317 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
324 check_operator_args_(i,j);
327 return _data[i*_offset[0] + j];
329 return _data[i + j*_offset[1]];
331 return _data[i*_offset[0] + j*_offset[1]];
342 template<
typename Id1,
typename Id2>
345 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
352 check_operator_args_(i,j);
355 return _data[i*_offset[0] + j];
357 return _data[i + j*_offset[1]];
359 return _data[i*_offset[0] + j*_offset[1]];
370 template<
typename... Args>
373 std::enable_if_t<
cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
379 check_operator_args_(indices...);
381 return _data[data_offset_(indices...)];
392 template<
typename... Args>
395 std::enable_if_t<
cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
401 check_operator_args_(indices...);
403 return _data[data_offset_(indices...)];
510 return reinterpret_cast<U*
>(_data);
521 template<
typename... Args>
523 mdspan<T, N-
sizeof...(Args), L>
529 check_sub_function_args_(indices...);
531 constexpr int n_idx =
sizeof...(Args);
536 for (
int i = 0; i < N - n_idx; i++)
537 dims[i] = _extent[i+n_idx];
540 for (
int i = 0; i < N - n_idx; i++)
541 dims[i] = _extent[i];
544 return mdspan<T,N-n_idx,L>(_data + contiguous_data_offset_(indices...), dims);
553 template<
typename... Args>
561 check_sub_function_args_(indices...);
563 return _data + contiguous_data_offset_(indices...);
580 assert(n_vals <= _size);
582 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
590 data_ptr[e_id] = val;
613 assert(n_vals <= _size);
615 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
622 data_ptr[e_id] = val;
640 assert(n_elts <= _size && n_elts >= 0);
647 if (elt_ids ==
nullptr)
654 data_ptr[elt_ids[e_id]] = val;
678 assert(n_elts <= _size && n_elts >= 0);
684 if (elt_ids ==
nullptr)
690 data_ptr[elt_ids[e_id]] = val;
711 data_ptr[e_id] =
static_cast<T
>(0);
734 data_ptr[e_id] =
static_cast<T
>(0);
754 assert(n_vals <= _size);
756 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
764 data_ptr[e_id] =
data[e_id];
786 assert(n_vals <= _size);
788 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
796 data_ptr[e_id] =
data[e_id];
818 assert(other._size == _size);
820 assert(n_vals <= _size);
822 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
826 T* o_data_ptr = other._data;
831 data_ptr[e_id] = o_data_ptr[e_id];
855 assert(n_vals <= _size);
857 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
863 data_ptr[e_id] =
data[e_id];
885 assert(n_vals <= _size);
887 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
893 data_ptr[e_id] =
data[e_id];
914 assert(other.
size() == _size);
916 assert(n_vals <= _size);
918 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
922 T* o_data_ptr = other._data;
925 data_ptr[e_id] = o_data_ptr[e_id];
937 template<
typename... Args>
946 static_assert(
sizeof...(Args) == N,
"Wrong number of arguments");
947 static_assert(
sizeof...(Args) != 0,
"No input arguments provided...");
948 static_assert(
cs::are_integral<Args...>::value,
"Non integral input arguments.");
957 template<
typename... Args>
961 check_sub_function_args_
966 static_assert(
sizeof...(Args) < N,
"Too many input arguments.");
967 static_assert(
sizeof...(Args) != 0,
"No input arguments provided...");
968 static_assert(
cs::are_integral<Args...>::value,
"Non integral indices provided");
977 template<
typename... Args>
986 static_assert(
sizeof...(Args) <= N &&
sizeof...(Args) > 0,
987 "Number of indices is out of bounds");
989 constexpr int n_idx =
sizeof...(Args);
991 cs_lnum_t _indices[n_idx] = {indices...};
994 for (
int i = 0; i < n_idx; i++)
995 retval +=_indices[i] * _offset[i];
1006 template<
typename... Args>
1010 contiguous_data_offset_
1015 static_assert(
sizeof...(Args) <= N &&
sizeof...(Args) > 0,
1016 "Number of indices is out of bounds");
1018 constexpr int n_idx =
sizeof...(Args);
1020 cs_lnum_t _indices[n_idx] = {indices...};
1024 for (
int i = 0; i < n_idx; i++)
1025 retval +=_indices[i] * _offset[i];
1028 for (
int i = 0; i < n_idx; i++)
1029 retval +=_indices[i] * _offset[N-1-i];
1052 _size = (N > 0) ? 1 : 0;
1053 for (
int i = 0; i < N; i++) {
1054 _extent[i] = dims[i];
1063 for (
int i = 0; i < N-1; i++) {
1064 for (
int j = i + 1; j < N; j++)
1065 _offset[i] *= dims[j];
1069 for (
int i = N-1; i >= 1; i--) {
1070 for (
int j = i - 1; j >= 0; j--)
1071 _offset[i] *= dims[j];
1082 template<
typename... Args>
1090 check_operator_args_(dims...);
1094 set_size_(loc_dims);
1109template<
class T, cs::layout L = cs::layout::right>
1112template<
class T, cs::layout L = cs::layout::right>
1115template<
class T, cs::layout L = cs::layout::right>
1118template<
class T, cs::layout L = cs::layout::right>
1121template<
class T,
int N>
1124template<
class T,
int N>
Definition: cs_array.h:1111
Definition: cs_mdspan.h:69
CS_F_HOST void set_to_val_on_subset(T val, const cs_lnum_t n_elts, const cs_lnum_t elt_ids[])
Set subset of values of the data array to a constant value.
Definition: cs_mdspan.h:634
CS_F_HOST void set_to_val(T val, const cs_lnum_t n_vals=-1)
Set all values of the data array to a constant value.
Definition: cs_mdspan.h:574
CS_F_HOST_DEVICE void copy_data(mdspan &other, const cs_lnum_t n_vals=-1)
Copy data from another mdspan, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:812
CS_F_HOST friend void swap(mdspan &first, mdspan &second)
Class swap operator used for assignment or move.
Definition: cs_mdspan.h:183
CS_F_HOST_DEVICE mdspan(T *data, const cs_lnum_t(&dims)[N])
Constructor method using dimensions.
Definition: cs_mdspan.h:121
CS_F_HOST_DEVICE cs_lnum_t size()
Getter for total size.
Definition: cs_mdspan.h:421
CS_F_HOST_DEVICE void zero(cs_dispatch_context &ctx)
Set all values of the data array to 0.
Definition: cs_mdspan.h:726
CS_F_HOST_DEVICE T * sub_array(Args... indices)
Get sub array based on index.
Definition: cs_mdspan.h:557
CS_F_HOST_DEVICE cs_lnum_t size() const
Getter for total size.
Definition: cs_mdspan.h:437
CS_F_HOST_DEVICE void copy_data(const T *data, const cs_lnum_t n_vals=-1)
Copy data from const raw pointer, we suppose that data size is same as that of the array.
Definition: cs_mdspan.h:780
CS_F_HOST_DEVICE cs_lnum_t extent(int i)
Getter for extent along a given dimension.
Definition: cs_mdspan.h:454
CS_F_HOST void set_to_val_on_subset(cs_dispatch_context &ctx, T val, const cs_lnum_t n_elts, const cs_lnum_t elt_ids[])
Set a subset of values of the data array to a constant value while providing a dispatch context....
Definition: cs_mdspan.h:671
CS_F_HOST_DEVICE mdspan()
Default constructor method leading to "empty container".
Definition: cs_mdspan.h:87
CS_F_HOST_DEVICE void copy_data(cs_dispatch_context &ctx, const T *data, const cs_lnum_t n_vals=-1)
Copy data from const raw pointer, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:878
CS_F_HOST_DEVICE U * data()
Getter for data raw pointer with recast (casts T* to U*)
Definition: cs_mdspan.h:508
CS_F_HOST_DEVICE void copy_data(cs_dispatch_context &ctx, mdspan &other, const cs_lnum_t n_vals=-1)
Copy data from another mdspan, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:907
CS_F_HOST_DEVICE ~mdspan()
Desstructor method using dimensions.
Definition: cs_mdspan.h:169
CS_F_HOST mdspan & operator=(mdspan &&other)
Definition: cs_mdspan.h:220
CS_F_HOST_DEVICE T * data()
Getter for data raw pointer.
Definition: cs_mdspan.h:490
CS_F_HOST_DEVICE void zero()
Set all values of the data array to 0.
Definition: cs_mdspan.h:703
CS_F_HOST_DEVICE mdspan(const mdspan &other)
Constructor method using copy. May be a shallow copy.
Definition: cs_mdspan.h:138
CS_F_HOST mdspan(mdspan &&other)
Move constructor.
Definition: cs_mdspan.h:154
CS_F_HOST_DEVICE mdspan< T, N-sizeof...(Args), L > sub_view(Args... indices)
Getter for a subspan based on first dimension.
Definition: cs_mdspan.h:525
CS_F_HOST_DEVICE cs_lnum_t extent(int i) const
Getter for extent along a given dimension.
Definition: cs_mdspan.h:473
CS_F_HOST_DEVICE mdspan(T *data, Args... indices)
Constructor method using only global size (works for N=1).
Definition: cs_mdspan.h:103
CS_F_HOST void set_to_val(cs_dispatch_context &ctx, T val, const cs_lnum_t n_vals=-1)
Set all values of the data array to a constant value while providing a dispatch context....
Definition: cs_mdspan.h:606
CS_F_HOST_DEVICE void copy_data(cs_dispatch_context &ctx, T *data, const cs_lnum_t n_vals=-1)
Copy data from raw pointer, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:848
CS_F_HOST_DEVICE void copy_data(T *data, const cs_lnum_t n_vals=-1)
Copy data from raw pointer, we suppose that data size is same as that of the array.
Definition: cs_mdspan.h:748
CS_F_HOST mdspan & operator=(const mdspan &other)
Assignment operator.
Definition: cs_mdspan.h:207
auto parallel_for(cs_lnum_t n, F &&f, Args &&... args)
Definition: cs_dispatch.h:1570
void wait(void)
Wait (synchronize) until launched computations have finished.
Definition: cs_dispatch.h:1635
Definition: cs_dispatch.h:1711
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
#define CS_LAMBDA
Definition: cs_defs.h:594
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
#define CS_F_HOST
Definition: cs_defs.h:583
Definition: cs_array.h:1098
layout
Definition: cs_mdspan.h:52
Utility template which returns "true" for a given pack. This is necessary of std::enable_if_t<> when ...
Definition: cs_defs.h:832
Utility template to check if a pack of parameters is made of integral types.
Definition: cs_defs.h:809