public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Per Bothner <per@bothner.com>
To: Kawa mailing list <kawa@sourceware.org>
Subject: much improved indexing and multi-dimensional arrays
Date: Fri, 11 Mar 2016 07:10:00 -0000	[thread overview]
Message-ID: <56E26F4E.2000003@bothner.com> (raw)

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/

                 reply	other threads:[~2016-03-11  7:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56E26F4E.2000003@bothner.com \
    --to=per@bothner.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).