[Numeric] column vector faster than row vector in mat multiply?
Terry Reedy
tjreedy at udel.edu
Fri Mar 4 15:27:19 EST 2005
"Zhang Le" <sigu4wa02 at sneakemail.com> wrote in message
news:1109952846.225378.136210 at o13g2000cwo.googlegroups.com...
> Hi,
> I did a small benchmark of matrix-vector multiply operation using
> Numeric module. I'm a bit suprised to find matrix*col-vector is much
> faster than row-vector*matrix. I wonder whether other people have
> observed this fact too,
Yes, common knowledge in numerical analysis community. Using the faster
direction for a particular system as much as possible is part of tuning
linear algebra software.
> and why?
I presume that Numeric, like Python, stores matrices by row. So M*v
multiplies contiguous rows by a contiguous vector. Multiplying a vector by
non-contiguous columns requires requires skipping thru the matrix, which
may require more computation and generate more cache misses and page
faults.
Terry J. Reedy
More information about the Python-list
mailing list