[Bio] / Numeric / Src / arraytypes.c Repository:
ViewVC logotype

Annotation of /Numeric/Src/arraytypes.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : efrank 1.1
2 :     #include "Python.h"
3 :     #include "Numeric/arrayobject.h"
4 :    
5 :     #ifndef CHAR_BIT
6 :     #define CHAR_BIT 8
7 :     #endif
8 :    
9 :     #ifndef INT_BIT
10 :     #define INT_BIT (CHAR_BIT * sizeof(int))
11 :     #endif
12 :    
13 :     #ifndef INT_MAX
14 :     #define INT_MAX ((1 << (INT_BIT-2)) + ((1 << (INT_BIT-2))-1))
15 :     #endif
16 :    
17 :     static void CHAR_to_CHAR(char *ip, int ipstep, char *op, int opstep, int n)
18 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
19 :    
20 :     static void CHAR_to_UBYTE(char *ip, int ipstep, unsigned char *op, int opstep, int n)
21 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
22 :    
23 :     static void CHAR_to_SBYTE(char *ip, int ipstep, signed char *op, int opstep, int n)
24 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
25 :    
26 :     static void CHAR_to_SHORT(char *ip, int ipstep, short *op, int opstep, int n)
27 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
28 :    
29 :     static void CHAR_to_USHORT(char *ip, int ipstep, unsigned short *op, int opstep, int n)
30 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
31 :    
32 :     static void CHAR_to_INT(char *ip, int ipstep, int *op, int opstep, int n)
33 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
34 :    
35 :     static void CHAR_to_UINT(char *ip, int ipstep, unsigned int *op, int opstep, int n)
36 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
37 :    
38 :     static void CHAR_to_LONG(char *ip, int ipstep, long *op, int opstep, int n)
39 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
40 :    
41 :     static void CHAR_to_FLOAT(char *ip, int ipstep, float *op, int opstep, int n)
42 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
43 :    
44 :     static void CHAR_to_DOUBLE(char *ip, int ipstep, double *op, int opstep, int n)
45 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
46 :    
47 :     static void CHAR_to_CFLOAT(char *ip, int ipstep, float *op, int opstep, int n)
48 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=(float)0.0;}}
49 :    
50 :     static void CHAR_to_CDOUBLE(char *ip, int ipstep, double *op, int opstep, int n)
51 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
52 :    
53 :     static void CHAR_to_OBJECT(char *ip, int ipstep, PyObject **op, int opstep, int n)
54 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyString_FromStringAndSize(ip,1);}}
55 :    
56 :     static PyObject * CHAR_getitem(char *ip) {return PyString_FromStringAndSize(ip,1);}
57 :    
58 :     static int CHAR_setitem(PyObject *op, char *ov) {*((char *)ov)=(char)PyInt_AsLong(op);return PyErr_Occurred() ? -1:0;}
59 :    
60 :     static PyArray_Descr CHAR_Descr = { {
61 :    
62 :     (PyArray_VectorUnaryFunc*)CHAR_to_CHAR,
63 :     (PyArray_VectorUnaryFunc*)CHAR_to_UBYTE,
64 :     (PyArray_VectorUnaryFunc*)CHAR_to_SBYTE,
65 :     (PyArray_VectorUnaryFunc*)CHAR_to_SHORT,
66 :     (PyArray_VectorUnaryFunc*)CHAR_to_USHORT,
67 :     (PyArray_VectorUnaryFunc*)CHAR_to_INT,
68 :     (PyArray_VectorUnaryFunc*)CHAR_to_UINT,
69 :     (PyArray_VectorUnaryFunc*)CHAR_to_LONG,
70 :     (PyArray_VectorUnaryFunc*)CHAR_to_FLOAT,
71 :     (PyArray_VectorUnaryFunc*)CHAR_to_DOUBLE,
72 :     (PyArray_VectorUnaryFunc*)CHAR_to_CFLOAT,
73 :     (PyArray_VectorUnaryFunc*)CHAR_to_CDOUBLE,
74 :     (PyArray_VectorUnaryFunc*)CHAR_to_OBJECT,
75 :     },
76 :     CHAR_getitem, CHAR_setitem,
77 :     PyArray_CHAR, sizeof(char), NULL, NULL, 'c'};
78 :    
79 :    
80 :     static void UBYTE_to_CHAR(unsigned char *ip, int ipstep, char *op, int opstep, int n)
81 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
82 :    
83 :     static void UBYTE_to_UBYTE(unsigned char *ip, int ipstep, unsigned char *op, int opstep, int n)
84 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
85 :    
86 :     static void UBYTE_to_SBYTE(unsigned char *ip, int ipstep, signed char *op, int opstep, int n)
87 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
88 :    
89 :     static void UBYTE_to_SHORT(unsigned char *ip, int ipstep, short *op, int opstep, int n)
90 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
91 :    
92 :     static void UBYTE_to_USHORT(unsigned char *ip, int ipstep, unsigned short *op, int opstep, int n)
93 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
94 :    
95 :     static void UBYTE_to_INT(unsigned char *ip, int ipstep, int *op, int opstep, int n)
96 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
97 :    
98 :     static void UBYTE_to_UINT(unsigned char *ip, int ipstep, unsigned int *op, int opstep, int n)
99 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
100 :    
101 :     static void UBYTE_to_LONG(unsigned char *ip, int ipstep, long *op, int opstep, int n)
102 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
103 :    
104 :     static void UBYTE_to_FLOAT(unsigned char *ip, int ipstep, float *op, int opstep, int n)
105 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
106 :    
107 :     static void UBYTE_to_DOUBLE(unsigned char *ip, int ipstep, double *op, int opstep, int n)
108 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
109 :    
110 :     static void UBYTE_to_CFLOAT(unsigned char *ip, int ipstep, float *op, int opstep, int n)
111 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
112 :    
113 :     static void UBYTE_to_CDOUBLE(unsigned char *ip, int ipstep, double *op, int opstep, int n)
114 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
115 :    
116 :     static void UBYTE_to_OBJECT(unsigned char *ip, int ipstep, PyObject **op, int opstep, int n)
117 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyInt_FromLong((long)*((unsigned char *)ip));}}
118 :    
119 :     static PyObject * UBYTE_getitem(char *ip) {return PyInt_FromLong((long)*((unsigned char *)ip));}
120 :    
121 :     static int UBYTE_setitem(PyObject *op, char *ov) {*((unsigned char *)ov)=(unsigned char)PyInt_AsLong(op);return PyErr_Occurred() ? -1:0;}
122 :    
123 :     static PyArray_Descr UBYTE_Descr = { {
124 :    
125 :     (PyArray_VectorUnaryFunc*)UBYTE_to_CHAR,
126 :     (PyArray_VectorUnaryFunc*)UBYTE_to_UBYTE,
127 :     (PyArray_VectorUnaryFunc*)UBYTE_to_SBYTE,
128 :     (PyArray_VectorUnaryFunc*)UBYTE_to_SHORT,
129 :     (PyArray_VectorUnaryFunc*)UBYTE_to_USHORT,
130 :     (PyArray_VectorUnaryFunc*)UBYTE_to_INT,
131 :     (PyArray_VectorUnaryFunc*)UBYTE_to_UINT,
132 :     (PyArray_VectorUnaryFunc*)UBYTE_to_LONG,
133 :     (PyArray_VectorUnaryFunc*)UBYTE_to_FLOAT,
134 :     (PyArray_VectorUnaryFunc*)UBYTE_to_DOUBLE,
135 :     (PyArray_VectorUnaryFunc*)UBYTE_to_CFLOAT,
136 :     (PyArray_VectorUnaryFunc*)UBYTE_to_CDOUBLE,
137 :     (PyArray_VectorUnaryFunc*)UBYTE_to_OBJECT,
138 :     },
139 :     UBYTE_getitem, UBYTE_setitem,
140 :     PyArray_UBYTE, sizeof(unsigned char), NULL, NULL, 'b'};
141 :    
142 :    
143 :     static void SBYTE_to_CHAR(signed char *ip, int ipstep, char *op, int opstep, int n)
144 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
145 :    
146 :     static void SBYTE_to_UBYTE(signed char *ip, int ipstep, unsigned char *op, int opstep, int n)
147 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
148 :    
149 :     static void SBYTE_to_SBYTE(signed char *ip, int ipstep, signed char *op, int opstep, int n)
150 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
151 :    
152 :     static void SBYTE_to_SHORT(signed char *ip, int ipstep, short *op, int opstep, int n)
153 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
154 :    
155 :     static void SBYTE_to_USHORT(signed char *ip, int ipstep, unsigned short *op, int opstep, int n)
156 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
157 :    
158 :     static void SBYTE_to_INT(signed char *ip, int ipstep, int *op, int opstep, int n)
159 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
160 :    
161 :     static void SBYTE_to_UINT(signed char *ip, int ipstep, unsigned int *op, int opstep, int n)
162 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
163 :    
164 :     static void SBYTE_to_LONG(signed char *ip, int ipstep, long *op, int opstep, int n)
165 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
166 :    
167 :     static void SBYTE_to_FLOAT(signed char *ip, int ipstep, float *op, int opstep, int n)
168 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
169 :    
170 :     static void SBYTE_to_DOUBLE(signed char *ip, int ipstep, double *op, int opstep, int n)
171 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
172 :    
173 :     static void SBYTE_to_CFLOAT(signed char *ip, int ipstep, float *op, int opstep, int n)
174 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
175 :    
176 :     static void SBYTE_to_CDOUBLE(signed char *ip, int ipstep, double *op, int opstep, int n)
177 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
178 :    
179 :     static void SBYTE_to_OBJECT(signed char *ip, int ipstep, PyObject **op, int opstep, int n)
180 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyInt_FromLong((long)*((signed char *)ip));}}
181 :    
182 :     static PyObject * SBYTE_getitem(char *ip) {return PyInt_FromLong((long)*((signed char *)ip));}
183 :    
184 :     static int SBYTE_setitem(PyObject *op, char *ov) {*((signed char *)ov)=(signed char)PyInt_AsLong(op);return PyErr_Occurred() ? -1:0;}
185 :    
186 :     static PyArray_Descr SBYTE_Descr = { {
187 :    
188 :     (PyArray_VectorUnaryFunc*)SBYTE_to_CHAR,
189 :     (PyArray_VectorUnaryFunc*)SBYTE_to_UBYTE,
190 :     (PyArray_VectorUnaryFunc*)SBYTE_to_SBYTE,
191 :     (PyArray_VectorUnaryFunc*)SBYTE_to_SHORT,
192 :     (PyArray_VectorUnaryFunc*)SBYTE_to_USHORT,
193 :     (PyArray_VectorUnaryFunc*)SBYTE_to_INT,
194 :     (PyArray_VectorUnaryFunc*)SBYTE_to_UINT,
195 :     (PyArray_VectorUnaryFunc*)SBYTE_to_LONG,
196 :     (PyArray_VectorUnaryFunc*)SBYTE_to_FLOAT,
197 :     (PyArray_VectorUnaryFunc*)SBYTE_to_DOUBLE,
198 :     (PyArray_VectorUnaryFunc*)SBYTE_to_CFLOAT,
199 :     (PyArray_VectorUnaryFunc*)SBYTE_to_CDOUBLE,
200 :     (PyArray_VectorUnaryFunc*)SBYTE_to_OBJECT,
201 :     },
202 :     SBYTE_getitem, SBYTE_setitem,
203 :     PyArray_SBYTE, sizeof(signed char), NULL, NULL, '1'};
204 :    
205 :    
206 :     static void USHORT_to_CHAR(unsigned short *ip, int ipstep, char *op, int opstep, int n)
207 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
208 :    
209 :     static void USHORT_to_UBYTE(unsigned short *ip, int ipstep, unsigned char *op, int opstep, int n)
210 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
211 :    
212 :     static void USHORT_to_SBYTE(unsigned short *ip, int ipstep, signed char *op, int opstep, int n)
213 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
214 :    
215 :     static void USHORT_to_SHORT(unsigned short *ip, int ipstep, short *op, int opstep, int n)
216 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
217 :    
218 :     static void USHORT_to_USHORT(unsigned short *ip, int ipstep, unsigned short *op, int opstep, int n)
219 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
220 :    
221 :     static void USHORT_to_INT(unsigned short *ip, int ipstep, int *op, int opstep, int n)
222 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
223 :    
224 :     static void USHORT_to_UINT(unsigned short *ip, int ipstep, unsigned int *op, int opstep, int n)
225 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
226 :    
227 :     static void USHORT_to_LONG(unsigned short *ip, int ipstep, long *op, int opstep, int n)
228 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
229 :    
230 :     static void USHORT_to_FLOAT(unsigned short *ip, int ipstep, float *op, int opstep, int n)
231 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
232 :    
233 :     static void USHORT_to_DOUBLE(unsigned short *ip, int ipstep, double *op, int opstep, int n)
234 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
235 :    
236 :     static void USHORT_to_CFLOAT(unsigned short *ip, int ipstep, float *op, int opstep, int n)
237 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
238 :    
239 :     static void USHORT_to_CDOUBLE(unsigned short *ip, int ipstep, double *op, int opstep, int n)
240 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
241 :    
242 :     static void USHORT_to_OBJECT(unsigned short *ip, int ipstep, PyObject **op, int opstep, int n)
243 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyInt_FromLong((long)*((unsigned short *)ip));}}
244 :    
245 :     static PyObject * USHORT_getitem(char *ip) {return PyInt_FromLong((long)*((unsigned short *)ip));}
246 :    
247 :     static int USHORT_setitem(PyObject *op, char *ov) {*((unsigned short *)ov)=(unsigned short)PyInt_AsLong(op);return PyErr_Occurred() ? -1:0;}
248 :    
249 :     static PyArray_Descr USHORT_Descr = { {
250 :    
251 :     (PyArray_VectorUnaryFunc*)USHORT_to_CHAR,
252 :     (PyArray_VectorUnaryFunc*)USHORT_to_UBYTE,
253 :     (PyArray_VectorUnaryFunc*)USHORT_to_SBYTE,
254 :     (PyArray_VectorUnaryFunc*)USHORT_to_SHORT,
255 :     (PyArray_VectorUnaryFunc*)USHORT_to_USHORT,
256 :     (PyArray_VectorUnaryFunc*)USHORT_to_INT,
257 :     (PyArray_VectorUnaryFunc*)USHORT_to_UINT,
258 :     (PyArray_VectorUnaryFunc*)USHORT_to_LONG,
259 :     (PyArray_VectorUnaryFunc*)USHORT_to_FLOAT,
260 :     (PyArray_VectorUnaryFunc*)USHORT_to_DOUBLE,
261 :     (PyArray_VectorUnaryFunc*)USHORT_to_CFLOAT,
262 :     (PyArray_VectorUnaryFunc*)USHORT_to_CDOUBLE,
263 :     (PyArray_VectorUnaryFunc*)USHORT_to_OBJECT,
264 :     },
265 :     USHORT_getitem, USHORT_setitem,
266 :     PyArray_USHORT, sizeof(unsigned short), NULL, NULL, 'w'};
267 :    
268 :    
269 :     static void SHORT_to_CHAR(short *ip, int ipstep, char *op, int opstep, int n)
270 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
271 :    
272 :     static void SHORT_to_UBYTE(short *ip, int ipstep, unsigned char *op, int opstep, int n)
273 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
274 :    
275 :     static void SHORT_to_SBYTE(short *ip, int ipstep, signed char *op, int opstep, int n)
276 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
277 :    
278 :     static void SHORT_to_SHORT(short *ip, int ipstep, short *op, int opstep, int n)
279 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
280 :    
281 :     static void SHORT_to_USHORT(short *ip, int ipstep, unsigned short *op, int opstep, int n)
282 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
283 :    
284 :     static void SHORT_to_INT(short *ip, int ipstep, int *op, int opstep, int n)
285 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
286 :    
287 :     static void SHORT_to_UINT(short *ip, int ipstep, unsigned int *op, int opstep, int n)
288 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
289 :    
290 :     static void SHORT_to_LONG(short *ip, int ipstep, long *op, int opstep, int n)
291 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
292 :    
293 :     static void SHORT_to_FLOAT(short *ip, int ipstep, float *op, int opstep, int n)
294 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
295 :    
296 :     static void SHORT_to_DOUBLE(short *ip, int ipstep, double *op, int opstep, int n)
297 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
298 :    
299 :     static void SHORT_to_CFLOAT(short *ip, int ipstep, float *op, int opstep, int n)
300 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
301 :    
302 :     static void SHORT_to_CDOUBLE(short *ip, int ipstep, double *op, int opstep, int n)
303 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
304 :    
305 :     static void SHORT_to_OBJECT(short *ip, int ipstep, PyObject **op, int opstep, int n)
306 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyInt_FromLong((long)*((short *)ip));}}
307 :    
308 :     static PyObject * SHORT_getitem(char *ip) {return PyInt_FromLong((long)*((short *)ip));}
309 :    
310 :     static int SHORT_setitem(PyObject *op, char *ov) {*((short *)ov)=(short)PyInt_AsLong(op);return PyErr_Occurred() ? -1:0;}
311 :    
312 :     static PyArray_Descr SHORT_Descr = { {
313 :    
314 :     (PyArray_VectorUnaryFunc*)SHORT_to_CHAR,
315 :     (PyArray_VectorUnaryFunc*)SHORT_to_UBYTE,
316 :     (PyArray_VectorUnaryFunc*)SHORT_to_SBYTE,
317 :     (PyArray_VectorUnaryFunc*)SHORT_to_SHORT,
318 :     (PyArray_VectorUnaryFunc*)SHORT_to_USHORT,
319 :     (PyArray_VectorUnaryFunc*)SHORT_to_INT,
320 :     (PyArray_VectorUnaryFunc*)SHORT_to_UINT,
321 :     (PyArray_VectorUnaryFunc*)SHORT_to_LONG,
322 :     (PyArray_VectorUnaryFunc*)SHORT_to_FLOAT,
323 :     (PyArray_VectorUnaryFunc*)SHORT_to_DOUBLE,
324 :     (PyArray_VectorUnaryFunc*)SHORT_to_CFLOAT,
325 :     (PyArray_VectorUnaryFunc*)SHORT_to_CDOUBLE,
326 :     (PyArray_VectorUnaryFunc*)SHORT_to_OBJECT,
327 :     },
328 :     SHORT_getitem, SHORT_setitem,
329 :     PyArray_SHORT, sizeof(short), NULL, NULL, 's'};
330 :    
331 :    
332 :     static void INT_to_CHAR(int *ip, int ipstep, char *op, int opstep, int n)
333 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
334 :    
335 :     static void INT_to_UBYTE(int *ip, int ipstep, unsigned char *op, int opstep, int n)
336 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
337 :    
338 :     static void INT_to_SBYTE(int *ip, int ipstep, signed char *op, int opstep, int n)
339 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
340 :    
341 :     static void INT_to_SHORT(int *ip, int ipstep, short *op, int opstep, int n)
342 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
343 :    
344 :     static void INT_to_USHORT(int *ip, int ipstep, unsigned short *op, int opstep, int n)
345 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
346 :    
347 :     static void INT_to_INT(int *ip, int ipstep, int *op, int opstep, int n)
348 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
349 :    
350 :     static void INT_to_UINT(int *ip, int ipstep, unsigned int *op, int opstep, int n)
351 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
352 :    
353 :     static void INT_to_LONG(int *ip, int ipstep, long *op, int opstep, int n)
354 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
355 :    
356 :     static void INT_to_FLOAT(int *ip, int ipstep, float *op, int opstep, int n)
357 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
358 :    
359 :     static void INT_to_DOUBLE(int *ip, int ipstep, double *op, int opstep, int n)
360 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
361 :    
362 :     static void INT_to_CFLOAT(int *ip, int ipstep, float *op, int opstep, int n)
363 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
364 :    
365 :     static void INT_to_CDOUBLE(int *ip, int ipstep, double *op, int opstep, int n)
366 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
367 :    
368 :     static void INT_to_OBJECT(int *ip, int ipstep, PyObject **op, int opstep, int n)
369 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyInt_FromLong((long)*((int *)ip));}}
370 :    
371 :     static PyObject * INT_getitem(char *ip) {return PyInt_FromLong((long)*((int *)ip));}
372 :    
373 :     static int INT_setitem(PyObject *op, char *ov) {*((int *)ov)=PyInt_AsLong(op);return PyErr_Occurred() ? -1:0;}
374 :    
375 :     static PyArray_Descr INT_Descr = { {
376 :    
377 :     (PyArray_VectorUnaryFunc*)INT_to_CHAR,
378 :     (PyArray_VectorUnaryFunc*)INT_to_UBYTE,
379 :     (PyArray_VectorUnaryFunc*)INT_to_SBYTE,
380 :     (PyArray_VectorUnaryFunc*)INT_to_SHORT,
381 :     (PyArray_VectorUnaryFunc*)INT_to_USHORT,
382 :     (PyArray_VectorUnaryFunc*)INT_to_INT,
383 :     (PyArray_VectorUnaryFunc*)INT_to_UINT,
384 :     (PyArray_VectorUnaryFunc*)INT_to_LONG,
385 :     (PyArray_VectorUnaryFunc*)INT_to_FLOAT,
386 :     (PyArray_VectorUnaryFunc*)INT_to_DOUBLE,
387 :     (PyArray_VectorUnaryFunc*)INT_to_CFLOAT,
388 :     (PyArray_VectorUnaryFunc*)INT_to_CDOUBLE,
389 :     (PyArray_VectorUnaryFunc*)INT_to_OBJECT,
390 :     },
391 :     INT_getitem, INT_setitem,
392 :     PyArray_INT, sizeof(int), NULL, NULL, 'i'};
393 :    
394 :     static void UINT_to_CHAR(unsigned int *ip, int ipstep, char *op, int opstep, int n)
395 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
396 :    
397 :     static void UINT_to_UBYTE(unsigned int *ip, int ipstep, unsigned char *op, int opstep, int n)
398 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
399 :    
400 :     static void UINT_to_SBYTE(unsigned int *ip, int ipstep, signed char *op, int opstep, int n)
401 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
402 :    
403 :     static void UINT_to_SHORT(unsigned int *ip, int ipstep, short *op, int opstep, int n)
404 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
405 :    
406 :     static void UINT_to_USHORT(unsigned int *ip, int ipstep, unsigned short *op, int opstep, int n)
407 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
408 :    
409 :     static void UINT_to_INT(unsigned int *ip, int ipstep, int *op, int opstep, int n)
410 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
411 :    
412 :     static void UINT_to_UINT(unsigned int *ip, int ipstep, unsigned int *op, int opstep, int n)
413 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
414 :    
415 :     static void UINT_to_LONG(unsigned int *ip, int ipstep, long *op, int opstep, int n)
416 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
417 :    
418 :     static void UINT_to_FLOAT(unsigned int *ip, int ipstep, float *op, int opstep, int n)
419 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
420 :    
421 :     static void UINT_to_DOUBLE(unsigned int *ip, int ipstep, double *op, int opstep, int n)
422 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
423 :    
424 :     static void UINT_to_CFLOAT(unsigned int *ip, int ipstep, float *op, int opstep, int n)
425 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
426 :    
427 :     static void UINT_to_CDOUBLE(unsigned int *ip, int ipstep, double *op, int opstep, int n)
428 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
429 :    
430 :     static void UINT_to_OBJECT(unsigned int *ip, int ipstep, PyObject **op, int opstep, int n)
431 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyInt_FromLong((long)*ip);}}
432 :    
433 :     static PyObject * UINT_getitem(char *ip) {
434 :     if (*((unsigned int *)ip) > (unsigned int) INT_MAX) {
435 :     return PyLong_FromUnsignedLong((unsigned long)*((unsigned int *)ip));
436 :     } else {
437 :     return PyInt_FromLong((long)*((unsigned int *)ip));
438 :     }
439 :     }
440 :    
441 :     static int UINT_setitem(PyObject *op, char *ov) {
442 :     if (PyLong_Check(op)) {
443 :     *((unsigned int *)ov)=(unsigned int)PyLong_AsUnsignedLong(op);
444 :     } else {
445 :     *((unsigned int *)ov)=(unsigned int)PyInt_AsLong(op);
446 :     }
447 :     return PyErr_Occurred() ? -1:0;
448 :     }
449 :    
450 :     static PyArray_Descr UINT_Descr = { {
451 :    
452 :     (PyArray_VectorUnaryFunc*)UINT_to_CHAR,
453 :     (PyArray_VectorUnaryFunc*)UINT_to_UBYTE,
454 :     (PyArray_VectorUnaryFunc*)UINT_to_SBYTE,
455 :     (PyArray_VectorUnaryFunc*)UINT_to_SHORT,
456 :     (PyArray_VectorUnaryFunc*)UINT_to_USHORT,
457 :     (PyArray_VectorUnaryFunc*)UINT_to_INT,
458 :     (PyArray_VectorUnaryFunc*)UINT_to_UINT,
459 :     (PyArray_VectorUnaryFunc*)UINT_to_LONG,
460 :     (PyArray_VectorUnaryFunc*)UINT_to_FLOAT,
461 :     (PyArray_VectorUnaryFunc*)UINT_to_DOUBLE,
462 :     (PyArray_VectorUnaryFunc*)UINT_to_CFLOAT,
463 :     (PyArray_VectorUnaryFunc*)UINT_to_CDOUBLE,
464 :     (PyArray_VectorUnaryFunc*)UINT_to_OBJECT,
465 :     },
466 :     UINT_getitem, UINT_setitem,
467 :     PyArray_UINT, sizeof(unsigned int), NULL, NULL, 'u'};
468 :    
469 :    
470 :     static void LONG_to_CHAR(long *ip, int ipstep, char *op, int opstep, int n)
471 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
472 :    
473 :     static void LONG_to_UBYTE(long *ip, int ipstep, unsigned char *op, int opstep, int n)
474 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
475 :    
476 :     static void LONG_to_SBYTE(long *ip, int ipstep, signed char *op, int opstep, int n)
477 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
478 :    
479 :     static void LONG_to_SHORT(long *ip, int ipstep, short *op, int opstep, int n)
480 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
481 :    
482 :     static void LONG_to_USHORT(long *ip, int ipstep, unsigned short *op, int opstep, int n)
483 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
484 :    
485 :     static void LONG_to_INT(long *ip, int ipstep, int *op, int opstep, int n)
486 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
487 :    
488 :     static void LONG_to_UINT(long *ip, int ipstep, unsigned int *op, int opstep, int n)
489 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
490 :    
491 :     static void LONG_to_LONG(long *ip, int ipstep, long *op, int opstep, int n)
492 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
493 :    
494 :     static void LONG_to_FLOAT(long *ip, int ipstep, float *op, int opstep, int n)
495 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
496 :    
497 :     static void LONG_to_DOUBLE(long *ip, int ipstep, double *op, int opstep, int n)
498 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
499 :    
500 :     static void LONG_to_CFLOAT(long *ip, int ipstep, float *op, int opstep, int n)
501 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
502 :    
503 :     static void LONG_to_CDOUBLE(long *ip, int ipstep, double *op, int opstep, int n)
504 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
505 :    
506 :     static void LONG_to_OBJECT(long *ip, int ipstep, PyObject **op, int opstep, int n)
507 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyInt_FromLong((long)*((long *)ip));}}
508 :    
509 :     static PyObject * LONG_getitem(char *ip) {return PyInt_FromLong((long)*((long *)ip));}
510 :    
511 :     static int LONG_setitem(PyObject *op, char *ov) {*((long *)ov)=PyInt_AsLong(op);return PyErr_Occurred() ? -1:0;}
512 :    
513 :     static PyArray_Descr LONG_Descr = { {
514 :    
515 :     (PyArray_VectorUnaryFunc*)LONG_to_CHAR,
516 :     (PyArray_VectorUnaryFunc*)LONG_to_UBYTE,
517 :     (PyArray_VectorUnaryFunc*)LONG_to_SBYTE,
518 :     (PyArray_VectorUnaryFunc*)LONG_to_SHORT,
519 :     (PyArray_VectorUnaryFunc*)LONG_to_USHORT,
520 :     (PyArray_VectorUnaryFunc*)LONG_to_INT,
521 :     (PyArray_VectorUnaryFunc*)LONG_to_UINT,
522 :     (PyArray_VectorUnaryFunc*)LONG_to_LONG,
523 :     (PyArray_VectorUnaryFunc*)LONG_to_FLOAT,
524 :     (PyArray_VectorUnaryFunc*)LONG_to_DOUBLE,
525 :     (PyArray_VectorUnaryFunc*)LONG_to_CFLOAT,
526 :     (PyArray_VectorUnaryFunc*)LONG_to_CDOUBLE,
527 :     (PyArray_VectorUnaryFunc*)LONG_to_OBJECT,
528 :     },
529 :     LONG_getitem, LONG_setitem,
530 :     PyArray_LONG, sizeof(long), NULL, NULL, 'l'};
531 :    
532 :    
533 :     static void FLOAT_to_CHAR(float *ip, int ipstep, char *op, int opstep, int n)
534 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
535 :    
536 :     static void FLOAT_to_UBYTE(float *ip, int ipstep, unsigned char *op, int opstep, int n)
537 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
538 :    
539 :     static void FLOAT_to_SBYTE(float *ip, int ipstep, signed char *op, int opstep, int n)
540 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
541 :    
542 :     static void FLOAT_to_SHORT(float *ip, int ipstep, short *op, int opstep, int n)
543 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
544 :    
545 :     static void FLOAT_to_USHORT(float *ip, int ipstep, unsigned short *op, int opstep, int n)
546 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
547 :    
548 :     static void FLOAT_to_INT(float *ip, int ipstep, int *op, int opstep, int n)
549 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
550 :    
551 :     static void FLOAT_to_UINT(float *ip, int ipstep, unsigned int *op, int opstep, int n)
552 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
553 :    
554 :     static void FLOAT_to_LONG(float *ip, int ipstep, long *op, int opstep, int n)
555 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
556 :    
557 :     static void FLOAT_to_FLOAT(float *ip, int ipstep, float *op, int opstep, int n)
558 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
559 :    
560 :     static void FLOAT_to_DOUBLE(float *ip, int ipstep, double *op, int opstep, int n)
561 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
562 :    
563 :     static void FLOAT_to_CFLOAT(float *ip, int ipstep, float *op, int opstep, int n)
564 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
565 :    
566 :     static void FLOAT_to_CDOUBLE(float *ip, int ipstep, double *op, int opstep, int n)
567 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
568 :    
569 :     static void FLOAT_to_OBJECT(float *ip, int ipstep, PyObject **op, int opstep, int n)
570 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyFloat_FromDouble((double)*((float *)ip));}}
571 :    
572 :     static PyObject * FLOAT_getitem(char *ip) {return PyFloat_FromDouble((double)*((float *)ip));}
573 :    
574 :     static int FLOAT_setitem(PyObject *op, char *ov) {*((float *)ov)=(float)PyFloat_AsDouble(op);return PyErr_Occurred() ? -1:0;}
575 :    
576 :     static PyArray_Descr FLOAT_Descr = { {
577 :    
578 :     (PyArray_VectorUnaryFunc*)FLOAT_to_CHAR,
579 :     (PyArray_VectorUnaryFunc*)FLOAT_to_UBYTE,
580 :     (PyArray_VectorUnaryFunc*)FLOAT_to_SBYTE,
581 :     (PyArray_VectorUnaryFunc*)FLOAT_to_SHORT,
582 :     (PyArray_VectorUnaryFunc*)FLOAT_to_USHORT,
583 :     (PyArray_VectorUnaryFunc*)FLOAT_to_INT,
584 :     (PyArray_VectorUnaryFunc*)FLOAT_to_UINT,
585 :     (PyArray_VectorUnaryFunc*)FLOAT_to_LONG,
586 :     (PyArray_VectorUnaryFunc*)FLOAT_to_FLOAT,
587 :     (PyArray_VectorUnaryFunc*)FLOAT_to_DOUBLE,
588 :     (PyArray_VectorUnaryFunc*)FLOAT_to_CFLOAT,
589 :     (PyArray_VectorUnaryFunc*)FLOAT_to_CDOUBLE,
590 :     (PyArray_VectorUnaryFunc*)FLOAT_to_OBJECT,
591 :     },
592 :     FLOAT_getitem, FLOAT_setitem,
593 :     PyArray_FLOAT, sizeof(float), NULL, NULL, 'f'};
594 :    
595 :    
596 :     static void DOUBLE_to_CHAR(double *ip, int ipstep, char *op, int opstep, int n)
597 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (char)*ip;}}
598 :    
599 :     static void DOUBLE_to_UBYTE(double *ip, int ipstep, unsigned char *op, int opstep, int n)
600 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned char)*ip;}}
601 :    
602 :     static void DOUBLE_to_SBYTE(double *ip, int ipstep, signed char *op, int opstep, int n)
603 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (signed char)*ip;}}
604 :    
605 :     static void DOUBLE_to_SHORT(double *ip, int ipstep, short *op, int opstep, int n)
606 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (short)*ip;}}
607 :    
608 :     static void DOUBLE_to_USHORT(double *ip, int ipstep, unsigned short *op, int opstep, int n)
609 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned short)*ip;}}
610 :    
611 :     static void DOUBLE_to_INT(double *ip, int ipstep, int *op, int opstep, int n)
612 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (int)*ip;}}
613 :    
614 :     static void DOUBLE_to_UINT(double *ip, int ipstep, unsigned int *op, int opstep, int n)
615 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (unsigned int)*ip;}}
616 :    
617 :     static void DOUBLE_to_LONG(double *ip, int ipstep, long *op, int opstep, int n)
618 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (long)*ip;}}
619 :    
620 :     static void DOUBLE_to_FLOAT(double *ip, int ipstep, float *op, int opstep, int n)
621 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
622 :    
623 :     static void DOUBLE_to_DOUBLE(double *ip, int ipstep, double *op, int opstep, int n)
624 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
625 :    
626 :     static void DOUBLE_to_CFLOAT(double *ip, int ipstep, float *op, int opstep, int n)
627 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (float)*ip; op[1]=0.0;}}
628 :    
629 :     static void DOUBLE_to_CDOUBLE(double *ip, int ipstep, double *op, int opstep, int n)
630 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep*2) {op[0] = (double)*ip; op[1]=0.0;}}
631 :    
632 :     static void DOUBLE_to_OBJECT(double *ip, int ipstep, PyObject **op, int opstep, int n)
633 :     {int i; for(i=0;i<n;i++,ip+=ipstep,op+=opstep) {op[0] = PyFloat_FromDouble((double)*((double *)ip));}}
634 :    
635 :     static PyObject * DOUBLE_getitem(char *ip) {return PyFloat_FromDouble((double)*((double *)ip));}
636 :    
637 :     static int DOUBLE_setitem(PyObject *op, char *ov) {*((double *)ov)=PyFloat_AsDouble(op);return PyErr_Occurred() ? -1:0;}
638 :    
639 :     static PyArray_Descr DOUBLE_Descr = { {
640 :    
641 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_CHAR,
642 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_UBYTE,
643 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_SBYTE,
644 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_SHORT,
645 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_USHORT,
646 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_INT,
647 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_UINT,
648 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_LONG,
649 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_FLOAT,
650 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_DOUBLE,
651 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_CFLOAT,
652 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_CDOUBLE,
653 :     (PyArray_VectorUnaryFunc*)DOUBLE_to_OBJECT,
654 :     },
655 :     DOUBLE_getitem, DOUBLE_setitem,
656 :     PyArray_DOUBLE, sizeof(double), NULL, NULL, 'd'};
657 :    
658 :    
659 :     static void CFLOAT_to_CHAR(float *ip, int ipstep, char *op, int opstep, int n)
660 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (char)*ip; }}
661 :    
662 :     static void CFLOAT_to_UBYTE(float *ip, int ipstep, unsigned char *op, int opstep, int n)
663 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (unsigned char)*ip; }}
664 :    
665 :     static void CFLOAT_to_SBYTE(float *ip, int ipstep, signed char *op, int opstep, int n)
666 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (signed char)*ip; }}
667 :    
668 :     static void CFLOAT_to_SHORT(float *ip, int ipstep, short *op, int opstep, int n)
669 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (short)*ip; }}
670 :    
671 :     static void CFLOAT_to_USHORT(float *ip, int ipstep, unsigned short *op, int opstep, int n)
672 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (unsigned short)*ip; }}
673 :    
674 :     static void CFLOAT_to_INT(float *ip, int ipstep, int *op, int opstep, int n)
675 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (int)*ip; }}
676 :    
677 :     static void CFLOAT_to_UINT(float *ip, int ipstep, unsigned int *op, int opstep, int n)
678 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (unsigned int)*ip; }}
679 :    
680 :     static void CFLOAT_to_LONG(float *ip, int ipstep, long *op, int opstep, int n)
681 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (long)*ip; }}
682 :    
683 :     static void CFLOAT_to_FLOAT(float *ip, int ipstep, float *op, int opstep, int n)
684 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (float)*ip; }}
685 :    
686 :     static void CFLOAT_to_DOUBLE(float *ip, int ipstep, double *op, int opstep, int n)
687 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (double)*ip; }}
688 :    
689 :     static void CFLOAT_to_CFLOAT(float *ip, int ipstep, float *op, int opstep, int n)
690 :     {int i; for(i=0;i<2*n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
691 :    
692 :     static void CFLOAT_to_CDOUBLE(float *ip, int ipstep, double *op, int opstep, int n)
693 :     {int i; for(i=0;i<2*n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
694 :    
695 :     static void CFLOAT_to_OBJECT(float *ip, int ipstep, PyObject **op, int opstep, int n)
696 :     {int i; for(i=0;i<n;i++,ip+=2*ipstep,op+=opstep) {op[0] = PyComplex_FromDoubles((double)((float *)ip)[0], (double)((float *)ip)[1]);}}
697 :    
698 :     static PyObject * CFLOAT_getitem(char *ip) {return PyComplex_FromDoubles((double)((float *)ip)[0], (double)((float *)ip)[1]);}
699 :    
700 :     static int CFLOAT_setitem(PyObject *op, char *ov)
701 :     {
702 :     Py_complex oop;
703 :     PyObject *op2;
704 :     if PyScalarArray_Check(op) op2 = ((PyArrayObject *)op)->descr->getitem(((PyArrayObject *)op)->data);
705 :     else { op2 = op; Py_INCREF(op);}
706 :     oop = PyComplex_AsCComplex (op2);
707 :     Py_DECREF(op2);
708 :     if (PyErr_Occurred()) return -1;
709 :     ((float *)ov)[0]= (float) oop.real;
710 :     ((float *)ov)[1]= (float) oop.imag;
711 :     return 0;
712 :     }
713 :    
714 :     static PyArray_Descr CFLOAT_Descr = { {
715 :    
716 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_CHAR,
717 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_UBYTE,
718 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_SBYTE,
719 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_SHORT,
720 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_USHORT,
721 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_INT,
722 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_UINT,
723 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_LONG,
724 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_FLOAT,
725 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_DOUBLE,
726 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_CFLOAT,
727 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_CDOUBLE,
728 :     (PyArray_VectorUnaryFunc*)CFLOAT_to_OBJECT,
729 :     },
730 :     CFLOAT_getitem, CFLOAT_setitem,
731 :     PyArray_CFLOAT, 2*sizeof(float), NULL, NULL, 'F'};
732 :    
733 :    
734 :     static void CDOUBLE_to_CHAR(double *ip, int ipstep, char *op, int opstep, int n)
735 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (char)*ip; }}
736 :    
737 :     static void CDOUBLE_to_UBYTE(double *ip, int ipstep, unsigned char *op, int opstep, int n)
738 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (unsigned char)*ip; }}
739 :    
740 :     static void CDOUBLE_to_SBYTE(double *ip, int ipstep, signed char *op, int opstep, int n)
741 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (signed char)*ip; }}
742 :    
743 :     static void CDOUBLE_to_SHORT(double *ip, int ipstep, short *op, int opstep, int n)
744 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (short)*ip; }}
745 :    
746 :     static void CDOUBLE_to_USHORT(double *ip, int ipstep, unsigned short *op, int opstep, int n)
747 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (unsigned short)*ip; }}
748 :    
749 :     static void CDOUBLE_to_INT(double *ip, int ipstep, int *op, int opstep, int n)
750 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (int)*ip; }}
751 :    
752 :     static void CDOUBLE_to_UINT(double *ip, int ipstep, unsigned int *op, int opstep, int n)
753 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (unsigned int)*ip; }}
754 :    
755 :     static void CDOUBLE_to_LONG(double *ip, int ipstep, long *op, int opstep, int n)
756 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (long)*ip; }}
757 :    
758 :     static void CDOUBLE_to_FLOAT(double *ip, int ipstep, float *op, int opstep, int n)
759 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (float)*ip; }}
760 :    
761 :     static void CDOUBLE_to_DOUBLE(double *ip, int ipstep, double *op, int opstep, int n)
762 :     {int i; for(i=0;i<n;i++,ip+=ipstep*2,op+=opstep) {*op = (double)*ip; }}
763 :    
764 :     static void CDOUBLE_to_CFLOAT(double *ip, int ipstep, float *op, int opstep, int n)
765 :     {int i; for(i=0;i<2*n;i++,ip+=ipstep,op+=opstep) {*op = (float)*ip;}}
766 :    
767 :     static void CDOUBLE_to_CDOUBLE(double *ip, int ipstep, double *op, int opstep, int n)
768 :     {int i; for(i=0;i<2*n;i++,ip+=ipstep,op+=opstep) {*op = (double)*ip;}}
769 :    
770 :     static void CDOUBLE_to_OBJECT(double *ip, int ipstep, PyObject **op, int opstep, int n)
771 :     {int i; for(i=0;i<n;i++,ip+=2*ipstep,op+=opstep) {op[0] = PyComplex_FromDoubles((double)((double *)ip)[0], (double)((double *)ip)[1]);}}
772 :    
773 :     static PyObject * CDOUBLE_getitem(char *ip) {return PyComplex_FromDoubles((double)((double *)ip)[0], (double)((double *)ip)[1]);}
774 :    
775 :     static int CDOUBLE_setitem(PyObject *op, char *ov) {
776 :     Py_complex oop;
777 :     PyObject *op2;
778 :     if PyScalarArray_Check(op) op2 = ((PyArrayObject *)op)->descr->getitem(((PyArrayObject *)op)->data);
779 :     else { op2 = op; Py_INCREF(op);}
780 :     oop = PyComplex_AsCComplex (op2);
781 :     Py_DECREF(op2);
782 :     if (PyErr_Occurred()) return -1;
783 :     ((double *)ov)[0]= (double) oop.real;
784 :     ((double *)ov)[1]= (double) oop.imag;
785 :     return 0;
786 :     }
787 :    
788 :     static PyArray_Descr CDOUBLE_Descr = { {
789 :    
790 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_CHAR,
791 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_UBYTE,
792 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_SBYTE,
793 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_SHORT,
794 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_USHORT,
795 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_INT,
796 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_UINT,
797 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_LONG,
798 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_FLOAT,
799 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_DOUBLE,
800 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_CFLOAT,
801 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_CDOUBLE,
802 :     (PyArray_VectorUnaryFunc*)CDOUBLE_to_OBJECT,
803 :     },
804 :     CDOUBLE_getitem, CDOUBLE_setitem,
805 :     PyArray_CDOUBLE, 2*sizeof(double), NULL, NULL, 'D'};
806 :    
807 :    
808 :     static PyObject * OBJECT_getitem(char *ip) {return Py_INCREF(*(PyObject **)ip), *(PyObject **)ip;}
809 :    
810 :     static int OBJECT_setitem(PyObject *op, char *ov) {if (*(PyObject **)ov != NULL) {Py_DECREF(*(PyObject **)ov);} Py_INCREF(op); *(PyObject **)ov = op;return PyErr_Occurred() ? -1:0;}
811 :    
812 :     static PyArray_Descr OBJECT_Descr = { {
813 :    
814 :     (PyArray_VectorUnaryFunc*)NULL,
815 :     (PyArray_VectorUnaryFunc*)NULL,
816 :     (PyArray_VectorUnaryFunc*)NULL,
817 :     (PyArray_VectorUnaryFunc*)NULL,
818 :     (PyArray_VectorUnaryFunc*)NULL,
819 :     (PyArray_VectorUnaryFunc*)NULL,
820 :     (PyArray_VectorUnaryFunc*)NULL,
821 :     (PyArray_VectorUnaryFunc*)NULL,
822 :     (PyArray_VectorUnaryFunc*)NULL,
823 :     (PyArray_VectorUnaryFunc*)NULL,
824 :     (PyArray_VectorUnaryFunc*)NULL,
825 :     (PyArray_VectorUnaryFunc*)NULL,
826 :     },
827 :     OBJECT_getitem, OBJECT_setitem,
828 :     PyArray_OBJECT, sizeof(PyObject*), NULL, NULL, 'O'};
829 :    
830 :    
831 :     static PyArray_Descr *descrs[] = {
832 :     &CHAR_Descr,
833 :     &UBYTE_Descr,
834 :     &SBYTE_Descr,
835 :     &SHORT_Descr,
836 :     &USHORT_Descr,
837 :     &INT_Descr,
838 :     &UINT_Descr,
839 :     &LONG_Descr,
840 :     &FLOAT_Descr,
841 :     &DOUBLE_Descr,
842 :     &CFLOAT_Descr,
843 :     &CDOUBLE_Descr,
844 :     &OBJECT_Descr,
845 :     };
846 :    
847 :     PyArray_Descr *PyArray_DescrFromType(int type) {
848 :     if (type < PyArray_NTYPES) {
849 :     return descrs[type];
850 :     } else {
851 :     switch(type) {
852 :     case 'c': return descrs[PyArray_CHAR];
853 :     case 'b': return descrs[PyArray_UBYTE];
854 :     case '1': return descrs[PyArray_SBYTE];
855 :     case 's': return descrs[PyArray_SHORT];
856 :     case 'w': return descrs[PyArray_USHORT];
857 :     case 'i': return descrs[PyArray_INT];
858 :     case 'u': return descrs[PyArray_UINT];
859 :     case 'l': return descrs[PyArray_LONG];
860 :     case 'f': return descrs[PyArray_FLOAT];
861 :     case 'd': return descrs[PyArray_DOUBLE];
862 :     case 'F': return descrs[PyArray_CFLOAT];
863 :     case 'D': return descrs[PyArray_CDOUBLE];
864 :     case 'O': return descrs[PyArray_OBJECT];
865 :    
866 :     default:
867 :     PyErr_SetString(PyExc_ValueError, "Invalid type for array");
868 :     return NULL;
869 :     }
870 :     }
871 :     }
872 :    
873 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3