40data_t &
data() {
return _glist; }
46data_t
const &
data()
const {
return _glist; }
52block_names_t
const &
block_names()
const {
return _block_names; }
62 static_assert(g_t::target_t::rank == 2);
63 auto res = std::vector<int>(_glist.size());
64 for (
auto [i, g] : itertools::enumerate(_glist)) {
65 EXPECTS(g.target_shape()[0] == g.target_shape()[1]);
66 res[i] = g.target_shape()[0];
101 return _glist.at(0).
size();
109 if constexpr (Arity == 1) {
110 return _glist.size();
119template <
typename RHS>
void _assign_impl(RHS &&rhs) {
121 if constexpr (Arity == 1) {
122 for (
int w = 0;
w <
size(); ++
w) _glist[w] = rhs[w];
124 for (
int w = 0;
w <
size1(); ++
w)
125 for (
int v = 0; v <
size2(); ++v) _glist[w][v] = rhs(w, v);
127 _block_names = rhs.block_names();
145decltype(
auto)
operator()(
int n)
const
157decltype(
auto)
operator()(
int n1,
int n2)
const
160 return _glist[n1][n2];
169decltype(
auto)
operator()(
int n1,
int n2)
172 return _glist[n1][n2];
182template <
typename... Args>
184 requires(nda::clef::is_clef_expression<Args...>)
186 return clef::make_expr_call(*
this, std::forward<Args>(args)...);
190template <
typename... Args>
192 requires(nda::clef::is_clef_expression<Args...>)
194 return clef::make_expr_call(*
this, std::forward<Args>(args)...);
198template <
typename... Args>
200 requires(nda::clef::is_clef_expression<Args...>)
202 return clef::make_expr_call(std::move(*
this), std::forward<Args>(args)...);
212decltype(
auto)
operator[](
int n)
const
223decltype(
auto)
operator[](
int n)
237template <
typename Arg>
239 requires(nda::clef::is_clef_expression<Arg>)
241 return clef::make_expr_subscript(*
this, std::forward<Arg>(arg));
245template <
typename Arg>
247 requires(nda::clef::is_clef_expression<Arg>)
249 return clef::make_expr_subscript(*
this, std::forward<Arg>(arg));
253template <
typename Arg>
255 requires(nda::clef::is_clef_expression<Arg>)
257 return clef::make_expr_subscript(std::move(*
this), std::forward<Arg>(arg));
267 if constexpr (Arity == 1)
280friend void h5_write(h5::group fg, std::string
const &subgroup_name, this_t
const &g) {
281 auto gr = fg.create_group(subgroup_name);
282 write_hdf5_format(gr, g);
284 if constexpr (Arity == 1) {
285 h5_write(gr,
"block_names", g.block_names());
286 for (
int i = 0; i < g.size(); ++i)
h5_write(gr, g.block_names()[i], g.data()[i]);
288 h5_write(gr,
"block_names1", g.block_names()[0]);
289 h5_write(gr,
"block_names2", g.block_names()[1]);
290 for (
int i = 0; i < g.size1(); ++i)
291 for (
int j = 0; j < g.size2(); ++j)
h5_write(gr, g.block_names()[0][i] +
"_" + g.block_names()[1][j], g._glist[i][j]);
304friend void h5_read(h5::group fg, std::string
const &subgroup_name, this_t &g) {
305 auto gr = fg.open_group(subgroup_name);
307 auto tag_file = read_hdf5_format(gr);
308 auto tag_expected = this_t::hdf5_format();
309 if (tag_file != tag_expected)
310 TRIQS_RUNTIME_ERROR <<
"h5_read : mismatch of the Format tag in the h5 group : found " << tag_file <<
" while I expected " << tag_expected;
311 if constexpr (Arity == 1) {
313 auto block_names = h5::h5_read<std::vector<std::string>>(gr,
"block_names");
319 auto block_names1 = h5::h5_read<std::vector<std::string>>(gr,
"block_names1");
320 auto block_names2 = h5::h5_read<std::vector<std::string>>(gr,
"block_names2");
321 auto block_names = std::vector<std::vector<std::string>>{block_names1, block_names2};
326 for (
int i = 0; i < s0; ++i) {
327 g._glist[i].resize(s1);
343 std::conditional_t<is_const, const this_t *, this_t *> bgf = NULL;
347 using iterator_category = std::forward_iterator_tag;
348 using value_type = g_t;
349 using difference_type = std::ptrdiff_t;
350 using pointer = std::conditional_t<is_const, const g_t *, g_t *>;
351 using reference = std::conditional_t<is_const, g_t const &, g_t &>;
352 using block_gf_ref = std::conditional_t<is_const, this_t const &, this_t &>;
358 iterator_impl(block_gf_ref _bgf,
bool at_end =
false) : bgf(&_bgf), n(at_end ? bgf->
size() : 0) {}
368 if constexpr (Arity == 1) {
371 return (*bgf)(n / bgf->size2(), n % bgf->size2());
377 if constexpr (Arity == 1) {
380 return (*bgf)(n / bgf->size2(), n % bgf->size2());
428auto cbegin() {
return const_view_type(*this).begin(); }
431auto cend() {
return const_view_type(*this).end(); }
data_t & data()
Direct access to the blocks.
iterator_impl< false > iterator
Mutable block iterator type.
auto cend()
Get a const iterator past the last block.
friend void h5_read(h5::group fg, std::string const &subgroup_name, this_t &g)
Read a block Green's function from HDF5.
gf_struct_t gf_struct() const
Get the block structure.
int size2() const
Get the number of blocks along the second index (block2_gf only).
block_names_t const & block_names() const
Get the block names.
decltype(auto) operator[](int n) const
Access the n-th block of a one-index block Green's function (const overload).
std::vector< int > block_sizes() const
Get the matrix size of each block.
iterator_impl< true > const_iterator
Const block iterator type.
iterator end()
Get an iterator past the last block.
auto cbegin()
Get a const iterator to the first block.
friend void h5_write(h5::group fg, std::string const &subgroup_name, this_t const &g)
Write a block Green's function to HDF5.
static std::string hdf5_format()
Get the HDF5 format tag of a block Green's function.
const_view_type operator()() const
Make a const view of *this.
iterator begin()
Get an iterator to the first block.
int size1() const
Get the number of blocks along the first index (block2_gf only).
int size() const
Get the total number of blocks.
Forward iterator over the blocks of a block Green's function.
reference operator*()
Dereference to the current block.
iterator_impl(block_gf_ref _bgf, int _n)
Construct an iterator over a block Green's function positioned at block _n.
iterator_impl & operator++()
Pre-increment to the next block.
reference operator*() const
Dereference to the current block (const overload).
iterator_impl()=default
Construct a past-the-end (singular) iterator.
iterator_impl(block_gf_ref _bgf, bool at_end=false)
Construct an iterator over a block Green's function, optionally positioned at the end.
iterator_impl operator++(int)
Post-increment to the next block.
bool operator==(iterator_impl const &other) const
Equality comparison (same block Green's function and same position).
reference operator->()
Member access to the current block.
bool operator!=(iterator_impl const &other) const
Inequality comparison.
many_body_operator_generic< T > n(IndexTypes... indices)
Create a number operator .
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.
constexpr nda::clef::placeholder< 3 > w
Placeholder for the frequency .