[...]
Sorry, I don't follow how you derive broadcasting from array-lift.
It seems to handle padding leading missing dimensions, but not
repeating aligned dimensions of trivial width.
For broadcasting array A into interval I, the result has
(max (array-dimension A) (interval-dimension I))
dimensions. If the intervals are already equal, the result
is the same (just return A).
On 8/28/24 2:10 PM, Bradley Lucier wrote:
> I now understand that array broadcasting (or at least array-lift as
> described below) can be framed as a "Bawden-style" array transformation.
This statement is incorrect in an interesting way---array-lift as
defined in the previous email employs an affine mapping of the
multi-index argument, but that mapping is not one-to-one on the new
domain to the old domain, it is necessarily many-to-one.
To be honest, I didn't realize this could be framed as a
"Bawden-style" array transformation myself right away.
My original array arithmetic operations handled two cases:
arrays of the same size, and an array with a scalar. When
I had need of a vector broadcast to an array, I decided to
implement the full numpy broadcasting rules. The result
was a horrific mess of looping and currying that took me
ages to get working. After this was complete I was
lamenting the poor performance, and it occurred to me
that it should work as an affine transformation. Not so much
intuitively but by the simple fact that the width 1 dimensions
already had a 0 coefficient and just keeping that would give
the same element for any width.
You raise a very good point that this is not strictly valid
because the SRFI requires a "one-to-one" affine mapping.
As you note, mutating the result will never make sense.
Perhaps as a refinement, specialized-array-share can
take an optional immutable? parameter, which if true
removes the "one-to-one" requirement.
--
Alex