Uniform vectors

Uniform vectors are vectors whose elements are of the same numeric type. The are defined by SRFI-4. The type names (such as s8vector) are a Kawa extension.

uniform-vector ::= # uniform-tag list
uniform-tag ::= f32 | f64
    | s8 | s16 | s32 | s64
    | u8 | u16 | u32 | u64

This example is a literal for a 5-element vector of unsigned short (ushort) values:

(define uvec1 #u16(64000 3200 160 8 0))

Since a uniform vector is a sequence, you can use function-call notation to index one. For example:

(uvec1 1) ⇒ 3200

In this case the result is a primitive unsigned short (ushort), which is converted to a gnu.math.UShort if an object is needed.

Type: s8vector

The type of uniform vectors where each element can contain a signed 8-bit integer. Represented using an array of byte.

Type: u8vector

The type of uniform vectors where each element can contain an unsigned 8-bit integer. Represented using an array of <byte>, but each element is treated as if unsigned.

This type is a synonym for bytevector, which has extra functions.

Type: s16vector

The type of uniform vectors where each element can contain a signed 16-bit integer. Represented using an array of short.

Type: u16vector

The type of uniform vectors where each element can contain an unsigned 16-bit integer. Represented using an array of short, but each element is treated as if unsigned.

Type: s32vector

The type of uniform vectors where each element can contain a signed 32-bit integer. Represented using an array of int.

Type: u32vector

The type of uniform vectors where each element can contain an unsigned 32-bit integer. Represented using an array of int, but each element is treated as if unsigned.

Type: s64vector

The type of uniform vectors where each element can contain a signed 64-bit integer. Represented using an array of long.

Type: u64vector

The type of uniform vectors where each element can contain an unsigned 64-bit integer. Represented using an array of long, but each element is treated as if unsigned.

Type: f32vector

The type of uniform vectors where each element can contain a 32-bit floating-point real. Represented using an array of float.

Type: f64vector

The type of uniform vectors where each element can contain a 64-bit floating-point real. Represented using an array of double.

Procedure: s8vector? value

Procedure: u8vector? value

Procedure: s16vector? value

Procedure: u16vector? value

Procedure: s32vector? value

Procedure: u32vector? value

Procedure: s64vector? value

Procedure: u64vector? value

Procedure: f32vector? value

Procedure: f64vector? value

Return true iff value is a uniform vector of the specified type.

Procedure: make-s8vector n [value]

Procedure: make-u8vector n [value]

Procedure: make-s16vector n [value]

Procedure: make-u16vector n [value]

Procedure: make-s32vector n [value]

Procedure: make-u32vector n [value]

Procedure: make-s64vector n [value]

Procedure: make-u64vector n [value]

Procedure: make-f32vector n [value]

Procedure: make-f64vector n [value]

Create a new uniform vector of the specified type, having room for n elements. Initialize each element to value if it is specified; zero otherwise.

Constructor: s8vector value ...

Constructor: u8vector value ...

Constructor: s16vector value ..

Constructor: u16vector value ...

Constructor: s32vector value ...

Constructor: u32vector value ...

Constructor: s64vector value ...

Constructor: u64vector value ...

Constructor: f32vector value ...

Constructor: f64vector value ...

Create a new uniform vector of the specified type, whose length is the number of values specified, and initialize it using those values.

Procedure: s8vector-length v

Procedure: u8vector-length v

Procedure: s16vector-length v

Procedure: u16vector-length v

Procedure: s32vector-length v

Procedure: u32vector-length v

Procedure: s64vector-length v

Procedure: u64vector-length v

Procedure: f32vector-length v

Procedure: f64vector-length v

Return the length (in number of elements) of the uniform vector v.

Procedure: s8vector-ref v i

Procedure: u8vector-ref v i

Procedure: s16vector-ref v i

Procedure: u16vector-ref v i

Procedure: s32vector-ref v i

Procedure: u32vector-ref v i

Procedure: s64vector-ref v i

Procedure: u64vector-ref v i

Procedure: f32vector-ref v i

Procedure: f64vector-ref v i

Return the element at index i of the uniform vector v.

Procedure: s8vector-set! v i x

Procedure: u8vector-set! v i x

Procedure: s16vector-set! v i x

Procedure: u16vector-set! v i x

Procedure: s32vector-set! v i x

Procedure: u32vector-set! v i x

Procedure: s64vector-set! v i x

Procedure: u64vector-set! v i x

Procedure: f32vector-set! v i x

Procedure: f64vector-set! v i x

Set the element at index i of uniform vector v to the value x, which must be a number coercible to the appropriate type.

Procedure: s8vector->list v

Procedure: u8vector->list v

Procedure: s16vector->list v

Procedure: u16vector->list v

Procedure: s32vector->list v

Procedure: u32vector->list v

Procedure: s64vector->list v

Procedure: u64vector->list v

Procedure: f32vector->list v

Procedure: f64vector->list v

Convert the uniform vetor v to a list containing the elments of v.

Procedure: list->s8vector l

Procedure: list->u8vector l

Procedure: list->s16vector l

Procedure: list->u16vector l

Procedure: list->s32vector l

Procedure: list->u32vector l

Procedure: list->s64vector l

Procedure: list->u64vector l

Procedure: list->f32vector l

Procedure: list->f64vector l

Create a uniform vector of the appropriate type, initializing it with the elements of the list l. The elements of l must be numbers coercible the new vector’s element type.

Relationship with Java arrays

Each uniform array type is implemented as an underlying Java array, and a length field. The underlying type is byte[] for u8vector or s8vector; short[] for u16vector or u16vector; int[] for u32vector or s32vector; long[] for u64vector or s64vector; float[] for f32vector; and double[] for f32vector. The length field allows a uniform array to only use the initial part of the underlying array. (This can be used to support Common Lisp’s fill pointer feature.) This also allows resizing a uniform vector. There is no Scheme function for this, but you can use the setSize method:

(invoke some-vector 'setSize 200)

If you have a Java array, you can create a uniform vector sharing with the Java array:

(define arr :: byte[] ((primitive-array-new byte) 10))
(define vec :: u8vector (make u8vector arr))

At this point vec uses arr for its underlying storage, so changes to one affect the other. It vec is re-sized so it needs a larger underlying array, then it will no longer use arr.