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
);
33 /* This caused gsl_vector_view functions to fail
, can we
34 * turn this off for those functions?
35 %typemap
(freearg
) double const
[] {
39 %typemap
(in
) float const
[] {
45 croak
("Math::GSL : $$1_name is not a reference!");
46 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
47 croak
("Math::GSL : $$1_name is not an array ref!");
49 tempav
= (AV
*)SvRV
($input
);
51 $
1 = (float
*) malloc
((len
+1)*sizeof
(float
));
52 for
(i
= 0; i
<= len
; i
++) {
53 tv
= av_fetch
(tempav
, i
, 0);
54 $
1[i
] = (float
)(double
) SvNV
(*tv
);
58 %typemap
(freearg
) float const
[] {
62 %typemap
(in
) size_t const
[] {
68 croak
("Math::GSL : $$1_name is not a reference!");
69 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
70 croak
("Math::GSL : $$1_name is not an array ref!");
72 tempav
= (AV
*)SvRV
($input
);
74 $
1 = (size_t
*) malloc
((len
+1)*sizeof
(size_t
));
75 for
(i
= 0; i
<= len
; i
++) {
76 tv
= av_fetch
(tempav
, i
, 0);
81 %typemap
(freearg
) size_t const
[] {
85 %apply double const
[] {
86 double
*data
, double
*dest
, double
*f_in
, double
*f_out
,
87 double data
[], const double
* src
, double x
[], double a
[], double b
[],
88 const double
* x
, const double
* y
, const double
* w
, const double x_array
[],
89 const double xrange
[], const double yrange
[], double
* base
,
90 const double
* base
, const double xrange
[], const double yrange
[] ,
91 const double
* array
, const double data2
[], const double w
[] ,
93 gsl_complex_packed_array data
96 %apply float const
[] {
97 float const
*A
, float const
*B
, float const
*C
, float
*C
100 %apply size_t const
[] {
104 %apply int
*OUTPUT { size_t
*imin
, size_t
*imax
, size_t
*neval
};
105 %apply double
* OUTPUT {
106 double
* min_out
, double
* max_out
,
107 double
*abserr
, double
*result
111 struct gsl_function_perl
{
112 gsl_function C_gsl_function
;
116 struct gsl_monte_function_perl
{
117 gsl_monte_function C_gsl_monte_function
;
124 /* this function returns the value
125 of evaluating the function pointer
126 stored in func with argument x
128 double call_gsl_function
(double x
, void
*params
){
129 struct gsl_function_perl
*F
=(struct gsl_function_perl
*)params
;
134 //fprintf
(stderr
, "LOOKUP CALLBACK\n");
139 XPUSHs
(sv_2mortal
(newSVnv
((double
)x
)));
141 PUTBACK
; /* make local stack pointer global
*/
143 count
= call_sv
(F-
>function
, G_SCALAR
);
147 croak
("Expected to call subroutine in scalar context!");
151 PUTBACK
; /* make local stack pointer global
*/
157 double call_gsl_monte_function
(double
*x_array
, size_t dim
, void
*params
){
158 struct gsl_monte_function_perl
*F
=(struct gsl_monte_function_perl
*)params
;
165 //fprintf
(stderr
, "LOOKUP CALLBACK\n");
171 sv_2mortal
((SV
*)perl_array
);
172 XPUSHs
(sv_2mortal
(newRV
((SV
*)perl_array
)));
173 for
(i
=0; i
<dim
; i
++) {
174 /* no mortal
: it is referenced by the array
*/
175 av_push
(perl_array
, newSVnv
(x_array
[i
]));
177 XPUSHs
(sv_2mortal
(newSViv
(dim
)));
179 PUTBACK
; /* make local stack pointer global
*/
181 count
= call_sv
(F-
>f
, G_SCALAR
);
185 croak
("Expected to call subroutine in scalar context!");
189 PUTBACK
; /* make local stack pointer global
*/
197 %typemap
(in
) gsl_monte_function
* (struct gsl_monte_function_perl w_gsl_monte_function
) {
203 if
(SvROK
($input
) && (SvTYPE(SvRV($input)) == SVt_PVAV)) {
204 AV
* array
=(AV
*)SvRV
($input
);
206 if
(av_len
(array
)<0) {
207 croak
("Math::GSL : $$1_name is an empty array!");
209 if
(av_len
(array
)>2) {
210 croak
("Math::GSL : $$1_name is an array with more than 3 elements!");
212 p_f
= av_fetch
(array
, 0, 0);
214 if
(av_len
(array
)>0) {
216 p_dim
= av_fetch
(array
, 1, 0);
219 if
(av_len
(array
)>1) {
221 p_params
= av_fetch
(array
, 1, 0);
228 if
(!f ||
!(SvPOK
(f
) ||
(SvROK
(f
) && (SvTYPE(SvRV(f)) == SVt_PVCV)))) {
229 croak
("Math::GSL : $$1_name is not a reference to code!");
239 croak
("Math::GSL : $$1_name is not an integer for dim!");
248 params
= newSVsv
(params
);
250 w_gsl_monte_function.f
= f
;
251 w_gsl_monte_function.dim
= dim
;
252 w_gsl_monte_function.params
= params
;
253 w_gsl_monte_function.C_gsl_monte_function.f
= &call_gsl_monte_function;
254 w_gsl_monte_function.C_gsl_monte_function.dim
= C_dim
;
255 w_gsl_monte_function.C_gsl_monte_function.params
= &w_gsl_monte_function;
256 $
1 = &w_gsl_monte_function.C_gsl_monte_function;
259 %typemap
(in
) gsl_function
* (struct gsl_function_perl w_gsl_function
) {
263 if
(SvROK
($input
) && (SvTYPE(SvRV($input)) == SVt_PVAV)) {
264 AV
* array
=(AV
*)SvRV
($input
);
265 SV
** p_function
= 0;
266 if
(av_len
(array
)<0) {
267 croak
("Math::GSL : $$1_name is an empty array!");
269 if
(av_len
(array
)>1) {
270 croak
("Math::GSL : $$1_name is an array with more than 2 elements!");
272 p_function
= av_fetch
(array
, 0, 0);
273 function
= *p_function
;
274 if
(av_len
(array
)>0) {
276 p_params
= av_fetch
(array
, 1, 0);
283 if
(!function ||
!(SvPOK
(function
) ||
(SvROK
(function
) && (SvTYPE(SvRV(function)) == SVt_PVCV)))) {
284 croak
("Math::GSL : $$1_name is not a reference to code!");
287 function
= newSVsv
(function
);
292 params
= newSVsv
(params
);
294 w_gsl_function.params
= params
;
295 w_gsl_function.function
= function
;
296 w_gsl_function.C_gsl_function.params
= &w_gsl_function;
297 w_gsl_function.C_gsl_function.function
= &call_gsl_function;
298 $
1 = &w_gsl_function.C_gsl_function;
301 %typemap
(freearg
) gsl_monte_function
* {
302 struct gsl_monte_function_perl
*p
=(struct gsl_monte_function_perl
*) $
1->params
;
304 SvREFCNT_dec
(p-
>dim
);
305 SvREFCNT_dec
(p-
>params
);
308 %typemap
(freearg
) gsl_function
* {
309 struct gsl_function_perl
*p
=(struct gsl_function_perl
*) $
1->params
;
310 SvREFCNT_dec
(p-
>function
);
311 SvREFCNT_dec
(p-
>params
);
314 %typemap
(in
) gsl_function_fdf
* {
315 fprintf
(stderr
, 'FDF_FUNC'
);