On 9/2/23 20:51, Lucier, Bradley J wrote:
Then row-major-aref would be

(define (row-major-aref array n)
   (apply array-ref array ((reverse-indexer (array-domain array)) n)))

It’s true that SRFI 231 does not provide a function like reverse-indexer.

I believe that SRFI 164 (and Kawa) relies on such a function for various 
procedures; Per can correct me if I’m wrong.

Not sure what you're referring to, but perhaps it is the following:

Kawa does divide indexing into two parts:
(1) Combining multiple indexes to a single "effective index" (a 32-bit int).
(2) Lookup from effective index to value.  Or setting element using
effective index and new value.

I believe this separation was partly to improve performance (including
minimizing boxing) without having a combinatorial explosion of methods.

If I recall correctly, the effective index is basically unspecified:
It may be the same as the row-major index but doesn't have to be.
If the array has an underlying vector (or is a simple gvector),
the effective index is an index into the underlying vector.

There is also a helper method rowMajorToEffectiveIndex which maps
a row-major index to the effective index. This is used by
array->vector (which returns a view) and array-flatten (which returns a copy).

--
        --Per Bothner
[email protected]   http://per.bothner.com/

Reply via email to