Hi guys,
I've been out of the country for a while but I'm getting back to work on my project. Something else I've been wondering about for GSLL is whether there is a way to quickly extract sub-matrices and especially sub-vectors from a matrix. Something with power equivalent to the matlab indexing using a colon to express ranges would be amazing but I guess probably quite nasty to implement efficiently. However, what would help me even more right now is a way to extract rows / columns from a matrix, without copying. I currently use a do-loop to run through the indices I want, but since the internals of the storage appear to be row major, is there a way to get a "pointer" (not sure if this is preferred lisp terminology, sorry) to an individual row?
To clarify, if I do
(defvar x (make-marray 'double-float :initial-contents '((1 2 3) (4 5 6) (7 8 9))))
is there any efficient way (ie don't need to copy element by element to a new object) thatI can get a reference to the row (4 5 6) of that, either as a gsll::matrix or gsll::vector object? If structure was shared between the matrix and the vector that would be no problem, it would be ideal in fact.
Regards
Malcolm
Malcolm
Malcolm,
Try #'column, #'row. They are also setfable. These will give you individual columns and rows from a matrix, as a vector (mvector). As for general submatrix or subvector, the answer is no. There actually are functions in GSL that will provide matrix "views" http://www.gnu.org/software/gsl/manual/html_node/Matrix-views.html but I haven't implemented them yet because of uncertainty of their value and the complexity of getting it right. There was a discussion on this list earlier about how/whether to do this; I think Tamas had some nice ideas but again, I've not implemented them at this point.
Liam
On Wed, Apr 29, 2009 at 2:16 PM, Malcolm Reynolds malcolm.reynolds@gmail.com wrote:
Hi guys,
I've been out of the country for a while but I'm getting back to work on my project. Something else I've been wondering about for GSLL is whether there is a way to quickly extract sub-matrices and especially sub-vectors from a matrix. Something with power equivalent to the matlab indexing using a colon to express ranges would be amazing but I guess probably quite nasty to implement efficiently. However, what would help me even more right now is a way to extract rows / columns from a matrix, without copying. I currently use a do-loop to run through the indices I want, but since the internals of the storage appear to be row major, is there a way to get a "pointer" (not sure if this is preferred lisp terminology, sorry) to an individual row?
To clarify, if I do
(defvar x (make-marray 'double-float :initial-contents '((1 2 3) (4 5 6) (7 8 9))))
is there any efficient way (ie don't need to copy element by element to a new object) thatI can get a reference to the row (4 5 6) of that, either as a gsll::matrix or gsll::vector object? If structure was shared between the matrix and the vector that would be no problem, it would be ideal in fact.
Regards
Malcolm
Malcolm
Try #'column, #'row. They are also setfable. These will give you individual columns and rows from a matrix, as a vector (mvector).
Excellent, just what I need.
As for general submatrix or subvector, the answer is no.
Fair enough, I can see there are lots of efficiency issues here which make it a big job. #'column and #'row are very useful by themselves for the moment, so thanks!
Malcolm