Re: array with index mapper - Java-based implementation Per Bothner 24 Aug 2015 19:40 UTC


On 08/24/2015 11:24 AM, John Cowan wrote:
> Per Bothner scripsit:
>
>> A fixed array consists of an indexer (a general integer array)
>> and a backing store (a uniform or general vector).
>
> As I noted in an earlier email, hash tables (from integers to objects)
> are also appropriate backing stores and should be supported.

That will be supported by Kawa by wrapping the hash table as a
java.util.List.

> In addition,
> it would be useful to allow bytevectors seen as uniform arrays per R6RS.

Of course.

>> Indexing the fixed array uses the indexer to transforms the source indexes
>> to an index in the backing store vector.
>
> But how?  (I have not tried to make my way through the Java code.)

There is an IntArray interface which maps a sequence of integers
to a single integer.  The array classes use this interface.  You can
create an arbitrary implementation of this interface.

I just noticed hte email sketch has a confusing bug: It has both an interface
named IntArray and an abstract class class named IntArray, which should
be renamed (probably) AbstractIntArray.   There are references to IntVector
which should be AbstractIntArray.  It should be:

public interface IntArray extends Array<Integer> {
     ...
}

abstract class AbstractIntArray<E> extends AbstractArray<E> {
     int[] data;
     ....
}

// Scheme: array[int] == s32array
public class S32Array extends AbstractIntArray<Integer> implements IntArray {
     ...
}

// Scheme: array[uint] == u32array
public class U32Array extends AbstractIntArray<UInt> {
     ...
}

A "plain" fixed array of integers is an S32Array, which implements the
IntArray interface, so you can use that as the index mapper.

Of course other implementations are possible ...

> In particular, are you using the NumPy/Julia stride model, in which
> indexer[n] gives the distance (measured in backing-store-elements) between
> consecutive elements that differ by 1 in dimension n?  If not, I strongly
> recommend it.  It is an encoded form of the affine transformations of
> SRFI 25.
>
> In addition, there should be an offset, conceptually part of the indexer,
> which is added to the final computation.  This corresponds to the constant
> part of the SRFI-25 affine transformation.

Yes.  That would be the ArrayMapper class, which implements IntArray,
just as you say.
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/