[SciPy-User] How to efficiently do dot(dot( A.T, diag(d) ), A ) ?
Tue Sep 11 03:08:50 CDT 2012
I'm not sure what's going on here, but when I run your MATLAB-code on my
(copy-pasted) I get results more in the line of
Elapsed time is 0.007203 seconds.
Elapsed time is 0.031520 seconds.
i.e. much worse than you report but still better than the Python ones. With
scipy I get
4.1 ms vs. 60 ms.
'Sparsifying' the code improves things on my end:
In : n = 10000
In : k = 100
In : r = rand(n)
In : a = scipy.sparse.spdiags(r, 0, n, n)
In : c = scipy.sparse.rand(k,n)
In : d = c.dot(a)
In : e = d.dot(c.T)
In : %timeit d = c.dot(a)
1000 loops, best of 3: 1.52 ms per loop
In : %timeit e = d.dot(c.T)
1000 loops, best of 3: 1.12 ms per loop
On Tue, Sep 11, 2012 at 4:43 AM, Hugh Perkins <email@example.com> wrote:
> > It's not so clear what kind of improvements you are looking for. Do you
> > perhaps expect that there exist some magic to ignore half of the
> > computations with dot product, when the result is symmetric?
> Here's the same test in matlab:
> >> 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.007769 seconds.
> >> tic, d = d*c'; toc
> Elapsed time is 0.007782 seconds.
> (vs, in scipy:
> >>> tic(); d = c.T * a; toc()
> Elapsed time: 0.00560903549194
> >>> tic(); e = dot( d, c ); toc()
> Elapsed time: 0.110434055328
> SciPy-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User