-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve user interface #3
Comments
You shouldn't need to use function generic_integrand!(ndim::Cint, xx::Ptr{Cdouble}, ncomp::Cint, ff::Ptr{Cdouble}, func_::Ptr{Void})
x = pointer_to_array(xx, (ndim,))
f = pointer_to_array(ff, (ncomp,))
func! = unsafe_pointer_to_objref(func_)::Function
func!(f, x) # call the user's function to compute f = func(x), in-place
return Cint(0)
end
const c_generic_integrand! = cfunction(generic_integrand!, Cint, (Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}) and then call Cubu by passing Note that Note also that This requires's the user's function to act in-place on the output. It would be more natural to just let the user return an iterable result (e.g. a single result for function generic_integrand(ndim::Cint, xx::Ptr{Cdouble}, ncomp::Cint, ff::Ptr{Cdouble}, func_::Ptr{Void})
x = pointer_to_array(xx, (ndim,))
func = unsafe_pointer_to_objref(func_)::Function
y = func(f, x)
length(y) != ncomp && return Cint(1) # error
for i = 1:length(y)
unsafe_store!(ff, y[i], i)
end
return Cint(0)
end
const c_generic_integrand = cfunction(generic_integrand, Cint, (Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}) (I haven't tested this, so I may have some typos and other errors, but this should give you the general idea.) |
Thanks for the suggestions! Looking at I tested both solutions you suggested, and I found that while the second one is more natural, the first one is faster, and I prefer speed over ease of use, I think I'll go for the first way. In addition, that would be exactly the same kind of functions required by |
Currently, users have to write their own integrand functions using this awkward boilerplate:
It would be better to let users directly call integrator functions with something like this:
Commit e61c7f1 in branch
ui
enables this feature, but that implementation (usingeval
) is really _slow_ ever for simple integrand functionsThe text was updated successfully, but these errors were encountered: