Skip to content
Browse files

ENH: linalg: properly expose the BLAS/LAPACK wrappers, and document this

  • Loading branch information...
1 parent 114ad37 commit 082b39adace53b0810067c15e2ed5b2c3adf8091 @pv committed Nov 17, 2012
Showing with 332 additions and 22 deletions.
  1. +3 −0 doc/API.rst.txt
  2. +3 −0 scipy/linalg/__init__.py
  3. +117 −14 scipy/linalg/blas.py
  4. +209 −8 scipy/linalg/lapack.py
View
3 doc/API.rst.txt
@@ -104,6 +104,9 @@ change is made.
* scipy.linalg
+ - scipy.linalg.blas
+ - scipy.linalg.lapack
+
* scipy.misc
* scipy.ndimage
View
3 scipy/linalg/__init__.py
@@ -135,6 +135,8 @@
get_blas_funcs
get_lapack_funcs
find_best_blas_type
+ scipy.linalg.blas
+ scipy.linalg.lapack
"""
@@ -151,6 +153,7 @@
from decomp_schur import *
from matfuncs import *
from blas import *
+from lapack import *
from special_matrices import *
from _solvers import *
View
131 scipy/linalg/blas.py
@@ -1,25 +1,128 @@
+"""
+Low-level BLAS functions
+========================
+
+This module contains low-level functions from the BLAS library.
+
+
+.. warning::
+
+ These functions do little to no error checking.
+ It is possible to cause crashes by mis-using them,
+ so prefer using the higher-level routines in `scipy.linalg`.
+
+Finding functions
+=================
+
+.. autosummary::
+
+ get_blas_funcs
+ find_best_blas_type
+
+All functions
+=============
+
+.. autosummary::
+ :toctree: generated/
+
+ caxpy
+ ccopy
+ cdotc
+ cdotu
+ cgemm
+ cgemv
+ cgerc
+ cgeru
+ chemv
+ crotg
+ cscal
+ csrot
+ csscal
+ cswap
+ ctrmv
+ dasum
+ daxpy
+ dcopy
+ ddot
+ dgemm
+ dgemv
+ dger
+ dnrm2
+ drot
+ drotg
+ drotm
+ drotmg
+ dscal
+ dswap
+ dsymv
+ dtrmv
+ dzasum
+ dznrm2
+ icamax
+ idamax
+ isamax
+ izamax
+ sasum
+ saxpy
+ scasum
+ scnrm2
+ scopy
+ sdot
+ sgemm
+ sgemv
+ sger
+ snrm2
+ srot
+ srotg
+ srotm
+ srotmg
+ sscal
+ sswap
+ ssymv
+ strmv
+ zaxpy
+ zcopy
+ zdotc
+ zdotu
+ zdrot
+ zdscal
+ zgemm
+ zgemv
+ zgerc
+ zgeru
+ zhemv
+ zrotg
+ zscal
+ zswap
+ ztrmv
+
+
+"""
#
# Author: Pearu Peterson, March 2002
# refactoring by Fabian Pedregosa, March 2010
#
__all__ = ['get_blas_funcs', 'find_best_blas_type']
-import numpy as np
+import numpy as _np
# The following ensures that possibly missing flavor (C or Fortran) is
# replaced with the available one. If none is available, exception
# is raised at the first attempt to use the resources.
-from scipy.linalg import fblas
+from scipy.linalg import fblas as _fblas
try:
- from scipy.linalg import cblas
+ from scipy.linalg import cblas as _cblas
except ImportError:
- cblas = None
-if cblas is None:
- cblas = fblas
-elif hasattr(fblas, 'empty_module'):
- fblas = cblas
+ _cblas = None
+if _cblas is None:
+ _cblas = _fblas
+elif hasattr(_fblas, 'empty_module'):
+ _fblas = _cblas
+
+# Expose all functions (only fblas --- cblas is an implementation detail)
+from scipy.linalg.fblas import *
# 'd' will be default for 'i',..
_type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z', 'G':'z'}
@@ -55,13 +158,13 @@ def find_best_blas_type(arrays=(), dtype=None):
Whether to prefer Fortran order routines over C order.
"""
- dtype = np.dtype(dtype)
+ dtype = _np.dtype(dtype)
prefer_fortran = False
if arrays:
# use the most generic type in arrays
dtypes = [ar.dtype for ar in arrays]
- dtype = np.find_common_type(dtypes, ())
+ dtype = _np.find_common_type(dtypes, ())
try:
index = dtypes.index(dtype)
except ValueError:
@@ -84,9 +187,9 @@ def _get_funcs(names, arrays, dtype,
funcs = []
unpack = False
- dtype = np.dtype(dtype)
- module1 = (cmodule, 'cblas')
- module2 = (fmodule, 'fblas')
+ dtype = _np.dtype(dtype)
+ module1 = (cmodule, cmodule.__name__.split('.')[-1])
+ module2 = (fmodule, fmodule.__name__.split('.')[-1])
if isinstance(names, str):
names = (names,)
@@ -157,4 +260,4 @@ def get_blas_funcs(names, arrays=(), dtype=None):
of the returned functions.
"""
return _get_funcs(names, arrays, dtype,
- "BLAS", fblas, cblas, _blas_alias)
+ "BLAS", _fblas, _cblas, _blas_alias)
View
217 scipy/linalg/lapack.py
@@ -1,3 +1,199 @@
+"""
+Low-level LAPACK functions
+==========================
+
+This module contains low-level functions from the LAPACK library.
+
+.. warning::
+
+ These functions do little to no error checking.
+ It is possible to cause crashes by mis-using them,
+ so prefer using the higher-level routines in `scipy.linalg`.
+
+Finding functions
+=================
+
+.. autosummary::
+
+ get_lapack_funcs
+ find_best_blas_type
+
+All functions
+=============
+
+.. autosummary::
+ :toctree: generated/
+
+ cgbsv
+ cgbtrf
+ cgbtrs
+ cgebal
+ cgees
+ cgeev
+ cgegv
+ cgehrd
+ cgelss
+ cgeqp3
+ cgeqrf
+ cgerqf
+ cgesdd
+ cgesv
+ cgetrf
+ cgetri
+ cgetrs
+ cgges
+ cggev
+ chbevd
+ chbevx
+ cheev
+ cheevr
+ chegv
+ chegvd
+ chegvx
+ claswp
+ clauum
+ cpbsv
+ cpbtrf
+ cpbtrs
+ cposv
+ cpotrf
+ cpotri
+ cpotrs
+ ctrsyl
+ ctrtri
+ ctrtrs
+ cungqr
+ cungrq
+ cunmqr
+ dgbsv
+ dgbtrf
+ dgbtrs
+ dgebal
+ dgees
+ dgeev
+ dgegv
+ dgehrd
+ dgelss
+ dgeqp3
+ dgeqrf
+ dgerqf
+ dgesdd
+ dgesv
+ dgetrf
+ dgetri
+ dgetrs
+ dgges
+ dggev
+ dlamch
+ dlaswp
+ dlauum
+ dorgqr
+ dorgrq
+ dormqr
+ dpbsv
+ dpbtrf
+ dpbtrs
+ dposv
+ dpotrf
+ dpotri
+ dpotrs
+ dsbev
+ dsbevd
+ dsbevx
+ dsyev
+ dsyevr
+ dsygv
+ dsygvd
+ dsygvx
+ dtrsyl
+ dtrtri
+ dtrtrs
+ sgbsv
+ sgbtrf
+ sgbtrs
+ sgebal
+ sgees
+ sgeev
+ sgegv
+ sgehrd
+ sgelss
+ sgeqp3
+ sgeqrf
+ sgerqf
+ sgesdd
+ sgesv
+ sgetrf
+ sgetri
+ sgetrs
+ sgges
+ sggev
+ slamch
+ slaswp
+ slauum
+ sorgqr
+ sorgrq
+ sormqr
+ spbsv
+ spbtrf
+ spbtrs
+ sposv
+ spotrf
+ spotri
+ spotrs
+ ssbev
+ ssbevd
+ ssbevx
+ ssyev
+ ssyevr
+ ssygv
+ ssygvd
+ ssygvx
+ strsyl
+ strtri
+ strtrs
+ zgbsv
+ zgbtrf
+ zgbtrs
+ zgebal
+ zgees
+ zgeev
+ zgegv
+ zgehrd
+ zgelss
+ zgeqp3
+ zgeqrf
+ zgerqf
+ zgesdd
+ zgesv
+ zgetrf
+ zgetri
+ zgetrs
+ zgges
+ zggev
+ zhbevd
+ zhbevx
+ zheev
+ zheevr
+ zhegv
+ zhegvd
+ zhegvx
+ zlaswp
+ zlauum
+ zpbsv
+ zpbtrf
+ zpbtrs
+ zposv
+ zpotrf
+ zpotri
+ zpotrs
+ ztrsyl
+ ztrtri
+ ztrtrs
+ zungqr
+ zungrq
+ zunmqr
+
+"""
#
# Author: Pearu Peterson, March 2002
#
@@ -12,18 +208,23 @@
# Backward compatibility:
from blas import find_best_blas_type as find_best_lapack_type
-from scipy.linalg import flapack
+from scipy.linalg import flapack as _flapack
try:
- from scipy.linalg import clapack
+ from scipy.linalg import clapack as _clapack
except ImportError:
- clapack = None
+ _clapack = None
_use_force_clapack = 1
-if clapack is None:
- clapack = flapack
+if _clapack is None:
+ _clapack = _flapack
_use_force_clapack = 0
-elif hasattr(flapack,'empty_module'):
- flapack = clapack
+elif hasattr(_flapack,'empty_module'):
+ _flapack = _clapack
+
+# Expose all functions (only flapack --- clapack is an implementation detail)
+empty_module = None
+from scipy.linalg.flapack import *
+del empty_module
# some convenience alias for complex functions
_lapack_alias = {
@@ -70,4 +271,4 @@ def get_lapack_funcs(names, arrays=(), dtype=None):
are stored in attribute `typecode` of the returned functions.
"""
return _get_funcs(names, arrays, dtype,
- "LAPACK", flapack, clapack, _lapack_alias)
+ "LAPACK", _flapack, _clapack, _lapack_alias)

0 comments on commit 082b39a

Please sign in to comment.
Something went wrong with that request. Please try again.