— Scheme Procedure: **make-shared-array**` oldarray mapfunc bound ...`

— C Function:**scm_make_shared_array** (`oldarray, mapfunc, boundlist`)

— C Function:

Return a new array which shares the storage of

oldarray. Changes made through either affect the same underlying storage. Thebound...arguments are the shape of the new array, the same as`make-array`

(see Array Procedures).

mapfunctranslates coordinates from the new array to theoldarray. It's called as`(`

mapfunc`newidx1 ...)`

with one parameter for each dimension of the new array, and should return a list of indices foroldarray, one for each dimension ofoldarray.

mapfuncmust be affine linear, meaning that eacholdarrayindex must be formed by adding integer multiples (possibly negative) of some or all ofnewidx1etc, plus a possible integer offset. The multiples and offset must be the same in each call.One good use for a shared array is to restrict the range of some dimensions, so as to apply say`array-for-each`

or`array-fill!`

to only part of an array. The plain`list`

function can be used formapfuncin this case, making no changes to the index values. For example,(make-shared-array #2((a b c) (d e f) (g h i)) list 3 2) ⇒ #2((a b) (d e) (g h))The new array can have fewer dimensions than

oldarray, for example to take a column from an array.(make-shared-array #2((a b c) (d e f) (g h i)) (lambda (i) (list i 2)) '(0 2)) ⇒ #1(c f i)A diagonal can be taken by using the single new array index for both row and column in the old array. For example,

(make-shared-array #2((a b c) (d e f) (g h i)) (lambda (i) (list i i)) '(0 2)) ⇒ #1(a e i)Dimensions can be increased by for instance considering portions of a one dimensional array as rows in a two dimensional array. (

`array-contents`

below can do the opposite, flattening an array.)(make-shared-array #1(a b c d e f g h i j k l) (lambda (i j) (list (+ (* i 3) j))) 4 3) ⇒ #2((a b c) (d e f) (g h i) (j k l))By negating an index the order that elements appear can be reversed. The following just reverses the column order,

(make-shared-array #2((a b c) (d e f) (g h i)) (lambda (i j) (list i (- 2 j))) 3 3) ⇒ #2((c b a) (f e d) (i h g))A fixed offset on indexes allows for instance a change from a 0 based to a 1 based array,

(define x #2((a b c) (d e f) (g h i))) (define y (make-shared-array x (lambda (i j) (list (1- i) (1- j))) '(1 3) '(1 3))) (array-ref x 0 0) ⇒ a (array-ref y 1 1) ⇒ aA multiple on an index allows every Nth element of an array to be taken. The following is every third element,

(make-shared-array #1(a b c d e f g h i j k l) (lambda (i) (list (* i 3))) 4) ⇒ #1(a d g j)The above examples can be combined to make weird and wonderful selections from an array, but it's important to note that because

mapfuncmust be affine linear, arbitrary permutations are not possible.In the current implementation,

mapfuncis not called for every access to the new array but only on some sample points to establish a base and stride for new array indices inoldarraydata. A few sample points are enough becausemapfuncis linear.

— Scheme Procedure: **shared-array-increments**` array`

— C Function:**scm_shared_array_increments** (`array`)

— C Function:

For each dimension, return the distance between elements in the root vector.

— Scheme Procedure: **shared-array-offset**` array`

— C Function:**scm_shared_array_offset** (`array`)

— C Function:

Return the root vector index of the first element in the array.

— Scheme Procedure: **shared-array-root**` array`

— C Function:**scm_shared_array_root** (`array`)

— C Function:

Return the root vector of a shared array.

— Scheme Procedure: **array-contents**` array `[`strict`]

— C Function:**scm_array_contents** (`array, strict`)

— C Function:

If

arraymay be unrolled into a one dimensional shared array without changing their order (last subscript changing fastest), then`array-contents`

returns that shared array, otherwise it returns`#f`

. All arrays made by`make-array`

and`make-typed-array`

may be unrolled, some arrays made by`make-shared-array`

may not be.If the optional argument

strictis provided, a shared array will be returned only if its elements are stored internally contiguous in memory.

— Scheme Procedure: **transpose-array**` array dim1 ...`

— C Function:**scm_transpose_array** (`array, dimlist`)

— C Function:

Return an array sharing contents with

array, but with dimensions arranged in a different order. There must be onedimargument for each dimension ofarray.dim1,dim2, ... should be integers between 0 and the rank of the array to be returned. Each integer in that range must appear at least once in the argument list.The values of

dim1,dim2, ... correspond to dimensions in the array to be returned, and their positions in the argument list to dimensions ofarray. Severaldims may have the same value, in which case the returned array will have smaller rank thanarray.(transpose-array '#2((a b) (c d)) 1 0) ⇒ #2((a c) (b d)) (transpose-array '#2((a b) (c d)) 0 0) ⇒ #1(a d) (transpose-array '#3(((a b c) (d e f)) ((1 2 3) (4 5 6))) 1 1 0) ⇒ #2((a 4) (b 5) (c 6))