[ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

## 9.24 `gauche.uvector` - Uniform vectors

Module: gauche.uvector
Provides vectors whose elements are of the same numeric type, as defined in SRFI-4 (SRFI-4).

Gauche's implementation is a superset of SRFI-4 in a few ways:

• Some routines takes optional parameters: `TAGvector->list` takes optional start and end indices, and `TAGvector-ref` takes optional fallback value.
• Additional functions: copy procedures (`TAGvector-copy` and `TAGvector-copy!`), conversion procedures (`TAGvector->vector` and `vector->TAGvector`), and some arithmetic functions (`TAGvector-add`, etc.)
• Implements the collection framework (See section 9.3 `gauche.collection` - Collection framework) and the sequence framework (See section 9.18 `gauche.sequence` - Sequence framework). So the methods like `map`, `for-each`, `ref` or `subseq` can be used on the SRFI-4 vector types.

There are some advantages of using SRFI-4 vectors over normal (heterogeneous) vectors. It may be more compact than the normal vectors. Some operations (especially Gauche's extension of vector arithmetic operations) can bypass type check and conversion of individual elements, thus be more efficient. And it is much easier and efficient to communicate with external libraries that require homogeneous array of numbers; for example, OpenGL binding of Gauche uses SRFI-4 vectors extensively.

The following ten types of vectors are defined.
s8vector
Elements are exact integers in the range between -2^7 and 2^7-1
u8vector
Elements are exact integers in the range between 0 and 2^8-1
s16vector
Elements are exact integers in the range between -2^15 and 2^15-1
u16vector
Elements are exact integers in the range between 0 and 2^16-1
s32vector
Elements are exact integers in the range between -2^31 and 2^31-1
u32vector
Elements are exact integers in the range between 0 and 2^32-1
s64vector
Elements are exact integers in the range between -2^63 and 2^63-1
u64vector
Elements are exact integers in the range between 0 and 2^64-1
f32vector
Elements are inexact real numbers representable in the `float` of C compiler that compiles Gauche. Usually it is a single precision IEEE floating point number.
f64vector
Elements are inexact real numbers representable in the `double` of C compiler that compiles Gauche. Usually it is a double precision IEEE floating point number.

When you try to store a number out of the range of the vector type, an error is signalled by default. However, some procedures take an optional argument clamp that specifies alternative behavior in such a case. Clamp argument may take one of the following values.

`#f`
Default behavior (signals an error).
`high`
Clamps high bound; i.e. if the value to be stored is beyond the higher bound of the range, the maximum value is stored instead.
`low`
Clamps low bound; i.e. if the value to be stored is below the lower bound of the range, the minimum value is stored instead.
`both`
Clamps both sides; does both `high` and `low`.

 ```(list->u8vector '(-1)) => error (list->u8vector '(-1) 'low) => #u8(0) (list->u8vector '(-1) 'high) => error (list->u8vector '(3000) 'high) => #u8(255) (list->u8vector '(-100 20 300) 'both) => #u8(0 20 255) ```

In the following description, `TAG` can be replaced for any of `s8`, `u8`, `s16`, `u16`, `s32`, `u32`, `s64`, `u64`, `f32`, `f64`.

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html