Repository: scipy/scipy

Issue:
Wrap BLAS function gbmv
_Original ticket http://projects.scipy.org/scipy/ticket/1390 on 2011-02-21 by trac user RhysU, assigned to unknown._

Please add a wrapper for the BLAS level 2 routine general band matrix-vector multiply (gbmv) within source:trunk/scipy/lib/blas/fblas_l2.pyf.src

This should just be wrapping the BLAS dgbmv routine (see http://www.netlib.org/blas/dgbmv.f) in the same way that dgemm has been wrapped.

Thank you,
Rhys



Discussion:
_@rgommers wrote on 2011-02-27_

This kind of thing usually gets implemented when someone has a need for it. So if you really need this, a patch (including test) may speed things up ....

Cheers,
Ralf

I support this issue. I either wanted to use the dgbmv BLAS routine... If somebody can add to scipy, I'd appreciate that.

ming.


Resolving patch:
diff --git a/scipy/linalg/blas.py b/scipy/linalg/blas.py
--- a/scipy/linalg/blas.py
+++ b/scipy/linalg/blas.py
@@ -82,34 +82,67 @@
 .. autosummary::
    :toctree: generated/
 
+   sgbmv
+   sgemv
+   sger
+   ssbmv
+   sspr
+   sspr2
+   ssymv
+   ssyr
+   ssyr2
+   stbmv
+   stpsv
+   strmv
+   strsv
+   dgbmv
+   dgemv
+   dger
+   dsbmv
+   dspr
+   dspr2
+   dsymv
+   dsyr
+   dsyr2
+   dtbmv
+   dtpsv
+   dtrmv
+   dtrsv
+   cgbmv
    cgemv
    cgerc
    cgeru
+   chbmv
    chemv
-   ctrmv
-   csyr
    cher
    cher2
-   dgemv
-   dger
-   dsymv
-   dtrmv
-   dsyr
-   dsyr2
-   sgemv
-   sger
-   ssymv
-   strmv
-   ssyr
-   ssyr2
+   chpmv
+   chpr
+   chpr2
+   ctbmv
+   ctbsv
+   ctpmv
+   ctpsv
+   ctrmv
+   ctrsv
+   csyr
+   zgbmv
    zgemv
    zgerc
    zgeru
+   zhbmv
    zhemv
-   ztrmv
-   zsyr
    zher
    zher2
+   zhpmv
+   zhpr
+   zhpr2
+   ztbmv
+   ztbsv
+   ztpmv
+   ztrmv
+   ztrsv
+   zsyr
 
 BLAS Level 3 functions
 ----------------------
@@ -117,28 +150,36 @@
 .. autosummary::
    :toctree: generated/
 
+   sgemm
+   ssymm
+   ssyr2k
+   ssyrk
+   strmm
+   strsm
+   dgemm
+   dsymm
+   dsyr2k
+   dsyrk
+   dtrmm
+   dtrsm
    cgemm
    chemm
-   cherk
    cher2k
+   cherk
    csymm
-   csyrk
    csyr2k
-   dgemm
-   dsymm
-   dsyrk
-   dsyr2k
-   sgemm
-   ssymm
-   ssyrk
-   ssyr2k
+   csyrk
+   ctrmm
+   ctrsm
    zgemm
    zhemm
-   zherk
    zher2k
+   zherk
    zsymm
-   zsyrk
    zsyr2k
+   zsyrk
+   ztrmm
+   ztrsm
 
 """
 #


Test patch:
diff --git a/scipy/linalg/tests/test_blas.py b/scipy/linalg/tests/test_blas.py
--- a/scipy/linalg/tests/test_blas.py
+++ b/scipy/linalg/tests/test_blas.py
@@ -18,21 +18,30 @@
                            assert_array_almost_equal, assert_allclose)
 from pytest import raises as assert_raises
 
-from scipy.linalg import _fblas as fblas, get_blas_funcs
+from numpy import float32, float64, complex64, complex128, arange, triu, \
+                  tril, zeros, tril_indices, ones, mod, diag, append, eye, \
+                  nonzero
+
+from numpy.random import rand, seed
+from scipy.linalg import _fblas as fblas, get_blas_funcs, toeplitz, solve
 
 try:
     from scipy.linalg import _cblas as cblas
 except ImportError:
     cblas = None
 
+REAL_DTYPES = [float32, float64]
+COMPLEX_DTYPES = [complex64, complex128]
+DTYPES = REAL_DTYPES + COMPLEX_DTYPES
+
 
 def test_get_blas_funcs():
     # check that it returns Fortran code for arrays that are
     # fortran-ordered
     f1, f2, f3 = get_blas_funcs(
         ('axpy', 'axpy', 'axpy'),
-        (np.empty((2,2), dtype=np.complex64, order='F'),
-         np.empty((2,2), dtype=np.complex128, order='C'))
+        (np.empty((2, 2), dtype=np.complex64, order='F'),
+         np.empty((2, 2), dtype=np.complex128, order='C'))
         )
 
     # get_blas_funcs will choose libraries depending on most generic
@@ -59,8 +68,8 @@ def test_get_blas_funcs():
 
     # check safe complex upcasting
     f1 = get_blas_funcs('axpy',
-                        (np.empty((2,2), dtype=np.float64),
-                         np.empty((2,2), dtype=np.complex64))
+                        (np.empty((2, 2), dtype=np.float64),
+                         np.empty((2, 2), dtype=np.complex64))
                         )
     assert_equal(f1.typecode, 'z')
 
@@ -80,193 +89,192 @@ class TestCBLAS1Simple(object):
 
     def test_axpy(self):
         for p in 'sd':
-            f = getattr(cblas,p+'axpy',None)
+            f = getattr(cblas, p+'axpy', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f([1,2,3],[2,-1,3],a=5),[7,9,18])
+            assert_array_almost_equal(f([1, 2, 3], [2, -1, 3], a=5),
+                                      [7, 9, 18])
         for p in 'cz':
-            f = getattr(cblas,p+'axpy',None)
+            f = getattr(cblas, p+'axpy', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f([1,2j,3],[2,-1,3],a=5),[7,10j-1,18])
+            assert_array_almost_equal(f([1, 2j, 3], [2, -1, 3], a=5),
+                                      [7, 10j-1, 18])
 
 
 class TestFBLAS1Simple(object):
 
     def test_axpy(self):
         for p in 'sd':
-            f = getattr(fblas,p+'axpy',None)
+            f = getattr(fblas, p+'axpy', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f([1,2,3],[2,-1,3],a=5),[7,9,18])
+            assert_array_almost_equal(f([1, 2, 3], [2, -1, 3], a=5),
+                                      [7, 9, 18])
         for p in 'cz':
-            f = getattr(fblas,p+'axpy',None)
+            f = getattr(fblas, p+'axpy', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f([1,2j,3],[2,-1,3],a=5),[7,10j-1,18])
+            assert_array_almost_equal(f([1, 2j, 3], [2, -1, 3], a=5),
+                                      [7, 10j-1, 18])
 
     def test_copy(self):
         for p in 'sd':
-            f = getattr(fblas,p+'copy',None)
+            f = getattr(fblas, p+'copy', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f([3,4,5],[8]*3),[3,4,5])
+            assert_array_almost_equal(f([3, 4, 5], [8]*3), [3, 4, 5])
         for p in 'cz':
-            f = getattr(fblas,p+'copy',None)
+            f = getattr(fblas, p+'copy', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f([3,4j,5+3j],[8]*3),[3,4j,5+3j])
+            assert_array_almost_equal(f([3, 4j, 5+3j], [8]*3), [3, 4j, 5+3j])
 
     def test_asum(self):
         for p in 'sd':
-            f = getattr(fblas,p+'asum',None)
+            f = getattr(fblas, p+'asum', None)
             if f is None:
                 continue
-            assert_almost_equal(f([3,-4,5]),12)
-        for p in ['sc','dz']:
-            f = getattr(fblas,p+'asum',None)
+            assert_almost_equal(f([3, -4, 5]), 12)
+        for p in ['sc', 'dz']:
+            f = getattr(fblas, p+'asum', None)
             if f is None:
                 continue
-            assert_almost_equal(f([3j,-4,3-4j]),14)
+            assert_almost_equal(f([3j, -4, 3-4j]), 14)
 
     def test_dot(self):
         for p in 'sd':
-            f = getattr(fblas,p+'dot',None)
+            f = getattr(fblas, p+'dot', None)
             if f is None:
                 continue
-            assert_almost_equal(f([3,-4,5],[2,5,1]),-9)
+            assert_almost_equal(f([3, -4, 5], [2, 5, 1]), -9)
 
     def test_complex_dotu(self):
         for p in 'cz':
-            f = getattr(fblas,p+'dotu',None)
+            f = getattr(fblas, p+'dotu', None)
             if f is None:
                 continue
-            assert_almost_equal(f([3j,-4,3-4j],[2,3,1]),-9+2j)
+            assert_almost_equal(f([3j, -4, 3-4j], [2, 3, 1]), -9+2j)
 
     def test_complex_dotc(self):
         for p in 'cz':
-            f = getattr(fblas,p+'dotc',None)
+            f = getattr(fblas, p+'dotc', None)
             if f is None:
                 continue
-            assert_almost_equal(f([3j,-4,3-4j],[2,3j,1]),3-14j)
+            assert_almost_equal(f([3j, -4, 3-4j], [2, 3j, 1]), 3-14j)
 
     def test_nrm2(self):
         for p in 'sd':
-            f = getattr(fblas,p+'nrm2',None)
+            f = getattr(fblas, p+'nrm2', None)
             if f is None:
                 continue
-            assert_almost_equal(f([3,-4,5]),math.sqrt(50))
-        for p in ['c', 'z', 'sc','dz']:
-            f = getattr(fblas,p+'nrm2',None)
+            assert_almost_equal(f([3, -4, 5]), math.sqrt(50))
+        for p in ['c', 'z', 'sc', 'dz']:
+            f = getattr(fblas, p+'nrm2', None)
             if f is None:
                 continue
-            assert_almost_equal(f([3j,-4,3-4j]),math.sqrt(50))
+            assert_almost_equal(f([3j, -4, 3-4j]), math.sqrt(50))
 
     def test_scal(self):
         for p in 'sd':
-            f = getattr(fblas,p+'scal',None)
+            f = getattr(fblas, p+'scal', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(2,[3,-4,5]),[6,-8,10])
+            assert_array_almost_equal(f(2, [3, -4, 5]), [6, -8, 10])
         for p in 'cz':
-            f = getattr(fblas,p+'scal',None)
+            f = getattr(fblas, p+'scal', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(3j,[3j,-4,3-4j]),[-9,-12j,12+9j])
-        for p in ['cs','zd']:
-            f = getattr(fblas,p+'scal',None)
+            assert_array_almost_equal(f(3j, [3j, -4, 3-4j]), [-9, -12j, 12+9j])
+        for p in ['cs', 'zd']:
+            f = getattr(fblas, p+'scal', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(3,[3j,-4,3-4j]),[9j,-12,9-12j])
+            assert_array_almost_equal(f(3, [3j, -4, 3-4j]), [9j, -12, 9-12j])
 
     def test_swap(self):
         for p in 'sd':
-            f = getattr(fblas,p+'swap',None)
+            f = getattr(fblas, p+'swap', None)
             if f is None:
                 continue
-            x,y = [2,3,1],[-2,3,7]
-            x1,y1 = f(x,y)
-            assert_array_almost_equal(x1,y)
-            assert_array_almost_equal(y1,x)
+            x, y = [2, 3, 1], [-2, 3, 7]
+            x1, y1 = f(x, y)
+            assert_array_almost_equal(x1, y)
+            assert_array_almost_equal(y1, x)
         for p in 'cz':
-            f = getattr(fblas,p+'swap',None)
+            f = getattr(fblas, p+'swap', None)
             if f is None:
                 continue
-            x,y = [2,3j,1],[-2,3,7-3j]
-            x1,y1 = f(x,y)
-            assert_array_almost_equal(x1,y)
-            assert_array_almost_equal(y1,x)
+            x, y = [2, 3j, 1], [-2, 3, 7-3j]
+            x1, y1 = f(x, y)
+            assert_array_almost_equal(x1, y)
+            assert_array_almost_equal(y1, x)
 
     def test_amax(self):
         for p in 'sd':
-            f = getattr(fblas,'i'+p+'amax')
-            assert_equal(f([-2,4,3]),1)
+            f = getattr(fblas, 'i'+p+'amax')
+            assert_equal(f([-2, 4, 3]), 1)
         for p in 'cz':
-            f = getattr(fblas,'i'+p+'amax')
-            assert_equal(f([-5,4+3j,6]),1)
-    #XXX: need tests for rot,rotm,rotg,rotmg
+            f = getattr(fblas, 'i'+p+'amax')
+            assert_equal(f([-5, 4+3j, 6]), 1)
+    # XXX: need tests for rot,rotm,rotg,rotmg
 
 
 class TestFBLAS2Simple(object):
 
     def test_gemv(self):
         for p in 'sd':
-            f = getattr(fblas,p+'gemv',None)
+            f = getattr(fblas, p+'gemv', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(3,[[3]],[-4]),[-36])
-            assert_array_almost_equal(f(3,[[3]],[-4],3,[5]),[-21])
+            assert_array_almost_equal(f(3, [[3]], [-4]), [-36])
+            assert_array_almost_equal(f(3, [[3]], [-4], 3, [5]), [-21])
         for p in 'cz':
-            f = getattr(fblas,p+'gemv',None)
+            f = getattr(fblas, p+'gemv', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(3j,[[3-4j]],[-4]),[-48-36j])
-            assert_array_almost_equal(f(3j,[[3-4j]],[-4],3,[5j]),[-48-21j])
+            assert_array_almost_equal(f(3j, [[3-4j]], [-4]), [-48-36j])
+            assert_array_almost_equal(f(3j, [[3-4j]], [-4], 3, [5j]),
+                                      [-48-21j])
 
     def test_ger(self):
 
         for p in 'sd':
-            f = getattr(fblas,p+'ger',None)
+            f = getattr(fblas, p+'ger', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(1,[1,
-                                           2],[3,4]),[[3,4],[6,8]])
-            assert_array_almost_equal(f(2,[1,
-                                           2,
-                                           3],[3,4]),[[6,8],[12,16],[18,24]])
+            assert_array_almost_equal(f(1, [1, 2], [3, 4]), [[3, 4], [6, 8]])
+            assert_array_almost_equal(f(2, [1, 2, 3], [3, 4]),
+                                      [[6, 8], [12, 16], [18, 24]])
 
-            assert_array_almost_equal(f(1,[1,
-                                           2],[3,4],
-                                        a=[[1,2],[3,4]]
-                                        ),[[4,6],[9,12]])
+            assert_array_almost_equal(f(1, [1, 2], [3, 4],
+                                        a=[[1, 2], [3, 4]]), [[4, 6], [9, 12]])
 
         for p in 'cz':
-            f = getattr(fblas,p+'geru',None)
+            f = getattr(fblas, p+'geru', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(1,[1j,
-                                           2],[3,4]),[[3j,4j],[6,8]])
-            assert_array_almost_equal(f(-2,[1j,
-                                           2j,
-                                           3j],[3j,4j]),[[6,8],[12,16],[18,24]])
+            assert_array_almost_equal(f(1, [1j, 2], [3, 4]),
+                                      [[3j, 4j], [6, 8]])
+            assert_array_almost_equal(f(-2, [1j, 2j, 3j], [3j, 4j]),
+                                      [[6, 8], [12, 16], [18, 24]])
 
         for p in 'cz':
             for name in ('ger', 'gerc'):
-                f = getattr(fblas,p+name,None)
+                f = getattr(fblas, p+name, None)
                 if f is None:
                     continue
-                assert_array_almost_equal(f(1,[1j,
-                                               2],[3,4]),[[3j,4j],[6,8]])
-                assert_array_almost_equal(f(2,[1j,
-                                               2j,
-                                               3j],[3j,4j]),[[6,8],[12,16],[18,24]])
+                assert_array_almost_equal(f(1, [1j, 2], [3, 4]),
+                                          [[3j, 4j], [6, 8]])
+                assert_array_almost_equal(f(2, [1j, 2j, 3j], [3j, 4j]),
+                                          [[6, 8], [12, 16], [18, 24]])
 
     def test_syr_her(self):
         x = np.arange(1, 5, dtype='d')
         resx = np.triu(x[:, np.newaxis] * x)
         resx_reverse = np.triu(x[::-1, np.newaxis] * x[::-1])
 
-        y = np.linspace(0,8.5,17,endpoint=False)
+        y = np.linspace(0, 8.5, 17, endpoint=False)
 
         z = np.arange(1, 9, dtype='d').view('D')
         resz = np.triu(z[:, np.newaxis] * z)
@@ -275,8 +283,8 @@ def test_syr_her(self):
         rehz_reverse = np.triu(z[::-1, np.newaxis] * z[::-1].conj())
 
         w = np.c_[np.zeros(4), z, np.zeros(4)].ravel()
-     
-        for p, rtol in zip('sd',[1e-7,1e-14]):
+
+        for p, rtol in zip('sd', [1e-7, 1e-14]):
             f = getattr(fblas, p+'syr', None)
             if f is None:
                 continue
@@ -285,9 +293,9 @@ def test_syr_her(self):
             assert_allclose(f(1.0, y, incx=2, offx=2, n=4), resx, rtol=rtol)
             # negative increments imply reversed vectors in blas
             assert_allclose(f(1.0, y, incx=-2, offx=2, n=4),
-                resx_reverse, rtol=rtol)
+                            resx_reverse, rtol=rtol)
 
-            a = np.zeros((4,4), 'f' if p == 's' else 'd', 'F')
+            a = np.zeros((4, 4), 'f' if p == 's' else 'd', 'F')
             b = f(1.0, x, a=a, overwrite_a=True)
             assert_allclose(a, resx, rtol=rtol)
 
@@ -301,9 +309,9 @@ def test_syr_her(self):
             assert_raises(Exception, f, 1.0, x, n=-2)
             assert_raises(Exception, f, 1.0, x, n=5)
             assert_raises(Exception, f, 1.0, x, lower=2)
-            assert_raises(Exception, f, 1.0, x, a=np.zeros((2,2), 'd', 'F'))
-        
-        for p, rtol in zip('cz',[1e-7,1e-14]):
+            assert_raises(Exception, f, 1.0, x, a=np.zeros((2, 2), 'd', 'F'))
+
+        for p, rtol in zip('cz', [1e-7, 1e-14]):
             f = getattr(fblas, p+'syr', None)
             if f is None:
                 continue
@@ -312,9 +320,9 @@ def test_syr_her(self):
             assert_allclose(f(1.0, w, incx=3, offx=1, n=4), resz, rtol=rtol)
             # negative increments imply reversed vectors in blas
             assert_allclose(f(1.0, w, incx=-3, offx=1, n=4),
-                resz_reverse, rtol=rtol)
+                            resz_reverse, rtol=rtol)
 
-            a = np.zeros((4,4), 'F' if p == 'c' else 'D', 'F')
+            a = np.zeros((4, 4), 'F' if p == 'c' else 'D', 'F')
             b = f(1.0, z, a=a, overwrite_a=True)
             assert_allclose(a, resz, rtol=rtol)
 
@@ -328,9 +336,9 @@ def test_syr_her(self):
             assert_raises(Exception, f, 1.0, x, n=-2)
             assert_raises(Exception, f, 1.0, x, n=5)
             assert_raises(Exception, f, 1.0, x, lower=2)
-            assert_raises(Exception, f, 1.0, x, a=np.zeros((2,2), 'd', 'F'))
- 
-        for p, rtol in zip('cz',[1e-7,1e-14]):
+            assert_raises(Exception, f, 1.0, x, a=np.zeros((2, 2), 'd', 'F'))
+
+        for p, rtol in zip('cz', [1e-7, 1e-14]):
             f = getattr(fblas, p+'her', None)
             if f is None:
                 continue
@@ -339,9 +347,9 @@ def test_syr_her(self):
             assert_allclose(f(1.0, w, incx=3, offx=1, n=4), rehz, rtol=rtol)
             # negative increments imply reversed vectors in blas
             assert_allclose(f(1.0, w, incx=-3, offx=1, n=4),
-                rehz_reverse, rtol=rtol)
+                            rehz_reverse, rtol=rtol)
 
-            a = np.zeros((4,4), 'F' if p == 'c' else 'D', 'F')
+            a = np.zeros((4, 4), 'F' if p == 'c' else 'D', 'F')
             b = f(1.0, z, a=a, overwrite_a=True)
             assert_allclose(a, rehz, rtol=rtol)
 
@@ -355,7 +363,7 @@ def test_syr_her(self):
             assert_raises(Exception, f, 1.0, x, n=-2)
             assert_raises(Exception, f, 1.0, x, n=5)
             assert_raises(Exception, f, 1.0, x, lower=2)
-            assert_raises(Exception, f, 1.0, x, a=np.zeros((2,2), 'd', 'F'))
+            assert_raises(Exception, f, 1.0, x, a=np.zeros((2, 2), 'd', 'F'))
 
     def test_syr2(self):
         x = np.arange(1, 5, dtype='d')
@@ -364,25 +372,25 @@ def test_syr2(self):
         resxy_reverse = np.triu(x[::-1, np.newaxis] * y[::-1]
                                 + y[::-1, np.newaxis] * x[::-1])
 
-        q = np.linspace(0,8.5,17,endpoint=False)
+        q = np.linspace(0, 8.5, 17, endpoint=False)
 
-        for p, rtol in zip('sd',[1e-7,1e-14]):
+        for p, rtol in zip('sd', [1e-7, 1e-14]):
             f = getattr(fblas, p+'syr2', None)
             if f is None:
                 continue
             assert_allclose(f(1.0, x, y), resxy, rtol=rtol)
-            assert_allclose(f(1.0, x, y, n=3), resxy[:3,:3], rtol=rtol)
+            assert_allclose(f(1.0, x, y, n=3), resxy[:3, :3], rtol=rtol)
             assert_allclose(f(1.0, x, y, lower=True), resxy.T, rtol=rtol)
 
             assert_allclose(f(1.0, q, q, incx=2, offx=2, incy=2, offy=10),
                             resxy, rtol=rtol)
             assert_allclose(f(1.0, q, q, incx=2, offx=2, incy=2, offy=10, n=3),
-                            resxy[:3,:3], rtol=rtol)
+                            resxy[:3, :3], rtol=rtol)
             # negative increments imply reversed vectors in blas
             assert_allclose(f(1.0, q, q, incx=-2, offx=2, incy=-2, offy=10),
                             resxy_reverse, rtol=rtol)
 
-            a = np.zeros((4,4), 'f' if p == 's' else 'd', 'F')
+            a = np.zeros((4, 4), 'f' if p == 's' else 'd', 'F')
             b = f(1.0, x, y, a=a, overwrite_a=True)
             assert_allclose(a, resxy, rtol=rtol)
 
@@ -399,8 +407,9 @@ def test_syr2(self):
             assert_raises(Exception, f, 1.0, x, y, n=-2)
             assert_raises(Exception, f, 1.0, x, y, n=5)
             assert_raises(Exception, f, 1.0, x, y, lower=2)
-            assert_raises(Exception, f, 1.0, x, y, a=np.zeros((2,2), 'd', 'F'))
-  
+            assert_raises(Exception, f, 1.0, x, y,
+                          a=np.zeros((2, 2), 'd', 'F'))
+
     def test_her2(self):
         x = np.arange(1, 9, dtype='d').view('D')
         y = np.arange(9, 17, dtype='d').view('D')
@@ -414,23 +423,24 @@ def test_her2(self):
         u = np.c_[np.zeros(4), x, np.zeros(4)].ravel()
         v = np.c_[np.zeros(4), y, np.zeros(4)].ravel()
 
-        for p, rtol in zip('cz',[1e-7,1e-14]):
+        for p, rtol in zip('cz', [1e-7, 1e-14]):
             f = getattr(fblas, p+'her2', None)
             if f is None:
                 continue
             assert_allclose(f(1.0, x, y), resxy, rtol=rtol)
-            assert_allclose(f(1.0, x, y, n=3), resxy[:3,:3], rtol=rtol)
-            assert_allclose(f(1.0, x, y, lower=True), resxy.T.conj(), rtol=rtol)
+            assert_allclose(f(1.0, x, y, n=3), resxy[:3, :3], rtol=rtol)
+            assert_allclose(f(1.0, x, y, lower=True), resxy.T.conj(),
+                            rtol=rtol)
 
             assert_allclose(f(1.0, u, v, incx=3, offx=1, incy=3, offy=1),
                             resxy, rtol=rtol)
             assert_allclose(f(1.0, u, v, incx=3, offx=1, incy=3, offy=1, n=3),
-                            resxy[:3,:3], rtol=rtol)
+                            resxy[:3, :3], rtol=rtol)
             # negative increments imply reversed vectors in blas
             assert_allclose(f(1.0, u, v, incx=-3, offx=1, incy=-3, offy=1),
                             resxy_reverse, rtol=rtol)
 
-            a = np.zeros((4,4), 'F' if p == 'c' else 'D', 'F')
+            a = np.zeros((4, 4), 'F' if p == 'c' else 'D', 'F')
             b = f(1.0, x, y, a=a, overwrite_a=True)
             assert_allclose(a, resxy, rtol=rtol)
 
@@ -447,24 +457,359 @@ def test_her2(self):
             assert_raises(Exception, f, 1.0, x, y, n=-2)
             assert_raises(Exception, f, 1.0, x, y, n=5)
             assert_raises(Exception, f, 1.0, x, y, lower=2)
-            assert_raises(Exception, f, 1.0, x, y, a=np.zeros((2,2), 'd', 'F'))
- 
+            assert_raises(Exception, f, 1.0, x, y,
+                          a=np.zeros((2, 2), 'd', 'F'))
+
+    def test_gbmv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 7
+            m = 5
+            kl = 1
+            ku = 2
+            # fake a banded matrix via toeplitz
+            A = toeplitz(append(rand(kl+1), zeros(m-kl-1)),
+                         append(rand(ku+1), zeros(n-ku-1)))
+            A = A.astype(dtype)
+            Ab = zeros((kl+ku+1, n), dtype=dtype)
+
+            # Form the banded storage
+            Ab[2, :5] = A[0, 0]  # diag
+            Ab[1, 1:6] = A[0, 1]  # sup1
+            Ab[0, 2:7] = A[0, 2]  # sup2
+            Ab[3, :4] = A[1, 0]  # sub1
+
+            x = rand(n).astype(dtype)
+            y = rand(m).astype(dtype)
+            alpha, beta = dtype(3), dtype(-5)
+
+            func, = get_blas_funcs(('gbmv',), dtype=dtype)
+            y1 = func(m=m, n=n, ku=ku, kl=kl, alpha=alpha, a=Ab,
+                      x=x, y=y, beta=beta)
+            y2 = alpha * A.dot(x) + beta * y
+            assert_array_almost_equal(y1, y2)
+
+    def test_sbmv_hbmv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 6
+            k = 2
+            A = zeros((n, n), dtype=dtype)
+            Ab = zeros((k+1, n), dtype=dtype)
+
+            # Form the array and its packed banded storage
+            A[arange(n), arange(n)] = rand(n)
+            for ind2 in range(1, k+1):
+                temp = rand(n-ind2)
+                A[arange(n-ind2), arange(ind2, n)] = temp
+                Ab[-1-ind2, ind2:] = temp
+            A = A.astype(dtype)
+            A = A + A.T if ind < 2 else A + A.conj().T
+            Ab[-1, :] = diag(A)
+            x = rand(n).astype(dtype)
+            y = rand(n).astype(dtype)
+            alpha, beta = dtype(1.25), dtype(3)
+
+            if ind > 1:
+                func, = get_blas_funcs(('hbmv',), dtype=dtype)
+            else:
+                func, = get_blas_funcs(('sbmv',), dtype=dtype)
+            y1 = func(k=k, alpha=alpha, a=Ab, x=x, y=y, beta=beta)
+            y2 = alpha * A.dot(x) + beta * y
+            assert_array_almost_equal(y1, y2)
+
+    def test_spmv_hpmv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES+COMPLEX_DTYPES):
+            n = 3
+            A = rand(n, n).astype(dtype)
+            if ind > 1:
+                A += rand(n, n)*1j
+            A = A.astype(dtype)
+            A = A + A.T if ind < 4 else A + A.conj().T
+            c, r = tril_indices(n)
+            Ap = A[r, c]
+            x = rand(n).astype(dtype)
+            y = rand(n).astype(dtype)
+            xlong = arange(2*n).astype(dtype)
+            ylong = ones(2*n).astype(dtype)
+            alpha, beta = dtype(1.25), dtype(2)
+
+            if ind > 3:
+                func, = get_blas_funcs(('hpmv',), dtype=dtype)
+            else:
+                func, = get_blas_funcs(('spmv',), dtype=dtype)
+            y1 = func(n=n, alpha=alpha, ap=Ap, x=x, y=y, beta=beta)
+            y2 = alpha * A.dot(x) + beta * y
+            assert_array_almost_equal(y1, y2)
+
+            # Test inc and offsets
+            y1 = func(n=n-1, alpha=alpha, beta=beta, x=xlong, y=ylong, ap=Ap,
+                      incx=2, incy=2, offx=n, offy=n)
+            y2 = (alpha * A[:-1, :-1]).dot(xlong[3::2]) + beta * ylong[3::2]
+            assert_array_almost_equal(y1[3::2], y2)
+            assert_almost_equal(y1[4], ylong[4])
+
+    def test_spr_hpr(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES+COMPLEX_DTYPES):
+            n = 3
+            A = rand(n, n).astype(dtype)
+            if ind > 1:
+                A += rand(n, n)*1j
+            A = A.astype(dtype)
+            A = A + A.T if ind < 4 else A + A.conj().T
+            c, r = tril_indices(n)
+            Ap = A[r, c]
+            x = rand(n).astype(dtype)
+            alpha = (DTYPES+COMPLEX_DTYPES)[mod(ind, 4)](2.5)
+
+            if ind > 3:
+                func, = get_blas_funcs(('hpr',), dtype=dtype)
+                y2 = alpha * x[:, None].dot(x[None, :].conj()) + A
+            else:
+                func, = get_blas_funcs(('spr',), dtype=dtype)
+                y2 = alpha * x[:, None].dot(x[None, :]) + A
+
+            y1 = func(n=n, alpha=alpha, ap=Ap, x=x)
+            y1f = zeros((3, 3), dtype=dtype)
+            y1f[r, c] = y1
+            y1f[c, r] = y1.conj() if ind > 3 else y1
+            assert_array_almost_equal(y1f, y2)
+
+    def test_spr2_hpr2(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 3
+            A = rand(n, n).astype(dtype)
+            if ind > 1:
+                A += rand(n, n)*1j
+            A = A.astype(dtype)
+            A = A + A.T if ind < 2 else A + A.conj().T
+            c, r = tril_indices(n)
+            Ap = A[r, c]
+            x = rand(n).astype(dtype)
+            y = rand(n).astype(dtype)
+            alpha = dtype(2)
+
+            if ind > 1:
+                func, = get_blas_funcs(('hpr2',), dtype=dtype)
+            else:
+                func, = get_blas_funcs(('spr2',), dtype=dtype)
+
+            u = alpha.conj() * x[:, None].dot(y[None, :].conj())
+            y2 = A + u + u.conj().T
+            y1 = func(n=n, alpha=alpha, x=x, y=y, ap=Ap)
+            y1f = zeros((3, 3), dtype=dtype)
+            y1f[r, c] = y1
+            y1f[[1, 2, 2], [0, 0, 1]] = y1[[1, 3, 4]].conj()
+            assert_array_almost_equal(y1f, y2)
+
+    def test_tbmv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 10
+            k = 3
+            x = rand(n).astype(dtype)
+            A = zeros((n, n), dtype=dtype)
+            # Banded upper triangular array
+            for sup in range(k+1):
+                A[arange(n-sup), arange(sup, n)] = rand(n-sup)
+
+            # Add complex parts for c,z
+            if ind > 1:
+                A[nonzero(A)] += 1j * rand((k+1)*n-(k*(k+1)//2)).astype(dtype)
+
+            # Form the banded storage
+            Ab = zeros((k+1, n), dtype=dtype)
+            for row in range(k+1):
+                Ab[-row-1, row:] = diag(A, k=row)
+            func, = get_blas_funcs(('tbmv',), dtype=dtype)
+
+            y1 = func(k=k, a=Ab, x=x)
+            y2 = A.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(k=k, a=Ab, x=x, diag=1)
+            A[arange(n), arange(n)] = dtype(1)
+            y2 = A.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(k=k, a=Ab, x=x, diag=1, trans=1)
+            y2 = A.T.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(k=k, a=Ab, x=x, diag=1, trans=2)
+            y2 = A.conj().T.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+    def test_tbsv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 6
+            k = 3
+            x = rand(n).astype(dtype)
+            A = zeros((n, n), dtype=dtype)
+            # Banded upper triangular array
+            for sup in range(k+1):
+                A[arange(n-sup), arange(sup, n)] = rand(n-sup)
+
+            # Add complex parts for c,z
+            if ind > 1:
+                A[nonzero(A)] += 1j * rand((k+1)*n-(k*(k+1)//2)).astype(dtype)
+
+            # Form the banded storage
+            Ab = zeros((k+1, n), dtype=dtype)
+            for row in range(k+1):
+                Ab[-row-1, row:] = diag(A, k=row)
+            func, = get_blas_funcs(('tbsv',), dtype=dtype)
+
+            y1 = func(k=k, a=Ab, x=x)
+            y2 = solve(A, x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(k=k, a=Ab, x=x, diag=1)
+            A[arange(n), arange(n)] = dtype(1)
+            y2 = solve(A, x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(k=k, a=Ab, x=x, diag=1, trans=1)
+            y2 = solve(A.T, x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(k=k, a=Ab, x=x, diag=1, trans=2)
+            y2 = solve(A.conj().T, x)
+            assert_array_almost_equal(y1, y2)
+
+    def test_tpmv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 10
+            x = rand(n).astype(dtype)
+            # Upper triangular array
+            A = triu(rand(n, n)) if ind < 2 else triu(rand(n, n)+rand(n, n)*1j)
+            # Form the packed storage
+            c, r = tril_indices(n)
+            Ap = A[r, c]
+            func, = get_blas_funcs(('tpmv',), dtype=dtype)
+
+            y1 = func(n=n, ap=Ap, x=x)
+            y2 = A.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(n=n, ap=Ap, x=x, diag=1)
+            A[arange(n), arange(n)] = dtype(1)
+            y2 = A.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(n=n, ap=Ap, x=x, diag=1, trans=1)
+            y2 = A.T.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(n=n, ap=Ap, x=x, diag=1, trans=2)
+            y2 = A.conj().T.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+    def test_tpsv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 10
+            x = rand(n).astype(dtype)
+            # Upper triangular array
+            A = triu(rand(n, n)) if ind < 2 else triu(rand(n, n)+rand(n, n)*1j)
+            A += eye(n)
+            # Form the packed storage
+            c, r = tril_indices(n)
+            Ap = A[r, c]
+            func, = get_blas_funcs(('tpsv',), dtype=dtype)
+
+            y1 = func(n=n, ap=Ap, x=x)
+            y2 = solve(A, x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(n=n, ap=Ap, x=x, diag=1)
+            A[arange(n), arange(n)] = dtype(1)
+            y2 = solve(A, x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(n=n, ap=Ap, x=x, diag=1, trans=1)
+            y2 = solve(A.T, x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(n=n, ap=Ap, x=x, diag=1, trans=2)
+            y2 = solve(A.conj().T, x)
+            assert_array_almost_equal(y1, y2)
+
+    def test_trmv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 3
+            A = (rand(n, n)+eye(n)).astype(dtype)
+            x = rand(3).astype(dtype)
+            func, = get_blas_funcs(('trmv',), dtype=dtype)
+
+            y1 = func(a=A, x=x)
+            y2 = triu(A).dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(a=A, x=x, diag=1)
+            A[arange(n), arange(n)] = dtype(1)
+            y2 = triu(A).dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(a=A, x=x, diag=1, trans=1)
+            y2 = triu(A).T.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(a=A, x=x, diag=1, trans=2)
+            y2 = triu(A).conj().T.dot(x)
+            assert_array_almost_equal(y1, y2)
+
+    def test_trsv(self):
+        seed(1234)
+        for ind, dtype in enumerate(DTYPES):
+            n = 15
+            A = (rand(n, n)+eye(n)).astype(dtype)
+            x = rand(n).astype(dtype)
+            func, = get_blas_funcs(('trsv',), dtype=dtype)
+
+            y1 = func(a=A, x=x)
+            y2 = solve(triu(A), x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(a=A, x=x, lower=1)
+            y2 = solve(tril(A), x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(a=A, x=x, diag=1)
+            A[arange(n), arange(n)] = dtype(1)
+            y2 = solve(triu(A), x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(a=A, x=x, diag=1, trans=1)
+            y2 = solve(triu(A).T, x)
+            assert_array_almost_equal(y1, y2)
+
+            y1 = func(a=A, x=x, diag=1, trans=2)
+            y2 = solve(triu(A).conj().T, x)
+            assert_array_almost_equal(y1, y2)
+
 
 class TestFBLAS3Simple(object):
 
     def test_gemm(self):
         for p in 'sd':
-            f = getattr(fblas,p+'gemm',None)
+            f = getattr(fblas, p+'gemm', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(3,[3],[-4]),[[-36]])
-            assert_array_almost_equal(f(3,[3],[-4],3,[5]),[-21])
+            assert_array_almost_equal(f(3, [3], [-4]), [[-36]])
+            assert_array_almost_equal(f(3, [3], [-4], 3, [5]), [-21])
         for p in 'cz':
-            f = getattr(fblas,p+'gemm',None)
+            f = getattr(fblas, p+'gemm', None)
             if f is None:
                 continue
-            assert_array_almost_equal(f(3j,[3-4j],[-4]),[[-48-36j]])
-            assert_array_almost_equal(f(3j,[3-4j],[-4],3,[5j]),[-48-21j])
+            assert_array_almost_equal(f(3j, [3-4j], [-4]), [[-48-36j]])
+            assert_array_almost_equal(f(3j, [3-4j], [-4], 3, [5j]), [-48-21j])
 
 
 def _get_func(func, ps='sdzc'):
@@ -483,7 +828,7 @@ def setup_method(self):
                            [0., 1.]])
         self.b = np.array([[1., 0., 3.],
                            [0., -1., 2.]])
-        self.c = np.ones((2,3))
+        self.c = np.ones((2, 3))
         self.t = np.array([[2., -1., 8.],
                            [3., 0., 9.]])
 
@@ -495,14 +840,15 @@ def test_symm(self):
             res = f(a=self.a.T, b=self.b, lower=1, c=self.c, alpha=1., beta=1.)
             assert_array_almost_equal(res, self.t)
 
-            res = f(a=self.a, b=self.b.T, side=1, c=self.c.T, alpha=1., beta=1.)
+            res = f(a=self.a, b=self.b.T, side=1, c=self.c.T,
+                    alpha=1., beta=1.)
             assert_array_almost_equal(res, self.t.T)
 
     def test_summ_wrong_side(self):
         f = getattr(fblas, 'dsymm', None)
         if f is not None:
-            assert_raises(Exception, f, **{'a': self.a, 'b': self.b, 'alpha': 1,
-                    'side': 1})
+            assert_raises(Exception, f, **{'a': self.a, 'b': self.b,
+                                           'alpha': 1, 'side': 1})
             # `side=1` means C <- B*A, hence shapes of A and B are to be
             #  compatible. Otherwise, f2py exception is raised
 
@@ -511,7 +857,7 @@ def test_symm_wrong_uplo(self):
         wrong value for `lower` (default is lower=0, meaning upper triangle)
         gives a wrong result.
         """
-        f = getattr(fblas,'dsymm',None)
+        f = getattr(fblas, 'dsymm', None)
         if f is not None:
             res = f(a=self.a, b=self.b, c=self.c, alpha=1., beta=1.)
             assert np.allclose(res, self.t)
@@ -546,13 +892,14 @@ def test_syrk(self):
             c = f(a=self.a, alpha=1., trans=1)
             assert_array_almost_equal(np.triu(c), np.triu(self.tt))
 
-    #prints '0-th dimension must be fixed to 3 but got 5', FIXME: suppress?
+    # prints '0-th dimension must be fixed to 3 but got 5',
+    # FIXME: suppress?
     # FIXME: how to catch the _fblas.error?
     def test_syrk_wrong_c(self):
         f = getattr(fblas, 'dsyrk', None)
         if f is not None:
             assert_raises(Exception, f, **{'a': self.a, 'alpha': 1.,
-                    'c': np.ones((5, 8))})
+                                           'c': np.ones((5, 8))})
         # if C is supplied, it must have compatible dimensions
 
 
@@ -585,12 +932,14 @@ def test_syr2k(self):
             c = f(a=self.a, b=self.b, alpha=1., trans=1)
             assert_array_almost_equal(np.triu(c), np.triu(self.tt))
 
-    #prints '0-th dimension must be fixed to 3 but got 5', FIXME: suppress?
+    # prints '0-th dimension must be fixed to 3 but got 5', FIXME: suppress?
     def test_syr2k_wrong_c(self):
         f = getattr(fblas, 'dsyr2k', None)
         if f is not None:
-            assert_raises(Exception, f, **{'a': self.a, 'b': self.b, 'alpha': 1.,
-                    'c': np.zeros((15, 8))})
+            assert_raises(Exception, f, **{'a': self.a,
+                                           'b': self.b,
+                                           'alpha': 1.,
+                                           'c': np.zeros((15, 8))})
         # if C is supplied, it must have compatible dimensions
 
 
@@ -645,8 +994,9 @@ def test_ab(self):
         f = getattr(fblas, 'dtrmm', None)
         if f is not None:
             result = f(1., self.a, self.b)
+            # default a is upper triangular
             expected = np.array([[13., 16., -5.],
-                                 [5., 6., -2.]])  # default a is upper triangular
+                                 [5., 6., -2.]])
             assert_array_almost_equal(result, expected)
 
     def test_ab_lower(self):
@@ -676,3 +1026,52 @@ def test_b_overwrites(self):
                     np.may_share_memory(bcopy, result) is True)
             assert_array_almost_equal(bcopy, result)
 
+
+def test_trsm():
+    seed(1234)
+    for ind, dtype in enumerate(DTYPES):
+        func, = get_blas_funcs(('trsm',), dtype=dtype)
+
+        # Test protection against size mismatches
+        A = rand(4, 5).astype(dtype)
+        B = rand(4, 4).astype(dtype)
+        alpha = dtype(1)
+        assert_raises(Exception, func, alpha, A, B)
+        assert_raises(Exception, func, alpha, A.T, B)
+
+        n = 8
+        m = 7
+        alpha = dtype(-2.5)
+        A = (rand(m, m) if ind < 2 else rand(m, m) + rand(m, m)*1j) + eye(m)
+        A = A.astype(dtype)
+        Au = triu(A)
+        Al = tril(A)
+        B1 = rand(m, n).astype(dtype)
+        B2 = rand(n, m).astype(dtype)
+
+        x1 = func(alpha=alpha, a=A, b=B1)
+        assert_equal(B1.shape, x1.shape)
+        x2 = solve(Au, alpha*B1)
+        assert_array_almost_equal(x1, x2)
+
+        x1 = func(alpha=alpha, a=A, b=B1, trans_a=1)
+        x2 = solve(Au.T, alpha*B1)
+        assert_array_almost_equal(x1, x2)
+
+        x1 = func(alpha=alpha, a=A, b=B1, trans_a=2)
+        x2 = solve(Au.conj().T, alpha*B1)
+        assert_array_almost_equal(x1, x2)
+
+        x1 = func(alpha=alpha, a=A, b=B1, diag=1)
+        Au[arange(m), arange(m)] = dtype(1)
+        x2 = solve(Au, alpha*B1)
+        assert_array_almost_equal(x1, x2)
+
+        x1 = func(alpha=alpha, a=A, b=B2, diag=1, side=1)
+        x2 = solve(Au.conj().T, alpha*B2.conj().T)
+        assert_array_almost_equal(x1, x2.conj().T)
+
+        x1 = func(alpha=alpha, a=A, b=B2, diag=1, side=1, lower=1)
+        Al[arange(m), arange(m)] = dtype(1)
+        x2 = solve(Al.conj().T, alpha*B2.conj().T)
+        assert_array_almost_equal(x1, x2.conj().T)
diff --git a/scipy/linalg/tests/test_fblas.py b/scipy/linalg/tests/test_fblas.py
--- a/scipy/linalg/tests/test_fblas.py
+++ b/scipy/linalg/tests/test_fblas.py
@@ -10,6 +10,7 @@
 
 from numpy import float32, float64, complex64, complex128, arange, array, \
                   zeros, shape, transpose, newaxis, common_type, conjugate
+
 from scipy.linalg import _fblas as fblas
 
 from scipy._lib.six import xrange
@@ -17,7 +18,6 @@
 from numpy.testing import assert_array_equal, \
     assert_allclose, assert_array_almost_equal, assert_
 
-
 # decimal accuracy to require between Python and LAPACK/BLAS calculations
 accuracy = 5
 
@@ -28,7 +28,7 @@
 def matrixmultiply(a, b):
     if len(b.shape) == 1:
         b_is_vector = True
-        b = b[:,newaxis]
+        b = b[:, newaxis]
     else:
         b_is_vector = False
     assert_(a.shape[1] == b.shape[0])
@@ -37,75 +37,76 @@ def matrixmultiply(a, b):
         for j in xrange(b.shape[1]):
             s = 0
             for k in xrange(a.shape[1]):
-                s += a[i,k] * b[k, j]
-            c[i,j] = s
+                s += a[i, k] * b[k, j]
+            c[i, j] = s
     if b_is_vector:
         c = c.reshape((a.shape[0],))
     return c
 
 ##################################################
-### Test blas ?axpy
+# Test blas ?axpy
 
 
 class BaseAxpy(object):
     ''' Mixin class for axpy tests '''
 
     def test_default_a(self):
-        x = arange(3.,dtype=self.dtype)
-        y = arange(3.,dtype=x.dtype)
+        x = arange(3., dtype=self.dtype)
+        y = arange(3., dtype=x.dtype)
         real_y = x*1.+y
-        y = self.blas_func(x,y)
-        assert_array_equal(real_y,y)
+        y = self.blas_func(x, y)
+        assert_array_equal(real_y, y)
 
     def test_simple(self):
-        x = arange(3.,dtype=self.dtype)
-        y = arange(3.,dtype=x.dtype)
+        x = arange(3., dtype=self.dtype)
+        y = arange(3., dtype=x.dtype)
         real_y = x*3.+y
-        y = self.blas_func(x,y,a=3.)
-        assert_array_equal(real_y,y)
+        y = self.blas_func(x, y, a=3.)
+        assert_array_equal(real_y, y)
 
     def test_x_stride(self):
-        x = arange(6.,dtype=self.dtype)
-        y = zeros(3,x.dtype)
-        y = arange(3.,dtype=x.dtype)
+        x = arange(6., dtype=self.dtype)
+        y = zeros(3, x.dtype)
+        y = arange(3., dtype=x.dtype)
         real_y = x[::2]*3.+y
-        y = self.blas_func(x,y,a=3.,n=3,incx=2)
-        assert_array_equal(real_y,y)
+        y = self.blas_func(x, y, a=3., n=3, incx=2)
+        assert_array_equal(real_y, y)
 
     def test_y_stride(self):
-        x = arange(3.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(3., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         real_y = x*3.+y[::2]
-        y = self.blas_func(x,y,a=3.,n=3,incy=2)
-        assert_array_equal(real_y,y[::2])
+        y = self.blas_func(x, y, a=3., n=3, incy=2)
+        assert_array_equal(real_y, y[::2])
 
     def test_x_and_y_stride(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         real_y = x[::4]*3.+y[::2]
-        y = self.blas_func(x,y,a=3.,n=3,incx=4,incy=2)
-        assert_array_equal(real_y,y[::2])
+        y = self.blas_func(x, y, a=3., n=3, incx=4, incy=2)
+        assert_array_equal(real_y, y[::2])
 
     def test_x_bad_size(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         try:
-            self.blas_func(x,y,n=4,incx=5)
+            self.blas_func(x, y, n=4, incx=5)
         except:  # what kind of error should be caught?
             return
         # should catch error and never get here
         assert_(0)
 
     def test_y_bad_size(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         try:
-            self.blas_func(x,y,n=3,incy=5)
+            self.blas_func(x, y, n=3, incy=5)
         except:  # what kind of error should be caught?
             return
         # should catch error and never get here
         assert_(0)
 
+
 try:
     class TestSaxpy(BaseAxpy):
         blas_func = fblas.saxpy
@@ -119,6 +120,7 @@ class TestDaxpy(BaseAxpy):
     blas_func = fblas.daxpy
     dtype = float64
 
+
 try:
     class TestCaxpy(BaseAxpy):
         blas_func = fblas.caxpy
@@ -134,33 +136,34 @@ class TestZaxpy(BaseAxpy):
 
 
 ##################################################
-### Test blas ?scal
+# Test blas ?scal
 
 class BaseScal(object):
     ''' Mixin class for scal testing '''
 
     def test_simple(self):
-        x = arange(3.,dtype=self.dtype)
+        x = arange(3., dtype=self.dtype)
         real_x = x*3.
-        x = self.blas_func(3.,x)
-        assert_array_equal(real_x,x)
+        x = self.blas_func(3., x)
+        assert_array_equal(real_x, x)
 
     def test_x_stride(self):
-        x = arange(6.,dtype=self.dtype)
+        x = arange(6., dtype=self.dtype)
         real_x = x.copy()
-        real_x[::2] = x[::2]*array(3.,self.dtype)
-        x = self.blas_func(3.,x,n=3,incx=2)
-        assert_array_equal(real_x,x)
+        real_x[::2] = x[::2]*array(3., self.dtype)
+        x = self.blas_func(3., x, n=3, incx=2)
+        assert_array_equal(real_x, x)
 
     def test_x_bad_size(self):
-        x = arange(12.,dtype=self.dtype)
+        x = arange(12., dtype=self.dtype)
         try:
-            self.blas_func(2.,x,n=4,incx=5)
+            self.blas_func(2., x, n=4, incx=5)
         except:  # what kind of error should be caught?
             return
         # should catch error and never get here
         assert_(0)
 
+
 try:
     class TestSscal(BaseScal):
         blas_func = fblas.sscal
@@ -174,6 +177,7 @@ class TestDscal(BaseScal):
     blas_func = fblas.dscal
     dtype = float64
 
+
 try:
     class TestCscal(BaseScal):
         blas_func = fblas.cscal
@@ -189,50 +193,50 @@ class TestZscal(BaseScal):
 
 
 ##################################################
-### Test blas ?copy
+# Test blas ?copy
 
 class BaseCopy(object):
     ''' Mixin class for copy testing '''
 
     def test_simple(self):
-        x = arange(3.,dtype=self.dtype)
-        y = zeros(shape(x),x.dtype)
-        y = self.blas_func(x,y)
-        assert_array_equal(x,y)
+        x = arange(3., dtype=self.dtype)
+        y = zeros(shape(x), x.dtype)
+        y = self.blas_func(x, y)
+        assert_array_equal(x, y)
 
     def test_x_stride(self):
-        x = arange(6.,dtype=self.dtype)
-        y = zeros(3,x.dtype)
-        y = self.blas_func(x,y,n=3,incx=2)
-        assert_array_equal(x[::2],y)
+        x = arange(6., dtype=self.dtype)
+        y = zeros(3, x.dtype)
+        y = self.blas_func(x, y, n=3, incx=2)
+        assert_array_equal(x[::2], y)
 
     def test_y_stride(self):
-        x = arange(3.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
-        y = self.blas_func(x,y,n=3,incy=2)
-        assert_array_equal(x,y[::2])
+        x = arange(3., dtype=self.dtype)
+        y = zeros(6, x.dtype)
+        y = self.blas_func(x, y, n=3, incy=2)
+        assert_array_equal(x, y[::2])
 
     def test_x_and_y_stride(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
-        y = self.blas_func(x,y,n=3,incx=4,incy=2)
-        assert_array_equal(x[::4],y[::2])
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
+        y = self.blas_func(x, y, n=3, incx=4, incy=2)
+        assert_array_equal(x[::4], y[::2])
 
     def test_x_bad_size(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         try:
-            self.blas_func(x,y,n=4,incx=5)
+            self.blas_func(x, y, n=4, incx=5)
         except:  # what kind of error should be caught?
             return
         # should catch error and never get here
         assert_(0)
 
     def test_y_bad_size(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         try:
-            self.blas_func(x,y,n=3,incy=5)
+            self.blas_func(x, y, n=3, incy=5)
         except:  # what kind of error should be caught?
             return
         # should catch error and never get here
@@ -245,6 +249,7 @@ def test_y_bad_size(self):
     #    self.blas_func(x,y)
     #    assert_array_equal(x,y)
 
+
 try:
     class TestScopy(BaseCopy):
         blas_func = fblas.scopy
@@ -258,6 +263,7 @@ class TestDcopy(BaseCopy):
     blas_func = fblas.dcopy
     dtype = float64
 
+
 try:
     class TestCcopy(BaseCopy):
         blas_func = fblas.ccopy
@@ -273,67 +279,68 @@ class TestZcopy(BaseCopy):
 
 
 ##################################################
-### Test blas ?swap
+# Test blas ?swap
 
 class BaseSwap(object):
     ''' Mixin class for swap tests '''
 
     def test_simple(self):
-        x = arange(3.,dtype=self.dtype)
-        y = zeros(shape(x),x.dtype)
+        x = arange(3., dtype=self.dtype)
+        y = zeros(shape(x), x.dtype)
         desired_x = y.copy()
         desired_y = x.copy()
-        x, y = self.blas_func(x,y)
-        assert_array_equal(desired_x,x)
-        assert_array_equal(desired_y,y)
+        x, y = self.blas_func(x, y)
+        assert_array_equal(desired_x, x)
+        assert_array_equal(desired_y, y)
 
     def test_x_stride(self):
-        x = arange(6.,dtype=self.dtype)
-        y = zeros(3,x.dtype)
+        x = arange(6., dtype=self.dtype)
+        y = zeros(3, x.dtype)
         desired_x = y.copy()
         desired_y = x.copy()[::2]
-        x, y = self.blas_func(x,y,n=3,incx=2)
-        assert_array_equal(desired_x,x[::2])
-        assert_array_equal(desired_y,y)
+        x, y = self.blas_func(x, y, n=3, incx=2)
+        assert_array_equal(desired_x, x[::2])
+        assert_array_equal(desired_y, y)
 
     def test_y_stride(self):
-        x = arange(3.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(3., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         desired_x = y.copy()[::2]
         desired_y = x.copy()
-        x, y = self.blas_func(x,y,n=3,incy=2)
-        assert_array_equal(desired_x,x)
-        assert_array_equal(desired_y,y[::2])
+        x, y = self.blas_func(x, y, n=3, incy=2)
+        assert_array_equal(desired_x, x)
+        assert_array_equal(desired_y, y[::2])
 
     def test_x_and_y_stride(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         desired_x = y.copy()[::2]
         desired_y = x.copy()[::4]
-        x, y = self.blas_func(x,y,n=3,incx=4,incy=2)
-        assert_array_equal(desired_x,x[::4])
-        assert_array_equal(desired_y,y[::2])
+        x, y = self.blas_func(x, y, n=3, incx=4, incy=2)
+        assert_array_equal(desired_x, x[::4])
+        assert_array_equal(desired_y, y[::2])
 
     def test_x_bad_size(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         try:
-            self.blas_func(x,y,n=4,incx=5)
+            self.blas_func(x, y, n=4, incx=5)
         except:  # what kind of error should be caught?
             return
         # should catch error and never get here
         assert_(0)
 
     def test_y_bad_size(self):
-        x = arange(12.,dtype=self.dtype)
-        y = zeros(6,x.dtype)
+        x = arange(12., dtype=self.dtype)
+        y = zeros(6, x.dtype)
         try:
-            self.blas_func(x,y,n=3,incy=5)
+            self.blas_func(x, y, n=3, incy=5)
         except:  # what kind of error should be caught?
             return
         # should catch error and never get here
         assert_(0)
 
+
 try:
     class TestSswap(BaseSwap):
         blas_func = fblas.sswap
@@ -347,6 +354,7 @@ class TestDswap(BaseSwap):
     blas_func = fblas.dswap
     dtype = float64
 
+
 try:
     class TestCswap(BaseSwap):
         blas_func = fblas.cswap
@@ -361,104 +369,105 @@ class TestZswap(BaseSwap):
     dtype = complex128
 
 ##################################################
-### Test blas ?gemv
-### This will be a mess to test all cases.
+# Test blas ?gemv
+# This will be a mess to test all cases.
 
 
 class BaseGemv(object):
     ''' Mixin class for gemv tests '''
 
-    def get_data(self,x_stride=1,y_stride=1):
+    def get_data(self, x_stride=1, y_stride=1):
         mult = array(1, dtype=self.dtype)
         if self.dtype in [complex64, complex128]:
             mult = array(1+1j, dtype=self.dtype)
         from numpy.random import normal, seed
         seed(1234)
         alpha = array(1., dtype=self.dtype) * mult
-        beta = array(1.,dtype=self.dtype) * mult
-        a = normal(0.,1.,(3,3)).astype(self.dtype) * mult
-        x = arange(shape(a)[0]*x_stride,dtype=self.dtype) * mult
-        y = arange(shape(a)[1]*y_stride,dtype=self.dtype) * mult
-        return alpha,beta,a,x,y
+        beta = array(1., dtype=self.dtype) * mult
+        a = normal(0., 1., (3, 3)).astype(self.dtype) * mult
+        x = arange(shape(a)[0]*x_stride, dtype=self.dtype) * mult
+        y = arange(shape(a)[1]*y_stride, dtype=self.dtype) * mult
+        return alpha, beta, a, x, y
 
     def test_simple(self):
-        alpha,beta,a,x,y = self.get_data()
-        desired_y = alpha*matrixmultiply(a,x)+beta*y
-        y = self.blas_func(alpha,a,x,beta,y)
-        assert_array_almost_equal(desired_y,y)
+        alpha, beta, a, x, y = self.get_data()
+        desired_y = alpha*matrixmultiply(a, x)+beta*y
+        y = self.blas_func(alpha, a, x, beta, y)
+        assert_array_almost_equal(desired_y, y)
 
     def test_default_beta_y(self):
-        alpha,beta,a,x,y = self.get_data()
-        desired_y = matrixmultiply(a,x)
-        y = self.blas_func(1,a,x)
-        assert_array_almost_equal(desired_y,y)
+        alpha, beta, a, x, y = self.get_data()
+        desired_y = matrixmultiply(a, x)
+        y = self.blas_func(1, a, x)
+        assert_array_almost_equal(desired_y, y)
 
     def test_simple_transpose(self):
-        alpha,beta,a,x,y = self.get_data()
-        desired_y = alpha*matrixmultiply(transpose(a),x)+beta*y
-        y = self.blas_func(alpha,a,x,beta,y,trans=1)
-        assert_array_almost_equal(desired_y,y)
+        alpha, beta, a, x, y = self.get_data()
+        desired_y = alpha*matrixmultiply(transpose(a), x)+beta*y
+        y = self.blas_func(alpha, a, x, beta, y, trans=1)
+        assert_array_almost_equal(desired_y, y)
 
     def test_simple_transpose_conj(self):
-        alpha,beta,a,x,y = self.get_data()
-        desired_y = alpha*matrixmultiply(transpose(conjugate(a)),x)+beta*y
-        y = self.blas_func(alpha,a,x,beta,y,trans=2)
-        assert_array_almost_equal(desired_y,y)
+        alpha, beta, a, x, y = self.get_data()
+        desired_y = alpha*matrixmultiply(transpose(conjugate(a)), x)+beta*y
+        y = self.blas_func(alpha, a, x, beta, y, trans=2)
+        assert_array_almost_equal(desired_y, y)
 
     def test_x_stride(self):
-        alpha,beta,a,x,y = self.get_data(x_stride=2)
-        desired_y = alpha*matrixmultiply(a,x[::2])+beta*y
-        y = self.blas_func(alpha,a,x,beta,y,incx=2)
-        assert_array_almost_equal(desired_y,y)
+        alpha, beta, a, x, y = self.get_data(x_stride=2)
+        desired_y = alpha*matrixmultiply(a, x[::2])+beta*y
+        y = self.blas_func(alpha, a, x, beta, y, incx=2)
+        assert_array_almost_equal(desired_y, y)
 
     def test_x_stride_transpose(self):
-        alpha,beta,a,x,y = self.get_data(x_stride=2)
-        desired_y = alpha*matrixmultiply(transpose(a),x[::2])+beta*y
-        y = self.blas_func(alpha,a,x,beta,y,trans=1,incx=2)
+        alpha, beta, a, x, y = self.get_data(x_stride=2)
+        desired_y = alpha*matrixmultiply(transpose(a), x[::2])+beta*y
+        y = self.blas_func(alpha, a, x, beta, y, trans=1, incx=2)
         assert_array_almost_equal(desired_y, y)
 
     def test_x_stride_assert(self):
         # What is the use of this test?
-        alpha,beta,a,x,y = self.get_data(x_stride=2)
+        alpha, beta, a, x, y = self.get_data(x_stride=2)
         try:
-            y = self.blas_func(1,a,x,1,y,trans=0,incx=3)
+            y = self.blas_func(1, a, x, 1, y, trans=0, incx=3)
             assert_(0)
         except:
             pass
         try:
-            y = self.blas_func(1,a,x,1,y,trans=1,incx=3)
+            y = self.blas_func(1, a, x, 1, y, trans=1, incx=3)
             assert_(0)
         except:
             pass
 
     def test_y_stride(self):
-        alpha,beta,a,x,y = self.get_data(y_stride=2)
+        alpha, beta, a, x, y = self.get_data(y_stride=2)
         desired_y = y.copy()
-        desired_y[::2] = alpha*matrixmultiply(a,x)+beta*y[::2]
-        y = self.blas_func(alpha,a,x,beta,y,incy=2)
-        assert_array_almost_equal(desired_y,y)
+        desired_y[::2] = alpha*matrixmultiply(a, x)+beta*y[::2]
+        y = self.blas_func(alpha, a, x, beta, y, incy=2)
+        assert_array_almost_equal(desired_y, y)
 
     def test_y_stride_transpose(self):
-        alpha,beta,a,x,y = self.get_data(y_stride=2)
+        alpha, beta, a, x, y = self.get_data(y_stride=2)
         desired_y = y.copy()
-        desired_y[::2] = alpha*matrixmultiply(transpose(a),x)+beta*y[::2]
-        y = self.blas_func(alpha,a,x,beta,y,trans=1,incy=2)
-        assert_array_almost_equal(desired_y,y)
+        desired_y[::2] = alpha*matrixmultiply(transpose(a), x)+beta*y[::2]
+        y = self.blas_func(alpha, a, x, beta, y, trans=1, incy=2)
+        assert_array_almost_equal(desired_y, y)
 
     def test_y_stride_assert(self):
         # What is the use of this test?
-        alpha,beta,a,x,y = self.get_data(y_stride=2)
+        alpha, beta, a, x, y = self.get_data(y_stride=2)
         try:
-            y = self.blas_func(1,a,x,1,y,trans=0,incy=3)
+            y = self.blas_func(1, a, x, 1, y, trans=0, incy=3)
             assert_(0)
         except:
             pass
         try:
-            y = self.blas_func(1,a,x,1,y,trans=1,incy=3)
+            y = self.blas_func(1, a, x, 1, y, trans=1, incy=3)
             assert_(0)
         except:
             pass
 
+
 try:
     class TestSgemv(BaseGemv):
         blas_func = fblas.sgemv
@@ -481,7 +490,7 @@ def aligned_array(shape, align, dtype, order='C'):
                 address = tmp.__array_interface__["data"][0]
                 # Find offset into array giving desired alignment
                 for offset in range(align):
-                    if (address + offset) % align == 0: 
+                    if (address + offset) % align == 0:
                         break
                 tmp = tmp[offset:offset+N*d.nbytes].view(dtype=dtype)
                 return tmp.reshape(shape, order=order)
@@ -493,10 +502,10 @@ def as_aligned(arr, align, dtype, order='C'):
                 return aligned
 
             def assert_dot_close(A, X, desired):
-                assert_allclose(self.blas_func(1.0,A,X), desired,
-                    rtol=1e-5, atol=1e-7)
+                assert_allclose(self.blas_func(1.0, A, X), desired,
+                                rtol=1e-5, atol=1e-7)
 
-            testdata = product((15,32), (10000,), (200,89), ('C','F'))
+            testdata = product((15, 32), (10000,), (200, 89), ('C', 'F'))
             for align, m, n, a_order in testdata:
                 A_d = np.random.rand(m, n)
                 X_d = np.random.rand(n)
@@ -515,6 +524,7 @@ class TestDgemv(BaseGemv):
     blas_func = fblas.dgemv
     dtype = float64
 
+
 try:
     class TestCgemv(BaseGemv):
         blas_func = fblas.cgemv
@@ -528,6 +538,7 @@ class TestZgemv(BaseGemv):
     blas_func = fblas.zgemv
     dtype = complex128
 
+
 """
 ##################################################
 ### Test blas ?ger
@@ -582,8 +593,8 @@ class TestDger(BaseGer):
     dtype = float64
 """
 ##################################################
-### Test blas ?gerc
-### This will be a mess to test all cases.
+# Test blas ?gerc
+# This will be a mess to test all cases.
 
 """
 class BaseGerComplex(BaseGer):