From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92421 invoked by alias); 11 Mar 2016 07:10:18 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 92400 invoked by uid 89); 11 Mar 2016 07:10:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL,BAYES_40,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=HTo:U*kawa, kawa, Hx-languages-length:1804, H*r:sk:kawa@so X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 11 Mar 2016 07:10:14 +0000 Received: from [10.9.9.210] (helo=mailfront10.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1aeHD8-0007F2-Km for kawa@sourceware.org; Fri, 11 Mar 2016 08:10:10 +0100 Received: from 70-36-239-75.dsl.dynamic.fusionbroadband.com ([70.36.239.75] helo=toshie.bothner.com) by mailfront10.runbox.com with esmtpsa (uid:757155 ) (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) id 1aeHD6-0003U7-Uy for kawa@sourceware.org; Fri, 11 Mar 2016 08:10:09 +0100 To: Kawa mailing list From: Per Bothner Subject: much improved indexing and multi-dimensional arrays Message-ID: <56E26F4E.2000003@bothner.com> Date: Fri, 11 Mar 2016 07:10:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-q1/txt/msg00038.txt.bz2 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/