MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_MatrixProduct2

Function PyArray_MatrixProduct2

numpy/core/src/multiarray/multiarraymodule.c:997–1152  ·  view source on GitHub ↗

NUMPY_API * Numeric.matrixproduct2(a,v,out) * just like inner product but does the swapaxes stuff on the fly */

Source from the content-addressed store, hash-verified

995 * just like inner product but does the swapaxes stuff on the fly
996 */
997NPY_NO_EXPORT PyObject *
998PyArray_MatrixProduct2(PyObject *op1, PyObject *op2, PyArrayObject* out)
999{
1000 PyArrayObject *ap1, *ap2, *out_buf = NULL, *result = NULL;
1001 PyArrayIterObject *it1, *it2;
1002 npy_intp i, j, l;
1003 int typenum, nd, axis, matchDim;
1004 npy_intp is1, is2, os;
1005 char *op;
1006 npy_intp dimensions[NPY_MAXDIMS];
1007 PyArray_DotFunc *dot;
1008 PyArray_Descr *typec = NULL;
1009 NPY_BEGIN_THREADS_DEF;
1010
1011 typenum = PyArray_ObjectType(op1, NPY_NOTYPE);
1012 if (typenum == NPY_NOTYPE) {
1013 return NULL;
1014 }
1015 typenum = PyArray_ObjectType(op2, typenum);
1016 if (typenum == NPY_NOTYPE) {
1017 return NULL;
1018 }
1019
1020 typec = PyArray_DescrFromType(typenum);
1021 if (typec == NULL) {
1022 if (!PyErr_Occurred()) {
1023 PyErr_SetString(PyExc_TypeError,
1024 "Cannot find a common data type.");
1025 }
1026 return NULL;
1027 }
1028
1029 Py_INCREF(typec);
1030 ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0,
1031 NPY_ARRAY_ALIGNED, NULL);
1032 if (ap1 == NULL) {
1033 Py_DECREF(typec);
1034 return NULL;
1035 }
1036 ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0,
1037 NPY_ARRAY_ALIGNED, NULL);
1038 if (ap2 == NULL) {
1039 Py_DECREF(ap1);
1040 return NULL;
1041 }
1042
1043#if defined(HAVE_CBLAS)
1044 if (PyArray_NDIM(ap1) <= 2 && PyArray_NDIM(ap2) <= 2 &&
1045 (NPY_DOUBLE == typenum || NPY_CDOUBLE == typenum ||
1046 NPY_FLOAT == typenum || NPY_CFLOAT == typenum)) {
1047 return cblas_matrixproduct(typenum, ap1, ap2, out);
1048 }
1049#endif
1050
1051 if (PyArray_NDIM(ap1) == 0 || PyArray_NDIM(ap2) == 0) {
1052 PyObject *mul_res = PyObject_CallFunctionObjArgs(
1053 n_ops.multiply, ap1, ap2, out, NULL);
1054 Py_DECREF(ap1);

Callers 4

array_dotFunction · 0.85
PyArray_InnerProductFunction · 0.85
PyArray_MatrixProductFunction · 0.85
array_matrixproductFunction · 0.85

Calls 14

PyArray_ObjectTypeFunction · 0.85
PyArray_FromAnyFunction · 0.85
PyArray_NDIMFunction · 0.85
cblas_matrixproductFunction · 0.85
PyArray_DIMSFunction · 0.85
dot_alignment_errorFunction · 0.85
PyArray_STRIDESFunction · 0.85
new_array_for_sumFunction · 0.85
PyArray_AssignZeroFunction · 0.85
PyArray_DESCRFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_IterAllButAxisFunction · 0.85

Tested by

no test coverage detected