| 1 | ;; Vectors |
|---|
| 2 | ;; Liam Healy, Sun Mar 26 2006 - 11:51 |
|---|
| 3 | ;; Time-stamp: <2008-03-09 21:45:37EDT vector.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | ;;; Vectors are specified in a letm binding with |
|---|
| 9 | ;;; (vector-double-float size-or-initial &optional zero) |
|---|
| 10 | ;;; (vector-single-float size-or-initial &optional zero) |
|---|
| 11 | ;;; (vector-fixnum size-or-initial &optional zero) |
|---|
| 12 | ;;; (vector-complex size-or-initial &optional zero) |
|---|
| 13 | ;;; where size-or-initial is a positive integer indicating the |
|---|
| 14 | ;;; size, and zero indicates that all elements should be set to zero, |
|---|
| 15 | ;;; or, size-or-initial is a sequence to which the vector |
|---|
| 16 | ;;; should be initially set. |
|---|
| 17 | |
|---|
| 18 | ;;; No mechanism for C stream input/output yet. |
|---|
| 19 | ;;; Generalize check-gsl-status to optionally signal errors, use here? |
|---|
| 20 | ;;; Functions like write-binary etc. as a single function, selecting the C fn with typecase? |
|---|
| 21 | ;;; #'subvector, #'subvector-stride cause crash, see notes 2006-03-30 |
|---|
| 22 | ;;; #'vector-complex-real, #'vector-complex-imag need structure definition |
|---|
| 23 | |
|---|
| 24 | ;;; GSL bug?: no gsl_vector_complex_add, etc. |
|---|
| 25 | |
|---|
| 26 | ;;; Need to build real vector out of view pointer. |
|---|
| 27 | |
|---|
| 28 | ;;; Need to #'cl-invalidate when (setf maref) called, see Mon Nov 26 2007. |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | ;;;;**************************************************************************** |
|---|
| 32 | ;;;; Vector structure and CL object |
|---|
| 33 | ;;;;**************************************************************************** |
|---|
| 34 | |
|---|
| 35 | #| |
|---|
| 36 | ;;FDL |
|---|
| 37 | The size is simply the number of vector elements. The range of |
|---|
| 38 | valid indices runs from 0 to size-1. The stride is the |
|---|
| 39 | step-size from one element to the next in physical memory, measured in |
|---|
| 40 | units of the appropriate datatype. The pointer data gives the |
|---|
| 41 | location of the first element of the vector in memory. The pointer |
|---|
| 42 | block stores the location of the memory block in which the vector |
|---|
| 43 | elements are located (if any). If the vector owns this block then the |
|---|
| 44 | owner field is set to one and the block will be deallocated when the |
|---|
| 45 | vector is freed. If the vector points to a block owned by another |
|---|
| 46 | object then the owner field is zero and any underlying block will not be |
|---|
| 47 | deallocated with the vector. |
|---|
| 48 | |# |
|---|
| 49 | |
|---|
| 50 | ;;; GSL-vector definition |
|---|
| 51 | (cffi:defcstruct gsl-vector-c |
|---|
| 52 | (size size) |
|---|
| 53 | (stride size) |
|---|
| 54 | (data :pointer) |
|---|
| 55 | (block :pointer) |
|---|
| 56 | (owner :int)) |
|---|
| 57 | |
|---|
| 58 | (defclass mvector (gsl-data) ()) |
|---|
| 59 | (add-data-class vector double-float vector-double-float mvector "vector") |
|---|
| 60 | (add-data-class vector single-float vector-single-float mvector "vector") |
|---|
| 61 | (add-data-class vector fixnum vector-fixnum mvector "vector") |
|---|
| 62 | (add-data-class vector complex vector-complex mvector "vector") |
|---|
| 63 | |
|---|
| 64 | ;;; Allocation, freeing, reading and writing |
|---|
| 65 | (defdata vector double-float) |
|---|
| 66 | (defdata vector single-float) |
|---|
| 67 | (defdata vector fixnum) |
|---|
| 68 | (defdata vector complex) |
|---|
| 69 | |
|---|
| 70 | (defmacro defmfun-vdsfc (&rest args) |
|---|
| 71 | "A defmfun for vectors of double, single, fixnum, complex, unsigned-fixnum." |
|---|
| 72 | (defmfun-all 'vector '(double-float single-float fixnum complex) args)) |
|---|
| 73 | |
|---|
| 74 | (defmacro defmfun-vdsf (&rest args) |
|---|
| 75 | "A defmfun for vectors of double, single, and fixnum." |
|---|
| 76 | (defmfun-all 'vector '(double-float single-float fixnum) args)) |
|---|
| 77 | |
|---|
| 78 | (defmethod gsl-array ((object mvector)) |
|---|
| 79 | (cffi:foreign-slot-value (pointer object) 'gsl-vector-c 'data)) |
|---|
| 80 | |
|---|
| 81 | (defun make-data-from-pointer (pointer &optional (class 'vector-double-float) size) |
|---|
| 82 | "Given a C pointer to a GSL data type, make the CL object." |
|---|
| 83 | (make-instance |
|---|
| 84 | class |
|---|
| 85 | :pointer pointer |
|---|
| 86 | :storage-size |
|---|
| 87 | (or size (cffi:foreign-slot-value pointer 'gsl-vector-c 'size)))) |
|---|
| 88 | |
|---|
| 89 | (export 'vector-data) |
|---|
| 90 | (defun vector-data (pointer) |
|---|
| 91 | "A pointer to the GSL array with the data contents, from the |
|---|
| 92 | sruct pointer." |
|---|
| 93 | (cffi:foreign-slot-value pointer 'gsl-vector-c 'data)) |
|---|
| 94 | |
|---|
| 95 | (defun element-size (object) |
|---|
| 96 | "The size of each element as stored in C." |
|---|
| 97 | (cffi:foreign-type-size |
|---|
| 98 | (rest (assoc (cl-elt-type object) |
|---|
| 99 | '((double . :double) (single . :float) |
|---|
| 100 | (fixnum . :int) (complex . gsl-complex)))))) |
|---|
| 101 | |
|---|
| 102 | ;;;;**************************************************************************** |
|---|
| 103 | ;;;; Getting values |
|---|
| 104 | ;;;;**************************************************************************** |
|---|
| 105 | |
|---|
| 106 | (defmfun-vdsfc maref ((vector vector) &rest indices) |
|---|
| 107 | "gsl_vector_get" |
|---|
| 108 | (((pointer vector) :pointer) ((first indices) size)) |
|---|
| 109 | :c-return :c-base-type |
|---|
| 110 | :documentation ; FDL |
|---|
| 111 | "The ith element of the vector.") |
|---|
| 112 | |
|---|
| 113 | (defmfun vref (pointer index) |
|---|
| 114 | "gsl_vector_get" |
|---|
| 115 | ((pointer :pointer) (index size)) |
|---|
| 116 | :c-return :double |
|---|
| 117 | :index nil |
|---|
| 118 | :documentation "An element of the vector of doubles, computed from the pointer.") |
|---|
| 119 | |
|---|
| 120 | (defmfun gsl-vector-ptr (vector i) |
|---|
| 121 | "gsl_vector_ptr" (((pointer vector) :pointer) (i size)) |
|---|
| 122 | :c-return :pointer |
|---|
| 123 | :documentation ; FDL |
|---|
| 124 | "The ith element of the vector as a pointer.") |
|---|
| 125 | |
|---|
| 126 | ;;;;**************************************************************************** |
|---|
| 127 | ;;;; Setting values |
|---|
| 128 | ;;;;**************************************************************************** |
|---|
| 129 | |
|---|
| 130 | (defmfun-vdsfc (setf maref) (value (vector vector) &rest indices) |
|---|
| 131 | "gsl_vector_set" |
|---|
| 132 | (((pointer vector) :pointer) ((first indices) size) (value :c-base-type)) |
|---|
| 133 | :c-return :void |
|---|
| 134 | :documentation ; FDL |
|---|
| 135 | "Set an element of the vector.") |
|---|
| 136 | |
|---|
| 137 | (defmfun (setf vref) (value pointer index) |
|---|
| 138 | "gsl_vector_set" |
|---|
| 139 | ((pointer :pointer) (index size) (value :double)) |
|---|
| 140 | :c-return :void |
|---|
| 141 | :index nil |
|---|
| 142 | :documentation ; FDL |
|---|
| 143 | "Set an element of the vector of doubles, using its pointer.") |
|---|
| 144 | |
|---|
| 145 | (defmfun-vdsfc set-all ((object vector) value) |
|---|
| 146 | "gsl_vector_set_all" |
|---|
| 147 | (((pointer object) :pointer) (value :c-base-type)) |
|---|
| 148 | :c-return :void) |
|---|
| 149 | |
|---|
| 150 | (defmfun-vdsfc set-zero ((object vector)) |
|---|
| 151 | "gsl_vector_set_zero" (((pointer object) :pointer)) |
|---|
| 152 | :c-return :void) |
|---|
| 153 | |
|---|
| 154 | (defmfun-vdsfc set-basis ((vector vector) index) |
|---|
| 155 | "gsl_vector_set_basis" (((pointer vector) gsl-vector-c) (index size)) |
|---|
| 156 | :invalidate (vector) |
|---|
| 157 | :documentation ; FDL |
|---|
| 158 | "Set the index element to 1, and the rest to 0.") |
|---|
| 159 | |
|---|
| 160 | ;;;;**************************************************************************** |
|---|
| 161 | ;;;; Views |
|---|
| 162 | ;;;;**************************************************************************** |
|---|
| 163 | |
|---|
| 164 | (cffi:defcstruct gsl-vector-view |
|---|
| 165 | (vector gsl-vector-c)) |
|---|
| 166 | |
|---|
| 167 | ;;; broken |
|---|
| 168 | ;;; (letm ((vec (vector-double-float #(-3.21d0 1.0d0 12.8d0)))) (subvector vec 1 2)) |
|---|
| 169 | |
|---|
| 170 | (export '(subvector subvector-stride)) |
|---|
| 171 | |
|---|
| 172 | (defgeneric subvector (vector offset size) |
|---|
| 173 | (:documentation ; FDL |
|---|
| 174 | "Return a vector view of a subvector of another vector |
|---|
| 175 | v. The start of the new vector is offset by offset elements |
|---|
| 176 | from the start of the original vector. The new vector has size |
|---|
| 177 | elements.")) |
|---|
| 178 | |
|---|
| 179 | (defgeneric subvector-stride (vector offset stride size) |
|---|
| 180 | (:documentation ; FDL |
|---|
| 181 | "A vector view of a subvector of another vector |
|---|
| 182 | v with an additional stride argument. The subvector is formed in |
|---|
| 183 | the same way as for #'subvector but the new vector has |
|---|
| 184 | n elements with a step-size of stride from one element to |
|---|
| 185 | the next in the original vector. Mathematically, the i-th element |
|---|
| 186 | of the new vector v' is given by |
|---|
| 187 | v'(i) = v->data[(offset + i*stride)*v->stride] |
|---|
| 188 | where the index i runs from 0 to n-1. |
|---|
| 189 | Note that subvector views give direct access to the underlying elements |
|---|
| 190 | of the original vector.")) |
|---|
| 191 | |
|---|
| 192 | (defmfun-vdsfc subvector ((vector vector) offset size) |
|---|
| 193 | "gsl_vector_subvector" |
|---|
| 194 | (((pointer vector) gsl-vector-c) (offset size) (size size)) |
|---|
| 195 | :c-return :pointer) |
|---|
| 196 | |
|---|
| 197 | (defmfun-vdsfc subvector-stride ((vector vector) offset stride size) |
|---|
| 198 | "gsl_vector_subvector_with_stride" |
|---|
| 199 | (((pointer vector) gsl-vector-c) |
|---|
| 200 | (offset size) (stride size) (size size)) |
|---|
| 201 | :c-return :pointer) |
|---|
| 202 | |
|---|
| 203 | ;;; These require that the gsl-vector-complex structure be defined. |
|---|
| 204 | #| |
|---|
| 205 | (defmfun vector-complex-real (vector) |
|---|
| 206 | "gsl_vector_complex_real" ((vector gsl-vector-complex)) |
|---|
| 207 | :c-return :pointer |
|---|
| 208 | :documentation |
|---|
| 209 | "A vector view of the real parts of the complex vector v.") |
|---|
| 210 | |
|---|
| 211 | (defmfun vector-complex-imag (vector) |
|---|
| 212 | "gsl_vector_complex_imag"((vector gsl-vector-complex)) |
|---|
| 213 | :c-return :pointer |
|---|
| 214 | :documentation |
|---|
| 215 | "A vector view of the imaginary parts of the complex vector v.") |
|---|
| 216 | |# |
|---|
| 217 | |
|---|
| 218 | (defmfun vector-array (base size) |
|---|
| 219 | "gsl_vector_view_array" ((base :pointer) (size size)) |
|---|
| 220 | :c-return :pointer |
|---|
| 221 | :documentation ; FDL |
|---|
| 222 | "A vector view of an array. The start of the new |
|---|
| 223 | vector is given by base and has n elements.") |
|---|
| 224 | |
|---|
| 225 | (defmfun vector-array-stride (base stride size) |
|---|
| 226 | "gsl_vector_view_array_with_stride" |
|---|
| 227 | ((base :pointer) (stride size) (size size)) |
|---|
| 228 | :c-return :pointer |
|---|
| 229 | :documentation ; FDL |
|---|
| 230 | "A vector view of an array with stride. The start of the new |
|---|
| 231 | vector is given by base.") |
|---|
| 232 | |
|---|
| 233 | ;;;;**************************************************************************** |
|---|
| 234 | ;;;; Copying |
|---|
| 235 | ;;;;**************************************************************************** |
|---|
| 236 | |
|---|
| 237 | (defmfun-vdsfc copy ((destination vector) (source vector)) |
|---|
| 238 | "gsl_vector_memcpy" |
|---|
| 239 | (((pointer destination) gsl-vector-c) ((pointer source) gsl-vector-c)) |
|---|
| 240 | :invalidate (destination) |
|---|
| 241 | :documentation ; FDL |
|---|
| 242 | "Copy the elements of the vector source into the |
|---|
| 243 | vector destination. The two vectors must have the same length.") |
|---|
| 244 | |
|---|
| 245 | (defmfun-vdsfc swap ((v vector) (w vector)) |
|---|
| 246 | "gsl_vector_swap" (((pointer v) gsl-vector-c) ((pointer w) gsl-vector-c)) |
|---|
| 247 | :invalidate (v w) |
|---|
| 248 | :documentation ; FDL |
|---|
| 249 | "Exchange the elements of the vectors v and w |
|---|
| 250 | by copying. The two vectors must have the same length.") |
|---|
| 251 | |
|---|
| 252 | ;;;;**************************************************************************** |
|---|
| 253 | ;;;; Exchanging elements |
|---|
| 254 | ;;;;**************************************************************************** |
|---|
| 255 | |
|---|
| 256 | (export '(swap-elements vector-reverse)) |
|---|
| 257 | |
|---|
| 258 | (defgeneric swap-elements (vec i j) |
|---|
| 259 | (:documentation ; FDL |
|---|
| 260 | "Exchange the i-th and j-th elements of the vector vec in-place.")) |
|---|
| 261 | |
|---|
| 262 | (defgeneric vector-reverse (vec) |
|---|
| 263 | (:documentation |
|---|
| 264 | "Exchange the i-th and j-th elements of the vector vec in-place.")) |
|---|
| 265 | |
|---|
| 266 | (defmfun-vdsfc swap-elements ((vec vector) i j) |
|---|
| 267 | "gsl_vector_swap_elements" (((pointer vec) gsl-vector-c) (i size) (j size)) |
|---|
| 268 | :after ((when (listp (cl-invalid vec)) |
|---|
| 269 | (push (list i) (cl-invalid vec)) |
|---|
| 270 | (push (list j) (cl-invalid vec)))) |
|---|
| 271 | :return (vec)) |
|---|
| 272 | |
|---|
| 273 | (defmfun-vdsfc vector-reverse ((vec vector)) |
|---|
| 274 | "gsl_vector_reverse" (((pointer vec) gsl-vector-c)) |
|---|
| 275 | :invalidate (vec) |
|---|
| 276 | :documentation ; FDL |
|---|
| 277 | "Reverse the order of the elements of the vector vec.") |
|---|
| 278 | |
|---|
| 279 | ;;;;**************************************************************************** |
|---|
| 280 | ;;;; Arithmetic operations |
|---|
| 281 | ;;;;**************************************************************************** |
|---|
| 282 | |
|---|
| 283 | (defmfun-vdsf m+ ((a vector) (b vector)) |
|---|
| 284 | "gsl_vector_add" (((pointer a) gsl-vector-c) ((pointer b) gsl-vector-c)) |
|---|
| 285 | :invalidate (a) |
|---|
| 286 | :documentation ; FDL |
|---|
| 287 | "Add the elements of vector b to the elements of |
|---|
| 288 | vector a, a'_i = a_i + b_i. The two vectors must have the |
|---|
| 289 | same length.") |
|---|
| 290 | |
|---|
| 291 | (defmfun-vdsf m- ((a vector) (b vector)) |
|---|
| 292 | "gsl_vector_sub" (((pointer a) gsl-vector-c) ((pointer b) gsl-vector-c)) |
|---|
| 293 | :invalidate (a) |
|---|
| 294 | :documentation ; FDL |
|---|
| 295 | "Subtract the elements of vector b from the elements of |
|---|
| 296 | vector a, a'_i = a_i - b_i. The two vectors must have the same length.") |
|---|
| 297 | |
|---|
| 298 | (defmfun-vdsf m* ((a vector) (b vector)) |
|---|
| 299 | "gsl_vector_mul" (((pointer a) gsl-vector-c) ((pointer b) gsl-vector-c)) |
|---|
| 300 | :invalidate (a) |
|---|
| 301 | :documentation ; FDL |
|---|
| 302 | "Multiply the elements of vector a by the elements of |
|---|
| 303 | vector b, a'_i = a_i * b_i. The two vectors must have the same length.") |
|---|
| 304 | |
|---|
| 305 | (defmfun-vdsf m/ ((a vector) (b vector)) |
|---|
| 306 | "gsl_vector_div" (((pointer a) gsl-vector-c) ((pointer b) gsl-vector-c)) |
|---|
| 307 | :invalidate (a) |
|---|
| 308 | :documentation ; FDL |
|---|
| 309 | "Divide the elements of vector a by the elements of |
|---|
| 310 | vector b, a'_i = a_i / b_i. The two vectors must have the same length.") |
|---|
| 311 | |
|---|
| 312 | (defmfun-vdsf m*c ((a vector) x) |
|---|
| 313 | "gsl_vector_scale" (((pointer a) gsl-vector-c) (x :double)) |
|---|
| 314 | :invalidate (a) |
|---|
| 315 | :documentation ; FDL |
|---|
| 316 | "Multiply the elements of vector a by the constant factor x, a'_i = x a_i.") |
|---|
| 317 | |
|---|
| 318 | (defmfun-vdsf m+c ((a vector) x) |
|---|
| 319 | "gsl_vector_add_constant" (((pointer a) gsl-vector-c) (x :double)) |
|---|
| 320 | :invalidate (a) |
|---|
| 321 | :documentation ; FDL |
|---|
| 322 | "Add the constant value x to the elements of the vector a, a'_i = a_i + x.") |
|---|
| 323 | |
|---|
| 324 | ;;;;**************************************************************************** |
|---|
| 325 | ;;;; Maximum and minimum elements |
|---|
| 326 | ;;;;**************************************************************************** |
|---|
| 327 | |
|---|
| 328 | (defmfun-vdsf gsl-max ((v vector)) |
|---|
| 329 | "gsl_vector_max" (((pointer v) gsl-vector-c)) |
|---|
| 330 | :c-return :c-base-type |
|---|
| 331 | :documentation ; FDL |
|---|
| 332 | "The maximum value in the vector v.") |
|---|
| 333 | |
|---|
| 334 | (defmfun-vdsf gsl-min ((v vector)) |
|---|
| 335 | "gsl_vector_min" (((pointer v) gsl-vector-c)) |
|---|
| 336 | :c-return :c-base-type |
|---|
| 337 | :documentation ; FDL |
|---|
| 338 | "The minimum value in the vector v.") |
|---|
| 339 | |
|---|
| 340 | (defmfun-vdsf gsl-minmax ((v vector)) |
|---|
| 341 | "gsl_vector_minmax" |
|---|
| 342 | (((pointer v) gsl-vector-c) (min :c-base-type) (max :c-base-type)) |
|---|
| 343 | :c-return :void |
|---|
| 344 | :documentation ; FDL |
|---|
| 345 | "The minimum and maximum values in the vector v.") |
|---|
| 346 | |
|---|
| 347 | (defmfun-vdsf gsl-max-index ((v vector)) |
|---|
| 348 | "gsl_vector_max_index" (((pointer v) gsl-vector-c)) |
|---|
| 349 | :c-return size |
|---|
| 350 | :documentation ; FDL |
|---|
| 351 | "The index of the maximum value in the vector v. |
|---|
| 352 | When there are several equal minimum elements then the lowest index is |
|---|
| 353 | returned.") |
|---|
| 354 | |
|---|
| 355 | (defmfun-vdsf gsl-min-index ((v vector)) |
|---|
| 356 | "gsl_vector_min_index" (((pointer v) gsl-vector-c)) |
|---|
| 357 | :c-return size |
|---|
| 358 | :documentation ; FDL |
|---|
| 359 | "The index of the minimum value in the vector v. When there are several |
|---|
| 360 | equal minimum elements then the lowest index is returned.") |
|---|
| 361 | |
|---|
| 362 | (defmfun-vdsf gsl-minmax-index ((v vector)) |
|---|
| 363 | "gsl_vector_minmax_index" |
|---|
| 364 | (((pointer v) gsl-vector-c) (imin size) (imax size)) |
|---|
| 365 | :c-return :void |
|---|
| 366 | :documentation ; FDL |
|---|
| 367 | "The indices of the minimum and maximum values in the vector v. |
|---|
| 368 | When there are several equal minimum elements then the lowest index is |
|---|
| 369 | returned.") |
|---|
| 370 | |
|---|
| 371 | ;;;;**************************************************************************** |
|---|
| 372 | ;;;; Properties |
|---|
| 373 | ;;;;**************************************************************************** |
|---|
| 374 | |
|---|
| 375 | (defmfun-vdsfc gsl-zerop ((v vector)) |
|---|
| 376 | "gsl_vector_isnull" (((pointer v) gsl-vector-c)) |
|---|
| 377 | :c-return :boolean |
|---|
| 378 | :documentation ; FDL |
|---|
| 379 | "All elements of vector v are zero.") |
|---|
| 380 | |
|---|
| 381 | ;;;;**************************************************************************** |
|---|
| 382 | ;;;; Examples and unit tests |
|---|
| 383 | ;;;;**************************************************************************** |
|---|
| 384 | |
|---|
| 385 | #| |
|---|
| 386 | (make-tests |
|---|
| 387 | vector-fixnum |
|---|
| 388 | (letm ((intvec (vector-fixnum 4))) ;(setf maref), maref |
|---|
| 389 | (setf (maref intvec 1) 77) |
|---|
| 390 | (maref intvec 1)) |
|---|
| 391 | (letm ((intvec (vector-fixnum 4))) ;(setf data) |
|---|
| 392 | (setf (data intvec) #(4 6 8 2)) |
|---|
| 393 | (data intvec)) |
|---|
| 394 | (letm ((intvec (vector-fixnum 4))) ;set-zero |
|---|
| 395 | (set-zero intvec) |
|---|
| 396 | (data intvec)) |
|---|
| 397 | (letm ((intvec (vector-fixnum 4))) ;set-all |
|---|
| 398 | (set-all intvec 44) |
|---|
| 399 | (data intvec)) |
|---|
| 400 | (letm ((intvec (vector-fixnum 4))) ;set-basis |
|---|
| 401 | (set-basis intvec 1) |
|---|
| 402 | (data intvec)) |
|---|
| 403 | (letm ((intvec (vector-fixnum #(1 2 3 4)))) ;vector-reverse |
|---|
| 404 | (vector-reverse intvec) |
|---|
| 405 | (data intvec)) |
|---|
| 406 | (letm ((intvec (vector-fixnum #(-1 -12 8 3)))) ;gsl-min |
|---|
| 407 | (gsl-min intvec)) |
|---|
| 408 | (letm ((intvec (vector-fixnum #(-1 -12 8 3)))) ;gsl-max |
|---|
| 409 | (gsl-max intvec)) |
|---|
| 410 | (letm ((intvec (vector-fixnum #(-1 -12 8 3)))) ;gsl-minmax |
|---|
| 411 | (multiple-value-list (gsl-minmax intvec))) |
|---|
| 412 | (letm ((intvec (vector-fixnum #(-1 -12 8 3)))) ;gsl-min-index |
|---|
| 413 | (gsl-min-index intvec)) |
|---|
| 414 | (letm ((intvec (vector-fixnum #(-1 -12 8 3)))) ;gsl-max-index |
|---|
| 415 | (gsl-max-index intvec)) |
|---|
| 416 | (letm ((intvec (vector-fixnum #(-1 -12 8 3)))) ;gsl-minmax-index |
|---|
| 417 | (multiple-value-list (gsl-minmax-index intvec))) |
|---|
| 418 | (letm ((intvec1 (vector-fixnum #(1 2 3 4))) ;copy |
|---|
| 419 | (intvec2 (vector-fixnum 4))) |
|---|
| 420 | (copy intvec2 intvec1) |
|---|
| 421 | (data intvec2)) |
|---|
| 422 | (letm ((intvec1 (vector-fixnum #(1 2 3 4))) ;swap |
|---|
| 423 | (intvec2 (vector-fixnum #(5 6 7 8)))) |
|---|
| 424 | (swap intvec2 intvec1) |
|---|
| 425 | (concatenate 'vector (data intvec1) (data intvec2))) |
|---|
| 426 | (letm ((intvec (vector-fixnum #(1 2 3 4)))) ;swap-elements |
|---|
| 427 | (swap-elements intvec 1 3) |
|---|
| 428 | (data intvec))) |
|---|
| 429 | |# |
|---|
| 430 | |
|---|
| 431 | (LISP-UNIT:DEFINE-TEST VECTOR-FIXNUM |
|---|
| 432 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 433 | (LIST 77) |
|---|
| 434 | (MULTIPLE-VALUE-LIST |
|---|
| 435 | (LETM ((INTVEC (VECTOR-FIXNUM 4))) |
|---|
| 436 | (SETF (MAREF INTVEC 1) 77) |
|---|
| 437 | (MAREF INTVEC 1)))) |
|---|
| 438 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 439 | (LIST #(4 6 8 2)) |
|---|
| 440 | (MULTIPLE-VALUE-LIST |
|---|
| 441 | (LETM ((INTVEC (VECTOR-FIXNUM 4))) |
|---|
| 442 | (SETF (DATA INTVEC) #(4 6 8 2)) |
|---|
| 443 | (DATA INTVEC)))) |
|---|
| 444 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 445 | (LIST #(0 0 0 0)) |
|---|
| 446 | (MULTIPLE-VALUE-LIST |
|---|
| 447 | (LETM ((INTVEC (VECTOR-FIXNUM 4))) |
|---|
| 448 | (SET-ZERO INTVEC) |
|---|
| 449 | (DATA INTVEC)))) |
|---|
| 450 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 451 | (LIST #(44 44 44 44)) |
|---|
| 452 | (MULTIPLE-VALUE-LIST |
|---|
| 453 | (LETM ((INTVEC (VECTOR-FIXNUM 4))) |
|---|
| 454 | (SET-ALL INTVEC 44) |
|---|
| 455 | (DATA INTVEC)))) |
|---|
| 456 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 457 | (LIST #(0 1 0 0)) |
|---|
| 458 | (MULTIPLE-VALUE-LIST |
|---|
| 459 | (LETM ((INTVEC (VECTOR-FIXNUM 4))) |
|---|
| 460 | (SET-BASIS INTVEC 1) |
|---|
| 461 | (DATA INTVEC)))) |
|---|
| 462 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 463 | (LIST #(4 3 2 1)) |
|---|
| 464 | (MULTIPLE-VALUE-LIST |
|---|
| 465 | (LETM ((INTVEC (VECTOR-FIXNUM #(1 2 3 4)))) |
|---|
| 466 | (VECTOR-REVERSE INTVEC) |
|---|
| 467 | (DATA INTVEC)))) |
|---|
| 468 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 469 | (LIST -12) |
|---|
| 470 | (MULTIPLE-VALUE-LIST |
|---|
| 471 | (LETM ((INTVEC (VECTOR-FIXNUM #(-1 -12 8 3)))) |
|---|
| 472 | (GSL-MIN INTVEC)))) |
|---|
| 473 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 474 | (LIST 8) |
|---|
| 475 | (MULTIPLE-VALUE-LIST |
|---|
| 476 | (LETM ((INTVEC (VECTOR-FIXNUM #(-1 -12 8 3)))) |
|---|
| 477 | (GSL-MAX INTVEC)))) |
|---|
| 478 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 479 | (LIST (LIST -12 8)) |
|---|
| 480 | (MULTIPLE-VALUE-LIST |
|---|
| 481 | (LETM ((INTVEC (VECTOR-FIXNUM #(-1 -12 8 3)))) |
|---|
| 482 | (MULTIPLE-VALUE-LIST |
|---|
| 483 | (GSL-MINMAX INTVEC))))) |
|---|
| 484 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 485 | (LIST 1) |
|---|
| 486 | (MULTIPLE-VALUE-LIST |
|---|
| 487 | (LETM ((INTVEC (VECTOR-FIXNUM #(-1 -12 8 3)))) |
|---|
| 488 | (GSL-MIN-INDEX INTVEC)))) |
|---|
| 489 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 490 | (LIST 2) |
|---|
| 491 | (MULTIPLE-VALUE-LIST |
|---|
| 492 | (LETM |
|---|
| 493 | ((INTVEC (VECTOR-FIXNUM #(-1 -12 8 3)))) |
|---|
| 494 | (GSL-MAX-INDEX INTVEC)))) |
|---|
| 495 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 496 | (LIST (LIST 1 2)) |
|---|
| 497 | (MULTIPLE-VALUE-LIST |
|---|
| 498 | (LETM ((INTVEC (VECTOR-FIXNUM #(-1 -12 8 3)))) |
|---|
| 499 | (MULTIPLE-VALUE-LIST |
|---|
| 500 | (GSL-MINMAX-INDEX INTVEC))))) |
|---|
| 501 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 502 | (LIST #(1 2 3 4)) |
|---|
| 503 | (MULTIPLE-VALUE-LIST |
|---|
| 504 | (LETM ((INTVEC1 (VECTOR-FIXNUM #(1 2 3 4))) |
|---|
| 505 | (INTVEC2 (VECTOR-FIXNUM 4))) |
|---|
| 506 | (COPY INTVEC2 INTVEC1) |
|---|
| 507 | (DATA INTVEC2)))) |
|---|
| 508 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 509 | (LIST #(5 6 7 8 1 2 3 4)) |
|---|
| 510 | (MULTIPLE-VALUE-LIST |
|---|
| 511 | (LETM ((INTVEC1 (VECTOR-FIXNUM #(1 2 3 4))) |
|---|
| 512 | (INTVEC2 (VECTOR-FIXNUM #(5 6 7 8)))) |
|---|
| 513 | (SWAP INTVEC2 INTVEC1) |
|---|
| 514 | (CONCATENATE 'VECTOR (DATA INTVEC1) (DATA INTVEC2))))) |
|---|
| 515 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 516 | (LIST #(1 4 3 2)) |
|---|
| 517 | (MULTIPLE-VALUE-LIST |
|---|
| 518 | (LETM ((INTVEC (VECTOR-FIXNUM #(1 2 3 4)))) |
|---|
| 519 | (SWAP-ELEMENTS INTVEC 1 3) |
|---|
| 520 | (DATA INTVEC))))) |
|---|
| 521 | |
|---|
| 522 | #| |
|---|
| 523 | (make-tests |
|---|
| 524 | vector-double |
|---|
| 525 | (letm ((vec (vector-double-float 3))) |
|---|
| 526 | (setf (maref vec 0) -3.21d0 |
|---|
| 527 | (maref vec 1) 1.0d0 |
|---|
| 528 | (maref vec 2) 12.8d0 |
|---|
| 529 | (cl-invalid vec) t) |
|---|
| 530 | (data vec)) |
|---|
| 531 | (letm ((vec (vector-double-float 3))) |
|---|
| 532 | (setf (data vec) #(-3.21d0 1.0d0 12.8d0)) |
|---|
| 533 | (data vec)) |
|---|
| 534 | (letm ((vec (vector-double-float #(-3.21d0 1.0d0 12.8d0)))) |
|---|
| 535 | (data vec)) |
|---|
| 536 | (letm ((base (vector-double-float 5))) |
|---|
| 537 | (set-basis base 1) |
|---|
| 538 | (data base)) |
|---|
| 539 | (letm ((vec1 (vector-double-float #(-3.21d0 1.0d0 12.8d0))) |
|---|
| 540 | (vec2 (vector-double-float 3))) |
|---|
| 541 | (copy vec2 vec1) |
|---|
| 542 | (data vec2))) |
|---|
| 543 | |# |
|---|
| 544 | |
|---|
| 545 | (LISP-UNIT:DEFINE-TEST VECTOR-DOUBLE-FLOAT |
|---|
| 546 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 547 | (LIST #(-3.21d0 1.0d0 12.8d0)) |
|---|
| 548 | (MULTIPLE-VALUE-LIST |
|---|
| 549 | (LETM ((VEC (VECTOR-DOUBLE-FLOAT 3))) |
|---|
| 550 | (SETF (MAREF VEC 0) -3.21d0 |
|---|
| 551 | (MAREF VEC 1) 1.0d0 |
|---|
| 552 | (MAREF VEC 2) 12.8d0 |
|---|
| 553 | (CL-INVALID VEC) T) |
|---|
| 554 | (DATA VEC)))) |
|---|
| 555 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 556 | (LIST #(-3.21d0 1.0d0 12.8d0)) |
|---|
| 557 | (MULTIPLE-VALUE-LIST |
|---|
| 558 | (LETM ((VEC (VECTOR-DOUBLE-FLOAT 3))) |
|---|
| 559 | (SETF (DATA VEC) #(-3.21d0 1.0d0 12.8d0)) |
|---|
| 560 | (DATA VEC)))) |
|---|
| 561 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 562 | (LIST #(-3.21d0 1.0d0 12.8d0)) |
|---|
| 563 | (MULTIPLE-VALUE-LIST |
|---|
| 564 | (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(-3.21d0 1.0d0 12.8d0)))) |
|---|
| 565 | (DATA VEC)))) |
|---|
| 566 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 567 | (LIST #(0.0d0 1.0d0 0.0d0 0.0d0 0.0d0)) |
|---|
| 568 | (MULTIPLE-VALUE-LIST |
|---|
| 569 | (LETM ((BASE (VECTOR-DOUBLE-FLOAT 5))) (SET-BASIS BASE 1) |
|---|
| 570 | (DATA BASE)))) |
|---|
| 571 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 572 | (LIST #(-3.21d0 1.0d0 12.8d0)) |
|---|
| 573 | (MULTIPLE-VALUE-LIST |
|---|
| 574 | (LETM |
|---|
| 575 | ((VEC1 (VECTOR-DOUBLE-FLOAT #(-3.21d0 1.0d0 12.8d0))) |
|---|
| 576 | (VEC2 (VECTOR-DOUBLE-FLOAT 3))) |
|---|
| 577 | (COPY VEC2 VEC1) (DATA VEC2))))) |
|---|