28#define Vec3d Eigen::Vector3d
29#define Vec2d Eigen::Vector2d
32#define ERROR(format, ...) fprintf (stderr, "E: " format, ##__VA_ARGS__)
48 double* targetbins =
new double[
num_bins];
50 ERROR(
"allocation failed while mpi-reducing histogram.\n");
54 MPI_Allreduce(
bins,targetbins,
num_bins,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
62 void save(
const char* filename)
const;
63 void load(
const char* filename);
64 virtual void saveAscii(
const char* filename)
const;
88 int histogram_bin = value *
num_bins;
90 if(histogram_bin < 0) {
92 }
else if (histogram_bin + 1 >= (ssize_t)
num_bins) {
95 bins[histogram_bin]++;
98 virtual void saveAscii(
const char* filename)
const;
117 int histogram_bin = value *
num_bins;
119 if(histogram_bin < 0) {
121 }
else if (histogram_bin + 1 >= (ssize_t)
num_bins) {
124 bins[histogram_bin]++;
152 ERROR(
"allocation failed while mpi-reducing histogram.\n");
163 void save(
const char* filename)
const;
164 void load(
const char* filename);
190 value = value.cwiseQuotient(
high -
low);
192 int histogram_bin[2];
193 histogram_bin[0] = value[0] *
num_bins[0];
194 histogram_bin[1] = value[1] *
num_bins[1];
196 for(
int i = 0;
i < 2;
i++) {
197 if(histogram_bin[
i] < 0) {
198 histogram_bin[
i] = 0;
199 }
else if (histogram_bin[
i] + 1 >= (ssize_t)
num_bins[
i]) {
203 bins[histogram_bin[0] +
num_bins[0] * histogram_bin[1]] += weight;
209 value = value.cwiseQuotient(
high -
low);
217 a[0] = v[0] -
floor(v[0]);
218 a[1] = v[1] -
floor(v[1]);
240 int histogram_bin[2];
241 histogram_bin[0] =
floor(v[0]);
242 histogram_bin[1] =
floor(v[1]);
244 bins[histogram_bin[0] +
num_bins[0] * histogram_bin[1]] += weight * (1. - a[0]) * (1. - a[1]);
245 bins[histogram_bin[0] +
num_bins[0] * (histogram_bin[1] + 1)] += weight * (1. - a[0]) * a[1];
246 bins[histogram_bin[0] + 1 +
num_bins[0] * histogram_bin[1]] += weight * a[0] * (1. - a[1]);
247 bins[histogram_bin[0] + 1 +
num_bins[0] * (histogram_bin[1] + 1)] += weight * a[0] * a[1];
279 int histogram_bin[2];
280 histogram_bin[0] = v[0] *
num_bins[0];
281 histogram_bin[1] = v[1] *
num_bins[1];
283 for(
int i = 0;
i < 2;
i++) {
284 if(histogram_bin[
i] < 0) {
285 histogram_bin[
i] = 0;
286 }
else if (histogram_bin[
i] + 1 >= (ssize_t)
num_bins[
i]) {
290 bins[histogram_bin[0] +
num_bins[0] * histogram_bin[1]] += weight;
296 v[0] = value[0] -
low[0];
298 v[1] = value[1] /
low[1];
299 v[1] = log(v[1]) / log(
high[1] /
low[1]);
306 a[0] = value[0] -
floor(value[0]);
307 a[1] = value[1] -
floor(value[1]);
329 int histogram_bin[2];
330 histogram_bin[0] =
floor(v[0]);
331 histogram_bin[1] =
floor(v[1]);
333 bins[histogram_bin[0] +
num_bins[0] * histogram_bin[1]] += weight * (1. - a[0]) * (1. - a[1]);
334 bins[histogram_bin[0] +
num_bins[0] * (histogram_bin[1] + 1)] += weight * (1. - a[0]) * a[1];
335 bins[histogram_bin[0] + 1 +
num_bins[0] * histogram_bin[1]] += weight * a[0] * (1. - a[1]);
336 bins[histogram_bin[0] + 1 +
num_bins[0] * (histogram_bin[1] + 1)] += weight * a[0] * a[1];
355 value = value.cwiseQuotient(
low);
358 v[0] = log(value[0]) / log(
high[0] /
low[0]);
359 v[1] = log(value[1]) / log(
high[1] /
low[1]);
361 int histogram_bin[2];
362 histogram_bin[0] = v[0] *
num_bins[0];
363 histogram_bin[1] = v[1] *
num_bins[1];
365 for(
int i = 0;
i < 2;
i++) {
366 if(histogram_bin[
i] < 0) {
367 histogram_bin[
i] = 0;
368 }
else if (histogram_bin[
i] + 1 >= (ssize_t)
num_bins[
i]) {
372 bins[histogram_bin[0] +
num_bins[0] * histogram_bin[1]] += weight;
400 ERROR(
"allocation failed while mpi-reducing histogram.\n");
411 void save(
const char* filename)
const;
412 void load(
const char* filename);
434 value = value.cwiseQuotient(
high -
low);
436 int histogram_bin[3];
437 histogram_bin[0] = value[0] *
num_bins[0];
438 histogram_bin[1] = value[1] *
num_bins[1];
439 histogram_bin[2] = value[2] *
num_bins[2];
441 for(
int i = 0;
i < 3;
i++) {
442 if(histogram_bin[
i] < 0) {
443 histogram_bin[
i] = 0;
444 }
else if (histogram_bin[
i] + 1 >= (ssize_t)
num_bins[
i]) {
453 return low + cell.cwiseQuotient(nx).cwiseProduct(
high -
low);
462 void readBov(
const char* filename);
virtual void saveAscii(const char *filename) const
void save(const char *filename) const
void load(const char *filename)
virtual void addValue(double value)=0
double operator()(int x, int y)
void load(const char *filename)
void save(const char *filename) const
virtual void addValue(Vec2d value, double weight=1.)=0
double operator()(int x, int y, int z)
void load(const char *filename)
virtual void addValue(Vec3d value)=0
void save(const char *filename) const
void addValueLinearInterpolate(Vec2d value, double weight=1.)
LinLogHistogram2D(size_t n[2], Vec2d _low, Vec2d _high)
virtual void addValue(Vec2d value, double weight=1.)
virtual void addValue(double value)
virtual void saveAscii(const char *filename) const
LinearHistogram1D(size_t n, double _low, double _high)
LinearHistogram2D(size_t n[2], Vec2d _low, Vec2d _high)
void addValueLinearInterpolate(Vec2d value, double weight=1.)
void operator+=(LinearHistogram2D &other)
virtual void addValue(Vec2d value, double weight=1.)
void operator-=(LinearHistogram2D &other)
void writeBovAscii(const char *filename, int index, const char *datafilename)
LinearHistogram2D(size_t nx, size_t ny, Vec2d _low, Vec2d _high)
void operator-=(LinearHistogram3D &other)
LinearHistogram3D(size_t n[3], Vec3d _low, Vec3d _high)
void readBov(const char *filename)
virtual void addValue(Vec3d value)
void writeBovAscii(const char *filename, int index, const char *datafilename)
void operator+=(LinearHistogram3D &other)
Vec3d coords_for_cell(Vec3d cell)
LogHistogram1D(size_t n, double _low, double _high)
virtual void addValue(double value)
void operator-=(LogHistogram2D &other)
virtual void addValue(Vec2d value, double weight=1.)
void operator+=(LogHistogram2D &other)
LogHistogram2D(size_t n[2], Vec2d _low, Vec2d _high)
#define ERROR(format,...)
static ARCH_HOSTDEV VecSimple< T > floor(VecSimple< T > const &a)