From 84b5a165186a43ebfdf1c8e98f77ac0653963a93 Mon Sep 17 00:00:00 2001 From: Liam Healy <liam@thinkpad.local> Date: Sun, 15 Feb 2009 11:09:25 -0500 Subject: [PATCH] Chebyshev ported to callbacks-included and example/test fixed Chebyshev object now built on callbacks-included. The example/test was generating an error because the calls in integral-chebyshev and derivative-chebyshev did not have a needed #'mpointer call. This has been fixed and the test results match the previous result given in 8d9ce4e810. --- chebyshev.lisp | 27 ++++++++++++++++-------- init/callback.lisp | 10 +++++---- solve-minimize-fit/minimization-one.lisp | 5 +---- tests/chebyshev.lisp | 8 ++++--- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/chebyshev.lisp b/chebyshev.lisp index bbf3c920..b786641d 100644 --- a/chebyshev.lisp +++ b/chebyshev.lisp @@ -1,6 +1,6 @@ ;; Chebyshev Approximations ;; Liam Healy Sat Nov 17 2007 - 20:36 -;; Time-stamp: <2009-01-28 19:05:30EST chebyshev.lisp> +;; Time-stamp: <2009-02-15 10:44:23EST chebyshev.lisp> ;; $Id$ (in-package :gsl) @@ -16,9 +16,19 @@ "Chebyshev series" :documentation ; FDL "Make a Chebyshev series of specified order." + :superclasses (callback-included) + :ci-class-slots (gsl-function nil (function)) :initialize-suffix "init" :initialize-args - ((function :pointer) (lower-limit :double) (upper-limit :double))) + ((callback :pointer) (lower-limit :double) (upper-limit :double)) + :singular (function)) + +(def-make-callbacks chebyshev (function) + `(defmcallback ,function + :double :double + nil + t + ,function)) ;;;;**************************************************************************** ;;;; Chebyshev series evaluation @@ -55,7 +65,7 @@ (defmfun derivative-chebyshev (derivative chebyshev) "gsl_cheb_calc_deriv" - ((derivative :pointer) ((mpointer chebyshev) :pointer)) + (((mpointer derivative) :pointer) ((mpointer chebyshev) :pointer)) :documentation ; FDL "Compute the derivative of the Chebyshev series, storing the derivative coefficients in the previously allocated series. @@ -63,7 +73,7 @@ (defmfun integral-chebyshev (integral chebyshev) "gsl_cheb_calc_integ" - ((integral :pointer) ((mpointer chebyshev) :pointer)) + (((mpointer integral) :pointer) ((mpointer chebyshev) :pointer)) :documentation ; FDL "Compute the integral of the Chebyshev series, storing the integral coefficients in the previously allocated series. @@ -80,11 +90,11 @@ (defun chebyshev-step (x) (if (< x 0.5d0) 0.25d0 0.75d0)) +(make-callbacks chebyshev chebyshev-step) + (defun chebyshev-table-example () (let ((steps 100)) - (let ((cheb - (make-chebyshev - 40 (make-single-function chebyshev-step) 0.0d0 1.0d0))) + (let ((cheb (make-chebyshev 40 'chebyshev-step 0.0d0 1.0d0))) (dotimes (i steps) (let ((x (coerce (/ i steps) 'double-float))) (format t "~&~a ~a ~a ~a" @@ -95,8 +105,7 @@ (defun chebyshev-point-example (x) (check-type x double-float) - (let ((cheb (make-chebyshev - 40 (make-single-function chebyshev-step) 0.0d0 1.0d0)) + (let ((cheb (make-chebyshev 40 'chebyshev-step 0.0d0 1.0d0)) (deriv (make-chebyshev 40)) (integ (make-chebyshev 40))) (derivative-chebyshev deriv cheb) diff --git a/init/callback.lisp b/init/callback.lisp index 5443ff25..96bea591 100644 --- a/init/callback.lisp +++ b/init/callback.lisp @@ -1,6 +1,6 @@ ;; Foreign callback functions. ;; Liam Healy -;; Time-stamp: <2009-02-14 19:22:53EST callback.lisp> +;; Time-stamp: <2009-02-15 10:43:05EST callback.lisp> ;; $Id$ (in-package :gsl) @@ -372,7 +372,9 @@ (defmethod print-object ((object callback-included) stream) (print-unreadable-object (object stream :type t :identity t) - (princ "for " stream) - (princ (first (functions object)) stream) - (princ ", dimensions " stream) + (when (slot-boundp object 'functions) + (princ "for " stream) + (princ (first (functions object)) stream) + (princ "," stream)) + (princ "dimensions " stream) (princ (dimensions object) stream))) diff --git a/solve-minimize-fit/minimization-one.lisp b/solve-minimize-fit/minimization-one.lisp index abab813e..d9ec300f 100644 --- a/solve-minimize-fit/minimization-one.lisp +++ b/solve-minimize-fit/minimization-one.lisp @@ -1,6 +1,6 @@ ;; Univariate minimization ;; Liam Healy Tue Jan 8 2008 - 21:02 -;; Time-stamp: <2009-02-10 21:47:41EST minimization-one.lisp> +;; Time-stamp: <2009-02-15 10:14:09EST minimization-one.lisp> ;; $Id$ (in-package :gsl) @@ -192,9 +192,6 @@ (make-callbacks one-dimensional-minimizer minimization-one-fn) -#+callback-toplevel-only -(defparameter *minone-cb* (make-single-function minimization-one-fn)) - (defun minimization-one-example (&optional (minimizer-type *brent-fminimizer*) (print-steps t)) "Solving a minimum, the example given in Sec. 33.8 of the GSL manual." diff --git a/tests/chebyshev.lisp b/tests/chebyshev.lisp index 721aef02..6863a358 100644 --- a/tests/chebyshev.lisp +++ b/tests/chebyshev.lisp @@ -3,7 +3,9 @@ (in-package :gsl) (LISP-UNIT:DEFINE-TEST CHEBYSHEV - (LISP-UNIT:ASSERT-ERROR 'TYPE-ERROR - (CHEBYSHEV-POINT-EXAMPLE - 0.55d0))) + (LISP-UNIT::ASSERT-NUMERICAL-EQUAL + (LIST + (LIST 0.7159209901689866d0 -1.5019966658054353d0 + 0.17239719403979925d0)) + (MULTIPLE-VALUE-LIST (CHEBYSHEV-POINT-EXAMPLE 0.55d0)))) -- GitLab