* Implementation which is common between PyArray_Correlate * and PyArray_Correlate2. * * inverted is set to 1 if computed correlate(ap2, ap1), 0 otherwise */
| 1216 | * inverted is set to 1 if computed correlate(ap2, ap1), 0 otherwise |
| 1217 | */ |
| 1218 | static PyArrayObject* |
| 1219 | _pyarray_correlate(PyArrayObject *ap1, PyArrayObject *ap2, int typenum, |
| 1220 | int mode, int *inverted) |
| 1221 | { |
| 1222 | PyArrayObject *ret; |
| 1223 | npy_intp length; |
| 1224 | npy_intp i, n1, n2, n, n_left, n_right; |
| 1225 | npy_intp is1, is2, os; |
| 1226 | char *ip1, *ip2, *op; |
| 1227 | PyArray_DotFunc *dot; |
| 1228 | |
| 1229 | NPY_BEGIN_THREADS_DEF; |
| 1230 | |
| 1231 | n1 = PyArray_DIMS(ap1)[0]; |
| 1232 | n2 = PyArray_DIMS(ap2)[0]; |
| 1233 | if (n1 == 0) { |
| 1234 | PyErr_SetString(PyExc_ValueError, "first array argument cannot be empty"); |
| 1235 | return NULL; |
| 1236 | } |
| 1237 | if (n2 == 0) { |
| 1238 | PyErr_SetString(PyExc_ValueError, "second array argument cannot be empty"); |
| 1239 | return NULL; |
| 1240 | } |
| 1241 | if (n1 < n2) { |
| 1242 | ret = ap1; |
| 1243 | ap1 = ap2; |
| 1244 | ap2 = ret; |
| 1245 | ret = NULL; |
| 1246 | i = n1; |
| 1247 | n1 = n2; |
| 1248 | n2 = i; |
| 1249 | *inverted = 1; |
| 1250 | } else { |
| 1251 | *inverted = 0; |
| 1252 | } |
| 1253 | |
| 1254 | length = n1; |
| 1255 | n = n2; |
| 1256 | switch(mode) { |
| 1257 | case 0: |
| 1258 | length = length - n + 1; |
| 1259 | n_left = n_right = 0; |
| 1260 | break; |
| 1261 | case 1: |
| 1262 | n_left = (npy_intp)(n/2); |
| 1263 | n_right = n - n_left - 1; |
| 1264 | break; |
| 1265 | case 2: |
| 1266 | n_right = n - 1; |
| 1267 | n_left = n - 1; |
| 1268 | length = length + n - 1; |
| 1269 | break; |
| 1270 | default: |
| 1271 | PyErr_SetString(PyExc_ValueError, "mode must be 0, 1, or 2"); |
| 1272 | return NULL; |
| 1273 | } |
| 1274 | |
| 1275 | /* |
no test coverage detected