[SciPy-User] How to efficiently do dot(dot( A.T, diag(d) ), A ) ?
Mon Sep 10 17:58:11 CDT 2012
On Mon, Sep 10, 2012 at 7:34 PM, Hugh Perkins <email@example.com> wrote:
> > > How to do efficiently do dot(dot( A.T, diag(d) ), A ) ?
> > dot( A.T * d , A )
> This is very good!
> Still, the second multiplication looks like it is doing a full
> brute-force matrix multiplication:
> >>> tic(); d = c.T * a; toc()
> Elapsed time: 0.00560903549194
> >>> tic(); e = dot( d, c ); toc()
> Elapsed time: 0.110434055328
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? Anyway, here
is a simple demonstration to show that dot product is fairly efficient
In : m, n= 500000, 5
In : A, d= randn(m, n), randn(m)
In : %timeit A.T* d
10 loops, best of 3: 34.4 ms per loop
In : mps= m* n/ .0344 # multiplications per second
In : c= A.T* d
In : %timeit dot(c, A)
10 loops, best of 3: 68 ms per loop
In : masps= m* n** 2/ .068 # multiplications and summations per second
In : masps/ mps
In : allclose(dot(c, A), dot(A.T* d, A))
In : sys.version
Out: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
In : np.version.version
Thus multiplication and summation with dot product is some 2.5 times faster
than simple multiplication.
My 2 cents,
> SciPy-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User