@@ -34,6 +34,13 @@ class BOUNDS(ctypes.Structure):
34
34
POINTER (c_double ), POINTER (c_int ), POINTER (c_double ), c_void_p )
35
35
peakfinder_type = ctypes .CFUNCTYPE (c_void_p , POINTER (c_int ), POINTER (BOUNDS ),
36
36
POINTER (c_int ), POINTER (c_double ))
37
+
38
+ def wrap_integrand (integrand ):
39
+ use_raw_callback = isinstance (integrand , ctypes ._CFuncPtr )
40
+ if use_raw_callback :
41
+ return integrand
42
+ else :
43
+ return integrand_type (integrand )
37
44
38
45
def Vegas (integrand , ndim , userdata = NULL ,
39
46
epsrel = EPSREL , epsabs = EPSABS , verbose = 0 , ncomp = 1 , seed = None ,
@@ -92,7 +99,7 @@ def integrand(ndim, x, ncomp, f, userdata, weight, iter):
92
99
if seed is None :
93
100
seed = 0
94
101
95
- lib .Vegas (ndim , ncomp , integrand_type (integrand ), userdata ,
102
+ lib .Vegas (ndim , ncomp , wrap_integrand (integrand ), userdata ,
96
103
c_int (nvec ), c_double (epsrel ), c_double (epsabs ), verbose , seed ,
97
104
mineval , maxeval , nstart , nincrease , nbatch ,
98
105
gridno , statefile , spin ,
@@ -137,7 +144,7 @@ def Suave(integrand, ndim, nnew=1000, nmin=2, flatness=50., userdata=NULL,
137
144
if seed is None :
138
145
seed = 0
139
146
140
- lib .Suave (ndim , ncomp , integrand_type (integrand ), userdata ,
147
+ lib .Suave (ndim , ncomp , wrap_integrand (integrand ), userdata ,
141
148
c_int (nvec ), c_double (epsrel ), c_double (epsabs ), verbose , seed ,
142
149
mineval , maxeval , nnew , nmin , c_double (flatness ), statefile , spin ,
143
150
byref (nregions ), byref (neval ), byref (fail ), integral , error , prob )
@@ -280,7 +287,7 @@ def integrand(ndim, x, ncomp, f, phase):
280
287
if seed is None :
281
288
seed = 0
282
289
283
- lib .Divonne (ndim , ncomp , integrand_type (integrand ), userdata ,
290
+ lib .Divonne (ndim , ncomp , wrap_integrand (integrand ), userdata ,
284
291
c_int (nvec ), c_double (epsrel ), c_double (epsabs ), verbose , seed ,
285
292
mineval , maxeval , key1 , key2 , key3 , maxpass ,
286
293
c_double (border ), c_double (maxchisq ), c_double (mindeviation ),
@@ -318,7 +325,7 @@ def Cuhre(integrand, ndim,
318
325
if seed is None :
319
326
seed = 0
320
327
321
- lib .Cuhre (ndim , ncomp , integrand_type (integrand ), userdata ,
328
+ lib .Cuhre (ndim , ncomp , wrap_integrand (integrand ), userdata ,
322
329
c_int (nvec ), c_double (epsrel ), c_double (epsabs ), verbose ,
323
330
mineval , maxeval , key , statefile , spin ,
324
331
byref (nregions ), byref (neval ), byref (fail ), integral , error , prob )
0 commit comments