Update of /project/cl-gsl/cvsroot/cl-gsl
In directory common-lisp.net:/tmp/cvs-serv17913
Modified Files:
poly.lisp
Log Message:
Added divided difference functions.
Date: Sun Mar 13 01:48:25 2005
Author: edenny
Index: cl-gsl/poly.lisp
diff -u cl-gsl/poly.lisp:1.1.1.1 cl-gsl/poly.lisp:1.2
--- cl-gsl/poly.lisp:1.1.1.1 Wed Mar 2 02:04:53 2005
+++ cl-gsl/poly.lisp Sun Mar 13 01:48:25 2005
@@ -170,72 +170,72 @@
(ret-val))
(setq ret-val (gsl-poly-complex-solve a-ptr len w z-ptr))
(gsl-poly-complex-workspace-free w)
- (prog1
- ;; FIXME: where is ret-val in result?
+ (multiple-value-prog1
(values (complex-packed-array->lisp-vec z-ptr (* 2 (1- len))) ret-val)
(uffi:free-foreign-object z-ptr))))
;; ----------------------------------------------------------------------
-;; (defun-foreign "gsl_poly_dd_int"
-;; ((dd double-ptr)
-;; (xa double-ptr)
-;; (ya double-ptr)
-;; (size :unsigned-long))
-;; :int)
-
-;; (defun-foreign "gsl_poly_dd_eval"
-;; ((dd double-ptr)
-;; (xa double-ptr)
-;; (size :unsigned-long)
-;; (x :double))
-;; :double)
-
-;; (defun-foreign "gsl_poly_dd_taylor"
-;; ((c double-ptr)
-;; (xp :double)
-;; (dd double-ptr)
-;; (xa double-ptr)
-;; (size :unsigned-long)
-;; (w double-ptr))
-;; :int)
-
-
-;; (defun dd-int (xa ya)
-;; (let* ((xa-ptr (lisp-vec->c-array xa))
-;; (ya-ptr (lisp-vec->c-array ya))
-;; (len (length xa))
-;; (dd-ptr (uffi:allocate-foreign-object :double len))
-;; (ret-val))
-;; (setq ret-val (gsl-poly-dd-init dd-ptr xa-ptr ya-ptr len))
-
-
-
-;; Function: int gsl_poly_dd_init (double dd[], const double xa[], const double ya[], size_t size)
-;; This function computes a divided-difference representation of the interpolating polynomial for the points (xa, ya) stored in the arrays xa and ya of length size.
-;; On output the divided-differences of (xa,ya) are stored in the array dd, also of length size.
-
-;; Function: double gsl_poly_dd_eval (const double dd[], const double xa[], const size_t size, const double x)
-;; This function evaluates the polynomial stored in divided-difference form in the arrays dd and xa of length size at the point x.
-
-;; Function: int gsl_poly_dd_taylor (double c[], double xp, const double dd[], const double xa[], size_t size, double w[])
-;; This function converts the divided-difference representation of a polynomial to a Taylor expansion. The divided-difference representation is supplied in the
-;; arrays dd and xa of length size. On output the Taylor coefficients of the polynomial expanded about the point xp are stored in the array c also of length size. A
-;; workspace of length size must be provided in the array w.
-
-
-
+(defun-foreign "gsl_poly_dd_init"
+ ((dd double-ptr)
+ (xa double-ptr)
+ (ya double-ptr)
+ (size :unsigned-long))
+ :int)
+
+(defun dd-init (xa ya)
+ (let* ((xa-ptr (lisp-vec->c-array xa))
+ (ya-ptr (lisp-vec->c-array ya))
+ (len (length xa))
+ (dd-ptr (uffi:allocate-foreign-object :double len))
+ (ret-val))
+ (setq ret-val (gsl-poly-dd-init dd-ptr xa-ptr ya-ptr len))
+ (multiple-value-prog1
+ (values (c-array->lisp-vec dd-ptr len) ret-val)
+ (uffi:free-foreign-object xa-ptr)
+ (uffi:free-foreign-object ya-ptr)
+ (uffi:free-foreign-object dd-ptr))))
+;; ----------------------------------------------------------------------
-;; #define GSL_REAL(z) ((z).dat[0])
-;; #define GSL_IMAG(z) ((z).dat[1])
-;; #define GSL_COMPLEX_P(zp) ((zp)->dat)
-;; #define GSL_COMPLEX_P_REAL(zp) ((zp)->dat[0])
-;; #define GSL_COMPLEX_P_IMAG(zp) ((zp)->dat[1])
-;; #define GSL_COMPLEX_EQ(z1,z2) (((z1).dat[0] == (z2).dat[0]) && ((z1).dat[1] == (z2).dat[1]))
+(defun-foreign "gsl_poly_dd_eval"
+ ((dd double-ptr)
+ (xa double-ptr)
+ (size :unsigned-long)
+ (x :double))
+ :double)
+
+(defun dd-eval (dd xa x)
+ (let ((dd-ptr (lisp-vec->c-array dd))
+ (xa-ptr (lisp-vec->c-array xa))
+ (len (length dd)))
+ (prog1
+ (gsl-poly-dd-eval dd-ptr xa-ptr len x)
+ (uffi:free-foreign-object xa-ptr)
+ (uffi:free-foreign-object dd-ptr))))
-;; #define GSL_SET_COMPLEX(zp,x,y) do {(zp)->dat[0]=(x); (zp)->dat[1]=(y);} while(0)
-;; #define GSL_SET_REAL(zp,x) do {(zp)->dat[0]=(x);} while(0)
-;; #define GSL_SET_IMAG(zp,y) do {(zp)->dat[1]=(y);} while(0)
+;; ----------------------------------------------------------------------
-;; #define GSL_SET_COMPLEX_PACKED(zp,n,x,y) do {*((zp)+2*(n))=(x); *((zp)+(2*(n)+1))=(y);} while(0)
+(defun-foreign "gsl_poly_dd_taylor"
+ ((c double-ptr)
+ (xp :double)
+ (dd double-ptr)
+ (xa double-ptr)
+ (size :unsigned-long)
+ (w double-ptr))
+ :int)
+
+(defun dd-taylor (xp dd xa)
+ (let* ((dd-ptr (lisp-vec->c-array dd))
+ (xa-ptr (lisp-vec->c-array xa))
+ (len (length dd))
+ (w-ptr (uffi:allocate-foreign-object :double len))
+ (c-ptr (uffi:allocate-foreign-object :double len))
+ (ret-val))
+ (setq ret-val (gsl-poly-dd-taylor c-ptr xp dd-ptr xa-ptr len w-ptr))
+ (multiple-value-prog1
+ (values (c-array->lisp-vec c-ptr len) ret-val)
+ (uffi:free-foreign-object w-ptr)
+ (uffi:free-foreign-object xa-ptr)
+ (uffi:free-foreign-object dd-ptr)
+ (uffi:free-foreign-object c-ptr))))