Next: Operations, Previous: Introduction, Up: Top
In the grid system, the only defined grid is an ordinary
(Common Lisp) array, and this may be created in the usual fashion, with
the #
reader macro
#(1.0d0 2.0d0 3.0d0)
or with make-array
.
The foreign-array system adds foreign arrays, and they may be
created with the #m
reader macro, or with
make-foreign-array
. The #m reader macro in the default form
creates a vector or matrix of element type double-float, which is the
most common type needed for mathematical functions. It optionally takes
a numeric argument prefix to make an array with a different element
type; a guide to the numeric argument is given below. It should be
followed by a list; this list will be evaluated. If the list contains
^
, the object created will be a matrix and each row is ended with
that symbol.
Classes of vectors and matrices are named by appending the element type as hypenated words to "vector" or "matrix". The following table shows the classes available on a 64-bit platform:
Element type | Vector class | Matrix class | #m prefix
|
---|---|---|---|
double-float | vector-double-float
| matrix-double-float
| 1 or empty
|
(complex double-float) | vector-complex-double-float
| matrix-complex-double-float
| 2
|
single-float | vector-single-float
| matrix-single-float
| 3
|
(complex single-float) | vector-complex-single-float
| matrix-complex-single-float
| 4
|
(signed-byte 8) | vector-signed-byte-8
| matrix-signed-byte-8
| 7
|
(unsigned-byte 8) | vector-unsigned-byte-8
| matrix-unsigned-byte-8
| 8
|
(signed-byte 16) | vector-signed-byte-16
| matrix-signed-byte-16
| 15
|
(unsigned-byte 16) | vector-unsigned-byte-16
| matrix-unsigned-byte-16
| 16
|
(signed-byte 32) | vector-signed-byte-32
| matrix-signed-byte-32
| 31
|
(unsigned-byte 32) | vector-unsigned-byte-32
| matrix-unsigned-byte-32
| 32
|
(signed-byte 64) | vector-signed-byte-64
| matrix-signed-byte-64
| 63
|
(unsigned-byte 64) | vector-unsigned-byte-64
| matrix-unsigned-byte-64
| 64
|
Individual elements are obtained using grid:gref
(analogous to
Lisp's aref
), and are set with setf grid:gref
.
Copying is performed with the function <code>copy</code>.
This works between grid:foreign-array
s, pointers, and CL arrays.
There are two functions provided to extract the dimensions of a
vector or array: dim0
and dim1
; the latter
is applicable only for matrices. If you
use iterate
system, there are extensions defined that make it easier to iterate over
grids: matrix-row
, matrix-row-index
,
matrix-column
, matrix-column-index
,
vector-element
, vector-element-index
,
matrix-element
, matrix-element-index
,
For example,
(defparameter m1 #m(1 2 3 ^ 0 6 8)) (iter:iter (iter:for e :matrix-element m1) (princ e) (princ " ")) 1.0 2.0 3.0 0.0 0.0 6.0 8.0