You are hiding type information from the compiler.
struct bundle_as_array{T<: Real}
x::AbstractArray{T,2}
y::AbstractArray{T,2}
angx::AbstractArray{T,2}# these are direction tangents.
angy::AbstractArray{T,2}
zpos:: Union{AbstractArray{T,2},Real}
end
function (cb::bundle_as_array)()
if length(size(cb.zpos))==2
R0=[[cb.x[i,j].+eps(),cb.y[i,j].+eps(),cb.zpos[i,j].+eps()] for i in 1:size(cb.x)[1],j in 1:size(cb.y)[2]]
else
R0=[[cb.x[i,j].+eps(),cb.y[i,j].+eps(),cb.zpos.+eps()] for i in 1:size(cb.x)[1],j in 1:size(cb.y)[2]]
end
D0=[[sin(cb.angx[i,j]),sin(cb.angy[i,j]),sqrt(1-sin(cb.angx[i,j])^2-sin(cb.angy[i,j])^2)] for i in 1:size(cb.x)[1],j in 1:size(cb.y)[2]]
return R0,D0
end
struct bundle_as_array2{T, V}
x::T
y::T
angx::T
angy::T
zpos::V
end
function (cb::bundle_as_array2)()
if length(size(cb.zpos))==2
R0=[[cb.x[i,j].+eps(),cb.y[i,j].+eps(),cb.zpos[i,j].+eps()] for i in 1:size(cb.x)[1],j in 1:size(cb.y)[2]]
else
R0=[[cb.x[i,j].+eps(),cb.y[i,j].+eps(),cb.zpos.+eps()] for i in 1:size(cb.x)[1],j in 1:size(cb.y)[2]]
end
D0=[[sin(cb.angx[i,j]),sin(cb.angy[i,j]),sqrt(1-sin(cb.angx[i,j])^2-sin(cb.angy[i,j])^2)] for i in 1:size(cb.x)[1],j in 1:size(cb.y)[2]]
return R0,D0
end
eval_bundle = bundle_as_array([0.5 1.], [0.5 1.], [0. 0.], [0. 0.], 0.)
eval_bundle2 = bundle_as_array2([0.5 1.], [0.5 1.], [0. 0.], [0. 0.], 0.)
You are hiding type information from the compiler.
See https://docs.julialang.org/en/v1/manual/performance-tips/