public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* much improved indexing and multi-dimensional arrays
@ 2016-03-11  7:10 Per Bothner
  0 siblings, 0 replies; only message in thread
From: Per Bothner @ 2016-03-11  7:10 UTC (permalink / raw)
  To: Kawa mailing list

I just checked in major change in how vectors and arrays are handled in Kawa.

The previous array-as-index feature has been generalized:

If A is an array (including a vector), then the expression: (A I J K ...)
in general evaluates to an array B such that:
   (B i1 i2 ... j1 j2 ... k1 k2 ... ...)
is
   (A (I i1 i2 ..) (J j1 j2 ...) (K k1 k2 ...) ...)

If an index I is an integer, it is treated as a zero-index array - a scalar.

For example: if

   (define B (A 2 [4 <: 10]))

then (B i) is (A 2 (+ i 4))

The following new procedures were added:
array-size, array-fill!, array-copy!, array-index-ref, array-index-share, array-transform, array-reshape, array-flatten, array->vector, index-array, build-array.

(array-index-ref A I J K ...) is the above indexing - i.e the same as (A I j K ...).
It creates a read-only copy (possibly copy-on-write).

(array-index-share A I J K ...) is like array-index-ref but creates a modifiable view into A.

(build-array SHAPE PROCEDURE) is a general constructor for lazy arrays:
If A is the result, the (A i j k ...) is (PROCEDURE [I J K ...]).

array-transform creates a view, with a mapping of the indexes.

When a procedures takes a SHAPE it can be one of:
   #2A(lo1 hi1) ...(loR hiR))
   [hi1 ... hrR]
   [[lo <: hi] ... [loR <: hiR]]

The result of these are the same as the Racket math library, though we allow
non-zero lower bounds.

A vector is basically array of rank 1 with a zero lower bound.

Documentation is in-progress.

Code using arrays can be reasonably efficient, however, it has not been
optimized yet.  that is planned.  When array types are implemented, you
should (for example) be able to use arrays of doubles without boxing
(object allocation).
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-03-11  7:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-11  7:10 much improved indexing and multi-dimensional arrays Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).