TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
declarations.hpp
Go to the documentation of this file.
1// Copyright (c) 2019--present, The Simons Foundation
2// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3// SPDX-License-Identifier: Apache-2.0
4// See LICENSE in the root of this distribution for details.
5
10
11#pragma once
12
13#include "./accessors.hpp"
14#include "./concepts.hpp"
15#include "./layout/idx_map.hpp"
17#include "./layout/policies.hpp"
19#include "./mem/policies.hpp"
20#include "./traits.hpp"
21
22#include <array>
23#include <cstddef>
24#include <cstdint>
25#include <stdexcept>
26#include <type_traits>
27
28namespace nda {
29
31 // Forward declarations.
32 template <int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
33 class idx_map;
34
35 template <typename ValueType, int Rank, typename Layout, char Algebra, typename ContainerPolicy>
36 class basic_array;
37
38 template <typename ValueType, int Rank, typename Layout, char Algebra = 'A',
39 typename AccessorPolicy = nda::default_accessor, //, nda::no_alias_accessor, //,
40 typename OwningPolicy = nda::borrowed<>>
41 class basic_array_view;
42
43 template <char OP, Array A>
44 struct expr_unary;
45
46 template <char OP, ArrayOrScalar L, ArrayOrScalar R>
47 struct expr;
49
54
63 template <typename ValueType, int Rank, typename Layout = C_layout, typename ContainerPolicy = heap<>>
64 using array = basic_array<ValueType, Rank, Layout, 'A', ContainerPolicy>;
65
74 template <typename ValueType, int Rank, typename Layout = C_stride_layout>
75 using array_view = basic_array_view<ValueType, Rank, Layout, 'A', default_accessor, borrowed<>>;
76
84 template <typename ValueType, int Rank, typename Layout = C_stride_layout>
85 using array_const_view = basic_array_view<ValueType const, Rank, Layout, 'A', default_accessor, borrowed<>>;
86
94 template <typename ValueType, int Rank, typename Layout = C_layout>
95 requires(has_contiguous(Layout::template mapping<Rank>::layout_prop))
96 using array_contiguous_view = basic_array_view<ValueType, Rank, Layout, 'A', default_accessor, borrowed<>>;
97
105 template <typename ValueType, int Rank, typename Layout = C_layout>
106 requires(has_contiguous(Layout::template mapping<Rank>::layout_prop))
107 using array_contiguous_const_view = basic_array_view<ValueType const, Rank, Layout, 'A', default_accessor, borrowed<>>;
108
116 template <typename ValueType, typename Layout = C_layout, typename ContainerPolicy = heap<>>
117 using matrix = basic_array<ValueType, 2, Layout, 'M', ContainerPolicy>;
118
126 template <typename ValueType, typename Layout = C_stride_layout>
127 using matrix_view = basic_array_view<ValueType, 2, Layout, 'M', default_accessor, borrowed<>>;
128
135 template <typename ValueType, typename Layout = C_stride_layout>
136 using matrix_const_view = basic_array_view<ValueType const, 2, Layout, 'M', default_accessor, borrowed<>>;
137
144 template <typename ValueType, typename ContainerPolicy = heap<>>
145 using vector = basic_array<ValueType, 1, C_layout, 'V', ContainerPolicy>;
146
154 template <typename ValueType, typename Layout = C_stride_layout>
155 using vector_view = basic_array_view<ValueType, 1, Layout, 'V', default_accessor, borrowed<>>;
156
163 template <typename ValueType, typename Layout = C_stride_layout>
164 using vector_const_view = basic_array_view<ValueType const, 1, Layout, 'V', default_accessor, borrowed<>>;
165
175 template <typename... Is>
176 constexpr uint64_t static_extents(int i0, Is... is) {
177 if (i0 > 15) throw std::runtime_error("Error in nda::static_extents: Only 16 dimensions are supported!");
178 return encode(std::array<int, sizeof...(Is) + 1>{i0, static_cast<int>(is)...});
179 }
180
189 template <typename ValueType, int N0, int... Ns>
191 nda::basic_array<ValueType, 1 + sizeof...(Ns),
192 nda::basic_layout<nda::static_extents(N0, Ns...), nda::C_stride_order<1 + sizeof...(Ns)>, nda::layout_prop_e::contiguous>, 'A',
193 nda::stack<N0 *(Ns *... * 1)>>;
194
203 template <typename ValueType, int N, int M>
205 nda::basic_array<ValueType, 2, nda::basic_layout<nda::static_extents(N, M), nda::C_stride_order<2>, nda::layout_prop_e::contiguous>, 'M',
207
215 template <typename ValueType, int N>
217 nda::basic_array<ValueType, 1, nda::basic_layout<nda::static_extents(N), nda::C_stride_order<1>, nda::layout_prop_e::contiguous>, 'V',
219
227 template <typename ValueType, int Rank, typename Layout = C_layout>
228 using cuarray = basic_array<ValueType, Rank, Layout, 'A', heap<mem::Device>>;
229
237 template <typename ValueType, int Rank, typename Layout = C_stride_layout>
239
247 template <typename ValueType, int Rank, typename Layout = C_stride_layout>
248 using cuarray_const_view = basic_array_view<ValueType const, Rank, Layout, 'A', default_accessor, borrowed<mem::Device>>;
249
257 template <typename ValueType, typename Layout = C_layout, typename ContainerPolicy = heap<mem::Device>>
258 using cumatrix = basic_array<ValueType, 2, Layout, 'M', ContainerPolicy>;
259
266 template <typename ValueType, typename Layout = C_stride_layout>
268
275 template <typename ValueType, typename Layout = C_stride_layout>
277
283 template <typename ValueType>
284 using cuvector = basic_array<ValueType, 1, C_layout, 'V', heap<mem::Device>>;
285
292 template <typename ValueType, typename Layout = C_stride_layout>
294
301 template <typename ValueType, typename Layout = C_stride_layout>
303
305
310
312 template <typename ValueType, int Rank, typename Layout, char Algebra, typename ContainerPolicy>
314
316 template <typename ValueType, int Rank, typename Layout, char Algebra, typename AccessorPolicy, typename OwningPolicy>
318
320 template <typename ValueType, int Rank, typename Layout, char Algebra, typename ContainerPolicy>
322
324 template <typename ValueType, int Rank, typename Layout, char Algebra, typename AccessorPolicy, typename OwningPolicy>
326
328 template <typename ValueType, int Rank, typename Layout, char Algebra, typename ContainerPolicy>
331
333 template <typename ValueType, int Rank, typename Layout, char Algebra, typename AccessorPolicy, typename OwningPolicy>
336
341 template <typename T, typename T2 = std::remove_reference_t<T> /* Keep this: Fix for gcc11 bug */>
342 using get_view_t = std::remove_reference_t<decltype(basic_array_view{std::declval<T>()})>;
343
348 template <typename T, typename T2 = std::remove_reference_t<T> /* Keep this: Fix for gcc11 bug */>
349 using get_regular_t = decltype(basic_array{std::declval<T>()});
350
357 template <typename T, typename RT = get_regular_t<T>>
359 std::conditional_t<mem::on_host<RT>, RT,
362
369 template <typename T, typename RT = get_regular_t<T>>
371 std::conditional_t<mem::on_device<RT>, RT,
374
381 template <typename T, typename RT = get_regular_t<T>>
383 std::conditional_t<mem::on_unified<RT>, RT,
386
388 template <char OP, Array A>
390
392 template <char OP, Array A>
394
396 template <char OP, typename L, typename R>
398
400 template <char OP, typename L, typename R>
402
404
405} // namespace nda
Defines accessors for nda::array objects (cf. std::default_accessor).
Provides definitions and type traits involving the different memory address spaces supported by nda.
A generic view of a multi-dimensional array.
A generic multi-dimensional array.
Layout that specifies how to map multi-dimensional indices to a linear/flat index.
Definition idx_map.hpp:90
Provides concepts for the nda library.
basic_array_view< ValueType, 1, Layout, 'V', default_accessor, borrowed<> > vector_view
Alias template of an nda::basic_array_view with rank 1, a 'V' algebra, nda::default_accessor and nda:...
basic_array_view< ValueType, Rank, Layout, 'A', default_accessor, borrowed<> > array_view
Alias template of an nda::basic_array_view with an 'A' algebra, nda::default_accessor and nda::borrow...
nda::basic_array< ValueType, 2, nda::basic_layout< nda::static_extents(N, M), nda::C_stride_order< 2 >, nda::layout_prop_e::contiguous >, 'M', nda::stack< static_cast< size_t >(N *M)> > stack_matrix
Alias template of an nda::basic_array with rank 2, static extents, contiguous C layout,...
basic_array_view< ValueType, 1, Layout, 'V', default_accessor, borrowed< mem::Device > > cuvector_view
Similar to nda::vector_view except the memory is stored on the device.
basic_array< ValueType, 1, C_layout, 'V', heap< mem::Device > > cuvector
Similar to nda::vector except the memory is stored on the device.
basic_array_view< ValueType const, 2, Layout, 'M', default_accessor, borrowed< mem::Device > > cumatrix_const_view
Similar to nda::matrix_const_view except the memory is stored on the device.
basic_array_view< ValueType, Rank, Layout, 'A', default_accessor, borrowed<> > array_contiguous_view
Same as nda::array_view except for contiguous memory layouts.
basic_array_view< ValueType, 2, Layout, 'M', default_accessor, borrowed<> > matrix_view
Alias template of an nda::basic_array_view with rank 2, an 'M' algebra, nda::default_accessor and nda...
basic_array_view< ValueType const, Rank, Layout, 'A', default_accessor, borrowed<> > array_contiguous_const_view
Same as nda::array_const_view except for contiguous memory layouts.
basic_array_view< ValueType const, Rank, Layout, 'A', default_accessor, borrowed<> > array_const_view
Same as nda::array_view except for const value types.
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
nda::basic_array< ValueType, 1, nda::basic_layout< nda::static_extents(N), nda::C_stride_order< 1 >, nda::layout_prop_e::contiguous >, 'V', nda::stack< N > > stack_vector
Alias template of an nda::basic_array with rank 1, static extents, contiguous C layout,...
basic_array< ValueType, Rank, Layout, 'A', heap< mem::Device > > cuarray
Similar to nda::array except the memory is stored on the device.
basic_array_view< ValueType const, Rank, Layout, 'A', default_accessor, borrowed< mem::Device > > cuarray_const_view
Similar to nda::array_const_view except the memory is stored on the device.
basic_array< ValueType, 2, Layout, 'M', ContainerPolicy > cumatrix
Similar to nda::matrix except the memory is stored on the device.
basic_array_view< ValueType const, 1, Layout, 'V', default_accessor, borrowed<> > vector_const_view
Same as nda::vector_view except for const value types.
basic_array< ValueType, 1, C_layout, 'V', ContainerPolicy > vector
Alias template of an nda::basic_array with rank 1 and a 'V' algebra.
basic_array_view< ValueType const, 2, Layout, 'M', default_accessor, borrowed<> > matrix_const_view
Same as nda::matrix_view except for const value types.
basic_array_view< ValueType, 2, Layout, 'M', default_accessor, borrowed< mem::Device > > cumatrix_view
Similar to nda::matrix_view except the memory is stored on the device.
basic_array< ValueType, 2, Layout, 'M', ContainerPolicy > matrix
Alias template of an nda::basic_array with rank 2 and an 'M' algebra.
basic_array_view< ValueType, Rank, Layout, 'A', default_accessor, borrowed< mem::Device > > cuarray_view
Similar to nda::array_view except the memory is stored on the device.
basic_array_view< ValueType const, 1, Layout, 'V', default_accessor, borrowed< mem::Device > > cuvector_const_view
Similar to nda::vector_const_view except the memory is stored on the device.
nda::basic_array< ValueType, 1+sizeof...(Ns), nda::basic_layout< nda::static_extents(N0, Ns...), nda::C_stride_order< 1+sizeof...(Ns)>, nda::layout_prop_e::contiguous >, 'A', nda::stack< N0 *(Ns *... *1)> > stack_array
Alias template of an nda::basic_array with static extents, contiguous C layout, 'A' algebra and nda::...
constexpr bool is_regular_v
Constexpr variable that is true if type A is a regular array, i.e. an nda::basic_array.
Definition traits.hpp:134
constexpr char get_algebra
Constexpr variable that specifies the algebra of a type.
Definition traits.hpp:115
std::conditional_t< mem::on_device< RT >, RT, basic_array< get_value_t< RT >, get_rank< RT >, get_contiguous_layout_policy< get_rank< RT >, get_layout_info< RT >.stride_order >, get_algebra< RT >, heap< mem::Device > > > get_regular_device_t
Get the type of the nda::basic_array that would be obtained by constructing an array on device memory...
decltype(basic_array{std::declval< T >()}) get_regular_t
Get the type of the nda::basic_array that would be obtained by constructing an array from a given typ...
std::conditional_t< mem::on_unified< RT >, RT, basic_array< get_value_t< RT >, get_rank< RT >, get_contiguous_layout_policy< get_rank< RT >, get_layout_info< RT >.stride_order >, get_algebra< RT >, heap< mem::Unified > > > get_regular_unified_t
Get the type of the nda::basic_array that would be obtained by constructing an array on unified memor...
std::conditional_t< mem::on_host< RT >, RT, basic_array< get_value_t< RT >, get_rank< RT >, get_contiguous_layout_policy< get_rank< RT >, get_layout_info< RT >.stride_order >, get_algebra< RT >, heap< mem::Host > > > get_regular_host_t
Get the type of the nda::basic_array that would be obtained by constructing an array on host memory f...
constexpr uint64_t static_extents(int i0, Is... is)
Encode the given shape into a single integer using the nda::encode function.
constexpr int get_rank
Constexpr variable that specifies the rank of an nda::Array or of a contiguous 1-dimensional range.
Definition traits.hpp:125
std::remove_reference_t< decltype(basic_array_view{std::declval< T >()})> get_view_t
Get the type of the nda::basic_array_view that would be obtained by constructing a view from a given ...
constexpr bool is_view_v
Constexpr variable that is true if type A is a view, i.e. an nda::basic_array_view.
Definition traits.hpp:143
constexpr uint64_t C_stride_order
C/Row-major stride order.
Definition idx_map.hpp:52
std::conditional_t< StrideOrder==C_stride_order< Rank >, C_layout, std::conditional_t< StrideOrder==Fortran_stride_order< Rank >, F_layout, contiguous_layout_with_stride_order< StrideOrder > > > get_contiguous_layout_policy
Get the contiguous layout policy for a given rank and stride order.
Definition policies.hpp:130
constexpr bool has_contiguous(layout_prop_e lp)
Checks if a layout property has the contiguous property.
Definition traits.hpp:271
constexpr layout_info_t get_layout_info
Constexpr variable that specifies the nda::layout_info_t of type A.
Definition traits.hpp:310
heap_basic< mem::mallocator< AdrSp > > heap
Alias template of the nda::heap_basic policy using an nda::mem::mallocator.
Definition policies.hpp:52
constexpr uint64_t encode(std::array< int, N > const &a)
Encode a std::array<int, N> in a uint64_t.
Provides a class that maps multi-dimensional indices to a linear index and vice versa.
Provides definitions of various layout policies.
Defines various memory handling policies.
Provides utilities to work with permutations and to compactly encode/decode std::array objects.
Contiguous layout policy with C-order (row-major order).
Definition policies.hpp:36
Generic layout policy with arbitrary order.
Definition policies.hpp:104
Memory policy using an nda::mem::handle_borrowed.
Definition policies.hpp:97
Default accessor for various array and view types.
Definition accessors.hpp:25
Lazy unary expression for nda::Array types.
Lazy binary expression for nda::ArrayOrScalar types.
static constexpr layout_info_t compute_layout_info()
Compute the layout information of the expression.
static constexpr char algebra
Constexpr variable specifying the algebra of one of the non-scalar operands.
Stores information about the memory layout and the stride order of an array/view.
Definition traits.hpp:284
Memory policy using an nda::mem::handle_stack.
Definition policies.hpp:73
Provides type traits for the nda library.