3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-26 14:23:38 +01:00

gf curry: clean call for a single index

- if the index is not a tuple, make it a tuple...
- better API.
This commit is contained in:
Olivier Parcollet 2013-10-21 17:03:50 +02:00
parent e5648d2bfd
commit cbf2142af6
2 changed files with 10 additions and 6 deletions

View File

@ -37,7 +37,7 @@ try {
//std::cout << G_t_tau_N (0.1,0.2) << std::endl; //std::cout << G_t_tau_N (0.1,0.2) << std::endl;
auto G_w_wn_view = G_w_wn(); auto G_w_wn_view = G_w_wn();
auto G_w_wn_sl0_a = partial_eval<0>(G_w_wn(), std::make_tuple(size_t(8))); auto G_w_wn_sl0_a = partial_eval<0>(G_w_wn(), 8);
static_assert(std::is_same<typename std::remove_reference<decltype(G_w_wn_sl0_a.mesh())>::type, const gf_mesh<imfreq>>::value, "oops"); static_assert(std::is_same<typename std::remove_reference<decltype(G_w_wn_sl0_a.mesh())>::type, const gf_mesh<imfreq>>::value, "oops");
//auto G_w_wn_curry0_a = curry0(G_w_wn); //auto G_w_wn_curry0_a = curry0(G_w_wn);
//auto G_w_wn_sl0_a = slice_mesh0(G_w_wn(), 8); //auto G_w_wn_sl0_a = slice_mesh0(G_w_wn(), 8);
@ -72,17 +72,15 @@ try {
// test curry // test curry
std::cout << "curry no"<< G_w_wn.on_mesh(8,3) << std::endl ; std::cout << "curry no"<< G_w_wn.on_mesh(8,3) << std::endl ;
/*
auto G_w_wn_curry0 = curry<0>(G_w_wn); auto G_w_wn_curry0 = curry<0>(G_w_wn);
static_assert(std::is_same<typename std::remove_reference<decltype(G_w_wn_curry0[0].mesh())>::type, const gf_mesh<imfreq>>::value, "oops"); static_assert(std::is_same<typename std::remove_reference<decltype(G_w_wn_curry0[0].mesh())>::type, const gf_mesh<imfreq>>::value, "oops");
static_assert(std::is_same<typename std::remove_reference<decltype(G_w_wn_curry0.mesh())>::type, const gf_mesh<refreq>>::value, "oops"); static_assert(std::is_same<typename std::remove_reference<decltype(G_w_wn_curry0.mesh())>::type, const gf_mesh<refreq>>::value, "oops");
auto G_w_wn_curry1 = curry<1>(G_w_wn); auto G_w_wn_curry1 = curry<1>(G_w_wn);
auto G_w_wn_view2 = G_w_wn(); auto G_w_wn_view2 = G_w_wn();
std::cout << " curry "<<G_w_wn_curry0[8] << G_w_wn_curry0[8][3] << G_w_wn_view2.on_mesh(8,3) << G_w_wn_view2.on_mesh(8,3) <<std::endl ; std::cout << " curry "<<G_w_wn_curry0[8] << G_w_wn_curry0[8][3] << G_w_wn_view2.on_mesh(8,3) << G_w_wn_view2.on_mesh(8,3) <<std::endl ;
std::cout << " curry "<<G_w_wn_curry1[3][8] << std::endl; std::cout << " curry "<<G_w_wn_curry1[3][8] << std::endl;
std::cout << "G_w_wn_sl0_a [3]"<<G_w_wn_sl0_a[3] << std::endl ; std::cout << "G_w_wn_sl0_a [3]"<<G_w_wn_sl0_a[3] << std::endl ;
*/
// test hdf5 // test hdf5
H5::H5File file("gf_re_im_freq_time.h5", H5F_ACC_TRUNC ); H5::H5File file("gf_re_im_freq_time.h5", H5F_ACC_TRUNC );
h5_write(file, "g_t_tau", G_t_tau); h5_write(file, "g_t_tau", G_t_tau);

View File

@ -49,15 +49,21 @@ namespace triqs { namespace gfs {
template<typename M0, typename M1, typename ...M> auto rm_tuple_of_size_one(std::tuple<M0,M1,M...> const & t) DECL_AND_RETURN(t); template<typename M0, typename M1, typename ...M> auto rm_tuple_of_size_one(std::tuple<M0,M1,M...> const & t) DECL_AND_RETURN(t);
template<typename M> auto rm_tuple_of_size_one(std::tuple<M> const & t) DECL_AND_RETURN(std::get<0>(t)); template<typename M> auto rm_tuple_of_size_one(std::tuple<M> const & t) DECL_AND_RETURN(std::get<0>(t));
// as_tuple leaves a tuple intact and wrap everything else in a tuple...
template<typename T> std::tuple<T> as_tuple(T && x) { return std::tuple<T> {std::forward<T>(x)};}
template<typename ... T> std::tuple<T...> as_tuple(std::tuple<T...> && x) { return std::forward<T...>(x);}
template<typename ... T> std::tuple<T...> const & as_tuple(std::tuple<T...> const & x) { return x;}
template<typename ... T> std::tuple<T...> & as_tuple(std::tuple<T...> & x) { return x;}
template<int ... pos, typename Opt, typename Target, bool B, bool IsConst, typename IT, typename ... Ms> template<int ... pos, typename Opt, typename Target, bool B, bool IsConst, typename IT, typename ... Ms>
gf_view< typename cart_prod_impl< triqs::tuple::filter_out_t<std::tuple<Ms...>, pos...>>::type ,Target, Opt,IsConst> gf_view< typename cart_prod_impl< triqs::tuple::filter_out_t<std::tuple<Ms...>, pos...>>::type ,Target, Opt,IsConst>
partial_eval(gf_impl< cartesian_product<Ms...>, Target,Opt,B,IsConst> const & g, IT index) { partial_eval(gf_impl< cartesian_product<Ms...>, Target,Opt,B,IsConst> const & g, IT index) {
// meshes of the returned gf_view : just drop the mesh of the evaluated variables // meshes of the returned gf_view : just drop the mesh of the evaluated variables
auto meshes_tuple_partial = triqs::tuple::filter_out<pos...>(g.mesh().components()); auto meshes_tuple_partial = triqs::tuple::filter_out<pos...>(g.mesh().components());
// a view of the array of g, with the dimension sizeof...(Ms) // a view of the array of g, with the dimension sizeof...(Ms)
auto arr = reinterpret_linear_array(g.mesh(),g.data()); auto arr = reinterpret_linear_array(g.mesh(),g.data()); // NO the second () forces a view
// now rebuild a tuple of the size sizeof...(Ms), containing the indices and range at the position of evaluated variables. // 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<sizeof...(Ms),pos...>(index, arrays::range()); auto arr_args = triqs::tuple::inverse_filter<sizeof...(Ms),pos...>(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 // 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, arr_args);
// finally, we build the view on this data. // finally, we build the view on this data.