File Coverage

lib/PDL/Stats/TS-pp-acf.c
Criterion Covered Total %
statement 48 68 70.5
branch 31 88 35.2
condition n/a
subroutine n/a
pod n/a
total 79 156 50.6


line stmt bran cond sub pod time code
1              
2             #line 453 "lib/PDL/PP.pm"
3             /*
4             * THIS FILE WAS GENERATED BY PDL::PP from lib/PDL/Stats/TS.pd! Do not modify!
5             */
6              
7             #define PDL_FREE_CODE(trans, destroy, comp_free_code, ntpriv_free_code) \
8             if (destroy) { \
9             comp_free_code \
10             } \
11             if ((trans)->dims_redone) { \
12             ntpriv_free_code \
13             }
14              
15             #include "EXTERN.h"
16             #include "perl.h"
17             #include "XSUB.h"
18             #include "pdl.h"
19             #include "pdlcore.h"
20             #define PDL PDL_Stats_TS
21             extern Core* PDL; /* Structure hold core C functions */
22             #line 23 "lib/PDL/Stats/TS-pp-acf.c"
23              
24             #include
25             #define Z10 1.64485362695147
26             #define Z05 1.95996398454005
27             #define Z01 2.5758293035489
28             #define Z001 3.29052673149193
29              
30              
31             #line 1846 "lib/PDL/PP.pm"
32             typedef struct pdl_params_acf {
33             #line 34 "lib/PDL/Stats/TS-pp-acf.c"
34             IV lag;
35             } pdl_params_acf;
36              
37              
38             #line 1857 "lib/PDL/PP.pm"
39             pdl_error pdl_acf_redodims(pdl_trans *__privtrans) {
40             pdl_error PDL_err = {0, NULL, 0};
41             #line 42 "lib/PDL/Stats/TS-pp-acf.c"
42 2           pdl_params_acf *__params = __privtrans->params; (void)__params;
43 2           __privtrans->ind_sizes[0] = __params->lag;
44 2 50         PDL_RETERROR(PDL_err, PDL->redodims_default(__privtrans));
45 2           return PDL_err;
46             }
47              
48              
49             #line 1857 "lib/PDL/PP.pm"
50             pdl_error pdl_acf_readdata(pdl_trans *__privtrans) {
51             pdl_error PDL_err = {0, NULL, 0};
52             #line 53 "lib/PDL/Stats/TS-pp-acf.c"
53 2           pdl_params_acf *__params = __privtrans->params; (void)__params;
54 2           register PDL_Indx __h_size = __privtrans->ind_sizes[0];
55 2           register PDL_Indx __t_size = __privtrans->ind_sizes[1];
56 2 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in acf:" "broadcast.incs NULL");
57             /* broadcastloop declarations */
58             int __brcloopval;
59             register PDL_Indx __tind0,__tind1; /* counters along dim */
60 2           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
61             /* dims here are how many steps along those dims */
62 2           register PDL_Indx __tinc0_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
63 2           register PDL_Indx __tinc0_r = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
64 2           register PDL_Indx __tinc1_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
65 2           register PDL_Indx __tinc1_r = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
66             #define PDL_BROADCASTLOOP_START_acf_readdata PDL_BROADCASTLOOP_START( \
67             readdata, \
68             __privtrans->broadcast, \
69             __privtrans->vtable, \
70             x_datap += __offsp[0]; \
71             r_datap += __offsp[1]; \
72             , \
73             ( ,x_datap += __tinc1_x - __tinc0_x * __tdims0 \
74             ,r_datap += __tinc1_r - __tinc0_r * __tdims0 \
75             ), \
76             ( ,x_datap += __tinc0_x \
77             ,r_datap += __tinc0_r \
78             ) \
79             )
80             #define PDL_BROADCASTLOOP_END_acf_readdata PDL_BROADCASTLOOP_END( \
81             __privtrans->broadcast, \
82             x_datap -= __tinc1_x * __tdims1 + __offsp[0]; \
83             r_datap -= __tinc1_r * __tdims1 + __offsp[1]; \
84             )
85 2           register PDL_Indx __inc_r_h = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,1,0)]; (void)__inc_r_h;
86 2           register PDL_Indx __inc_x_t = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,0,0)]; (void)__inc_x_t;
87             #ifndef PDL_DECLARE_PARAMS_acf_1
88             #define PDL_DECLARE_PARAMS_acf_1(PDL_TYPE_OP,PDL_PPSYM_OP) \
89             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, x, (__privtrans->pdls[0]), 1, PDL_PPSYM_OP) \
90             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, r, (__privtrans->pdls[1]), 1, PDL_PPSYM_OP)
91             #endif
92             #define PDL_IF_BAD(t,f) f
93 2           switch (__privtrans->__datatype) { /* Start generic switch */
94 0           case PDL_F: {
95 0 0         PDL_DECLARE_PARAMS_acf_1(PDL_Float,F)
    0          
    0          
    0          
    0          
    0          
96 0 0         PDL_BROADCASTLOOP_START_acf_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
97             PDL_Float s, s2, m, cov0, covh;
98 0           s=0; s2=0; m=0; cov0=0; covh=0;
99             PDL_Indx T, i;
100 0           T = __privtrans->ind_sizes[1];
101 0 0         {/* Open t */ PDL_EXPAND2(register PDL_Indx t=0, __t_stop=(__t_size)); for(; t<__t_stop; t+=1) {
102 0           s += (x_datap)[0+(__inc_x_t*(t))];
103 0           s2 += (x_datap)[0+(__inc_x_t*(t))]*(x_datap)[0+(__inc_x_t*(t))];
104             }} /* Close t */
105 0           m = s/T;
106 0           cov0 = s2 - T * m * m;
107 0 0         {/* Open h */ PDL_EXPAND2(register PDL_Indx h=0, __h_stop=(__h_size)); for(; h<__h_stop; h+=1) {
108 0 0         if (h) {
109 0           covh = 0;
110 0 0         for (i=0; i
111 0           covh += ((x_datap)[0+(__inc_x_t*(i))] - m) * ((x_datap)[0+(__inc_x_t*(i+h))] - m);
112             }
113 0           (r_datap)[0+(__inc_r_h*(h))] = covh / cov0;
114             }
115             else {
116 0           (r_datap)[0+(__inc_r_h*(h))] = 1;
117             }
118             }} /* Close h */
119 0 0         }PDL_BROADCASTLOOP_END_acf_readdata
    0          
120 0           } break;
121 2           case PDL_D: {
122 2 50         PDL_DECLARE_PARAMS_acf_1(PDL_Double,D)
    50          
    50          
    50          
    50          
    50          
123 8 50         PDL_BROADCASTLOOP_START_acf_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
124             PDL_Double s, s2, m, cov0, covh;
125 2           s=0; s2=0; m=0; cov0=0; covh=0;
126             PDL_Indx T, i;
127 2           T = __privtrans->ind_sizes[1];
128 22 100         {/* Open t */ PDL_EXPAND2(register PDL_Indx t=0, __t_stop=(__t_size)); for(; t<__t_stop; t+=1) {
129 20           s += (x_datap)[0+(__inc_x_t*(t))];
130 20           s2 += (x_datap)[0+(__inc_x_t*(t))]*(x_datap)[0+(__inc_x_t*(t))];
131             }} /* Close t */
132 2           m = s/T;
133 2           cov0 = s2 - T * m * m;
134 13 100         {/* Open h */ PDL_EXPAND2(register PDL_Indx h=0, __h_stop=(__h_size)); for(; h<__h_stop; h+=1) {
135 11 100         if (h) {
136 9           covh = 0;
137 74 100         for (i=0; i
138 65           covh += ((x_datap)[0+(__inc_x_t*(i))] - m) * ((x_datap)[0+(__inc_x_t*(i+h))] - m);
139             }
140 9           (r_datap)[0+(__inc_r_h*(h))] = covh / cov0;
141             }
142             else {
143 2           (r_datap)[0+(__inc_r_h*(h))] = 1;
144             }
145             }} /* Close h */
146 2 50         }PDL_BROADCASTLOOP_END_acf_readdata
    50          
147 2           } break;
148 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in acf: unhandled datatype(%d), only handles (FD)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
149             }
150             #undef PDL_IF_BAD
151 2           return PDL_err;
152             }
153              
154             static pdl_datatypes pdl_acf_vtable_gentypes[] = { PDL_F, PDL_D, -1 };
155             static PDL_Indx pdl_acf_vtable_realdims[] = { 1, 1 };
156             static char *pdl_acf_vtable_parnames[] = { "x","r" };
157             static short pdl_acf_vtable_parflags[] = {
158             0,
159             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE
160             };
161             static pdl_datatypes pdl_acf_vtable_partypes[] = { -1, -1 };
162             static PDL_Indx pdl_acf_vtable_realdims_starts[] = { 0, 1 };
163             static PDL_Indx pdl_acf_vtable_realdims_ind_ids[] = { 1, 0 };
164             static char *pdl_acf_vtable_indnames[] = { "h","t" };
165             pdl_transvtable pdl_acf_vtable = {
166             PDL_TRANS_DO_BROADCAST, 0, pdl_acf_vtable_gentypes, 1, 2, NULL /*CORE21*/,
167             pdl_acf_vtable_realdims, pdl_acf_vtable_parnames,
168             pdl_acf_vtable_parflags, pdl_acf_vtable_partypes,
169             pdl_acf_vtable_realdims_starts, pdl_acf_vtable_realdims_ind_ids, 2,
170             2, pdl_acf_vtable_indnames,
171             pdl_acf_redodims, pdl_acf_readdata, NULL,
172             NULL,
173             sizeof(pdl_params_acf),"PDL::Stats::TS::acf"
174             };
175              
176              
177 2           pdl_error pdl_run_acf(pdl *x,pdl *r,IV lag) {
178 2           pdl_error PDL_err = {0, NULL, 0};
179 2 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
180 2           pdl_trans *__privtrans = PDL->create_trans(&pdl_acf_vtable);
181 2 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
182 2           pdl_params_acf *__params = __privtrans->params;
183 2           __privtrans->pdls[0] = x;
184 2           __privtrans->pdls[1] = r;
185 2 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
186 2           (__params->lag) = (lag); /* CType.get_copy */
187 2 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
188 2           return PDL_err;
189             }