TRIQS/triqs_modest 3.3.0
Brillouin zone summation
Loading...
Searching...
No Matches
nda_supp.hpp
Go to the documentation of this file.
1// Copyright (c) 2025--present, The Simons Foundation
2// This file is part of TRIQS/modest and is licensed under the terms of GPLv3 or later.
3// SPDX-License-Identifier: GPL-3.0-or-later
4// See LICENSE in the root of this distribution for details.
5
6#pragma once
7#include <nda/nda.hpp>
8using dcomplex = std::complex<double>;
9namespace nda {
10
11 // FIXME : to be replace by linalg
12 inline void Ainv_B(nda::matrix<dcomplex, nda::F_layout> A, nda::matrix_view<dcomplex, nda::F_layout> B) {
13 nda::vector<int> ipiv(A.extent(0)); //
14 lapack::getrf(A, ipiv); // Perform LU factorization of A
15 lapack::getrs(A, B, ipiv); // Solve AX = B (X = A^{-1} B)
16 }
17
18 // M(p[j], j) = 1 for all j
19 template <typename T> nda::matrix<T> make_matrix_from_permutation(std::vector<int> const &p) {
20 int N = int(p.size());
21 auto res = nda::matrix<T>::zeros(N, N);
22 for (int j = 0; j < N; ++j) res(p[j], j) = 1;
23 return res;
24 }
25
26 template <typename T> std::vector<T> flatten(const std::vector<std::vector<T>> &nested) {
27 std::vector<T> flat;
28 for (const auto &sub : nested) { flat.insert(flat.end(), sub.begin(), sub.end()); }
29 return flat;
30 }
31
32 template <typename T> bool is_diagonal(nda::matrix<T> const &M) {
33 auto dim = M.shape()[0];
34 for (size_t i = 0; i < dim; i++)
35 for (size_t j = i + 1; j < dim; j++)
36 if (abs(M(i, j)) > 1.e-14) return false;
37 return true;
38 }
39} // namespace nda
nda::matrix< T > make_matrix_from_permutation(std::vector< int > const &p)
Definition nda_supp.hpp:19
std::vector< T > flatten(const std::vector< std::vector< T > > &nested)
Definition nda_supp.hpp:26
bool is_diagonal(nda::matrix< T > const &M)
Definition nda_supp.hpp:32
void Ainv_B(nda::matrix< dcomplex, nda::F_layout > A, nda::matrix_view< dcomplex, nda::F_layout > B)
Definition nda_supp.hpp:12
std::complex< double > dcomplex
Definition nda_supp.hpp:8