Hacker News new | ask | show | jobs
by adrian_b 25 days ago
I agree with the explanation you give at that link.

For linear algebra, the Fortran convention, "column-major" is indeed superior.

This is most obvious when computing a matrix-vector product, i.e. a linear transformation of a vector, which is a very common operation.

In schools this operation is typically taught in the wrong way, i.e. by computing scalar products of row vectors from the matrix with the column vector operand.

This naive method is inefficient. The correct method that must be used in computers is to avoid scalar products, but use the so-called AXPY operation (from its BLAS name. i.e. scalar A times vector X Plus vector Y), where the operands are column vectors from the matrix and the column vector that is the second operand of the matrix-vector product.

Therefore, to compute the product one needs to read columns from the matrix, so for maximum throughput the elements of a column must be stored sequentially.

In schools, also the matrix-matrix product is taught in the wrong way, with scalar products between row vectors and column vectors.

The correct way also avoids the inefficient scalar products and replaces them with tensor products of column vectors.

1 comments

hank you for your response. I didn't know there was a pattern called AXPY. I was vaguely aware that something like that was used, but I didn't know it was called AXPY. Thanks to you, I've learned a new term. I'll save this for myself as well. Thank you for the kind explanation