TRIQS/triqs_cthyb 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
array_suppl.hpp
1#pragma once
2#include <nda/nda.hpp>
3
4namespace triqs {
5 namespace arrays {
6
8
10 template <typename T> T vec_bdm_vec(vector<T> const &psi1, std::vector<matrix<T>> const &M, vector<T> const &psi2) {
11 T r = 0;
12 int block_start = 0; // the index in the full Hilbert space of the first vector in the current block
13 for (int bl = 0; bl < M.size(); ++bl) {
14 int d = M[bl].shape()[0];
15 if (d != M[bl].shape()[1]) TRIQS_RUNTIME_ERROR << "vec_bdm_vec: the matrix of block " << bl << " is not square !";
16 // not optimal: use psi1(range(block_start, block_start + a +1)) + BLAS if necessary FIXME
17 for (int a = 0; a < d; ++a) {
18 T tmp = 0;
19 for (int b = 0; b < d; ++b) tmp += M[bl](a, b) * psi2(block_start + b);
20 r += triqs::utility::conj(psi1(block_start + a)) * tmp;
21 }
22 block_start += d;
23 }
24 return r;
25 }
26
27 // Tr (A^* B) : Not optimal. Is blas possible ? FIXME
28 template <typename T> T dot_product(matrix<T> const &a, matrix<T> const &b) {
29 T r = 0;
30 int dim1 = a.shape()[0], dim2 = a.shape()[1];
31 if ((dim1 != b.shape()[1]) || (dim2 != b.shape()[0])) TRIQS_RUNTIME_ERROR << "dot_product of matrices : size mismatch";
32 for (int i = 0; i < dim1; ++i)
33 for (int j = 0; j < dim2; ++j) r += triqs::utility::conj(a(i, j)) * b(j, i);
34 return r;
35 }
36 }
37}