Re: Matrix column access

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

Thanks, this is indeed much, much better. Have you considered
contributing some of your code back to matlisp? I looked at it, and
there is a lot of nice functionality in your fl.matlisp package (apart
from minject and mextract I also liked the BLAS-based vector
operations). I think this code could be very useful to many people. But
it seems it is dependent on some other utitilies, and I'd prefer not to
pull in the entire Femlisp code...

As it is, I'll probably reinvent the wheel and write my own functions
using DCOPY, as you suggested.

--J.



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