[SciPy-Dev] Integrate.Quad w/ Ctypes Function - Linux Error

Brian Lee Newsom Brian.Newsom at Colorado.EDU
Mon Oct 7 23:19:11 EDT 2013


Hi all,

I believe I have found a bug in Integrate.Quad's handling of ctypes
functions (at least on linux systems)  It seems to throw the following
error for functions of dimensions higher than 1.  The following code works
on OSX but not on either of two ubuntu systems I've tested.

  File "test.py", line 10, in <module>
    print quad(testlib.twoD,-1,1,(0,))
  File
"/usr/local/lib/python2.7/dist-packages/scipy/integrate/quadpack.py", line
252, in quad
    retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
  File
"/usr/local/lib/python2.7/dist-packages/scipy/integrate/quadpack.py", line
317, in _quad
    return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
quadpack.error: quad: first argument is a ctypes function pointer with
incorrect signature

To reproduce:
create c function test.c

///////////////////////////test.c\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#include <stdio.h>
double oneD(double* x);
double twoD(double* x, double* y);
int main(){
    return 0;
}
double oneD(double* x){
  return *x+2.0;
}
double twoD(double* x, double* y){
  return (*x)*(*x) + (*y)*(*y);
}
///////////////////////////test.c\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Compile to a library in same directory with gcc:
OSX: gcc -dynamiclib -o testlib.dylib
Linux: gcc -shared -o testlib.so -fPIC test.c

Then we run the following python file:
///////////////////////////test.py\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
from ctypes import *
from scipy.integrate import quad
testlib = CDLL('./testlib.so') #use .dylib for osx
testlib.oneD.restype = c_double
testlib.oneD.argtypes = (c_double,)
testlib.twoD.restype = c_double
testlib.twoD.argtypes = (c_double, c_double)
#import pdb;pdb.set_trace()
print quad(testlib.oneD,-1,1)
print quad(testlib.twoD,-1,1,(0,))
///////////////////////////test.py\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

oneD works fine, but moving to twoD on ubuntu throws the above error for
whatever reason, while it runs fine on OSX.

If anyone has suggestions or requires any further info, let me know.  It
would also be helpful if someone could confirm this on other systems.

If nothing is immediately evident I plan to submit it to the git issues,
and was curious - what info specifically should I include with that formal
bug report?

Thanks,

Brian Newsom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20131007/6c272f66/attachment.html>


More information about the SciPy-Dev mailing list