mini / maxi functions



Some time ago I wrote a function column_map that maps a function over the columns of a matrix;
example:

 (%i3) column_map(lambda([s], lmax(list_matrix_entries(s))), matrix([a,b,c],[1,2,3]));
 (%o3) [max(1,a),max(2,b),max(3,c)]

Lightly tested:

(defmacro opapply (op l)
  `(simplify (cons (list ,op) ,l)))

(defmfun $column_map (f mat)
  (let ((acc nil))
    (if ($matrixp mat) (setq mat (mcx (margs mat)))
      (merror "The first argument to column_map must be a matrix"))
    (while (car mat)
      (push (mfuncall f (opapply '$matrix (mapcar #'(lambda (s) (opcons 'mlist (car s))) mat))) acc)
      (setq mat (mapcar #'cdr mat)))
    (opapply 'mlist (nreverse acc))))

--Barton

-----Robert Dodier <robert.dodier at gmail.com> wrote: -----


>How?about?this??Make?it?easier?to?loop?over?parts?of?a?matrix
>(or?any?other?aggregate)?and?let?the?user?spell?out?just?what?they?want.