| 1 | ;; Matrices |
|---|
| 2 | ;; Liam Healy, Sun Mar 26 2006 - 11:51 |
|---|
| 3 | ;; Time-stamp: <2008-03-18 21:16:41EDT matrix.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | ;;; Matrices are specified in a letm binding with |
|---|
| 9 | ;;; (matrix-double-float size-or-initial &optional zero) |
|---|
| 10 | ;;; (matrix-single-float size-or-initial &optional zero) |
|---|
| 11 | ;;; (matrix-fixnum size-or-initial &optional zero) |
|---|
| 12 | ;;; (matrix-complex size-or-initial &optional zero) |
|---|
| 13 | ;;; where size-or-initial is a length-2 list of positive integers |
|---|
| 14 | ;;; indicating the dimensions, and zero indicates that all elements should |
|---|
| 15 | ;;; be set to zero, or, size-or-initial is a 2D array to which the |
|---|
| 16 | ;;; vector should be initially set. |
|---|
| 17 | |
|---|
| 18 | ;;;;**************************************************************************** |
|---|
| 19 | ;;;; Matrix object definition, allocation, reading & writing |
|---|
| 20 | ;;;;**************************************************************************** |
|---|
| 21 | |
|---|
| 22 | ;;; GSL-matrix definition |
|---|
| 23 | (cffi:defcstruct gsl-matrix-c |
|---|
| 24 | (size1 size) |
|---|
| 25 | (size2 size) |
|---|
| 26 | (tda size) |
|---|
| 27 | (data :pointer) |
|---|
| 28 | (block :pointer) |
|---|
| 29 | (owner :int)) |
|---|
| 30 | |
|---|
| 31 | (defclass matrix (gsl-data) ()) |
|---|
| 32 | (add-data-class matrix double-float matrix-double-float matrix "matrix") |
|---|
| 33 | (add-data-class matrix single-float matrix-single-float matrix "matrix") |
|---|
| 34 | (add-data-class matrix fixnum matrix-fixnum matrix "matrix") |
|---|
| 35 | (add-data-class matrix complex matrix-complex matrix "matrix") |
|---|
| 36 | |
|---|
| 37 | (defdata matrix double-float 2) |
|---|
| 38 | (defdata matrix single-float 2) |
|---|
| 39 | (defdata matrix fixnum 2) |
|---|
| 40 | (defdata matrix complex 2) |
|---|
| 41 | |
|---|
| 42 | (defmacro defmfun-mdsfc (&rest args) |
|---|
| 43 | "A defmfun for matrices of double, single, fixnum, and complex." |
|---|
| 44 | (defmfun-all '(matrix vector) '(double-float single-float fixnum complex) args)) |
|---|
| 45 | |
|---|
| 46 | (defmacro defmfun-mdsf (&rest args) |
|---|
| 47 | "A defmfun for matrices of double, single, and fixnum." |
|---|
| 48 | (defmfun-all '(matrix vector) '(double-float single-float fixnum) args)) |
|---|
| 49 | |
|---|
| 50 | (defmethod gsl-array ((object matrix)) |
|---|
| 51 | (foreign-slot-value (pointer object) 'gsl-matrix-c 'data)) |
|---|
| 52 | |
|---|
| 53 | (export 'matrix-data) |
|---|
| 54 | (defun matrix-data (pointer) |
|---|
| 55 | "A pointer to the GSL array with the data contents, from the |
|---|
| 56 | sruct pointer." |
|---|
| 57 | (cffi:foreign-slot-value pointer 'gsl-matrix-c 'data)) |
|---|
| 58 | |
|---|
| 59 | ;;;;**************************************************************************** |
|---|
| 60 | ;;;; Getting values |
|---|
| 61 | ;;;;**************************************************************************** |
|---|
| 62 | |
|---|
| 63 | (defmfun-mdsfc maref ((matrix matrix) &rest indices) |
|---|
| 64 | "gsl_matrix_get" |
|---|
| 65 | (((pointer matrix) :pointer) |
|---|
| 66 | ((first indices) size) |
|---|
| 67 | ((second indices) size)) |
|---|
| 68 | :c-return :c-base-type |
|---|
| 69 | :documentation ; FDL |
|---|
| 70 | "The (i,j)-th element of the matrix.") |
|---|
| 71 | |
|---|
| 72 | (defmfun mref (pointer index0 index1) |
|---|
| 73 | "gsl_matrix_get" |
|---|
| 74 | ((pointer :pointer) (index0 size) (index1 size)) |
|---|
| 75 | :c-return :double |
|---|
| 76 | :index nil |
|---|
| 77 | :documentation ; FDL |
|---|
| 78 | "An element of the matrix of doubles, computed from the pointer.") |
|---|
| 79 | |
|---|
| 80 | (export 'gsl-matrix-ptr) |
|---|
| 81 | (defgeneric gsl-matrix-ptr (matrix i j) |
|---|
| 82 | (:documentation |
|---|
| 83 | "A pointer to the i,j-th element of a matrix.")) |
|---|
| 84 | |
|---|
| 85 | (defmfun-mdsfc gsl-matrix-ptr ((matrix matrix) i j) |
|---|
| 86 | "gsl_matrix_ptr" (((pointer matrix) :pointer) (i size) (j size)) |
|---|
| 87 | :c-return :pointer) |
|---|
| 88 | |
|---|
| 89 | (defmethod data ((object matrix) &optional array) |
|---|
| 90 | (let ((arr (or array |
|---|
| 91 | (make-array (storage-size object) |
|---|
| 92 | :element-type (cl-elt-type object))))) |
|---|
| 93 | (loop for i from 0 |
|---|
| 94 | below (min (array-dimension arr 0) (first (storage-size object))) |
|---|
| 95 | do |
|---|
| 96 | (loop for j from 0 |
|---|
| 97 | below |
|---|
| 98 | (min (array-dimension arr 1) (second (storage-size object))) |
|---|
| 99 | do |
|---|
| 100 | (setf (aref arr i j) (maref object i j)))) |
|---|
| 101 | arr)) |
|---|
| 102 | |
|---|
| 103 | ;;;;**************************************************************************** |
|---|
| 104 | ;;;; Setting values |
|---|
| 105 | ;;;;**************************************************************************** |
|---|
| 106 | |
|---|
| 107 | (defmfun-mdsfc (setf maref) (value (matrix matrix) &rest indices) |
|---|
| 108 | "gsl_matrix_set" |
|---|
| 109 | (((pointer matrix) :pointer) |
|---|
| 110 | ((first indices) size) |
|---|
| 111 | ((second indices) size) |
|---|
| 112 | (value :c-base-type)) |
|---|
| 113 | :c-return :void |
|---|
| 114 | :documentation ; FDL |
|---|
| 115 | "Set the (i,j)-th element of the matrix.") |
|---|
| 116 | |
|---|
| 117 | (defmfun (setf mref) (value pointer index0 index1) |
|---|
| 118 | "gsl_matrix_set" |
|---|
| 119 | ((pointer :pointer) (index0 size) (index1 size) (value :double)) |
|---|
| 120 | :c-return :void |
|---|
| 121 | :index nil |
|---|
| 122 | :documentation ; FDL |
|---|
| 123 | "Set an element of the matrix of doubles, using its pointer.") |
|---|
| 124 | |
|---|
| 125 | (defmethod (setf data) (array (object matrix)) |
|---|
| 126 | (loop for i from 0 |
|---|
| 127 | below |
|---|
| 128 | (min (array-dimension array 0) (first (storage-size object))) |
|---|
| 129 | do |
|---|
| 130 | (loop for j from 0 |
|---|
| 131 | below |
|---|
| 132 | (min (array-dimension array 1) (second (storage-size object))) |
|---|
| 133 | do |
|---|
| 134 | (setf (maref object i j) (aref array i j))))) |
|---|
| 135 | |
|---|
| 136 | (defmfun-mdsfc set-all ((object matrix) value) |
|---|
| 137 | "gsl_matrix_set_all" |
|---|
| 138 | (((pointer object) :pointer) (value :c-base-type)) |
|---|
| 139 | :c-return :void) |
|---|
| 140 | |
|---|
| 141 | (defmfun-mdsfc set-zero ((object matrix)) |
|---|
| 142 | "gsl_matrix_set_zero" |
|---|
| 143 | (((pointer object) :pointer)) |
|---|
| 144 | :c-return :void) |
|---|
| 145 | |
|---|
| 146 | (defmfun-mdsfc set-identity ((matrix matrix)) |
|---|
| 147 | "gsl_matrix_set_identity" (((pointer matrix) gsl-matrix-c)) |
|---|
| 148 | :c-return :void |
|---|
| 149 | :documentation ; FDL |
|---|
| 150 | "Set the elements of the matrix m to the |
|---|
| 151 | corresponding elements of the identity matrix, m(i,j) = |
|---|
| 152 | \delta(i,j), i.e. a unit diagonal with all off-diagonal elements zero. |
|---|
| 153 | This applies to both square and rectangular matrices.") |
|---|
| 154 | |
|---|
| 155 | ;;;;**************************************************************************** |
|---|
| 156 | ;;;; Matrix Views |
|---|
| 157 | ;;;;**************************************************************************** |
|---|
| 158 | |
|---|
| 159 | (cffi:defcstruct gsl-matrix-view |
|---|
| 160 | (matrix gsl-matrix-c)) |
|---|
| 161 | |
|---|
| 162 | (export 'submatrix) |
|---|
| 163 | (defgeneric submatrix (matrix k1 k2 n1 n2) |
|---|
| 164 | (:documentation ; FDL |
|---|
| 165 | "A matrix view of a submatrix of the matrix. |
|---|
| 166 | The upper-left element of the submatrix is the element |
|---|
| 167 | (k1, k2) of the original matrix. The submatrix has n1 |
|---|
| 168 | rows and n2 columns. The physical number of columns in memory |
|---|
| 169 | is unchanged.")) |
|---|
| 170 | |
|---|
| 171 | (defmfun-mdsfc submatrix ((matrix matrix) k1 k2 n1 n2) |
|---|
| 172 | "gsl_matrix_submatrix" |
|---|
| 173 | (((pointer matrix) gsl-matrix-c) (k1 size) (k2 size) (n1 size) (n2 size)) |
|---|
| 174 | :c-return gsl-matrix-view) |
|---|
| 175 | |
|---|
| 176 | (export 'matrix-array) |
|---|
| 177 | (defgeneric matrix-array (matrix n1 n2) |
|---|
| 178 | (:documentation ; FDL |
|---|
| 179 | "A matrix view of the array. The |
|---|
| 180 | matrix has n1 rows and n2 columns. The physical number of |
|---|
| 181 | columns in memory is also given by n2.")) |
|---|
| 182 | |
|---|
| 183 | (defmfun-mdsfc matrix-array ((matrix matrix) n1 n2) |
|---|
| 184 | "gsl_matrix_view_array" |
|---|
| 185 | (((pointer matrix) gsl-matrix-c) (n1 size) (n2 size)) |
|---|
| 186 | :c-return gsl-matrix-view) |
|---|
| 187 | |
|---|
| 188 | (export 'matrix-array-tda) |
|---|
| 189 | (defgeneric matrix-array-tda (matrix i j tda) |
|---|
| 190 | (:documentation ; FDL |
|---|
| 191 | "A matrix view of the array with a |
|---|
| 192 | physical number of columns tda which may differ from the corresponding |
|---|
| 193 | dimension of the matrix. The matrix has n1 rows and n2 |
|---|
| 194 | columns, and the physical number of columns in memory is given by |
|---|
| 195 | tda.")) |
|---|
| 196 | |
|---|
| 197 | (defmfun-mdsfc matrix-array-tda ((matrix matrix) n1 n2 tda) |
|---|
| 198 | "gsl_matrix_view_array_with_tda" |
|---|
| 199 | (((pointer matrix) gsl-matrix-c) (n1 size) (n2 size) (tda size)) |
|---|
| 200 | :c-return gsl-matrix-view) |
|---|
| 201 | |
|---|
| 202 | (defmacro defmfun-mvdsfc (&rest args) |
|---|
| 203 | "A defmfun for vectors of double, single, fixnum, and complex, |
|---|
| 204 | translating to a GSL function named matrix_*." |
|---|
| 205 | (defmfun-all |
|---|
| 206 | 'vector '(double-float single-float fixnum complex) args |
|---|
| 207 | "matrix")) |
|---|
| 208 | |
|---|
| 209 | (export 'matrix-vector) |
|---|
| 210 | (defgeneric matrix-vector (vector n1 n2) |
|---|
| 211 | (:documentation ; FDL |
|---|
| 212 | "A matrix view of the vector. The matrix |
|---|
| 213 | has n1 rows and n2 columns. The vector must have unit |
|---|
| 214 | stride. The physical number of columns in memory is also given by |
|---|
| 215 | n2. Mathematically, the (i,j)-th element of the new |
|---|
| 216 | matrix is given by m'(i,j) = v->data[i*n2 + j] |
|---|
| 217 | where the index i runs from 0 to n1-1 and the index j |
|---|
| 218 | runs from 0 to n2-1. |
|---|
| 219 | The new matrix is only a view of the vector. When the view |
|---|
| 220 | goes out of scope the original vector will continue to exist. |
|---|
| 221 | The original memory can only be deallocated by freeing the original |
|---|
| 222 | vector. Of course, the original vector should not be deallocated while |
|---|
| 223 | the view is still in use.")) |
|---|
| 224 | |
|---|
| 225 | (defmfun-mvdsfc matrix-vector ((v vector) n1 n2) |
|---|
| 226 | "gsl_matrix_view_vector" |
|---|
| 227 | (((pointer v) gsl-vector-c) (n1 size) (n2 size)) |
|---|
| 228 | :c-return gsl-matrix-view) |
|---|
| 229 | |
|---|
| 230 | (export 'matrix-vector-tda) |
|---|
| 231 | (defgeneric matrix-vector-tda (vector n1 n2 tda) |
|---|
| 232 | (:documentation ; FDL |
|---|
| 233 | "A matrix view of the vector with a |
|---|
| 234 | physical number of columns tda which may differ from the |
|---|
| 235 | corresponding matrix dimension. The vector must have unit stride. The |
|---|
| 236 | matrix has n1 rows and n2 columns, and the physical number |
|---|
| 237 | of columns in memory is given by tda. Mathematically, the |
|---|
| 238 | (i,j)-th element of the new matrix is given by |
|---|
| 239 | m'(i,j) = v->data[i*tda + j] |
|---|
| 240 | where the index i runs from 0 to n1-1 and the index j |
|---|
| 241 | runs from 0 to n2-1. |
|---|
| 242 | The new matrix is only a view of the vector. When the view |
|---|
| 243 | goes out of scope the original vector will continue to exist. |
|---|
| 244 | The original memory can only be deallocated by freeing the original |
|---|
| 245 | vector. Of course, the original vector should not be deallocated while |
|---|
| 246 | the view is still in use.")) |
|---|
| 247 | |
|---|
| 248 | (defmfun-mvdsfc matrix-vector-tda ((v vector) n1 n2 tda) |
|---|
| 249 | "gsl_matrix_view_vector_with_tda" |
|---|
| 250 | (((pointer v) gsl-vector-c) (n1 size) (n2 size) (tda size)) |
|---|
| 251 | :c-return gsl-matrix-view) |
|---|
| 252 | |
|---|
| 253 | ;;;;**************************************************************************** |
|---|
| 254 | ;;;; Row and Column Views |
|---|
| 255 | ;;;;**************************************************************************** |
|---|
| 256 | |
|---|
| 257 | (export 'row-view) |
|---|
| 258 | (defgeneric row-view (matrix i) |
|---|
| 259 | (:documentation ; FDL |
|---|
| 260 | "A vector view of the ith row of the matrix.")) |
|---|
| 261 | |
|---|
| 262 | (defmfun-mdsfc row-view ((matrix matrix) i) |
|---|
| 263 | "gsl_matrix_row" (((pointer matrix) gsl-matrix-c) (i size)) |
|---|
| 264 | :c-return gsl-vector-view |
|---|
| 265 | :null-pointer-info (:EFAULT (format nil "index ~d out of range" i))) |
|---|
| 266 | |
|---|
| 267 | (export 'column-view) |
|---|
| 268 | (defgeneric column-view (matrix j) |
|---|
| 269 | (:documentation ; FDL |
|---|
| 270 | "A vector view of the jth column of the matrix.")) |
|---|
| 271 | |
|---|
| 272 | (defmfun-mdsfc column-view ((matrix matrix) j) |
|---|
| 273 | "gsl_matrix_column" ((matrix gsl-matrix-c) (j size)) |
|---|
| 274 | :c-return gsl-matrix-view |
|---|
| 275 | :null-pointer-info (:EFAULT (format nil "index ~d out of range" j))) |
|---|
| 276 | |
|---|
| 277 | (export 'diagonal-view) |
|---|
| 278 | (defgeneric diagonal-view (matrix) |
|---|
| 279 | (:documentation ; FDL |
|---|
| 280 | "A vector view of the diagonal of the matrix. |
|---|
| 281 | The matrix is not required to be square. |
|---|
| 282 | For a rectangular matrix the length of the diagonal is the same as the smaller |
|---|
| 283 | dimension of the matrix.")) |
|---|
| 284 | |
|---|
| 285 | (defmfun-mdsfc diagonal-view ((matrix matrix)) |
|---|
| 286 | "gsl_matrix_diagonal" ((matrix gsl-matrix-c)) |
|---|
| 287 | :c-return gsl-matrix-view) |
|---|
| 288 | |
|---|
| 289 | (export 'subdiagonal-view) |
|---|
| 290 | (defgeneric subdiagonal-view (matrix k) |
|---|
| 291 | (:documentation ; FDL |
|---|
| 292 | "A vector view of the kth subdiagonal of the matrix; it is not |
|---|
| 293 | required to be square. The diagonal of the matrix corresponds to |
|---|
| 294 | k = 0.")) |
|---|
| 295 | |
|---|
| 296 | (defmfun-mdsfc subdiagonal-view ((matrix matrix) k) |
|---|
| 297 | "gsl_matrix_subdiagonal" ((matrix gsl-matrix-c) (k size)) |
|---|
| 298 | :c-return gsl-matrix-view) |
|---|
| 299 | |
|---|
| 300 | (export 'superdiagonal-view) |
|---|
| 301 | (defgeneric superdiagonal-view (matrix k) |
|---|
| 302 | (:documentation ; FDL |
|---|
| 303 | "A vector view of the kth superdiagonal of the matrix; it is not |
|---|
| 304 | required to be square. The diagonal of the matrix corresponds to k = 0.")) |
|---|
| 305 | |
|---|
| 306 | (defmfun-mdsfc superdiagonal-view ((matrix matrix) k) |
|---|
| 307 | "gsl_matrix_superdiagonal" |
|---|
| 308 | ((matrix gsl-matrix-c) (k size)) |
|---|
| 309 | :c-return gsl-matrix-view) |
|---|
| 310 | |
|---|
| 311 | ;;;;**************************************************************************** |
|---|
| 312 | ;;;; Copying |
|---|
| 313 | ;;;;**************************************************************************** |
|---|
| 314 | |
|---|
| 315 | (defmfun-mdsfc copy ((destination matrix) (source matrix)) |
|---|
| 316 | "gsl_matrix_memcpy" |
|---|
| 317 | (((pointer destination) gsl-matrix-c) ((pointer source) gsl-matrix-c)) |
|---|
| 318 | :invalidate (destination) |
|---|
| 319 | :documentation ; FDL |
|---|
| 320 | "Copy the elements of the matrix source into the |
|---|
| 321 | matrix destination. The two matrices must have the same size.") |
|---|
| 322 | |
|---|
| 323 | (defmfun-mdsfc swap ((m1 matrix) (m2 matrix)) |
|---|
| 324 | "gsl_matrix_swap" |
|---|
| 325 | (((pointer m1) gsl-matrix-c) ((pointer m2) gsl-matrix-c)) |
|---|
| 326 | :invalidate (m1 m2) |
|---|
| 327 | :documentation ; FDL |
|---|
| 328 | "Exchange the elements of the matrices m1 and |
|---|
| 329 | m2 by copying. The two matrices must have the same size.") |
|---|
| 330 | |
|---|
| 331 | ;;;;**************************************************************************** |
|---|
| 332 | ;;;; Copying rows and columns |
|---|
| 333 | ;;;;**************************************************************************** |
|---|
| 334 | |
|---|
| 335 | (export 'row) |
|---|
| 336 | (defgeneric row (vector matrix i) |
|---|
| 337 | (:documentation ; FDL |
|---|
| 338 | "Copy the elements of the ith row of the matrix |
|---|
| 339 | into the vector. The length of the vector must be the |
|---|
| 340 | same as the length of the row.")) |
|---|
| 341 | |
|---|
| 342 | (defmfun-mdsfc row ((vector vector) (matrix matrix) i) |
|---|
| 343 | "gsl_matrix_get_row" |
|---|
| 344 | (((pointer vector) gsl-vector-c) ((pointer matrix) gsl-matrix-c) (i size)) |
|---|
| 345 | :invalidate (vector)) |
|---|
| 346 | |
|---|
| 347 | (export 'column) |
|---|
| 348 | (defgeneric column (vector matrix j) |
|---|
| 349 | (:documentation ; FDL |
|---|
| 350 | "Copy the elements of the jth column of the matrix |
|---|
| 351 | into the vector. The length of the vector must be the |
|---|
| 352 | same as the length of the column.")) |
|---|
| 353 | |
|---|
| 354 | (defmfun-mdsfc column ((vector vector) (matrix matrix) j) |
|---|
| 355 | "gsl_matrix_get_col" |
|---|
| 356 | (((pointer vector) gsl-vector-c) ((pointer matrix) gsl-matrix-c) (j size)) |
|---|
| 357 | :invalidate (vector)) |
|---|
| 358 | |
|---|
| 359 | (export 'set-row) |
|---|
| 360 | (defgeneric set-row (vector matrix i) |
|---|
| 361 | (:documentation ; FDL |
|---|
| 362 | "Copy the elements of the vector into the |
|---|
| 363 | ith row of the matrix. The length of the vector must be |
|---|
| 364 | the same as the length of the row.")) |
|---|
| 365 | |
|---|
| 366 | (defmfun-mdsfc set-row ((matrix matrix) i (vector vector)) |
|---|
| 367 | "gsl_matrix_set_row" |
|---|
| 368 | (((pointer matrix) gsl-matrix-c) (i size) ((pointer vector) gsl-vector-c)) |
|---|
| 369 | :invalidate (matrix)) |
|---|
| 370 | |
|---|
| 371 | (export 'set-column) |
|---|
| 372 | (defgeneric set-column (vector matrix j) |
|---|
| 373 | (:documentation ; FDL |
|---|
| 374 | "Copy the elements of the vector into the jth column of the matrix. |
|---|
| 375 | The length of the vector must be the same as the length of the column.")) |
|---|
| 376 | |
|---|
| 377 | (defmfun-mdsfc set-column ((matrix matrix) j (vector vector)) |
|---|
| 378 | "gsl_matrix_set_col" |
|---|
| 379 | (((pointer matrix) gsl-matrix-c) (j size) ((pointer vector) gsl-vector-c)) |
|---|
| 380 | :invalidate (matrix)) |
|---|
| 381 | |
|---|
| 382 | (defun (setf row) (vector matrix i) (set-row matrix i vector)) |
|---|
| 383 | (defun (setf column) (vector matrix j) (set-column matrix j vector)) |
|---|
| 384 | |
|---|
| 385 | ;;;;**************************************************************************** |
|---|
| 386 | ;;;; Exchanging rows and columns |
|---|
| 387 | ;;;;**************************************************************************** |
|---|
| 388 | |
|---|
| 389 | (export 'swap-rows) |
|---|
| 390 | (defgeneric swap-rows (matrix i j) |
|---|
| 391 | (:documentation ; FDL |
|---|
| 392 | "Exchange the ith and jth rows of the matrix in-place.")) |
|---|
| 393 | |
|---|
| 394 | (defmfun-mdsfc swap-rows ((matrix matrix) i j) |
|---|
| 395 | "gsl_matrix_swap_rows" |
|---|
| 396 | (((pointer matrix) gsl-matrix-c) (i size) (j size)) |
|---|
| 397 | :invalidate (matrix)) |
|---|
| 398 | |
|---|
| 399 | (export 'swap-columns) |
|---|
| 400 | (defgeneric swap-columns (matrix i j) |
|---|
| 401 | (:documentation ; FDL |
|---|
| 402 | "Exchange the ith and jth columns of the matrix in-place.")) |
|---|
| 403 | |
|---|
| 404 | (defmfun-mdsfc swap-columns ((matrix matrix) i j) |
|---|
| 405 | "gsl_matrix_swap_columns" |
|---|
| 406 | (((pointer matrix) gsl-matrix-c) (i size) (j size)) |
|---|
| 407 | :invalidate (matrix)) |
|---|
| 408 | |
|---|
| 409 | (export 'swap-rowcol) |
|---|
| 410 | (defgeneric swap-rowcol (matrix i j) |
|---|
| 411 | (:documentation ; FDL |
|---|
| 412 | "Exchange the ith row and jth column of the |
|---|
| 413 | matrix in-place. The matrix must be square for this operation to |
|---|
| 414 | be possible.")) |
|---|
| 415 | |
|---|
| 416 | (defmfun-mdsfc swap-rowcol ((matrix matrix) i j) |
|---|
| 417 | "gsl_matrix_swap_rowcol" |
|---|
| 418 | (((pointer matrix) gsl-matrix-c) (i size) (j size)) |
|---|
| 419 | :invalidate (matrix)) |
|---|
| 420 | |
|---|
| 421 | (export 'matrix-transpose-copy) |
|---|
| 422 | (defgeneric matrix-transpose-copy (destination source) |
|---|
| 423 | (:documentation ; FDL |
|---|
| 424 | "Make the destination matrix the transpose of the source matrix |
|---|
| 425 | by copying the elements. The dimensions of the destination |
|---|
| 426 | matrix must match the transposed dimensions of the source.")) |
|---|
| 427 | |
|---|
| 428 | (defmfun-mdsfc matrix-transpose-copy |
|---|
| 429 | ((destination matrix) (source matrix)) |
|---|
| 430 | "gsl_matrix_transpose_memcpy" |
|---|
| 431 | (((pointer destination) gsl-matrix-c) ((pointer source) gsl-matrix-c)) |
|---|
| 432 | :invalidate (destination)) |
|---|
| 433 | |
|---|
| 434 | (export 'matrix-transpose) |
|---|
| 435 | (defgeneric matrix-transpose (matrix) |
|---|
| 436 | (:documentation ; FDL |
|---|
| 437 | "Replace the matrix by its transpose by copying the elements |
|---|
| 438 | of the matrix in-place. The matrix must be square for this |
|---|
| 439 | operation to be possible.")) |
|---|
| 440 | |
|---|
| 441 | (defmfun-mdsfc matrix-transpose ((matrix matrix)) |
|---|
| 442 | "gsl_matrix_transpose" |
|---|
| 443 | (((pointer matrix) gsl-matrix-c)) |
|---|
| 444 | :invalidate (matrix)) |
|---|
| 445 | |
|---|
| 446 | ;;;;**************************************************************************** |
|---|
| 447 | ;;;; Arithmetic operations |
|---|
| 448 | ;;;;**************************************************************************** |
|---|
| 449 | |
|---|
| 450 | (defmfun-mdsfc m+ ((a matrix) (b matrix)) |
|---|
| 451 | "gsl_matrix_add" |
|---|
| 452 | (((pointer a) gsl-matrix-c) ((pointer b) gsl-matrix-c)) |
|---|
| 453 | :invalidate (a) |
|---|
| 454 | :documentation ; FDL |
|---|
| 455 | "Add the elements of b to the elements of a, |
|---|
| 456 | a'_i = a_i + b_i. The two matrices must have the |
|---|
| 457 | same dimensions.") |
|---|
| 458 | |
|---|
| 459 | (defmfun-mdsfc m- ((a matrix) (b matrix)) |
|---|
| 460 | "gsl_matrix_sub" (((pointer a) gsl-matrix-c) ((pointer b) gsl-matrix-c)) |
|---|
| 461 | :invalidate (a) |
|---|
| 462 | :documentation ; FDL |
|---|
| 463 | "Subtract the elements of matrix b from the elements of matrix |
|---|
| 464 | a, a'_i = a_i - b_i. The two matrices must have the |
|---|
| 465 | same dimensions.") |
|---|
| 466 | |
|---|
| 467 | (defmfun-mdsfc m* ((a matrix) (b matrix)) |
|---|
| 468 | "gsl_matrix_mul_elements" |
|---|
| 469 | (((pointer a) gsl-matrix-c) ((pointer b) gsl-matrix-c)) |
|---|
| 470 | :invalidate (a) |
|---|
| 471 | :documentation ; FDL |
|---|
| 472 | "Multiply the elements of matrix a by the elements of |
|---|
| 473 | matrix b, a'(i,j) = a(i,j) * b(i,j). The two matrices must have the |
|---|
| 474 | same dimensions.") |
|---|
| 475 | |
|---|
| 476 | (defmfun-mdsfc m/ ((a matrix) (b matrix)) |
|---|
| 477 | "gsl_matrix_div_elements" |
|---|
| 478 | (((pointer a) gsl-matrix-c) ((pointer b) gsl-matrix-c)) |
|---|
| 479 | :invalidate (a) |
|---|
| 480 | :documentation ; FDL |
|---|
| 481 | "Divide the elements of matrix a by the elements of |
|---|
| 482 | matrix b, a'(i,j) = a(i,j) / b(i,j). The two matrices must have the |
|---|
| 483 | same dimensions.") |
|---|
| 484 | |
|---|
| 485 | (defmfun-mdsfc m*c ((a matrix) x) |
|---|
| 486 | "gsl_matrix_scale" (((pointer a) gsl-matrix-c) (x :c-base-type)) |
|---|
| 487 | :invalidate (a) |
|---|
| 488 | :documentation ; FDL |
|---|
| 489 | "Multiply the elements of matrix a by the constant |
|---|
| 490 | factor x, a'(i,j) = x a(i,j).") |
|---|
| 491 | |
|---|
| 492 | (defmfun-mdsfc m+c ((a matrix) x) |
|---|
| 493 | "gsl_matrix_add_constant" (((pointer a) gsl-matrix-c) (x :c-base-type)) |
|---|
| 494 | :invalidate (a) |
|---|
| 495 | :documentation ; FDL |
|---|
| 496 | "Add the constant value x to the elements of the |
|---|
| 497 | matrix a, a'(i,j) = a(i,j) + x.") |
|---|
| 498 | |
|---|
| 499 | ;;;;**************************************************************************** |
|---|
| 500 | ;;;; Maximum and minimum elements |
|---|
| 501 | ;;;;**************************************************************************** |
|---|
| 502 | |
|---|
| 503 | (defmfun-mdsf gsl-max ((m matrix)) |
|---|
| 504 | "gsl_matrix_max" (((pointer m) gsl-matrix-c)) |
|---|
| 505 | :documentation ; FDL |
|---|
| 506 | "The maximum value in the matrix m." |
|---|
| 507 | :c-return :c-base-type) |
|---|
| 508 | |
|---|
| 509 | (defmfun-mdsf gsl-min ((m matrix)) |
|---|
| 510 | "gsl_matrix_min" (((pointer m) gsl-matrix-c)) |
|---|
| 511 | :documentation ; FDL |
|---|
| 512 | "The minimum value in the matrix m." |
|---|
| 513 | :c-return :c-base-type) |
|---|
| 514 | |
|---|
| 515 | (defmfun-mdsf gsl-minmax ((m matrix)) |
|---|
| 516 | "gsl_matrix_minmax" |
|---|
| 517 | (((pointer m) gsl-matrix-c) (min :c-base-type) (max :c-base-type)) |
|---|
| 518 | :documentation ; FDL |
|---|
| 519 | "The minimum and maximum values in the matrix m." |
|---|
| 520 | :c-return :void) |
|---|
| 521 | |
|---|
| 522 | (defmfun-mdsf gsl-max-index ((m matrix)) |
|---|
| 523 | "gsl_matrix_max_index" |
|---|
| 524 | (((pointer m) gsl-matrix-c) (imax size) (jmax size)) |
|---|
| 525 | :documentation ; FDL |
|---|
| 526 | "The index of the maximum value in the matrix m |
|---|
| 527 | When there are several equal maximum elements then the lowest index is |
|---|
| 528 | returned." |
|---|
| 529 | :c-return :void |
|---|
| 530 | :return ((list (scref imax) (scref jmax)))) |
|---|
| 531 | |
|---|
| 532 | (defmfun-mdsf gsl-min-index ((m matrix)) |
|---|
| 533 | "gsl_matrix_min_index" |
|---|
| 534 | (((pointer m) gsl-matrix-c) (imin size) (jmin size)) |
|---|
| 535 | :documentation ; FDL |
|---|
| 536 | "The index of the minimum value in the matrix m |
|---|
| 537 | When there are several equal minimum elements then the |
|---|
| 538 | lowest index is returned." |
|---|
| 539 | :c-return :void |
|---|
| 540 | :return ((list (scref imin) (scref jmin)))) |
|---|
| 541 | |
|---|
| 542 | (defmfun-mdsf gsl-minmax-index ((m matrix)) |
|---|
| 543 | "gsl_matrix_minmax_index" |
|---|
| 544 | (((pointer m) gsl-matrix-c) |
|---|
| 545 | (imin size) (jmin size) (imax size) (jmax size)) |
|---|
| 546 | :documentation ; FDL |
|---|
| 547 | "The indices of the minimum and maximum values in the matrix m. |
|---|
| 548 | When there are several equal minimum elements then the lowest index is |
|---|
| 549 | returned." |
|---|
| 550 | :c-return :void |
|---|
| 551 | :return ((list (scref imin) (scref jmin)) |
|---|
| 552 | (list (scref imax) (scref jmax)))) |
|---|
| 553 | |
|---|
| 554 | ;;;;**************************************************************************** |
|---|
| 555 | ;;;; Properties |
|---|
| 556 | ;;;;**************************************************************************** |
|---|
| 557 | |
|---|
| 558 | (defmfun-mdsfc gsl-zerop ((m matrix)) |
|---|
| 559 | "gsl_matrix_isnull" (((pointer m) gsl-matrix-c)) |
|---|
| 560 | :documentation ; FDL |
|---|
| 561 | "All elements of matrix m are zero." |
|---|
| 562 | :c-return :boolean) |
|---|
| 563 | |
|---|
| 564 | ;;;;**************************************************************************** |
|---|
| 565 | ;;;; Examples and unit test |
|---|
| 566 | ;;;;**************************************************************************** |
|---|
| 567 | |
|---|
| 568 | #| |
|---|
| 569 | (make-tests matrix-fixnum |
|---|
| 570 | (letm ((intmat (matrix-fixnum 2 2))) ;(setf maref), maref |
|---|
| 571 | (setf (maref intmat 0 1) 77) |
|---|
| 572 | (maref intmat 0 1)) |
|---|
| 573 | (letm ((intmat (matrix-fixnum 2 2))) ;(setf data) |
|---|
| 574 | (setf (data intmat) #2A((4 6) (8 2))) |
|---|
| 575 | (data intmat)) |
|---|
| 576 | (letm ((intmat (matrix-fixnum 2 2))) ;set-zero |
|---|
| 577 | (set-zero intmat) |
|---|
| 578 | (data intmat)) |
|---|
| 579 | (letm ((intmat (matrix-fixnum 2 2))) ;set-all |
|---|
| 580 | (set-all intmat 44) |
|---|
| 581 | (data intmat)) |
|---|
| 582 | (letm ((intmat (matrix-fixnum 2 2))) ;set-identity |
|---|
| 583 | (set-identity intmat) |
|---|
| 584 | (data intmat)) |
|---|
| 585 | (letm ((intmat (matrix-fixnum #2A((4 6) (8 2)))) ;row |
|---|
| 586 | (vect (vector-fixnum 2))) |
|---|
| 587 | (row vect intmat 0) |
|---|
| 588 | (data vect)) |
|---|
| 589 | (letm ((intmat (matrix-fixnum #2A((4 6) (8 2)))) ;column |
|---|
| 590 | (vect (vector-fixnum 2))) |
|---|
| 591 | (column vect intmat 1) |
|---|
| 592 | (data vect)) |
|---|
| 593 | (letm ((intmat (matrix-fixnum #2A((-1 -12) (8 3))))) ;gsl-min |
|---|
| 594 | (gsl-min intmat)) |
|---|
| 595 | (letm ((intmat (matrix-fixnum #2A((-1 -12) (8 3))))) ;gsl-max |
|---|
| 596 | (gsl-max intmat)) |
|---|
| 597 | (letm ((intmat (matrix-fixnum #2A((-1 -12) (8 3))))) ;gsl-minmax |
|---|
| 598 | (multiple-value-list (gsl-minmax intmat))) |
|---|
| 599 | (letm ((intmat (matrix-fixnum #2A((-1 -12) (8 3))))) ;gsl-min-index |
|---|
| 600 | (gsl-min-index intmat)) |
|---|
| 601 | (letm ((intmat (matrix-fixnum #2A((-1 -12) (8 3))))) ;gsl-max-index |
|---|
| 602 | (gsl-max-index intmat)) |
|---|
| 603 | (letm ((intmat (matrix-fixnum #2A((-1 -12) (8 3))))) ;gsl-minmax-index |
|---|
| 604 | (multiple-value-list (gsl-minmax-index intmat))) |
|---|
| 605 | (letm ((intmat1 (matrix-fixnum #2A((1 2)(3 4)))) ;copy |
|---|
| 606 | (intmat2 (matrix-fixnum 2 2))) |
|---|
| 607 | (copy intmat2 intmat1) |
|---|
| 608 | (data intmat2)) |
|---|
| 609 | (letm ((intmat1 (matrix-fixnum #2A((1 2)(3 4)))) ;swap |
|---|
| 610 | (intmat2 (matrix-fixnum #2A((5 6) (7 8))))) |
|---|
| 611 | (swap intmat1 intmat2) |
|---|
| 612 | (data intmat1)) |
|---|
| 613 | (letm ((intmat1 (matrix-fixnum #2A((1 2)(3 4))))) ;swap-rows |
|---|
| 614 | (swap-rows intmat1 0 1) |
|---|
| 615 | (data intmat1)) |
|---|
| 616 | (letm ((intmat1 (matrix-fixnum #2A((1 2)(3 4))))) ;swap-columns |
|---|
| 617 | (swap-columns intmat1 0 1) |
|---|
| 618 | (data intmat1)) |
|---|
| 619 | (letm ((intmat1 (matrix-fixnum #2A((1 2)(3 4))))) ;swap-rowcol |
|---|
| 620 | (swap-rowcol intmat1 0 1) |
|---|
| 621 | (data intmat1))) |
|---|
| 622 | |# |
|---|
| 623 | |
|---|
| 624 | (LISP-UNIT:DEFINE-TEST |
|---|
| 625 | MATRIX-FIXNUM |
|---|
| 626 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 627 | (LIST 77) |
|---|
| 628 | (MULTIPLE-VALUE-LIST |
|---|
| 629 | (LETM ((INTMAT (MATRIX-FIXNUM 2 2))) |
|---|
| 630 | (SETF (MAREF INTMAT 0 1) 77) |
|---|
| 631 | (MAREF INTMAT 0 1)))) |
|---|
| 632 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 633 | (LIST #2A((4 6) (8 2))) |
|---|
| 634 | (MULTIPLE-VALUE-LIST |
|---|
| 635 | (LETM ((INTMAT (MATRIX-FIXNUM 2 2))) |
|---|
| 636 | (SETF (DATA INTMAT) #2A((4 6) (8 2))) |
|---|
| 637 | (DATA INTMAT)))) |
|---|
| 638 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 639 | (LIST #2A((0 0) (0 0))) |
|---|
| 640 | (MULTIPLE-VALUE-LIST |
|---|
| 641 | (LETM ((INTMAT (MATRIX-FIXNUM 2 2))) (SET-ZERO INTMAT) |
|---|
| 642 | (DATA INTMAT)))) |
|---|
| 643 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 644 | (LIST #2A((44 44) (44 44))) |
|---|
| 645 | (MULTIPLE-VALUE-LIST |
|---|
| 646 | (LETM ((INTMAT (MATRIX-FIXNUM 2 2))) |
|---|
| 647 | (SET-ALL INTMAT 44) (DATA INTMAT)))) |
|---|
| 648 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 649 | (LIST #2A((1 0) (0 1))) |
|---|
| 650 | (MULTIPLE-VALUE-LIST |
|---|
| 651 | (LETM ((INTMAT (MATRIX-FIXNUM 2 2))) |
|---|
| 652 | (SET-IDENTITY INTMAT) (DATA INTMAT)))) |
|---|
| 653 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 654 | (LIST #(4 6)) |
|---|
| 655 | (MULTIPLE-VALUE-LIST |
|---|
| 656 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((4 6) (8 2)))) |
|---|
| 657 | (VECT (VECTOR-FIXNUM 2))) |
|---|
| 658 | (ROW VECT INTMAT 0) |
|---|
| 659 | (DATA VECT)))) |
|---|
| 660 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 661 | (LIST #(6 2)) |
|---|
| 662 | (MULTIPLE-VALUE-LIST |
|---|
| 663 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((4 6) (8 2)))) |
|---|
| 664 | (VECT (VECTOR-FIXNUM 2))) |
|---|
| 665 | (COLUMN VECT INTMAT 1) |
|---|
| 666 | (DATA VECT)))) |
|---|
| 667 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 668 | (LIST -12) |
|---|
| 669 | (MULTIPLE-VALUE-LIST |
|---|
| 670 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((-1 -12) (8 3))))) |
|---|
| 671 | (GSL-MIN INTMAT)))) |
|---|
| 672 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 673 | (LIST 8) |
|---|
| 674 | (MULTIPLE-VALUE-LIST |
|---|
| 675 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((-1 -12) (8 3))))) |
|---|
| 676 | (GSL-MAX INTMAT)))) |
|---|
| 677 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 678 | (LIST (LIST -12 8)) |
|---|
| 679 | (MULTIPLE-VALUE-LIST |
|---|
| 680 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((-1 -12) (8 3))))) |
|---|
| 681 | (MULTIPLE-VALUE-LIST (GSL-MINMAX INTMAT))))) |
|---|
| 682 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 683 | (LIST (LIST 0 1)) |
|---|
| 684 | (MULTIPLE-VALUE-LIST |
|---|
| 685 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((-1 -12) (8 3))))) |
|---|
| 686 | (GSL-MIN-INDEX INTMAT)))) |
|---|
| 687 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 688 | (LIST (LIST 1 0)) |
|---|
| 689 | (MULTIPLE-VALUE-LIST |
|---|
| 690 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((-1 -12) (8 3))))) |
|---|
| 691 | (GSL-MAX-INDEX INTMAT)))) |
|---|
| 692 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 693 | (LIST (LIST (LIST 0 1) (LIST 1 0))) |
|---|
| 694 | (MULTIPLE-VALUE-LIST |
|---|
| 695 | (LETM ((INTMAT (MATRIX-FIXNUM #2A((-1 -12) (8 3))))) |
|---|
| 696 | (MULTIPLE-VALUE-LIST |
|---|
| 697 | (GSL-MINMAX-INDEX INTMAT))))) |
|---|
| 698 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 699 | (LIST #2A((1 2) (3 4))) |
|---|
| 700 | (MULTIPLE-VALUE-LIST |
|---|
| 701 | (LETM ((INTMAT1 (MATRIX-FIXNUM #2A((1 2) (3 4)))) |
|---|
| 702 | (INTMAT2 (MATRIX-FIXNUM 2 2))) |
|---|
| 703 | (COPY INTMAT2 INTMAT1) (DATA INTMAT2)))) |
|---|
| 704 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 705 | (LIST #2A((5 6) (7 8))) |
|---|
| 706 | (MULTIPLE-VALUE-LIST |
|---|
| 707 | (LETM ((INTMAT1 (MATRIX-FIXNUM #2A((1 2) (3 4)))) |
|---|
| 708 | (INTMAT2 (MATRIX-FIXNUM #2A((5 6) (7 8))))) |
|---|
| 709 | (SWAP INTMAT1 INTMAT2) (DATA INTMAT1)))) |
|---|
| 710 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 711 | (LIST #2A((3 4) (1 2))) |
|---|
| 712 | (MULTIPLE-VALUE-LIST |
|---|
| 713 | (LETM ((INTMAT1 (MATRIX-FIXNUM #2A((1 2) (3 4))))) |
|---|
| 714 | (SWAP-ROWS INTMAT1 0 1) (DATA INTMAT1)))) |
|---|
| 715 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 716 | (LIST #2A((2 1) (4 3))) |
|---|
| 717 | (MULTIPLE-VALUE-LIST |
|---|
| 718 | (LETM ((INTMAT1 (MATRIX-FIXNUM #2A((1 2) (3 4))))) |
|---|
| 719 | (SWAP-COLUMNS INTMAT1 0 1) (DATA INTMAT1)))) |
|---|
| 720 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 721 | (LIST #2A((2 4) (3 1))) |
|---|
| 722 | (MULTIPLE-VALUE-LIST |
|---|
| 723 | (LETM ((INTMAT1 (MATRIX-FIXNUM #2A((1 2) (3 4))))) |
|---|
| 724 | (SWAP-ROWCOL INTMAT1 0 1) (DATA INTMAT1))))) |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | #| |
|---|
| 728 | (make-tests |
|---|
| 729 | matrix-double |
|---|
| 730 | (letm ((mat (matrix-double-float 10 3))) |
|---|
| 731 | (loop for i from 0 below 10 |
|---|
| 732 | do |
|---|
| 733 | (loop for j from 0 below 3 |
|---|
| 734 | do (setf (maref mat i j) (+ 0.23d0 j (* 100 i))))) |
|---|
| 735 | (data mat)) |
|---|
| 736 | (letm ((mat (matrix-double-float #2A((1.0d0 2.0d0) (3.0d0 4.0d0)))) |
|---|
| 737 | (ans (matrix-double-float 2 2))) |
|---|
| 738 | (copy ans mat) |
|---|
| 739 | (data ans)) |
|---|
| 740 | (letm ((mat (matrix-double-float #2A((1.0d0 2.0d0) (3.0d0 4.0d0))))) |
|---|
| 741 | (m* mat mat) |
|---|
| 742 | (data mat)) |
|---|
| 743 | (letm ((mat (matrix-double-float #2A((1.0d0 2.0d0) (-3.0d0 4.0d0))))) |
|---|
| 744 | (list (maref mat 0 0) (maref mat 0 1) (maref mat 1 0) (maref mat 1 1)))) |
|---|
| 745 | |# |
|---|
| 746 | |
|---|
| 747 | (LISP-UNIT:DEFINE-TEST MATRIX-DOUBLE |
|---|
| 748 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 749 | (LIST |
|---|
| 750 | #2A((0.23d0 1.23d0 2.23d0) |
|---|
| 751 | (100.23d0 101.23d0 102.23d0) |
|---|
| 752 | (200.23d0 201.23d0 202.23d0) |
|---|
| 753 | (300.23d0 301.23d0 302.23d0) |
|---|
| 754 | (400.23d0 401.23d0 402.23d0) |
|---|
| 755 | (500.23d0 501.23d0 502.23d0) |
|---|
| 756 | (600.23d0 601.23d0 602.23d0) |
|---|
| 757 | (700.23d0 701.23d0 702.23d0) |
|---|
| 758 | (800.23d0 801.23d0 802.23d0) |
|---|
| 759 | (900.23d0 901.23d0 902.23d0))) |
|---|
| 760 | (MULTIPLE-VALUE-LIST |
|---|
| 761 | (LETM ((MAT (MATRIX-DOUBLE-FLOAT 10 3))) |
|---|
| 762 | (LOOP FOR I FROM 0 BELOW 10 DO |
|---|
| 763 | (LOOP FOR J FROM 0 BELOW 3 DO |
|---|
| 764 | (SETF (MAREF MAT I J) |
|---|
| 765 | (+ 0.23d0 J (* 100 I))))) |
|---|
| 766 | (DATA MAT)))) |
|---|
| 767 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 768 | (LIST #2A((1.0d0 2.0d0) (3.0d0 4.0d0))) |
|---|
| 769 | (MULTIPLE-VALUE-LIST |
|---|
| 770 | (LETM ((MAT (MATRIX-DOUBLE-FLOAT #2A((1.0d0 2.0d0) (3.0d0 4.0d0)))) |
|---|
| 771 | (ANS (MATRIX-DOUBLE-FLOAT 2 2))) |
|---|
| 772 | (COPY ANS MAT) (DATA ANS)))) |
|---|
| 773 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 774 | (LIST #2A((1.0d0 4.0d0) (9.0d0 16.0d0))) |
|---|
| 775 | (MULTIPLE-VALUE-LIST |
|---|
| 776 | (LETM ((MAT (MATRIX-DOUBLE-FLOAT #2A((1.0d0 2.0d0) (3.0d0 4.0d0))))) |
|---|
| 777 | (M* MAT MAT) (DATA MAT)))) |
|---|
| 778 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 779 | (LIST (LIST 1.0d0 2.0d0 -3.0d0 4.0d0)) |
|---|
| 780 | (MULTIPLE-VALUE-LIST |
|---|
| 781 | (LETM ((MAT (MATRIX-DOUBLE-FLOAT #2A((1.0d0 2.0d0) (-3.0d0 4.0d0))))) |
|---|
| 782 | (LIST (MAREF MAT 0 0) (MAREF MAT 0 1) (MAREF MAT 1 0) (MAREF MAT 1 1)))))) |
|---|
| 783 | |
|---|