This is the mail archive of the
gsl-discuss@sourceware.cygnus.com
mailing list for the GSL project.
Problems with integration when wrapping it for Python.
- To: gsl-discuss at sourceware dot cygnus dot com
- Subject: Problems with integration when wrapping it for Python.
- From: Vanroose Wim <vanroose at ruca dot ua dot ac dot be>
- Date: Fri, 28 Apr 2000 22:03:28 +0200
Dear Sir, Madam,
I am new to GSL discuss list.
I recently started to use the GSL library to do calculations in
physics. Previously I used a collection of fortran function that I
f2c'd to use in C++, python and C. So I am very happy with the GSL
library, It makes my life easier.
I used the integration package to do some integrations in C. The
program works fine and gives very accurate results. My pure C program
was based on the example included in the on-line manual.
But when I tried to wrap the function that calculates the integral
into a "shared library" to be used by python. the troubles start. I
seems that as soon as I allocate the memory with
"gsl_integration_workspace" my application crashes.
Does anybody has the same experiences.
I include some code snippets of the example, When I eleminate the
integration application in "calculate" and just return a number it works
fine but as soon I allocate the workspace the problems start
##############################################################################
double calculate( double oscillatorL, int n,int m){
double output,error;
gsl_integration_workspace * w = gsl_integration_workspace_alloc(1000);
gsl_function F;
struct integration_params p;
F.function = &integrationformula;
F.params = &p;
p.n=n;
p.m=m;
p.b=oscillatorL;
gsl_integration_qag(&F, 0, 30, 0, 1e-5, 1000, 4,w, &output, &error);
return output;
}
static PyObject * matrix(PyObject *self, PyObject *args){
double oscillatorL;
if(!PyArg_ParseTuple(args,"d",&oscillatorL)
return NULL;
return Py_BuildValue("f",calculate(oscillatorL,1,1));
}
static PyMethodDef potentialMethods[] = {
{"matrix",matrix,1},
{"wim",wim,1},
{NULL,NULL}
};
void initpotential(){
PyObject *m, *d;
m = Py_InitModule("potential", potentialMethods);
import_array();
d = PyModule_GetDict(m);
}
#############################################################################
MakeFile
potential: potential.c
gcc -c -fpic potential -I$(PYTHONINCL) -I$(GSLINCLUDE)
gcc -shared -fpic -o potentialmodule.sl potential.o -L(GSLLIB)
-lgslspecfunc -lgslerr -lgslintegration -lm