Getting closer...
[Math-GSL.git] / Deriv.i
blob5b38a7a85edf908b840372763dc7068fc81e4bd8
1 %module "Math::GSL::Deriv"
2 /*
3 struct gsl_function_struct
5 double (* function) (double x, void * params);
6 void * params;
7 };
9 typedef struct gsl_function_struct gsl_function ;
10 #define GSL_FN_EVAL(F,x) (*((F)->function))(x,(F)->params)
13 %include "typemaps.i"
14 %include "gsl_typemaps.i"
16 static HV * Callbacks = (HV*)NULL;
17 typedef struct callback_t
19 SV * obj;
21 double xsquared(double x,void *params){
22 fprintf(stderr,"static xsquared!!\n");
23 return x * x;
26 %apply double * OUTPUT { double *abserr, double *result };
28 int gsl_deriv_central (const gsl_function *f,
29 double x, double h,
30 double *result, double *abserr);
32 %typemap(in) gsl_function const * {
33 fprintf(stderr,"typemap in!\n");
34 gsl_function F;
35 int count;
36 F.params = 0;
37 F.function = &xsquared;
38 SV * callback;
40 if (!SvROK($input)) {
41 croak("Math::GSL : not a reference value!");
43 if (Callbacks == (HV*)NULL)
44 Callbacks = newHV();
46 hv_store( Callbacks, (char*)&$input, sizeof($input), newSVsv($input), 0 );
48 //Perl_sv_dump( $input );
49 // how to register callback ?
50 $1 = &F;
53 %typemap(argout) gsl_function const * {
54 fprintf(stderr,"typemap out!\n");
55 SV ** sv;
56 sv = hv_fetch(Callbacks, (char*)&$input, sizeof($input), FALSE );
57 double x;
59 if (sv == (SV**)NULL)
60 croak("Math::GSL : Missing callback!\n");
62 dSP;
63 ENTER;
64 SAVETMPS;
67 PUSHMARK(SP);
68 XPUSHs(sv_2mortal(newSViv((int)$input)));
69 PUTBACK;
72 fprintf(stderr, "\nCALLBACK!\n");
74 call_sv(*sv, G_SCALAR); /* The money shot */
75 x = POPn;
76 $result = &x;
77 fprintf(stderr, "x = %.8f", x);
79 FREETMPS;
80 LEAVE;
84 %typemap(in) void * {
85 $1 = (double *) $input;
88 #include "gsl/gsl_math.h"
89 #include "gsl/gsl_deriv.h"
92 %include "gsl/gsl_math.h"
93 %include "gsl/gsl_deriv.h"
95 %perlcode %{
96 @EXPORT_OK = qw/
97 gsl_deriv_central
98 gsl_deriv_backward
99 gsl_deriv_forward
101 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
103 __END__
105 =head1 NAME
107 Math::GSL::Deriv - Functions to compute numerical derivatives by finite differencing
109 =head1 SYNOPSIS
111 This module is not yet implemented. Patches Welcome!
113 use Math::GSL::Deriv qw /:all/;
115 =head1 DESCRIPTION
117 Here is a list of all the functions in this module :
119 =over
121 =item * C<gsl_deriv_central>
123 =item * C<gsl_deriv_backward>
125 =item * C<gsl_deriv_forward>
127 =back
129 For more informations on the functions, we refer you to the GSL offcial
130 documentation: L<http://www.gnu.org/software/gsl/manual/html_node/>
132 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
135 =head1 AUTHORS
137 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
139 =head1 COPYRIGHT AND LICENSE
141 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
143 This program is free software; you can redistribute it and/or modify it
144 under the same terms as Perl itself.
146 =cut