AUTOMAP: How to do NumPy-style broadcasting in Futhark (but better) (futhark-lang.org)
from armchair_progamer@programming.dev to programming_languages@programming.dev on 18 Jun 2024 04:42
https://programming.dev/post/15671924

NumPy-style broadcasting = being able to write code like

[[1, 2, 3],
 [4, 5, 6],  + [10, 11, 12]
 [7, 8, 9]]

and have it evaluate the same as

              [[1, 2, 3],
map (map (+))  [4, 5, 6],  (rep 3 [10, 11, 12])
               [7, 8, 9]]

(which evaluates to [[11, 13, 15], [14, 16, 18], [18, 19, 21]]).

numpy docs. Numpy and most other languages do this at runtime, which is typically easier. But Futhark is statically-typed, so the type of the result must be known at compile time, and this means the broadcasting must also be done at compile time.

#programming_languages

threaded - newest