1 %module
"Math::GSL::Deriv"
2 // Danger Will Robinson
, for realz
!
4 struct gsl_function_struct
6 double
(* function
) (double x
, void
* params
);
10 typedef struct gsl_function_struct gsl_function
;
11 #define GSL_FN_EVAL
(F
,x
) (*((F
)->function
))(x
,(F
)->params
)
15 //%include
"gsl_typemaps.i"
17 static HV
* Callbacks
= (HV
*)NULL;
18 typedef struct callback_t
22 double xsquared
(double x
,void
*params
){
23 fprintf
(stderr
,"static xsquared!!\n");
27 %apply double
* OUTPUT { double
*abserr
, double
*result
};
29 int gsl_deriv_central
(const gsl_function
*f
,
31 double
*result
, double
*abserr
);
34 %typemap
(in
) (const gsl_function
*f
,
36 double
*result
, double
*abserr
) {
37 fprintf
(stderr
,"XXXX\n");
40 %typemap
(in
) gsl_function const
* {
41 fprintf
(stderr
,"typemap in!\n");
45 F.function
= &xsquared;
49 croak
("Math::GSL : not a reference value!");
51 if
(Callbacks
== (HV
*)NULL)
53 fprintf
(stderr
,"input =%d\n", (int
)$input
);
54 hv_store
( Callbacks
, (char
*)&$input, sizeof($input), newSVsv($input), 0 );
56 //Perl_sv_dump
( $input
);
57 //call_sv
((SV
*)$input
, G_SCALAR
);
58 // how to register callback ?
61 %typemap
(argout
) gsl_function const
* {
62 fprintf
(stderr
,"typemap argout!\n");
66 sv
= hv_fetch
(Callbacks
, (char
*)&$input, sizeof($input), FALSE );
68 croak
("Math::GSL : Missing callback!\n");
74 // these are the arguments passed to the callback
75 // this is currently passing in the memory address of the callback
76 XPUSHs
(sv_2mortal
(newSViv
((int
)$input
)));
77 //XPUSHs
(sv_2mortal
($input
));
78 //XPUSHs
(newSVsv
($input
));
79 //XPUSHs
(sv_2mortal
(newSViv
(42)));
80 //XPUSHs
(sv_2mortal
(newSVnv
((double
) (*($input
)->function
)() )));
83 fprintf
(stderr
, "\nCALLBACK!\n");
85 /* This actually calls the perl subroutine
*/
86 call_sv
(*sv
, G_SCALAR
);
90 //fprintf
(stderr
, "argout:x = %.8f\n", x
);
95 //XPUSHs
(sv_2mortal
(newSVnv
(x
)));
101 %typemap
(in
) void
* {
102 $
1 = (double
*) $input
;
105 #include
"gsl/gsl_math.h"
106 #include
"gsl/gsl_deriv.h"
109 %include
"gsl/gsl_math.h"
110 %include
"gsl/gsl_deriv.h"
118 %EXPORT_TAGS
= ( all
=> [ @EXPORT_OK
] );
124 Math
::GSL
::Deriv
- Functions to compute numerical derivatives by finite differencing
128 This module is not yet implemented. Patches Welcome
!
130 use Math
::GSL
::Deriv qw
/:all
/;
134 Here is a list of all the functions in this module
:
138 =item
* C
<gsl_deriv_central
>
140 =item
* C
<gsl_deriv_backward
>
142 =item
* C
<gsl_deriv_forward
>
146 For more informations on the functions
, we refer you to the GSL offcial
147 documentation
: L
<http
://www.gnu.org
/software
/gsl
/manual
/html_node
/>
149 Tip
: search on google
: site
:http
://www.gnu.org
/software
/gsl
/manual
/html_node
/ name_of_the_function_you_want
154 Jonathan Leto
<jonathan@leto.net
> and Thierry Moisan
<thierry.moisan@gmail.com
>
156 =head1 COPYRIGHT
AND LICENSE
158 Copyright
(C
) 2008 Jonathan Leto and Thierry Moisan
160 This program is free software
; you can redistribute it and
/or modify it
161 under the same terms as Perl itself.