Howdy, folks.
I have a code which allows for a user defined function. I do this with a struct:
Base.@kwdef mutable struct Solver{T<:Function}
Δt :: Float64 = 0.3
t :: Float64 = 0.0
...
kinematicVelocity :: T = (_...) -> SA_F64[0,0,0]
end
So the user can create an arbitrary function and put it in that struct, which is used throughout the code and is its main input.
This works ok, but I don’t love it as a solution. It’s ok when I’m using the CPU version of my code, but for the GPU I don’t really know how to pass an arbitrary function within a struct do it.
I need to make another one of these user defined functions and I’m wondering about the best way to do it (this function needs to work on the GPU, unlike that other function). One option I thought of was to pass it as a string within that struct and eval
it in my code.
The other option I can think of is to let the user simply declare that function before calling my code, overriding my default one. Not sure there are some caveats to doing that.
Has anyone else run into this before? Any clever solutions that I haven’t thought of?
Thanks a lot!