[Numpy-discussion] Speed ups to matrix-vector multiplication
oliphant.travis at ieee.org
Sat Jan 14 21:59:01 CST 2006
Travis Oliphant wrote:
> Paulo J. S. Silva wrote:
>> In :i = time.clock(); bench(A,b); time.clock() - i
>> Why is numpy so slow??????
> I think the problem here is that using the properties here to take
> advantage of the nice matrix math stuff is slower than just computing
> the dot product in the fastest possible way with raw arrays. I've
> been concerned about this for awhile. The benchmark below makes my
> While a matrix is a nice thing, I think it will always be slower....
> It might be possible to speed it up and I'm open to suggestions...
Indeed it was possible to speed things up as Paulo pointed out, by using
the correct blas calls for the real size of the array.
With some relatively simple modifications, I was able to get significant
speed-ups in time using matrices:
t1 = timeit.Timer('c = b.T*A; d=c*b','from numpy import rand,mat; A =
mat(rand(1000,1000));b = mat(rand(1000,1))')
t2 = timeit.Timer('c = dot(b,A); d=dot(b,c)','from numpy import rand,
dot; A = rand(1000,1000);b = rand(1000)')
Now, that looks more like a 10% overhead for the matrix class.
More information about the Numpy-discussion