chickadee » srfi-179 » array-tile

array-tile A Sprocedure

Assume that A is an array and S is a vector of positive, exact integers. The routine array-tile returns a new immutable array $T$, each entry of which is a subarray of A whose domain has sidelengths given (mostly) by the entries of S. These subarrays completely "tile" A, in the sense that every entry in A is an entry of precisely one entry of the result $T$.

More formally, if S is the vector $(s_0,\ldots,s_{d-1})$, and the domain of A is the interval $[l_0,u_0)\times\cdots\times [l_{d-1},u_{d-1})$, then $T$ is an immutable array with all lower bounds zero and upper bounds given by $$ \operatorname{ceiling}((u_0-l_0)/s_0),\ldots,\operatorname{ceiling}((u_{d-1}-l_{d-1})/s_{d-1}). $$ The $i_0,\ldots,i_{d-1}$ entry of $T$ is (array-extract A D_i) with the interval D_i given by $$ [l_0+i_0*s_0,\min(l_0+(i_0+1)s_0,u_0))\times\cdots\times[l_{d-1}+i_{d-1}*s_{d-1},\min(l_{d-1}+(i_{d-1}+1)s_{d-1},u_{d-1})). $$ (The "minimum" operators are necessary if $u_j-l_j$ is not divisible by $s_j$.) Thus, each entry of $T$ will be a specialized, mutable, or immutable array, depending on the type of the input array A.

It is an error if the arguments of array-tile do not satisfy these conditions.

If A is a specialized array, the subarrays of the result inherit safety and mutability from A.

Note: The routines array-tile and array-curry both decompose an array into subarrays, but in different ways. For example, if A is defined as (make-array (make-interval '#(10 10)) list), then (array-tile A '#(1 10)) returns an array with domain (make-interval '#(10 1)), each element of which is an array with domain (make-interval '#(1 10)) (i.e., a two-dimensional array whose elements are two-dimensional arrays), while (array-curry A 1) returns an array with domain (make-interval '#(10)), each element of which has domain (make-interval '#(10)) (i.e., a one-dimensional array whose elements are one-dimensional arrays).