diff --git a/data/iterate.lisp b/data/iterate.lisp index 3fac62c99afd56ca87c0e5c6f7636d2fd30141c2..c82b5bb71cfbfae78195cf1373f0b416ed68249a 100644 --- a/data/iterate.lisp +++ b/data/iterate.lisp @@ -1,113 +1,90 @@ ;; Iterate ;; Norman Werner 2009-05-26 22:23:40EDT iterate.lisp -;; Time-stamp: <2009-05-30 21:40:26EDT iterate.lisp> +;; Time-stamp: <2009-06-03 23:22:29EDT iterate.lisp> (in-package :iter) #| As an example try: -(setf m1 (gsll:make-marray 'double-float - :initial-contents '((1 2 3) (0 6 8)))) +(defparameter m1 #m((1 2 3) (0 6 8))) -(iterate:iterate (iterate:for e ELEMENT-IN-GSLL-MATRIX m1) - (format t "~A " e)) +(iter:iter (iter:for e :matrix-element m1) (format t "~A " e)) -(iterate:iterate (iterate:for (row column) INDEXES-IN-GSLL-MATRIX m1) - (format t "~A " (gsll:maref m1 row column))) +(iter:iter (iter:for (row column) :matrix-element-index m1) + (format t "~A " (gsll:maref m1 row column))) |# -(defclause-sequence :ROW-IN-GSLL-MATRIX - :ROW-INDEX-OF-GSLL-MATRIX +(defclause-sequence matrix-row matrix-row-index :access-fn (lambda (marray index) - (typecase marray - (gsll::matrix (gsll:row marray index)) - (gsll::mvector - (error "iterating over the rows in a vector is not supported.~ - You may want iterate over its elements instead")) - (t (error "only iterating over rows of an gsll:matrix is supported")))) + (check-type marray gsl:matrix) + (gsll:row marray index)) :size-fn (lambda (marray) - (typecase marray - (gsll::matrix (elt (gsll:dimensions marray) 0)) - (gsll::vector (error "iterating over the rows in a vector is not ~ - supported. You may want iterate over its elements instead")) - (t (error "only iterating over rows of an gsll:matrix is supported")))) + (check-type marray gsl:matrix) + (gsll:dim0 marray)) :element-type t :sequence-type t - :element-doc-string "(copied) rows of a gsll matrix" - :index-doc-string "index of the rows in a gsll matrix") + :element-doc-string "(copied) rows of a matrix" + :index-doc-string "index of the rows in a matrix") -(defclause-sequence column-in-gsll-matrix - column-index-of-gsll-matrix +(defclause-sequence matrix-column matrix-column-index :access-fn (lambda (marray index) - (typecase marray - (gsll::matrix (gsll:column marray index)) - (gsll::vector - (error "iterating over the columns in a vector is not - supported. You may want iterate over its elements instead")) - (t (error "only iterating over columns of an gsll:matrix is supported")))) + (check-type marray gsl:matrix) + (gsll:column marray index)) :size-fn (lambda (marray) - (typecase marray - (gsll::matrix (elt (gsll:dimensions marray) 1)) - (gsll::vector - (error "iterating over the columns in a vector is not - supported. You may want iterate over its elements instead")) - (t (error "only iterating over columns of an gsll:matrix is - supported")))) + (check-type marray gsl:matrix) + (gsll:dim1 marray)) :element-type t :sequence-type t - :element-doc-string "(copied) columns of a gsll matrix" - :index-doc-string "index of the columns in a gsll matrix") + :element-doc-string "(copied) columns of a matrix" + :index-doc-string "index of the columns in a matrix") -(defclause-sequence element-in-gsll-vector - index-of-gsll-vector - :access-fn (lambda (vector index) - (typecase vector - (gsll::mvector (gsll:maref vector index)) - (t (error "only iterating over elements of an gsll:vector is supported")))) - :size-fn (lambda (vector) - (typecase vector - (gsll::mvector (elt (gsll:dimensions vector) 0)) - (t (error - "only iterating over elements of an gsll:vector is supported")))) - :element-type t :sequence-type t - :element-doc-string "(copied) elements of a gsll vector" - :index-doc-string "index of elements in a gsll vector") +(defclause-sequence vector-element vector-element-index + :access-fn + (lambda (vector index) + (check-type vector gsl:mvector) + (gsll:maref vector index)) + :size-fn + (lambda (vector) + (check-type vector gsl:mvector) + (gsll:dim0 vector)) + :element-type t :sequence-type t + :element-doc-string "(copied) elements of a vector" + :index-doc-string "index of elements in a vector") -(defmacro-driver (FOR element :ELEMENT-IN-GSLL-MATRIX - matrix) - "Iterates over all (copied) Elements in matrix" +(defmacro-driver (FOR element matrix-element matrix) + "Iterates over all (copied) elements in matrix" (let ((row-index (gensym "row-index")) (col-index (gensym "col-index")) (row-size (gensym "row-size")) (col-size (gensym "col-size")) (m (gensym "m"))) - (when :generate - (error "not yet implemented a generate clause for ELEMENT-IN-GSLL-MATRIX")) + (when generate + (error "Not yet implemented a generate clause for matrix-element.")) `(progn (with ,m = ,matrix) (with ,row-index = 0) (with ,col-index = 0) - (with ,row-size = (elt (gsll:dimensions ,m) 0)) - (with ,col-size = (elt (gsll:dimensions ,m) 1)) - (:for ,element + (with ,row-size = (gsll:dim0 ,m)) + (with ,col-size = (gsll:dim1 ,m)) + (for ,element :next (if (>= ,row-index ,row-size) - (:terminate) + (terminate) (if (>= ,col-index ,col-size) (progn (setf ,col-index 0) (incf ,row-index) (if (>= ,row-index ,row-size) - (:terminate) + (terminate) (gsll:maref ,m ,row-index ,col-index))) (prog1 (gsll:maref ,m ,row-index ,col-index) (incf ,col-index)))))))) -(defmacro-driver (FOR indexes :INDEXES-IN-GSLL-MATRIX +(defmacro-driver (FOR indexes matrix-element-index matrix) "Iterates over the indexes in matrix. indexes is a list like (row-index-name column-index-name) " @@ -116,14 +93,14 @@ As an example try: (row-size (gensym "row-size")) (col-size (gensym "col-size")) (m (gensym "m"))) - (when :generate - (error "not yet implemented a generate clause for INDEXES-IN-GSLL-MATRIX")) + (when generate + (error "Not yet implemented a generate clause for matrix-element-index.")) `(progn (with ,m = ,matrix) (with ,row-index = 0) (with ,col-index = 0) - (with ,row-size = (elt (gsll:dimensions ,m) 0)) - (with ,col-size = (elt (gsll:dimensions ,m) 1)) + (with ,row-size = (gsll:dim0 ,m)) + (with ,col-size = (gsll:dim1 ,m)) (for ,indexes next (if (>= ,row-index ,row-size) (terminate) (if (>= ,col-index ,col-size) diff --git a/data/matrix.lisp b/data/matrix.lisp index 082b6d6076ea9c5dc2b02bdbfcb1a8270792e716..7ae31863a5502a933c7d618407e6978d26edeaf6 100644 --- a/data/matrix.lisp +++ b/data/matrix.lisp @@ -1,6 +1,6 @@ ;; Matrices ;; Liam Healy 2008-04-15 21:57:52EDT matrix.lisp -;; Time-stamp: <2009-03-20 17:20:57EDT matrix.lisp> +;; Time-stamp: <2009-06-02 22:51:24EDT matrix.lisp> ;; $Id$ (in-package :gsl) @@ -9,6 +9,7 @@ ;;;; Matrix structure and CL object ;;;;**************************************************************************** +(export 'matrix) (defclass matrix (marray) () (:documentation "GSL matrices.")) diff --git a/data/vector.lisp b/data/vector.lisp index 664d2e803e3a77c4fa8bbdde69671222ef2c959d..a6a17b3c1ca9c9e966a67aa17eaa5811387df9f1 100644 --- a/data/vector.lisp +++ b/data/vector.lisp @@ -1,6 +1,6 @@ ;; Vectors ;; Liam Healy 2008-04-13 09:39:02EDT vector.lisp -;; Time-stamp: <2009-03-20 17:20:40EDT vector.lisp> +;; Time-stamp: <2009-06-02 22:51:23EDT vector.lisp> ;; $Id$ (in-package :gsl) @@ -9,6 +9,7 @@ ;;;; Vector structure, CL object, and allocation ;;;;**************************************************************************** +(export 'mvector) (defclass mvector (marray) () (:documentation "GSL vectors."))