3 ms·
In Julia this would read using broadcasting: X = ones(Int, 1_000_000_000) Y = ones(Int, 1_000_000_000) # explicit dot notation X .+= 2 .* Y
by stabbles 9y ago
In Julia this would read using broadcasting:
X = ones(Int, 1_000_000_000)
Y = ones(Int, 1_000_000_000)
# explicit dot notation
X .+= 2 .* Y
# or with a macro
@. X += 2 * Y
The + and * do not allocate, the operations are fused into element-wise operations so the vectors are traversed only once, and the loop is compiled to vectorized code. No need for Numpy / BLAS.
- FractalNerve 9y agoThat's impressive! What does fusion mean? I've heard fusion multiple times and I've the feel that fusion (in haskell at least) is something very advanced that's not really thought. Can you explain?
- Gravityloss 9y agoTwo passes with one operation each are fused into one pass that has two operations? Too bad common languages today (Python and its extensions for example) are a big step back from Matlab when it comes to matrix and vector operations syntax.