TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
utils.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
21
22#pragma once
23
24#include "../basic_array.hpp"
26#include "../concepts.hpp"
27#include "../declarations.hpp"
28#include "../exceptions.hpp"
30#include "../macros.hpp"
32#include "../traits.hpp"
33
34#include <utility>
35
36namespace nda::linalg {
37
42
56 auto get_permutation_vector(Vector auto const &ipiv, int m) {
57 static_assert(nda::mem::have_host_compatible_addr_space<decltype(ipiv)>);
58 EXPECTS(m >= ipiv.size());
59 auto sigma = vector<int>{arange<int>(m)};
60 for (int i = 0; i < ipiv.size(); ++i) std::swap(sigma(i), sigma(ipiv(i) - 1));
61 return sigma;
62 }
63
80 template <Scalar T, typename LP = F_layout>
81 auto get_permutation_matrix(Vector auto const &sigma, bool column_permutations = false) {
82 static_assert(nda::mem::have_host_compatible_addr_space<decltype(sigma)>);
83 int m = sigma.size();
84 auto P = matrix<T, LP>::zeros(m, m);
85 for (int i = 0; i < m; ++i) (column_permutations ? P(sigma(i), i) : P(i, sigma(i))) = T{1};
86 return P;
87 }
88
102 template <Scalar T, typename LP = F_layout>
103 auto get_permutation_matrix(Vector auto const &ipiv, int m) {
105 }
106
108
109} // namespace nda::linalg
Provides definitions and type traits involving the different memory address spaces supported by nda.
Provides the generic class for arrays.
void swap(nda::basic_array_view< V1, R1, LP1, A1, AP1, OP1 > &a, nda::basic_array_view< V2, R2, LP2, A2, AP2, OP2 > &b)=delete
std::swap is deleted for nda::basic_array_view.
Provides basic functions to create and manipulate arrays and views.
static basic_array zeros(std::array< Int, Rank > const &shape)
Check if a given type is a vector, i.e. an nda::ArrayOfRank<1>.
Definition concepts.hpp:273
Provides concepts for the nda library.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
auto arange(long first, long last, long step=1)
Make a 1-dimensional integer array and initialize it with values of a given nda::range.
basic_array< ValueType, 1, C_layout, 'V', ContainerPolicy > vector
Alias template of an nda::basic_array with rank 1 and a 'V' algebra.
auto get_permutation_matrix(Vector auto const &sigma, bool column_permutations=false)
Get the permutation matrix from a permutation vector .
Definition utils.hpp:81
auto get_permutation_vector(Vector auto const &ipiv, int m)
Get the permutation vector from the pivot indices returned by nda::lapack::getrf or other LAPACK rou...
Definition utils.hpp:56
static constexpr bool have_host_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Host.
Provides definitions of various layout policies.
Macros used in the nda library.
Provides type traits for the nda library.