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--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 "../concepts.hpp"
14#include "../map.hpp"
16
17#include <complex>
18#include <tuple>
19#include <type_traits>
20#include <utility>
21
22namespace nda {
23
28 using dcomplex = std::complex<double>;
29
30} // namespace nda
31
32namespace nda::blas {
33
38
40 template <typename A>
41 static constexpr bool is_conj_array_expr = false;
42
44 template <MemoryArray A>
46
47 // Specialization of nda::blas::is_conj_array_expr for cvref types.
48 template <typename A>
49 requires(!std::is_same_v<A, std::remove_cvref_t<A>>)
50 static constexpr bool is_conj_array_expr<A> = is_conj_array_expr<std::remove_cvref_t<A>>;
51
53 template <Array A>
55 static constexpr bool has_F_layout = []() {
56 if constexpr (is_conj_array_expr<A>)
57 return has_F_layout<decltype(std::get<0>(std::declval<A>().a))>;
58 else
59 return std::remove_cvref_t<A>::is_stride_order_Fortran();
60 }();
61
63 template <Array A>
64 requires(MemoryArray<A> or is_conj_array_expr<A>)
65 static constexpr bool has_C_layout = []() {
66 if constexpr (is_conj_array_expr<A>)
67 return has_C_layout<decltype(std::get<0>(std::declval<A>().a))>;
68 else
69 return std::remove_cvref_t<A>::is_stride_order_C();
70 }();
71
79 template <bool conj, bool transpose>
80 const char get_op = []() {
81 static_assert(!(conj and not transpose), "Error in nda::blas::get_op: Cannot use conjugate operation alone in blas operations");
82 if constexpr (conj and transpose)
83 return 'C';
84 else if constexpr (transpose)
85 return 'T';
86 else // !conj and !transpose
87 return 'N';
88 }();
89
97 template <MemoryMatrix A>
98 int get_ld(A const &a) {
99 return a.indexmap().strides()[has_F_layout<A> ? 1 : 0];
100 }
101
109 template <MemoryMatrix A>
110 int get_ncols(A const &a) {
111 return a.shape()[has_F_layout<A> ? 1 : 0];
112 }
113
115
116} // 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.
decltype(auto) conj(A &&a)
Function conj for nda::ArrayOrScalar types (lazy and coefficient-wise for nda::Array types with a com...
int get_ld(A const &a)
Get the leading dimension in LAPACK jargon of an nda::MemoryMatrix.
Definition tools.hpp:98
static constexpr bool has_C_layout
Constexpr variable that is true if the given nda::Array type has a C memory layout.
Definition tools.hpp:65
std::complex< double > dcomplex
Alias for std::complex<double> type.
Definition tools.hpp:28
static constexpr bool is_conj_array_expr
Constexpr variable that is true if the given type is a conjugate lazy expression.
Definition tools.hpp:41
int get_ncols(A const &a)
Get the number of columns in LAPACK jargon of an nda::MemoryMatrix.
Definition tools.hpp:110
static constexpr bool has_F_layout
Constexpr variable that is true if the given nda::Array type has a Fortran memory layout.
Definition tools.hpp:55
const char get_op
Variable template that determines the BLAS matrix operation tag ('N','T','C') based on the given bool...
Definition tools.hpp:80
Provides lazy function calls on arrays/views.
Provides some custom implementations of standard mathematical functions used for lazy,...