histogram.c

filter: Statementstmt 96.1% 250 / 260 Branchbran 80.4% 103 / 128 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 90.9% 353 / 388 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« histogram_agg.c ↑ Summary XS/bins.xs »
1 #include "histogram.h"
2  
3  
4 simple_histo_1d*
5 24 histo_alloc_new_fixed_bins(pTHX_ unsigned int nbins, double min, double max)
6 {
7 simple_histo_1d* rv;
8 24 ▶ if (min == max)
Branch: 1 branch
BranchTrueFalseTotal
if (min == max) 0 24 24
9 0 croak("histogram width cannot be 0");
10 24 ▶ else if (nbins == 0)
Branch: 1 branch
BranchTrueFalseTotal
else if (nbins == 0) 0 24 24
11 0 croak("Cannot create histogram with 0 bins");
12  
13 24 Newx(rv, 1, simple_histo_1d);
14 24 ▶ if (rv == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rv == 0) 0 24 24
15 0 croak("unable to malloc simple_histo_1d");
16  
17 24 ▶ if (min > max) {
Branch: 1 branch
BranchTrueFalseTotal
if (min > max) { 0 24 24
18 double tmp = min;
19 min = max;
20 max = tmp;
21 }
22 24 rv->nbins = nbins;
23 24 rv->min = min;
24 24 rv->max = max;
25 24 rv->width = max-min;
26 24 rv->binsize = rv->width/(double)nbins;
27 24 rv->overflow = 0.;
28 24 rv->underflow = 0.;
29 24 rv->total = 0.;
30 24 rv->nfills = 0;
31 24 rv->bins = 0;
32 24 rv->cumulative_hist = 0;
33 24 Newxz(rv->data, (int)rv->nbins, double);
34 24 return rv;
35 }
36  
37  
38 simple_histo_1d*
39 35 histo_clone(pTHX_ simple_histo_1d* src, bool empty)
40 {
41 simple_histo_1d* clone;
42 35 unsigned int n = src->nbins;
43  
44 35 Newx(clone, 1, simple_histo_1d);
45 35 clone->cumulative_hist = 0;
46  
47 35 ▶ if (src->bins != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->bins != NULL) { 9 26 35
48 9 Newx(clone->bins, n+1, double);
49 9 Copy(src->bins, clone->bins, n+1, double);
50 }
51 else
52 26 clone->bins = NULL;
53  
54 35 ▶ if (!empty) {
Branch: 1 branch
BranchTrueFalseTotal
if (!empty) { 33 2 35
55 33 Newx(clone->data, n, double);
56 33 Copy(src->data, clone->data, n, double);
57  
58 33 clone->nfills = src->nfills;
59 33 clone->overflow = src->overflow;
60 33 clone->underflow = src->underflow;
61 33 clone->total = src->total;
62 }
63 else {
64 2 Newxz(clone->data, n, double); /* zero it all */
65 2 clone->nfills = 0.;
66 2 clone->overflow = 0.;
67 2 clone->underflow = 0.;
68 2 clone->total = 0.;
69 }
70  
71 35 clone->nbins = n;
72 35 clone->min = src->min;
73 35 clone->max = src->max;
74 35 clone->width = src->width;
75 35 clone->binsize = src->binsize;
76  
77 35 return clone;
78 }
79  
80  
81 unsigned int
82 2536 find_bin_nonconstant(double x, unsigned int nbins, double* bins)
83 {
84 /* TODO optimize */
85 unsigned int mid;
86 double mid_val;
87 unsigned int imin = 0;
88 unsigned int imax = nbins;
89 while (1) {
90 8776 mid = imin + (imax-imin)/2;
91 8776 mid_val = bins[mid];
92 8776 ▶ if (mid_val == x)
Branch: 1 branch
BranchTrueFalseTotal
if (mid_val == x) 25 8751 8776
93 25 return mid;
94 8751 ▶ else if (mid_val > x) {
Branch: 1 branch
BranchTrueFalseTotal
else if (mid_val > x) { 3272 5479 8751
95 3272 ▶ if (mid == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (mid == 0) 3272 0 3272
96 return 0;
97 3272 imax = mid-1;
98 3272 ▶ if (imin > imax)
Branch: 1 branch
BranchTrueFalseTotal
if (imin > imax) 1220 2052 3272
99 2052 return mid-1;
100 }
101 else {
102 5479 imin = mid+1;
103 5479 ▶ if (imin > imax)
Branch: 1 branch
BranchTrueFalseTotal
if (imin > imax) 5020 459 5479
104 459 return imin-1;
105 }
106 }
107 }
108  
109 /* These are left in for later optimization/testing */
110 /*
111 STATIC
112 unsigned int
113 histo_find_bin_nonconstant_internal2(double x, unsigned int nbins, double* bins)
114 {
115 unsigned int imin = 0;
116 unsigned int imax = nbins;
117 unsigned int i = (unsigned int)(imax/2);
118 while (1) {
119 if (bins[i] >= x)
120 imax = i;
121 else {
122 imin = i + (bins[i+1] == x);
123 if (bins[i+1] >= x)
124 break;
125 }
126 if (imin == imax)
127 break;
128 i = (unsigned int) ((imax+imin)/2);
129 }
130 return imin;
131 }
132 */
133  
134  
135 /*
136 STATIC
137 unsigned int
138 histo_find_bin_nonconstant_internal3(double x, unsigned int nbins, double* bins)
139 {
140 unsigned int mid;
141 double mid_val;
142 unsigned int imin = 0;
143 unsigned int imax = nbins;
144 while (imin <= imax) {
145 mid = imin + (imax-imin)/2;
146 mid_val = bins[mid];
147  
148 if (mid_val < x) {
149 imin = mid + 1;
150 }
151 else if (mid_val > x) {
152 imax = mid - 1;
153 }
154 else {
155 return mid;
156 }
157 }
158 return 0;
159 }
160 */
161  
162  
163  
164 simple_histo_1d*
165 2 histo_clone_from_bin_range(pTHX_ simple_histo_1d* src, bool empty,
166 unsigned int bin_start, unsigned int bin_end)
167 {
168 simple_histo_1d* clone;
169 2 unsigned int i, n = src->nbins;
170 2 unsigned int nbinsnew = bin_end-bin_start+1;
171 2 ▶ if (bin_start > bin_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (bin_start > bin_end) { 0 2 2
172 i = bin_end;
173 bin_end = bin_start;
174 bin_start = i;
175 }
176 2 ▶ if (bin_end >= n)
Branch: 1 branch
BranchTrueFalseTotal
if (bin_end >= n) 0 2 2
177 0 bin_end = n-1;
178  
179 2 Newx(clone, 1, simple_histo_1d);
180 2 clone->cumulative_hist = 0;
181 2 Newx(clone->data, nbinsnew, double);
182 2 clone->nbins = nbinsnew;
183  
184 2 ▶ if (!empty) {
Branch: 1 branch
BranchTrueFalseTotal
if (!empty) { 1 1 2
185 1 clone->nfills = src->nfills;
186 1 clone->underflow = src->underflow;
187 1 clone->overflow = src->overflow;
188 1 clone->total = 0.;
189  
190 3 ▶ for (i = 0; i < bin_start; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bin_start; ++i) 2 1 3
191 2 clone->underflow += src->data[i];
192  
193 5 ▶ for (i = bin_start; i <= bin_end; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = bin_start; i <= bin_end; ++i) { 4 1 5
194 4 clone->data[i-bin_start] = src->data[i];
195 4 clone->total += src->data[i];
196 }
197  
198 5 ▶ for (i = bin_end+1; i < n; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = bin_end+1; i < n; ++i) 4 1 5
199 4 clone->overflow += src->data[i];
200 }
201 else { /* empty */
202 1 clone->nfills = 0.;
203 1 clone->overflow = 0.;
204 1 clone->underflow = 0.;
205 1 clone->total = 0.;
206 }
207  
208 2 clone->binsize = src->binsize;
209 2 ▶ if (src->bins == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->bins == 0) { 2 0 2
210 2 clone->bins = 0;
211 2 clone->min = src->min + (double)bin_start * clone->binsize;
212 2 clone->max = src->max - (double)(n - bin_end -1) * clone->binsize;
213 }
214 else {
215 double *bins_start;
216 0 Newx(clone->bins, nbinsnew+1, double);
217 0 bins_start = src->bins + bin_start;
218 Copy(bins_start, clone->bins, nbinsnew+1, double);
219 0 clone->min = clone->bins[0];
220 0 clone->max = clone->bins[nbinsnew];
221 }
222 2 clone->width = clone->max - clone->min;
223  
224 2 return clone;
225 }
226  
227  
228 unsigned int
229 77 histo_find_bin(simple_histo_1d* self, double x)
230 {
231 77 ▶ if (self->bins == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (self->bins == NULL) { 4 73 77
232 4 return( (x-self->min) / self->binsize );
233 }
234 else {
235 73 return find_bin_nonconstant(x, self->nbins, self->bins);
236 }
237 }
238  
239  
240 void
241 4059 histo_fill(simple_histo_1d* self, unsigned int n, const double* x_in, const double* w_in)
242 {
243 unsigned int i;
244 4059 double min = self->min, max = self->max, binsize = self->binsize, x;
245 4059 double *data = self->data;
246 4059 double *bins = self->bins;
247  
248 4059 ▶ HS_INVALIDATE_CUMULATIVE(self);
Branch: 2 branches
BranchTrueFalseTotal
HS_INVALIDATE_CUMULATIVE(self); 2 4057 4059
HS_INVALIDATE_CUMULATIVE(self); 0 2 2
249  
250 /* Code duplication for performance */
251 #define HANDLE_OVERFLOW \
252 if (UNLIKELY( x >= max )) { \
253 self->overflow += w; \
254 continue; \
255 } \
256 else if (UNLIKELY( x < min )) { \
257 self->underflow += w; \
258 continue; \
259 }
260  
261 4059 ▶ if (w_in == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (w_in == NULL) { 23 4036 4059
262 const double w = 1;
263 23 ▶ if (bins == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bins == NULL) { 22 1 23
264 45 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 23 22 45
265 23 self->nfills++;
266 23 x = x_in[i];
267  
268 23 ▶ HANDLE_OVERFLOW
Branch: 2 branches
BranchTrueFalseTotal
HANDLE_OVERFLOW 2 21 23
HANDLE_OVERFLOW 3 18 21
269  
270 18 self->total += w;
271 18 data[(int)((x-min)/binsize)] += w;
272 }
273 }
274 else {
275 8 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 7 1 8
276 7 self->nfills++;
277 7 x = x_in[i];
278  
279 7 ▶ HANDLE_OVERFLOW
Branch: 2 branches
BranchTrueFalseTotal
HANDLE_OVERFLOW 1 6 7
HANDLE_OVERFLOW 2 4 6
280  
281 4 self->total += w;
282 4 data[find_bin_nonconstant(x, self->nbins, self->bins)] += w;
283 }
284 }
285 }
286 else {
287 double w;
288 4036 ▶ if (bins == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bins == NULL) { 2029 2007 4036
289 604054 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 602025 2029 604054
290 602025 self->nfills++;
291 602025 x = x_in[i];
292 602025 w = w_in[i];
293  
294 602025 ▶ HANDLE_OVERFLOW
Branch: 2 branches
BranchTrueFalseTotal
HANDLE_OVERFLOW 2 602023 602025
HANDLE_OVERFLOW 1 602022 602023
295  
296 602022 self->total += w;
297 602022 data[(int)((x-min)/binsize)] += w;
298 }
299 }
300 else {
301 4014 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 2007 2007 4014
302 2007 self->nfills++;
303 2007 x = x_in[i];
304 2007 w = w_in[i];
305  
306 2007 ▶ HANDLE_OVERFLOW
Branch: 2 branches
BranchTrueFalseTotal
HANDLE_OVERFLOW 1 2006 2007
HANDLE_OVERFLOW 1 2005 2006
307  
308 2005 self->total += w;
309 2005 data[find_bin_nonconstant(x, self->nbins, self->bins)] += w;
310 }
311 }
312 }
313 #undef HANDLE_OVERFLOW
314 4059 }
315  
316  
317 void
318 6 histo_fill_by_bin(simple_histo_1d* self, const unsigned int n, const int* ibin_in, const double* w_in)
319 {
320 unsigned int i;
321 int ibin;
322 double w;
323 6 double *data = self->data;
324 6 const int nbins = (int)self->nbins;
325  
326 6 ▶ HS_INVALIDATE_CUMULATIVE(self);
Branch: 2 branches
BranchTrueFalseTotal
HS_INVALIDATE_CUMULATIVE(self); 0 6 6
HS_INVALIDATE_CUMULATIVE(self); 0 0 0
327  
328 14 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 8 6 14
329 8 self->nfills++;
330 8 ibin = ibin_in[i];
331  
332 8 ▶ if (w_in == NULL) w = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (w_in == NULL) w = 1; 4 4 8
333 4 else w = w_in[i];
334  
335 8 ▶ if (ibin < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ibin < 0) { 1 7 8
336 1 self->underflow += w;
337 1 continue;
338 }
339 7 ▶ else if (ibin >= nbins) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ibin >= nbins) { 1 6 7
340 1 self->overflow += w;
341 1 continue;
342 }
343  
344 6 self->total += w;
345 6 data[ibin] += w;
346 }
347 6 }
348  
349  
350  
351 simple_histo_1d*
352 18 histo_cumulative(pTHX_ simple_histo_1d* src, double prenormalization)
353 {
354 unsigned int i, nbins;
355 simple_histo_1d* cum;
356 double* cum_data;
357 double total;
358  
359 18 nbins = src->nbins;
360 18 cum = histo_clone(aTHX_ src, 0);
361  
362 18 ▶ if (prenormalization <= 0.) {
Branch: 1 branch
BranchTrueFalseTotal
if (prenormalization <= 0.) { 2 16 18
363 2 cum_data = cum->data;
364 2 total = cum_data[0];
365  
366 205 ▶ for (i = 1; i < nbins; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < nbins; ++i) { 203 2 205
367 203 cum_data[i] += cum_data[i-1];
368 203 total += cum_data[i];
369 }
370 }
371 else {
372 16 cum_data = cum->data;
373 16 prenormalization = prenormalization/cum->total;
374 16 cum_data[0] *= prenormalization;
375 total = cum_data[0];
376  
377 1000615 ▶ for (i = 1; i < nbins; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < nbins; ++i) { 1000599 16 1000615
378 1000599 cum_data[i] = cum_data[i]*prenormalization + cum_data[i-1];
379 1000599 total += cum_data[i];
380 }
381 }
382 18 cum->total = total;
383  
384 18 return cum;
385 }
386  
387  
388 void
389 4 histo_multiply_constant(simple_histo_1d* self, double constant)
390 {
391 unsigned int i, n;
392 double * data;
393 4 ▶ HS_INVALIDATE_CUMULATIVE(self); /* Rescaling invalidates the cache. */
Branch: 2 branches
BranchTrueFalseTotal
HS_INVALIDATE_CUMULATIVE(self); /* Rescaling invalidates the cache. */ 0 4 4
HS_INVALIDATE_CUMULATIVE(self); /* Rescaling invalidates the cache. */ 0 0 0
394 4 n = self->nbins;
395 4 data = self->data;
396 229 ▶ for (i = 0; i < n; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) 225 4 229
397 225 data[i] *= constant;
398 4 self->total *= constant;
399 4 self->overflow *= constant;
400 4 self->underflow *= constant;
401 4 }
402  
403 #define MY_FLOAT_EQ_EPS(a, b, eps) ((a) + (eps) > (b) && (a) - (eps) < (b))
404 #define MY_FLOAT_EQ(a, b) (MY_FLOAT_EQ_EPS(a, b, 1.e-9))
405  
406 #define MY_FLOAT_NE_EPS(a, b, eps) ((a) + (eps) <= (b) || (a) - (eps) >= (b))
407 #define MY_FLOAT_NE(a, b) (MY_FLOAT_NE_EPS(a, b, 1.e-9))
408  
409 STATIC bool S_histogram_bin_equality(simple_histo_1d *h1, simple_histo_1d *h2)
410 {
411 if (h1->bins == NULL) {
412 /* fixed bins */
413 if ( h2->bins != NULL
414 || h1->nbins != h2->nbins
415 || MY_FLOAT_NE(h1->min, h2->min)
416 || MY_FLOAT_NE(h1->max, h2->max) )
417 {
418 return 0;
419 }
420 }
421 else { /* variable bins */
422 double *dh1;
423 double *dh2;
424 unsigned int i;
425 const unsigned int n = h1->nbins;
426  
427 if ( h2->bins == NULL || n != h2->nbins)
428 return 0;
429  
430 dh1 = h1->bins;
431 dh2 = h2->bins;
432  
433 for (i = 0; i < n; ++i) {
434 if (MY_FLOAT_NE(dh1[i], dh2[i]))
435 return 0;
436 }
437 }
438 }
439  
440  
441 STATIC bool
442 4 S_add_sub_histogram(simple_histo_1d* target, simple_histo_1d* to_add, double factor)
443 {
444 unsigned int i;
445 double *d_target;
446 double *d_to_add;
447  
448 4 const unsigned int n = target->nbins;
449  
450 S_histogram_bin_equality(target, to_add);
451  
452 /* Adding histograms invalidates the cache. */
453 4 ▶ HS_INVALIDATE_CUMULATIVE(target);
Branch: 2 branches
BranchTrueFalseTotal
HS_INVALIDATE_CUMULATIVE(target); 0 4 4
HS_INVALIDATE_CUMULATIVE(target); 0 0 0
454  
455 4 d_target = target->data;
456 4 d_to_add = to_add->data;
457  
458 44 ▶ for (i = 0; i < n; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) 40 4 44
459 40 d_target[i] += d_to_add[i] * factor;
460  
461 4 target->total += to_add->total * factor;
462 4 target->overflow += to_add->overflow * factor;
463 4 target->underflow += to_add->underflow * factor;
464 4 target->nfills += to_add->nfills;
465  
466 4 return 1;
467 }
468  
469  
470 bool
471 2 histo_add_histogram(simple_histo_1d* target, simple_histo_1d* to_add)
472 {
473 2 return S_add_sub_histogram(target, to_add, 1.);
474 }
475  
476  
477 bool
478 2 histo_subtract_histogram(simple_histo_1d* target, simple_histo_1d* to_subtract)
479 {
480 2 return S_add_sub_histogram(target, to_subtract, -1.);
481 }
482  
483  
484 bool
485 1 histo_multiply_histogram(simple_histo_1d* target, simple_histo_1d* to_multiply)
486 {
487 unsigned int i;
488 double *d_target;
489 double *d_to_multiply;
490  
491 1 const unsigned int n = target->nbins;
492  
493 S_histogram_bin_equality(target, to_multiply);
494  
495 /* Adding histograms invalidates the cache. */
496 1 ▶ HS_INVALIDATE_CUMULATIVE(target);
Branch: 2 branches
BranchTrueFalseTotal
HS_INVALIDATE_CUMULATIVE(target); 0 1 1
HS_INVALIDATE_CUMULATIVE(target); 0 0 0
497  
498 1 d_target = target->data;
499 1 d_to_multiply = to_multiply->data;
500  
501 1 target->total = 0.;
502 11 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 10 1 11
503 10 d_target[i] *= d_to_multiply[i];
504 10 target->total += d_target[i];
505 }
506  
507 1 target->overflow *= to_multiply->overflow;
508 1 target->underflow *= to_multiply->underflow;
509 1 target->nfills += to_multiply->nfills;
510  
511 1 return 1;
512 }
513  
514  
515 bool
516 1 histo_divide_histogram(simple_histo_1d* target, simple_histo_1d* to_divide)
517 {
518 unsigned int i;
519 double *d_target;
520 double *d_to_divide;
521  
522 1 const unsigned int n = target->nbins;
523  
524 S_histogram_bin_equality(target, to_divide);
525  
526 /* Adding histograms invalidates the cache. */
527 1 ▶ HS_INVALIDATE_CUMULATIVE(target);
Branch: 2 branches
BranchTrueFalseTotal
HS_INVALIDATE_CUMULATIVE(target); 0 1 1
HS_INVALIDATE_CUMULATIVE(target); 0 0 0
528  
529 1 d_target = target->data;
530 1 d_to_divide = to_divide->data;
531  
532 1 target->total = 0.;
533 11 ▶ for (i = 0; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; ++i) { 10 1 11
534 10 d_target[i] /= d_to_divide[i];
535 10 target->total += d_target[i];
536 }
537  
538 1 target->overflow /= to_divide->overflow;
539 1 target->underflow /= to_divide->underflow;
540 1 target->nfills += to_divide->nfills;
541  
542 1 return 1;
543 }
544  
545  
546 simple_histo_1d*
547 5 histo_rebin(pTHX_ simple_histo_1d* self, unsigned int rebin_factor)
548 {
549 5 unsigned int nbins_in = self->nbins;
550 simple_histo_1d* out = NULL;
551 5 unsigned int nbins_out = nbins_in / rebin_factor;
552 5 ▶ if ((nbins_in % rebin_factor) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((nbins_in % rebin_factor) != 0) 2 3 5
553 return out;
554  
555 3 ▶ if (self->bins == NULL) { /* fixed bins */
Branch: 1 branch
BranchTrueFalseTotal
if (self->bins == NULL) { /* fixed bins */ 2 1 3
556 unsigned int i;
557 unsigned int j;
558 unsigned int end;
559 2 out = histo_alloc_new_fixed_bins(aTHX_ nbins_out, self->min, self->max);
560 112 ▶ for (i = 0; i < nbins_out; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nbins_out; ++i) { 110 2 112
561 double content = 0.;
562 110 end = rebin_factor*(i+1);
563 410 ▶ for (j = rebin_factor*i; j < end; ++j)
Branch: 1 branch
BranchTrueFalseTotal
for (j = rebin_factor*i; j < end; ++j) 300 110 410
564 300 content += self->data[j];
565 110 out->data[i] = content;
566 }
567 }
568 else {
569 unsigned int i;
570 unsigned int j;
571 unsigned int end;
572 double* bins_ary;
573 /* FIXME duplicated from XS/construction.xs -- needs refactoring */
574 1 Newx(out, 1, simple_histo_1d);
575 1 ▶ if( out == NULL ){
Branch: 1 branch
BranchTrueFalseTotal
if( out == NULL ){ 0 1 1
576 0 warn("unable to malloc simple_histo_1d");
577 0 return NULL;
578 }
579  
580 1 out->nbins = nbins_out;
581 1 Newx(bins_ary, nbins_out+1, double);
582 1 out->bins = bins_ary;
583 1 Newxz(out->data, (int)nbins_out, double);
584  
585 1 bins_ary[0] = self->bins[0];
586 3 ▶ for (i = 0; i < nbins_out; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nbins_out; ++i) { 2 1 3
587 double content = 0.;
588 2 end = rebin_factor*(i+1);
589 8 ▶ for (j = rebin_factor*i; j < end; ++j)
Branch: 1 branch
BranchTrueFalseTotal
for (j = rebin_factor*i; j < end; ++j) 6 2 8
590 6 content += self->data[j];
591 2 out->data[i] = content;
592 2 bins_ary[i+1] = self->bins[ end ];
593 }
594  
595 1 out->min = self->min;
596 1 out->max = self->max;
597 1 out->width = out->max - out->min;
598 1 out->binsize = 0.;
599 1 out->cumulative_hist = 0;
600 }
601  
602 3 out->overflow = self->overflow;
603 3 out->underflow = self->underflow;
604 3 out->total = self->total;
605 3 out->nfills = self->nfills;
606  
607 3 return out;
608 }
« histogram_agg.c ↑ Summary XS/bins.xs »