<commit_before>#pragma once 

#include "grid_base.hpp"
#include <numeric>

namespace gftools { 

template <bool Fermion> inline complex_type Matsubara(int n, real_type beta){return PI*I/beta*complex_type(2*n+Fermion);};
template <bool Fermion> inline int MatsubaraIndex(complex_type in, real_type beta){return std::round((beta*imag(in)/PI-Fermion)/2.0);};

inline complex_type FMatsubara(int n, real_type beta){return Matsubara<1>(n,beta);};
inline complex_type BMatsubara(int n, real_type beta){return Matsubara<0>(n,beta);};
inline int FMatsubaraIndex(complex_type in, real_type beta){return MatsubaraIndex<1>(in,beta);};
inline int BMatsubaraIndex(complex_type in, real_type beta){return MatsubaraIndex<0>(in,beta);};

/** A Grid of fermionic Matsubara frequencies. */
template <bool Fermion>
class matsubara_grid : public grid_base<complex_type, matsubara_grid<Fermion>>
{
public:
    typedef grid_base<complex_type, matsubara_grid<Fermion>> base;
    typedef typename base::point point;
    using base::vals_;
    using typename base::ex_wrong_index;
    //typedef typename grid_base<complex_type, matsubara_grid<Fermion>>::point point;
    //using typename grid_base<complex_type, matsubara_grid<Fermion>>::point;
    /** Inverse temperature. */
    const real_type beta_;
    /** Spacing between values. */
    const real_type spacing_;
    /** Min and max numbers of freq. - useful for searching. */
    const int w_min_, w_max_;
    matsubara_grid(int min, int max, real_type beta);
    matsubara_grid(const matsubara_grid &rhs);
    matsubara_grid(matsubara_grid&& rhs);
    matsubara_grid(std::vector<complex_type> const& in);
    int getNumber(complex_type in) const;
    double beta() const { return beta_; }
    int min_n() const { return w_min_; }
    int max_n() const { return w_max_; }

    point find_nearest(complex_type in) const;
    template <class Obj> auto integrate(const Obj &in) const -> decltype(in(vals_[0]));
    template <class Obj> auto prod(const Obj &in) const -> decltype(in(vals_[0]));
    //template <class Obj> auto gridIntegrate(const std::vector<Obj> &in) const -> Obj;
    template <class Obj> auto eval(Obj &in, complex_type x) const ->decltype(in[0]);
    //template <class Obj> auto eval(Obj &in, point x) const ->decltype(in[0]);
    //using base::eval;
};

typedef matsubara_grid<1> fmatsubara_grid;
typedef matsubara_grid<0> bmatsubara_grid;

//
// matsubara_grid implementations
//

template <bool F>
matsubara_grid<F>::matsubara_grid(int min, int max, real_type beta):
    //grid_base<complex_type, matsubara_grid<F>>(min,max,std::bind(Matsubara<F>, std::placeholders::_1, beta)),
    grid_base<complex_type, matsubara_grid<F>>(min,max,[beta](int n){return Matsubara<F>(n,beta);}),
    beta_(beta), 
    spacing_(PI/beta), 
    w_min_(min),
    w_max_(max)
{
}

template <bool F>
matsubara_grid<F>::matsubara_grid(const matsubara_grid<F> &rhs) : 
    grid_base<complex_type, matsubara_grid<F>>(rhs.vals_),
    beta_(rhs.beta_), 
    spacing_(rhs.spacing_), 
    w_min_(rhs.w_min_), 
    w_max_(rhs.w_max_)
{
}

template <bool F>
matsubara_grid<F>::matsubara_grid(matsubara_grid<F>&& rhs):
    grid_base<complex_type, matsubara_grid>(rhs.vals_), 
    beta_(rhs.beta_), 
    spacing_(rhs.spacing_), 
    w_min_(rhs.w_min_), 
    w_max_(rhs.w_max_)
{
}

template <bool F>
matsubara_grid<F>::matsubara_grid(std::vector<complex_type> const& in):
    base(in),
    beta_( PI / std::abs((in[1] - in[0])/2.) ),
    spacing_(std::abs((in[1] - in[0])/2.)),
    w_min_(FMatsubaraIndex(in[0], beta_)),
    w_max_(FMatsubaraIndex(in[in.size() - 1], beta_))
{
}

template <bool F>
template <class Obj> 
auto matsubara_grid<F>::integrate(const Obj &in) const -> decltype(in(vals_[0]))
{
    decltype(in(this->vals_[0])) R = in(this->vals_[0]);
    R=std::accumulate(vals_.begin()+1, vals_.end(), R,[&](decltype(in(vals_[0]))& y,decltype(vals_[0]) &x) {return y+in(x);}); 
    return R/beta_;
}
<commit_msg>matsubara_grid : bugfix in constructor for bosonic grids<commit_after>#pragma once 

#include "grid_base.hpp"
#include <numeric>

namespace gftools { 

template <bool Fermion> inline complex_type Matsubara(int n, real_type beta){return PI*I/beta*complex_type(2*n+Fermion);};
template <bool Fermion> inline int MatsubaraIndex(complex_type in, real_type beta){return std::round((beta*imag(in)/PI-Fermion)/2.0);};

inline complex_type FMatsubara(int n, real_type beta){return Matsubara<1>(n,beta);};
inline complex_type BMatsubara(int n, real_type beta){return Matsubara<0>(n,beta);};
inline int FMatsubaraIndex(complex_type in, real_type beta){return MatsubaraIndex<1>(in,beta);};
inline int BMatsubaraIndex(complex_type in, real_type beta){return MatsubaraIndex<0>(in,beta);};

/** A Grid of fermionic Matsubara frequencies. */
template <bool Fermion>
class matsubara_grid : public grid_base<complex_type, matsubara_grid<Fermion>>
{
public:
    typedef grid_base<complex_type, matsubara_grid<Fermion>> base;
    typedef typename base::point point;
    using base::vals_;
    using typename base::ex_wrong_index;
    //typedef typename grid_base<complex_type, matsubara_grid<Fermion>>::point point;
    //using typename grid_base<complex_type, matsubara_grid<Fermion>>::point;
    /** Inverse temperature. */
    const real_type beta_;
    /** Spacing between values. */
    const real_type spacing_;
    /** Min and max numbers of freq. - useful for searching. */
    const int w_min_, w_max_;
    matsubara_grid(int min, int max, real_type beta);
    matsubara_grid(const matsubara_grid &rhs);
    matsubara_grid(matsubara_grid&& rhs);
    matsubara_grid(std::vector<complex_type> const& in);
    int getNumber(complex_type in) const;
    double beta() const { return beta_; }
    int min_n() const { return w_min_; }
    int max_n() const { return w_max_; }

    point find_nearest(complex_type in) const;
    template <class Obj> auto integrate(const Obj &in) const -> decltype(in(vals_[0]));
    template <class Obj> auto prod(const Obj &in) const -> decltype(in(vals_[0]));
    //template <class Obj> auto gridIntegrate(const std::vector<Obj> &in) const -> Obj;
    template <class Obj> auto eval(Obj &in, complex_type x) const ->decltype(in[0]);
    //template <class Obj> auto eval(Obj &in, point x) const ->decltype(in[0]);
    //using base::eval;
};

typedef matsubara_grid<1> fmatsubara_grid;
typedef matsubara_grid<0> bmatsubara_grid;

//
// matsubara_grid implementations
//

template <bool F>
matsubara_grid<F>::matsubara_grid(int min, int max, real_type beta):
    //grid_base<complex_type, matsubara_grid<F>>(min,max,std::bind(Matsubara<F>, std::placeholders::_1, beta)),
    grid_base<complex_type, matsubara_grid<F>>(min,max,[beta](int n){return Matsubara<F>(n,beta);}),
    beta_(beta), 
    spacing_(PI/beta), 
    w_min_(min),
    w_max_(max)
{
}

template <bool F>
matsubara_grid<F>::matsubara_grid(const matsubara_grid<F> &rhs) : 
    grid_base<complex_type, matsubara_grid<F>>(rhs.vals_),
    beta_(rhs.beta_), 
    spacing_(rhs.spacing_), 
    w_min_(rhs.w_min_), 
    w_max_(rhs.w_max_)
{
}

template <bool F>
matsubara_grid<F>::matsubara_grid(matsubara_grid<F>&& rhs):
    grid_base<complex_type, matsubara_grid>(rhs.vals_), 
    beta_(rhs.beta_), 
    spacing_(rhs.spacing_), 
    w_min_(rhs.w_min_), 
    w_max_(rhs.w_max_)
{
}

template <bool F>
matsubara_grid<F>::matsubara_grid(std::vector<complex_type> const& in):
    base(in),
    beta_( PI / std::abs((in[1] - in[0])/2.) ),
    spacing_(std::abs((in[1] - in[0])/2.)),
    w_min_(MatsubaraIndex<F>(in[0], beta_)),
    w_max_(MatsubaraIndex<F>(in[in.size() - 1], beta_))
{
}

template <bool F>
template <class Obj> 
auto matsubara_grid<F>::integrate(const Obj &in) const -> decltype(in(vals_[0]))
{
    decltype(in(this->vals_[0])) R = in(this->vals_[0]);
    R=std::accumulate(vals_.begin()+1, vals_.end(), R,[&](decltype(in(vals_[0]))& y,decltype(vals_[0]) &x) {return y+in(x);}); 
    return R/beta_;
}

{'fraction_non_alphanumeric': 0.1522260058014882, 'fraction_numerical': 0.007062681296506495, 'mean_word_length': 5.156832298136646, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '210183', 'n_tokens_mistral': 3050, 'n_tokens_neox': 2944, 'n_words': 600}