Hi, I was wondering if I could get some feedback on how I can increase the performance of this section of code, I am relatively new to Julia and I am not to sure if there is a better way to do this:
x = [-88.58, -86.31, -83.89, -83.36]
y = [58.58, 58.49, 58.24, 57.54]
bndxmin = [-95,-95,-95,-90,-90,-90,-85,-85,-85,-80,-80,-95,-95,-90,-85,-80,-85,-90,-95,-95,-95,-90,-85]
bndxmax = [-95,-95,-90,-90,-90,-85,-85,-85,-80,-80,-80,-80,-90,-85,-80,-80,-80,-85,-90,-95,-90,-85,-80]
bndymin = [57.5,52.5,52.5,52.5,57.5,62.5,57.5,52.5,52.5,52.5,57.5,52.5,52.5,52.5,52.5,52.5,57.5,57.5,57.5,57.5,62.5,62.5,62.5]
bndymax = [62.5,57.5,52.5,57.5,62.5,62.5,62.5,57.5,52.5,57.5,62.5,62.5,52.5,52.5,52.5,57.5,57.5,57.5,57.5,62.5,62.5,62.5,62.5]
function getids(x, y, bndxmin, bndxmax, bndymin, bndymax)
ijc = Vector{Union{Array{Float64,2}, Nothing}}(nothing, length(x)-1)
logiArr = zeros(length(bndxmin))
for ii = 1:(length(x)-1)
for jj = 1:length(bndxmin)
@inbounds logiArr[jj] = (bndxmin[jj] <= max(x[ii], x[ii+1])) &
(bndxmax[jj] >= min(x[ii], x[ii+1])) &
(bndymin[jj] <= max(y[ii], y[ii+1])) &
(bndymax[jj] >= min(y[ii], y[ii+1]))
end
idxs = findall(cl -> (cl == 1), logiArr)
if !isempty(idxs)
@inbounds ijc[ii] = [idxs ones(length(idxs))*ii]
end
end
return ijc
end
Profiling the code tells me it is the main body of the For Loop which fills the logiArr and the findall statement that really bogs down the code. Are there any suggestions on how I can make this loop more efficient? Typically x, y, and the bnd variables are on the order 10,000 - 50,000 elements. This section of code is part of larger function that checks where a curve intersects a grid. This particular section of code provides the indices where the x and y cross the bounds of the grid.