2 %include
"gsl/gsl_nan.h"
3 #if defined GSL_MINOR_VERSION
&& (GSL_MINOR_VERSION >= 12)
4 %include
"gsl/gsl_inline.h"
10 #include
"gsl/gsl_nan.h"
11 #include
"gsl/gsl_math.h"
12 #include
"gsl/gsl_monte.h"
15 %typemap
(in
) double const
[] {
21 croak
("Math::GSL : $$1_name is not a reference!");
22 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
23 croak
("Math::GSL : $$1_name is not an array ref!");
25 tempav
= (AV
*)SvRV
($input
);
27 $
1 = (double
*) malloc
((len
+1)*sizeof
(double
));
28 for
(i
= 0; i
<= len
; i
++) {
29 tv
= av_fetch
(tempav
, i
, 0);
30 $
1[i
] = (double
) SvNV
(*tv
);
34 %typemap
(freearg
) double const
[] {
38 %typemap
(in
) float const
[] {
44 croak
("Math::GSL : $$1_name is not a reference!");
45 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
46 croak
("Math::GSL : $$1_name is not an array ref!");
48 tempav
= (AV
*)SvRV
($input
);
50 $
1 = (float
*) malloc
((len
+1)*sizeof
(float
));
51 for
(i
= 0; i
<= len
; i
++) {
52 tv
= av_fetch
(tempav
, i
, 0);
53 $
1[i
] = (float
)(double
) SvNV
(*tv
);
57 %typemap
(freearg
) float const
[] {
61 %typemap
(in
) size_t const
[] {
67 croak
("Math::GSL : $$1_name is not a reference!");
68 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
69 croak
("Math::GSL : $$1_name is not an array ref!");
71 tempav
= (AV
*)SvRV
($input
);
73 $
1 = (size_t
*) malloc
((len
+1)*sizeof
(size_t
));
74 for
(i
= 0; i
<= len
; i
++) {
75 tv
= av_fetch
(tempav
, i
, 0);
80 %typemap
(freearg
) size_t const
[] {
84 %apply double const
[] {
85 double
*data
, double
*dest
, double
*f_in
, double
*f_out
,
86 double data
[], const double
* src
, double x
[], double a
[], double b
[],
87 const double
* x
, const double
* y
, const double
* w
, const double x_array
[],
88 const double xrange
[], const double yrange
[], double
* base
,
89 const double
* base
, const double xrange
[], const double yrange
[] ,
90 const double
* array
, const double data2
[], const double w
[] ,
92 gsl_complex_packed_array data
95 %apply float const
[] {
96 float const
*A
, float const
*B
, float const
*C
, float
*C
99 %apply size_t const
[] {
103 %apply int
*OUTPUT { size_t
*imin
, size_t
*imax
, size_t
*neval
};
104 %apply double
* OUTPUT {
105 double
* min_out
, double
* max_out
,
106 double
*abserr
, double
*result
110 struct gsl_function_perl
{
111 gsl_function C_gsl_function
;
115 struct gsl_monte_function_perl
{
116 gsl_monte_function C_gsl_monte_function
;
123 /* this function returns the value
124 of evaluating the function pointer
125 stored in func with argument x
127 double call_gsl_function
(double x
, void
*params
){
128 struct gsl_function_perl
*F
=(struct gsl_function_perl
*)params
;
133 //fprintf
(stderr
, "LOOKUP CALLBACK\n");
138 XPUSHs
(sv_2mortal
(newSVnv
((double
)x
)));
140 PUTBACK
; /* make local stack pointer global
*/
142 count
= call_sv
(F-
>function
, G_SCALAR
);
146 croak
("Expected to call subroutine in scalar context!");
150 PUTBACK
; /* make local stack pointer global
*/
156 double call_gsl_monte_function
(double
*x_array
, size_t dim
, void
*params
){
157 struct gsl_monte_function_perl
*F
=(struct gsl_monte_function_perl
*)params
;
164 //fprintf
(stderr
, "LOOKUP CALLBACK\n");
170 sv_2mortal
((SV
*)perl_array
);
171 XPUSHs
(sv_2mortal
(newRV
((SV
*)perl_array
)));
172 for
(i
=0; i
<dim
; i
++) {
173 /* no mortal
: it is referenced by the array
*/
174 av_push
(perl_array
, newSVnv
(x_array
[i
]));
176 XPUSHs
(sv_2mortal
(newSViv
(dim
)));
178 PUTBACK
; /* make local stack pointer global
*/
180 count
= call_sv
(F-
>f
, G_SCALAR
);
184 croak
("Expected to call subroutine in scalar context!");
188 PUTBACK
; /* make local stack pointer global
*/
196 %typemap
(in
) gsl_monte_function
* (struct gsl_monte_function_perl w_gsl_monte_function
) {
202 if
(SvROK
($input
) && (SvTYPE(SvRV($input)) == SVt_PVAV)) {
203 AV
* array
=(AV
*)SvRV
($input
);
205 if
(av_len
(array
)<0) {
206 croak
("Math::GSL : $$1_name is an empty array!");
208 if
(av_len
(array
)>2) {
209 croak
("Math::GSL : $$1_name is an array with more than 3 elements!");
211 p_f
= av_fetch
(array
, 0, 0);
213 if
(av_len
(array
)>0) {
215 p_dim
= av_fetch
(array
, 1, 0);
218 if
(av_len
(array
)>1) {
220 p_params
= av_fetch
(array
, 1, 0);
227 if
(!f ||
!(SvPOK
(f
) ||
(SvROK
(f
) && (SvTYPE(SvRV(f)) == SVt_PVCV)))) {
228 croak
("Math::GSL : $$1_name is not a reference to code!");
238 croak
("Math::GSL : $$1_name is not an integer for dim!");
247 params
= newSVsv
(params
);
249 w_gsl_monte_function.f
= f
;
250 w_gsl_monte_function.dim
= dim
;
251 w_gsl_monte_function.params
= params
;
252 w_gsl_monte_function.C_gsl_monte_function.f
= &call_gsl_monte_function;
253 w_gsl_monte_function.C_gsl_monte_function.dim
= C_dim
;
254 w_gsl_monte_function.C_gsl_monte_function.params
= &w_gsl_monte_function;
255 $
1 = &w_gsl_monte_function.C_gsl_monte_function;
258 %typemap
(in
) gsl_function
* (struct gsl_function_perl w_gsl_function
) {
262 if
(SvROK
($input
) && (SvTYPE(SvRV($input)) == SVt_PVAV)) {
263 AV
* array
=(AV
*)SvRV
($input
);
264 SV
** p_function
= 0;
265 if
(av_len
(array
)<0) {
266 croak
("Math::GSL : $$1_name is an empty array!");
268 if
(av_len
(array
)>1) {
269 croak
("Math::GSL : $$1_name is an array with more than 2 elements!");
271 p_function
= av_fetch
(array
, 0, 0);
272 function
= *p_function
;
273 if
(av_len
(array
)>0) {
275 p_params
= av_fetch
(array
, 1, 0);
282 if
(!function ||
!(SvPOK
(function
) ||
(SvROK
(function
) && (SvTYPE(SvRV(function)) == SVt_PVCV)))) {
283 croak
("Math::GSL : $$1_name is not a reference to code!");
286 function
= newSVsv
(function
);
291 params
= newSVsv
(params
);
293 w_gsl_function.params
= params
;
294 w_gsl_function.function
= function
;
295 w_gsl_function.C_gsl_function.params
= &w_gsl_function;
296 w_gsl_function.C_gsl_function.function
= &call_gsl_function;
297 $
1 = &w_gsl_function.C_gsl_function;
300 %typemap
(freearg
) gsl_monte_function
* {
301 struct gsl_monte_function_perl
*p
=(struct gsl_monte_function_perl
*) $
1->params
;
303 SvREFCNT_dec
(p-
>dim
);
304 SvREFCNT_dec
(p-
>params
);
307 %typemap
(freearg
) gsl_function
* {
308 struct gsl_function_perl
*p
=(struct gsl_function_perl
*) $
1->params
;
309 SvREFCNT_dec
(p-
>function
);
310 SvREFCNT_dec
(p-
>params
);
313 %typemap
(in
) gsl_function_fdf
* {
314 fprintf
(stderr
, 'FDF_FUNC'
);