I’m trying to get an understanding on how to (most efficiently) handle elementwise array operations. If I construct an image like

```
function myImg(pts::Integer)::Array{Float64,2}
# variables
# rotation of ellipse
aEll = 35.0/180.0*pi
axes = [1/6,1/25]
values = collect(linspace(-0.5,0.5,pts))
# meshes
gridX = [i for i in values, j in values]
gridY = [j for i in values, j in values]
# generate ellipse
# rotate by alpha
Xr = cos(aEll).*gridX - sin(aEll).*gridY
Yr = cos(aEll).*gridY + sin(aEll).*gridX
img = ((1/axes[1]*Xr.^2 + 1/axes[2]*Yr.^2).<=1).*( 10*pi*Yr);
return mod(img-pi,2*pi)+pi
end
@time myImg(1024);
```

then I admit, the code is mainly taken from MatLab (despite the `meshgrid`

function is replaced by the lines for `Xr`

and `Yr`

, that’s what I worked with the last years).

I would like to do this – merely to lean how Julia works – as efficient as possible: Take the equidistant grid of `1024`

points on `[0,1]`

in a rotated manner in order to build an ellipse with main axes `axes`

and a linear increase inside (along the rotated `y`

direction).

For now this code takes on my machine `0.552937 seconds (45.96 k allocations: 163.213 MB, 41.35% gc time)`

(while MatLab takes for the same roughly `0.15 seconds`

). This increases in both allocations and and time if I would add two more such elements on rotated grids (circles, squares,…); my approach to for-loops was indeed even slower…

TL;DR: How can I get such an element wise array construction as efficient as possible (mainly w.r.t. time, memory would be nice but not necessary)?