File Coverage

pp-Casin.c
Criterion Covered Total %
statement 40 75 53.3
branch 27 138 19.5
condition n/a
subroutine n/a
pod n/a
total 67 213 31.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 complex.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_Complex
21             extern Core* PDL; /* Structure hold core C functions */
22             #line 23 "pp-Casin.c"
23              
24             #include
25              
26             #ifndef M_PI
27             # define M_PI 3.1415926535897932384626433832795029
28             #endif
29             #ifndef M_2PI
30             # define M_2PI (2. * M_PI)
31             #endif
32              
33             #if __GLIBC__ > 1 && (defined __USE_MISC || defined __USE_XOPEN || defined __USE_ISOC9X)
34             # define CABS(r,i) hypot (r, i)
35             #else
36             static double
37             CABS (double r, double i)
38             {
39             double t;
40              
41             if (r < 0) r = - r;
42             if (i < 0) i = - i;
43              
44             if (i > r)
45             {
46             t = r; r = i; i = t;
47             }
48              
49             if (r + i == r)
50             return r;
51              
52             t = i / r;
53             return r * sqrt (1 + t*t);
54             }
55             #endif
56              
57             #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 && defined __USE_GNU
58             # define SINCOS(x,s,c) sincos ((x), &(s), &(c))
59             #else
60             # define SINCOS(x,s,c) \
61             (s) = sin (x); \
62             (c) = cos (x);
63             #endif
64              
65              
66             #define CSQRT(type,ar,ai,cr,ci) \
67             type mag = CABS ((ar), (ai)); \
68             type t; \
69             \
70             if (mag == 0) \
71             (cr) = (ci) = 0; \
72             else if ((ar) > 0) \
73             { \
74             t = sqrt (0.5 * (mag + (ar))); \
75             (cr) = t; \
76             (ci) = 0.5 * (ai) / t; \
77             } \
78             else \
79             { \
80             t = sqrt (0.5 * (mag - (ar))); \
81             \
82             if ((ai) < 0) \
83             t = -t; \
84             \
85             (cr) = 0.5 * (ai) / t; \
86             (ci) = t; \
87             }
88              
89              
90             #define CLOG(ar,ai,cr,ci) \
91             (cr) = log (CABS ((ar), (ai))); \
92             (ci) = atan2 ((ai), (ar));
93              
94              
95             #line 1857 "lib/PDL/PP.pm"
96             pdl_error pdl_Casin_redodims(pdl_trans *__privtrans) {
97             pdl_error PDL_err = {0, NULL, 0};
98             #line 99 "pp-Casin.c"
99 2           __privtrans->ind_sizes[0] = 2;
100 2 50         PDL_RETERROR(PDL_err, PDL->redodims_default(__privtrans));
101 2           return PDL_err;
102             }
103              
104              
105             #line 1857 "lib/PDL/PP.pm"
106             pdl_error pdl_Casin_readdata(pdl_trans *__privtrans) {
107             pdl_error PDL_err = {0, NULL, 0};
108             #line 109 "pp-Casin.c"
109 2 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in Casin:" "broadcast.incs NULL");
110             /* broadcastloop declarations */
111             int __brcloopval;
112             register PDL_Indx __tind0,__tind1; /* counters along dim */
113 2           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
114             /* dims here are how many steps along those dims */
115 2           register PDL_Indx __tinc0_a = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
116 2           register PDL_Indx __tinc0_c = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
117 2           register PDL_Indx __tinc1_a = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
118 2           register PDL_Indx __tinc1_c = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
119             #define PDL_BROADCASTLOOP_START_Casin_readdata PDL_BROADCASTLOOP_START( \
120             readdata, \
121             __privtrans->broadcast, \
122             __privtrans->vtable, \
123             a_datap += __offsp[0]; \
124             c_datap += __offsp[1]; \
125             , \
126             ( ,a_datap += __tinc1_a - __tinc0_a * __tdims0 \
127             ,c_datap += __tinc1_c - __tinc0_c * __tdims0 \
128             ), \
129             ( ,a_datap += __tinc0_a \
130             ,c_datap += __tinc0_c \
131             ) \
132             )
133             #define PDL_BROADCASTLOOP_END_Casin_readdata PDL_BROADCASTLOOP_END( \
134             __privtrans->broadcast, \
135             a_datap -= __tinc1_a * __tdims1 + __offsp[0]; \
136             c_datap -= __tinc1_c * __tdims1 + __offsp[1]; \
137             )
138 2           register PDL_Indx __inc_a_m = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,0,0)]; (void)__inc_a_m;
139 2           register PDL_Indx __inc_c_m = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,1,0)]; (void)__inc_c_m;
140             #ifndef PDL_DECLARE_PARAMS_Casin_1
141             #define PDL_DECLARE_PARAMS_Casin_1(PDL_TYPE_OP,PDL_PPSYM_OP) \
142             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, a, (__privtrans->pdls[0]), 1, PDL_PPSYM_OP) \
143             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, c, (__privtrans->pdls[1]), 1, PDL_PPSYM_OP)
144             #endif
145             #define PDL_IF_BAD(t,f) f
146 2           switch (__privtrans->__datatype) { /* Start generic switch */
147 0           case PDL_F: {
148 0 0         PDL_DECLARE_PARAMS_Casin_1(PDL_Float,F)
    0          
    0          
    0          
    0          
    0          
149 0 0         PDL_BROADCASTLOOP_START_Casin_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
150 0           PDL_Float ar = (a_datap)[0+(__inc_a_m*(0))], ai = (a_datap)[0+(__inc_a_m*(1))];
151              
152 0           PDL_Float t1 = sqrt ((ar+1)*(ar+1) + ai*ai);
153 0           PDL_Float t2 = sqrt ((ar-1)*(ar-1) + ai*ai);
154 0           PDL_Float alpha = (t1+t2)*0.5;
155 0           PDL_Float beta = (t1-t2)*0.5;
156              
157 0 0         if (alpha < 1) alpha = 1;
158 0 0         if (beta > 1) beta = 1;
159 0 0         else if (beta < -1) beta = -1;
160              
161 0           (c_datap)[0+(__inc_c_m*(0))] = atan2 (beta, sqrt (1-beta*beta));
162 0           (c_datap)[0+(__inc_c_m*(1))] = - log (alpha + sqrt (alpha*alpha-1));
163 0 0         if (ai > 0 || (ai == 0 && ar < -1))
    0          
    0          
164 0           (c_datap)[0+(__inc_c_m*(1))] = - (c_datap)[0+(__inc_c_m*(1))];
165 0 0         }PDL_BROADCASTLOOP_END_Casin_readdata
    0          
166 0           } break;
167 2           case PDL_D: {
168 2 50         PDL_DECLARE_PARAMS_Casin_1(PDL_Double,D)
    50          
    50          
    50          
    50          
    50          
169 10 50         PDL_BROADCASTLOOP_START_Casin_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
170 4           PDL_Double ar = (a_datap)[0+(__inc_a_m*(0))], ai = (a_datap)[0+(__inc_a_m*(1))];
171              
172 4           PDL_Double t1 = sqrt ((ar+1)*(ar+1) + ai*ai);
173 4           PDL_Double t2 = sqrt ((ar-1)*(ar-1) + ai*ai);
174 4           PDL_Double alpha = (t1+t2)*0.5;
175 4           PDL_Double beta = (t1-t2)*0.5;
176              
177 4 50         if (alpha < 1) alpha = 1;
178 4 50         if (beta > 1) beta = 1;
179 4 50         else if (beta < -1) beta = -1;
180              
181 4           (c_datap)[0+(__inc_c_m*(0))] = atan2 (beta, sqrt (1-beta*beta));
182 4           (c_datap)[0+(__inc_c_m*(1))] = - log (alpha + sqrt (alpha*alpha-1));
183 4 50         if (ai > 0 || (ai == 0 && ar < -1))
    0          
    0          
184 4           (c_datap)[0+(__inc_c_m*(1))] = - (c_datap)[0+(__inc_c_m*(1))];
185 2 50         }PDL_BROADCASTLOOP_END_Casin_readdata
    50          
186 2           } break;
187 0           case PDL_LD: {
188 0 0         PDL_DECLARE_PARAMS_Casin_1(PDL_LDouble,E)
    0          
    0          
    0          
    0          
    0          
189 0 0         PDL_BROADCASTLOOP_START_Casin_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
190 0           PDL_LDouble ar = (a_datap)[0+(__inc_a_m*(0))], ai = (a_datap)[0+(__inc_a_m*(1))];
191              
192 0           PDL_LDouble t1 = sqrt ((ar+1)*(ar+1) + ai*ai);
193 0           PDL_LDouble t2 = sqrt ((ar-1)*(ar-1) + ai*ai);
194 0           PDL_LDouble alpha = (t1+t2)*0.5;
195 0           PDL_LDouble beta = (t1-t2)*0.5;
196              
197 0 0         if (alpha < 1) alpha = 1;
198 0 0         if (beta > 1) beta = 1;
199 0 0         else if (beta < -1) beta = -1;
200              
201 0           (c_datap)[0+(__inc_c_m*(0))] = atan2 (beta, sqrt (1-beta*beta));
202 0           (c_datap)[0+(__inc_c_m*(1))] = - log (alpha + sqrt (alpha*alpha-1));
203 0 0         if (ai > 0 || (ai == 0 && ar < -1))
    0          
    0          
204 0           (c_datap)[0+(__inc_c_m*(1))] = - (c_datap)[0+(__inc_c_m*(1))];
205 0 0         }PDL_BROADCASTLOOP_END_Casin_readdata
    0          
206 0           } break;
207 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in Casin: unhandled datatype(%d), only handles (FDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
208             }
209             #undef PDL_IF_BAD
210 2           return PDL_err;
211             }
212              
213             static pdl_datatypes pdl_Casin_vtable_gentypes[] = { PDL_F, PDL_D, PDL_LD, -1 };
214             static PDL_Indx pdl_Casin_vtable_realdims[] = { 1, 1 };
215             static char *pdl_Casin_vtable_parnames[] = { "a","c" };
216             static short pdl_Casin_vtable_parflags[] = {
217             0,
218             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE
219             };
220             static pdl_datatypes pdl_Casin_vtable_partypes[] = { -1, -1 };
221             static PDL_Indx pdl_Casin_vtable_realdims_starts[] = { 0, 1 };
222             static PDL_Indx pdl_Casin_vtable_realdims_ind_ids[] = { 0, 0 };
223             static char *pdl_Casin_vtable_indnames[] = { "m" };
224             pdl_transvtable pdl_Casin_vtable = {
225             PDL_TRANS_DO_BROADCAST, 0, pdl_Casin_vtable_gentypes, 1, 2, NULL /*CORE21*/,
226             pdl_Casin_vtable_realdims, pdl_Casin_vtable_parnames,
227             pdl_Casin_vtable_parflags, pdl_Casin_vtable_partypes,
228             pdl_Casin_vtable_realdims_starts, pdl_Casin_vtable_realdims_ind_ids, 2,
229             1, pdl_Casin_vtable_indnames,
230             pdl_Casin_redodims, pdl_Casin_readdata, NULL,
231             NULL,
232             0,"PDL::Complex::Casin"
233             };
234              
235              
236 2           pdl_error pdl_run_Casin(pdl *a,pdl *c) {
237 2           pdl_error PDL_err = {0, NULL, 0};
238 2 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
239 2           pdl_trans *__privtrans = PDL->create_trans(&pdl_Casin_vtable);
240 2 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
241 2           __privtrans->pdls[0] = a;
242 2           __privtrans->pdls[1] = c;
243 2 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
244 2 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
245 2           return PDL_err;
246             }