Oberon > Software > MultiArrays


[ Description | Installation | Version log ]


Current Version: Version 1.0 - 19 Jan, 2001

MultiArrays implements a base type Array for constructing arrays of arbitrary dimensions and of arbitrary element types together with an associated SizeVector defining the length of the dimensions. Array elements can be accessed in various ways:

It is hoped that these generic procedures for multidimensional array handling will evolve to ultimately provide the same functionality as is known from MATLAB or APL.

Maintainer: Patrick Hunziker

In the Oberon programming language, an array is a data type that represents a set of elements that are all of the same type - the element type. In a multidimensional array, each index spans a dimension in a Cartesian space.

In the context of MultiArrays, an array is defined by a pair of POINTERs consisting of the base type

    Array = POINTER TO ArrayDesc;
and a size vector
    SizeVector = POINTER TO SizeVectorDesc;
Both are abstract data types containing no data. The array elements forming the data can be of any type, including extensions of Objects.Object defined in ETH Oberon. The module MultiArrays offers a base type Scalar and a collection of extensions thereof, seven of them in all: SInt, Int, LInt, Real, LReal, Bool and Complex. The definition of the first one SInt (Short Integer) is given in below. The definition of the remaing six is left out to keep this document short. They can easily be inferred from the first one and are found in the source code anyway.
    SInt = POINTER TO SIntDesc; 
    SIntDesc = RECORD (ScalarDesc) s*: SHORTINT END;
Before an array of type ARRAY is instantiated, its dimensions with their respective lengths must be instantiated as vector with:
    PROCEDURE SizeVector1 (VAR Vec: SizeVector; x: LONGINT); 
    PROCEDURE SizeVector2 (VAR Vec: SizeVector; x, y: LONGINT); 
    PROCEDURE SizeVector3 (VAR Vec: SizeVector; x, y, z: LONGINT); 
    PROCEDURE SizeVector4 (VAR Vec: SizeVector; x, y, z, u: LONGINT);
where x, y, z, u specify the length of each dimension. As one can see, arrays of up to 4 dimensions are possible. If need be, additional size vectors can be defined and programmed to support other hyperspaces.

An array of SInt elements is instantiated with the procedure:

    PROCEDURE InitSInt (VAR A: Array; dimension: SizeVector; data: SIntPtr; copy: BOOLEAN);
If data = NIL, then the array will contain no data, under the provision that it will receive data at a later stage. Otherwise, the "copy" parameter value will condition the operation. If copy = TRUE, the array will be assigned a copy of the original data, else the data will become part of the array. Six other such Init procedures exist for handling the remaining element types.

For an existing array:

    PROCEDURE Size (A: Array): SizeVector; returns dimension vector 
    PROCEDURE Order (A: Array): LONGINT; returns the number of dimensions 
    PROCEDURE Len (A: Array; dim: LONGINT): LONGINT; returns length of the dimension
The value of an SInt array element at a specified position is returned by the procedure:
    PROCEDURE GetSInt (A: Array; position: SizeVector): SHORTINT;
where position is a vector which must correspond to an element within the boundaries of A. Six other such Get procedures exist for handling the remaining element types.

An array From is copied to an array To with:

    PROCEDURE Copy (From, To: Array);
All the SInt elements of an array A can be transformed by a user-defined monadic algorithm f, using the procedure:
All the SInt elements of an array A can be transformed by a user-defined dyadic operation f on two arrays A and B:
    PROCEDURE AllSInt2 (A, B: Array; f: PROCEDURE (s1, s2: SHORTINT): SHORTINT);
Four other such All procedures pairs (monadic and dyadic) exist for handling element types Int, LInt, Real and LReal.

The data of an array is organized as a linear sequence of elements each having an index which can be inferred from the position vector

    PROCEDURE Index (pos, dimension: ARRAY OF LONGINT): LONGINT;
Conversely, the position vector can be calculated from the index with:
    PROCEDURE CalculatePos (Index: LONGINT; dimension: ARRAY OF LONGINT): SizeVector;
The index in the linear sequence of elements can be computed from the coordinates of an element using one of the procedures:
    PROCEDURE Index1 (A: Array; x: LONGINT): LONGINT; 
    PROCEDURE Index2 (A: Array; x, y: LONGINT): LONGINT; 
    PROCEDURE Index3 (A: Array; x, y, z: LONGINT): LONGINT; 
    PROCEDURE Index4 (A: Array; x, y, z, u: LONGINT): LONGINT;
depending on the number of dimensions. If need be, additional IndexN can be defined and programmed to support other hyperspaces.

Installation and usage

1. Download the modules MultiArrays.Mod, MultiArrayRiders.Mod and compile them.

2. Use Watson to obtain a list of available functions.

3. For each module a Test procedure demonstrates the efficiency of the algorithms compared to the conventional array indexing scheme. These procedures can also be used as examples.

Version log

5.11.2000 First released
19.01.2001 Version 1.0

21 Jan 2001 - Copyright © 2000 ETH Zürich. All rights reserved.
E-Mail: oberon@inf.ethz.ch
Homepage: http://www.ethoberon.ethz.ch/