get_blas_funcs#
- scipy.linalg.get_blas_funcs(names, arrays=(), dtype=None, ilp64='preferred')[source]#
Return available BLAS function objects from names.
Arrays are used to determine the optimal prefix of BLAS routines.
- Parameters:
- namesstr or sequence of str
Name(s) of BLAS functions without type prefix.
- arrayssequence of ndarrays, optional
Arrays can be given to determine optimal prefix of BLAS routines. If not given, double-precision routines will be used, otherwise the most generic type in arrays will be used.
- dtypestr or dtype, optional
Data-type specifier. Not used if arrays is non-empty.
- ilp64{True, False, ‘preferred’}, optional
Whether to return ILP64 routine variant. Choosing
'preferred'returns ILP64 routine if available, and otherwise the 32-bit (LP64) routine. Default:'preferred'.
- Returns:
- funcslist
List containing the found function(s).
- Raises:
- RuntimeError
If the requested LP64/ILP64 variant is not available.
See also
scipy.linalg.lapack.get_lapack_funcsa similar routine for selecting LAPACK functions.
Notes
In BLAS, the naming convention is that all functions start with a type prefix, which depends on the type of the principal matrix. These can be one of
{'s', 'd', 'c', 'z'}for the NumPy types{float32, float64, complex64, complex128}respectively. The code and the dtype are stored in attributes typecode and dtype of the returned functions.Examples
>>> import numpy as np >>> import scipy.linalg as LA >>> rng = np.random.default_rng() >>> a = rng.random((3, 2)) >>> x_gemv = LA.get_blas_funcs('gemv', (a,))
Note that
x_gemvstring representation shows the exact BLAS function with the prefix (here,d-becauseais double precision real):>>> x_gemv <fortran function dgemv>
The BLAS variant information is also available from the
typecodeattribute:>>> x_gemv.typecode 'd'
For double precision complex arrays, we select the
z-variant,zgemv>>> x_gemv = LA.get_blas_funcs('gemv', (a*1j,)) >>> x_gemv.typecode 'z'
If you want to select a specific BLAS variant instead of relying on array types, use the
dtype=argument:>>> LA.get_blas_funcs('gemv', dtype=np.float32) <fortran function sgemv>
The
int_dtypeattribute stores whether the routine is ILP64 (integer arguments and outputs are 64-bit) or LP64 (integer arguments and outputs are 32-bit):>>> x_gemv.int_dtype dtype('int32') # may vary