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
data/ext/array_complex.c
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
/*
|
2
|
+
array_complex.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
|
+
#include "rb_gsl_config.h"
|
12
|
+
|
13
|
+
#include "rb_gsl_complex.h"
|
14
|
+
#include "rb_gsl_array.h"
|
15
|
+
|
16
|
+
enum {
|
17
|
+
GSL_COMPLEX_ADD,
|
18
|
+
GSL_COMPLEX_SUB,
|
19
|
+
GSL_COMPLEX_MUL,
|
20
|
+
GSL_COMPLEX_DIV,
|
21
|
+
};
|
22
|
+
|
23
|
+
static VALUE rb_gsl_complex_arithmetics5(int flag, VALUE obj, VALUE bb);
|
24
|
+
|
25
|
+
static VALUE rb_gsl_complex_arithmetics5(int flag, VALUE obj, VALUE bb)
|
26
|
+
{
|
27
|
+
gsl_complex *a = NULL, *b = NULL, *c = NULL, tmp, tmp2;
|
28
|
+
gsl_matrix *m = NULL;
|
29
|
+
gsl_matrix_complex *cm = NULL, *cmself = NULL;
|
30
|
+
gsl_vector *v = NULL;
|
31
|
+
gsl_vector_complex *cv = NULL, *cvnew = NULL;
|
32
|
+
gsl_complex (*func1)(gsl_complex, gsl_complex);
|
33
|
+
int (*func2)(gsl_matrix_complex*, const gsl_matrix_complex*);
|
34
|
+
int (*func3)(gsl_matrix_complex*, const gsl_complex);
|
35
|
+
int flagcm = 0;
|
36
|
+
switch (flag) {
|
37
|
+
case GSL_COMPLEX_ADD:
|
38
|
+
func1 = gsl_complex_add;
|
39
|
+
func2 = gsl_matrix_complex_add;
|
40
|
+
func3 = gsl_matrix_complex_add_constant;
|
41
|
+
break;
|
42
|
+
case GSL_COMPLEX_SUB:
|
43
|
+
func1 = gsl_complex_sub;
|
44
|
+
func2 = gsl_matrix_complex_sub;
|
45
|
+
func3 = gsl_matrix_complex_add_constant;
|
46
|
+
break;
|
47
|
+
case GSL_COMPLEX_MUL:
|
48
|
+
func1 = gsl_complex_mul;
|
49
|
+
func2 = gsl_matrix_complex_mul_elements;
|
50
|
+
func3 = gsl_matrix_complex_scale;
|
51
|
+
break;
|
52
|
+
case GSL_COMPLEX_DIV:
|
53
|
+
func1 = gsl_complex_div;
|
54
|
+
func2 = gsl_matrix_complex_div_elements;
|
55
|
+
func3 = gsl_matrix_complex_scale;
|
56
|
+
break;
|
57
|
+
default:
|
58
|
+
rb_raise(rb_eRuntimeError, "undefined operation");
|
59
|
+
}
|
60
|
+
|
61
|
+
CHECK_COMPLEX(obj);
|
62
|
+
Data_Get_Struct(obj, gsl_complex, a);
|
63
|
+
switch (TYPE(bb)) {
|
64
|
+
case T_FLOAT:
|
65
|
+
case T_FIXNUM:
|
66
|
+
case T_BIGNUM:
|
67
|
+
tmp2 = gsl_complex_rect(NUM2DBL(bb), 0.0);
|
68
|
+
b = &tmp2;
|
69
|
+
tmp = (*func1)(*a, *b);
|
70
|
+
switch (flag) {
|
71
|
+
case GSL_COMPLEX_ADD:
|
72
|
+
case GSL_COMPLEX_SUB:
|
73
|
+
case GSL_COMPLEX_MUL:
|
74
|
+
case GSL_COMPLEX_DIV:
|
75
|
+
c = ALLOC(gsl_complex);
|
76
|
+
*c = tmp;
|
77
|
+
return Data_Wrap_Struct(cgsl_complex, 0, free, c);
|
78
|
+
break;
|
79
|
+
}
|
80
|
+
break;
|
81
|
+
default:
|
82
|
+
if (COMPLEX_P(bb)) {
|
83
|
+
Data_Get_Struct(bb, gsl_complex, b);
|
84
|
+
tmp = (*func1)(*a, *b);
|
85
|
+
switch (flag) {
|
86
|
+
case GSL_COMPLEX_ADD:
|
87
|
+
case GSL_COMPLEX_SUB:
|
88
|
+
case GSL_COMPLEX_MUL:
|
89
|
+
case GSL_COMPLEX_DIV:
|
90
|
+
c = ALLOC(gsl_complex);
|
91
|
+
*c = tmp;
|
92
|
+
return Data_Wrap_Struct(cgsl_complex, 0, free, c);
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
} else {
|
96
|
+
if (VECTOR_P(bb)) {
|
97
|
+
Data_Get_Struct(bb, gsl_vector, v);
|
98
|
+
cv = vector_to_complex(v);
|
99
|
+
cvnew = gsl_vector_complex_alloc(v->size);
|
100
|
+
if (cvnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
|
101
|
+
gsl_vector_complex_set_all(cvnew, *a);
|
102
|
+
switch (flag) {
|
103
|
+
case GSL_COMPLEX_ADD:
|
104
|
+
gsl_vector_complex_add(cvnew, cv);
|
105
|
+
break;
|
106
|
+
case GSL_COMPLEX_SUB:
|
107
|
+
gsl_vector_complex_sub(cvnew, cv);
|
108
|
+
break;
|
109
|
+
case GSL_COMPLEX_MUL:
|
110
|
+
gsl_vector_complex_mul(cvnew, cv);
|
111
|
+
break;
|
112
|
+
case GSL_COMPLEX_DIV:
|
113
|
+
gsl_vector_complex_add(cvnew, cv);
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
gsl_vector_complex_free(cv);
|
117
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cvnew);
|
118
|
+
}
|
119
|
+
if (VECTOR_COMPLEX_P(bb)) {
|
120
|
+
Data_Get_Struct(bb, gsl_vector_complex, cv);
|
121
|
+
cvnew = gsl_vector_complex_alloc(v->size);
|
122
|
+
if (cvnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
|
123
|
+
gsl_vector_complex_set_all(cvnew, *a);
|
124
|
+
switch (flag) {
|
125
|
+
case GSL_COMPLEX_ADD:
|
126
|
+
gsl_vector_complex_add(cvnew, cv);
|
127
|
+
break;
|
128
|
+
case GSL_COMPLEX_SUB:
|
129
|
+
gsl_vector_complex_sub(cvnew, cv);
|
130
|
+
break;
|
131
|
+
case GSL_COMPLEX_MUL:
|
132
|
+
gsl_vector_complex_mul(cvnew, cv);
|
133
|
+
break;
|
134
|
+
case GSL_COMPLEX_DIV:
|
135
|
+
gsl_vector_complex_add(cvnew, cv);
|
136
|
+
break;
|
137
|
+
}
|
138
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cvnew);
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
if (MATRIX_P(bb)) {
|
143
|
+
Data_Get_Struct(bb, gsl_matrix, m);
|
144
|
+
cm = matrix_to_complex(m);
|
145
|
+
flagcm = 1;
|
146
|
+
} else if (MATRIX_COMPLEX_P(bb)) {
|
147
|
+
Data_Get_Struct(bb, gsl_matrix_complex, cm);
|
148
|
+
} else {
|
149
|
+
rb_raise(rb_eTypeError, "wrong argument type %s", rb_class2name(CLASS_OF(bb)));
|
150
|
+
}
|
151
|
+
cmself = gsl_matrix_complex_alloc(m->size1, m->size2);
|
152
|
+
if (cmself == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
|
153
|
+
gsl_matrix_complex_set_all(cmself, *a);
|
154
|
+
switch (flag) {
|
155
|
+
case GSL_COMPLEX_ADD:
|
156
|
+
gsl_matrix_complex_add(cmself, cm);
|
157
|
+
break;
|
158
|
+
case GSL_COMPLEX_SUB:
|
159
|
+
gsl_matrix_complex_sub(cmself, cm);
|
160
|
+
break;
|
161
|
+
case GSL_COMPLEX_MUL:
|
162
|
+
gsl_matrix_complex_mul_elements(cmself, cm);
|
163
|
+
break;
|
164
|
+
case GSL_COMPLEX_DIV:
|
165
|
+
gsl_matrix_complex_div_elements(cmself, cm);
|
166
|
+
break;
|
167
|
+
}
|
168
|
+
if (flagcm == 1) gsl_matrix_complex_free(cm);
|
169
|
+
return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmself);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
/* never reach here */
|
173
|
+
return Qnil;
|
174
|
+
}
|
175
|
+
|
176
|
+
static VALUE rb_gsl_complex_add(VALUE obj, VALUE bb)
|
177
|
+
{
|
178
|
+
return rb_gsl_complex_arithmetics5(GSL_COMPLEX_ADD, obj, bb);
|
179
|
+
}
|
180
|
+
|
181
|
+
static VALUE rb_gsl_complex_sub(VALUE obj, VALUE bb)
|
182
|
+
{
|
183
|
+
return rb_gsl_complex_arithmetics5(GSL_COMPLEX_SUB, obj, bb);
|
184
|
+
}
|
185
|
+
|
186
|
+
static VALUE rb_gsl_complex_mul(VALUE obj, VALUE bb)
|
187
|
+
{
|
188
|
+
return rb_gsl_complex_arithmetics5(GSL_COMPLEX_MUL, obj, bb);
|
189
|
+
}
|
190
|
+
|
191
|
+
static VALUE rb_gsl_complex_div(VALUE obj, VALUE bb)
|
192
|
+
{
|
193
|
+
return rb_gsl_complex_arithmetics5(GSL_COMPLEX_DIV, obj, bb);
|
194
|
+
}
|
195
|
+
|
196
|
+
static VALUE rb_gsl_complex_coerce(VALUE obj, VALUE other)
|
197
|
+
{
|
198
|
+
gsl_complex *c = NULL;
|
199
|
+
gsl_matrix *m = NULL;
|
200
|
+
gsl_matrix_complex *cmnew = NULL, *cmself = NULL;
|
201
|
+
VALUE vcmself, vcmnew;
|
202
|
+
double x;
|
203
|
+
switch (TYPE(other)) {
|
204
|
+
case T_FLOAT: case T_FIXNUM: case T_BIGNUM:
|
205
|
+
x = NUM2DBL(other);
|
206
|
+
c = ALLOC(gsl_complex);
|
207
|
+
*c = gsl_complex_rect(x, 0.0);
|
208
|
+
return rb_ary_new3(2, Data_Wrap_Struct(cgsl_complex, 0, free, c),
|
209
|
+
obj);
|
210
|
+
break;
|
211
|
+
default:
|
212
|
+
if (MATRIX_P(other)) {
|
213
|
+
Data_Get_Struct(other, gsl_matrix, m);
|
214
|
+
cmnew = matrix_to_complex(m);
|
215
|
+
vcmnew = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
|
216
|
+
cmself = gsl_matrix_complex_alloc(m->size1, m->size2);
|
217
|
+
if (cmself == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
|
218
|
+
Data_Get_Struct(obj, gsl_complex, c);
|
219
|
+
gsl_matrix_complex_set_all(cmself, *c);
|
220
|
+
vcmself = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmself);
|
221
|
+
return rb_ary_new3(2, vcmself, vcmnew);
|
222
|
+
}
|
223
|
+
if (MATRIX_COMPLEX_P(other)) {
|
224
|
+
Data_Get_Struct(other, gsl_matrix_complex, cmnew);
|
225
|
+
cmself = gsl_matrix_complex_alloc(cmnew->size1, cmnew->size2);
|
226
|
+
if (cmself == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
|
227
|
+
vcmself = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmself);
|
228
|
+
return rb_ary_new3(2, vcmself, other);
|
229
|
+
} else {
|
230
|
+
rb_raise(rb_eTypeError, "cannot coerce to GSL::Complex");
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
void Init_gsl_array_complex(VALUE mgsl)
|
236
|
+
{
|
237
|
+
rb_define_method(cgsl_complex, "coerce", rb_gsl_complex_coerce, 1);
|
238
|
+
|
239
|
+
rb_define_method(cgsl_complex, "add", rb_gsl_complex_add, 1);
|
240
|
+
rb_define_alias(cgsl_complex, "+", "add");
|
241
|
+
rb_define_method(cgsl_complex, "sub", rb_gsl_complex_sub, 1);
|
242
|
+
rb_define_alias(cgsl_complex, "-", "sub");
|
243
|
+
rb_define_method(cgsl_complex, "mul", rb_gsl_complex_mul, 1);
|
244
|
+
rb_define_alias(cgsl_complex, "*", "mul");
|
245
|
+
rb_define_method(cgsl_complex, "div", rb_gsl_complex_div, 1);
|
246
|
+
rb_define_alias(cgsl_complex, "/", "div");
|
247
|
+
}
|
data/ext/blas.c
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
blas.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
|
+
#include "rb_gsl_config.h"
|
12
|
+
|
13
|
+
#include <gsl/gsl_blas.h>
|
14
|
+
#include "rb_gsl_common.h"
|
15
|
+
#include "rb_gsl_array.h"
|
16
|
+
|
17
|
+
void Init_gsl_blas1(VALUE module);
|
18
|
+
void Init_gsl_blas2(VALUE module);
|
19
|
+
void Init_gsl_blas3(VALUE module);
|
20
|
+
|
21
|
+
void Init_gsl_blas(VALUE module)
|
22
|
+
{
|
23
|
+
VALUE mgsl_blas;
|
24
|
+
mgsl_blas = rb_define_module_under(module, "Blas");
|
25
|
+
|
26
|
+
Init_gsl_blas1(mgsl_blas);
|
27
|
+
Init_gsl_blas2(mgsl_blas);
|
28
|
+
Init_gsl_blas3(mgsl_blas);
|
29
|
+
}
|
data/ext/blas1.c
ADDED
@@ -0,0 +1,731 @@
|
|
1
|
+
/*
|
2
|
+
blas1.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
|
+
#include "rb_gsl_config.h"
|
12
|
+
|
13
|
+
#include <gsl/gsl_blas.h>
|
14
|
+
#include "rb_gsl_complex.h"
|
15
|
+
#include "rb_gsl_array.h"
|
16
|
+
#include "rb_gsl_common.h"
|
17
|
+
|
18
|
+
static int get_vector1(int argc, VALUE *argv, VALUE obj, gsl_vector **x);
|
19
|
+
static int get_vector_complex1(int argc, VALUE *argv, VALUE obj, gsl_vector_complex **x);
|
20
|
+
static int get_vector2(int argc, VALUE *argv, VALUE obj,
|
21
|
+
gsl_vector **x, gsl_vector **y);
|
22
|
+
static int get_vector_complex2(int argc, VALUE *argv, VALUE obj,
|
23
|
+
gsl_vector_complex **x, gsl_vector_complex **y);
|
24
|
+
|
25
|
+
static int get_vector1(int argc, VALUE *argv, VALUE obj, gsl_vector **x)
|
26
|
+
{
|
27
|
+
int flag = 0;
|
28
|
+
switch (TYPE(obj)) {
|
29
|
+
case T_MODULE:
|
30
|
+
case T_CLASS:
|
31
|
+
case T_OBJECT:
|
32
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
33
|
+
argc);
|
34
|
+
Data_Get_Vector(argv[0], (*x));
|
35
|
+
break;
|
36
|
+
default:
|
37
|
+
Data_Get_Vector(obj, (*x));
|
38
|
+
flag = 1;
|
39
|
+
break;
|
40
|
+
}
|
41
|
+
return flag;
|
42
|
+
}
|
43
|
+
|
44
|
+
static int get_vector_complex1(int argc, VALUE *argv, VALUE obj, gsl_vector_complex **x)
|
45
|
+
{
|
46
|
+
int flag = 0;
|
47
|
+
switch (TYPE(obj)) {
|
48
|
+
case T_MODULE:
|
49
|
+
case T_CLASS:
|
50
|
+
case T_OBJECT:
|
51
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
52
|
+
argc);
|
53
|
+
CHECK_VECTOR_COMPLEX(argv[0]);
|
54
|
+
Data_Get_Struct(argv[0], gsl_vector_complex, (*x));
|
55
|
+
break;
|
56
|
+
default:
|
57
|
+
Data_Get_Struct(obj, gsl_vector_complex, (*x));
|
58
|
+
flag = 1;
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
return flag;
|
62
|
+
}
|
63
|
+
|
64
|
+
static int get_vector2(int argc, VALUE *argv, VALUE obj,
|
65
|
+
gsl_vector **x, gsl_vector **y)
|
66
|
+
{
|
67
|
+
int flag = 0;
|
68
|
+
switch (TYPE(obj)) {
|
69
|
+
case T_MODULE:
|
70
|
+
case T_CLASS:
|
71
|
+
case T_OBJECT:
|
72
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
73
|
+
argc);
|
74
|
+
Data_Get_Vector(argv[0], (*x));
|
75
|
+
Data_Get_Vector(argv[1], (*y));
|
76
|
+
break;
|
77
|
+
default:
|
78
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
79
|
+
argc);
|
80
|
+
Data_Get_Vector(obj, (*x));
|
81
|
+
Data_Get_Vector(argv[0], (*y));
|
82
|
+
flag = 1;
|
83
|
+
break;
|
84
|
+
}
|
85
|
+
return flag;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
static int get_vector_complex2(int argc, VALUE *argv, VALUE obj,
|
90
|
+
gsl_vector_complex **x, gsl_vector_complex **y)
|
91
|
+
{
|
92
|
+
int flag = 0;
|
93
|
+
switch (TYPE(obj)) {
|
94
|
+
case T_MODULE:
|
95
|
+
case T_CLASS:
|
96
|
+
case T_OBJECT:
|
97
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
98
|
+
argc);
|
99
|
+
CHECK_VECTOR_COMPLEX(argv[0]);
|
100
|
+
CHECK_VECTOR_COMPLEX(argv[1]);
|
101
|
+
Data_Get_Struct(argv[0], gsl_vector_complex, (*x));
|
102
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, (*y));
|
103
|
+
break;
|
104
|
+
default:
|
105
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
106
|
+
argc);
|
107
|
+
CHECK_VECTOR_COMPLEX(argv[0]);
|
108
|
+
Data_Get_Struct(obj, gsl_vector_complex, (*x));
|
109
|
+
Data_Get_Struct(argv[0], gsl_vector_complex, (*y));
|
110
|
+
flag = 1;
|
111
|
+
break;
|
112
|
+
}
|
113
|
+
return flag;
|
114
|
+
}
|
115
|
+
|
116
|
+
static VALUE rb_gsl_blas_ddot(int argc, VALUE *argv, VALUE obj)
|
117
|
+
{
|
118
|
+
double r;
|
119
|
+
int status;
|
120
|
+
gsl_vector *x = NULL, *y = NULL;
|
121
|
+
get_vector2(argc, argv, obj, &x, &y);
|
122
|
+
status = gsl_blas_ddot(x, y, &r);
|
123
|
+
return rb_float_new(r);
|
124
|
+
}
|
125
|
+
|
126
|
+
static VALUE rb_gsl_blas_zdotu(int argc, VALUE *argv, VALUE obj)
|
127
|
+
{
|
128
|
+
gsl_complex *r;
|
129
|
+
int status;
|
130
|
+
gsl_vector_complex *x = NULL, *y = NULL;
|
131
|
+
get_vector_complex2(argc, argv, obj, &x, &y);
|
132
|
+
r = ALLOC(gsl_complex);
|
133
|
+
status = gsl_blas_zdotu(x, y, r);
|
134
|
+
return Data_Wrap_Struct(cgsl_complex, 0, free, r);
|
135
|
+
}
|
136
|
+
|
137
|
+
static VALUE rb_gsl_blas_zdotc(int argc, VALUE *argv, VALUE obj)
|
138
|
+
{
|
139
|
+
gsl_complex *r;
|
140
|
+
int status;
|
141
|
+
gsl_vector_complex *x = NULL, *y = NULL;
|
142
|
+
get_vector_complex2(argc, argv, obj, &x, &y);
|
143
|
+
r = ALLOC(gsl_complex);
|
144
|
+
status = gsl_blas_zdotc(x, y, r);
|
145
|
+
return Data_Wrap_Struct(cgsl_complex, 0, free, r);
|
146
|
+
}
|
147
|
+
|
148
|
+
static VALUE rb_gsl_blas_dnrm2(int argc, VALUE *argv, VALUE obj)
|
149
|
+
{
|
150
|
+
gsl_vector *x = NULL;
|
151
|
+
get_vector1(argc, argv, obj, &x);
|
152
|
+
return rb_float_new(gsl_blas_dnrm2(x));
|
153
|
+
}
|
154
|
+
|
155
|
+
static VALUE rb_gsl_blas_dnrm(int argc, VALUE *argv, VALUE obj)
|
156
|
+
{
|
157
|
+
gsl_vector *x = NULL;
|
158
|
+
double a;
|
159
|
+
get_vector1(argc, argv, obj, &x);
|
160
|
+
a = gsl_blas_dnrm2(x);
|
161
|
+
return rb_float_new(a*a);
|
162
|
+
}
|
163
|
+
|
164
|
+
static VALUE rb_gsl_blas_dznrm2(int argc, VALUE *argv, VALUE obj)
|
165
|
+
{
|
166
|
+
gsl_vector_complex *x = NULL;
|
167
|
+
get_vector_complex1(argc, argv, obj, &x);
|
168
|
+
return rb_float_new(gsl_blas_dznrm2(x));
|
169
|
+
}
|
170
|
+
|
171
|
+
static VALUE rb_gsl_blas_dasum(int argc, VALUE *argv, VALUE obj)
|
172
|
+
{
|
173
|
+
gsl_vector *x = NULL;
|
174
|
+
get_vector1(argc, argv, obj, &x);
|
175
|
+
return rb_float_new(gsl_blas_dasum(x));
|
176
|
+
}
|
177
|
+
|
178
|
+
static VALUE rb_gsl_blas_dzasum(int argc, VALUE *argv, VALUE obj)
|
179
|
+
{
|
180
|
+
gsl_vector_complex *x = NULL;
|
181
|
+
get_vector_complex1(argc, argv, obj, &x);
|
182
|
+
return rb_float_new(gsl_blas_dzasum(x));
|
183
|
+
}
|
184
|
+
|
185
|
+
static VALUE rb_gsl_blas_idamax(int argc, VALUE *argv, VALUE obj)
|
186
|
+
{
|
187
|
+
gsl_vector *x = NULL;
|
188
|
+
get_vector1(argc, argv, obj, &x);
|
189
|
+
return INT2FIX(gsl_blas_idamax(x));
|
190
|
+
}
|
191
|
+
|
192
|
+
static VALUE rb_gsl_blas_izamax(int argc, VALUE *argv, VALUE obj)
|
193
|
+
{
|
194
|
+
gsl_vector_complex *x = NULL;
|
195
|
+
get_vector_complex1(argc, argv, obj, &x);
|
196
|
+
return INT2FIX(gsl_blas_izamax(x));
|
197
|
+
}
|
198
|
+
|
199
|
+
static VALUE rb_gsl_blas_dswap(int argc, VALUE *argv, VALUE obj)
|
200
|
+
{
|
201
|
+
gsl_vector *x = NULL, *y = NULL;
|
202
|
+
get_vector2(argc, argv, obj, &x, &y);
|
203
|
+
return INT2FIX(gsl_blas_dswap(x, y));
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE rb_gsl_blas_zswap(int argc, VALUE *argv, VALUE obj)
|
207
|
+
{
|
208
|
+
gsl_vector_complex *x = NULL, *y = NULL;
|
209
|
+
get_vector_complex2(argc, argv, obj, &x, &y);
|
210
|
+
return INT2FIX(gsl_blas_zswap(x, y));
|
211
|
+
}
|
212
|
+
|
213
|
+
static VALUE rb_gsl_blas_dcopy(int argc, VALUE *argv, VALUE obj)
|
214
|
+
{
|
215
|
+
gsl_vector *x = NULL, *y = NULL;
|
216
|
+
get_vector2(argc, argv, obj, &x, &y);
|
217
|
+
return INT2FIX(gsl_blas_dcopy(x, y));
|
218
|
+
}
|
219
|
+
|
220
|
+
static VALUE rb_gsl_blas_zcopy(int argc, VALUE *argv, VALUE obj)
|
221
|
+
{
|
222
|
+
gsl_vector_complex *x = NULL, *y = NULL;
|
223
|
+
get_vector_complex2(argc, argv, obj, &x, &y);
|
224
|
+
return INT2FIX(gsl_blas_zcopy(x, y));
|
225
|
+
}
|
226
|
+
|
227
|
+
static VALUE rb_gsl_blas_daxpy(int argc, VALUE *argv, VALUE obj)
|
228
|
+
{
|
229
|
+
double a;
|
230
|
+
gsl_vector *x = NULL, *y = NULL;
|
231
|
+
switch (TYPE(obj)) {
|
232
|
+
case T_MODULE:
|
233
|
+
case T_CLASS:
|
234
|
+
case T_OBJECT:
|
235
|
+
get_vector2(argc-1, argv+1, obj, &x, &y);
|
236
|
+
Need_Float(argv[0]);
|
237
|
+
// a = RFLOAT(argv[0])->value;
|
238
|
+
a = NUM2DBL(argv[0]);
|
239
|
+
break;
|
240
|
+
default:
|
241
|
+
Data_Get_Struct(obj, gsl_vector, x);
|
242
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
243
|
+
argc);
|
244
|
+
Need_Float(argv[0]);
|
245
|
+
// a = RFLOAT(argv[0])->value;
|
246
|
+
a = NUM2DBL(argv[0]);
|
247
|
+
Data_Get_Vector(argv[1], y);
|
248
|
+
break;
|
249
|
+
}
|
250
|
+
gsl_blas_daxpy(a, x, y);
|
251
|
+
return argv[argc-1];
|
252
|
+
}
|
253
|
+
|
254
|
+
static VALUE rb_gsl_blas_daxpy2(int argc, VALUE *argv, VALUE obj)
|
255
|
+
{
|
256
|
+
double a;
|
257
|
+
gsl_vector *x = NULL, *y = NULL, *y2 = NULL;
|
258
|
+
switch (TYPE(obj)) {
|
259
|
+
case T_MODULE:
|
260
|
+
case T_CLASS:
|
261
|
+
case T_OBJECT:
|
262
|
+
get_vector2(argc-1, argv+1, obj, &x, &y);
|
263
|
+
Need_Float(argv[0]);
|
264
|
+
// a = RFLOAT(argv[0])->value;
|
265
|
+
a = NUM2DBL(argv[0]);
|
266
|
+
break;
|
267
|
+
default:
|
268
|
+
Data_Get_Struct(obj, gsl_vector, x);
|
269
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
270
|
+
argc);
|
271
|
+
Need_Float(argv[0]);
|
272
|
+
CHECK_VECTOR(argv[1]);
|
273
|
+
// a = RFLOAT(argv[0])->value;
|
274
|
+
a = NUM2DBL(argv[0]);
|
275
|
+
Data_Get_Struct(argv[1], gsl_vector, y);
|
276
|
+
break;
|
277
|
+
}
|
278
|
+
y2 = gsl_vector_alloc(y->size);
|
279
|
+
gsl_vector_memcpy(y2, y);
|
280
|
+
gsl_blas_daxpy(a, x, y2);
|
281
|
+
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, y2);
|
282
|
+
}
|
283
|
+
|
284
|
+
static VALUE rb_gsl_blas_zaxpy(int argc, VALUE *argv, VALUE obj)
|
285
|
+
{
|
286
|
+
gsl_complex *a = NULL;
|
287
|
+
gsl_vector_complex *x = NULL, *y = NULL;
|
288
|
+
switch (TYPE(obj)) {
|
289
|
+
case T_MODULE:
|
290
|
+
case T_CLASS:
|
291
|
+
case T_OBJECT:
|
292
|
+
CHECK_COMPLEX(argv[0]);
|
293
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
294
|
+
get_vector_complex2(argc-1, argv+1, obj, &x, &y);
|
295
|
+
break;
|
296
|
+
default:
|
297
|
+
Data_Get_Struct(obj, gsl_vector_complex, x);
|
298
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
299
|
+
argc);
|
300
|
+
CHECK_COMPLEX(argv[0]);
|
301
|
+
CHECK_VECTOR_COMPLEX(argv[1]);
|
302
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
303
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, y);
|
304
|
+
break;
|
305
|
+
}
|
306
|
+
|
307
|
+
gsl_blas_zaxpy(*a, x, y);
|
308
|
+
return argv[argc-1];
|
309
|
+
}
|
310
|
+
|
311
|
+
static VALUE rb_gsl_blas_zaxpy2(int argc, VALUE *argv, VALUE obj)
|
312
|
+
{
|
313
|
+
gsl_complex *a = NULL;
|
314
|
+
gsl_vector_complex *x = NULL, *y = NULL, *y2 = NULL;
|
315
|
+
switch (TYPE(obj)) {
|
316
|
+
case T_MODULE:
|
317
|
+
case T_CLASS:
|
318
|
+
case T_OBJECT:
|
319
|
+
get_vector_complex2(argc-1, argv+1, obj, &x, &y);
|
320
|
+
CHECK_COMPLEX(argv[0]);
|
321
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
322
|
+
break;
|
323
|
+
default:
|
324
|
+
Data_Get_Struct(obj, gsl_vector_complex, x);
|
325
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
326
|
+
argc);
|
327
|
+
CHECK_COMPLEX(argv[0]);
|
328
|
+
CHECK_VECTOR_COMPLEX(argv[1]);
|
329
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
330
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, y);
|
331
|
+
break;
|
332
|
+
}
|
333
|
+
y2 = gsl_vector_complex_alloc(y->size);
|
334
|
+
gsl_vector_complex_memcpy(y2, y);
|
335
|
+
gsl_blas_zaxpy(*a, x, y2);
|
336
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, y2);
|
337
|
+
}
|
338
|
+
|
339
|
+
static VALUE rb_gsl_blas_dscal(int argc, VALUE *argv, VALUE obj)
|
340
|
+
{
|
341
|
+
double a;
|
342
|
+
gsl_vector *x = NULL;
|
343
|
+
switch (TYPE(obj)) {
|
344
|
+
case T_MODULE:
|
345
|
+
case T_CLASS:
|
346
|
+
case T_OBJECT:
|
347
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
348
|
+
argc);
|
349
|
+
Need_Float(argv[0]);
|
350
|
+
CHECK_VECTOR(argv[1]);
|
351
|
+
// a = RFLOAT(argv[0])->value;
|
352
|
+
a = NUM2DBL(argv[0]);
|
353
|
+
Data_Get_Struct(argv[1], gsl_vector, x);
|
354
|
+
gsl_blas_dscal(a, x);
|
355
|
+
return argv[1];
|
356
|
+
break;
|
357
|
+
default:
|
358
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
359
|
+
argc);
|
360
|
+
Need_Float(argv[0]);
|
361
|
+
// a = RFLOAT(argv[0])->value;
|
362
|
+
a = NUM2DBL(argv[0]);
|
363
|
+
Data_Get_Struct(obj, gsl_vector, x);
|
364
|
+
gsl_blas_dscal(a, x);
|
365
|
+
return obj;
|
366
|
+
break;
|
367
|
+
}
|
368
|
+
return Qnil; /* never reach here */
|
369
|
+
}
|
370
|
+
|
371
|
+
static VALUE rb_gsl_blas_dscal2(int argc, VALUE *argv, VALUE obj)
|
372
|
+
{
|
373
|
+
double a;
|
374
|
+
gsl_vector *x = NULL, *xnew = NULL;
|
375
|
+
switch (TYPE(obj)) {
|
376
|
+
case T_MODULE:
|
377
|
+
case T_CLASS:
|
378
|
+
case T_OBJECT:
|
379
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
380
|
+
argc);
|
381
|
+
Need_Float(argv[0]);
|
382
|
+
CHECK_VECTOR(argv[1]);
|
383
|
+
a = NUM2DBL(argv[0]);
|
384
|
+
Data_Get_Struct(argv[1], gsl_vector, x);
|
385
|
+
break;
|
386
|
+
default:
|
387
|
+
Data_Get_Struct(obj, gsl_vector, x);
|
388
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
389
|
+
argc);
|
390
|
+
Need_Float(argv[0]);
|
391
|
+
a = NUM2DBL(argv[0]);
|
392
|
+
break;
|
393
|
+
}
|
394
|
+
xnew = gsl_vector_alloc(x->size);
|
395
|
+
gsl_vector_memcpy(xnew, x);
|
396
|
+
gsl_blas_dscal(a, xnew);
|
397
|
+
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, xnew);
|
398
|
+
}
|
399
|
+
|
400
|
+
static VALUE rb_gsl_blas_zdscal(int argc, VALUE *argv, VALUE obj)
|
401
|
+
{
|
402
|
+
double a;
|
403
|
+
gsl_vector_complex *x = NULL;
|
404
|
+
switch (TYPE(obj)) {
|
405
|
+
case T_MODULE:
|
406
|
+
case T_CLASS:
|
407
|
+
case T_OBJECT:
|
408
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
409
|
+
argc);
|
410
|
+
Need_Float(argv[0]);
|
411
|
+
CHECK_VECTOR_COMPLEX(argv[1]);
|
412
|
+
// a = RFLOAT(argv[0])->value;
|
413
|
+
a = NUM2DBL(argv[0]);
|
414
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, x);
|
415
|
+
gsl_blas_zdscal(a, x);
|
416
|
+
return argv[1];
|
417
|
+
break;
|
418
|
+
default:
|
419
|
+
Data_Get_Struct(obj, gsl_vector_complex, x);
|
420
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
421
|
+
argc);
|
422
|
+
Need_Float(argv[0]);
|
423
|
+
a = NUM2DBL(argv[0]);
|
424
|
+
gsl_blas_zdscal(a, x);
|
425
|
+
return obj;
|
426
|
+
break;
|
427
|
+
}
|
428
|
+
}
|
429
|
+
|
430
|
+
static VALUE rb_gsl_blas_zdscal2(int argc, VALUE *argv, VALUE obj)
|
431
|
+
{
|
432
|
+
double a;
|
433
|
+
gsl_vector_complex *x = NULL, *xnew = NULL;
|
434
|
+
switch (TYPE(obj)) {
|
435
|
+
case T_MODULE:
|
436
|
+
case T_CLASS:
|
437
|
+
case T_OBJECT:
|
438
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
439
|
+
argc);
|
440
|
+
Need_Float(argv[0]);
|
441
|
+
CHECK_VECTOR_COMPLEX(argv[1]);
|
442
|
+
a = NUM2DBL(argv[0]);
|
443
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, x);
|
444
|
+
break;
|
445
|
+
default:
|
446
|
+
Data_Get_Struct(obj, gsl_vector_complex, x);
|
447
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
448
|
+
argc);
|
449
|
+
Need_Float(argv[0]);
|
450
|
+
a = NUM2DBL(argv[0]);
|
451
|
+
break;
|
452
|
+
}
|
453
|
+
xnew = gsl_vector_complex_alloc(x->size);
|
454
|
+
gsl_vector_complex_memcpy(xnew, x);
|
455
|
+
gsl_blas_zdscal(a, xnew);
|
456
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, xnew);
|
457
|
+
}
|
458
|
+
|
459
|
+
static VALUE rb_gsl_blas_zscal(int argc, VALUE *argv, VALUE obj)
|
460
|
+
{
|
461
|
+
gsl_complex *a = NULL;
|
462
|
+
gsl_vector_complex *x = NULL;
|
463
|
+
CHECK_COMPLEX(argv[0]);
|
464
|
+
switch (TYPE(obj)) {
|
465
|
+
case T_MODULE:
|
466
|
+
case T_CLASS:
|
467
|
+
case T_OBJECT:
|
468
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
469
|
+
argc);
|
470
|
+
CHECK_VECTOR_COMPLEX(argv[1]);
|
471
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
472
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, x);
|
473
|
+
gsl_blas_zscal(*a, x);
|
474
|
+
return argv[1];
|
475
|
+
break;
|
476
|
+
default:
|
477
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
478
|
+
argc);
|
479
|
+
Data_Get_Struct(obj, gsl_vector_complex, x);
|
480
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
481
|
+
gsl_blas_zscal(*a, x);
|
482
|
+
return obj;
|
483
|
+
break;
|
484
|
+
}
|
485
|
+
}
|
486
|
+
|
487
|
+
static VALUE rb_gsl_blas_zscal2(int argc, VALUE *argv, VALUE obj)
|
488
|
+
{
|
489
|
+
gsl_complex *a = NULL;
|
490
|
+
gsl_vector_complex *x = NULL, *xnew = NULL;
|
491
|
+
CHECK_COMPLEX(argv[0]);
|
492
|
+
switch (TYPE(obj)) {
|
493
|
+
case T_MODULE:
|
494
|
+
case T_CLASS:
|
495
|
+
case T_OBJECT:
|
496
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
497
|
+
argc);
|
498
|
+
CHECK_VECTOR_COMPLEX(argv[1]);
|
499
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
500
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, x);
|
501
|
+
break;
|
502
|
+
default:
|
503
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
504
|
+
argc);
|
505
|
+
Data_Get_Struct(obj, gsl_vector_complex, x);
|
506
|
+
Data_Get_Struct(argv[0], gsl_complex, a);
|
507
|
+
break;
|
508
|
+
}
|
509
|
+
xnew = gsl_vector_complex_alloc(x->size);
|
510
|
+
gsl_vector_complex_memcpy(xnew, x);
|
511
|
+
gsl_blas_zscal(*a, xnew);
|
512
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, xnew);
|
513
|
+
}
|
514
|
+
|
515
|
+
static VALUE rb_gsl_blas_drot(VALUE obj, VALUE xx, VALUE yy, VALUE cc, VALUE ss)
|
516
|
+
{
|
517
|
+
gsl_vector *x = NULL, *y = NULL;
|
518
|
+
double c, s;
|
519
|
+
CHECK_VECTOR(xx);
|
520
|
+
CHECK_VECTOR(yy);
|
521
|
+
Need_Float(cc);
|
522
|
+
Need_Float(ss);
|
523
|
+
Data_Get_Struct(xx, gsl_vector, x);
|
524
|
+
Data_Get_Struct(yy, gsl_vector, y);
|
525
|
+
c = NUM2DBL(cc);
|
526
|
+
s = NUM2DBL(ss);
|
527
|
+
gsl_blas_drot(x, y, c, s);
|
528
|
+
return rb_ary_new3(2, xx, yy);
|
529
|
+
}
|
530
|
+
|
531
|
+
static VALUE rb_gsl_blas_drot2(VALUE obj, VALUE xx, VALUE yy, VALUE cc, VALUE ss)
|
532
|
+
{
|
533
|
+
gsl_vector *x = NULL, *y = NULL, *xnew = NULL, *ynew = NULL;
|
534
|
+
double c, s;
|
535
|
+
CHECK_VECTOR(xx);
|
536
|
+
CHECK_VECTOR(yy);
|
537
|
+
Need_Float(cc);
|
538
|
+
Need_Float(ss);
|
539
|
+
Data_Get_Struct(xx, gsl_vector, x);
|
540
|
+
Data_Get_Struct(yy, gsl_vector, y);
|
541
|
+
c = NUM2DBL(cc);
|
542
|
+
s = NUM2DBL(ss);
|
543
|
+
xnew = gsl_vector_alloc(x->size);
|
544
|
+
ynew = gsl_vector_alloc(y->size);
|
545
|
+
gsl_vector_memcpy(xnew, x);
|
546
|
+
gsl_vector_memcpy(ynew, y);
|
547
|
+
gsl_blas_drot(xnew, ynew, c, s);
|
548
|
+
return rb_ary_new3(2, Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, xnew),
|
549
|
+
Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, ynew));
|
550
|
+
}
|
551
|
+
|
552
|
+
static VALUE rb_gsl_blas_drotm(VALUE obj, VALUE xx, VALUE yy, VALUE PP)
|
553
|
+
{
|
554
|
+
gsl_vector *x = NULL, *y = NULL, *p = NULL;
|
555
|
+
int flag = 0, i;
|
556
|
+
CHECK_VECTOR(xx);
|
557
|
+
CHECK_VECTOR(yy);
|
558
|
+
Data_Get_Struct(xx, gsl_vector, x);
|
559
|
+
Data_Get_Struct(yy, gsl_vector, y);
|
560
|
+
if (rb_obj_is_kind_of(PP, cgsl_vector)) {
|
561
|
+
Data_Get_Struct(PP, gsl_vector, p);
|
562
|
+
} else {
|
563
|
+
if (TYPE(PP) != T_ARRAY) rb_raise(rb_eTypeError, "wrong argument type %s (Array of Vector expected", rb_class2name(CLASS_OF(PP)));
|
564
|
+
// p = gsl_vector_alloc(RARRAY(PP)->len);
|
565
|
+
p = gsl_vector_alloc(RARRAY_LEN(PP));
|
566
|
+
for (i = 0; i < RARRAY_LEN(PP); i++) {
|
567
|
+
gsl_vector_set(p, i, rb_ary_entry(PP, i));
|
568
|
+
}
|
569
|
+
flag = 1;
|
570
|
+
}
|
571
|
+
gsl_blas_drotm(x, y, p->data);
|
572
|
+
if (flag == 1) gsl_vector_free(p);
|
573
|
+
return rb_ary_new3(2, xx, yy);
|
574
|
+
}
|
575
|
+
|
576
|
+
static VALUE rb_gsl_blas_drotm2(VALUE obj, VALUE xx, VALUE yy, VALUE PP)
|
577
|
+
{
|
578
|
+
gsl_vector *x = NULL, *y = NULL, *p = NULL, *xnew = NULL, *ynew = NULL;
|
579
|
+
int flag = 0, i;
|
580
|
+
CHECK_VECTOR(xx);
|
581
|
+
CHECK_VECTOR(yy);
|
582
|
+
Data_Get_Struct(xx, gsl_vector, x);
|
583
|
+
Data_Get_Struct(yy, gsl_vector, y);
|
584
|
+
if (rb_obj_is_kind_of(PP, cgsl_vector)) {
|
585
|
+
Data_Get_Struct(PP, gsl_vector, p);
|
586
|
+
} else {
|
587
|
+
if (TYPE(PP) != T_ARRAY) rb_raise(rb_eTypeError, "wrong argument type %s (Array of Vector expected", rb_class2name(CLASS_OF(PP)));
|
588
|
+
// p = gsl_vector_alloc(RARRAY(PP)->len);
|
589
|
+
p = gsl_vector_alloc(RARRAY_LEN(PP));
|
590
|
+
for (i = 0; i < RARRAY_LEN(PP); i++) {
|
591
|
+
gsl_vector_set(p, i, rb_ary_entry(PP, i));
|
592
|
+
}
|
593
|
+
flag = 1;
|
594
|
+
}
|
595
|
+
xnew = gsl_vector_alloc(x->size);
|
596
|
+
ynew = gsl_vector_alloc(y->size);
|
597
|
+
gsl_vector_memcpy(xnew, x);
|
598
|
+
gsl_vector_memcpy(ynew, y);
|
599
|
+
gsl_blas_drotm(xnew, ynew, p->data);
|
600
|
+
if (flag == 1) gsl_vector_free(p);
|
601
|
+
return rb_ary_new3(2, Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, xnew),
|
602
|
+
Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, ynew));
|
603
|
+
}
|
604
|
+
|
605
|
+
void Init_gsl_blas1(VALUE module)
|
606
|
+
{
|
607
|
+
rb_define_module_function(module, "ddot", rb_gsl_blas_ddot, -1);
|
608
|
+
rb_define_method(cgsl_vector, "blas_ddot", rb_gsl_blas_ddot, -1);
|
609
|
+
rb_define_alias(cgsl_vector, "ddot", "blas_ddot");
|
610
|
+
/* rb_define_alias(cgsl_vector, "dot", "blas_ddot");*/
|
611
|
+
|
612
|
+
rb_define_module_function(module, "zdotu", rb_gsl_blas_zdotu, -1);
|
613
|
+
rb_define_method(cgsl_vector_complex, "blas_zdotu", rb_gsl_blas_zdotu, -1);
|
614
|
+
rb_define_alias(cgsl_vector_complex, "zdotu", "blas_zdotu");
|
615
|
+
rb_define_alias(cgsl_vector_complex, "dotu", "blas_zdotu");
|
616
|
+
|
617
|
+
rb_define_module_function(module, "zdotc", rb_gsl_blas_zdotc, -1);
|
618
|
+
rb_define_method(cgsl_vector_complex, "blas_zdotc", rb_gsl_blas_zdotc, -1);
|
619
|
+
rb_define_alias(cgsl_vector_complex, "zdotc", "blas_zdotc");
|
620
|
+
rb_define_alias(cgsl_vector_complex, "dotc", "blas_zdotc");
|
621
|
+
|
622
|
+
rb_define_module_function(module, "dnrm2", rb_gsl_blas_dnrm2, -1);
|
623
|
+
rb_define_method(cgsl_vector, "blas_dnrm2", rb_gsl_blas_dnrm2, -1);
|
624
|
+
rb_define_alias(cgsl_vector, "dnrm2", "blas_dnrm2");
|
625
|
+
rb_define_alias(cgsl_vector, "nrm2", "blas_dnrm2");
|
626
|
+
rb_define_alias(cgsl_vector, "norm", "blas_dnrm2");
|
627
|
+
|
628
|
+
rb_define_module_function(module, "dnrm", rb_gsl_blas_dnrm, -1);
|
629
|
+
rb_define_method(cgsl_vector, "blas_dnrm", rb_gsl_blas_dnrm, -1);
|
630
|
+
rb_define_alias(cgsl_vector, "dnrm", "blas_dnrm");
|
631
|
+
rb_define_alias(cgsl_vector, "nrm", "blas_dnrm");
|
632
|
+
rb_define_alias(cgsl_vector, "sumsq", "blas_dnrm");
|
633
|
+
|
634
|
+
rb_define_module_function(module, "dznrm2", rb_gsl_blas_dznrm2, -1);
|
635
|
+
rb_define_method(cgsl_vector_complex, "blas_dznrm2", rb_gsl_blas_dznrm2, -1);
|
636
|
+
rb_define_alias(cgsl_vector_complex, "dznrm2", "blas_dznrm2");
|
637
|
+
rb_define_alias(cgsl_vector_complex, "nrm2", "blas_dznrm2");
|
638
|
+
|
639
|
+
rb_define_module_function(module, "dasum", rb_gsl_blas_dasum, -1);
|
640
|
+
rb_define_method(cgsl_vector, "blas_dasum", rb_gsl_blas_dasum, -1);
|
641
|
+
rb_define_alias(cgsl_vector, "dasum", "blas_dasum");
|
642
|
+
rb_define_alias(cgsl_vector, "asum", "blas_dasum");
|
643
|
+
|
644
|
+
rb_define_module_function(module, "dzasum", rb_gsl_blas_dzasum, -1);
|
645
|
+
rb_define_method(cgsl_vector_complex, "blas_dzasum", rb_gsl_blas_dzasum, -1);
|
646
|
+
rb_define_alias(cgsl_vector_complex, "dzasum", "blas_dzasum");
|
647
|
+
rb_define_alias(cgsl_vector_complex, "asum", "blas_dzasum");
|
648
|
+
|
649
|
+
rb_define_module_function(module, "idamax", rb_gsl_blas_idamax, -1);
|
650
|
+
rb_define_method(cgsl_vector, "blas_idamax", rb_gsl_blas_idamax, -1);
|
651
|
+
rb_define_alias(cgsl_vector, "idamax", "blas_idamax");
|
652
|
+
|
653
|
+
rb_define_module_function(module, "izamax", rb_gsl_blas_izamax, -1);
|
654
|
+
rb_define_method(cgsl_vector_complex, "blas_izamax", rb_gsl_blas_izamax, -1);
|
655
|
+
rb_define_alias(cgsl_vector_complex, "izamax", "blas_izamax");
|
656
|
+
|
657
|
+
rb_define_module_function(module, "dswap", rb_gsl_blas_dswap, -1);
|
658
|
+
rb_define_method(cgsl_vector, "blas_dswap", rb_gsl_blas_dswap, -1);
|
659
|
+
rb_define_alias(cgsl_vector, "dswap", "blas_dswap");
|
660
|
+
rb_define_alias(cgsl_vector, "swap", "blas_dswap");
|
661
|
+
|
662
|
+
rb_define_module_function(module, "zswap", rb_gsl_blas_zswap, -1);
|
663
|
+
rb_define_method(cgsl_vector_complex, "blas_zswap", rb_gsl_blas_zswap, -1);
|
664
|
+
rb_define_alias(cgsl_vector_complex, "zswap", "blas_zswap");
|
665
|
+
rb_define_alias(cgsl_vector_complex, "swap", "blas_zswap");
|
666
|
+
|
667
|
+
rb_define_module_function(module, "dcopy", rb_gsl_blas_dcopy, -1);
|
668
|
+
rb_define_method(cgsl_vector, "blas_dcopy", rb_gsl_blas_dcopy, -1);
|
669
|
+
rb_define_alias(cgsl_vector, "dcopy", "blas_dcopy");
|
670
|
+
rb_define_alias(cgsl_vector, "copy", "blas_dcopy");
|
671
|
+
|
672
|
+
rb_define_module_function(module, "zcopy", rb_gsl_blas_zcopy, -1);
|
673
|
+
rb_define_method(cgsl_vector_complex, "blas_zcopy", rb_gsl_blas_zcopy, -1);
|
674
|
+
rb_define_alias(cgsl_vector_complex, "zcopy", "blas_zcopy");
|
675
|
+
rb_define_alias(cgsl_vector_complex, "copy", "blas_zcopy");
|
676
|
+
|
677
|
+
rb_define_module_function(module, "daxpy!", rb_gsl_blas_daxpy, -1);
|
678
|
+
rb_define_method(cgsl_vector, "blas_daxpy!", rb_gsl_blas_daxpy, -1);
|
679
|
+
rb_define_alias(cgsl_vector, "daxpy!", "blas_daxpy!");
|
680
|
+
rb_define_alias(cgsl_vector, "axpy!", "blas_daxpy!");
|
681
|
+
|
682
|
+
rb_define_module_function(module, "daxpy", rb_gsl_blas_daxpy2, -1);
|
683
|
+
rb_define_method(cgsl_vector, "blas_daxpy", rb_gsl_blas_daxpy2, -1);
|
684
|
+
rb_define_alias(cgsl_vector, "daxpy", "blas_daxpy");
|
685
|
+
rb_define_alias(cgsl_vector, "axpy", "blas_daxpy");
|
686
|
+
|
687
|
+
rb_define_module_function(module, "zaxpy!", rb_gsl_blas_zaxpy, -1);
|
688
|
+
rb_define_method(cgsl_vector_complex, "blas_zaxpy!", rb_gsl_blas_zaxpy, -1);
|
689
|
+
rb_define_alias(cgsl_vector_complex, "zaxpy!", "blas_zaxpy!");
|
690
|
+
rb_define_alias(cgsl_vector_complex, "axpy!", "blas_zaxpy!");
|
691
|
+
|
692
|
+
rb_define_module_function(module, "zaxpy", rb_gsl_blas_zaxpy2, -1);
|
693
|
+
rb_define_method(cgsl_vector_complex, "blas_zaxpy", rb_gsl_blas_zaxpy2, -1);
|
694
|
+
rb_define_alias(cgsl_vector_complex, "zaxpy", "blas_zaxpy");
|
695
|
+
rb_define_alias(cgsl_vector_complex, "axpy", "blas_zaxpy");
|
696
|
+
|
697
|
+
rb_define_module_function(module, "dscal!", rb_gsl_blas_dscal, -1);
|
698
|
+
rb_define_method(cgsl_vector, "blas_dscal!", rb_gsl_blas_dscal, -1);
|
699
|
+
rb_define_alias(cgsl_vector, "dscal!", "blas_dscal!");
|
700
|
+
rb_define_alias(cgsl_vector, "scal!", "blas_dscal!");
|
701
|
+
|
702
|
+
rb_define_module_function(module, "dscal", rb_gsl_blas_dscal2, -1);
|
703
|
+
rb_define_method(cgsl_vector, "blas_dscal", rb_gsl_blas_dscal2, -1);
|
704
|
+
rb_define_alias(cgsl_vector, "dscal", "blas_dscal");
|
705
|
+
rb_define_alias(cgsl_vector, "scal", "blas_dscal");
|
706
|
+
|
707
|
+
rb_define_module_function(module, "zdscal!", rb_gsl_blas_zdscal, -1);
|
708
|
+
rb_define_method(cgsl_vector_complex, "blas_zdscal!", rb_gsl_blas_zdscal, -1);
|
709
|
+
rb_define_alias(cgsl_vector_complex, "zdscal!", "blas_zdscal!");
|
710
|
+
rb_define_alias(cgsl_vector_complex, "scal!", "blas_zdscal!");
|
711
|
+
|
712
|
+
rb_define_module_function(module, "zdscal", rb_gsl_blas_zdscal2, -1);
|
713
|
+
rb_define_method(cgsl_vector_complex, "blas_zdscal", rb_gsl_blas_zdscal2, -1);
|
714
|
+
rb_define_alias(cgsl_vector_complex, "zdscal", "blas_zdscal");
|
715
|
+
rb_define_alias(cgsl_vector_complex, "scal", "blas_zdscal");
|
716
|
+
|
717
|
+
rb_define_module_function(module, "zscal!", rb_gsl_blas_zscal, -1);
|
718
|
+
rb_define_method(cgsl_vector_complex, "blas_zscal!", rb_gsl_blas_zscal, -1);
|
719
|
+
rb_define_alias(cgsl_vector_complex, "zscal!", "blas_zscal!");
|
720
|
+
|
721
|
+
rb_define_module_function(module, "zscal2", rb_gsl_blas_zscal2, -1);
|
722
|
+
rb_define_method(cgsl_vector_complex, "blas_zscal2", rb_gsl_blas_zscal2, -1);
|
723
|
+
rb_define_alias(cgsl_vector_complex, "zscal2", "blas_zscal2");
|
724
|
+
rb_define_alias(cgsl_vector_complex, "scal2", "blas_zscal2");
|
725
|
+
|
726
|
+
rb_define_module_function(module, "drot!", rb_gsl_blas_drot, 4);
|
727
|
+
rb_define_module_function(module, "drot", rb_gsl_blas_drot2, 4);
|
728
|
+
|
729
|
+
rb_define_module_function(module, "drotm!", rb_gsl_blas_drotm, 3);
|
730
|
+
rb_define_module_function(module, "drotm", rb_gsl_blas_drotm2, 3);
|
731
|
+
}
|