array-tests.lisp 6.93 KB
Newer Older
1 2
;; Tests of array functions 
;; Liam Healy 2008-10-20 22:41:48EDT array-tests.lisp
3
;; Time-stamp: <2008-12-31 21:40:17EST array-tests.lisp>
4 5
;; $Id: $

6 7 8
;;; Generate each file with #'write-test-to-file, e.g.
;;; (write-test-to-file 'matrix-set-zero "../test/")

9 10
(in-package :gsl)

11
;;; Some of these don't work for complex because:
12 13
;;; Cannot pass complex scalars to and from GSL functions (structs passed by value).

Liam Healy's avatar
Liam Healy committed
14 15 16 17
;;;;****************************************************************************
;;;; Bulk operations
;;;;****************************************************************************

18
(generate-all-array-tests
19
 vector-set-all-m+ :no-complex
20
 (let ((v1 (array-default 3 t))
21 22
	(v2 (array-default 3)))
   (set-all v1 (scalar-default))
23 24
   (cl-array (m+ v1 v2))))

25
(generate-all-array-tests
26
 matrix-set-all-m+ :no-complex
27 28
 (let ((m1 (array-default '(3 3) t))
       (m2 (array-default '(3 3))))
29 30 31 32 33
   (set-all m1 (scalar-default))
   (cl-array (m+ m1 m2))))

(generate-all-array-tests
 vector-set-zero t
34
 (let ((v1 (array-default 3)))
35 36 37 38
   (set-zero v1)
   (cl-array v1)))

(generate-all-array-tests
39
 matrix-set-zero t
40
 (let ((m1 (array-default '(3 3))))
41 42 43 44 45
   (set-zero m1)
   (cl-array m1)))

(generate-all-array-tests
 vector-copy t
46
 (let ((v1 (array-default 3))
47
	(v2 (array-default 3 t)))
48 49 50 51
   (copy v2 v1)
   (cl-array v2)))

(generate-all-array-tests
52
 matrix-copy t
53
 (let ((m1 (array-default '(3 3)))
54 55 56 57 58 59
	(m2 (array-default '(3 3) t)))
   (copy m2 m1)
   (cl-array m2)))

(generate-all-array-tests
 vector-swap t
60
 (let ((v1 (array-default 3))
61
	(v2 (array-default 3)))
62
   (swap v2 v1)
63 64 65 66
   (list (cl-array v1) (cl-array v2))))

(generate-all-array-tests
 matrix-swap t
67
 (let ((m1 (array-default '(3 3)))
68 69 70
	(m2 (array-default '(3 3))))
   (swap m2 m1)
   (list (cl-array m1) (cl-array m2))))
Liam Healy's avatar
Liam Healy committed
71 72 73 74 75 76

;;;;****************************************************************************
;;;; Arithmetic operations
;;;;****************************************************************************

(generate-all-array-tests vector-m+ :no-complex
77
 (let ((v1 (array-default 3))
Liam Healy's avatar
Liam Healy committed
78 79 80 81
	(v2 (array-default 3)))
   (cl-array (m+ v1 v2))))

(generate-all-array-tests matrix-m+ :no-complex
82
 (let ((m1 (array-default '(3 3)))
Liam Healy's avatar
Liam Healy committed
83 84 85 86
	(m2 (array-default '(3 3))))
   (cl-array (m+ m1 m2))))

(generate-all-array-tests vector-m- :no-complex
87
 (let ((v1 (array-default 3))
Liam Healy's avatar
Liam Healy committed
88 89 90 91
	(v2 (array-default 3)))
   (cl-array (m- v1 v2))))

(generate-all-array-tests matrix-m- :no-complex
92
 (let ((m1 (array-default '(3 3)))
Liam Healy's avatar
Liam Healy committed
93 94 95 96
	(m2 (array-default '(3 3))))
   (cl-array (m- m1 m2))))

(generate-all-array-tests vector-mult :no-complex
97
 (let ((v1 (array-default 3))
Liam Healy's avatar
Liam Healy committed
98 99 100 101
	(v2 (array-default 3)))
   (cl-array (m* v1 v2))))

(generate-all-array-tests matrix-mult :no-complex
102
 (let ((m1 (array-default '(3 3)))
Liam Healy's avatar
Liam Healy committed
103 104 105 106
	(m2 (array-default '(3 3))))
   (cl-array (m* m1 m2))))

(generate-all-array-tests vector-div :no-complex
107
 (let ((v1 (array-default 3))
Liam Healy's avatar
Liam Healy committed
108 109 110 111
	(v2 (array-default 3)))
   (cl-array (m/ v1 v2))))

(generate-all-array-tests matrix-div :no-complex
112
 (let ((m1 (array-default '(3 3)))
Liam Healy's avatar
Liam Healy committed
113 114 115 116
	(m2 (array-default '(3 3))))
   (cl-array (m/ m1 m2))))

(generate-all-array-tests vector-mult-scalar :no-complex
117
 (let ((v1 (array-default 3)))
118
   (cl-array (m*c v1 1.39d0))))
Liam Healy's avatar
Liam Healy committed
119 120

(generate-all-array-tests matrix-mult-scalar :no-complex
121
 (let ((m1 (array-default '(3 3))))
122
   (cl-array (m*c m1 1.39d0))))
Liam Healy's avatar
Liam Healy committed
123 124

(generate-all-array-tests vector-add-scalar :no-complex
125
 (let ((v1 (array-default 3)))
126
   (cl-array (m+c v1 18.19d0))))
Liam Healy's avatar
Liam Healy committed
127 128

(generate-all-array-tests matrix-add-scalar :no-complex
129
 (let ((m1 (array-default '(3 3))))
130
   (cl-array (m+c m1 18.19d0))))
Liam Healy's avatar
Liam Healy committed
131 132 133 134 135 136

;;;;****************************************************************************
;;;; Maximum and minimum elements
;;;;****************************************************************************

(generate-all-array-tests vector-max :no-complex
137
 (let ((v1 (array-default 3)))
Liam Healy's avatar
Liam Healy committed
138 139 140
   (mmax v1)))

(generate-all-array-tests matrix-max :no-complex
141
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
142 143 144
   (mmax m1)))

(generate-all-array-tests vector-min :no-complex
145
 (let ((v1 (array-default 3)))
Liam Healy's avatar
Liam Healy committed
146 147 148
   (mmin v1)))

(generate-all-array-tests matrix-min :no-complex
149
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
150 151 152
   (mmin m1)))

(generate-all-array-tests vector-minmax :no-complex
153
 (let ((v1 (array-default 3)))
Liam Healy's avatar
Liam Healy committed
154 155 156
   (minmax v1)))

(generate-all-array-tests matrix-minmax :no-complex
157
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
158 159 160
   (minmax m1)))

(generate-all-array-tests vector-min-index :no-complex
161
 (let ((v1 (array-default 8)))
Liam Healy's avatar
Liam Healy committed
162 163 164
   (min-index v1)))

(generate-all-array-tests matrix-min-index :no-complex
165
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
166 167 168
   (min-index m1)))

(generate-all-array-tests vector-max-index :no-complex
169
 (let ((v1 (array-default 8)))
Liam Healy's avatar
Liam Healy committed
170 171 172
   (max-index v1)))

(generate-all-array-tests matrix-max-index :no-complex
173
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
174 175 176
   (max-index m1)))

(generate-all-array-tests vector-minmax-index :no-complex
177
 (let ((v1 (array-default 8)))
Liam Healy's avatar
Liam Healy committed
178 179 180
   (minmax-index v1)))

(generate-all-array-tests matrix-minmax-index :no-complex
181
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
182 183 184
   (minmax-index m1)))

;;; No test for mzerop yet.
185 186 187 188 189 190

;;;;****************************************************************************
;;;; Vector-only function definitions
;;;;****************************************************************************

(generate-all-array-tests set-basis t
191
 (let ((v1 (array-default 8)))
192 193 194 195
   (set-basis v1 2)
   (cl-array v1)))

(generate-all-array-tests swap-elements t
196
 (let ((v1 (array-default 8)))
197 198 199 200
   (swap-elements v1 2 5)
   (cl-array v1)))

(generate-all-array-tests vector-reverse t
201
 (let ((v1 (array-default 8)))
202 203 204 205 206 207 208
   (cl-array (vector-reverse v1))))

;;;;****************************************************************************
;;;; Matrix-only function definitions
;;;;****************************************************************************

(generate-all-array-tests set-identity t
209
 (let ((m1 (array-default '(3 3))))
210
   (cl-array (set-identity m1))))
211 212

(generate-all-array-tests row t
213
 (let ((m1 (array-default '(3 3)))
214 215 216 217
	(row (array-default 3 t)))
   (cl-array (row row m1 1))))

(generate-all-array-tests setf-row t
218
 (let ((m1 (array-default '(3 3)))
219 220 221 222 223
	(row (array-default 3)))
   (setf (row m1 2) row)
   (cl-array m1)))

(generate-all-array-tests column t
224
 (let ((m1 (array-default '(3 3)))
225 226 227 228
	(col (array-default 3 t)))
   (cl-array (column col m1 1))))

(generate-all-array-tests setf-column t
229
 (let ((m1 (array-default '(3 3)))
230 231 232 233 234
	(col (array-default 3)))
   (setf (column m1 2) col)
   (cl-array m1)))

(generate-all-array-tests swap-rows t
235
 (let ((m1 (array-default '(3 3))))
236 237 238
   (cl-array (swap-rows m1 0 1))))

(generate-all-array-tests swap-columns t
239
 (let ((m1 (array-default '(3 3))))
240 241 242
   (cl-array (swap-columns m1 1 2))))

(generate-all-array-tests swap-row-column t
243
 (let ((m1 (array-default '(3 3))))
244 245 246
   (cl-array (swap-row-column m1 0 2))))

(generate-all-array-tests matrix-transpose t
247
 (let ((m1 (array-default '(3 3))))
248 249 250
   (cl-array (matrix-transpose m1))))

(generate-all-array-tests matrix-transpose-copy t
251
 (let ((m1 (array-default '(3 3)))
252 253
	(m2 (array-default '(3 3) t)))
   (cl-array (matrix-transpose-copy m2 m1))))