TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
utils.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 "../basic_array.hpp"
15#include "../concepts.hpp"
16#include "../declarations.hpp"
17#include "../exceptions.hpp"
19#include "../macros.hpp"
21#include "../traits.hpp"
22
23#include <utility>
24
25namespace nda::linalg {
26
31
47 auto get_permutation_vector(Vector auto const &ipiv, int m) {
48 static_assert(nda::mem::have_host_compatible_addr_space<decltype(ipiv)>);
49 EXPECTS(m >= ipiv.size());
50 auto sigma = vector<int>{arange<int>(m)};
51 for (int i = 0; i < ipiv.size(); ++i) std::swap(sigma(i), sigma(ipiv(i) - 1));
52 return sigma;
53 }
54
73 template <Scalar T, typename LP = F_layout>
74 auto get_permutation_matrix(Vector auto const &sigma, bool column_permutations = false) {
75 static_assert(nda::mem::have_host_compatible_addr_space<decltype(sigma)>);
76 int m = sigma.size();
77 auto P = matrix<T, LP>::zeros(m, m);
78 for (int i = 0; i < m; ++i) (column_permutations ? P(sigma(i), i) : P(i, sigma(i))) = T{1};
79 return P;
80 }
81
97 template <Scalar T, typename LP = F_layout>
98 auto get_permutation_matrix(Vector auto const &ipiv, int m) {
100 }
101
103
104} // 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:280
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:74
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:47
Provides definitions of various layout policies.
Macros used in the nda library.
Provides type traits for the nda library.