diff --git a/test/triqs/gfs/g_k_om2.cpp b/test/triqs/gfs/g_k_om2.cpp index f6589a8f..2139b3ff 100644 --- a/test/triqs/gfs/g_k_om2.cpp +++ b/test/triqs/gfs/g_k_om2.cpp @@ -2,16 +2,20 @@ #include #include + +// FAIRE make_value !! +// using namespace triqs::gfs; using namespace triqs::clef; using namespace triqs::arrays; using namespace triqs::lattice; template // requires ( is_function_on_mesh()) -auto sum(Function const &f, Mesh const &m)->decltype(f(typename Mesh::mesh_point_t{})) { +auto sum(Function const &f, Mesh const &m) ->decltype(make_matrix(0*f(*(m.begin())))) { //auto sum(Function const &f, Mesh const &m) { - auto res = decltype(f(typename Mesh::mesh_point_t{})) {}; - for (auto const &x : m) res = res + f(x); + //auto res = typename triqs::regular_type_if_exists_else_type::type (f(m.begin())); + auto res = make_matrix(0*f(*(m.begin()))); + for (auto const &x : m) res = res + f(x); return res; } namespace triqs { @@ -21,7 +25,7 @@ namespace triqs { } } -#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> " << (X) << std::endl << std::endl; +#define TEST(...) std::cout << BOOST_PP_STRINGIZE((__VA_ARGS__)) << " ---> " << (__VA_ARGS__) << std::endl << std::endl; int main() { try { @@ -41,16 +45,25 @@ int main() { G_k_iom(k_, w_) << 1 / (w_ - eps(k_)); - auto G_loc = gf{{beta,Fermion, 100}}; - //G_loc(w_) << sum(k_ >> G_k_iom(k_,w_), g_eps.mesh());//does not compile + auto G_loc = gf{{beta, Fermion, 100}, {1, 1}}; + + auto r = G_k_iom(k_t{0, 0}, matsubara_freq{0, beta, Fermion}); + + auto r5 = sum(k_ >> G_k_iom(k_,0), g_eps.mesh()); + G_loc(w_) << sum(k_ >> G_k_iom(k_,w_), g_eps.mesh()); TEST(G_loc(0)); auto G_k_tau = gf>{{{bz_, 20}, {beta, Fermion, 100}}, {1, 1}}; - //curry<1>(G_k_tau) [k_] << inverse_fourier(curry<1>(G_k_iom)[k_]); //does not compile + //auto r3 = partial_eval<0>(G_k_iom,0); + //auto r4 = partial_eval<0>(G_k_tau,0); + //auto gt = curry<0>(G_k_tau) [0]; + //auto gw = curry<0>(G_k_iom)[0]; + + //curry<0>(G_k_tau) [k_] << inverse_fourier(curry<0>(G_k_iom)[k_]); - //TEST(G_k_tau(0,0)); + //TEST(G_k_tau[{0,0}]); // hdf5 //H5::H5File file("ess_g_k_om.h5", H5F_ACC_TRUNC ); diff --git a/triqs/clef/clef.hpp b/triqs/clef/clef.hpp index e299e0c5..ff512ac5 100644 --- a/triqs/clef/clef.hpp +++ b/triqs/clef/clef.hpp @@ -170,8 +170,7 @@ namespace triqs { namespace clef { }; \ } \ template \ - typename std::enable_if::value, expr, expr_storage_t>>::type operator OP( \ - L&& l, R&& r) { \ + std14::enable_if_t::value, expr, expr_storage_t>> operator OP(L&& l, R&& r) { \ return {tags::TAG(), std::forward(l), std::forward(r)}; \ } \ template <> struct operation { \ @@ -198,7 +197,7 @@ namespace triqs { namespace clef { }; \ } \ template \ - typename std::enable_if::value, expr>>::type operator OP(L&& l) { \ + std14::enable_if_t::value, expr>> operator OP(L&& l) { \ return {tags::TAG(), std::forward(l)}; \ } \ template <> struct operation { \ @@ -223,11 +222,7 @@ namespace triqs { namespace clef { /* --------------------------------------------------------------------------------------------------- * Evaluation of the expression tree. * --------------------------------------------------------------------------------------------------- */ - //template struct _or; - //template struct _or : std::integral_constant::value>{}; - //template<> struct _or<> : std::false_type{}; - // just to try constexpr bool __or() { return false;} template constexpr bool __or(bool b, B... bs) { return b || __or(bs...); } @@ -283,8 +278,8 @@ namespace triqs { namespace clef { static constexpr bool is_lazy = __or(evaluator::is_lazy...); auto operator()(expr const& ex, Pairs const&... pairs) const { - auto eval_in_context = [&pairs](auto const& _child) { return eval(_child, pairs); }; - return triqs::tuple::apply_compose(op_dispatch{}, eval_in_context, ex.childs); + auto eval_in_context = [&pairs...](auto const& _child) { return eval(_child, pairs...); }; + return tuple::apply_compose(op_dispatch{}, eval_in_context, ex.childs); } }; #else @@ -299,8 +294,10 @@ namespace triqs { namespace clef { template struct evaluator_node_gal<2, expr, Pairs...> { static constexpr bool is_lazy = __or(evaluator::is_lazy...); - auto operator()(expr const& ex, Pairs const&... pairs) const DECL_AND_RETURN(op_dispatch { - }(eval(std::get<0>(ex.childs), pairs...), eval(std::get<1>(ex.childs), pairs...))); + decltype(auto) operator()(expr const &ex, + Pairs const &... pairs) const { + return op_dispatch {}(eval(std::get<0>(ex.childs), pairs...), eval(std::get<1>(ex.childs), pairs...)); + } }; // the general case for more than 2 nodes. I put 1 and 2 nodes apart, just because it is the most frequent diff --git a/triqs/gfs/bz.hpp b/triqs/gfs/bz.hpp index bb397348..7aa97206 100644 --- a/triqs/gfs/bz.hpp +++ b/triqs/gfs/bz.hpp @@ -50,10 +50,13 @@ namespace gfs { // simple evaluation : take the point on the grid... template <> struct evaluator_fnt_on_mesh { - lattice::k_t k; + size_t n; evaluator_fnt_on_mesh() = default; - template evaluator_fnt_on_mesh(MeshType const &m, lattice::k_t const &k_) { k = k_; } - template auto operator()(F const &f) const DECL_AND_RETURN(f(k)); + template evaluator_fnt_on_mesh(MeshType const &m, lattice::k_t const &k) { + n = m.locate_neighbours(k); // TO BE IMPROVED + } + //template auto operator()(F const &f) const DECL_AND_RETURN(f(k)); + template decltype(auto) operator()(F const &f) const { return f(n); } }; // ------------- evaluator ------------------- diff --git a/triqs/gfs/curry.hpp b/triqs/gfs/curry.hpp index c7e38798..8384aae4 100644 --- a/triqs/gfs/curry.hpp +++ b/triqs/gfs/curry.hpp @@ -44,7 +44,7 @@ namespace triqs { namespace gfs { template struct cart_prod_impl; template using cart_prod = typename cart_prod_impl::type; template struct cart_prod_impl> { using type = cartesian_product;}; - template struct cart_prod_impl> { typedef M type;}; //using type = M;}; + template struct cart_prod_impl> { using type = M;}; template auto rm_tuple_of_size_one(std::tuple const & t) DECL_AND_RETURN(t); template auto rm_tuple_of_size_one(std::tuple const & t) DECL_AND_RETURN(std::get<0>(t)); @@ -55,9 +55,9 @@ namespace triqs { namespace gfs { template std::tuple const & as_tuple(std::tuple const & x) { return x;} template std::tuple & as_tuple(std::tuple & x) { return x;} - template - gf_view< typename cart_prod_impl< triqs::tuple::filter_out_t, pos...>>::type ,Target, Opt,IsConst> - partial_eval(gf_impl< cartesian_product, Target,Opt,B,IsConst> const & g, IT index) { + template + gf_view, pos...>>, Target, Opt, IsConst> + partial_eval(gf_view, Target, Opt, IsConst> g, IT index) { // meshes of the returned gf_view : just drop the mesh of the evaluated variables auto meshes_tuple_partial = triqs::tuple::filter_out(g.mesh().components()); // a view of the array of g, with the dimension sizeof...(Ms) @@ -65,12 +65,24 @@ namespace triqs { namespace gfs { // now rebuild a tuple of the size sizeof...(Ms), containing the indices and range at the position of evaluated variables. auto arr_args = triqs::tuple::inverse_filter(as_tuple(index), arrays::range()); // from it, we make a slice of the array of g, corresponding to the data of the returned gf_view - auto arr2 = triqs::tuple::apply(arr, arr_args); + auto arr2 = triqs::tuple::apply(arr, std::tuple_cat(arr_args, std::make_tuple(arrays::ellipsis{}))); // finally, we build the view on this data. using r_t = gf_view< cart_prod< triqs::tuple::filter_out_t, pos...>> ,Target, Opt,IsConst>; return r_t{ rm_tuple_of_size_one(meshes_tuple_partial), arr2, typename r_t::singularity_non_view_t{}, typename r_t::symmetry_t{} }; } + template + gf_view, pos...>>, Target, Opt, false> + partial_eval(gf, Target, Opt> & g, IT index) { + return partial_eval(g(),index); + } + + template + gf_view, pos...>>, Target, Opt, true> + partial_eval(gf, Target, Opt> const& g, IT index) { + return partial_eval(g(),index); + } + /// --------------------------- curry --------------------------------- // curry<0>(g) returns : x-> y... -> g(x,y...) // curry<1>(g) returns : y-> x,z... -> g(x,y,z...) diff --git a/triqs/gfs/product.hpp b/triqs/gfs/product.hpp index 0f4f11cd..d08d7d46 100644 --- a/triqs/gfs/product.hpp +++ b/triqs/gfs/product.hpp @@ -92,7 +92,10 @@ namespace gfs { struct data_proxy, matrix_valued, Opt> : data_proxy_array, 3> {}; template struct data_proxy, tensor_valued, Opt> : data_proxy_array, R + 1> {}; - + + template + struct data_proxy, matrix_valued, Opt> : data_proxy_array {}; + /// --------------------------- evaluator --------------------------------- /** diff --git a/triqs/lattice/bz_mesh.cpp b/triqs/lattice/bz_mesh.cpp index 4996ef07..2ef1aad5 100644 --- a/triqs/lattice/bz_mesh.cpp +++ b/triqs/lattice/bz_mesh.cpp @@ -45,7 +45,7 @@ namespace lattice { } pos++; } - return pos; + return pos_min; } /// Write into HDF5 diff --git a/triqs/utility/tuple_tools.hpp b/triqs/utility/tuple_tools.hpp index d9deebe7..732c6e53 100644 --- a/triqs/utility/tuple_tools.hpp +++ b/triqs/utility/tuple_tools.hpp @@ -35,15 +35,15 @@ namespace std { template _triqs_reversed_tupleconst &> reverse(std::tuple const & x) { return {x};} template auto get(_triqs_reversed_tuple const & t) - DECL_AND_RETURN(std::get::type>::type>::value-1-pos>(t._x)); + DECL_AND_RETURN(std::get>::value-1-pos>(t._x)); template auto get(_triqs_reversed_tuple & t) - DECL_AND_RETURN(std::get::type>::type>::value-1-pos>(t._x)); + DECL_AND_RETURN(std::get>::value-1-pos>(t._x)); template auto get(_triqs_reversed_tuple && t) - DECL_AND_RETURN(std::get::type>::type>::value-1-pos>(move(t)._x)); + DECL_AND_RETURN(std::get>::value-1-pos>(move(t)._x)); - template class tuple_size<_triqs_reversed_tuple> : public tuple_size::type>::type>{}; + template class tuple_size<_triqs_reversed_tuple> : public tuple_size>{}; } @@ -177,7 +177,7 @@ namespace triqs { namespace tuple { }; template - auto apply_on_tuple (F && f,T1 && t1) DECL_AND_RETURN( apply_on_tuple_impl::type>::type>::value-1>()(std::forward(f),std::forward(t1))); + auto apply_on_tuple (F && f,T1 && t1) DECL_AND_RETURN( apply_on_tuple_impl>::value-1>()(std::forward(f),std::forward(t1))); /** * apply_on_zip(f, t1,t2) @@ -197,7 +197,7 @@ namespace triqs { namespace tuple { }; template - auto apply_on_zip (F && f,T1 && t1, T2 && t2) DECL_AND_RETURN( apply_on_zip_impl::type>::type>::value-1>()(std::forward(f),std::forward(t1),std::forward(t2))); + auto apply_on_zip (F && f,T1 && t1, T2 && t2) DECL_AND_RETURN( apply_on_zip_impl>::value-1>()(std::forward(f),std::forward(t1),std::forward(t2))); /** * apply_on_zip(f, t1,t2,t3)