TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
iterators.hpp
Go to the documentation of this file.
1// Copyright (c) 2019-2020 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Olivier Parcollet, Nils Wentzell
16
17/**
18 * @file
19 * @brief Provides an iterator for nda::basic_array and nda::basic_array_view types.
20 */
21
22#pragma once
23
24#include "./stdutil/array.hpp"
25
26#include <array>
27#include <cstddef>
28#include <iterator>
29
30namespace nda {
31
32 /**
33 * @addtogroup av_utils
34 * @{
35 */
36
37 namespace detail {
38
39 // N-dimensional rectangular grid iterator in C traversal order.
40 template <int Rank>
41 class grid_iterator {
42 // Stride or number of elements to skip when increasing the iterator in the current dimension.
43 long stri = 0;
44
45 // Position of the iterator in the current dimension.
46 long pos = 0;
47
48 // Position times the stride in the current dimension.
49 long offset = 0;
50
51 // Iterator to the beginning of the Rank - 1 dimensional grid (excluding the current dimension).
52 grid_iterator<Rank - 1> it_begin;
53
54 // Iterator to the end of the Rank - 1 dimensional grid (excluding the current dimension).
55 grid_iterator<Rank - 1> it_end;
56
57 // Iterator to the Rank - 1 dimensional grid (excluding the current dimension).
58 grid_iterator<Rank - 1> it;
59
60 public:
61 using iterator_category = std::forward_iterator_tag;
62 using value_type = long;
63 using difference_type = std::ptrdiff_t;
64 using pointer = long *;
65 using reference = long &;
66
67 // Default constructor.
68 grid_iterator() = default;
69
70 // Construct an iterator from the shape of the grid, the stride of the grid and a flag indicating if the iterator
71 // is at the end.
72 grid_iterator(long const *lengths, long const *strides, bool at_end)
73 : stri(strides[0]),
74 pos(at_end ? lengths[0] : 0),
75 offset(pos * stri),
76 it_begin(lengths + 1, strides + 1, false),
77 it_end(lengths + 1, strides + 1, true),
78 it(it_begin) {}
79
80 // Get the position/multi-dimensional index of the iterator.
81 [[nodiscard]] std::array<long, Rank> indices() { return stdutil::front_append(it.indices(), pos); }
82
83 // Dereference operator returns the sum of the offsets of every dimension = its linear index.
84 [[nodiscard]] long operator*() const { return offset + *it; }
85
86 // Member access operator returns the sum of the offsets of every dimension = its linear index.
87 [[nodiscard]] long operator->() const { return operator*(); }
88
89 // True if the positions of the iterators are equal in every dimension, false otherwise.
90 [[nodiscard]] bool operator==(grid_iterator const &rhs) const { return ((rhs.pos == pos) and (rhs.it == it)); }
91
92 // True if the positions of the iterators are not equal in every dimension, false otherwise.
93 [[nodiscard]] bool operator!=(grid_iterator const &rhs) const { return not operator==(rhs); }
94
95 // Prefix increment operator.
96 grid_iterator &operator++() {
97 // increment the iterator of the subgrid
98 ++it;
99
100 // if the iterator of the subgrid is at the end, reset it and increment the current position and offset
101 if (it == it_end) { //FIXME [[unlikely]]
102 ++pos;
103 offset += stri;
104 it = it_begin;
105 }
106 return *this;
107 }
108
109 // Postfix increment operator.
110 grid_iterator operator++(int) {
111 auto c = *this;
112 ++(*this);
113 return c;
114 }
115 };
116
117 // Specialization of nda::grid_iterator for 1-dimensional grids.
118 template <>
119 class grid_iterator<1> {
120 // Stride or number of elements to skip when increasing the iterator.
121 long stri = 0;
122
123 // Position of the iterator.
124 long pos = 0;
125
126 // Position times the stride.
127 long offset = 0;
128
129 public:
130 using iterator_category = std::forward_iterator_tag;
131 using value_type = long;
132 using difference_type = std::ptrdiff_t;
133 using pointer = long *;
134 using reference = long &;
135
136 // Default constructor.
137 grid_iterator() = default;
138
139 // Construct an iterator from the shape of the grid, the stride of the grid and a flag indicating if the iterator
140 // is at the end.
141 grid_iterator(long const *lengths, long const *strides, bool at_end) : stri(strides[0]), pos(at_end ? lengths[0] : 0), offset(pos * stri) {}
142
143 // Get the position/index of the iterator.
144 [[nodiscard]] std::array<long, 1> indices() { return {pos}; }
145
146 // Dereference operator returns the offset = its linear index.
147 [[nodiscard]] long operator*() const { return offset; }
148
149 // Member access operator returns the offset = its linear index.
150 [[nodiscard]] long operator->() const { return operator*(); }
151
152 // True if the positions of the iterators are equal, false otherwise.
153 [[nodiscard]] bool operator==(grid_iterator const &rhs) const { return (rhs.pos == pos); }
154
155 // True if the positions of the iterators are not equal, false otherwise.
156 [[nodiscard]] bool operator!=(grid_iterator const &rhs) const { return (rhs.pos != pos); }
157
158 // Prefix increment operator increments the offset by the stride and the position by one.
159 grid_iterator &operator++() {
160 offset += stri;
161 ++pos;
162 return *this;
163 }
164
165 // Prefix decrement operator decrements the offset by the stride and the position by one.
166 grid_iterator &operator--() {
167 offset -= stri;
168 --pos;
169 return *this;
170 }
171
172 // Compound assignment addition operator increments the offset by n times the stride and the position by n.
173 grid_iterator &operator+=(std::ptrdiff_t n) {
174 offset += n * stri;
175 pos += n;
176 return *this;
177 }
178
179 // Binary addition of a grid iterator and an integer.
180 [[nodiscard]] friend grid_iterator operator+(grid_iterator it, std::ptrdiff_t n) { return it += n; }
181
182 // Binary subtraction of two grid iterators.
183 [[nodiscard]] friend std::ptrdiff_t operator-(grid_iterator const &lhs, grid_iterator const &rhs) { return lhs.pos - rhs.pos; }
184
185 // True if the position of the left hand side iterator is less than the position of the right hand side iterator,
186 // false otherwise.
187 [[nodiscard]] friend bool operator<(grid_iterator const &lhs, grid_iterator const &rhs) { return lhs.pos < rhs.pos; }
188
189 // True if the position of the left hand side iterator is greater than the position of the right hand side
190 // iterator, false otherwise.
191 [[nodiscard]] friend bool operator>(grid_iterator const &lhs, grid_iterator const &rhs) { return lhs.pos > rhs.pos; }
192 };
193
194 } // namespace detail
195
196 /**
197 * @brief Iterator for nda::basic_array and nda::basic_array_view types.
198 *
199 * @details It is a <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">LegacyRandomAccessIterator</a>
200 * for 1-dimensional and a <a href="https://en.cppreference.com/w/cpp/named_req/ForwardIterator">LegacyForwardIterator</a>
201 * for multi-dimensional arrays/views.
202 *
203 * Given the shape, strides and a pointer to the start of the data, the iterator uses an `nda::detail::grid_iterator`
204 * to traverse the element in the array/view.
205 *
206 * @note The memory layout is always assumed to be C-style. For other layouts, one has to permute the given shape and
207 * the strides according to the stride order.
208 *
209 * @tparam Rank Number of dimensions of the array.
210 * @tparam T Type of the elements in the array (can be const).
211 * @tparam Pointer Type of the pointer used to access the elements in the array (might be restricted depending on the
212 * accessor).
213 */
214 template <int Rank, typename T, typename Pointer>
216 // Pointer to the data (to the first element).
217 T *data = nullptr;
218
219 // Shape of the array.
220 std::array<long, Rank> len;
221
222 // Strides of the array.
223 std::array<long, Rank> stri;
224
225 // Grid iterator.
226 detail::grid_iterator<Rank> iter;
227
228 public:
229 /// Iterator category.
230 using iterator_category = std::forward_iterator_tag;
231
232 /// Value type.
233 using value_type = T;
234
235 /// Difference type.
236 using difference_type = std::ptrdiff_t;
237
238 /// Pointer type.
239 using pointer = T *;
240
241 /// Reference type.
242 using reference = T &;
243
244 /// Default constructor leaves the iterator in an uninitialized state.
245 array_iterator() = default;
246
247 /**
248 * @brief Construct an iterator from the shape and the strides of an array/view, a pointer to its data and a flag
249 * indicating if the iterator is at the end.
250 *
251 * @param lengths Shape of the array/view.
252 * @param strides Strides of the array/view.
253 * @param start Pointer to the data.
254 * @param at_end Flag indicating if the iterator is at the end.
255 */
256 array_iterator(std::array<long, Rank> const &lengths, std::array<long, Rank> const &strides, T *start, bool at_end)
257 : data(start), len(lengths), stri(strides), iter(len.data(), stri.data(), at_end) {}
258
259 /**
260 * @brief Get the current position/multi-dimensional index of the iterator.
261 * @return `std::array<long, Rank>` containing the current position/multi-dimensional index of the iterator.
262 */
263 [[nodiscard]] auto indices() { return iter.indices(); }
264
265 /**
266 * @brief Dereference operator.
267 * @return Reference to the element at the position of the iterator.
268 */
269 [[nodiscard]] value_type &operator*() const { return ((Pointer)data)[*iter]; }
270
271 /**
272 * @brief Member access operator.
273 * @return Reference to the element at the position of the iterator.
274 */
275 [[nodiscard]] value_type &operator->() const { return operator*(); }
276
277 /**
278 * @brief Prefix increment operator.
279 * @return Reference to the current iterator.
280 */
282 ++iter;
283 return *this;
284 }
285
286 /**
287 * @brief Postfix increment operator.
288 * @return Copy of the current iterator.
289 */
291 auto c = *this;
292 ++iter;
293 return c;
294 }
295
296 /**
297 * @brief Equal-to operator.
298 * @param rhs Other iterator to compare to.
299 * @return True if the positions of the iterators are equal, false otherwise.
300 */
301 [[nodiscard]] bool operator==(array_iterator const &rhs) const { return (rhs.iter == iter); }
302
303 /**
304 * @brief Not-equal-to operator.
305 * @param rhs Other iterator to compare to.
306 * @return True if the positions of the iterators are not equal, false otherwise.
307 */
308 [[nodiscard]] bool operator!=(array_iterator const &rhs) const { return (!operator==(rhs)); }
309 };
310
311 /**
312 * @brief Specialization of nda::array_iterator for 1-dimensional grids.
313 *
314 * @details It is a <a href="https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator">LegacyRandomAccessIterator</a>.
315 *
316 * @tparam T Type of the elements in the array (can be const).
317 * @tparam Pointer Type of the pointer used to access the elements in the array (might be restricted
318 * depending on the accessor).
319 */
320 template <typename T, typename Pointer>
321 class array_iterator<1, T, Pointer> {
322 // Pointer to the data.
323 T *data = nullptr;
324
325 // Shape of the array.
326 std::array<long, 1> len{};
327
328 // Strides of the array.
329 std::array<long, 1> stri{};
330
331 // Grid iterator.
332 detail::grid_iterator<1> iter;
333
334 public:
335 /// Iterator category.
336 using iterator_category = std::random_access_iterator_tag;
337
338 /// Value type.
339 using value_type = T;
340
341 /// Difference type.
342 using difference_type = std::ptrdiff_t;
343
344 /// Pointer type.
345 using pointer = T *;
346
347 /// Reference type.
348 using reference = T &;
349
350 /// Default constructor leaves the iterator in an uninitialized state.
351 array_iterator() = default;
352
353 /**
354 * @brief Construct an iterator from the shape and the strides of an array/view, a pointer to its data and a flag
355 * indicating if the iterator is at the end.
356 *
357 * @param lengths Shape of the array/view.
358 * @param strides Stride of the array/view.
359 * @param start Pointer to the data.
360 * @param at_end Flag indicating if the iterator is at the end.
361 */
362 array_iterator(std::array<long, 1> const &lengths, std::array<long, 1> const &strides, T *start, bool at_end)
363 : data(start), len(lengths), stri(strides), iter(len.data(), stri.data(), at_end) {}
364
365 /**
366 * @brief Get the current position/index of the iterator.
367 * @return `std::array<long, 1>` containing the current position/index of the iterator.
368 */
369 [[nodiscard]] auto indices() { return iter.indices(); }
370
371 /**
372 * @brief Dereference operator.
373 * @return Reference to the element at the position of the iterator.
374 */
375 [[nodiscard]] T &operator*() const { return ((Pointer)data)[*iter]; }
376
377 /**
378 * @brief Member access operator.
379 * @return Reference to the element at the position of the iterator.
380 */
381 T &operator->() const { return operator*(); }
382
383 /**
384 * @brief Prefix increment operator.
385 * @return Reference to the current iterator.
386 */
388 ++iter;
389 return *this;
390 }
391
392 /**
393 * @brief Postfix increment operator.
394 * @return Copy of the current iterator.
395 */
397 auto c = *this;
398 ++iter;
399 return c;
400 }
401
402 /**
403 * @brief Prefix decrement operator.
404 * @return Reference to the current iterator.
405 */
407 --iter;
408 return *this;
409 }
410
411 /**
412 * @brief Postfix decrement operator.
413 * @return Copy of the current iterator.
414 */
416 auto c = *this;
417 --iter;
418 return c;
419 }
420
421 /**
422 * @brief Equal-to operator.
423 * @param rhs Right hand side operand.
424 * @return True if the positions of the iterators are equal, false otherwise.
425 */
426 [[nodiscard]] bool operator==(array_iterator const &rhs) const { return (rhs.iter == iter); }
427
428 /**
429 * @brief Not-equal-to operator.
430 * @param rhs Right hand side operand.
431 * @return True if the positions of the iterators are not equal, false otherwise.
432 */
433 [[nodiscard]] bool operator!=(array_iterator const &rhs) const { return (!operator==(rhs)); }
434
435 /**
436 * @brief Compound assignment addition operator increments the iterator a given number of times.
437 *
438 * @param n Number of times to increment the iterator.
439 * @return Reference to the current iterator.
440 */
441 array_iterator &operator+=(std::ptrdiff_t n) {
442 iter += n;
443 return *this;
444 }
445
446 /**
447 * @brief Compound assignment subtraction operator decrements the iterator a given number of times.
448 *
449 * @param n Number of times to decrement the iterator.
450 * @return Reference to the current iterator.
451 */
452 array_iterator &operator-=(std::ptrdiff_t n) {
453 iter += (-n);
454 return *this;
455 }
456
457 /**
458 * @brief Binary addition of an integer with an 1-dimensional array iterator.
459 *
460 * @param n Integer.
461 * @param it 1-dimensional array iterator.
462 * @return Array iterator incremented n times.
463 */
464 [[nodiscard]] friend array_iterator operator+(std::ptrdiff_t n, array_iterator it) { return it += n; }
465
466 /**
467 * @brief Binary addition of an 1-dimensional array iterator with an integer.
468 *
469 * @param it 1-dimensional array iterator.
470 * @param n Integer.
471 * @return Array iterator incremented n times.
472 */
473 [[nodiscard]] friend array_iterator operator+(array_iterator it, std::ptrdiff_t n) { return it += n; }
474
475 /**
476 * @brief Binary subtraction of an 1-dimensional array iterator with an integer.
477 *
478 * @param it 1-dimensional array iterator.
479 * @param n Integer.
480 * @return Array iterator decremented n times.
481 */
482 [[nodiscard]] friend array_iterator operator-(array_iterator it, std::ptrdiff_t n) { return it -= n; }
483
484 /**
485 * @brief Binary subtraction of two 1-dimensional array iterators.
486 *
487 * @param lhs Left hand side operand.
488 * @param rhs Right hand side operand.
489 * @return Difference between their positions.
490 */
491 [[nodiscard]] friend std::ptrdiff_t operator-(array_iterator const &lhs, array_iterator const &rhs) { return lhs.iter - rhs.iter; }
492
493 /**
494 * @brief Subscript operator.
495 *
496 * @param n Number of times to increment the iterator before dereferencing it.
497 * @return Reference to the element at the position of the incremented iterator.
498 */
499 [[nodiscard]] T &operator[](std::ptrdiff_t n) { return ((Pointer)data)[*(iter + n)]; }
500
501 // FIXME C++20 ? with <=> operator
502 /**
503 * @brief Less-than comparison operator for two 1-dimensional array iterators.
504 *
505 * @param lhs Left hand side operand.
506 * @param rhs Right hand side operand.
507 * @return True if the position of the left hand side iterator is less than the position of the right hand side
508 * iterator, false otherwise.
509 */
510 [[nodiscard]] friend bool operator<(array_iterator const &lhs, array_iterator const &rhs) { return lhs.iter < rhs.iter; }
511
512 /**
513 * @brief Greater-than comparison operator for two 1-dimensional array iterators.
514 *
515 * @param lhs Left hand side operand.
516 * @param rhs Right hand side operand.
517 * @return True if the position of the left hand side iterator is greater than the position of the right hand side
518 * iterator, false otherwise.
519 */
520 [[nodiscard]] friend bool operator>(array_iterator const &lhs, array_iterator const &rhs) { return lhs.iter > rhs.iter; }
521
522 /**
523 * @brief Less-than or equal-to comparison operator for two 1-dimensional array iterators.
524 *
525 * @param lhs Left hand side operand.
526 * @param rhs Right hand side operand.
527 * @return True if the position of the left hand side iterator is less than or equal to the position of the right
528 * hand side iterator, false otherwise.
529 */
530 [[nodiscard]] friend bool operator<=(array_iterator const &lhs, array_iterator const &rhs) { return not(lhs.iter > rhs.iter); }
531
532 /**
533 * @brief Greater-than or equal-to comparison operator for two 1-dimensional array iterators.
534 *
535 * @param lhs Left hand side operand.
536 * @param rhs Right hand side operand.
537 * @return True if the position of the left hand side iterator is greater than or equal to the position of the right
538 * hand side iterator, false otherwise.
539 */
540 [[nodiscard]] friend bool operator>=(array_iterator const &lhs, array_iterator const &rhs) { return not(lhs.iter < rhs.iter); }
541 };
542
543 /** @} */
544
545} // namespace nda
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.
friend std::ptrdiff_t operator-(array_iterator const &lhs, array_iterator const &rhs)
Binary subtraction of two 1-dimensional array iterators.
friend bool operator>=(array_iterator const &lhs, array_iterator const &rhs)
Greater-than or equal-to comparison operator for two 1-dimensional array iterators.
friend bool operator<=(array_iterator const &lhs, array_iterator const &rhs)
Less-than or equal-to comparison operator for two 1-dimensional array iterators.
array_iterator & operator--()
Prefix decrement operator.
friend array_iterator operator+(std::ptrdiff_t n, array_iterator it)
Binary addition of an integer with an 1-dimensional array iterator.
array_iterator()=default
Default constructor leaves the iterator in an uninitialized state.
friend bool operator>(array_iterator const &lhs, array_iterator const &rhs)
Greater-than comparison operator for two 1-dimensional array iterators.
T & operator[](std::ptrdiff_t n)
Subscript operator.
bool operator!=(array_iterator const &rhs) const
Not-equal-to operator.
array_iterator & operator++()
Prefix increment operator.
array_iterator & operator+=(std::ptrdiff_t n)
Compound assignment addition operator increments the iterator a given number of times.
array_iterator operator--(int)
Postfix decrement operator.
T & operator*() const
Dereference operator.
array_iterator operator++(int)
Postfix increment operator.
friend array_iterator operator-(array_iterator it, std::ptrdiff_t n)
Binary subtraction of an 1-dimensional array iterator with an integer.
array_iterator & operator-=(std::ptrdiff_t n)
Compound assignment subtraction operator decrements the iterator a given number of times.
array_iterator(std::array< long, 1 > const &lengths, std::array< long, 1 > const &strides, T *start, bool at_end)
Construct an iterator from the shape and the strides of an array/view, a pointer to its data and a fl...
bool operator==(array_iterator const &rhs) const
Equal-to operator.
friend array_iterator operator+(array_iterator it, std::ptrdiff_t n)
Binary addition of an 1-dimensional array iterator with an integer.
friend bool operator<(array_iterator const &lhs, array_iterator const &rhs)
Less-than comparison operator for two 1-dimensional array iterators.
T & operator->() const
Member access operator.
auto indices()
Get the current position/index of the iterator.
Iterator for nda::basic_array and nda::basic_array_view types.
value_type & operator->() const
Member access operator.
array_iterator(std::array< long, Rank > const &lengths, std::array< long, Rank > const &strides, T *start, bool at_end)
Construct an iterator from the shape and the strides of an array/view, a pointer to its data and a fl...
array_iterator operator++(int)
Postfix increment operator.
array_iterator()=default
Default constructor leaves the iterator in an uninitialized state.
bool operator==(array_iterator const &rhs) const
Equal-to operator.
bool operator!=(array_iterator const &rhs) const
Not-equal-to operator.
value_type & operator*() const
Dereference operator.
auto indices()
Get the current position/multi-dimensional index of the iterator.
array_iterator & operator++()
Prefix increment operator.
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...
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.
Definition idx_map.hpp:103
__inline__ long operator()(Args const &...args) const noexcept(true)
Function call operator to map a given multi-dimensional index to a linear index.
Definition idx_map.hpp:512
static constexpr std::array< int, Rank > stride_order
Decoded stride order.
Definition idx_map.hpp:121
idx_map(idx_map< Rank, StaticExtents, StrideOrder, LP > const &idxm) noexcept
Construct a new map from an existing map with different layout properties.
Definition idx_map.hpp:327
static bool is_stride_order_valid(Int *lenptr, Int *strptr)
Check if a given shape and strides are compatible with the stride order.
Definition idx_map.hpp:244
static constexpr layout_info_t layout_info
Compile-time information about the layout (stride order and layout properties).
Definition idx_map.hpp:130
idx_map(idx_map &&)=default
Default move constructor.
long size() const noexcept
Get the total number of elements.
Definition idx_map.hpp:160
long min_stride() const noexcept
Get the value of the smallest stride.
Definition idx_map.hpp:190
idx_map(std::array< long, n_dynamic_extents > const &shape) noexcept
Construct a new map from an array with its dynamic extents.
Definition idx_map.hpp:404
auto transpose() const
Create a new map by permuting the indices/dimensions of the current map with a given permutation.
Definition idx_map.hpp:604
std::array< long, Rank > to_idx(long lin_idx) const
Calculate the multi-dimensional index from a given linear index.
Definition idx_map.hpp:543
bool is_stride_order_valid() const
Check if the shape and strides of the current map are compatible with its stride order.
Definition idx_map.hpp:259
idx_map(idx_map< Rank, SE, SO, LP > const &)
Construct a new map from an existing map with a different stride order.
Definition idx_map.hpp:418
bool operator==(idx_map< R, SE, SO, LP > const &rhs) const
Equal-to operator for two nda::idx_map objects.
Definition idx_map.hpp:585
static constexpr bool is_stride_order_C()
Is the stride order equal to C-order?
Definition idx_map.hpp:227
static constexpr int n_dynamic_extents
Number of dynamic dimensions/extents.
Definition idx_map.hpp:143
static constexpr uint64_t stride_order_encoded
Encoded stride order.
Definition idx_map.hpp:124
static constexpr int rank() noexcept
Get the rank of the map.
Definition idx_map.hpp:154
static constexpr std::array< int, Rank > static_extents
Decoded static extents.
Definition idx_map.hpp:118
bool is_strided_1d() const noexcept
Is the data strided in memory with a constant stride?
Definition idx_map.hpp:216
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...
Definition idx_map.hpp:138
idx_map(std::array< Int, Rank > const &shape) noexcept
Construct a new map from a given shape and with contiguous strides.
Definition idx_map.hpp:390
std::array< long, Rank > const & lengths() const noexcept
Get the extents of all dimensions.
Definition idx_map.hpp:178
auto slice(Args const &...args) const
Get a new nda::idx_map by taking a slice of the current one.
Definition idx_map.hpp:570
static constexpr bool is_stride_order_Fortran()
Is the stride order equal to Fortran-order?
Definition idx_map.hpp:233
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.
Definition idx_map.hpp:134
static constexpr long ce_size() noexcept
Get the size known at compile-time.
Definition idx_map.hpp:166
bool is_contiguous() const noexcept
Is the data contiguous in memory?
Definition idx_map.hpp:200
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...
Definition idx_map.hpp:350
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.
Definition idx_map.hpp:374
idx_map()
Default constructor.
Definition idx_map.hpp:310
std::array< long, Rank > const & strides() const noexcept
Get the strides of all dimensions.
Definition idx_map.hpp:184
idx_map & operator=(idx_map const &)=default
Default copy assignment operator.
static constexpr layout_prop_e layout_prop
Compile-time memory layout properties.
Definition idx_map.hpp:127
static constexpr uint64_t static_extents_encoded
Encoded static extents.
Definition idx_map.hpp:115
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.
Definition idx_map.hpp:430
Custom allocator that allocates a bucket of memory on the heap consisting of 64 chunks.
bucket(bucket &&)=default
Default move constructor.
bool empty() const noexcept
Check if the bucket is empty.
bucket()=default
Default constructor.
bool owns(blk_t b) const noexcept
Check if a given nda::mem::blk_t memory block is owned by the bucket.
void deallocate(blk_t b) noexcept
Deallocate a chunk of memory from the bucket by simply resetting the bitmask.
bool is_full() const noexcept
Check if the bucket is full.
auto mask() const noexcept
Get the bitmask of the bucket.
const char * data() const noexcept
Get a pointer to the start of the bucket.
static constexpr auto address_space
Only Host nda::mem::AddressSpace is supported for this allocator.
bucket(bucket const &)=delete
Deleted copy constructor.
bucket & operator=(bucket const &)=delete
Deleted copy assignment operator.
bucket & operator=(bucket &&)=default
Default move assignment operator.
blk_t allocate(size_t s) noexcept
Allocate a chunk of memory in the bucket and update the bitmask.
static constexpr int TotalChunkSize
Total size of the bucket in bytes.
blk_t allocate_zero(size_t s) noexcept
Allocate a chunk of memory in the bucket, set it to zero and update the bitmask.
Wrap an allocator to check for memory leaks.
bool empty() const
Check if the base allocator is empty.
long get_memory_used() const noexcept
Get the total memory used by the base allocator.
bool owns(blk_t b) const noexcept
Check if a given nda::mem::blk_t memory block is owned by the base allocator.
leak_check & operator=(leak_check &&)=default
Default move assignment operator.
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
leak_check(leak_check const &)=delete
Deleted copy constructor.
~leak_check()
Destructor that checks for memory leaks.
blk_t allocate_zero(size_t s)
Allocate memory, set it to zero and update the total memory used.
leak_check()=default
Default constructor.
blk_t allocate(size_t s)
Allocate memory and update the total memory used.
leak_check & operator=(leak_check const &)=delete
Deleted copy assignment operator.
void deallocate(blk_t b) noexcept
Deallocate memory and update the total memory used.
leak_check(leak_check &&)=default
Default move constructor.
Custom allocator that uses nda::mem::malloc to allocate memory.
mallocator & operator=(mallocator const &)=delete
Deleted copy assignment operator.
static void deallocate(blk_t b) noexcept
Deallocate memory using nda::mem::free.
mallocator & operator=(mallocator &&)=default
Default move assignment operator.
mallocator()=default
Default constructor.
mallocator(mallocator const &)=delete
Deleted copy constructor.
static blk_t allocate_zero(size_t s) noexcept
Allocate memory and set it to zero.
static blk_t allocate(size_t s) noexcept
Allocate memory using nda::mem::malloc.
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
mallocator(mallocator &&)=default
Default move constructor.
Custom allocator that uses multiple nda::mem::bucket allocators.
multi_bucket(multi_bucket &&)=default
Default move constructor.
bool owns(blk_t b) const noexcept
Check if a given nda::mem::blk_t memory block is owned by allocator.
blk_t allocate_zero(size_t s) noexcept
Allocate a chunk of memory in the current bucket or find a new one if the current one is full and set...
void deallocate(blk_t b) noexcept
Deallocate a chunk of memory from the bucket to which it belongs.
multi_bucket()
Default constructor.
bool empty() const noexcept
Check if the current allocator is empty.
static constexpr auto address_space
Only Host nda::mem::AddressSpace is supported for this allocator.
multi_bucket & operator=(multi_bucket &&)=default
Default move assignment operator.
auto const & buckets() const noexcept
Get the bucket vector.
blk_t allocate(size_t s) noexcept
Allocate a chunk of memory in the current bucket or find a new one if the current one is full.
multi_bucket(multi_bucket const &)=delete
Deleted copy constructor.
multi_bucket & operator=(multi_bucket const &)=delete
Deleted copy assignment operator.
Custom allocator that dispatches memory allocation to one of two allocators based on the size of the ...
blk_t allocate_zero(size_t s) noexcept
Allocate memory and set the memory to zero using the small allocator if the size is less than or equa...
segregator()=default
Default constructor.
segregator(segregator const &)=delete
Deleted copy constructor.
void deallocate(blk_t b) noexcept
Deallocate memory using the small allocator if the size is less than or equal to the Threshold,...
bool owns(blk_t b) const noexcept
Check if a given nda::mem::blk_t memory block is owned by the allocator.
segregator & operator=(segregator &&)=default
Default move assignment operator.
segregator(segregator &&)=default
Default move constructor.
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
segregator & operator=(segregator const &)=delete
Deleted copy assignment operator.
blk_t allocate(size_t s) noexcept
Allocate memory using the small allocator if the size is less than or equal to the Threshold,...
Wrap an allocator to gather statistics about memory allocation.
stats & operator=(stats &&)=default
Default move assignment operator.
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
blk_t allocate(uint64_t s)
Allocate memory and update the histogram.
auto const & histogram() const noexcept
Get the histogram of the allocation sizes.
void print_histogram(std::ostream &os) const
Print the histogram to a std::ostream.
blk_t allocate_zero(uint64_t s)
Allocate memory, set it to zero and update the histogram.
~stats()
Destructor that outputs the statistics about the memory allocation in debug mode.
stats & operator=(stats const &)=delete
Deleted copy assignment operator.
bool owns(blk_t b) const noexcept
Check if a given nda::mem::blk_t memory block is owned by the base allocator.
stats(stats const &)=delete
Deleted copy constructor.
void deallocate(blk_t b) noexcept
Deallocate memory.
stats(stats &&)=default
Default move constructor.
stats()=default
Default constructor.
#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_subscript(std::vector< T > &v, F f)
Overload of clef_auto_assign_subscript function for std::vector.
Definition vector.hpp:61
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.
Definition eval.hpp:197
__inline__ auto make_function(T &&obj, Phs...)
Factory function for nda::clef::make_fun_impl objects.
Definition function.hpp:100
#define CLEF_MAKE_FNT_LAZY(name)
Macro to make any function lazy, i.e. accept lazy arguments and return a function call expression nod...
auto sum(Expr const &ex, D0 &&d0, D1 &&d1, Ds &&...ds)
Sum an expression over a multi-dimensional domain.
Definition sum.hpp:109
__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.
Definition make_lazy.hpp:45
#define CLEF_MAKE_STD_FNT_LAZY(name)
Definition math.hpp:36
__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.
decltype(auto) sum(Expr const &ex, clef::pair< N, D > d)
Sum an expression over a 1-dimensional domain.
Definition sum.hpp:76
auto make_expr_subscript(T &&t, Args &&...args)
Create a subscript expression from an object and a list of arguments.
Definition make_lazy.hpp:93
auto make_expr_call(F &&f, Args &&...args)
Create a function call expression from a callable object and a list of arguments.
Definition make_lazy.hpp:74
auto make_expr_from_clone(T &&t)
Create a terminal expression node of an object.
Definition make_lazy.hpp:57
constexpr auto iW_
Placeholder for imaginary bosonic frequencies.
Definition literals.hpp:62
constexpr auto iw_
Placeholder for imaginary fermionic frequencies.
Definition literals.hpp:56
constexpr auto j_
Generic placeholder #2.
Definition literals.hpp:41
constexpr auto tau_
Placeholder for imaginary times.
Definition literals.hpp:68
constexpr auto i_
Generic placeholder #1.
Definition literals.hpp:38
constexpr auto bl_
Placeholder for block indices.
Definition literals.hpp:50
constexpr auto W_
Placeholder for real bosonic frequencies.
Definition literals.hpp:59
constexpr auto w_
Placeholder for real fermionic frequencies.
Definition literals.hpp:53
constexpr auto t_
Placeholder for real times.
Definition literals.hpp:65
#define PH(I)
Definition literals.hpp:34
constexpr auto k_
Generic placeholder #3.
Definition literals.hpp:44
constexpr auto l_
Generic placeholder #4.
Definition literals.hpp:47
constexpr bool is_clef_expression
Alias template for nda::clef::is_any_lazy.
Definition utils.hpp:161
constexpr bool is_lazy
Constexpr variable that is true if the type T is a lazy type.
Definition utils.hpp:153
std::ostream & print_tuple(std::ostream &sout, Tuple const &t)
Print a std::tuple to std::ostream.
Definition io.hpp:114
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...
Definition utils.hpp:137
constexpr bool is_function
Constexpr variable that is true if the type T is an nda::clef::make_fun_impl type.
Definition utils.hpp:165
constexpr bool is_any_lazy
Constexpr variable that is true if any of the given types is lazy.
Definition utils.hpp:157
std::ostream & variadic_print(std::ostream &sout, T0 &&t0, Ts &&...ts)
Print a variadic list of arguments to std::ostream.
Definition io.hpp:78
constexpr uint64_t C_stride_order
C/Row-major stride order.
Definition idx_map.hpp:65
constexpr uint64_t Fortran_stride_order
Fortran/Column-major stride order.
Definition idx_map.hpp:57
__inline__ decltype(auto) slice_idx_map(idx_map< R, SE, SO, LP > const &idxm, Args const &...args)
Determine the resulting nda::idx_map when taking a slice of a given nda::idx_map.
constexpr bool layout_property_compatible(layout_prop_e from, layout_prop_e to)
Checks if two layout properties are compatible with each other.
Definition traits.hpp:237
constexpr bool has_contiguous(layout_prop_e lp)
Checks if a layout property has the contiguous property.
Definition traits.hpp:282
constexpr bool has_strided_1d(layout_prop_e lp)
Checks if a layout property has the strided_1d property.
Definition traits.hpp:266
__inline__ void for_each(std::array< Int, R > const &shape, F &&f)
Loop over all possible index values of a given shape and apply a function to them.
Definition for_each.hpp:129
__inline__ void for_each_static(std::array< Int, R > const &shape, F &&f)
Loop over all possible index values of a given shape and apply a function to them.
Definition for_each.hpp:108
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.
Definition traits.hpp:274
layout_prop_e
Compile-time guarantees of the memory layout of an array/view.
Definition traits.hpp:222
AddressSpace
Enum providing identifiers for the different memory address spaces.
static constexpr bool have_host_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Host.
static constexpr bool have_compatible_addr_space
Constexpr variable that is true if all given types have compatible address spaces.
constexpr AddressSpace combine
Promotion rules for nda::mem::AddressSpace values.
static constexpr bool have_device_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Device.
static constexpr bool on_device
Constexpr variable that is true if all given types have a Device address space.
static constexpr bool on_unified
Constexpr variable that is true if all given types have a Unified address space.
static constexpr AddressSpace get_addr_space
Variable template providing the address space for different types.
static constexpr bool on_host
Constexpr variable that is true if all given types have a Host address space.
constexpr AddressSpace common_addr_space
Get common address space for a number of given nda::MemoryArray types.
static const auto check_adr_sp_valid
Check validity of a set of nda::mem::AddressSpace values.
static constexpr bool have_same_addr_space
Constexpr variable that is true if all given types have the same address space.
static constexpr bool have_cuda
Constexpr variable that is true if the project is configured with CUDA support.
Definition device.hpp:146
void memset2D(void *ptr, size_t pitch, int value, size_t width, size_t height)
Call CUDA's cudaMemset2D function or simulate its behavior on the Host based on the given address spa...
Definition memset.hpp:78
void memcpy2D(void *dest, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height)
Call CUDA's cudaMemcpy2D function or simulate its behavior on the Host based on the given address spa...
Definition memcpy.hpp:84
#define device_error_check(ARG1, ARG2)
Trigger a compilation error every time the nda::device_error_check function is called.
Definition device.hpp:140
static constexpr bool have_device
Constexpr variable that is true if the project is configured with GPU support.
Definition device.hpp:143
static constexpr bool init_dcmplx
Should we initialize memory for complex double types to zero.
Definition handle.hpp:45
void * malloc(size_t size)
Call the correct malloc function based on the given address space.
Definition malloc.hpp:49
static constexpr do_not_initialize_t do_not_initialize
Instance of nda::mem::do_not_initialize_t.
Definition handle.hpp:69
void memset(void *p, int value, size_t count)
Call the correct memset function based on the given address space.
Definition memset.hpp:49
void memcpy(void *dest, void const *src, size_t count)
Call the correct memcpy function based on the given address spaces.
Definition memcpy.hpp:51
static constexpr init_zero_t init_zero
Instance of nda::mem::init_zero_t.
Definition handle.hpp:75
void free(void *p)
Call the correct free function based on the given address space.
Definition malloc.hpp:75
constexpr std::array< int, N > transposition(int i, int j)
Get the permutation representing a single given transposition.
constexpr std::array< Int, N > inverse(std::array< Int, N > const &p)
Inverse of a permutation.
constexpr std::array< int, N > decode(uint64_t binary_representation)
Decode a uint64_t into a std::array<int, N>.
constexpr bool is_valid(std::array< Int, N > const &p)
Check if a given array is a valid permutation.
constexpr std::array< T, N > apply_inverse(std::array< Int, N > const &p, std::array< T, N > const &a)
Apply the inverse of a permutation to a std::array.
constexpr std::array< int, N > identity()
Get the identity permutation.
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< int, N > cycle(int p, int pos=N)
Perform a forward (partial) cyclic permutation of the identity p times.
constexpr std::array< Int, N > compose(std::array< Int, N > const &p1, std::array< Int, N > const &p2)
Composition of two permutations.
constexpr std::array< T, N > apply(std::array< Int, N > const &p, std::array< T, N > const &a)
Apply a permutation to a std::array.
constexpr std::array< T, R > operator*(std::array< T, R > const &lhs, std::array< T, R > const &rhs)
Multiply two std::array objects element-wise.
Definition array.hpp:115
constexpr std::array< T, R - N > front_mpop(std::array< T, R > const &a)
Make a new std::array by popping the first N elements of an existing std::array.
Definition array.hpp:278
constexpr std::array< T, R+1 > append(std::array< T, R > const &a, U const &x)
Make a new std::array by appending one element at the end to an existing std::array.
Definition array.hpp:214
constexpr std::array< T, R+1 > front_append(std::array< T, R > const &a, U const &x)
Make a new std::array by prepending one element at the front to an existing std::array.
Definition array.hpp:232
constexpr std::array< T, R - 1 > pop(std::array< T, R > const &a)
Make a new std::array by popping the last element of an existing std::array.
Definition array.hpp:264
constexpr std::array< T, R > operator+(std::array< T, R > const &lhs, std::array< T, R > const &rhs)
Add two std::array objects element-wise.
Definition array.hpp:83
constexpr std::array< T, R > operator-(std::array< T, R > const &a)
Negate a std::array element-wise (unary minus).
Definition array.hpp:130
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.
Definition array.hpp:309
constexpr std::array< T, R > operator*(T s, std::array< T, R > const &a)
Multiply a scalar and a std::array element-wise.
Definition array.hpp:146
constexpr std::vector< T > to_vector(std::array< T, R > const &a)
Convert a std::array to a std::vector.
Definition array.hpp:197
constexpr std::array< T, R > make_initialized_array(T v)
Create a new std::array object initialized with a specific value.
Definition array.hpp:165
constexpr auto sum(std::array< T, R > const &a)
Calculate the sum of all elements in a std::array.
Definition array.hpp:326
std::string to_string(std::array< T, R > const &a)
Get a string representation of a std::array.
Definition array.hpp:65
constexpr std::array< T, R > operator-(std::array< T, R > const &lhs, std::array< T, R > const &rhs)
Subtract two std::array objects element-wise.
Definition array.hpp:99
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.
Definition array.hpp:181
constexpr std::array< T, R - 1 > front_pop(std::array< T, R > const &a)
Make a new std::array by popping the first element of an existing std::array.
Definition array.hpp:293
constexpr auto product(std::array< T, R > const &a)
Calculate the product of all elements in a std::array.
Definition array.hpp:345
constexpr auto dot_product(std::array< T, R > const &a1, std::array< U, R > const &a2)
Calculate the dot product of two std::array objects.
Definition array.hpp:366
constexpr std::array< T, R - N > mpop(std::array< T, R > const &a)
Make a new std::array by popping the last N elements of an existing std::array.
Definition array.hpp:249
#define EXPECTS(X)
Definition macros.hpp:59
#define FORCEINLINE
Definition macros.hpp:41
#define EXPECTS_WITH_MESSAGE(X,...)
Definition macros.hpp:75
#define ENSURES(X)
Definition macros.hpp:69
#define AS_STRING(...)
Definition macros.hpp:31
#define ASSERT(X)
Definition macros.hpp:64
Contiguous layout policy with C-order (row-major order).
Definition policies.hpp:47
Strided (non-contiguous) layout policy with C-order (row-major order).
Definition policies.hpp:79
Contiguous layout policy with Fortran-order (column-major order).
Definition policies.hpp:63
Strided (non-contiguous) layout policy with Fortran-order (column-major order).
Definition policies.hpp:95
A small wrapper around a single long integer to be used as a linear index.
Definition traits.hpp:343
long value
Linear index.
Definition traits.hpp:345
Generic layout policy with arbitrary order.
Definition policies.hpp:115
Memory policy using an nda::mem::handle_borrowed.
Definition policies.hpp:108
static constexpr bool is_lazy
Constexpr variable that is true if any of the evaluators of the child nodes is lazy.
Definition eval.hpp:150
__inline__ decltype(auto) operator()(expr< Tag, Childs... > const &ex, Pairs &...pairs) const
Evaluate the given expression by applying the given nda::clef::pair objects.
Definition eval.hpp:170
__inline__ decltype(auto) operator()(make_fun_impl< T, Is... > const &f, Pairs &...pairs) const
Evaluate the nda::clef::make_fun_impl object.
Definition function.hpp:133
static constexpr bool is_lazy
Constexpr variable that is true if all the placeholders are assigned a value.
Definition function.hpp:120
static constexpr bool is_lazy
Constexpr variable that is true if the there is no nda::clef::pair containing an nda::clef::placehold...
Definition eval.hpp:92
__inline__ decltype(auto) operator()(placeholder< N >, pair< Is, Ts > &...pairs) const
Evaluate the placeholder.
Definition eval.hpp:101
static constexpr bool is_lazy
Constexpr variable that is always false.
Definition eval.hpp:126
__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...
Definition eval.hpp:135
Generic evaluator for types which do not have a specialized evaluator.
Definition eval.hpp:55
__inline__ T const & operator()(T const &t, Pairs &...) const
Evaluate the object and ignore all given nda::clef::pair objects.
Definition eval.hpp:65
static constexpr bool is_lazy
Constexpr variable that is true if the type T is lazy.
Definition eval.hpp:57
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.
Definition function.hpp:52
T obj
Object to be evaluated.
Definition function.hpp:54
__inline__ decltype(auto) operator()(Args &&...args) const
Function call operator.
Definition function.hpp:68
__inline__ decltype(auto) operator()(F &&f, Args &&...args) const
Perform a function call operation.
Definition operation.hpp:95
__inline__ A operator()(C const &c, A const &a, B const &b) const
Perform a ternary (if-else) operation.
__inline__ decltype(auto) operator()(F &&f, Args &&...args) const
Perform a subscript operation.
__inline__ L operator()(L &&l) const
Perform a terminal operation.
Definition operation.hpp:77
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.
Tag for binary operator expressions.
Tag for function call expressions.
Tag for conditional expressions.
Tag for subscript expressions.
Tag to indicate a terminal node in the expression tree.
Tag for unary operator expressions.
Accessor type of the nda::default_accessor.
Definition accessors.hpp:42
static __inline__ T * offset(pointer p, std::ptrdiff_t i) noexcept
Offset the pointer by a certain number of elements.
Definition accessors.hpp:71
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
Definition accessors.hpp:59
Default accessor for various array and view types.
Definition accessors.hpp:36
Mimics Python's ... syntax.
Definition range.hpp:49
A lazy function call expression on arrays/views.
Definition map.hpp:90
Lazy unary expression for nda::Array types.
Lazy binary expression for nda::ArrayOrScalar types.
Memory policy using an nda::mem::handle_heap.
Definition policies.hpp:44
Stores information about the memory layout and the stride order of an array/view.
Definition traits.hpp:295
Wraps an arbitrary type to have a specified alignment.
Definition handle.hpp:54
T & get() noexcept
Get reference to the wrapped object.
Definition handle.hpp:59
T const & get() const noexcept
Get const reference to the wrapped object.
Definition handle.hpp:62
T x
Wrapped object of type T.
Definition handle.hpp:56
Memory block consisting of a pointer and its size.
char * ptr
Pointer to the memory block.
size_t s
Size of the memory block in bytes.
Tag used in constructors to indicate that the memory should not be initialized.
Definition handle.hpp:66
A non-owning handle for a memory block on the heap.
Definition handle.hpp:858
handle_borrowed(T *ptr) noexcept
Construct a borrowed handle from a pointer to the data.
Definition handle.hpp:892
handle_heap< T0 > const * parent() const
Get a pointer to the parent handle.
Definition handle.hpp:934
handle_borrowed(H const &h, long offset=0) noexcept
Construct a borrowed handle from a another handle.
Definition handle.hpp:904
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
Definition handle.hpp:874
handle_borrowed & operator=(handle_borrowed &&)=default
Default move assignment operator.
handle_borrowed & operator=(handle_borrowed const &)=default
Default copy assignment operator.
handle_borrowed()=default
Default constructor leaves the handle in a null state (nullptr).
T & operator[](long i) noexcept
Subscript operator to access the data.
Definition handle.hpp:914
bool is_null() const noexcept
Check if the handle is in a null state.
Definition handle.hpp:928
T const & operator[](long i) const noexcept
Subscript operator to access the data.
Definition handle.hpp:922
handle_borrowed(handle_borrowed const &)=default
Default copy constructor.
T * data() const noexcept
Get a pointer to the stored data.
Definition handle.hpp:940
A handle for a memory block on the heap.
Definition handle.hpp:99
long size() const noexcept
Get the size of the handle.
Definition handle.hpp:347
~handle_heap() noexcept
Destructor for the handle.
Definition handle.hpp:165
handle_heap & operator=(handle_heap const &h)
Copy assignment operator utilizes the copy constructor and move assignment operator to make a deep co...
Definition handle.hpp:221
T const & operator[](long i) const noexcept
Subscript operator to access the data.
Definition handle.hpp:323
handle_heap(handle_heap &&h) noexcept
Move constructor simply copies the pointers and size and resets the source handle to a null state.
Definition handle.hpp:176
handle_heap(long size, init_zero_t)
Construct a handle by allocating memory for the data of a given size and initializing it to zero.
Definition handle.hpp:273
T * data() const noexcept
Get a pointer to the stored data.
Definition handle.hpp:341
handle_heap(long size)
Construct a handle by allocating memory for the data of a given size and initializing it depending on...
Definition handle.hpp:292
handle_heap & operator=(handle_heap< T, AS > const &h)
Assignment operator utilizes another constructor and move assignment to make a deep copy of the data ...
Definition handle.hpp:252
handle_heap(long size, do_not_initialize_t)
Construct a handle by allocating memory for the data of a given size but without initializing it.
Definition handle.hpp:261
bool is_null() const noexcept
Check if the handle is in a null state.
Definition handle.hpp:329
handle_heap(handle_heap const &h)
Copy constructor makes a deep copy of the data from another handle.
Definition handle.hpp:206
T & operator[](long i) noexcept
Subscript operator to access the data.
Definition handle.hpp:315
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
Definition handle.hpp:149
handle_heap & operator=(handle_heap &&h) noexcept
Move assignment operator first releases the resources held by the current handle and then moves the r...
Definition handle.hpp:187
handle_heap()=default
Default constructor leaves the handle in a null state (nullptr and size 0).
std::shared_ptr< void > get_sptr() const
Get a shared pointer to the memory block.
Definition handle.hpp:155
handle_heap(H const &h)
Construct a handle by making a deep copy of the data from another handle.
Definition handle.hpp:233
A handle for a memory block on the heap with shared ownership.
Definition handle.hpp:754
handle_shared(handle_heap< T, A > const &h) noexcept
Construct a shared handle from an nda::mem::handle_heap.
Definition handle.hpp:798
handle_shared()=default
Default constructor leaves the handle in a null state (nullptr and size 0).
T & operator[](long i) noexcept
Subscript operator to access the data.
Definition handle.hpp:810
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
Definition handle.hpp:775
long refcount() const noexcept
Get the reference count of the shared object.
Definition handle.hpp:836
bool is_null() const noexcept
Check if the handle is in a null state.
Definition handle.hpp:824
T const & operator[](long i) const noexcept
Subscript operator to access the data.
Definition handle.hpp:818
handle_shared(T *data, size_t size, void *foreign_handle, void(*foreign_decref)(void *)) noexcept
Construct a handle from a shared object from a foreign library.
Definition handle.hpp:788
T * data() const noexcept
Get a pointer to the stored data.
Definition handle.hpp:842
long size() const noexcept
Get the size of the handle.
Definition handle.hpp:848
A handle for a memory block on the heap or stack depending on the size of the data.
Definition handle.hpp:492
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated.
Definition handle.hpp:524
handle_sso()
Default constructor.
Definition handle.hpp:527
long size() const noexcept
Get the size of the handle.
Definition handle.hpp:744
~handle_sso() noexcept
Destructor for the handle.
Definition handle.hpp:535
T & operator[](long i) noexcept
Subscript operator to access the data.
Definition handle.hpp:707
bool is_null() const noexcept
Check if the handle is in a null state.
Definition handle.hpp:727
handle_sso & operator=(handle_sso const &h) noexcept
Copy assignment operator first cleans up the current handle and then makes a deep copy of the data fr...
Definition handle.hpp:598
handle_sso & operator=(handle_sso &&h) noexcept
Move assignment operator first releases the resources held by the current handle and then either copi...
Definition handle.hpp:563
handle_sso(long size)
Construct a handle for the data of a given size and initialize it depending on the value type.
Definition handle.hpp:680
handle_sso(handle_sso const &h)
Copy construct a handle by making a deep copy of the data from the source handle.
Definition handle.hpp:583
T * data() const noexcept
Get a pointer to the stored data.
Definition handle.hpp:738
bool on_heap() const
Check if the data is/should be stored on the heap.
Definition handle.hpp:721
handle_sso(long size, do_not_initialize_t)
Construct a handle for the data of a given size and do not initialize it.
Definition handle.hpp:636
handle_sso(long size, init_zero_t)
Construct a handle for the data of a given size and initialize it to zero (only for scalar and comple...
Definition handle.hpp:656
handle_sso(handle_sso &&h) noexcept
Move constructor either copies the heap pointers or makes a deep copy of the stack data.
Definition handle.hpp:542
handle_sso(H const &h)
Construct a handle by making a deep copy of the data from another owning handle.
Definition handle.hpp:620
T const & operator[](long i) const noexcept
Subscript operator to access the data.
Definition handle.hpp:715
A handle for a memory block on the stack.
Definition handle.hpp:359
static constexpr auto address_space
nda::mem::AddressSpace in which the memory is allocated (always on Host).
Definition handle.hpp:372
handle_stack()=default
Default constructor leaves the data uninitialized.
handle_stack(long)
Construct a handle and initialize the data depending on the value type.
Definition handle.hpp:437
T & operator[](long i) noexcept
Subscript operator to access the data.
Definition handle.hpp:449
T * data() const noexcept
Get a pointer to the stored data.
Definition handle.hpp:469
handle_stack & operator=(handle_stack const &h)
Copy assignment operator makes a deep copy of the data from the source handle using placement new.
Definition handle.hpp:416
~handle_stack() noexcept
Destructor for the handle.
Definition handle.hpp:378
handle_stack(handle_stack const &h) noexcept
Copy constructor simply calls the copy assignment operator.
Definition handle.hpp:410
handle_stack(long, do_not_initialize_t)
Construct a handle and do not initialize the data.
Definition handle.hpp:422
handle_stack(handle_stack &&h) noexcept
Move constructor simply calls the copy assignment operator.
Definition handle.hpp:393
handle_stack & operator=(handle_stack &&h) noexcept
Move assignment operator simply calls the copy assignment operator.
Definition handle.hpp:400
handle_stack(long, init_zero_t)
Construct a handle and initialize the data to zero (only for scalar and complex types).
Definition handle.hpp:425
static constexpr long size() noexcept
Get the size of the handle.
Definition handle.hpp:475
static constexpr bool is_null() noexcept
Check if the handle is in a null state.
Definition handle.hpp:463
T const & operator[](long i) const noexcept
Subscript operator to access the data.
Definition handle.hpp:457
Tag used in constructors to indicate that the memory should be initialized to zero.
Definition handle.hpp:72
Accessor type of the nda::no_alias_accessor.
Definition accessors.hpp:82
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
Definition accessors.hpp:99
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.
Definition accessors.hpp:76
Memory policy using an nda::mem::handle_shared.
Definition policies.hpp:94
Memory policy using an nda::mem::handle_sso.
Definition policies.hpp:70
Memory policy using an nda::mem::handle_stack.
Definition policies.hpp:84