3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-23 21:03:45 +01:00

implement gf_const_view

This commit is contained in:
Olivier Parcollet 2013-10-18 13:39:00 +02:00
parent 445f7d42e1
commit 9edda8724d
15 changed files with 345 additions and 217 deletions

View File

@ -15,7 +15,7 @@ int main() {
// test hdf5
H5::H5File file("gf_scalar.h5", H5F_ACC_TRUNC);
h5_write(file, "g", G);
h5_write(file, "gm", reinterpret_scalar_valued_gf_as_matrix_valued(G()));
h5_write(file, "gm", reinterpret_scalar_valued_gf_as_matrix_valued(G));
}
TRIQS_CATCH_AND_ABORT;

View File

@ -43,21 +43,24 @@ namespace triqs { namespace gfs {
template<typename Target, typename Opt> struct h5_name<block_index,Target,Opt> { static std::string invoke(){ return "BlockGf";}};
template <typename Target, typename Opt, bool IsView> struct h5_rw<block_index,Target,Opt,IsView> {
template <typename Target, typename Opt> struct h5_rw<block_index,Target,Opt> {
static void write (h5::group gr, gf_impl<block_index,Target,Opt,IsView> const & g) {
static void write (h5::group gr, gf_const_view<block_index,Target,Opt> g) {
for (size_t i =0; i<g.mesh().size(); ++i) h5_write(gr,g.mesh().domain().names()[i],g._data[i]);
//h5_write(gr,"symmetry",g._symmetry);
}
static void read (h5::group gr, gf_impl<block_index,Target,Opt,IsView> & g) {
template<bool IsView>
static void read (h5::group gr, gf_impl<block_index,Target,Opt,IsView,false> &g) {
// does not work : need to read the block name and remake the mesh...
g._mesh = gf_mesh<block_index,Opt> (gr.get_all_subgroup_names());
g._data.resize(g._mesh.size());
//if (g._data.size() != g._mesh.size()) TRIQS_RUNTIME_ERROR << "h5 read block gf : number of block mismatch";
for (size_t i =0; i<g.mesh().size(); ++i) h5_read(gr,g.mesh().domain().names()[i],g._data[i]);
//h5_read(gr,"symmetry",g._symmetry);
}
};
};
/// --------------------------- data access ---------------------------------
@ -78,8 +81,69 @@ namespace triqs { namespace gfs {
} // gfs_implementation
// ------------------------------- aliases --------------------------------------------------
template<typename ... T> using block_gf = gf<block_index, gf<T...>>;
template<typename ... T> using block_gf_view = gf_view<block_index, gf<T...>>;
template<typename ... T> using block_gf_const_view = gf_const_view<block_index, gf<T...>>;
// ------------------------------- Free Factories for regular type --------------------------------------------------
// from a number and a gf to be copied
template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(int n, gf<Variable, Target, Opt> const & g) {
auto V = std::vector<gf<Variable, Target, Opt>>{};
for (int i = 0; i < n; ++i) V.push_back(g);
return {{n}, std::move(V), nothing{}, nothing{}};
}
// from a vector of gf (moving directly)
template <typename Variable, typename Target, typename Opt, typename GF2>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<gf<Variable, Target, Opt>> &&V) {
return {{int(V.size())}, std::move(V), nothing{}, nothing{}};
}
// from a vector of gf : generalized to have a different type of gf in the vector (e.g. views...)
template <typename Variable, typename Target, typename Opt, typename GF2>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<GF2> const &V) {
auto V2 = std::vector<gf<Variable, Target, Opt>>{};
for (auto const &g : V) V2.push_back(g);
return {{int(V.size())}, std::move(V2), nothing{}, nothing{}};
}
// from a init list of GF with the correct type
template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(std::initializer_list<gf<Variable, Target, Opt>> const &V) {
return {{int(V.size())}, V, nothing{}, nothing{}};
}
// from vector<string> and a gf to be copied
template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names, gf<Variable, Target, Opt> const &g) {
auto V = std::vector<gf<Variable, Target, Opt>>{};
for (int i = 0; i < block_names.size(); ++i) V.push_back(g);
return {{block_names}, std::move(V), nothing{}, nothing{}};
}
// from vector<string>, vector<gf>
template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names,
std::vector<gf<Variable, Target, Opt>> V) {
if (block_names.size() != V.size())
TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, vector<gf>) : the two vectors do not have the same size !";
return {{block_names}, std::move(V), nothing{}, nothing{}};
}
// from vector<string>, init_list<GF>
template <typename Variable, typename Target, typename Opt>
block_gf<Variable, Target, Opt> make_block_gf(std::vector<std::string> const &block_names,
std::initializer_list<gf<Variable, Target, Opt>> const &V) {
if (block_names.size() != V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, init_list) : size mismatch !";
return {{block_names}, V, nothing{}, nothing{}};
}
// ------------------------------- Free Factories for view type --------------------------------------------------
template<typename G0, typename ... G>
gf_view<block_index, typename std::remove_reference<G0>::type::view_type> make_block_gf_view(G0 && g0, G && ... g) {
auto V = std::vector<typename std::remove_reference<G0>::type::view_type>{std::forward<G0>(g0), std::forward<G>(g)...};
@ -87,54 +151,6 @@ namespace triqs { namespace gfs {
//return { gf_mesh<block_index, Opt> {int(V.size())}, std::move(V), nothing{}, nothing{} } ;
}
// from a number and a gf to be copied
template<typename Variable, typename Target, typename Opt>
gf<block_index,gf<Variable,Target,Opt>>
make_block_gf(int n, gf<Variable,Target,Opt> g) {
auto V = std::vector<gf<Variable,Target,Opt>>{};
for (int i =0; i<n; ++i) V.push_back(g);
return { {n}, std::move(V), nothing{}, nothing{}};
}
// from a vector of gf (moving directly)
template<typename Variable, typename Target, typename Opt, typename GF2>
gf<block_index,gf<Variable,Target,Opt>>
make_block_gf(std::vector<gf<Variable,Target,Opt>> && V) {
return { {int(V.size())}, std::move(V), nothing{}, nothing{}};
}
// from a vector of gf : generalized to have a different type of gf in the vector (e.g. views...)
template<typename Variable, typename Target, typename Opt, typename GF2>
gf<block_index,gf<Variable,Target,Opt>>
make_block_gf(std::vector<GF2> const & V) {
auto V2 = std::vector<gf<Variable,Target,Opt>>{};
for (auto const & g : V) V2.push_back(g);
return { {int(V.size())}, std::move(V2), nothing{}, nothing{}};
}
// from a init list of GF with the correct type
template<typename Variable, typename Target, typename Opt>
gf<block_index,gf<Variable,Target,Opt>>
make_block_gf(std::initializer_list<gf<Variable,Target,Opt>> const & V) { return { {int(V.size())}, V, nothing{}, nothing{}} ; }
// from vector<string>, vector<gf>
template<typename Variable, typename Target, typename Opt>
gf<block_index,gf<Variable,Target,Opt>>
make_block_gf(std::vector<std::string> const & block_names, std::vector<gf<Variable,Target,Opt>> V) {
if (block_names.size()!=V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, vector<gf>) : the two vectors do not have the same size !";
return { {block_names}, std::move(V), nothing{}, nothing{}};
}
// from vector<string>, init_list<GF>
template<typename Variable, typename Target, typename Opt>
gf<block_index,gf<Variable,Target,Opt>>
make_block_gf(std::vector<std::string> const & block_names, std::initializer_list<gf<Variable,Target,Opt>> const & V) {
if (block_names.size()!=V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector<string>, init_list) : size mismatch !";
return { {block_names}, V, nothing{}, nothing{}};
}
// ------------------------------- Free Factories for view type --------------------------------------------------
template<typename GF, typename GF2>
gf_view<block_index,GF>
make_block_gf_view_from_vector (std::vector<GF2> V) { return { {int(V.size())}, std::move(V), nothing{}, nothing{}} ; }
@ -145,8 +161,6 @@ namespace triqs { namespace gfs {
template<typename T> size_t n_blocks (gf<block_index,T> const & g) { return g.mesh().size();}
template<typename T> size_t n_blocks (gf_view<block_index,T> const & g) { return g.mesh().size();}
template<typename T> using block_gf = gf<block_index, gf<T>>;
// an iterator over the block
template<typename Target, typename Opt>
class block_gf_iterator :
@ -165,11 +179,11 @@ namespace triqs { namespace gfs {
bool at_end() const { return mesh_it.at_end();}
};
template<typename Target, typename Opt, bool B>
block_gf_iterator<Target,Opt> begin(gf_impl<block_index,Target,Opt,B> const & bgf) { return {bgf,false};}
template<typename Target, typename Opt, bool B, bool C>
block_gf_iterator<Target,Opt> begin(gf_impl<block_index,Target,Opt,B,C> const & bgf) { return {bgf,false};}
template<typename Target, typename Opt, bool B>
block_gf_iterator<Target,Opt> end(gf_impl<block_index,Target,Opt,B> const & bgf) { return {bgf,true};}
template<typename Target, typename Opt, bool B, bool C>
block_gf_iterator<Target,Opt> end(gf_impl<block_index,Target,Opt,B,C> const & bgf) { return {bgf,true};}
}}
#endif

View File

@ -49,9 +49,9 @@ 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 M> auto rm_tuple_of_size_one(std::tuple<M> const & t) DECL_AND_RETURN(std::get<0>(t));
template<int ... pos, typename Opt, typename Target, bool B, typename IT, typename ... Ms>
gf_view< typename cart_prod_impl< triqs::tuple::filter_out_t<std::tuple<Ms...>, pos...>>::type ,Target, Opt>
partial_eval(gf_impl< cartesian_product<Ms...>, Target,Opt,B> const & g, IT index) {
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>
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
auto meshes_tuple_partial = triqs::tuple::filter_out<pos...>(g.mesh().components());
// a view of the array of g, with the dimension sizeof...(Ms)
@ -61,7 +61,7 @@ namespace triqs { namespace gfs {
// 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);
// finally, we build the view on this data.
using r_t = gf_view< cart_prod< triqs::tuple::filter_out_t<std::tuple<Ms...>, pos...>> ,Target, Opt>;
using r_t = gf_view< cart_prod< triqs::tuple::filter_out_t<std::tuple<Ms...>, 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{} };
}
@ -78,18 +78,23 @@ namespace triqs { namespace gfs {
};
// curry function ...
template<int ... pos, typename Target, typename Opt, bool B, typename ... Ms>
gf_view<cart_prod< triqs::tuple::filter_t<std::tuple<Ms...>,pos...> >,
lambda_valued<curry_polymorphic_lambda<gf_view<cartesian_product<Ms...>, Target,Opt>,pos...>>,
Opt>
curry (gf_impl<cartesian_product<Ms...>, Target,Opt,B> const & g) {
template <int... pos, typename Target, typename Opt, bool IsConst, typename... Ms>
gf_view<cart_prod<triqs::tuple::filter_t<std::tuple<Ms...>, pos...>>,
lambda_valued<curry_polymorphic_lambda<gf_view<cartesian_product<Ms...>, Target, Opt,IsConst>, pos...>>, Opt, IsConst>
curry(gf_view<cartesian_product<Ms...>, Target, Opt, IsConst> g) {
// pick up the meshed corresponding to the curryed variables
auto meshes_tuple = triqs::tuple::filter<pos...>(g.mesh().components());
// building the view
return {rm_tuple_of_size_one(meshes_tuple),curry_polymorphic_lambda<gf_view<cartesian_product<Ms...>, Target,Opt>, pos ...>{g}, nothing(), nothing()};
return {rm_tuple_of_size_one(meshes_tuple),curry_polymorphic_lambda<gf_view<cartesian_product<Ms...>, Target,Opt,IsConst>, pos ...>{g}, nothing(), nothing()};
//using m_t = gf_mesh< cart_prod< triqs::tuple::filter_t<std::tuple<Ms...>,pos...>>>;
//return {triqs::tuple::apply_construct<m_t>(meshes_tuple),curry_polymorphic_lambda<gf_view<cartesian_product<Ms...>, Target,Opt>, pos ...>{g}, nothing(), nothing()};
};
template <int... pos, typename Target, typename Opt, typename... Ms>
auto curry(gf<cartesian_product<Ms...>, Target, Opt> & g) DECL_AND_RETURN(curry<pos...>(g()));
template <int... pos, typename Target, typename Opt, typename... Ms>
auto curry(gf<cartesian_product<Ms...>, Target, Opt> const & g) DECL_AND_RETURN(curry<pos...>(g()));
} // gf_implementation
using gfs_implementation::partial_eval;

View File

@ -32,24 +32,29 @@ namespace triqs { namespace gfs {
template<typename T, int R> struct data_proxy_array {
/// The storage
typedef arrays::array<T,R> storage_t;
typedef typename storage_t::view_type storage_view_t;
typedef arrays::array<T, R> storage_t;
typedef typename storage_t::view_type storage_view_t;
typedef typename storage_t::const_view_type storage_const_view_t;
/// The data access
auto operator()(storage_t& data, long i) const DECL_AND_RETURN(arrays::make_tensor_proxy(data, i));
auto operator()(storage_t const& data, long i) const DECL_AND_RETURN(arrays::make_const_tensor_proxy(data, i));
auto operator()(storage_view_t& data, long i) const DECL_AND_RETURN(arrays::make_tensor_proxy(data, i));
auto operator()(storage_view_t const& data, long i) const DECL_AND_RETURN(arrays::make_const_tensor_proxy(data, i));
auto operator()(storage_const_view_t& data, long i) const DECL_AND_RETURN(arrays::make_const_tensor_proxy(data, i));
auto operator()(storage_const_view_t const& data, long i) const DECL_AND_RETURN(arrays::make_const_tensor_proxy(data, i));
#ifdef TRIQS_GF_DATA_PROXIES_WITH_SIMPLE_VIEWS
auto operator()(storage_t & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_t const & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_view_t & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_view_t const & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_const_view_t & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_const_view_t const & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
#endif
template<typename S, typename RHS> static void assign_to_scalar (S & data, RHS && rhs) { data() = std::forward<RHS>(rhs);}
template<typename RHS> static void rebind (storage_view_t & data, RHS && rhs) { data.rebind(rhs.data()); }
template <typename ST, typename RHS> static void rebind(ST& data, RHS&& rhs) { data.rebind(rhs.data()); }
};
//---------------------------- 3d array : returns matrices in this case ! ----------------------------------
@ -58,15 +63,18 @@ namespace triqs { namespace gfs {
/// The storage
typedef arrays::array<T,3> storage_t;
typedef typename storage_t::view_type storage_view_t;
typedef typename storage_t::const_view_type storage_const_view_t;
/// The data access
auto operator()(storage_t& data, long i) const DECL_AND_RETURN(arrays::make_matrix_proxy(data, i));
auto operator()(storage_t const& data, long i) const DECL_AND_RETURN(arrays::make_const_matrix_proxy(data, i));
auto operator()(storage_view_t& data, long i) const DECL_AND_RETURN(arrays::make_matrix_proxy(data, i));
auto operator()(storage_view_t const& data, long i) const DECL_AND_RETURN(arrays::make_const_matrix_proxy(data, i));
auto operator()(storage_const_view_t& data, long i) const DECL_AND_RETURN(arrays::make_const_matrix_proxy(data, i));
auto operator()(storage_const_view_t const& data, long i) const DECL_AND_RETURN(arrays::make_const_matrix_proxy(data, i));
#ifdef TRIQS_DATA_PROXIES_OLD_MATRIX_VIEW_PROXY
arrays::matrix_view_proxy<storage_t,0> operator()(storage_t & data, size_t i) const { return arrays::matrix_view_proxy<storage_t,0>(data,i); }
arrays::matrix_view_proxy<storage_t,0> operator()(storage_t & data, size_t i) const { return arrays::matrix_view_proxy<storage_t,0>(data,i); }
arrays::const_matrix_view_proxy<storage_t,0> operator()(storage_t const & data, size_t i) const { return arrays::const_matrix_view_proxy<storage_t,0>(data,i); }
arrays::matrix_view_proxy<storage_view_t,0> operator()(storage_view_t & data, size_t i) const { return arrays::matrix_view_proxy<storage_view_t,0>(data,i); }
arrays::const_matrix_view_proxy<storage_view_t,0> operator()(storage_view_t const & data, size_t i) const { return arrays::const_matrix_view_proxy<storage_view_t,0>(data,i); }
@ -78,10 +86,13 @@ namespace triqs { namespace gfs {
auto operator()(storage_view_t & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_view_t const & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_const_view_t & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
auto operator()(storage_const_view_t const & data, size_t i) const DECL_AND_RETURN(data(i,arrays::ellipsis()));
#endif
template<typename S, typename RHS> static void assign_to_scalar (S & data, RHS && rhs) { data() = std::forward<RHS>(rhs);}
template<typename RHS> static void rebind (storage_view_t & data, RHS && rhs) { data.rebind(rhs.data()); }
template <typename S, typename RHS> static void assign_to_scalar(S& data, RHS&& rhs) { data() = std::forward<RHS>(rhs); }
template <typename ST, typename RHS> static void rebind(ST& data, RHS&& rhs) { data.rebind(rhs.data()); }
};
//---------------------------- 1d array ----------------------------------
@ -90,34 +101,57 @@ namespace triqs { namespace gfs {
/// The storage
typedef arrays::array<T,1> storage_t;
typedef typename storage_t::view_type storage_view_t;
typedef typename storage_t::const_view_type storage_const_view_t;
/// The data access
auto operator()(storage_t & data,size_t i) const -> decltype(data(i)) { return data(i);}
auto operator()(storage_t const & data,size_t i) const -> decltype(data(i)) { return data(i);}
auto operator()(storage_view_t & data,size_t i) const -> decltype(data(i)) { return data(i);}
auto operator()(storage_view_t const & data,size_t i) const -> decltype(data(i)) { return data(i);}
auto operator()(storage_const_view_t & data,size_t i) const -> decltype(data(i)) { return data(i);}
auto operator()(storage_const_view_t const & data,size_t i) const -> decltype(data(i)) { return data(i);}
template<typename S, typename RHS> static void assign_to_scalar (S & data, RHS && rhs) { data() = std::forward<RHS>(rhs);}
template<typename RHS> static void rebind (storage_view_t & data, RHS && rhs) { data.rebind(rhs.data()); }
template <typename ST, typename RHS> static void rebind(ST& data, RHS&& rhs) { data.rebind(rhs.data()); }
};
//---------------------------- vector ----------------------------------
template<typename V> struct view_proxy : public V {
view_proxy() : V(typename V::regular_type()) {}
view_proxy(V const &v) : V(v){};
view_proxy(view_proxy const & p) : V(p) {};
template<typename ... Args> explicit view_proxy(Args && ... args) : V (std::forward<Args>(args)...){}
view_proxy & operator = ( view_proxy const & cp ) { this->rebind(cp); return *this;}
view_proxy & operator = ( V const & v ) { this->rebind(v); return *this;}
using V::operator=;
//template<typename X> view_proxy & operator = (X && x) { V::operator=( std::forward<X>(x) ); return *this;}
};
template<typename T> struct data_proxy_vector {
typedef typename T::view_type Tv;
typedef typename T::const_view_type Tcv;
/// The storage
typedef std::vector<T> storage_t;
typedef std::vector<Tv> storage_view_t;
typedef std::vector<view_proxy<Tv>> storage_view_t;
typedef std::vector<view_proxy<Tcv>> storage_const_view_t;
/// The data access
T & operator()(storage_t & data, size_t i) { return data[i];}
T & operator()(storage_t & data, size_t i) { return data[i];}
T const & operator()(storage_t const & data, size_t i) const { return data[i];}
Tv & operator()(storage_view_t & data, size_t i) { return data[i];}
Tv const & operator()(storage_view_t const & data, size_t i) const { return data[i];}
Tcv & operator()(storage_const_view_t & data, size_t i) { return data[i];}
Tcv const & operator()(storage_const_view_t const & data, size_t i) const { return data[i];}
/*Tv operator()(storage_view_t & data, size_t i) const { return data[i];}
Tv operator()(storage_view_t const & data, size_t i) const { return data[i];}
Tcv operator()(storage_const_view_t & data, size_t i) const { return data[i];}
Tcv operator()(storage_const_view_t const & data, size_t i) const { return data[i];}
*/
template<typename S, typename RHS> static void assign_to_scalar (S & data, RHS && rhs) {for (size_t i =0; i<data.size(); ++i) data[i] = rhs;}
template<typename RHS> static void rebind (storage_view_t & data, RHS && rhs) { data.clear(); for (auto & x : rhs.data()) data.push_back(x);}
template <typename ST, typename RHS> static void rebind(ST& data, RHS&& rhs) { data.clear(); for (auto & x : rhs.data()) data.push_back(x);}
};
//---------------------------- lambda ----------------------------------
@ -127,13 +161,14 @@ namespace triqs { namespace gfs {
/// The storage
typedef F storage_t;
typedef F storage_view_t;
typedef F storage_const_view_t;
/// The data access
auto operator()(storage_t & data, size_t i) DECL_AND_RETURN( data(i));
auto operator()(storage_t const & data, size_t i) const DECL_AND_RETURN( data(i));
template<typename S, typename RHS> static void assign_to_scalar (S & data, RHS && rhs) = delete;
template<typename RHS> static void rebind (storage_view_t & data, RHS && rhs) = delete;// { data = std::forward<RHS>(rhs);}
template <typename ST, typename RHS> static void rebind(ST& data, RHS&& rhs) = delete;
};

View File

@ -33,12 +33,23 @@ namespace triqs { namespace gfs {
using utility::factory;
using arrays::make_shape;
template<typename T> long get_shape(std::vector<T> const & x) {return x.size();}
template <typename T> long get_shape(std::vector<T> const &x) { return x.size(); }
template<typename Variable, typename Opt=void> struct gf_mesh;
template<typename Variable, typename Target=matrix_valued, typename Opt=void> class gf; // the regular type
template<typename Variable, typename Target=matrix_valued, typename Opt=void> class gf_view; // the view type
template<typename Variable, typename Target, typename Opt, bool IsView> class gf_impl;
// the gf mesh
template <typename Variable, typename Opt = void> struct gf_mesh;
// The regular type
template <typename Variable, typename Target = matrix_valued, typename Opt = void> class gf;
// The view type
template <typename Variable, typename Target = matrix_valued, typename Opt = void, bool IsConst = false> class gf_view;
// The const view type
template <typename Variable, typename Target = matrix_valued, typename Opt = void>
using gf_const_view = gf_view<Variable, Target, Opt, true>;
// the implementation class
template<typename Variable, typename Target, typename Opt, bool IsView, bool IsConst> class gf_impl;
// various implementation traits
namespace gfs_implementation { // never use using of this...
@ -63,23 +74,24 @@ namespace triqs { namespace gfs {
template <typename Variable, typename Target, typename Opt> struct h5_name; // value is a const char *
template<typename Variable, typename Opt> struct h5_name<Variable,scalar_valued,Opt> { static std::string invoke(){ return h5_name<Variable,matrix_valued,Opt>::invoke() + "_s";}};
// the h5 write and read of gf members, so that we can specialize it e.g. for block gf
template <typename Variable, typename Target, typename Opt, bool IsView> struct h5_rw {
static void write (h5::group gr, gf_impl<Variable,Target,Opt,IsView> const & g) {
// the h5 write and read of gf members, so that we can specialize it e.g. for block gf
template <typename Variable, typename Target, typename Opt> struct h5_rw {
static void write (h5::group gr, gf_const_view<Variable,Target,Opt> g) {
h5_write(gr,"data",g._data);
h5_write(gr,"singularity",g._singularity);
h5_write(gr,"mesh",g._mesh);
h5_write(gr,"symmetry",g._symmetry);
}
static void read (h5::group gr, gf_impl<Variable,Target,Opt,IsView> & g) {
h5_read(gr,"data",g._data);
h5_read(gr,"singularity",g._singularity);
h5_read(gr,"mesh",g._mesh);
h5_read(gr,"symmetry",g._symmetry);
}
template<bool B>
static void read (h5::group gr, gf_impl<Variable,Target,Opt,B,false> & g) {
h5_read(gr,"data",g._data);
h5_read(gr,"singularity",g._singularity);
h5_read(gr,"mesh",g._mesh);
h5_read(gr,"symmetry",g._symmetry);
}
};
// factories regroup all factories (constructors..) for all types of gf.
@ -112,7 +124,7 @@ namespace triqs { namespace gfs {
static typename gf_t::singularity_t make_singularity(mesh_t const & m, target_shape_t shape) { return typename gf_t::singularity_t(shape); }
};
template<typename Var, typename Opt> struct factories<Var,scalar_valued,Opt> {
typedef gf<Var,scalar_valued,Opt> gf_t;
struct target_shape_t {};
@ -149,10 +161,13 @@ namespace triqs { namespace gfs {
// ---------------------- implementation --------------------------------
/// A common implementation class for gf and gf_view. They will only redefine contructor and = ...
template<typename Variable, typename Target, typename Opt, bool IsView> class gf_impl :
template<typename Variable, typename Target, typename Opt, bool IsView, bool IsConst> class gf_impl :
TRIQS_CONCEPT_TAG_NAME(ImmutableGreenFunction){
static_assert(!( !IsView && IsConst), "Internal error");
public :
typedef gf_view<Variable,Target,Opt> view_type;
typedef gf_view<Variable,Target,Opt> mutable_view_type;
typedef gf_const_view<Variable,Target,Opt> const_view_type;
typedef typename std::conditional <IsConst, const_view_type, mutable_view_type>::type view_type;
typedef gf<Variable,Target,Opt> regular_type;
typedef Variable variable_t;
@ -169,7 +184,9 @@ namespace triqs { namespace gfs {
typedef gfs_implementation::data_proxy<Variable,Target,Opt> data_proxy_t;
typedef typename data_proxy_t::storage_t data_regular_t;
typedef typename data_proxy_t::storage_view_t data_view_t;
typedef typename std::conditional<IsView, data_view_t, data_regular_t>::type data_t;
typedef typename data_proxy_t::storage_const_view_t data_const_view_t;
typedef typename std::conditional<IsView, typename std::conditional<IsConst, data_const_view_t, data_view_t>::type,
data_regular_t>::type data_t;
typedef typename gfs_implementation::singularity<Variable,Target,Opt>::type singularity_non_view_t;
typedef typename view_type_if_exists_else_type<singularity_non_view_t>::type singularity_view_t;
@ -207,8 +224,9 @@ namespace triqs { namespace gfs {
protected:
gf_impl(gf_impl<Variable,Target,Opt,!IsView> const & x): _mesh(x.mesh()), _data(factory<data_t>(x.data())),
_singularity(factory<singularity_t>(x.singularity())), _symmetry(x.symmetry()), _evaluator(x.get_evaluator()){}
template<typename G>
gf_impl(G && x, bool): _mesh(x.mesh()), _data(factory<data_t>(x.data())),
_singularity(factory<singularity_t>(x.singularity())), _symmetry(x.symmetry()), _evaluator(x.get_evaluator()){}
template<typename M, typename D, typename S, typename SY, typename EV>
gf_impl(M && m, D && dat, S && sing, SY && sy, EV && ev) :
@ -225,7 +243,8 @@ namespace triqs { namespace gfs {
// ------------- All the call operators -----------------------------
// First, a simple () returns a view, like for an array...
view_type operator()() const { return *this;}
const_view_type operator()() const { return *this;}
view_type operator()() { return *this; }
/// Calls are (perfectly) forwarded to the evaluator::operator(), except mesh_point_t and when
/// there is at least one lazy argument ...
@ -241,7 +260,6 @@ namespace triqs { namespace gfs {
>::type // end of add_Const
operator() (Arg0&& arg0, Args&&... args) const { return _evaluator(this,std::forward<Arg0>( arg0), std::forward<Args>(args)...); }
// WHY SEPARATE ARg0 ?
template<typename Arg0, typename ...Args>
typename clef::_result_of::make_expr_call<gf_impl &,Arg0, Args...>::type
operator()(Arg0 &&arg0, Args&&... args) & {
@ -260,20 +278,6 @@ namespace triqs { namespace gfs {
return clef::make_expr_call(std::move(*this),std::forward<Arg0>(arg0), std::forward<Args>(args)...);
}
/*
// on mesh component for composite meshes
// enable iif the first arg is a mesh_point_t for the first component of the mesh_t
template<typename Arg0, typename ... Args, bool MeshIsComposite = std::is_base_of<tag::composite, mesh_t>::value >
typename std::enable_if< MeshIsComposite && std::is_base_of< tag::mesh_point, Arg0>::value, r_type>::type
operator() (Arg0 const & arg0, Args const & ... args)
{ return _data_proxy(_data, _mesh.mesh_pt_components_to_linear(arg0, args...));}
template<typename Arg0, typename ... Args, bool MeshIsComposite = std::is_base_of<tag::composite, mesh_t>::value >
typename std::enable_if< MeshIsComposite && std::is_base_of< tag::mesh_point, Arg0>::value, cr_type>::type
operator() (Arg0 const & arg0, Args const & ... args) const
{ return _data_proxy(_data, _mesh.mesh_pt_components_to_linear(arg0, args...));}
*/
//// [] and access to the grid point
typedef typename std::result_of<data_proxy_t(data_t &,size_t)>::type r_type;
typedef typename std::result_of<data_proxy_t(data_t const &,size_t)>::type cr_type;
@ -325,13 +329,13 @@ namespace triqs { namespace gfs {
friend std::string get_triqs_hdf5_data_scheme(gf_impl const & g) { return "Gf" + gfs_implementation::h5_name<Variable,Target,Opt>::invoke();}
friend class gfs_implementation::h5_rw<Variable,Target,Opt,IsView>;
friend class gfs_implementation::h5_rw<Variable,Target,Opt>;
/// Write into HDF5
friend void h5_write (h5::group fg, std::string subgroup_name, gf_impl const & g) {
auto gr = fg.create_group(subgroup_name);
gr.write_triqs_hdf5_data_scheme(g);
gfs_implementation::h5_rw<Variable,Target,Opt,IsView>::write(gr, g);
gfs_implementation::h5_rw<Variable,Target,Opt>::write(gr, g);
}
/// Read from HDF5
@ -342,7 +346,7 @@ namespace triqs { namespace gfs {
auto tag_expected= get_triqs_hdf5_data_scheme(g);
if (tag_file != tag_expected)
TRIQS_RUNTIME_ERROR<< "h5_read : mismatch of the tag TRIQS_HDF5_data_scheme tag in the h5 group : found "<<tag_file << " while I expected "<< tag_expected;
gfs_implementation::h5_rw<Variable,Target,Opt,IsView>::read(gr, g);
gfs_implementation::h5_rw<Variable,Target,Opt>::read(gr, g);
}
//----------------------------- BOOST Serialization -----------------------------
@ -360,7 +364,7 @@ namespace triqs { namespace gfs {
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<typename RHS> friend void triqs_clef_auto_assign (gf_impl & g, RHS const & rhs) {
template <typename RHS> 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<tag::composite,mesh_t>::type());
assign_from_expression(g.singularity(),rhs);
@ -376,12 +380,9 @@ namespace triqs { namespace gfs {
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<typename RHS> void triqs_clef_auto_assign_impl (RHS const & rhs, std::integral_constant<bool,true>) {
template <typename RHS> void triqs_clef_auto_assign_impl(RHS const &rhs, std::integral_constant<bool, true>) {
for (auto const & w: this->mesh()) {
//std::cout << "abot "<<w.components_tuple()<<std::endl ;
//std::cout << "eefef "<< triqs::tuple::apply(rhs,w.components_tuple()) << std::endl ;
(*this)[w] = triqs::tuple::apply(rhs,w.components_tuple());
//std::cout << "done "<<std::endl ;
}
//for (auto w: this->mesh()) triqs::tuple::apply(*this,w.components_tuple()) = triqs::tuple::apply(rhs,w.components_tuple());
}
@ -389,15 +390,15 @@ namespace triqs { namespace gfs {
// ---------------------------------------------------------------------------------
///The regular class of GF
template<typename Variable, typename Target, typename Opt> class gf : public gf_impl<Variable,Target,Opt,false> {
typedef gf_impl<Variable,Target,Opt,false> B;
template<typename Variable, typename Target, typename Opt> class gf : public gf_impl<Variable,Target,Opt,false, false> {
typedef gf_impl<Variable,Target,Opt,false,false> B;
typedef gfs_implementation::factories<Variable,Target,Opt> factory;
public :
gf():B() {}
gf(gf const & g): B(g){}
gf(gf && g) noexcept : B(std::move(g)){}
gf(gf_view<Variable,Target,Opt> const & g): B(g){}
gf(gf_view<Variable,Target,Opt> const & g): B(g, bool() ){}
template<typename GfType> gf(GfType const & x,typename std::enable_if<ImmutableGreenFunction<GfType>::value>::type *dummy =0 ): B() { *this = x;}
gf(typename B::mesh_t m,
@ -431,14 +432,50 @@ namespace triqs { namespace gfs {
};
// ---------------------------------------------------------------------------------
///The View class of GF
template<typename Variable, typename Target, typename Opt> class gf_view : public gf_impl<Variable,Target,Opt,true> {
typedef gf_impl<Variable,Target,Opt,true> B;
///The const View class of GF
template<typename Variable, typename Target, typename Opt> class gf_view<Variable,Target,Opt,true> : public gf_impl<Variable,Target,Opt,true,true> {
typedef gf_impl<Variable,Target,Opt,true,true> B;
public :
gf_view() = delete;
gf_view(gf_view const & g): B(g){}
gf_view(gf_view && g) noexcept : B(std::move(g)){}
template<bool V> gf_view(gf_impl<Variable,Target,Opt,V> const & g): B(g){}
gf_view(gf_impl<Variable,Target,Opt,true,true> const & g) : B(g, bool()){} // from a const_view
gf_view(gf_impl<Variable,Target,Opt,true,false> const & g): B(g, bool()){} // from a view
gf_view(gf_impl<Variable,Target,Opt,false,false> const & g): B(g, bool()){} // from a const gf
gf_view(gf_impl<Variable,Target,Opt,false,false> & g): B(g, bool()){} // from a gf &
gf_view(gf_impl<Variable,Target,Opt,false,false> && g) noexcept: B(std::move(g), bool()){} // from a gf &&
template<typename D>
gf_view (typename B::mesh_t const & m,
D const & dat,typename B::singularity_view_t const & t,typename B::symmetry_t const & s,
typename B::evaluator_t const &e = typename B::evaluator_t () ) :
B(m,factory<typename B::data_t>(dat),t,s,e) {}
void rebind (gf_view const &X) noexcept {
this->_mesh = X._mesh; this->_symmetry = X._symmetry;
this->_data_proxy.rebind(this->_data,X);
this->_singularity.rebind(X._singularity);
}
gf_view & operator = (gf_view const & ) = delete;
}; // class gf_const_view
// ---------------------------------------------------------------------------------
///The View class of GF
template<typename Variable, typename Target, typename Opt> class gf_view<Variable,Target,Opt,false> : public gf_impl<Variable,Target,Opt,true,false> {
typedef gf_impl<Variable,Target,Opt,true,false> B;
public :
gf_view() = delete;
gf_view(gf_view const & g): B(g){}
gf_view(gf_view && g) noexcept : B(std::move(g)){}
gf_view(gf_impl<Variable,Target,Opt,true,true> const & g) = delete; // from a const view : impossible
gf_view(gf_impl<Variable,Target,Opt,true,false> const & g): B(g, bool()){} // from a view
gf_view(gf_impl<Variable,Target,Opt,false,false> const & g) = delete; // from a const gf : impossible
//gf_view(gf_impl<Variable,Target,Opt,false,false> const & g): B(g, bool()){} // from a gf &
gf_view(gf_impl<Variable,Target,Opt,false,false> & g): B(g, bool()){} // from a gf &
gf_view(gf_impl<Variable,Target,Opt,false,false> && g) noexcept: B(std::move(g), bool()){} // from a gf &&
template<typename D>
gf_view (typename B::mesh_t const & m,
@ -474,33 +511,67 @@ namespace triqs { namespace gfs {
}
// tool for lazy transformation
template<typename Tag, typename D, typename Target = matrix_valued> struct gf_keeper{ gf_view<D,Target> g; gf_keeper (gf_view<D,Target> const & g_) : g(g_) {} };
template <typename Tag, typename D, typename Target = matrix_valued> struct gf_keeper {
gf_const_view<D, Target> g;
};
// ---------------------------------- slicing ------------------------------------
//slice
template<typename Variable, typename Target, typename Opt, typename... Args>
gf_view<Variable,matrix_valued,Opt> slice_target (gf_view<Variable,Target,Opt> g, Args&& ... args) {
static_assert(std::is_same<Target,matrix_valued>::value, "slice_target only for matrix_valued GF's");
using arrays::range;
//auto sg=slice_target (g.singularity(),range(args,args+1)...);
return gf_view<Variable,matrix_valued,Opt>(g.mesh(), g.data()(range(), std::forward<Args>(args)... ), slice_target (g.singularity(), std::forward<Args>(args)...) , g.symmetry());
}
// slice
template <typename Variable, typename Target, typename Opt, bool IsConst, typename... Args>
gf_view<Variable, matrix_valued, Opt,IsConst> slice_target(gf_view<Variable, Target, Opt, IsConst> g, Args &&... args) {
static_assert(std::is_same<Target, matrix_valued>::value, "slice_target only for matrix_valued GF's");
using arrays::range;
return {g.mesh(), g.data()(range(), std::forward<Args>(args)...),
slice_target(g.singularity(), std::forward<Args>(args)...), g.symmetry()};
}
template<typename Variable, typename Target, typename Opt, typename... Args>
gf_view<Variable,scalar_valued,Opt> slice_target_to_scalar (gf_view<Variable,Target,Opt> g, Args&& ... args) {
static_assert(std::is_same<Target,matrix_valued>::value, "slice_target only for matrix_valued GF's");
using arrays::range;
auto sg=slice_target (g.singularity(),range(args,args+1)...);
return gf_view<Variable,scalar_valued,Opt>(g.mesh(), g.data()(range(), std::forward<Args>(args)... ), sg, g.symmetry());
}
template <typename Variable, typename Target, typename Opt, typename... Args>
gf_view<Variable, matrix_valued, Opt> slice_target(gf<Variable, Target, Opt> & g, Args &&... args) {
return slice_target(g(), std::forward<Args>(args)...);
}
template <typename Variable, typename Target, typename Opt, typename... Args>
gf_const_view<Variable, matrix_valued, Opt> slice_target(gf<Variable, Target, Opt> const &g, Args &&... args) {
return slice_target(g(), std::forward<Args>(args)...);
}
// slice to scalar
template <typename Variable, typename Target, typename Opt, bool IsConst, typename... Args>
gf_view<Variable, scalar_valued, Opt, IsConst> slice_target_to_scalar(gf_view<Variable, Target, Opt, IsConst> g,
Args &&... args) {
static_assert(std::is_same<Target, matrix_valued>::value, "slice_target only for matrix_valued GF's");
using arrays::range;
return {g.mesh(), g.data()(range(), std::forward<Args>(args)...),
slice_target(g.singularity(), range(args, args + 1)...), g.symmetry()};
}
template <typename Variable, typename Target, typename Opt, typename... Args>
gf_view<Variable, scalar_valued, Opt> slice_target_to_scalar(gf<Variable, Target, Opt> & g, Args &&... args) {
return slice_target_to_scalar(g(), std::forward<Args>(args)...);
}
template <typename Variable, typename Target, typename Opt, typename... Args>
gf_const_view<Variable, scalar_valued, Opt> slice_target_to_scalar(gf<Variable, Target, Opt> const &g, Args &&... args) {
return slice_target_to_scalar(g(), std::forward<Args>(args)...);
}
// a scalar_valued gf can be viewed as a 1x1 matrix
template<typename Variable, typename Opt, typename... Args>
gf_view<Variable,matrix_valued,Opt> reinterpret_scalar_valued_gf_as_matrix_valued (gf_view<Variable,scalar_valued,Opt> g) {
typedef typename gf_view<Variable,matrix_valued,Opt>::data_view_t a_t;
template<typename Variable, typename Opt, bool IsConst, typename... Args>
gf_view<Variable,matrix_valued,Opt,IsConst> reinterpret_scalar_valued_gf_as_matrix_valued (gf_view<Variable,scalar_valued,Opt,IsConst> g) {
typedef typename gf_view<Variable,matrix_valued,Opt,IsConst>::data_view_t a_t;
auto a = a_t {typename a_t::indexmap_type (join(g.data().shape(),make_shape(1,1))), g.data().storage()};
return gf_view<Variable,matrix_valued,Opt>(g.mesh(), a, g.singularity(), g.symmetry());
return {g.mesh(), a, g.singularity(), g.symmetry()};
}
template<typename Variable, typename Opt, typename... Args>
gf_view<Variable,matrix_valued,Opt> reinterpret_scalar_valued_gf_as_matrix_valued (gf<Variable,scalar_valued,Opt> & g) {
return reinterpret_scalar_valued_gf_as_matrix_valued(g());
}
template<typename Variable, typename Opt, typename... Args>
gf_const_view<Variable,matrix_valued,Opt> reinterpret_scalar_valued_gf_as_matrix_valued (gf<Variable,scalar_valued,Opt> const & g) {
return reinterpret_scalar_valued_gf_as_matrix_valued(g());
}
/*

View File

@ -44,7 +44,7 @@ namespace triqs { namespace gfs {
tqa::vector<dcomplex> g_in, g_out;
void direct (gf_view<imfreq,scalar_valued> gw, gf_view<imtime,scalar_valued> const gt) {
void direct (gf_view<imfreq,scalar_valued> gw, gf_const_view<imtime,scalar_valued> gt) {
using namespace impl_local_matsubara;
auto ta = gt(freq_infty());
//TO BE MODIFIED AFTER SCALAR IMPLEMENTATION TODO
@ -81,7 +81,7 @@ namespace triqs { namespace gfs {
gw.singularity() = gt.singularity();// set tail
}
void inverse(gf_view<imtime,scalar_valued> gt, gf_view<imfreq,scalar_valued> const gw){
void inverse(gf_view<imtime,scalar_valued> gt, gf_const_view<imfreq,scalar_valued> gw){
using namespace impl_local_matsubara;
static bool Green_Function_Are_Complex_in_time = false;
// If the Green function are NOT complex, then one use the symmetry property
@ -139,12 +139,12 @@ namespace triqs { namespace gfs {
};
void fourier_impl (gf_view<imfreq,scalar_valued> gw , gf_view<imtime,scalar_valued> const gt, scalar_valued){
void fourier_impl (gf_view<imfreq,scalar_valued> gw , gf_const_view<imtime,scalar_valued> gt, scalar_valued){
impl_worker w;
w.direct(gw,gt);
}
void fourier_impl (gf_view<imfreq,matrix_valued> gw , gf_view<imtime,matrix_valued> const gt, matrix_valued){
void fourier_impl (gf_view<imfreq,matrix_valued> gw , gf_const_view<imtime,matrix_valued> gt, matrix_valued){
impl_worker w;
for (size_t n1=0; n1<gt.data().shape()[1];n1++)
for (size_t n2=0; n2<gt.data().shape()[2];n2++){
@ -158,12 +158,12 @@ namespace triqs { namespace gfs {
//---------------------------------------------------------------------------
void inverse_fourier_impl (gf_view<imtime,scalar_valued> gt , gf_view<imfreq,scalar_valued> const gw, scalar_valued){
void inverse_fourier_impl (gf_view<imtime,scalar_valued> gt , gf_const_view<imfreq,scalar_valued> gw, scalar_valued){
impl_worker w;
w.inverse(gt,gw);
}
void inverse_fourier_impl (gf_view<imtime,matrix_valued> gt , gf_view<imfreq,matrix_valued> const gw, matrix_valued){
void inverse_fourier_impl (gf_view<imtime,matrix_valued> gt , gf_const_view<imfreq,matrix_valued> gw, matrix_valued){
impl_worker w;
for (size_t n1=0; n1<gw.data().shape()[1];n1++)
for (size_t n2=0; n2<gw.data().shape()[2];n2++){

View File

@ -28,19 +28,19 @@
namespace triqs { namespace gfs {
// First the implementation of the fourier transform
void fourier_impl (gf_view<imfreq,scalar_valued> gw , gf_view<imtime,scalar_valued> const gt, scalar_valued);
void fourier_impl (gf_view<imfreq,matrix_valued> gw , gf_view<imtime,matrix_valued> const gt, matrix_valued);
void inverse_fourier_impl (gf_view<imtime,scalar_valued> gt, gf_view<imfreq,scalar_valued> const gw, scalar_valued);
void inverse_fourier_impl (gf_view<imtime,matrix_valued> gt, gf_view<imfreq,matrix_valued> const gw, matrix_valued);
void fourier_impl (gf_view<imfreq,scalar_valued> gw , gf_const_view<imtime,scalar_valued> gt, scalar_valued);
void fourier_impl (gf_view<imfreq,matrix_valued> gw , gf_const_view<imtime,matrix_valued> gt, matrix_valued);
void inverse_fourier_impl (gf_view<imtime,scalar_valued> gt, gf_const_view<imfreq,scalar_valued> gw, scalar_valued);
void inverse_fourier_impl (gf_view<imtime,matrix_valued> gt, gf_const_view<imfreq,matrix_valued> gw, matrix_valued);
inline gf_view<imfreq,matrix_valued> fourier (gf_view<imtime,matrix_valued> const gt) {
inline gf_view<imfreq,matrix_valued> fourier (gf_const_view<imtime,matrix_valued> gt) {
int L = (gt.mesh().kind() == full_bins ? gt.mesh().size()-1 : gt.mesh().size() );
auto gw = gf<imfreq,matrix_valued>{ {gt.domain(),L}, gt.data().shape().front_pop() };
auto V = gw();
fourier_impl(V, gt, matrix_valued());
return gw;
}
inline gf_view<imfreq,scalar_valued> fourier (gf_view<imtime,scalar_valued> const gt) {
inline gf_view<imfreq,scalar_valued> fourier (gf_const_view<imtime,scalar_valued> gt) {
int L = (gt.mesh().kind() == full_bins ? gt.mesh().size()-1 : gt.mesh().size() );
auto gw = gf<imfreq,scalar_valued>{ {gt.domain(),L} };
auto V = gw();
@ -48,7 +48,7 @@ namespace triqs { namespace gfs {
return gw;
}
inline gf_view<imtime, matrix_valued> inverse_fourier (gf_view<imfreq, matrix_valued> const gw, mesh_kind mk = half_bins) {
inline gf_view<imtime, matrix_valued> inverse_fourier (gf_const_view<imfreq, matrix_valued> gw, mesh_kind mk = half_bins) {
double pi = std::acos(-1);
int L = (mk == full_bins ? gw.mesh().size()+1 : gw.mesh().size() );
auto gt = gf<imtime,matrix_valued>{ {gw.domain(),L}, gw.data().shape().front_pop()};
@ -56,7 +56,7 @@ namespace triqs { namespace gfs {
inverse_fourier_impl(V, gw, matrix_valued());
return gt;
}
inline gf_view<imtime,scalar_valued> inverse_fourier (gf_view<imfreq,scalar_valued> const gw, mesh_kind mk = half_bins) {
inline gf_view<imtime,scalar_valued> inverse_fourier (gf_const_view<imfreq,scalar_valued> gw, mesh_kind mk = half_bins) {
double pi = std::acos(-1);
int L = (mk == full_bins ? gw.mesh().size()+1 : gw.mesh().size() );
auto gt = gf<imtime,scalar_valued>{ {gw.domain(),L} };
@ -65,10 +65,10 @@ namespace triqs { namespace gfs {
return gt;
}
inline gf_keeper<tags::fourier,imtime,scalar_valued> lazy_fourier (gf_view<imtime,scalar_valued> const & g) { return g;}
inline gf_keeper<tags::fourier,imfreq,scalar_valued> lazy_inverse_fourier (gf_view<imfreq,scalar_valued> const & g) { return g;}
inline gf_keeper<tags::fourier,imtime,matrix_valued> lazy_fourier (gf_view<imtime,matrix_valued> const & g) { return g;}
inline gf_keeper<tags::fourier,imfreq,matrix_valued> lazy_inverse_fourier (gf_view<imfreq,matrix_valued> const & g) { return g;}
inline gf_keeper<tags::fourier,imtime,scalar_valued> lazy_fourier (gf_const_view<imtime,scalar_valued> g) { return {g};}
inline gf_keeper<tags::fourier,imfreq,scalar_valued> lazy_inverse_fourier (gf_const_view<imfreq,scalar_valued> g) { return {g};}
inline gf_keeper<tags::fourier,imtime,matrix_valued> lazy_fourier (gf_const_view<imtime,matrix_valued> g) { return {g};}
inline gf_keeper<tags::fourier,imfreq,matrix_valued> lazy_inverse_fourier (gf_const_view<imfreq,matrix_valued> g) { return {g};}
void triqs_gf_view_assign_delegation( gf_view<imfreq,scalar_valued> g, gf_keeper<tags::fourier,imtime,scalar_valued> const & L);
void triqs_gf_view_assign_delegation( gf_view<imfreq,matrix_valued> g, gf_keeper<tags::fourier,imtime,matrix_valued> const & L);

View File

@ -37,7 +37,7 @@ namespace triqs { namespace gfs {
tqa::vector<dcomplex> g_in, g_out;
void direct (gf_view<refreq,scalar_valued> gw, gf_view<retime,scalar_valued> const gt){
void direct (gf_view<refreq,scalar_valued> gw, gf_const_view<retime,scalar_valued> gt){
size_t L = gt.mesh().size();
if (gw.mesh().size() != L) TRIQS_RUNTIME_ERROR << "Meshes are different";
@ -70,7 +70,7 @@ namespace triqs { namespace gfs {
}
void inverse(gf_view<retime,scalar_valued> gt, gf_view<refreq,scalar_valued> const gw){
void inverse(gf_view<retime,scalar_valued> gt, gf_const_view<refreq,scalar_valued> gw){
size_t L = gw.mesh().size();
if ( L != gt.mesh().size()) TRIQS_RUNTIME_ERROR << "Meshes are different";
@ -108,12 +108,12 @@ namespace triqs { namespace gfs {
//--------------------------------------------------------------------------------------
void fourier_impl(gf_view<refreq,scalar_valued> gw, gf_view<retime,scalar_valued> const gt, scalar_valued){
void fourier_impl(gf_view<refreq,scalar_valued> gw, gf_const_view<retime,scalar_valued> gt, scalar_valued){
impl_worker w;
w.direct(gw, gt);
}
void fourier_impl(gf_view<refreq,matrix_valued> gw, gf_view<retime,matrix_valued> const gt, matrix_valued){
void fourier_impl(gf_view<refreq,matrix_valued> gw, gf_const_view<retime,matrix_valued> gt, matrix_valued){
impl_worker w;
for (size_t n1=0; n1<gw.data().shape()[1];n1++)
for (size_t n2=0; n2<gw.data().shape()[2];n2++) {
@ -125,12 +125,12 @@ namespace triqs { namespace gfs {
//---------------------------------------------------------------------------
void inverse_fourier_impl (gf_view<retime,scalar_valued> gt, gf_view<refreq,scalar_valued> const gw, scalar_valued){
void inverse_fourier_impl (gf_view<retime,scalar_valued> gt, gf_const_view<refreq,scalar_valued> gw, scalar_valued){
impl_worker w;
w.inverse(gt,gw);
}
void inverse_fourier_impl (gf_view<retime,matrix_valued> gt, gf_view<refreq,matrix_valued> const gw, matrix_valued){
void inverse_fourier_impl (gf_view<retime,matrix_valued> gt, gf_const_view<refreq,matrix_valued> gw, matrix_valued){
impl_worker w;
for (size_t n1=0; n1<gt.data().shape()[1];n1++)
for (size_t n2=0; n2<gt.data().shape()[2];n2++) {

View File

@ -28,12 +28,12 @@
namespace triqs { namespace gfs {
// First the implementation of the fourier transform
void fourier_impl (gf_view<refreq,scalar_valued> gw , gf_view<retime,scalar_valued> const gt, scalar_valued);
void fourier_impl (gf_view<refreq,matrix_valued> gw , gf_view<retime,matrix_valued> const gt, matrix_valued);
void inverse_fourier_impl (gf_view<retime,scalar_valued> gt, gf_view<refreq,scalar_valued> const gw, scalar_valued);
void inverse_fourier_impl (gf_view<retime,matrix_valued> gt, gf_view<refreq,matrix_valued> const gw, matrix_valued);
void fourier_impl (gf_view<refreq,scalar_valued> gw , gf_const_view<retime,scalar_valued> gt, scalar_valued);
void fourier_impl (gf_view<refreq,matrix_valued> gw , gf_const_view<retime,matrix_valued> gt, matrix_valued);
void inverse_fourier_impl (gf_view<retime,scalar_valued> gt, gf_const_view<refreq,scalar_valued> gw, scalar_valued);
void inverse_fourier_impl (gf_view<retime,matrix_valued> gt, gf_const_view<refreq,matrix_valued> gw, matrix_valued);
inline gf_view<refreq,matrix_valued> fourier (gf_view<retime, matrix_valued> const gt) {
inline gf_view<refreq,matrix_valued> fourier (gf_const_view<retime, matrix_valued> gt) {
double pi = std::acos(-1);
int L = gt.mesh().size();
double wmin = -pi * (L-1) / (L*gt.mesh().delta());
@ -43,7 +43,7 @@ namespace triqs { namespace gfs {
fourier_impl(V, gt, matrix_valued());
return gw;
}
inline gf_view<refreq,scalar_valued> fourier (gf_view<retime, scalar_valued> const gt) {
inline gf_view<refreq,scalar_valued> fourier (gf_const_view<retime, scalar_valued> gt) {
double pi = std::acos(-1);
int L = gt.mesh().size();
double wmin = -pi * (L-1) / (L*gt.mesh().delta());
@ -54,7 +54,7 @@ namespace triqs { namespace gfs {
return gw;
}
inline gf_view<retime,matrix_valued> inverse_fourier (gf_view<refreq,matrix_valued> const gw) {
inline gf_view<retime,matrix_valued> inverse_fourier (gf_const_view<refreq,matrix_valued> gw) {
double pi = std::acos(-1);
int L = gw.mesh().size();
double tmin = -pi * (L-1) / (L*gw.mesh().delta());
@ -64,7 +64,7 @@ namespace triqs { namespace gfs {
inverse_fourier_impl(V, gw, matrix_valued());
return gt;
}
inline gf_view<retime,scalar_valued> inverse_fourier (gf_view<refreq,scalar_valued> const gw) {
inline gf_view<retime,scalar_valued> inverse_fourier (gf_const_view<refreq,scalar_valued> gw) {
double pi = std::acos(-1);
int L = gw.mesh().size();
double tmin = -pi * (L-1) / (L*gw.mesh().delta());
@ -74,11 +74,11 @@ namespace triqs { namespace gfs {
inverse_fourier_impl(V, gw, scalar_valued());
return gt;
}
inline gf_keeper<tags::fourier,retime,scalar_valued> lazy_fourier (gf_view<retime,scalar_valued> const & g) { return g;}
inline gf_keeper<tags::fourier,refreq,scalar_valued> lazy_inverse_fourier (gf_view<refreq,scalar_valued> const & g) { return g;}
inline gf_keeper<tags::fourier,retime,matrix_valued> lazy_fourier (gf_view<retime,matrix_valued> const & g) { return g;}
inline gf_keeper<tags::fourier,refreq,matrix_valued> lazy_inverse_fourier (gf_view<refreq,matrix_valued> const & g) { return g;}
inline gf_keeper<tags::fourier, retime, scalar_valued> lazy_fourier(gf_const_view<retime, scalar_valued> g) { return {g}; }
inline gf_keeper<tags::fourier, refreq, scalar_valued> lazy_inverse_fourier(gf_const_view<refreq, scalar_valued> g) { return {g}; }
inline gf_keeper<tags::fourier, retime, matrix_valued> lazy_fourier(gf_const_view<retime, matrix_valued> g) { return {g}; }
inline gf_keeper<tags::fourier, refreq, matrix_valued> lazy_inverse_fourier(gf_const_view<refreq, matrix_valued> g) { return {g}; }
void triqs_gf_view_assign_delegation( gf_view<refreq,scalar_valued> g, gf_keeper<tags::fourier,retime,scalar_valued> const & L);
void triqs_gf_view_assign_delegation( gf_view<refreq,matrix_valued> g, gf_keeper<tags::fourier,retime,matrix_valued> const & L);

View File

@ -87,7 +87,7 @@ namespace triqs { namespace gfs {
// compute a tail from the Legendre GF
// this is Eq. 8 of our paper
local::tail_view get_tail(gf_view<legendre> const & gl, int size = 10, int omin = -1) {
local::tail_view get_tail(gf_const_view<legendre> gl, int size = 10, int omin = -1) {
auto sh = gl.data().shape().front_pop();
local::tail t(sh, size, omin);

View File

@ -36,7 +36,7 @@ namespace triqs {
tqa::matrix<double> density(gf_view<legendre> const & g);
local::tail_view get_tail(gf_view<legendre> const & gl, int size, int omin);
local::tail_view get_tail(gf_const_view<legendre> gl, int size, int omin);
void enforce_discontinuity(gf_view<legendre> & gl, triqs::arrays::array_view<double,2> disc);

View File

@ -29,7 +29,7 @@ using namespace triqs::utility;
namespace triqs { namespace gfs {
void legendre_matsubara_direct(gf_view<imfreq> & gw, gf_view<legendre> const & gl) {
void legendre_matsubara_direct(gf_view<imfreq> & gw, gf_const_view<legendre> gl) {
gw() = 0.0;
triqs::arrays::range R;
@ -45,7 +45,7 @@ void legendre_matsubara_direct(gf_view<imfreq> & gw, gf_view<legendre> const & g
}
void legendre_matsubara_inverse (gf_view<legendre> & gl, gf_view<imfreq> const & gw) {
void legendre_matsubara_inverse (gf_view<legendre> & gl, gf_const_view<imfreq> gw) {
gl() = 0.0;
@ -62,7 +62,7 @@ void legendre_matsubara_inverse (gf_view<legendre> & gl, gf_view<imfreq> const &
}
void legendre_matsubara_direct (gf_view<imtime> & gt, gf_view<legendre> const & gl) {
void legendre_matsubara_direct (gf_view<imtime> & gt, gf_const_view<legendre> gl) {
gt() = 0.0;
legendre_generator L;
@ -78,7 +78,7 @@ void legendre_matsubara_direct (gf_view<imtime> & gt, gf_view<legendre> const &
}
void legendre_matsubara_inverse (gf_view<legendre> & gl, gf_view<imtime> const & gt) {
void legendre_matsubara_inverse (gf_view<legendre> & gl, gf_const_view<imtime> gt) {
gl() = 0.0;
legendre_generator L;
@ -95,10 +95,10 @@ void legendre_matsubara_inverse (gf_view<legendre> & gl, gf_view<imtime> const &
}
gf_keeper<tags::legendre,legendre> lazy_legendre_imfreq (gf_view<legendre> const & gl) { return gl; }
gf_keeper<tags::legendre,legendre> lazy_legendre_imtime (gf_view<legendre> const & gl) { return gl; }
gf_keeper<tags::legendre,imfreq> lazy_imfreq_legendre (gf_view<imfreq> const & gw) { return gw; }
gf_keeper<tags::legendre,imtime> lazy_imtime_legendre (gf_view<imtime> const & gt) { return gt; }
gf_keeper<tags::legendre,legendre> lazy_legendre_imfreq (gf_const_view<legendre> gl) { return {gl}; }
gf_keeper<tags::legendre,legendre> lazy_legendre_imtime (gf_const_view<legendre> gl) { return {gl}; }
gf_keeper<tags::legendre,imfreq> lazy_imfreq_legendre (gf_const_view<imfreq> gw) { return {gw}; }
gf_keeper<tags::legendre,imtime> lazy_imtime_legendre (gf_const_view<imtime> gt) { return {gt}; }
void triqs_gf_view_assign_delegation( gf_view<imfreq> &gw, gf_keeper<tags::legendre,legendre> const & L) {
legendre_matsubara_direct(gw, L.g);

View File

@ -28,18 +28,18 @@
namespace triqs { namespace gfs {
void legendre_matsubara_direct (gf_view<imfreq> &gw, gf_view<legendre> const &gl);
void legendre_matsubara_inverse (gf_view<legendre> &gl, gf_view<imfreq> const &gw);
void legendre_matsubara_direct (gf_view<imfreq> &gw, gf_const_view<legendre> gl);
void legendre_matsubara_inverse (gf_view<legendre> &gl, gf_const_view<imfreq> gw);
void legendre_matsubara_direct (gf_view<imtime> &gt, gf_view<legendre> const &gl);
void legendre_matsubara_inverse (gf_view<legendre> &gl, gf_view<imtime> const &gt);
void legendre_matsubara_direct (gf_view<imtime> &gt, gf_const_view<legendre> gl);
void legendre_matsubara_inverse (gf_view<legendre> &gl, gf_const_view<imtime> gt);
namespace tags { struct legendre{}; }
gf_keeper<tags::legendre,legendre> lazy_legendre_imfreq (gf_view<legendre> const & gl);
gf_keeper<tags::legendre,legendre> lazy_legendre_imtime (gf_view<legendre> const & gl);
gf_keeper<tags::legendre,imfreq> lazy_imfreq_legendre (gf_view<imfreq> const & gw);
gf_keeper<tags::legendre,imtime> lazy_imtime_legendre (gf_view<imtime> const & gt);
gf_keeper<tags::legendre,legendre> lazy_legendre_imfreq (gf_const_view<legendre> gl);
gf_keeper<tags::legendre,legendre> lazy_legendre_imtime (gf_const_view<legendre> gl);
gf_keeper<tags::legendre,imfreq> lazy_imfreq_legendre (gf_const_view<imfreq> gw);
gf_keeper<tags::legendre,imtime> lazy_imtime_legendre (gf_const_view<imtime> gt);
void triqs_gf_view_assign_delegation( gf_view<imfreq> &gw, gf_keeper<tags::legendre,legendre> const & L);
void triqs_gf_view_assign_delegation( gf_view<imtime> &gt, gf_keeper<tags::legendre,legendre> const & L);

View File

@ -176,9 +176,9 @@ namespace triqs { namespace gfs {
// reinterpret_linear_array(m,A) returns a d-dimensionnal view of the array
// with indices egal to the indices of the components of the mesh.
// Very useful for slicing, currying functions.
template<typename ... Meshes, typename T, ull_t OptionsFlags, int R >
arrays::array_view<T, sizeof...(Meshes)+ R-1,OptionsFlags>
reinterpret_linear_array(mesh_product<Meshes...> const & m, arrays::array_view<T,R,OptionsFlags> const & A) {
template<typename ... Meshes, typename T, ull_t OptionsFlags, ull_t To, int R , bool B, bool C>
arrays::array_view<T, sizeof...(Meshes)+ R-1,OptionsFlags,To,true,C>
reinterpret_linear_array(mesh_product<Meshes...> const & m, arrays::array_view<T,R,OptionsFlags,To,B,C> A) {
return { {join (m.all_size_as_mini_vector(), get_shape(A).front_pop())}, A.storage()};
}

View File

@ -59,29 +59,32 @@ namespace triqs { namespace gfs {
template<typename Opt, int R, typename ... Ms> struct h5_name<cartesian_product<Ms...>,tensor_valued<R>,Opt> : h5_name<cartesian_product<Ms...>,matrix_valued,Opt> {};
// a slight difference with the generic case : reinterpret the data array to avoid flattening the variables
template <typename Opt, bool IsView, int R, typename ... Ms>
struct h5_rw<cartesian_product<Ms...>,tensor_valued<R>,Opt,IsView> {
typedef gf_impl<cartesian_product<Ms...>,tensor_valued<R>,Opt,IsView> g_t;
template <typename Opt, int R, typename ... Ms>
struct h5_rw<cartesian_product<Ms...>,tensor_valued<R>,Opt> {
typedef gf<cartesian_product<Ms...>,tensor_valued<R>,Opt> g_t;
static void write (h5::group gr, g_t const & g) {
static void write (h5::group gr, typename g_t::const_view_type g) {
h5_write(gr,"data",reinterpret_linear_array(g.mesh(), g().data()));
h5_write(gr,"singularity",g._singularity);
h5_write(gr,"mesh",g._mesh);
h5_write(gr,"symmetry",g._symmetry);
}
static void read (h5::group gr, g_t & g) {
template<bool IsView>
static void read (h5::group gr, gf_impl<cartesian_product<Ms...>,tensor_valued<R>,Opt,IsView,false> & g) {
using G_t= gf_impl<cartesian_product<Ms...>,tensor_valued<R>,Opt,IsView,false> ;
h5_read(gr,"mesh",g._mesh);
auto arr = arrays::array<typename g_t::data_t::value_type, sizeof...(Ms)+ R>{};
auto arr = arrays::array<typename G_t::data_t::value_type, sizeof...(Ms)+ R>{};
h5_read(gr,"data",arr);
auto sh = arr.shape();
arrays::mini_vector<size_t,R+1> sh2;
sh2[0] = g._mesh.size();
for (int u=1; u<R+1; ++u) sh2[u] = sh[sizeof...(Ms)-1+u];
g._data = arrays::array<typename g_t::data_t::value_type, R+1>{sh2, std::move(arr.storage())};
g._data = arrays::array<typename G_t::data_t::value_type, R+1>{sh2, std::move(arr.storage())};
h5_read(gr,"singularity",g._singularity);
h5_read(gr,"symmetry",g._symmetry);
}
};
/// --------------------------- data access ---------------------------------