File Coverage

lib/PDL/Primitive-pp-vsearch_insert_leftmost.c
Criterion Covered Total %
statement 58 78 74.3
branch 73 172 42.4
condition n/a
subroutine n/a
pod n/a
total 131 250 52.4


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_insert_leftmost.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_insert_leftmost_readdata(pdl_trans *__privtrans) {
43             pdl_error PDL_err = {0, NULL, 0};
44             #line 45 "lib/PDL/Primitive-pp-vsearch_insert_leftmost.c"
45 24           register PDL_Indx __n_size = __privtrans->ind_sizes[0];
46 24 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in vsearch_insert_leftmost:" "broadcast.incs NULL");
47             /* broadcastloop declarations */
48             int __brcloopval;
49             register PDL_Indx __tind0,__tind1; /* counters along dim */
50 24           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
51             /* dims here are how many steps along those dims */
52 24           register PDL_Indx __tinc0_vals = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
53 24           register PDL_Indx __tinc0_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
54 24           register PDL_Indx __tinc0_idx = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,0);
55 24           register PDL_Indx __tinc1_vals = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
56 24           register PDL_Indx __tinc1_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
57 24           register PDL_Indx __tinc1_idx = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,1);
58             #define PDL_BROADCASTLOOP_START_vsearch_insert_leftmost_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_insert_leftmost_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 24           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_insert_leftmost_1
83             #define PDL_DECLARE_PARAMS_vsearch_insert_leftmost_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 24           switch (__privtrans->__datatype) { /* Start generic switch */
90 0           case PDL_F: {
91 0 0         PDL_DECLARE_PARAMS_vsearch_insert_leftmost_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_insert_leftmost_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 = 0;
97 0           PDL_Indx high = n1;
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 (low <= high ) {
106 0           mid = low + (( high - low )>> 1);;
107 0 0         if ( ( (x_datap)[0+(__inc_x_n*(mid))] >= value ) == up ) high = mid - 1;
108 0           else low = mid + 1;
109             }
110 0 0         (idx_datap)[0] = up ? low : high;
111            
112             }
113              
114             else {
115 0           (idx_datap)[0]=idx_badval;
116             }
117             }} /* Close n */
118              
119 0 0         }PDL_BROADCASTLOOP_END_vsearch_insert_leftmost_readdata
    0          
120 0           } break;
121 5           case PDL_D: {
122 5 50         PDL_DECLARE_PARAMS_vsearch_insert_leftmost_1(PDL_Double,D,PDL_Indx,N)
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
123 1138 50         PDL_BROADCASTLOOP_START_vsearch_insert_leftmost_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
124 803852 100         {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
125 802729 50         if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,D,vals_badval_isnan) ) {
    50          
126 802729           PDL_Indx n1 = __privtrans->ind_sizes[0]-1;
127 802729           PDL_Indx low = 0;
128 802729           PDL_Indx high = n1;
129             PDL_Indx mid;
130              
131 802729           PDL_Double value = (vals_datap)[0];
132              
133             /* determine sort order of data */
134 802729           int up = (x_datap)[0+(__inc_x_n*(n1))] >= (x_datap)[0+(__inc_x_n*(0))];
135            
136 8177090 100         while (low <= high ) {
137 7374361           mid = low + (( high - low )>> 1);;
138 7374361 100         if ( ( (x_datap)[0+(__inc_x_n*(mid))] >= value ) == up ) high = mid - 1;
139 1388800           else low = mid + 1;
140             }
141 802729 100         (idx_datap)[0] = up ? low : high;
142            
143             }
144              
145             else {
146 0           (idx_datap)[0]=idx_badval;
147             }
148             }} /* Close n */
149              
150 5 50         }PDL_BROADCASTLOOP_END_vsearch_insert_leftmost_readdata
    50          
151 5           } break;
152 19           case PDL_LD: {
153 19 50         PDL_DECLARE_PARAMS_vsearch_insert_leftmost_1(PDL_LDouble,E,PDL_Indx,N)
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
154 5852 50         PDL_BROADCASTLOOP_START_vsearch_insert_leftmost_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
155 4195580 100         {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
156 4189785 50         if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,E,vals_badval_isnan) ) {
    100          
157 3144327           PDL_Indx n1 = __privtrans->ind_sizes[0]-1;
158 3144327           PDL_Indx low = 0;
159 3144327           PDL_Indx high = n1;
160             PDL_Indx mid;
161              
162 3144327           PDL_LDouble value = (vals_datap)[0];
163              
164             /* determine sort order of data */
165 3144327           int up = (x_datap)[0+(__inc_x_n*(n1))] >= (x_datap)[0+(__inc_x_n*(0))];
166            
167 33283305 100         while (low <= high ) {
168 30138978           mid = low + (( high - low )>> 1);;
169 30138978 100         if ( ( (x_datap)[0+(__inc_x_n*(mid))] >= value ) == up ) high = mid - 1;
170 15799719           else low = mid + 1;
171             }
172 3144327 100         (idx_datap)[0] = up ? low : high;
173            
174             }
175              
176             else {
177 1045458           (idx_datap)[0]=idx_badval;
178             }
179             }} /* Close n */
180              
181 19 50         }PDL_BROADCASTLOOP_END_vsearch_insert_leftmost_readdata
    50          
182 19           } break;
183 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in vsearch_insert_leftmost: unhandled datatype(%d), only handles (FDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
184             }
185             #undef PDL_IF_BAD
186 24           return PDL_err;
187             }
188              
189             static pdl_datatypes pdl_vsearch_insert_leftmost_vtable_gentypes[] = { PDL_F, PDL_D, PDL_LD, -1 };
190             static PDL_Indx pdl_vsearch_insert_leftmost_vtable_realdims[] = { 0, 1, 0 };
191             static char *pdl_vsearch_insert_leftmost_vtable_parnames[] = { "vals","x","idx" };
192             static short pdl_vsearch_insert_leftmost_vtable_parflags[] = {
193             0,
194             0,
195             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISTYPED|PDL_PARAM_ISWRITE
196             };
197             static pdl_datatypes pdl_vsearch_insert_leftmost_vtable_partypes[] = { -1, -1, PDL_IND };
198             static PDL_Indx pdl_vsearch_insert_leftmost_vtable_realdims_starts[] = { 0, 0, 1 };
199             static PDL_Indx pdl_vsearch_insert_leftmost_vtable_realdims_ind_ids[] = { 0 };
200             static char *pdl_vsearch_insert_leftmost_vtable_indnames[] = { "n" };
201             pdl_transvtable pdl_vsearch_insert_leftmost_vtable = {
202             PDL_TRANS_DO_BROADCAST|PDL_TRANS_BADPROCESS, 0, pdl_vsearch_insert_leftmost_vtable_gentypes, 2, 3, NULL /*CORE21*/,
203             pdl_vsearch_insert_leftmost_vtable_realdims, pdl_vsearch_insert_leftmost_vtable_parnames,
204             pdl_vsearch_insert_leftmost_vtable_parflags, pdl_vsearch_insert_leftmost_vtable_partypes,
205             pdl_vsearch_insert_leftmost_vtable_realdims_starts, pdl_vsearch_insert_leftmost_vtable_realdims_ind_ids, 1,
206             1, pdl_vsearch_insert_leftmost_vtable_indnames,
207             NULL, pdl_vsearch_insert_leftmost_readdata, NULL,
208             NULL,
209             0,"PDL::Primitive::vsearch_insert_leftmost"
210             };
211              
212              
213 24           pdl_error pdl_run_vsearch_insert_leftmost(pdl *vals,pdl *x,pdl *idx) {
214 24           pdl_error PDL_err = {0, NULL, 0};
215 24 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
216 24           pdl_trans *__privtrans = PDL->create_trans(&pdl_vsearch_insert_leftmost_vtable);
217 24 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
218 24           __privtrans->pdls[0] = vals;
219 24           __privtrans->pdls[1] = x;
220 24           __privtrans->pdls[2] = idx;
221 24 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
222 24 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
223 24           return PDL_err;
224             }