Changeset 47 for trunk

Show
Ignore:
Timestamp:
03/28/08 03:12:26 (8 months ago)
Author:
lhealy
Message:

Unification of errors and warnings using a single class
'gsl-condition. Each numbered GSL conditions is a subclass of this
condition, under the name given by GSL, e.g. 'EDOM.

Location:
trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/documentation/index.html

    r32 r47  
    7070<pre> 
    7171(jacobian-elliptic-functions 0.61802d0 1.5d0) 
    72 debugger invoked on a GSL-ERROR in thread #<THREAD "initial thread" {10032258C1}>: 
    73   Input domain error (EDOM), |m| > 1.0 in elljac.c at line 46 
     72Input domain error |m| > 1.0 in elljac.c at line 46 
     73   [Condition of type EDOM] 
    7474</pre> 
    7575 </div> 
     
    159159<!-- hhmts start --> 
    160160    <small> 
    161        Time-stamp: <2008-03-08 11:22:52EST index.html> 
     161       Time-stamp: <2008-03-27 23:08:11EDT index.html> 
    162162       </small> 
    163163<!-- hhmts end --> 
  • trunk/histogram/updating-accessing.lisp

    r26 r47  
    11;; Updating and accessing histogram elements. 
    22;; Liam Healy, Mon Jan  1 2007 - 14:43 
    3 ;; Time-stamp: <2008-02-23 18:49:16EST updating-accessing.lisp> 
     3;; Time-stamp: <2008-03-27 23:09:26EDT updating-accessing.lisp> 
    44;; $Id$ 
    55 
     
    117117              ((first values) (second values)))) 
    118118 
    119 ;;; Examples and unit test 
    120  
    121 #| 
    122 (make-tests histogram 
    123119 (letm ((histo (histogram 10)))         ; should be a gsl-warning here, how to check? 
    124120     (set-ranges-uniform histo 0.0d0 10.0d0) 
    125121     (increment histo -2.0d0)) 
     122;;; Examples and unit test 
     123 
     124#| 
     125(make-tests histogram 
     126   ;; The first one gives a warning while compiling in SBCL, 
     127   ;; should only give a warning while runnin. 
     128 (letm ((histo (histogram 10))) 
     129     (set-ranges-uniform histo 0.0d0 10.0d0) 
     130     (increment histo -2.0d0)) 
    126131 (letm ((histo (histogram 10))) 
    127132   (set-ranges-uniform histo 0.0d0 10.0d0) 
     
    162167 
    163168(LISP-UNIT:DEFINE-TEST HISTOGRAM 
    164   (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    165    (LIST) 
    166    (MULTIPLE-VALUE-LIST 
    167     (LETM ((HISTO (HISTOGRAM 10))) 
    168       (SET-RANGES-UNIFORM HISTO 0.0d0 10.0d0) 
    169       (INCREMENT HISTO -2.0d0)))) 
     169  (LISP-UNIT:ASSERT-ERROR 
     170   'GSL-CONDITION 
     171   (LETM ((HISTO (HISTOGRAM 10))) 
     172     (SET-RANGES-UNIFORM HISTO 0.0d0 10.0d0) 
     173     (INCREMENT HISTO -2.0d0))) 
    170174  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    171175   (LIST 0.0d0) 
     
    193197      (MAREF HISTO 6)))) 
    194198  (LISP-UNIT:ASSERT-ERROR 
    195    'GSL-ERROR 
     199   'GSL-CONDITION 
    196200   (LETM ((HISTO (HISTOGRAM 10))) 
    197201     (SET-RANGES-UNIFORM HISTO 0.0d0 10.0d0) 
  • trunk/init/conditions.lisp

    r33 r47  
    11;; GSL errors                                 
    22;; Liam Healy Sat Mar  4 2006 - 18:33 
    3 ;; Time-stamp: <2008-03-08 12:39:50EST conditions.lisp> 
     3;; Time-stamp: <2008-03-27 23:07:29EDT conditions.lisp> 
    44;; $Id$ 
    55 
    66(in-package :gsl) 
    77 
    8 (cffi:defcenum gsl-errorno 
    9   "Error codes for GSL, from /usr/include/gsl/gsl_errno.h." 
    10   (:CONTINUE -2) 
    11   :FAILURE :SUCCESS :EDOM :ERANGE :EFAULT :EINVAL :EFAILED :EFACTOR   
    12   :ESANITY :ENOMEM :EBADFUNC :ERUNAWAY :EMAXITER :EZERODIV :EBADTOL   
    13   :ETOL :EUNDRFLW :EOVRFLW :ELOSS :EROUND :EBADLEN :ENOTSQR :ESING     
    14   :EDIVERGE :EUNSUP :EUNIMPL :ECACHE :ETABLE :ENOPROG :ENOPROGJ  
    15   :ETOLF :ETOLX :ETOLG :EOF) 
     8;;;;**************************************************************************** 
     9;;;; GSL conditions 
     10;;;;**************************************************************************** 
    1611 
    17 (defparameter *gsl-error-alist* 
    18   '((-2 . "Iteration has not converged") 
    19     (-1 . "Failure") 
    20     (0 . "Success")  
    21     (1 . "Input domain error") 
    22     (2 . "Output range error") 
    23     (3 . "Invalid pointer") 
    24     (4 . "Invalid argument") 
    25     (5 . "Generic failure") 
    26     (6 . "Factorization failed") 
    27     (7 . "Sanity check failed - shouldn't happen") 
    28     (8 . "Malloc failed") 
    29     (9 . "Problem with user-supplied function") 
    30     (10 . "Iterative process is out of control") 
    31     (11 . "Exceeded max number of iterations") 
    32     (12 . "Tried to divide by zero") 
    33     (13 . "User specified an invalid tolerance") 
    34     (14 . "Failed to reach the specified tolerance") 
    35     (15 . "Underflow") 
    36     (16 . "Overflow ") 
    37     (17 . "Loss of accuracy") 
    38     (18 . "Failed because of roundoff error") 
    39     (19 . "Matrix, vector lengths are not conformant") 
    40     (20 . "Matrix not square") 
    41     (21 . "Apparent singularity detected") 
    42     (22 . "Integral or series is divergent") 
    43     (23 . "Requested feature is not supported by the hardware") 
    44     (24 . "Requested feature not (yet) implemented") 
    45     (25 . "Cache limit exceeded") 
    46     (26 . "Table limit exceeded") 
    47     (27 . "Iteration is not making progress towards solution") 
    48     (28 . "Jacobian evaluations are not improving the solution") 
    49     (29 . "Cannot reach the specified tolerance in F") 
    50     (30 . "Cannot reach the specified tolerance in X") 
    51     (31 . "Cannot reach the specified tolerance in gradient") 
    52     (32 . "End of file"))) 
    53  
    54 ;;; It would be nice to be able to return, or give the option to return, 
    55 ;;; the portable equivalent of #.SB-EXT:DOUBLE-FLOAT-POSITIVE-INFINITY 
    56 ;;; for :EOVRFLW. 
    57  
    58 (define-condition gsl-error (arithmetic-error) 
    59   ((gsl-errno :initarg :gsl-errno :reader gsl-errno) 
    60    (gsl-reason :initarg :gsl-reason :reader gsl-reason) 
    61    (gsl-source-file :initform nil :initarg :gsl-source-file :reader gsl-source-file) 
    62    (gsl-line-number :initform 0 :initarg :gsl-line-number :reader gsl-line-number)) 
     12(export 'gsl-condition) 
     13(define-condition gsl-condition (arithmetic-error warning) 
     14  ((error-number :initarg :error-number :reader error-number) 
     15   (error-text :initarg :error-text :reader error-text)    
     16   (explanation :initarg :explanation :reader explanation) 
     17   (source-file :initform nil :initarg :source-file :reader source-file) 
     18   (line-number :initform 0 :initarg :line-number :reader line-number)) 
    6319  (:report 
    6420   (lambda (condition stream) 
    65      (format stream "~a (~a), ~a ~@[in ~a at line ~d~]" 
    66              (rest (assoc (gsl-errno condition) *gsl-error-alist*)) 
    67              (cffi:foreign-enum-keyword 'gsl-errorno (gsl-errno condition)) 
    68              (gsl-reason condition) 
    69              (gsl-source-file condition) 
    70              (gsl-line-number condition)))) 
     21     (format stream "~a ~a ~@[in ~a at line ~d~]" 
     22             (error-text condition) 
     23             (explanation condition) 
     24             (source-file condition) 
     25             (line-number condition)))) 
    7126  (:documentation 
    72    "An error that has been signalled by the GNU Scientific Library.")) 
     27   "A condition that has been signalled by the GNU Scientific Library.")) 
    7328 
    74 (define-condition gsl-warning (warning) 
    75   ((gsl-errno :initarg :gsl-errno :reader gsl-errno) 
    76    (gsl-context :initarg :gsl-context :reader gsl-context)) 
    77   (:report 
    78    (lambda (condition stream) 
    79      (format stream "GSL condition ~a (~d), ~a in ~a" 
    80              (cffi:foreign-enum-keyword 'gsl-errorno (gsl-errno condition)) 
    81              (gsl-errno condition) 
    82              (rest (assoc (gsl-errno condition) *gsl-error-alist*)) 
    83              (gsl-context condition)))) 
    84   (:documentation 
    85    "An warning that has been signalled by the GNU Scientific Library.")) 
     29(defparameter *errorno-keyword* nil) 
     30 
     31(defmacro define-gsl-condition (keyword number text) 
     32  `(progn 
     33    (define-condition ,keyword (gsl-condition) 
     34      ((error-number :initform ,number :reader error-number :allocation :class) 
     35       (error-text :initform ,text :reader error-text :allocation :class)) 
     36      (:documentation 
     37       (format nil 
     38               "The condition ~a, ~a, signalled by the GNU Scientific Library." 
     39               ',keyword ,text))) 
     40    (setf *errorno-keyword* (acons ,number ',keyword *errorno-keyword*)) 
     41    (export ',keyword))) 
     42 
     43(define-gsl-condition EDOM 1 "Input domain error") 
     44(define-gsl-condition ERANGE 2 "Output range error") 
     45(define-gsl-condition EFAULT 3 "Invalid pointer") 
     46(define-gsl-condition EINVAL 4 "Invalid argument") 
     47(define-gsl-condition EFAILED 5 "Generic failure") 
     48(define-gsl-condition EFACTOR 6 "Factorization failed") 
     49(define-gsl-condition ESANITY 7 "Sanity check failed - shouldn't happen") 
     50(define-gsl-condition ENOMEM 8 "Malloc failed") 
     51(define-gsl-condition EBADFUNC 9 "Problem with user-supplied function") 
     52(define-gsl-condition ERUNAWAY 10 "Iterative process is out of control") 
     53(define-gsl-condition EMAXITER 11 "Exceeded max number of iterations") 
     54(define-gsl-condition EZERODIV 12 "Tried to divide by zero") 
     55(define-gsl-condition EBADTOL 13 "User specified an invalid tolerance") 
     56(define-gsl-condition ETOL 14 "Failed to reach the specified tolerance") 
     57(define-gsl-condition EUNDRFLW 15 "Underflow") 
     58(define-gsl-condition EOVRFLW 16 "Overflow") 
     59(define-gsl-condition ELOSS 17 "Loss of accuracy") 
     60(define-gsl-condition EROUND 18 "Failed because of roundoff error") 
     61(define-gsl-condition EBADLEN 19 "Matrix, vector lengths are not conformant") 
     62(define-gsl-condition ENOTSQR 20 "Matrix not square") 
     63(define-gsl-condition ESING 21 "Apparent singularity detected") 
     64(define-gsl-condition EDIVERGE 22 "Integral or series is divergent") 
     65(define-gsl-condition EUNSUP 23 "Requested feature is not supported by the hardware") 
     66(define-gsl-condition EUNIMPL 24 "Requested feature not (yet) implemented") 
     67(define-gsl-condition ECACHE 25 "Cache limit exceeded") 
     68(define-gsl-condition ETABLE 26 "Table limit exceeded") 
     69(define-gsl-condition ENOPROG 27 "Iteration is not making progress towards solution") 
     70(define-gsl-condition ENOPROGJ 28 "Jacobian evaluations are not improving the solution") 
     71(define-gsl-condition ETOLF 29 "Cannot reach the specified tolerance in F") 
     72(define-gsl-condition ETOLX 30 "Cannot reach the specified tolerance in X") 
     73(define-gsl-condition ETOLG 31 "Cannot reach the specified tolerance in gradient") 
     74(define-gsl-condition EOF 32 "End of file") 
     75;;; It is possible to return +positive-infinity+ 
     76;;; by defining a handler for :EOVRFLW. 
     77 
     78(defun lookup-condition (number) 
     79  (or (rest (assoc number *errorno-keyword*)) 
     80      ;; go for "Generic failure" of the code doesn't come up 
     81      'EFAILED)) 
     82 
     83(defun signal-gsl-error (number explanation &optional file line) 
     84  "Signal an error from the GSL library." 
     85  (error (lookup-condition number) 
     86         :explanation explanation 
     87         :source-file file 
     88         :line-number line)) 
     89 
     90(defun signal-gsl-warning (number explanation &optional file line) 
     91  "Signal a warning from the GSL library." 
     92  (warn (lookup-condition number) 
     93         :explanation explanation 
     94         :source-file file 
     95         :line-number line)) 
    8696 
    8797(cffi:defcallback gsl-error :void 
    8898    ((reason :string) (file :string) (line :int) (error-number :int)) 
    89   (error 'gsl-error 
    90          :gsl-errno error-number 
    91          :gsl-reason reason 
    92          :gsl-source-file file 
    93          :gsl-line-number line)) 
     99  (signal-gsl-error error-number reason file line)) 
    94100 
    95101(defun establish-handler () 
     
    104110#+sbcl (push 'establish-handler sb-ext:*init-hooks*) 
    105111 
     112;;;;**************************************************************************** 
     113;;;; Define non-error C codes  
     114;;;;**************************************************************************** 
     115 
     116(cffi:defcenum gsl-errorno 
     117  "Error codes for GSL, from /usr/include/gsl/gsl_errno.h." 
     118  ;; We really only need the first three here; the rest are handled 
     119  ;; above. 
     120  (:CONTINUE -2) 
     121  :FAILURE :SUCCESS :EDOM :ERANGE :EFAULT :EINVAL :EFAILED :EFACTOR   
     122  :ESANITY :ENOMEM :EBADFUNC :ERUNAWAY :EMAXITER :EZERODIV :EBADTOL   
     123  :ETOL :EUNDRFLW :EOVRFLW :ELOSS :EROUND :EBADLEN :ENOTSQR :ESING     
     124  :EDIVERGE :EUNSUP :EUNIMPL :ECACHE :ETABLE :ENOPROG :ENOPROGJ  
     125  :ETOLF :ETOLX :ETOLG :EOF) 
     126 
    106127(defmacro gsl-errorno-sm (keyword) 
    107128  `(define-symbol-macro 
  • trunk/init/interface.lisp

    r37 r47  
    11;; Macros to interface GSL functions. 
    22;; Liam Healy  
    3 ;; Time-stamp: <2008-03-15 21:51:07EDT interface.lisp> 
     3;; Time-stamp: <2008-03-27 22:36:35EDT interface.lisp> 
    44;; $Id$ 
    55 
     
    7474  "Check the return status code from a GSL function and signal a warning 
    7575   if it is not :SUCCESS." 
    76   (unless (eql :success (cffi:foreign-enum-keyword 'gsl-errorno status-code)) 
    77     (warn 'gsl-warning 
    78           :gsl-errno status-code :gsl-context context))) 
     76  (unless (eql status-code success) 
     77    (signal-gsl-warning status-code (format nil "in ~a" context)))) 
    7978 
    8079(defun check-null-pointer (pointer error-code reason) 
    8180  (when (cffi:null-pointer-p pointer) 
    82     (error 'gsl-error 
    83            :gsl-errno (cffi:foreign-enum-value 'gsl-errorno error-code) 
    84            :gsl-reason reason))) 
     81    (signal-gsl-error error-code reason))) 
    8582 
    8683(defun success-failure (value) 
  • trunk/numerical-integration.lisp

    r26 r47  
    11;; Numerical integration 
    22;; Liam Healy, Wed Jul  5 2006 - 23:14 
    3 ;; Time-stamp: <2008-02-17 11:43:47EST numerical-integration.lisp> 
     3;; Time-stamp: <2008-03-27 21:30:20EDT numerical-integration.lisp> 
    44;; $Id$ 
    55 
     
    247247                       WS)))) 
    248248  (LISP-UNIT:ASSERT-ERROR 
    249    'GSL-ERROR 
     249   'GSL-CONDITION 
    250250   (LETM ((WS (INTEGRATION-WORKSPACE 20))) 
    251251     (INTEGRATION-QAG ONE-SINE 0.0d0 PI :GAUSS15 50 WS)))) 
  • trunk/special-functions/elliptic-functions.lisp

    r26 r47  
    11;; Jacobian elliptic functions 
    22;; Liam Healy, Mon Mar 20 2006 - 22:21 
    3 ;; Time-stamp: <2008-02-16 20:42:55EST elliptic-functions.lisp> 
     3;; Time-stamp: <2008-03-27 21:29:35EDT elliptic-functions.lisp> 
    44;; $Id$ 
    55 
     
    3838   (MULTIPLE-VALUE-LIST 
    3939    (JACOBIAN-ELLIPTIC-FUNCTIONS 0.2d0 0.81d0))) 
    40   (LISP-UNIT:ASSERT-ERROR 'GSL-ERROR 
     40  (LISP-UNIT:ASSERT-ERROR 'GSL-CONDITION 
    4141                          (JACOBIAN-ELLIPTIC-FUNCTIONS 
    4242                           0.61802d0 1.5d0))) 
  • trunk/special-functions/exponential-integrals.lisp

    r26 r47  
    11;; Exponential integrals 
    22;; Liam Healy, Tue Mar 21 2006 - 17:37 
    3 ;; Time-stamp: <2008-02-16 22:16:29EST exponential-integrals.lisp> 
     3;; Time-stamp: <2008-03-27 21:29:32EDT exponential-integrals.lisp> 
    44;; $Id$ 
    55 
     
    105105 
    106106(LISP-UNIT:DEFINE-TEST EXPONENTIAL-INTEGRALS 
    107   (LISP-UNIT:ASSERT-ERROR 'GSL-ERROR (EXPINT-E1 0.0d0)) 
     107  (LISP-UNIT:ASSERT-ERROR 'GSL-CONDITION (EXPINT-E1 0.0d0)) 
    108108  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    109109   (LIST 0.21938393439552029d0 2.6541220085226265d-16) 
  • trunk/special-functions/gamma.lisp

    r26 r47  
    11;; Gamma functions 
    22;; Liam Healy, Thu Apr 27 2006 - 22:06 
    3 ;; Time-stamp: <2008-02-16 21:58:18EST gamma.lisp> 
     3;; Time-stamp: <2008-03-27 21:29:36EDT gamma.lisp> 
    44;; $Id$ 
    55 
     
    219219 
    220220(LISP-UNIT:DEFINE-TEST GAMMA 
    221   (LISP-UNIT:ASSERT-ERROR 'GSL-ERROR (GAMMA -1.0d0)) 
     221  (LISP-UNIT:ASSERT-ERROR 'GSL-CONDITION (GAMMA -1.0d0)) 
    222222  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    223223   (LIST 120.0d0 2.6645352591003757d-14) 
    224224   (MULTIPLE-VALUE-LIST (GAMMA 6.0d0))) 
    225   (LISP-UNIT:ASSERT-ERROR 'GSL-ERROR (LOG-GAMMA -100.0d0)) 
     225  (LISP-UNIT:ASSERT-ERROR 'GSL-CONDITION (LOG-GAMMA -100.0d0)) 
    226226  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    227227   (LIST 359.13420536957534d0 2.4544868717695813d-13) 
     
    260260   (LIST 56.0d0 7.460698725481052d-14) 
    261261   (MULTIPLE-VALUE-LIST (CHOOSE 8 3))) 
    262   (LISP-UNIT:ASSERT-ERROR 'GSL-ERROR (CHOOSE 3 8)) 
     262  (LISP-UNIT:ASSERT-ERROR 'GSL-CONDITION (CHOOSE 3 8)) 
    263263  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    264264   (LIST 29.422274169864693d0 1.9338924605168215d-13) 
  • trunk/special-functions/legendre.lisp

    r34 r47  
    11;; Legendre functions 
    22;; Liam Healy, Sat Apr 29 2006 - 19:16 
    3 ;; Time-stamp: <2008-03-09 19:29:17EDT legendre.lisp> 
     3;; Time-stamp: <2008-03-27 21:30:02EDT legendre.lisp> 
    44;; $Id$ 
    55 
     
    307307   (LIST -0.38249999999999995d0 1.9984014443252816d-16) 
    308308   (MULTIPLE-VALUE-LIST (LEGENDRE-P3 0.3d0))) 
    309   (LISP-UNIT:ASSERT-ERROR 'GSL-ERROR 
     309  (LISP-UNIT:ASSERT-ERROR 'GSL-CONDITION 
    310310                          (LEGENDRE-PL -4 0.3d0)) 
    311   (LISP-UNIT:ASSERT-ERROR 'GSL-ERROR 
     311  (LISP-UNIT:ASSERT-ERROR 'GSL-CONDITION 
    312312                          (LEGENDRE-PL 4 3.0d0)) 
    313313  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL