XS/Axis.xs

filter: Statementstmt 80.8% 38 / 47 Branchbran 83.9% 47 / 56 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 82.5% 85 / 103 SCAR 0
CC
0
Cov
0%
CRAP 0
« perl_type_tools.h ↑ Summary mh_axis.c »
1  
2 MODULE = Math::Histogram PACKAGE = Math::Histogram::Axis
3  
4 mh_axis_t *
5 mh_axis_t::new(...)
6 PREINIT:
7 SV *tmp;
8 AV *bins;
9 I32 n, i;
10 double prev;
11 double *dbl_ary;
12 CODE:
13 /* varbins => just a single arrayref */
14 36 ▶ if (items == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) { 11 25 36
15 11 tmp = ST(1);
16 11 ▶ DEREF_RV_TO_AV(bins, tmp);
Branch: 2 branches
BranchTrueFalseTotal
DEREF_RV_TO_AV(bins, tmp); 11 0 11
DEREF_RV_TO_AV(bins, tmp); 0 11 11
17 if (bins == NULL)
18 0 croak("Need either array reference as first parameter or a number of bins followed by min/max");
19 11 n = av_len(bins) + 1;
20 11 ▶ if (n <= 1)
Branch: 1 branch
BranchTrueFalseTotal
if (n <= 1) 0 11 11
21 0 croak("Bins array must have at least a lower and upper boundary for a single bin");
22  
23 11 RETVAL = mh_axis_create( n-1, MH_AXIS_OPT_VARBINS );
24 11 ▶ if (RETVAL == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == NULL) 0 11 11
25 0 croak("Cannot create Math::Histogram::Axis! Invalid number of bins or out of memory.");
26  
27 11 av_to_double_ary(aTHX_ bins, RETVAL->bins);
28  
29 /* Check whether the numbers make some basic sense */
30 11 dbl_ary = RETVAL->bins;
31 11 prev = dbl_ary[0];
32 55 ▶ for (i = 1; i < n; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < n; ++i) { 44 11 55
33 44 ▶ if (dbl_ary[i] <= prev) {
Branch: 1 branch
BranchTrueFalseTotal
if (dbl_ary[i] <= prev) { 0 44 44
34 0 mh_axis_free(RETVAL);
35 0 croak("Bin boundaries for histogram axis are not strictly monotonic!");
36 }
37 prev = dbl_ary[i];
38 }
39 11 mh_axis_init( RETVAL, RETVAL->bins[0], RETVAL->bins[n-1] );
40 }
41 /* fixbins => n, min, max */
42 25 ▶ else if (items == 4) {
Branch: 1 branch
BranchTrueFalseTotal
else if (items == 4) { 25 0 25
43 25 RETVAL = mh_axis_create( SvUV(ST(1)), MH_AXIS_OPT_FIXEDBINS );
44 25 ▶ if (RETVAL == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == NULL) 0 25 25
45 0 croak("Cannot create Math::Histogram::Axis! Invalid number of bins or out of memory.");
46 25 prev = SvNV(ST(2));
47 25 ▶ if (prev >= SvNV(ST(3))) {
Branch: 1 branch
BranchTrueFalseTotal
if (prev >= SvNV(ST(3))) { 0 25 25
48 0 mh_axis_free(RETVAL);
49 0 croak("Lower axis boundary (%f) cannot be larger than or equal to upper boundary (%f)!", prev, SvNV(ST(3)));
50 }
51 25 mh_axis_init( RETVAL, prev, SvNV(ST(3)) );
52 }
53 OUTPUT: RETVAL
54  
55  
56 void
57 mh_axis_t::DESTROY()
58 CODE:
59 /* free only if not owned by some histogram */
60 69 ▶ if (!( PTR2UV(MH_AXIS_USERDATA(THIS)) & F_AXIS_OWNED_BY_HIST ))
Branch: 1 branch
BranchTrueFalseTotal
if (!( PTR2UV(MH_AXIS_USERDATA(THIS)) & F_AXIS_OWNED_BY_HIST )) 13 56 69
61 13 mh_axis_free(THIS);
62  
63  
64 void
65 mh_axis_t::_as_hash()
66 PREINIT:
67 SV *rv;
68 PPCODE:
69 1 rv = sv_2mortal(axis_to_hashref(aTHX_ THIS));
70 1 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 1 1
71 1 XSRETURN(1);
72  
73  
74 mh_axis_t *
75 _from_hash(CLASS, hash)
76 char *CLASS;
77 HV *hash;
78 CODE:
79 1 RETVAL = hash_to_axis(aTHX_ hash);
80 OUTPUT: RETVAL
81  
82  
83 mh_axis_t *
84 mh_axis_t::clone()
85 PREINIT:
86 const char *CLASS = "Math::Histogram::Axis"; /* hack around deficient typemap */
87 CODE:
88 0 RETVAL = mh_axis_clone(THIS);
89 OUTPUT: RETVAL
90  
91  
92 unsigned int
93 mh_axis_t::nbins()
94 CODE:
95 55 ▶ RETVAL = MH_AXIS_NBINS(THIS);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_NBINS(THIS); 41 14 55
96 OUTPUT: RETVAL
97  
98  
99 double
100 mh_axis_t::min()
101 CODE:
102 26 ▶ RETVAL = MH_AXIS_MIN(THIS);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_MIN(THIS); 20 6 26
103 OUTPUT: RETVAL
104  
105  
106 double
107 mh_axis_t::max()
108 CODE:
109 26 ▶ RETVAL = MH_AXIS_MAX(THIS);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_MAX(THIS); 20 6 26
110 OUTPUT: RETVAL
111  
112  
113 double
114 mh_axis_t::width()
115 CODE:
116 24 ▶ RETVAL = MH_AXIS_WIDTH(THIS);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_WIDTH(THIS); 19 5 24
117 OUTPUT: RETVAL
118  
119  
120  
121 double
122 mh_axis_t::binsize(unsigned int ibin = 1)
123 CODE:
124 660 ▶ ASSERT_BIN_RANGE(THIS, ibin);
Branch: 2 branches
BranchTrueFalseTotal
ASSERT_BIN_RANGE(THIS, ibin); 658 2 660
ASSERT_BIN_RANGE(THIS, ibin); 2 656 658
125 656 ▶ RETVAL = MH_AXIS_BINSIZE(THIS, ibin);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_BINSIZE(THIS, ibin); 620 36 656
126 OUTPUT: RETVAL
127  
128  
129 double
130 mh_axis_t::lower_boundary(unsigned int ibin = 1)
131 CODE:
132 984 ▶ ASSERT_BIN_RANGE(THIS, ibin);
Branch: 2 branches
BranchTrueFalseTotal
ASSERT_BIN_RANGE(THIS, ibin); 982 2 984
ASSERT_BIN_RANGE(THIS, ibin); 2 980 982
133 980 ▶ RETVAL = MH_AXIS_BIN_LOWER(THIS, ibin);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_BIN_LOWER(THIS, ibin); 928 52 980
134 OUTPUT: RETVAL
135  
136  
137 double
138 mh_axis_t::upper_boundary(unsigned int ibin = 1)
139 CODE:
140 984 ▶ ASSERT_BIN_RANGE(THIS, ibin);
Branch: 2 branches
BranchTrueFalseTotal
ASSERT_BIN_RANGE(THIS, ibin); 982 2 984
ASSERT_BIN_RANGE(THIS, ibin); 2 980 982
141 980 ▶ RETVAL = MH_AXIS_BIN_UPPER(THIS, ibin);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_BIN_UPPER(THIS, ibin); 928 52 980
142 OUTPUT: RETVAL
143  
144  
145 double
146 mh_axis_t::bin_center(unsigned int ibin = 1)
147 CODE:
148 984 ▶ ASSERT_BIN_RANGE(THIS, ibin);
Branch: 2 branches
BranchTrueFalseTotal
ASSERT_BIN_RANGE(THIS, ibin); 982 2 984
ASSERT_BIN_RANGE(THIS, ibin); 2 980 982
149 980 ▶ RETVAL = MH_AXIS_BIN_CENTER(THIS, ibin);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = MH_AXIS_BIN_CENTER(THIS, ibin); 928 52 980
150 OUTPUT: RETVAL
151  
152  
153 unsigned int
154 mh_axis_t::find_bin(double x)
155 CODE:
156 996 RETVAL = mh_axis_find_bin(THIS, x);
157 OUTPUT: RETVAL
158  
« perl_type_tools.h ↑ Summary mh_axis.c »