Commit 65a33d3e authored by Liam Healy's avatar Liam Healy

New directory "calculus" and small changes

New directory "calculus" to hold numerical-differentiation,
numerical-integeration, and monte-carlo.  Converted some return array
arguments in BLAS to optional arguments.  Define a condition
'obsolete-gsl-version to use in #'complete-definition.  Try to
incorporate cygwin into init.lisp; needs testing by a cygwin user.
parent b484c1d1
;; Definition of GSLL system
;; Liam Healy
;; Time-stamp: <2009-01-15 14:12:18EST gsll.asd>
;; Time-stamp: <2009-01-15 21:18:57EST gsll.asd>
;; $Id$
(asdf:defsystem "gsll"
:name "gsll"
:description "GNU Scientific Library for Lisp."
:version "0"
:author "Liam M. Healy"
:licence "LLGPL v3, FDL"
:depends-on (cffi trivial-garbage cl-utilities)
:components
((:module init
:components
((:file "init")
(:file "conditions" :depends-on (init))
(:file "mobject" :depends-on (init))
(:file "types" :depends-on (init))
(:file "complex-types" :depends-on (types))
(:file "element-types" :depends-on (init complex-types))
(:file "number-conversion" :depends-on (init))
(:file "interface"
:depends-on (init conditions element-types number-conversion))
(:file "defmfun" :depends-on (init element-types interface))
(:file "defmfun-array" :depends-on (defmfun))
(:file "defmfun-single" :depends-on (defmfun))
(:file "callback" :depends-on (init))
(:file "generate-examples" :depends-on (init))))
(:module floating-point
:depends-on (init)
:components
((:file "ieee-modes")
(:file "floating-point")))
(:module mathematical
:depends-on (init)
:components
((:file "mathematical")
(:file "complex")))
(:module data
:depends-on (init)
:components
((:file "foreign-friendly")
(:file "foreign-array" :depends-on (foreign-friendly))
(:file "marray" :depends-on (foreign-array))
(:file "vector" :depends-on (marray))
(:file "matrix" :depends-on (marray vector))
(:file "maref" :depends-on (marray vector matrix))
(:file "both" :depends-on (marray vector matrix))
(:file "array-tests" :depends-on (both))
(:file "permutation" :depends-on (marray))
(:file "combination" :depends-on (marray))))
(:file "polynomial" :depends-on (init data))
(:module special-functions
:depends-on (init)
:components
((:file "return-structures")
(:file "airy" :depends-on (return-structures))
(:file "bessel" :depends-on (return-structures))
(:file "clausen" :depends-on (return-structures))
(:file "coulomb" :depends-on (return-structures))
(:file "coupling" :depends-on (return-structures))
(:file "dawson" :depends-on (return-structures))
(:file "debye" :depends-on (return-structures))
(:file "dilogarithm" :depends-on (return-structures))
(:file "elementary" :depends-on (return-structures))
(:file "elliptic-integrals" :depends-on (return-structures))
(:file "elliptic-functions" :depends-on (return-structures))
(:file "error-functions" :depends-on (return-structures))
(:file "exponential-functions" :depends-on (return-structures))
(:file "exponential-integrals" :depends-on (return-structures))
(:file "fermi-dirac" :depends-on (return-structures))
(:file "gamma" :depends-on (return-structures))
(:file "gegenbauer" :depends-on (return-structures))
(:file "hypergeometric" :depends-on (return-structures))
(:file "laguerre" :depends-on (return-structures))
(:file "lambert" :depends-on (return-structures))
(:file "legendre" :depends-on (return-structures))
(:file "logarithm" :depends-on (return-structures))
(:file "power" :depends-on (return-structures))
(:file "psi" :depends-on (return-structures))
(:file "synchrotron" :depends-on (return-structures))
(:file "transport" :depends-on (return-structures))
(:file "trigonometry" :depends-on (return-structures))
(:file "zeta" :depends-on (return-structures))))
(:file "sorting" :depends-on (init data))
(:module linear-algebra
:depends-on (init data special-functions)
:components
((:file "blas1")
(:file "blas2")
(:file "blas3" :depends-on (blas2))
(:file "exponential")
(:file "lu")
(:file "qr")
(:file "qrpt")
(:file "svd")
(:file "cholesky")
(:file "diagonal")
(:file "householder")))
(:file "eigensystems" :depends-on (init data))
;; Skip fft for now, I'm not sure how it works in C
(:file "numerical-integration" :depends-on (init))
(:module random
:depends-on (init data)
:components
((:file "rng-types")
(:file "generators" :depends-on (rng-types))
(:file "quasi" :depends-on (rng-types generators))
(:file "gaussian" :depends-on (rng-types))
(:file "gaussian-tail" :depends-on (rng-types))
(:file "gaussian-bivariate" :depends-on (rng-types))
(:file "exponential" :depends-on (rng-types))
(:file "laplace" :depends-on (rng-types))
(:file "exponential-power" :depends-on (rng-types))
(:file "cauchy" :depends-on (rng-types))
(:file "rayleigh" :depends-on (rng-types))
(:file "rayleigh-tail" :depends-on (rng-types))
(:file "landau" :depends-on (rng-types))
(:file "levy" :depends-on (rng-types))
(:file "gamma" :depends-on (rng-types))
(:file "flat" :depends-on (rng-types))
(:file "lognormal" :depends-on (rng-types))
(:file "chi-squared" :depends-on (rng-types))
(:file "fdist" :depends-on (rng-types))
(:file "tdist" :depends-on (rng-types))
(:file "beta" :depends-on (rng-types))
(:file "logistic" :depends-on (rng-types))
(:file "pareto" :depends-on (rng-types))
(:file "spherical-vector" :depends-on (rng-types))
(:file "weibull" :depends-on (rng-types))
(:file "gumbel1" :depends-on (rng-types))
(:file "gumbel2" :depends-on (rng-types))
(:file "dirichlet" :depends-on (rng-types))
(:file "discrete" :depends-on (rng-types))
(:file "poisson" :depends-on (rng-types))
(:file "bernoulli" :depends-on (rng-types))
(:file "binomial" :depends-on (rng-types))
(:file "multinomial" :depends-on (rng-types))
(:file "negative-binomial" :depends-on (rng-types))
(:file "geometric" :depends-on (rng-types))
(:file "hypergeometric" :depends-on (rng-types))
(:file "logarithmic" :depends-on (rng-types))
(:file "shuffling-sampling" :depends-on (rng-types))))
(:module statistics
:depends-on (init data)
:components
((:file "mean-variance")
(:file "absolute-deviation")
(:file "higher-moments")
(:file "autocorrelation")
(:file "covariance")
;; minimum and maximum values provided in vector.lisp
(:file "median-percentile")))
(:module histogram
:depends-on (init linear-algebra)
:components
((:file "histogram")
(:file "updating-accessing" :depends-on (histogram))
(:file "statistics" :depends-on (histogram))
(:file "operations" :depends-on (histogram))
(:file "probability-distribution" :depends-on (histogram))
(:file "ntuple")))
(:file "monte-carlo" :depends-on (init data random))
(:module ordinary-differential-equations
:depends-on (init)
:components
((:file "ode-system")
(:file "stepping")
(:file "control")
(:file "evolution")
(:file "ode-example" :depends-on (ode-system stepping))))
(:module interpolation
:depends-on (init)
:components
((:file "interpolation")
(:file "types" :depends-on (interpolation))
(:file "lookup")
(:file "evaluation")
(:file "spline-example" :depends-on (types))))
(:file "numerical-differentiation" :depends-on (init))
(:file "chebyshev" :depends-on (init))
(:file "series-acceleration" :depends-on (init))
(:file "wavelet" :depends-on (init data))
(:file "hankel" :depends-on (init data))
(:module solve-minimize-fit
:depends-on (init data random)
:components
((:file "generic")
(:file "roots-one" :depends-on (generic))
(:file "minimization-one" :depends-on (generic))
(:file "roots-multi" :depends-on (roots-one generic))
(:file "minimization-multi" :depends-on (generic))
(:file "linear-least-squares")
(:file "nonlinear-least-squares" :depends-on (generic))))
(:file "basis-splines" :depends-on (init data))))
:name "gsll"
:description "GNU Scientific Library for Lisp."
:version "0"
:author "Liam M. Healy"
:licence "LLGPL v3, FDL"
:depends-on (cffi trivial-garbage cl-utilities)
:components
((:module init
:components
((:file "init")
(:file "conditions" :depends-on (init))
(:file "mobject" :depends-on (init))
(:file "types" :depends-on (init))
(:file "complex-types" :depends-on (types))
(:file "element-types" :depends-on (init complex-types))
(:file "number-conversion" :depends-on (init))
(:file "interface"
:depends-on (init conditions element-types number-conversion))
(:file "defmfun" :depends-on (init element-types interface))
(:file "defmfun-array" :depends-on (defmfun))
(:file "defmfun-single" :depends-on (defmfun))
(:file "callback" :depends-on (init))
(:file "generate-examples" :depends-on (init))))
(:module floating-point
:depends-on (init)
:components
((:file "ieee-modes")
(:file "floating-point")))
(:module mathematical
:depends-on (init)
:components
((:file "mathematical")
(:file "complex")))
(:module data
:depends-on (init)
:components
((:file "foreign-friendly")
(:file "foreign-array" :depends-on (foreign-friendly))
(:file "marray" :depends-on (foreign-array))
(:file "vector" :depends-on (marray))
(:file "matrix" :depends-on (marray vector))
(:file "maref" :depends-on (marray vector matrix))
(:file "both" :depends-on (marray vector matrix))
(:file "array-tests" :depends-on (both))
(:file "permutation" :depends-on (marray))
(:file "combination" :depends-on (marray))))
(:file "polynomial" :depends-on (init data))
(:module special-functions
:depends-on (init)
:components
((:file "return-structures")
(:file "airy" :depends-on (return-structures))
(:file "bessel" :depends-on (return-structures))
(:file "clausen" :depends-on (return-structures))
(:file "coulomb" :depends-on (return-structures))
(:file "coupling" :depends-on (return-structures))
(:file "dawson" :depends-on (return-structures))
(:file "debye" :depends-on (return-structures))
(:file "dilogarithm" :depends-on (return-structures))
(:file "elementary" :depends-on (return-structures))
(:file "elliptic-integrals" :depends-on (return-structures))
(:file "elliptic-functions" :depends-on (return-structures))
(:file "error-functions" :depends-on (return-structures))
(:file "exponential-functions" :depends-on (return-structures))
(:file "exponential-integrals" :depends-on (return-structures))
(:file "fermi-dirac" :depends-on (return-structures))
(:file "gamma" :depends-on (return-structures))
(:file "gegenbauer" :depends-on (return-structures))
(:file "hypergeometric" :depends-on (return-structures))
(:file "laguerre" :depends-on (return-structures))
(:file "lambert" :depends-on (return-structures))
(:file "legendre" :depends-on (return-structures))
(:file "logarithm" :depends-on (return-structures))
(:file "power" :depends-on (return-structures))
(:file "psi" :depends-on (return-structures))
(:file "synchrotron" :depends-on (return-structures))
(:file "transport" :depends-on (return-structures))
(:file "trigonometry" :depends-on (return-structures))
(:file "zeta" :depends-on (return-structures))))
(:file "sorting" :depends-on (init data))
(:module linear-algebra
:depends-on (init data special-functions)
:components
((:file "blas1")
(:file "blas2")
(:file "blas3" :depends-on (blas2))
(:file "exponential")
(:file "lu")
(:file "qr")
(:file "qrpt")
(:file "svd")
(:file "cholesky")
(:file "diagonal")
(:file "householder")))
(:file "eigensystems" :depends-on (init data))
;; Skip fft for now, I'm not sure how it works in C
(:module random
:depends-on (init data)
:components
((:file "rng-types")
(:file "generators" :depends-on (rng-types))
(:file "quasi" :depends-on (rng-types generators))
(:file "gaussian" :depends-on (rng-types))
(:file "gaussian-tail" :depends-on (rng-types))
(:file "gaussian-bivariate" :depends-on (rng-types))
(:file "exponential" :depends-on (rng-types))
(:file "laplace" :depends-on (rng-types))
(:file "exponential-power" :depends-on (rng-types))
(:file "cauchy" :depends-on (rng-types))
(:file "rayleigh" :depends-on (rng-types))
(:file "rayleigh-tail" :depends-on (rng-types))
(:file "landau" :depends-on (rng-types))
(:file "levy" :depends-on (rng-types))
(:file "gamma" :depends-on (rng-types))
(:file "flat" :depends-on (rng-types))
(:file "lognormal" :depends-on (rng-types))
(:file "chi-squared" :depends-on (rng-types))
(:file "fdist" :depends-on (rng-types))
(:file "tdist" :depends-on (rng-types))
(:file "beta" :depends-on (rng-types))
(:file "logistic" :depends-on (rng-types))
(:file "pareto" :depends-on (rng-types))
(:file "spherical-vector" :depends-on (rng-types))
(:file "weibull" :depends-on (rng-types))
(:file "gumbel1" :depends-on (rng-types))
(:file "gumbel2" :depends-on (rng-types))
(:file "dirichlet" :depends-on (rng-types))
(:file "discrete" :depends-on (rng-types))
(:file "poisson" :depends-on (rng-types))
(:file "bernoulli" :depends-on (rng-types))
(:file "binomial" :depends-on (rng-types))
(:file "multinomial" :depends-on (rng-types))
(:file "negative-binomial" :depends-on (rng-types))
(:file "geometric" :depends-on (rng-types))
(:file "hypergeometric" :depends-on (rng-types))
(:file "logarithmic" :depends-on (rng-types))
(:file "shuffling-sampling" :depends-on (rng-types))))
(:module statistics
:depends-on (init data)
:components
((:file "mean-variance")
(:file "absolute-deviation")
(:file "higher-moments")
(:file "autocorrelation")
(:file "covariance")
;; minimum and maximum values provided in vector.lisp
(:file "median-percentile")))
(:module histogram
:depends-on (init linear-algebra)
:components
((:file "histogram")
(:file "updating-accessing" :depends-on (histogram))
(:file "statistics" :depends-on (histogram))
(:file "operations" :depends-on (histogram))
(:file "probability-distribution" :depends-on (histogram))
(:file "ntuple")))
(:module calculus
:depends-on (init data random)
:components
((:file "numerical-integration")
(:file "monte-carlo")
(:file "numerical-differentiation")))
(:module ordinary-differential-equations
:depends-on (init)
:components
((:file "ode-system")
(:file "stepping")
(:file "control")
(:file "evolution")
(:file "ode-example" :depends-on (ode-system stepping))))
(:module interpolation
:depends-on (init)
:components
((:file "interpolation")
(:file "types" :depends-on (interpolation))
(:file "lookup")
(:file "evaluation")
(:file "spline-example" :depends-on (types))))
(:file "chebyshev" :depends-on (init))
(:file "series-acceleration" :depends-on (init))
(:file "wavelet" :depends-on (init data))
(:file "hankel" :depends-on (init data))
(:module solve-minimize-fit
:depends-on (init data random)
:components
((:file "generic")
(:file "roots-one" :depends-on (generic))
(:file "minimization-one" :depends-on (generic))
(:file "roots-multi" :depends-on (roots-one generic))
(:file "minimization-multi" :depends-on (generic))
(:file "linear-least-squares")
(:file "nonlinear-least-squares" :depends-on (generic))))
(:file "basis-splines" :depends-on (init data))))
;; Helpers that define a single GSL function interface
;; Liam Healy 2009-01-07 22:02:20EST defmfun-single.lisp
;; Time-stamp: <2009-01-14 22:03:12EST defmfun-single.lisp>
;; Time-stamp: <2009-01-15 22:27:56EST defmfun-single.lisp>
;; $Id: $
(in-package :gsl)
;;;;****************************************************************************
;;;; A single function
;;;;****************************************************************************
(defun defgeneric-method-p (name)
"When defining :method in a defgeneric, (nil foo) is used for
the name, and foo will be returned from this function."
......@@ -57,6 +53,23 @@
(native-pointer-protect array-symbols body)
body))
(define-condition obsolete-gsl-version (error)
((name :initarg :name :reader name)
(gsl-name :initarg :gsl-name :reader gsl-name)
(gsl-version :initarg :gsl-version :reader gsl-version))
(:report
(lambda (condition stream)
(apply 'format stream
"Function ~a (~a) is not available in the ~
~%currently loaded releases ~a of GSL; it was introduced in release ~d.~d."
(name condition)
(gsl-name condition)
*gsl-version*
(gsl-version condition))))
(:documentation
"An error indicating that the currently loaded version of the GSL libary
does not have the function defined."))
(defun complete-definition
(definition name arglist gsl-name c-arguments key-args
&optional
......@@ -107,12 +120,8 @@
,@(when qualifier (list qualifier))
(&rest args)
(declare (ignore args))
(error
,(apply 'format
nil
"Function ~a (~a) is not available in your current version ~
~a of GSL; it was introduced in version ~d.~d."
name gsl-name *gsl-version* gsl-version))))))
(error 'obsolete-gsl-version
:name ',name :gsl-name ,gsl-name :gsl-version ',gsl-version)))))
(defun wrap-letlike (when binding wrapping body)
(if when
......
;; Load GSL
;; Liam Healy Sat Mar 4 2006 - 18:53
;; Time-stamp: <2008-12-27 09:33:09EST init.lisp>
;; Time-stamp: <2009-01-15 22:10:30EST init.lisp>
;; $Id$
(defpackage gsll
......@@ -8,19 +8,27 @@
(:use :common-lisp :cffi :cl-utilities))
(cffi:define-foreign-library libgslcblas
(:darwin
(:or "/opt/local/lib/libgslcblas.dylib" "/sw/lib/libgslcblas.dylib"
"/usr/local/lib/libgslcblas.dylib"))
(:darwin
(:or "/opt/local/lib/libgslcblas.dylib" "/sw/lib/libgslcblas.dylib"
"/usr/local/lib/libgslcblas.dylib"))
(:cygwin (:or "/bin/cyggslcblas-0.dll"))
(:unix (:or "/usr/lib/libgslcblas.so.0" "/usr/lib/libgslcblas.so"
"/usr/lib64/libgslcblas.so.0" "/usr/lib64/libgslcblas.so"))
(t (:default "libgslcblas")))
(cffi:use-foreign-library libgslcblas)
;; When calling libgsl from emacs built for windows and slime, and
;; using clisp built for cygwin, we have to load lapack/cygblas.dll
;; before loading cyggsl-0.dll
#+(and clisp cygwin)
(cffi:load-foreign-library "/lib/lapack/cygblas.dll")
(cffi:define-foreign-library libgsl
(:darwin
(:or "/opt/local/lib/libgsl.dylib" "/sw/lib/libgsl.dylib"
"/usr/local/lib/libgsl.dylib"))
(:darwin
(:or "/opt/local/lib/libgsl.dylib" "/sw/lib/libgsl.dylib"
"/usr/local/lib/libgsl.dylib"))
(:cygwin (:or "/bin/cyggsl-0.dll"))
(:unix (:or "/usr/lib/libgsl.so.0" "/usr/lib/libgsl.so"
"/usr/lib64/libgsl.so.0" "/usr/lib64/libgsl.so"))
(t (:default "libgsl")))
......
;; BLAS level 1, Vector operations
;; Liam Healy, Wed Apr 26 2006 - 15:23
;; Time-stamp: <2008-12-26 16:30:16EST blas1.lisp>
;; Time-stamp: <2009-01-15 21:28:41EST blas1.lisp>
;; $Id$
(in-package :gsl)
......@@ -92,7 +92,10 @@
:documentation ; FDL
"Copy the elements of the vector x into the vector y.")
(defmfun axpy (alpha (x vector) (y vector))
(defmfun axpy
(alpha (x vector)
&optional
(y (make-marray element-type :dimensions (dimensions x))))
;; This gets an error for complex types because you can't pass a
;; struct in CFFI yet.
("gsl_blas_" :type "axpy")
......
;; BLAS level 2, Matrix-vector operations
;; Liam Healy, Wed Apr 26 2006 - 21:08
;; Time-stamp: <2008-12-29 22:14:14EST blas2.lisp>
;; Time-stamp: <2009-01-15 21:45:11EST blas2.lisp>
;; $Id$
(in-package :gsl)
......@@ -27,10 +27,18 @@
;;;; Functions
;;;;****************************************************************************
(defun matrix-product-dimensions (a b)
(if (typep b 'matrix)
(list (first (dimensions a))
(second (dimensions a)))
(first (dimensions a))))
;;; To do: the y should be an optional argument, default to a zero vector.
(defmfun matrix-product
((A matrix) (x vector) (y vector)
&optional (alpha 1) (beta 1) (TransA :notrans) TransB)
((A matrix) (x vector)
&optional
(y (make-marray element-type :dimensions (matrix-product-dimensions A x)))
(alpha 1) (beta 1) (TransA :notrans) TransB)
("gsl_blas_" :type "gemv")
((transa cblas-transpose) (alpha :element-c-type) ((mpointer A) :pointer)
((mpointer x) :pointer) (beta :element-c-type) ((mpointer y) :pointer))
......@@ -113,8 +121,10 @@
matrix A are taken as unity and are not referenced.")
(defmfun matrix-product-symmetric
((A matrix) (x vector) (y vector)
&optional (alpha 1) (beta 1) (uplo :upper) (side :left))
((A matrix) (x vector)
&optional
(y (make-marray element-type :dimensions (matrix-product-dimensions A x)))
(alpha 1) (beta 1) (uplo :upper) (side :left))
("gsl_blas_" :type "symv")
((uplo cblas-uplo) (alpha :element-c-type) ((mpointer A) :pointer)
((mpointer x) :pointer) (beta :element-c-type) ((mpointer y) :pointer))
......@@ -139,8 +149,10 @@
and diagonal of A are used.")
(defmfun matrix-product-hermitian
((A matrix) (x vector) (y vector)
&optional (alpha 1) (beta 1) (uplo :upper) (side :left))
((A matrix) (x vector)
&optional
(y (make-marray element-type :dimensions (matrix-product-dimensions A x)))
(alpha 1) (beta 1) (uplo :upper) (side :left))
;; This always signals an error because you can't pass a
;; struct in CFFI yet.
("gsl_blas_" :type "hemv")
......
;; BLAS level 3, Matrix-matrix operations
;; Liam Healy, Wed Apr 26 2006 - 21:08
;; Time-stamp: <2008-12-29 21:57:02EST blas3.lisp>
;; Time-stamp: <2009-01-15 21:49:10EST blas3.lisp>
;; $Id$
(in-package :gsl)
......@@ -20,8 +20,10 @@
;;;;****************************************************************************
(defmfun matrix-product
((A matrix) (B matrix) (C matrix)
&optional (alpha 1) (beta 1) (TransA :notrans) (TransB :notrans))
((A matrix) (B matrix)
&optional
(C (make-marray element-type :dimensions (matrix-product-dimensions A B)))
(alpha 1) (beta 1) (TransA :notrans) (TransB :notrans))
("gsl_blas_" :type "gemm")
((TransA cblas-transpose) (TransB cblas-transpose)
(alpha :element-c-type) ((mpointer A) :pointer)
......@@ -32,8 +34,10 @@
:outputs (C))
(defmfun matrix-product-symmetric
((A matrix) (B matrix) (C matrix)
&optional (alpha 1) (beta 1) (uplo :upper) (side :left))
((A matrix) (B matrix)
&optional
(C (make-marray element-type :dimensions (matrix-product-dimensions A B)))
(alpha 1) (beta 1) (uplo :upper) (side :left))
("gsl_blas_" :type "symm")
((side cblas-side) (uplo cblas-uplo) (alpha :element-c-type)
((mpointer A) :pointer) ((mpointer B) :pointer)
......@@ -44,8 +48,10 @@
:outputs (C))
(defmfun matrix-product-hermitian
((A matrix) (B matrix) (C matrix)
&optional (alpha 1) (beta 1) (uplo :upper) (side :left))
((A matrix) (B matrix)
&optional
(C (make-marray element-type :dimensions (matrix-product-dimensions A B)))
(alpha 1) (beta 1) (uplo :upper) (side :left))
;; This always signals an error because you can't pass a
;; struct in CFFI yet.
("gsl_blas_" :type "hemm")
......
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