Re: First stab at API for adding new array axes and broadcasting arrays Bradley Lucier (18 Sep 2025 16:24 UTC)

Re: First stab at API for adding new array axes and broadcasting arrays Bradley Lucier 18 Sep 2025 16:24 UTC

On 9/16/25 22:43, Bradley Lucier wrote:
> (array-add-axes array vector)
>
> Sample calls:
>
> (array-add-axes A '#(* 0 1 * 2 * 3))
> (array-add-axes A (vector '* 0 1 '* 2 '* 3))
> (array-add-axes A '#(* * *))      ;; if A is zero-dimensional
>
> Assumes that the first argument A is an array with dimension d.
>
> Assumes the second argument is a vector v whose elements are the exact
> integers 0, 1, ..., d-1, in order, interspersed with zero or more
> instances of the symbol *.

Two points:

1. If we have array-add-axes, should we have its pseudo-inverse,
array-squeeze?  I used array-squeeze as an example in the documentation
but did not include it in the library because it was easy to compute
with more fundamental routines, but maybe if we add array-add-axes we
should also add array-squeeze.

2. There is no real reason that the axis indices must be in order.

Relaxing this condition makes some algorithms easier to write because
SRFI 231 doesn't have any <whatever>-by-axis routines and relies on
array-permute and array-curry to achieve something a bit more general.

Allowing the axis indices to be in any order would make this routine a
generalization of array-permute.

I suppose we could give array-permute the proposed functionality of
array-add-axes, to insert new axes with lower bounds 0 and upper bounds
1, but I'm not too keen on that idea.

Brad