> On Sep 14, 2025, at 9:24 PM, Alex Shinn <xxxxxx@gmail.com> wrote:
>
> I'm not sure I would differentiate between APL-style and broadcasting,
> since numpy does separately provide most APL-style operations as you
> note in the SRFI itself. So broadcasting is not "one weird trick" for
> equivalent operations, but rather a solution to a different set of problems.
I’m not going to argue with you about the “one weird trick” thing, but here are some examples of what I meant.
NumPy uses broadcasting to implement inner product:
https://stackoverflow.com/questions/42170477/does-numpy-provide-a-generalized-inner-product
NumPy uses broadcasting to implement outer product:
https://www.reddit.com/r/learnpython/comments/m47htb/numpy_outer_product_of_inner_dimensions_of_two/
(NumPy has an “outer” procedure, but that implements only linear algebra outer product [so specifically with multiplication and addition as the operators], not a general outer product.)
NumPy now does have lambda’s and one can do the equivalent of array-map:
https://stackoverflow.com/questions/35215161/most-efficient-way-to-map-function-over-numpy-array
But not for arrays of arrays, I don’t think, so if you want to apply a partially evaluated function f with one fixed argument to each row of an array, you use broadcasting followed by reduction over a single axis to do it. (And even that isn’t as general as provided by SRFI 231. That’s not a value judgement, it’s just a comparison.)
I don’t know yet what API should be used with array broadcasting. It’s implicit and very easy to specify in NumPy, everything I’ve tried to far in “SRFI 231 style” has been somewhat clumsy.
Because I can’t figure out what the correct notation or API should be for general, NumPy-style, broadcasting, I’m tempted to allow it only at the left end of arrays with explicitly specified array bounds and then people can use array-permute to move the added axes to wherever they’re needed. But that’s just a temptation.
Some languages other than Python have array broadcasting: Stan:
https://mc-stan.org/docs/2_20/functions-reference/array-broadcasting.html
Julia:
https://docs.julialang.org/en/v1/base/arrays/#Broadcast-and-vectorization
Javascript:
https://github.com/stdlib-js/ndarray-base-broadcast-array
Matlab:
https://blogs.mathworks.com/loren/2019/12/19/importance-of-implicit-expansion-for-performance/
https://www.mathworks.com/help/coder/ug/generate-code-with-implicit-expansion-enabled.html
Racket, of course:
https://docs.racket-lang.org/math/array_pointwise.html
So I suppose what we need to decide is (1) How to specify it, (2) what it means, and (3) how to implement it.
Brad