69 template <MemoryArray A,
typename NewLayoutType>
71 using A_t = std::remove_reference_t<A>;
74 using layout_policy =
typename detail::layout_to_policy<NewLayoutType>::type;
77 static constexpr auto algebra = (NewLayoutType::rank() ==
get_rank<A> ? get_algebra<A> :
'A');
79 if constexpr (is_regular_v<A> and !std::is_reference_v<A>) {
81 using array_t =
basic_array<
typename A_t::value_type, NewLayoutType::rank(), layout_policy, algebra,
typename A_t::container_policy_t>;
82 return array_t{new_layout, std::forward<A>(a).storage()};
85 using value_t = std::conditional_t<std::is_const_v<A_t>,
const typename A_t::value_type,
typename A_t::value_type>;
88 return basic_array_view<value_t, NewLayoutType::rank(), layout_policy, algebra, accessor_policy, owning_policy>{new_layout, a.storage()};
107 template <MemoryArray A, std::
integral Int, auto R>
108 auto reshape(A &&a, std::array<Int, R>
const &new_shape) {
110 EXPECTS_WITH_MESSAGE(a.size() == (std::accumulate(new_shape.cbegin(), new_shape.cend(), Int{1}, std::multiplies<>{})),
111 "Error in nda::reshape: New shape has an incorrect number of elements");
112 EXPECTS_WITH_MESSAGE(a.indexmap().is_contiguous(),
"Error in nda::reshape: Only contiguous arrays/views are supported");
115 using A_t = std::remove_cvref_t<A>;
116 static_assert(A_t::is_stride_order_C() or A_t::is_stride_order_Fortran() or R == 1,
117 "Error in nda::reshape: Only C or Fortran layouts are supported");
120 using layout_t =
typename std::decay_t<A>::layout_policy_t::template mapping<R>;
135 template <MemoryArray A, std::integral... Ints>
137 return reshape(std::forward<A>(a), std::array<
long,
sizeof...(Ints)>{
static_cast<long>(is)...});
141 template <MemoryArray A, std::
integral Int, auto newRank>
142 [[deprecated(
"Please use reshape(arr, shape) instead")]]
auto reshaped_view(A &&a, std::array<Int, newRank>
const &new_shape) {
143 return reshape(std::forward<A>(a), new_shape);
155 template <MemoryArray A>
157 return reshape(std::forward<A>(a), std::array{a.size()});
171 template <u
int64_t Permutation, MemoryArray A>
187 template <
typename A>
194 static_assert(std::tuple_size_v<
decltype(a.a)> == 1,
"Error in nda::transpose: Cannot transpose expr_call with more than one array argument");
195 return map(a.f)(
transpose(std::get<0>(std::forward<A>(a).a)));
211 template <
int I,
int J, MemoryArray A>
242 template <MemoryArray A,
typename... IdxGrps>
250 template <
int N, auto R>
251 constexpr std::array<int, R + N> complete_stride_order_with_fast(std::array<int, R>
const &order) {
253 for (
int i = 0; i < R; ++i) r[i] = order[i];
254 for (
int i = 0; i < N; ++i) r[R + i] = R + i;
268 template <
int N,
typename A>
272 auto const &lay = a.indexmap();
273 using lay_t = std::decay_t<
decltype(lay)>;
275 static constexpr uint64_t new_stride_order_encoded =
encode(detail::complete_stride_order_with_fast<N>(lay_t::stride_order));
277 using new_lay_t =
idx_map<get_rank<A> + N, new_static_extents_encoded, new_stride_order_encoded, lay_t::layout_prop>;
Provides utility functions for std::array.
A generic view of a multi-dimensional array.
A generic multi-dimensional array.
Layout that specifies how to map multi-dimensional indices to a linear/flat index.
Check if a given type satisfies the memory array concept.
Provides concepts for the nda library.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
auto transposed_view(A &&a)
Transpose two indices/dimensions of an nda::basic_array or nda::basic_array_view.
auto reinterpret_add_fast_dims_of_size_one(A &&a)
Add N fast varying dimensions of size 1 to a given nda::basic_array or nda::basic_array_view.
auto permuted_indices_view(A &&a)
Permute the indices/dimensions of an nda::basic_array or nda::basic_array_view.
auto map_layout_transform(A &&a, NewLayoutType const &new_layout)
Transform the memory layout of an nda::basic_array or nda::basic_array_view.
auto flatten(A &&a)
Flatten an nda::basic_array or nda::basic_array_view to a 1-dimensional array/view by reshaping it.
auto transpose(A &&a)
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.
auto reshape(A &&a, std::array< Int, R > const &new_shape)
Reshape an nda::basic_array or nda::basic_array_view.
auto group_indices_view(A &&a, IdxGrps...)
Create a new nda::basic_array or nda::basic_array_view by grouping indices together of a given array/...
auto reshaped_view(A &&a, std::array< Int, newRank > const &new_shape)
mapped< F > map(F f)
Create a lazy function call expression on arrays/views.
constexpr int get_rank
Constexpr variable that specifies the rank of an nda::Array or of a contiguous 1-dimensional range.
std::remove_reference_t< decltype(basic_array_view{std::declval< T >()})> get_view_t
Get the type of the nda::basic_array_view that would be obtained by constructing a view from a given ...
constexpr bool is_regular_or_view_v
Constexpr variable that is true if type A is either a regular array or a view.
Provides functions used in nda::group_indices_view.
auto group_indices_layout(idx_map< Rank, StaticExtents, StrideOrder, LayoutProp > const &idxm, IdxGrps...)
Given an nda::idx_map and a partition of its indices, return a new nda::idx_map with the grouped indi...
constexpr std::array< int, N > transposition(int i, int j)
Get the permutation representing a single given transposition.
constexpr uint64_t encode(std::array< int, N > const &a)
Encode a std::array<int, N> in a uint64_t.
constexpr std::array< int, N > reverse_identity()
Get the reverse identity permutation.
constexpr std::array< T, R1+R2 > join(std::array< T, R1 > const &a1, std::array< T, R2 > const &a2)
Make a new std::array by joining two existing std::array objects.
constexpr std::array< T, R > make_initialized_array(T v)
Create a new std::array object initialized with a specific value.
constexpr std::array< T, R > make_std_array(std::array< U, R > const &a)
Convert a std::array with value type U to a std::array with value type T.
constexpr bool is_instantiation_of_v
Constexpr variable that is true if type T is an instantiation of TMPLT (see nda::is_instantiation_of)...
Provides a class that maps multi-dimensional indices to a linear index and vice versa.
Provides definitions of various layout policies.
Provides lazy function calls on arrays/views.
Provides utilities to work with permutations and to compactly encode/decode std::array objects.
Provides type traits for the nda library.