diff --git a/README b/README index 268f7ecc90d527df4581a33b2be2a430513016aa..5260202d1c1b2277a1e1a016e545a5d6b63b00f9 100644 --- a/README +++ b/README @@ -44,4 +44,4 @@ I have implemented only one, double. This means that the following functions have been put aside: - #'polynomial-solve (requires vector_complex) - The index functions in sorting that are not returning permutations, -because the need a vector_int. +because they need a vector_int. diff --git a/init/interface.lisp b/init/interface.lisp index 9363e9c9f43238f8a51c2f6e3990f2eb05ae5325..d871b951c439a9a645a99ed791282212c929f90b 100644 --- a/init/interface.lisp +++ b/init/interface.lisp @@ -3,7 +3,7 @@ ; description: Macros to interface GSL functions. ; date: Mon Mar 6 2006 - 22:35 ; author: Liam M. Healy -; modified: Fri Apr 28 2006 - 22:31 +; modified: Sat Apr 29 2006 - 10:06 ;******************************************************** (in-package :gsl) @@ -201,7 +201,7 @@ and a scaling exponent e10, such that the value is val*10^e10." (rest wrappers)) form)) -;;; All arrays and vectors are pass with a gsl-data object that is made +;;; All arrays and vectors are passed with a gsl-data object that is made ;;; outside the function, and pieces are spliced in the function call. ;;; If a raw array is needed, use the :function argument to defun-gsl, ;;; then use the appropriate function(s) e.g. gsl-array, dim0 @@ -261,7 +261,7 @@ and a scaling exponent e10, such that the value is val*10^e10." (defmacro defun-gsl (cl-name arguments gsl-name &key documentation return mode (c-return-value :error-code) - return-input check-null-pointers function method after) + return-input check-null-pointers function method invalidate after) "Define a CL function that provides an interface to a GSL function. If cl-name is :lambda, make a lambda. Arguments: arguments: a list of input arguments (symbol type) to the GSL function @@ -269,17 +269,20 @@ and a scaling exponent e10, such that the value is val*10^e10." documentation: a string return: a list of return types return-input: input variables to return - mode: T or NIL, depending on whether gsl_mode is an argument + mode: T, NIL or position, depending on whether + gsl_mode is an argument c-return-value: The C function returns an :error-code, :number-of-answers, - a value to :return from the CL function, :success-failure - as T or NIL, or :void. + a value to :return from the CL function, a + :success-failure code to be returned from CL as T or NIL, + or :void. check-null-pointers: a list of return variables that should be checked, if a null pointer, signal an error. method Make output a defmethod with the value as the arglist; 'arguments should then include explicit mapping of all arguments to GSL form. - function Arguments for CL function (like :method, but make a function) + function Arguments for CL function (like :method, but make a function). + invalidate CL copies of data to invalidate before return. after Functions to call after the GSL function has been called; result is discarded." (let ((clargs (or function method (mapcar #'rst-symbol arguments))) @@ -313,6 +316,7 @@ and a scaling exponent e10, such that the value is val*10^e10." `((check-gsl-status creturn `(,',cl-name))) ; need args `((check-gsl-status creturn `(,',cl-name ,,@clargs)))))) ,@(check-null-pointers check-null-pointers) + ,@(when invalidate `((cl-invalidate ,@invalidate))) ,@after (values ,@return-input diff --git a/linear-algebra/lu.lisp b/linear-algebra/lu.lisp index 91b1b0ef1b17bea639beb312d9611130c806f940..627676ec654f1ba36fae0e176456c51537ff4879 100644 --- a/linear-algebra/lu.lisp +++ b/linear-algebra/lu.lisp @@ -3,7 +3,7 @@ ; description: LU decomposition ; date: Thu Apr 27 2006 - 12:42 ; author: Liam Healy -; modified: Fri Apr 28 2006 - 17:01 +; modified: Sat Apr 29 2006 - 18:09 ;******************************************************** ;;; $Id: $ @@ -29,21 +29,27 @@ The algorithm used in the decomposition is Gaussian Elimination with partial pivoting (Golub & Van Loan, @cite{Matrix Computations}, - Algorithm 3.4.1).") + Algorithm 3.4.1)." + :invalidate (A p) + :return-input (A p)) (defun-gsl LU-solve ((LU gsl-matrix-c) (p gsl-permutation-c) (b gsl-vector-c) (x gsl-vector-c)) "gsl_linalg_LU_solve" :documentation "Solve the square system @math{A x = b} using the @math{LU} decomposition of @math{A} into (@var{LU}, @var{p}) given by - LU-decomp.") + LU-decomp." + :invalidate (x) + :return-input (x)) (defun-gsl LU-svx ((LU gsl-matrix-c) (p gsl-permutation-c) (x gsl-vector-c)) "gsl_linalg_LU_svx" :documentation "Solve the square system @math{A x = b} in-place using the @math{LU} decomposition of @math{A} into (@var{LU},@var{p}). On input @var{x} should contain the right-hand - side @math{b}, which is replaced by the solution on output.") + side @math{b}, which is replaced by the solution on output." + :invalidate (x) + :return-input (x)) (defun-gsl LU-refine ((A gsl-matrix-c) (LU gsl-matrix-c) (p gsl-permutation-c) @@ -51,7 +57,9 @@ "gsl_linalg_LU_refine" :documentation "Apply an iterative improvement to x, the solution of A x = b, using the LU decomposition of A into (LU,p). The initial - residual r = A x - b is also computed and stored in residual. ") + residual r = A x - b is also computed and stored in residual. " + :invalidate (x residual) + :return-input (x residual)) (defun-gsl LU-invert ((LU gsl-matrix-c) (p gsl-permutation-c) (inverse gsl-matrix-c)) @@ -62,23 +70,31 @@ the identity matrix. It is preferable to avoid direct use of the inverse whenever possible, as the linear solver functions can obtain the same result more efficiently and reliably (consult any - introductory textbook on numerical linear algebra for details).") + introductory textbook on numerical linear algebra for details)." + :invalidate (inverse) + :return-input (inverse)) (defun-gsl LU-det ((LU gsl-matrix-c) (signum :int)) "gsl_linalg_LU_det" :documentation "Compute the determinant of a matrix A from its LU decomposition, LU. The determinant is computed as the product of the - diagonal elements of U and the sign of the row permutation signum.") + diagonal elements of U and the sign of the row permutation signum." + :c-return-value :return + :return (:double)) (defun-gsl LU-lndet ((LU gsl-matrix-c)) "gsl_linalg_LU_lndet" :documentation "The logarithm of the absolute value of the determinant of a matrix A, \ln|\det(A)|, from its LU decomposition, LU. This function may be useful if the direct computation of the - determinant would overflow or underflow.") + determinant would overflow or underflow." + :c-return-value :return + :return (:double)) (defun-gsl LU-sgndet ((LU gsl-matrix-c) (signum :int)) "gsl_linalg_LU_sgndet" :documentation "Compute the sign or phase factor of the determinant of a matrix A, - \det(A)/|\det(A)|, from its LU decomposition, LU.") + \det(A)/|\det(A)|, from its LU decomposition, LU." + :c-return-value :return + :return (:int)) diff --git a/linear-algebra/qr.lisp b/linear-algebra/qr.lisp index ea78e04e2e4494126a0685abb957a64dc8bfc666..cb9b8235729ac2175539e68180ad43e27c14e8e1 100644 --- a/linear-algebra/qr.lisp +++ b/linear-algebra/qr.lisp @@ -3,7 +3,7 @@ ; description: QR decomposition ; date: Fri Apr 28 2006 - 16:53 ; author: Liam Healy -; modified: Fri Apr 28 2006 - 21:03 +; modified: Sat Apr 29 2006 - 18:00 ;******************************************************** ;;; $Id: $ @@ -39,7 +39,7 @@ The algorithm used to perform the decomposition is Householder QR (Golub & Van Loan, @cite{Matrix Computations}, Algorithm 5.2.1)." - :after ((cl-invalidate A)) + :invalidate (A) :return-input (A tau)) (defun-gsl QR-solve @@ -49,7 +49,7 @@ decomposition of @math{A} into (@var{QR}, @var{tau}) given by QR-decomp. The least-squares solution for rectangular systems can be found using QR-lssolve." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) (defun-gsl QR-svx ((QR gsl-matrix-c) (tau gsl-vector-c) (x gsl-vector-c)) @@ -58,7 +58,7 @@ @math{QR} decomposition of @math{A} into (@var{QR},@var{tau}) given by QR-decomp. On input @var{x} should contain the right-hand side @math{b}, which is replaced by the solution on output." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) (defun-gsl QR-lssolve @@ -72,7 +72,7 @@ of @math{A} into (@var{QR}, @var{tau}) given by @code{gsl_linalg_QR_decomp}. The solution is returned in @var{x}. The residual is computed as a by-product and stored in @var{residual}." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) (defun-gsl QR-QTvec ((QR gsl-matrix-c) (tau gsl-vector-c) (v gsl-vector-c)) @@ -82,7 +82,7 @@ v} in @var{v}. The matrix multiplication is carried out directly using the encoding of the Householder vectors without needing to form the full matrix @math{Q^T}." - :after ((cl-invalidate v)) + :invalidate (v) :return-input (v)) (defun-gsl QR-Qvec ((QR gsl-matrix-c) (tau gsl-vector-c) (v gsl-vector-c)) @@ -92,7 +92,7 @@ v} in @var{v}. The matrix multiplication is carried out directly using the encoding of the Householder vectors without needing to form the full matrix @math{Q}." - :after ((cl-invalidate v)) + :invalidate (v) :return-input (v)) (defun-gsl QR-Rsolve ((QR gsl-matrix-c) (b gsl-vector-c) (x gsl-vector-c)) @@ -100,7 +100,7 @@ :documentation "Solve the triangular system @math{R x = b} for @var{x}. It may be useful if the product @math{b' = Q^T b} has already been computed using QR-QTvec}." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) (defun-gsl QR-Rsvx ((QR gsl-matrix-c) (x gsl-vector-c)) @@ -110,7 +110,7 @@ and is replaced by the solution on output. This function may be useful if the product @math{b' = Q^T b} has already been computed using QR-QTvec}." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) (defun-gsl QR-unpack @@ -119,7 +119,7 @@ :documentation "Unpack the encoded @math{QR} decomposition (@var{QR},@var{tau}) into the matrices @var{Q} and @var{R}, where @var{Q} is @math{M}-by-@math{M} and @var{R} is @math{M}-by-@math{N}." - :after ((cl-invalidate Q R)) + :invalidate (Q R) :return-input (Q R)) (defun-gsl QR-QRsolve @@ -128,7 +128,7 @@ :documentation "Solves the system @math{R x = Q^T b} for @var{x}. It can be used when the @math{QR} decomposition of a matrix is available in unpacked form as (@var{Q}, @var{R})." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) (defun-gsl QR-update @@ -139,14 +139,14 @@ R + w v^T} where the output matrices @math{Q'} and @math{R'} are also orthogonal and right triangular. Note that @var{w} is destroyed by the update." - :after ((cl-invalidate w Q R)) + :invalidate (w Q R) :return-input (Q R)) (defun-gsl R-solve ((R gsl-matrix-c) (b gsl-vector-c) (x gsl-vector-c)) "gsl_linalg_R_solve" :documentation "Solves the triangular system @math{R x = b} for the @math{N}-by-@math{N} matrix @var{R}." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) (defun-gsl R-svx ((R gsl-matrix-c) (x gsl-vector-c)) @@ -154,5 +154,5 @@ :documentation "Solve the triangular system @math{R x = b} in-place. On input @var{x} should contain the right-hand side @math{b}, which is replaced by the solution on output." - :after ((cl-invalidate x)) + :invalidate (x) :return-input (x)) diff --git a/special-functions/hypergeometric.lisp b/special-functions/hypergeometric.lisp index 7a41352ba93b026bd09f863bbb809905774b2c93..af98d3507fddc6ddbde56dae1f82490af221134f 100644 --- a/special-functions/hypergeometric.lisp +++ b/special-functions/hypergeometric.lisp @@ -3,7 +3,7 @@ ; description: Hypergeometric function ; date: Fri Apr 28 2006 - 23:00 ; author: Liam M. Healy -; modified: Fri Apr 28 2006 - 23:52 +; modified: Sat Apr 29 2006 - 17:58 ;******************************************************** ;;; $Id: $ @@ -62,10 +62,10 @@ approximation converges too slowly. This occurs in the region of @math{x=1}, @math{c - a - b = m} for integer m.") -(defun-gsl hypergeometric-2F1 +(defun-gsl hypergeometric-2F1-conj (((realpart a) :double) ((imagpart a) :double) (c :double) (x :double)) "gsl_sf_hyperg_2F1_conj_e" - :function (a b c x) + :function (a c x) :return (sf-result) :documentation "The Gauss hypergeometric function @math{2F1(a, a*, c, x)} with complex parameters