Commit 5b255beb authored by Liam Healy's avatar Liam Healy

Use CFFI-grovel to define enumerations and programming constants

Instead of hardwiring GSL's #define or enum values, define them in
init/libgsl-unix.lisp and run CFFI-grovel on them.  This has the
advantage that if these values change in GSL, GSLL will automatically
get the new values; also, there was an error in the 'integrate-method
enum due to an incorrect starting value.  It has the disadvantage that
building GSLL now requires a C compiler and some of the header (.h)
files for GSL.  Also, it's not clear what the form for libgsl-*.lisp
files are for non-unix OSes.
parent 938ae6d6
;; Numerical integration techniques that require tables
;; Liam Healy 2009-04-04 15:24:05EDT
;; Time-stamp: <2009-04-26 23:20:16EDT numerical-integration-with-tables.lisp>
;; Time-stamp: <2009-05-25 13:22:13EDT numerical-integration-with-tables.lisp>
;; $Id: $
(in-package :gsl)
......@@ -69,9 +69,6 @@
;;;; QAWO adaptive integration for oscillatory functions
;;;;****************************************************************************
(cffi:defcenum integrate-sine-cosine
:cosine :sine)
(defmobject qawo-table
"gsl_integration_qawo_table"
((omega :double) (L :double) (trig integrate-sine-cosine) (n sizet))
......
;; Numerical integration
;; Liam Healy, Wed Jul 5 2006 - 23:14
;; Time-stamp: <2009-04-26 23:19:49EDT numerical-integration.lisp>
;; Time-stamp: <2009-05-25 13:22:13EDT numerical-integration.lisp>
;; $Id$
(in-package :gsl)
......@@ -61,10 +61,6 @@
"Make a workspace sufficient to hold n double
precision intervals, their integration results and error estimates.")
(cffi:defcenum integrate-method
:gauss15 :gauss21 :gauss31
:gauss41 :gauss51 :gauss61)
(defmfun integration-QAG
(function a b method
&optional
......
;; Functions for both vectors and matrices.
;; Liam Healy 2008-04-26 20:48:44EDT both.lisp
;; Time-stamp: <2009-05-25 12:42:22EDT both.lisp>
;; Time-stamp: <2009-05-25 15:19:49EDT both.lisp>
;; $Id$
(in-package :gsl)
......@@ -87,6 +87,7 @@
;;; coherency between the C and CL sides and therefore should not be
;;; used in production.
;;; For matrix functions, there should be another index argument
#|
(defmfun set-value ((object vector) index value)
("gsl_" :category :type "_set")
(((mpointer object) :pointer) (index sizet) (value :element-c-type))
......@@ -108,6 +109,7 @@
:export nil ; debugging only
:documentation
"Set single element to the value. For debugging only; do not use.")
|#
;;;;****************************************************************************
;;;; Elementwise arithmetic operations overwriting an array
......
......@@ -109,7 +109,7 @@ combination for which the following are supported:</p>
<li><a href="http://www.gnu.org/software/gsl/">GSL</a>
</li>
<li><a href="http://common-lisp.net/project/cffi/">CFFI</a>,
version 0.10.0 or newer; callbacks and <code>foreign-funcall</code> must be supported
version 0.10.4 or newer; callbacks and <code>foreign-funcall</code> must be supported
</li>
<li><a href="http://www.cliki.net/trivial-garbage">trivial-garbage</a>
<li><a href="http://www.cliki.net/asdf">ASDF</a></li>
......@@ -393,7 +393,7 @@ and arrays used internally or for function return.
<!-- Created: Feb 25 2005 -->
<!-- hhmts start -->
<small>
Time-stamp: <2009-05-19 21:23:43EDT index.html>
Time-stamp: <2009-05-25 16:43:40EDT index.html>
</small>
<!-- hhmts end -->
</div>
......
;; Eigenvectors and eigenvalues
;; Liam Healy, Sun May 21 2006 - 19:52
;; Time-stamp: <2009-02-16 12:52:43EST symmetric-hermitian.lisp>
;; Time-stamp: <2009-05-25 14:08:27EDT symmetric-hermitian.lisp>
;; $Id$
(in-package :gsl)
......@@ -119,10 +119,6 @@
;;;; Sorting Eigenvalues and Eigenvectors
;;;;****************************************************************************
(cffi:defcenum eigen-sort-type
;; gsl_eigen_sort_t from /usr/include/gsl/gsl_eigen.h.
:value-ascending :value-descending :absolute-ascending :absolute-descending)
(defmfun sort-eigenvalues-eigenvectors
((eigenvalues vector) (eigenvectors matrix) sort-type)
(double-float "gsl_eigen_symmv_sort"
......
;; IEEE 754 Modes and masks
;; Liam Healy 2008-01-29 21:35:50EST ieee-modes.lisp
;; Time-stamp: <2008-12-31 18:36:26EST ieee-modes.lisp>
;; Time-stamp: <2009-05-25 14:37:57EDT ieee-modes.lisp>
;; $Id$
(in-package :gsl)
(cffi:defcenum ieee-types
"IEEE 754 types, from /usr/include/gsl/gsl_ieee_utils.h"
(:NAN 1) :INF :NORMAL :DENORMAL :ZERO)
(cffi:defcenum ieee-precisions
"IEEE 754 precisions, from /usr/include/gsl/gsl_ieee_utils.h"
(:SINGLE-PRECISION 1) :DOUBLE-PRECISION :EXTENDED-PRECISION)
(cffi:defcenum ieee-rounding
"IEEE 754 rounding, from /usr/include/gsl/gsl_ieee_utils.h"
(:TO-NEAREST 1) :DOWN :UP :TO-ZERO)
(cffi:defcenum ieee-mask
"IEEE 754 mask, from /usr/include/gsl/gsl_ieee_utils.h"
(:INVALID 1) (:DENORMALIZED 2) (:DIVISION-BY-ZERO 4)
(:OVERFLOW 8) (:UNDERFLOW 16) (:ALL 31) (:INEXACT 32))
#+ieee-floating-point
(defmfun set-floating-point-modes (precision rounding exception-mask)
"gsl_ieee_set_mode"
......
;; Definition of GSLL system
;; Liam Healy
;; Time-stamp: <2009-05-24 16:07:08EDT gsll.asd>
;; Time-stamp: <2009-05-25 13:54:01EDT gsll.asd>
;; $Id$
(when (asdf:find-system :fsbv nil)
......@@ -17,6 +17,7 @@
((:module init
:components
((:file "init")
(cffi-grovel:grovel-file "libgsl" :pathname #+unix "libgsl-unix")
(:file "utility")
(:file "forms")
(:file "conditions" :depends-on (init))
......
;; GSL errors
;; Liam Healy Sat Mar 4 2006 - 18:33
;; Time-stamp: <2009-03-23 12:27:09EDT conditions.lisp>
;; Time-stamp: <2009-05-25 14:52:25EDT conditions.lisp>
;; $Id$
(in-package :gsl)
......@@ -9,16 +9,6 @@
;;;; Define non-error and error C return codes
;;;;****************************************************************************
(eval-when (:compile-toplevel :load-toplevel :execute)
(cffi:defcenum gsl-errorno
"Error codes for GSL, from /usr/include/gsl/gsl_errno.h."
(:CONTINUE -2)
:FAILURE :SUCCESS :EDOM :ERANGE :EFAULT :EINVAL :EFAILED :EFACTOR
:ESANITY :ENOMEM :EBADFUNC :ERUNAWAY :EMAXITER :EZERODIV :EBADTOL
:ETOL :EUNDRFLW :EOVRFLW :ELOSS :EROUND :EBADLEN :ENOTSQR :ESING
:EDIVERGE :EUNSUP :EUNIMPL :ECACHE :ETABLE :ENOPROG :ENOPROGJ
:ETOLF :ETOLX :ETOLG :EOF))
#.(cons 'progn
(loop for i from (cffi:foreign-enum-value 'gsl-errorno :continue)
to (cffi:foreign-enum-value 'gsl-errorno :eof)
......
;; Load GSL
;; Liam Healy Sat Mar 4 2006 - 18:53
;; Time-stamp: <2009-04-04 09:55:29EDT init.lisp>
;; Time-stamp: <2009-05-25 16:32:45EDT init.lisp>
;; $Id$
(defpackage gsll
......
;; CFFI-Grovel definitions for unix systems.
;; Liam Healy 2009-05-25 13:10:50EDT libgsl-unix.lisp
;; Time-stamp: <2009-05-25 16:32:12EDT libgsl-unix.lisp>
;; $Id: $
#+linux
(define "_GNU_SOURCE")
(in-package :gsl)
(include "gsl/gsl_integration.h")
;; gsl_integration_qawo_enum
(cenum integrate-sine-cosine
((:cosine "GSL_INTEG_COSINE"))
((:sine "GSL_INTEG_SINE")))
(cenum integrate-method
((:gauss15 "GSL_INTEG_GAUSS15"))
((:gauss21 "GSL_INTEG_GAUSS21"))
((:gauss31 "GSL_INTEG_GAUSS31"))
((:gauss41 "GSL_INTEG_GAUSS41"))
((:gauss51 "GSL_INTEG_GAUSS51"))
((:gauss61 "GSL_INTEG_GAUSS61")))
(include "gsl/gsl_eigen.h")
;; gsl_eigen_sort_t
(cenum eigen-sort-type
((:value-ascending "GSL_EIGEN_SORT_VAL_ASC"))
((:value-descending "GSL_EIGEN_SORT_VAL_DESC"))
((:absolute-ascending "GSL_EIGEN_SORT_ABS_ASC"))
((:absolute-descending "GSL_EIGEN_SORT_ABS_DESC")))
(include "gsl/gsl_cblas.h")
(cenum cblas-transpose
;; CBLAS_TRANSPOSE
((:notrans "CblasNoTrans"))
((:trans "CblasTrans"))
((:conjtrans "CblasConjTrans")))
(cenum cblas-uplo
;; CBLAS_UPLO
((:upper "CblasUpper"))
((:lower "CblasLower")))
(cenum cblas-diag
;; CBLAS_DIAG
((:nonunit "CblasNonUnit"))
((:unit "CblasUnit")))
(cenum cblas-side
;; CBLAS_SIDE
((:left "CblasLeft"))
((:right "CblasRight")))
(include "gsl/gsl_odeiv.h")
(cenum step-size-adjustment
((:step-size-decreased "GSL_ODEIV_HADJ_DEC"))
((:step-size-unchanged "GSL_ODEIV_HADJ_NIL"))
((:step-size-increased "GSL_ODEIV_HADJ_INC")))
(include "gsl/gsl_ieee_utils.h")
(cenum ieee-types
((:NAN "GSL_IEEE_TYPE_NAN"))
((:INF "GSL_IEEE_TYPE_INF"))
((:NORMAL "GSL_IEEE_TYPE_NORMAL"))
((:DENORMAL "GSL_IEEE_TYPE_DENORMAL"))
((:ZERO "GSL_IEEE_TYPE_ZERO")))
(cenum ieee-precisions
((:SINGLE-PRECISION "GSL_IEEE_SINGLE_PRECISION"))
((:DOUBLE-PRECISION "GSL_IEEE_DOUBLE_PRECISION"))
((:EXTENDED-PRECISION "GSL_IEEE_EXTENDED_PRECISION")))
(cenum ieee-rounding
((:TO-NEAREST "GSL_IEEE_ROUND_TO_NEAREST"))
((:DOWN "GSL_IEEE_ROUND_DOWN"))
((:UP "GSL_IEEE_ROUND_UP"))
((:TO-ZERO "GSL_IEEE_ROUND_TO_ZERO")))
(cenum ieee-mask
((:INVALID "GSL_IEEE_MASK_INVALID"))
((:DENORMALIZED "GSL_IEEE_MASK_DENORMALIZED"))
((:DIVISION-BY-ZERO "GSL_IEEE_MASK_DIVISION_BY_ZERO"))
((:OVERFLOW "GSL_IEEE_MASK_OVERFLOW"))
((:UNDERFLOW "GSL_IEEE_MASK_UNDERFLOW"))
((:ALL "GSL_IEEE_MASK_ALL"))
((:INEXACT "GSL_IEEE_TRAP_INEXACT")))
(include "gsl/gsl_mode.h")
(cenum sf-mode
((:double "GSL_PREC_DOUBLE"))
((:single "GSL_PREC_SINGLE"))
((:approx "GSL_PREC_APPROX")))
(include "gsl/gsl_errno.h")
(cenum gsl-errorno
((:CONTINUE "GSL_CONTINUE"))
((:FAILURE "GSL_FAILURE"))
((:SUCCESS "GSL_SUCCESS"))
((:EDOM "GSL_EDOM"))
((:ERANGE "GSL_ERANGE"))
((:EFAULT "GSL_EFAULT"))
((:EINVAL "GSL_EINVAL"))
((:EFAILED "GSL_EFAILED"))
((:EFACTOR "GSL_EFACTOR"))
((:ESANITY "GSL_ESANITY"))
((:ENOMEM "GSL_ENOMEM"))
((:EBADFUNC "GSL_EBADFUNC"))
((:ERUNAWAY "GSL_ERUNAWAY"))
((:EMAXITER "GSL_EMAXITER"))
((:EZERODIV "GSL_EZERODIV"))
((:EBADTOL "GSL_EBADTOL"))
((:ETOL "GSL_ETOL"))
((:EUNDRFLW "GSL_EUNDRFLW"))
((:EOVRFLW "GSL_EOVRFLW"))
((:ELOSS "GSL_ELOSS"))
((:EROUND "GSL_EROUND"))
((:EBADLEN "GSL_EBADLEN"))
((:ENOTSQR "GSL_ENOTSQR"))
((:ESING "GSL_ESING"))
((:EDIVERGE "GSL_EDIVERGE"))
((:EUNSUP "GSL_EUNSUP"))
((:EUNIMPL "GSL_EUNIMPL"))
((:ECACHE "GSL_ECACHE"))
((:ETABLE "GSL_ETABLE"))
((:ENOPROG "GSL_ENOPROG"))
((:ENOPROGJ "GSL_ENOPROGJ"))
((:ETOLF "GSL_ETOLF"))
((:ETOLX "GSL_ETOLX"))
((:ETOLG "GSL_ETOLG"))
((:EOF "GSL_EOF")))
(ctype sizet "size_t")
;; Number types used by GSL functions, and specification conversion
;; Liam Healy 2008-12-31 21:06:34EST types.lisp
;; Time-stamp: <2009-05-03 09:42:01EDT types.lisp>
;; Time-stamp: <2009-05-25 16:34:12EDT types.lisp>
;; $Id: $
(in-package :gsl)
......@@ -9,17 +9,13 @@
;;;; Unsigned address types size_t
;;;;****************************************************************************
(case
(cffi:foreign-type-size :long)
(case (cffi:foreign-type-size :long)
(8
(push :int64 *features*)
(cffi:defctype sizet :uint64)
#+fsbv (fsbv:defsynonym sizet :uint64))
(4
(push :int32 *features*)
(cffi:defctype sizet :uint32)
#+fsbv (fsbv:defsynonym sizet :uint32))
(t (error "Size of :long unrecognized")))
#+fsbv (fsbv:defsynonym sizet :uint32)))
;;;;****************************************************************************
;;;; Type specification conversion
......
;; BLAS level 2, Matrix-vector operations
;; Liam Healy, Wed Apr 26 2006 - 21:08
;; Time-stamp: <2009-05-03 12:38:28EDT blas2.lisp>
;; Time-stamp: <2009-05-25 14:23:16EDT blas2.lisp>
;; $Id$
(in-package :gsl)
......@@ -11,24 +11,12 @@
;;;; Options
;;;;****************************************************************************
(cffi:defcenum cblas-transpose
"CBLAS_TRANSPOSE from /usr/include/gsl/gsl_cblas.h."
(:notrans 111) :trans :conjtrans)
#+fsbv
(fsbv:defcenum-aux cblas-transpose)
(cffi:defcenum cblas-uplo
"/usr/include/gsl/gsl_cblas.h."
(:upper 121) :lower)
#+fsbv
(fsbv:defcenum-aux cblas-uplo)
(cffi:defcenum cblas-diag
"/usr/include/gsl/gsl_cblas.h."
(:nonunit 131) :unit)
#+fsbv
(fsbv:defcenum-aux cblas-diag)
......
;; BLAS level 3, Matrix-matrix operations
;; Liam Healy, Wed Apr 26 2006 - 21:08
;; Time-stamp: <2009-05-06 16:07:03EDT blas3.lisp>
;; Time-stamp: <2009-05-25 14:26:09EDT blas3.lisp>
;; $Id$
(in-package :gsl)
......@@ -11,10 +11,6 @@
;;;; Options
;;;;****************************************************************************
(cffi:defcenum cblas-side
"/usr/include/gsl/gsl_cblas.h."
(:left 141) :right)
#+fsbv
(fsbv:defcenum-aux cblas-side)
......
;; Adaptive step-size control
;; Liam Healy 2008-02-17 17:30:04EST control.lisp
;; Time-stamp: <2009-01-25 17:09:29EST control.lisp>
;; Time-stamp: <2009-05-25 14:52:26EDT control.lisp>
;; $Id$
(in-package :gsl)
......@@ -118,9 +118,6 @@
defining new types of control functions. For most purposes the standard
control functions described above should be sufficient.")
(cffi:defcenum step-size-adjustment
(:step-size-decreased -1) :step-size-unchanged :step-size-increased)
(defmfun adjust-stepsize (control stepper current-y y-error dydt step-size)
"gsl_odeiv_control_hadjust"
(((mpointer control) :pointer) (stepper :pointer) (current-y :pointer)
......
;; Structures returned by special functions.
;; Liam Healy, Mon Jan 1 2007 - 11:35
;; Time-stamp: <2009-05-25 12:42:19EDT return-structures.lisp>
;; Time-stamp: <2009-05-25 14:43:47EDT return-structures.lisp>
;; $Id$
(in-package :gsl)
......@@ -23,13 +23,6 @@
(err :double)
(e10 :int))
(cffi:defcenum sf-mode
"Numerical precision modes with which to calculate special functions."
;; file:///usr/share/doc/gsl-ref-html/gsl-ref_7.html#SEC62
:double
:single
:approx)
(defun val (sf-result &optional (type 'sf-result))
(cffi:foreign-slot-value sf-result type 'val))
......
......@@ -119,12 +119,12 @@
(INTEGRATION-QAG (INTEGRATION-TEST-F1 2.6d0) 1.0d0
0.0d0 :GAUSS15 0.0d0 1.d-10 1000)))
(LISP-UNIT:ASSERT-NUMERICAL-EQUAL
(LIST 0.07716049382716048d0 5.181082604031411d-15)
(LIST 0.0771604938271605D0 2.227969532823568D-15)
(MULTIPLE-VALUE-LIST
(INTEGRATION-QAG (INTEGRATION-TEST-F1 2.6d0) 0.0d0
1.0d0 :GAUSS21 1.d-14 0.0d0 1000)))
(LISP-UNIT:ASSERT-NUMERICAL-EQUAL
(LIST -0.07716049382716048d0 5.181082604031411d-15)
(LIST -0.0771604938271605D0 2.227969532823568D-15)
(MULTIPLE-VALUE-LIST
(INTEGRATION-QAG (INTEGRATION-TEST-F1 2.6d0) 1.0d0
0.0d0 :GAUSS21 1.d-14 0.0d0 1000)))
......
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