File Coverage

lib/PDL/Primitive-pp-vsearch_sample.c
Criterion Covered Total %
statement 62 84 73.8
branch 77 178 43.2
condition n/a
subroutine n/a
pod n/a
total 139 262 53.0


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/Primitive.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_Primitive
21             extern Core* PDL; /* Structure hold core C functions */
22             #line 23 "lib/PDL/Primitive-pp-vsearch_sample.c"
23             extern int pdl_srand_threads;
24             extern uint64_t *pdl_rand_state;
25             void pdl_srand(uint64_t **s, uint64_t seed, int n);
26             double pdl_drand(uint64_t *s);
27             #define PDL_MAYBE_SRAND \
28             if (pdl_srand_threads < 0) \
29             pdl_srand(&pdl_rand_state, PDL->pdl_seed(), PDL->online_cpus());
30             #define PDL_RAND_SET_OFFSET(v, thr, pdl) \
31             if (v < 0) { \
32             if (thr.mag_nthr >= 0) { \
33             int thr_no = PDL->magic_get_thread(pdl); \
34             if (thr_no < 0) return PDL->make_error_simple(PDL_EFATAL, "Invalid pdl_magic_get_thread!"); \
35             v = thr_no == 0 ? thr_no : thr_no % PDL->online_cpus(); \
36             } else { \
37             v = 0; \
38             } \
39             }
40              
41             #line 1857 "lib/PDL/PP.pm"
42             pdl_error pdl_vsearch_sample_readdata(pdl_trans *__privtrans) {
43             pdl_error PDL_err = {0, NULL, 0};
44             #line 45 "lib/PDL/Primitive-pp-vsearch_sample.c"
45 28           register PDL_Indx __n_size = __privtrans->ind_sizes[0];
46 28 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in vsearch_sample:" "broadcast.incs NULL");
47             /* broadcastloop declarations */
48             int __brcloopval;
49             register PDL_Indx __tind0,__tind1; /* counters along dim */
50 28           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
51             /* dims here are how many steps along those dims */
52 28           register PDL_Indx __tinc0_vals = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
53 28           register PDL_Indx __tinc0_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
54 28           register PDL_Indx __tinc0_idx = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,0);
55 28           register PDL_Indx __tinc1_vals = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
56 28           register PDL_Indx __tinc1_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
57 28           register PDL_Indx __tinc1_idx = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,1);
58             #define PDL_BROADCASTLOOP_START_vsearch_sample_readdata PDL_BROADCASTLOOP_START( \
59             readdata, \
60             __privtrans->broadcast, \
61             __privtrans->vtable, \
62             vals_datap += __offsp[0]; \
63             x_datap += __offsp[1]; \
64             idx_datap += __offsp[2]; \
65             , \
66             ( ,vals_datap += __tinc1_vals - __tinc0_vals * __tdims0 \
67             ,x_datap += __tinc1_x - __tinc0_x * __tdims0 \
68             ,idx_datap += __tinc1_idx - __tinc0_idx * __tdims0 \
69             ), \
70             ( ,vals_datap += __tinc0_vals \
71             ,x_datap += __tinc0_x \
72             ,idx_datap += __tinc0_idx \
73             ) \
74             )
75             #define PDL_BROADCASTLOOP_END_vsearch_sample_readdata PDL_BROADCASTLOOP_END( \
76             __privtrans->broadcast, \
77             vals_datap -= __tinc1_vals * __tdims1 + __offsp[0]; \
78             x_datap -= __tinc1_x * __tdims1 + __offsp[1]; \
79             idx_datap -= __tinc1_idx * __tdims1 + __offsp[2]; \
80             )
81 28           register PDL_Indx __inc_x_n = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,1,0)]; (void)__inc_x_n;
82             #ifndef PDL_DECLARE_PARAMS_vsearch_sample_1
83             #define PDL_DECLARE_PARAMS_vsearch_sample_1(PDL_TYPE_OP,PDL_PPSYM_OP,PDL_TYPE_PARAM_idx,PDL_PPSYM_PARAM_idx) \
84             PDL_DECLARE_PARAMETER_BADVAL(PDL_TYPE_OP, vals, (__privtrans->pdls[0]), 1, PDL_PPSYM_OP) \
85             PDL_DECLARE_PARAMETER_BADVAL(PDL_TYPE_OP, x, (__privtrans->pdls[1]), 1, PDL_PPSYM_OP) \
86             PDL_DECLARE_PARAMETER_BADVAL(PDL_TYPE_PARAM_idx, idx, (__privtrans->pdls[2]), 1, PDL_PPSYM_PARAM_idx)
87             #endif
88             #define PDL_IF_BAD(t,f) f
89 28           switch (__privtrans->__datatype) { /* Start generic switch */
90 0           case PDL_F: {
91 0 0         PDL_DECLARE_PARAMS_vsearch_sample_1(PDL_Float,F,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
92 0 0         PDL_BROADCASTLOOP_START_vsearch_sample_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
93 0 0         {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
94 0 0         if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,F,vals_badval_isnan) ) {
    0          
95 0           PDL_Indx n1 = __privtrans->ind_sizes[0]-1;
96 0           PDL_Indx low = -1;
97 0           PDL_Indx high = __privtrans->ind_sizes[0];
98             PDL_Indx mid;
99              
100 0           PDL_Float value = (vals_datap)[0];
101              
102             /* determine sort order of data */
103 0           int up = ((x_datap)[0+(__inc_x_n*(n1))] > (x_datap)[0+(__inc_x_n*(0))]);
104            
105 0 0         while ( high - low > 1 ) {
106 0           mid = low + (( high - low )>> 1);;
107 0 0         if ( ( value > (x_datap)[0+(__inc_x_n*(mid))] ) == up ) low = mid;
108 0           else high = mid;
109             }
110 0           (idx_datap)[0] = low >= n1 ? n1
111 0 0         : up ? low + 1
112 0 0         : PDLMAX(low, 0);
113              
114            
115             }
116              
117             else {
118 0           (idx_datap)[0]=idx_badval;
119             }
120             }} /* Close n */
121              
122 0 0         }PDL_BROADCASTLOOP_END_vsearch_sample_readdata
    0          
123 0           } break;
124 7           case PDL_D: {
125 7 50         PDL_DECLARE_PARAMS_vsearch_sample_1(PDL_Double,D,PDL_Indx,N)
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
126 1344 50         PDL_BROADCASTLOOP_START_vsearch_sample_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
127 824052 100         {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
128 822729 50         if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,D,vals_badval_isnan) ) {
    50          
129 822729           PDL_Indx n1 = __privtrans->ind_sizes[0]-1;
130 822729           PDL_Indx low = -1;
131 822729           PDL_Indx high = __privtrans->ind_sizes[0];
132             PDL_Indx mid;
133              
134 822729           PDL_Double value = (vals_datap)[0];
135              
136             /* determine sort order of data */
137 822729           int up = ((x_datap)[0+(__inc_x_n*(n1))] > (x_datap)[0+(__inc_x_n*(0))]);
138            
139 8855019 100         while ( high - low > 1 ) {
140 8032290           mid = low + (( high - low )>> 1);;
141 8032290 100         if ( ( value > (x_datap)[0+(__inc_x_n*(mid))] ) == up ) low = mid;
142 1343200           else high = mid;
143             }
144 822729           (idx_datap)[0] = low >= n1 ? n1
145 1121329 100         : up ? low + 1
146 298600 100         : PDLMAX(low, 0);
147              
148            
149             }
150              
151             else {
152 0           (idx_datap)[0]=idx_badval;
153             }
154             }} /* Close n */
155              
156 7 50         }PDL_BROADCASTLOOP_END_vsearch_sample_readdata
    50          
157 7           } break;
158 21           case PDL_LD: {
159 21 50         PDL_DECLARE_PARAMS_vsearch_sample_1(PDL_LDouble,E,PDL_Indx,N)
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
160 5860 50         PDL_BROADCASTLOOP_START_vsearch_sample_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
161 4197028 100         {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
162 4191231 50         if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,E,vals_badval_isnan) ) {
    100          
163 3145773           PDL_Indx n1 = __privtrans->ind_sizes[0]-1;
164 3145773           PDL_Indx low = -1;
165 3145773           PDL_Indx high = __privtrans->ind_sizes[0];
166             PDL_Indx mid;
167              
168 3145773           PDL_LDouble value = (vals_datap)[0];
169              
170             /* determine sort order of data */
171 3145773           int up = ((x_datap)[0+(__inc_x_n*(n1))] > (x_datap)[0+(__inc_x_n*(0))]);
172            
173 33298488 100         while ( high - low > 1 ) {
174 30152715           mid = low + (( high - low )>> 1);;
175 30152715 100         if ( ( value > (x_datap)[0+(__inc_x_n*(mid))] ) == up ) low = mid;
176 14345766           else high = mid;
177             }
178 3145773           (idx_datap)[0] = low >= n1 ? n1
179 6287208 100         : up ? low + 1
180 3141435 100         : PDLMAX(low, 0);
181              
182            
183             }
184              
185             else {
186 1045458           (idx_datap)[0]=idx_badval;
187             }
188             }} /* Close n */
189              
190 21 50         }PDL_BROADCASTLOOP_END_vsearch_sample_readdata
    50          
191 21           } break;
192 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in vsearch_sample: unhandled datatype(%d), only handles (FDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
193             }
194             #undef PDL_IF_BAD
195 28           return PDL_err;
196             }
197              
198             static pdl_datatypes pdl_vsearch_sample_vtable_gentypes[] = { PDL_F, PDL_D, PDL_LD, -1 };
199             static PDL_Indx pdl_vsearch_sample_vtable_realdims[] = { 0, 1, 0 };
200             static char *pdl_vsearch_sample_vtable_parnames[] = { "vals","x","idx" };
201             static short pdl_vsearch_sample_vtable_parflags[] = {
202             0,
203             0,
204             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISTYPED|PDL_PARAM_ISWRITE
205             };
206             static pdl_datatypes pdl_vsearch_sample_vtable_partypes[] = { -1, -1, PDL_IND };
207             static PDL_Indx pdl_vsearch_sample_vtable_realdims_starts[] = { 0, 0, 1 };
208             static PDL_Indx pdl_vsearch_sample_vtable_realdims_ind_ids[] = { 0 };
209             static char *pdl_vsearch_sample_vtable_indnames[] = { "n" };
210             pdl_transvtable pdl_vsearch_sample_vtable = {
211             PDL_TRANS_DO_BROADCAST|PDL_TRANS_BADPROCESS, 0, pdl_vsearch_sample_vtable_gentypes, 2, 3, NULL /*CORE21*/,
212             pdl_vsearch_sample_vtable_realdims, pdl_vsearch_sample_vtable_parnames,
213             pdl_vsearch_sample_vtable_parflags, pdl_vsearch_sample_vtable_partypes,
214             pdl_vsearch_sample_vtable_realdims_starts, pdl_vsearch_sample_vtable_realdims_ind_ids, 1,
215             1, pdl_vsearch_sample_vtable_indnames,
216             NULL, pdl_vsearch_sample_readdata, NULL,
217             NULL,
218             0,"PDL::Primitive::vsearch_sample"
219             };
220              
221              
222 28           pdl_error pdl_run_vsearch_sample(pdl *vals,pdl *x,pdl *idx) {
223 28           pdl_error PDL_err = {0, NULL, 0};
224 28 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
225 28           pdl_trans *__privtrans = PDL->create_trans(&pdl_vsearch_sample_vtable);
226 28 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
227 28           __privtrans->pdls[0] = vals;
228 28           __privtrans->pdls[1] = x;
229 28           __privtrans->pdls[2] = idx;
230 28 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
231 28 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
232 28           return PDL_err;
233             }