From dce0aefdad358311ab46c9ebbee38d5e46cd7c08 Mon Sep 17 00:00:00 2001 From: liam <liam@a3d8a0fb-c1db-0310-ace7-a616afeb9e30> Date: Mon, 5 Jun 2006 01:53:03 +0000 Subject: [PATCH] Fix permutation so that it knows about different types of vectors. Port combinations to new defun-gsl. If defun-gsl is to return a success-failure and invalidated (input) values, do the former first. Shell function list to list all of the gsl library. git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3084 a3d8a0fb-c1db-0310-ace7-a616afeb9e30 --- data/combination.lisp | 112 ++++++++++++++++++++++++++---------------- data/permutation.lisp | 8 +-- gsll.asd | 7 ++- init/interface.lisp | 7 ++- list | 4 ++ 5 files changed, 86 insertions(+), 52 deletions(-) create mode 100755 list diff --git a/data/combination.lisp b/data/combination.lisp index 052df5b0..0e26cfca 100644 --- a/data/combination.lisp +++ b/data/combination.lisp @@ -3,7 +3,7 @@ ; description: Combinations ; date: Sun Mar 26 2006 - 11:51 ; author: Liam M. Healy -; modified: Tue Apr 18 2006 - 23:28 +; modified: Sun Jun 4 2006 - 21:43 ;******************************************************** ;;; $Id: $ @@ -20,23 +20,20 @@ (data :pointer)) ;;; Allocation, freeing, reading and writing -(defdata "combination" :size 'fixnum 2) +(defdata "combination" combination unsigned-byte gsl-data 2) (defmethod gsl-array ((object gsl-combination)) (foreign-slot-value (pointer object) 'gsl-combination-c 'data)) -(add-wrap-type gsl-combination-c (lambda (x) `(pointer ,x))) - ;;;;**************************************************************************** ;;;; Getting values ;;;;**************************************************************************** -(defun-gsl gsl-aref - (((pointer combination) :pointer) ((first indices) :size)) +(defun-gsl gsl-aref ((combination gsl-combination) &rest indices) "gsl_combination_get" - :method ((combination gsl-combination) &rest indices) - :return (:size) - :c-return-value :return + (((pointer combination) :pointer) ((first indices) :size)) + :type :method + :c-return :size :documentation "The ith element of the combination.") (defmethod data ((object gsl-combination) &optional sequence) @@ -51,24 +48,30 @@ ;;;; Setting values ;;;;**************************************************************************** -(defun-gsl init-first ((combination gsl-combination-c)) +(defun-gsl init-first (combination) "gsl_combination_init_first" - :c-return-value :void + (((pointer combination) gsl-combination-c)) + :c-return :void + :invalidate (combination) :documentation "Initialize the combination @var{c} to the lexicographically first combination, i.e. @math{(0,1,2,@dots{},k-1)}.") -(defun-gsl init-last ((combination gsl-combination-c)) +(defun-gsl init-last (combination) "gsl_combination_init_last" - :c-return-value :void + (((pointer combination) gsl-combination-c)) + :c-return :void + :invalidate (combination) :documentation "Initialize the combination @var{c} to the lexicographically last combination, i.e. @math{(n-k,n-k+1,@dots{},n-1)}.") -(defun-gsl combination-copy - ((destination gsl-combination-c) (source gsl-combination-c) ) +(defun-gsl copy (destination source) "gsl_combination_memcpy" - :after ((cl-invalidate destination)) + (((pointer destination) gsl-combination-c) + ((pointer source) gsl-combination-c)) + :type :method + :invalidate (destination) :documentation "Copy the elements of the combination @var{src} into the combination @var{dest}. The two combinations must have the same size.") @@ -77,32 +80,35 @@ ;;;; Combination properties ;;;;**************************************************************************** -(defun-gsl combination-range ((c gsl-combination-c)) +(defun-gsl combination-range (c) "gsl_combination_n" - :c-return-value :return - :return (:size) + (((pointer c) gsl-combination-c)) + :c-return :size :documentation "The range (@math{n}) of the combination @var{c}.") -(defun-gsl combination-size ((c gsl-combination-c)) +(defun-gsl combination-size (c) "gsl_combination_k" - :c-return-value :return - :return (:size) + (((pointer c) gsl-combination-c)) + :c-return :size :documentation "The number of elements (@math{k}) in the combination @var{c}.") -(defun-gsl combination-data ((c gsl-combination-c)) +#| +;;; Unnecessary, gsl-array serves this function. +(defun-gsl combination-data (c) "gsl_combination_data" - :c-return-value :return - :return (:pointer) + (((pointer c) gsl-combination-c)) + :c-return :pointer :documentation "A pointer to the array of elements in the combination @var{p}.") +|# -(defun-gsl data-valid (((pointer combination) :pointer)) +(defun-gsl data-valid ((combination gsl-combination)) "gsl_combination_valid" - :method ((combination gsl-combination)) - :c-return-value :return - :return (:boolean) + (((pointer combination) :pointer)) + :type :method + :c-return :boolean :documentation "Check that the combination @var{c} is valid. The @var{k} elements should lie in the range 0 to @math{@var{n}-1}, with each @@ -112,32 +118,55 @@ ;;;; Combination functions ;;;;**************************************************************************** -(defun-gsl combination-next ((c gsl-combination-c)) - "gsl_combination_next" - :c-return-value :success-failure - :after ((cl-invalidate c)) +(defun-gsl combination-next (c) + "gsl_combination_next" (((pointer c) gsl-combination-c)) + :c-return :success-failure + :invalidate (c) :documentation "Advance the combination @var{c} to the next combination - in lexicographic order and return T. If no further - combinations are available it return NIL and leave + in lexicographic order and return T and c. If no further + combinations are available it return NIL and c with @var{c} unmodified. Starting with the first combination and repeatedly applying this function will iterate through all possible combinations of a given order.") -(defun-gsl combination-previous ((c gsl-combination-c)) +(defun-gsl combination-previous (c) "gsl_combination_prev" - :c-return-value :success-failure - :after ((cl-invalidate c)) + (((pointer c) gsl-combination-c)) + :c-return :success-failure + :invalidate (c) :documentation "Step backwards from the combination @var{c} to the previous combination in lexicographic order, returning - T. If no previous combination is available it returns - NIL and leaves @var{c} unmodified.") + T and c. If no previous combination is available it returns + NIL and c with @var{c} unmodified.") ;;;;**************************************************************************** -;;;; Examples +;;;; Examples and unit test ;;;;**************************************************************************** +(defparameter *comb-1* (make-data 'combination t 4 2)) + +(lisp-unit:define-test combination + (lisp-unit:assert-eql ; combination-range + 4 + (combination-range *comb-1*)) + (lisp-unit:assert-eql ; combination-size + 2 + (combination-size *comb-1*)) + (lisp-unit:assert-equal ; init-first, combination-next + '((0 1) (0 2) (0 3) (1 2) (1 3) (2 3)) + (progn + (init-first *comb-1*) + (loop collect (data *comb-1*) + while (combination-next *comb-1*)))) + (lisp-unit:assert-equal ; init-first, combination-next + '((2 3) (1 3) (1 2) (0 3) (0 2) (0 1)) + (progn + (init-last *comb-1*) + (loop collect (data *comb-1*) + while (combination-previous *comb-1*))))) + #| (loop for i from 0 to 4 append @@ -147,5 +176,4 @@ (NIL (0) (1) (2) (3) (0 1) (0 2) (0 3) (1 2) (1 3) (2 3) (0 1 2) (0 1 3) (0 2 3) (1 2 3) (0 1 2 3)) - |# diff --git a/data/permutation.lisp b/data/permutation.lisp index 2b924254..955e3079 100644 --- a/data/permutation.lisp +++ b/data/permutation.lisp @@ -3,7 +3,7 @@ ; description: Permutations ; date: Sun Mar 26 2006 - 11:51 ; author: Liam M. Healy -; modified: Sat Jun 3 2006 - 22:04 +; modified: Sun Jun 4 2006 - 21:02 ;******************************************************** ;;; $Id: $ @@ -19,7 +19,7 @@ (data :pointer)) ;;; Allocation, freeing, reading and writing -(defdata "permutation" permutation fixnum) +(defdata "permutation" permutation unsigned-byte) (defmethod gsl-array ((object gsl-permutation)) (foreign-slot-value (pointer object) 'gsl-permutation-c 'data)) @@ -157,7 +157,7 @@ "Apply the inverse of the permutation @var{p} to the array @var{data} of size @var{n} with stride @var{stride}.") -(defun-gsl permute-vector (p v) +(defun-gsl-vdsfc permute-vector (p (v gsl-vector)) "gsl_permute_vector" (((pointer p) gsl-permutation-c) ((pointer v) gsl-vector-c)) :invalidate (v) @@ -169,7 +169,7 @@ identity matrix. The permutation @var{p} and the vector @var{v} must have the same length.") -(defun-gsl permute-vector-inverse (p v) +(defun-gsl-vdsfc permute-vector-inverse (p (v gsl-vector)) "gsl_permute_vector_inverse" (((pointer p) gsl-permutation-c) ((pointer v) gsl-vector-c)) :invalidate (v) diff --git a/gsll.asd b/gsll.asd index 3f666401..f1dc62b0 100644 --- a/gsll.asd +++ b/gsll.asd @@ -3,7 +3,7 @@ ; description: Definition of GSLL system ; date: ; author: Liam Healy -; modified: Sat Jun 3 2006 - 22:08 +; modified: Sun Jun 4 2006 - 21:40 ;******************************************************** ;;; $Id: $ @@ -36,9 +36,8 @@ (:file "block" :depends-on (data)) (:file "vector" :depends-on (data)) (:file "matrix" :depends-on (data vector)) - (:file "permutation" :depends-on (data)) - ;;(:file "combination" :depends-on (data)) - )) + (:file "permutation" :depends-on (data vector)) + (:file "combination" :depends-on (data)))) #+future (:file "cffi-array") #+future diff --git a/init/interface.lisp b/init/interface.lisp index b6abe59f..7f115e6a 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 Jun 2 2006 - 23:20 +; modified: Sun Jun 4 2006 - 21:39 ;******************************************************** (in-package :gsl) @@ -184,7 +184,10 @@ clret (loop for i below (length clret) collect i))) (:success-failure - `(,@clret (success-failure ,cret-name))) + (if (equal clret invalidate) + ;; success-failure more important than passed-in + `((success-failure ,cret-name) ,@clret) + `(,@clret (success-failure ,cret-name)))) (t (unless (and (null return) return-supplied-p) clret))))))) (map-name ',(or index name) ,gsl-name) diff --git a/list b/list new file mode 100755 index 00000000..15e7e7f3 --- /dev/null +++ b/list @@ -0,0 +1,4 @@ +#!/bin/bash +# List all exported symbols in the gsl library. +# As far as I know this works in Linux only. +nm -D --defined-only -g /usr/lib/libgsl.so | cut -d " " -f 3 -- GitLab