20
21
22
26#include "./permutation.hpp"
28#include "./slice_static.hpp"
29#include "../macros.hpp"
30#include "../traits.hpp"
47
48
49
52
53
54
55
60
61
62
63
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 template <
int Rank, uint64_t StaticExtents, uint64_t StrideOrder,
layout_prop_e LayoutProp>
104 static_assert(Rank < 16,
"Error in nda::idx_map: Rank must be < 16");
105 static_assert((StrideOrder != 0)
or (Rank == 1),
"Error in nda::idx_map: StrideOrder can only be zero for 1D arrays");
108 std::array<
long, Rank> len;
111 std::array<
long, Rank> str;
118 static constexpr std::array<
int, Rank>
static_extents = decode<Rank>(StaticExtents);
121 static constexpr std::array<
int, Rank>
stride_order = (StrideOrder == 0 ? permutations::identity<Rank>() : decode<Rank>(StrideOrder));
133 template <
typename T>
137 template <
typename T>
145 for (
int u = 0; u < Rank; ++u) r += (
static_extents[u] == 0 ? 1 : 0);
151
152
153
154 static constexpr int rank()
noexcept {
return Rank; }
157
158
159
160 [[
nodiscard]]
long size()
const noexcept {
return std::accumulate(len.cbegin(), len.cend(), 1L, std::multiplies<>{}); }
163
164
165
175
176
177
181
182
183
187
188
189
193
194
195
196
197
198
199
202 if (s == 0)
return true;
203 auto const str_x_len = str * len;
204 return (*std::max_element(str_x_len.cbegin(), str_x_len.cend()) == s);
208
209
210
211
212
213
214
215
218 if (s == 0)
return true;
219 auto const str_x_len = str * len;
220 return (*std::max_element(str_x_len.cbegin(), str_x_len.cend()) == s *
min_stride());
224
225
226
230
231
232
236
237
238
239
240
241
242
243 template <
std::integral Int>
245 auto dims_to_check = std::vector<
int>{};
246 dims_to_check.reserve(Rank);
248 if (lenptr[dim] > 1) dims_to_check.push_back(dim);
249 for (
int n = 1; n < dims_to_check.size(); ++n)
250 if (std::abs(strptr[dims_to_check[n - 1]]) < std::abs(strptr[dims_to_check[n]]))
return false;
255
256
257
258
263 void compute_strides_contiguous() {
265 for (
int v =
rank() - 1; v >= 0; --v) {
274 void assert_static_extents_and_len_are_compatible()
const {
275#ifdef NDA_ENFORCE_BOUNDCHECK
276 if constexpr (n_dynamic_extents != Rank) {
278 for (
int u = 0; u < Rank; ++u)
279 if (static_extents[u] != 0) EXPECTS(static_extents[u] == len[u]);
289 static constexpr bool check_stride_order =
false;
293 static std::array<
long, Rank> merge_static_and_dynamic_extents(std::array<
long,
n_dynamic_extents>
const &dynamic_extents) {
294 std::array<
long, Rank> extents;
303
304
305
306
307
308
309
313 compute_strides_contiguous();
315 for (
int u = 0; u < Rank; ++u)
321
322
323
324
325
327 idx_map(
idx_map<Rank, StaticExtents, StrideOrder, LP>
const &idxm)
noexcept : len(idxm.lengths()), str(idxm.strides()) {
329 EXPECTS(is_stride_order_valid());
334 EXPECTS_WITH_MESSAGE(idxm.is_contiguous(),
"Error in nda::idx_map: Constructing a contiguous from a non-contiguous layout");
337 EXPECTS_WITH_MESSAGE(idxm.is_strided_1d(),
"Error in nda::idx_map: Constructing a strided_1d from a non-strided_1d layout");
343
344
345
346
347
348
350 idx_map(
idx_map<Rank, SE, StrideOrder, LP>
const &idxm)
noexcept(
false) : len(idxm.lengths()), str(idxm.strides()) {
352 EXPECTS(is_stride_order_valid());
357 EXPECTS_WITH_MESSAGE(idxm.is_contiguous(),
"Error in nda::idx_map: Constructing a contiguous from a non-contiguous layout");
360 EXPECTS_WITH_MESSAGE(idxm.is_strided_1d(),
"Error in nda::idx_map: Constructing a strided_1d from a non-strided_1d layout");
365 assert_static_extents_and_len_are_compatible();
369
370
371
372
373
376 : len(shape), str(strides) {
377 EXPECTS(std::all_of(shape.cbegin(), shape.cend(), [](
auto const &i) {
return i >= 0; }));
378 if constexpr (check_stride_order) {
379 if (
not is_stride_order_valid())
throw std::runtime_error(
"Error in nda::idx_map: Incompatible strides, shape and stride order");
384
385
386
387
388
389 template <
std::integral Int =
long>
390 idx_map(std::array<Int, Rank>
const &shape)
noexcept : len(stdutil::make_std_array<
long>(shape)) {
391 EXPECTS(std::all_of(shape.cbegin(), shape.cend(), [](
auto const &i) {
return i >= 0; }));
392 assert_static_extents_and_len_are_compatible();
393 compute_strides_contiguous();
397
398
399
400
401
402
403
406 :
idx_map(merge_static_and_dynamic_extents(shape)) {}
409
410
411
412
413
414
415
416
421 static_assert((
stride_order_encoded == SO),
"Error in nda::idx_map: Incompatible stride orders");
425
426
427
428
433 static_assert(R == Rank,
"Error in nda::idx_map: Incompatible ranks");
450 template <
bool skip_stride,
auto I>
457 template <
bool skip_stride,
auto I>
458 [[nodiscard]]
FORCEINLINE long myget(
long arg)
const noexcept {
459 if constexpr (skip_stride
and (I ==
stride_order[Rank - 1])) {
464 return arg * std::get<I>(str);
472 template <
typename... Args, size_t... Is>
473 [[nodiscard]]
FORCEINLINE long call_impl(std::index_sequence<Is...>, Args... args)
const noexcept {
475 static constexpr int e_pos = ((std::is_same_v<Args,
ellipsis> ?
int(Is) + 1 : 0) + ...) - 1;
477 if constexpr (e_pos == -1) {
479 if constexpr (smallest_stride_is_one) {
481 return (myget<
true, Is>(
static_cast<
long>(args)) + ...);
484 return ((args * std::get<Is>(str)) + ...);
488 return (myget<smallest_stride_is_one, (Is < e_pos ? Is : Is - 1)>(args) + ...);
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511 template <
typename... Args>
513#ifdef NDA_ENFORCE_BOUNDCHECK
519 return call_impl(std::make_index_sequence<
sizeof...(Args)>{}, args...);
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543 std::array<
long, Rank>
to_idx(
long lin_idx)
const {
545 std::array<
long, Rank> residues;
546 residues[0] = lin_idx;
547 for (
auto i : range(1, Rank)) { residues[i] = residues[i - 1] % str[
stride_order[i - 1]]; }
550 std::array<
long, Rank> idx;
551 idx[Rank - 1] = residues[Rank - 1] / str[
stride_order[Rank - 1]];
552 for (
auto i : range(Rank - 2, -1, -1)) { idx[i] = (residues[i] - residues[i + 1]) / str[
stride_order[i]]; }
559
560
561
562
563
564
565
566
567
568
569 template <
typename... Args>
570 auto slice(Args
const &...args)
const {
571 return slice_static::slice_idx_map(*
this, args...);
575
576
577
578
579
580
581
582
583
586 return (Rank == R
and len == rhs.lengths()
and str == rhs.strides());
590
591
592
593
594
595
596
597
598
599
600
601
602
603 template <uint64_t Permutation>
646 static constexpr std::array<
int, Rank> permu = decode<Rank>(Permutation);
647 static constexpr std::array<
int, Rank> new_stride_order = permutations::compose(permu,
stride_order);
648 static constexpr std::array<
int, Rank> new_static_extents = permutations::apply_inverse(permu,
static_extents);
650 return idx_map<Rank, encode(new_static_extents), encode(new_stride_order), LayoutProp>{permutations::apply_inverse(permu,
lengths()),
651 permutations::apply_inverse(permu,
strides())};
void swap(nda::basic_array_view< V1, R1, LP1, A1, AP1, OP1 > &a, nda::basic_array_view< V2, R2, LP2, A2, AP2, OP2 > &b)=delete
std::swap is deleted for nda::basic_array_view.
Iterator for nda::basic_array and nda::basic_array_view types.
A generic view of a multi-dimensional array.
basic_array_view(A &&a) noexcept
Generic constructor from any nda::MemoryArray type.
const_iterator end() const noexcept
Get a const iterator to the end of the view/array.
ValueType const * data() const noexcept
Get a pointer to the actual data (in general this is not the beginning of the memory block for a view...
auto as_array_view() const
static constexpr bool is_stride_order_C() noexcept
Is the stride order of the view/array in C-order?
iterator begin() noexcept
Get an iterator to the beginning of the view/array.
ValueType * data() noexcept
Get a pointer to the actual data (in general this is not the beginning of thr memory block for a view...
basic_array_view & operator=(RHS const &rhs) noexcept
Assignment operator makes a deep copy of the contents of an nda::ArrayOfRank object.
auto & operator/=(RHS const &rhs) noexcept
Division assignment operator.
static constexpr int rank
Number of dimensions of the view.
decltype(auto) operator[](T const &idx) const &noexcept(has_no_boundcheck)
Subscript operator to access the 1-dimensional view/array.
auto const & shape() const noexcept
Get the shape of the view/array.
static __inline__ decltype(auto) call(Self &&self, Ts const &...idxs) noexcept(has_no_boundcheck)
Implementation of the function call operator.
basic_array_view(layout_t const &idxm, ValueType *p) noexcept
Construct a view from a bare pointer to some contiguous data and a memory layout.
__inline__ decltype(auto) operator()(Ts const &...idxs) &noexcept(has_no_boundcheck)
Non-const overload of nda::basic_array_view::operator()(Ts const &...) const &.
decltype(auto) operator[](T const &x) &&noexcept(has_no_boundcheck)
Rvalue overload of nda::basic_array_view::operator[](T const &) const &.
basic_array_view(R &rg) noexcept
Construct a 1-dimensional view of a general contiguous range.
basic_array_view & operator=(basic_array_view const &rhs) noexcept
Copy assignment operator makes a deep copy of the contents of the view.
basic_array_view(std::array< ValueType, N > &a) noexcept
Construct a 1-dimensional view of a std::array.
auto const & strides() const noexcept
Get the strides of the view/array (see nda::idx_map for more details on how we define strides).
long shape(int i) const noexcept
storage_t storage() &&noexcept
Get the data storage of the view/array.
decltype(auto) operator[](T const &x) &noexcept(has_no_boundcheck)
Non-const overload of nda::basic_array_view::operator[](T const &) const &.
decltype(auto) operator()(_linear_index_t idx) noexcept
Non-const overload of nda::basic_array_view::operator()(_linear_index_t) const.
auto & operator+=(RHS const &rhs) noexcept
Addition assignment operator.
auto indices() const noexcept
Get a range that generates all valid index tuples.
basic_array_view()=default
Default constructor constructs an empty view with a default constructed memory handle and layout.
long is_contiguous() const noexcept
Is the memory layout of the view/array contiguous?
auto & operator=(R const &rhs) noexcept
Assignment operator makes a deep copy of a general contiguous range and assigns it to the 1-dimension...
storage_t & storage() &noexcept
Get the data storage of the view/array.
static constexpr bool is_stride_order_Fortran() noexcept
Is the stride order of the view/array in Fortran-order?
decltype(auto) operator()(_linear_index_t idx) const noexcept
Access the element of the view/array at the given nda::_linear_index_t.
__inline__ decltype(auto) operator()(Ts const &...idxs) const &noexcept(has_no_boundcheck)
Function call operator to access the view/array.
auto & operator*=(RHS const &rhs) noexcept
Multiplication assignment operator.
basic_array_view(std::array< std::remove_const_t< ValueType >, N > const &a) noexcept
Construct a 1-dimensional view of a std::array.
friend void deep_swap(basic_array_view a, basic_array_view b) noexcept
Swap two views by swapping their data.
iterator end() noexcept
Get an iterator to the end of the view/array.
long size() const noexcept
Get the total size of the view/array.
auto & operator-=(RHS const &rhs) noexcept
Subtraction assignment operator.
bool empty() const
Is the view/array empty?
basic_array_view(std::array< long, Rank > const &shape, ValueType *p) noexcept
Construct a view from a bare pointer to some contiguous data and a shape.
bool is_empty() const noexcept
friend void swap(basic_array_view &a, basic_array_view &b) noexcept
Swap two views by swapping their memory handles and layouts.
constexpr auto stride_order() const noexcept
Get the stride order of the memory layout of the view/array (see nda::idx_map for more details on how...
const_iterator cbegin() const noexcept
Get a const iterator to the beginning of the view/array.
basic_array_view(layout_t const &idxm, storage_t st)
Construct a view from a given layout and memory handle.
static constexpr int iterator_rank
Rank of the nda::array_iterator for the view/array.
basic_array_view(basic_array_view &&)=default
Default move constructor moves the memory handle and layout.
void rebind(basic_array_view< T, R, LP, A, AP, OP > v) noexcept
Rebind the current view to another view.
basic_array_view(basic_array_view const &)=default
Default copy constructor copies the memory handle and layout.
__inline__ decltype(auto) operator()(Ts const &...idxs) &&noexcept(has_no_boundcheck)
Rvalue overload of nda::basic_array_view::operator()(Ts const &...) const &.
long extent(int i) const noexcept
Get the extent of the ith dimension.
constexpr auto const & indexmap() const noexcept
Get the memory layout of the view/array.
const_iterator begin() const noexcept
Get a const iterator to the beginning of the view/array.
const_iterator cend() const noexcept
Get a const iterator to the end of the view/array.
storage_t const & storage() const &noexcept
Get the data storage of the view/array.
A generic multi-dimensional array.
auto & operator+=(RHS const &rhs) noexcept
Addition assignment operator.
decltype(auto) operator[](T const &idx) const &noexcept(has_no_boundcheck)
Subscript operator to access the 1-dimensional view/array.
basic_array(basic_array< ValueType, 2, LayoutPolicy, A2, ContainerPolicy > &&a) noexcept
Construct a 2-dimensional array from another 2-dimensional array with a different algebra.
basic_array & operator=(RHS const &rhs)
Assignment operator makes a deep copy of an nda::ArrayOfRank object.
static constexpr bool is_stride_order_Fortran() noexcept
Is the stride order of the view/array in Fortran-order?
ValueType const * data() const noexcept
Get a pointer to the actual data (in general this is not the beginning of the memory block for a view...
ValueType * data() noexcept
Get a pointer to the actual data (in general this is not the beginning of thr memory block for a view...
long shape(int i) const noexcept
const_iterator cbegin() const noexcept
Get a const iterator to the beginning of the view/array.
static constexpr int rank
Number of dimensions of the array.
static constexpr bool is_stride_order_C() noexcept
Is the stride order of the view/array in C-order?
storage_t & storage() &noexcept
Get the data storage of the view/array.
basic_array(basic_array< ValueType, Rank, LayoutPolicy, A, CP > a) noexcept
Construct an array from another array with a different algebra and/or container policy.
auto const & strides() const noexcept
Get the strides of the view/array (see nda::idx_map for more details on how we define strides).
basic_array(Ints... is)
Construct an array with the given dimensions.
static basic_array ones(Ints... is)
Make a one-initialized array with the given dimensions.
const_iterator begin() const noexcept
Get a const iterator to the beginning of the view/array.
auto as_array_view() const
Convert the current array to a view with an 'A' (array) algebra.
long extent(int i) const noexcept
Get the extent of the ith dimension.
basic_array(std::initializer_list< ValueType > const &l)
Construct a 1-dimensional array from an initializer list.
decltype(auto) operator[](T const &x) &&noexcept(has_no_boundcheck)
Rvalue overload of nda::basic_array_view::operator[](T const &) const &.
long is_contiguous() const noexcept
Is the memory layout of the view/array contiguous?
basic_array(std::initializer_list< std::initializer_list< ValueType > > const &l2)
Construct a 2-dimensional array from a double nested initializer list.
decltype(auto) operator()(_linear_index_t idx) noexcept
Non-const overload of nda::basic_array_view::operator()(_linear_index_t) const.
__inline__ decltype(auto) operator()(Ts const &...idxs) &noexcept(has_no_boundcheck)
Non-const overload of nda::basic_array_view::operator()(Ts const &...) const &.
bool empty() const
Is the view/array empty?
void resize(std::array< long, Rank > const &shape)
Resize the array to a new shape.
basic_array(Int sz, RHS const &val)
Construct a 1-dimensional array with the given size and initialize each element to the given scalar v...
static basic_array ones(std::array< Int, Rank > const &shape)
Make a one-initialized array with the given shape.
constexpr auto stride_order() const noexcept
Get the stride order of the memory layout of the view/array (see nda::idx_map for more details on how...
auto & operator/=(RHS const &rhs) noexcept
Division assignment operator.
auto as_array_view()
Convert the current array to a view with an 'A' (array) algebra.
basic_array(A const &a)
Construct an array from an nda::ArrayOfRank object with the same rank by copying each element.
static basic_array zeros(Ints... is)
Make a zero-initialized array with the given dimensions.
auto indices() const noexcept
Get a range that generates all valid index tuples.
static __inline__ decltype(auto) call(Self &&self, Ts const &...idxs) noexcept(has_no_boundcheck)
Implementation of the function call operator.
void resize(Ints const &...is)
Resize the array to a new shape.
storage_t storage() &&noexcept
Get the data storage of the view/array.
basic_array()
Default constructor constructs an empty array with a default constructed memory handle and layout.
bool is_empty() const noexcept
auto & operator=(R const &rhs) noexcept
Assignment operator makes a deep copy of a general contiguous range and assigns it to the 1-dimension...
storage_t const & storage() const &noexcept
Get the data storage of the view/array.
basic_array & operator=(basic_array const &)=default
Default copy assignment copies the memory handle and layout from the right hand side array.
basic_array & operator=(basic_array< ValueType, Rank, LayoutPolicy, A, CP > const &rhs)
Assignment operator makes a deep copy of another array with a different algebra and/or container poli...
basic_array(basic_array const &a)=default
Default copy constructor copies the memory handle and layout.
basic_array(std::initializer_list< std::initializer_list< std::initializer_list< ValueType > > > const &l3)
Construct a 3-dimensional array from a triple nested initializer list.
iterator begin() noexcept
Get an iterator to the beginning of the view/array.
basic_array(layout_t const &layout)
Construct an array with the given memory layout.
static basic_array rand(Ints... is)
Make a random-initialized array with the given dimensions.
basic_array(layout_t const &layout, storage_t &&storage) noexcept
Construct an array with the given memory layout and with an existing memory handle/storage.
static constexpr int iterator_rank
Rank of the nda::array_iterator for the view/array.
auto & operator-=(RHS const &rhs) noexcept
Subtraction assignment operator.
const_iterator end() const noexcept
Get a const iterator to the end of the view/array.
basic_array(basic_array &&)=default
Default move constructor moves the memory handle and layout.
__inline__ decltype(auto) operator()(Ts const &...idxs) &&noexcept(has_no_boundcheck)
Rvalue overload of nda::basic_array_view::operator()(Ts const &...) const &.
basic_array(std::array< Int, Rank > const &shape)
Construct an array with the given shape.
const_iterator cend() const noexcept
Get a const iterator to the end of the view/array.
auto const & shape() const noexcept
Get the shape of the view/array.
long size() const noexcept
Get the total size of the view/array.
decltype(auto) operator[](T const &x) &noexcept(has_no_boundcheck)
Non-const overload of nda::basic_array_view::operator[](T const &) const &.
auto & operator*=(RHS const &rhs) noexcept
Multiplication assignment operator.
basic_array & operator=(basic_array &&)=default
Default move assignment moves the memory handle and layout from the right hand side array.
static basic_array zeros(std::array< Int, Rank > const &shape)
Make a zero-initialized array with the given shape.
__inline__ decltype(auto) operator()(Ts const &...idxs) const &noexcept(has_no_boundcheck)
Function call operator to access the view/array.
constexpr auto const & indexmap() const noexcept
Get the memory layout of the view/array.
iterator end() noexcept
Get an iterator to the end of the view/array.
decltype(auto) operator()(_linear_index_t idx) const noexcept
Access the element of the view/array at the given nda::_linear_index_t.
static basic_array rand(std::array< Int, Rank > const &shape)
Make a random-initialized array with the given shape.
Layout that specifies how to map multi-dimensional indices to a linear/flat index.
__inline__ long operator()(Args const &...args) const noexcept(true)
Function call operator to map a given multi-dimensional index to a linear index.
static constexpr std::array< int, Rank > stride_order
Decoded stride order.
idx_map(idx_map< Rank, StaticExtents, StrideOrder, LP > const &idxm) noexcept
Construct a new map from an existing map with different layout properties.
static bool is_stride_order_valid(Int *lenptr, Int *strptr)
Check if a given shape and strides are compatible with the stride order.
static constexpr layout_info_t layout_info
Compile-time information about the layout (stride order and layout properties).
idx_map(idx_map &&)=default
Default move constructor.
long size() const noexcept
Get the total number of elements.
long min_stride() const noexcept
Get the value of the smallest stride.
idx_map(std::array< long, n_dynamic_extents > const &shape) noexcept
Construct a new map from an array with its dynamic extents.
auto transpose() const
Create a new map by permuting the indices/dimensions of the current map with a given permutation.
std::array< long, Rank > to_idx(long lin_idx) const
Calculate the multi-dimensional index from a given linear index.
bool is_stride_order_valid() const
Check if the shape and strides of the current map are compatible with its stride order.
idx_map(idx_map< Rank, SE, SO, LP > const &)
Construct a new map from an existing map with a different stride order.
bool operator==(idx_map< R, SE, SO, LP > const &rhs) const
Equal-to operator for two nda::idx_map objects.
static constexpr bool is_stride_order_C()
Is the stride order equal to C-order?
static constexpr int n_dynamic_extents
Number of dynamic dimensions/extents.
static constexpr uint64_t stride_order_encoded
Encoded stride order.
static constexpr int rank() noexcept
Get the rank of the map.
static constexpr std::array< int, Rank > static_extents
Decoded static extents.
bool is_strided_1d() const noexcept
Is the data strided in memory with a constant stride?
static constexpr int argument_is_allowed_for_call_or_slice
Alias template to check if type T can be used to either access a single element or a slice of element...
idx_map(std::array< Int, Rank > const &shape) noexcept
Construct a new map from a given shape and with contiguous strides.
std::array< long, Rank > const & lengths() const noexcept
Get the extents of all dimensions.
auto slice(Args const &...args) const
Get a new nda::idx_map by taking a slice of the current one.
static constexpr bool is_stride_order_Fortran()
Is the stride order equal to Fortran-order?
idx_map(idx_map const &)=default
Default copy constructor.
static constexpr int argument_is_allowed_for_call
Alias template to check if type T can be used to access a single element.
static constexpr long ce_size() noexcept
Get the size known at compile-time.
bool is_contiguous() const noexcept
Is the data contiguous in memory?
idx_map(idx_map< Rank, SE, StrideOrder, LP > const &idxm) noexcept(false)
Construct a new map from an existing map with different layout properties and different static extent...
idx_map(std::array< long, Rank > const &shape, std::array< long, Rank > const &strides) noexcept(!check_stride_order)
Construct a new map from a given shape and strides.
idx_map()
Default constructor.
std::array< long, Rank > const & strides() const noexcept
Get the strides of all dimensions.
idx_map & operator=(idx_map const &)=default
Default copy assignment operator.
static constexpr layout_prop_e layout_prop
Compile-time memory layout properties.
static constexpr uint64_t static_extents_encoded
Encoded static extents.
idx_map & operator=(idx_map &&)=default
Default move assignment operator.
idx_map(std::array< long, R > const &)
Construct a new map with a shape of a different rank.
#define CUSOLVER_CHECK(X, info,...)
#define NDA_RUNTIME_ERROR
auto rand(std::array< Int, Rank > const &shape)
Make an array of the given shape and initialize it with random values from the uniform distribution o...
decltype(auto) make_regular(A &&a)
Make a given object regular.
void resize_or_check_if_view(A &a, std::array< long, A::rank > const &sha)
Resize a given regular array to the given shape or check if a given view as the correct shape.
decltype(auto) to_unified(A &&a)
Convert an nda::MemoryArray to its regular type on unified memory.
auto make_const_view(basic_array< T, R, LP, A, CP > const &a)
Make an nda::basic_array_view with a const value type from a given nda::basic_array.
auto zeros(Ints... is)
Make an array of the given shape on the given address space and zero-initialize it.
auto zeros(std::array< Int, Rank > const &shape)
Make an array of the given shape on the given address space and zero-initialize it.
auto rand(Ints... is)
Make an array of the given dimensions and initialize it with random values from the uniform distribut...
auto arange(long first, long last, long step=1)
Make a 1-dimensional integer array and initialize it with values of a given nda::range.
decltype(auto) to_host(A &&a)
Convert an nda::MemoryArray to its regular type on host memory.
auto make_matrix_view(basic_array_view< T, R, LP, A, AP, OP > const &a)
Make an nda::matrix_view of a given nda::basic_array_view.
auto arange(long last)
Make a 1-dimensional integer array and initialize it with values of a given nda::range with a step si...
auto make_matrix_view(basic_array< T, R, LP, A, CP > const &a)
Make an nda::matrix_view of a given nda::basic_array.
auto ones(Ints... is)
Make an array with the given dimensions and one-initialize it.
auto make_const_view(basic_array_view< T, R, LP, A, AP, OP > const &a)
Make an nda::basic_array_view with a const value type from a given nda::basic_array_view.
decltype(auto) to_device(A &&a)
Convert an nda::MemoryArray to its regular type on device memory.
auto make_array_view(basic_array< T, R, LP, A, CP > const &a)
Make an nda::array_view of a given nda::basic_array.
auto make_array_const_view(basic_array< T, R, LP, A, CP > const &a)
Make an nda::array_const_view of a given nda::basic_array.
auto ones(std::array< Int, Rank > const &shape)
Make an array of the given shape and one-initialize it.
auto make_array_const_view(basic_array_view< T, R, LP, A, AP, OP > const &a)
Make an nda::array_const_view of a given nda::basic_array_view.
auto make_array_view(basic_array_view< T, R, LP, A, AP, OP > const &a)
Make an nda::array_view of a given nda::basic_array_view.
auto concatenate(A0 const &a0, As const &...as)
Join a sequence of nda::Array types along an existing axis.
long first_dim(A const &a)
Get the extent of the first dimension of the array.
constexpr bool is_view_v< basic_array_view< ValueType, Rank, Layout, Algebra, AccessorPolicy, OwningPolicy > >
Specialization of nda::is_view_v for nda::basic_array_view.
constexpr bool is_regular_v< basic_array< ValueType, Rank, Layout, Algebra, ContainerPolicy > >
Specialization of nda::is_regular_v for nda::basic_array.
constexpr char get_algebra< basic_array_view< ValueType, Rank, Layout, Algebra, AccessorPolicy, OwningPolicy > >
Specialization of nda::get_algebra for nda::basic_array_view types.
constexpr char get_algebra< basic_array< ValueType, Rank, Layout, Algebra, ContainerPolicy > >
Specialization of nda::get_algebra for nda::basic_array types.
constexpr uint64_t static_extents(int i0, Is... is)
Encode the given shape into a single integer using the nda::encode function.
constexpr char get_algebra< expr_unary< OP, A > >
Specialization of nda::get_algebra for nda::expr_unary types.
bool operator==(LHS const &lhs, RHS const &rhs)
Equal-to comparison operator for two nda::Array objects.
long second_dim(A const &a)
Get the extent of the second dimension of the array.
constexpr char get_algebra< expr< OP, L, R > >
Specialization of nda::get_algebra for nda::expr types.
__inline__ void clef_auto_assign(expr< tags::terminal, T > const &ex, RHS &&rhs)
Overload of clef_auto_assign function for terminal expressions.
__inline__ void clef_auto_assign(std::reference_wrapper< T > wrapper, RHS &&rhs)
Overload of clef_auto_assign function for std::reference_wrapper objects.
__inline__ void operator<<(expr< tags::function, F, placeholder< Is >... > const &ex, RHS &&rhs)
Assign values to the underlying object of a lazy function call expression.
__inline__ void clef_auto_assign_subscript(std::reference_wrapper< T > wrapper, RHS &&rhs)
Overload of clef_auto_assign_subscript function for std::reference_wrapper objects.
__inline__ void clef_auto_assign_subscript(expr< Tag, Childs... > const &ex, RHS const &rhs)
Overload of clef_auto_assign_subscript function for generic expressions.
__inline__ void clef_auto_assign_subscript(expr< tags::terminal, T > const &ex, RHS &&rhs)
Overload of clef_auto_assign_subscript function for terminal expressions.
__inline__ void clef_auto_assign(expr< Tag, Childs... > const &ex, RHS const &rhs)
Overload of clef_auto_assign function for generic expressions.
void clef_auto_assign(A &&a, F &&f)
Overload of nda::clef::clef_auto_assign function for nda::Array objects.
__inline__ void operator<<(expr< tags::subscript, T, placeholder< Is >... > const &ex, RHS &&rhs)
Assign values to the underlying object of a lazy subscript expression.
__inline__ decltype(auto) eval(T const &obj, Pairs &&...pairs)
Generic function to evaluate expressions and other types.
__inline__ auto make_function(T &&obj, Phs...)
Factory function for nda::clef::make_fun_impl objects.
__inline__ auto if_else(C &&c, A &&a, B &&b)
Create a lazy ternary (if-else) expression.
#define CLEF_OPERATION(TAG, OP)
auto make_expr(T &&t)
Create a terminal expression node of an object.
__inline__ auto op_dispatch(std::true_type, Args &&...args)
Dispatch operations containing at least one lazy operand.
__inline__ decltype(auto) op_dispatch(std::false_type, Args &&...args)
Dispatch operations containing only non-lazy operands.
auto make_expr_subscript(T &&t, Args &&...args)
Create a subscript expression from an object and a list of arguments.
auto make_expr_call(F &&f, Args &&...args)
Create a function call expression from a callable object and a list of arguments.
auto make_expr_from_clone(T &&t)
Create a terminal expression node of an object.
constexpr bool is_clef_expression
Alias template for nda::clef::is_any_lazy.
constexpr bool is_lazy
Constexpr variable that is true if the type T is a lazy type.
constexpr bool force_copy_in_expr
Constexpr variable that is true if objects of type T should be forced to be copied into an expression...
constexpr bool is_function
Constexpr variable that is true if the type T is an nda::clef::make_fun_impl type.
constexpr bool is_any_lazy
Constexpr variable that is true if any of the given types is lazy.
constexpr uint64_t C_stride_order
C/Row-major stride order.
constexpr uint64_t Fortran_stride_order
Fortran/Column-major stride order.
constexpr bool layout_property_compatible(layout_prop_e from, layout_prop_e to)
Checks if two layout properties are compatible with each other.
constexpr bool has_contiguous(layout_prop_e lp)
Checks if a layout property has the contiguous property.
constexpr bool has_strided_1d(layout_prop_e lp)
Checks if a layout property has the strided_1d property.
auto get_block_layout(A const &a)
Check if a given nda::MemoryArray has a block-strided layout.
constexpr bool has_smallest_stride_is_one(layout_prop_e lp)
Checks if a layout property has the smallest_stride_is_one property.
layout_prop_e
Compile-time guarantees of the memory layout of an array/view.
AddressSpace
Enum providing identifiers for the different memory address spaces.
static constexpr do_not_initialize_t do_not_initialize
Instance of nda::mem::do_not_initialize_t.
static constexpr init_zero_t init_zero
Instance of nda::mem::init_zero_t.
constexpr uint64_t encode(std::array< int, N > const &a)
Encode a std::array<int, N> in a uint64_t.
#define EXPECTS_WITH_MESSAGE(X,...)
Contiguous layout policy with C-order (row-major order).
Strided (non-contiguous) layout policy with C-order (row-major order).
A small wrapper around a single long integer to be used as a linear index.
Generic layout policy with arbitrary order.
Memory policy using an nda::mem::handle_borrowed.
static constexpr bool is_lazy
Constexpr variable that is true if any of the evaluators of the child nodes is lazy.
__inline__ decltype(auto) operator()(expr< Tag, Childs... > const &ex, Pairs &...pairs) const
Evaluate the given expression by applying the given nda::clef::pair objects.
__inline__ decltype(auto) operator()(make_fun_impl< T, Is... > const &f, Pairs &...pairs) const
Evaluate the nda::clef::make_fun_impl object.
static constexpr bool is_lazy
Constexpr variable that is true if all the placeholders are assigned a value.
static constexpr bool is_lazy
Constexpr variable that is true if the there is no nda::clef::pair containing an nda::clef::placehold...
__inline__ decltype(auto) operator()(placeholder< N >, pair< Is, Ts > &...pairs) const
Evaluate the placeholder.
static constexpr bool is_lazy
Constexpr variable that is always false.
__inline__ decltype(auto) operator()(std::reference_wrapper< T > const &wrapper, Pairs const &...pairs) const
Evaluate the std::reference_wrapper by redirecting the evaluation to the object contained in the wrap...
Generic evaluator for types which do not have a specialized evaluator.
__inline__ T const & operator()(T const &t, Pairs &...) const
Evaluate the object and ignore all given nda::clef::pair objects.
static constexpr bool is_lazy
Constexpr variable that is true if the type T is lazy.
Single node of the expression tree.
expr & operator=(expr const &)=delete
Copy assignment operator is deleted.
expr(expr &&ex) noexcept
Move constructor simply moves the child nodes from the source expression.
auto operator[](Args &&...args) const
Subscript operator.
expr & operator=(expr &&)=default
Default move assignment operator.
expr(expr const &)=default
Default copy constructor.
expr(Tag, Us &&...us)
Construct an expression node with a given tag and child nodes.
childs_t childs
Child nodes of the current expression node.
auto operator()(Args &&...args) const
Function call operator.
Helper struct to simplify calls to nda::clef::eval.
T obj
Object to be evaluated.
__inline__ decltype(auto) operator()(Args &&...args) const
Function call operator.
A pair consisting of a placeholder and its assigned value.
T rhs
Value assigned to the placeholder (can be an lvalue reference).
static constexpr int p
Integer label of the placeholder.
A placeholder is an empty struct, labelled by an int.
static constexpr int index
Integer label.
auto operator[](T &&t) const
Subscript operator.
pair< N, RHS > operator=(RHS &&rhs) const
Assign a value to the placeholder.
auto operator()(Args &&...args) const
Function call operator.
Accessor type of the nda::default_accessor.
static __inline__ T * offset(pointer p, std::ptrdiff_t i) noexcept
Offset the pointer by a certain number of elements.
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
Default accessor for various array and view types.
Mimics Python's ... syntax.
Lazy unary expression for nda::Array types.
Lazy binary expression for nda::ArrayOrScalar types.
Stores information about the memory layout and the stride order of an array/view.
Tag used in constructors to indicate that the memory should be initialized to zero.
Accessor type of the nda::no_alias_accessor.
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
static __inline__ T * offset(pointer p, std::ptrdiff_t i) noexcept
Offset the pointer by a certain number of elements.
Accessor for array and view types with no aliasing.
Memory policy using an nda::mem::handle_stack.