Histo.xs

filter: Statementstmt 71.1% 664 / 933 Branchbran 41.1% 427 / 1038 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 55.3% 1091 / 1971 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Math/Histo/Sketch.pm ↑ Summary blib/lib/Math/Histo/CLI.pm »
1 /*
2 * Perl XS extension module bridging libhisto C APIs to Perl Math::Histo.
3 */
4  
5 #define PERL_NO_GET_CONTEXT
6 #include "EXTERN.h"
7 #include "perl.h"
8 #include "XSUB.h"
9 #include "ppport.h"
10  
11 #include <histo/histo.h>
12 #include <histo/histo2d.h>
13 #include <histo/fit.h>
14 #include <histo/kde.h>
15 #include <histo/sketch.h>
16 #include <histo/cli.h>
17 #include <histo/types.h>
18 #include <histo/version.h>
19  
20 3 static int histo_xs_cli_capture(pTHX_ int argc, char **argv, char **out_buf_p, size_t *out_sz_p, char **err_buf_p, size_t *err_sz_p) {
21 3 char *out_buf = NULL;
22 3 size_t out_sz = 0;
23 3 char *err_buf = NULL;
24 3 size_t err_sz = 0;
25  
26 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L && !defined(_WIN32)
27 3 FILE *out_f = open_memstream(&out_buf, &out_sz);
28 3 FILE *err_f = open_memstream(&err_buf, &err_sz);
29 #else
30 FILE *out_f = tmpfile();
31 FILE *err_f = tmpfile();
32 #endif
33  
34 3 ▶ if (!out_f || !err_f) {
Branch: 2 branches
BranchTrueFalseTotal
if (!out_f || !err_f) { 3 0 3
if (!out_f || !err_f) { 0 3 3
35 0 ▶ if (out_f) fclose(out_f);
Branch: 1 branch
BranchTrueFalseTotal
if (out_f) fclose(out_f); 0 0 0
36 0 ▶ if (err_f) fclose(err_f);
Branch: 1 branch
BranchTrueFalseTotal
if (err_f) fclose(err_f); 0 0 0
37 0 return -1;
38 }
39  
40 3 int code = histo_cli_main(argc, argv, out_f, err_f);
41  
42 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L && !defined(_WIN32)
43 3 fclose(out_f);
44 3 fclose(err_f);
45 #else
46 fflush(out_f);
47 fflush(err_f);
48 fseek(out_f, 0, SEEK_END);
49 long o_len = ftell(out_f);
50 fseek(out_f, 0, SEEK_SET);
51 if (o_len > 0) {
52 out_sz = (size_t)o_len;
53 out_buf = (char *)malloc(out_sz + 1);
54 if (out_buf) {
55 size_t read_bytes = fread(out_buf, 1, out_sz, out_f);
56 out_buf[read_bytes] = '\0';
57 out_sz = read_bytes;
58 }
59 }
60 fclose(out_f);
61  
62 fseek(err_f, 0, SEEK_END);
63 long e_len = ftell(err_f);
64 fseek(err_f, 0, SEEK_SET);
65 if (e_len > 0) {
66 err_sz = (size_t)e_len;
67 err_buf = (char *)malloc(err_sz + 1);
68 if (err_buf) {
69 size_t read_bytes = fread(err_buf, 1, err_sz, err_f);
70 err_buf[read_bytes] = '\0';
71 err_sz = read_bytes;
72 }
73 }
74 fclose(err_f);
75 #endif
76  
77 3 *out_buf_p = out_buf;
78 3 *out_sz_p = out_sz;
79 3 *err_buf_p = err_buf;
80 3 *err_sz_p = err_sz;
81 3 return code;
82 }
83  
84  
85 MODULE = Math::Histo PACKAGE = Math::Histo PREFIX = histo_xs_
86  
87 PROTOTYPES: DISABLE
88  
89 const char *
90 libhisto_version()
91 CODE:
92 0 RETVAL = HISTO_VERSION_STRING;
93 OUTPUT:
94 RETVAL
95  
96 histo_t *
97 _create_uniform(CLASS, uint32_t nbins, double min, double max, uint32_t flags=0)
98 char *CLASS
99 CODE:
100 (void)CLASS;
101 1023 RETVAL = histo_create_uniform(nbins, min, max, flags);
102 1023 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 1023 1023
103 0 croak("Math::Histo: failed to create uniform histogram (invalid parameters)");
104 }
105 OUTPUT:
106 RETVAL
107  
108 histo_t *
109 _create_variable(CLASS, SV *edges_ref, uint32_t flags=0)
110 char *CLASS
111 CODE:
112 (void)CLASS;
113 1 ▶ if (!SvROK(edges_ref) || SvTYPE(SvRV(edges_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(edges_ref) || SvTYPE(SvRV(edges_ref)) != SVt_PVAV) { 1 0 1
if (!SvROK(edges_ref) || SvTYPE(SvRV(edges_ref)) != SVt_PVAV) { 0 1 1
114 0 croak("Math::Histo: edges must be an array reference of numbers");
115 }
116 1 AV *av = (AV*)SvRV(edges_ref);
117 1 SSize_t n_edges = av_top_index(av) + 1;
118 1 ▶ if (n_edges < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (n_edges < 2) { 0 1 1
119 0 croak("Math::Histo: variable binning requires at least 2 edges");
120 }
121 1 double *edges = (double*)malloc((size_t)n_edges * sizeof(double));
122 1 ▶ if (!edges) {
Branch: 1 branch
BranchTrueFalseTotal
if (!edges) { 0 1 1
123 0 croak("Math::Histo: memory allocation failure");
124 }
125 {
126 SSize_t i;
127 6 ▶ for (i = 0; i < n_edges; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n_edges; i++) { 5 1 6
128 5 SV **item = av_fetch(av, i, 0);
129 5 ▶ edges[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
edges[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0; 5 0 5
edges[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0; 5 0 5
130 }
131 }
132 1 RETVAL = histo_create_variable((uint32_t)(n_edges - 1), edges, flags);
133 1 free(edges);
134 1 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 1 1
135 0 croak("Math::Histo: failed to create variable histogram (edges must be strictly monotonically increasing)");
136 }
137 OUTPUT:
138 RETVAL
139  
140 histo_t *
141 _create_auto(CLASS, SV *samples_ref, int rule=0, uint32_t flags=0)
142 char *CLASS
143 CODE:
144 (void)CLASS;
145 6 ▶ if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) { 6 0 6
if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) { 0 6 6
146 0 croak("Math::Histo: samples must be an array reference of numbers");
147 }
148 6 AV *av = (AV*)SvRV(samples_ref);
149 6 SSize_t n = av_top_index(av) + 1;
150 6 ▶ if (n < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (n < 1) { 0 6 6
151 0 croak("Math::Histo: auto binning requires at least 1 sample");
152 }
153 6 double *vals = (double*)malloc((size_t)n * sizeof(double));
154 6 ▶ if (!vals) {
Branch: 1 branch
BranchTrueFalseTotal
if (!vals) { 0 6 6
155 0 croak("Math::Histo: memory allocation failure");
156 }
157 {
158 SSize_t i;
159 1806 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 1800 6 1806
160 1800 SV **item = av_fetch(av, i, 0);
161 1800 ▶ vals[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
vals[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0; 1800 0 1800
vals[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0; 1800 0 1800
162 }
163 }
164 6 RETVAL = histo_create_auto((size_t)n, vals, (histo_bin_rule_t)rule, flags);
165 6 free(vals);
166 6 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 6 6
167 0 croak("Math::Histo: failed to create auto histogram");
168 }
169 OUTPUT:
170 RETVAL
171  
172 void
173 _estimate_bins(CLASS, SV *samples_ref, int rule=0)
174 char *CLASS
175 PPCODE:
176 (void)CLASS;
177 1 ▶ if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) { 1 0 1
if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) { 0 1 1
178 0 croak("Math::Histo: samples must be an array reference of numbers");
179 }
180 1 AV *av = (AV*)SvRV(samples_ref);
181 1 SSize_t n = av_top_index(av) + 1;
182 1 ▶ if (n < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (n < 1) { 0 1 1
183 0 croak("Math::Histo: auto binning requires at least 1 sample");
184 }
185 1 double *vals = (double*)malloc((size_t)n * sizeof(double));
186 1 ▶ if (!vals) {
Branch: 1 branch
BranchTrueFalseTotal
if (!vals) { 0 1 1
187 0 croak("Math::Histo: memory allocation failure");
188 }
189 {
190 SSize_t i;
191 301 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 300 1 301
192 300 SV **item = av_fetch(av, i, 0);
193 300 ▶ vals[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
vals[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0; 300 0 300
vals[i] = (item && SvOK(*item)) ? SvNV(*item) : 0.0; 300 0 300
194 }
195 }
196 1 uint32_t nbins = 0;
197 1 double min_v = 0.0, max_v = 0.0;
198 1 histo_status_t st = histo_estimate_bins((size_t)n, vals, (histo_bin_rule_t)rule, &nbins, &min_v, &max_v);
199 1 free(vals);
200 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
201 0 croak("Math::Histo: estimate_bins failed");
202 }
203 1 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 1 1
204 1 PUSHs(sv_2mortal(newSVuv(nbins)));
205 1 PUSHs(sv_2mortal(newSVnv(min_v)));
206 1 PUSHs(sv_2mortal(newSVnv(max_v)));
207  
208 histo_t *
209 _clone(histo_t *self)
210 CODE:
211 5 ▶ if (!self) croak("Math::Histo::clone: NULL histogram");
Branch: 1 branch
BranchTrueFalseTotal
if (!self) croak("Math::Histo::clone: NULL histogram"); 0 5 5
212 5 RETVAL = histo_clone(self, false);
213 5 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 5 5
214 0 croak("Math::Histo::clone: failed to clone histogram");
215 }
216 OUTPUT:
217 RETVAL
218  
219 histo_t *
220 _deserialize_binary(CLASS, SV *buf_sv)
221 char *CLASS
222 CODE:
223 (void)CLASS;
224 STRLEN len;
225 1002 const char *buf = SvPVbyte(buf_sv, len);
226 1002 histo_t *out = NULL;
227 1002 histo_status_t st = histo_deserialize_binary(buf, len, &out);
228 1002 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1002 0 1002
if (st != HISTO_OK || !out) { 0 1002 1002
229 0 croak("Math::Histo::from_binary: deserialization failed (corrupt or invalid blob)");
230 }
231 1002 RETVAL = out;
232 OUTPUT:
233 RETVAL
234  
235 histo_t *
236 _deserialize_json(CLASS, SV *json_sv)
237 char *CLASS
238 CODE:
239 (void)CLASS;
240 STRLEN len;
241 1 const char *str = SvPV(json_sv, len);
242 1 histo_t *out = NULL;
243 1 histo_status_t st = histo_deserialize_json(str, &out);
244 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
245 0 croak("Math::Histo::from_json: JSON deserialization failed");
246 }
247 1 RETVAL = out;
248 OUTPUT:
249 RETVAL
250  
251  
252 void
253 DESTROY(histo_t *self)
254 CODE:
255 2044 ▶ if (self) {
Branch: 1 branch
BranchTrueFalseTotal
if (self) { 2044 0 2044
256 2044 histo_destroy(self);
257 }
258  
259 int
260 fill(histo_t *self, double x, double weight=1.0)
261 CODE:
262 21823 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 21823 21823
263 histo_status_t st;
264 21823 ▶ if (weight == 1.0) {
Branch: 1 branch
BranchTrueFalseTotal
if (weight == 1.0) { 20029 1794 21823
265 20029 st = histo_fill(self, x);
266 } else {
267 1794 st = histo_fill_w(self, x, weight);
268 }
269 21823 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 21805 18 21823
270 OUTPUT:
271 RETVAL
272  
273 int
274 fill_n(histo_t *self, SV *x_ref, SV *w_ref=NULL)
275 CODE:
276 15 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 15 15
277 15 ▶ if (!SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV) { 15 0 15
if (!SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV) { 0 15 15
278 0 croak("Math::Histo::fill_n: x values must be an array reference");
279 }
280 15 AV *x_av = (AV*)SvRV(x_ref);
281 15 SSize_t n = av_top_index(x_av) + 1;
282 15 ▶ if (n == 0) XSRETURN_IV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) XSRETURN_IV(0); 0 15 15
283  
284 15 AV *w_av = NULL;
285 15 ▶ if (w_ref && SvOK(w_ref)) {
Branch: 2 branches
BranchTrueFalseTotal
if (w_ref && SvOK(w_ref)) { 2 13 15
if (w_ref && SvOK(w_ref)) { 2 0 2
286 2 ▶ if (!SvROK(w_ref) || SvTYPE(SvRV(w_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(w_ref) || SvTYPE(SvRV(w_ref)) != SVt_PVAV) { 2 0 2
if (!SvROK(w_ref) || SvTYPE(SvRV(w_ref)) != SVt_PVAV) { 0 2 2
287 0 croak("Math::Histo::fill_n: weights must be an array reference");
288 }
289 2 w_av = (AV*)SvRV(w_ref);
290 2 ▶ if (av_top_index(w_av) + 1 != n) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_top_index(w_av) + 1 != n) { 0 2 2
291 0 croak("Math::Histo::fill_n: x and weights array lengths must match");
292 }
293 }
294  
295 15 double *x_arr = (double*)malloc((size_t)n * sizeof(double));
296 15 ▶ double *w_arr = w_av ? (double*)malloc((size_t)n * sizeof(double)) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
double *w_arr = w_av ? (double*)malloc((size_t)n * sizeof(double)) : NULL; 2 13 15
297 15 ▶ if (!x_arr || (w_av && !w_arr)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!x_arr || (w_av && !w_arr)) { 15 0 15
if (!x_arr || (w_av && !w_arr)) { 2 13 15
if (!x_arr || (w_av && !w_arr)) { 0 2 2
298 0 free(x_arr);
299 0 free(w_arr);
300 0 croak("Math::Histo::fill_n: memory allocation failure");
301 }
302  
303 {
304 SSize_t i;
305 270 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 255 15 270
306 255 SV **xi = av_fetch(x_av, i, 0);
307 255 ▶ x_arr[i] = (xi && SvOK(*xi)) ? SvNV(*xi) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
x_arr[i] = (xi && SvOK(*xi)) ? SvNV(*xi) : 0.0; 255 0 255
x_arr[i] = (xi && SvOK(*xi)) ? SvNV(*xi) : 0.0; 255 0 255
308 255 ▶ if (w_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (w_av) { 6 249 255
309 6 SV **wi = av_fetch(w_av, i, 0);
310 6 ▶ w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0;
Branch: 2 branches
BranchTrueFalseTotal
w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0; 6 0 6
w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0; 6 0 6
311 }
312 }
313 }
314  
315 15 histo_status_t st = histo_fill_n(self, (size_t)n, x_arr, w_arr);
316 15 free(x_arr);
317 15 free(w_arr);
318 15 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 15 15
319 OUTPUT:
320 RETVAL
321  
322 int
323 fill_packed_f64(histo_t *self, SV *packed_x, SV *packed_w=NULL)
324 CODE:
325 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
326 STRLEN x_len;
327 1 const char *x_bytes = SvPVbyte(packed_x, x_len);
328 1 ▶ if (x_len % sizeof(double) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (x_len % sizeof(double) != 0) { 0 1 1
329 0 croak("Math::Histo::fill_packed_f64: packed x byte length must be multiple of 8 (double)");
330 }
331 1 size_t n = x_len / sizeof(double);
332 1 ▶ if (n == 0) XSRETURN_IV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) XSRETURN_IV(0); 0 1 1
333  
334 1 const double *x_arr = (const double *)x_bytes;
335 1 const double *w_arr = NULL;
336  
337 1 ▶ if (packed_w && SvOK(packed_w)) {
Branch: 2 branches
BranchTrueFalseTotal
if (packed_w && SvOK(packed_w)) { 1 0 1
if (packed_w && SvOK(packed_w)) { 1 0 1
338 STRLEN w_len;
339 1 const char *w_bytes = SvPVbyte(packed_w, w_len);
340 1 ▶ if (w_len != x_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (w_len != x_len) { 0 1 1
341 0 croak("Math::Histo::fill_packed_f64: weights length must match x length");
342 }
343 1 w_arr = (const double *)w_bytes;
344 }
345  
346 1 histo_status_t st = histo_fill_n(self, n, x_arr, w_arr);
347 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
348 OUTPUT:
349 RETVAL
350  
351 uint64_t
352 num_entries(histo_t *self)
353 CODE:
354 13 RETVAL = histo_num_entries(self);
355 OUTPUT:
356 RETVAL
357  
358 double
359 total_weight(histo_t *self)
360 CODE:
361 14 RETVAL = histo_total_weight(self);
362 OUTPUT:
363 RETVAL
364  
365 double
366 underflow_weight(histo_t *self)
367 CODE:
368 1 RETVAL = histo_underflow(self);
369 OUTPUT:
370 RETVAL
371  
372 double
373 overflow_weight(histo_t *self)
374 CODE:
375 1 RETVAL = histo_overflow(self);
376 OUTPUT:
377 RETVAL
378  
379 uint64_t
380 nan_count(histo_t *self)
381 CODE:
382 1 RETVAL = histo_nan_count(self);
383 OUTPUT:
384 RETVAL
385  
386 uint32_t
387 nbins(histo_t *self)
388 CODE:
389 18 RETVAL = histo_nbins(self);
390 OUTPUT:
391 RETVAL
392  
393 double
394 min(histo_t *self)
395 CODE:
396 3 double min_val = 0.0, max_val = 0.0;
397 3 histo_range(self, &min_val, &max_val);
398 3 ▶ RETVAL = min_val;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = min_val; 0 3 3
399 OUTPUT:
400 RETVAL
401  
402 double
403 max(histo_t *self)
404 CODE:
405 3 double min_val = 0.0, max_val = 0.0;
406 3 histo_range(self, &min_val, &max_val);
407 3 ▶ RETVAL = max_val;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = max_val; 0 3 3
408 OUTPUT:
409 RETVAL
410  
411 int
412 is_uniform(histo_t *self)
413 CODE:
414 2 ▶ RETVAL = (histo_bin_type(self) == HISTO_BIN_UNIFORM) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_bin_type(self) == HISTO_BIN_UNIFORM) ? 1 : 0; 0 2 2
415 OUTPUT:
416 RETVAL
417  
418  
419 double
420 mean(histo_t *self)
421 CODE:
422 1004 double out = 0.0;
423 1004 ▶ if (histo_mean(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_mean(self, &out) != HISTO_OK) XSRETURN_UNDEF; 1 1003 1004
424 1003 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 999 4 1003
425 OUTPUT:
426 RETVAL
427  
428 double
429 variance(histo_t *self)
430 CODE:
431 1 double out = 0.0;
432 1 ▶ if (histo_variance(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_variance(self, &out) != HISTO_OK) XSRETURN_UNDEF; 1 0 1
433 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
434 OUTPUT:
435 RETVAL
436  
437 double
438 std_dev(histo_t *self)
439 CODE:
440 2 double out = 0.0;
441 2 ▶ if (histo_std_dev(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_std_dev(self, &out) != HISTO_OK) XSRETURN_UNDEF; 1 1 2
442 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
443 OUTPUT:
444 RETVAL
445  
446 double
447 skewness(histo_t *self)
448 CODE:
449 0 double out = 0.0;
450 0 ▶ if (histo_skewness(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_skewness(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
451 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
452 OUTPUT:
453 RETVAL
454  
455 double
456 kurtosis(histo_t *self)
457 CODE:
458 0 double out = 0.0;
459 0 ▶ if (histo_kurtosis(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_kurtosis(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
460 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
461 OUTPUT:
462 RETVAL
463  
464 double
465 excess_kurtosis(histo_t *self)
466 CODE:
467 0 double out = 0.0;
468 0 ▶ if (histo_excess_kurtosis(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_excess_kurtosis(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
469 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
470 OUTPUT:
471 RETVAL
472  
473 double
474 central_moment(histo_t *self, uint32_t order)
475 CODE:
476 0 double out = 0.0;
477 0 ▶ if (histo_central_moment(self, order, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_central_moment(self, order, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
478 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
479 OUTPUT:
480 RETVAL
481  
482 double
483 median(histo_t *self)
484 CODE:
485 2 double out = 0.0;
486 2 ▶ if (histo_median(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_median(self, &out) != HISTO_OK) XSRETURN_UNDEF; 1 1 2
487 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
488 OUTPUT:
489 RETVAL
490  
491 double
492 quantile(histo_t *self, double q)
493 CODE:
494 3 double out = 0.0;
495 3 ▶ if (histo_quantile(self, q, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_quantile(self, q, &out) != HISTO_OK) XSRETURN_UNDEF; 1 2 3
496 2 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 2 2
497 OUTPUT:
498 RETVAL
499  
500 double
501 iqr(histo_t *self)
502 CODE:
503 2 double out = 0.0;
504 2 ▶ if (histo_iqr(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_iqr(self, &out) != HISTO_OK) XSRETURN_UNDEF; 1 1 2
505 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
506 OUTPUT:
507 RETVAL
508  
509 double
510 mad(histo_t *self)
511 CODE:
512 0 double out = 0.0;
513 0 ▶ if (histo_mad(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_mad(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
514 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
515 OUTPUT:
516 RETVAL
517  
518 double
519 mode(histo_t *self)
520 CODE:
521 1 double out = 0.0;
522 1 ▶ if (histo_mode_continuous(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_mode_continuous(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
523 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
524 OUTPUT:
525 RETVAL
526  
527 double
528 fwhm(histo_t *self)
529 CODE:
530 1 double out = 0.0;
531 1 ▶ if (histo_fwhm(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_fwhm(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
532 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
533 OUTPUT:
534 RETVAL
535  
536 double
537 rms(histo_t *self)
538 CODE:
539 1 double out = 0.0;
540 1 ▶ if (histo_rms(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_rms(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
541 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
542 OUTPUT:
543 RETVAL
544  
545 double
546 trimmed_mean(histo_t *self, double fraction)
547 CODE:
548 1 double out = 0.0;
549 1 ▶ if (histo_trimmed_mean(self, fraction, 1.0 - fraction, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_trimmed_mean(self, fraction, 1.0 - fraction, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
550 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
551 OUTPUT:
552 RETVAL
553  
554 double
555 winsorized_mean(histo_t *self, double fraction)
556 CODE:
557 1 double out = 0.0;
558 1 ▶ if (histo_winsorized_mean(self, fraction, 1.0 - fraction, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_winsorized_mean(self, fraction, 1.0 - fraction, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
559 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
560 OUTPUT:
561 RETVAL
562  
563 double
564 integral(histo_t *self)
565 CODE:
566 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
567 1 uint32_t n = histo_nbins(self);
568 1 double out = 0.0;
569 1 ▶ if (n == 0 || histo_integral(self, 0, n - 1, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (n == 0 || histo_integral(self, 0, n - 1, &out) != HISTO_OK) XSRETURN_UNDEF; 1 0 1
if (n == 0 || histo_integral(self, 0, n - 1, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
570 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
571 OUTPUT:
572 RETVAL
573  
574 histo_t *
575 cdf(histo_t *self, double prenormalization=1.0)
576 CODE:
577 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
578 0 RETVAL = histo_cdf(self, prenormalization);
579 0 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 0 0
580 0 croak("Math::Histo::cdf failed");
581 }
582 OUTPUT:
583 RETVAL
584  
585 int64_t
586 find_bin(histo_t *self, double x)
587 CODE:
588 2 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 2 2
589 2 int64_t bin_idx = -1;
590 2 ▶ if (histo_find_bin(self, x, &bin_idx) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_find_bin(self, x, &bin_idx) != HISTO_OK) XSRETURN_UNDEF; 0 2 2
591 2 ▶ RETVAL = bin_idx;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = bin_idx; 0 2 2
592 OUTPUT:
593 RETVAL
594  
595 double
596 bin_content(histo_t *self, int bin_idx)
597 CODE:
598 7 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 7 7
599 7 double out = 0.0;
600 7 ▶ if (histo_bin_content(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_bin_content(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF; 0 7 7
601 7 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 7 7
602 OUTPUT:
603 RETVAL
604  
605 double
606 bin_error(histo_t *self, int bin_idx)
607 CODE:
608 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
609 0 double out = 0.0;
610 0 ▶ if (histo_bin_error(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_bin_error(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
611 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
612 OUTPUT:
613 RETVAL
614  
615 double
616 bin_sum_w2(histo_t *self, int bin_idx)
617 CODE:
618 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
619 0 double out = 0.0;
620 0 ▶ if (histo_bin_sum_w2(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_bin_sum_w2(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
621 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
622 OUTPUT:
623 RETVAL
624  
625 double
626 bin_low_edge(histo_t *self, int bin_idx)
627 CODE:
628 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
629 0 double low = 0.0, high = 0.0;
630 0 ▶ if (histo_bin_bounds(self, (uint32_t)bin_idx, &low, &high) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_bin_bounds(self, (uint32_t)bin_idx, &low, &high) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
631 0 ▶ RETVAL = low;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = low; 0 0 0
632 OUTPUT:
633 RETVAL
634  
635 double
636 bin_high_edge(histo_t *self, int bin_idx)
637 CODE:
638 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
639 0 double low = 0.0, high = 0.0;
640 0 ▶ if (histo_bin_bounds(self, (uint32_t)bin_idx, &low, &high) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_bin_bounds(self, (uint32_t)bin_idx, &low, &high) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
641 0 ▶ RETVAL = high;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = high; 0 0 0
642 OUTPUT:
643 RETVAL
644  
645 double
646 bin_center(histo_t *self, int bin_idx)
647 CODE:
648 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
649 0 double out = 0.0;
650 0 ▶ if (histo_bin_center(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_bin_center(self, (uint32_t)bin_idx, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
651 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
652 OUTPUT:
653 RETVAL
654  
655 double
656 bin_width(histo_t *self, int bin_idx)
657 CODE:
658 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
659 0 double low = 0.0, high = 0.0;
660 0 ▶ if (histo_bin_bounds(self, (uint32_t)bin_idx, &low, &high) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo_bin_bounds(self, (uint32_t)bin_idx, &low, &high) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
661 0 ▶ RETVAL = high - low;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = high - low; 0 0 0
662 OUTPUT:
663 RETVAL
664  
665 SV *
666 bin_contents(histo_t *self)
667 CODE:
668 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
669 0 uint32_t n = histo_nbins(self);
670 0 AV *av = newAV();
671 0 av_extend(av, (SSize_t)n - 1);
672 {
673 uint32_t i;
674 0 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 0 0 0
675 0 double c = 0.0;
676 0 histo_bin_content(self, i, &c);
677 0 av_push(av, newSVnv(c));
678 }
679 }
680 0 RETVAL = newRV_noinc((SV*)av);
681 OUTPUT:
682 RETVAL
683  
684 SV *
685 bin_edges(histo_t *self)
686 CODE:
687 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
688 1 uint32_t n = histo_nbins(self);
689 1 AV *av = newAV();
690 1 av_extend(av, (SSize_t)n);
691 1 double low = 0.0, high = 0.0;
692 {
693 uint32_t i;
694 5 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 4 1 5
695 4 histo_bin_bounds(self, i, &low, &high);
696 4 av_push(av, newSVnv(low));
697 }
698 }
699 1 av_push(av, newSVnv(high));
700 1 RETVAL = newRV_noinc((SV*)av);
701 OUTPUT:
702 RETVAL
703  
704  
705 SV *
706 stats(histo_t *self)
707 CODE:
708 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
709 histo_stats_t st;
710 1 histo_status_t err = histo_get_stats(self, &st);
711 1 ▶ if (err != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (err != HISTO_OK) XSRETURN_UNDEF; 0 1 1
712 1 HV *hv = newHV();
713 1 hv_stores(hv, "entries", newSVuv(st.n_entries));
714 1 hv_stores(hv, "total_weight", newSVnv(st.total_weight));
715 1 hv_stores(hv, "mean", newSVnv(st.mean));
716 1 hv_stores(hv, "variance", newSVnv(st.variance));
717 1 hv_stores(hv, "std_dev", newSVnv(st.std_dev));
718 1 hv_stores(hv, "min", newSVnv(st.min));
719 1 hv_stores(hv, "max", newSVnv(st.max));
720 1 hv_stores(hv, "median", newSVnv(st.median));
721 1 RETVAL = newRV_noinc((SV*)hv);
722 OUTPUT:
723 RETVAL
724  
725 int
726 reset(histo_t *self)
727 CODE:
728 0 ▶ RETVAL = (histo_reset(self) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_reset(self) == HISTO_OK) ? 1 : 0; 0 0 0
729 OUTPUT:
730 RETVAL
731  
732 int
733 scale(histo_t *self, double factor)
734 CODE:
735 3 ▶ RETVAL = (histo_scale(self, factor) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_scale(self, factor) == HISTO_OK) ? 1 : 0; 0 3 3
736 OUTPUT:
737 RETVAL
738  
739 int
740 normalize(histo_t *self, double target_integral=1.0)
741 CODE:
742 1 ▶ RETVAL = (histo_normalize(self, target_integral) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_normalize(self, target_integral) == HISTO_OK) ? 1 : 0; 0 1 1
743 OUTPUT:
744 RETVAL
745  
746 histo_t *
747 rebin(histo_t *self, uint32_t group_factor)
748 CODE:
749 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
750 1 RETVAL = histo_rebin(self, group_factor);
751 1 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 1 1
752 0 croak("Math::Histo::rebin: failed to rebin (invalid group factor)");
753 }
754 OUTPUT:
755 RETVAL
756  
757 int
758 add(histo_t *self, histo_t *other)
759 CODE:
760 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
761 1 ▶ RETVAL = (histo_add(self, other) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_add(self, other) == HISTO_OK) ? 1 : 0; 0 1 1
762 OUTPUT:
763 RETVAL
764  
765 int
766 subtract(histo_t *self, histo_t *other)
767 CODE:
768 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
769 1 ▶ RETVAL = (histo_subtract(self, other) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_subtract(self, other) == HISTO_OK) ? 1 : 0; 0 1 1
770 OUTPUT:
771 RETVAL
772  
773 int
774 multiply(histo_t *self, histo_t *other)
775 CODE:
776 0 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 0 0 0
if (!self || !other) XSRETURN_UNDEF; 0 0 0
777 0 ▶ RETVAL = (histo_multiply(self, other) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_multiply(self, other) == HISTO_OK) ? 1 : 0; 0 0 0
778 OUTPUT:
779 RETVAL
780  
781 int
782 divide(histo_t *self, histo_t *other)
783 CODE:
784 0 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 0 0 0
if (!self || !other) XSRETURN_UNDEF; 0 0 0
785 0 ▶ RETVAL = (histo_divide(self, other) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_divide(self, other) == HISTO_OK) ? 1 : 0; 0 0 0
786 OUTPUT:
787 RETVAL
788  
789 void
790 chi2_test(histo_t *self, histo_t *other)
791 PPCODE:
792 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
793 1 double chi2 = 0.0;
794 1 uint32_t ndf = 0;
795 1 histo_status_t st = histo_cmp_chi2(self, other, &chi2, &ndf);
796 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
797 0 croak("Math::Histo::chi2_test failed (incompatible binning)");
798 }
799 1 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 1 0 1
800 1 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 1 1
801 1 mPUSHn(chi2);
802 1 mPUSHi((IV)ndf);
803 } else {
804 0 mPUSHn(chi2);
805 }
806  
807 double
808 kolmogorov_smirnov(histo_t *self, histo_t *other)
809 CODE:
810 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
811 1 double ks_stat = 0.0;
812 1 histo_status_t st = histo_cmp_ks(self, other, &ks_stat);
813 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
814 0 croak("Math::Histo::kolmogorov_smirnov failed");
815 }
816 1 ▶ RETVAL = ks_stat;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ks_stat; 0 1 1
817 OUTPUT:
818 RETVAL
819  
820 double
821 wasserstein_distance(histo_t *self, histo_t *other)
822 CODE:
823 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
824 1 double w1 = 0.0;
825 1 histo_status_t st = histo_cmp_wasserstein_1d(self, other, &w1);
826 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
827 0 croak("Math::Histo::wasserstein_distance failed");
828 }
829 1 ▶ RETVAL = w1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = w1; 0 1 1
830 OUTPUT:
831 RETVAL
832  
833 double
834 kl_divergence(histo_t *self, histo_t *other, double eps=1e-12)
835 CODE:
836 (void)eps;
837 0 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 0 0 0
if (!self || !other) XSRETURN_UNDEF; 0 0 0
838 0 double kl = 0.0;
839 0 histo_status_t st = histo_cmp_kl_divergence(self, other, &kl);
840 0 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 0 0
841 0 croak("Math::Histo::kl_divergence failed");
842 }
843 0 ▶ RETVAL = kl;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = kl; 0 0 0
844 OUTPUT:
845 RETVAL
846  
847 double
848 bhattacharyya_distance(histo_t *self, histo_t *other)
849 CODE:
850 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
851 1 double bhat = 0.0;
852 1 histo_status_t st = histo_cmp_bhattacharyya(self, other, &bhat);
853 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
854 0 croak("Math::Histo::bhattacharyya_distance failed");
855 }
856 1 ▶ RETVAL = bhat;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = bhat; 0 1 1
857 OUTPUT:
858 RETVAL
859  
860 SV *
861 serialize_binary(histo_t *self)
862 CODE:
863 1003 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1003 1003
864 1003 void *out_buf = NULL;
865 1003 size_t out_size = 0;
866 1003 histo_status_t st = histo_serialize_binary(self, &out_buf, &out_size);
867 1003 ▶ if (st != HISTO_OK || !out_buf) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out_buf) { 1003 0 1003
if (st != HISTO_OK || !out_buf) { 0 1003 1003
868 0 croak("Math::Histo::serialize_binary: serialization failed");
869 }
870 1003 RETVAL = newSVpvn((const char*)out_buf, out_size);
871 1003 histo_free_buffer(out_buf);
872 OUTPUT:
873 RETVAL
874  
875 SV *
876 serialize_json(histo_t *self, int pretty=0)
877 CODE:
878 (void)pretty;
879 3 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 3 3
880 3 char *json = NULL;
881 3 histo_status_t st = histo_serialize_json(self, &json);
882 3 ▶ if (st != HISTO_OK || !json) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !json) { 3 0 3
if (st != HISTO_OK || !json) { 0 3 3
883 0 croak("Math::Histo::serialize_json: JSON serialization failed");
884 }
885 3 RETVAL = newSVpv(json, 0);
886 3 histo_free_buffer(json);
887 OUTPUT:
888 RETVAL
889  
890  
891 MODULE = Math::Histo PACKAGE = Math::Histo::2D PREFIX = histo2d_xs_
892  
893 histo2d_t *
894 _create_uniform(CLASS, uint32_t nx, double xmin, double xmax, uint32_t ny, double ymin, double ymax, uint32_t flags=0)
895 char *CLASS
896 CODE:
897 (void)CLASS;
898 5 RETVAL = histo2d_create_uniform(nx, xmin, xmax, ny, ymin, ymax, flags);
899 5 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 5 5
900 0 croak("Math::Histo::2D: failed to create uniform 2D histogram");
901 }
902 OUTPUT:
903 RETVAL
904  
905 histo2d_t *
906 _create_variable(CLASS, SV *xedges_ref, SV *yedges_ref, uint32_t flags=0)
907 char *CLASS
908 CODE:
909 (void)CLASS;
910 1 ▶ if (!SvROK(xedges_ref) || SvTYPE(SvRV(xedges_ref)) != SVt_PVAV ||
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(xedges_ref) || SvTYPE(SvRV(xedges_ref)) != SVt_PVAV || 1 0 1
if (!SvROK(xedges_ref) || SvTYPE(SvRV(xedges_ref)) != SVt_PVAV || 1 0 1
911 1 ▶ !SvROK(yedges_ref) || SvTYPE(SvRV(yedges_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
!SvROK(yedges_ref) || SvTYPE(SvRV(yedges_ref)) != SVt_PVAV) { 1 0 1
!SvROK(yedges_ref) || SvTYPE(SvRV(yedges_ref)) != SVt_PVAV) { 0 1 1
912 0 croak("Math::Histo::2D: xedges and yedges must be array references");
913 }
914 1 AV *x_av = (AV*)SvRV(xedges_ref);
915 1 AV *y_av = (AV*)SvRV(yedges_ref);
916 1 SSize_t nx_edges = av_top_index(x_av) + 1;
917 1 SSize_t ny_edges = av_top_index(y_av) + 1;
918 1 ▶ if (nx_edges < 2 || ny_edges < 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (nx_edges < 2 || ny_edges < 2) { 1 0 1
if (nx_edges < 2 || ny_edges < 2) { 0 1 1
919 0 croak("Math::Histo::2D: variable binning requires >= 2 edges per axis");
920 }
921 1 double *xedges = (double*)malloc((size_t)nx_edges * sizeof(double));
922 1 double *yedges = (double*)malloc((size_t)ny_edges * sizeof(double));
923 1 ▶ if (!xedges || !yedges) {
Branch: 2 branches
BranchTrueFalseTotal
if (!xedges || !yedges) { 1 0 1
if (!xedges || !yedges) { 0 1 1
924 0 free(xedges); free(yedges);
925 0 croak("Math::Histo::2D: memory allocation failure");
926 }
927 {
928 SSize_t i;
929 4 ▶ for (i = 0; i < nx_edges; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nx_edges; i++) { 3 1 4
930 3 SV **it = av_fetch(x_av, i, 0);
931 3 ▶ xedges[i] = (it && SvOK(*it)) ? SvNV(*it) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
xedges[i] = (it && SvOK(*it)) ? SvNV(*it) : 0.0; 3 0 3
xedges[i] = (it && SvOK(*it)) ? SvNV(*it) : 0.0; 3 0 3
932 }
933 }
934 {
935 SSize_t i;
936 5 ▶ for (i = 0; i < ny_edges; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ny_edges; i++) { 4 1 5
937 4 SV **it = av_fetch(y_av, i, 0);
938 4 ▶ yedges[i] = (it && SvOK(*it)) ? SvNV(*it) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
yedges[i] = (it && SvOK(*it)) ? SvNV(*it) : 0.0; 4 0 4
yedges[i] = (it && SvOK(*it)) ? SvNV(*it) : 0.0; 4 0 4
939 }
940 }
941 1 RETVAL = histo2d_create_variable((uint32_t)(nx_edges - 1), xedges, (uint32_t)(ny_edges - 1), yedges, flags);
942 1 free(xedges);
943 1 free(yedges);
944 1 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 1 1
945 0 croak("Math::Histo::2D: failed to create variable 2D histogram");
946 }
947 OUTPUT:
948 RETVAL
949  
950 histo2d_t *
951 _clone(histo2d_t *self)
952 CODE:
953 4 ▶ if (!self) croak("Math::Histo::2D::clone: NULL histogram");
Branch: 1 branch
BranchTrueFalseTotal
if (!self) croak("Math::Histo::2D::clone: NULL histogram"); 0 4 4
954 4 RETVAL = histo2d_clone(self, false);
955 4 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 4 4
956 0 croak("Math::Histo::2D::clone: failed to clone");
957 }
958 OUTPUT:
959 RETVAL
960  
961  
962 histo2d_t *
963 _deserialize_binary(CLASS, SV *buf_sv)
964 char *CLASS
965 CODE:
966 (void)CLASS;
967 STRLEN len;
968 1 const char *buf = SvPVbyte(buf_sv, len);
969 1 histo2d_t *out = NULL;
970 1 histo_status_t st = histo2d_deserialize_binary(buf, len, &out);
971 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
972 0 croak("Math::Histo::2D::from_binary: deserialization failed");
973 }
974 1 RETVAL = out;
975 OUTPUT:
976 RETVAL
977  
978 histo2d_t *
979 _deserialize_json(CLASS, SV *json_sv)
980 char *CLASS
981 CODE:
982 (void)CLASS;
983 STRLEN len;
984 0 const char *str = SvPV(json_sv, len);
985 0 histo2d_t *out = NULL;
986 0 histo_status_t st = histo2d_deserialize_json(str, &out);
987 0 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 0 0 0
if (st != HISTO_OK || !out) { 0 0 0
988 0 croak("Math::Histo::2D::from_json: JSON deserialization failed");
989 }
990 0 RETVAL = out;
991 OUTPUT:
992 RETVAL
993  
994 void
995 DESTROY(histo2d_t *self)
996 CODE:
997 12 ▶ if (self) {
Branch: 1 branch
BranchTrueFalseTotal
if (self) { 12 0 12
998 12 histo2d_destroy(self);
999 }
1000  
1001 int
1002 fill(histo2d_t *self, double x, double y, double weight=1.0)
1003 CODE:
1004 11 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 11 11
1005 histo_status_t st;
1006 11 ▶ if (weight == 1.0) {
Branch: 1 branch
BranchTrueFalseTotal
if (weight == 1.0) { 3 8 11
1007 3 st = histo2d_fill(self, x, y);
1008 } else {
1009 8 st = histo2d_fill_w(self, x, y, weight);
1010 }
1011 11 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 11 11
1012 OUTPUT:
1013 RETVAL
1014  
1015 int
1016 fill_n(histo2d_t *self, SV *x_ref, SV *y_ref, SV *w_ref=NULL)
1017 CODE:
1018 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1019 1 ▶ if (!SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV ||
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV || 1 0 1
if (!SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV || 1 0 1
1020 1 ▶ !SvROK(y_ref) || SvTYPE(SvRV(y_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
!SvROK(y_ref) || SvTYPE(SvRV(y_ref)) != SVt_PVAV) { 1 0 1
!SvROK(y_ref) || SvTYPE(SvRV(y_ref)) != SVt_PVAV) { 0 1 1
1021 0 croak("Math::Histo::2D::fill_n: x and y must be array references");
1022 }
1023 1 AV *x_av = (AV*)SvRV(x_ref);
1024 1 AV *y_av = (AV*)SvRV(y_ref);
1025 1 SSize_t n = av_top_index(x_av) + 1;
1026 1 ▶ if (av_top_index(y_av) + 1 != n) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_top_index(y_av) + 1 != n) { 0 1 1
1027 0 croak("Math::Histo::2D::fill_n: x and y array lengths must match");
1028 }
1029 1 ▶ if (n == 0) XSRETURN_IV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) XSRETURN_IV(0); 0 1 1
1030  
1031 1 AV *w_av = NULL;
1032 1 ▶ if (w_ref && SvOK(w_ref)) {
Branch: 2 branches
BranchTrueFalseTotal
if (w_ref && SvOK(w_ref)) { 1 0 1
if (w_ref && SvOK(w_ref)) { 1 0 1
1033 1 ▶ if (!SvROK(w_ref) || SvTYPE(SvRV(w_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(w_ref) || SvTYPE(SvRV(w_ref)) != SVt_PVAV) { 1 0 1
if (!SvROK(w_ref) || SvTYPE(SvRV(w_ref)) != SVt_PVAV) { 0 1 1
1034 0 croak("Math::Histo::2D::fill_n: weights must be an array reference");
1035 }
1036 1 w_av = (AV*)SvRV(w_ref);
1037 1 ▶ if (av_top_index(w_av) + 1 != n) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_top_index(w_av) + 1 != n) { 0 1 1
1038 0 croak("Math::Histo::2D::fill_n: weights length must match x length");
1039 }
1040 }
1041  
1042 1 double *x_arr = (double*)malloc((size_t)n * sizeof(double));
1043 1 double *y_arr = (double*)malloc((size_t)n * sizeof(double));
1044 1 ▶ double *w_arr = w_av ? (double*)malloc((size_t)n * sizeof(double)) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
double *w_arr = w_av ? (double*)malloc((size_t)n * sizeof(double)) : NULL; 1 0 1
1045 1 ▶ if (!x_arr || !y_arr || (w_av && !w_arr)) {
Branch: 4 branches
BranchTrueFalseTotal
if (!x_arr || !y_arr || (w_av && !w_arr)) { 1 0 1
if (!x_arr || !y_arr || (w_av && !w_arr)) { 1 0 1
if (!x_arr || !y_arr || (w_av && !w_arr)) { 1 0 1
if (!x_arr || !y_arr || (w_av && !w_arr)) { 0 1 1
1046 0 free(x_arr); free(y_arr); free(w_arr);
1047 0 croak("Math::Histo::2D::fill_n: memory allocation failure");
1048 }
1049  
1050 {
1051 SSize_t i;
1052 4 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 3 1 4
1053 3 SV **xi = av_fetch(x_av, i, 0);
1054 3 SV **yi = av_fetch(y_av, i, 0);
1055 3 ▶ x_arr[i] = (xi && SvOK(*xi)) ? SvNV(*xi) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
x_arr[i] = (xi && SvOK(*xi)) ? SvNV(*xi) : 0.0; 3 0 3
x_arr[i] = (xi && SvOK(*xi)) ? SvNV(*xi) : 0.0; 3 0 3
1056 3 ▶ y_arr[i] = (yi && SvOK(*yi)) ? SvNV(*yi) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
y_arr[i] = (yi && SvOK(*yi)) ? SvNV(*yi) : 0.0; 3 0 3
y_arr[i] = (yi && SvOK(*yi)) ? SvNV(*yi) : 0.0; 3 0 3
1057 3 ▶ if (w_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (w_av) { 3 0 3
1058 3 SV **wi = av_fetch(w_av, i, 0);
1059 3 ▶ w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0;
Branch: 2 branches
BranchTrueFalseTotal
w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0; 3 0 3
w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0; 3 0 3
1060 }
1061 }
1062 }
1063  
1064 1 histo_status_t st = histo2d_fill_n(self, (size_t)n, x_arr, y_arr, w_arr);
1065 1 free(x_arr); free(y_arr); free(w_arr);
1066 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
1067 OUTPUT:
1068 RETVAL
1069  
1070 int
1071 fill_packed_f64(histo2d_t *self, SV *packed_x, SV *packed_y, SV *packed_w=NULL)
1072 CODE:
1073 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1074 1 STRLEN x_len = 0, y_len = 0;
1075 1 ▶ const char *x_raw = SvPVbyte(packed_x, x_len);
Branch: 1 branch
BranchTrueFalseTotal
const char *x_raw = SvPVbyte(packed_x, x_len); 1 0 1
1076 1 const char *y_raw = SvPVbyte(packed_y, y_len);
1077 1 ▶ if ((x_len % sizeof(double)) != 0 || (y_len % sizeof(double)) != 0 || x_len != y_len) {
Branch: 3 branches
BranchTrueFalseTotal
if ((x_len % sizeof(double)) != 0 || (y_len % sizeof(double)) != 0 || x_len != y_len) { 1 0 1
if ((x_len % sizeof(double)) != 0 || (y_len % sizeof(double)) != 0 || x_len != y_len) { 1 0 1
if ((x_len % sizeof(double)) != 0 || (y_len % sizeof(double)) != 0 || x_len != y_len) { 0 1 1
1078 0 croak("Math::Histo::2D::fill_packed_f64: packed x and y byte lengths must match and be multiple of 8 (double)");
1079 }
1080 1 size_t n = x_len / sizeof(double);
1081 1 ▶ if (n == 0) XSRETURN_IV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) XSRETURN_IV(0); 0 1 1
1082  
1083 1 const double *x_arr = (const double *)(const void *)x_raw;
1084 1 const double *y_arr = (const double *)(const void *)y_raw;
1085 1 const double *w_arr = NULL;
1086 1 ▶ if (packed_w && SvOK(packed_w)) {
Branch: 2 branches
BranchTrueFalseTotal
if (packed_w && SvOK(packed_w)) { 0 1 1
if (packed_w && SvOK(packed_w)) { 0 0 0
1087 0 STRLEN w_len = 0;
1088 0 const char *w_raw = SvPVbyte(packed_w, w_len);
1089 0 ▶ if (w_len != x_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (w_len != x_len) { 0 0 0
1090 0 croak("Math::Histo::2D::fill_packed_f64: weights length must match x length");
1091 }
1092 0 w_arr = (const double *)(const void *)w_raw;
1093 }
1094 1 histo_status_t st = histo2d_fill_n(self, n, x_arr, y_arr, w_arr);
1095 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
1096 OUTPUT:
1097 RETVAL
1098  
1099 uint64_t
1100 num_entries(histo2d_t *self)
1101  
1102 CODE:
1103 5 RETVAL = histo2d_num_entries(self);
1104 OUTPUT:
1105 RETVAL
1106  
1107 double
1108 total_weight(histo2d_t *self)
1109 CODE:
1110 4 RETVAL = histo2d_total_weight(self);
1111 OUTPUT:
1112 RETVAL
1113  
1114 double
1115 bin_sum_w2(histo2d_t *self, int ix, int iy)
1116 CODE:
1117 0 double out = 0.0;
1118 0 ▶ if (histo2d_bin_sum_w2(self, (uint32_t)ix, (uint32_t)iy, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_bin_sum_w2(self, (uint32_t)ix, (uint32_t)iy, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
1119 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
1120 OUTPUT:
1121 RETVAL
1122  
1123  
1124 uint32_t
1125 nx(histo2d_t *self)
1126 CODE:
1127 4 RETVAL = histo2d_nbins_x(self);
1128 OUTPUT:
1129 RETVAL
1130  
1131 uint32_t
1132 ny(histo2d_t *self)
1133 CODE:
1134 4 RETVAL = histo2d_nbins_y(self);
1135 OUTPUT:
1136 RETVAL
1137  
1138 double
1139 xmin(histo2d_t *self)
1140 CODE:
1141 histo2d_axis_t axis_x_def;
1142 1 ▶ if (histo2d_axis_x(self, &axis_x_def) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_axis_x(self, &axis_x_def) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1143 1 ▶ RETVAL = axis_x_def.min;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = axis_x_def.min; 0 1 1
1144 OUTPUT:
1145 RETVAL
1146  
1147 double
1148 xmax(histo2d_t *self)
1149 CODE:
1150 histo2d_axis_t axis_x_def;
1151 1 ▶ if (histo2d_axis_x(self, &axis_x_def) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_axis_x(self, &axis_x_def) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1152 1 ▶ RETVAL = axis_x_def.max;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = axis_x_def.max; 0 1 1
1153 OUTPUT:
1154 RETVAL
1155  
1156 double
1157 ymin(histo2d_t *self)
1158 CODE:
1159 histo2d_axis_t axis_y_def;
1160 1 ▶ if (histo2d_axis_y(self, &axis_y_def) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_axis_y(self, &axis_y_def) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1161 1 ▶ RETVAL = axis_y_def.min;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = axis_y_def.min; 0 1 1
1162 OUTPUT:
1163 RETVAL
1164  
1165 double
1166 ymax(histo2d_t *self)
1167 CODE:
1168 histo2d_axis_t axis_y_def;
1169 1 ▶ if (histo2d_axis_y(self, &axis_y_def) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_axis_y(self, &axis_y_def) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1170 1 ▶ RETVAL = axis_y_def.max;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = axis_y_def.max; 0 1 1
1171 OUTPUT:
1172 RETVAL
1173  
1174  
1175 double
1176 mean_x(histo2d_t *self)
1177 CODE:
1178 0 double out = 0.0;
1179 0 ▶ if (histo2d_mean_x(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_mean_x(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
1180 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
1181 OUTPUT:
1182 RETVAL
1183  
1184 double
1185 mean_y(histo2d_t *self)
1186 CODE:
1187 0 double out = 0.0;
1188 0 ▶ if (histo2d_mean_y(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_mean_y(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
1189 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
1190 OUTPUT:
1191 RETVAL
1192  
1193 double
1194 variance_x(histo2d_t *self)
1195 CODE:
1196 0 double out = 0.0;
1197 0 ▶ if (histo2d_variance_x(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_variance_x(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
1198 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
1199 OUTPUT:
1200 RETVAL
1201  
1202 double
1203 variance_y(histo2d_t *self)
1204 CODE:
1205 0 double out = 0.0;
1206 0 ▶ if (histo2d_variance_y(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_variance_y(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
1207 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
1208 OUTPUT:
1209 RETVAL
1210  
1211 double
1212 covariance(histo2d_t *self)
1213 CODE:
1214 1 double out = 0.0;
1215 1 ▶ if (histo2d_covariance(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_covariance(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1216 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
1217 OUTPUT:
1218 RETVAL
1219  
1220 double
1221 correlation(histo2d_t *self)
1222 CODE:
1223 1 double out = 0.0;
1224 1 ▶ if (histo2d_correlation(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_correlation(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1225 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
1226 OUTPUT:
1227 RETVAL
1228  
1229 double
1230 bin_content(histo2d_t *self, int ix, int iy)
1231 CODE:
1232 4 double out = 0.0;
1233 4 ▶ if (histo2d_bin_content(self, (uint32_t)ix, (uint32_t)iy, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_bin_content(self, (uint32_t)ix, (uint32_t)iy, &out) != HISTO_OK) XSRETURN_UNDEF; 0 4 4
1234 4 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 4 4
1235 OUTPUT:
1236 RETVAL
1237  
1238 double
1239 bin_error(histo2d_t *self, int ix, int iy)
1240 CODE:
1241 0 double out = 0.0;
1242 0 ▶ if (histo2d_bin_error(self, (uint32_t)ix, (uint32_t)iy, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_bin_error(self, (uint32_t)ix, (uint32_t)iy, &out) != HISTO_OK) XSRETURN_UNDEF; 0 0 0
1243 0 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 0 0
1244 OUTPUT:
1245 RETVAL
1246  
1247 histo_t *
1248 project_x(histo2d_t *self)
1249 CODE:
1250 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1251 1 histo_t *out = NULL;
1252 1 histo_status_t st = histo2d_project_x(self, &out);
1253 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
1254 0 croak("Math::Histo::2D::project_x failed");
1255 }
1256 1 RETVAL = out;
1257 OUTPUT:
1258 RETVAL
1259  
1260 histo_t *
1261 project_y(histo2d_t *self)
1262 CODE:
1263 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1264 1 histo_t *out = NULL;
1265 1 histo_status_t st = histo2d_project_y(self, &out);
1266 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
1267 0 croak("Math::Histo::2D::project_y failed");
1268 }
1269 1 RETVAL = out;
1270 OUTPUT:
1271 RETVAL
1272  
1273 histo_t *
1274 slice_x(histo2d_t *self, int iy_min, int iy_max)
1275 CODE:
1276 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1277 1 histo_t *out = NULL;
1278 1 histo_status_t st = histo2d_slice_x(self, iy_min, iy_max, &out);
1279 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
1280 0 croak("Math::Histo::2D::slice_x failed");
1281 }
1282 1 RETVAL = out;
1283 OUTPUT:
1284 RETVAL
1285  
1286 histo_t *
1287 slice_y(histo2d_t *self, int ix_min, int ix_max)
1288 CODE:
1289 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1290 1 histo_t *out = NULL;
1291 1 histo_status_t st = histo2d_slice_y(self, ix_min, ix_max, &out);
1292 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
1293 0 croak("Math::Histo::2D::slice_y failed");
1294 }
1295 1 RETVAL = out;
1296 OUTPUT:
1297 RETVAL
1298  
1299 histo_t *
1300 profile_x(histo2d_t *self)
1301 CODE:
1302 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1303 1 histo_t *out = NULL;
1304 1 histo_status_t st = histo2d_profile_x(self, &out);
1305 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
1306 0 croak("Math::Histo::2D::profile_x failed");
1307 }
1308 1 RETVAL = out;
1309 OUTPUT:
1310 RETVAL
1311  
1312 histo_t *
1313 profile_y(histo2d_t *self)
1314 CODE:
1315 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
1316 0 histo_t *out = NULL;
1317 0 histo_status_t st = histo2d_profile_y(self, &out);
1318 0 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 0 0 0
if (st != HISTO_OK || !out) { 0 0 0
1319 0 croak("Math::Histo::2D::profile_y failed");
1320 }
1321 0 RETVAL = out;
1322 OUTPUT:
1323 RETVAL
1324  
1325 SV *
1326 serialize_binary(histo2d_t *self)
1327 CODE:
1328 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1329 1 void *out_buf = NULL;
1330 1 size_t out_size = 0;
1331 1 histo_status_t st = histo2d_serialize_binary_alloc(self, &out_buf, &out_size);
1332 1 ▶ if (st != HISTO_OK || !out_buf) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out_buf) { 1 0 1
if (st != HISTO_OK || !out_buf) { 0 1 1
1333 0 croak("Math::Histo::2D::serialize_binary failed");
1334 }
1335 1 RETVAL = newSVpvn((const char*)out_buf, out_size);
1336 1 histo_free_buffer(out_buf);
1337 OUTPUT:
1338 RETVAL
1339  
1340 SV *
1341 serialize_json(histo2d_t *self, int pretty=0)
1342 CODE:
1343 (void)pretty;
1344 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1345 1 char *json = NULL;
1346 1 size_t size = 0;
1347 1 histo_status_t st = histo2d_serialize_json_alloc(self, &json, &size);
1348 1 ▶ if (st != HISTO_OK || !json) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !json) { 1 0 1
if (st != HISTO_OK || !json) { 0 1 1
1349 0 croak("Math::Histo::2D::serialize_json failed");
1350 }
1351 1 RETVAL = newSVpv(json, size);
1352 1 histo_free_buffer(json);
1353 OUTPUT:
1354 RETVAL
1355  
1356 double
1357 std_dev_x(histo2d_t *self)
1358 CODE:
1359 1 double out = 0.0;
1360 1 ▶ if (histo2d_std_dev_x(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_std_dev_x(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1361 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
1362 OUTPUT:
1363 RETVAL
1364  
1365 double
1366 std_dev_y(histo2d_t *self)
1367 CODE:
1368 1 double out = 0.0;
1369 1 ▶ if (histo2d_std_dev_y(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_std_dev_y(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1370 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
1371 OUTPUT:
1372 RETVAL
1373  
1374 void
1375 bin_bounds(histo2d_t *self, int ix, int iy)
1376 PPCODE:
1377 1 ▶ if (!self) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_EMPTY; 0 1 1
1378 1 double xmin = 0, xmax = 0, ymin = 0, ymax = 0;
1379 1 ▶ if (histo2d_bin_bounds(self, (uint32_t)ix, (uint32_t)iy, &xmin, &xmax, &ymin, &ymax) != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_bin_bounds(self, (uint32_t)ix, (uint32_t)iy, &xmin, &xmax, &ymin, &ymax) != HISTO_OK) { 0 1 1
1380 0 XSRETURN_EMPTY;
1381 }
1382 1 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 1 1
1383 1 PUSHs(sv_2mortal(newSVnv(xmin)));
1384 1 PUSHs(sv_2mortal(newSVnv(xmax)));
1385 1 PUSHs(sv_2mortal(newSVnv(ymin)));
1386 1 PUSHs(sv_2mortal(newSVnv(ymax)));
1387  
1388 void
1389 bin_center(histo2d_t *self, int ix, int iy)
1390 PPCODE:
1391 1 ▶ if (!self) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_EMPTY; 0 1 1
1392 1 double cx = 0, cy = 0;
1393 1 ▶ if (histo2d_bin_center(self, (uint32_t)ix, (uint32_t)iy, &cx, &cy) != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_bin_center(self, (uint32_t)ix, (uint32_t)iy, &cx, &cy) != HISTO_OK) { 0 1 1
1394 0 XSRETURN_EMPTY;
1395 }
1396 1 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 1 1
1397 1 PUSHs(sv_2mortal(newSVnv(cx)));
1398 1 PUSHs(sv_2mortal(newSVnv(cy)));
1399  
1400 void
1401 find_bin(histo2d_t *self, double x, double y)
1402 PPCODE:
1403 1 ▶ if (!self) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_EMPTY; 0 1 1
1404 1 int64_t ix = 0, iy = 0;
1405 1 ▶ if (histo2d_find_bin(self, x, y, &ix, &iy) != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_find_bin(self, x, y, &ix, &iy) != HISTO_OK) { 0 1 1
1406 0 XSRETURN_EMPTY;
1407 }
1408 1 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 1 1
1409 1 PUSHs(sv_2mortal(newSViv((IV)ix)));
1410 1 PUSHs(sv_2mortal(newSViv((IV)iy)));
1411  
1412 int
1413 find_region(histo2d_t *self, double x, double y)
1414 CODE:
1415 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1416 1 histo2d_region_t reg = HISTO2D_REGION_CENTER;
1417 1 ▶ if (histo2d_find_region(self, x, y, &reg) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_find_region(self, x, y, &reg) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1418 1 ▶ RETVAL = (int)reg;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (int)reg; 0 1 1
1419 OUTPUT:
1420 RETVAL
1421  
1422 double
1423 integral(histo2d_t *self)
1424 CODE:
1425 2 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 2 2
1426 2 double out = 0.0;
1427 2 ▶ if (histo2d_integral(self, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_integral(self, &out) != HISTO_OK) XSRETURN_UNDEF; 0 2 2
1428 2 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 2 2
1429 OUTPUT:
1430 RETVAL
1431  
1432 double
1433 integral_range(histo2d_t *self, int ix_min, int ix_max, int iy_min, int iy_max)
1434 CODE:
1435 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1436 1 double out = 0.0;
1437 1 ▶ if (histo2d_integral_range(self, (uint32_t)ix_min, (uint32_t)ix_max, (uint32_t)iy_min, (uint32_t)iy_max, &out) != HISTO_OK) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (histo2d_integral_range(self, (uint32_t)ix_min, (uint32_t)ix_max, (uint32_t)iy_min, (uint32_t)iy_max, &out) != HISTO_OK) XSRETURN_UNDEF; 0 1 1
1438 1 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 1 1
1439 OUTPUT:
1440 RETVAL
1441  
1442 int
1443 scale(histo2d_t *self, double factor)
1444 CODE:
1445 2 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 2 2
1446 2 histo_status_t st = histo2d_scale(self, factor);
1447 2 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 2 2
1448 OUTPUT:
1449 RETVAL
1450  
1451 int
1452 normalize(histo2d_t *self, double target=1.0)
1453 CODE:
1454 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1455 1 histo_status_t st = histo2d_normalize(self, target);
1456 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
1457 OUTPUT:
1458 RETVAL
1459  
1460 histo2d_t *
1461 rebin(histo2d_t *self, int fx, int fy)
1462 CODE:
1463 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1464 1 histo2d_t *rebinned = NULL;
1465 1 histo_status_t st = histo2d_rebin(self, (uint32_t)fx, (uint32_t)fy, &rebinned);
1466 1 ▶ if (st != HISTO_OK || !rebinned) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !rebinned) { 1 0 1
if (st != HISTO_OK || !rebinned) { 0 1 1
1467 0 croak("Math::Histo::2D::rebin failed");
1468 }
1469 1 RETVAL = rebinned;
1470 OUTPUT:
1471 RETVAL
1472  
1473 int
1474 add(histo2d_t *self, histo2d_t *other, double scale=1.0)
1475 CODE:
1476 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
1477 1 histo_status_t st = histo2d_add(self, other, scale);
1478 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
1479 OUTPUT:
1480 RETVAL
1481  
1482 int
1483 subtract(histo2d_t *self, histo2d_t *other)
1484 CODE:
1485 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
1486 1 histo_status_t st = histo2d_subtract(self, other);
1487 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
1488 OUTPUT:
1489 RETVAL
1490  
1491 int
1492 multiply(histo2d_t *self, histo2d_t *other)
1493 CODE:
1494 0 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 0 0 0
if (!self || !other) XSRETURN_UNDEF; 0 0 0
1495 0 histo_status_t st = histo2d_multiply(self, other);
1496 0 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 0 0
1497 OUTPUT:
1498 RETVAL
1499  
1500 int
1501 divide(histo2d_t *self, histo2d_t *other)
1502 CODE:
1503 0 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 0 0 0
if (!self || !other) XSRETURN_UNDEF; 0 0 0
1504 0 histo_status_t st = histo2d_divide(self, other);
1505 0 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 0 0
1506 OUTPUT:
1507 RETVAL
1508  
1509 int
1510 reset(histo2d_t *self)
1511 CODE:
1512 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1513 1 histo_status_t st = histo2d_reset(self);
1514 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
1515 OUTPUT:
1516 RETVAL
1517  
1518  
1519 MODULE = Math::Histo PACKAGE = Math::Histo::Fit PREFIX = histo_fit_xs_
1520  
1521 histo_fit_result_t *
1522 _fit_builtin(CLASS, histo_t *h, int model_type, SV *init_ref, SV *lower_ref=NULL, SV *upper_ref=NULL, SV *fixed_ref=NULL, int max_iter=200, double tol=1e-8, int loss_fn=0)
1523 char *CLASS
1524 CODE:
1525 (void)CLASS;
1526 5 ▶ if (!h) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) XSRETURN_UNDEF; 0 5 5
1527  
1528 histo_fit_options_t opts;
1529 5 histo_fit_options_init(&opts);
1530 5 opts.max_iterations = max_iter;
1531 5 opts.ftol = tol;
1532 5 opts.gtol = tol;
1533 5 opts.xtol = tol;
1534 5 opts.loss_type = (histo_fit_loss_t)loss_fn;
1535  
1536 5 size_t n_p = histo_fit_model_num_params((histo_fit_model_t)model_type, opts.poly_degree);
1537 5 double *init_p = NULL;
1538  
1539 /* Unpack initial parameters if provided */
1540 5 ▶ if (init_ref && SvOK(init_ref) && SvROK(init_ref) && SvTYPE(SvRV(init_ref)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (init_ref && SvOK(init_ref) && SvROK(init_ref) && SvTYPE(SvRV(init_ref)) == SVt_PVAV) { 5 0 5
if (init_ref && SvOK(init_ref) && SvROK(init_ref) && SvTYPE(SvRV(init_ref)) == SVt_PVAV) { 1 4 5
if (init_ref && SvOK(init_ref) && SvROK(init_ref) && SvTYPE(SvRV(init_ref)) == SVt_PVAV) { 1 0 1
if (init_ref && SvOK(init_ref) && SvROK(init_ref) && SvTYPE(SvRV(init_ref)) == SVt_PVAV) { 1 0 1
1541 1 AV *av = (AV*)SvRV(init_ref);
1542 1 SSize_t n = av_top_index(av) + 1;
1543 1 ▶ if (n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) { 1 0 1
1544 1 init_p = (double*)malloc((size_t)n * sizeof(double));
1545 1 ▶ if (!init_p) croak("Math::Histo::Fit: memory allocation failure");
Branch: 1 branch
BranchTrueFalseTotal
if (!init_p) croak("Math::Histo::Fit: memory allocation failure"); 0 1 1
1546 {
1547 SSize_t i;
1548 3 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 2 1 3
1549 2 SV **v = av_fetch(av, i, 0);
1550 2 ▶ init_p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
init_p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0; 2 0 2
init_p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0; 2 0 2
1551 }
1552 }
1553 }
1554 }
1555  
1556 5 double *lower_bounds = NULL;
1557 5 double *upper_bounds = NULL;
1558 5 bool *fixed_params = NULL;
1559  
1560 5 ▶ if (lower_ref && SvOK(lower_ref) && SvROK(lower_ref) && SvTYPE(SvRV(lower_ref)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (lower_ref && SvOK(lower_ref) && SvROK(lower_ref) && SvTYPE(SvRV(lower_ref)) == SVt_PVAV) { 5 0 5
if (lower_ref && SvOK(lower_ref) && SvROK(lower_ref) && SvTYPE(SvRV(lower_ref)) == SVt_PVAV) { 0 5 5
if (lower_ref && SvOK(lower_ref) && SvROK(lower_ref) && SvTYPE(SvRV(lower_ref)) == SVt_PVAV) { 0 0 0
if (lower_ref && SvOK(lower_ref) && SvROK(lower_ref) && SvTYPE(SvRV(lower_ref)) == SVt_PVAV) { 0 0 0
1561 0 AV *av = (AV*)SvRV(lower_ref);
1562 0 lower_bounds = (double*)calloc(n_p, sizeof(double));
1563 {
1564 SSize_t i;
1565 0 ▶ for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) { 0 0 0
for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) { 0 0 0
1566 0 SV **v = av_fetch(av, i, 0);
1567 0 ▶ if (v && SvOK(*v)) lower_bounds[i] = SvNV(*v);
Branch: 2 branches
BranchTrueFalseTotal
if (v && SvOK(*v)) lower_bounds[i] = SvNV(*v); 0 0 0
if (v && SvOK(*v)) lower_bounds[i] = SvNV(*v); 0 0 0
1568 }
1569 }
1570 0 opts.lower_bounds = lower_bounds;
1571 }
1572  
1573 5 ▶ if (upper_ref && SvOK(upper_ref) && SvROK(upper_ref) && SvTYPE(SvRV(upper_ref)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (upper_ref && SvOK(upper_ref) && SvROK(upper_ref) && SvTYPE(SvRV(upper_ref)) == SVt_PVAV) { 5 0 5
if (upper_ref && SvOK(upper_ref) && SvROK(upper_ref) && SvTYPE(SvRV(upper_ref)) == SVt_PVAV) { 0 5 5
if (upper_ref && SvOK(upper_ref) && SvROK(upper_ref) && SvTYPE(SvRV(upper_ref)) == SVt_PVAV) { 0 0 0
if (upper_ref && SvOK(upper_ref) && SvROK(upper_ref) && SvTYPE(SvRV(upper_ref)) == SVt_PVAV) { 0 0 0
1574 0 AV *av = (AV*)SvRV(upper_ref);
1575 0 upper_bounds = (double*)calloc(n_p, sizeof(double));
1576 {
1577 SSize_t i;
1578 0 ▶ for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) { 0 0 0
for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) { 0 0 0
1579 0 SV **v = av_fetch(av, i, 0);
1580 0 ▶ if (v && SvOK(*v)) upper_bounds[i] = SvNV(*v);
Branch: 2 branches
BranchTrueFalseTotal
if (v && SvOK(*v)) upper_bounds[i] = SvNV(*v); 0 0 0
if (v && SvOK(*v)) upper_bounds[i] = SvNV(*v); 0 0 0
1581 }
1582 }
1583 0 opts.upper_bounds = upper_bounds;
1584 }
1585  
1586 5 ▶ if (fixed_ref && SvOK(fixed_ref) && SvROK(fixed_ref) && SvTYPE(SvRV(fixed_ref)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (fixed_ref && SvOK(fixed_ref) && SvROK(fixed_ref) && SvTYPE(SvRV(fixed_ref)) == SVt_PVAV) { 5 0 5
if (fixed_ref && SvOK(fixed_ref) && SvROK(fixed_ref) && SvTYPE(SvRV(fixed_ref)) == SVt_PVAV) { 0 5 5
if (fixed_ref && SvOK(fixed_ref) && SvROK(fixed_ref) && SvTYPE(SvRV(fixed_ref)) == SVt_PVAV) { 0 0 0
if (fixed_ref && SvOK(fixed_ref) && SvROK(fixed_ref) && SvTYPE(SvRV(fixed_ref)) == SVt_PVAV) { 0 0 0
1587 0 AV *av = (AV*)SvRV(fixed_ref);
1588 0 fixed_params = (bool*)calloc(n_p, sizeof(bool));
1589 {
1590 SSize_t i;
1591 0 ▶ for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) { 0 0 0
for (i = 0; i <= av_top_index(av) && (size_t)i < n_p; i++) { 0 0 0
1592 0 SV **v = av_fetch(av, i, 0);
1593 0 ▶ if (v && SvOK(*v) && SvTRUE(*v)) fixed_params[i] = true;
Branch: 3 branches
BranchTrueFalseTotal
if (v && SvOK(*v) && SvTRUE(*v)) fixed_params[i] = true; 0 0 0
if (v && SvOK(*v) && SvTRUE(*v)) fixed_params[i] = true; 0 0 0
if (v && SvOK(*v) && SvTRUE(*v)) fixed_params[i] = true; 0 0 0
1594 }
1595 }
1596 0 opts.fixed_params = fixed_params;
1597 }
1598  
1599 5 histo_fit_result_t *res = NULL;
1600 5 histo_status_t st = histo_fit_model(h, (histo_fit_model_t)model_type, init_p, &opts, &res);
1601  
1602 5 free(init_p);
1603 5 free(lower_bounds);
1604 5 free(upper_bounds);
1605 5 free(fixed_params);
1606  
1607 5 ▶ if (st < 0 || !res) {
Branch: 2 branches
BranchTrueFalseTotal
if (st < 0 || !res) { 5 0 5
if (st < 0 || !res) { 0 5 5
1608 0 croak("Math::Histo::Fit::fit failed (numerical error or optimization diverged)");
1609 }
1610 5 RETVAL = res;
1611 OUTPUT:
1612 RETVAL
1613  
1614 double
1615 eval_model(CLASS, int model_type, SV *params_ref, double x)
1616 char *CLASS
1617 CODE:
1618 (void)CLASS;
1619 1 ▶ if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 1 0 1
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 1 0 1
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 1 0 1
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 0 1 1
1620 0 croak("Math::Histo::Fit::eval_model: params must be an arrayref");
1621 }
1622 1 AV *av = (AV*)SvRV(params_ref);
1623 1 SSize_t n = av_top_index(av) + 1;
1624 double stack_p[16];
1625 1 double *p = stack_p;
1626 1 ▶ if (n > 16) {
Branch: 1 branch
BranchTrueFalseTotal
if (n > 16) { 0 1 1
1627 0 p = (double*)malloc((size_t)n * sizeof(double));
1628 0 ▶ if (!p) croak("Out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Out of memory"); 0 0 0
1629 }
1630 {
1631 SSize_t i;
1632 4 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 3 1 4
1633 3 SV **v = av_fetch(av, i, 0);
1634 3 ▶ p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0; 3 0 3
p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0; 3 0 3
1635 }
1636 }
1637 1 RETVAL = histo_fit_eval((histo_fit_model_t)model_type, p, (size_t)n, x);
1638 1 ▶ if (p != stack_p) free(p);
Branch: 1 branch
BranchTrueFalseTotal
if (p != stack_p) free(p); 0 1 1
1639 OUTPUT:
1640 RETVAL
1641  
1642 SV *
1643 eval_gradient(CLASS, int model_type, SV *params_ref, double x)
1644 char *CLASS
1645 CODE:
1646 (void)CLASS;
1647 1 ▶ if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 1 0 1
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 1 0 1
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 1 0 1
if (!params_ref || !SvOK(params_ref) || !SvROK(params_ref) || SvTYPE(SvRV(params_ref)) != SVt_PVAV) { 0 1 1
1648 0 croak("Math::Histo::Fit::eval_gradient: params must be an arrayref");
1649 }
1650 1 AV *av = (AV*)SvRV(params_ref);
1651 1 SSize_t n = av_top_index(av) + 1;
1652 double stack_p[16];
1653 1 double *p = stack_p;
1654 1 ▶ if (n > 16) {
Branch: 1 branch
BranchTrueFalseTotal
if (n > 16) { 0 1 1
1655 0 p = (double*)malloc((size_t)n * sizeof(double));
1656 0 ▶ if (!p) croak("Out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Out of memory"); 0 0 0
1657 }
1658 {
1659 SSize_t i;
1660 4 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 3 1 4
1661 3 SV **v = av_fetch(av, i, 0);
1662 3 ▶ p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0; 3 0 3
p[i] = (v && SvOK(*v)) ? SvNV(*v) : 0.0; 3 0 3
1663 }
1664 }
1665 1 double *grad = (double*)malloc((size_t)n * sizeof(double));
1666 1 ▶ if (!grad) {
Branch: 1 branch
BranchTrueFalseTotal
if (!grad) { 0 1 1
1667 0 ▶ if (p != stack_p) free(p);
Branch: 1 branch
BranchTrueFalseTotal
if (p != stack_p) free(p); 0 0 0
1668 0 croak("Out of memory");
1669 }
1670 1 histo_status_t st = histo_fit_eval_gradient((histo_fit_model_t)model_type, p, (size_t)n, x, grad);
1671 1 ▶ if (p != stack_p) free(p);
Branch: 1 branch
BranchTrueFalseTotal
if (p != stack_p) free(p); 0 1 1
1672 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
1673 0 free(grad);
1674 0 croak("Math::Histo::Fit::eval_gradient failed");
1675 }
1676 1 AV *res_av = newAV();
1677 1 av_extend(res_av, n - 1);
1678 {
1679 SSize_t i;
1680 4 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 3 1 4
1681 3 av_push(res_av, newSVnv(grad[i]));
1682 }
1683 }
1684 1 free(grad);
1685 1 RETVAL = newRV_noinc((SV*)res_av);
1686 OUTPUT:
1687 RETVAL
1688  
1689  
1690 MODULE = Math::Histo PACKAGE = Math::Histo::Fit::Result PREFIX = histo_fit_res_xs_
1691  
1692 void
1693 DESTROY(histo_fit_result_t *self)
1694 CODE:
1695 5 ▶ if (self) {
Branch: 1 branch
BranchTrueFalseTotal
if (self) { 5 0 5
1696 5 histo_fit_result_destroy(self);
1697 }
1698  
1699 int
1700 status(histo_fit_result_t *self)
1701 CODE:
1702 6 ▶ RETVAL = (int)self->status;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (int)self->status; 0 6 6
1703 OUTPUT:
1704 RETVAL
1705  
1706 uint32_t
1707 iterations(histo_fit_result_t *self)
1708 CODE:
1709 1 ▶ RETVAL = self->iterations;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->iterations; 0 1 1
1710 OUTPUT:
1711 RETVAL
1712  
1713 uint32_t
1714 n_params(histo_fit_result_t *self)
1715 CODE:
1716 4 ▶ RETVAL = (uint32_t)self->num_params;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (uint32_t)self->num_params; 0 4 4
1717 OUTPUT:
1718 RETVAL
1719  
1720 double
1721 chi2(histo_fit_result_t *self)
1722 CODE:
1723 2 ▶ RETVAL = self->chi2;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->chi2; 0 2 2
1724 OUTPUT:
1725 RETVAL
1726  
1727 int32_t
1728 ndf(histo_fit_result_t *self)
1729 CODE:
1730 1 ▶ RETVAL = self->ndf;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->ndf; 0 1 1
1731 OUTPUT:
1732 RETVAL
1733  
1734 double
1735 reduced_chi2(histo_fit_result_t *self)
1736 CODE:
1737 2 ▶ RETVAL = self->reduced_chi2;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->reduced_chi2; 0 2 2
1738 OUTPUT:
1739 RETVAL
1740  
1741 double
1742 p_value(histo_fit_result_t *self)
1743 CODE:
1744 2 ▶ RETVAL = self->p_value;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->p_value; 0 2 2
1745 OUTPUT:
1746 RETVAL
1747  
1748 double
1749 log_likelihood(histo_fit_result_t *self)
1750 CODE:
1751 0 ▶ RETVAL = self->log_likelihood;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->log_likelihood; 0 0 0
1752 OUTPUT:
1753 RETVAL
1754  
1755 double
1756 aic(histo_fit_result_t *self)
1757 CODE:
1758 0 ▶ RETVAL = self->aic;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->aic; 0 0 0
1759 OUTPUT:
1760 RETVAL
1761  
1762 double
1763 bic(histo_fit_result_t *self)
1764 CODE:
1765 0 ▶ RETVAL = self->bic;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->bic; 0 0 0
1766 OUTPUT:
1767 RETVAL
1768  
1769 SV *
1770 params(histo_fit_result_t *self)
1771 CODE:
1772 4 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 4 4
1773 4 AV *av = newAV();
1774 4 av_extend(av, (SSize_t)self->num_params - 1);
1775 {
1776 size_t i;
1777 16 ▶ for (i = 0; i < self->num_params; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < self->num_params; i++) { 12 4 16
1778 12 av_push(av, newSVnv(self->params[i]));
1779 }
1780 }
1781 4 RETVAL = newRV_noinc((SV*)av);
1782 OUTPUT:
1783 RETVAL
1784  
1785 SV *
1786 errors(histo_fit_result_t *self)
1787 CODE:
1788 2 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 2 2
1789 2 AV *av = newAV();
1790 2 av_extend(av, (SSize_t)self->num_params - 1);
1791 {
1792 size_t i;
1793 8 ▶ for (i = 0; i < self->num_params; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < self->num_params; i++) { 6 2 8
1794 6 ▶ av_push(av, newSVnv(self->param_errors ? self->param_errors[i] : 0.0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, newSVnv(self->param_errors ? self->param_errors[i] : 0.0)); 6 0 6
1795 }
1796 }
1797 2 RETVAL = newRV_noinc((SV*)av);
1798 OUTPUT:
1799 RETVAL
1800  
1801 SV *
1802 cov_matrix(histo_fit_result_t *self)
1803 CODE:
1804 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
1805 0 AV *rows = newAV();
1806 0 av_extend(rows, (SSize_t)self->num_params - 1);
1807 {
1808 size_t i;
1809 0 ▶ for (i = 0; i < self->num_params; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < self->num_params; i++) { 0 0 0
1810 0 AV *row = newAV();
1811 0 av_extend(row, (SSize_t)self->num_params - 1);
1812 {
1813 size_t j;
1814 0 ▶ for (j = 0; j < self->num_params; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < self->num_params; j++) { 0 0 0
1815 0 ▶ double val = self->cov_matrix ? self->cov_matrix[i * self->num_params + j] : 0.0;
Branch: 1 branch
BranchTrueFalseTotal
double val = self->cov_matrix ? self->cov_matrix[i * self->num_params + j] : 0.0; 0 0 0
1816 0 av_push(row, newSVnv(val));
1817 }
1818 }
1819 0 av_push(rows, newRV_noinc((SV*)row));
1820 }
1821 }
1822 0 RETVAL = newRV_noinc((SV*)rows);
1823 OUTPUT:
1824 RETVAL
1825  
1826  
1827 MODULE = Math::Histo PACKAGE = Math::Histo::Sketch PREFIX = histo_sketch_xs_
1828  
1829 histo_sketch_t *
1830 _create(CLASS, double alpha=0.01, uint32_t max_bins=2048)
1831 char *CLASS
1832 CODE:
1833 (void)CLASS;
1834 2 RETVAL = histo_sketch_create(alpha, max_bins);
1835 2 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 2 2
1836 0 croak("Math::Histo::Sketch: failed to create sketch");
1837 }
1838 OUTPUT:
1839 RETVAL
1840  
1841 histo_sketch_t *
1842 _deserialize_binary(CLASS, SV *buf_sv)
1843 char *CLASS
1844 CODE:
1845 (void)CLASS;
1846 STRLEN len;
1847 1 const char *buf = SvPVbyte(buf_sv, len);
1848 1 histo_sketch_t *out = NULL;
1849 1 histo_status_t st = histo_sketch_deserialize_binary(buf, len, &out);
1850 1 ▶ if (st != HISTO_OK || !out) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out) { 1 0 1
if (st != HISTO_OK || !out) { 0 1 1
1851 0 croak("Math::Histo::Sketch::from_binary: deserialization failed");
1852 }
1853 1 RETVAL = out;
1854 OUTPUT:
1855 RETVAL
1856  
1857 void
1858 DESTROY(histo_sketch_t *self)
1859 CODE:
1860 3 ▶ if (self) {
Branch: 1 branch
BranchTrueFalseTotal
if (self) { 3 0 3
1861 3 histo_sketch_destroy(self);
1862 }
1863  
1864 int
1865 insert(histo_sketch_t *self, double value, double weight=1.0)
1866 CODE:
1867 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
1868 histo_status_t st;
1869 0 ▶ if (weight == 1.0) {
Branch: 1 branch
BranchTrueFalseTotal
if (weight == 1.0) { 0 0 0
1870 0 st = histo_sketch_insert(self, value);
1871 } else {
1872 0 st = histo_sketch_insert_w(self, value, weight);
1873 }
1874 0 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 0 0
1875 OUTPUT:
1876 RETVAL
1877  
1878 int
1879 insert_n(histo_sketch_t *self, SV *values_ref, SV *weights_ref=NULL)
1880 CODE:
1881 2 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 2 2
1882 2 ▶ if (!SvROK(values_ref) || SvTYPE(SvRV(values_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(values_ref) || SvTYPE(SvRV(values_ref)) != SVt_PVAV) { 2 0 2
if (!SvROK(values_ref) || SvTYPE(SvRV(values_ref)) != SVt_PVAV) { 0 2 2
1883 0 croak("Math::Histo::Sketch::insert_n: values must be an array reference");
1884 }
1885 2 AV *v_av = (AV*)SvRV(values_ref);
1886 2 SSize_t n = av_top_index(v_av) + 1;
1887 2 ▶ if (n == 0) XSRETURN_IV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) XSRETURN_IV(0); 0 2 2
1888  
1889 2 AV *w_av = NULL;
1890 2 ▶ if (weights_ref && SvOK(weights_ref)) {
Branch: 2 branches
BranchTrueFalseTotal
if (weights_ref && SvOK(weights_ref)) { 0 2 2
if (weights_ref && SvOK(weights_ref)) { 0 0 0
1891 0 ▶ if (!SvROK(weights_ref) || SvTYPE(SvRV(weights_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(weights_ref) || SvTYPE(SvRV(weights_ref)) != SVt_PVAV) { 0 0 0
if (!SvROK(weights_ref) || SvTYPE(SvRV(weights_ref)) != SVt_PVAV) { 0 0 0
1892 0 croak("Math::Histo::Sketch::insert_n: weights must be an array reference");
1893 }
1894 0 w_av = (AV*)SvRV(weights_ref);
1895 0 ▶ if (av_top_index(w_av) + 1 != n) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_top_index(w_av) + 1 != n) { 0 0 0
1896 0 croak("Math::Histo::Sketch::insert_n: values and weights length mismatch");
1897 }
1898 }
1899  
1900 2 double *v_arr = (double*)malloc((size_t)n * sizeof(double));
1901 2 ▶ double *w_arr = w_av ? (double*)malloc((size_t)n * sizeof(double)) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
double *w_arr = w_av ? (double*)malloc((size_t)n * sizeof(double)) : NULL; 0 2 2
1902 2 ▶ if (!v_arr || (w_av && !w_arr)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!v_arr || (w_av && !w_arr)) { 2 0 2
if (!v_arr || (w_av && !w_arr)) { 0 2 2
if (!v_arr || (w_av && !w_arr)) { 0 0 0
1903 0 free(v_arr); free(w_arr);
1904 0 croak("Math::Histo::Sketch::insert_n: memory allocation failure");
1905 }
1906  
1907 {
1908 SSize_t i;
1909 2002 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 2000 2 2002
1910 2000 SV **vi = av_fetch(v_av, i, 0);
1911 2000 ▶ v_arr[i] = (vi && SvOK(*vi)) ? SvNV(*vi) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
v_arr[i] = (vi && SvOK(*vi)) ? SvNV(*vi) : 0.0; 2000 0 2000
v_arr[i] = (vi && SvOK(*vi)) ? SvNV(*vi) : 0.0; 2000 0 2000
1912 2000 ▶ if (w_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (w_av) { 0 2000 2000
1913 0 SV **wi = av_fetch(w_av, i, 0);
1914 0 ▶ w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0;
Branch: 2 branches
BranchTrueFalseTotal
w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0; 0 0 0
w_arr[i] = (wi && SvOK(*wi)) ? SvNV(*wi) : 1.0; 0 0 0
1915 }
1916 }
1917 }
1918  
1919 2 histo_status_t st = histo_sketch_insert_n(self, (size_t)n, v_arr, w_arr);
1920 2 free(v_arr); free(w_arr);
1921 2 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 2 2
1922 OUTPUT:
1923 RETVAL
1924  
1925 int
1926 insert_packed_f64(histo_sketch_t *self, SV *packed_v, SV *packed_w=NULL)
1927 CODE:
1928 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
1929 1 STRLEN v_len = 0;
1930 1 const char *v_raw = SvPVbyte(packed_v, v_len);
1931 1 ▶ if ((v_len % sizeof(double)) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((v_len % sizeof(double)) != 0) { 0 1 1
1932 0 croak("Math::Histo::Sketch::insert_packed_f64: packed values byte length must be multiple of 8 (double)");
1933 }
1934 1 size_t n = v_len / sizeof(double);
1935 1 ▶ if (n == 0) XSRETURN_IV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) XSRETURN_IV(0); 0 1 1
1936  
1937 1 const double *v_arr = (const double *)(const void *)v_raw;
1938 1 const double *w_arr = NULL;
1939 1 ▶ if (packed_w && SvOK(packed_w)) {
Branch: 2 branches
BranchTrueFalseTotal
if (packed_w && SvOK(packed_w)) { 0 1 1
if (packed_w && SvOK(packed_w)) { 0 0 0
1940 0 STRLEN w_len = 0;
1941 0 const char *w_raw = SvPVbyte(packed_w, w_len);
1942 0 ▶ if (w_len != v_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (w_len != v_len) { 0 0 0
1943 0 croak("Math::Histo::Sketch::insert_packed_f64: weights length must match values length");
1944 }
1945 0 w_arr = (const double *)(const void *)w_raw;
1946 }
1947 1 histo_status_t st = histo_sketch_insert_n(self, n, v_arr, w_arr);
1948 1 ▶ RETVAL = (st == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (st == HISTO_OK) ? 1 : 0; 0 1 1
1949 OUTPUT:
1950 RETVAL
1951  
1952 double
1953 quantile(histo_sketch_t *self, double q)
1954  
1955 CODE:
1956 3 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 3 3
1957 3 double out = 0.0;
1958 3 histo_status_t st = histo_sketch_quantile(self, q, &out);
1959 3 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 3 3
1960 0 croak("Math::Histo::Sketch::quantile failed (empty sketch or invalid q in [0,1])");
1961 }
1962 3 ▶ RETVAL = out;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out; 0 3 3
1963 OUTPUT:
1964 RETVAL
1965  
1966 int
1967 merge(histo_sketch_t *self, histo_sketch_t *other)
1968 CODE:
1969 1 ▶ if (!self || !other) XSRETURN_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !other) XSRETURN_UNDEF; 1 0 1
if (!self || !other) XSRETURN_UNDEF; 0 1 1
1970 1 ▶ RETVAL = (histo_sketch_merge(self, other) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_sketch_merge(self, other) == HISTO_OK) ? 1 : 0; 0 1 1
1971 OUTPUT:
1972 RETVAL
1973  
1974 double
1975 min(histo_sketch_t *self)
1976 CODE:
1977 1 RETVAL = histo_sketch_min(self);
1978 OUTPUT:
1979 RETVAL
1980  
1981 double
1982 max(histo_sketch_t *self)
1983 CODE:
1984 2 RETVAL = histo_sketch_max(self);
1985 OUTPUT:
1986 RETVAL
1987  
1988 double
1989 total_weight(histo_sketch_t *self)
1990 CODE:
1991 2 RETVAL = histo_sketch_total_weight(self);
1992 OUTPUT:
1993 RETVAL
1994  
1995 uint64_t
1996 num_entries(histo_sketch_t *self)
1997 CODE:
1998 5 RETVAL = histo_sketch_num_entries(self);
1999 OUTPUT:
2000 RETVAL
2001  
2002 int
2003 reset(histo_sketch_t *self)
2004 CODE:
2005 0 ▶ RETVAL = (histo_sketch_reset(self) == HISTO_OK) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (histo_sketch_reset(self) == HISTO_OK) ? 1 : 0; 0 0 0
2006 OUTPUT:
2007 RETVAL
2008  
2009 SV *
2010 serialize_binary(histo_sketch_t *self)
2011 CODE:
2012 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
2013 1 void *out_buf = NULL;
2014 1 size_t out_size = 0;
2015 1 histo_status_t st = histo_sketch_serialize_binary(self, &out_buf, &out_size);
2016 1 ▶ if (st != HISTO_OK || !out_buf) {
Branch: 2 branches
BranchTrueFalseTotal
if (st != HISTO_OK || !out_buf) { 1 0 1
if (st != HISTO_OK || !out_buf) { 0 1 1
2017 0 croak("Math::Histo::Sketch::serialize_binary failed");
2018 }
2019 1 RETVAL = newSVpvn((const char*)out_buf, out_size);
2020 1 histo_free_buffer(out_buf);
2021 OUTPUT:
2022 RETVAL
2023  
2024 MODULE = Math::Histo PACKAGE = Math::Histo::KDE PREFIX = histo_kde_xs_
2025  
2026 histo_kde_t *
2027 _create(CLASS, SV *samples_ref, SV *weights_ref=NULL, int kernel=0, int bw_method=0, double bandwidth=0.0, double bw_adjust=1.0)
2028 char *CLASS
2029 CODE:
2030 (void)CLASS;
2031 7 ▶ if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) { 7 0 7
if (!SvROK(samples_ref) || SvTYPE(SvRV(samples_ref)) != SVt_PVAV) { 0 7 7
2032 0 croak("Math::Histo::KDE: samples must be an array reference of numbers");
2033 }
2034 7 AV *av_s = (AV*)SvRV(samples_ref);
2035 7 SSize_t n = av_top_index(av_s) + 1;
2036 7 ▶ if (n < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (n < 1) { 0 7 7
2037 0 croak("Math::Histo::KDE: samples array cannot be empty");
2038 }
2039 7 double *samples = (double*)malloc((size_t)n * sizeof(double));
2040 7 double *weights = NULL;
2041 7 ▶ if (weights_ref && SvOK(weights_ref) && SvROK(weights_ref) && SvTYPE(SvRV(weights_ref)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (weights_ref && SvOK(weights_ref) && SvROK(weights_ref) && SvTYPE(SvRV(weights_ref)) == SVt_PVAV) { 7 0 7
if (weights_ref && SvOK(weights_ref) && SvROK(weights_ref) && SvTYPE(SvRV(weights_ref)) == SVt_PVAV) { 0 7 7
if (weights_ref && SvOK(weights_ref) && SvROK(weights_ref) && SvTYPE(SvRV(weights_ref)) == SVt_PVAV) { 0 0 0
if (weights_ref && SvOK(weights_ref) && SvROK(weights_ref) && SvTYPE(SvRV(weights_ref)) == SVt_PVAV) { 0 0 0
2042 0 AV *av_w = (AV*)SvRV(weights_ref);
2043 0 weights = (double*)malloc((size_t)n * sizeof(double));
2044 {
2045 SSize_t i;
2046 0 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 0 0 0
2047 0 SV **item_w = av_fetch(av_w, i, 0);
2048 0 ▶ weights[i] = (item_w && SvOK(*item_w)) ? SvNV(*item_w) : 1.0;
Branch: 2 branches
BranchTrueFalseTotal
weights[i] = (item_w && SvOK(*item_w)) ? SvNV(*item_w) : 1.0; 0 0 0
weights[i] = (item_w && SvOK(*item_w)) ? SvNV(*item_w) : 1.0; 0 0 0
2049 }
2050 }
2051 }
2052 {
2053 SSize_t i;
2054 77 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 70 7 77
2055 70 SV **item_s = av_fetch(av_s, i, 0);
2056 70 ▶ samples[i] = (item_s && SvOK(*item_s)) ? SvNV(*item_s) : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
samples[i] = (item_s && SvOK(*item_s)) ? SvNV(*item_s) : 0.0; 70 0 70
samples[i] = (item_s && SvOK(*item_s)) ? SvNV(*item_s) : 0.0; 70 0 70
2057 }
2058 }
2059  
2060 histo_kde_options_t opts;
2061 7 opts.kernel = (histo_kde_kernel_t)kernel;
2062 7 opts.bw_method = (histo_kde_bandwidth_method_t)bw_method;
2063 7 opts.bandwidth = bandwidth;
2064 7 opts.bw_adjust = bw_adjust;
2065  
2066 7 RETVAL = histo_kde_create((size_t)n, samples, weights, &opts);
2067 7 free(samples);
2068 7 ▶ if (weights) free(weights);
Branch: 1 branch
BranchTrueFalseTotal
if (weights) free(weights); 0 7 7
2069 7 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 7 7
2070 0 croak("Math::Histo::KDE: failed to create KDE model");
2071 }
2072 OUTPUT:
2073 RETVAL
2074  
2075 histo_kde_t *
2076 _create_from_histo(CLASS, histo_t *h, int kernel=0, int bw_method=0, double bandwidth=0.0, double bw_adjust=1.0)
2077 char *CLASS
2078 CODE:
2079 (void)CLASS;
2080 1 ▶ if (!h) croak("Math::Histo::KDE: NULL histogram handle");
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Math::Histo::KDE: NULL histogram handle"); 0 1 1
2081 histo_kde_options_t opts;
2082 1 opts.kernel = (histo_kde_kernel_t)kernel;
2083 1 opts.bw_method = (histo_kde_bandwidth_method_t)bw_method;
2084 1 opts.bandwidth = bandwidth;
2085 1 opts.bw_adjust = bw_adjust;
2086 1 RETVAL = histo_kde_create_from_histo(h, &opts);
2087 1 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 1 1
2088 0 croak("Math::Histo::KDE: failed to create KDE from histogram");
2089 }
2090 OUTPUT:
2091 RETVAL
2092  
2093 void
2094 DESTROY(histo_kde_t *self)
2095 CODE:
2096 8 ▶ if (self) {
Branch: 1 branch
BranchTrueFalseTotal
if (self) { 8 0 8
2097 8 histo_kde_destroy(self);
2098 }
2099  
2100 double
2101 eval(histo_kde_t *self, double x)
2102 CODE:
2103 8 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 8 8
2104 8 RETVAL = histo_kde_eval(self, x);
2105 OUTPUT:
2106 RETVAL
2107  
2108 double
2109 cdf(histo_kde_t *self, double x)
2110 CODE:
2111 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
2112 1 RETVAL = histo_kde_cdf(self, x);
2113 OUTPUT:
2114 RETVAL
2115  
2116 double
2117 quantile(histo_kde_t *self, double q)
2118 CODE:
2119 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
2120 1 double out_val = 0.0;
2121 1 histo_status_t st = histo_kde_quantile(self, q, &out_val);
2122 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
2123 0 croak("Math::Histo::KDE: quantile calculation failed");
2124 }
2125 1 ▶ RETVAL = out_val;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = out_val; 0 1 1
2126 OUTPUT:
2127 RETVAL
2128  
2129 void
2130 sample(histo_kde_t *self, size_t n=1, uint64_t seed=0)
2131 PPCODE:
2132 1 ▶ if (!self) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_EMPTY; 0 1 1
2133 1 ▶ if (n == 0) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) XSRETURN_EMPTY; 0 1 1
2134 1 double *buf = (double*)malloc(n * sizeof(double));
2135 1 ▶ if (!buf) croak("Math::Histo::KDE::sample: out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!buf) croak("Math::Histo::KDE::sample: out of memory"); 0 1 1
2136 1 histo_status_t st = histo_kde_sample(self, n, buf, seed);
2137 1 ▶ if (st != HISTO_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (st != HISTO_OK) { 0 1 1
2138 0 free(buf);
2139 0 croak("Math::Histo::KDE::sample failed");
2140 }
2141 1 ▶ EXTEND(SP, (SSize_t)n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, (SSize_t)n); 1 0 1
EXTEND(SP, (SSize_t)n); 0 1 1
2142 {
2143 size_t i;
2144 26 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 25 1 26
2145 25 PUSHs(sv_2mortal(newSVnv(buf[i])));
2146 }
2147 }
2148 1 free(buf);
2149  
2150 double
2151 bandwidth(histo_kde_t *self)
2152 CODE:
2153 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
2154 1 RETVAL = histo_kde_get_bandwidth(self);
2155 OUTPUT:
2156 RETVAL
2157  
2158 int
2159 kernel(histo_kde_t *self)
2160 CODE:
2161 0 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 0 0
2162 0 ▶ RETVAL = (int)histo_kde_get_kernel(self);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (int)histo_kde_get_kernel(self); 0 0 0
2163 OUTPUT:
2164 RETVAL
2165  
2166 size_t
2167 n_points(histo_kde_t *self)
2168 CODE:
2169 1 ▶ if (!self) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!self) XSRETURN_UNDEF; 0 1 1
2170 1 RETVAL = histo_kde_num_points(self);
2171 OUTPUT:
2172 RETVAL
2173  
2174 MODULE = Math::Histo PACKAGE = Math::Histo::CLI PREFIX = histo_cli_xs_
2175  
2176 int
2177 run(...)
2178 PROTOTYPE: @
2179 CODE:
2180 9 int start = 0;
2181 18 ▶ if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) { 9 0 9
if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) { 9 0 9
if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) { 9 0 9
2182 9 start = 1;
2183 }
2184 9 int argc = items - start;
2185 9 ▶ if (argc == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (argc == 0) { 0 9 9
2186 0 char *default_argv[] = { "phisto", NULL };
2187 0 RETVAL = histo_cli_main(1, default_argv, stdout, stderr);
2188 } else {
2189 9 char **argv = (char **)malloc(((size_t)argc + 2) * sizeof(char *));
2190 9 ▶ if (!argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!argv) { 0 9 9
2191 0 croak("Math::Histo::CLI::run: out of memory allocating argv");
2192 }
2193 9 argv[0] = (char *)"phisto";
2194 {
2195 int i;
2196 28 ▶ for (i = 0; i < argc; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < argc; ++i) { 19 9 28
2197 38 argv[i + 1] = SvPV_nolen(ST(start + i));
2198 }
2199 }
2200 9 argv[argc + 1] = NULL;
2201 9 RETVAL = histo_cli_main(argc + 1, argv, stdout, stderr);
2202 9 free(argv);
2203 }
2204 OUTPUT:
2205 RETVAL
2206  
2207 void
2208 capture(...)
2209 PROTOTYPE: @
2210 PPCODE:
2211 3 int start = 0;
2212 6 ▶ if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) { 3 0 3
if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) { 3 0 3
if (items > 0 && SvPOK(ST(0)) && strcmp(SvPV_nolen(ST(0)), "Math::Histo::CLI") == 0) { 3 0 3
2213 3 start = 1;
2214 }
2215 3 int argc = items - start;
2216 3 char *out_buf = NULL;
2217 3 size_t out_sz = 0;
2218 3 char *err_buf = NULL;
2219 3 size_t err_sz = 0;
2220 3 int code = 0;
2221  
2222 3 ▶ if (argc == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (argc == 0) { 0 3 3
2223 0 char *default_argv[] = { (char *)"phisto", NULL };
2224 0 code = histo_xs_cli_capture(aTHX_ 1, default_argv, &out_buf, &out_sz, &err_buf, &err_sz);
2225 } else {
2226 3 char **argv = (char **)malloc(((size_t)argc + 2) * sizeof(char *));
2227 3 ▶ if (!argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!argv) { 0 3 3
2228 0 croak("Math::Histo::CLI::capture: out of memory");
2229 }
2230 3 argv[0] = (char *)"phisto";
2231 {
2232 int i;
2233 14 ▶ for (i = 0; i < argc; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < argc; ++i) { 11 3 14
2234 22 argv[i + 1] = SvPV_nolen(ST(start + i));
2235 }
2236 }
2237 3 argv[argc + 1] = NULL;
2238 3 code = histo_xs_cli_capture(aTHX_ argc + 1, argv, &out_buf, &out_sz, &err_buf, &err_sz);
2239 3 free(argv);
2240 }
2241  
2242 3 ▶ if (code < 0 && !out_buf && !err_buf) {
Branch: 3 branches
BranchTrueFalseTotal
if (code < 0 && !out_buf && !err_buf) { 0 3 3
if (code < 0 && !out_buf && !err_buf) { 0 0 0
if (code < 0 && !out_buf && !err_buf) { 0 0 0
2243 0 croak("Math::Histo::CLI::capture: stream capture failed");
2244 }
2245  
2246 3 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 3 3
2247 3 PUSHs(sv_2mortal(newSViv(code)));
2248 3 ▶ PUSHs(sv_2mortal(out_buf ? newSVpvn(out_buf, out_sz) : newSVpvn("", 0)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(sv_2mortal(out_buf ? newSVpvn(out_buf, out_sz) : newSVpvn("", 0))); 3 0 3
2249 3 ▶ PUSHs(sv_2mortal(err_buf ? newSVpvn(err_buf, err_sz) : newSVpvn("", 0)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(sv_2mortal(err_buf ? newSVpvn(err_buf, err_sz) : newSVpvn("", 0))); 3 0 3
2250 3 ▶ if (out_buf) free(out_buf);
Branch: 1 branch
BranchTrueFalseTotal
if (out_buf) free(out_buf); 3 0 3
2251 3 ▶ if (err_buf) free(err_buf);
Branch: 1 branch
BranchTrueFalseTotal
if (err_buf) free(err_buf); 3 0 3
2252  
2253  
2254 int
2255 histo_cli_xs_run_raw(...)
2256 PROTOTYPE: @
2257 CODE:
2258 /* Run with explicit argv[0] */
2259 0 int argc = items;
2260 0 ▶ if (argc == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (argc == 0) { 0 0 0
2261 0 char *default_argv[] = { "phisto", NULL };
2262 0 RETVAL = histo_cli_main(1, default_argv, stdout, stderr);
2263 } else {
2264 0 char **argv = (char **)malloc(((size_t)argc + 1) * sizeof(char *));
2265 0 ▶ if (!argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!argv) { 0 0 0
2266 0 croak("Math::Histo::CLI::run_raw: out of memory allocating argv");
2267 }
2268 {
2269 int i;
2270 0 ▶ for (i = 0; i < argc; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < argc; ++i) { 0 0 0
2271 0 argv[i] = SvPV_nolen(ST(i));
2272 }
2273 }
2274 0 argv[argc] = NULL;
2275 0 RETVAL = histo_cli_main(argc, argv, stdout, stderr);
2276 0 free(argv);
2277 }
2278 OUTPUT:
2279 RETVAL
2280  
« blib/lib/Math/Histo/Sketch.pm ↑ Summary blib/lib/Math/Histo/CLI.pm »