Common Lisp `row-major-aref` John Cowan (02 Sep 2023 06:08 UTC)
Re: Common Lisp `row-major-aref` Per Bothner (02 Sep 2023 15:35 UTC)
Re: Common Lisp `row-major-aref` John Cowan (02 Sep 2023 22:04 UTC)
(missing)
Re: Common Lisp `row-major-aref` Per Bothner (03 Sep 2023 04:32 UTC)
Re: Common Lisp `row-major-aref` John Cowan (03 Sep 2023 05:11 UTC)
Re: Common Lisp `row-major-aref` Bradley Lucier (09 Sep 2023 23:34 UTC)
Re: Common Lisp `row-major-aref` Per Bothner (11 Sep 2023 00:41 UTC)

Re: Common Lisp `row-major-aref` Per Bothner 03 Sep 2023 04:32 UTC


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
xxxxxx@bothner.com   http://per.bothner.com/