File Coverage

lib/PDL/Primitive-pp-pchip_chfe.c
Criterion Covered Total %
statement 53 75 70.6
branch 47 246 19.1
condition n/a
subroutine n/a
pod n/a
total 100 321 31.1


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-pchip_chfe.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_pchip_chfe_redodims(pdl_trans *__privtrans) {
43             pdl_error PDL_err = {0, NULL, 0};
44             #line 45 "lib/PDL/Primitive-pp-pchip_chfe.c"
45             #ifndef PDL_DECLARE_PARAMS_pchip_chfe_0
46             #define PDL_DECLARE_PARAMS_pchip_chfe_0(PDL_TYPE_OP,PDL_PPSYM_OP,PDL_TYPE_PARAM_ierr,PDL_PPSYM_PARAM_ierr,PDL_TYPE_PARAM_skip,PDL_PPSYM_PARAM_skip) \
47             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, x, (__privtrans->pdls[0]), 0, PDL_PPSYM_OP) \
48             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, f, (__privtrans->pdls[1]), 0, PDL_PPSYM_OP) \
49             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, d, (__privtrans->pdls[2]), 0, PDL_PPSYM_OP) \
50             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, xe, (__privtrans->pdls[3]), 0, PDL_PPSYM_OP) \
51             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, fe, (__privtrans->pdls[4]), 0, PDL_PPSYM_OP) \
52             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_ierr, ierr, (__privtrans->pdls[5]), 0, PDL_PPSYM_PARAM_ierr) \
53             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_skip, skip, (__privtrans->pdls[6]), 0, PDL_PPSYM_PARAM_skip)
54             #endif
55             #define PDL_IF_BAD(t,f) f
56 7           switch (__privtrans->__datatype) { /* Start generic switch */
57 0           case PDL_F: {
58 0 0         PDL_DECLARE_PARAMS_pchip_chfe_0(PDL_Float,F,PDL_Indx,N,PDL_Long,L)
    0          
    0          
    0          
    0          
    0          
    0          
59 0 0         {if (__privtrans->ind_sizes[0] < 2) return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "NUMBER OF DATA POINTS LESS THAN TWO");
60 0 0         if (__privtrans->ind_sizes[1] < 1) return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "NUMBER OF EVALUATION POINTS LESS THAN ONE");
61             }
62 0           } break;
63 7           case PDL_D: {
64 7 50         PDL_DECLARE_PARAMS_pchip_chfe_0(PDL_Double,D,PDL_Indx,N,PDL_Long,L)
    50          
    50          
    50          
    50          
    50          
    50          
65 7 50         {if (__privtrans->ind_sizes[0] < 2) return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "NUMBER OF DATA POINTS LESS THAN TWO");
66 7 50         if (__privtrans->ind_sizes[1] < 1) return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "NUMBER OF EVALUATION POINTS LESS THAN ONE");
67             }
68 7           } break;
69 0           case PDL_LD: {
70 0 0         PDL_DECLARE_PARAMS_pchip_chfe_0(PDL_LDouble,E,PDL_Indx,N,PDL_Long,L)
    0          
    0          
    0          
    0          
    0          
    0          
71 0 0         {if (__privtrans->ind_sizes[0] < 2) return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "NUMBER OF DATA POINTS LESS THAN TWO");
72 0 0         if (__privtrans->ind_sizes[1] < 1) return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "NUMBER OF EVALUATION POINTS LESS THAN ONE");
73             }
74 0           } break;
75 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in pchip_chfe: unhandled datatype(%d), only handles (FDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
76             }
77             #undef PDL_IF_BAD
78              
79 7 50         PDL_RETERROR(PDL_err, PDL->redodims_default(__privtrans));
80 7           return PDL_err;
81             }
82              
83              
84             #line 1857 "lib/PDL/PP.pm"
85             pdl_error pdl_pchip_chfe_readdata(pdl_trans *__privtrans) {
86             pdl_error PDL_err = {0, NULL, 0};
87             #line 88 "lib/PDL/Primitive-pp-pchip_chfe.c"
88 7           register PDL_Indx __n_size = __privtrans->ind_sizes[0];
89 7           register PDL_Indx __ne_size = __privtrans->ind_sizes[1];
90 7 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "broadcast.incs NULL");
91             /* broadcastloop declarations */
92             int __brcloopval;
93             register PDL_Indx __tind0,__tind1; /* counters along dim */
94 7           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
95             /* dims here are how many steps along those dims */
96 7           register PDL_Indx __tinc0_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
97 7           register PDL_Indx __tinc0_f = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
98 7           register PDL_Indx __tinc0_d = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,0);
99 7           register PDL_Indx __tinc0_xe = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,3,0);
100 7           register PDL_Indx __tinc0_fe = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,4,0);
101 7           register PDL_Indx __tinc0_ierr = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,5,0);
102 7           register PDL_Indx __tinc0_skip = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,6,0);
103 7           register PDL_Indx __tinc1_x = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
104 7           register PDL_Indx __tinc1_f = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
105 7           register PDL_Indx __tinc1_d = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,1);
106 7           register PDL_Indx __tinc1_xe = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,3,1);
107 7           register PDL_Indx __tinc1_fe = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,4,1);
108 7           register PDL_Indx __tinc1_ierr = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,5,1);
109 7           register PDL_Indx __tinc1_skip = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,6,1);
110             #define PDL_BROADCASTLOOP_START_pchip_chfe_readdata PDL_BROADCASTLOOP_START( \
111             readdata, \
112             __privtrans->broadcast, \
113             __privtrans->vtable, \
114             x_datap += __offsp[0]; \
115             f_datap += __offsp[1]; \
116             d_datap += __offsp[2]; \
117             xe_datap += __offsp[3]; \
118             fe_datap += __offsp[4]; \
119             ierr_datap += __offsp[5]; \
120             skip_datap += __offsp[6]; \
121             , \
122             ( ,x_datap += __tinc1_x - __tinc0_x * __tdims0 \
123             ,f_datap += __tinc1_f - __tinc0_f * __tdims0 \
124             ,d_datap += __tinc1_d - __tinc0_d * __tdims0 \
125             ,xe_datap += __tinc1_xe - __tinc0_xe * __tdims0 \
126             ,fe_datap += __tinc1_fe - __tinc0_fe * __tdims0 \
127             ,ierr_datap += __tinc1_ierr - __tinc0_ierr * __tdims0 \
128             ,skip_datap += __tinc1_skip - __tinc0_skip * __tdims0 \
129             ), \
130             ( ,x_datap += __tinc0_x \
131             ,f_datap += __tinc0_f \
132             ,d_datap += __tinc0_d \
133             ,xe_datap += __tinc0_xe \
134             ,fe_datap += __tinc0_fe \
135             ,ierr_datap += __tinc0_ierr \
136             ,skip_datap += __tinc0_skip \
137             ) \
138             )
139             #define PDL_BROADCASTLOOP_END_pchip_chfe_readdata PDL_BROADCASTLOOP_END( \
140             __privtrans->broadcast, \
141             x_datap -= __tinc1_x * __tdims1 + __offsp[0]; \
142             f_datap -= __tinc1_f * __tdims1 + __offsp[1]; \
143             d_datap -= __tinc1_d * __tdims1 + __offsp[2]; \
144             xe_datap -= __tinc1_xe * __tdims1 + __offsp[3]; \
145             fe_datap -= __tinc1_fe * __tdims1 + __offsp[4]; \
146             ierr_datap -= __tinc1_ierr * __tdims1 + __offsp[5]; \
147             skip_datap -= __tinc1_skip * __tdims1 + __offsp[6]; \
148             )
149 7           register PDL_Indx __inc_d_n = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,2,0)]; (void)__inc_d_n;
150 7           register PDL_Indx __inc_f_n = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,1,0)]; (void)__inc_f_n;
151 7           register PDL_Indx __inc_fe_ne = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,4,0)]; (void)__inc_fe_ne;
152 7           register PDL_Indx __inc_x_n = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,0,0)]; (void)__inc_x_n;
153 7           register PDL_Indx __inc_xe_ne = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,3,0)]; (void)__inc_xe_ne;
154             #ifndef PDL_DECLARE_PARAMS_pchip_chfe_1
155             #define PDL_DECLARE_PARAMS_pchip_chfe_1(PDL_TYPE_OP,PDL_PPSYM_OP,PDL_TYPE_PARAM_ierr,PDL_PPSYM_PARAM_ierr,PDL_TYPE_PARAM_skip,PDL_PPSYM_PARAM_skip) \
156             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, x, (__privtrans->pdls[0]), 1, PDL_PPSYM_OP) \
157             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, f, (__privtrans->pdls[1]), 1, PDL_PPSYM_OP) \
158             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, d, (__privtrans->pdls[2]), 1, PDL_PPSYM_OP) \
159             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, xe, (__privtrans->pdls[3]), 1, PDL_PPSYM_OP) \
160             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, fe, (__privtrans->pdls[4]), 1, PDL_PPSYM_OP) \
161             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_ierr, ierr, (__privtrans->pdls[5]), 1, PDL_PPSYM_PARAM_ierr) \
162             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_skip, skip, (__privtrans->pdls[6]), 1, PDL_PPSYM_PARAM_skip)
163             #endif
164             #define PDL_IF_BAD(t,f) f
165 7           switch (__privtrans->__datatype) { /* Start generic switch */
166 0           case PDL_F: {
167 0 0         PDL_DECLARE_PARAMS_pchip_chfe_1(PDL_Float,F,PDL_Indx,N,PDL_Long,L)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
168 0 0         PDL_BROADCASTLOOP_START_pchip_chfe_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
169             #line 5591 "lib/PDL/Primitive.pd"
170              
171             /* Programming notes: */
172             /* 2. Most of the coding between the call to DCHFDV and the end of */
173             /* the IR-loop could be eliminated if it were permissible to */
174             /* assume that XE is ordered relative to X. */
175             /* 3. DCHFDV does not assume that X1 is less than X2. thus, it would */
176             /* be possible to write a version of DPCHFD that assumes a strict- */
177             /* ly decreasing X-array by simply running the IR-loop backwards */
178             /* (and reversing the order of appropriate tests). */
179             /* 4. The present code has a minor bug, which I have decided is not */
180             /* worth the effort that would be required to fix it. */
181             /* If XE contains points in [X(N-1),X(N)], followed by points .LT. */
182             /* X(N-1), followed by points .GT.X(N), the extrapolation points */
183             /* will be counted (at least) twice in the total returned in IERR. */
184             /* VALIDITY-CHECK ARGUMENTS. */
185             if (!(skip_datap)[0]) {
186             {/* Open n=1 */ PDL_EXPAND2(register PDL_Indx n=PDLMAX((1),0), __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
187             if ((x_datap)[0+(__inc_x_n*(n))] > (x_datap)[0+(__inc_x_n*(n-1))]) continue;
188             (ierr_datap)[0] = -3;
189             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "X-ARRAY NOT STRICTLY INCREASING");
190             }} /* Close n=1 */
191             }
192             /* FUNCTION DEFINITION IS OK, GO ON. */
193             (ierr_datap)[0] = 0;
194             (skip_datap)[0] = 1;
195             /* LOOP OVER INTERVALS. ( INTERVAL INDEX IS IL = IR-1 . ) */
196             /* ( INTERVAL IS X(IL).LE.X.LT.X(IR) . ) */
197             PDL_Indx n = __privtrans->ind_sizes[0], ne = __privtrans->ind_sizes[1];
198             PDL_Indx jfirst = 0, ir;
199             for (ir = 1; ir < n && jfirst < ne; ++ir) {
200             /* SKIP OUT OF LOOP IF HAVE PROCESSED ALL EVALUATION POINTS. */
201             /* LOCATE ALL POINTS IN INTERVAL. */
202             char located = 0;
203             PDL_Indx j = jfirst;
204             {/* Open ne=jfirst */ PDL_EXPAND2(register PDL_Indx ne=PDLMAX((jfirst),0), __ne_stop=(__ne_size)); for(; ne<__ne_stop; ne+=1) {
205             j = ne;
206             if ((xe_datap)[0+(__inc_xe_ne*(ne))] >= (x_datap)[0+(__inc_x_n*(ir))]) {
207             located = 1;
208             break;
209             }
210             }} /* Close ne=jfirst */
211             if (!located || ir == n-1)
212             j = ne;
213             /* HAVE LOCATED FIRST POINT BEYOND INTERVAL. */
214             PDL_Indx nj = j - jfirst;
215             /* SKIP EVALUATION IF NO POINTS IN INTERVAL. */
216             if (nj == 0)
217             continue;
218             /* EVALUATE CUBIC AT XE(I), I = JFIRST (1) J-1 . */
219             /* ---------------------------------------------------------------- */
220             PDL_Indx next[] = {0,0};
221             do { /* inline dchfdv */
222             /* Local variables */
223             PDL_Float x1 = (x_datap)[0+(__inc_x_n*(ir-1))], x2 = (x_datap)[0+(__inc_x_n*(ir))];
224             PDL_Float f1 = (f_datap)[0+(__inc_f_n*(ir-1))], f2 = (f_datap)[0+(__inc_f_n*(ir))];
225             PDL_Float d1 = (d_datap)[0+(__inc_d_n*(ir-1))], d2 = (d_datap)[0+(__inc_d_n*(ir))];
226             PDL_Float h = x2 - x1;
227             if (h == 0.)
228             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "INTERVAL ENDPOINTS EQUAL");
229             /* INITIALIZE. */
230             PDL_Float xmi = PDLMIN(0.,h);
231             PDL_Float xma = PDLMAX(0.,h);
232             /* COMPUTE CUBIC COEFFICIENTS (EXPANDED ABOUT X1). */
233             PDL_Float delta = (f2 - f1) / h;
234             PDL_Float del1 = (d1 - delta) / h;
235             PDL_Float del2 = (d2 - delta) / h;
236             /* (DELTA IS NO LONGER NEEDED.) */
237             PDL_Float c2 = -(del1 + del1 + del2);
238            
239             PDL_Float c3 = (del1 + del2) / h;
240             /* (H, DEL1 AND DEL2 ARE NO LONGER NEEDED.) */
241            
242             /* EVALUATION LOOP. */
243             {/* Open ne=:nj */ PDL_EXPAND2(register PDL_Indx ne=0, __ne_stop=PDLMIN(nj, (__ne_size))); for(; ne<__ne_stop; ne+=1) {
244             PDL_Float x = (xe_datap)[0+(__inc_xe_ne*(ne+jfirst))] - x1;
245             (fe_datap)[0+(__inc_fe_ne*(ne+jfirst))] = f1 + x * (d1 + x * (c2 + x * c3));
246            
247             /* COUNT EXTRAPOLATION POINTS. */
248             if (x < xmi)
249             ++next[0];
250             if (x > xma)
251             ++next[1];
252             /* (NOTE REDUNDANCY--IF EITHER CONDITION IS TRUE, OTHER IS FALSE.) */
253             }} /* Close ne=:nj */
254             } while (0); /* end inline dchfdv */
255             /* ---------------------------------------------------------------- */
256             if (next[1] != 0) {
257             /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(2) TO THE */
258             /* RIGHT OF X(IR). */
259             /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
260             (ierr_datap)[0] += next[1];
261             }
262             if (next[0] != 0) {
263             /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(1) TO THE */
264             /* LEFT OF X(IR-1). */
265             if (ir < 2) {
266             /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
267             (ierr_datap)[0] += next[0];
268             jfirst = j;
269             continue;
270             }
271             /* XE IS NOT ORDERED RELATIVE TO X, SO MUST ADJUST */
272             /* EVALUATION INTERVAL. */
273             /* FIRST, LOCATE FIRST POINT TO LEFT OF X(IR-1). */
274             located = 0;
275             PDL_Indx i = jfirst;
276             {/* Open ne=jfirst:j */ PDL_EXPAND2(register PDL_Indx ne=PDLMAX((jfirst),0), __ne_stop=PDLMIN(j, (__ne_size))); for(; ne<__ne_stop; ne+=1) {
277             i = ne;
278             if ((xe_datap)[0+(__inc_xe_ne*(ne))] < (x_datap)[0+(__inc_x_n*(ir-1))]) {
279             located = 1;
280             break;
281             }
282             }} /* Close ne=jfirst:j */
283             if (!located) {
284             /* NOTE-- CANNOT DROP THROUGH HERE UNLESS THERE IS AN ERROR */
285             /* IN DCHFDV. */
286             (ierr_datap)[0] = -5;
287             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "ERROR RETURN FROM DCHFDV -- FATAL");
288             }
289             /* RESET J. (THIS WILL BE THE NEW JFIRST.) */
290             j = i;
291             /* NOW FIND OUT HOW FAR TO BACK UP IN THE X-ARRAY. */
292             {/* Open n=:ir */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=PDLMIN(ir, (__n_size))); for(; n<__n_stop; n+=1) {
293             i = n;
294             if ((xe_datap)[0+(__inc_xe_ne*(j))] < (x_datap)[0+(__inc_x_n*(n))])
295             break;
296             }} /* Close n=:ir */
297             /* NB-- CAN NEVER DROP THROUGH HERE, SINCE XE(J).LT.X(IR-1). */
298             /* AT THIS POINT, EITHER XE(J) .LT. X(1) */
299             /* OR X(I-1) .LE. XE(J) .LT. X(I) . */
300             /* RESET IR, RECOGNIZING THAT IT WILL BE INCREMENTED BEFORE */
301             /* CYCLING. */
302             /* Computing MAX */
303             ir = PDLMAX(0,i-1);
304             }
305             jfirst = j;
306             /* END OF IR-LOOP. */
307             }
308             ;
309             #line 310 "lib/PDL/Primitive-pp-pchip_chfe.c"
310 0 0         }PDL_BROADCASTLOOP_END_pchip_chfe_readdata
    0          
311 0           } break;
312 7           case PDL_D: {
313 7 50         PDL_DECLARE_PARAMS_pchip_chfe_1(PDL_Double,D,PDL_Indx,N,PDL_Long,L)
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
314 33 50         PDL_BROADCASTLOOP_START_pchip_chfe_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
315             #line 5591 "lib/PDL/Primitive.pd"
316              
317             /* Programming notes: */
318             /* 2. Most of the coding between the call to DCHFDV and the end of */
319             /* the IR-loop could be eliminated if it were permissible to */
320             /* assume that XE is ordered relative to X. */
321             /* 3. DCHFDV does not assume that X1 is less than X2. thus, it would */
322             /* be possible to write a version of DPCHFD that assumes a strict- */
323             /* ly decreasing X-array by simply running the IR-loop backwards */
324             /* (and reversing the order of appropriate tests). */
325             /* 4. The present code has a minor bug, which I have decided is not */
326             /* worth the effort that would be required to fix it. */
327             /* If XE contains points in [X(N-1),X(N)], followed by points .LT. */
328             /* X(N-1), followed by points .GT.X(N), the extrapolation points */
329             /* will be counted (at least) twice in the total returned in IERR. */
330             /* VALIDITY-CHECK ARGUMENTS. */
331             if (!(skip_datap)[0]) {
332             {/* Open n=1 */ PDL_EXPAND2(register PDL_Indx n=PDLMAX((1),0), __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
333             if ((x_datap)[0+(__inc_x_n*(n))] > (x_datap)[0+(__inc_x_n*(n-1))]) continue;
334             (ierr_datap)[0] = -3;
335             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "X-ARRAY NOT STRICTLY INCREASING");
336             }} /* Close n=1 */
337             }
338             /* FUNCTION DEFINITION IS OK, GO ON. */
339             (ierr_datap)[0] = 0;
340             (skip_datap)[0] = 1;
341             /* LOOP OVER INTERVALS. ( INTERVAL INDEX IS IL = IR-1 . ) */
342             /* ( INTERVAL IS X(IL).LE.X.LT.X(IR) . ) */
343             PDL_Indx n = __privtrans->ind_sizes[0], ne = __privtrans->ind_sizes[1];
344             PDL_Indx jfirst = 0, ir;
345             for (ir = 1; ir < n && jfirst < ne; ++ir) {
346             /* SKIP OUT OF LOOP IF HAVE PROCESSED ALL EVALUATION POINTS. */
347             /* LOCATE ALL POINTS IN INTERVAL. */
348             char located = 0;
349             PDL_Indx j = jfirst;
350             {/* Open ne=jfirst */ PDL_EXPAND2(register PDL_Indx ne=PDLMAX((jfirst),0), __ne_stop=(__ne_size)); for(; ne<__ne_stop; ne+=1) {
351             j = ne;
352             if ((xe_datap)[0+(__inc_xe_ne*(ne))] >= (x_datap)[0+(__inc_x_n*(ir))]) {
353             located = 1;
354             break;
355             }
356             }} /* Close ne=jfirst */
357             if (!located || ir == n-1)
358             j = ne;
359             /* HAVE LOCATED FIRST POINT BEYOND INTERVAL. */
360             PDL_Indx nj = j - jfirst;
361             /* SKIP EVALUATION IF NO POINTS IN INTERVAL. */
362             if (nj == 0)
363             continue;
364             /* EVALUATE CUBIC AT XE(I), I = JFIRST (1) J-1 . */
365             /* ---------------------------------------------------------------- */
366             PDL_Indx next[] = {0,0};
367             do { /* inline dchfdv */
368             /* Local variables */
369             PDL_Double x1 = (x_datap)[0+(__inc_x_n*(ir-1))], x2 = (x_datap)[0+(__inc_x_n*(ir))];
370             PDL_Double f1 = (f_datap)[0+(__inc_f_n*(ir-1))], f2 = (f_datap)[0+(__inc_f_n*(ir))];
371             PDL_Double d1 = (d_datap)[0+(__inc_d_n*(ir-1))], d2 = (d_datap)[0+(__inc_d_n*(ir))];
372             PDL_Double h = x2 - x1;
373             if (h == 0.)
374             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "INTERVAL ENDPOINTS EQUAL");
375             /* INITIALIZE. */
376             PDL_Double xmi = PDLMIN(0.,h);
377             PDL_Double xma = PDLMAX(0.,h);
378             /* COMPUTE CUBIC COEFFICIENTS (EXPANDED ABOUT X1). */
379             PDL_Double delta = (f2 - f1) / h;
380             PDL_Double del1 = (d1 - delta) / h;
381             PDL_Double del2 = (d2 - delta) / h;
382             /* (DELTA IS NO LONGER NEEDED.) */
383             PDL_Double c2 = -(del1 + del1 + del2);
384            
385             PDL_Double c3 = (del1 + del2) / h;
386             /* (H, DEL1 AND DEL2 ARE NO LONGER NEEDED.) */
387            
388             /* EVALUATION LOOP. */
389             {/* Open ne=:nj */ PDL_EXPAND2(register PDL_Indx ne=0, __ne_stop=PDLMIN(nj, (__ne_size))); for(; ne<__ne_stop; ne+=1) {
390             PDL_Double x = (xe_datap)[0+(__inc_xe_ne*(ne+jfirst))] - x1;
391             (fe_datap)[0+(__inc_fe_ne*(ne+jfirst))] = f1 + x * (d1 + x * (c2 + x * c3));
392            
393             /* COUNT EXTRAPOLATION POINTS. */
394             if (x < xmi)
395             ++next[0];
396             if (x > xma)
397             ++next[1];
398             /* (NOTE REDUNDANCY--IF EITHER CONDITION IS TRUE, OTHER IS FALSE.) */
399             }} /* Close ne=:nj */
400             } while (0); /* end inline dchfdv */
401             /* ---------------------------------------------------------------- */
402             if (next[1] != 0) {
403             /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(2) TO THE */
404             /* RIGHT OF X(IR). */
405             /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
406             (ierr_datap)[0] += next[1];
407             }
408             if (next[0] != 0) {
409             /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(1) TO THE */
410             /* LEFT OF X(IR-1). */
411             if (ir < 2) {
412             /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
413             (ierr_datap)[0] += next[0];
414             jfirst = j;
415             continue;
416             }
417             /* XE IS NOT ORDERED RELATIVE TO X, SO MUST ADJUST */
418             /* EVALUATION INTERVAL. */
419             /* FIRST, LOCATE FIRST POINT TO LEFT OF X(IR-1). */
420             located = 0;
421             PDL_Indx i = jfirst;
422             {/* Open ne=jfirst:j */ PDL_EXPAND2(register PDL_Indx ne=PDLMAX((jfirst),0), __ne_stop=PDLMIN(j, (__ne_size))); for(; ne<__ne_stop; ne+=1) {
423             i = ne;
424             if ((xe_datap)[0+(__inc_xe_ne*(ne))] < (x_datap)[0+(__inc_x_n*(ir-1))]) {
425             located = 1;
426             break;
427             }
428             }} /* Close ne=jfirst:j */
429             if (!located) {
430             /* NOTE-- CANNOT DROP THROUGH HERE UNLESS THERE IS AN ERROR */
431             /* IN DCHFDV. */
432             (ierr_datap)[0] = -5;
433             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "ERROR RETURN FROM DCHFDV -- FATAL");
434             }
435             /* RESET J. (THIS WILL BE THE NEW JFIRST.) */
436             j = i;
437             /* NOW FIND OUT HOW FAR TO BACK UP IN THE X-ARRAY. */
438             {/* Open n=:ir */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=PDLMIN(ir, (__n_size))); for(; n<__n_stop; n+=1) {
439             i = n;
440             if ((xe_datap)[0+(__inc_xe_ne*(j))] < (x_datap)[0+(__inc_x_n*(n))])
441             break;
442             }} /* Close n=:ir */
443             /* NB-- CAN NEVER DROP THROUGH HERE, SINCE XE(J).LT.X(IR-1). */
444             /* AT THIS POINT, EITHER XE(J) .LT. X(1) */
445             /* OR X(I-1) .LE. XE(J) .LT. X(I) . */
446             /* RESET IR, RECOGNIZING THAT IT WILL BE INCREMENTED BEFORE */
447             /* CYCLING. */
448             /* Computing MAX */
449             ir = PDLMAX(0,i-1);
450             }
451             jfirst = j;
452             /* END OF IR-LOOP. */
453             }
454             ;
455             #line 456 "lib/PDL/Primitive-pp-pchip_chfe.c"
456 7 50         }PDL_BROADCASTLOOP_END_pchip_chfe_readdata
    50          
457 7           } break;
458 0           case PDL_LD: {
459 0 0         PDL_DECLARE_PARAMS_pchip_chfe_1(PDL_LDouble,E,PDL_Indx,N,PDL_Long,L)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
460 0 0         PDL_BROADCASTLOOP_START_pchip_chfe_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
461             #line 5591 "lib/PDL/Primitive.pd"
462              
463             /* Programming notes: */
464             /* 2. Most of the coding between the call to DCHFDV and the end of */
465             /* the IR-loop could be eliminated if it were permissible to */
466             /* assume that XE is ordered relative to X. */
467             /* 3. DCHFDV does not assume that X1 is less than X2. thus, it would */
468             /* be possible to write a version of DPCHFD that assumes a strict- */
469             /* ly decreasing X-array by simply running the IR-loop backwards */
470             /* (and reversing the order of appropriate tests). */
471             /* 4. The present code has a minor bug, which I have decided is not */
472             /* worth the effort that would be required to fix it. */
473             /* If XE contains points in [X(N-1),X(N)], followed by points .LT. */
474             /* X(N-1), followed by points .GT.X(N), the extrapolation points */
475             /* will be counted (at least) twice in the total returned in IERR. */
476             /* VALIDITY-CHECK ARGUMENTS. */
477             if (!(skip_datap)[0]) {
478             {/* Open n=1 */ PDL_EXPAND2(register PDL_Indx n=PDLMAX((1),0), __n_stop=(__n_size)); for(; n<__n_stop; n+=1) {
479             if ((x_datap)[0+(__inc_x_n*(n))] > (x_datap)[0+(__inc_x_n*(n-1))]) continue;
480             (ierr_datap)[0] = -3;
481             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "X-ARRAY NOT STRICTLY INCREASING");
482             }} /* Close n=1 */
483             }
484             /* FUNCTION DEFINITION IS OK, GO ON. */
485             (ierr_datap)[0] = 0;
486             (skip_datap)[0] = 1;
487             /* LOOP OVER INTERVALS. ( INTERVAL INDEX IS IL = IR-1 . ) */
488             /* ( INTERVAL IS X(IL).LE.X.LT.X(IR) . ) */
489             PDL_Indx n = __privtrans->ind_sizes[0], ne = __privtrans->ind_sizes[1];
490             PDL_Indx jfirst = 0, ir;
491             for (ir = 1; ir < n && jfirst < ne; ++ir) {
492             /* SKIP OUT OF LOOP IF HAVE PROCESSED ALL EVALUATION POINTS. */
493             /* LOCATE ALL POINTS IN INTERVAL. */
494             char located = 0;
495             PDL_Indx j = jfirst;
496             {/* Open ne=jfirst */ PDL_EXPAND2(register PDL_Indx ne=PDLMAX((jfirst),0), __ne_stop=(__ne_size)); for(; ne<__ne_stop; ne+=1) {
497             j = ne;
498             if ((xe_datap)[0+(__inc_xe_ne*(ne))] >= (x_datap)[0+(__inc_x_n*(ir))]) {
499             located = 1;
500             break;
501             }
502             }} /* Close ne=jfirst */
503             if (!located || ir == n-1)
504             j = ne;
505             /* HAVE LOCATED FIRST POINT BEYOND INTERVAL. */
506             PDL_Indx nj = j - jfirst;
507             /* SKIP EVALUATION IF NO POINTS IN INTERVAL. */
508             if (nj == 0)
509             continue;
510             /* EVALUATE CUBIC AT XE(I), I = JFIRST (1) J-1 . */
511             /* ---------------------------------------------------------------- */
512             PDL_Indx next[] = {0,0};
513             do { /* inline dchfdv */
514             /* Local variables */
515             PDL_LDouble x1 = (x_datap)[0+(__inc_x_n*(ir-1))], x2 = (x_datap)[0+(__inc_x_n*(ir))];
516             PDL_LDouble f1 = (f_datap)[0+(__inc_f_n*(ir-1))], f2 = (f_datap)[0+(__inc_f_n*(ir))];
517             PDL_LDouble d1 = (d_datap)[0+(__inc_d_n*(ir-1))], d2 = (d_datap)[0+(__inc_d_n*(ir))];
518             PDL_LDouble h = x2 - x1;
519             if (h == 0.)
520             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "INTERVAL ENDPOINTS EQUAL");
521             /* INITIALIZE. */
522             PDL_LDouble xmi = PDLMIN(0.,h);
523             PDL_LDouble xma = PDLMAX(0.,h);
524             /* COMPUTE CUBIC COEFFICIENTS (EXPANDED ABOUT X1). */
525             PDL_LDouble delta = (f2 - f1) / h;
526             PDL_LDouble del1 = (d1 - delta) / h;
527             PDL_LDouble del2 = (d2 - delta) / h;
528             /* (DELTA IS NO LONGER NEEDED.) */
529             PDL_LDouble c2 = -(del1 + del1 + del2);
530            
531             PDL_LDouble c3 = (del1 + del2) / h;
532             /* (H, DEL1 AND DEL2 ARE NO LONGER NEEDED.) */
533            
534             /* EVALUATION LOOP. */
535             {/* Open ne=:nj */ PDL_EXPAND2(register PDL_Indx ne=0, __ne_stop=PDLMIN(nj, (__ne_size))); for(; ne<__ne_stop; ne+=1) {
536             PDL_LDouble x = (xe_datap)[0+(__inc_xe_ne*(ne+jfirst))] - x1;
537             (fe_datap)[0+(__inc_fe_ne*(ne+jfirst))] = f1 + x * (d1 + x * (c2 + x * c3));
538            
539             /* COUNT EXTRAPOLATION POINTS. */
540             if (x < xmi)
541             ++next[0];
542             if (x > xma)
543             ++next[1];
544             /* (NOTE REDUNDANCY--IF EITHER CONDITION IS TRUE, OTHER IS FALSE.) */
545             }} /* Close ne=:nj */
546             } while (0); /* end inline dchfdv */
547             /* ---------------------------------------------------------------- */
548             if (next[1] != 0) {
549             /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(2) TO THE */
550             /* RIGHT OF X(IR). */
551             /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
552             (ierr_datap)[0] += next[1];
553             }
554             if (next[0] != 0) {
555             /* IN THE CURRENT SET OF XE-POINTS, THERE ARE NEXT(1) TO THE */
556             /* LEFT OF X(IR-1). */
557             if (ir < 2) {
558             /* THESE ARE ACTUALLY EXTRAPOLATION POINTS. */
559             (ierr_datap)[0] += next[0];
560             jfirst = j;
561             continue;
562             }
563             /* XE IS NOT ORDERED RELATIVE TO X, SO MUST ADJUST */
564             /* EVALUATION INTERVAL. */
565             /* FIRST, LOCATE FIRST POINT TO LEFT OF X(IR-1). */
566             located = 0;
567             PDL_Indx i = jfirst;
568             {/* Open ne=jfirst:j */ PDL_EXPAND2(register PDL_Indx ne=PDLMAX((jfirst),0), __ne_stop=PDLMIN(j, (__ne_size))); for(; ne<__ne_stop; ne+=1) {
569             i = ne;
570             if ((xe_datap)[0+(__inc_xe_ne*(ne))] < (x_datap)[0+(__inc_x_n*(ir-1))]) {
571             located = 1;
572             break;
573             }
574             }} /* Close ne=jfirst:j */
575             if (!located) {
576             /* NOTE-- CANNOT DROP THROUGH HERE UNLESS THERE IS AN ERROR */
577             /* IN DCHFDV. */
578             (ierr_datap)[0] = -5;
579             return PDL->make_error(PDL_EUSERERROR, "Error in pchip_chfe:" "ERROR RETURN FROM DCHFDV -- FATAL");
580             }
581             /* RESET J. (THIS WILL BE THE NEW JFIRST.) */
582             j = i;
583             /* NOW FIND OUT HOW FAR TO BACK UP IN THE X-ARRAY. */
584             {/* Open n=:ir */ PDL_EXPAND2(register PDL_Indx n=0, __n_stop=PDLMIN(ir, (__n_size))); for(; n<__n_stop; n+=1) {
585             i = n;
586             if ((xe_datap)[0+(__inc_xe_ne*(j))] < (x_datap)[0+(__inc_x_n*(n))])
587             break;
588             }} /* Close n=:ir */
589             /* NB-- CAN NEVER DROP THROUGH HERE, SINCE XE(J).LT.X(IR-1). */
590             /* AT THIS POINT, EITHER XE(J) .LT. X(1) */
591             /* OR X(I-1) .LE. XE(J) .LT. X(I) . */
592             /* RESET IR, RECOGNIZING THAT IT WILL BE INCREMENTED BEFORE */
593             /* CYCLING. */
594             /* Computing MAX */
595             ir = PDLMAX(0,i-1);
596             }
597             jfirst = j;
598             /* END OF IR-LOOP. */
599             }
600             ;
601             #line 602 "lib/PDL/Primitive-pp-pchip_chfe.c"
602 0 0         }PDL_BROADCASTLOOP_END_pchip_chfe_readdata
    0          
603 0           } break;
604 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in pchip_chfe: unhandled datatype(%d), only handles (FDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
605             }
606             #undef PDL_IF_BAD
607 7           return PDL_err;
608             }
609              
610             static pdl_datatypes pdl_pchip_chfe_vtable_gentypes[] = { PDL_F, PDL_D, PDL_LD, -1 };
611             static PDL_Indx pdl_pchip_chfe_vtable_realdims[] = { 1, 1, 1, 1, 1, 0, 0 };
612             static char *pdl_pchip_chfe_vtable_parnames[] = { "x","f","d","xe","fe","ierr","skip" };
613             static short pdl_pchip_chfe_vtable_parflags[] = {
614             0,
615             0,
616             0,
617             0,
618             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE,
619             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISTYPED|PDL_PARAM_ISWRITE,
620             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISTYPED|PDL_PARAM_ISWRITE
621             };
622             static pdl_datatypes pdl_pchip_chfe_vtable_partypes[] = { -1, -1, -1, -1, -1, PDL_IND, PDL_L };
623             static PDL_Indx pdl_pchip_chfe_vtable_realdims_starts[] = { 0, 1, 2, 3, 4, 5, 5 };
624             static PDL_Indx pdl_pchip_chfe_vtable_realdims_ind_ids[] = { 0, 0, 0, 1, 1 };
625             static char *pdl_pchip_chfe_vtable_indnames[] = { "n","ne" };
626             pdl_transvtable pdl_pchip_chfe_vtable = {
627             PDL_TRANS_DO_BROADCAST, 0, pdl_pchip_chfe_vtable_gentypes, 4, 7, NULL /*CORE21*/,
628             pdl_pchip_chfe_vtable_realdims, pdl_pchip_chfe_vtable_parnames,
629             pdl_pchip_chfe_vtable_parflags, pdl_pchip_chfe_vtable_partypes,
630             pdl_pchip_chfe_vtable_realdims_starts, pdl_pchip_chfe_vtable_realdims_ind_ids, 5,
631             2, pdl_pchip_chfe_vtable_indnames,
632             pdl_pchip_chfe_redodims, pdl_pchip_chfe_readdata, NULL,
633             NULL,
634             0,"PDL::Primitive::pchip_chfe"
635             };
636              
637              
638 7           pdl_error pdl_run_pchip_chfe(pdl *x,pdl *f,pdl *d,pdl *xe,pdl *fe,pdl *ierr,pdl *skip) {
639 7           pdl_error PDL_err = {0, NULL, 0};
640 7 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
641 7           pdl_trans *__privtrans = PDL->create_trans(&pdl_pchip_chfe_vtable);
642 7 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
643 7           __privtrans->pdls[0] = x;
644 7           __privtrans->pdls[1] = f;
645 7           __privtrans->pdls[2] = d;
646 7           __privtrans->pdls[3] = xe;
647 7           __privtrans->pdls[4] = fe;
648 7           __privtrans->pdls[5] = ierr;
649 7           __privtrans->pdls[6] = skip;
650 7 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
651 7 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
652 7           return PDL_err;
653             }