gsl 1.12.108

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/README.rdoc +29 -0
  2. data/Rakefile +54 -0
  3. data/VERSION +2 -0
  4. data/ext/MANIFEST +119 -0
  5. data/ext/alf.c +206 -0
  6. data/ext/array.c +666 -0
  7. data/ext/array_complex.c +247 -0
  8. data/ext/blas.c +29 -0
  9. data/ext/blas1.c +731 -0
  10. data/ext/blas2.c +1093 -0
  11. data/ext/blas3.c +881 -0
  12. data/ext/block.c +44 -0
  13. data/ext/block_source.c +886 -0
  14. data/ext/bspline.c +130 -0
  15. data/ext/bundle.c +3 -0
  16. data/ext/cdf.c +754 -0
  17. data/ext/cheb.c +542 -0
  18. data/ext/combination.c +283 -0
  19. data/ext/common.c +325 -0
  20. data/ext/complex.c +1004 -0
  21. data/ext/const.c +673 -0
  22. data/ext/const_additional.c +120 -0
  23. data/ext/cqp.c +283 -0
  24. data/ext/deriv.c +195 -0
  25. data/ext/dht.c +361 -0
  26. data/ext/diff.c +166 -0
  27. data/ext/dirac.c +395 -0
  28. data/ext/eigen.c +2373 -0
  29. data/ext/error.c +194 -0
  30. data/ext/extconf.rb +281 -0
  31. data/ext/fcmp.c +66 -0
  32. data/ext/fft.c +1092 -0
  33. data/ext/fit.c +205 -0
  34. data/ext/fresnel.c +312 -0
  35. data/ext/function.c +524 -0
  36. data/ext/geometry.c +139 -0
  37. data/ext/graph.c +1638 -0
  38. data/ext/gsl.c +271 -0
  39. data/ext/gsl_narray.c +653 -0
  40. data/ext/histogram.c +1995 -0
  41. data/ext/histogram2d.c +1068 -0
  42. data/ext/histogram3d.c +884 -0
  43. data/ext/histogram3d_source.c +750 -0
  44. data/ext/histogram_find.c +101 -0
  45. data/ext/histogram_oper.c +159 -0
  46. data/ext/ieee.c +98 -0
  47. data/ext/integration.c +1138 -0
  48. data/ext/interp.c +512 -0
  49. data/ext/jacobi.c +739 -0
  50. data/ext/linalg.c +4047 -0
  51. data/ext/linalg_complex.c +741 -0
  52. data/ext/math.c +725 -0
  53. data/ext/matrix.c +39 -0
  54. data/ext/matrix_complex.c +1732 -0
  55. data/ext/matrix_double.c +560 -0
  56. data/ext/matrix_int.c +256 -0
  57. data/ext/matrix_source.c +2733 -0
  58. data/ext/min.c +250 -0
  59. data/ext/monte.c +992 -0
  60. data/ext/multifit.c +1879 -0
  61. data/ext/multimin.c +808 -0
  62. data/ext/multimin_fsdf.c +156 -0
  63. data/ext/multiroots.c +955 -0
  64. data/ext/ndlinear.c +321 -0
  65. data/ext/nmf.c +167 -0
  66. data/ext/nmf_wrap.c +72 -0
  67. data/ext/ntuple.c +469 -0
  68. data/ext/odeiv.c +959 -0
  69. data/ext/ool.c +879 -0
  70. data/ext/oper_complex_source.c +253 -0
  71. data/ext/permutation.c +596 -0
  72. data/ext/poly.c +42 -0
  73. data/ext/poly2.c +265 -0
  74. data/ext/poly_source.c +1885 -0
  75. data/ext/qrng.c +171 -0
  76. data/ext/randist.c +1873 -0
  77. data/ext/rational.c +480 -0
  78. data/ext/rng.c +612 -0
  79. data/ext/root.c +408 -0
  80. data/ext/sf.c +1494 -0
  81. data/ext/sf_airy.c +200 -0
  82. data/ext/sf_bessel.c +867 -0
  83. data/ext/sf_clausen.c +28 -0
  84. data/ext/sf_coulomb.c +206 -0
  85. data/ext/sf_coupling.c +118 -0
  86. data/ext/sf_dawson.c +29 -0
  87. data/ext/sf_debye.c +157 -0
  88. data/ext/sf_dilog.c +42 -0
  89. data/ext/sf_elementary.c +44 -0
  90. data/ext/sf_ellint.c +206 -0
  91. data/ext/sf_elljac.c +29 -0
  92. data/ext/sf_erfc.c +93 -0
  93. data/ext/sf_exp.c +164 -0
  94. data/ext/sf_expint.c +211 -0
  95. data/ext/sf_fermi_dirac.c +148 -0
  96. data/ext/sf_gamma.c +344 -0
  97. data/ext/sf_gegenbauer.c +96 -0
  98. data/ext/sf_hyperg.c +197 -0
  99. data/ext/sf_laguerre.c +112 -0
  100. data/ext/sf_lambert.c +47 -0
  101. data/ext/sf_legendre.c +367 -0
  102. data/ext/sf_log.c +104 -0
  103. data/ext/sf_mathieu.c +238 -0
  104. data/ext/sf_power.c +46 -0
  105. data/ext/sf_psi.c +98 -0
  106. data/ext/sf_synchrotron.c +48 -0
  107. data/ext/sf_transport.c +76 -0
  108. data/ext/sf_trigonometric.c +207 -0
  109. data/ext/sf_zeta.c +119 -0
  110. data/ext/signal.c +310 -0
  111. data/ext/siman.c +718 -0
  112. data/ext/sort.c +208 -0
  113. data/ext/spline.c +395 -0
  114. data/ext/stats.c +799 -0
  115. data/ext/sum.c +168 -0
  116. data/ext/tamu_anova.c +56 -0
  117. data/ext/tensor.c +38 -0
  118. data/ext/tensor_source.c +1123 -0
  119. data/ext/vector.c +38 -0
  120. data/ext/vector_complex.c +2236 -0
  121. data/ext/vector_double.c +1433 -0
  122. data/ext/vector_int.c +204 -0
  123. data/ext/vector_source.c +3329 -0
  124. data/ext/wavelet.c +937 -0
  125. data/include/rb_gsl.h +151 -0
  126. data/include/rb_gsl_array.h +238 -0
  127. data/include/rb_gsl_cheb.h +21 -0
  128. data/include/rb_gsl_common.h +343 -0
  129. data/include/rb_gsl_complex.h +25 -0
  130. data/include/rb_gsl_const.h +29 -0
  131. data/include/rb_gsl_dirac.h +13 -0
  132. data/include/rb_gsl_eigen.h +17 -0
  133. data/include/rb_gsl_fft.h +62 -0
  134. data/include/rb_gsl_fit.h +25 -0
  135. data/include/rb_gsl_function.h +27 -0
  136. data/include/rb_gsl_graph.h +70 -0
  137. data/include/rb_gsl_histogram.h +63 -0
  138. data/include/rb_gsl_histogram3d.h +97 -0
  139. data/include/rb_gsl_integration.h +17 -0
  140. data/include/rb_gsl_interp.h +46 -0
  141. data/include/rb_gsl_linalg.h +25 -0
  142. data/include/rb_gsl_math.h +26 -0
  143. data/include/rb_gsl_odeiv.h +21 -0
  144. data/include/rb_gsl_poly.h +71 -0
  145. data/include/rb_gsl_rational.h +37 -0
  146. data/include/rb_gsl_rng.h +21 -0
  147. data/include/rb_gsl_root.h +22 -0
  148. data/include/rb_gsl_sf.h +119 -0
  149. data/include/rb_gsl_statistics.h +17 -0
  150. data/include/rb_gsl_tensor.h +45 -0
  151. data/include/rb_gsl_with_narray.h +22 -0
  152. data/include/templates_off.h +87 -0
  153. data/include/templates_on.h +241 -0
  154. data/lib/gsl/gnuplot.rb +41 -0
  155. data/lib/gsl/oper.rb +68 -0
  156. data/lib/ool.rb +22 -0
  157. data/lib/ool/conmin.rb +30 -0
  158. metadata +224 -0
@@ -0,0 +1,38 @@
1
+ /*
2
+ vector.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
+ /*
13
+ This code uses "templates_on.h" and "templates_off.h",
14
+ which are provided by the GSL source.
15
+ */
16
+
17
+ #include "rb_gsl_config.h"
18
+ #include "rb_gsl_array.h"
19
+ #include "rb_gsl_histogram.h"
20
+ #include "rb_gsl_complex.h"
21
+ #include "rb_gsl_poly.h"
22
+ #ifdef HAVE_NARRAY_H
23
+ #include "rb_gsl_with_narray.h"
24
+ #endif
25
+
26
+ #define BASE_DOUBLE
27
+ #include "templates_on.h"
28
+ #include "vector_source.c"
29
+ #include "templates_off.h"
30
+ #undef BASE_DOUBLE
31
+
32
+ #define BASE_INT
33
+ #include "templates_on.h"
34
+ #include "vector_source.c"
35
+ #include "templates_off.h"
36
+ #undef BASE_INT
37
+
38
+
@@ -0,0 +1,2236 @@
1
+ /*
2
+ vector_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
+ #include "rb_gsl_array.h"
13
+ #include "rb_gsl_complex.h"
14
+
15
+ EXTERN VALUE cgsl_complex;
16
+ static VALUE rb_gsl_vector_complex_inner_product(int argc, VALUE *argv, VALUE obj);
17
+ static VALUE rb_gsl_vector_complex_product_to_m(int argc, VALUE *argv, VALUE obj);
18
+
19
+ // From vector_source.c
20
+ void get_range_beg_en_n(VALUE range, double *beg, double *en, size_t *n, int *step);
21
+ //
22
+ // From vector_source.c
23
+ void parse_subvector_args(int argc, VALUE *argv, size_t size,
24
+ size_t *offset, size_t *stride, size_t *n);
25
+
26
+ // From complex.c
27
+ gsl_complex rb_gsl_obj_to_gsl_complex(VALUE obj, gsl_complex *z);
28
+
29
+ static VALUE rb_gsl_vector_complex_new(int argc, VALUE *argv, VALUE klass)
30
+ {
31
+ VALUE tmp;
32
+ gsl_vector_complex *v = NULL;
33
+ gsl_vector *x, *y;
34
+ gsl_complex z, *z2 = NULL;
35
+ size_t n, i;
36
+ switch (argc) {
37
+ case 1:
38
+ switch (TYPE(argv[0])) {
39
+ case T_FIXNUM:
40
+ n = FIX2INT(argv[0]);
41
+ v = gsl_vector_complex_calloc(n);
42
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
43
+ break;
44
+ case T_ARRAY:
45
+ n = RARRAY_LEN(argv[0]);
46
+ v = gsl_vector_complex_alloc(n);
47
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
48
+ for (i = 0; i < n; i++) {
49
+ z2 = &z;
50
+ tmp = rb_ary_entry(argv[0], i);
51
+ if (TYPE(tmp) == T_ARRAY) {
52
+ GSL_SET_REAL(z2, NUM2DBL(rb_ary_entry(tmp, 0)));
53
+ GSL_SET_IMAG(z2, NUM2DBL(rb_ary_entry(tmp, 1)));
54
+ } else if (COMPLEX_P(tmp)) {
55
+ Data_Get_Struct(tmp, gsl_complex, z2);
56
+ } else {
57
+ rb_raise(rb_eTypeError,
58
+ "wrong argument type %s (Array or Complex expected)",
59
+ rb_class2name(CLASS_OF(tmp)));
60
+
61
+ }
62
+ gsl_vector_complex_set(v, i, *z2);
63
+ }
64
+ break;
65
+ default:
66
+ rb_raise(rb_eTypeError,
67
+ "wrong argument type %s", rb_class2name(CLASS_OF(argv[0])));
68
+ break;
69
+ }
70
+ break;
71
+ default:
72
+ if (argc == 2 && (VECTOR_P(argv[0]) && VECTOR_P(argv[1]))) {
73
+ Data_Get_Struct(argv[0], gsl_vector, x);
74
+ Data_Get_Struct(argv[1], gsl_vector, y);
75
+ n = GSL_MIN_INT(x->size, y->size);
76
+ v = gsl_vector_complex_alloc(n);
77
+ for (i = 0; i < n; i++) {
78
+ z.dat[0] = gsl_vector_get(x, i);
79
+ z.dat[1] = gsl_vector_get(y, i);
80
+ gsl_vector_complex_set(v, i, z);
81
+ }
82
+ break;
83
+ }
84
+ n = argc;
85
+ v = gsl_vector_complex_alloc(n);
86
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
87
+ for (i = 0; i < n; i++) {
88
+ if (TYPE(argv[i]) == T_ARRAY) {
89
+ GSL_SET_REAL(&z, NUM2DBL(rb_ary_entry(argv[i], 0)));
90
+ GSL_SET_IMAG(&z, NUM2DBL(rb_ary_entry(argv[i], 1)));
91
+ z2 = &z;
92
+ } else if (COMPLEX_P(argv[i])) {
93
+ Data_Get_Struct(argv[i], gsl_complex, z2);
94
+ } else {
95
+ rb_raise(rb_eTypeError,
96
+ "wrong argument type %s (Array or Complex expected)",
97
+ rb_class2name(CLASS_OF(argv[i])));
98
+ }
99
+ gsl_vector_complex_set(v, i, *z2);
100
+ }
101
+ break;
102
+ }
103
+ return Data_Wrap_Struct(klass, 0, gsl_vector_complex_free, v);
104
+ }
105
+
106
+ static VALUE rb_gsl_vector_complex_row_new(int argc, VALUE *argv, VALUE klass)
107
+ {
108
+ return rb_gsl_vector_complex_new(argc, argv, klass);
109
+ }
110
+
111
+ static VALUE rb_gsl_vector_complex_calloc(VALUE klass, VALUE nn)
112
+ {
113
+ gsl_vector_complex *vc = NULL;
114
+ CHECK_FIXNUM(nn);
115
+ vc = gsl_vector_complex_calloc(FIX2INT(nn));
116
+ if (vc == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
117
+ return Data_Wrap_Struct(klass, 0, gsl_vector_complex_free, vc);
118
+ }
119
+
120
+ static VALUE rb_gsl_vector_complex_size(VALUE obj)
121
+ {
122
+ gsl_vector_complex *v = NULL;
123
+ Data_Get_Struct(obj, gsl_vector_complex, v);
124
+ return INT2FIX(v->size);
125
+ }
126
+
127
+ static VALUE rb_gsl_vector_complex_stride(VALUE obj)
128
+ {
129
+ gsl_vector_complex *v = NULL;
130
+ Data_Get_Struct(obj, gsl_vector_complex, v);
131
+ return INT2FIX(v->stride);
132
+ }
133
+
134
+ static VALUE rb_gsl_vector_complex_owner(VALUE obj)
135
+ {
136
+ gsl_vector_complex *v = NULL;
137
+ Data_Get_Struct(obj, gsl_vector_complex, v);
138
+ return INT2FIX(v->owner);
139
+ }
140
+
141
+ static VALUE rb_gsl_vector_complex_ptr(VALUE obj, VALUE i)
142
+ {
143
+ gsl_vector_complex *v = NULL;
144
+ Data_Get_Struct(obj, gsl_vector_complex, v);
145
+ return Data_Wrap_Struct(cgsl_complex, 0, NULL, gsl_vector_complex_ptr(v, FIX2INT(i)));
146
+ }
147
+
148
+ // TODO return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj),..." where appropriate
149
+ static VALUE rb_gsl_vector_complex_subvector(int argc, VALUE *argv, VALUE obj);
150
+ static VALUE rb_gsl_vector_complex_get(int argc, VALUE *argv, VALUE obj)
151
+ {
152
+ VALUE retval = Qnil;
153
+ gsl_vector_complex *v = NULL, *vnew;
154
+ gsl_complex *c = NULL;
155
+ gsl_index *p;
156
+ int i, k;
157
+ size_t index, j;
158
+ // If argc is not 1 or argv[0] is a Range
159
+ if( argc != 1 || rb_obj_is_kind_of(argv[0], rb_cRange)) {
160
+ // Treat as call to subvector
161
+ retval = rb_gsl_vector_complex_subvector(argc, argv, obj);
162
+ } else {
163
+ Data_Get_Struct(obj, gsl_vector_complex, v);
164
+
165
+ switch (TYPE(argv[0])) {
166
+ case T_FIXNUM:
167
+ CHECK_FIXNUM(argv[0]);
168
+ i = FIX2INT(argv[0]);
169
+ if (i < 0) index = (size_t) (v->size + i);
170
+ else index = (size_t) i;
171
+ c = ALLOC(gsl_complex);
172
+ *c = gsl_vector_complex_get(v, index);
173
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
174
+ break;
175
+ case T_ARRAY:
176
+ vnew = gsl_vector_complex_alloc(RARRAY_LEN(argv[0]));
177
+ for (j = 0; j < vnew->size; j++) {
178
+ i = FIX2INT(rb_ary_entry(argv[0], j));
179
+ if (i < 0) i = v->size + i;
180
+ gsl_vector_complex_set(vnew, j, gsl_vector_complex_get(v, i));
181
+ }
182
+ retval = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
183
+ break;
184
+ default:
185
+ if (PERMUTATION_P(argv[0])) {
186
+ Data_Get_Struct(argv[0], gsl_index, p);
187
+ vnew = gsl_vector_complex_alloc(p->size);
188
+ for (j = 0; j < p->size; j++) {
189
+ k = p->data[j];
190
+ if (k < 0) k = p->size + j;
191
+ gsl_vector_complex_set(vnew, j, gsl_vector_complex_get(v, k));
192
+ }
193
+ retval = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
194
+ } else {
195
+ // TODO Support Vector::Int (and even Vector?)
196
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array, Range, GSL::Permutation, or Fixnum expected)", rb_class2name(CLASS_OF(argv[0])));
197
+ }
198
+ break;
199
+ }
200
+ }
201
+ return retval;
202
+ }
203
+
204
+ static VALUE rb_gsl_vector_complex_set_all(int argc, VALUE *argv, VALUE obj)
205
+ {
206
+ gsl_vector_complex *v = NULL;
207
+ gsl_complex tmp;
208
+
209
+ if (argc < 1) rb_raise(rb_eArgError, "wrong number of arguments");
210
+
211
+ Data_Get_Struct(obj, gsl_vector_complex, v);
212
+
213
+ switch (argc) {
214
+ case 1:
215
+ tmp = rb_gsl_obj_to_gsl_complex(argv[0], NULL);
216
+ break;
217
+ case 2:
218
+ GSL_SET_COMPLEX(&tmp, NUM2DBL(argv[0]), NUM2DBL(argv[1]));
219
+ break;
220
+ default:
221
+ rb_raise(rb_eArgError, "wrong number of arguments");
222
+ break;
223
+ }
224
+
225
+ gsl_vector_complex_set_all(v, tmp);
226
+
227
+ return obj;
228
+ }
229
+
230
+ void rb_gsl_vector_complex_set_subvector(int argc, VALUE *argv, gsl_vector_complex *v, VALUE other)
231
+ {
232
+ gsl_vector_complex *vother;
233
+ gsl_vector_complex_view vv;
234
+ gsl_complex tmp;
235
+ int step;
236
+ size_t i, offset, stride, n, nother;
237
+ double beg, end;
238
+
239
+ // assignment to v.subvector(...)
240
+ parse_subvector_args(argc, argv, v->size, &offset, &stride, &n);
241
+ vv = gsl_vector_complex_subvector_with_stride(v, offset, stride, n);
242
+ if(rb_obj_is_kind_of(other, cgsl_vector_complex)) {
243
+ Data_Get_Struct(other, gsl_vector_complex, vother);
244
+ if(n != vother->size) {
245
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) vother->size);
246
+ }
247
+ // TODO Change to gsl_vector_complex_memmove if/when GSL has such a
248
+ // function because gsl_vector_memcpy does not handle overlapping regions
249
+ // (e.g. Views) well.
250
+ gsl_vector_complex_memcpy(&vv.vector, vother);
251
+ } else if(rb_obj_is_kind_of(other, rb_cArray)) {
252
+ // TODO Support other forms of Array contents as well
253
+ if(n != RARRAY_LEN(other)) {
254
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) RARRAY_LEN(other));
255
+ }
256
+ for(i = 0; i < n; i++) {
257
+ tmp = rb_gsl_obj_to_gsl_complex(rb_ary_entry(other, i), NULL);
258
+ gsl_vector_complex_set(&vv.vector, i, tmp);
259
+ }
260
+ } else if(rb_obj_is_kind_of(other, rb_cRange)) {
261
+ get_range_beg_en_n(other, &beg, &end, &nother, &step);
262
+ if(n != nother) {
263
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) nother);
264
+ }
265
+ GSL_SET_IMAG(&tmp, 0.0);
266
+ for(i = 0; i < n; i++) {
267
+ GSL_SET_REAL(&tmp, beg);
268
+ gsl_vector_complex_set(&vv.vector, i, tmp);
269
+ beg += step;
270
+ }
271
+ } else {
272
+ tmp = rb_gsl_obj_to_gsl_complex(argv[1], NULL);
273
+ gsl_vector_complex_set_all(&vv.vector, tmp);
274
+ }
275
+ }
276
+
277
+ static VALUE rb_gsl_vector_complex_set(int argc, VALUE *argv, VALUE obj)
278
+ {
279
+ gsl_vector_complex *v = NULL;
280
+ gsl_complex tmp;
281
+ VALUE other;
282
+ int ii;
283
+
284
+ if(argc < 1 || argc > 4) {
285
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-4)", argc);
286
+ }
287
+
288
+ Data_Get_Struct(obj, gsl_vector_complex, v);
289
+ other = argv[argc-1];
290
+
291
+ if(argc == 1) {
292
+ rb_gsl_vector_complex_set_all(argc, argv, obj);
293
+ } else if(argc == 2 && TYPE(argv[0]) == T_FIXNUM) {
294
+ // v[i] = x
295
+ ii = FIX2INT(argv[0]);
296
+ if(ii < 0) ii += v->size;
297
+ // Get/make GSL::Complex from second arg
298
+ tmp = gsl_vector_complex_get(v, ii);
299
+ rb_gsl_obj_to_gsl_complex(argv[1], &tmp);
300
+ gsl_vector_complex_set(v, (size_t)ii, tmp);
301
+ } else {
302
+ // assignment to v.subvector(...)
303
+ rb_gsl_vector_complex_set_subvector(argc-1, argv, v, other);
304
+ }
305
+
306
+ return obj;
307
+ }
308
+
309
+ static VALUE rb_gsl_vector_complex_each(VALUE obj)
310
+ {
311
+ gsl_vector_complex *v = NULL;
312
+ VALUE vz;
313
+ gsl_complex * zp;
314
+ size_t i;
315
+ Data_Get_Struct(obj, gsl_vector_complex, v);
316
+ for (i = 0; i < v->size; i++) {
317
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
318
+ *zp = gsl_vector_complex_get(v, i);
319
+ rb_yield(vz);
320
+ }
321
+ return obj;
322
+ }
323
+
324
+ static VALUE rb_gsl_vector_complex_reverse_each(VALUE obj)
325
+ {
326
+ gsl_vector_complex *v = NULL;
327
+ VALUE vz;
328
+ gsl_complex * zp;
329
+ size_t i;
330
+ Data_Get_Struct(obj, gsl_vector_complex, v);
331
+ for (i = v->size-1; i >= 0; i--) {
332
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
333
+ *zp = gsl_vector_complex_get(v, i);
334
+ rb_yield(vz);
335
+ }
336
+ return obj;
337
+ }
338
+
339
+ static VALUE rb_gsl_vector_complex_each_index(VALUE obj)
340
+ {
341
+ gsl_vector_complex *v = NULL;
342
+ size_t i;
343
+ Data_Get_Struct(obj, gsl_vector_complex, v);
344
+ for (i = 0; i < v->size; i++) rb_yield(INT2FIX(i));
345
+ return obj;
346
+ }
347
+
348
+ static VALUE rb_gsl_vector_complex_reverse_each_index(VALUE obj)
349
+ {
350
+ gsl_vector_complex *v = NULL;
351
+ size_t i;
352
+ Data_Get_Struct(obj, gsl_vector_complex, v);
353
+ for (i = v->size-1; i >= 0; i--) {
354
+ rb_yield(INT2FIX(i));
355
+ if (i == 0) break;
356
+ }
357
+ return obj;
358
+ }
359
+
360
+ static void rb_gsl_vector_complex_collect_native(gsl_vector_complex *src, gsl_vector_complex *dst)
361
+ {
362
+ VALUE vz;
363
+ gsl_complex * zp;
364
+ size_t i;
365
+ for (i = 0; i < src->size; i++) {
366
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
367
+ *zp = gsl_vector_complex_get(src, i);
368
+ vz = rb_yield(vz);
369
+ CHECK_COMPLEX(vz);
370
+ Data_Get_Struct(vz, gsl_complex, zp);
371
+ gsl_vector_complex_set(dst, i, *zp);
372
+ }
373
+ }
374
+
375
+ static VALUE rb_gsl_vector_complex_collect(VALUE obj)
376
+ {
377
+ gsl_vector_complex *v = NULL, *vnew;
378
+ Data_Get_Struct(obj, gsl_vector_complex, v);
379
+ vnew = gsl_vector_complex_alloc(v->size);
380
+ rb_gsl_vector_complex_collect_native(v, vnew);
381
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
382
+ }
383
+
384
+ static VALUE rb_gsl_vector_complex_collect_bang(VALUE obj)
385
+ {
386
+ gsl_vector_complex *v = NULL;
387
+ Data_Get_Struct(obj, gsl_vector_complex, v);
388
+ rb_gsl_vector_complex_collect_native(v, v);
389
+ return obj;
390
+ }
391
+
392
+ static VALUE rb_gsl_vector_complex_set_zero(VALUE obj)
393
+ {
394
+ gsl_vector_complex *v = NULL;
395
+ Data_Get_Struct(obj, gsl_vector_complex, v);
396
+ gsl_vector_complex_set_zero(v);
397
+ return obj;
398
+ }
399
+
400
+ static VALUE rb_gsl_vector_complex_set_basis(VALUE obj, VALUE ii)
401
+ {
402
+ gsl_vector_complex *v = NULL;
403
+ CHECK_FIXNUM(ii);
404
+ Data_Get_Struct(obj, gsl_vector_complex, v);
405
+ gsl_vector_complex_set_basis(v, FIX2INT(ii));
406
+ return obj;
407
+ }
408
+
409
+ static VALUE rb_gsl_vector_complex_to_s(VALUE obj)
410
+ {
411
+ gsl_vector_complex *v = NULL;
412
+ char buf[64];
413
+ size_t i;
414
+ VALUE str;
415
+ gsl_complex * z;
416
+
417
+ Data_Get_Struct(obj, gsl_vector_complex, v);
418
+ if (v->size == 0) return rb_str_new2("[ ]");
419
+ str = rb_str_new2("[ ");
420
+ if (VECTOR_COMPLEX_COL_P(obj)) {
421
+ for (i = 0; i < v->size; i++) {
422
+ if (i != 0) {
423
+ rb_str_cat(str, " ", 2);
424
+ }
425
+ z = GSL_COMPLEX_AT(v, i);
426
+ sprintf(buf, "[%4.3e %4.3e]", GSL_REAL(*z), GSL_IMAG(*z));
427
+ if (i != v->size-1) strcat(buf, "\n");
428
+ rb_str_cat(str, buf, strlen(buf));
429
+ if (i >= 10 && i != v->size-1) {
430
+ rb_str_cat(str, " ...", 5);
431
+ break;
432
+ }
433
+ }
434
+ } else {
435
+ z = GSL_COMPLEX_AT(v, 0);
436
+ sprintf(buf, "[%4.3e %4.3e]", GSL_REAL(*z), GSL_IMAG(*z));
437
+ rb_str_cat(str, buf, strlen(buf));
438
+ for (i = 1; i < v->size; i++) {
439
+ z = GSL_COMPLEX_AT(v, i);
440
+ sprintf(buf, " [%4.3e %4.3e]", GSL_REAL(*z), GSL_IMAG(*z));
441
+ rb_str_cat(str, buf, strlen(buf));
442
+ if (i >= 10 && i != v->size-1) {
443
+ rb_str_cat(str, " ...", 4);
444
+ break;
445
+ }
446
+ }
447
+ }
448
+ rb_str_cat(str, " ]", 2);
449
+ return str;
450
+ }
451
+
452
+ static VALUE rb_gsl_vector_complex_inspect(VALUE obj)
453
+ {
454
+ VALUE str;
455
+ char buf[128];
456
+ gsl_vector_complex *v;
457
+
458
+ Data_Get_Struct(obj, gsl_vector_complex, v);
459
+ sprintf(buf, "#<%s[%lu]:%#x>\n", rb_class2name(CLASS_OF(obj)), v->size, NUM2UINT(rb_obj_id(obj)));
460
+ str = rb_str_new2(buf);
461
+ return rb_str_concat(str, rb_gsl_vector_complex_to_s(obj));
462
+ }
463
+
464
+ /*static VALUE rb_gsl_vector_complex_fprintf(VALUE obj, VALUE io, VALUE format)*/
465
+ static VALUE rb_gsl_vector_complex_fprintf(int argc, VALUE *argv, VALUE obj)
466
+ {
467
+ gsl_vector_complex *h = NULL;
468
+ FILE *fp = NULL;
469
+ int status, flag = 0;
470
+ if (argc != 1 && argc != 2) {
471
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
472
+ }
473
+ Data_Get_Struct(obj, gsl_vector_complex, h);
474
+ fp = rb_gsl_open_writefile(argv[0], &flag);
475
+ if (argc == 2) {
476
+ Check_Type(argv[1], T_STRING);
477
+ status = gsl_vector_complex_fprintf(fp, h, STR2CSTR(argv[1]));
478
+ } else {
479
+ status = gsl_vector_complex_fprintf(fp, h, "%4.3e");
480
+ }
481
+ if (flag == 1) fclose(fp);
482
+ return INT2FIX(status);
483
+ }
484
+
485
+ /*static VALUE rb_gsl_vector_complex_printf(VALUE obj, VALUE format)*/
486
+ static VALUE rb_gsl_vector_complex_printf(int argc, VALUE *argv, VALUE obj)
487
+ {
488
+ gsl_vector_complex *h = NULL;
489
+ int status;
490
+ Data_Get_Struct(obj, gsl_vector_complex, h);
491
+ if (argc == 1) {
492
+ Check_Type(argv[0], T_STRING);
493
+ status = gsl_vector_complex_fprintf(stdout, h, STR2CSTR(argv[0]));
494
+ } else {
495
+ status = gsl_vector_complex_fprintf(stdout, h, "%4.3e");
496
+ }
497
+ return INT2FIX(status);
498
+ }
499
+ /*
500
+ static VALUE rb_gsl_vector_complex_print(VALUE obj);
501
+ static VALUE rb_gsl_vector_complex_inspect(VALUE obj)
502
+ {
503
+ gsl_vector_complex *h = NULL;
504
+ Data_Get_Struct(obj, gsl_vector_complex, h);
505
+ printf("%s\n", rb_class2name(CLASS_OF(obj)));
506
+ rb_gsl_vector_complex_print(obj);
507
+ return Qtrue;
508
+ }
509
+ */
510
+ static VALUE rb_gsl_vector_complex_print(VALUE obj)
511
+ {
512
+ gsl_vector_complex *h = NULL;
513
+ gsl_complex *z = NULL;
514
+ size_t i;
515
+ Data_Get_Struct(obj, gsl_vector_complex, h);
516
+ printf("[ ");
517
+ if (VECTOR_COMPLEX_COL_P(obj)) {
518
+ printf("\n");
519
+ for (i = 0; i < h->size; i++) {
520
+ z = GSL_COMPLEX_AT(h, i);
521
+ printf(" [%4.3e %4.3e]\n", GSL_REAL(*z), GSL_IMAG(*z));
522
+ }
523
+ } else {
524
+ for (i = 0; i < h->size; i++) {
525
+ z = GSL_COMPLEX_AT(h, i);
526
+ printf("[%4.3e %4.3e] ", GSL_REAL(*z), GSL_IMAG(*z));
527
+ }
528
+ }
529
+ printf("]\n");
530
+ return obj;
531
+ }
532
+
533
+ static VALUE rb_gsl_vector_complex_fwrite(VALUE obj, VALUE io)
534
+ {
535
+ gsl_vector_complex *h = NULL;
536
+ FILE *fp = NULL;
537
+ int status, flag = 0;
538
+ Data_Get_Struct(obj, gsl_vector_complex, h);
539
+ fp = rb_gsl_open_writefile(io, &flag);
540
+ status = gsl_vector_complex_fwrite(fp, h);
541
+ if (flag == 1) fclose(fp);
542
+ return INT2FIX(status);
543
+ }
544
+
545
+ static VALUE rb_gsl_vector_complex_fread(VALUE obj, VALUE io)
546
+ {
547
+ gsl_vector_complex *h = NULL;
548
+ FILE *f = NULL;
549
+ int status, flag = 0;
550
+ Data_Get_Struct(obj, gsl_vector_complex, h);
551
+ f = rb_gsl_open_writefile(io, &flag);
552
+ status = gsl_vector_complex_fread(f, h);
553
+ if (flag == 1) fclose(f);
554
+ return INT2FIX(status);
555
+ }
556
+
557
+ static VALUE rb_gsl_vector_complex_fscanf(VALUE obj, VALUE io)
558
+ {
559
+ gsl_vector_complex *h = NULL;
560
+ FILE *f = NULL;
561
+ int status, flag = 0;
562
+ Data_Get_Struct(obj, gsl_vector_complex, h);
563
+ f = rb_gsl_open_writefile(io, &flag);
564
+ status = gsl_vector_complex_fscanf(f, h);
565
+ if (flag == 1) fclose(f);
566
+ return INT2FIX(status);
567
+ }
568
+
569
+ static VALUE rb_gsl_vector_complex_real(VALUE obj)
570
+ {
571
+ gsl_vector_complex *c = NULL;
572
+ gsl_vector_view *vv = NULL;
573
+ Data_Get_Struct(obj, gsl_vector_complex, c);
574
+ vv = gsl_vector_view_alloc();
575
+ *vv = gsl_vector_complex_real(c);
576
+ if (VECTOR_COMPLEX_ROW_P(obj))
577
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, vv);
578
+ else
579
+ return Data_Wrap_Struct(cgsl_vector_col_view, 0, gsl_vector_view_free, vv);
580
+ }
581
+
582
+ static VALUE rb_gsl_vector_complex_imag(VALUE obj)
583
+ {
584
+ gsl_vector_complex *c = NULL;
585
+ gsl_vector_view *vv = NULL;
586
+ Data_Get_Struct(obj, gsl_vector_complex, c);
587
+ vv = gsl_vector_view_alloc();
588
+ *vv = gsl_vector_complex_imag(c);
589
+ if (VECTOR_COMPLEX_ROW_P(obj))
590
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, vv);
591
+ else
592
+ return Data_Wrap_Struct(cgsl_vector_col_view, 0, gsl_vector_view_free, vv);
593
+ }
594
+
595
+ static VALUE rb_gsl_vector_complex_set_real(VALUE obj, VALUE val)
596
+ {
597
+ gsl_vector_complex *v = NULL;
598
+ gsl_vector_view vv;
599
+ double d = NUM2DBL(val);
600
+ Data_Get_Struct(obj, gsl_vector_complex, v);
601
+ vv = gsl_vector_complex_real(v);
602
+ gsl_vector_set_all(&vv.vector, d);
603
+ return obj;
604
+ }
605
+
606
+ static VALUE rb_gsl_vector_complex_set_imag(VALUE obj, VALUE val)
607
+ {
608
+ gsl_vector_complex *v = NULL;
609
+ gsl_vector_view vv;
610
+ double d = NUM2DBL(val);
611
+ Data_Get_Struct(obj, gsl_vector_complex, v);
612
+ vv = gsl_vector_complex_imag(v);
613
+ gsl_vector_set_all(&vv.vector, d);
614
+ return obj;
615
+ }
616
+
617
+ static VALUE rb_gsl_vector_complex_conj(VALUE obj)
618
+ {
619
+ size_t i;
620
+ gsl_vector_complex *vin = NULL;
621
+ gsl_vector_complex *vout = NULL;
622
+ Data_Get_Struct(obj, gsl_vector_complex, vin);
623
+ vout = gsl_vector_complex_alloc(vin->size);
624
+ for(i=0; i<vin->size; i++) {
625
+ gsl_vector_complex_set(vout, i,
626
+ gsl_complex_conjugate(
627
+ gsl_vector_complex_get(vin, i)));
628
+ }
629
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vout);
630
+ }
631
+
632
+ static VALUE rb_gsl_vector_complex_conj_bang(VALUE obj)
633
+ {
634
+ size_t i;
635
+ gsl_vector_complex *v = NULL;
636
+ Data_Get_Struct(obj, gsl_vector_complex, v);
637
+ for(i=0; i<v->size; i++) {
638
+ gsl_vector_complex_set(v, i,
639
+ gsl_complex_conjugate(
640
+ gsl_vector_complex_get(v, i)));
641
+ }
642
+ return obj;
643
+ }
644
+
645
+ static VALUE rb_gsl_vector_complex_to_a(VALUE obj)
646
+ {
647
+ gsl_vector_complex *c = NULL;
648
+ gsl_complex *z = NULL;
649
+ size_t i, j;
650
+ VALUE ary;
651
+ Data_Get_Struct(obj, gsl_vector_complex, c);
652
+ ary = rb_ary_new2(c->size*2);
653
+ for (i = 0, j = 0; i < c->size; i++, j+=2) {
654
+ z = GSL_COMPLEX_AT(c, i);
655
+ rb_ary_store(ary, j, rb_float_new(GSL_REAL(*z)));
656
+ rb_ary_store(ary, j+1, rb_float_new(GSL_IMAG(*z)));
657
+ }
658
+ return ary;
659
+ }
660
+
661
+ static VALUE rb_gsl_vector_complex_to_a2(VALUE obj)
662
+ {
663
+ gsl_vector_complex *c = NULL;
664
+ gsl_complex *znew = NULL, *z = NULL;
665
+ size_t i;
666
+ VALUE ary, vz;
667
+ Data_Get_Struct(obj, gsl_vector_complex, c);
668
+ ary = rb_ary_new2(c->size);
669
+ for (i = 0; i < c->size; i++) {
670
+ z = GSL_COMPLEX_AT(c, i);
671
+ znew = make_complex(z->dat[0], z->dat[1]);
672
+ vz = Data_Wrap_Struct(cgsl_complex, 0, free, znew);
673
+ rb_ary_store(ary, i, vz);
674
+ }
675
+ return ary;
676
+ }
677
+
678
+ gsl_vector_complex_view* gsl_vector_complex_view_alloc()
679
+ {
680
+ gsl_vector_complex_view *vv = NULL;
681
+ vv = ALLOC(gsl_vector_complex_view);
682
+ if (vv == NULL) rb_raise(rb_eRuntimeError, "malloc failed");
683
+ return vv;
684
+ }
685
+
686
+ void gsl_vector_complex_view_free(gsl_vector_view * vv)
687
+ {
688
+ free((gsl_vector_complex_view *) vv);
689
+ }
690
+
691
+ static VALUE rb_gsl_vector_complex_subvector(int argc, VALUE *argv, VALUE obj)
692
+ {
693
+ gsl_vector_complex *v = NULL;
694
+ gsl_vector_complex_view *vv = NULL;
695
+ size_t offset, stride, n;
696
+ Data_Get_Struct(obj, gsl_vector_complex, v);
697
+ parse_subvector_args(argc, argv, v->size, &offset, &stride, &n);
698
+ vv = gsl_vector_complex_view_alloc();
699
+ *vv = gsl_vector_complex_subvector_with_stride(v, offset, stride, n);
700
+ if (VECTOR_COMPLEX_ROW_P(obj))
701
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
702
+ else
703
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, gsl_vector_complex_view_free, vv);
704
+ }
705
+
706
+ static VALUE rb_gsl_vector_complex_subvector_with_stride(VALUE obj, VALUE o, VALUE s, VALUE nn)
707
+ {
708
+ gsl_vector_complex *v = NULL;
709
+ gsl_vector_complex_view *vv = NULL;
710
+ int offset;
711
+ CHECK_FIXNUM(o); CHECK_FIXNUM(nn); CHECK_FIXNUM(s);
712
+ offset = NUM2INT(o);
713
+ Data_Get_Struct(obj, gsl_vector_complex, v);
714
+ if(offset < 0) {
715
+ offset += v->size;
716
+ }
717
+ vv = gsl_vector_complex_view_alloc();
718
+ *vv = gsl_vector_complex_subvector_with_stride(v, (size_t)offset, FIX2INT(s), FIX2INT(nn));
719
+ if (VECTOR_COMPLEX_ROW_P(obj))
720
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
721
+ else
722
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, gsl_vector_complex_view_free, vv);
723
+ }
724
+
725
+ /* singleton */
726
+ static VALUE rb_gsl_vector_complex_memcpy(VALUE obj, VALUE dst, VALUE src)
727
+ {
728
+ gsl_vector_complex *v = NULL, *dest = NULL;
729
+ CHECK_VECTOR_COMPLEX(dst);
730
+ CHECK_VECTOR_COMPLEX(src);
731
+ Data_Get_Struct(dst, gsl_vector_complex, dest);
732
+ Data_Get_Struct(src, gsl_vector_complex, v);
733
+ gsl_vector_complex_memcpy(dest, v);
734
+ return dst;
735
+ }
736
+
737
+ static VALUE rb_gsl_vector_complex_clone(VALUE obj)
738
+ {
739
+ gsl_vector_complex *v = NULL, *vnew = NULL;
740
+ Data_Get_Struct(obj, gsl_vector_complex, v);
741
+ vnew = gsl_vector_complex_alloc(v->size);
742
+ if (vnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
743
+ gsl_vector_complex_memcpy(vnew, v);
744
+ if (VECTOR_COMPLEX_ROW_P(obj))
745
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
746
+ else
747
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, vnew);
748
+ }
749
+
750
+ static VALUE rb_gsl_vector_complex_reverse(VALUE obj)
751
+ {
752
+ gsl_vector_complex *v = NULL;
753
+ Data_Get_Struct(obj, gsl_vector_complex, v);
754
+ gsl_vector_complex_reverse(v);
755
+ return obj;
756
+ }
757
+
758
+ static VALUE rb_gsl_vector_complex_reverse2(VALUE obj)
759
+ {
760
+ gsl_vector_complex *v = NULL, *vnew = NULL;
761
+ Data_Get_Struct(obj, gsl_vector_complex, v);
762
+ vnew = gsl_vector_complex_alloc(v->size);
763
+ gsl_vector_complex_memcpy(vnew, v);
764
+ gsl_vector_complex_reverse(vnew);
765
+ if (VECTOR_COMPLEX_ROW_P(obj))
766
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
767
+ else
768
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, vnew);
769
+ }
770
+
771
+ static VALUE rb_gsl_vector_complex_swap_elements(VALUE obj, VALUE i, VALUE j)
772
+ {
773
+ gsl_vector_complex *v = NULL;
774
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
775
+ Data_Get_Struct(obj, gsl_vector_complex, v);
776
+ gsl_vector_complex_swap_elements(v, FIX2INT(i), FIX2INT(j));
777
+ return obj;
778
+ }
779
+
780
+ static VALUE rb_gsl_vector_complex_fftshift_bang(VALUE obj)
781
+ {
782
+ gsl_vector_complex *v = NULL;
783
+ gsl_complex tmp;
784
+ size_t i, n;
785
+
786
+ Data_Get_Struct(obj, gsl_vector_complex, v);
787
+ n = v->size;
788
+ if(n & 1) {
789
+ // length is odd
790
+ tmp = gsl_vector_complex_get(v,0);
791
+ for(i = 0; i < n/2; i++) {
792
+ gsl_vector_complex_set(v, i, gsl_vector_complex_get(v, i+n/2+1));
793
+ gsl_vector_complex_set(v, i+n/2+1, gsl_vector_complex_get(v, i+1));
794
+ }
795
+ gsl_vector_complex_set(v, n/2, tmp);
796
+ } else {
797
+ // length is even
798
+ for(i = 0; i < n/2; i++) {
799
+ gsl_vector_complex_swap_elements(v, i, i+n/2);
800
+ }
801
+ }
802
+
803
+ return obj;
804
+ }
805
+
806
+ static VALUE rb_gsl_vector_complex_fftshift(VALUE obj)
807
+ {
808
+ gsl_vector_complex *v, *vnew;
809
+ gsl_vector_complex_view vv, vvnew;
810
+ size_t n;
811
+
812
+ Data_Get_Struct(obj, gsl_vector_complex, v);
813
+ n = v->size;
814
+ vnew = gsl_vector_complex_alloc(n);
815
+ // Copy low to high
816
+ vv = gsl_vector_complex_subvector(v, 0, (n+1)/2);
817
+ vvnew = gsl_vector_complex_subvector(vnew, n/2, (n+1)/2);
818
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
819
+ // Copy high to low
820
+ vv = gsl_vector_complex_subvector(v, (n+1)/2, n/2);
821
+ vvnew = gsl_vector_complex_subvector(vnew, 0, n/2);
822
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
823
+
824
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
825
+ }
826
+
827
+ static VALUE rb_gsl_vector_complex_ifftshift_bang(VALUE obj)
828
+ {
829
+ gsl_vector_complex *v = NULL;
830
+ gsl_complex tmp;
831
+ size_t i, n;
832
+
833
+ Data_Get_Struct(obj, gsl_vector_complex, v);
834
+ n = v->size;
835
+ if(n & 1) {
836
+ // length is odd
837
+ tmp = gsl_vector_complex_get(v,n/2);
838
+ for(i = n/2; i > 0; i--) {
839
+ gsl_vector_complex_set(v, i, gsl_vector_complex_get(v, i+n/2));
840
+ gsl_vector_complex_set(v, i+n/2, gsl_vector_complex_get(v, i-1));
841
+ }
842
+ gsl_vector_complex_set(v, 0, tmp);
843
+ } else {
844
+ // length is even
845
+ for(i = 0; i < n/2; i++) {
846
+ gsl_vector_complex_swap_elements(v, i, i+n/2);
847
+ }
848
+ }
849
+
850
+ return obj;
851
+ }
852
+
853
+ static VALUE rb_gsl_vector_complex_ifftshift(VALUE obj)
854
+ {
855
+ return rb_gsl_vector_complex_ifftshift_bang(rb_gsl_vector_complex_clone(obj));
856
+ gsl_vector_complex *v, *vnew;
857
+ gsl_vector_complex_view vv, vvnew;
858
+ size_t n;
859
+
860
+ Data_Get_Struct(obj, gsl_vector_complex, v);
861
+ n = v->size;
862
+ vnew = gsl_vector_complex_alloc(n);
863
+ // Copy high to low
864
+ vv = gsl_vector_complex_subvector(vnew, n/2, (n+1)/2);
865
+ vvnew = gsl_vector_complex_subvector(v, 0, (n+1)/2);
866
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
867
+ // Copy low to high
868
+ vv = gsl_vector_complex_subvector(vnew, 0, n/2);
869
+ vvnew = gsl_vector_complex_subvector(v, (n+1)/2, n/2);
870
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
871
+
872
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
873
+ }
874
+
875
+ static VALUE rb_gsl_vector_complex_isnull(VALUE obj)
876
+ {
877
+ gsl_vector_complex *v = NULL;
878
+ Data_Get_Struct(obj, gsl_vector_complex, v);
879
+ if (gsl_vector_complex_isnull(v)) return Qtrue;
880
+ else return Qfalse;
881
+ }
882
+
883
+ static VALUE rb_gsl_vector_complex_matrix_view(int argc, VALUE *argv, VALUE obj)
884
+ {
885
+ gsl_vector_complex *v = NULL;
886
+ gsl_matrix_complex_view *mv = NULL;
887
+ Data_Get_Struct(obj, gsl_vector_complex, v);
888
+ switch (argc) {
889
+ case 2:
890
+ mv = gsl_matrix_complex_view_alloc();
891
+ *mv = gsl_matrix_complex_view_vector(v, FIX2INT(argv[0]), FIX2INT(argv[1]));
892
+ break;
893
+ case 3:
894
+ mv = gsl_matrix_complex_view_alloc();
895
+ *mv = gsl_matrix_complex_view_vector_with_tda(v, FIX2INT(argv[0]), FIX2INT(argv[1]),
896
+ FIX2INT(argv[2]));
897
+ break;
898
+ default:
899
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
900
+ break;
901
+ }
902
+ return Data_Wrap_Struct(cgsl_matrix_complex_view, 0, gsl_matrix_complex_view_free, mv);
903
+ }
904
+
905
+ static VALUE rb_gsl_vector_complex_matrix_view_with_tda(VALUE obj, VALUE nn1, VALUE nn2,
906
+ VALUE tda)
907
+ {
908
+ gsl_vector_complex *v = NULL;
909
+ gsl_matrix_complex_view *mv = NULL;
910
+ CHECK_FIXNUM(nn1); CHECK_FIXNUM(nn2); CHECK_FIXNUM(tda);
911
+ Data_Get_Struct(obj, gsl_vector_complex, v);
912
+ mv = gsl_matrix_complex_view_alloc();
913
+ if (mv == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
914
+ *mv = gsl_matrix_complex_view_vector_with_tda(v, FIX2INT(nn1), FIX2INT(nn2), FIX2INT(tda));
915
+ return Data_Wrap_Struct(cgsl_matrix_complex_view, 0, gsl_matrix_complex_view_free, mv);
916
+ }
917
+
918
+ static VALUE rb_gsl_vector_complex_trans(VALUE obj)
919
+ {
920
+ gsl_vector_complex *v = NULL, *vnew = NULL;
921
+ Data_Get_Struct(obj, gsl_vector_complex, v);
922
+ vnew = make_vector_complex_clone(v);
923
+ if (VECTOR_COMPLEX_ROW_P(obj))
924
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, vnew);
925
+ else if (VECTOR_COMPLEX_COL_P(obj))
926
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
927
+ else {
928
+ rb_raise(rb_eTypeError, "wrong type");
929
+ }
930
+ }
931
+
932
+ static VALUE rb_gsl_vector_complex_trans2(VALUE obj)
933
+ {
934
+ if (CLASS_OF(obj) == cgsl_vector_complex)
935
+ RBASIC(obj)->klass = cgsl_vector_complex_col;
936
+ else if (CLASS_OF(obj) == cgsl_vector_complex_col)
937
+ RBASIC(obj)->klass = cgsl_vector_complex;
938
+ else {
939
+ rb_raise(rb_eRuntimeError, "method trans! for %s is forbidden",
940
+ rb_class2name(CLASS_OF(obj)));
941
+ }
942
+ return obj;
943
+ }
944
+
945
+ static VALUE rb_gsl_vector_complex_to_real(VALUE obj)
946
+ {
947
+ gsl_vector_complex *cv = NULL;
948
+ gsl_vector *v = NULL;
949
+ gsl_complex z;
950
+ size_t i;
951
+ Data_Get_Struct(obj, gsl_vector_complex, cv);
952
+ v = gsl_vector_alloc(cv->size);
953
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
954
+ for (i = 0; i < cv->size; i++) {
955
+ z = gsl_vector_complex_get(cv, i);
956
+ gsl_vector_set(v, i, GSL_REAL(z));
957
+ }
958
+ if (VECTOR_COMPLEX_ROW_P(obj))
959
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
960
+ else
961
+ return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, v);
962
+ }
963
+
964
+ enum {
965
+ GSL_VECTOR_COMPLEX_ADD,
966
+ GSL_VECTOR_COMPLEX_SUB,
967
+ GSL_VECTOR_COMPLEX_MUL,
968
+ GSL_VECTOR_COMPLEX_DIV,
969
+ GSL_VECTOR_COMPLEX_ADD_BANG,
970
+ GSL_VECTOR_COMPLEX_SUB_BANG,
971
+ GSL_VECTOR_COMPLEX_MUL_BANG,
972
+ GSL_VECTOR_COMPLEX_DIV_BANG,
973
+ };
974
+
975
+ static VALUE rb_gsl_vector_complex_arithmetics(int flag, VALUE obj, VALUE bb);
976
+
977
+ static VALUE rb_gsl_vector_complex_arithmetics(int flag, VALUE obj, VALUE bb)
978
+ {
979
+ gsl_vector *b = NULL;
980
+ gsl_vector_complex *cv = NULL, *cvnew = NULL, *cb = NULL;
981
+ gsl_complex *c = NULL, z;
982
+ Data_Get_Struct(obj, gsl_vector_complex, cv);
983
+ switch (flag) {
984
+ case GSL_VECTOR_COMPLEX_ADD:
985
+ case GSL_VECTOR_COMPLEX_SUB:
986
+ case GSL_VECTOR_COMPLEX_MUL:
987
+ case GSL_VECTOR_COMPLEX_DIV:
988
+ cvnew = make_vector_complex_clone(cv);
989
+ obj = Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, cvnew);
990
+ break;
991
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
992
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
993
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
994
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
995
+ cvnew = cv;
996
+ break;
997
+ default:
998
+ rb_raise(rb_eRuntimeError, "unknown operation");
999
+ break;
1000
+ }
1001
+ switch (TYPE(bb)) {
1002
+ case T_FLOAT:
1003
+ case T_FIXNUM:
1004
+ case T_BIGNUM:
1005
+ z = gsl_complex_rect(NUM2DBL(bb), 0.0);
1006
+ switch (flag) {
1007
+ case GSL_VECTOR_COMPLEX_ADD:
1008
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1009
+ gsl_vector_complex_add_constant(cvnew, z);
1010
+ break;
1011
+ case GSL_VECTOR_COMPLEX_SUB:
1012
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1013
+ gsl_vector_complex_add_constant(cvnew, gsl_complex_negative(z));
1014
+ break;
1015
+ case GSL_VECTOR_COMPLEX_MUL:
1016
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1017
+ gsl_vector_complex_scale(cvnew, z);
1018
+ break;
1019
+ case GSL_VECTOR_COMPLEX_DIV:
1020
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1021
+ gsl_vector_complex_scale(cvnew, gsl_complex_inverse(z));
1022
+ break;
1023
+ }
1024
+ break;
1025
+ default:
1026
+ if (VECTOR_P(bb)) {
1027
+ Data_Get_Struct(bb, gsl_vector, b);
1028
+ cb = vector_to_complex(b);
1029
+ switch (flag) {
1030
+ case GSL_VECTOR_COMPLEX_ADD:
1031
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1032
+ gsl_vector_complex_add(cvnew, cb);
1033
+ break;
1034
+ case GSL_VECTOR_COMPLEX_SUB:
1035
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1036
+ gsl_vector_complex_sub(cvnew, cb);
1037
+ break;
1038
+ case GSL_VECTOR_COMPLEX_MUL:
1039
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1040
+ gsl_vector_complex_mul(cvnew, cb);
1041
+ break;
1042
+ case GSL_VECTOR_COMPLEX_DIV:
1043
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1044
+ gsl_vector_complex_div(cvnew, cb);
1045
+ break;
1046
+ }
1047
+ gsl_vector_complex_free(cb);
1048
+ } else if (VECTOR_COMPLEX_P(bb)) {
1049
+ Data_Get_Struct(bb, gsl_vector_complex, cb);
1050
+ switch (flag) {
1051
+ case GSL_VECTOR_COMPLEX_ADD:
1052
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1053
+ gsl_vector_complex_add(cvnew, cb);
1054
+ break;
1055
+ case GSL_VECTOR_COMPLEX_SUB:
1056
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1057
+ gsl_vector_complex_sub(cvnew, cb);
1058
+ break;
1059
+ case GSL_VECTOR_COMPLEX_MUL:
1060
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1061
+ gsl_vector_complex_mul(cvnew, cb);
1062
+ break;
1063
+ case GSL_VECTOR_COMPLEX_DIV:
1064
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1065
+ gsl_vector_complex_div(cvnew, cb);
1066
+ break;
1067
+ }
1068
+ } else if (COMPLEX_P(bb)) {
1069
+ Data_Get_Struct(bb, gsl_complex, c);
1070
+ switch (flag) {
1071
+ case GSL_VECTOR_COMPLEX_ADD:
1072
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1073
+ gsl_vector_complex_add_constant(cvnew, *c);
1074
+ break;
1075
+ case GSL_VECTOR_COMPLEX_SUB:
1076
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1077
+ gsl_vector_complex_add_constant(cvnew, gsl_complex_negative(*c));
1078
+ break;
1079
+ case GSL_VECTOR_COMPLEX_MUL:
1080
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1081
+ gsl_vector_complex_scale(cvnew, *c);
1082
+ break;
1083
+ case GSL_VECTOR_COMPLEX_DIV:
1084
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1085
+ gsl_vector_complex_scale(cvnew, gsl_complex_inverse(*c));
1086
+ break;
1087
+ }
1088
+ } else {
1089
+ rb_raise(rb_eTypeError, "wrong type argument %s", rb_class2name(CLASS_OF(bb)));
1090
+ }
1091
+ break;
1092
+ }
1093
+ return obj;
1094
+ }
1095
+
1096
+ static VALUE rb_gsl_vector_complex_add(VALUE obj, VALUE bb)
1097
+ {
1098
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_ADD, obj, bb);
1099
+ }
1100
+
1101
+ static VALUE rb_gsl_vector_complex_sub(VALUE obj, VALUE bb)
1102
+ {
1103
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_SUB, obj, bb);
1104
+ }
1105
+
1106
+ static VALUE rb_gsl_vector_complex_mul(VALUE obj, VALUE bb)
1107
+ {
1108
+ VALUE argv[2];
1109
+ if (VECTOR_COMPLEX_ROW_P(obj) && VECTOR_COMPLEX_COL_P(bb)) {
1110
+ argv[0] = obj;
1111
+ argv[1] = bb;
1112
+ return rb_gsl_vector_complex_inner_product(2, argv, CLASS_OF(obj));
1113
+ }
1114
+ if (VECTOR_COMPLEX_COL_P(obj) && VECTOR_COMPLEX_ROW_P(bb)) {
1115
+ argv[0] = obj;
1116
+ argv[1] = bb;
1117
+ return rb_gsl_vector_complex_product_to_m(2, argv, CLASS_OF(obj));
1118
+ }
1119
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_MUL, obj, bb);
1120
+ }
1121
+
1122
+ static VALUE rb_gsl_vector_complex_div(VALUE obj, VALUE bb)
1123
+ {
1124
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_DIV, obj, bb);
1125
+ }
1126
+
1127
+ static VALUE rb_gsl_vector_complex_add_bang(VALUE obj, VALUE bb)
1128
+ {
1129
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_ADD_BANG, obj, bb);
1130
+ }
1131
+
1132
+ static VALUE rb_gsl_vector_complex_sub_bang(VALUE obj, VALUE bb)
1133
+ {
1134
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_SUB_BANG, obj, bb);
1135
+ }
1136
+
1137
+ static VALUE rb_gsl_vector_complex_mul_bang(VALUE obj, VALUE bb)
1138
+ {
1139
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_MUL_BANG, obj, bb);
1140
+ }
1141
+
1142
+ static VALUE rb_gsl_vector_complex_div_bang(VALUE obj, VALUE bb)
1143
+ {
1144
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_DIV_BANG, obj, bb);
1145
+ }
1146
+
1147
+ static VALUE rb_gsl_vector_complex_coerce(VALUE obj, VALUE other)
1148
+ {
1149
+ gsl_vector_complex *cv = NULL, *cb = NULL;
1150
+ gsl_complex z;
1151
+ VALUE vv;
1152
+ Data_Get_Struct(obj, gsl_vector_complex, cv);
1153
+ switch (TYPE(other)) {
1154
+ case T_FLOAT:
1155
+ case T_FIXNUM:
1156
+ case T_BIGNUM:
1157
+ z = gsl_complex_rect(NUM2DBL(other), 0.0);
1158
+ cb = gsl_vector_complex_alloc(cv->size);
1159
+ if (cb == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
1160
+ gsl_vector_complex_set_all(cb, z);
1161
+ vv = Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, cb);
1162
+ return rb_ary_new3(2, vv, obj);
1163
+ break;
1164
+ default:
1165
+ rb_raise(rb_eTypeError, "GSL::Vector::Complex, operation not defined");
1166
+ break;
1167
+ }
1168
+ }
1169
+
1170
+ /* 2.Aug.2004 */
1171
+ static VALUE rb_gsl_vector_complex_inner_product(int argc, VALUE *argv, VALUE obj)
1172
+ {
1173
+ gsl_vector_complex *v = NULL, *v2 = NULL;
1174
+ gsl_complex prod, a, b, *z = NULL;
1175
+ size_t i;
1176
+ switch (TYPE(obj)) {
1177
+ case T_MODULE:
1178
+ case T_CLASS:
1179
+ case T_OBJECT:
1180
+ if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
1181
+ argc);
1182
+ if (!VECTOR_COMPLEX_ROW_P(argv[0]))
1183
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Complex expected)",
1184
+ rb_class2name(CLASS_OF(argv[0])));
1185
+ if (!VECTOR_COMPLEX_COL_P(argv[1]))
1186
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Complex::Col expected)",
1187
+ rb_class2name(CLASS_OF(argv[1])));
1188
+ Data_Get_Struct(argv[0], gsl_vector_complex, v);
1189
+ Data_Get_Struct(argv[1], gsl_vector_complex, v2);
1190
+ break;
1191
+ default:
1192
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
1193
+ argc);
1194
+ if (!VECTOR_COMPLEX_COL_P(argv[0]))
1195
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Complex::Col expected)",
1196
+ rb_class2name(CLASS_OF(argv[0])));
1197
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1198
+ Data_Get_Struct(argv[0], gsl_vector_complex, v2);
1199
+ break;
1200
+ }
1201
+ if (v->size != v2->size) rb_raise(rb_eRangeError, "vector lengths are different.");
1202
+ prod = gsl_complex_rect(0.0, 0.0);
1203
+ for (i = 0; i < v->size; i++) {
1204
+ a = gsl_vector_complex_get(v, i);
1205
+ b = gsl_vector_complex_get(v2, i);
1206
+ prod = gsl_complex_add(prod, gsl_complex_mul(a, b));
1207
+ }
1208
+ z = ALLOC(gsl_complex);
1209
+ *z = prod;
1210
+ return Data_Wrap_Struct(cgsl_complex, 0, free, z);
1211
+ }
1212
+
1213
+ static VALUE rb_gsl_vector_complex_product_to_m(int argc, VALUE *argv, VALUE obj)
1214
+ {
1215
+ gsl_vector_complex *v = NULL, *v2 = NULL;
1216
+ gsl_matrix_complex *m = NULL;
1217
+ gsl_complex a, b;
1218
+ size_t i, j;
1219
+ switch (TYPE(obj)) {
1220
+ case T_MODULE:
1221
+ case T_CLASS:
1222
+ case T_OBJECT:
1223
+ if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
1224
+ argc);
1225
+ if (!VECTOR_COMPLEX_COL_P(argv[0]))
1226
+ rb_raise(rb_eTypeError,
1227
+ "wrong argument type %s (GSL::Vector::Complex::Col expected)",
1228
+ rb_class2name(CLASS_OF(argv[0])));
1229
+ if (!VECTOR_COMPLEX_ROW_P(argv[1]))
1230
+ rb_raise(rb_eTypeError,
1231
+ "wrong argument type %s (GSL::Vector::Complex expected)",
1232
+ rb_class2name(CLASS_OF(argv[1])));
1233
+ Data_Get_Struct(argv[0], gsl_vector_complex, v);
1234
+ Data_Get_Struct(argv[1], gsl_vector_complex, v2);
1235
+ break;
1236
+ default:
1237
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
1238
+ argc);
1239
+ if (!VECTOR_COMPLEX_ROW_P(argv[0]))
1240
+ rb_raise(rb_eTypeError,
1241
+ "wrong argument type %s (GSL::Vector::Complex expected)",
1242
+ rb_class2name(CLASS_OF(argv[0])));
1243
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1244
+ Data_Get_Struct(argv[0], gsl_vector_complex, v2);
1245
+ break;
1246
+ }
1247
+ m = gsl_matrix_complex_alloc(v->size, v2->size);
1248
+ for (i = 0; i < v->size; i++) {
1249
+ for (j = 0; j < v2->size; j++) {
1250
+ a = gsl_vector_complex_get(v, i);
1251
+ b = gsl_vector_complex_get(v2, j);
1252
+ gsl_matrix_complex_set(m, i, j, gsl_complex_mul(a, b));
1253
+ }
1254
+ }
1255
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, m);
1256
+ }
1257
+
1258
+ static VALUE rb_gsl_vector_complex_uplus(VALUE obj)
1259
+ {
1260
+ return obj;
1261
+ }
1262
+
1263
+ static VALUE rb_gsl_vector_complex_uminus(VALUE obj)
1264
+ {
1265
+ gsl_vector_complex *v = NULL, *vnew;
1266
+ size_t i;
1267
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1268
+ vnew = gsl_vector_complex_alloc(v->size);
1269
+ for (i = 0; i < v->size; i++) {
1270
+ gsl_vector_complex_set(vnew, i, gsl_complex_negative(gsl_vector_complex_get(v, i)));
1271
+ }
1272
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
1273
+ }
1274
+
1275
+ /*****/
1276
+ static VALUE rb_gsl_vector_complex_XXX(VALUE obj, double (*f)(gsl_complex))
1277
+ {
1278
+ gsl_vector_complex *m;
1279
+ gsl_vector *v;
1280
+ gsl_complex c;
1281
+ size_t i;
1282
+ Data_Get_Struct(obj, gsl_vector_complex, m);
1283
+ v = gsl_vector_alloc(m->size);
1284
+ for (i = 0; i < m->size; i++) {
1285
+ c = gsl_vector_complex_get(m, i);
1286
+ gsl_vector_set(v, i, (*f)(c));
1287
+ }
1288
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
1289
+ }
1290
+
1291
+ static VALUE rb_gsl_vector_complex_XXXz(VALUE obj, gsl_complex (*f)(gsl_complex))
1292
+ {
1293
+ gsl_vector_complex *m, *v;
1294
+ gsl_complex c;
1295
+ size_t i;
1296
+ Data_Get_Struct(obj, gsl_vector_complex, m);
1297
+ v = gsl_vector_complex_alloc(m->size);
1298
+ for (i = 0; i < m->size; i++) {
1299
+ c = gsl_vector_complex_get(m, i);
1300
+ gsl_vector_complex_set(v, i, (*f)(c));
1301
+ }
1302
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
1303
+ }
1304
+
1305
+ /* In-place version of rb_gsl_vector_complex_XXXz */
1306
+ static VALUE rb_gsl_vector_complex_XXXz_bang(VALUE obj, gsl_complex (*f)(gsl_complex))
1307
+ {
1308
+ gsl_vector_complex *v;
1309
+ gsl_complex c;
1310
+ size_t i;
1311
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1312
+ for (i = 0; i < v->size; i++) {
1313
+ c = gsl_vector_complex_get(v, i);
1314
+ gsl_vector_complex_set(v, i, (*f)(c));
1315
+ }
1316
+ return obj;
1317
+ }
1318
+
1319
+ static VALUE rb_gsl_vector_complex_XXXz2(VALUE obj, VALUE a,
1320
+ gsl_complex (*f)(gsl_complex, gsl_complex))
1321
+ {
1322
+ gsl_vector_complex *m, *v;
1323
+ gsl_complex c, *z;
1324
+ size_t i;
1325
+ CHECK_COMPLEX(a);
1326
+ Data_Get_Struct(obj, gsl_vector_complex, m);
1327
+ Data_Get_Struct(a, gsl_complex, z);
1328
+ v = gsl_vector_complex_alloc(m->size);
1329
+ for (i = 0; i < m->size; i++) {
1330
+ c = gsl_vector_complex_get(m, i);
1331
+ gsl_vector_complex_set(v, i, (*f)(c, *z));
1332
+ }
1333
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
1334
+ }
1335
+
1336
+ static VALUE rb_gsl_vector_complex_XXXz2_bang(VALUE obj, VALUE a,
1337
+ gsl_complex (*f)(gsl_complex, gsl_complex))
1338
+ {
1339
+ gsl_vector_complex *v;
1340
+ gsl_complex c, *z;
1341
+ size_t i;
1342
+ CHECK_COMPLEX(a);
1343
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1344
+ Data_Get_Struct(a, gsl_complex, z);
1345
+ for (i = 0; i < v->size; i++) {
1346
+ c = gsl_vector_complex_get(v, i);
1347
+ gsl_vector_complex_set(v, i, (*f)(c, *z));
1348
+ }
1349
+ return obj;
1350
+ }
1351
+
1352
+ static VALUE rb_gsl_vector_complex_abs2(VALUE obj)
1353
+ {
1354
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_abs2);
1355
+ }
1356
+
1357
+ static VALUE rb_gsl_vector_complex_abs(VALUE obj)
1358
+ {
1359
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_abs);
1360
+ }
1361
+
1362
+ static VALUE rb_gsl_vector_complex_logabs(VALUE obj)
1363
+ {
1364
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_logabs);
1365
+ }
1366
+
1367
+ static VALUE rb_gsl_vector_complex_arg(VALUE obj)
1368
+ {
1369
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_arg);
1370
+ }
1371
+
1372
+ static VALUE rb_gsl_vector_complex_sqrt(VALUE obj)
1373
+ {
1374
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sqrt);
1375
+ }
1376
+
1377
+ static VALUE rb_gsl_vector_complex_sqrt_bang(VALUE obj)
1378
+ {
1379
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_sqrt);
1380
+ }
1381
+
1382
+ static VALUE rb_gsl_vector_complex_exp(VALUE obj)
1383
+ {
1384
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_exp);
1385
+ }
1386
+
1387
+ static VALUE rb_gsl_vector_complex_exp_bang(VALUE obj)
1388
+ {
1389
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_exp);
1390
+ }
1391
+
1392
+ static VALUE rb_gsl_vector_complex_pow(VALUE obj, VALUE a)
1393
+ {
1394
+ return rb_gsl_vector_complex_XXXz2(obj, a, gsl_complex_pow);
1395
+ }
1396
+
1397
+ static VALUE rb_gsl_vector_complex_pow_bang(VALUE obj, VALUE a)
1398
+ {
1399
+ return rb_gsl_vector_complex_XXXz2_bang(obj, a, gsl_complex_pow);
1400
+ }
1401
+
1402
+ static VALUE rb_gsl_vector_complex_log(VALUE obj)
1403
+ {
1404
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_log);
1405
+ }
1406
+
1407
+ static VALUE rb_gsl_vector_complex_log_bang(VALUE obj)
1408
+ {
1409
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_log);
1410
+ }
1411
+
1412
+ static VALUE rb_gsl_vector_complex_log10(VALUE obj)
1413
+ {
1414
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_log10);
1415
+ }
1416
+
1417
+ static VALUE rb_gsl_vector_complex_log10_bang(VALUE obj)
1418
+ {
1419
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_log10);
1420
+ }
1421
+
1422
+ static VALUE rb_gsl_vector_complex_log_b(VALUE obj, VALUE a)
1423
+ {
1424
+ return rb_gsl_vector_complex_XXXz2(obj, a, gsl_complex_log_b);
1425
+ }
1426
+
1427
+ static VALUE rb_gsl_vector_complex_log_b_bang(VALUE obj, VALUE a)
1428
+ {
1429
+ return rb_gsl_vector_complex_XXXz2_bang(obj, a, gsl_complex_log_b);
1430
+ }
1431
+
1432
+ /* gsl_vector_complex_sum */
1433
+ static gsl_complex rb_gsl_vector_complex_sum_gsl(gsl_vector_complex * v)
1434
+ {
1435
+ size_t i;
1436
+ gsl_complex z = gsl_complex_rect(0.0,0.0);
1437
+
1438
+ for(i=0; i<v->size; i++) {
1439
+ z = gsl_complex_add(z, gsl_vector_complex_get(v,i));
1440
+ }
1441
+ return z;
1442
+ }
1443
+
1444
+ /* gsl_vector_complex_mean */
1445
+ static gsl_complex rb_gsl_vector_complex_mean_gsl(gsl_vector_complex * v)
1446
+ {
1447
+ gsl_complex z = rb_gsl_vector_complex_sum_gsl(v);
1448
+ return gsl_complex_div_real(z, (double)v->size);
1449
+ }
1450
+
1451
+ /* gsl_vector_complex_tss_m */
1452
+ static double rb_gsl_vector_complex_tss_m_gsl(gsl_vector_complex * v, gsl_complex mean)
1453
+ {
1454
+ size_t i;
1455
+ double tss = 0.0;
1456
+
1457
+ for(i=0; i<v->size; i++) {
1458
+ tss += gsl_complex_abs2(gsl_complex_sub(gsl_vector_complex_get(v,i), mean));
1459
+ }
1460
+ return tss;
1461
+ }
1462
+
1463
+ /* gsl_vector_complex_variance_m */
1464
+ static double rb_gsl_vector_complex_variance_m_gsl(gsl_vector_complex * v, gsl_complex mean)
1465
+ {
1466
+ double tss = rb_gsl_vector_complex_tss_m_gsl(v, mean);
1467
+ return tss / (double)(v->size - 1);
1468
+ }
1469
+
1470
+ /* gsl_vector_complex_variance_with_fixed_mean */
1471
+ static double rb_gsl_vector_complex_variance_fm_gsl(gsl_vector_complex * v, gsl_complex mean)
1472
+ {
1473
+ double tss = rb_gsl_vector_complex_tss_m_gsl(v, mean);
1474
+ return tss / (double)(v->size);
1475
+ }
1476
+
1477
+ /* gsl_vector_complex_sd_m */
1478
+ static double rb_gsl_vector_complex_sd_m_gsl(gsl_vector_complex * v, gsl_complex mean)
1479
+ {
1480
+ double var = rb_gsl_vector_complex_variance_m_gsl(v, mean);
1481
+ return sqrt(var);
1482
+ }
1483
+
1484
+ /* gsl_vector_complex_sd_with_fixed_mean */
1485
+ static double rb_gsl_vector_complex_sd_fm_gsl(gsl_vector_complex * v, gsl_complex mean)
1486
+ {
1487
+ double var = rb_gsl_vector_complex_variance_fm_gsl(v, mean);
1488
+ return sqrt(var);
1489
+ }
1490
+
1491
+ /* gsl_vector_complex_tss */
1492
+ static double rb_gsl_vector_complex_tss_gsl(gsl_vector_complex * v)
1493
+ {
1494
+ gsl_complex mean = rb_gsl_vector_complex_mean_gsl(v);
1495
+ return rb_gsl_vector_complex_tss_m_gsl(v, mean);
1496
+ }
1497
+
1498
+ /* gsl_vector_complex_variance */
1499
+ static double rb_gsl_vector_complex_variance_gsl(gsl_vector_complex * v)
1500
+ {
1501
+ double tss = rb_gsl_vector_complex_tss_gsl(v);
1502
+ return tss / (double)(v->size - 1);
1503
+ }
1504
+
1505
+ /* gsl_vector_complex_sd */
1506
+ static double rb_gsl_vector_complex_sd_gsl(gsl_vector_complex * v)
1507
+ {
1508
+ double var = rb_gsl_vector_complex_variance_gsl(v);
1509
+ return sqrt(var);
1510
+ }
1511
+
1512
+ /* Wrapper around stats funcs with prototype like
1513
+ * "gsl_complex func(gsl_vector_complex *v)"
1514
+ * (e.g. sum and mean)
1515
+ */
1516
+ static VALUE rb_gsl_vector_complex_z_stats_v(VALUE obj,
1517
+ gsl_complex (*func)(gsl_vector_complex*))
1518
+ {
1519
+ gsl_vector_complex * v;
1520
+ gsl_complex * zp;
1521
+ VALUE zv;
1522
+
1523
+ CHECK_VECTOR_COMPLEX(obj);
1524
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1525
+
1526
+ zv = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
1527
+ *zp = func(v);
1528
+
1529
+ return zv;
1530
+ }
1531
+
1532
+ /* Wrapper around stats funcs with prototype like
1533
+ * "double func(gsl_vector_complex *v)"
1534
+ * (e.g. tss, variance, sd)
1535
+ */
1536
+ static VALUE rb_gsl_vector_complex_d_stats_v(VALUE obj,
1537
+ double (*func)(gsl_vector_complex*))
1538
+ {
1539
+ gsl_vector_complex * v;
1540
+ double d;
1541
+
1542
+ CHECK_VECTOR_COMPLEX(obj);
1543
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1544
+
1545
+ d = func(v);
1546
+
1547
+ return rb_float_new(d);
1548
+ }
1549
+
1550
+ /* Wrapper around stats funcs with prototype like
1551
+ * "double func(gsl_vector_complex *v, gsl_complex z)"
1552
+ * (e.g. tss_m, variance_m, sd_m, variance_fm, sd_fm)
1553
+ */
1554
+ static VALUE rb_gsl_vector_complex_d_stats_v_z(VALUE obj, VALUE arg,
1555
+ double (*func)(gsl_vector_complex*, gsl_complex))
1556
+ {
1557
+ gsl_vector_complex * v;
1558
+ gsl_complex z;
1559
+ gsl_complex * zp;
1560
+ double d;
1561
+
1562
+ CHECK_VECTOR_COMPLEX(obj);
1563
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1564
+
1565
+
1566
+ switch (TYPE(arg)) {
1567
+ case T_FLOAT:
1568
+ case T_FIXNUM:
1569
+ case T_BIGNUM:
1570
+ z = gsl_complex_rect(NUM2DBL(arg), 0.0);
1571
+ zp = &z;
1572
+ break;
1573
+ default:
1574
+ CHECK_COMPLEX(arg);
1575
+ Data_Get_Struct(arg, gsl_complex, zp);
1576
+ break;
1577
+ }
1578
+
1579
+ d = func(v,*zp);
1580
+
1581
+ return rb_float_new(d);
1582
+ }
1583
+
1584
+ static VALUE rb_gsl_vector_complex_sum(VALUE obj)
1585
+ {
1586
+ return rb_gsl_vector_complex_z_stats_v(obj, rb_gsl_vector_complex_sum_gsl);
1587
+ }
1588
+
1589
+ static VALUE rb_gsl_vector_complex_mean(VALUE obj)
1590
+ {
1591
+ return rb_gsl_vector_complex_z_stats_v(obj, rb_gsl_vector_complex_mean_gsl);
1592
+ }
1593
+
1594
+ static VALUE rb_gsl_vector_complex_tss_m(VALUE obj, VALUE arg)
1595
+ {
1596
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_tss_m_gsl);
1597
+ }
1598
+
1599
+ static VALUE rb_gsl_vector_complex_variance_m(VALUE obj, VALUE arg)
1600
+ {
1601
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_variance_m_gsl);
1602
+ }
1603
+
1604
+ static VALUE rb_gsl_vector_complex_variance_fm(VALUE obj, VALUE arg)
1605
+ {
1606
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_variance_fm_gsl);
1607
+ }
1608
+
1609
+ static VALUE rb_gsl_vector_complex_sd_m(VALUE obj, VALUE arg)
1610
+ {
1611
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_sd_m_gsl);
1612
+ }
1613
+
1614
+ static VALUE rb_gsl_vector_complex_sd_fm(VALUE obj, VALUE arg)
1615
+ {
1616
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_sd_fm_gsl);
1617
+ }
1618
+
1619
+ static VALUE rb_gsl_vector_complex_tss(VALUE obj)
1620
+ {
1621
+ return rb_gsl_vector_complex_d_stats_v(obj, rb_gsl_vector_complex_tss_gsl);
1622
+ }
1623
+
1624
+ static VALUE rb_gsl_vector_complex_variance(VALUE obj)
1625
+ {
1626
+ return rb_gsl_vector_complex_d_stats_v(obj, rb_gsl_vector_complex_variance_gsl);
1627
+ }
1628
+
1629
+ static VALUE rb_gsl_vector_complex_sd(VALUE obj)
1630
+ {
1631
+ return rb_gsl_vector_complex_d_stats_v(obj, rb_gsl_vector_complex_sd_gsl);
1632
+ }
1633
+
1634
+ /*****/
1635
+
1636
+ static VALUE rb_gsl_vector_complex_sin(VALUE obj)
1637
+ {
1638
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sin);
1639
+ }
1640
+
1641
+ static VALUE rb_gsl_vector_complex_cos(VALUE obj)
1642
+ {
1643
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_cos);
1644
+ }
1645
+
1646
+ static VALUE rb_gsl_vector_complex_tan(VALUE obj)
1647
+ {
1648
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_tan);
1649
+ }
1650
+
1651
+ static VALUE rb_gsl_vector_complex_sec(VALUE obj)
1652
+ {
1653
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sec);
1654
+ }
1655
+
1656
+ static VALUE rb_gsl_vector_complex_csc(VALUE obj)
1657
+ {
1658
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_csc);
1659
+ }
1660
+ static VALUE rb_gsl_vector_complex_cot(VALUE obj)
1661
+ {
1662
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_cot);
1663
+ }
1664
+
1665
+ static VALUE rb_gsl_vector_complex_arcsin(VALUE obj)
1666
+ {
1667
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsin);
1668
+ }
1669
+
1670
+ static VALUE rb_gsl_vector_complex_arccos(VALUE obj)
1671
+ {
1672
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccos);
1673
+ }
1674
+
1675
+ static VALUE rb_gsl_vector_complex_arctan(VALUE obj)
1676
+ {
1677
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arctan);
1678
+ }
1679
+
1680
+ static VALUE rb_gsl_vector_complex_arcsec(VALUE obj)
1681
+ {
1682
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsec);
1683
+ }
1684
+
1685
+ static VALUE rb_gsl_vector_complex_arccsc(VALUE obj)
1686
+ {
1687
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccsc);
1688
+ }
1689
+
1690
+ static VALUE rb_gsl_vector_complex_arccot(VALUE obj)
1691
+ {
1692
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccot);
1693
+ }
1694
+
1695
+ static VALUE rb_gsl_vector_complex_sinh(VALUE obj)
1696
+ {
1697
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sinh);
1698
+ }
1699
+
1700
+ static VALUE rb_gsl_vector_complex_cosh(VALUE obj)
1701
+ {
1702
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_cosh);
1703
+ }
1704
+
1705
+ static VALUE rb_gsl_vector_complex_tanh(VALUE obj)
1706
+ {
1707
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_tanh);
1708
+ }
1709
+
1710
+ static VALUE rb_gsl_vector_complex_sech(VALUE obj)
1711
+ {
1712
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sech);
1713
+ }
1714
+
1715
+ static VALUE rb_gsl_vector_complex_csch(VALUE obj)
1716
+ {
1717
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_csch);
1718
+ }
1719
+
1720
+ static VALUE rb_gsl_vector_complex_coth(VALUE obj)
1721
+ {
1722
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_coth);
1723
+ }
1724
+
1725
+ static VALUE rb_gsl_vector_complex_arcsinh(VALUE obj)
1726
+ {
1727
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsinh);
1728
+ }
1729
+
1730
+ static VALUE rb_gsl_vector_complex_arccosh(VALUE obj)
1731
+ {
1732
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccosh);
1733
+ }
1734
+
1735
+ static VALUE rb_gsl_vector_complex_arctanh(VALUE obj)
1736
+ {
1737
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arctanh);
1738
+ }
1739
+
1740
+ static VALUE rb_gsl_vector_complex_arcsech(VALUE obj)
1741
+ {
1742
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsech);
1743
+ }
1744
+
1745
+ static VALUE rb_gsl_vector_complex_arccsch(VALUE obj)
1746
+ {
1747
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccsch);
1748
+ }
1749
+
1750
+ static VALUE rb_gsl_vector_complex_arccoth(VALUE obj)
1751
+ {
1752
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccoth);
1753
+ }
1754
+
1755
+ static VALUE rb_gsl_vector_complex_concat(VALUE obj, VALUE other)
1756
+ {
1757
+ gsl_vector_complex *v = NULL, *v2 = NULL, *vnew = NULL;
1758
+ gsl_vector_complex_view vv;
1759
+ gsl_complex tmp;
1760
+ VALUE x;
1761
+ double beg, end;
1762
+ int step;
1763
+ size_t i, size2;
1764
+
1765
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1766
+
1767
+ switch(TYPE(other)) {
1768
+ case T_FIXNUM:
1769
+ case T_BIGNUM:
1770
+ case T_FLOAT:
1771
+ vnew = gsl_vector_complex_alloc(v->size + 1);
1772
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1773
+ gsl_vector_complex_memcpy(&vv.vector, v);
1774
+ gsl_vector_complex_set(vnew, v->size, rb_gsl_obj_to_gsl_complex(other, NULL));
1775
+ break;
1776
+
1777
+ case T_ARRAY:
1778
+ size2 = RARRAY_LEN(other);
1779
+ vnew = gsl_vector_complex_alloc(v->size + size2);
1780
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1781
+ gsl_vector_complex_memcpy(&vv.vector, v);
1782
+ for (i = 0; i < size2; i++) {
1783
+ x = rb_ary_entry(other, i);
1784
+ gsl_vector_complex_set(vnew, v->size + i, rb_gsl_obj_to_gsl_complex(x, NULL));
1785
+ }
1786
+ break;
1787
+
1788
+ default:
1789
+ if(rb_obj_is_kind_of(other, cgsl_complex)) {
1790
+ vnew = gsl_vector_complex_alloc(v->size + 1);
1791
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1792
+ gsl_vector_complex_memcpy(&vv.vector, v);
1793
+ gsl_vector_complex_set(vnew, v->size, rb_gsl_obj_to_gsl_complex(other, NULL));
1794
+ } else if(rb_obj_is_kind_of(other, rb_cRange)) {
1795
+ get_range_beg_en_n(other, &beg, &end, &size2, &step);
1796
+ vnew = gsl_vector_complex_alloc(v->size + size2);
1797
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1798
+ gsl_vector_complex_memcpy(&vv.vector, v);
1799
+ GSL_SET_COMPLEX(&tmp, beg, 0.0);
1800
+ for (i = 0; i < size2; i++) {
1801
+ gsl_vector_complex_set(vnew, v->size + i, tmp);
1802
+ GSL_SET_REAL(&tmp, GSL_REAL(tmp) + step);
1803
+ }
1804
+ } else if (rb_obj_is_kind_of(other, cgsl_vector_complex)) {
1805
+ Data_Get_Struct(other, gsl_vector_complex, v2);
1806
+ size2 = v2->size;
1807
+ vnew = gsl_vector_complex_alloc(v->size + size2);
1808
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1809
+ gsl_vector_complex_memcpy(&vv.vector, v);
1810
+ vv = gsl_vector_complex_subvector(vnew, v->size, size2);
1811
+ gsl_vector_complex_memcpy(&vv.vector, v2);
1812
+ } else {
1813
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array, Numeric, Range, GSL::Complex, or %s expected)",
1814
+ rb_class2name(CLASS_OF(other)), rb_class2name(cgsl_vector_complex));
1815
+ }
1816
+ break;
1817
+ }
1818
+
1819
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
1820
+ }
1821
+
1822
+ static VALUE rb_gsl_vector_complex_block(VALUE obj)
1823
+ {
1824
+ gsl_vector_complex *v = NULL;
1825
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1826
+ return Data_Wrap_Struct(cgsl_block_complex, 0, NULL, v->block);
1827
+ }
1828
+
1829
+ static VALUE rb_gsl_vector_complex_indgen_bang(int argc, VALUE *argv[], VALUE obj)
1830
+ {
1831
+ gsl_vector_complex *v = NULL;
1832
+ double start = 0.0, step = 1.0, x;
1833
+ size_t i;
1834
+ switch (argc) {
1835
+ case 0:
1836
+ break;
1837
+ case 1:
1838
+ start = NUM2DBL(argv[0]);
1839
+ break;
1840
+ case 2:
1841
+ start = NUM2DBL(argv[0]);
1842
+ step = NUM2DBL(argv[1]);
1843
+ break;
1844
+ default:
1845
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1846
+ }
1847
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1848
+ for (i = 0, x = start; i < v->size; i++, x += step) {
1849
+ gsl_vector_complex_set(v, i, gsl_complex_rect(x,0));
1850
+ }
1851
+ return obj;
1852
+ }
1853
+
1854
+ static VALUE rb_gsl_vector_complex_indgen(int argc, VALUE *argv, VALUE obj)
1855
+ {
1856
+ gsl_vector_complex *v = NULL, *vnew;
1857
+ double start = 0, step = 1, x;
1858
+ size_t i;
1859
+ switch (argc) {
1860
+ case 0:
1861
+ break;
1862
+ case 1:
1863
+ start = NUM2DBL(argv[0]);
1864
+ break;
1865
+ case 2:
1866
+ start = NUM2DBL(argv[0]);
1867
+ step = NUM2DBL(argv[1]);
1868
+ break;
1869
+ default:
1870
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1871
+ }
1872
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1873
+ vnew = gsl_vector_complex_calloc(v->size);
1874
+ for (i = 0, x = start; i < vnew->size; i++, x += step) {
1875
+ gsl_vector_complex_set(vnew, i, gsl_complex_rect(x,0));
1876
+ }
1877
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
1878
+ }
1879
+
1880
+ static VALUE rb_gsl_vector_complex_indgen_singleton(int argc, VALUE *argv, VALUE obj)
1881
+ {
1882
+ gsl_vector_complex *vnew;
1883
+ double start = 0, step = 1, x;
1884
+ size_t n, i;
1885
+ switch (argc) {
1886
+ case 1:
1887
+ n = (size_t) FIX2INT(argv[0]);
1888
+ break;
1889
+ case 2:
1890
+ n = (size_t) FIX2INT(argv[0]);
1891
+ start = NUM2DBL(argv[1]);
1892
+ break;
1893
+ case 3:
1894
+ n = (size_t) FIX2INT(argv[0]);
1895
+ start = NUM2DBL(argv[1]);
1896
+ step = NUM2DBL(argv[2]);
1897
+ break;
1898
+ default:
1899
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-3)",argc);
1900
+ }
1901
+ vnew = gsl_vector_complex_calloc(n);
1902
+ for (i = 0, x = start; i < vnew->size; i++, x += step) {
1903
+ gsl_vector_complex_set(vnew, i, gsl_complex_rect(x,0));
1904
+ }
1905
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
1906
+ }
1907
+
1908
+ static VALUE rb_gsl_vector_complex_phasor_singleton(int argc, VALUE *argv, VALUE obj)
1909
+ {
1910
+ gsl_vector_complex *vnew;
1911
+ double start, step, theta;
1912
+ size_t n, i;
1913
+ switch (argc) {
1914
+ case 1:
1915
+ n = (size_t) FIX2INT(argv[0]);
1916
+ start = 0;
1917
+ step = 2 * M_PI / n;
1918
+ break;
1919
+ case 2:
1920
+ n = (size_t) FIX2INT(argv[0]);
1921
+ start = NUM2DBL(argv[1]);
1922
+ step = 2 * M_PI / n;
1923
+ break;
1924
+ case 3:
1925
+ n = (size_t) FIX2INT(argv[0]);
1926
+ start = NUM2DBL(argv[1]);
1927
+ step = NUM2DBL(argv[2]);
1928
+ break;
1929
+ default:
1930
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-3)",argc);
1931
+ }
1932
+ vnew = gsl_vector_complex_alloc(n);
1933
+ for (i = 0, theta = start; i < vnew->size; i++, theta += step) {
1934
+ gsl_vector_complex_set(vnew, i, gsl_complex_polar(1.0,theta));
1935
+ }
1936
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
1937
+ }
1938
+
1939
+ static VALUE rb_gsl_vector_complex_zip(int argc, VALUE *argv, VALUE obj)
1940
+ {
1941
+ gsl_vector_complex *v0, **vp, *vnew;
1942
+ VALUE ary;
1943
+ size_t i, j;
1944
+ int argc2;
1945
+ VALUE *argv2;
1946
+ gsl_complex zzero = gsl_complex_rect(0, 0);
1947
+ if (VECTOR_COMPLEX_P(obj)) {
1948
+ Data_Get_Struct(obj, gsl_vector_complex, v0);
1949
+ argc2 = argc;
1950
+ argv2 = argv;
1951
+ } else {
1952
+ if (argc < 1) rb_raise(rb_eArgError, "Too few arguments.");
1953
+ Data_Get_Struct(argv[0], gsl_vector_complex, v0);
1954
+ argc2 = argc - 1;
1955
+ argv2 = argv + 1;
1956
+ }
1957
+ for (i = 0; i < argc2; i++) {
1958
+ CHECK_VECTOR_COMPLEX(argv2[i]);
1959
+ }
1960
+ vp = (gsl_vector_complex**) malloc(sizeof(gsl_vector_complex**));
1961
+ for (i = 0; i < argc2; i++) {
1962
+ Data_Get_Struct(argv2[i], gsl_vector_complex, vp[i]);
1963
+ }
1964
+ ary = rb_ary_new2(v0->size);
1965
+ for (i = 0; i < v0->size; i++) {
1966
+ vnew = gsl_vector_complex_alloc(argc2 + 1);
1967
+ gsl_vector_complex_set(vnew, 0, gsl_vector_complex_get(v0, i));
1968
+ for (j = 0; j < argc2; j++) {
1969
+ if (i < vp[j]->size) {
1970
+ gsl_vector_complex_set(vnew, j+1, gsl_vector_complex_get(vp[j], i));
1971
+ } else {
1972
+ gsl_vector_complex_set(vnew, j+1, zzero);
1973
+ }
1974
+ }
1975
+ rb_ary_store(ary, i, Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew));
1976
+ }
1977
+
1978
+ free((gsl_vector_complex**) vp);
1979
+ return ary;
1980
+ }
1981
+
1982
+ static int gsl_vector_complex_equal(const gsl_vector_complex *v1,
1983
+ const gsl_vector_complex *v2, double eps)
1984
+ {
1985
+ gsl_complex z1, z2;
1986
+ size_t i;
1987
+ if (v1->size != v2->size) return 0;
1988
+ for (i = 0; i < v1->size; i++) {
1989
+ z1 = gsl_vector_complex_get(v1, i);
1990
+ z2 = gsl_vector_complex_get(v2, i);
1991
+ if (!rbgsl_complex_equal(&z1, &z2, eps)) return 0;
1992
+ }
1993
+ return 1;
1994
+
1995
+ }
1996
+
1997
+ static VALUE rb_gsl_vector_complex_equal(int argc, VALUE *argv, VALUE obj)
1998
+ {
1999
+ gsl_vector_complex *v1, *v2;
2000
+ double eps = 1e-8;
2001
+ int ret;
2002
+ switch (argc) {
2003
+ case 1:
2004
+ eps = 1e-8;
2005
+ break;
2006
+ case 2:
2007
+ eps = NUM2DBL(argv[1]);
2008
+ break;
2009
+ default:
2010
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)\n", argc);
2011
+ }
2012
+ Data_Get_Struct(obj, gsl_vector_complex, v1);
2013
+ CHECK_VECTOR_COMPLEX(argv[0]);
2014
+ Data_Get_Struct(argv[0], gsl_vector_complex, v2);
2015
+ ret = gsl_vector_complex_equal(v1, v2, eps);
2016
+ if (ret == 1) return Qtrue;
2017
+ else return Qfalse;
2018
+ }
2019
+
2020
+ static VALUE rb_gsl_vector_complex_not_equal(int argc, VALUE *argv, VALUE obj)
2021
+ {
2022
+ VALUE ret;
2023
+ ret = rb_gsl_vector_complex_equal(argc, argv, obj);
2024
+ if (ret == Qtrue) return Qfalse;
2025
+ else return Qtrue;
2026
+ }
2027
+
2028
+ void Init_gsl_vector_complex(VALUE module)
2029
+ {
2030
+ rb_define_singleton_method(cgsl_vector_complex, "new", rb_gsl_vector_complex_new, -1);
2031
+ rb_define_singleton_method(cgsl_vector_complex, "[]", rb_gsl_vector_complex_new, -1);
2032
+ rb_define_singleton_method(cgsl_vector_complex, "alloc", rb_gsl_vector_complex_new, -1);
2033
+ rb_define_singleton_method(cgsl_vector_complex, "calloc", rb_gsl_vector_complex_calloc, 1);
2034
+
2035
+ rb_define_singleton_method(cgsl_vector_complex_col, "new",
2036
+ rb_gsl_vector_complex_row_new, -1);
2037
+
2038
+ rb_define_method(cgsl_vector_complex, "size", rb_gsl_vector_complex_size, 0);
2039
+ rb_define_alias(cgsl_vector_complex, "len", "size");
2040
+ rb_define_alias(cgsl_vector_complex, "length", "size");
2041
+ rb_define_method(cgsl_vector_complex, "stride", rb_gsl_vector_complex_stride, 0);
2042
+ rb_define_method(cgsl_vector_complex, "owner", rb_gsl_vector_complex_owner, 0);
2043
+ rb_define_method(cgsl_vector_complex, "get", rb_gsl_vector_complex_get, -1);
2044
+ rb_define_alias(cgsl_vector_complex, "[]", "get");
2045
+ rb_define_method(cgsl_vector_complex, "ptr", rb_gsl_vector_complex_ptr, 1);
2046
+
2047
+ rb_define_method(cgsl_vector_complex, "set", rb_gsl_vector_complex_set, -1);
2048
+ rb_define_alias(cgsl_vector_complex, "[]=", "set");
2049
+ rb_define_method(cgsl_vector_complex, "set_all", rb_gsl_vector_complex_set_all, -1);
2050
+
2051
+ rb_define_method(cgsl_vector_complex, "each", rb_gsl_vector_complex_each, 0);
2052
+ rb_define_method(cgsl_vector_complex, "reverse_each", rb_gsl_vector_complex_reverse_each, 0);
2053
+ rb_define_method(cgsl_vector_complex, "each_index", rb_gsl_vector_complex_each_index, 0);
2054
+ rb_define_method(cgsl_vector_complex, "reverse_each_index", rb_gsl_vector_complex_reverse_each_index, 0);
2055
+ rb_define_method(cgsl_vector_complex, "collect", rb_gsl_vector_complex_collect, 0);
2056
+ rb_define_method(cgsl_vector_complex, "collect!", rb_gsl_vector_complex_collect_bang, 0);
2057
+ rb_define_alias(cgsl_vector_complex, "map", "collect");
2058
+ rb_define_alias(cgsl_vector_complex, "map!", "collect!");
2059
+
2060
+ rb_define_method(cgsl_vector_complex, "set_zero", rb_gsl_vector_complex_set_zero, 0);
2061
+ rb_define_method(cgsl_vector_complex, "set_basis", rb_gsl_vector_complex_set_basis, 1);
2062
+
2063
+ rb_define_method(cgsl_vector_complex, "to_s", rb_gsl_vector_complex_to_s, 0);
2064
+ rb_define_method(cgsl_vector_complex, "fprintf", rb_gsl_vector_complex_fprintf, -1);
2065
+ rb_define_method(cgsl_vector_complex, "printf", rb_gsl_vector_complex_printf, -1);
2066
+ rb_define_method(cgsl_vector_complex, "print", rb_gsl_vector_complex_print, 0);
2067
+ rb_define_method(cgsl_vector_complex, "inspect", rb_gsl_vector_complex_inspect, 0);
2068
+ rb_define_method(cgsl_vector_complex, "fwrite", rb_gsl_vector_complex_fwrite, 1);
2069
+ rb_define_method(cgsl_vector_complex, "fread", rb_gsl_vector_complex_fread, 1);
2070
+ rb_define_method(cgsl_vector_complex, "fscanf", rb_gsl_vector_complex_fscanf, 1);
2071
+
2072
+ rb_define_method(cgsl_vector_complex, "real", rb_gsl_vector_complex_real, 0);
2073
+ rb_define_alias(cgsl_vector_complex, "re", "real");
2074
+ rb_define_method(cgsl_vector_complex, "imag", rb_gsl_vector_complex_imag, 0);
2075
+ rb_define_alias(cgsl_vector_complex, "im", "imag");
2076
+
2077
+ rb_define_method(cgsl_vector_complex, "set_real", rb_gsl_vector_complex_set_real, 1);
2078
+ rb_define_alias(cgsl_vector_complex, "real=", "set_real");
2079
+ rb_define_alias(cgsl_vector_complex, "re=", "set_real");
2080
+ rb_define_method(cgsl_vector_complex, "set_imag", rb_gsl_vector_complex_set_imag, 1);
2081
+ rb_define_alias(cgsl_vector_complex, "imag=", "set_imag");
2082
+ rb_define_alias(cgsl_vector_complex, "im=", "set_imag");
2083
+
2084
+ rb_define_method(cgsl_vector_complex, "conj", rb_gsl_vector_complex_conj, 0);
2085
+ rb_define_alias(cgsl_vector_complex, "conjugate", "conj");
2086
+ rb_define_method(cgsl_vector_complex, "conj!", rb_gsl_vector_complex_conj_bang, 0);
2087
+ rb_define_alias(cgsl_vector_complex, "conjugate!", "conj!");
2088
+
2089
+ rb_define_method(cgsl_vector_complex, "to_a", rb_gsl_vector_complex_to_a, 0);
2090
+ rb_define_method(cgsl_vector_complex, "to_a2", rb_gsl_vector_complex_to_a2, 0);
2091
+
2092
+ rb_define_method(cgsl_vector_complex, "subvector", rb_gsl_vector_complex_subvector, -1);
2093
+ rb_define_alias(cgsl_vector_complex, "view", "subvector");
2094
+ rb_define_method(cgsl_vector_complex, "subvector_with_stride", rb_gsl_vector_complex_subvector_with_stride, 3);
2095
+
2096
+ rb_define_singleton_method(cgsl_vector_complex, "memcpy", rb_gsl_vector_complex_memcpy, 2);
2097
+ rb_define_method(cgsl_vector_complex, "clone", rb_gsl_vector_complex_clone, 0);
2098
+ rb_define_alias(cgsl_vector_complex, "duplicate", "clone");
2099
+ rb_define_alias(cgsl_vector_complex, "dup", "clone");
2100
+ rb_define_method(cgsl_vector_complex, "reverse!", rb_gsl_vector_complex_reverse, 0);
2101
+ rb_define_method(cgsl_vector_complex, "reverse", rb_gsl_vector_complex_reverse2, 0);
2102
+ rb_define_method(cgsl_vector_complex, "swap_elements", rb_gsl_vector_complex_swap_elements, 2);
2103
+ rb_define_method(cgsl_vector_complex, "fftshift!", rb_gsl_vector_complex_fftshift_bang, 0);
2104
+ rb_define_method(cgsl_vector_complex, "fftshift", rb_gsl_vector_complex_fftshift, 0);
2105
+ rb_define_method(cgsl_vector_complex, "ifftshift!", rb_gsl_vector_complex_ifftshift_bang, 0);
2106
+ rb_define_method(cgsl_vector_complex, "ifftshift", rb_gsl_vector_complex_ifftshift, 0);
2107
+ rb_define_method(cgsl_vector_complex, "isnull", rb_gsl_vector_complex_isnull, 0);
2108
+
2109
+ rb_define_method(cgsl_vector_complex, "matrix_view", rb_gsl_vector_complex_matrix_view, -1);
2110
+ rb_define_method(cgsl_vector_complex, "matrix_view_with_tda", rb_gsl_vector_complex_matrix_view_with_tda, -1);
2111
+
2112
+ rb_define_method(cgsl_vector_complex, "trans", rb_gsl_vector_complex_trans, 0);
2113
+ rb_define_alias(cgsl_vector_complex, "transpose", "trans");
2114
+ rb_define_method(cgsl_vector_complex, "trans!", rb_gsl_vector_complex_trans2, 0);
2115
+ rb_define_alias(cgsl_vector_complex, "transpose!", "trans!");
2116
+
2117
+ /*****/
2118
+ rb_define_alias(cgsl_vector_complex, "col", "trans");
2119
+ rb_define_alias(cgsl_vector_complex, "col!", "trans!");
2120
+
2121
+ rb_define_alias(cgsl_vector_complex_col, "row", "trans");
2122
+ rb_define_alias(cgsl_vector_complex_col, "row!", "trans!");
2123
+
2124
+ /*****/
2125
+ rb_define_method(cgsl_vector_complex, "to_real", rb_gsl_vector_complex_to_real, 0);
2126
+
2127
+ rb_define_method(cgsl_vector_complex, "add", rb_gsl_vector_complex_add, 1);
2128
+ rb_define_method(cgsl_vector_complex, "sub", rb_gsl_vector_complex_sub, 1);
2129
+ rb_define_method(cgsl_vector_complex, "mul", rb_gsl_vector_complex_mul, 1);
2130
+ rb_define_method(cgsl_vector_complex, "div", rb_gsl_vector_complex_div, 1);
2131
+ rb_define_method(cgsl_vector_complex, "add!", rb_gsl_vector_complex_add_bang, 1);
2132
+ rb_define_method(cgsl_vector_complex, "sub!", rb_gsl_vector_complex_sub_bang, 1);
2133
+ rb_define_method(cgsl_vector_complex, "mul!", rb_gsl_vector_complex_mul_bang, 1);
2134
+ rb_define_method(cgsl_vector_complex, "div!", rb_gsl_vector_complex_div_bang, 1);
2135
+
2136
+ rb_define_alias(cgsl_vector_complex, "+", "add");
2137
+ rb_define_alias(cgsl_vector_complex, "add_constant", "add");
2138
+ rb_define_alias(cgsl_vector_complex, "add_constant!", "add!");
2139
+ rb_define_alias(cgsl_vector_complex, "-", "sub");
2140
+ rb_define_alias(cgsl_vector_complex, "*", "mul");
2141
+ rb_define_alias(cgsl_vector_complex, "scale", "mul");
2142
+ rb_define_alias(cgsl_vector_complex, "scale!", "mul!");
2143
+ rb_define_alias(cgsl_vector_complex, "/", "div");
2144
+
2145
+ rb_define_method(cgsl_vector_complex, "coerce", rb_gsl_vector_complex_coerce, 1);
2146
+
2147
+ /* 2.Aug.2004 */
2148
+ rb_define_singleton_method(cgsl_vector_complex, "inner_product", rb_gsl_vector_complex_inner_product, -1);
2149
+ rb_define_singleton_method(cgsl_vector_complex, "dot", rb_gsl_vector_complex_inner_product, -1);
2150
+ rb_define_method(cgsl_vector_complex, "inner_product", rb_gsl_vector_complex_inner_product, -1);
2151
+ /* rb_define_alias(cgsl_vector_complex, "dot", "inner_product");*/
2152
+
2153
+ /*****/
2154
+ rb_define_method(cgsl_vector_complex, "-@", rb_gsl_vector_complex_uminus, 0);
2155
+ rb_define_method(cgsl_vector_complex, "+@", rb_gsl_vector_complex_uplus, 0);
2156
+
2157
+ rb_define_method(cgsl_vector_complex, "abs2", rb_gsl_vector_complex_abs2, 0);
2158
+ rb_define_alias(cgsl_vector_complex, "square", "abs2");
2159
+ rb_define_method(cgsl_vector_complex, "abs", rb_gsl_vector_complex_abs, 0);
2160
+ rb_define_alias(cgsl_vector_complex, "amp", "abs");
2161
+ rb_define_alias(cgsl_vector_complex, "mag", "abs");
2162
+ rb_define_method(cgsl_vector_complex, "arg", rb_gsl_vector_complex_arg, 0);
2163
+ rb_define_alias(cgsl_vector_complex, "angle", "arg");
2164
+ rb_define_alias(cgsl_vector_complex, "phase", "arg");
2165
+ rb_define_method(cgsl_vector_complex, "logabs", rb_gsl_vector_complex_logabs, 0);
2166
+
2167
+ rb_define_method(cgsl_vector_complex, "sqrt", rb_gsl_vector_complex_sqrt, 0);
2168
+ rb_define_method(cgsl_vector_complex, "sqrt!", rb_gsl_vector_complex_sqrt_bang, 0);
2169
+ rb_define_method(cgsl_vector_complex, "exp", rb_gsl_vector_complex_exp, 0);
2170
+ rb_define_method(cgsl_vector_complex, "exp!", rb_gsl_vector_complex_exp_bang, 0);
2171
+ rb_define_method(cgsl_vector_complex, "pow", rb_gsl_vector_complex_pow, 1);
2172
+ rb_define_method(cgsl_vector_complex, "pow!", rb_gsl_vector_complex_pow_bang, 1);
2173
+ rb_define_method(cgsl_vector_complex, "log", rb_gsl_vector_complex_log, 0);
2174
+ rb_define_method(cgsl_vector_complex, "log!", rb_gsl_vector_complex_log_bang, 0);
2175
+ rb_define_method(cgsl_vector_complex, "log10", rb_gsl_vector_complex_log10, 0);
2176
+ rb_define_method(cgsl_vector_complex, "log10!", rb_gsl_vector_complex_log10_bang, 0);
2177
+ rb_define_method(cgsl_vector_complex, "log_b", rb_gsl_vector_complex_log_b, 1);
2178
+ rb_define_method(cgsl_vector_complex, "log_b!", rb_gsl_vector_complex_log_b_bang, 1);
2179
+
2180
+ rb_define_method(cgsl_vector_complex, "sum", rb_gsl_vector_complex_sum, 0);
2181
+ rb_define_method(cgsl_vector_complex, "mean", rb_gsl_vector_complex_mean, 0);
2182
+ rb_define_method(cgsl_vector_complex, "tss", rb_gsl_vector_complex_tss, 0);
2183
+ rb_define_method(cgsl_vector_complex, "tss_m", rb_gsl_vector_complex_tss_m, 1);
2184
+ rb_define_method(cgsl_vector_complex, "variance", rb_gsl_vector_complex_variance, 0);
2185
+ rb_define_method(cgsl_vector_complex, "variance_m", rb_gsl_vector_complex_variance_m, 1);
2186
+ rb_define_method(cgsl_vector_complex, "variance_fm", rb_gsl_vector_complex_variance_fm, 1);
2187
+ rb_define_method(cgsl_vector_complex, "sd", rb_gsl_vector_complex_sd, 0);
2188
+ rb_define_method(cgsl_vector_complex, "sd_m", rb_gsl_vector_complex_sd_m, 1);
2189
+ rb_define_method(cgsl_vector_complex, "sd_fm", rb_gsl_vector_complex_sd_fm, 1);
2190
+
2191
+ rb_define_method(cgsl_vector_complex, "sin", rb_gsl_vector_complex_sin, 0);
2192
+ rb_define_method(cgsl_vector_complex, "cos", rb_gsl_vector_complex_cos, 0);
2193
+ rb_define_method(cgsl_vector_complex, "tan", rb_gsl_vector_complex_tan, 0);
2194
+ rb_define_method(cgsl_vector_complex, "sec", rb_gsl_vector_complex_sec, 0);
2195
+ rb_define_method(cgsl_vector_complex, "csc", rb_gsl_vector_complex_csc, 0);
2196
+ rb_define_method(cgsl_vector_complex, "cot", rb_gsl_vector_complex_cot, 0);
2197
+
2198
+ rb_define_method(cgsl_vector_complex, "arcsin", rb_gsl_vector_complex_arcsin, 0);
2199
+ rb_define_method(cgsl_vector_complex, "arccos", rb_gsl_vector_complex_arccos, 0);
2200
+ rb_define_method(cgsl_vector_complex, "arctan", rb_gsl_vector_complex_arctan, 0);
2201
+ rb_define_method(cgsl_vector_complex, "arcsec", rb_gsl_vector_complex_arcsec, 0);
2202
+ rb_define_method(cgsl_vector_complex, "arccsc", rb_gsl_vector_complex_arccsc, 0);
2203
+ rb_define_method(cgsl_vector_complex, "arccot", rb_gsl_vector_complex_arccot, 0);
2204
+
2205
+ rb_define_method(cgsl_vector_complex, "sinh", rb_gsl_vector_complex_sinh, 0);
2206
+ rb_define_method(cgsl_vector_complex, "cosh", rb_gsl_vector_complex_cosh, 0);
2207
+ rb_define_method(cgsl_vector_complex, "tanh", rb_gsl_vector_complex_tanh, 0);
2208
+ rb_define_method(cgsl_vector_complex, "sech", rb_gsl_vector_complex_sech, 0);
2209
+ rb_define_method(cgsl_vector_complex, "csch", rb_gsl_vector_complex_csch, 0);
2210
+ rb_define_method(cgsl_vector_complex, "coth", rb_gsl_vector_complex_coth, 0);
2211
+
2212
+ rb_define_method(cgsl_vector_complex, "arcsinh", rb_gsl_vector_complex_arcsinh, 0);
2213
+ rb_define_method(cgsl_vector_complex, "arccosh", rb_gsl_vector_complex_arccosh, 0);
2214
+ rb_define_method(cgsl_vector_complex, "arctanh", rb_gsl_vector_complex_arctanh, 0);
2215
+ rb_define_method(cgsl_vector_complex, "arcsech", rb_gsl_vector_complex_arcsech, 0);
2216
+ rb_define_method(cgsl_vector_complex, "arccsch", rb_gsl_vector_complex_arccsch, 0);
2217
+ rb_define_method(cgsl_vector_complex, "arccoth", rb_gsl_vector_complex_arccoth, 0);
2218
+
2219
+ /*****/
2220
+ rb_define_method(cgsl_vector_complex, "concat", rb_gsl_vector_complex_concat, 1);
2221
+ rb_define_method(cgsl_vector_complex, "block", rb_gsl_vector_complex_block, 0);
2222
+
2223
+ rb_define_method(cgsl_vector_complex, "indgen", rb_gsl_vector_complex_indgen, -1);
2224
+ rb_define_method(cgsl_vector_complex, "indgen!", rb_gsl_vector_complex_indgen_bang, -1);
2225
+ rb_define_singleton_method(cgsl_vector_complex, "indgen", rb_gsl_vector_complex_indgen_singleton, -1);
2226
+ rb_define_singleton_method(cgsl_vector_complex, "phasor", rb_gsl_vector_complex_phasor_singleton, -1);
2227
+
2228
+ rb_define_method(cgsl_vector_complex, "zip", rb_gsl_vector_complex_zip, -1);
2229
+ rb_define_singleton_method(cgsl_vector_complex, "zip", rb_gsl_vector_complex_zip, -1);
2230
+
2231
+ rb_define_method(cgsl_vector_complex, "equal?", rb_gsl_vector_complex_equal, -1);
2232
+ rb_define_alias(cgsl_vector_complex, "==", "equal?");
2233
+ rb_define_method(cgsl_vector_complex, "not_equal?", rb_gsl_vector_complex_not_equal, -1);
2234
+ rb_define_alias(cgsl_vector_complex, "!=", "not_equal?");
2235
+ }
2236
+