Re: Matrix column access

Nicolas Neuss <[email protected]> Mon, 05 Dec 2005 14:42:24 +0100
Newsgroups gmane.lisp.matlisp.user
Organization IWR
Message-ID <[email protected]>
Jan Rychter <[email protected]> writes:

> 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.

Probably, the easiest way for you to go is to call the BLAS routine DCOPY
(or similar) with suitable parameters:

MATLISP(9): (apropos "dcopy")
BLAS::FORTRAN-DCOPY [function] (N DX INCX DY ...)
DCOPY               [function] (N DX INCX DY ...)


If you want generic functions working on every matlisp matrix, you will
probably have to write a suitable set of functions yourself.  In my app
Femlisp (which contains a part written in CL giving basic matlisp
functionality) I have written (generic) functions

  minject ((x standard-matrix) (y standard-matrix) row-off col-off)

injecting x into y, and

  mextract ((x standard-matrix) (y standard-matrix) row-off col-off)

extracting y from x.

Yours, Nicolas.

P.S: Timings:

APPLICATION> (time (let ((A (eye 1000)) (x (zeros 1000 1)))
	       (loop repeat 1000 do (mextract A x 0 5))))
; cpu time (non-gc) 50 msec user, 0 msec system
; cpu time (gc)     10 msec user, 0 msec system
; cpu time (total)  60 msec user, 0 msec system
; real time  54 msec
; space allocation:
;  18,218 cons cells, 8,026,592 other bytes, 0 static bytes
NIL

compared with:

MATLISP(11): (time (let ((a (eye 1000)))
(loop repeat 1000 do (extract-column a 5))))
; cpu time (non-gc) 1,580 msec user, 0 msec system
; cpu time (gc)     90 msec user, 0 msec system
; cpu time (total)  1,670 msec user, 0 msec system
; real time  1,675 msec
; space allocation:
;  1,292,128 cons cells, 41,409,488 other bytes, 0 static bytes
NIL


-------------------------------------------------------
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