numpy  2.0.0
src/multiarray/cblasfuncs.h File Reference

Go to the source code of this file.

Functions

NPY_NO_EXPORT PyObject * cblas_matrixproduct (int, PyArrayObject *, PyArrayObject *, PyArrayObject *)

Function Documentation

NPY_NO_EXPORT PyObject* cblas_matrixproduct ( int  typenum,
PyArrayObject ap1,
PyArrayObject ap2,
PyArrayObject out 
)
dot(a,b) Returns the dot product of a and b for arrays of floating point types. Like the generic numpy equivalent the product sum is over the last dimension of a and the second-to-last dimension of b. NB: The first argument is not conjugated.;
This is for use by PyArray_MatrixProduct2. It is assumed on entry that the arrays ap1 and ap2 have a common data type given by typenum that is float, double, cfloat, or cdouble and have dimension <= 2. The __numpy_ufunc__ nonsense is also assumed to have been taken care of.
One of ap1 or ap2 is a scalar
Make ap2 the scalar
nd = 0 or 1 or 2. If nd == 0 do nothing ...
Either PyArray_NDIM(ap1) is 1 dim or PyArray_NDIM(ap2) is 1 dim and the other is 2 dim
Fix it so that dot(shape=(N,1), shape=(1,)) and dot(shape=(1,), shape=(1,N)) both return an (N,) array (but use the fast scalar code)
We need to make sure that dot(shape=(1,1), shape=(1,N)) and dot(shape=(N,1),shape=(1,1)) uses scalar multiplication appropriately
Check if the summation dimension is 0-sized
(PyArray_NDIM(ap1) <= 2 && PyArray_NDIM(ap2) <= 2) Both ap1 and ap2 are vectors or matrices
Choose which subtype to return
verify that out is usable
Multiplication by a scalar -- Level 1 BLAS if ap1shape is a matrix and we are not contiguous, then we can't just blast through the entire array using a single striding factor
Dot product between two vectors -- Level 1 BLAS
Matrix vector multiplication -- Level 2 BLAS
lda must be MAX(M,1)
Vector matrix multiplication -- Level 2 BLAS
(PyArray_NDIM(ap1) == 2 && PyArray_NDIM(ap2) == 2) Matrix matrix multiplication -- Level 3 BLAS

System Message: ERROR/3 (<string>, line 3) Unexpected indentation.

<blockquote> L x M multiplied by M x N</blockquote>

Optimization possible:
We may be able to handle single-segment arrays here using appropriate values of Order, Trans1, and Trans2.
Avoid temporary copies for arrays in Fortran order
Use syrk if we have a case of a matrix times its transpose. Otherwise, use gemm for all other cases.

References NPY_ANYORDER, and PyArray_NewCopy().