Commit f3a45c98 authored by Liam Healy's avatar Liam Healy

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.
parent a9cf4a74
;; 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*)))
;; 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))))
;; 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
......
;; 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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment