Matrix column access

Jan Rychter <[email protected]> Mon, 05 Dec 2005 13:05:04 +0100
Newsgroups gmane.lisp.matlisp.user
Message-ID <[email protected]>
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.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click