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.is_contiguous(),
"Error in nda::reshape: Only contiguous arrays/views are supported");
113 EXPECTS_WITH_MESSAGE(a.has_positive_strides(),
"Error in nda::reshape: Only arrays/views with positive strides are supported")
116 using A_t = std::remove_cvref_t<A>;
117 static_assert(A_t::is_stride_order_C() or A_t::is_stride_order_Fortran() or R == 1,
118 "Error in nda::reshape: Only C or Fortran layouts are supported");
123 using layout_t = std::conditional_t<(R == 1), C_layout::template mapping<1>,
typename std::decay_t<A>::layout_policy_t::template mapping<R>>;
138 template <MemoryArray A, std::integral... Ints>
140 return reshape(std::forward<A>(a), std::array<
long,
sizeof...(Ints)>{
static_cast<long>(is)...});
144 template <MemoryArray A, std::
integral Int, auto newRank>
145 [[deprecated(
"Please use reshape(arr, shape) instead")]]
auto reshaped_view(A &&a, std::array<Int, newRank>
const &new_shape) {
146 return reshape(std::forward<A>(a), new_shape);
158 template <MemoryArray A>
160 return reshape(std::forward<A>(a), std::array{a.size()});
174 template <u
int64_t Permutation, MemoryArray A>
190 template <
typename A>
197 static_assert(std::tuple_size_v<
decltype(a.a)> == 1,
"Error in nda::transpose: Cannot transpose expr_call with more than one array argument");
198 return map(a.f)(
transpose(std::get<0>(std::forward<A>(a).a)));
214 template <
int I,
int J, MemoryArray A>
245 template <MemoryArray A,
typename... IdxGrps>
253 template <
int N, auto R>
254 constexpr std::array<int, R + N> complete_stride_order_with_fast(std::array<int, R>
const &order) {
256 for (
int i = 0; i < R; ++i) r[i] = order[i];
257 for (
int i = 0; i < N; ++i) r[R + i] = R + i;
271 template <
int N,
typename A>
275 auto const &lay = a.indexmap();
276 using lay_t = std::decay_t<
decltype(lay)>;
278 static constexpr uint64_t new_stride_order_encoded =
encode(detail::complete_stride_order_with_fast<N>(lay_t::stride_order));
280 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.