33#include <itertools/itertools.hpp>
51 template <
typename Gf>
58 using nda::array_const_view;
78 template <
int N = 0,
typename G,
typename A =
typename G::const_view_type::data_t>
79 std::pair<typename A::regular_type, double>
fit_tail(G
const &g, A
const &known_moments = {})
83 return m.get_tail_fitter().template fit<N>(m, make_array_const_view(g.data()),
true, make_array_const_view(known_moments));
99 template <
int N = 0,
typename BG,
typename BA = std::vector<
typename BG::g_t::data_t::regular_type>>
100 std::pair<std::vector<typename BG::g_t::data_t::regular_type>,
double>
fit_tail(BG
const &bg, BA
const &known_moments = {})
103 double max_err = 0.0;
104 std::vector<typename BG::g_t::data_t::regular_type> tail_vec;
105 for (
auto [i, g_bl] : itertools::enumerate(bg)) {
107 tail_vec.emplace_back(std::move(tail));
108 max_err = std::max(err, max_err);
110 return std::make_pair(tail_vec, max_err);
126 template <
int N = 0,
typename G,
typename A =
typename G::data_t>
127 std::pair<typename A::regular_type, double>
fit_hermitian_tail(G
const &g, A
const &known_moments = {})
130 std::optional<long> inner_matrix_dim;
131 constexpr int rank = G::target_t::rank;
133 inner_matrix_dim = 1;
134 else if (rank == 2 && g.target_shape()[0] == g.target_shape()[1]) {
135 inner_matrix_dim = g.target_shape()[0];
140 return m.get_tail_fitter().template fit_hermitian<N>(m, make_array_const_view(g.data()),
true, make_array_const_view(known_moments),
160 template <
int N = 0,
typename BG,
typename A = std::vector<
typename BG::g_t::data_t::regular_type>>
161 std::pair<std::vector<typename BG::g_t::data_t::regular_type>,
double>
fit_hermitian_tail(BG
const &bg, A
const &known_moments = {})
164 double max_err = 0.0;
165 std::vector<typename BG::g_t::data_t::regular_type> tail_vec;
166 for (
auto [i, g_bl] : itertools::enumerate(bg)) {
169 tail_vec.emplace_back(std::move(tail));
170 max_err = std::max(err, max_err);
172 return std::make_pair(tail_vec, max_err);
176 template <
template <
typename,
typename,
typename...>
typename G,
typename V,
typename T,
typename... U>
177 auto fit_tail_no_normalize(G<V, T, U...>
const &g) {
178 return g.mesh().get_tail_fitter().template fit<0>(g.mesh(), make_array_const_view(g.data()),
false,
179 array_const_view<dcomplex, G<V, T, U...>::data_rank>{});
191 template <
int N = 0,
typename G>
auto make_zero_tail(G
const &g,
int n_moments = 10) {
193 auto sh = nda::rotate_index_view<N>(
make_const_view(g.data())).shape();
195 return nda::zeros<dcomplex>(sh);
216 template <
typename G,
typename... Args>
auto slice_target(G &&g, Args &&...args) {
217 return std::forward<G>(g).apply_on_data([&args...](
auto &&d) { return d(nda::ellipsis(), std::forward<Args>(args)...); });
236 auto r = std::forward<G>(g).apply_on_data([&args...](
auto &&d) { return d(nda::ellipsis(), std::forward<Args>(args)...); });
255 static_assert(std::is_same_v<typename std::decay_t<G>::target_t,
scalar_valued>,
256 "slice_target_to_scalar : the result is not a scalar valued function");
257 return std::forward<G>(g).apply_on_data([](
auto &&d) {
return nda::reinterpret_add_fast_dims_of_size_one<2>(d); });
273 auto mesh_lengths = stdutil::mpop<2>(a.indexmap().lengths());
274 nda::for_each(mesh_lengths, [&a](
auto &&...i) { nda::linalg::inv_in_place(make_matrix_view(a(i..., range::all, range::all))); });
311 template <
typename G>
315 return max_element(abs(
imag(g.data()))) <= tolerance;
320 template <
typename G>
324 return std::all_of(bg.begin(), bg.end(), [&](
auto &g) { return is_gf_real(g, tolerance); });
335 template <
typename G>
336 typename G::regular_type::real_t
real(G
const &g)
340 return {g.mesh(),
real(g.data())};
354 template <
typename G>
355 typename G::regular_type::real_t
imag(G
const &g)
359 return {g.mesh(),
imag(g.data())};
390 template <
typename G>
391 typename G::regular_type
conj(G
const &g)
394 return {g.mesh(),
conj(g.data())};
403 template <
typename A3,
typename T>
void _gf_data_mul_R(A3 &&a, matrix<T>
const &r) {
404 for (
int i = 0; i < first_dim(a); ++i) {
405 matrix_view<T> v = a(i, nda::range::all, nda::range::all);
412 template <
typename A3,
typename T>
void _gf_data_mul_L(matrix<T>
const &l, A3 &&a) {
413 for (
int i = 0; i < first_dim(a); ++i) {
414 matrix_view<T> v = a(i, nda::range::all, nda::range::all);
430 _gf_data_mul_R(g.
data(), r);
445 _gf_data_mul_L(l, g.
data());
455 template <
typename A,
typename B,
typename M>
void set_from_gf_data_mul_LR(A &a, M
const &l, B
const &b, M
const &r) {
456 auto tmp = matrix<typename M::value_type>(second_dim(b), second_dim(r));
457 auto _ = nda::range::all;
458 for (
int i = 0; i < first_dim(a); ++i) {
459 auto rhs_v = make_matrix_view(b(i, _, _));
460 auto lhs_v = make_matrix_view(a(i, _, _));
461 nda::blas::gemm(1, rhs_v, r, 0, tmp);
462 nda::blas::gemm(1, l, tmp, 0, lhs_v);
478 template <
typename G1,
typename G2,
typename M>
void set_from_L_G_R(G1 &g1, M
const &l, G2
const &g2, M
const &r) {
479 set_from_gf_data_mul_LR(g1.data(), l, g2.data(), r);
Provides the block Green's function container.
A read-only, non-owning view of a Green's function.
A mutable, non-owning view of a Green's function.
data_t & data() &
Get the data array view.
mesh_t const & mesh() const
Get the mesh of the Green's function.
The owning Green's function container.
data_t & data() &
Get the data array.
TRIQS exception hierarchy and related macros.
Provides a mutable non-owning view of a Green's function.
Provides the Green's function class.
void set_from_L_G_R(G1 &g1, M const &l, G2 const &g2, M const &r)
Set g1 = l * g2 * r at every mesh point (in place, optimized for speed).
void invert_in_place(gf_view< M, matrix_valued > g)
Invert, in place, the target matrix at each mesh point of a matrix-valued Green's function.
auto inverse(block_gf< M, T, L, A > &g)
Apply inverse block-wise to each block of the block Green's function.
auto reinterpret_scalar_valued_gf_as_matrix_valued(block_gf< M, T, L, A > &g)
Apply reinterpret_scalar_valued_gf_as_matrix_valued block-wise to each block of the block Green's fun...
auto map_block_gf(F &&f, G &&g)
Apply a callable to each block of a block Green's function.
G::regular_type::real_t real(G const &g)
Take the real part of a Green's function (no check), returning a new Green's function with a real tar...
bool is_gf_real(G const &g, double tolerance=1.e-13)
Test whether a Green's function is real up to a tolerance.
G::regular_type::real_t imag(G const &g)
Take the imaginary part of a Green's function (no check), returning a new Green's function with a rea...
G::regular_type conj(G const &g)
Complex-conjugate a Green's function, returning a new Green's function.
gf< M, matrix_valued > transpose(gf_view< M, matrix_valued > g)
Transpose the target matrix of a matrix-valued Green's function, returning a new Green's function.
auto slice_target(G &&g, Args &&...1)
Slice the target of a Green's function, keeping the result matrix- (or tensor-) valued.
auto make_const_view(Gf const &g)
Make a const view of a Green's function.
auto slice_target_to_scalar(G &&g, Args &&...1)
Slice the target of a matrix-valued Green's function down to a scalar-valued one.
std::pair< typename A::regular_type, double > fit_hermitian_tail(G const &g, A const &known_moments={})
Fit the high-frequency tail of a Green's function, imposing hermitian symmetry on the fitted moments.
auto make_zero_tail(G const &g, int n_moments=10)
Create a zero-initialized tail object for a given Green function object.
std::pair< typename A::regular_type, double > fit_tail(G const &g, A const &known_moments={})
Fit the high-frequency tail of a Green's function using a least-squares procedure.
constexpr bool is_block_gf_v
Trait to check whether a type is a block Green's function.
constexpr bool is_gf_v
Trait to check whether a type models the Green's function concept.
auto const & get_mesh(BG const &bg)
Get the mesh of a block Green's function, or its N-th component for a product mesh.
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.
Provides the function applying a callable block by block to a block Green's function.
Target type for a complex scalar-valued Green's function.