41namespace triqs::stat {
99 histogram(
double a,
double b, std::size_t nbins);
133 auto size()
const {
return data_.size(); }
139 C2PY_PROPERTY_GET(
limits)
auto limits()
const {
return std::pair{a_, b_}; }
145 C2PY_PROPERTY_GET(
data)
auto const &
data()
const {
return data_; }
187 mpi::broadcast(h.a_, c, root);
188 mpi::broadcast(h.b_, c, root);
189 mpi::broadcast(h.data_, c, root);
190 mpi::broadcast(h.n_data_pts_, c, root);
191 mpi::broadcast(h.n_lost_pts_, c, root);
192 if (c.rank() != root) h.initialize();
210 mpi::reduce_into(h.data_, h2.data_, c, root, all, MPI_SUM);
211 h2.n_data_pts_ = mpi::reduce(h.n_data_pts_, c, root, all, MPI_SUM);
212 h2.n_lost_pts_ = mpi::reduce(h.n_lost_pts_, c, root, all, MPI_SUM);
217 [[nodiscard]]
static std::string
hdf5_format() {
return "Histogram"; }
250 void serialize(
auto &ar)
const { ar & a_ & b_ & n_data_pts_ & n_lost_pts_ & data_ & binsize_; }
256 void deserialize(
auto &ar) { ar & a_ & b_ & n_data_pts_ & n_lost_pts_ & data_ & binsize_; }
289 for (
int i = 1; i < h.
size(); ++i)
cdf.data_[i] +=
cdf.data_[i - 1];
301 double binsize_{0.0};
302 std::uint64_t n_data_pts_{0};
303 std::uint64_t n_lost_pts_{0};
304 nda::vector<double> data_{};
Backward-compatibility umbrella header pulling in the nda array library.
Class representing a histogram on a given interval.
friend void h5_write(h5::group g, std::string const &name, histogram const &h)
Write a triqs::stat::histogram to HDF5.
friend histogram cdf(histogram const &h)
Normalize and integrate a histogram.
friend histogram operator+(histogram h1, histogram const &h2)
Add two histograms together.
friend void mpi_broadcast(histogram &h, mpi::communicator c={}, int root=0)
Implementation of an MPI broadcast for triqs::stat::histogram.
friend void h5_read(h5::group g, std::string const &name, histogram &h)
Read a triqs::stat::histogram from HDF5.
bool operator==(histogram const &h) const =default
Default equal-to operator compares the domains, data vectors, number of accumulated and discarded dat...
auto n_data_pts() const
Get the number of data points that have been added to the histogram.
auto mesh_point(int n) const
Get the position of the center of the n-th bin.
static std::string hdf5_format()
Get the HDF5 format tag.
void serialize(auto &ar) const
Serialize the histogram to an archive.
friend histogram mpi_reduce(histogram const &h, mpi::communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for triqs::stat::histogram.
histogram()=default
Default constructor leaves the histogram in a valid but unusable state.
auto const & data() const
Get the data stored in the histogram.
void deserialize(auto &ar)
Deserialize the histogram from an archive.
auto n_lost_pts() const
Get the number of data points that fell outside of the interval and were discarded.
void clear()
Reset the histogram to its initial state, i.e. with no data points added to it.
friend histogram pdf(histogram const &h)
Normalize a histogram.
auto limits() const
Get the domain on which the histogram is defined.
histogram & operator<<(double x)
Add a data point to the histogram.
auto size() const
Get number of bins in the histogram.
TRIQS exception hierarchy and related macros.
#define TRIQS_ASSERT(X)
Throw a triqs::runtime_error if the boolean expression X evaluates to false.