Better error message in double * typemap and refactor FFT tests
[Math-GSL.git] / gsl_typemaps.i
blob08eb6c22772c03ad30b3b58bae131dbb019ac18d
2 %typemap(in) double const [] {
3 AV *tempav;
4 I32 len;
5 int i;
6 SV **tv;
7 if (!SvROK($input))
8 croak("Math::GSL : $$1_name is not a reference!");
9 if (SvTYPE(SvRV($input)) != SVt_PVAV)
10 croak("Math::GSL : $$1_name is not an array ref!");
12 tempav = (AV*)SvRV($input);
13 len = av_len(tempav);
14 $1 = (double *) malloc((len+1)*sizeof(double));
15 for (i = 0; i <= len; i++) {
16 tv = av_fetch(tempav, i, 0);
17 $1[i] = (double) SvNV(*tv);
21 %apply double const [] {
22 size_t *p ,double *data, double *dest, double *f_in, double *f_out,
23 double data[], const double * src, double x[], double a[], double b[] ,
24 const double * x, const double * y, const double * w , const double x_array[],
25 const double xrange[], const double yrange[], double * base,
26 const double * base, const double xrange[], const double yrange[] ,
27 const double * array , const double data2[], const double w[] ,
28 float const *A, float const *B, float const *C, float *C, double *v
31 %apply int *OUTPUT { size_t *imin, size_t *imax, size_t *neval };
32 %apply double * OUTPUT {
33 double * min_out, double * max_out,
34 double *abserr, double *result
37 static HV * Callbacks = (HV*)NULL;
38 /* this function returns the value
39 of evaluating the function pointer
40 stored in func with argument x
42 double callthis(double x , int func, void *params){
43 SV ** sv;
44 double y;
45 dSP;
47 //fprintf(stderr, "LOOKUP CALLBACK\n");
48 sv = hv_fetch(Callbacks, (char*)func, sizeof(func), FALSE );
49 if (sv == (SV**)NULL) {
50 fprintf(stderr, "Math::GSL(callthis): %d not in Callbacks!\n", func);
51 return;
54 PUSHMARK(SP);
55 XPUSHs(sv_2mortal(newSVnv((double)x)));
56 PUTBACK;
57 call_sv(*sv, G_SCALAR);
58 y = POPn;
59 return y;
62 %typemap(in) gsl_function * {
63 gsl_function F;
64 int count;
65 SV ** callback;
66 double x;
68 if (!SvROK($input)) {
69 croak("Math::GSL : $1_name is not a reference value!");
71 if (Callbacks == (HV*)NULL)
72 Callbacks = newHV();
73 //fprintf(stderr,"STORE CALLBACK: %d\n", (int)$input);
74 hv_store( Callbacks, (char*)&$input, sizeof($input), newSVsv($input), 0 );
76 F.params = &$input;
77 F.function = &callthis;
78 $1 = &F;
81 %typemap(in) gsl_function_fdf * {
82 fprintf(stderr, 'FDF_FUNC');