Could anyone make this run faster?

Probably not faster, but more elegant and general:

function Optim∇ᵢWᵢⱼ(αD,q,xᵢⱼ,h)
    # Skip distances outside the support of the kernel:
    if 0 <= q <= 2
        Fac = αD*5*(q-2)^3*q / (8h*(q*h+1e-6)) 
    else
        Fac = 0.0 # or return zero(xᵢⱼ) 
    end
    return Fac .* xᵢⱼ
end
1 Like