[SciPy-User] How to efficiently do dot(dot( A.T, diag(d) ), A ) ?
Pauli Virtanen
pav@iki...
Tue Sep 11 13:30:47 CDT 2012
11.09.2012 20:15, Pauli Virtanen kirjoitti:
> Here are results on one (slowish) machine:
Ok, just for completeness: the bad performance for `np.dot` on this
machine comes from the fact that Numpy is not linked with any BLAS
library, so it falls back to a slow and naive algorithm. (You can check
this as follows: if `numpy.dot.__module__` is 'numpy.core._dotblas', you
have some BLAS.)
> ----
> import numpy as np
> n = 10000
> k = 100
> a = np.random.rand(n)
> c = np.random.rand(k,n)
> d = c*a
> e = np.dot(d, c.T)
> %timeit d = c*a
> # -> 100 loops, best of 3: 11 ms per loop
> %timeit e = np.dot(d, c.T)
> # -> 10 loops, best of 3: 538 ms per loop
> ----
> n = 10000;
> k = 100;
> a = spdiags(rand(n,1),0,n,n);
> c = rand(k,n);
> tic, d = c*a; toc
> % -> Elapsed time is 0.018380 seconds.
> tic, e = d*c'; toc
> % -> Elapsed time is 0.138673 seconds.
>
More information about the SciPy-User
mailing list