« lib/PDL/Primitive-pp-vsearch_insert_leftmost.c
↑ Summary
lib/PDL/Primitive-pp-vsearch_bin_inclusive.c »
| 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_rightmost.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 1888 "lib/PDL/PP.pm" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | pdl_error pdl_vsearch_insert_rightmost_readdata(pdl_trans *__privtrans) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | pdl_error PDL_err = {0, NULL, 0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #line 45 "lib/PDL/Primitive-pp-vsearch_insert_rightmost.c" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 25 | register PDL_Indx __n_size = __privtrans->ind_sizes[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 25 | ▶ | if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in vsearch_insert_rightmost:" "broadcast.incs NULL"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | /* broadcastloop declarations */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | int __brcloopval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | register PDL_Indx __tind0,__tind1; /* counters along dim */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 25 | register PDL_Indx __tnpdls = __privtrans->broadcast.npdls; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | /* dims here are how many steps along those dims */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 25 | register PDL_Indx __tinc0_vals = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | register PDL_Indx __tinc0_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 25 | register PDL_Indx __tinc0_idx = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 25 | register PDL_Indx __tinc1_vals = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 25 | register PDL_Indx __tinc1_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 25 | register PDL_Indx __tinc1_idx = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | #define PDL_BROADCASTLOOP_START_vsearch_insert_rightmost_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_rightmost_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 | 25 | 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_rightmost_1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #define PDL_DECLARE_PARAMS_vsearch_insert_rightmost_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 | 25 | switch (__privtrans->__datatype) { /* Start generic switch */ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | case PDL_F: { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | PDL_DECLARE_PARAMS_vsearch_insert_rightmost_1(PDL_Float,F,PDL_Indx,N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | PDL_BROADCASTLOOP_START_vsearch_insert_rightmost_readdata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,F,vals_badval_isnan) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | while (low <= high ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | mid = low + (( high - low )>> 1);; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( ( (x_datap)[0+(__inc_x_n*(mid))] > value ) == up ) high = mid - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | else low = mid + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | (idx_datap)[0] = up ? low : high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | (idx_datap)[0]=idx_badval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | }} /* Close n */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | }PDL_BROADCASTLOOP_END_vsearch_insert_rightmost_readdata | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | } break; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | case PDL_D: { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 5 | ▶ | PDL_DECLARE_PARAMS_vsearch_insert_rightmost_1(PDL_Double,D,PDL_Indx,N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1138 | ▶ | PDL_BROADCASTLOOP_START_vsearch_insert_rightmost_readdata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 803852 | ▶ | {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 802729 | ▶ | if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,D,vals_badval_isnan) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 8699819 | ▶ | while (low <= high ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 7897090 | mid = low + (( high - low )>> 1);; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 7897090 | ▶ | if ( ( (x_datap)[0+(__inc_x_n*(mid))] > value ) == up ) high = mid - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6616090 | else low = mid + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 802729 | ▶ | (idx_datap)[0] = up ? low : high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | (idx_datap)[0]=idx_badval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | }} /* Close n */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | ▶ | }PDL_BROADCASTLOOP_END_vsearch_insert_rightmost_readdata | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 5 | } break; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 20 | case PDL_LD: { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 20 | ▶ | PDL_DECLARE_PARAMS_vsearch_insert_rightmost_1(PDL_LDouble,E,PDL_Indx,N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 5856 | ▶ | PDL_BROADCASTLOOP_START_vsearch_insert_rightmost_readdata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4196304 | ▶ | {/* Open n */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=(__n_size)); for(; n<__n_stop; n+=1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4190508 | ▶ | if ( !PDL_ISBAD2((vals_datap)[0],vals_badval,E,vals_badval_isnan) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 3145050 | PDL_Indx n1 = __privtrans->ind_sizes[0]-1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3145050 | PDL_Indx low = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3145050 | PDL_Indx high = n1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | PDL_Indx mid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 3145050 | PDL_LDouble value = (vals_datap)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | /* determine sort order of data */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 3145050 | int up = (x_datap)[0+(__inc_x_n*(n1))] >= (x_datap)[0+(__inc_x_n*(0))]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 33291258 | ▶ | while (low <= high ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 30146208 | mid = low + (( high - low )>> 1);; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 30146208 | ▶ | if ( ( (x_datap)[0+(__inc_x_n*(mid))] > value ) == up ) high = mid - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 15806226 | else low = mid + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 3145050 | ▶ | (idx_datap)[0] = up ? low : high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1045458 | (idx_datap)[0]=idx_badval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | }} /* Close n */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 20 | ▶ | }PDL_BROADCASTLOOP_END_vsearch_insert_rightmost_readdata | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 20 | } break; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in vsearch_insert_rightmost: unhandled datatype(%d), only handles (FDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | #undef PDL_IF_BAD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 25 | return PDL_err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | static pdl_datatypes pdl_vsearch_insert_rightmost_vtable_gentypes[] = { PDL_F, PDL_D, PDL_LD, -1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | static PDL_Indx pdl_vsearch_insert_rightmost_vtable_realdims[] = { 0, 1, 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | static char *pdl_vsearch_insert_rightmost_vtable_parnames[] = { "vals","x","idx" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | static short pdl_vsearch_insert_rightmost_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_rightmost_vtable_partypes[] = { -1, -1, PDL_IND }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | static PDL_Indx pdl_vsearch_insert_rightmost_vtable_realdims_starts[] = { 0, 0, 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | static PDL_Indx pdl_vsearch_insert_rightmost_vtable_realdims_ind_ids[] = { 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | static char *pdl_vsearch_insert_rightmost_vtable_indnames[] = { "n" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | pdl_transvtable pdl_vsearch_insert_rightmost_vtable = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | PDL_TRANS_DO_BROADCAST|PDL_TRANS_BADPROCESS, 0, pdl_vsearch_insert_rightmost_vtable_gentypes, 2, 3, NULL /*CORE21*/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | pdl_vsearch_insert_rightmost_vtable_realdims, pdl_vsearch_insert_rightmost_vtable_parnames, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | pdl_vsearch_insert_rightmost_vtable_parflags, pdl_vsearch_insert_rightmost_vtable_partypes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | pdl_vsearch_insert_rightmost_vtable_realdims_starts, pdl_vsearch_insert_rightmost_vtable_realdims_ind_ids, 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1, pdl_vsearch_insert_rightmost_vtable_indnames, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | NULL, pdl_vsearch_insert_rightmost_readdata, NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | NULL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0,"PDL::Primitive::vsearch_insert_rightmost" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 25 | pdl_error pdl_run_vsearch_insert_rightmost(pdl *vals,pdl *x,pdl *idx) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 25 | pdl_error PDL_err = {0, NULL, 0}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 25 | ▶ | if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 25 | pdl_trans *__privtrans = PDL->create_trans(&pdl_vsearch_insert_rightmost_vtable); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 25 | ▶ | if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 25 | __privtrans->pdls[0] = vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 25 | __privtrans->pdls[1] = x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 25 | __privtrans->pdls[2] = idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 25 | ▶ | PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 25 | ▶ | PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 25 | return PDL_err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||