|
From: Richard F. <fa...@be...> - 2017-03-31 00:44:07
|
consider mm: genmatrix(e,3,4);
selecting rows and colums from mm
can be done by
submatrix_sel(mm, 1 .. 2, 2 ..4)
where the following lisp program defines submatrix_sel
(defmfun $submatrix_sel (mm rows cols)
;; rows is a list like ((mlist) 1 2 3)
;; similarly for cols
;; the elt operation is 0 based, so (mlist) is 0
;; should check for rows and/or cols being single index
(let ((r (cons '(mlist)(loop for i in (cdr rows) collect (elt mm i)))))
(cons '($matrix)(loop for k in (cdr r) collect
(cons '(mlist)(loop for i in(cdr cols) collect (elt k i))))) ))
;;doing some checking for single indices or non-lists or .. an exercise
;; also, incorporating this into matrix subscript operation instead of
;; being an error, a submatrix selection.
|