Commit dce0aefd authored by liam's avatar liam

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
parent 55a79001
......@@ -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))
|#
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
#!/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
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