1 
2 %{
3 #include <gsl/gsl_complex_math.h>
4 %}
5 
6 %typemap(in) gsl_complex {
7   Py_complex temp;
8   if (!PyComplex_Check($input)) {
9     PyErr_SetString(PyExc_ValueError,"Expected a complex");
10     return NULL;
11   }
12   temp = PyComplex_AsCComplex($input);
13   $1.dat[0] = temp.real;
14   $1.dat[1] = temp.imag;
15 };
16 
17 %typemap(out) gsl_complex {
18   Py_complex temp;
19   temp.real = $1.dat[0];
20   temp.imag = $1.dat[1];
21   $result = PyComplex_FromCComplex(temp);
22 }
23 
24 
25 %typemap(in) gsl_complex * (gsl_complex *tempComplex){
26   /* Complex Pointer (in) */
27   Py_complex temp;
28   tempComplex = new(gsl_complex);
29   tempComplex->dat[0] = temp.real;
30   tempComplex->dat[1] = temp.imag;
31   $1 = tempComplex;
32 };
33 
34 %typemap(out) gsl_complex * {
35   /* Complex Pionter (out) */
36   Py_complex temp;
37   temp.real = $1->dat[0];
38   temp.imag = $1->dat[1];
39   $result = PyComplex_FromCComplex(temp);
40 }
41 
42 %typemap(argout) gsl_complex * {
43   /* Complex Pionter (argout) */
44   Py_complex temp;
45   temp.real = $1->dat[0];
46   temp.imag = $1->dat[1];
47   $result = SWIG_Python_AppendOutput($result, PyComplex_FromCComplex(temp));
48 }
49 
50 //%include gsl/gsl_complex_math.h
51