Re: Matrix column access
Jan Rychter <[email protected]> Wed, 14 Dec 2005 20:54:05 +0100
| Newsgroups | gmane.lisp.matlisp.user |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "Nicolas" == Nicolas Neuss <[email protected]> writes: Nicolas> Jan Rychter <[email protected]> writes: [...] >> As it is, I'll probably reinvent the wheel and write my own >> functions using DCOPY, as you suggested. Nicolas> I'm quite sure this is the choice fitting the Matlisp way Nicolas> best. If you indeed want to make it into a generic function, Nicolas> it would be nice if you could use my MEXTRACT/MINJECT syntax. Nicolas> Probably, the Matlisp authors would also welcome such a Nicolas> contribution. Well, the discussion seems to have died, so I thought I'd contribute what I use now. It is much faster than my previous macros. Only works for real matrices for now. I didn't use DCOPY, because I don't know how to dereference a particular element in the matrix store, instead of the store itself (C pointers, anyone?). DCOPY would undoubtedly be much faster, especially for larger matrices. Nicolas -- sorry, I didn't use your syntax. I felt it isn't really compatible with matlisp and I really wanted to do things like (setf (column-ref m i) some-vector) --J. (defmethod column-ref ((matrix real-matrix) column) (let* ((n (nrows matrix)) (result (make-real-matrix-dim n 1)) (src-store (matlisp::store matrix)) (dst-store (matlisp::store result))) (declare (type fixnum n) (type (real-matrix-store-type (*)) src-store dst-store)) (dotimes (i n) (declare (type fixnum i)) (setf (aref dst-store i) (aref src-store (fortran-matrix-indexing i column n)))) result)) (defmethod (setf column-ref) (value (matrix real-matrix) column) (let* ((n (nrows matrix)) (src-store (matlisp::store value)) (dst-store (matlisp::store matrix))) (declare (type fixnum n) (type (real-matrix-store-type (*)) src-store dst-store)) (dotimes (i n) (declare (type fixnum i)) (setf (aref dst-store (fortran-matrix-indexing i column n)) (aref src-store i))) matrix)) (defmethod row-ref ((matrix real-matrix) row) (let* ((n (nrows matrix)) (m (ncols matrix)) (result (make-real-matrix-dim 1 m)) (src-store (matlisp::store matrix)) (dst-store (matlisp::store result))) (declare (type fixnum n m) (type (real-matrix-store-type (*)) src-store dst-store)) (dotimes (i m) (declare (type fixnum i)) (setf (aref dst-store (fortran-matrix-indexing 0 i 1)) (aref src-store (fortran-matrix-indexing row i n)))) result)) (defmethod (setf row-ref) (value (matrix real-matrix) row) (let* ((n (nrows matrix)) (m (ncols matrix)) (src-store (matlisp::store value)) (dst-store (matlisp::store matrix))) (declare (type fixnum n m) (type (real-matrix-store-type (*)) src-store dst-store)) (dotimes (i m) (declare (type fixnum i)) (setf (aref dst-store (fortran-matrix-indexing row i n)) (aref src-store (fortran-matrix-indexing 0 i 1)))) matrix)) (defmethod row-ref-transposed ((matrix real-matrix) row) (let* ((n (nrows matrix)) (m (ncols matrix)) (result (make-real-matrix-dim m 1)) (src-store (matlisp::store matrix)) (dst-store (matlisp::store result))) (declare (type fixnum n m) (type (real-matrix-store-type (*)) src-store dst-store)) (dotimes (i m) (declare (type fixnum i)) (setf (aref dst-store i) (aref src-store (fortran-matrix-indexing row i n)))) result)) ------------------------------------------------------- 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