From: Jan R. <ja...@ry...> - 2005-12-14 20:00:57
|
>>>>> "Nicolas" == Nicolas Neuss <Nic...@iw...> writes: Nicolas> Jan Rychter <ja...@ry...> 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)) |