Skip to content
This repository

Fix for new name of scipy.linalg.blas.fblas #1150

Merged
merged 2 commits into from over 1 year ago

3 participants

Olivier Delalleau Frédéric Bastien Michael McNeil Forbes
Olivier Delalleau
Collaborator

Also cleaned up duplicated / useless code at the same time.
This fixes gh-1144.

Fix for new name of scipy.linalg.blas.fblas
Also cleaned up duplicated / useless code at the same time.
This fixes gh-1144.
94aab09
Michael McNeil Forbes mforbes commented on the diff January 06, 2013
theano/tensor/blas.py
@@ -150,16 +150,22 @@
150 150
 
151 151
 try:
152 152
     import scipy.linalg.blas
153  
-    _have_fblas = True
  153
+    have_fblas = True
  154
+    try:
5
Michael McNeil Forbes
mforbes added a note January 06, 2013

It might be more explicit to check for the scipy version numbers with scipy.version.version. (I think the API changed in 0.10.0).

Frédéric Bastien Owner
nouiz added a note January 07, 2013

I prefer the not explicit version as this make it more robust in case of changes. But adding the version with the change in comment would be great. @delallea, can you add it?

Olivier Delalleau Collaborator
delallea added a note January 07, 2013

I can but we should make sure exactly which version it is. 0.10 seems surprising to me as I would have expected to see a bug report sooner.

Frédéric Bastien Owner
nouiz added a note January 07, 2013

I looked into the git history of scipy and it is included only in the trunk of scipy. So this will be for version > 0.11.0 as 0.11 is the last version and it is not changed. @mforbes, can you confirm the version of SciPy that you use?

Michael McNeil Forbes
mforbes added a note January 07, 2013

I was using the latest development trunk. I think the comments in the code are now correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Frédéric Bastien
Owner

I added a comment to the scipy PR that broke this:

scipy/scipy#358

Olivier Delalleau
Collaborator

I pushed another commit that gives more details on when & where the Scipy change occurred.

Michael McNeil Forbes mforbes commented on the diff January 07, 2013
theano/tensor/blas.py
@@ -150,16 +150,23 @@
150 150
 
151 151
 try:
152 152
     import scipy.linalg.blas
153  
-    _have_fblas = True
  153
+    have_fblas = True
  154
+    try:
  155
+        fblas = scipy.linalg.blas.fblas
  156
+    except AttributeError:
  157
+        # A change merged in Scipy development version on 2012-12-02 replaced
  158
+        # `scipy.linalg.blas.fblas` with `scipy.linalg.blas`.
  159
+        # See http://github.com/scipy/scipy/pull/358
  160
+        fblas = scipy.linalg.blas
1
Michael McNeil Forbes
mforbes added a note January 07, 2013

This is correct. Some more details:

  • The new code 'fblas = scipy.linalg.blas' will work as of version 0.10.0 when scipy.linalg.blas has all of the fblas routines exposed.
  • The old code will fail as of revision 812c886b448276617f3094f0693c5c54bc97d85f which changed scipy.linalg.blas.fblas to scipy.linalg.blas._fblas. This is a recent change as @nouiz pointed out and explains why this bug was only noticed recently. (I am using the latest version of scipy from github to deal with other BLAS issues.)
  • scipy.linalg.blas._fblas is completely removed in a89748ba10e689973d74a23be00b4566b7c03bcb.

The try form is probably fine and more robust. My only complaint was that it first tries a deprecated form of the API and the falls back to the supported form, but I understand that in this case, it is somewhat tricky to fall-back to the old code.

As far as I can tell, this PR now looks good and works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Frédéric Bastien nouiz merged commit 55f6a18 into from January 08, 2013
Frédéric Bastien nouiz closed this January 08, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jan 06, 2013
Fix for new name of scipy.linalg.blas.fblas
Also cleaned up duplicated / useless code at the same time.
This fixes gh-1144.
94aab09
Jan 07, 2013
More specific comment on the Scipy change fdc2b78
This page is out of date. Refresh to see the latest.
25  theano/tensor/blas.py
@@ -142,7 +142,7 @@
142 142
 from theano.compile.mode import optdb
143 143
 from theano.gof.python25 import all, any
144 144
 import theano.scalar
145  
-import basic as T
  145
+from theano.tensor import basic as T
146 146
 from theano.tensor.blas_headers import blas_header_text
147 147
 from theano.tensor.opt import local_dimshuffle_lift
148 148
 
@@ -150,16 +150,23 @@
150 150
 
151 151
 try:
152 152
     import scipy.linalg.blas
153  
-    _have_fblas = True
  153
+    have_fblas = True
  154
+    try:
  155
+        fblas = scipy.linalg.blas.fblas
  156
+    except AttributeError:
  157
+        # A change merged in Scipy development version on 2012-12-02 replaced
  158
+        # `scipy.linalg.blas.fblas` with `scipy.linalg.blas`.
  159
+        # See http://github.com/scipy/scipy/pull/358
  160
+        fblas = scipy.linalg.blas
154 161
     _blas_gemv_fns = {
155  
-            numpy.dtype('float32'): scipy.linalg.blas.fblas.sgemv,
156  
-            numpy.dtype('float64'): scipy.linalg.blas.fblas.dgemv,
157  
-            numpy.dtype('complex64'): scipy.linalg.blas.fblas.cgemv,
158  
-            numpy.dtype('complex128'): scipy.linalg.blas.fblas.zgemv,
  162
+            numpy.dtype('float32'): fblas.sgemv,
  163
+            numpy.dtype('float64'): fblas.dgemv,
  164
+            numpy.dtype('complex64'): fblas.cgemv,
  165
+            numpy.dtype('complex128'): fblas.zgemv,
159 166
             }
160 167
 except ImportError, e:
161  
-    _have_fblas = False
162  
-    _logger.warning('Failed to import scipy.linalg.blas.fblas. '
  168
+    have_fblas = False
  169
+    _logger.warning('Failed to import scipy.linalg.blas. '
163 170
             'Falling back on slower implementations (%s)', str(e))
164 171
 
165 172
 
@@ -216,7 +223,7 @@ def make_node(self, y, alpha, A, x, beta):
216 223
 
217 224
     def perform(self, node, inputs, out_storage):
218 225
         y, alpha, A, x, beta = inputs
219  
-        if _have_fblas and y.shape[0] != 0 and x.shape[0] != 0:
  226
+        if have_fblas and y.shape[0] != 0 and x.shape[0] != 0:
220 227
             gemv = _blas_gemv_fns[y.dtype]
221 228
 
222 229
             if (A.shape[0] != y.shape[0] or A.shape[1] != x.shape[0]):
26  theano/tensor/blas_scipy.py
@@ -3,28 +3,20 @@
3 3
 """
4 4
 import numpy
5 5
 
6  
-from blas import Ger, ger, ger_destructive
7  
-from blas import blas_optdb, optdb,local_optimizer
  6
+from theano.tensor.blas import Ger, ger, ger_destructive, have_fblas
  7
+from theano.tensor.blas import blas_optdb, optdb,local_optimizer
8 8
 
9 9
 from theano.tensor.opt import in2out
10 10
 
11  
-try:
12  
-    import scipy.linalg.blas
13  
-    have_fblas = True
14  
-    _blas_gemv_fns = {
15  
-            numpy.dtype('float32'):scipy.linalg.blas.fblas.sgemv,
16  
-            numpy.dtype('float64'):scipy.linalg.blas.fblas.dgemv,
17  
-            numpy.dtype('complex64'):scipy.linalg.blas.fblas.cgemv,
18  
-            numpy.dtype('complex128'):scipy.linalg.blas.fblas.zgemv,
19  
-            }
  11
+
  12
+if have_fblas:
  13
+    from theano.tensor.blas import fblas
20 14
     _blas_ger_fns = {
21  
-            numpy.dtype('float32'):scipy.linalg.blas.fblas.sger,
22  
-            numpy.dtype('float64'):scipy.linalg.blas.fblas.dger,
23  
-            numpy.dtype('complex64'):scipy.linalg.blas.fblas.cgeru,
24  
-            numpy.dtype('complex128'):scipy.linalg.blas.fblas.zgeru,
  15
+            numpy.dtype('float32'): fblas.sger,
  16
+            numpy.dtype('float64'): fblas.dger,
  17
+            numpy.dtype('complex64'): fblas.cgeru,
  18
+            numpy.dtype('complex128'): fblas.zgeru,
25 19
             }
26  
-except ImportError, e:
27  
-    have_fblas = False
28 20
 
29 21
 
30 22
 class ScipyGer(Ger):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.