Skip to content

Commit 665e3cb

Browse files
author
Ralf Gommers
committed
Merge branch 'lapack-imports' into master.
Review at scipy#358.
2 parents 15e9ac0 + 4f86244 commit 665e3cb

32 files changed

+735
-274
lines changed

doc/API.rst.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ change is made.
104104

105105
* scipy.linalg
106106

107+
- scipy.linalg.blas
108+
- scipy.linalg.lapack
109+
107110
* scipy.misc
108111

109112
* scipy.ndimage

doc/release/0.12.0-notes.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ exactly the same interface as KDTree, and can be used as a drop-in replacement.
4343
-------------------------------
4444
A callback mechanism was added to L-BFGS-B and TNC minimization solvers.
4545

46-
4746
Complex error functions in ``scipy.special``
4847
--------------------------------------------
4948
The computation of special functions related to the error function now uses a
@@ -63,10 +62,27 @@ Evaluation of orthogonal polynomials (the ``eval_*`` routines) in now
6362
faster in ``scipy.special``, and their ``out=`` argument functions
6463
properly.
6564

65+
Documented BLAS and LAPACK low-level interfaces
66+
-----------------------------------------------
67+
The modules `scipy.linalg.blas` and `scipy.linalg.lapack` can be used
68+
to access low-level BLAS and LAPACK functions.
69+
6670

6771
Deprecated features
6872
===================
6973

74+
`scipy.lib.lapack`
75+
------------------
76+
The module `scipy.lib.lapack` is deprecated. You can use
77+
`scipy.linalg.lapack` instead. The module `scipy.lib.blas` was
78+
deprecated earlier in Scipy 0.10.0.
79+
80+
`fblas` and `cblas`
81+
-------------------
82+
Accessing the modules `scipy.linalg.fblas`, `cblas`, `flapack`,
83+
`clapack` is deprecated. Instead, use the modules
84+
`scipy.linalg.lapack` and `scipy.linalg.blas`.
85+
7086

7187
Backwards incompatible changes
7288
==============================

doc/source/linalg.blas.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: scipy.linalg.blas

doc/source/linalg.lapack.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodule:: scipy.linalg.lapack

doc/source/linalg.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
.. automodule:: scipy.linalg
2+
3+
.. toctree::
4+
:hidden:
5+
6+
linalg.blas
7+
linalg.lapack

scipy/lib/blas/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Wrappers to BLAS library
33
========================
44
5+
NOTE: this module is deprecated -- use scipy.linalg.blas instead!
6+
57
fblas -- wrappers for Fortran [*] BLAS routines
68
cblas -- wrappers for ATLAS BLAS routines
79
get_blas_funcs -- query for wrapper functions.
@@ -88,6 +90,15 @@
8890

8991
from numpy import deprecate
9092

93+
@deprecate(old_name="scipy.lib.blas", new_name="scipy.linalg.blas")
94+
def _deprecated():
95+
pass
96+
try:
97+
_deprecated()
98+
except DeprecationWarning, e:
99+
# don't fail import if DeprecationWarnings raise error -- works around
100+
# the situation with Numpy's test framework
101+
pass
91102

92103
_use_force_cblas = 1
93104
if hasattr(cblas,'empty_module'):

scipy/lib/lapack/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Wrappers to LAPACK library
33
==========================
44
5+
NOTE: this module is deprecated -- use scipy.linalg.lapack instead!
6+
57
flapack -- wrappers for Fortran [*] LAPACK routines
68
clapack -- wrappers for ATLAS LAPACK routines
79
calc_lwork -- calculate optimal lwork parameters
@@ -137,17 +139,27 @@
137139

138140
__all__ = ['get_lapack_funcs','calc_lwork','flapack','clapack']
139141

142+
from numpy import deprecate
140143

141144
import calc_lwork
142145

143146
# The following ensures that possibly missing flavor (C or Fortran) is
144147
# replaced with the available one. If none is available, exception
145148
# is raised at the first attempt to use the resources.
146149

150+
@deprecate(old_name="scipy.lib.lapack", new_name="scipy.linalg.lapack")
151+
def _deprecated():
152+
pass
153+
try:
154+
_deprecated()
155+
except DeprecationWarning, e:
156+
# don't fail import if DeprecationWarnings raise error -- works around
157+
# the situation with Numpy's test framework
158+
pass
159+
147160
import flapack
148161
import clapack
149162

150-
151163
_use_force_clapack = 1
152164
if hasattr(clapack,'empty_module'):
153165
clapack = flapack
@@ -159,7 +171,7 @@
159171
_type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z'} # 'd' will be default for 'i',..
160172
_inv_type_conv = {'s':'f','d':'d','c':'F','z':'D'}
161173

162-
174+
@deprecate
163175
def get_lapack_funcs(names,arrays=(),debug=0,force_clapack=1):
164176
"""Return available LAPACK function objects with names.
165177
arrays are used to determine the optimal prefix of

scipy/linalg/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@
126126
toeplitz - Toeplitz matrix
127127
tri - Construct a matrix filled with ones at and below a given diagonal
128128
129+
Low-level routines
130+
==================
131+
132+
.. autosummary::
133+
:toctree: generated/
134+
135+
get_blas_funcs
136+
get_lapack_funcs
137+
find_best_blas_type
138+
scipy.linalg.blas
139+
scipy.linalg.lapack
140+
129141
"""
130142

131143
from linalg_version import linalg_version as __version__
@@ -141,6 +153,7 @@
141153
from decomp_schur import *
142154
from matfuncs import *
143155
from blas import *
156+
from lapack import *
144157
from special_matrices import *
145158
from _solvers import *
146159

scipy/linalg/basic.py

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -356,31 +356,18 @@ def inv(a, overwrite_a=False, check_finite=True):
356356
## if info<0: raise ValueError,\
357357
## 'illegal value in %d-th argument of internal inv.getrf|getri'%(-info)
358358
getrf, getri = get_lapack_funcs(('getrf','getri'), (a1,))
359-
#XXX: C ATLAS versions of getrf/i have rowmajor=1, this could be
360-
# exploited for further optimization. But it will be probably
361-
# a mess. So, a good testing site is required before trying
362-
# to do that.
363-
if getrf.module_name[:7] == 'clapack' != getri.module_name[:7]:
364-
# ATLAS 3.2.1 has getrf but not getri.
365-
lu, piv, info = getrf(np.transpose(a1), rowmajor=0,
366-
overwrite_a=overwrite_a)
367-
lu = np.transpose(lu)
368-
else:
369-
lu, piv, info = getrf(a1, overwrite_a=overwrite_a)
359+
lu, piv, info = getrf(a1, overwrite_a=overwrite_a)
370360
if info == 0:
371-
if getri.module_name[:7] == 'flapack':
372-
lwork = calc_lwork.getri(getri.prefix, a1.shape[0])
373-
lwork = lwork[1]
374-
# XXX: the following line fixes curious SEGFAULT when
375-
# benchmarking 500x500 matrix inverse. This seems to
376-
# be a bug in LAPACK ?getri routine because if lwork is
377-
# minimal (when using lwork[0] instead of lwork[1]) then
378-
# all tests pass. Further investigation is required if
379-
# more such SEGFAULTs occur.
380-
lwork = int(1.01 * lwork)
381-
inv_a, info = getri(lu, piv, lwork=lwork, overwrite_lu=1)
382-
else: # clapack
383-
inv_a, info = getri(lu, piv, overwrite_lu=1)
361+
lwork = calc_lwork.getri(getri.typecode, a1.shape[0])
362+
lwork = lwork[1]
363+
# XXX: the following line fixes curious SEGFAULT when
364+
# benchmarking 500x500 matrix inverse. This seems to
365+
# be a bug in LAPACK ?getri routine because if lwork is
366+
# minimal (when using lwork[0] instead of lwork[1]) then
367+
# all tests pass. Further investigation is required if
368+
# more such SEGFAULTs occur.
369+
lwork = int(1.01 * lwork)
370+
inv_a, info = getri(lu, piv, lwork=lwork, overwrite_lu=1)
384371
if info > 0:
385372
raise LinAlgError("singular matrix")
386373
if info < 0:
@@ -531,16 +518,14 @@ def lstsq(a, b, cond=None, overwrite_a=False, overwrite_b=False,
531518

532519
overwrite_a = overwrite_a or _datacopied(a1, a)
533520
overwrite_b = overwrite_b or _datacopied(b1, b)
534-
if gelss.module_name[:7] == 'flapack':
535-
# get optimal work array
536-
work = gelss(a1, b1, lwork=-1)[4]
537-
lwork = work[0].real.astype(np.int)
538-
v, x, s, rank, work, info = gelss(
539-
a1, b1, cond=cond, lwork=lwork, overwrite_a=overwrite_a,
540-
overwrite_b=overwrite_b)
541521

542-
else:
543-
raise NotImplementedError('calling gelss from %s' % gelss.module_name)
522+
# get optimal work array
523+
work = gelss(a1, b1, lwork=-1)[4]
524+
lwork = work[0].real.astype(np.int)
525+
v, x, s, rank, work, info = gelss(
526+
a1, b1, cond=cond, lwork=lwork, overwrite_a=overwrite_a,
527+
overwrite_b=overwrite_b)
528+
544529
if info > 0:
545530
raise LinAlgError("SVD did not converge in Linear Least Squares")
546531
if info < 0:

scipy/linalg/bento.info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
HookFile: bscript
22

33
Library:
4-
Extension: fblas
4+
Extension: _fblas
55
Sources:
66
fblas.pyf.src,
77
src/fblaswrap.f
8-
Extension: cblas
8+
Extension: _cblas
99
Sources:
1010
generic_cblas.pyf
11-
Extension: flapack
11+
Extension: _flapack
1212
Sources:
1313
flapack.pyf.src
14-
Extension: clapack
14+
Extension: _clapack
1515
Sources:
1616
generic_clapack.pyf
1717
Extension: _flinalg

0 commit comments

Comments
 (0)