One more thing, maybe it’ll help. It looks like the central (and most heavy computational) function of your package is RunSR, which in turn has niterations option. If it possible to rewrite your algorithm in a way that BINOP! function would be called multiple times for the same i, then issue of dynamical dispatch will be complete gone. I mean, if it is possible to do something like
function RunSR(x, y, niterations, options)
# ... some preliminary calculations
BINOP!(x, y, niterations, i, options)
# ... some preliminary calculations
end
function BINOP!(x::Array, y, niterations, i, options)
op = options.binop[i]
BINOP!(op, x, y, niterations)
end
function BINOP!(op, x, y, niterations)
for k = 1:niterations
broadcast!(op, x, x, y)
# ... do some other calculations
end
end
It’s just an idea, but I hope it is clear - push dynamic dispatch as early in your calculations as possible and proceed to work with well defined types. This way you can avoid meta programming completely.