Re: array with index mapper - Java-based implementation Per Bothner 26 Aug 2015 20:37 UTC


On 08/26/2015 06:50 PM, John Cowan wrote:
> Bradley Lucier scripsit:
>
>>> A general array has a getter that maps an interval to a value.
>>
>> Shouldn't the array carry around interval with it? Maybe I don't understand.
>
> I think the idea is that the getter is passed the array's interval (but
> not the array's body) and returns an index into the body.
> So unlike your getter, this function does not actually do any getting:
> it just transforms a specific set of indices into a single index.

Sorry for poor phrasing.

First, I use the term "interface" in the object-oriented
(specifically Java) sense: An abstract class (or a "contract")
with no implementation and only specification of method signatures.

An "abstract array" is an interface that has a getter method
that maps 0 or more integer (fixnum) indexes to a value.  It has
other methods - like bounds inquiry, and an optional setter
(which we will ignore in this discussion).

A "general array" is an implementation of an abstract array that has two
properties (fields):
(1) A backing store, which is a plain vector (possibly uniform).
(In general the backing store could be lazy or a sparse, as long
as it implements the "vector interface".)
(2) A mapper object.  The type of this field "integer array" - i.e.
abstract array, restricted to integer values.  The mapper can be a
general array, or any other object that implements the abstract
integer array interface.

The getter method of a general array calls the getter method
of the mapper object and uses the result to index into the
backing store.  This getter method is fixed for general
arrays - it is not an overridable hook.  (It is 'final'
in the Java sense.)

The most common mapper object is a single affine transform
that multiplies each index by a fixed value, and adds them
together along with an initial offset.

There may be subclasses of general array that uses different
backing store implementations and/or impose restrictions
on the element type or rank. Having multiple subclasses
is primarily to aid performance tuning or compile-time
tyoe-checking: The basic general array class using a plain
vector as backing store is quite general (as long as you
don't need laziness, sparse arrays, or things like that.)

The design has custom subclasses for various number types,
using uniform arrays for the backing store (or in Kawa: Java native arrays).
This is to enable efficient code without needless heap allocation.

The interval/shape/dimensions and rank of a general array
is that of the mapper object.

A vector is a general array, restricted to rank 1, and a
lower index bound of 0.

You can index any (abstract) array with either an integer
or an integer array.  If the argument is general array, then
the result is another general array that shares the same backing store.
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/