File Coverage

lib/PDL/ImageND-pp-convolve.c
Criterion Covered Total %
statement 104 704 14.7
branch 74 1078 6.8
condition n/a
subroutine n/a
pod n/a
total 178 1782 9.9


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/ImageND.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_ImageND
21             extern Core* PDL; /* Structure hold core C functions */
22             #line 23 "lib/PDL/ImageND-pp-convolve.c"
23             /* Compute offset of (x,y,z,...) position in row-major list */
24 2           static inline PDL_Indx ndim_get_offset(PDL_Indx* pos, PDL_Indx* dims, PDL_Long ndims) {
25             PDL_Long i;
26             PDL_Indx result,size;
27 2           size = 1;
28 2           result = 0;
29 6 100         for (i=0; i
30 4 100         if (i>0)
31 2           size = size*dims[i-1];
32 4           result = result + pos[i]*size;
33             }
34 2           return result;
35             }
36             /* Increment a position pointer array by one row */
37 4           static inline void ndim_row_plusplus ( PDL_Indx* pos, PDL_Indx* dims, PDL_Long ndims ) {
38             PDL_Long noescape;
39             PDL_Indx i;
40 4           i=1; noescape=1;
41 8 100         while(noescape) {
42 4           (pos[i])++;
43 4 100         if (pos[i]==dims[i]) { /* Carry */
44 1 50         if (i>=(ndims)-1) {
45 1           noescape = 0; /* Exit */
46             }else{
47 0           pos[i]=0;
48 0           i++;
49             }
50             }else{
51 3           noescape = 0; /* Exit */
52             }
53             }
54 4           }
55              
56              
57              
58             #line 1857 "lib/PDL/PP.pm"
59             pdl_error pdl_convolve_redodims(pdl_trans *__privtrans) {
60             pdl_error PDL_err = {0, NULL, 0};
61             #line 62 "lib/PDL/ImageND-pp-convolve.c"
62             #ifndef PDL_DECLARE_PARAMS_convolve_0
63             #define PDL_DECLARE_PARAMS_convolve_0(PDL_TYPE_OP,PDL_PPSYM_OP,PDL_TYPE_PARAM_adims,PDL_PPSYM_PARAM_adims,PDL_TYPE_PARAM_bdims,PDL_PPSYM_PARAM_bdims) \
64             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, a, (__privtrans->pdls[0]), 0, PDL_PPSYM_OP) \
65             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, b, (__privtrans->pdls[1]), 0, PDL_PPSYM_OP) \
66             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_adims, adims, (__privtrans->pdls[2]), 0, PDL_PPSYM_PARAM_adims) \
67             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_bdims, bdims, (__privtrans->pdls[3]), 0, PDL_PPSYM_PARAM_bdims) \
68             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, c, (__privtrans->pdls[4]), 0, PDL_PPSYM_OP)
69             #endif
70             #define PDL_IF_BAD(t,f) f
71 1           switch (__privtrans->__datatype) { /* Start generic switch */
72 0           case PDL_SB: {
73 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_SByte,A,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
74             {
75 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
76 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
77 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
78 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
79 0 0         if (dimsb[i]>=dimsa[i])
80 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
81             }
82 0           } break;
83 0           case PDL_B: {
84 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_Byte,B,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
85             {
86 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
87 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
88 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
89 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
90 0 0         if (dimsb[i]>=dimsa[i])
91 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
92             }
93 0           } break;
94 0           case PDL_S: {
95 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_Short,S,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
96             {
97 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
98 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
99 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
100 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
101 0 0         if (dimsb[i]>=dimsa[i])
102 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
103             }
104 0           } break;
105 0           case PDL_US: {
106 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_Ushort,U,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
107             {
108 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
109 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
110 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
111 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
112 0 0         if (dimsb[i]>=dimsa[i])
113 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
114             }
115 0           } break;
116 0           case PDL_L: {
117 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_Long,L,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
118             {
119 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
120 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
121 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
122 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
123 0 0         if (dimsb[i]>=dimsa[i])
124 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
125             }
126 0           } break;
127 0           case PDL_UL: {
128 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_ULong,K,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
129             {
130 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
131 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
132 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
133 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
134 0 0         if (dimsb[i]>=dimsa[i])
135 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
136             }
137 0           } break;
138 0           case PDL_IND: {
139 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_Indx,N,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
140             {
141 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
142 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
143 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
144 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
145 0 0         if (dimsb[i]>=dimsa[i])
146 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
147             }
148 0           } break;
149 0           case PDL_ULL: {
150 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_ULongLong,P,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
151             {
152 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
153 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
154 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
155 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
156 0 0         if (dimsb[i]>=dimsa[i])
157 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
158             }
159 0           } break;
160 0           case PDL_LL: {
161 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_LongLong,Q,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
162             {
163 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
164 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
165 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
166 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
167 0 0         if (dimsb[i]>=dimsa[i])
168 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
169             }
170 0           } break;
171 0           case PDL_F: {
172 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_Float,F,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
173             {
174 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
175 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
176 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
177 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
178 0 0         if (dimsb[i]>=dimsa[i])
179 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
180             }
181 0           } break;
182 1           case PDL_D: {
183 1 50         PDL_DECLARE_PARAMS_convolve_0(PDL_Double,D,PDL_Indx,N,PDL_Indx,N)
    50          
    50          
    50          
    50          
184             {
185 1 50         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
186 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
187 1           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
188 3 100         for(i=0; i<__privtrans->ind_sizes[2]; i++)
189 2 50         if (dimsb[i]>=dimsa[i])
190 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
191             }
192 1           } break;
193 0           case PDL_LD: {
194 0 0         PDL_DECLARE_PARAMS_convolve_0(PDL_LDouble,E,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
195             {
196 0 0         if (__privtrans->ind_sizes[2] != __privtrans->ind_sizes[3])
197 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Arguments do not have the same dimensionality");
198 0           PDL_Indx i, *dimsa = adims_datap, *dimsb = bdims_datap;
199 0 0         for(i=0; i<__privtrans->ind_sizes[2]; i++)
200 0 0         if (dimsb[i]>=dimsa[i])
201 0           return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "Second argument must be smaller in all dimensions that first");
202             }
203 0           } break;
204 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in convolve: unhandled datatype(%d), only handles (ABSULKNPQFDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
205             }
206             #undef PDL_IF_BAD
207              
208 1 50         PDL_RETERROR(PDL_err, PDL->redodims_default(__privtrans));
209 1           return PDL_err;
210             }
211              
212              
213             #line 1857 "lib/PDL/PP.pm"
214             pdl_error pdl_convolve_readdata(pdl_trans *__privtrans) {
215             pdl_error PDL_err = {0, NULL, 0};
216             #line 217 "lib/PDL/ImageND-pp-convolve.c"
217 1 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in convolve:" "broadcast.incs NULL");
218             /* broadcastloop declarations */
219             int __brcloopval;
220             register PDL_Indx __tind0,__tind1; /* counters along dim */
221 1           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
222             /* dims here are how many steps along those dims */
223 1           register PDL_Indx __tinc0_a = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
224 1           register PDL_Indx __tinc0_b = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
225 1           register PDL_Indx __tinc0_adims = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,0);
226 1           register PDL_Indx __tinc0_bdims = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,3,0);
227 1           register PDL_Indx __tinc0_c = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,4,0);
228 1           register PDL_Indx __tinc1_a = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
229 1           register PDL_Indx __tinc1_b = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
230 1           register PDL_Indx __tinc1_adims = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,1);
231 1           register PDL_Indx __tinc1_bdims = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,3,1);
232 1           register PDL_Indx __tinc1_c = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,4,1);
233             #define PDL_BROADCASTLOOP_START_convolve_readdata PDL_BROADCASTLOOP_START( \
234             readdata, \
235             __privtrans->broadcast, \
236             __privtrans->vtable, \
237             a_datap += __offsp[0]; \
238             b_datap += __offsp[1]; \
239             adims_datap += __offsp[2]; \
240             bdims_datap += __offsp[3]; \
241             c_datap += __offsp[4]; \
242             , \
243             ( ,a_datap += __tinc1_a - __tinc0_a * __tdims0 \
244             ,b_datap += __tinc1_b - __tinc0_b * __tdims0 \
245             ,adims_datap += __tinc1_adims - __tinc0_adims * __tdims0 \
246             ,bdims_datap += __tinc1_bdims - __tinc0_bdims * __tdims0 \
247             ,c_datap += __tinc1_c - __tinc0_c * __tdims0 \
248             ), \
249             ( ,a_datap += __tinc0_a \
250             ,b_datap += __tinc0_b \
251             ,adims_datap += __tinc0_adims \
252             ,bdims_datap += __tinc0_bdims \
253             ,c_datap += __tinc0_c \
254             ) \
255             )
256             #define PDL_BROADCASTLOOP_END_convolve_readdata PDL_BROADCASTLOOP_END( \
257             __privtrans->broadcast, \
258             a_datap -= __tinc1_a * __tdims1 + __offsp[0]; \
259             b_datap -= __tinc1_b * __tdims1 + __offsp[1]; \
260             adims_datap -= __tinc1_adims * __tdims1 + __offsp[2]; \
261             bdims_datap -= __tinc1_bdims * __tdims1 + __offsp[3]; \
262             c_datap -= __tinc1_c * __tdims1 + __offsp[4]; \
263             )
264 1           register PDL_Indx __inc_a_m = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,0,0)]; (void)__inc_a_m;
265 1           register PDL_Indx __inc_adims_p = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,2,0)]; (void)__inc_adims_p;
266 1           register PDL_Indx __inc_b_n = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,1,0)]; (void)__inc_b_n;
267 1           register PDL_Indx __inc_bdims_q = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,3,0)]; (void)__inc_bdims_q;
268 1           register PDL_Indx __inc_c_m = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,4,0)]; (void)__inc_c_m;
269             #ifndef PDL_DECLARE_PARAMS_convolve_1
270             #define PDL_DECLARE_PARAMS_convolve_1(PDL_TYPE_OP,PDL_PPSYM_OP,PDL_TYPE_PARAM_adims,PDL_PPSYM_PARAM_adims,PDL_TYPE_PARAM_bdims,PDL_PPSYM_PARAM_bdims) \
271             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, a, (__privtrans->pdls[0]), 1, PDL_PPSYM_OP) \
272             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, b, (__privtrans->pdls[1]), 1, PDL_PPSYM_OP) \
273             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_adims, adims, (__privtrans->pdls[2]), 1, PDL_PPSYM_PARAM_adims) \
274             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_bdims, bdims, (__privtrans->pdls[3]), 1, PDL_PPSYM_PARAM_bdims) \
275             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, c, (__privtrans->pdls[4]), 1, PDL_PPSYM_OP)
276             #endif
277             #define PDL_IF_BAD(t,f) f
278 1           switch (__privtrans->__datatype) { /* Start generic switch */
279 0           case PDL_SB: {
280 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_SByte,A,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
281 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
282 0           PDL_Indx *dimsa = adims_datap;
283 0           PDL_Indx *dimsb = bdims_datap;
284 0           PDL_Indx andims = __privtrans->ind_sizes[2];
285 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
286 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
287 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
288             double cc;
289              
290 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
291              
292 0           PDL_Indx pos[andims];
293 0 0         for (i=0; i
294 0           pos[i]=0;
295              
296             /* Find middle pixel in b */
297 0           i=0; nrow = dimsb[0];
298 0 0         while (i
299 0 0         for (j=0; j
300 0           pos[0]=j;
301 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
302 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_SByte;
303             }
304 0           ncen = i;
305 0           getout_PDL_SByte: i++;
306             }
307 0           pos[0]=0;
308 0           ndim_row_plusplus( pos, dimsb, bndims );
309             }
310              
311 0 0         for (i=0; i
312 0           pos[i]=0;
313              
314             /* Initialise offset array to handle the relative coords efficiently */
315 0           PDL_Indx off[bnvals]; /* Offset array */
316              
317 0           i=0;
318 0 0         while(i
319 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
320 0 0         for (j=0; j
321 0           off[i] = n+j;
322 0 0         if (i==ncen)
323 0           offcen = off[i]; /* Offset to middle */
324 0           i++;
325             }
326 0           ndim_row_plusplus( pos, dimsa, andims );
327             }
328              
329 0 0         for(i=0;i
330 0           off[i]=offcen-off[i];
331              
332             /* Now convolve the data */
333              
334 0 0         for(i=0; i
335 0           cc = 0;
336 0 0         for(j=0; j
337 0           i2 = (i+off[j]+anvals) % anvals ;
338 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
339             }
340 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
341             }
342 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
343 0           } break;
344 0           case PDL_B: {
345 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_Byte,B,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
346 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
347 0           PDL_Indx *dimsa = adims_datap;
348 0           PDL_Indx *dimsb = bdims_datap;
349 0           PDL_Indx andims = __privtrans->ind_sizes[2];
350 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
351 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
352 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
353             double cc;
354              
355 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
356              
357 0           PDL_Indx pos[andims];
358 0 0         for (i=0; i
359 0           pos[i]=0;
360              
361             /* Find middle pixel in b */
362 0           i=0; nrow = dimsb[0];
363 0 0         while (i
364 0 0         for (j=0; j
365 0           pos[0]=j;
366 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
367 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_Byte;
368             }
369 0           ncen = i;
370 0           getout_PDL_Byte: i++;
371             }
372 0           pos[0]=0;
373 0           ndim_row_plusplus( pos, dimsb, bndims );
374             }
375              
376 0 0         for (i=0; i
377 0           pos[i]=0;
378              
379             /* Initialise offset array to handle the relative coords efficiently */
380 0           PDL_Indx off[bnvals]; /* Offset array */
381              
382 0           i=0;
383 0 0         while(i
384 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
385 0 0         for (j=0; j
386 0           off[i] = n+j;
387 0 0         if (i==ncen)
388 0           offcen = off[i]; /* Offset to middle */
389 0           i++;
390             }
391 0           ndim_row_plusplus( pos, dimsa, andims );
392             }
393              
394 0 0         for(i=0;i
395 0           off[i]=offcen-off[i];
396              
397             /* Now convolve the data */
398              
399 0 0         for(i=0; i
400 0           cc = 0;
401 0 0         for(j=0; j
402 0           i2 = (i+off[j]+anvals) % anvals ;
403 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
404             }
405 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
406             }
407 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
408 0           } break;
409 0           case PDL_S: {
410 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_Short,S,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
411 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
412 0           PDL_Indx *dimsa = adims_datap;
413 0           PDL_Indx *dimsb = bdims_datap;
414 0           PDL_Indx andims = __privtrans->ind_sizes[2];
415 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
416 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
417 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
418             double cc;
419              
420 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
421              
422 0           PDL_Indx pos[andims];
423 0 0         for (i=0; i
424 0           pos[i]=0;
425              
426             /* Find middle pixel in b */
427 0           i=0; nrow = dimsb[0];
428 0 0         while (i
429 0 0         for (j=0; j
430 0           pos[0]=j;
431 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
432 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_Short;
433             }
434 0           ncen = i;
435 0           getout_PDL_Short: i++;
436             }
437 0           pos[0]=0;
438 0           ndim_row_plusplus( pos, dimsb, bndims );
439             }
440              
441 0 0         for (i=0; i
442 0           pos[i]=0;
443              
444             /* Initialise offset array to handle the relative coords efficiently */
445 0           PDL_Indx off[bnvals]; /* Offset array */
446              
447 0           i=0;
448 0 0         while(i
449 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
450 0 0         for (j=0; j
451 0           off[i] = n+j;
452 0 0         if (i==ncen)
453 0           offcen = off[i]; /* Offset to middle */
454 0           i++;
455             }
456 0           ndim_row_plusplus( pos, dimsa, andims );
457             }
458              
459 0 0         for(i=0;i
460 0           off[i]=offcen-off[i];
461              
462             /* Now convolve the data */
463              
464 0 0         for(i=0; i
465 0           cc = 0;
466 0 0         for(j=0; j
467 0           i2 = (i+off[j]+anvals) % anvals ;
468 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
469             }
470 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
471             }
472 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
473 0           } break;
474 0           case PDL_US: {
475 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_Ushort,U,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
476 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
477 0           PDL_Indx *dimsa = adims_datap;
478 0           PDL_Indx *dimsb = bdims_datap;
479 0           PDL_Indx andims = __privtrans->ind_sizes[2];
480 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
481 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
482 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
483             double cc;
484              
485 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
486              
487 0           PDL_Indx pos[andims];
488 0 0         for (i=0; i
489 0           pos[i]=0;
490              
491             /* Find middle pixel in b */
492 0           i=0; nrow = dimsb[0];
493 0 0         while (i
494 0 0         for (j=0; j
495 0           pos[0]=j;
496 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
497 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_Ushort;
498             }
499 0           ncen = i;
500 0           getout_PDL_Ushort: i++;
501             }
502 0           pos[0]=0;
503 0           ndim_row_plusplus( pos, dimsb, bndims );
504             }
505              
506 0 0         for (i=0; i
507 0           pos[i]=0;
508              
509             /* Initialise offset array to handle the relative coords efficiently */
510 0           PDL_Indx off[bnvals]; /* Offset array */
511              
512 0           i=0;
513 0 0         while(i
514 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
515 0 0         for (j=0; j
516 0           off[i] = n+j;
517 0 0         if (i==ncen)
518 0           offcen = off[i]; /* Offset to middle */
519 0           i++;
520             }
521 0           ndim_row_plusplus( pos, dimsa, andims );
522             }
523              
524 0 0         for(i=0;i
525 0           off[i]=offcen-off[i];
526              
527             /* Now convolve the data */
528              
529 0 0         for(i=0; i
530 0           cc = 0;
531 0 0         for(j=0; j
532 0           i2 = (i+off[j]+anvals) % anvals ;
533 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
534             }
535 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
536             }
537 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
538 0           } break;
539 0           case PDL_L: {
540 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_Long,L,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
541 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
542 0           PDL_Indx *dimsa = adims_datap;
543 0           PDL_Indx *dimsb = bdims_datap;
544 0           PDL_Indx andims = __privtrans->ind_sizes[2];
545 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
546 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
547 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
548             double cc;
549              
550 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
551              
552 0           PDL_Indx pos[andims];
553 0 0         for (i=0; i
554 0           pos[i]=0;
555              
556             /* Find middle pixel in b */
557 0           i=0; nrow = dimsb[0];
558 0 0         while (i
559 0 0         for (j=0; j
560 0           pos[0]=j;
561 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
562 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_Long;
563             }
564 0           ncen = i;
565 0           getout_PDL_Long: i++;
566             }
567 0           pos[0]=0;
568 0           ndim_row_plusplus( pos, dimsb, bndims );
569             }
570              
571 0 0         for (i=0; i
572 0           pos[i]=0;
573              
574             /* Initialise offset array to handle the relative coords efficiently */
575 0           PDL_Indx off[bnvals]; /* Offset array */
576              
577 0           i=0;
578 0 0         while(i
579 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
580 0 0         for (j=0; j
581 0           off[i] = n+j;
582 0 0         if (i==ncen)
583 0           offcen = off[i]; /* Offset to middle */
584 0           i++;
585             }
586 0           ndim_row_plusplus( pos, dimsa, andims );
587             }
588              
589 0 0         for(i=0;i
590 0           off[i]=offcen-off[i];
591              
592             /* Now convolve the data */
593              
594 0 0         for(i=0; i
595 0           cc = 0;
596 0 0         for(j=0; j
597 0           i2 = (i+off[j]+anvals) % anvals ;
598 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
599             }
600 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
601             }
602 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
603 0           } break;
604 0           case PDL_UL: {
605 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_ULong,K,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
606 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
607 0           PDL_Indx *dimsa = adims_datap;
608 0           PDL_Indx *dimsb = bdims_datap;
609 0           PDL_Indx andims = __privtrans->ind_sizes[2];
610 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
611 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
612 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
613             double cc;
614              
615 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
616              
617 0           PDL_Indx pos[andims];
618 0 0         for (i=0; i
619 0           pos[i]=0;
620              
621             /* Find middle pixel in b */
622 0           i=0; nrow = dimsb[0];
623 0 0         while (i
624 0 0         for (j=0; j
625 0           pos[0]=j;
626 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
627 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_ULong;
628             }
629 0           ncen = i;
630 0           getout_PDL_ULong: i++;
631             }
632 0           pos[0]=0;
633 0           ndim_row_plusplus( pos, dimsb, bndims );
634             }
635              
636 0 0         for (i=0; i
637 0           pos[i]=0;
638              
639             /* Initialise offset array to handle the relative coords efficiently */
640 0           PDL_Indx off[bnvals]; /* Offset array */
641              
642 0           i=0;
643 0 0         while(i
644 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
645 0 0         for (j=0; j
646 0           off[i] = n+j;
647 0 0         if (i==ncen)
648 0           offcen = off[i]; /* Offset to middle */
649 0           i++;
650             }
651 0           ndim_row_plusplus( pos, dimsa, andims );
652             }
653              
654 0 0         for(i=0;i
655 0           off[i]=offcen-off[i];
656              
657             /* Now convolve the data */
658              
659 0 0         for(i=0; i
660 0           cc = 0;
661 0 0         for(j=0; j
662 0           i2 = (i+off[j]+anvals) % anvals ;
663 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
664             }
665 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
666             }
667 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
668 0           } break;
669 0           case PDL_IND: {
670 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_Indx,N,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
671 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
672 0           PDL_Indx *dimsa = adims_datap;
673 0           PDL_Indx *dimsb = bdims_datap;
674 0           PDL_Indx andims = __privtrans->ind_sizes[2];
675 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
676 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
677 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
678             double cc;
679              
680 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
681              
682 0           PDL_Indx pos[andims];
683 0 0         for (i=0; i
684 0           pos[i]=0;
685              
686             /* Find middle pixel in b */
687 0           i=0; nrow = dimsb[0];
688 0 0         while (i
689 0 0         for (j=0; j
690 0           pos[0]=j;
691 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
692 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_Indx;
693             }
694 0           ncen = i;
695 0           getout_PDL_Indx: i++;
696             }
697 0           pos[0]=0;
698 0           ndim_row_plusplus( pos, dimsb, bndims );
699             }
700              
701 0 0         for (i=0; i
702 0           pos[i]=0;
703              
704             /* Initialise offset array to handle the relative coords efficiently */
705 0           PDL_Indx off[bnvals]; /* Offset array */
706              
707 0           i=0;
708 0 0         while(i
709 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
710 0 0         for (j=0; j
711 0           off[i] = n+j;
712 0 0         if (i==ncen)
713 0           offcen = off[i]; /* Offset to middle */
714 0           i++;
715             }
716 0           ndim_row_plusplus( pos, dimsa, andims );
717             }
718              
719 0 0         for(i=0;i
720 0           off[i]=offcen-off[i];
721              
722             /* Now convolve the data */
723              
724 0 0         for(i=0; i
725 0           cc = 0;
726 0 0         for(j=0; j
727 0           i2 = (i+off[j]+anvals) % anvals ;
728 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
729             }
730 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
731             }
732 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
733 0           } break;
734 0           case PDL_ULL: {
735 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_ULongLong,P,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
736 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
737 0           PDL_Indx *dimsa = adims_datap;
738 0           PDL_Indx *dimsb = bdims_datap;
739 0           PDL_Indx andims = __privtrans->ind_sizes[2];
740 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
741 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
742 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
743             double cc;
744              
745 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
746              
747 0           PDL_Indx pos[andims];
748 0 0         for (i=0; i
749 0           pos[i]=0;
750              
751             /* Find middle pixel in b */
752 0           i=0; nrow = dimsb[0];
753 0 0         while (i
754 0 0         for (j=0; j
755 0           pos[0]=j;
756 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
757 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_ULongLong;
758             }
759 0           ncen = i;
760 0           getout_PDL_ULongLong: i++;
761             }
762 0           pos[0]=0;
763 0           ndim_row_plusplus( pos, dimsb, bndims );
764             }
765              
766 0 0         for (i=0; i
767 0           pos[i]=0;
768              
769             /* Initialise offset array to handle the relative coords efficiently */
770 0           PDL_Indx off[bnvals]; /* Offset array */
771              
772 0           i=0;
773 0 0         while(i
774 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
775 0 0         for (j=0; j
776 0           off[i] = n+j;
777 0 0         if (i==ncen)
778 0           offcen = off[i]; /* Offset to middle */
779 0           i++;
780             }
781 0           ndim_row_plusplus( pos, dimsa, andims );
782             }
783              
784 0 0         for(i=0;i
785 0           off[i]=offcen-off[i];
786              
787             /* Now convolve the data */
788              
789 0 0         for(i=0; i
790 0           cc = 0;
791 0 0         for(j=0; j
792 0           i2 = (i+off[j]+anvals) % anvals ;
793 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
794             }
795 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
796             }
797 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
798 0           } break;
799 0           case PDL_LL: {
800 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_LongLong,Q,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
801 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
802 0           PDL_Indx *dimsa = adims_datap;
803 0           PDL_Indx *dimsb = bdims_datap;
804 0           PDL_Indx andims = __privtrans->ind_sizes[2];
805 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
806 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
807 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
808             double cc;
809              
810 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
811              
812 0           PDL_Indx pos[andims];
813 0 0         for (i=0; i
814 0           pos[i]=0;
815              
816             /* Find middle pixel in b */
817 0           i=0; nrow = dimsb[0];
818 0 0         while (i
819 0 0         for (j=0; j
820 0           pos[0]=j;
821 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
822 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_LongLong;
823             }
824 0           ncen = i;
825 0           getout_PDL_LongLong: i++;
826             }
827 0           pos[0]=0;
828 0           ndim_row_plusplus( pos, dimsb, bndims );
829             }
830              
831 0 0         for (i=0; i
832 0           pos[i]=0;
833              
834             /* Initialise offset array to handle the relative coords efficiently */
835 0           PDL_Indx off[bnvals]; /* Offset array */
836              
837 0           i=0;
838 0 0         while(i
839 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
840 0 0         for (j=0; j
841 0           off[i] = n+j;
842 0 0         if (i==ncen)
843 0           offcen = off[i]; /* Offset to middle */
844 0           i++;
845             }
846 0           ndim_row_plusplus( pos, dimsa, andims );
847             }
848              
849 0 0         for(i=0;i
850 0           off[i]=offcen-off[i];
851              
852             /* Now convolve the data */
853              
854 0 0         for(i=0; i
855 0           cc = 0;
856 0 0         for(j=0; j
857 0           i2 = (i+off[j]+anvals) % anvals ;
858 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
859             }
860 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
861             }
862 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
863 0           } break;
864 0           case PDL_F: {
865 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_Float,F,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
866 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
867 0           PDL_Indx *dimsa = adims_datap;
868 0           PDL_Indx *dimsb = bdims_datap;
869 0           PDL_Indx andims = __privtrans->ind_sizes[2];
870 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
871 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
872 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
873             double cc;
874              
875 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
876              
877 0           PDL_Indx pos[andims];
878 0 0         for (i=0; i
879 0           pos[i]=0;
880              
881             /* Find middle pixel in b */
882 0           i=0; nrow = dimsb[0];
883 0 0         while (i
884 0 0         for (j=0; j
885 0           pos[0]=j;
886 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
887 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_Float;
888             }
889 0           ncen = i;
890 0           getout_PDL_Float: i++;
891             }
892 0           pos[0]=0;
893 0           ndim_row_plusplus( pos, dimsb, bndims );
894             }
895              
896 0 0         for (i=0; i
897 0           pos[i]=0;
898              
899             /* Initialise offset array to handle the relative coords efficiently */
900 0           PDL_Indx off[bnvals]; /* Offset array */
901              
902 0           i=0;
903 0 0         while(i
904 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
905 0 0         for (j=0; j
906 0           off[i] = n+j;
907 0 0         if (i==ncen)
908 0           offcen = off[i]; /* Offset to middle */
909 0           i++;
910             }
911 0           ndim_row_plusplus( pos, dimsa, andims );
912             }
913              
914 0 0         for(i=0;i
915 0           off[i]=offcen-off[i];
916              
917             /* Now convolve the data */
918              
919 0 0         for(i=0; i
920 0           cc = 0;
921 0 0         for(j=0; j
922 0           i2 = (i+off[j]+anvals) % anvals ;
923 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
924             }
925 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
926             }
927 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
928 0           } break;
929 1           case PDL_D: {
930 1 50         PDL_DECLARE_PARAMS_convolve_1(PDL_Double,D,PDL_Indx,N,PDL_Indx,N)
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
931 4 50         PDL_BROADCASTLOOP_START_convolve_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
932 1           PDL_Indx *dimsa = adims_datap;
933 1           PDL_Indx *dimsb = bdims_datap;
934 1           PDL_Indx andims = __privtrans->ind_sizes[2];
935 1           PDL_Indx bndims = __privtrans->ind_sizes[3];
936 1           PDL_Indx anvals = __privtrans->ind_sizes[0];
937 1           PDL_Indx bnvals = __privtrans->ind_sizes[1];
938             double cc;
939              
940 1           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
941              
942 1           PDL_Indx pos[andims];
943 3 100         for (i=0; i
944 2           pos[i]=0;
945              
946             /* Find middle pixel in b */
947 1           i=0; nrow = dimsb[0];
948 3 100         while (i
949 6 100         for (j=0; j
950 4           pos[0]=j;
951 7 100         for (k=0; k < bndims; k++) { /* Is centre? */
952 6 100         if (pos[k] != dimsb[k]/2) goto getout_PDL_Double;
953             }
954 1           ncen = i;
955 4           getout_PDL_Double: i++;
956             }
957 2           pos[0]=0;
958 2           ndim_row_plusplus( pos, dimsb, bndims );
959             }
960              
961 3 100         for (i=0; i
962 2           pos[i]=0;
963              
964             /* Initialise offset array to handle the relative coords efficiently */
965 1           PDL_Indx off[bnvals]; /* Offset array */
966              
967 1           i=0;
968 3 100         while(i
969 2           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
970 6 100         for (j=0; j
971 4           off[i] = n+j;
972 4 100         if (i==ncen)
973 1           offcen = off[i]; /* Offset to middle */
974 4           i++;
975             }
976 2           ndim_row_plusplus( pos, dimsa, andims );
977             }
978              
979 5 100         for(i=0;i
980 4           off[i]=offcen-off[i];
981              
982             /* Now convolve the data */
983              
984 31 100         for(i=0; i
985 30           cc = 0;
986 150 100         for(j=0; j
987 120           i2 = (i+off[j]+anvals) % anvals ;
988 120           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
989             }
990 30           (c_datap)[0+(__inc_c_m*(i))] = cc;
991             }
992 1 50         }PDL_BROADCASTLOOP_END_convolve_readdata
    50          
993 1           } break;
994 0           case PDL_LD: {
995 0 0         PDL_DECLARE_PARAMS_convolve_1(PDL_LDouble,E,PDL_Indx,N,PDL_Indx,N)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
996 0 0         PDL_BROADCASTLOOP_START_convolve_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
997 0           PDL_Indx *dimsa = adims_datap;
998 0           PDL_Indx *dimsb = bdims_datap;
999 0           PDL_Indx andims = __privtrans->ind_sizes[2];
1000 0           PDL_Indx bndims = __privtrans->ind_sizes[3];
1001 0           PDL_Indx anvals = __privtrans->ind_sizes[0];
1002 0           PDL_Indx bnvals = __privtrans->ind_sizes[1];
1003             double cc;
1004              
1005 0           PDL_Indx i,i2,j,k,n,offcen=0,ncen=0,nrow;
1006              
1007 0           PDL_Indx pos[andims];
1008 0 0         for (i=0; i
1009 0           pos[i]=0;
1010              
1011             /* Find middle pixel in b */
1012 0           i=0; nrow = dimsb[0];
1013 0 0         while (i
1014 0 0         for (j=0; j
1015 0           pos[0]=j;
1016 0 0         for (k=0; k < bndims; k++) { /* Is centre? */
1017 0 0         if (pos[k] != dimsb[k]/2) goto getout_PDL_LDouble;
1018             }
1019 0           ncen = i;
1020 0           getout_PDL_LDouble: i++;
1021             }
1022 0           pos[0]=0;
1023 0           ndim_row_plusplus( pos, dimsb, bndims );
1024             }
1025              
1026 0 0         for (i=0; i
1027 0           pos[i]=0;
1028              
1029             /* Initialise offset array to handle the relative coords efficiently */
1030 0           PDL_Indx off[bnvals]; /* Offset array */
1031              
1032 0           i=0;
1033 0 0         while(i
1034 0           n = ndim_get_offset(pos, dimsa, andims); /* Start of row in A */
1035 0 0         for (j=0; j
1036 0           off[i] = n+j;
1037 0 0         if (i==ncen)
1038 0           offcen = off[i]; /* Offset to middle */
1039 0           i++;
1040             }
1041 0           ndim_row_plusplus( pos, dimsa, andims );
1042             }
1043              
1044 0 0         for(i=0;i
1045 0           off[i]=offcen-off[i];
1046              
1047             /* Now convolve the data */
1048              
1049 0 0         for(i=0; i
1050 0           cc = 0;
1051 0 0         for(j=0; j
1052 0           i2 = (i+off[j]+anvals) % anvals ;
1053 0           cc += (a_datap)[0+(__inc_a_m*(i2))] * (b_datap)[0+(__inc_b_n*(j))] ;
1054             }
1055 0           (c_datap)[0+(__inc_c_m*(i))] = cc;
1056             }
1057 0 0         }PDL_BROADCASTLOOP_END_convolve_readdata
    0          
1058 0           } break;
1059 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in convolve: unhandled datatype(%d), only handles (ABSULKNPQFDE)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
1060             }
1061             #undef PDL_IF_BAD
1062 1           return PDL_err;
1063             }
1064              
1065             static pdl_datatypes pdl_convolve_vtable_gentypes[] = { PDL_SB, PDL_B, PDL_S, PDL_US, PDL_L, PDL_UL, PDL_IND, PDL_ULL, PDL_LL, PDL_F, PDL_D, PDL_LD, -1 };
1066             static PDL_Indx pdl_convolve_vtable_realdims[] = { 1, 1, 1, 1, 1 };
1067             static char *pdl_convolve_vtable_parnames[] = { "a","b","adims","bdims","c" };
1068             static short pdl_convolve_vtable_parflags[] = {
1069             0,
1070             0,
1071             PDL_PARAM_ISPHYS|PDL_PARAM_ISTYPED,
1072             PDL_PARAM_ISPHYS|PDL_PARAM_ISTYPED,
1073             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE
1074             };
1075             static pdl_datatypes pdl_convolve_vtable_partypes[] = { -1, -1, PDL_IND, PDL_IND, -1 };
1076             static PDL_Indx pdl_convolve_vtable_realdims_starts[] = { 0, 1, 2, 3, 4 };
1077             static PDL_Indx pdl_convolve_vtable_realdims_ind_ids[] = { 0, 1, 2, 3, 0 };
1078             static char *pdl_convolve_vtable_indnames[] = { "m","n","p","q" };
1079             pdl_transvtable pdl_convolve_vtable = {
1080             PDL_TRANS_DO_BROADCAST, 0, pdl_convolve_vtable_gentypes, 4, 5, NULL /*CORE21*/,
1081             pdl_convolve_vtable_realdims, pdl_convolve_vtable_parnames,
1082             pdl_convolve_vtable_parflags, pdl_convolve_vtable_partypes,
1083             pdl_convolve_vtable_realdims_starts, pdl_convolve_vtable_realdims_ind_ids, 5,
1084             4, pdl_convolve_vtable_indnames,
1085             pdl_convolve_redodims, pdl_convolve_readdata, NULL,
1086             NULL,
1087             0,"PDL::ImageND::convolve"
1088             };
1089              
1090              
1091 1           pdl_error pdl_run_convolve(pdl *a,pdl *b,pdl *adims,pdl *bdims,pdl *c) {
1092 1           pdl_error PDL_err = {0, NULL, 0};
1093 1 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
1094 1           pdl_trans *__privtrans = PDL->create_trans(&pdl_convolve_vtable);
1095 1 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
1096 1           __privtrans->pdls[0] = a;
1097 1           __privtrans->pdls[1] = b;
1098 1           __privtrans->pdls[2] = adims;
1099 1           __privtrans->pdls[3] = bdims;
1100 1           __privtrans->pdls[4] = c;
1101 1 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
1102 1 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
1103 1           return PDL_err;
1104             }