From f3a45c98055539360ece6e5865704655a9dc8d4f Mon Sep 17 00:00:00 2001
From: Liam Healy <liam@thinkpad.local>
Date: Mon, 21 Dec 2009 10:01:33 -0500
Subject: [PATCH] Moved some maref definitions to grid

Moved the defgeneric and methods for CL arrays and foreign-array for
cl-array, maref and (setf maref) to a new file
grid/element-reference.lisp.  The old file data/maref.lisp remains
with the GSL pointer methods.
---
 data/maref.lisp             | 88 +++----------------------------------
 grid/element-reference.lisp | 83 ++++++++++++++++++++++++++++++++++
 gsll.asd                    |  5 ++-
 init/init.lisp              |  7 ++-
 4 files changed, 96 insertions(+), 87 deletions(-)
 create mode 100644 grid/element-reference.lisp

diff --git a/data/maref.lisp b/data/maref.lisp
index d026a257..b5f41a57 100644
--- a/data/maref.lisp
+++ b/data/maref.lisp
@@ -1,94 +1,20 @@
 ;; Get/set array or elements: cl-array, maref
 ;; Liam Healy 2008-08-27 22:43:10EDT maref.lisp
-;; Time-stamp: <2009-12-21 08:17:03EST maref.lisp>
+;; Time-stamp: <2009-12-21 09:42:47EST maref.lisp>
 ;; $Id: $
 
 (in-package :gsl)
 
-(export '(cl-array maref))
-
-;;; These functions handle the details of converting between the GSL
-;;; representation of arrays and Common Lisp arrays.  The function
-;;; #'maref can be treated like #'aref for reading and setting
-;;; elements, except that it is limited to two indices (vectors or
-;;; matrices only) and requires a final argument with the element
-;;; type when taking a GSL pointer as the first argument (only needed
-;;; in the case of solve-minimize-fit for callbacks and some return
-;;; values).
-
-;;; Both these functions take one of the following class arguments for
-;;; the array:
-;;; - a c-array:foreign-array
-;;; - a Common Lisp array
-;;; - a pointer to a GSL vector or matrix structure
-
-;;;;****************************************************************************
-;;;; Get the entire array:  cl-array
-;;;;****************************************************************************
-
-(defgeneric cl-array (object &optional array-rank element-type)
-  (:documentation
-   "The array as a CL native array.  The object may be a c-array:foreign-array object,
-    a pointer to a GSL vector or matrix, or an ordinary CL array of one
-    or two dimensions.  Optional arguments array-rank and element-type
-    are used only for pointers.")
-  (:method ((object c-array:foreign-array) &optional array-rank element-type)
-    (declare (ignore array-rank element-type))
-    #-native (copy-c-to-cl object)
-    (slot-value object 'cl-array))
-  (:method ((object array) &optional array-rank element-type)
-    ;; For compatibility, work on CL arrays as well.
-    (declare (ignore array-rank element-type))
-    object))
-
-;;;;****************************************************************************
-;;;; Get or set elements of the array:  maref, (setf maref)
-;;;;****************************************************************************
-
-(defgeneric maref (object index &optional index2 type)
-  (:documentation
-   "An element of the data.  The object may be a c-array:foreign-array object, a pointer to
-    a GSL vector or matrix, or an ordinary CL array of one or two dimensions.")
-  (:method ((object c-array:foreign-array) index &optional index2 type)
-    (declare (ignore type))
-    #-native (copy-c-to-cl object)
-    (if index2
-	(aref (cl-array object) index index2)
-	(aref (cl-array object) index)))
-  (:method ((object array) index &optional index2 type)
-    ;; For compatibility, work on CL arrays as well.
-    (declare (ignore type))
-    (if index2
-	(aref object index index2)
-	(aref object index))))
-
-;;; Alternative to complete copy is to mark which elements have
-;;; changed and just copy them.  Is it worth it?
-
-(defgeneric (setf maref) (value object index &optional index2 type)
-  (:documentation
-   "Set an element of the data.  The object may be a c-array:foreign-array object,
-    a pointer to a GSL vector or matrix, or an ordinary CL array
-    of one or two dimensions.")
-  (:method (value (object c-array:foreign-array) index &optional index2 type)
-    (declare (ignore type))
-    (if index2
-	(setf (aref (slot-value object 'cl-array) index index2) value)
-	(setf (aref (slot-value object 'cl-array) index) value))
-    #-native (setf (c-invalid object) t))
-  (:method (value (object array) index &optional index2 type)
-    ;; For compatibility, work on CL arrays as well.
-    (declare (ignore type))
-    (if index2
-	(setf (aref object index index2) value)
-	(setf (aref object index) value))))
-
 ;;; Normally we won't need to set or get directly from the GSL
 ;;; vector/matrix pointer.  However, it is necessary to have access to
 ;;; elements from the GSL vector/matrix pointers for things like
 ;;; callback functions in solve-minimize-fit and in #'cl-array method
 ;;; for pointers.
 
+;;; These functions add the following class arguments for
+;;; the array:
+;;; - a pointer to a GSL vector or matrix structure
+
 (defmacro maref-function-picker
     (type-symbol category ffrestargs &optional value-symbol)
   "Generate sexp to select on the various gsl_{vector,matrix}*_{get,set} functions."
@@ -162,7 +88,3 @@
 		       `("gsl_" :category :type ,"_set")
 		       'matrix tp)))
 		 c-array:*array-element-types*)))
-
-
-
-
diff --git a/grid/element-reference.lisp b/grid/element-reference.lisp
new file mode 100644
index 00000000..9c007192
--- /dev/null
+++ b/grid/element-reference.lisp
@@ -0,0 +1,83 @@
+;; Get/set array or elements: cl-array, maref
+;; Liam Healy 2009-12-21 09:40:27EST element-reference.lisp
+;; Time-stamp: <2009-12-21 09:47:31EST element-reference.lisp>
+
+(in-package :c-array)
+
+(export '(cl-array maref))
+
+;;; These functions handle the details of converting between the C
+;;; representation of arrays and Common Lisp arrays.  The function
+;;; #'maref can be treated like #'aref for reading and setting
+;;; elements, except that it is limited to two indices (vectors or
+;;; matrices only) and requires a final argument with the element
+;;; type when taking a C pointer as the first argument (only needed
+;;; in the case of solve-minimize-fit for callbacks and some return
+;;; values).
+
+;;; Both these functions take one of the following class arguments for
+;;; the array:
+;;; - a foreign-array
+;;; - a Common Lisp array
+
+;;;;****************************************************************************
+;;;; Get the entire array:  cl-array
+;;;;****************************************************************************
+
+(defgeneric cl-array (object &optional array-rank element-type)
+  (:documentation
+   "The array as a CL native array.  The object may be a foreign-array object,
+    or an ordinary CL array of one or two dimensions.  Optional
+    arguments array-rank and element-type are used only for
+    pointers.")
+  (:method ((object foreign-array) &optional array-rank element-type)
+    (declare (ignore array-rank element-type))
+    #-native (copy-c-to-cl object)
+    (slot-value object 'cl-array))
+  (:method ((object array) &optional array-rank element-type)
+    ;; For compatibility, work on CL arrays as well.
+    (declare (ignore array-rank element-type))
+    object))
+
+;;;;****************************************************************************
+;;;; Get or set elements of the array:  maref, (setf maref)
+;;;;****************************************************************************
+
+(defgeneric maref (object index &optional index2 type)
+  (:documentation
+   "An element of the data.  The object may be a foreign-array
+   object or an ordinary CL array of one or two dimensions.")
+  (:method ((object foreign-array) index &optional index2 type)
+    (declare (ignore type))
+    #-native (copy-c-to-cl object)
+    (if index2
+	(aref (cl-array object) index index2)
+	(aref (cl-array object) index)))
+  (:method ((object array) index &optional index2 type)
+    ;; For compatibility, work on CL arrays as well.
+    (declare (ignore type))
+    (if index2
+	(aref object index index2)
+	(aref object index))))
+
+;;; Alternative to complete copy is to mark which elements have
+;;; changed and just copy them.  Is it worth it?
+
+(defgeneric (setf maref) (value object index &optional index2 type)
+  (:documentation
+   "Set an element of the data.  The object may be a
+    foreign-array object or an ordinary CL array of one or two
+    dimensions.")
+  (:method (value (object foreign-array) index &optional index2 type)
+    (declare (ignore type))
+    (if index2
+	(setf (aref (slot-value object 'cl-array) index index2) value)
+	(setf (aref (slot-value object 'cl-array) index) value))
+    #-native (setf (c-invalid object) t))
+  (:method (value (object array) index &optional index2 type)
+    ;; For compatibility, work on CL arrays as well.
+    (declare (ignore type))
+    (if index2
+	(setf (aref object index index2) value)
+	(setf (aref object index) value))))
+
diff --git a/gsll.asd b/gsll.asd
index 84ab9564..ba58b98a 100644
--- a/gsll.asd
+++ b/gsll.asd
@@ -1,6 +1,6 @@
 ;; Definition of GSLL system 
 ;; Liam Healy
-;; Time-stamp: <2009-12-21 08:45:28EST gsll.asd>
+;; Time-stamp: <2009-12-21 09:44:15EST gsll.asd>
 
 (when (asdf:find-system :fsbv nil)
   (pushnew :fsbv *features*))
@@ -26,7 +26,8 @@
 	     (:file "number-conversion"
 		    :depends-on ("pkgdcl" "complex-types" "symbol-type"))
 	     (:file "foreign-friendly" :depends-on ("pkgdcl"))
-	     (:file "foreign-array" :depends-on ("pkgdcl" "foreign-friendly"))))
+	     (:file "foreign-array" :depends-on ("pkgdcl" "foreign-friendly"))
+	     (:file "element-reference" :depends-on ("pkgdcl"))))
    (:module init
 	    :depends-on (grid)
 	    :components
diff --git a/init/init.lisp b/init/init.lisp
index 67f950fe..c2f541a1 100644
--- a/init/init.lisp
+++ b/init/init.lisp
@@ -1,6 +1,6 @@
 ;; Load GSL
 ;; Liam Healy Sat Mar  4 2006 - 18:53
-;; Time-stamp: <2009-12-21 08:59:29EST init.lisp>
+;; Time-stamp: <2009-12-21 09:49:47EST init.lisp>
 ;; $Id$
 
 (defpackage gsll
@@ -9,7 +9,10 @@
   (:import-from
    :c-array
    #:cl-array #:dimensions #:total-size #:element-type #:dim0 #:dim1
-   #:c-pointer))
+   #:c-pointer #:maref)
+  (:export
+   #:cl-array #:dimensions #:total-size #:element-type #:dim0 #:dim1
+   #:maref))
 
 (cffi:define-foreign-library libgslcblas
     (:darwin
-- 
GitLab