Broadcasting in Julia (Illustrated)
blog.glcs.io
blog.glcs.io
f(x,y) = cos(x)*sin(y)
g(x,y) = tan(x)*inv(y)
x, y = (rand(4), rand(4))
z = rand(4)
z .= f.(x,y') .+ g.(x',y)
to create create one loop that creates whole matrix of results and writes in-place into z. Is there a syntax for that in modern Fortran? I know that it has intrinsic functions which accepts vectors but its this fusion of multiple operations mixed with how it handles differently-sized objects that really defines the braodcasting operation.1. caller based. As a user, I can ask for a broadcasted version of any function (not only specific functions which implement broadcasting)
2. composable. The expression `sqrt.(exp.(x).+1)` in julia will generate a single loop over `x` compared to the numpy version which will make 3 passes over the memory.