From 1d5ea99d4fcb75b5001735b4ad807958bed58085 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Wed, 23 Oct 2013 18:02:01 +0200 Subject: [PATCH] gf block : clean - clean some constructor and clang format --- doc/reference/c++/gf/gf_block.rst | 10 +-- test/triqs/gfs/block.cpp | 2 +- triqs/gfs/block.hpp | 119 +++++++++++++++--------------- 3 files changed, 64 insertions(+), 67 deletions(-) diff --git a/doc/reference/c++/gf/gf_block.rst b/doc/reference/c++/gf/gf_block.rst index bd9d5f13..b168a41d 100644 --- a/doc/reference/c++/gf/gf_block.rst +++ b/doc/reference/c++/gf/gf_block.rst @@ -42,7 +42,7 @@ The factories for the regular type *gf* are :: // From a vector of gf (moving directly) template block_gf - make_block_gf(std::vector> &&V); + make_block_gf(std::vector> V); // From a vector of gf or views (a gf must be contructible from GF2) template @@ -57,19 +57,17 @@ The factories for the regular type *gf* are :: // From vector and a gf to be copied template block_gf - make_block_gf(std::vector const &block_names, - gf const &g); + make_block_gf(std::vector block_names, gf const &g); // From vector, vector template block_gf - make_block_gf(std::vector const &block_names, - std::vector> V); + make_block_gf(std::vector block_names, std::vector> V); // From vector, init_list template block_gf - make_block_gf(std::vector const &block_names, + make_block_gf(std::vector block_names, std::initializer_list> const &V); diff --git a/test/triqs/gfs/block.cpp b/test/triqs/gfs/block.cpp index 814d32a6..5e5b9aa4 100644 --- a/test/triqs/gfs/block.cpp +++ b/test/triqs/gfs/block.cpp @@ -17,7 +17,7 @@ int main() { auto B1 = make_block_gf (3, G1); auto B2 = make_block_gf ({G1,G1,G1}); auto B3 = make_block_gf ({"a","b","c"}, {G1,G1,G1}); - auto B4 = block_gf (1); + auto B4 = block_gf (1); // test hdf5 { diff --git a/triqs/gfs/block.hpp b/triqs/gfs/block.hpp index 8dde72d1..97838c49 100644 --- a/triqs/gfs/block.hpp +++ b/triqs/gfs/block.hpp @@ -25,73 +25,76 @@ #include "./local/tail.hpp" #include "./meshes/discrete.hpp" -namespace triqs { namespace gfs { +namespace triqs { +namespace gfs { struct block_index {}; - template struct gf_mesh : discrete_mesh { + template struct gf_mesh : discrete_mesh { typedef discrete_mesh B; gf_mesh() = default; gf_mesh(int s) : B(s) {} - gf_mesh(discrete_domain const & d) : B(d) {} - gf_mesh(std::initializer_list const & s) : B(s){} + gf_mesh(discrete_domain const &d) : B(d) {} + gf_mesh(std::initializer_list const &s) : B(s) {} }; namespace gfs_implementation { /// --------------------------- hdf5 --------------------------------- - template struct h5_name { static std::string invoke(){ return "BlockGf";}}; + template struct h5_name { + static std::string invoke() { return "BlockGf"; } + }; - template struct h5_rw { + template struct h5_rw { - static void write (h5::group gr, gf_const_view g) { - for (size_t i =0; i 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); } - template - static void read (h5::group gr, gf_impl &g) { + template static void read(h5::group gr, gf_impl &g) { // does not work : need to read the block name and remake the mesh... - g._mesh = gf_mesh (gr.get_all_subgroup_names()); + g._mesh = gf_mesh(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 struct data_proxy : data_proxy_vector ::type>{}; + template + struct data_proxy : data_proxy_vector::type> {}; // ------------------------------- Factories -------------------------------------------------- - template - struct factories { - typedef gf_mesh mesh_t; - typedef gf gf_t; - typedef gf_view gf_view_t; - struct target_shape_t{}; + template struct factories { + typedef gf_mesh mesh_t; + typedef gf gf_t; + typedef gf_view gf_view_t; + struct target_shape_t {}; - static typename gf_t::data_t make_data(mesh_t const & m, target_shape_t) { return std::vector (m.size()); } - static typename gf_t::singularity_t make_singularity (mesh_t const & m, target_shape_t) { return {};} - }; + static typename gf_t::data_t make_data(mesh_t const &m, target_shape_t) { return std::vector(m.size()); } + static typename gf_t::singularity_t make_singularity(mesh_t const &m, target_shape_t) { + return {}; + } + }; } // gfs_implementation // ------------------------------- aliases -------------------------------------------------- - - template using block_gf = gf>; - template using block_gf_view = gf_view>; - template using block_gf_const_view = gf_const_view>; + + template using block_gf = gf>; + template using block_gf_view = gf_view>; + template using block_gf_const_view = gf_const_view>; // ------------------------------- Free Factories for regular type -------------------------------------------------- // from a number and a gf to be copied template - block_gf make_block_gf(int n, gf const & g) { + block_gf make_block_gf(int n, gf const &g) { auto V = std::vector>{}; for (int i = 0; i < n; ++i) V.push_back(g); return {{n}, std::move(V), nothing{}, nothing{}}; @@ -99,7 +102,7 @@ namespace triqs { namespace gfs { // from a vector of gf (moving directly) template - block_gf make_block_gf(std::vector> &&V) { + block_gf make_block_gf(std::vector> V) { return {{int(V.size())}, std::move(V), nothing{}, nothing{}}; } @@ -119,16 +122,15 @@ namespace triqs { namespace gfs { // from vector and a gf to be copied template - block_gf make_block_gf(std::vector const &block_names, gf const &g) { + block_gf make_block_gf(std::vector block_names, gf const &g) { auto V = std::vector>{}; for (int i = 0; i < block_names.size(); ++i) V.push_back(g); return {{block_names}, std::move(V), nothing{}, nothing{}}; } - + // from vector, vector template - block_gf make_block_gf(std::vector const &block_names, - std::vector> V) { + block_gf make_block_gf(std::vector block_names, std::vector> V) { if (block_names.size() != V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector, vector) : the two vectors do not have the same size !"; return {{block_names}, std::move(V), nothing{}, nothing{}}; @@ -136,7 +138,7 @@ namespace triqs { namespace gfs { // from vector, init_list template - block_gf make_block_gf(std::vector const &block_names, + block_gf make_block_gf(std::vector block_names, std::initializer_list> const &V) { if (block_names.size() != V.size()) TRIQS_RUNTIME_ERROR << "make_block_gf(vector, init_list) : size mismatch !"; return {{block_names}, V, nothing{}, nothing{}}; @@ -144,22 +146,22 @@ namespace triqs { namespace gfs { // ------------------------------- Free Factories for view type -------------------------------------------------- - template - gf_view::type::view_type> make_block_gf_view(G0 && g0, G && ... g) { - auto V = std::vector::type::view_type>{std::forward(g0), std::forward(g)...}; - return { {int(V.size())}, std::move(V), nothing{}, nothing{} } ; - //return { gf_mesh {int(V.size())}, std::move(V), nothing{}, nothing{} } ; - } + template + gf_view::type::view_type> make_block_gf_view(G0 &&g0, G &&... g) { + auto V = std::vector::type::view_type>{std::forward(g0), std::forward(g)...}; + return {{int(V.size())}, std::move(V), nothing{}, nothing{}}; + // return { gf_mesh {int(V.size())}, std::move(V), nothing{}, nothing{} } ; + } - template - gf_view - make_block_gf_view_from_vector (std::vector V) { return { {int(V.size())}, std::move(V), nothing{}, nothing{}} ; } + template gf_view make_block_gf_view_from_vector(std::vector V) { + return {{int(V.size())}, std::move(V), nothing{}, nothing{}}; + } // ------------------------------- Free functions -------------------------------------------------- // a simple function to get the number of blocks - template size_t n_blocks (gf const & g) { return g.mesh().size();} - template size_t n_blocks (gf_view const & g) { return g.mesh().size();} + template size_t n_blocks(gf const &g) { return g.mesh().size(); } + template size_t n_blocks(gf_view const &g) { return g.mesh().size(); } // ------------------------------- an iterator over the blocks -------------------------------------------------- @@ -169,7 +171,7 @@ namespace triqs { namespace gfs { : public boost::iterator_facade, Target, boost::forward_traversal_tag, Target &> { friend class boost::iterator_core_access; typedef gf_impl big_gf_t; - big_gf_t & big_gf; + big_gf_t &big_gf; typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t; mesh_iterator_t mesh_it; @@ -177,8 +179,7 @@ namespace triqs { namespace gfs { bool equal(block_gf_iterator const &other) const { return ((mesh_it == other.mesh_it)); } public: - block_gf_iterator(big_gf_t & bgf, bool at_end = false) - : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {} + block_gf_iterator(big_gf_t &bgf, bool at_end = false) : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {} void increment() { ++mesh_it; } bool at_end() const { return mesh_it.at_end(); } }; @@ -197,11 +198,11 @@ namespace triqs { namespace gfs { //----- const iterator template - class block_gf_const_iterator - : public boost::iterator_facade, Target, boost::forward_traversal_tag, Target const &> { + class block_gf_const_iterator : public boost::iterator_facade, Target, + boost::forward_traversal_tag, Target const &> { friend class boost::iterator_core_access; typedef gf_impl big_gf_t; - big_gf_t const & big_gf; + big_gf_t const &big_gf; typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t; mesh_iterator_t mesh_it; @@ -209,8 +210,7 @@ namespace triqs { namespace gfs { bool equal(block_gf_const_iterator const &other) const { return ((mesh_it == other.mesh_it)); } public: - block_gf_const_iterator(big_gf_t const& bgf, bool at_end = false) - : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {} + block_gf_const_iterator(big_gf_t const &bgf, bool at_end = false) : big_gf(bgf), mesh_it(&big_gf.mesh(), at_end) {} void increment() { ++mesh_it; } bool at_end() const { return mesh_it.at_end(); } }; @@ -234,8 +234,7 @@ namespace triqs { namespace gfs { block_gf_const_iterator cend(gf_impl const &bgf) { return {bgf, true}; } - -}} +} +} #endif -