From e5928de7f53375e36bc42dd76be2ae3b9d76a704 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Thu, 24 Jul 2014 17:17:16 +0200 Subject: [PATCH] Fix #108 (tentatively). - Pb was that indices for gf where empty when constructed with default args from C++. - changed into : make indices from the shape in the default case. - also added more, simpler construction, for the indices to easy C++ construction. --- triqs/gfs/gf.hpp | 4 +++- triqs/gfs/tools.hpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/triqs/gfs/gf.hpp b/triqs/gfs/gf.hpp index acc7d9e5..06f07625 100644 --- a/triqs/gfs/gf.hpp +++ b/triqs/gfs/gf.hpp @@ -433,7 +433,9 @@ namespace gfs { gf(typename B::mesh_t m, target_shape_t shape = target_shape_t{}, typename B::indices_t const &ind = typename B::indices_t{}, std::string name = "") : B(std::move(m), factory::make_data(m, shape), factory::make_singularity(m, shape), typename B::symmetry_t{}, ind, name, // clean unncessary types - typename B::evaluator_t{}) {} + typename B::evaluator_t{}) { + if (this->_indices.is_empty()) this->_indices = typename B::indices_t(shape); + } friend void swap(gf &a, gf &b) noexcept { a.swap_impl(b); } diff --git a/triqs/gfs/tools.hpp b/triqs/gfs/tools.hpp index b25415fe..0a831c9a 100644 --- a/triqs/gfs/tools.hpp +++ b/triqs/gfs/tools.hpp @@ -83,8 +83,24 @@ namespace gfs { std::vector> ind; indices_2() = default; + indices_2(std::vector> _ind) : ind(std::move(_ind)) {} + // from a size + indices_2(int L) : indices_2(arrays::mini_vector{L, L}) {}; + + // from a shape + indices_2(arrays::mini_vector const & shape) : ind(2) { + for (int i = 0; i < shape[0]; ++i) ind[0].push_back(std::to_string(i)); + for (int i = 0; i < shape[1]; ++i) ind[1].push_back(std::to_string(i)); + } + + // indices from a vector : L and R are the same. + template indices_2(std::vector const & _ind) : ind(2) { + for (auto const &i : _ind) ind[0].push_back(std::to_string(i)); + ind[1] = ind[0]; + } + bool is_empty() const { return ind.size() == 0; } void resize(int s) { ind.resize(s);} @@ -173,6 +189,7 @@ namespace gfs { friend nothing operator+(nothing, nothing) { return nothing(); } template friend void assign_from_expression(nothing &, RHS) {} template bool check_size(A) {return true;} + bool is_empty() const { return false;} }; inline nothing transpose(nothing) { return {};}