Permalink
Browse files

OPTIM: do not allocate a (n_samples, n_samples) temporary array with …

…scipy.linalg.qr when (n_samples, k + p)) is all what is needed
  • Loading branch information...
1 parent f2dc157 commit e61c7df1e5b004cb971d166fbc71153072f0363c @ogrisel ogrisel committed Dec 1, 2010
Showing with 1 addition and 4 deletions.
  1. +1 −4 scikits/learn/utils/extmath.py
@@ -158,12 +158,9 @@ def fast_svd(M, k, p=None, rng=0, q=0):
Y = _sparsedot(M, _sparsedot(M.T, Y))
# extracting an orthonormal basis of the M range samples
- Q, R = linalg.qr(Y)
+ Q, R = np.linalg.qr(Y)
del R
- # only keep the (k + p) first vectors of the basis
- Q = Q[:, :(k + p)]
-
# project M to the (k + p) dimensional space using the basis vectors
B = _sparsedot(Q.T, M)

6 comments on commit e61c7df

@GaelVaroquaux
Member

Using numpy to do linear algebra is something I avoid, because quite often (eg on Mandriva) it is compiled without any linear algebra pack, and it falls back to it's hand-written routines which are really slow.

@ogrisel
Member
ogrisel commented on e61c7df Dec 1, 2010

Hum but then using the scipy.linalg.qr of version 0.7.2 in economic mode gives me a deprecation warning I cannot remove since the non-deprecated equivalent is not yet available in scipy 0.7.2...

@GaelVaroquaux
Member

I know, it's a pain, but I would go for this, rather than risking hitting bad buils of numpy (they are quite frequent)

@fabianp
Member
fabianp commented on e61c7df Dec 1, 2010

I agree with Gael, we should use scipy's qr. The developement version of scipy still has the same deprecation warning that cannot be removed, so we are quite safe using econ=True.

@ogrisel
Member
ogrisel commented on e61c7df Dec 1, 2010

ok then. One day one of us has to send scipy a pull-request / patch to get rid of this :)

@GaelVaroquaux
Member

Yes, scipy needs more love and we should give it :)

Please sign in to comment.