NUMPY_API * Numeric.innerproduct(a,v) */
| 900 | * Numeric.innerproduct(a,v) |
| 901 | */ |
| 902 | NPY_NO_EXPORT PyObject * |
| 903 | PyArray_InnerProduct(PyObject *op1, PyObject *op2) |
| 904 | { |
| 905 | PyArrayObject *ap1 = NULL; |
| 906 | PyArrayObject *ap2 = NULL; |
| 907 | int typenum; |
| 908 | PyArray_Descr *typec = NULL; |
| 909 | PyObject* ap2t = NULL; |
| 910 | npy_intp dims[NPY_MAXDIMS]; |
| 911 | PyArray_Dims newaxes = {dims, 0}; |
| 912 | int i; |
| 913 | PyObject* ret = NULL; |
| 914 | |
| 915 | typenum = PyArray_ObjectType(op1, NPY_NOTYPE); |
| 916 | if (typenum == NPY_NOTYPE) { |
| 917 | return NULL; |
| 918 | } |
| 919 | typenum = PyArray_ObjectType(op2, typenum); |
| 920 | if (typenum == NPY_NOTYPE) { |
| 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | typec = PyArray_DescrFromType(typenum); |
| 925 | if (typec == NULL) { |
| 926 | if (!PyErr_Occurred()) { |
| 927 | PyErr_SetString(PyExc_TypeError, |
| 928 | "Cannot find a common data type."); |
| 929 | } |
| 930 | goto fail; |
| 931 | } |
| 932 | |
| 933 | Py_INCREF(typec); |
| 934 | ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, |
| 935 | NPY_ARRAY_ALIGNED, NULL); |
| 936 | if (ap1 == NULL) { |
| 937 | Py_DECREF(typec); |
| 938 | goto fail; |
| 939 | } |
| 940 | ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0, |
| 941 | NPY_ARRAY_ALIGNED, NULL); |
| 942 | if (ap2 == NULL) { |
| 943 | goto fail; |
| 944 | } |
| 945 | |
| 946 | newaxes.len = PyArray_NDIM(ap2); |
| 947 | if ((PyArray_NDIM(ap1) >= 1) && (newaxes.len >= 2)) { |
| 948 | for (i = 0; i < newaxes.len - 2; i++) { |
| 949 | dims[i] = (npy_intp)i; |
| 950 | } |
| 951 | dims[newaxes.len - 2] = newaxes.len - 1; |
| 952 | dims[newaxes.len - 1] = newaxes.len - 2; |
| 953 | |
| 954 | ap2t = PyArray_Transpose(ap2, &newaxes); |
| 955 | if (ap2t == NULL) { |
| 956 | goto fail; |
| 957 | } |
| 958 | } |
| 959 | else { |
no test coverage detected