numpy  2.0.0
src/multiarray/cblasfuncs.c File Reference
#include <Python.h>
#include <assert.h>
#include <numpy/arrayobject.h>
#include "npy_cblas.h"
#include "arraytypes.h"
#include "common.h"

Defines

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE

Enumerations

enum  MatrixShape { _scalar, _column, _row, _matrix }

Functions

static void blas_dot (int typenum, npy_intp n, void *a, npy_intp stridea, void *b, npy_intp strideb, void *res)
static void gemm (int typenum, enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE transA, enum CBLAS_TRANSPOSE transB, int m, int n, int k, PyArrayObject *A, int lda, PyArrayObject *B, int ldb, PyArrayObject *R)
static void gemv (int typenum, enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE trans, PyArrayObject *A, int lda, PyArrayObject *X, int incX, PyArrayObject *R)
static void syrk (int typenum, enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE trans, int n, int k, PyArrayObject *A, int lda, PyArrayObject *R)
static MatrixShape _select_matrix_shape (PyArrayObject *array)
static int _bad_strides (PyArrayObject *ap)
NPY_NO_EXPORT PyObject * cblas_matrixproduct (int typenum, PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject *out)

Variables

static const double oneD [2] = {1.0, 0.0}
static const double zeroD [2] = {0.0, 0.0}
static const float oneF [2] = {1.0, 0.0}
static const float zeroF [2] = {0.0, 0.0}

Define Documentation

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Enumeration Type Documentation

Enumerator:
_scalar 
_column 
_row 
_matrix 

Function Documentation

static int _bad_strides ( PyArrayObject ap) [static]
This also makes sure that the data segment is aligned with an itemsize address as well by returning one if not true.

References dimensions, NPY_ANYORDER, NPY_MAXDIMS, and PyArray_NewCopy().

static void blas_dot ( int  typenum,
npy_intp  n,
void *  a,
npy_intp  stridea,
void *  b,
npy_intp  strideb,
void *  res 
) [static]
Helper: call appropriate BLAS dot function for typenum. Strides are NumPy strides.

References CDOUBLE_dot(), CFLOAT_dot(), DOUBLE_dot(), FLOAT_dot(), NPY_CDOUBLE, NPY_CFLOAT, NPY_DOUBLE, and NPY_FLOAT.

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().

static void gemm ( int  typenum,
enum CBLAS_ORDER  order,
enum CBLAS_TRANSPOSE  transA,
enum CBLAS_TRANSPOSE  transB,
int  m,
int  n,
int  k,
PyArrayObject A,
int  lda,
PyArrayObject B,
int  ldb,
PyArrayObject R 
) [static]
Helper: dispatch to appropriate cblas_?gemm for typenum.

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink Unknown target name: "cblas".

References cblas_cgemm(), cblas_dgemm(), cblas_sgemm(), cblas_zgemm(), NPY_CDOUBLE, NPY_CFLOAT, NPY_DOUBLE, NPY_FLOAT, oneD, oneF, zeroD, and zeroF.

static void gemv ( int  typenum,
enum CBLAS_ORDER  order,
enum CBLAS_TRANSPOSE  trans,
PyArrayObject A,
int  lda,
PyArrayObject X,
int  incX,
PyArrayObject R 
) [static]
Helper: dispatch to appropriate cblas_?gemv for typenum.

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink Unknown target name: "cblas".
static void syrk ( int  typenum,
enum CBLAS_ORDER  order,
enum CBLAS_TRANSPOSE  trans,
int  n,
int  k,
PyArrayObject A,
int  lda,
PyArrayObject R 
) [static]
Helper: dispatch to appropriate cblas_?syrk for typenum.

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink Unknown target name: "cblas".

Variable Documentation

const double oneD[2] = {1.0, 0.0} [static]

Referenced by gemm().

const float oneF[2] = {1.0, 0.0} [static]

Referenced by gemm().

const double zeroD[2] = {0.0, 0.0} [static]

Referenced by gemm().

const float zeroF[2] = {0.0, 0.0} [static]

Referenced by gemm().