This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home.

Source for wiki AdvancedArraysCowan version 5

author

cowan

comment


    

ipnr

198.185.18.207

name

AdvancedArraysCowan

readonly

0

text

This is a continuation of ArraysCowan, put on a separate page for convenience.

== Advanced procedures ==

These procedures are mostly derived in function, and sometimes in name, from ISO/IEC 8485 and ISO 17351, which standardize basic and extended APL respectively.

`(array-collapse `''array''` `''j''`)`

Let ''k'' be the rank of ''array''.  This procedure constructs and returns an array of rank ''j'', which MUST be less than or equal to ''k'', whose components are arrays of rank ''k'' - ''j''.  The shape of the returned array is equal to the first ''j'' components of the shape of ''array'', and the shapes of its subarrays are equal to the remaining ''k''-''j'' components.

`(array-explode `''array''` `''j''`)`

Let ''k'' be the rank of ''array''.  This procedure constructs and returns an array of rank ''j'', which MUST be greater than or equal to ''k''.  Each component of ''array'' MUST be an array of rank ''j'' - ''k'', all of which MUST have the same shape.  The shape of the returned array is the shape of ''array'' concatenated with the shape of any of its components, and each component is the corresponding component of the corresponding subarray of ''array''.

`(array-reshape `''shape''` `''array''`)`

Constructs and returns a new array of shape ''shape'' whose components in row-major order are the same (in the sense of `eqv?`) as the components of ''array'' in row-major order.

`(array-reverse `''array''` `''axis''`)`

Constructs and returns an array with the same shape as ''array'', but whose elements on the specified ''axis'' are reversed.  ''Axis'' must be a non-negative integer less than the rank of ''array''.

`(array-reverse! `''array''` `''axis''`)`

Overwrites ''array'' with the value of `(array-reverse `''array''` `''axis''`)`, but without allocating storage.

`(array-compress `''array''` `''booleans''` `''axis''`)`

`(array-expand `''array''` `''booleans''` `''nil''` `''axis''`)`

`(array-rearrange `''array''` `''vector''` `''axis''`)`

`(array-rearrange-axes `''array''` `''vector''`)`

`(subarray `''array''` `''start-subscripts''` `''end-subscripts''`)`

Constructs and returns a smaller array with the same rank as ''array'' whose elements begin at the "lower left" corner specified by the list ''start-subscripts'' and end at the "upper right" corner specified by the list ''end-subscripts''.

`(array-recursive-ref `''array''` `''subscript'' ...`)`

Applies `array-ref` to the ''array'' using the first ''i'' subscripts, where ''i'' is the rank of ''array''.  If there are more subscripts, the result MUST be an array. Apply `array-ref` to the result using the next ''j'' subscripts, where ''j'' is the rank of the result.  Repeat until there are no more subscripts, returning the last result.


== Higher-order procedures ==

These procedures are mostly derived in function, and sometimes in name, from ISO/IEC 8485 and ISO 17351, which standardize basic and extended APL respectively.

`(array-reduce `''proc''` `''array''` `''axis''`)`

Constructs and returns an array whose rank is one less than the rank of ''array'', by combining all the elements along ''axis'' using ''proc'', which MUST be a two-argument procedure.  The order and number of invocations of ''proc'' is unspecified.  If there is only one such element, it is unchanged.

`(array-reduce-by-groups`''proc''` `''array''` `''axis''` `''n''`)`

Constructs and returns an array with the same rank as the rank of ''array'', by combining all the groups of elements of length ''n'' along ''axis'' using ''proc'', which MUST be a two-argument procedure.  The order and number of invocations of ''proc'' is unspecified.  If there is only one such group of elements, it is unchanged.

`(array-scan `''proc''` `''array''` `''axis''`)`

Constructs and returns an array whose shape is the same as the shape of ''array''.  Each element along ''axis'' is constructed by reducing (as if by `array-reduce`) successive prefixes of the elements of ''array'' along that axis.

`(array-outer-product `''proc''` `''array1''` `''array2''`)`

Constructs and returns an array whose shape is the concatenation of the shapes of ''array1'' and ''array2''.  Each component of the new array is the result of applying ''proc'' to every element of ''array1'' and every element of ''array2''.  The order and number of invocations of ''proc'' is unspecified.

`(array-inner-product `''proc1''` `''proc2''` `''array1''` `''array2''`)`

Constructs and returns an array whose shape is equal to the shape of ''array1'' without its last element concatenated with the shape of ''array2'' without its first element; these elements MUST be numerically equal.  It is an error if both arrays have rank 0.

Each element of the result array results from applying ''proc2'' to the corresponding elements of the last vectors of ''array1'' and the first vectors of ''array2'' and then reducing them with ''proc1'' to a single value.  The order and number of invocations of the procedures is unspecified.

In particular, if both arrays have rank 1, the last and first vectors are the whole of the arrays, and the result has rank 0; if both arrays have rank 2, the last vectors of ''array1'' are the column-wise vectors, and the first vectors of ''array2'' are the row-wise vectors, and the result has rank 2.

Example:  `(array-inner-product + * `''vector1''` `''vector2''`)` computes the usual inner product of ''vector1'' and ''vector2''.

time

2010-10-23 03:18:20

version

5