[Numpy-discussion] performance matrix multiplication vs. matlab
Anne Archibald
peridot.faceted at gmail.com
Thu Jun 4 17:03:25 EDT 2009
2009/6/4 David Paul Reichert <D.P.Reichert at sms.ed.ac.uk>:
> Hi all,
>
> I would be glad if someone could help me with
> the following issue:
>
> From what I've read on the web it appears to me
> that numpy should be about as fast as matlab. However,
> when I do simple matrix multiplication, it consistently
> appears to be about 5 times slower. I tested this using
>
> A = 0.9 * numpy.matlib.ones((500,100))
> B = 0.8 * numpy.matlib.ones((500,100))
>
> def test():
> for i in range(1000):
> A*B.T
>
> I also used ten times larger matrices with ten times less
> iterations, used xrange instead of range, arrays instead
> of matrices, and tested it on two different machines,
> and the result always seems to be the same.
>
> Any idea what could go wrong? I'm using ipython and
> matlab R2008b.
Apart from the implementation issues people have chimed in about
already, it's worth noting that the speed of matrix multiplication
depends on the memory layout of the matrices. So generating B instead
directly as a 100 by 500 matrix might affect the speed substantially
(I'm not sure in which direction). If MATLAB's matrices have a
different memory order, that might be a factor as well.
Anne
> Thanks,
>
> David
>
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list