50 template <
typename F,
typename T>
auto _map(F &&f, std::vector<T>
const &V) {
51 std::vector<std::invoke_result_t<F, T>> res;
52 res.reserve(V.size());
53 for (
auto &x : V) res.emplace_back(f(x));
57 template <
typename F,
typename T>
auto _map(F &&f, std::vector<T> &V) {
58 std::vector<std::invoke_result_t<F, T>> res;
59 res.reserve(V.size());
60 for (
auto &x : V) res.emplace_back(f(x));
65 template <
typename F,
typename T>
auto _map(F &&f, std::vector<std::vector<T>>
const &V) {
66 std::vector<std::vector<std::invoke_result_t<F, T>>> res;
67 res.reserve(V.size());
68 for (
auto &x : V) res.push_back(_map(f, x));
72 template <
typename F,
typename T>
auto _map(F &&f, std::vector<std::vector<T>> &V) {
73 std::vector<std::vector<std::invoke_result_t<F, T>>> res;
74 res.reserve(V.size());
75 for (
auto &x : V) res.push_back(_map(f, x));
80 template <typename F, typename G, typename R = std::decay_t<std::invoke_result_t<F, typename std::decay_t<G>::g_t>>>
struct map;
83 template <
typename F,
typename G,
typename R>
struct map {
84 static auto invoke(F &&f, G &&g) {
return _map(std::forward<F>(f), std::forward<G>(g).
data()); }
88 template <
typename F,
typename G,
typename... T>
struct map<F, G,
gf<T...>> {
89 static auto invoke(F &&f, G &&g) {
90 if constexpr (std::remove_reference_t<G>::arity == 1)
91 return make_block_gf(g.block_names(), _map(std::forward<F>(f), std::forward<G>(g).
data()));
93 return make_block2_gf(g.block_names()[0], g.block_names()[1], _map(std::forward<F>(f), std::forward<G>(g).
data()));
97 template <
typename F,
typename G,
typename... T>
struct map<F, G, gf_view<T...>> {
98 static auto invoke(F &&f, G &&g) {
99 if constexpr (std::remove_reference_t<G>::arity == 1)
102 return make_block2_gf_view(g.block_names()[0], g.block_names()[1], _map(std::forward<F>(f), std::forward<G>(g).
data()));
106 template <
typename F,
typename G,
typename... T>
struct map<F, G, gf_const_view<T...>> {
107 static auto invoke(F &&f, G &&g) {
108 if constexpr (std::remove_reference_t<G>::arity == 1)
133 return impl::map<F, G>::invoke(std::forward<F>(f), std::forward<G>(g));
146 template <
typename F,
typename G>
150 return impl::map<F, G>::invoke(std::forward<F>(f), std::forward<G>(g));
data_t & data()
Direct access to the blocks.
Provides the free factory functions for block Green's functions.
gf(M, DataArray) -> gf< M, target_from_array< DataArray, n_variables< M > > >
Deduce a triqs::gfs::gf type from a mesh and a data array.
block_gf_const_view_of< G0 > make_block_gf_const_view(G0 &&g0, G &&...g)
Make a triqs::gfs::block_gf_const_view from a list of Green's function views (block names default to ...
block2_gf_const_view_of< Gf > make_block2_gf_const_view(std::vector< std::vector< Gf > > &v)
Make a triqs::gfs::block2_gf_const_view from a matrix of views (block names default to "0",...
block2_gf_view_of< Gf > make_block2_gf_view(std::vector< std::vector< Gf > > &v)
Make a triqs::gfs::block2_gf_view from a matrix of views (block names default to "0",...
block_gf_view_of< G0 > make_block_gf_view(G0 &&g0, G &&...g)
Make a triqs::gfs::block_gf_view from a list of Green's function views (block names default to "0",...
block2_gf< V, T, L > make_block2_gf(int n, int p, gf< V, T, L > const &g)
Make a triqs::gfs::block2_gf of n x p copies of a Green's function.
block_gf< V, T, L > make_block_gf(int n, gf< V, T, L > const &g)
Make a triqs::gfs::block_gf of n copies of a Green's function (block names default to "0",...
auto map(F &&f, G &&g)
Apply a callable to each block of a block Green's function (alias of triqs::gfs::map_block_gf).
auto map_block_gf(F &&f, G &&g)
Apply a callable to each block of a block Green's function.
constexpr bool is_block_gf_v
Trait to check whether a type is a block Green's function.