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