| File: | /tmp/pyrefcon/scipy/scipy/signal/splinemodule.c | 
| Warning: | line 558, column 9 PyObject ownership leak with reference count of 1  | 
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | #include "Python.h" | |||
| 2 | #include "numpy/arrayobject.h" | |||
| 3 | #include <math.h> | |||
| 4 | ||||
| 5 | ||||
| 6 | #define PYERR(message)do {PyErr_SetString(PyExc_ValueError, message); goto fail;} while (0) do {PyErr_SetString(PyExc_ValueError, message); goto fail;} while(0)  | |||
| 7 | ||||
| 8 | static void convert_strides(npy_intp*,npy_intp*,int,int); | |||
| 9 | ||||
| 10 | extern int S_cubic_spline2D(float*,float*,int,int,double,npy_intp*,npy_intp*,float); | |||
| 11 | extern int S_quadratic_spline2D(float*,float*,int,int,double,npy_intp*,npy_intp*,float); | |||
| 12 | extern int S_IIR_forback1(float,float,float*,float*,int,int,int,float); | |||
| 13 | extern int S_IIR_forback2(double,double,float*,float*,int,int,int,float); | |||
| 14 | extern int S_separable_2Dconvolve_mirror(float*,float*,int,int,float*,float*,int,int,npy_intp*,npy_intp*); | |||
| 15 | ||||
| 16 | extern int D_cubic_spline2D(double*,double*,int,int,double,npy_intp*,npy_intp*,double); | |||
| 17 | extern int D_quadratic_spline2D(double*,double*,int,int,double,npy_intp*,npy_intp*,double); | |||
| 18 | extern int D_IIR_forback1(double,double,double*,double*,int,int,int,double); | |||
| 19 | extern int D_IIR_forback2(double,double,double*,double*,int,int,int,double); | |||
| 20 | extern int D_separable_2Dconvolve_mirror(double*,double*,int,int,double*,double*,int,int,npy_intp*,npy_intp*); | |||
| 21 | ||||
| 22 | #ifdef __GNUC__4 | |||
| 23 | extern int C_IIR_forback1(__complex__ float,__complex__ float,__complex__ float*,__complex__ float*,int,int,int,float); | |||
| 24 | extern int C_separable_2Dconvolve_mirror(__complex__ float*,__complex__ float*,int,int,__complex__ float*,__complex__ float*,int,int,npy_intp*,npy_intp*); | |||
| 25 | extern int Z_IIR_forback1(__complex__ double,__complex__ double,__complex__ double*,__complex__ double*,int,int,int,double); | |||
| 26 | extern int Z_separable_2Dconvolve_mirror(__complex__ double*,__complex__ double*,int,int,__complex__ double*,__complex__ double*,int,int,npy_intp*,npy_intp*); | |||
| 27 | #endif | |||
| 28 | ||||
| 29 | static void | |||
| 30 | convert_strides(npy_intp* instrides,npy_intp* convstrides,int size,int N) | |||
| 31 | { | |||
| 32 | int n; npy_intp bitshift; | |||
| 33 | ||||
| 34 | bitshift = -1; | |||
| 35 | ||||
| 36 | while (size != 0) { | |||
| 37 | size >>= 1; | |||
| 38 | bitshift++; | |||
| 39 | } | |||
| 40 | for (n = 0; n < N; n++) { | |||
| 41 | convstrides[n] = instrides[n] >> bitshift; | |||
| 42 | } | |||
| 43 | } | |||
| 44 | ||||
| 45 | ||||
| 46 | static char doc_cspline2d[] = "out = cspline2d(input, lambda=0.0, precision=-1.0)\n" | |||
| 47 | "\n" | |||
| 48 | " Coefficients for 2-D cubic (3rd order) B-spline.\n" | |||
| 49 | "\n" | |||
| 50 | " Return the third-order B-spline coefficients over a regularly spaced\n" | |||
| 51 | " input grid for the two-dimensional input image.\n" | |||
| 52 | "\n" | |||
| 53 | " Parameters\n" | |||
| 54 | " ----------\n" | |||
| 55 | " input : ndarray\n" | |||
| 56 | " The input signal.\n" | |||
| 57 | " lambda : float\n" | |||
| 58 | " Specifies the amount of smoothing in the transfer function.\n" | |||
| 59 | " precision : float\n" | |||
| 60 | " Specifies the precision for computing the infinite sum needed to apply mirror-\n" | |||
| 61 | " symmetric boundary conditions.\n" | |||
| 62 | "\n" | |||
| 63 | " Returns\n" | |||
| 64 | " -------\n" | |||
| 65 | " output : ndarray\n" | |||
| 66 | " The filtered signal.\n" | |||
| 67 | "\n" | |||
| 68 | " Examples\n" | |||
| 69 | " --------\n" | |||
| 70 | " Examples are given :ref:`in the tutorial <tutorial-signal-bsplines>`.\n" | |||
| 71 | "\n"; | |||
| 72 | ||||
| 73 | ||||
| 74 | static PyObject *cspline2d(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args) | |||
| 75 | { | |||
| 76 | PyObject *image=NULL((void*)0); | |||
| 77 | PyArrayObject *a_image=NULL((void*)0), *ck=NULL((void*)0); | |||
| 78 | double lambda = 0.0; | |||
| 79 | double precision = -1.0; | |||
| 80 | int thetype, M, N, retval=0; | |||
| 81 | npy_intp outstrides[2], instrides[2]; | |||
| 82 | ||||
| 83 | if (!PyArg_ParseTuple(args, "O|dd", &image, &lambda, &precision)) return NULL((void*)0); | |||
| 84 | ||||
| 85 | thetype = PyArray_ObjectType(*(int (*)(PyObject *, int)) PyArray_API[54])(image, NPY_FLOAT); | |||
| 86 | thetype = PyArray_MIN(thetype, NPY_DOUBLE)(((thetype)<(NPY_DOUBLE))?(thetype):(NPY_DOUBLE)); | |||
| 87 |   a_image = (PyArrayObject *)PyArray_FromObject(image, thetype, 2, 2)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) PyArray_API[69])(image, (*(PyArray_Descr * (*)( int)) PyArray_API[45])(thetype), 2, 2, (0x0100 | 0x0400) | 0x0040 , ((void*)0));  | |||
| 88 | if (a_image == NULL((void*)0)) goto fail; | |||
| 89 | ||||
| 90 |   ck = (PyArrayObject *)PyArray_SimpleNew(2, PyArray_DIMS(a_image), thetype)(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) PyArray_API [93])(&(*(PyTypeObject *)PyArray_API[2]), 2, PyArray_DIMS (a_image), thetype, ((void*)0), ((void*)0), 0, 0, ((void*)0));  | |||
| 91 | if (ck == NULL((void*)0)) goto fail; | |||
| 92 | M = PyArray_DIMS(a_image)[0]; | |||
| 93 | N = PyArray_DIMS(a_image)[1]; | |||
| 94 | ||||
| 95 | convert_strides(PyArray_STRIDES(a_image), instrides, PyArray_ITEMSIZE(a_image), 2); | |||
| 96 | outstrides[0] = N; | |||
| 97 | outstrides[1] = 1; | |||
| 98 | ||||
| 99 | if (thetype == NPY_FLOAT) { | |||
| 100 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-3; | |||
| 101 | retval = S_cubic_spline2D((float *)PyArray_DATA(a_image), | |||
| 102 | (float *)PyArray_DATA(ck), | |||
| 103 | M, N, lambda, instrides, outstrides, precision); | |||
| 104 | } | |||
| 105 | else if (thetype == NPY_DOUBLE) { | |||
| 106 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-6; | |||
| 107 | retval = D_cubic_spline2D((double *)PyArray_DATA(a_image), | |||
| 108 | (double *)PyArray_DATA(ck), | |||
| 109 | M, N, lambda, instrides, outstrides, precision); | |||
| 110 | } | |||
| 111 | ||||
| 112 |   if (retval == -3) PYERR("Precision too high.  Error did not converge.")do {PyErr_SetString(PyExc_ValueError, "Precision too high.  Error did not converge." ); goto fail;} while(0);  | |||
| 113 |   if (retval < 0) PYERR("Problem occurred inside routine")do {PyErr_SetString(PyExc_ValueError, "Problem occurred inside routine" ); goto fail;} while(0);  | |||
| 114 | ||||
| 115 | Py_DECREF(a_image)_Py_DECREF(((PyObject*)(a_image))); | |||
| 116 | return PyArray_Return(*(PyObject * (*)(PyArrayObject *)) PyArray_API[76])(ck); | |||
| 117 | ||||
| 118 | fail: | |||
| 119 | Py_XDECREF(a_image)_Py_XDECREF(((PyObject*)(a_image))); | |||
| 120 | Py_XDECREF(ck)_Py_XDECREF(((PyObject*)(ck))); | |||
| 121 | return NULL((void*)0); | |||
| 122 | ||||
| 123 | } | |||
| 124 | ||||
| 125 | static char doc_qspline2d[] = "out = qspline2d(input, lambda=0.0, precision=-1.0)\n" | |||
| 126 | "\n" | |||
| 127 | " Coefficients for 2-D quadratic (2nd order) B-spline:\n" | |||
| 128 | "\n" | |||
| 129 | " Return the second-order B-spline coefficients over a regularly spaced\n" | |||
| 130 | " input grid for the two-dimensional input image.\n" | |||
| 131 | "\n" | |||
| 132 | " Parameters\n" | |||
| 133 | " ----------\n" | |||
| 134 | " input : ndarray\n" | |||
| 135 | " The input signal.\n" | |||
| 136 | " lambda : float\n" | |||
| 137 | " Specifies the amount of smoothing in the transfer function.\n" | |||
| 138 | " precision : float\n" | |||
| 139 | " Specifies the precision for computing the infinite sum needed to apply mirror-\n" | |||
| 140 | " symmetric boundary conditions.\n" | |||
| 141 | "\n" | |||
| 142 | " Returns\n" | |||
| 143 | " -------\n" | |||
| 144 | " output : ndarray\n" | |||
| 145 | " The filtered signal.\n" | |||
| 146 | "\n" | |||
| 147 | " Examples\n" | |||
| 148 | " --------\n" | |||
| 149 | " Examples are given :ref:`in the tutorial <tutorial-signal-bsplines>`.\n" | |||
| 150 | "\n"; | |||
| 151 | ||||
| 152 | static PyObject *qspline2d(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args) | |||
| 153 | { | |||
| 154 | PyObject *image=NULL((void*)0); | |||
| 155 | PyArrayObject *a_image=NULL((void*)0), *ck=NULL((void*)0); | |||
| 156 | double lambda = 0.0; | |||
| 157 | double precision = -1.0; | |||
| 158 | int thetype, M, N, retval=0; | |||
| 159 | npy_intp outstrides[2], instrides[2]; | |||
| 160 | ||||
| 161 | if (!PyArg_ParseTuple(args, "O|dd", &image, &lambda, &precision)) return NULL((void*)0); | |||
| 162 | ||||
| 163 |   if (lambda != 0.0) PYERR("Smoothing spline not yet implemented.")do {PyErr_SetString(PyExc_ValueError, "Smoothing spline not yet implemented." ); goto fail;} while(0);  | |||
| 164 | ||||
| 165 | thetype = PyArray_ObjectType(*(int (*)(PyObject *, int)) PyArray_API[54])(image, NPY_FLOAT); | |||
| 166 | thetype = PyArray_MIN(thetype, NPY_DOUBLE)(((thetype)<(NPY_DOUBLE))?(thetype):(NPY_DOUBLE)); | |||
| 167 |   a_image = (PyArrayObject *)PyArray_FromObject(image, thetype, 2, 2)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) PyArray_API[69])(image, (*(PyArray_Descr * (*)( int)) PyArray_API[45])(thetype), 2, 2, (0x0100 | 0x0400) | 0x0040 , ((void*)0));  | |||
| 168 | if (a_image == NULL((void*)0)) goto fail; | |||
| 169 | ||||
| 170 |   ck = (PyArrayObject *)PyArray_SimpleNew(2, PyArray_DIMS(a_image), thetype)(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) PyArray_API [93])(&(*(PyTypeObject *)PyArray_API[2]), 2, PyArray_DIMS (a_image), thetype, ((void*)0), ((void*)0), 0, 0, ((void*)0));  | |||
| 171 | if (ck == NULL((void*)0)) goto fail; | |||
| 172 | M = PyArray_DIMS(a_image)[0]; | |||
| 173 | N = PyArray_DIMS(a_image)[1]; | |||
| 174 | ||||
| 175 | convert_strides(PyArray_STRIDES(a_image), instrides, PyArray_ITEMSIZE(a_image), 2); | |||
| 176 | outstrides[0] = N; | |||
| 177 | outstrides[1] = 1; | |||
| 178 | ||||
| 179 | if (thetype == NPY_FLOAT) { | |||
| 180 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-3; | |||
| 181 | retval = S_quadratic_spline2D((float *)PyArray_DATA(a_image), | |||
| 182 | (float *)PyArray_DATA(ck), | |||
| 183 | M, N, lambda, instrides, outstrides, precision); | |||
| 184 | } | |||
| 185 | else if (thetype == NPY_DOUBLE) { | |||
| 186 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-6; | |||
| 187 | retval = D_quadratic_spline2D((double *)PyArray_DATA(a_image), | |||
| 188 | (double *)PyArray_DATA(ck), | |||
| 189 | M, N, lambda, instrides, outstrides, precision); | |||
| 190 | } | |||
| 191 | ||||
| 192 |   if (retval == -3) PYERR("Precision too high.  Error did not converge.")do {PyErr_SetString(PyExc_ValueError, "Precision too high.  Error did not converge." ); goto fail;} while(0);  | |||
| 193 |   if (retval < 0) PYERR("Problem occurred inside routine")do {PyErr_SetString(PyExc_ValueError, "Problem occurred inside routine" ); goto fail;} while(0);  | |||
| 194 | ||||
| 195 | Py_DECREF(a_image)_Py_DECREF(((PyObject*)(a_image))); | |||
| 196 | return PyArray_Return(*(PyObject * (*)(PyArrayObject *)) PyArray_API[76])(ck); | |||
| 197 | ||||
| 198 | fail: | |||
| 199 | Py_XDECREF(a_image)_Py_XDECREF(((PyObject*)(a_image))); | |||
| 200 | Py_XDECREF(ck)_Py_XDECREF(((PyObject*)(ck))); | |||
| 201 | return NULL((void*)0); | |||
| 202 | ||||
| 203 | } | |||
| 204 | ||||
| 205 | static char doc_FIRsepsym2d[] = "out = sepfir2d(input, hrow, hcol)\n" | |||
| 206 | "\n" | |||
| 207 | " Convolve with a 2-D separable FIR filter.\n" | |||
| 208 | "\n" | |||
| 209 | " Convolve the rank-2 input array with the separable filter defined by the\n" | |||
| 210 | " rank-1 arrays hrow, and hcol. Mirror symmetric boundary conditions are\n" | |||
| 211 | " assumed. This function can be used to find an image given its B-spline\n" | |||
| 212 | " representation.\n" | |||
| 213 | "\n" | |||
| 214 | " Parameters\n" | |||
| 215 | " ----------\n" | |||
| 216 | " input : ndarray\n" | |||
| 217 | " The input signal. Must be a rank-2 array.\n" | |||
| 218 | " hrow : ndarray\n" | |||
| 219 | " A rank-1 array defining the row direction of the filter.\n" | |||
| 220 | " Must be odd-length\n" | |||
| 221 | " hcol : ndarray\n" | |||
| 222 | " A rank-1 array defining the column direction of the filter.\n" | |||
| 223 | " Must be odd-length\n" | |||
| 224 | "\n" | |||
| 225 | " Returns\n" | |||
| 226 | " -------\n" | |||
| 227 | " output : ndarray\n" | |||
| 228 | " The filtered signal.\n" | |||
| 229 | "\n" | |||
| 230 | " Examples\n" | |||
| 231 | " --------\n" | |||
| 232 | " Examples are given :ref:`in the tutorial <tutorial-signal-bsplines>`.\n" | |||
| 233 | "\n"; | |||
| 234 | ||||
| 235 | static PyObject *FIRsepsym2d(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args) | |||
| 236 | { | |||
| 237 | PyObject *image=NULL((void*)0), *hrow=NULL((void*)0), *hcol=NULL((void*)0); | |||
| 238 | PyArrayObject *a_image=NULL((void*)0), *a_hrow=NULL((void*)0), *a_hcol=NULL((void*)0), *out=NULL((void*)0); | |||
| 239 | int thetype, M, N, ret; | |||
| 240 | npy_intp outstrides[2], instrides[2]; | |||
| 241 | ||||
| 242 | if (!PyArg_ParseTuple(args, "OOO", &image, &hrow, &hcol)) return NULL((void*)0); | |||
| 243 | ||||
| 244 | thetype = PyArray_ObjectType(*(int (*)(PyObject *, int)) PyArray_API[54])(image, NPY_FLOAT); | |||
| 245 | thetype = PyArray_MIN(thetype, NPY_CDOUBLE)(((thetype)<(NPY_CDOUBLE))?(thetype):(NPY_CDOUBLE)); | |||
| 246 |   a_image = (PyArrayObject *)PyArray_FromObject(image, thetype, 2, 2)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) PyArray_API[69])(image, (*(PyArray_Descr * (*)( int)) PyArray_API[45])(thetype), 2, 2, (0x0100 | 0x0400) | 0x0040 , ((void*)0));  | |||
| 247 | if (a_image == NULL((void*)0)) goto fail; | |||
| 248 | ||||
| 249 |   a_hrow = (PyArrayObject *)PyArray_ContiguousFromObject(hrow, thetype, 1, 1)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) PyArray_API[69])(hrow, (*(PyArray_Descr * (*)(int )) PyArray_API[45])(thetype), 1, 1, ((0x0001 | (0x0100 | 0x0400 ))) | 0x0040, ((void*)0));  | |||
| 250 | if (a_hrow == NULL((void*)0)) goto fail; | |||
| 251 | ||||
| 252 |   a_hcol = (PyArrayObject *)PyArray_ContiguousFromObject(hcol, thetype, 1, 1)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) PyArray_API[69])(hcol, (*(PyArray_Descr * (*)(int )) PyArray_API[45])(thetype), 1, 1, ((0x0001 | (0x0100 | 0x0400 ))) | 0x0040, ((void*)0));  | |||
| 253 | if (a_hcol == NULL((void*)0)) goto fail; | |||
| 254 | ||||
| 255 |   out = (PyArrayObject *)PyArray_SimpleNew(2, PyArray_DIMS(a_image), thetype)(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) PyArray_API [93])(&(*(PyTypeObject *)PyArray_API[2]), 2, PyArray_DIMS (a_image), thetype, ((void*)0), ((void*)0), 0, 0, ((void*)0));  | |||
| 256 | if (out == NULL((void*)0)) goto fail; | |||
| 257 | ||||
| 258 | M = PyArray_DIMS(a_image)[0]; | |||
| 259 | N = PyArray_DIMS(a_image)[1]; | |||
| 260 | ||||
| 261 | convert_strides(PyArray_STRIDES(a_image), instrides, PyArray_ITEMSIZE(a_image), 2); | |||
| 262 | outstrides[0] = N; | |||
| 263 | outstrides[1] = 1; | |||
| 264 | ||||
| 265 | if (PyArray_DIMS(a_hrow)[0] % 2 != 1 || | |||
| 266 | PyArray_DIMS(a_hcol)[0] % 2 != 1) { | |||
| 267 |     PYERR("hrow and hcol must be odd length")do {PyErr_SetString(PyExc_ValueError, "hrow and hcol must be odd length" ); goto fail;} while(0);  | |||
| 268 | } | |||
| 269 | ||||
| 270 | switch (thetype) { | |||
| 271 | case NPY_FLOAT: | |||
| 272 | ret = S_separable_2Dconvolve_mirror((float *)PyArray_DATA(a_image), | |||
| 273 | (float *)PyArray_DATA(out), M, N, | |||
| 274 | (float *)PyArray_DATA(a_hrow), | |||
| 275 | (float *)PyArray_DATA(a_hcol), | |||
| 276 | PyArray_DIMS(a_hrow)[0], PyArray_DIMS(a_hcol)[0], | |||
| 277 | instrides, outstrides); | |||
| 278 | break; | |||
| 279 | case NPY_DOUBLE: | |||
| 280 | ret = D_separable_2Dconvolve_mirror((double *)PyArray_DATA(a_image), | |||
| 281 | (double *)PyArray_DATA(out), M, N, | |||
| 282 | (double *)PyArray_DATA(a_hrow), | |||
| 283 | (double *)PyArray_DATA(a_hcol), | |||
| 284 | PyArray_DIMS(a_hrow)[0], PyArray_DIMS(a_hcol)[0], | |||
| 285 | instrides, outstrides); | |||
| 286 | break; | |||
| 287 | #ifdef __GNUC__4 | |||
| 288 | case NPY_CFLOAT: | |||
| 289 | ret = C_separable_2Dconvolve_mirror((__complex__ float *)PyArray_DATA(a_image), | |||
| 290 | (__complex__ float *)PyArray_DATA(out), M, N, | |||
| 291 | (__complex__ float *)PyArray_DATA(a_hrow), | |||
| 292 | (__complex__ float *)PyArray_DATA(a_hcol), | |||
| 293 | PyArray_DIMS(a_hrow)[0], PyArray_DIMS(a_hcol)[0], | |||
| 294 | instrides, outstrides); | |||
| 295 | break; | |||
| 296 | case NPY_CDOUBLE: | |||
| 297 | ret = Z_separable_2Dconvolve_mirror((__complex__ double *)PyArray_DATA(a_image), | |||
| 298 | (__complex__ double *)PyArray_DATA(out), M, N, | |||
| 299 | (__complex__ double *)PyArray_DATA(a_hrow), | |||
| 300 | (__complex__ double *)PyArray_DATA(a_hcol), | |||
| 301 | PyArray_DIMS(a_hrow)[0], PyArray_DIMS(a_hcol)[0], | |||
| 302 | instrides, outstrides); | |||
| 303 | break; | |||
| 304 | #endif | |||
| 305 | default: | |||
| 306 |     PYERR("Incorrect type.")do {PyErr_SetString(PyExc_ValueError, "Incorrect type."); goto fail;} while(0);  | |||
| 307 | } | |||
| 308 | ||||
| 309 |   if (ret < 0) PYERR("Problem occurred inside routine.")do {PyErr_SetString(PyExc_ValueError, "Problem occurred inside routine." ); goto fail;} while(0);  | |||
| 310 | ||||
| 311 | Py_DECREF(a_image)_Py_DECREF(((PyObject*)(a_image))); | |||
| 312 | Py_DECREF(a_hrow)_Py_DECREF(((PyObject*)(a_hrow))); | |||
| 313 | Py_DECREF(a_hcol)_Py_DECREF(((PyObject*)(a_hcol))); | |||
| 314 | return PyArray_Return(*(PyObject * (*)(PyArrayObject *)) PyArray_API[76])(out); | |||
| 315 | ||||
| 316 | fail: | |||
| 317 | Py_XDECREF(a_image)_Py_XDECREF(((PyObject*)(a_image))); | |||
| 318 | Py_XDECREF(a_hrow)_Py_XDECREF(((PyObject*)(a_hrow))); | |||
| 319 | Py_XDECREF(a_hcol)_Py_XDECREF(((PyObject*)(a_hcol))); | |||
| 320 | Py_XDECREF(out)_Py_XDECREF(((PyObject*)(out))); | |||
| 321 | return NULL((void*)0); | |||
| 322 | ||||
| 323 | } | |||
| 324 | ||||
| 325 | static char doc_IIRsymorder1[] = "out = symiirorder1(input, c0, z1, precision=-1.0)\n" | |||
| 326 | "\n" | |||
| 327 | " Implement a smoothing IIR filter with mirror-symmetric boundary conditions\n" | |||
| 328 | " using a cascade of first-order sections. The second section uses a\n" | |||
| 329 | " reversed sequence. This implements a system with the following\n" | |||
| 330 | " transfer function and mirror-symmetric boundary conditions::\n" | |||
| 331 | "\n" | |||
| 332 | " c0 \n" | |||
| 333 | " H(z) = --------------------- \n" | |||
| 334 | " (1-z1/z) (1 - z1 z) \n" | |||
| 335 | "\n" | |||
| 336 | " The resulting signal will have mirror symmetric boundary conditions as well.\n" | |||
| 337 | "\n" | |||
| 338 | " Parameters\n" | |||
| 339 | " ----------\n" | |||
| 340 | " input : ndarray\n" | |||
| 341 | " The input signal.\n" | |||
| 342 | " c0, z1 : scalar\n" | |||
| 343 | " Parameters in the transfer function.\n" | |||
| 344 | " precision :\n" | |||
| 345 | " Specifies the precision for calculating initial conditions\n" | |||
| 346 | " of the recursive filter based on mirror-symmetric input.\n" | |||
| 347 | "\n" | |||
| 348 | " Returns\n" | |||
| 349 | " -------\n" | |||
| 350 | " output : ndarray\n" | |||
| 351 | " The filtered signal."; | |||
| 352 | ||||
| 353 | static PyObject *IIRsymorder1(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args) | |||
| 354 | { | |||
| 355 | PyObject *sig=NULL((void*)0); | |||
| 356 | PyArrayObject *a_sig=NULL((void*)0), *out=NULL((void*)0); | |||
| 357 | Py_complex c0, z1; | |||
| 358 | double precision = -1.0; | |||
| 359 | int thetype, N, ret; | |||
| 360 | npy_intp outstrides, instrides; | |||
| 361 | ||||
| 362 | if (!PyArg_ParseTuple(args, "ODD|d", &sig, &c0, &z1, &precision)) | |||
| 363 | return NULL((void*)0); | |||
| 364 | ||||
| 365 | thetype = PyArray_ObjectType(*(int (*)(PyObject *, int)) PyArray_API[54])(sig, NPY_FLOAT); | |||
| 366 | thetype = PyArray_MIN(thetype, NPY_CDOUBLE)(((thetype)<(NPY_CDOUBLE))?(thetype):(NPY_CDOUBLE)); | |||
| 367 |   a_sig = (PyArrayObject *)PyArray_FromObject(sig, thetype, 1, 1)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) PyArray_API[69])(sig, (*(PyArray_Descr * (*)(int )) PyArray_API[45])(thetype), 1, 1, (0x0100 | 0x0400) | 0x0040 , ((void*)0));  | |||
| 368 | ||||
| 369 | if (a_sig == NULL((void*)0)) goto fail; | |||
| 370 | ||||
| 371 |   out = (PyArrayObject *)PyArray_SimpleNew(1, PyArray_DIMS(a_sig), thetype)(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) PyArray_API [93])(&(*(PyTypeObject *)PyArray_API[2]), 1, PyArray_DIMS (a_sig), thetype, ((void*)0), ((void*)0), 0, 0, ((void*)0));  | |||
| 372 | if (out == NULL((void*)0)) goto fail; | |||
| 373 | N = PyArray_DIMS(a_sig)[0]; | |||
| 374 | ||||
| 375 | convert_strides(PyArray_STRIDES(a_sig), &instrides, PyArray_ITEMSIZE(a_sig), 1); | |||
| 376 | outstrides = 1; | |||
| 377 | ||||
| 378 | switch (thetype) { | |||
| 379 | case NPY_FLOAT: | |||
| 380 | { | |||
| 381 | float rc0 = c0.real; | |||
| 382 | float rz1 = z1.real; | |||
| 383 | ||||
| 384 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-6; | |||
| 385 | ret = S_IIR_forback1 (rc0, rz1, (float *)PyArray_DATA(a_sig), | |||
| 386 | (float *)PyArray_DATA(out), N, | |||
| 387 | instrides, outstrides, (float )precision); | |||
| 388 | } | |||
| 389 | break; | |||
| 390 | case NPY_DOUBLE: | |||
| 391 | { | |||
| 392 | double rc0 = c0.real; | |||
| 393 | double rz1 = z1.real; | |||
| 394 | ||||
| 395 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-11; | |||
| 396 | ret = D_IIR_forback1 (rc0, rz1, (double *)PyArray_DATA(a_sig), | |||
| 397 | (double *)PyArray_DATA(out), N, | |||
| 398 | instrides, outstrides, precision); | |||
| 399 | } | |||
| 400 | break; | |||
| 401 | #ifdef __GNUC__4 | |||
| 402 | case NPY_CFLOAT: | |||
| 403 | { | |||
| 404 | __complex__ float zc0 = c0.real + 1.0i*c0.imag; | |||
| 405 | __complex__ float zz1 = z1.real + 1.0i*z1.imag; | |||
| 406 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-6; | |||
| 407 | ret = C_IIR_forback1 (zc0, zz1, (__complex__ float *)PyArray_DATA(a_sig), | |||
| 408 | (__complex__ float *)PyArray_DATA(out), N, | |||
| 409 | instrides, outstrides, (float )precision); | |||
| 410 | } | |||
| 411 | break; | |||
| 412 | case NPY_CDOUBLE: | |||
| 413 | { | |||
| 414 | __complex__ double zc0 = c0.real + 1.0i*c0.imag; | |||
| 415 | __complex__ double zz1 = z1.real + 1.0i*z1.imag; | |||
| 416 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-11; | |||
| 417 | ret = Z_IIR_forback1 (zc0, zz1, (__complex__ double *)PyArray_DATA(a_sig), | |||
| 418 | (__complex__ double *)PyArray_DATA(out), N, | |||
| 419 | instrides, outstrides, precision); | |||
| 420 | } | |||
| 421 | break; | |||
| 422 | #endif | |||
| 423 | default: | |||
| 424 |     PYERR("Incorrect type.")do {PyErr_SetString(PyExc_ValueError, "Incorrect type."); goto fail;} while(0);  | |||
| 425 | } | |||
| 426 | ||||
| 427 | if (ret == 0) { | |||
| 428 | Py_DECREF(a_sig)_Py_DECREF(((PyObject*)(a_sig))); | |||
| 429 | return PyArray_Return(*(PyObject * (*)(PyArrayObject *)) PyArray_API[76])(out); | |||
| 430 | } | |||
| 431 | ||||
| 432 |   if (ret == -1) PYERR("Could not allocate enough memory.")do {PyErr_SetString(PyExc_ValueError, "Could not allocate enough memory." ); goto fail;} while(0);  | |||
| 433 |   if (ret == -2) PYERR("|z1| must be less than 1.0")do {PyErr_SetString(PyExc_ValueError, "|z1| must be less than 1.0" ); goto fail;} while(0);  | |||
| 434 |   if (ret == -3) PYERR("Sum to find symmetric boundary conditions did not converge.")do {PyErr_SetString(PyExc_ValueError, "Sum to find symmetric boundary conditions did not converge." ); goto fail;} while(0);  | |||
| 435 | ||||
| 436 |   PYERR("Unknown error.")do {PyErr_SetString(PyExc_ValueError, "Unknown error."); goto fail;} while(0);  | |||
| 437 | ||||
| 438 | ||||
| 439 | fail: | |||
| 440 | Py_XDECREF(a_sig)_Py_XDECREF(((PyObject*)(a_sig))); | |||
| 441 | Py_XDECREF(out)_Py_XDECREF(((PyObject*)(out))); | |||
| 442 | return NULL((void*)0); | |||
| 443 | ||||
| 444 | } | |||
| 445 | ||||
| 446 | static char doc_IIRsymorder2[] = "out = symiirorder2(input, r, omega, precision=-1.0)\n" | |||
| 447 | "\n" | |||
| 448 | " Implement a smoothing IIR filter with mirror-symmetric boundary conditions\n" | |||
| 449 | " using a cascade of second-order sections. The second section uses a\n" | |||
| 450 | " reversed sequence. This implements the following transfer function::\n" | |||
| 451 | "\n" | |||
| 452 | " cs^2\n" | |||
| 453 | " H(z) = ---------------------------------------\n" | |||
| 454 | " (1 - a2/z - a3/z^2) (1 - a2 z - a3 z^2 )\n" | |||
| 455 | "\n" | |||
| 456 | " where::\n" | |||
| 457 | "\n" | |||
| 458 | " a2 = (2 r cos omega)\n" | |||
| 459 | " a3 = - r^2\n" | |||
| 460 | " cs = 1 - 2 r cos omega + r^2\n" | |||
| 461 | "\n" | |||
| 462 | " Parameters\n" | |||
| 463 | " ----------\n" | |||
| 464 | " input : ndarray\n" | |||
| 465 | " The input signal.\n" | |||
| 466 | " r, omega : float\n" | |||
| 467 | " Parameters in the transfer function.\n" | |||
| 468 | " precision : float\n" | |||
| 469 | " Specifies the precision for calculating initial conditions\n" | |||
| 470 | " of the recursive filter based on mirror-symmetric input.\n" | |||
| 471 | "\n" | |||
| 472 | " Returns\n" | |||
| 473 | " -------\n" | |||
| 474 | " output : ndarray\n" | |||
| 475 | " The filtered signal."; | |||
| 476 | ||||
| 477 | static PyObject *IIRsymorder2(PyObject *NPY_UNUSED(dummy)(__NPY_UNUSED_TAGGEDdummy) __attribute__ ((__unused__)), PyObject *args) | |||
| 478 | { | |||
| 479 | PyObject *sig=NULL((void*)0); | |||
| 480 | PyArrayObject *a_sig=NULL((void*)0), *out=NULL((void*)0); | |||
| 481 | double r, omega; | |||
| 482 | double precision = -1.0; | |||
| 483 | int thetype, N, ret; | |||
| 484 | npy_intp outstrides, instrides; | |||
| 485 | ||||
| 486 | if (!PyArg_ParseTuple(args, "Odd|d", &sig, &r, &omega, &precision)) | |||
| 487 | return NULL((void*)0); | |||
| 488 | ||||
| 489 | thetype = PyArray_ObjectType(*(int (*)(PyObject *, int)) PyArray_API[54])(sig, NPY_FLOAT); | |||
| 490 | thetype = PyArray_MIN(thetype, NPY_DOUBLE)(((thetype)<(NPY_DOUBLE))?(thetype):(NPY_DOUBLE)); | |||
| 491 |   a_sig = (PyArrayObject *)PyArray_FromObject(sig, thetype, 1, 1)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int, PyObject *)) PyArray_API[69])(sig, (*(PyArray_Descr * (*)(int )) PyArray_API[45])(thetype), 1, 1, (0x0100 | 0x0400) | 0x0040 , ((void*)0));  | |||
| 492 | ||||
| 493 | if (a_sig == NULL((void*)0)) goto fail; | |||
| 494 | ||||
| 495 |   out = (PyArrayObject *)PyArray_SimpleNew(1, PyArray_DIMS(a_sig), thetype)(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int, npy_intp const *, void *, int, int, PyObject *)) PyArray_API [93])(&(*(PyTypeObject *)PyArray_API[2]), 1, PyArray_DIMS (a_sig), thetype, ((void*)0), ((void*)0), 0, 0, ((void*)0));  | |||
| 496 | if (out == NULL((void*)0)) goto fail; | |||
| 497 | N = PyArray_DIMS(a_sig)[0]; | |||
| 498 | ||||
| 499 | convert_strides(PyArray_STRIDES(a_sig), &instrides, PyArray_ITEMSIZE(a_sig), 1); | |||
| 500 | outstrides = 1; | |||
| 501 | ||||
| 502 | switch (thetype) { | |||
| 503 | case NPY_FLOAT: | |||
| 504 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-6; | |||
| 505 | ret = S_IIR_forback2 (r, omega, (float *)PyArray_DATA(a_sig), | |||
| 506 | (float *)PyArray_DATA(out), N, | |||
| 507 | instrides, outstrides, precision); | |||
| 508 | break; | |||
| 509 | case NPY_DOUBLE: | |||
| 510 | if ((precision <= 0.0) || (precision > 1.0)) precision = 1e-11; | |||
| 511 | ret = D_IIR_forback2 (r, omega, (double *)PyArray_DATA(a_sig), | |||
| 512 | (double *)PyArray_DATA(out), N, | |||
| 513 | instrides, outstrides, precision); | |||
| 514 | break; | |||
| 515 | default: | |||
| 516 |     PYERR("Incorrect type.")do {PyErr_SetString(PyExc_ValueError, "Incorrect type."); goto fail;} while(0);  | |||
| 517 | } | |||
| 518 | ||||
| 519 |   if (ret < 0) PYERR("Problem occurred inside routine.")do {PyErr_SetString(PyExc_ValueError, "Problem occurred inside routine." ); goto fail;} while(0);  | |||
| 520 | ||||
| 521 | Py_DECREF(a_sig)_Py_DECREF(((PyObject*)(a_sig))); | |||
| 522 | return PyArray_Return(*(PyObject * (*)(PyArrayObject *)) PyArray_API[76])(out); | |||
| 523 | ||||
| 524 | fail: | |||
| 525 | Py_XDECREF(a_sig)_Py_XDECREF(((PyObject*)(a_sig))); | |||
| 526 | Py_XDECREF(out)_Py_XDECREF(((PyObject*)(out))); | |||
| 527 | return NULL((void*)0); | |||
| 528 | ||||
| 529 | } | |||
| 530 | ||||
| 531 | ||||
| 532 | static struct PyMethodDef toolbox_module_methods[] = { | |||
| 533 | {"cspline2d", cspline2d, METH_VARARGS0x0001, doc_cspline2d}, | |||
| 534 | {"qspline2d", qspline2d, METH_VARARGS0x0001, doc_qspline2d}, | |||
| 535 | {"sepfir2d", FIRsepsym2d, METH_VARARGS0x0001, doc_FIRsepsym2d}, | |||
| 536 | {"symiirorder1", IIRsymorder1, METH_VARARGS0x0001, doc_IIRsymorder1}, | |||
| 537 | {"symiirorder2", IIRsymorder2, METH_VARARGS0x0001, doc_IIRsymorder2}, | |||
| 538 | {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)} /* sentinel */ | |||
| 539 | }; | |||
| 540 | ||||
| 541 | /* Initialization function for the module */ | |||
| 542 | static struct PyModuleDef moduledef = { | |||
| 543 | PyModuleDef_HEAD_INIT{ { 1, ((void*)0) }, ((void*)0), 0, ((void*)0), }, | |||
| 544 | "spline", | |||
| 545 | NULL((void*)0), | |||
| 546 | -1, | |||
| 547 | toolbox_module_methods, | |||
| 548 | NULL((void*)0), | |||
| 549 | NULL((void*)0), | |||
| 550 | NULL((void*)0), | |||
| 551 | NULL((void*)0) | |||
| 552 | }; | |||
| 553 | ||||
| 554 | PyObject *PyInit_spline(void) | |||
| 555 | { | |||
| 556 | PyObject *m, *d, *s; | |||
| 557 | ||||
| 558 | m = PyModule_Create(&moduledef)PyModule_Create2(&moduledef, 1013); | |||
  | ||||
  | ||||
| 559 |     import_array(){if (_import_array() < 0) {PyErr_Print(); PyErr_SetString( PyExc_ImportError, "numpy.core.multiarray failed to import"); return ((void*)0); } };  | |||
| 560 | ||||
| 561 | /* Add some symbolic constants to the module */ | |||
| 562 | d = PyModule_GetDict(m); | |||
| 563 | ||||
| 564 | s = PyUnicode_FromString("0.2"); | |||
| 565 | PyDict_SetItemString(d, "__version__", s); | |||
| 566 | Py_DECREF(s)_Py_DECREF(((PyObject*)(s))); | |||
| 567 | ||||
| 568 | /* Check for errors */ | |||
| 569 | if (PyErr_Occurred()) { | |||
| 570 | Py_FatalError("can't initialize module array"); | |||
| 571 | } | |||
| 572 | return m; | |||
| 573 | } | 
| 1 | #ifndef PyModule_Create2 | 
| 2 | struct _object; | 
| 3 | typedef struct _object PyObject; | 
| 4 | PyObject* clang_analyzer_PyObject_New_Reference(); | 
| 5 | PyObject* PyModule_Create2(PyModuleDef *def, int module_api_version) { | 
| 6 | return clang_analyzer_PyObject_New_Reference(); | 
| 7 | } | 
| 8 | #else | 
| 9 | #warning "API PyModule_Create2 is defined as a macro." | 
| 10 | #endif |