From: Jan R. <ja...@ry...> - 2005-12-05 12:21:36
|
Is there a way to efficiently operate on matrix columns and/or rows? I often need to extract a column (or a row) and do operations on it, sometimes storing it right back. I expected to be able to use matrix-ref with a single number for this, but couldn't find a simple way. Perusing the copious documentation pointed me to the sequence parameter to matrix ref, so I came up with this: (defmacro extract-column (matrix column) `(matrix-ref ,matrix (seq 0 1 (1- (first (size ,matrix)))) ,column)) (defmacro extract-row (matrix row) `(matrix-ref ,matrix ,row (seq 0 1 (1- (second (size ,matrix)))))) This works (also for (setf (extract-column...))), but is very inefficient, as it conses a *lot*. This is something I do very, very often in my code, so the performance impact is huge. Surely there must be a better way? From what I remember, matlisp stores matrices in a column-major order, so at least columns could be processed quickly... --J. PS: amusingly enough, it seems that using ATLAS actually slowed down my program, by about 3%. Rather surprising. |