array-tests.lisp 6.9 KB
Newer Older
1
2
;; Tests of array functions 
;; Liam Healy 2008-10-20 22:41:48EDT array-tests.lisp
Liam Healy's avatar
Liam Healy committed
3
;; Time-stamp: <2009-04-15 23:28:05EDT 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 vector-set-all-add :no-complex
19
 (let ((v1 (array-default 3 t))
20
21
	(v2 (array-default 3)))
   (set-all v1 (scalar-default))
22
   (cl-array (elt+ v1 v2))))
23

24
(generate-all-array-tests matrix-set-all-add :no-complex
25
26
 (let ((m1 (array-default '(3 3) t))
       (m2 (array-default '(3 3))))
27
   (set-all m1 (scalar-default))
28
   (cl-array (elt+ m1 m2))))
29

30
(generate-all-array-tests vector-set-zero t
31
 (let ((v1 (array-default 3)))
32
33
34
   (set-zero v1)
   (cl-array v1)))

35
(generate-all-array-tests matrix-set-zero t
36
 (let ((m1 (array-default '(3 3))))
37
38
39
   (set-zero m1)
   (cl-array m1)))

40
(generate-all-array-tests vector-copy t
Liam Healy's avatar
Liam Healy committed
41
 (cl-array (copy (array-default 3))))
42

43
(generate-all-array-tests matrix-copy t
Liam Healy's avatar
Liam Healy committed
44
 (cl-array (copy (array-default '(3 3)))))
45

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

52
(generate-all-array-tests matrix-swap t
53
 (let ((m1 (array-default '(3 3)))
54
       (m2 (array-default '(3 3))))
55
56
   (swap m2 m1)
   (list (cl-array m1) (cl-array m2))))
Liam Healy's avatar
Liam Healy committed
57
58
59
60
61

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

62
(generate-all-array-tests vector-add :no-complex
63
 (let ((v1 (array-default 3))
64
       (v2 (array-default 3)))
Liam Healy's avatar
Liam Healy committed
65
   (elt+ v1 v2)))
Liam Healy's avatar
Liam Healy committed
66

67
(generate-all-array-tests matrix-add :no-complex
68
 (let ((m1 (array-default '(3 3)))
69
70
       (m2 (array-default '(3 3))))
   (cl-array (elt+ m1 m2))))
Liam Healy's avatar
Liam Healy committed
71

72
(generate-all-array-tests vector-sub :no-complex
73
 (let ((v1 (array-default 3))
74
75
       (v2 (array-default 3)))
   (cl-array (elt- v1 v2))))
Liam Healy's avatar
Liam Healy committed
76

77
(generate-all-array-tests matrix-sub :no-complex
78
 (let ((m1 (array-default '(3 3)))
79
80
       (m2 (array-default '(3 3))))
   (cl-array (elt- m1 m2))))
Liam Healy's avatar
Liam Healy committed
81
82

(generate-all-array-tests vector-mult :no-complex
83
 (let ((v1 (array-default 3))
84
       (v2 (array-default 3)))
85
   (cl-array (elt* v1 v2))))
Liam Healy's avatar
Liam Healy committed
86
87

(generate-all-array-tests matrix-mult :no-complex
88
 (let ((m1 (array-default '(3 3)))
89
       (m2 (array-default '(3 3))))
90
   (cl-array (elt* m1 m2))))
Liam Healy's avatar
Liam Healy committed
91
92

(generate-all-array-tests vector-div :no-complex
93
 (let ((v1 (array-default 3))
94
       (v2 (array-default 3)))
95
   (cl-array (elt/ v1 v2))))
Liam Healy's avatar
Liam Healy committed
96
97

(generate-all-array-tests matrix-div :no-complex
98
 (let ((m1 (array-default '(3 3)))
99
       (m2 (array-default '(3 3))))
100
   (cl-array (elt/ m1 m2))))
Liam Healy's avatar
Liam Healy committed
101
102

(generate-all-array-tests vector-mult-scalar :no-complex
103
 (let ((v1 (array-default 3)))
104
   (cl-array (elt* v1 1.39d0))))
Liam Healy's avatar
Liam Healy committed
105
106

(generate-all-array-tests matrix-mult-scalar :no-complex
107
 (let ((m1 (array-default '(3 3))))
108
   (cl-array (elt* m1 1.39d0))))
Liam Healy's avatar
Liam Healy committed
109
110

(generate-all-array-tests vector-add-scalar :no-complex
111
 (let ((v1 (array-default 3)))
112
   (cl-array (elt+ v1 18.19d0))))
Liam Healy's avatar
Liam Healy committed
113
114

(generate-all-array-tests matrix-add-scalar :no-complex
115
 (let ((m1 (array-default '(3 3))))
116
   (cl-array (elt+ m1 18.19d0))))
Liam Healy's avatar
Liam Healy committed
117
118
119
120
121
122

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

(generate-all-array-tests vector-max :no-complex
123
 (let ((v1 (array-default 3)))
Liam Healy's avatar
Liam Healy committed
124
125
126
   (mmax v1)))

(generate-all-array-tests matrix-max :no-complex
127
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
128
129
130
   (mmax m1)))

(generate-all-array-tests vector-min :no-complex
131
 (let ((v1 (array-default 3)))
Liam Healy's avatar
Liam Healy committed
132
133
134
   (mmin v1)))

(generate-all-array-tests matrix-min :no-complex
135
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
136
137
138
   (mmin m1)))

(generate-all-array-tests vector-minmax :no-complex
139
 (let ((v1 (array-default 3)))
Liam Healy's avatar
Liam Healy committed
140
141
142
   (minmax v1)))

(generate-all-array-tests matrix-minmax :no-complex
143
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
144
145
146
   (minmax m1)))

(generate-all-array-tests vector-min-index :no-complex
147
 (let ((v1 (array-default 8)))
Liam Healy's avatar
Liam Healy committed
148
149
150
   (min-index v1)))

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

(generate-all-array-tests vector-max-index :no-complex
155
 (let ((v1 (array-default 8)))
Liam Healy's avatar
Liam Healy committed
156
157
158
   (max-index v1)))

(generate-all-array-tests matrix-max-index :no-complex
159
 (let ((m1 (array-default '(3 3))))
Liam Healy's avatar
Liam Healy committed
160
161
162
   (max-index m1)))

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

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

;;; No test for mzerop yet.
171
172
173
174
175
176

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

(generate-all-array-tests set-basis t
177
 (let ((v1 (array-default 8)))
178
179
180
181
   (set-basis v1 2)
   (cl-array v1)))

(generate-all-array-tests swap-elements t
182
 (let ((v1 (array-default 8)))
183
184
185
186
   (swap-elements v1 2 5)
   (cl-array v1)))

(generate-all-array-tests vector-reverse t
187
 (let ((v1 (array-default 8)))
188
189
190
191
192
193
194
   (cl-array (vector-reverse v1))))

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

(generate-all-array-tests set-identity t
195
 (let ((m1 (array-default '(3 3))))
196
   (cl-array (set-identity m1))))
197
198

(generate-all-array-tests row t
199
 (let ((m1 (array-default '(3 3)))
200
201
       (row (array-default 3 t)))
   (cl-array (row m1 1 row))))
202
203

(generate-all-array-tests setf-row t
204
 (let ((m1 (array-default '(3 3)))
205
206
207
208
209
	(row (array-default 3)))
   (setf (row m1 2) row)
   (cl-array m1)))

(generate-all-array-tests column t
210
 (let ((m1 (array-default '(3 3)))
211
212
       (col (array-default 3 t)))
   (cl-array (column m1 1 col))))
213
214

(generate-all-array-tests setf-column t
215
 (let ((m1 (array-default '(3 3)))
216
217
218
219
220
	(col (array-default 3)))
   (setf (column m1 2) col)
   (cl-array m1)))

(generate-all-array-tests swap-rows t
221
 (let ((m1 (array-default '(3 3))))
222
223
224
   (cl-array (swap-rows m1 0 1))))

(generate-all-array-tests swap-columns t
225
 (let ((m1 (array-default '(3 3))))
226
227
228
   (cl-array (swap-columns m1 1 2))))

(generate-all-array-tests swap-row-column t
229
 (let ((m1 (array-default '(3 3))))
230
231
   (cl-array (swap-row-column m1 0 2))))

232
(generate-all-array-tests matrix-transpose* t
233
 (let ((m1 (array-default '(3 3))))
234
   (cl-array (matrix-transpose* m1))))
235

236
(generate-all-array-tests matrix-transpose t
237
 (let ((m1 (array-default '(3 3)))
238
239
       (m2 (array-default '(3 3) t)))
   (cl-array (matrix-transpose m1 m2))))