Permalink
Browse files

ENH: linalg: document the low-level functions, and deal with some bac…

…kward compatibility issues
  • Loading branch information...
pv committed Nov 17, 2012
1 parent 91ac56d commit 4084100e2b070fb3c5d51d08509a933317f8a0dc
Showing with 56 additions and 9 deletions.
  1. +10 −0 scipy/linalg/__init__.py
  2. +43 −9 scipy/linalg/blas.py
  3. +3 −0 scipy/linalg/lapack.py
View
@@ -126,6 +126,16 @@
toeplitz - Toeplitz matrix
tri - Construct a matrix filled with ones at and below a given diagonal
+Low-level routines
+==================
+
+.. autosummary::
+ :toctree: generated/
+
+ get_blas_funcs
+ get_lapack_funcs
+ find_best_blas_type
+
"""
from linalg_version import linalg_version as __version__
View
@@ -3,7 +3,7 @@
# refactoring by Fabian Pedregosa, March 2010
#
-__all__ = ['get_blas_funcs']
+__all__ = ['get_blas_funcs', 'find_best_blas_type']
import numpy as np
@@ -31,6 +31,45 @@
'sdotc': 'sdot', 'sdotu': 'sdot',
'ddotc': 'ddot', 'ddotu': 'ddot'}
+def find_best_blas_type(arrays=(), dtype=None):
+ """Find best-matching BLAS/LAPACK type.
+
+ Arrays are used to determine the optimal prefix of BLAS routines.
+
+ Parameters
+ ----------
+ arrays : sequency of ndarrays, optional
+ Arrays can be given to determine optiomal prefix of BLAS
+ routines. If not given, double-precision routines will be
+ used, otherwise the most generic type in arrays will be used.
+ dtype : str or dtype, optional
+ Data-type specifier. Not used if `arrays` is non-empty.
+
+ Returns
+ -------
+ prefix : str
+ BLAS/LAPACK prefix character.
+ dtype : dtype
+ Inferred Numpy data type.
+ prefer_fortran : bool
+ Whether to prefer Fortran order routines over C order.
+
+ """
+ dtype = np.dtype(dtype)
+ prefer_fortran = False
+
+ if arrays:
+ # use the most generic type in arrays
+ dtype, index = max(
+ [(ar.dtype, i) for i, ar in enumerate(arrays)])
+ if arrays[index].flags['FORTRAN']:
+ # prefer Fortran for leading array with column major order
+ prefer_fortran = True
+
+ prefix = _type_conv.get(dtype.char, 'd')
+
+ return prefix, dtype, prefer_fortran
+
def _get_funcs(names, arrays, dtype,
lib_name, fmodule, cmodule, alias):
"""
@@ -49,15 +88,10 @@ def _get_funcs(names, arrays, dtype,
names = (names,)
unpack = True
- if arrays:
- # use the most generic type in arrays
- dtype, index = max(
- [(ar.dtype, i) for i, ar in enumerate(arrays)])
- if arrays[index].flags['FORTRAN']:
- # prefer Fortran for leading array with column major order
- module1, module2 = module2, module1
+ prefix, dtype, prefer_fortran = find_best_blas_type(arrays, dtype)
- prefix = _type_conv.get(dtype.char, 'd')
+ if prefer_fortran:
+ module1, module2 = module2, module1
for i, name in enumerate(names):
func_name = prefix + name
View
@@ -9,6 +9,9 @@
# is raised at the first attempt to use the resources.
from blas import _get_funcs
+# Backward compatibility:
+from blas import find_best_blas_type as find_best_lapack_type
+
from scipy.linalg import flapack
try:
from scipy.linalg import clapack

0 comments on commit 4084100

Please sign in to comment.