TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
tools.hpp
Go to the documentation of this file.
1// Copyright (c) 2019-2024 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: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include "../concepts.hpp"
25#include "../map.hpp"
27
28#include <complex>
29#include <tuple>
30#include <type_traits>
31#include <utility>
32
33namespace nda {
34
39 using dcomplex = std::complex<double>;
40
41} // namespace nda
42
43namespace nda::blas {
44
51 template <typename A>
52 static constexpr bool is_conj_array_expr = false;
53
55 template <MemoryArray A>
56 static constexpr bool is_conj_array_expr<expr_call<detail::conj_f, A>> = true;
57
58 // Specialization of nda::blas::is_conj_array_expr for cvref types.
59 template <typename A>
60 requires(!std::is_same_v<A, std::remove_cvref_t<A>>)
61 static constexpr bool is_conj_array_expr<A> = is_conj_array_expr<std::remove_cvref_t<A>>;
62
64 template <Array A>
65 requires(MemoryArray<A> or is_conj_array_expr<A>)
66 static constexpr bool has_F_layout = []() {
67 if constexpr (is_conj_array_expr<A>)
68 return has_F_layout<decltype(std::get<0>(std::declval<A>().a))>;
69 else
70 return std::remove_cvref_t<A>::is_stride_order_Fortran();
71 }();
72
74 template <Array A>
75 requires(MemoryArray<A> or is_conj_array_expr<A>)
76 static constexpr bool has_C_layout = []() {
77 if constexpr (is_conj_array_expr<A>)
78 return has_C_layout<decltype(std::get<0>(std::declval<A>().a))>;
79 else
80 return std::remove_cvref_t<A>::is_stride_order_C();
81 }();
82
90 template <bool conj, bool transpose>
91 const char get_op = []() {
92 static_assert(!(conj and not transpose), "Error in nda::blas::get_op: Cannot use conjugate operation alone in blas operations");
93 if constexpr (conj and transpose)
94 return 'C';
95 else if constexpr (transpose)
96 return 'T';
97 else // !conj and !transpose
98 return 'N';
99 }();
100
108 template <MemoryMatrix A>
109 int get_ld(A const &a) {
110 return a.indexmap().strides()[has_F_layout<A> ? 1 : 0];
111 }
112
120 template <MemoryMatrix A>
121 int get_ncols(A const &a) {
122 return a.shape()[has_F_layout<A> ? 1 : 0];
123 }
124
127} // namespace nda::blas
Check if a given type satisfies the memory array concept.
Definition concepts.hpp:248
Provides concepts for the nda library.
auto transpose(A &&a)
Transpose the memory layout of an nda::MemoryArray or an nda::expr_call.
int get_ld(A const &a)
Get the leading dimension in LAPACK jargon of an nda::MemoryMatrix.
Definition tools.hpp:109
std::complex< double > dcomplex
Alias for std::complex<double> type.
Definition tools.hpp:39
int get_ncols(A const &a)
Get the number of columns in LAPACK jargon of an nda::MemoryMatrix.
Definition tools.hpp:121
Provides lazy function calls on arrays/views.
Provides some custom implementations of standard mathematical functions used for lazy,...