Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/manual_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ end


## Root finding
function gsl_function_helper(x::Cdouble, fn)::Cdouble
try
return fn(x)
catch
return NaN
end
end
gsl_function_helper(x::Cdouble, fn::F) where {F} = fn(x)

# The following code relies on `gsl_function` being a mutable type
# (such that we can call `pointer_from_objref` on it) to simplify the object structure
Expand Down Expand Up @@ -71,10 +65,7 @@ Create a `gsl_function` object.
`f(x::Float64) -> Float64` Return target functions f
"""
macro gsl_function(f)
return :(
gsl_function( @cfunction( (x,p) -> $f(x), Cdouble, (Cdouble, Ptr{Cvoid})),
0 )
)
return :(Base.cconvert(Ref{gsl_function}, $(esc(f)))[1])
end

"""
Expand Down
17 changes: 9 additions & 8 deletions test/quadrature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ using GSL
ws_size = 100
ws = integration_cquad_workspace_alloc(ws_size)

a = 0
b = 1
result = Cdouble[0]
abserr = Cdouble[0]
nevals = Csize_t[0]
integration_cquad(fquad, a, b, 1e-10, 1e-10, ws, result, abserr, nevals)

@test abs(result[] - 1/2.5) < abserr[]
for f in (fquad, @gsl_function(fquad))
a = 0
b = 1
result = Cdouble[0]
abserr = Cdouble[0]
nevals = Csize_t[0]
integration_cquad(f, a, b, 1e-10, 1e-10, ws, result, abserr, nevals)

@test abs(result[] - 1/2.5) < abserr[]
end
integration_cquad_workspace_free(ws)
end