Changeset 37 for trunk

Show
Ignore:
Timestamp:
03/16/08 02:25:01 (8 months ago)
Author:
lhealy
Message:

The functions #'sort-vector-smallest-index and
#'sort-vector-largest-index now work on 64-bit platforms. It was
necessary to change the API in order to do this: instead of taking a
GSL vector fixnum as the first argument, they now take either a
positive integer, or a CL vector. This is because it appears to be
very difficult to find a GSL vector type that matches a C array of
size_ts. Thus, the GSLL policy of using only GSL vectors and not raw
C vectors needs to be altered. However, now the GSLL policy of not
requiring an object to be passed as an argument if it is used only
for returning values is fulfilled.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/documentation/documentation.html

    r34 r37  
    119119 properly, unless CFFI and the CL platform provide C stream 
    120120 compatibility. 
    121 <li>Some <a href="Sorting.html">sorting</a> functions fail on amd64 platforms, 
    122  perhaps because of lack of unsigned integer vectors. 
    123121<li><a href="BLAS-Support.html">BLAS</a> is completed, but with only very 
    124122 limited testing. 
     
    141139<ul> 
    142140<li>CLISP shows three "foreign callout errors". Remedy unknown. 
    143 <li>Sorting shows two failures on amd64 platforms.  This is possibly 
    144 because of the use of integer vectors to store unsigned integer 
    145 vectors. 
    146141<li>There are several regression failures that are apparently due to 
    147142changes in GSL between versions 1.8 and 1.10.  These are: 
     
    156151<!-- hhmts start --> 
    157152    <small> 
    158        Time-stamp: <2008-03-09 22:21:24EDT documentation.html> 
     153       Time-stamp: <2008-03-15 21:59:58EDT documentation.html> 
    159154       </small> 
    160155<!-- hhmts end --> 
  • trunk/init/interface.lisp

    r29 r37  
    11;; Macros to interface GSL functions. 
    22;; Liam Healy  
    3 ;; Time-stamp: <2008-03-02 21:43:02EST interface.lisp> 
     3;; Time-stamp: <2008-03-15 21:51:07EDT interface.lisp> 
    44;; $Id$ 
    55 
     
    150150;;; after        After method. 
    151151;;; enumeration  The name of the enumeration return. 
     152;;; global     Bind variable(s) in a let* enclosing the whole body. 
    152153(defmacro defmfun 
    153154    (name arglist gsl-name c-arguments 
     
    155156     (return nil return-supplied-p) 
    156157     (type :function) (index t) (export (not (eq type :method))) 
    157      null-pointer-info documentation invalidate after enumeration) 
     158     null-pointer-info documentation invalidate after enumeration 
     159     global) 
    158160  (let* ((cargs (substitute '(mode sf-mode) :mode c-arguments)) 
    159161         (carg-symbs 
     
    171173          (if (listp c-return) (st-symbol c-return) (make-symbol "CRETURN"))) 
    172174         (allocated                  ; Foreign objects to be allocated 
    173           (remove-if (lambda (s) (member s arglist-symbs)) carg-symbs)) 
     175          (remove-if 
     176           (lambda (s) (or (member s arglist-symbs) (member s global :key #'first))) 
     177           carg-symbs)) 
    174178         (allocated-decl 
    175179          (mapcar 
     
    185189      (,(if (eq type :function) 'defun 'defmethod) 
    186190       ,name 
    187        ,(if (member :mode c-arguments) 
    188             `(,@clargs &optional (mode :double-prec)) 
    189             `(,@clargs)) 
     191       ,(let ((noaux 
     192               (if (member :mode c-arguments) 
     193                   `(,@clargs &optional (mode :double-prec)) 
     194                   `(,@clargs)))) 
     195             (if global 
     196                 (append noaux (cons '&aux global)) 
     197                 noaux)) 
    190198       ,(declaration-form clargs-types) 
    191199       ,@(when documentation (list documentation)) 
  • trunk/sorting.lisp

    r34 r37  
    11;; Sorting 
    22;; Liam Healy, Fri Apr 14 2006 - 20:20 
    3 ;; Time-stamp: <2008-03-09 21:42:24EDT sorting.lisp> 
     3;; Time-stamp: <2008-03-15 22:09:56EDT sorting.lisp> 
    44;; $Id$ 
    55 
     
    88;;; #'heapsort has just a cursory port, use CL's #'sort. 
    99;;; Raw C array functions not ported, not policy. 
    10  
    11 ;;; Errors: 
    12 ;;; sort-vector-smallest-index and sort-vector-largest-index 
    13 ;;; do not work on amd64/SBCL, and should be defined in terms of 
    14 ;;; vector-unsigned-fixnum anyway 
    1510 
    1611;;;;**************************************************************************** 
     
    9388  :invalidate (dest)) 
    9489 
    95 ;;; p should be gsl-vector-unsigned-fixnum, if that can be made to 
    96 ;;; work (see vector.lisp). 
    9790(export 'sort-vector-smallest-index) 
    98 (defgeneric sort-vector-smallest-index (p vector) 
    99   (:documentation                       ; FDL 
    100    "The indices of the smallest elements of the vector stored 
    101    in the array p.")) 
     91(defgeneric sort-vector-smallest-index (indices vector) 
     92  (:documentation 
     93   "The indices of the smallest elements of the vector stored, 
     94    returned as a CL vector of element type fixnum.  If 
     95    indices is a positive initeger, a vector will be 
     96    allocated and returned.  If it is a CL vector, 
     97    it will be filled with the indices.")) 
    10298 
    10399(defmfun-vdsf sort-vector-smallest-index 
    104     ((p vector-fixnum) (v vector)) 
     100    (indices (v vector)) 
    105101  "gsl_sort_vector_smallest_index" 
    106   (((gsl-array p) :pointer) ((dim0 p) size) 
    107    ((pointer v) gsl-vector-c)) 
    108   :c-return :void 
    109   :invalidate (p)) 
     102  ((p (size number)) (number size) ((pointer v) :pointer)) 
     103  :type :method 
     104  :global ((number (if (numberp indices) indices (length indices)))) 
     105  :c-return :void 
     106  :return 
     107  ((let* ((vector 
     108           (if (numberp indices) 
     109               (make-array (list indices) :element-type 'fixnum) 
     110               indices))) 
     111     (dotimes (i number vector) 
     112       (setf (aref vector i) (scref p i)))))) 
    110113 
    111114(export 'sort-vector-largest) 
     
    125128;;; p should be gsl-vector-unsigned-fixnum, if that can be made to 
    126129;;; work (see vector.lisp). 
    127 (defgeneric sort-vector-largest-index (p vector) 
    128   (:documentation                       ; FDL 
    129    "The indices of the largest elements of the vector stored 
    130    in the array p.")) 
    131  
    132 (defmfun-vdsf sort-vector-largest-index 
    133     ((p vector-fixnum) (v vector)) 
     130(defgeneric sort-vector-largest-index (indices vector) 
     131  (:documentation                
     132   "The indices of the largest elements of the vector stored, 
     133    returned as a CL vector of element type fixnum.  If 
     134    indices is a positive initeger, a vector will be 
     135    allocated and returned.  If it is a CL vector, 
     136    it will be filled with the indices.")) 
     137 
     138(defmfun-vdsf sort-vector-largest-index (indices (v vector)) 
    134139  "gsl_sort_vector_largest_index" 
    135   (((gsl-array p) :pointer) ((dim0 p) size) 
    136    ((pointer v) gsl-vector-c)) 
    137   :c-return :void 
    138   :invalidate (p)) 
     140  ((p (size number)) (number size) ((pointer v) :pointer)) 
     141  :type :method 
     142  :global ((number (if (numberp indices) indices (length indices)))) 
     143  :c-return :void 
     144  :return 
     145  ((let* ((vector 
     146           (if (numberp indices) 
     147               (make-array (list indices) :element-type 'fixnum) 
     148               indices))) 
     149     (dotimes (i number vector) 
     150       (setf (aref vector i) (scref p i)))))) 
    139151 
    140152;;;;**************************************************************************** 
     
    155167   (sort-vector-smallest smallest vec) 
    156168   (data smallest)) 
    157  (letm ((vec (vector-double-float #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))) 
    158         (smallest (vector-fixnum 3))) 
    159    (sort-vector-smallest-index smallest vec) 
    160    (data smallest)) 
     169 (letm ((vec (vector-double-float #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
     170   (sort-vector-smallest-index 3 vec)) 
    161171 (letm ((vec (vector-double-float #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))) 
    162172        (largest (vector-double-float 3))) 
    163173   (sort-vector-largest largest vec) 
    164174   (data largest)) 
    165  (letm ((vec (vector-double-float #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))) 
    166         (largest (vector-fixnum 3))) 
    167    (sort-vector-largest-index largest vec) 
    168    (data largest))) 
     175 (letm ((vec (vector-double-float #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
     176   (sort-vector-largest-index 3 vec))) 
    169177|# 
    170178 
     179 
    171180(LISP-UNIT:DEFINE-TEST SORTING 
    172181  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    173182   (LIST #(-3.21d0 -2.0d0 1.0d0 7.1d0 12.8d0)) 
    174183   (MULTIPLE-VALUE-LIST 
    175     (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
     184    (LETM 
     185        ((VEC 
     186          (VECTOR-DOUBLE-FLOAT 
     187           #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
    176188      (SORT-VECTOR VEC) (DATA VEC)))) 
    177189  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
     
    179191   (MULTIPLE-VALUE-LIST 
    180192    (LETM ((PERM (PERMUTATION 5)) 
    181          (VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
     193           (VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
    182194      (SORT-VECTOR-INDEX PERM VEC) 
    183195      (DATA PERM)))) 
     
    186198   (MULTIPLE-VALUE-LIST 
    187199    (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))) 
    188          (SMALLEST (VECTOR-DOUBLE-FLOAT 3))) 
     200           (SMALLEST (VECTOR-DOUBLE-FLOAT 3))) 
    189201      (SORT-VECTOR-SMALLEST SMALLEST VEC) 
    190202      (DATA SMALLEST)))) 
     
    192204   (LIST #(3 1 4)) 
    193205   (MULTIPLE-VALUE-LIST 
     206    (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
     207      (SORT-VECTOR-SMALLEST-INDEX 3 VEC)))) 
     208  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
     209   (LIST #(12.8d0 7.1d0 1.0d0)) 
     210   (MULTIPLE-VALUE-LIST 
    194211    (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))) 
    195          (SMALLEST (VECTOR-FIXNUM 3))) 
    196       (SORT-VECTOR-SMALLEST-INDEX 
    197        SMALLEST VEC) 
    198       (DATA SMALLEST)))) 
    199   (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    200    (LIST #(12.8d0 7.1d0 1.0d0)) 
    201    (MULTIPLE-VALUE-LIST 
    202     (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))) 
    203          (LARGEST (VECTOR-DOUBLE-FLOAT 3))) 
     212           (LARGEST (VECTOR-DOUBLE-FLOAT 3))) 
    204213      (SORT-VECTOR-LARGEST LARGEST VEC) (DATA LARGEST)))) 
    205214  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL 
    206215   (LIST #(2 0 4)) 
    207216   (MULTIPLE-VALUE-LIST 
    208     (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))) 
    209          (LARGEST (VECTOR-FIXNUM 3))) 
    210       (SORT-VECTOR-LARGEST-INDEX LARGEST VEC) 
    211       (DATA LARGEST))))) 
     217    (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))) 
     218      (SORT-VECTOR-LARGEST-INDEX 3 VEC)))))