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--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 "./idx_map.hpp"
14#include "../traits.hpp"
15
16#include <cstdint>
17#include <type_traits>
18
19namespace nda {
20
25
27 // Forward declarations.
28 struct C_stride_layout;
29 struct F_stride_layout;
31
36 struct C_layout {
38 template <int Rank>
39 using mapping = idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::contiguous>;
40
43
46 };
47
52 struct F_layout {
54 template <int Rank>
55 using mapping = idx_map<Rank, 0, Fortran_stride_order<Rank>, layout_prop_e::contiguous>;
56
59
62 };
63
70 template <int Rank>
71 using mapping = idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::none>;
72
75
78 };
79
86 template <int Rank>
88
91
94 };
95
103 template <uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
115
120 template <uint64_t StrideOrder>
122
129 template <int Rank, uint64_t StrideOrder>
131 std::conditional_t<StrideOrder == C_stride_order<Rank>, C_layout,
132 std::conditional_t<StrideOrder == Fortran_stride_order<Rank>, F_layout, contiguous_layout_with_stride_order<StrideOrder>>>;
133
134 namespace detail {
135
137 // Forward declarations.
138 template <typename L>
139 struct layout_to_policy;
141
142 // Get the correct layout policy given a general nda::idx_map.
143 template <int Rank, uint64_t StaticExtents, uint64_t StrideOrder, layout_prop_e LayoutProp>
144 struct layout_to_policy<idx_map<Rank, StaticExtents, StrideOrder, LayoutProp>> {
146 };
147
148 // Get the correct layout policy given a contiguous nda::idx_map with C-order.
149 template <int Rank>
150 struct layout_to_policy<idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::contiguous>> {
151 using type = C_layout;
152 };
153
154 // Get the correct layout policy given a strided nda::idx_map with C-order.
155 template <int Rank>
156 struct layout_to_policy<idx_map<Rank, 0, C_stride_order<Rank>, layout_prop_e::none>> {
157 using type = C_stride_layout;
158 };
159
160 // Get the correct layout policy given a contiguous nda::idx_map with Fortran-order.
161 template <int Rank>
162 requires(Rank > 1)
163 struct layout_to_policy<idx_map<Rank, 0, Fortran_stride_order<Rank>, layout_prop_e::contiguous>> {
164 using type = F_layout;
165 };
166
167 // Get the correct layout policy given a strided nda::idx_map with Fortran-order.
168 template <int Rank>
169 requires(Rank > 1)
170 struct layout_to_policy<idx_map<Rank, 0, Fortran_stride_order<Rank>, layout_prop_e::none>> {
171 using type = F_stride_layout;
172 };
173
174 } // namespace detail
175
177
178} // namespace nda
Layout that specifies how to map multi-dimensional indices to a linear/flat index.
Definition idx_map.hpp:90
constexpr uint64_t C_stride_order
C/Row-major stride order.
Definition idx_map.hpp:52
constexpr uint64_t Fortran_stride_order
Fortran/Column-major stride order.
Definition idx_map.hpp:44
basic_layout< 0, StrideOrder, layout_prop_e::contiguous > contiguous_layout_with_stride_order
Contiguous layout policy with arbitrary stride order.
Definition policies.hpp:121
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
layout_prop_e
Compile-time guarantees of the memory layout of an array/view.
Definition traits.hpp:211
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:36
idx_map< Rank, 0, C_stride_order< Rank >, layout_prop_e::contiguous > mapping
Multi-dimensional to flat index mapping.
Definition policies.hpp:39
C_stride_layout with_lowest_guarantee_t
The same layout policy, but with no guarantee of contiguity.
Definition policies.hpp:42
C_layout contiguous_t
The same layout policy, but with guarantee of contiguity.
Definition policies.hpp:45
Strided (non-contiguous) layout policy with C-order (row-major order).
Definition policies.hpp:68
idx_map< Rank, 0, C_stride_order< Rank >, layout_prop_e::none > mapping
Multi-dimensional to flat index mapping.
Definition policies.hpp:71
C_stride_layout with_lowest_guarantee_t
The same layout policy, but with no guarantee of contiguity.
Definition policies.hpp:74
C_layout contiguous_t
The same layout policy, but with guarantee of contiguity.
Definition policies.hpp:77
Contiguous layout policy with Fortran-order (column-major order).
Definition policies.hpp:52
F_stride_layout with_lowest_guarantee_t
The same layout policy, but with no guarantee of contiguity.
Definition policies.hpp:58
F_layout contiguous_t
The same layout policy, but with guarantee of contiguity.
Definition policies.hpp:61
idx_map< Rank, 0, Fortran_stride_order< Rank >, layout_prop_e::contiguous > mapping
Multi-dimensional to flat index mapping.
Definition policies.hpp:55
Strided (non-contiguous) layout policy with Fortran-order (column-major order).
Definition policies.hpp:84
F_stride_layout with_lowest_guarantee_t
The same layout policy, but with no guarantee of contiguity.
Definition policies.hpp:90
F_layout contiguous_t
The same layout policy, but with guarantee of contiguity.
Definition policies.hpp:93
idx_map< Rank, 0, Fortran_stride_order< Rank >, layout_prop_e::none > mapping
Multi-dimensional to flat index mapping.
Definition policies.hpp:87
Generic layout policy with arbitrary order.
Definition policies.hpp:104
basic_layout< StaticExtents, StrideOrder, layout_prop_e::contiguous > contiguous_t
Definition policies.hpp:113
basic_layout< StaticExtents, StrideOrder, layout_prop_e::none > with_lowest_guarantee_t
The same layout policy, but with no guarantee of contiguity.
Definition policies.hpp:110
idx_map< Rank, StaticExtents, StrideOrder, LayoutProp > mapping
Multi-dimensional to flat index mapping.
Definition policies.hpp:107
Provides type traits for the nda library.