Update Changes
[Math-GSL.git] / swig / gsl_typemaps.i
blobe325956e2e05ffc00ac4e175503ac46fb7dc6d9a
1 // Only include if we have GSL >= 1.12
2 // This needs to be conditional
3 #ifdef GSL_VERSION && GSL_VERSION == "1.12"
4 %include "gsl_inline.h"
5 #endif
10 %typemap(in) double const [] {
11 AV *tempav;
12 I32 len;
13 int i;
14 SV **tv;
15 if (!SvROK($input))
16 croak("Math::GSL : $$1_name is not a reference!");
17 if (SvTYPE(SvRV($input)) != SVt_PVAV)
18 croak("Math::GSL : $$1_name is not an array ref!");
20 tempav = (AV*)SvRV($input);
21 len = av_len(tempav);
22 $1 = (double *) malloc((len+1)*sizeof(double));
23 for (i = 0; i <= len; i++) {
24 tv = av_fetch(tempav, i, 0);
25 $1[i] = (double) SvNV(*tv);
29 %apply double const [] {
30 size_t *p ,double *data, double *dest, double *f_in, double *f_out,
31 double data[], const double * src, double x[], double a[], double b[] ,
32 const double * x, const double * y, const double * w , const double x_array[],
33 const double xrange[], const double yrange[], double * base,
34 const double * base, const double xrange[], const double yrange[] ,
35 const double * array , const double data2[], const double w[] ,
36 float const *A, float const *B, float const *C, float *C, double *v,
37 gsl_complex_packed_array data
40 %apply int *OUTPUT { size_t *imin, size_t *imax, size_t *neval };
41 %apply double * OUTPUT {
42 double * min_out, double * max_out,
43 double *abserr, double *result
46 static HV * Callbacks = (HV*)NULL;
47 /* this function returns the value
48 of evaluating the function pointer
49 stored in func with argument x
51 double callthis(double x , int func, void *params){
52 SV ** sv;
53 double y;
54 dSP;
56 //fprintf(stderr, "LOOKUP CALLBACK\n");
57 sv = hv_fetch(Callbacks, (char*)func, sizeof(func), FALSE );
58 if (sv == (SV**)NULL) {
59 fprintf(stderr, "Math::GSL(callthis): %d not in Callbacks!\n", func);
60 return;
63 PUSHMARK(SP);
64 XPUSHs(sv_2mortal(newSVnv((double)x)));
65 PUTBACK;
66 call_sv(*sv, G_SCALAR);
67 y = POPn;
68 return y;
71 %typemap(in) gsl_monte_function * {
72 croak("FOOBAR!");
73 gsl_monte_function MF;
74 int count;
75 SV ** callback;
76 double x;
77 if (!SvROK($input)) {
78 croak("Math::GSL : $$1_name is not a reference value!");
80 if (Callbacks == (HV*)NULL)
81 Callbacks = newHV();
82 fprintf(stderr,"STORE gsl_monte_function CALLBACK: %d\n", (int)$input);
83 hv_store( Callbacks, (char*)&$input, sizeof($input), newSVsv($input), 0 );
85 MF.params = &$input;
86 MF.function = &callthis;
87 $1 = &MF;
89 %typemap(in) gsl_function * {
90 gsl_function F;
91 int count;
92 SV ** callback;
93 double x;
95 if (!SvROK($input)) {
96 croak("Math::GSL : $$1_name is not a reference value!");
98 if (Callbacks == (HV*)NULL)
99 Callbacks = newHV();
100 //fprintf(stderr,"STORE CALLBACK: %d\n", (int)$input);
101 hv_store( Callbacks, (char*)&$input, sizeof($input), newSVsv($input), 0 );
103 F.params = &$input;
104 F.function = &callthis;
105 $1 = &F;
108 %typemap(in) gsl_function_fdf * {
109 fprintf(stderr, 'FDF_FUNC');
113 typedef int size_t;