gsl 1.12.108
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +29 -0
- data/Rakefile +54 -0
- data/VERSION +2 -0
- data/ext/MANIFEST +119 -0
- data/ext/alf.c +206 -0
- data/ext/array.c +666 -0
- data/ext/array_complex.c +247 -0
- data/ext/blas.c +29 -0
- data/ext/blas1.c +731 -0
- data/ext/blas2.c +1093 -0
- data/ext/blas3.c +881 -0
- data/ext/block.c +44 -0
- data/ext/block_source.c +886 -0
- data/ext/bspline.c +130 -0
- data/ext/bundle.c +3 -0
- data/ext/cdf.c +754 -0
- data/ext/cheb.c +542 -0
- data/ext/combination.c +283 -0
- data/ext/common.c +325 -0
- data/ext/complex.c +1004 -0
- data/ext/const.c +673 -0
- data/ext/const_additional.c +120 -0
- data/ext/cqp.c +283 -0
- data/ext/deriv.c +195 -0
- data/ext/dht.c +361 -0
- data/ext/diff.c +166 -0
- data/ext/dirac.c +395 -0
- data/ext/eigen.c +2373 -0
- data/ext/error.c +194 -0
- data/ext/extconf.rb +281 -0
- data/ext/fcmp.c +66 -0
- data/ext/fft.c +1092 -0
- data/ext/fit.c +205 -0
- data/ext/fresnel.c +312 -0
- data/ext/function.c +524 -0
- data/ext/geometry.c +139 -0
- data/ext/graph.c +1638 -0
- data/ext/gsl.c +271 -0
- data/ext/gsl_narray.c +653 -0
- data/ext/histogram.c +1995 -0
- data/ext/histogram2d.c +1068 -0
- data/ext/histogram3d.c +884 -0
- data/ext/histogram3d_source.c +750 -0
- data/ext/histogram_find.c +101 -0
- data/ext/histogram_oper.c +159 -0
- data/ext/ieee.c +98 -0
- data/ext/integration.c +1138 -0
- data/ext/interp.c +512 -0
- data/ext/jacobi.c +739 -0
- data/ext/linalg.c +4047 -0
- data/ext/linalg_complex.c +741 -0
- data/ext/math.c +725 -0
- data/ext/matrix.c +39 -0
- data/ext/matrix_complex.c +1732 -0
- data/ext/matrix_double.c +560 -0
- data/ext/matrix_int.c +256 -0
- data/ext/matrix_source.c +2733 -0
- data/ext/min.c +250 -0
- data/ext/monte.c +992 -0
- data/ext/multifit.c +1879 -0
- data/ext/multimin.c +808 -0
- data/ext/multimin_fsdf.c +156 -0
- data/ext/multiroots.c +955 -0
- data/ext/ndlinear.c +321 -0
- data/ext/nmf.c +167 -0
- data/ext/nmf_wrap.c +72 -0
- data/ext/ntuple.c +469 -0
- data/ext/odeiv.c +959 -0
- data/ext/ool.c +879 -0
- data/ext/oper_complex_source.c +253 -0
- data/ext/permutation.c +596 -0
- data/ext/poly.c +42 -0
- data/ext/poly2.c +265 -0
- data/ext/poly_source.c +1885 -0
- data/ext/qrng.c +171 -0
- data/ext/randist.c +1873 -0
- data/ext/rational.c +480 -0
- data/ext/rng.c +612 -0
- data/ext/root.c +408 -0
- data/ext/sf.c +1494 -0
- data/ext/sf_airy.c +200 -0
- data/ext/sf_bessel.c +867 -0
- data/ext/sf_clausen.c +28 -0
- data/ext/sf_coulomb.c +206 -0
- data/ext/sf_coupling.c +118 -0
- data/ext/sf_dawson.c +29 -0
- data/ext/sf_debye.c +157 -0
- data/ext/sf_dilog.c +42 -0
- data/ext/sf_elementary.c +44 -0
- data/ext/sf_ellint.c +206 -0
- data/ext/sf_elljac.c +29 -0
- data/ext/sf_erfc.c +93 -0
- data/ext/sf_exp.c +164 -0
- data/ext/sf_expint.c +211 -0
- data/ext/sf_fermi_dirac.c +148 -0
- data/ext/sf_gamma.c +344 -0
- data/ext/sf_gegenbauer.c +96 -0
- data/ext/sf_hyperg.c +197 -0
- data/ext/sf_laguerre.c +112 -0
- data/ext/sf_lambert.c +47 -0
- data/ext/sf_legendre.c +367 -0
- data/ext/sf_log.c +104 -0
- data/ext/sf_mathieu.c +238 -0
- data/ext/sf_power.c +46 -0
- data/ext/sf_psi.c +98 -0
- data/ext/sf_synchrotron.c +48 -0
- data/ext/sf_transport.c +76 -0
- data/ext/sf_trigonometric.c +207 -0
- data/ext/sf_zeta.c +119 -0
- data/ext/signal.c +310 -0
- data/ext/siman.c +718 -0
- data/ext/sort.c +208 -0
- data/ext/spline.c +395 -0
- data/ext/stats.c +799 -0
- data/ext/sum.c +168 -0
- data/ext/tamu_anova.c +56 -0
- data/ext/tensor.c +38 -0
- data/ext/tensor_source.c +1123 -0
- data/ext/vector.c +38 -0
- data/ext/vector_complex.c +2236 -0
- data/ext/vector_double.c +1433 -0
- data/ext/vector_int.c +204 -0
- data/ext/vector_source.c +3329 -0
- data/ext/wavelet.c +937 -0
- data/include/rb_gsl.h +151 -0
- data/include/rb_gsl_array.h +238 -0
- data/include/rb_gsl_cheb.h +21 -0
- data/include/rb_gsl_common.h +343 -0
- data/include/rb_gsl_complex.h +25 -0
- data/include/rb_gsl_const.h +29 -0
- data/include/rb_gsl_dirac.h +13 -0
- data/include/rb_gsl_eigen.h +17 -0
- data/include/rb_gsl_fft.h +62 -0
- data/include/rb_gsl_fit.h +25 -0
- data/include/rb_gsl_function.h +27 -0
- data/include/rb_gsl_graph.h +70 -0
- data/include/rb_gsl_histogram.h +63 -0
- data/include/rb_gsl_histogram3d.h +97 -0
- data/include/rb_gsl_integration.h +17 -0
- data/include/rb_gsl_interp.h +46 -0
- data/include/rb_gsl_linalg.h +25 -0
- data/include/rb_gsl_math.h +26 -0
- data/include/rb_gsl_odeiv.h +21 -0
- data/include/rb_gsl_poly.h +71 -0
- data/include/rb_gsl_rational.h +37 -0
- data/include/rb_gsl_rng.h +21 -0
- data/include/rb_gsl_root.h +22 -0
- data/include/rb_gsl_sf.h +119 -0
- data/include/rb_gsl_statistics.h +17 -0
- data/include/rb_gsl_tensor.h +45 -0
- data/include/rb_gsl_with_narray.h +22 -0
- data/include/templates_off.h +87 -0
- data/include/templates_on.h +241 -0
- data/lib/gsl/gnuplot.rb +41 -0
- data/lib/gsl/oper.rb +68 -0
- data/lib/ool.rb +22 -0
- data/lib/ool/conmin.rb +30 -0
- metadata +224 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
/*
|
2
|
+
sf_trigonometric.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2001-2006 by Yoshiki Tsunesada
|
5
|
+
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
7
|
+
under the terms of the GNU General Public License.
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "rb_gsl_sf.h"
|
13
|
+
|
14
|
+
static VALUE rb_gsl_sf_sin(VALUE obj, VALUE x)
|
15
|
+
{
|
16
|
+
if (COMPLEX_P(x) || VECTOR_COMPLEX_P(x) || MATRIX_COMPLEX_P(x))
|
17
|
+
return rb_gsl_math_complex_eval(gsl_complex_sin, x);
|
18
|
+
return rb_gsl_sf_eval1(gsl_sf_sin, x);
|
19
|
+
}
|
20
|
+
|
21
|
+
static VALUE rb_gsl_sf_sin_e(VALUE obj, VALUE x)
|
22
|
+
{
|
23
|
+
return rb_gsl_sf_eval_e(gsl_sf_sin_e, x);
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE rb_gsl_sf_cos(VALUE obj, VALUE x)
|
27
|
+
{
|
28
|
+
if (COMPLEX_P(x) || VECTOR_COMPLEX_P(x) || MATRIX_COMPLEX_P(x))
|
29
|
+
return rb_gsl_math_complex_eval(gsl_complex_cos, x);
|
30
|
+
return rb_gsl_sf_eval1(gsl_sf_cos, x);
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE rb_gsl_sf_cos_e(VALUE obj, VALUE x)
|
34
|
+
{
|
35
|
+
return rb_gsl_sf_eval_e(gsl_sf_cos_e, x);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE rb_gsl_sf_hypot(VALUE obj, VALUE x, VALUE y)
|
39
|
+
{
|
40
|
+
Need_Float(x); Need_Float(y);
|
41
|
+
return rb_float_new(gsl_sf_hypot(NUM2DBL(x), NUM2DBL(y)));
|
42
|
+
}
|
43
|
+
|
44
|
+
static VALUE rb_gsl_sf_hypot_e(VALUE obj, VALUE x, VALUE y)
|
45
|
+
{
|
46
|
+
return rb_gsl_sf_eval_e_double2(gsl_sf_hypot_e, x, y);
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE rb_gsl_sf_sinc(VALUE obj, VALUE x)
|
50
|
+
{
|
51
|
+
return rb_gsl_sf_eval1(gsl_sf_sinc, x);
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE rb_gsl_sf_sinc_e(VALUE obj, VALUE x)
|
55
|
+
{
|
56
|
+
return rb_gsl_sf_eval_e(gsl_sf_sinc_e, x);
|
57
|
+
}
|
58
|
+
|
59
|
+
static VALUE rb_gsl_sf_complex_XXX_e(int argc, VALUE *argv, VALUE obj,
|
60
|
+
int (*f)(double, double, gsl_sf_result*, gsl_sf_result*))
|
61
|
+
{
|
62
|
+
gsl_sf_result *r1, *r2;
|
63
|
+
gsl_complex *z;
|
64
|
+
double re, im;
|
65
|
+
VALUE v1, v2;
|
66
|
+
int status;
|
67
|
+
switch (argc) {
|
68
|
+
case 1:
|
69
|
+
CHECK_COMPLEX(argv[0]);
|
70
|
+
Data_Get_Struct(argv[0], gsl_complex, z);
|
71
|
+
re = GSL_REAL(*z);
|
72
|
+
im = GSL_IMAG(*z);
|
73
|
+
break;
|
74
|
+
case 2:
|
75
|
+
Need_Float(argv[0]); Need_Float(argv[1]);
|
76
|
+
re = NUM2DBL(argv[0]);
|
77
|
+
im = NUM2DBL(argv[1]);
|
78
|
+
break;
|
79
|
+
default:
|
80
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
81
|
+
break;
|
82
|
+
}
|
83
|
+
v1 = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, r1);
|
84
|
+
v2 = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, r2);
|
85
|
+
status = (*f)(re, im, r1, r2);
|
86
|
+
return rb_ary_new3(2, v1, v2);
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE rb_gsl_sf_complex_sin_e(int argc, VALUE *argv, VALUE obj)
|
90
|
+
{
|
91
|
+
return rb_gsl_sf_complex_XXX_e(argc, argv, obj, gsl_sf_complex_sin_e);
|
92
|
+
}
|
93
|
+
|
94
|
+
static VALUE rb_gsl_sf_complex_cos_e(int argc, VALUE *argv, VALUE obj)
|
95
|
+
{
|
96
|
+
return rb_gsl_sf_complex_XXX_e(argc, argv, obj, gsl_sf_complex_cos_e);
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE rb_gsl_sf_complex_logsin_e(int argc, VALUE *argv, VALUE obj)
|
100
|
+
{
|
101
|
+
return rb_gsl_sf_complex_XXX_e(argc, argv, obj, gsl_sf_complex_logsin_e);
|
102
|
+
}
|
103
|
+
|
104
|
+
static VALUE rb_gsl_sf_lnsinh(VALUE obj, VALUE x)
|
105
|
+
{
|
106
|
+
return rb_gsl_sf_eval1(gsl_sf_lnsinh, x);
|
107
|
+
}
|
108
|
+
|
109
|
+
static VALUE rb_gsl_sf_lnsinh_e(VALUE obj, VALUE x)
|
110
|
+
{
|
111
|
+
return rb_gsl_sf_eval_e(gsl_sf_lnsinh_e, x);
|
112
|
+
}
|
113
|
+
|
114
|
+
static VALUE rb_gsl_sf_lncosh(VALUE obj, VALUE x)
|
115
|
+
{
|
116
|
+
return rb_gsl_sf_eval1(gsl_sf_lncosh, x);
|
117
|
+
}
|
118
|
+
|
119
|
+
static VALUE rb_gsl_sf_lncosh_e(VALUE obj, VALUE x)
|
120
|
+
{
|
121
|
+
return rb_gsl_sf_eval_e(gsl_sf_lncosh_e, x);
|
122
|
+
}
|
123
|
+
|
124
|
+
static VALUE rb_gsl_sf_polar_to_rect(int argc, VALUE *argv, VALUE obj)
|
125
|
+
{
|
126
|
+
return rb_gsl_sf_complex_XXX_e(argc, argv, obj, gsl_sf_polar_to_rect);
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE rb_gsl_sf_rect_to_polar(int argc, VALUE *argv, VALUE obj)
|
130
|
+
{
|
131
|
+
return rb_gsl_sf_complex_XXX_e(argc, argv, obj, gsl_sf_rect_to_polar);
|
132
|
+
}
|
133
|
+
|
134
|
+
static VALUE rb_gsl_sf_angle_restrict_symm(VALUE obj, VALUE theta)
|
135
|
+
{
|
136
|
+
return rb_gsl_sf_eval1(gsl_sf_angle_restrict_symm, theta);
|
137
|
+
}
|
138
|
+
|
139
|
+
static VALUE rb_gsl_sf_angle_restrict_pos(VALUE obj, VALUE theta)
|
140
|
+
{
|
141
|
+
return rb_gsl_sf_eval1(gsl_sf_angle_restrict_pos, theta);
|
142
|
+
}
|
143
|
+
|
144
|
+
/*
|
145
|
+
static VALUE rb_gsl_sf_sin_err(VALUE obj, VALUE x, VALUE dx)
|
146
|
+
{
|
147
|
+
return rb_float_new(gsl_sf_sin_err(NUM2DBL(x), NUM2DBL(dx)));
|
148
|
+
}
|
149
|
+
|
150
|
+
static VALUE rb_gsl_sf_cos_err(VALUE obj, VALUE x, VALUE dx)
|
151
|
+
{
|
152
|
+
return rb_float_new(gsl_sf_cos_err(NUM2DBL(x), NUM2DBL(dx)));
|
153
|
+
}
|
154
|
+
*/
|
155
|
+
|
156
|
+
static VALUE rb_gsl_sf_sin_err_e(VALUE obj, VALUE x, VALUE dx)
|
157
|
+
{
|
158
|
+
gsl_sf_result *rslt = NULL;
|
159
|
+
VALUE v;
|
160
|
+
int status;
|
161
|
+
Need_Float(x);
|
162
|
+
Need_Float(dx);
|
163
|
+
v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
|
164
|
+
status = gsl_sf_sin_err_e(NUM2DBL(x), NUM2DBL(dx), rslt);
|
165
|
+
return v;
|
166
|
+
}
|
167
|
+
|
168
|
+
static VALUE rb_gsl_sf_cos_err_e(VALUE obj, VALUE x, VALUE dx)
|
169
|
+
{
|
170
|
+
gsl_sf_result *rslt = NULL;
|
171
|
+
VALUE v;
|
172
|
+
int status;
|
173
|
+
Need_Float(x);
|
174
|
+
Need_Float(dx);
|
175
|
+
v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
|
176
|
+
status = gsl_sf_cos_err_e(NUM2DBL(x), NUM2DBL(dx), rslt);
|
177
|
+
return v;
|
178
|
+
}
|
179
|
+
|
180
|
+
void Init_gsl_sf_trigonometric(VALUE module)
|
181
|
+
{
|
182
|
+
rb_define_module_function(module, "sin", rb_gsl_sf_sin, 1);
|
183
|
+
rb_define_module_function(module, "sin_e", rb_gsl_sf_sin_e, 1);
|
184
|
+
rb_define_module_function(module, "cos", rb_gsl_sf_cos, 1);
|
185
|
+
rb_define_module_function(module, "cos_e", rb_gsl_sf_cos_e, 1);
|
186
|
+
rb_define_module_function(module, "hypot", rb_gsl_sf_hypot, 2);
|
187
|
+
rb_define_module_function(module, "hypot_e", rb_gsl_sf_hypot_e, 2);
|
188
|
+
rb_define_module_function(module, "sinc", rb_gsl_sf_sinc, 1);
|
189
|
+
rb_define_module_function(module, "sinc_e", rb_gsl_sf_sinc_e, 1);
|
190
|
+
rb_define_module_function(module, "complex_sin_e", rb_gsl_sf_complex_sin_e, -1);
|
191
|
+
rb_define_module_function(module, "complex_cos_e", rb_gsl_sf_complex_cos_e, -1);
|
192
|
+
rb_define_module_function(module, "complex_logsin_e", rb_gsl_sf_complex_logsin_e, -1);
|
193
|
+
rb_define_module_function(module, "lnsinh", rb_gsl_sf_lnsinh, 1);
|
194
|
+
rb_define_module_function(module, "lnsinh_e", rb_gsl_sf_lnsinh_e, 1);
|
195
|
+
rb_define_module_function(module, "lncosh", rb_gsl_sf_lncosh, 1);
|
196
|
+
rb_define_module_function(module, "lncosh_e", rb_gsl_sf_lncosh_e, 1);
|
197
|
+
rb_define_module_function(module, "polar_to_rect", rb_gsl_sf_polar_to_rect, -1);
|
198
|
+
rb_define_module_function(module, "rect_to_polar", rb_gsl_sf_rect_to_polar, -1);
|
199
|
+
rb_define_module_function(module, "angle_restrict_symm", rb_gsl_sf_angle_restrict_symm, 1);
|
200
|
+
rb_define_module_function(module, "angle_restrict_pos", rb_gsl_sf_angle_restrict_pos, 1);
|
201
|
+
|
202
|
+
/* rb_define_module_function(module, "sin_err", rb_gsl_sf_sin_err, 2);
|
203
|
+
rb_define_module_function(module, "cos_err", rb_gsl_sf_cos_err, 2);*/
|
204
|
+
rb_define_module_function(module, "sin_err_e", rb_gsl_sf_sin_err_e, 2);
|
205
|
+
rb_define_module_function(module, "cos_err_e", rb_gsl_sf_cos_err_e, 2);
|
206
|
+
|
207
|
+
}
|
data/ext/sf_zeta.c
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
/*
|
2
|
+
sf_zeta.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2001-2006 by Yoshiki Tsunesada
|
5
|
+
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
7
|
+
under the terms of the GNU General Public License.
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "rb_gsl_sf.h"
|
13
|
+
|
14
|
+
static VALUE rb_gsl_sf_zeta_int(VALUE obj, VALUE n)
|
15
|
+
{
|
16
|
+
VALUE nn;
|
17
|
+
if (TYPE(n) != T_FIXNUM) nn = INT2FIX(NUM2INT(n));
|
18
|
+
else nn = n;
|
19
|
+
return rb_gsl_sf_eval1_int(gsl_sf_zeta_int, nn);
|
20
|
+
}
|
21
|
+
|
22
|
+
static VALUE rb_gsl_sf_zeta_int_e(VALUE obj, VALUE n)
|
23
|
+
{
|
24
|
+
VALUE nn;
|
25
|
+
if (TYPE(n) != T_FIXNUM) nn = INT2FIX(NUM2INT(n));
|
26
|
+
else nn = n;
|
27
|
+
return rb_gsl_sf_eval_e_int(gsl_sf_zeta_int_e, nn);
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE rb_gsl_sf_zeta(VALUE obj, VALUE x)
|
31
|
+
{
|
32
|
+
return rb_gsl_sf_eval1(gsl_sf_zeta, x);
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE rb_gsl_sf_zeta_e(VALUE obj, VALUE x)
|
36
|
+
{
|
37
|
+
return rb_gsl_sf_eval_e(gsl_sf_zeta_e, x);
|
38
|
+
}
|
39
|
+
|
40
|
+
static VALUE rb_gsl_sf_hzeta(VALUE obj, VALUE s, VALUE q)
|
41
|
+
{
|
42
|
+
Need_Float(s); Need_Float(q);
|
43
|
+
return rb_float_new(gsl_sf_hzeta(NUM2DBL(s), NUM2DBL(q)));
|
44
|
+
}
|
45
|
+
|
46
|
+
static VALUE rb_gsl_sf_hzeta_e(VALUE obj, VALUE s, VALUE q)
|
47
|
+
{
|
48
|
+
return rb_gsl_sf_eval_e_double2(gsl_sf_hzeta_e, s, q);
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE rb_gsl_sf_eta_int(VALUE obj, VALUE n)
|
52
|
+
{
|
53
|
+
return rb_gsl_sf_eval1_int(gsl_sf_eta_int, n);
|
54
|
+
}
|
55
|
+
|
56
|
+
static VALUE rb_gsl_sf_eta_int_e(VALUE obj, VALUE n)
|
57
|
+
{
|
58
|
+
return rb_gsl_sf_eval_e_int(gsl_sf_eta_int_e, n);
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE rb_gsl_sf_eta(VALUE obj, VALUE x)
|
62
|
+
{
|
63
|
+
return rb_gsl_sf_eval1(gsl_sf_eta, x);
|
64
|
+
}
|
65
|
+
|
66
|
+
static VALUE rb_gsl_sf_eta_e(VALUE obj, VALUE x)
|
67
|
+
{
|
68
|
+
return rb_gsl_sf_eval_e(gsl_sf_eta_e, x);
|
69
|
+
}
|
70
|
+
|
71
|
+
#ifdef GSL_1_4_9_LATER
|
72
|
+
static VALUE rb_gsl_sf_zetam1_int(VALUE obj, VALUE n)
|
73
|
+
{
|
74
|
+
VALUE nn;
|
75
|
+
if (TYPE(n) != T_FIXNUM) nn = INT2FIX(NUM2INT(n));
|
76
|
+
else nn = n;
|
77
|
+
return rb_gsl_sf_eval1_int(gsl_sf_zetam1_int, nn);
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE rb_gsl_sf_zetam1_int_e(VALUE obj, VALUE n)
|
81
|
+
{
|
82
|
+
VALUE nn;
|
83
|
+
if (TYPE(n) != T_FIXNUM) nn = INT2FIX(NUM2INT(n));
|
84
|
+
else nn = n;
|
85
|
+
return rb_gsl_sf_eval_e_int(gsl_sf_zetam1_int_e, nn);
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE rb_gsl_sf_zetam1(VALUE obj, VALUE x)
|
89
|
+
{
|
90
|
+
return rb_gsl_sf_eval1(gsl_sf_zetam1, x);
|
91
|
+
}
|
92
|
+
|
93
|
+
static VALUE rb_gsl_sf_zetam1_e(VALUE obj, VALUE x)
|
94
|
+
{
|
95
|
+
return rb_gsl_sf_eval_e(gsl_sf_zetam1_e, x);
|
96
|
+
}
|
97
|
+
#endif
|
98
|
+
|
99
|
+
void Init_gsl_sf_zeta(VALUE module)
|
100
|
+
{
|
101
|
+
rb_define_module_function(module, "zeta_int", rb_gsl_sf_zeta_int, 1);
|
102
|
+
rb_define_module_function(module, "zeta_int_e", rb_gsl_sf_zeta_int_e, 1);
|
103
|
+
rb_define_module_function(module, "zeta", rb_gsl_sf_zeta, 1);
|
104
|
+
rb_define_module_function(module, "zeta_e", rb_gsl_sf_zeta_e, 1);
|
105
|
+
|
106
|
+
rb_define_module_function(module, "hzeta", rb_gsl_sf_hzeta, 2);
|
107
|
+
rb_define_module_function(module, "hzeta_e", rb_gsl_sf_hzeta_e, 2);
|
108
|
+
rb_define_module_function(module, "eta_int", rb_gsl_sf_eta_int, 1);
|
109
|
+
rb_define_module_function(module, "eta_int_e", rb_gsl_sf_eta_int_e, 1);
|
110
|
+
rb_define_module_function(module, "eta", rb_gsl_sf_eta, 1);
|
111
|
+
rb_define_module_function(module, "eta_e", rb_gsl_sf_eta_e, 1);
|
112
|
+
|
113
|
+
#ifdef GSL_1_4_9_LATER
|
114
|
+
rb_define_module_function(module, "zetam1_int", rb_gsl_sf_zetam1_int, 1);
|
115
|
+
rb_define_module_function(module, "zetam1_int_e", rb_gsl_sf_zetam1_int_e, 1);
|
116
|
+
rb_define_module_function(module, "zetam1", rb_gsl_sf_zetam1, 1);
|
117
|
+
rb_define_module_function(module, "zetam1_e", rb_gsl_sf_zetam1_e, 1);
|
118
|
+
#endif
|
119
|
+
}
|
data/ext/signal.c
ADDED
@@ -0,0 +1,310 @@
|
|
1
|
+
/*
|
2
|
+
signal.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2004 by Yoshiki Tsunesada
|
5
|
+
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
7
|
+
under the terms of the GNU General Public License.
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "rb_gsl_config.h"
|
13
|
+
#include "rb_gsl_fft.h"
|
14
|
+
|
15
|
+
enum FFT_CONV_CORR {
|
16
|
+
RB_GSL_FFT_CONVOLVE = 0,
|
17
|
+
RB_GSL_FFT_CORRELATE = 1,
|
18
|
+
RB_GSL_FFT_REAL = 2,
|
19
|
+
RB_GSL_FFT_HALFCOMPLEX = 3,
|
20
|
+
RB_GSL_FFT_DECONVOLVE = 4,
|
21
|
+
};
|
22
|
+
|
23
|
+
#ifndef WAVETABLE_P
|
24
|
+
#define WAVETABLE_P(x) (rb_obj_is_kind_of(x,cgsl_fft_halfcomplex_wavetable)?1:0)
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#ifndef CHECK_WAVETABLE
|
28
|
+
#define CHECK_WAVETABLE(x) if(!rb_obj_is_kind_of(x,cgsl_fft_halfcomplex_wavetable))\
|
29
|
+
rb_raise(rb_eTypeError, "wrong argument type (FFT::HalfComplex::Wavetable expected)");
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifndef WORKSPACE_P
|
33
|
+
#define WORKSPACE_P(x) (rb_obj_is_kind_of(x,cgsl_fft_real_workspace)?1:0)
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#ifndef CHECK_WORKSPACE
|
37
|
+
#define CHECK_WORKSPACE(x) if(!rb_obj_is_kind_of(x,cgsl_fft_real_workspace))\
|
38
|
+
rb_raise(rb_eTypeError, "wrong argument type (FFT::Real::Workspace expected)");
|
39
|
+
#endif
|
40
|
+
|
41
|
+
static void complex_mul(double re1, double im1, double re2, double im2,
|
42
|
+
double *re, double *im)
|
43
|
+
{
|
44
|
+
*re = re1*re2 - im1*im2;
|
45
|
+
*im = re1*im2 + im1*re2;
|
46
|
+
}
|
47
|
+
|
48
|
+
static void complex_conj_mul(double re1, double im1, double re2, double im2,
|
49
|
+
double *re, double *im)
|
50
|
+
{
|
51
|
+
*re = re1*re2 + im1*im2;
|
52
|
+
*im = -re1*im2 + im1*re2;
|
53
|
+
}
|
54
|
+
|
55
|
+
static void complex_div(double re1, double im1, double re2, double im2,
|
56
|
+
double *re, double *im)
|
57
|
+
{
|
58
|
+
double factor = re2*re2 + im2*im2;
|
59
|
+
complex_conj_mul(re1, im1, re2, im2, re, im);
|
60
|
+
*re /= factor;
|
61
|
+
*im /= factor;
|
62
|
+
}
|
63
|
+
|
64
|
+
/* data1, data2: FFTed data */
|
65
|
+
static void rbgsl_calc_conv_corr_c(const double *data1, const double *data2,
|
66
|
+
double *data3, size_t size,
|
67
|
+
gsl_fft_halfcomplex_wavetable *table,
|
68
|
+
gsl_fft_real_workspace *space, enum FFT_CONV_CORR calcflag)
|
69
|
+
{
|
70
|
+
size_t i;
|
71
|
+
double re1, re2, im1, im2;
|
72
|
+
void (*complex_cal)(double, double, double, double, double*, double*);
|
73
|
+
|
74
|
+
switch (calcflag) {
|
75
|
+
case RB_GSL_FFT_CONVOLVE:
|
76
|
+
complex_cal = complex_mul;
|
77
|
+
data3[0] = data1[0]*data2[0];
|
78
|
+
data3[size-1] = data1[size-1]*data2[size-1];
|
79
|
+
break;
|
80
|
+
case RB_GSL_FFT_CORRELATE:
|
81
|
+
data3[0] = data1[0]*data2[0];
|
82
|
+
data3[size-1] = data1[size-1]*data2[size-1];
|
83
|
+
complex_cal = complex_conj_mul;
|
84
|
+
break;
|
85
|
+
case RB_GSL_FFT_DECONVOLVE:
|
86
|
+
complex_cal = complex_div;
|
87
|
+
data3[0] = data1[0]/data2[0];
|
88
|
+
data3[size-1] = data1[size-1]/data2[size-1];
|
89
|
+
break;
|
90
|
+
default:
|
91
|
+
rb_raise(rb_eArgError, "Wrong flag.");
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
|
95
|
+
for (i = 1; i < size-1; i+=2) {
|
96
|
+
re1 = data1[i]; im1 = data1[i+1];
|
97
|
+
re2 = data2[i]; im2 = data2[i+1];
|
98
|
+
(*complex_cal)(re1, im1, re2, im2, &data3[i], &data3[i+1]);
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE rb_gsl_fft_conv_corr(int argc, VALUE *argv, VALUE obj,
|
104
|
+
enum FFT_CONV_CORR flag1,
|
105
|
+
enum FFT_CONV_CORR flag2)
|
106
|
+
{
|
107
|
+
double *data1, *data2, *data3;
|
108
|
+
size_t stride1, stride2, stride3 = 1, size1, size2;
|
109
|
+
#ifdef HAVE_NARRAY_H
|
110
|
+
int naflag1, naflag2, shape;
|
111
|
+
#else
|
112
|
+
int naflag1, naflag2;
|
113
|
+
#endif
|
114
|
+
gsl_vector *v = NULL;
|
115
|
+
gsl_fft_halfcomplex_wavetable *table = NULL;
|
116
|
+
gsl_fft_real_wavetable *rtable = NULL;
|
117
|
+
gsl_fft_real_workspace *space = NULL, *space2 = NULL;
|
118
|
+
int flagt = 0, flagw = 0;
|
119
|
+
// size_t i;
|
120
|
+
gsl_vector *vtmp1 = NULL, *vtmp2 = NULL;
|
121
|
+
VALUE ary;
|
122
|
+
switch (argc) {
|
123
|
+
case 3:
|
124
|
+
data1 = get_ptr_double3(obj, &size1, &stride1, &naflag1);
|
125
|
+
data2 = get_ptr_double3(argv[0], &size2, &stride2, &naflag2);
|
126
|
+
CHECK_WAVETABLE(argv[1]);
|
127
|
+
Data_Get_Struct(argv[1], gsl_fft_halfcomplex_wavetable, table);
|
128
|
+
CHECK_WORKSPACE(argv[2]);
|
129
|
+
Data_Get_Struct(argv[2], gsl_fft_real_workspace, space);
|
130
|
+
break;
|
131
|
+
case 2:
|
132
|
+
data1 = get_ptr_double3(obj, &size1, &stride1, &naflag1);
|
133
|
+
data2 = get_ptr_double3(argv[0], &size2, &stride2, &naflag2);
|
134
|
+
if (WAVETABLE_P(argv[1])) {
|
135
|
+
Data_Get_Struct(argv[1], gsl_fft_halfcomplex_wavetable, table);
|
136
|
+
space = gsl_fft_real_workspace_alloc(size1);
|
137
|
+
flagw = 1;
|
138
|
+
} else if (WORKSPACE_P(argv[1])) {
|
139
|
+
Data_Get_Struct(argv[1], gsl_fft_real_workspace, space);
|
140
|
+
table = gsl_fft_halfcomplex_wavetable_alloc(size1);
|
141
|
+
flagt = 1;
|
142
|
+
} else {
|
143
|
+
rb_raise(rb_eTypeError,
|
144
|
+
"wrong argument type %s "
|
145
|
+
"(FFT::HalfComplex::Wavetable or FFT::Real::Workspace expected)",
|
146
|
+
rb_class2name(CLASS_OF(argv[2])));
|
147
|
+
}
|
148
|
+
break;
|
149
|
+
case 1:
|
150
|
+
data1 = get_ptr_double3(obj, &size1, &stride1, &naflag1);
|
151
|
+
data2 = get_ptr_double3(argv[0], &size2, &stride2, &naflag2);
|
152
|
+
table = gsl_fft_halfcomplex_wavetable_alloc(size1);
|
153
|
+
space = gsl_fft_real_workspace_alloc(size1);
|
154
|
+
flagt = 1;
|
155
|
+
flagw = 1;
|
156
|
+
break;
|
157
|
+
default:
|
158
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-3)", argc);
|
159
|
+
}
|
160
|
+
|
161
|
+
switch (naflag1*naflag2) {
|
162
|
+
case 0:
|
163
|
+
v = gsl_vector_alloc(size1);
|
164
|
+
switch (flag1) {
|
165
|
+
case RB_GSL_FFT_REAL:
|
166
|
+
ary = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
|
167
|
+
break;
|
168
|
+
default:
|
169
|
+
ary = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
|
170
|
+
break;
|
171
|
+
}
|
172
|
+
data3 = v->data;
|
173
|
+
stride3 = 1;
|
174
|
+
break;
|
175
|
+
case 1:
|
176
|
+
#ifdef HAVE_NARRAY_H
|
177
|
+
shape = (int) size1;
|
178
|
+
ary = na_make_object(NA_DFLOAT, 1, &shape, cNArray);
|
179
|
+
data3 = NA_PTR_TYPE(ary, double*);
|
180
|
+
stride3 = 1;
|
181
|
+
#endif
|
182
|
+
break;
|
183
|
+
default:
|
184
|
+
break;
|
185
|
+
}
|
186
|
+
switch (flag1) {
|
187
|
+
case RB_GSL_FFT_REAL: // do FFT
|
188
|
+
vtmp1 = gsl_vector_alloc(size1);
|
189
|
+
vtmp2 = gsl_vector_alloc(size2);
|
190
|
+
memcpy(vtmp1->data, data1, sizeof(double)*size1);
|
191
|
+
memcpy(vtmp2->data, data2, sizeof(double)*size2);
|
192
|
+
data1 = vtmp1->data;
|
193
|
+
data2 = vtmp2->data;
|
194
|
+
rtable = gsl_fft_real_wavetable_alloc(size1);
|
195
|
+
if (size1 == space->n) {
|
196
|
+
gsl_fft_real_transform(data1, stride1, size1, rtable, space);
|
197
|
+
} else {
|
198
|
+
space2 = gsl_fft_real_workspace_alloc(size1);
|
199
|
+
gsl_fft_real_transform(data1, stride1, size1, rtable, space2);
|
200
|
+
/* no freeing space2 here */
|
201
|
+
}
|
202
|
+
if (size1 != size2) {
|
203
|
+
if (rtable) gsl_fft_real_wavetable_free(rtable);
|
204
|
+
rtable = gsl_fft_real_wavetable_alloc(size2);
|
205
|
+
}
|
206
|
+
if (size2 == space->n) {
|
207
|
+
gsl_fft_real_transform(data2, stride2, size2, rtable, space);
|
208
|
+
} else if (size2 == size1) {
|
209
|
+
gsl_fft_real_transform(data2, stride2, size2, rtable, space2);
|
210
|
+
gsl_fft_real_workspace_free(space2);
|
211
|
+
} else {
|
212
|
+
if (space2) gsl_fft_real_workspace_free(space2);
|
213
|
+
space2 = gsl_fft_real_workspace_alloc(size2);
|
214
|
+
gsl_fft_real_transform(data2, stride2, size2, rtable, space2);
|
215
|
+
gsl_fft_real_workspace_free(space2);
|
216
|
+
}
|
217
|
+
gsl_fft_real_wavetable_free(rtable);
|
218
|
+
space2 = NULL;
|
219
|
+
rtable = NULL;
|
220
|
+
break;
|
221
|
+
case RB_GSL_FFT_HALFCOMPLEX:
|
222
|
+
/* do nothing */
|
223
|
+
break;
|
224
|
+
default:
|
225
|
+
/* not occur */
|
226
|
+
break;
|
227
|
+
}
|
228
|
+
|
229
|
+
rbgsl_calc_conv_corr_c(data1, data2, data3, size1, table, space, flag2);
|
230
|
+
|
231
|
+
if (flag1 == RB_GSL_FFT_REAL) {
|
232
|
+
gsl_fft_halfcomplex_inverse(data3, 1, size1, table, space);
|
233
|
+
// for (i = 0; i < size1; i++) data3[i] /= size1;
|
234
|
+
}
|
235
|
+
|
236
|
+
if (flagt == 1) gsl_fft_halfcomplex_wavetable_free(table);
|
237
|
+
if (flagw == 1) gsl_fft_real_workspace_free(space);
|
238
|
+
if (vtmp1) gsl_vector_free(vtmp1);
|
239
|
+
if (vtmp2) gsl_vector_free(vtmp2);
|
240
|
+
return ary;
|
241
|
+
}
|
242
|
+
|
243
|
+
/* GSL::Vector#convolve */
|
244
|
+
static VALUE rb_gsl_fft_real_convolve(int argc, VALUE *argv, VALUE obj)
|
245
|
+
{
|
246
|
+
return rb_gsl_fft_conv_corr(argc, argv, obj,
|
247
|
+
RB_GSL_FFT_REAL,
|
248
|
+
RB_GSL_FFT_CONVOLVE);
|
249
|
+
}
|
250
|
+
/* GSL::Vector#deconvolve */
|
251
|
+
static VALUE rb_gsl_fft_real_deconvolve(int argc, VALUE *argv, VALUE obj)
|
252
|
+
{
|
253
|
+
return rb_gsl_fft_conv_corr(argc, argv, obj,
|
254
|
+
RB_GSL_FFT_REAL,
|
255
|
+
RB_GSL_FFT_DECONVOLVE);
|
256
|
+
}
|
257
|
+
|
258
|
+
/* GSL::Vector#correlate */
|
259
|
+
static VALUE rb_gsl_fft_real_correlate(int argc, VALUE *argv, VALUE obj)
|
260
|
+
{
|
261
|
+
return rb_gsl_fft_conv_corr(argc, argv, obj,
|
262
|
+
RB_GSL_FFT_REAL,
|
263
|
+
RB_GSL_FFT_CORRELATE);
|
264
|
+
}
|
265
|
+
|
266
|
+
/* GSL::Vector#halfcomplex_convolve */
|
267
|
+
static VALUE rb_gsl_fft_halfcomplex_convolve(int argc, VALUE *argv, VALUE obj)
|
268
|
+
{
|
269
|
+
return rb_gsl_fft_conv_corr(argc, argv, obj,
|
270
|
+
RB_GSL_FFT_HALFCOMPLEX,
|
271
|
+
RB_GSL_FFT_CONVOLVE);
|
272
|
+
}
|
273
|
+
/* GSL::Vector#halfcomplex_deconvolve */
|
274
|
+
static VALUE rb_gsl_fft_halfcomplex_deconvolve(int argc, VALUE *argv, VALUE obj)
|
275
|
+
{
|
276
|
+
return rb_gsl_fft_conv_corr(argc, argv, obj,
|
277
|
+
RB_GSL_FFT_HALFCOMPLEX,
|
278
|
+
RB_GSL_FFT_DECONVOLVE);
|
279
|
+
}
|
280
|
+
/* GSL::Vector#halfcomplex_correlate */
|
281
|
+
static VALUE rb_gsl_fft_halfcomplex_correlate(int argc, VALUE *argv, VALUE obj)
|
282
|
+
{
|
283
|
+
return rb_gsl_fft_conv_corr(argc, argv, obj,
|
284
|
+
RB_GSL_FFT_HALFCOMPLEX,
|
285
|
+
RB_GSL_FFT_CORRELATE);
|
286
|
+
}
|
287
|
+
|
288
|
+
void Init_gsl_signal(VALUE module)
|
289
|
+
{
|
290
|
+
rb_define_method(cgsl_vector, "real_convolve", rb_gsl_fft_real_convolve, -1);
|
291
|
+
rb_define_method(cgsl_vector, "real_deconvolve", rb_gsl_fft_real_deconvolve, -1);
|
292
|
+
rb_define_method(cgsl_vector, "real_correlate", rb_gsl_fft_real_correlate, -1);
|
293
|
+
|
294
|
+
rb_define_alias(cgsl_vector, "convolve", "real_convolve");
|
295
|
+
rb_define_alias(cgsl_vector, "deconvolve", "real_deconvolve");
|
296
|
+
rb_define_alias(cgsl_vector, "correlate", "real_correlate");
|
297
|
+
|
298
|
+
rb_define_method(cgsl_vector, "halfcomplex_convolve", rb_gsl_fft_halfcomplex_convolve, -1);
|
299
|
+
rb_define_method(cgsl_vector, "halfcomplex_deconvolve", rb_gsl_fft_halfcomplex_deconvolve, -1);
|
300
|
+
rb_define_method(cgsl_vector, "halfcomplex_correlate", rb_gsl_fft_halfcomplex_correlate, -1);
|
301
|
+
|
302
|
+
rb_define_alias(cgsl_vector, "hc_convolve", "halfcomplex_convolve");
|
303
|
+
rb_define_alias(cgsl_vector, "hc_deconvolve", "halfcomplex_deconvolve");
|
304
|
+
rb_define_alias(cgsl_vector, "hc_correlate", "halfcomplex_correlate");
|
305
|
+
}
|
306
|
+
|
307
|
+
#undef WAVETABLE_P
|
308
|
+
#undef CHECK_WAVETABLE
|
309
|
+
#undef WORKSPACE_P
|
310
|
+
#undef CHECK_WORKSPACE
|