specialized-array-reshape Bradley Lucier (06 May 2020 15:40 UTC) Re: specialized-array-reshape John Cowan (06 May 2020 16:16 UTC) Re: specialized-array-reshape Jeffrey Mark Siskind (06 May 2020 16:24 UTC) Re: specialized-array-reshape Bradley Lucier (06 May 2020 19:24 UTC) Re: specialized-array-reshape John Cowan (06 May 2020 19:27 UTC)

specialized-array-reshape Bradley Lucier 06 May 2020 15:40 UTC

```I've been looking at array reshape operators in other languages,
specifically numpy and Matlab.

When we share a specialized array, to ensure efficient indexing of the
multi-indices of the new array into the body of the old array we require
the new index function to have the following property:

The linear distance between elements in the body of an array when
changing the k'th index from \$i_k\$ to \$i_k + 1\$

must be the same as

the linear distance between elements in the body of an array when
changing the k'th index from \$i_k + 1\$ to \$i_k + 2\$.

And this must be true even if the old array is the result of a
combination of other array transformations:

reversing the array in one or more dimensions, permuting the array,
extracting a subarray, ...

To ensure that this is always true, one cannot always, e.g., reshape a 3
x 5 array into a 5 x 3 array, whereas this is allowed in numpy and
Matlab.  (It seems that numpy sometimes copies the array to reshape it,
presumably when it can't reshape it in place.)

I first thought of this transform when thinking that I should be able to
think of a 4-vector as a 2 x 2 matrix, and it's true, one can always
make this transformation.

So the best thing I can think of doing is

(a) implementing this transform (which will be nontrivial), and

(b) explaining the restrictions on reshaping in the SRFI document and
have the error message point directly to the document when the user
tries to do a non-allowed reshaping (especially one that might be
allowed, e.g., in numpy or Matlab).

Ideas? (he cries into the lonely ether ...)

Brad
```