[Numpy-discussion] Cython numerical syntax revisited

Francesc Alted faltet@pytables....
Thu Mar 5 10:30:12 CST 2009


A Thursday 05 March 2009, David Cournapeau escrigué:
> I don't understand your argument about Row vs Column matters: which
> one is best depends on your linear algebra equations. You give an
> example where Fortran is better, but I can find example where C order
> will be more appropriate. Most of the time, for anything non trivial,
> which one is best depends on the dimensions of the problem (Kalman
> filtering in high dimensional spaces for example), because some parts
> of the equations are better handled in a row-order fashion, and some
> other parts in a column order fashion.

Yeah.  Yet another (simple) example coming from linear algebra: a matrix 
multiplied by a vector.  Given a (matrix):

a = [[0,1,2],
     [3,4,5],
     [6,7,8]]

and b (vector):

b = [[1],
     [2],
     [3]]

the most intuitive way to do the multiplication is to take the 1st row 
of a and do a dot product against b, repeating the process for 2nd and 
3rd rows of a.  C order coincides with this rule, and it is optimal 
from the point of view of memory access, while Fortran order is not.

-- 
Francesc Alted


More information about the Numpy-discussion mailing list