TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
policies.hpp
Go to the documentation of this file.
1// Copyright (c) 2019-2022 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
22#pragma once
23
24#include "./idx_map.hpp"
25#include "../traits.hpp"
26
27#include <cstdint>
28#include <type_traits>
29
30namespace nda {
31
38 // Forward declarations.
39 struct C_stride_layout;
40 struct F_stride_layout;
42
47 struct C_layout {
49 template <int Rank>
50 using mapping = idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::contiguous>;
51
54
57 };
58
63 struct F_layout {
65 template <int Rank>
66 using mapping = idx_map<Rank, 0, Fortran_stride_order<Rank>, layout_prop_e::contiguous>;
67
70
73 };
74
81 template <int Rank>
82 using mapping = idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::none>;
83
86
89 };
90
97 template <int Rank>
99
102
105 };
106
114 template <uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
126
131 template <uint64_t StrideOrder>
133
140 template <int Rank, uint64_t StrideOrder>
142 std::conditional_t<StrideOrder == C_stride_order<Rank>, C_layout,
143 std::conditional_t<StrideOrder == Fortran_stride_order<Rank>, F_layout, contiguous_layout_with_stride_order<StrideOrder>>>;
144
145 namespace detail {
146
148 // Forward declarations.
149 template <typename L>
150 struct layout_to_policy;
152
153 // Get the correct layout policy given a general nda::idx_map.
154 template <int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
155 struct layout_to_policy<idx_map<Rank, StaticExtents, StrideOrder, LayoutProp>> {
157 };
158
159 // Get the correct layout policy given a contiguous nda::idx_map with C-order.
160 template <int Rank>
161 struct layout_to_policy<idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::contiguous>> {
162 using type = C_layout;
163 };
164
165 // Get the correct layout policy given a strided nda::idx_map with C-order.
166 template <int Rank>
167 struct layout_to_policy<idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::none>> {
168 using type = C_stride_layout;
169 };
170
171 // Get the correct layout policy given a contiguous nda::idx_map with Fortran-order.
172 template <int Rank>
173 requires(Rank > 1)
174 struct layout_to_policy<idx_map<Rank, 0, Fortran_stride_order<Rank>, layout_prop_e::contiguous>> {
175 using type = F_layout;
176 };
177
178 // Get the correct layout policy given a strided nda::idx_map with Fortran-order.
179 template <int Rank>
180 requires(Rank > 1)
181 struct layout_to_policy<idx_map<Rank, 0, Fortran_stride_order<Rank>, layout_prop_e::none>> {
182 using type = F_stride_layout;
183 };
184
185 } // namespace detail
186
189} // namespace nda
Layout that specifies how to map multi-dimensional indices to a linear/flat index.
Definition idx_map.hpp:103
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
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:141
layout_prop_e
Compile-time guarantees of the memory layout of an array/view.
Definition traits.hpp:222
Provides a class that maps multi-dimensional indices to a linear index and vice versa.
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
Generic layout policy with arbitrary order.
Definition policies.hpp:115
Provides type traits for the nda library.