On 5/21/07, Charles R Harris <[EMAIL PROTECTED]> wrote:



On 5/21/07, David Cournapeau <[EMAIL PROTECTED]> wrote:
>
> Nils Wagner wrote:
> > Robert Cimrman wrote:
> >> I have come to a case where using a matrix would be easier than an
> >> array. The code uses lots of dot products, so I tested scipy.dot()
> >> performance with the code below and found that the array version is
> much
> >> faster (about 3 times for the given shape). What is the reason for
> this?
> >> Or is something wrong with my measurement?
> >>
> >> regards,
> >> r.
> >>
> >> ---
> >> import timeit
> >> setup = """
> >> import numpy as nm
> >> import scipy as sc
> >> X = nm.random.rand( 100, 3 )
> >> X = nm.asmatrix( X ) # (un)comment this line.
> >> print X.shape
> >> """
> >> tt = timeit.Timer( 'sc.dot( X.T, X )', setup )
> >> print tt.timeit()
> >> _______________________________________________
> >> Numpy-discussion mailing list
> >> [email protected]
> >> http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >>
> > Confirmed, but for what reason ?
> >
> > 0.5.3.dev3020
> > 1.0.3.dev3792
> > Array version
> > 6.84843301773
> > Matrix version
> > 17.1273219585
> >
> My guess would be that for such small matrices, the cost of matrix
> wrapping is not negligeable against the actual computation. This
> difference disappears for bigger matrices (for example, try 1000 and
> 5000 instead of 100 for the first dimension).


Hmmm, I wonder how Tim's matrix version works. I've attached the code. I
am rather fond of the approach and have used it a few times myself. Tim uses
the dot product is written so: a(b). That is, the () operator is used
instead of the *.


Well, it doesn't go. There is a bug in the code and, on a second look, it
doesn't use dot.

BTW, on my machine numpy dot is faster than the scipy version.

Chuck
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to