how to solve a weired swig python c++ interfacing type error
Posted
by
user2981648
on Stack Overflow
See other posts from Stack Overflow
or by user2981648
Published on 2013-11-12T03:50:17Z
Indexed on
2013/11/12
3:53 UTC
Read the original article
Hit count: 170
I want to use swig to switch a simple cpp function to python and use "scipy.integrate.quadrature" function to calculate the integration. But python 2.7 reports a type error. Do you guys know what is going on here? Thanks a lot. Furthermore, "scipy.integrate.quad" runs smoothly. So is there something special for "scipy.integrate.quadrature" function?
The code is in the following:
File "testfunctions.h":
#ifndef TESTFUNCTIONS_H
#define TESTFUNCTIONS_H
double test_square(double x);
#endif
File "testfunctions.cpp":
#include "testfunctions.h"
double test_square(double x)
{
return x * x;
}
File "swig_test.i" :
/* File : swig_test.i */
%module swig_test
%{
#include "testfunctions.h"
%}
/* Let's just grab the original header file here */
%include "testfunctions.h"
File "test.py":
import scipy.integrate
import _swig_test
print scipy.integrate.quadrature(_swig_test.test_square, 0., 1.)
error info:
UMD has deleted: _swig_test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 523, in runfile
execfile(filename, namespace)
File "D:\data\haitaliu\Desktop\Projects\swig_test\Release\test.py", line 4, in <module>
print scipy.integrate.quadrature(_swig_test.test_square, 0., 1.)
File "C:\Python27\lib\site-packages\scipy\integrate\quadrature.py", line 161, in quadrature
newval = fixed_quad(vfunc, a, b, (), n)[0]
File "C:\Python27\lib\site-packages\scipy\integrate\quadrature.py", line 61, in fixed_quad
return (b-a)/2.0*sum(w*func(y,*args),0), None
File "C:\Python27\lib\site-packages\scipy\integrate\quadrature.py", line 90, in vfunc
return func(x, *args)
TypeError: in method 'test_square', argument 1 of type 'double'
© Stack Overflow or respective owner