Skip to main content
`Ctrl`+`K`

# BLAS Functions for Cython

Usable from Cython via:

    cimport scipy.linalg.cython_blas

These wrappers do not check for alignment of arrays. Alignment should be checked before these wrappers are used.

If using `cdotu`, `cdotc`, `zdotu`, `zdotc`, `sladiv`, or `dladiv`, the `CYTHON_CCOMPLEX` define must be set to 0 during compilation. For example, in a `meson.build` file when using Meson:

    py.extension_module('ext_module'
        'ext_module.pyx',
        c_args: ['-DCYTHON_CCOMPLEX=0'],
        ...
    )

## ILP64 support

Integer parameters in the function signatures use `int` for LP64 builds (the default) and `int64_t` for ILP64 builds. A convenience typedef `blas_int` (aliasing the appropriate concrete type) is also exported so that downstream packages can write code that works with both variants. The build configuration can be checked at runtime via `scipy.show_config(mode='dicts')['Build Dependencies']['blas']['cython blas ilp64']`.

Boolean (Fortran `logical`) parameters in the function signatures use `bint` for LP64 builds and `int64_t` for ILP64 builds. A convenience typedef `blas_bint` is exported in a similar way to `blas_int`.

Downstream packages that want to support both LP64 and ILP64 builds of SciPy should follow this pattern:

1. Use `blas_int` for all integer variables passed to BLAS functions. For boolean variables, use `blas_bint`.

2. For backwards compatibility with scipy <=1.17.0 (if desired), perform a build-time check for whether `blas_int` is available, and typedef it as `int` otherwise. Example for Meson:

    # Check if scipy's cython_blas exports blas_int (ILP64 support).
    _blas_int_conf = configuration_data()
    if cython.compiles('from scipy.linalg.cython_blas cimport blas_int')
      _blas_int_conf.set('BLAS_INT_DEF', 'from scipy.linalg.cython_blas cimport blas_int')
      _blas_int_conf.set('BLAS_BINT_DEF', 'from scipy.linalg.cython_blas cimport blas_bint')
    else
      _blas_int_conf.set('BLAS_INT_DEF', 'ctypedef int blas_int')
      _blas_int_conf.set('BLAS_BINT_DEF', 'ctypedef bint blas_bint')
    endif

    _blas_int_pxi = configure_file(
      input: '_blas_int.pxi.in',
      output: '_blas_int.pxi',
      configuration: _blas_int_conf,
    )

With the file `_blas_int.pxi.in` containing two lines:

    @BLAS_INT_DEF@
    @BLAS_BINT_DEF@

## `cython_blas` API

Integer types:

- blas_int: convenience typedef for either `int` (LP64) or `int64_t` (ILP64)

- blas_bint: convenience typedef for either `bint` (LP64) or `int64_t` (ILP64)

Raw function pointers (Fortran-style pointer arguments):

- caxpy

- ccopy

- cdotc

- cdotu

- cgbmv

- cgemm

- cgemv

- cgerc

- cgeru

- chbmv

- chemm

- chemv

- cher

- cher2

- cher2k

- cherk

- chpmv

- chpr

- chpr2

- crotg

- cscal

- csrot

- csscal

- cswap

- csymm

- csyr2k

- csyrk

- ctbmv

- ctbsv

- ctpmv

- ctpsv

- ctrmm

- ctrmv

- ctrsm

- ctrsv

- dasum

- daxpy

- dcabs1

- dcopy

- ddot

- dgbmv

- dgemm

- dgemv

- dger

- dnrm2

- drot

- drotg

- drotm

- drotmg

- dsbmv

- dscal

- dsdot

- dspmv

- dspr

- dspr2

- dswap

- dsymm

- dsymv

- dsyr

- dsyr2

- dsyr2k

- dsyrk

- dtbmv

- dtbsv

- dtpmv

- dtpsv

- dtrmm

- dtrmv

- dtrsm

- dtrsv

- dzasum

- dznrm2

- icamax

- idamax

- isamax

- izamax

- lsame

- sasum

- saxpy

- scasum

- scnrm2

- scopy

- sdot

- sdsdot

- sgbmv

- sgemm

- sgemv

- sger

- snrm2

- srot

- srotg

- srotm

- srotmg

- ssbmv

- sscal

- sspmv

- sspr

- sspr2

- sswap

- ssymm

- ssymv

- ssyr

- ssyr2

- ssyr2k

- ssyrk

- stbmv

- stbsv

- stpmv

- stpsv

- strmm

- strmv

- strsm

- strsv

- zaxpy

- zcopy

- zdotc

- zdotu

- zdrot

- zdscal

- zgbmv

- zgemm

- zgemv

- zgerc

- zgeru

- zhbmv

- zhemm

- zhemv

- zher

- zher2

- zher2k

- zherk

- zhpmv

- zhpr

- zhpr2

- zrotg

- zscal

- zswap

- zsymm

- zsyr2k

- zsyrk

- ztbmv

- ztbsv

- ztpmv

- ztpsv

- ztrmm

- ztrmv

- ztrsm

- ztrsv