Commit 3680b307 authored by Liam Healy's avatar Liam Healy

Move copy, copy-making-destination to grid

Moved the definition of the generic function copy-making-destination
to copy objects while making a destination object, and the wrapper
function #'copy for that and copy-to-destination to grid/ and c-array:
package.
parent 06f99392
;; Functions for both vectors and matrices.
;; Liam Healy 2008-04-26 20:48:44EDT both.lisp
;; Time-stamp: <2009-12-21 10:21:28EST both.lisp>
;; Time-stamp: <2009-12-21 10:47:55EST both.lisp>
(in-package :gsl)
......@@ -61,7 +61,7 @@
:inputs (source)
:outputs (destination))
(defmfun copy-making-destination
(defmfun c-array:copy-making-destination
((source both) &aux
(destination
(make-marray element-type :dimensions (dimensions source))))
......
;; A "marray" is an array in both GSL and CL
;; Liam Healy 2008-04-06 21:23:41EDT
;; Time-stamp: <2009-12-21 10:21:31EST marray.lisp>
;; Time-stamp: <2009-12-21 10:47:55EST marray.lisp>
(in-package :gsl)
......@@ -199,7 +199,7 @@
"Create a contents list from the GSL object of type struct-type
referenced by pointer."))
(defmethod copy-making-destination ((pointer #.+foreign-pointer-class+))
(defmethod c-array:copy-making-destination ((pointer #.+foreign-pointer-class+))
(foreign-pointer-method
pointer
;; Default assumption when destination isn't given in #'copy is
......
;; Copy objects
;; Liam Healy 2009-12-21 10:16:04EST copy.lisp
;; Time-stamp: <2009-12-21 10:24:07EST copy.lisp>
;; Time-stamp: <2009-12-21 10:46:41EST copy.lisp>
;; $Id: $
(in-package :c-array)
(export '(copy-to-destination array-mismatch))
(export
'(copy clone copy-to-destination copy-making-destination array-mismatch))
(defun copy (object &optional destination)
"Create a duplicate object."
(if destination
(copy-to-destination object destination)
(copy-making-destination object)))
;;; Could be part of copy when the second argument is optional?
(defgeneric clone (object)
(:documentation "Create a duplicate object."))
(defgeneric copy-making-destination (object)
(:documentation "Create new duplicate object."))
(defgeneric copy-to-destination (object destination)
;; This copies values into an existing object. Methods are defined
......
;; The histogram structure
;; Liam Healy, Mon Jan 1 2007 - 11:32
;; Time-stamp: <2009-12-21 10:21:26EST histogram.lisp>
;; Time-stamp: <2009-12-21 10:47:54EST histogram.lisp>
;; $Id$
(in-package :gsl)
......@@ -88,14 +88,14 @@
an exact copy of the former.
The two histograms must be of the same size.")
(defmfun copy-making-destination ((source histogram))
(defmfun c-array:copy-making-destination ((source histogram))
"gsl_histogram_clone"
(((mpointer source) :pointer))
:definition :method
:c-return :pointer
:index copy)
(defmfun copy-making-destination ((source histogram2d))
(defmfun c-array:copy-making-destination ((source histogram2d))
"gsl_histogram2d_clone"
(((mpointer source) :pointer))
:definition :method
......
;; Load GSL
;; Liam Healy Sat Mar 4 2006 - 18:53
;; Time-stamp: <2009-12-21 09:49:47EST init.lisp>
;; Time-stamp: <2009-12-21 10:45:40EST init.lisp>
;; $Id$
(defpackage gsll
......@@ -9,10 +9,10 @@
(:import-from
:c-array
#:cl-array #:dimensions #:total-size #:element-type #:dim0 #:dim1
#:c-pointer #:maref)
#:c-pointer #:maref #:copy #:clone)
(:export
#:cl-array #:dimensions #:total-size #:element-type #:dim0 #:dim1
#:maref))
#:maref #:copy #:clone))
(cffi:define-foreign-library libgslcblas
(:darwin
......
;; Definition of GSL objects and ways to use them.
;; Liam Healy, Sun Dec 3 2006 - 10:21
;; Time-stamp: <2009-12-21 10:21:27EST mobject.lisp>
;; Time-stamp: <2009-12-21 10:44:01EST mobject.lisp>
;;; GSL objects are represented in GSLL as and instance of a 'mobject.
;;; The macro demobject takes care of defining the appropriate
......@@ -337,42 +337,22 @@
;;;; Making objects from existing objects
;;;;****************************************************************************
(export 'copy)
(defun copy (object &optional destination)
"Create a duplicate object."
(if destination
(c-array:copy-to-destination object destination)
(copy-making-destination object)))
(defgeneric copy-making-destination (object)
(:documentation "Create new duplicate object.")
(:method :around ((object mobject))
(if (next-method-p)
;; The subclass method should only return the malloced
;; mpointer (as from a "_clone" function); it will be put into
;; the CL object here. The initial-instance method for these
;; objects must be written to do nothing if the mpointer is
;; already defined.
;; Defined for
;; histogram, histogram2d,
;; random-number-generator, quasi-random-number-generator,
(if (typep object 'marray)
(call-next-method)
(make-instance (class-of object) :mpointer (call-next-method)))
;; The subclass does not supply a method, so this will be called
;; by default. We can only try to make something from the load form.
(eval (make-load-form object)))))
;;; Could be part of copy when the second argument is optional?
(export 'clone)
(defgeneric clone (object)
(:documentation "Create a duplicate object.")
(:method :around ((object mobject))
(make-instance (class-of object) :mpointer (call-next-method))))
;;; To make-load-form
;;; (make-basis-spline (bspline-order bspline) (number-of-breakpoints bspline))
;;; Then initialize by making a vector from (breakpoint i bspline)
;;; and calling knots.
(defmethod c-array:copy-making-destination :around ((object mobject))
(if (next-method-p)
;; The subclass method should only return the malloced
;; mpointer (as from a "_clone" function); it will be put into
;; the CL object here. The initial-instance method for these
;; objects must be written to do nothing if the mpointer is
;; already defined.
;; Defined for
;; histogram, histogram2d,
;; random-number-generator, quasi-random-number-generator,
(if (typep object 'marray)
(call-next-method)
(make-instance (class-of object) :mpointer (call-next-method)))
;; The subclass does not supply a method, so this will be called
;; by default. We can only try to make something from the load form.
(eval (make-load-form object))))
(defmethod c-array:clone :around ((object mobject))
(make-instance (class-of object) :mpointer (call-next-method)))
;; Generators of random numbers.
;; Liam Healy, Sat Jul 15 2006 - 14:43
;; Time-stamp: <2009-12-21 10:21:25EST generators.lisp>
;; Time-stamp: <2009-12-21 10:47:53EST generators.lisp>
;; $Id$
(in-package :gsl)
......@@ -173,7 +173,7 @@
making destination into an exact copy
of source. The two generators must be of the same type.")
(defmfun copy-making-destination ((instance random-number-generator))
(defmfun c-array:copy-making-destination ((instance random-number-generator))
"gsl_rng_clone" (((mpointer instance) :pointer))
:definition :method
:c-return :pointer
......
;; Quasi-random sequences in arbitrary dimensions.
;; Liam Healy, Sun Jul 16 2006 - 15:54
;; Time-stamp: <2009-12-21 10:21:25EST quasi.lisp>
;; Time-stamp: <2009-12-21 10:47:54EST quasi.lisp>
;; $Id$
(in-package :gsl)
......@@ -61,7 +61,7 @@
pre-existing generator dest, making dest into an exact copy
of src. The two generators must be of the same type.")
(defmfun copy-making-destination ((instance quasi-random-number-generator))
(defmfun c-array:copy-making-destination ((instance quasi-random-number-generator))
"gsl_qrng_clone" (((mpointer instance) :pointer))
:definition :method
:c-return :pointer
......
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