Fiddle with Monte. Callbacks are being stored but not called
[Math-GSL.git] / swig / gsl_typemaps.i
blob313eefbaf93c67ce848207e5200cac8bc32fa421
1 %include "system.i"
2 #ifdef GSL_MINOR_VERSION && GSL_MINOR_VERSION >= 12
3 %include "gsl_inline.h"
4 #endif
6 %typemap(in) double const [] {
7 AV *tempav;
8 I32 len;
9 int i;
10 SV **tv;
11 if (!SvROK($input))
12 croak("Math::GSL : $$1_name is not a reference!");
13 if (SvTYPE(SvRV($input)) != SVt_PVAV)
14 croak("Math::GSL : $$1_name is not an array ref!");
16 tempav = (AV*)SvRV($input);
17 len = av_len(tempav);
18 $1 = (double *) malloc((len+1)*sizeof(double));
19 for (i = 0; i <= len; i++) {
20 tv = av_fetch(tempav, i, 0);
21 $1[i] = (double) SvNV(*tv);
25 %apply double const [] {
26 size_t *p ,double *data, double *dest, double *f_in, double *f_out,
27 double data[], const double * src, double x[], double a[], double b[] ,
28 const double * x, const double * y, const double * w , const double x_array[],
29 const double xrange[], const double yrange[], double * base,
30 const double * base, const double xrange[], const double yrange[] ,
31 const double * array , const double data2[], const double w[] ,
32 float const *A, float const *B, float const *C, float *C, double *v,
33 gsl_complex_packed_array data
36 %apply int *OUTPUT { size_t *imin, size_t *imax, size_t *neval };
37 %apply double * OUTPUT {
38 double * min_out, double * max_out,
39 double *abserr, double *result
42 static HV * Callbacks = (HV*)NULL;
43 /* this function returns the value
44 of evaluating the function pointer
45 stored in func with argument x
47 double callthis(double x , int func, void *params){
48 SV ** sv;
49 double y;
50 dSP;
52 //fprintf(stderr, "LOOKUP CALLBACK\n");
53 sv = hv_fetch(Callbacks, (char*)func, sizeof(func), FALSE );
54 if (sv == (SV**)NULL) {
55 fprintf(stderr, "Math::GSL(callthis): %d not in Callbacks!\n", func);
56 return;
59 PUSHMARK(SP);
60 XPUSHs(sv_2mortal(newSVnv((double)x)));
61 PUTBACK;
62 call_sv(*sv, G_SCALAR);
63 y = POPn;
64 return y;
66 double callmonte(double x, int func, int dim, void *params ){
67 fprintf(stderr, "callmonte!!!");
70 %typemap(in) gsl_monte_function * {
71 gsl_monte_function MF;
72 int count;
73 SV ** callback;
74 double x;
75 if (!SvROK($input)) {
76 croak("Math::GSL : $$1_name is not a reference value!");
78 if (Callbacks == (HV*)NULL)
79 Callbacks = newHV();
80 fprintf(stderr,"STORE $$1_name gsl_monte_function CALLBACK: %d\n", (int)$input);
81 hv_store( Callbacks, (char*)&$input, sizeof($input), newSVsv($input), 0 );
83 MF.params = &$input;
84 MF.dim = 1; // XXX
85 MF.f = &callmonte;
86 $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;