From 12cb2db2ba2a6ca1e16ad6b791ac3c464ddbfe40 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Sat, 26 Oct 2013 13:49:24 +0200 Subject: [PATCH] gf: fix auto_assign for chained calls. - g[k_][om_] << expression was not working. now implemented like for std::vector adapter. --- test/triqs/gfs/block.cpp | 9 ++++++ triqs/gfs/gf.hpp | 69 ++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/test/triqs/gfs/block.cpp b/test/triqs/gfs/block.cpp index 5e5b9aa4..58ac7bac 100644 --- a/test/triqs/gfs/block.cpp +++ b/test/triqs/gfs/block.cpp @@ -61,6 +61,15 @@ int main() { for (auto & g : View) { g[0] = 20;} for (auto & g : B1) { g[0] = 20;} + // check chaining of clef + clef::placeholder<0> b_; + clef::placeholder<1> om_; + B1[b_][om_] << b_ / ( om_ + 2); + + // does not work + //std::vector> green_v; + //green_v.emplace_back({beta, Fermion}, {2,2} ); + } TRIQS_CATCH_AND_ABORT; } diff --git a/triqs/gfs/gf.hpp b/triqs/gfs/gf.hpp index 5adc9bb5..10930c1d 100644 --- a/triqs/gfs/gf.hpp +++ b/triqs/gfs/gf.hpp @@ -324,32 +324,53 @@ namespace triqs { namespace gfs { friend std::ostream & operator << (std::ostream & out, gf_impl const & x) { return out<<(IsView ? "gf_view": "gf");} friend std::ostream & triqs_nvl_formal_print(std::ostream & out, gf_impl const & x) { return out<<(IsView ? "gf_view": "gf");} - // Interaction with the CLEF library : auto assignment of the gf (gf(om_) << expression fills the functions by evaluation of expression) - template friend void triqs_clef_auto_assign(gf_impl &g, RHS const &rhs) { - // access to the data . Beware, we view it as a *matrix* NOT an array... (crucial for assignment to scalars !) - g.triqs_clef_auto_assign_impl(rhs, typename std::is_base_of::type()); - assign_from_expression(g.singularity(),rhs); - // if f is an expression, replace the placeholder with a simple tail. If f is a function callable on freq_infty, - // it uses the fact that tail_non_view_t can be casted into freq_infty - } + }; - // enable the writing g[om_] << .... also - template friend void triqs_clef_auto_assign_subscript (gf_impl & g, RHS rhs) { triqs_clef_auto_assign(g,rhs);} + // -------------------------Interaction with the CLEF library : auto assignement implemnetation-------------------------------------- + // auto assignment of the gf (gf(om_) << expression fills the functions by evaluation of expression) - private: - template void triqs_clef_auto_assign_impl(RHS const &rhs, std::integral_constant) { - for (auto const &w : this->mesh()) { - (*this)[w] = rhs(w); - } - //for (auto const & w: this->mesh()) (*this)[w] = rhs(typename B::mesh_t::mesh_point_t::cast_t(w)); - } - template void triqs_clef_auto_assign_impl(RHS const &rhs, std::integral_constant) { - for (auto const & w: this->mesh()) { - (*this)[w] = triqs::tuple::apply(rhs,w.components_tuple()); - } - //for (auto w: this->mesh()) triqs::tuple::apply(*this,w.components_tuple()) = triqs::tuple::apply(rhs,w.components_tuple()); - } - }; + template + void triqs_clef_auto_assign(gf_impl &g, RHS const &rhs) { + triqs_clef_auto_assign_impl(g, rhs, typename std::is_base_of>::type()); + assign_from_expression(g.singularity(), rhs); + // access to the data . Beware, we view it as a *matrix* NOT an array... (crucial for assignment to scalars !) + // if f is an expression, replace the placeholder with a simple tail. If f is a function callable on freq_infty, + // it uses the fact that tail_non_view_t can be casted into freq_infty + } + + // enable the writing g[om_] << .... also + template + void triqs_clef_auto_assign_subscript(gf_impl &g, RHS const &rhs) { + triqs_clef_auto_assign(g, rhs); + } + + template + void triqs_gf_clef_auto_assign_impl_aux_assign(G &&g, RHS &&rhs, std::integral_constant) { + std::forward(g) = std::forward(rhs); + } + + template + void triqs_gf_clef_auto_assign_impl_aux_assign(G &&g, clef::make_fun_impl &&rhs, std::integral_constant) { + triqs_clef_auto_assign_impl(std::forward(g), std::forward>(rhs), std::integral_constant()); + } + + template + void triqs_clef_auto_assign_impl(gf_impl &g, RHS const &rhs, + std::integral_constant) { + for (auto const &w : g.mesh()) { + triqs_gf_clef_auto_assign_impl_aux_assign(g[w], rhs(w), std::integral_constant()); + //(*this)[w] = rhs(w); + } + } + + template + void triqs_clef_auto_assign_impl(gf_impl &g, RHS const &rhs, + std::integral_constant) { + for (auto const &w : g.mesh()) { + triqs_gf_clef_auto_assign_impl_aux_assign(g[w], triqs::tuple::apply(rhs, w.components_tuple()), std::integral_constant()); + //(*this)[w] = triqs::tuple::apply(rhs, w.components_tuple()); + } + } // -------------------------The regular class of GF --------------------------------------------------------