NUMPY_API * correlate(a1,a2,mode) * * This function computes the usual correlation (correlate(a1, a2) != * correlate(a2, a1), and conjugate the second argument for complex inputs */
| 1387 | * correlate(a2, a1), and conjugate the second argument for complex inputs |
| 1388 | */ |
| 1389 | NPY_NO_EXPORT PyObject * |
| 1390 | PyArray_Correlate2(PyObject *op1, PyObject *op2, int mode) |
| 1391 | { |
| 1392 | PyArrayObject *ap1, *ap2, *ret = NULL; |
| 1393 | int typenum; |
| 1394 | PyArray_Descr *typec; |
| 1395 | int inverted; |
| 1396 | int st; |
| 1397 | |
| 1398 | typenum = PyArray_ObjectType(op1, NPY_NOTYPE); |
| 1399 | if (typenum == NPY_NOTYPE) { |
| 1400 | return NULL; |
| 1401 | } |
| 1402 | typenum = PyArray_ObjectType(op2, typenum); |
| 1403 | if (typenum == NPY_NOTYPE) { |
| 1404 | return NULL; |
| 1405 | } |
| 1406 | |
| 1407 | typec = PyArray_DescrFromType(typenum); |
| 1408 | Py_INCREF(typec); |
| 1409 | ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 1, 1, |
| 1410 | NPY_ARRAY_DEFAULT, NULL); |
| 1411 | if (ap1 == NULL) { |
| 1412 | Py_DECREF(typec); |
| 1413 | return NULL; |
| 1414 | } |
| 1415 | ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 1, 1, |
| 1416 | NPY_ARRAY_DEFAULT, NULL); |
| 1417 | if (ap2 == NULL) { |
| 1418 | goto clean_ap1; |
| 1419 | } |
| 1420 | |
| 1421 | if (PyArray_ISCOMPLEX(ap2)) { |
| 1422 | PyArrayObject *cap2; |
| 1423 | cap2 = (PyArrayObject *)PyArray_Conjugate(ap2, NULL); |
| 1424 | if (cap2 == NULL) { |
| 1425 | goto clean_ap2; |
| 1426 | } |
| 1427 | Py_DECREF(ap2); |
| 1428 | ap2 = cap2; |
| 1429 | } |
| 1430 | |
| 1431 | ret = _pyarray_correlate(ap1, ap2, typenum, mode, &inverted); |
| 1432 | if (ret == NULL) { |
| 1433 | goto clean_ap2; |
| 1434 | } |
| 1435 | |
| 1436 | /* |
| 1437 | * If we inverted input orders, we need to reverse the output array (i.e. |
| 1438 | * ret = ret[::-1]) |
| 1439 | */ |
| 1440 | if (inverted) { |
| 1441 | st = _pyarray_revert(ret); |
| 1442 | if (st) { |
| 1443 | goto clean_ret; |
| 1444 | } |
| 1445 | } |
| 1446 |
no test coverage detected