Commit 8f43fe94 authored by Liam Healy's avatar Liam Healy

Complex arrays initialize correctly; pool data 8-bit correct; new array tests

Complex arrays can be initialized with either reals or complexes.  If
initialized with reals, there must be an even number.  Now created
complex arrays are the right length and are not always zero in the
imaginary part.  Pool data supplied in *signed-byte-pool* is between
±127 inclusive, instead of ±255, which is required for making
(signed-byte 8).  Added some tests from functions in both.lisp to
generate-tests.lisp.
parent 0343f3ce
;; Tests of array functions
;; Liam Healy 2008-10-20 22:41:48EDT array-tests.lisp
;; Time-stamp: <2008-10-20 22:42:46EDT array-tests.lisp>
;; Time-stamp: <2008-11-02 13:18:30EST array-tests.lisp>
;; $Id: $
(in-package :gsl)
;;; doesn't work for complex because:
;;; Some of these don't work for complex because:
;;; Cannot pass complex scalars to and from GSL functions (structs passed by value).
(generate-all-array-tests
......@@ -15,3 +15,22 @@
(set-all v1 (scalar-default 2))
(cl-array (m+ v1 v2))))
(generate-all-array-tests
set-zero t
(letm ((v1 (vector-default 3)))
(set-zero v1)
(cl-array v1)))
(generate-all-array-tests
array-copy t
(letm ((v1 (vector-default 3))
(v2 (vector-default 3 t)))
(copy v2 v1)
(cl-array v2)))
(generate-all-array-tests
array-swap t
(letm ((v1 (vector-default 3))
(v2 (vector-default 3)))
(swap v2 v1)
(concatenate 'vector (cl-array v1) (cl-array v2))))
;; Data using ffa
;; Liam Healy 2008-04-06 21:23:41EDT data-ffa.lisp
;; Time-stamp: <2008-08-28 21:31:49EDT data.lisp>
;; Time-stamp: <2008-11-02 12:50:17EST data.lisp>
;; $Id$
(in-package :gsl)
......@@ -157,14 +157,24 @@
(cont
(if firsttype
(rest type-contents)
type-contents)))
type-contents))
(matrixp (listp (first cont)))
(complex-with-real-init
(and (subtypep element-type 'complex)
(typep (if matrixp (caar cont) (first cont)) 'real))))
(when complex-with-real-init
(assert
(evenp (length cont)) (cont)
"Complex arrays require initial contents of even length."))
(make-array*
(if (listp (first cont)) ; make a matrix
(list (length cont) (length (first cont)))
(list (length cont))) ; make a vector
(if matrixp
(list (length cont)
(* (if complex-with-real-init 1/2 1) (length (first cont))))
;; make a vector
(list (* (if complex-with-real-init 1/2 1) (length cont))))
element-type
:initial-contents
(if (listp (first cont))
(if matrixp
(apply #'append cont) ; flatten lists
cont))))
......
;; Use the foreign-friendly arrays package.
;; Liam Healy 2008-03-22 15:40:08EDT ffa.lisp
;; Time-stamp: <2008-09-14 16:16:50EDT foreign-friendly.lisp>
;; Time-stamp: <2008-11-02 12:20:23EST foreign-friendly.lisp>
;; $Id$
;;; Use Papp's Foreign-friendly arrays
......@@ -47,12 +47,14 @@ defined in ffa will be usable.
(defun make-array*
(dimensions element-type
&key (initial-element nil initial-element-p) (initial-contents nil initial-contents-p))
&key (initial-element nil initial-element-p)
(initial-contents nil initial-contents-p))
"Make an array for possible use in foreign code.
Syntax is similar to make-array, but note that element-type
is mandatory and limited to certain types."
(assert (member element-type *array-element-types* :test 'equal)
(element-type) "Specified element-type must be one of *array-element-types*.")
(element-type)
"Specified element-type must be one of *array-element-types*.")
(if initial-contents-p
(if (and (subtypep element-type 'complex)
(= (length initial-contents)
......
;; Make tests and examples
;; Liam Healy 2008-09-07 21:00:48EDT generate-tests.lisp
;; Time-stamp: <2008-10-25 19:06:40EDT generate-tests.lisp>
;; Time-stamp: <2008-11-02 10:56:53EST generate-tests.lisp>
;; $Id: $
(in-package :gsl)
......@@ -122,11 +122,11 @@
156 158 157 167 157 34 219 249)
"A sequence of random integers ranging between 0 and 255.")
;;; (loop repeat 50 collect (* (if (zerop (random 2)) -1 1) (random 256)))
;;; (loop repeat 50 collect (* (if (zerop (random 2)) -1 1) (random 128)))
(defparameter *signed-byte-pool*
'(-161 17 -194 -135 -90 253 -22 22 -102 -27 -254 175 -107 -76 108 -209 54
-239 -73 237 -80 -92 150 -107 164 63 -48 -142 0 105 182 253 96 124 -28
-153 -84 188 181 3 96 -114 -222 -39 225 233 84 -218 51 -188)
'(-64 -68 71 -91 52 -10 73 -5 123 32 28 30 37 -73 -8 -15 -22 68 -47 -81 -68
125 -15 -53 -17 -114 24 -60 32 106 -3 37 -1 97 -96 -12 -20 -61 18 108 61
-82 75 -30 -71 44 48 88 121 106)
"A sequence of random integers ranging between -255 and 255.")
(defun make-vector-from-pool (type length &optional (starting 0))
......
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