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,39 @@
1
+ /*
2
+ matrix.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
+ int gsl_linalg_matmult_int(const gsl_matrix_int *A,
27
+ const gsl_matrix_int *B, gsl_matrix_int *C);
28
+
29
+ #define BASE_DOUBLE
30
+ #include "templates_on.h"
31
+ #include "matrix_source.c"
32
+ #include "templates_off.h"
33
+ #undef BASE_DOUBLE
34
+
35
+ #define BASE_INT
36
+ #include "templates_on.h"
37
+ #include "matrix_source.c"
38
+ #include "templates_off.h"
39
+ #undef BASE_INT
@@ -0,0 +1,1732 @@
1
+ /*
2
+ matrix_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
+
12
+ #include "rb_gsl_config.h"
13
+ #include "rb_gsl_array.h"
14
+ #include "rb_gsl_complex.h"
15
+
16
+ enum {
17
+ GSL_MATRIX_COMPLEX_ADD,
18
+ GSL_MATRIX_COMPLEX_SUB,
19
+ GSL_MATRIX_COMPLEX_MUL,
20
+ GSL_MATRIX_COMPLEX_DIV,
21
+ };
22
+
23
+ // From complex.c
24
+ gsl_complex rb_gsl_obj_to_gsl_complex(VALUE obj, gsl_complex *z);
25
+
26
+ // From ext/vector_source.c
27
+ void get_range_beg_en_n(VALUE range, double *beg, double *en, size_t *n, int *step);
28
+
29
+ // From ext/matrix_source.c
30
+ void parse_submatrix_args(int argc, VALUE *argv, size_t size1, size_t size2,
31
+ size_t *i, size_t *j, size_t *n1, size_t *n2);
32
+
33
+ static VALUE rb_gsl_matrix_complex_arithmetics(int flag, VALUE obj, VALUE bb)
34
+ {
35
+ gsl_matrix *m = NULL;
36
+ gsl_matrix_complex *cm = NULL, *cmb = NULL, *cmnew = NULL;
37
+ gsl_complex *c = NULL, z;
38
+ gsl_vector *v = NULL;
39
+ gsl_vector_complex *cv = NULL, *cvnew = NULL, *cvb = NULL;
40
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
41
+ switch (TYPE(bb)) {
42
+ case T_FLOAT:
43
+ case T_FIXNUM:
44
+ case T_BIGNUM:
45
+ z = gsl_complex_rect(NUM2DBL(bb), 0.0);
46
+ switch (flag) {
47
+ case GSL_MATRIX_COMPLEX_ADD:
48
+ cmnew = make_matrix_complex_clone(cm);
49
+ gsl_matrix_complex_add_constant(cmnew, z);
50
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
51
+ break;
52
+ case GSL_MATRIX_COMPLEX_SUB:
53
+ cmnew = make_matrix_complex_clone(cm);
54
+ gsl_matrix_complex_add_constant(cmnew, gsl_complex_negative(z));
55
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
56
+ break;
57
+ case GSL_MATRIX_COMPLEX_MUL:
58
+ cmnew = make_matrix_complex_clone(cm);
59
+ gsl_matrix_complex_scale(cmnew, z);
60
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
61
+ break;
62
+ case GSL_MATRIX_COMPLEX_DIV:
63
+ cmnew = make_matrix_complex_clone(cm);
64
+ gsl_matrix_complex_scale(cmnew, gsl_complex_inverse(z));
65
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
66
+ break;
67
+ default:
68
+ rb_raise(rb_eRuntimeError, "operation not defined");
69
+ break;
70
+ }
71
+ break;
72
+ default:
73
+ if (rb_obj_is_kind_of(bb, cgsl_matrix_complex)) {
74
+ Data_Get_Struct(bb, gsl_matrix_complex, cmb);
75
+ switch (flag) {
76
+ case GSL_MATRIX_COMPLEX_ADD:
77
+ cmnew = make_matrix_complex_clone(cm);
78
+ gsl_matrix_complex_add(cmnew, cmb);
79
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
80
+ break;
81
+ case GSL_MATRIX_COMPLEX_SUB:
82
+ cmnew = make_matrix_complex_clone(cm);
83
+ gsl_matrix_complex_sub(cmnew,cmb);
84
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
85
+ break;
86
+ case GSL_MATRIX_COMPLEX_MUL:
87
+ cmnew = make_matrix_complex_clone(cm);
88
+ gsl_matrix_complex_mul_elements(cmnew, cmb);
89
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
90
+ break;
91
+ case GSL_MATRIX_COMPLEX_DIV:
92
+ cmnew = make_matrix_complex_clone(cm);
93
+ gsl_matrix_complex_div_elements(cmnew, cmb);
94
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
95
+ break;
96
+ default:
97
+ rb_raise(rb_eRuntimeError, "operation not defined");
98
+ break;
99
+ }
100
+ } else if (rb_obj_is_kind_of(bb, cgsl_matrix)) {
101
+ Data_Get_Struct(bb, gsl_matrix, m);
102
+ cmb = matrix_to_complex(m);
103
+ cmnew = make_matrix_complex_clone(cm);
104
+ switch (flag) {
105
+ case GSL_MATRIX_COMPLEX_ADD:
106
+ gsl_matrix_complex_add(cmnew, cmb);
107
+ break;
108
+ case GSL_MATRIX_COMPLEX_SUB:
109
+ gsl_matrix_complex_sub(cmnew,cmb);
110
+ break;
111
+ case GSL_MATRIX_COMPLEX_MUL:
112
+ gsl_matrix_complex_mul_elements(cmnew, cmb);
113
+ break;
114
+ case GSL_MATRIX_COMPLEX_DIV:
115
+ gsl_matrix_complex_div_elements(cmnew, cmb);
116
+ break;
117
+ default:
118
+ rb_raise(rb_eRuntimeError, "operation not defined");
119
+ break;
120
+ }
121
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
122
+ } else if (rb_obj_is_kind_of(bb, cgsl_complex)) {
123
+ Data_Get_Struct(bb, gsl_complex, c);
124
+ switch (flag) {
125
+ case GSL_MATRIX_COMPLEX_ADD:
126
+ cmnew = make_matrix_complex_clone(cm);
127
+ gsl_matrix_complex_add_constant(cmnew, *c);
128
+ break;
129
+ case GSL_MATRIX_COMPLEX_SUB:
130
+ cmnew = make_matrix_complex_clone(cm);
131
+ gsl_matrix_complex_add_constant(cmnew, gsl_complex_negative(*c));
132
+ break;
133
+ case GSL_MATRIX_COMPLEX_MUL:
134
+ cmnew = make_matrix_complex_clone(cm);
135
+ gsl_matrix_complex_scale(cmnew, *c);
136
+ break;
137
+ case GSL_MATRIX_COMPLEX_DIV:
138
+ cmnew = make_matrix_complex_clone(cm);
139
+ gsl_matrix_complex_scale(cmnew, gsl_complex_inverse(*c));
140
+ break;
141
+ default:
142
+ rb_raise(rb_eRuntimeError, "operation not defined");
143
+ break;
144
+ }
145
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
146
+ } else if (rb_obj_is_kind_of(bb, cgsl_vector)) {
147
+ Data_Get_Struct(bb, gsl_vector, v);
148
+ switch (flag) {
149
+ case GSL_MATRIX_COMPLEX_MUL:
150
+ cvb = vector_to_complex(v);
151
+ cvnew = gsl_vector_complex_alloc(v->size);
152
+ if (cvnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
153
+ gsl_matrix_complex_mul_vector(cvnew, cm, cvb);
154
+ gsl_vector_complex_free(cvb);
155
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cvnew);
156
+ break;
157
+ default:
158
+ rb_raise(rb_eRuntimeError,
159
+ "operation is not defined %s and Matrix_Complex",
160
+ rb_class2name(CLASS_OF(bb)));
161
+ break;
162
+ }
163
+ } else if (rb_obj_is_kind_of(bb, cgsl_vector_complex)) {
164
+ if (!VECTOR_COMPLEX_COL_P(bb))
165
+ rb_raise(rb_eTypeError,
166
+ "Operation is not defined with %s (Vector::Complex::Col expected)",
167
+ rb_class2name(CLASS_OF(bb)));
168
+ Data_Get_Struct(bb, gsl_vector_complex, cv);
169
+ switch (flag) {
170
+ case GSL_MATRIX_COMPLEX_MUL:
171
+ cvnew = gsl_vector_complex_alloc(cv->size);
172
+ if (cvnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
173
+ gsl_matrix_complex_mul_vector(cvnew, cm, cv);
174
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, cvnew);;
175
+ default:
176
+ rb_raise(rb_eRuntimeError,
177
+ "operation is not defined %s and Matrix_Complex",
178
+ rb_class2name(CLASS_OF(bb)));
179
+ break;
180
+ }
181
+ } else {
182
+ rb_raise(rb_eTypeError, "wrong argument type %s", rb_class2name(CLASS_OF(bb)));
183
+ }
184
+ }
185
+ /* never reach here */
186
+ return Qnil;
187
+ }
188
+
189
+ static VALUE rb_gsl_matrix_complex_new(VALUE klass, VALUE s1, VALUE s2)
190
+ {
191
+ gsl_matrix_complex *m = NULL;
192
+ CHECK_FIXNUM(s1); CHECK_FIXNUM(s2);
193
+ m = gsl_matrix_complex_calloc(FIX2INT(s1), FIX2INT(s2));
194
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
195
+ return Data_Wrap_Struct(klass, 0, gsl_matrix_complex_free, m);
196
+ }
197
+
198
+ static VALUE rb_gsl_matrix_complex_eye(int argc, VALUE *argv, VALUE klass)
199
+ {
200
+ size_t n, i;
201
+ gsl_matrix_complex *m = NULL;
202
+ gsl_complex z, *p = &z;
203
+ switch (argc) {
204
+ case 1:
205
+ CHECK_FIXNUM(argv[0]);
206
+ n = FIX2INT(argv[0]);
207
+ z = gsl_complex_rect(1.0, 0.0);
208
+ break;
209
+ case 2:
210
+ CHECK_FIXNUM(argv[0]);
211
+ n = FIX2INT(argv[0]);
212
+ switch (TYPE(argv[1])) {
213
+ case T_FIXNUM:
214
+ case T_BIGNUM:
215
+ case T_FLOAT:
216
+ z = gsl_complex_rect(NUM2DBL(argv[1]), 0.0);
217
+ break;
218
+ case T_ARRAY:
219
+ // if (RARRAY(argv[1])->len < 2) rb_raise(rb_eArgError, "wrong argument");
220
+ if (RARRAY_LEN(argv[1]) < 2) rb_raise(rb_eArgError, "wrong argument");
221
+ z = gsl_complex_rect(NUM2DBL(rb_ary_entry(argv[1], 0)),
222
+ NUM2DBL(rb_ary_entry(argv[1], 1)));
223
+ break;
224
+ default:
225
+ if (rb_obj_is_kind_of(argv[1], cgsl_complex)) {
226
+ Data_Get_Struct(argv[1], gsl_complex, p);
227
+ } else {
228
+ rb_raise(rb_eTypeError,
229
+ "wrong argument type %s", rb_class2name(CLASS_OF(argv[1])));
230
+ }
231
+ break;
232
+ }
233
+ break;
234
+ case 3:
235
+ CHECK_FIXNUM(argv[0]);
236
+ n = FIX2INT(argv[0]);
237
+ Need_Float(argv[1]); Need_Float(argv[2]);
238
+ z = gsl_complex_rect(NUM2DBL(argv[1]), NUM2DBL(argv[2]));
239
+ break;
240
+ default:
241
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1, 2, or 3)", argc);
242
+ break;
243
+ }
244
+ m = gsl_matrix_complex_calloc(n, n);
245
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
246
+ for (i = 0; i < n; i++) gsl_matrix_complex_set(m, i, i, z);
247
+ return Data_Wrap_Struct(klass, 0, gsl_matrix_complex_free, m);
248
+ }
249
+
250
+ static VALUE rb_gsl_matrix_complex_identity(VALUE klass, VALUE nn)
251
+ {
252
+ size_t n, i;
253
+ gsl_matrix_complex *m = NULL;
254
+ gsl_complex z;
255
+ CHECK_FIXNUM(nn);
256
+ n = FIX2INT(nn);
257
+ m = gsl_matrix_complex_calloc(n, n);
258
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_calloc failed");
259
+ z = gsl_complex_rect(1.0, 0.0);
260
+ for (i = 0; i < n; i++) gsl_matrix_complex_set(m, i, i, z);
261
+ return Data_Wrap_Struct(klass, 0, gsl_matrix_complex_free, m);
262
+ }
263
+
264
+ static VALUE rb_gsl_matrix_complex_set_zero(VALUE obj)
265
+ {
266
+ gsl_matrix_complex *m = NULL;
267
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
268
+ gsl_matrix_complex_set_zero(m);
269
+ return obj;
270
+ }
271
+
272
+ static VALUE rb_gsl_matrix_complex_set_identity(VALUE obj)
273
+ {
274
+ gsl_matrix_complex *m = NULL;
275
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
276
+ gsl_matrix_complex_set_identity(m);
277
+ return obj;
278
+ }
279
+
280
+ static VALUE rb_gsl_matrix_complex_set_all(VALUE obj, VALUE s)
281
+ {
282
+ gsl_matrix_complex *m = NULL;
283
+ gsl_complex c, *z = NULL;
284
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
285
+ switch (TYPE(s)) {
286
+ case T_FLOAT:
287
+ case T_BIGNUM:
288
+ case T_FIXNUM:
289
+ c.dat[0] = NUM2DBL(s);
290
+ c.dat[1] = 0.0;
291
+ gsl_matrix_complex_set_all(m, c);
292
+ break;
293
+ case T_ARRAY:
294
+ c.dat[0] = NUM2DBL(rb_ary_entry(s, 0));
295
+ c.dat[1] = NUM2DBL(rb_ary_entry(s, 1));
296
+ gsl_matrix_complex_set_all(m, c);
297
+ break;
298
+ default:
299
+ if (rb_obj_is_kind_of(s, cgsl_complex)) {
300
+ Data_Get_Struct(s, gsl_complex, z);
301
+ gsl_matrix_complex_set_all(m, *z);
302
+ } else {
303
+ rb_raise(rb_eTypeError,
304
+ "wrong argument type %s", rb_class2name(CLASS_OF(s)));
305
+ }
306
+ break;
307
+ }
308
+ return obj;
309
+ }
310
+
311
+ void rb_gsl_vector_complex_set_subvector(int argc, VALUE *argv, gsl_vector_complex *v, VALUE other);
312
+ static VALUE rb_gsl_matrix_complex_set(int argc, VALUE *argv, VALUE obj)
313
+ {
314
+ gsl_matrix_complex *m = NULL, *mother;
315
+ gsl_matrix_complex_view mv;
316
+ gsl_vector_complex_view vv;
317
+ gsl_complex tmp;
318
+ VALUE other, row, row_set_argv[2];
319
+ int ii, ij, step;
320
+ size_t i, j, k, n1, n2, nother;
321
+ double beg, end;
322
+
323
+ if(argc < 1 || argc > 5) {
324
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-5)", argc);
325
+ }
326
+
327
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
328
+ other = argv[argc-1];
329
+
330
+ if(argc == 1) {
331
+ // m[] = x
332
+ gsl_matrix_complex_set_all(m, rb_gsl_obj_to_gsl_complex(other, NULL));
333
+ } else if(argc == 3 && TYPE(argv[0]) == T_FIXNUM && TYPE(argv[1]) == T_FIXNUM) {
334
+ // m[i,j] = x
335
+ ii = FIX2INT(argv[0]);
336
+ ij = FIX2INT(argv[1]);
337
+ if(ii < 0) ii += m->size1;
338
+ if(ij < 0) ij += m->size2;
339
+ gsl_matrix_complex_set(m, (size_t)ii, (size_t)ij, rb_gsl_obj_to_gsl_complex(other, NULL));
340
+ } else if(TYPE(argv[0]) == T_ARRAY) {
341
+ // m.set(row0...)
342
+ row_set_argv[0] = INT2FIX(0);
343
+ row_set_argv[1] = INT2FIX(m->size2);
344
+
345
+ for(k = 0; k < argc && k < m->size1; k++) {
346
+ vv = gsl_matrix_complex_row(m, k);
347
+ rb_gsl_vector_complex_set_subvector(2, row_set_argv, &vv.vector, argv[k]);
348
+ }
349
+ } else {
350
+ // x -> assignment to m.submatrix(i...)
351
+ parse_submatrix_args(argc-1, argv, m->size1, m->size2, &i, &j, &n1, &n2);
352
+ if(n1 == 0) n1 = 1;
353
+ if(n2 == 0) n2 = 1;
354
+ mv = gsl_matrix_complex_submatrix(m, i, j, n1, n2);
355
+ if(rb_obj_is_kind_of(other, cgsl_matrix_complex)) {
356
+ // m[...] = m_other
357
+ Data_Get_Struct(other, gsl_matrix_complex, mother);
358
+ if(n1 * n2 != mother->size1 * mother->size2) {
359
+ rb_raise(rb_eRangeError, "sizes do not match (%d x %d != %d x %d)",
360
+ (int) n1, (int) n2, (int) mother->size1, (int) mother->size2);
361
+ }
362
+ // TODO Change to gsl_matrix_memmove if/when GSL has such a function
363
+ // because gsl_matrix_memcpy does not handle overlapping regions (e.g.
364
+ // Views) well.
365
+ gsl_matrix_complex_memcpy(&mv.matrix, mother);
366
+ } else if(rb_obj_is_kind_of(other, rb_cArray)) {
367
+ row_set_argv[0] = INT2FIX(0);
368
+ row_set_argv[1] = INT2FIX(n2);
369
+
370
+ if(n1 == 1) {
371
+ // m[...] = [col0, ...] # single row
372
+ vv = gsl_matrix_complex_row(&mv.matrix, 0);
373
+ rb_gsl_vector_complex_set_subvector(2, row_set_argv, &vv.vector, other);
374
+ } else {
375
+ // m[...] = [[row0], [row1], ...] # multiple rows
376
+ if(n1 != RARRAY_LEN(other)) {
377
+ rb_raise(rb_eRangeError, "row counts do not match (%d != %d)",
378
+ (int) n1, (int) RARRAY_LEN(other));
379
+ }
380
+ for(k = 0; k < n1; k++) {
381
+ vv = gsl_matrix_complex_row(&mv.matrix, k);
382
+ row = rb_ary_entry(other, k);
383
+ rb_gsl_vector_complex_set_subvector(2, row_set_argv, &vv.vector, row);
384
+ }
385
+ }
386
+ } else if(rb_obj_is_kind_of(other, rb_cRange)) {
387
+ // m[...] = beg..end
388
+ get_range_beg_en_n(other, &beg, &end, &nother, &step);
389
+ if(n1 * n2 != nother) {
390
+ rb_raise(rb_eRangeError, "sizes do not match (%d x %d != %d)", (int) n1, (int) n2, (int) nother);
391
+ }
392
+ tmp = gsl_complex_rect(beg, 0.0);
393
+ for(k = 0; k < nother; k++) {
394
+ gsl_matrix_complex_set(&mv.matrix, k / n2, k % n2, tmp);
395
+ GSL_SET_REAL(&tmp, GSL_REAL(tmp) + step);
396
+ }
397
+ } else {
398
+ // m[...] = x
399
+ gsl_matrix_complex_set_all(&mv.matrix, rb_gsl_obj_to_gsl_complex(other, NULL));
400
+ }
401
+ }
402
+
403
+ return obj;
404
+ }
405
+
406
+ static VALUE rb_gsl_matrix_complex_set_row(int argc, VALUE *argv, VALUE obj)
407
+ {
408
+ gsl_matrix_complex *A = NULL;
409
+ size_t i, k;
410
+ gsl_complex z, *pz = &z;
411
+ if (argc < 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for >= 2)",
412
+ argc);
413
+ CHECK_FIXNUM(argv[0]);
414
+ Data_Get_Struct(obj, gsl_matrix_complex, A);
415
+ i = FIX2INT(argv[0]);
416
+ for (k = 1; k < argc; k++) {
417
+ if (k-1 >= A->size1) break;
418
+ switch (TYPE(argv[k])) {
419
+ case T_ARRAY:
420
+ z = ary2complex(argv[k]);
421
+ break;
422
+ default:
423
+ CHECK_COMPLEX(argv[k]);
424
+ Data_Get_Struct(argv[k], gsl_complex, pz);
425
+ break;
426
+ }
427
+ gsl_matrix_complex_set(A, i, k-1, z);
428
+ }
429
+ return obj;
430
+ }
431
+
432
+ static VALUE rb_gsl_matrix_complex_set_col(int argc, VALUE *argv, VALUE obj)
433
+ {
434
+ gsl_matrix_complex *A = NULL;
435
+ int j, k;
436
+ gsl_complex z, *pz = &z;
437
+ if (argc < 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for >= 2)",
438
+ argc);
439
+ CHECK_FIXNUM(argv[0]);
440
+ Data_Get_Struct(obj, gsl_matrix_complex, A);
441
+ j = FIX2INT(argv[0]);
442
+ for (k = 1; k < argc; k++) {
443
+ if (k-1 >= A->size2) break;
444
+ switch (TYPE(argv[k])) {
445
+ case T_ARRAY:
446
+ z = ary2complex(argv[k]);
447
+ break;
448
+ default:
449
+ CHECK_COMPLEX(argv[k]);
450
+ Data_Get_Struct(argv[k], gsl_complex, pz);
451
+ break;
452
+ }
453
+ gsl_matrix_complex_set(A, k-1, j, z);
454
+ }
455
+ return obj;
456
+ }
457
+
458
+ static VALUE rb_gsl_matrix_complex_submatrix(int argc, VALUE *argv, VALUE obj);
459
+ static VALUE rb_gsl_matrix_complex_get(int argc, VALUE *argv, VALUE obj)
460
+ {
461
+ gsl_matrix_complex *m = NULL;
462
+ gsl_complex *c = NULL;
463
+ VALUE retval;
464
+ int ii, ij;
465
+
466
+ if(argc == 2 && TYPE(argv[0]) == T_FIXNUM && TYPE(argv[1]) == T_FIXNUM) {
467
+ // m[i,j]
468
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
469
+ ii = FIX2INT(argv[0]);
470
+ ij = FIX2INT(argv[1]);
471
+ if(ii < 0) ii += m->size1;
472
+ if(ij < 0) ij += m->size2;
473
+ c = ALLOC(gsl_complex);
474
+ *c = gsl_matrix_complex_get(m, (size_t)ii, (size_t)ij);
475
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
476
+ } else if(argc == 1 && TYPE(argv[0]) == T_FIXNUM) {
477
+ // m[i]
478
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
479
+ ii = FIX2INT(argv[0]);
480
+ if(ii < 0) ii += m->size1 * m->size2;
481
+ c = ALLOC(gsl_complex);
482
+ *c = gsl_matrix_complex_get(m, (size_t)(ii / m->size2), (size_t)(ii % m->size2));
483
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
484
+ } else if(argc == 1 && TYPE(argv[0]) == T_ARRAY) {
485
+ // m[[i,j]], to have parity with Real Matrix types
486
+ if(RARRAY_LEN(argv[0]) == 2) {
487
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
488
+ ii = FIX2INT(RARRAY_PTR(argv[0])[0]);
489
+ ij = FIX2INT(RARRAY_PTR(argv[0])[1]);
490
+ if(ii < 0) ii += m->size1;
491
+ if(ij < 0) ij += m->size2;
492
+ c = ALLOC(gsl_complex);
493
+ *c = gsl_matrix_complex_get(m, (size_t)ii, (size_t)ij);
494
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
495
+ } else {
496
+ rb_raise(rb_eArgError, "Array index must have length 2, not %d", (int) RARRAY_LEN(argv[0]));
497
+ }
498
+ } else {
499
+ retval = rb_gsl_matrix_complex_submatrix(argc, argv, obj);
500
+ }
501
+
502
+ return retval;
503
+ }
504
+
505
+ static void rb_gsl_matrix_complex_collect_native(gsl_matrix_complex *src, gsl_matrix_complex *dst)
506
+ {
507
+ VALUE vz;
508
+ gsl_complex * zp;
509
+ size_t i, j;
510
+ for (i = 0; i < src->size1; i++) {
511
+ for (j = 0; j < src->size2; j++) {
512
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
513
+ *zp = gsl_matrix_complex_get(src, i, j);
514
+ vz = rb_yield(vz);
515
+ CHECK_COMPLEX(vz);
516
+ Data_Get_Struct(vz, gsl_complex, zp);
517
+ gsl_matrix_complex_set(dst, i, j, *zp);
518
+ }
519
+ }
520
+ }
521
+
522
+ static VALUE rb_gsl_matrix_complex_collect(VALUE obj)
523
+ {
524
+ gsl_matrix_complex *m = NULL, *mnew;
525
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
526
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
527
+ rb_gsl_matrix_complex_collect_native(m, mnew);
528
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
529
+ }
530
+
531
+ static VALUE rb_gsl_matrix_complex_collect_bang(VALUE obj)
532
+ {
533
+ gsl_matrix_complex *m = NULL;
534
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
535
+ rb_gsl_matrix_complex_collect_native(m, m);
536
+ return obj;
537
+ }
538
+
539
+ static VALUE rb_gsl_matrix_complex_to_a(VALUE obj)
540
+ {
541
+ gsl_matrix_complex *m;
542
+ gsl_complex *c;
543
+ VALUE ma, ra;
544
+ size_t i, j;
545
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
546
+ ma = rb_ary_new2(m->size1);
547
+ for(i=0; i < m->size1; i++) {
548
+ ra = rb_ary_new2(m->size2);
549
+ rb_ary_store(ma, i, ra);
550
+ for(j=0; j < m->size2; j++) {
551
+ c = ALLOC(gsl_complex);
552
+ *c = gsl_matrix_complex_get(m, i, j);
553
+ rb_ary_store(ra, j, Data_Wrap_Struct(cgsl_complex, 0, free, c));
554
+ }
555
+ }
556
+ return ma;
557
+ }
558
+
559
+ static VALUE rb_gsl_matrix_complex_ptr(VALUE obj, VALUE i, VALUE j)
560
+ {
561
+ gsl_matrix_complex *m = NULL;
562
+ gsl_complex *c = NULL;
563
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
564
+ c = gsl_matrix_complex_ptr(m, FIX2INT(i), FIX2INT(j));
565
+ return Data_Wrap_Struct(cgsl_complex, 0, NULL, c);
566
+ }
567
+
568
+ static VALUE rb_gsl_matrix_complex_printf(int argc, VALUE *argv, VALUE obj)
569
+ {
570
+ gsl_matrix_complex *h = NULL;
571
+ int status;
572
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
573
+ if (argc == 1) {
574
+ Check_Type(argv[0], T_STRING);
575
+ status = gsl_matrix_complex_fprintf(stdout, h, STR2CSTR(argv[0]));
576
+ } else {
577
+ status = gsl_matrix_complex_fprintf(stdout, h, "%g");
578
+ }
579
+ return INT2FIX(status);
580
+ }
581
+
582
+ static VALUE rb_gsl_matrix_complex_print(VALUE obj)
583
+ {
584
+ gsl_matrix_complex *h = NULL;
585
+ gsl_complex *z = NULL;
586
+ size_t i, j;
587
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
588
+ printf("[ ");
589
+ for (i = 0; i < h->size1; i++) {
590
+ if (i != 0) printf(" ");
591
+ for (j = 0; j < h->size2; j++) {
592
+ z = gsl_matrix_complex_ptr(h, i, j);
593
+ printf("[%4.3e %4.3e] ", GSL_REAL(*z), GSL_IMAG(*z));
594
+ }
595
+ if (i != h->size1 -1) printf("\n");
596
+ else printf("]\n");
597
+ }
598
+ return obj;
599
+ }
600
+
601
+ static VALUE rb_gsl_matrix_complex_to_s(int argc, VALUE *argv, VALUE obj)
602
+ {
603
+ gsl_matrix_complex *m = NULL;
604
+ char buf[64];
605
+ size_t i, j;
606
+ VALUE str;
607
+ gsl_complex z;
608
+ int max_rows = 4;
609
+ int max_cols = 4;
610
+
611
+ switch(argc){
612
+ case 2: max_cols = NUM2INT(argv[1]);
613
+ case 1: max_rows = NUM2INT(argv[0]);
614
+ case 0: break;
615
+ default:
616
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0, 1, or 2)", argc);
617
+ }
618
+
619
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
620
+ if (m->size1 == 0 && m->size2 == 0) return rb_str_new2("[ ]");
621
+ str = rb_str_new2("[ ");
622
+ for (i = 0; i < m->size1; i++) {
623
+ if (i != 0) {
624
+ rb_str_cat(str, "\n ", 3);
625
+ }
626
+ for (j = 0; j < m->size2; j++) {
627
+ z = gsl_matrix_complex_get(m, i, j);
628
+ sprintf(buf,
629
+ "%s[ %4.3e %4.3e ]", (j==0) ? "" : " ", GSL_REAL(z), GSL_IMAG(z));
630
+ rb_str_cat(str, buf, strlen(buf));
631
+ // if too many cols
632
+ if (j >= max_cols-1 && j != m->size2-1) {
633
+ rb_str_cat(str, " ...", 4);
634
+ break;
635
+ }
636
+ }
637
+ // if too many rows
638
+ if (i >= max_rows-1 && i != m->size1-1) {
639
+ rb_str_cat(str, "\n ...", 6);
640
+ break;
641
+ }
642
+ }
643
+ rb_str_cat(str, " ]", 2);
644
+ return str;
645
+ }
646
+
647
+ static VALUE rb_gsl_matrix_complex_inspect(int argc, VALUE *argv, VALUE obj)
648
+ {
649
+ VALUE str;
650
+ char buf[128];
651
+ gsl_matrix_complex *m;
652
+
653
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
654
+ sprintf(buf, "#<%s[%lu,%lu]:%#x>\n", rb_class2name(CLASS_OF(obj)), m->size1, m->size2, NUM2UINT(rb_obj_id(obj)));
655
+ str = rb_str_new2(buf);
656
+ return rb_str_concat(str, rb_gsl_matrix_complex_to_s(argc, argv, obj));
657
+ }
658
+
659
+ static VALUE rb_gsl_matrix_complex_fwrite(VALUE obj, VALUE io)
660
+ {
661
+ gsl_matrix_complex *h = NULL;
662
+ FILE *fp = NULL;
663
+ int status, flag = 0;
664
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
665
+ fp = rb_gsl_open_writefile(io, &flag);
666
+ status = gsl_matrix_complex_fwrite(fp, h);
667
+ if (flag == 1) fclose(fp);
668
+ return INT2FIX(status);
669
+ }
670
+
671
+ static VALUE rb_gsl_matrix_complex_fread(VALUE obj, VALUE io)
672
+ {
673
+ gsl_matrix_complex *h = NULL;
674
+ FILE *f = NULL;
675
+ int status, flag = 0;
676
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
677
+ f = rb_gsl_open_readfile(io, &flag);
678
+ status = gsl_matrix_complex_fread(f, h);
679
+ if (flag == 1) fclose(f);
680
+ return INT2FIX(status);
681
+ }
682
+
683
+ static VALUE rb_gsl_matrix_complex_fprintf(int argc, VALUE *argv, VALUE obj)
684
+ {
685
+ gsl_matrix_complex *h = NULL;
686
+ FILE *fp = NULL;
687
+ int status, flag = 0;
688
+ if (argc != 1 && argc != 2) {
689
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
690
+ }
691
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
692
+ fp = rb_gsl_open_writefile(argv[0], &flag);
693
+ if (argc == 2) {
694
+ Check_Type(argv[1], T_STRING);
695
+ status = gsl_matrix_complex_fprintf(fp, h, STR2CSTR(argv[1]));
696
+ } else {
697
+ status = gsl_matrix_complex_fprintf(fp, h, "%g");
698
+ }
699
+ if (flag == 1) fclose(fp);
700
+ return INT2FIX(status);
701
+ }
702
+
703
+ static VALUE rb_gsl_matrix_complex_fscanf(VALUE obj, VALUE io)
704
+ {
705
+ gsl_matrix_complex *h = NULL;
706
+ FILE *f = NULL;
707
+ int status, flag = 0;
708
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
709
+ f = rb_gsl_open_readfile(io, &flag);
710
+ status = gsl_matrix_complex_fscanf(f, h);
711
+ if (flag == 1) fclose(f);
712
+ return INT2FIX(status);
713
+ }
714
+
715
+ gsl_matrix_complex_view* gsl_matrix_complex_view_alloc()
716
+ {
717
+ gsl_matrix_complex_view *vv = NULL;
718
+ vv = ALLOC(gsl_matrix_complex_view);
719
+ if (vv == NULL) rb_raise(rb_eRuntimeError, "malloc failed");
720
+ return vv;
721
+ }
722
+
723
+ void gsl_matrix_complex_view_free(gsl_matrix_view * vv)
724
+ {
725
+ free((gsl_matrix_complex_view *) vv);
726
+ }
727
+
728
+ /* singleton */
729
+ static VALUE rb_gsl_matrix_complex_memcpy(VALUE obj, VALUE dst, VALUE src)
730
+ {
731
+ gsl_matrix_complex *m, *dest;
732
+ CHECK_MATRIX_COMPLEX(dst);
733
+ CHECK_MATRIX_COMPLEX(src);
734
+ Data_Get_Struct(dst, gsl_matrix_complex, dest);
735
+ Data_Get_Struct(src, gsl_matrix_complex, m);
736
+ gsl_matrix_complex_memcpy(dest, m);
737
+ return dst;
738
+ }
739
+
740
+ static VALUE rb_gsl_matrix_complex_clone(VALUE obj)
741
+ {
742
+ gsl_matrix_complex *m, *mnew = NULL;
743
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
744
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
745
+ if (mnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
746
+ gsl_matrix_complex_memcpy(mnew, m);
747
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
748
+ }
749
+
750
+ static VALUE rb_gsl_matrix_complex_swap_rows(VALUE obj, VALUE i, VALUE j)
751
+ {
752
+ gsl_matrix_complex *m = NULL;
753
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
754
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
755
+ gsl_matrix_complex_swap_rows(m, FIX2INT(i), FIX2INT(j));
756
+ return obj;
757
+ }
758
+
759
+ static VALUE rb_gsl_matrix_complex_swap_columns(VALUE obj, VALUE i, VALUE j)
760
+ {
761
+ gsl_matrix_complex *m = NULL;
762
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
763
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
764
+ gsl_matrix_complex_swap_columns(m, FIX2INT(i), FIX2INT(j));
765
+ return obj;
766
+ }
767
+
768
+ static VALUE rb_gsl_matrix_complex_swap_rowcol(VALUE obj, VALUE i, VALUE j)
769
+ {
770
+ gsl_matrix_complex *m = NULL;
771
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
772
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
773
+ gsl_matrix_complex_swap_rowcol(m, FIX2INT(i), FIX2INT(j));
774
+ return obj;
775
+ }
776
+
777
+ static VALUE rb_gsl_matrix_complex_transpose(VALUE obj)
778
+ {
779
+ gsl_matrix_complex *m = NULL;
780
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
781
+ gsl_matrix_complex_transpose(m);
782
+ return obj;
783
+ }
784
+
785
+ static VALUE rb_gsl_matrix_complex_isnull(VALUE obj)
786
+ {
787
+ gsl_matrix_complex *m = NULL;
788
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
789
+ if (gsl_matrix_complex_isnull(m)) return Qtrue;
790
+ else return Qfalse;
791
+ }
792
+
793
+ static VALUE rb_gsl_matrix_complex_add(VALUE obj, VALUE mmb)
794
+ {
795
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_ADD, obj, mmb);
796
+ }
797
+
798
+ static VALUE rb_gsl_matrix_complex_sub(VALUE obj, VALUE mmb)
799
+ {
800
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_SUB, obj, mmb);
801
+ }
802
+
803
+ static VALUE rb_gsl_matrix_complex_mul_elements(VALUE obj, VALUE mmb)
804
+ {
805
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_MUL, obj, mmb);
806
+ }
807
+
808
+ static VALUE rb_gsl_matrix_complex_div_elements(VALUE obj, VALUE mmb)
809
+ {
810
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_DIV, obj, mmb);
811
+ }
812
+
813
+ static VALUE rb_gsl_matrix_complex_scale(VALUE obj, VALUE s)
814
+ {
815
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_MUL, obj, s);
816
+ }
817
+
818
+ static VALUE rb_gsl_matrix_complex_scale_bang(VALUE obj, VALUE s)
819
+ {
820
+ gsl_matrix_complex *m;
821
+ gsl_complex c, *z = &c;
822
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
823
+ switch (TYPE(s)) {
824
+ case T_FIXNUM:
825
+ case T_FLOAT:
826
+ GSL_SET_REAL(z, NUM2DBL(s));
827
+ GSL_SET_IMAG(z, 0.0);
828
+ break;
829
+ default:
830
+ CHECK_COMPLEX(s);
831
+ Data_Get_Struct(s, gsl_complex, z);
832
+ break;
833
+ }
834
+ gsl_matrix_complex_scale(m, *z);
835
+ return obj;
836
+ }
837
+
838
+ static VALUE rb_gsl_matrix_complex_mul(VALUE obj, VALUE mb)
839
+ {
840
+ gsl_matrix_complex *cm = NULL, *cmb = NULL, *cmnew = NULL;
841
+ gsl_matrix *m = NULL;
842
+ gsl_vector *v = NULL;
843
+ gsl_vector_complex *vc = NULL, *vcnew = NULL;
844
+ gsl_complex a, b;
845
+ int flag = 0;
846
+ if (COMPLEX_P(mb) || TYPE(mb) == T_FIXNUM || TYPE(mb) == T_FLOAT)
847
+ return rb_gsl_matrix_complex_mul_elements(obj, mb);
848
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
849
+ if (VECTOR_P(mb)) {
850
+ Data_Get_Struct(mb, gsl_vector, v);
851
+ vc = vector_to_complex(v);
852
+ vcnew = gsl_vector_complex_calloc(vc->size);
853
+ a.dat[0] = 1.0; a.dat[1] = 0.0;
854
+ b.dat[0] = 0.0; b.dat[1] = 0.0;
855
+ gsl_blas_zgemv(CblasNoTrans, a, cm, vc, b, vcnew);
856
+ gsl_vector_complex_free(vc);
857
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vcnew);
858
+ }
859
+ if (VECTOR_COMPLEX_P(mb)) {
860
+ Data_Get_Struct(mb, gsl_vector_complex, vc);
861
+ vcnew = gsl_vector_complex_calloc(vc->size);
862
+ a.dat[0] = 1.0; a.dat[1] = 0.0;
863
+ b.dat[0] = 0.0; b.dat[1] = 0.0;
864
+ gsl_blas_zgemv(CblasNoTrans, a, cm, vc, b, vcnew);
865
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vcnew);
866
+ }
867
+ if (MATRIX_P(mb)) {
868
+ Data_Get_Struct(mb, gsl_matrix, m);
869
+ cmb = matrix_to_complex(m);
870
+ flag = 1;
871
+ } else {
872
+ CHECK_MATRIX_COMPLEX(mb);
873
+ Data_Get_Struct(mb, gsl_matrix_complex, cmb);
874
+ }
875
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
876
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
877
+ gsl_matrix_complex_mul(cmnew, cm, cmb);
878
+ if (flag == 1) gsl_matrix_complex_free(cmb);
879
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
880
+ }
881
+
882
+ static VALUE rb_gsl_matrix_complex_mul2(VALUE obj, VALUE mb)
883
+ {
884
+ gsl_matrix_complex *cm = NULL, *cmb = NULL, *cmnew = NULL;
885
+ gsl_matrix *m = NULL;
886
+ int flag = 0;
887
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
888
+ if (MATRIX_P(mb)) {
889
+ Data_Get_Struct(mb, gsl_matrix, m);
890
+ cmb = matrix_to_complex(m);
891
+ flag = 1;
892
+ } else {
893
+ CHECK_MATRIX_COMPLEX(mb);
894
+ Data_Get_Struct(mb, gsl_matrix_complex, cmb);
895
+ }
896
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
897
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
898
+ gsl_matrix_complex_mul(cmnew, cm, cmb);
899
+ gsl_matrix_complex_memcpy(cm, cmnew);
900
+ if (flag == 1) gsl_matrix_complex_free(cmb);
901
+ return obj;
902
+ }
903
+
904
+ static VALUE rb_gsl_matrix_complex_add_diagonal(VALUE obj, VALUE s)
905
+ {
906
+ gsl_matrix_complex *m = NULL;
907
+ gsl_complex c, *z = NULL;
908
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
909
+ switch (TYPE(s)) {
910
+ case T_FLOAT:
911
+ case T_BIGNUM:
912
+ case T_FIXNUM:
913
+ c.dat[0] = NUM2DBL(s);
914
+ c.dat[1] = 0.0;
915
+ gsl_matrix_complex_add_diagonal(m, c);
916
+ break;
917
+ case T_ARRAY:
918
+ c.dat[0] = NUM2DBL(rb_ary_entry(s, 0));
919
+ c.dat[1] = NUM2DBL(rb_ary_entry(s, 1));
920
+ gsl_matrix_complex_add_diagonal(m, c);
921
+ break;
922
+ default:
923
+ if (rb_obj_is_kind_of(s, cgsl_complex)) {
924
+ Data_Get_Struct(s, gsl_complex, z);
925
+ gsl_matrix_complex_add_diagonal(m, *z);
926
+ } else {
927
+ rb_raise(rb_eTypeError,
928
+ "wrong argument type %s", rb_class2name(CLASS_OF(s)));
929
+ }
930
+ break;
931
+ }
932
+ return obj;
933
+ }
934
+
935
+ static VALUE rb_gsl_matrix_complex_submatrix(int argc, VALUE *argv, VALUE obj)
936
+ {
937
+ gsl_matrix_complex *m = NULL;
938
+ gsl_matrix_complex_view *mv = NULL;
939
+ gsl_vector_complex_view *vv = NULL;
940
+ size_t i, j, n1, n2;
941
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
942
+ parse_submatrix_args(argc, argv, m->size1, m->size2, &i, &j, &n1, &n2);
943
+ if(n1 == 0) {
944
+ vv = ALLOC(gsl_vector_complex_view);
945
+ *vv = gsl_matrix_complex_subrow(m, i, j, n2);
946
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, free, vv);
947
+ }
948
+ else if(n2 == 0) {
949
+ vv = ALLOC(gsl_vector_complex_view);
950
+ *vv = gsl_matrix_complex_subcolumn(m, j, i, n1);
951
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, free, vv);
952
+ } else {
953
+ mv = ALLOC(gsl_matrix_complex_view);
954
+ *mv = gsl_matrix_complex_submatrix(m, i, j, n1, n2);
955
+ return Data_Wrap_Struct(cgsl_matrix_complex_view, 0, free, mv);
956
+ }
957
+ }
958
+
959
+ static VALUE rb_gsl_matrix_complex_row(VALUE obj, VALUE i)
960
+ {
961
+ gsl_matrix_complex *m = NULL;
962
+ gsl_vector_complex_view *vv = NULL;
963
+ CHECK_FIXNUM(i);
964
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
965
+ vv = gsl_vector_complex_view_alloc();
966
+ *vv = gsl_matrix_complex_row(m, FIX2INT(i));
967
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
968
+ }
969
+
970
+ static VALUE rb_gsl_matrix_complex_column(VALUE obj, VALUE i)
971
+ {
972
+ gsl_matrix_complex *m = NULL;
973
+ gsl_vector_complex_view *vv = NULL;
974
+ CHECK_FIXNUM(i);
975
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
976
+ vv = gsl_vector_complex_view_alloc();
977
+ *vv = gsl_matrix_complex_column(m, FIX2INT(i));
978
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, gsl_vector_complex_view_free, vv);
979
+ }
980
+
981
+ static VALUE rb_gsl_matrix_complex_diagonal(VALUE obj)
982
+ {
983
+ gsl_matrix_complex *m = NULL;
984
+ gsl_vector_complex_view *vv = NULL;
985
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
986
+ vv = gsl_vector_complex_view_alloc();
987
+ *vv = gsl_matrix_complex_diagonal(m);
988
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
989
+ }
990
+
991
+ static VALUE rb_gsl_matrix_complex_set_diagonal(VALUE obj, VALUE diag)
992
+ {
993
+ gsl_matrix_complex *m = NULL;
994
+ gsl_vector_complex *v;
995
+ size_t i;
996
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
997
+ if (VECTOR_COMPLEX_P(diag)) {
998
+ Data_Get_Struct(diag, gsl_vector_complex, v);
999
+ for (i = 0; i < m->size1; i++) gsl_matrix_complex_set(m, i, i, gsl_vector_complex_get(v, i));
1000
+ } else {
1001
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector_Complex or Array expected)",
1002
+ rb_class2name(CLASS_OF(diag)));
1003
+ }
1004
+ return obj;
1005
+ }
1006
+
1007
+ static VALUE rb_gsl_matrix_complex_subdiagonal(VALUE obj, VALUE i)
1008
+ {
1009
+ gsl_matrix_complex *m = NULL;
1010
+ gsl_vector_complex_view *vv = NULL;
1011
+ CHECK_FIXNUM(i);
1012
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1013
+ vv = gsl_vector_complex_view_alloc();
1014
+ *vv = gsl_matrix_complex_subdiagonal(m, FIX2INT(i));
1015
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
1016
+ }
1017
+
1018
+ static VALUE rb_gsl_matrix_complex_superdiagonal(VALUE obj, VALUE i)
1019
+ {
1020
+ gsl_matrix_complex *m = NULL;
1021
+ gsl_vector_complex_view *vv = NULL;
1022
+ CHECK_FIXNUM(i);
1023
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1024
+ vv = gsl_vector_complex_view_alloc();
1025
+ *vv = gsl_matrix_complex_superdiagonal(m, FIX2INT(i));
1026
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
1027
+ }
1028
+
1029
+ static VALUE rb_gsl_matrix_complex_coerce(VALUE obj, VALUE other)
1030
+ {
1031
+ gsl_matrix_complex *cm = NULL, *cmnew = NULL;
1032
+ gsl_matrix *m = NULL;
1033
+ gsl_complex z;
1034
+ VALUE vcm;
1035
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1036
+ switch (TYPE(other)) {
1037
+ case T_FLOAT:
1038
+ case T_FIXNUM:
1039
+ case T_BIGNUM:
1040
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
1041
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
1042
+ GSL_SET_REAL(&z, NUM2DBL(other));
1043
+ GSL_SET_IMAG(&z, 0.0);
1044
+ gsl_matrix_complex_set_all(cmnew, z);
1045
+ vcm = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1046
+ return rb_ary_new3(2, vcm, obj);
1047
+ break;
1048
+ default:
1049
+ if (rb_obj_is_kind_of(other, cgsl_matrix)) {
1050
+ Data_Get_Struct(other, gsl_matrix, m);
1051
+ cmnew = matrix_to_complex(m);
1052
+ vcm = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1053
+ return rb_ary_new3(2, vcm, obj);
1054
+ } else {
1055
+ rb_raise(rb_eTypeError, "cannot coerce %s to GSL::Matrix::Complex",
1056
+ rb_class2name(CLASS_OF(other)));
1057
+ }
1058
+ break;
1059
+ }
1060
+ }
1061
+
1062
+ static VALUE rb_gsl_matrix_complex_real(VALUE obj)
1063
+ {
1064
+ gsl_matrix_complex *cm = NULL;
1065
+ gsl_matrix *m = NULL;
1066
+ gsl_complex z;
1067
+ size_t i, j;
1068
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1069
+ m = gsl_matrix_alloc(cm->size1, cm->size2);
1070
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_alloc failed");
1071
+ for (i = 0; i < cm->size1; i++) {
1072
+ for (j = 0; j < cm->size2; j++) {
1073
+ z = gsl_matrix_complex_get(cm, i, j);
1074
+ gsl_matrix_set(m, i, j, GSL_REAL(z));
1075
+ }
1076
+ }
1077
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, m);
1078
+ }
1079
+
1080
+ static VALUE rb_gsl_matrix_complex_imag(VALUE obj)
1081
+ {
1082
+ gsl_matrix_complex *cm = NULL;
1083
+ gsl_matrix *m = NULL;
1084
+ gsl_complex z;
1085
+ size_t i, j;
1086
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1087
+ m = gsl_matrix_alloc(cm->size1, cm->size2);
1088
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_alloc failed");
1089
+ for (i = 0; i < cm->size1; i++) {
1090
+ for (j = 0; j < cm->size2; j++) {
1091
+ z = gsl_matrix_complex_get(cm, i, j);
1092
+ gsl_matrix_set(m, i, j, GSL_IMAG(z));
1093
+ }
1094
+ }
1095
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, m);
1096
+ }
1097
+
1098
+ static void gsl_matrix_complex_conjugate(gsl_matrix_complex *cm)
1099
+ {
1100
+ gsl_complex z;
1101
+ size_t i, j;
1102
+ for (i = 0; i < cm->size1; i++) {
1103
+ for (j = 0; j < cm->size2; j++) {
1104
+ z = gsl_matrix_complex_get(cm, i, j);
1105
+ gsl_matrix_complex_set(cm, i, j, gsl_complex_conjugate(z));
1106
+ }
1107
+ }
1108
+ }
1109
+
1110
+ static void gsl_matrix_complex_conjugate2(gsl_matrix_complex *cmnew, gsl_matrix_complex *cm)
1111
+ {
1112
+ gsl_complex z;
1113
+ size_t i, j;
1114
+ for (i = 0; i < cm->size1; i++) {
1115
+ for (j = 0; j < cm->size2; j++) {
1116
+ z = gsl_matrix_complex_get(cm, i, j);
1117
+ gsl_matrix_complex_set(cmnew, i, j, gsl_complex_conjugate(z));
1118
+ }
1119
+ }
1120
+ }
1121
+
1122
+ static VALUE rb_gsl_matrix_complex_conjugate(VALUE obj)
1123
+ {
1124
+ gsl_matrix_complex *cm = NULL;
1125
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1126
+ gsl_matrix_complex_conjugate(cm);
1127
+ return obj;
1128
+ }
1129
+
1130
+ static VALUE rb_gsl_matrix_complex_conjugate2(VALUE obj)
1131
+ {
1132
+ gsl_matrix_complex *cm = NULL, *cmnew = NULL;
1133
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1134
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
1135
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
1136
+ gsl_matrix_complex_conjugate2(cmnew, cm);
1137
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1138
+ }
1139
+
1140
+ static VALUE rb_gsl_matrix_complex_dagger(VALUE obj)
1141
+ {
1142
+ gsl_matrix_complex *cm = NULL;
1143
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1144
+ gsl_matrix_complex_conjugate(cm);
1145
+ gsl_matrix_complex_transpose(cm);
1146
+ return obj;
1147
+ }
1148
+
1149
+ static VALUE rb_gsl_matrix_complex_dagger2(VALUE obj)
1150
+ {
1151
+ gsl_matrix_complex *cm = NULL, *cmnew = NULL;
1152
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1153
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
1154
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
1155
+ gsl_matrix_complex_conjugate2(cmnew, cm);
1156
+ gsl_matrix_complex_transpose(cmnew);
1157
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1158
+ }
1159
+
1160
+ static VALUE rb_gsl_matrix_complex_trace(VALUE obj)
1161
+ {
1162
+ gsl_matrix_complex *m = NULL;
1163
+ gsl_complex *trace = NULL;
1164
+ VALUE vtrace;
1165
+ size_t i;
1166
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1167
+ vtrace = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, trace);
1168
+ trace->dat[0] = 0.0; trace->dat[1] = 0.0;
1169
+ for (i = 0; i < m->size1; i++) *trace = gsl_complex_add(*trace, gsl_matrix_complex_get(m, i, i));
1170
+ return vtrace;
1171
+ }
1172
+
1173
+ static VALUE rb_gsl_matrix_complex_each_row(VALUE obj)
1174
+ {
1175
+ gsl_matrix_complex *m = NULL;
1176
+ gsl_vector_complex_view *vv;
1177
+ size_t i;
1178
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1179
+ for (i = 0; i < m->size1; i++) {
1180
+ vv = ALLOC(gsl_vector_complex_view);
1181
+ *vv = gsl_matrix_complex_row(m, i);
1182
+ rb_yield(Data_Wrap_Struct(cgsl_vector_complex_view, 0, free, vv));
1183
+ }
1184
+ return obj;
1185
+ }
1186
+
1187
+ static VALUE rb_gsl_matrix_complex_each_col(VALUE obj)
1188
+ {
1189
+ gsl_matrix_complex *m = NULL;
1190
+ gsl_vector_complex_view *vv;
1191
+ size_t i;
1192
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1193
+ for (i = 0; i < m->size2; i++) {
1194
+ vv = ALLOC(gsl_vector_complex_view);
1195
+ *vv = gsl_matrix_complex_column(m, i);
1196
+ rb_yield(Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, free, vv));
1197
+ }
1198
+ return obj;
1199
+ }
1200
+
1201
+ static VALUE rb_gsl_matrix_complex_size1(VALUE obj)
1202
+ {
1203
+ gsl_matrix_complex *m = NULL;
1204
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1205
+ return INT2FIX(m->size1);
1206
+ }
1207
+ static VALUE rb_gsl_matrix_complex_size2(VALUE obj)
1208
+ {
1209
+ gsl_matrix_complex *m = NULL;
1210
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1211
+ return INT2FIX(m->size2);
1212
+ }
1213
+ static VALUE rb_gsl_matrix_complex_shape(VALUE obj)
1214
+ {
1215
+ gsl_matrix_complex *m = NULL;
1216
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1217
+ return rb_ary_new3(2, INT2FIX(m->size1), INT2FIX(m->size2));
1218
+ }
1219
+
1220
+ static VALUE rb_gsl_matrix_complex_uplus(VALUE obj)
1221
+ {
1222
+ return obj;
1223
+ }
1224
+
1225
+ static VALUE rb_gsl_matrix_complex_uminus(VALUE obj)
1226
+ {
1227
+ gsl_matrix_complex *m = NULL, *mnew;
1228
+ size_t i, j;
1229
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1230
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
1231
+ for (i = 0; i < m->size1; i++) {
1232
+ for (j = 0; j < m->size2; j++) {
1233
+ gsl_matrix_complex_set(mnew, i, j, gsl_complex_negative(gsl_matrix_complex_get(m, i, j)));
1234
+ }
1235
+ }
1236
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1237
+ }
1238
+
1239
+ static VALUE rb_gsl_matrix_complex_XXX(VALUE obj, double (*f)(gsl_complex))
1240
+ {
1241
+ gsl_matrix_complex *m;
1242
+ gsl_matrix *mnew;
1243
+ size_t i, j;
1244
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1245
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
1246
+ for (i = 0; i < m->size1; i++) {
1247
+ for (j = 0; j < m->size2; j++) {
1248
+ gsl_matrix_set(mnew, i, j, (*f)(gsl_matrix_complex_get(m, i, j)));
1249
+ }
1250
+ }
1251
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1252
+ }
1253
+
1254
+ static VALUE rb_gsl_matrix_complex_arg(VALUE obj)
1255
+ {
1256
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_arg);
1257
+ }
1258
+
1259
+ static VALUE rb_gsl_matrix_complex_abs(VALUE obj)
1260
+ {
1261
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_abs);
1262
+ }
1263
+
1264
+ static VALUE rb_gsl_matrix_complex_abs2(VALUE obj)
1265
+ {
1266
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_abs2);
1267
+ }
1268
+
1269
+ static VALUE rb_gsl_matrix_complex_logabs(VALUE obj)
1270
+ {
1271
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_logabs);
1272
+ }
1273
+
1274
+ static VALUE rb_gsl_matrix_complex_XXX_complex(VALUE obj,
1275
+ gsl_complex (*f)(gsl_complex))
1276
+ {
1277
+ gsl_matrix_complex *m, *mnew;
1278
+ size_t i, j;
1279
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1280
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
1281
+ for (i = 0; i < m->size1; i++) {
1282
+ for (j = 0; j < m->size2; j++) {
1283
+ gsl_matrix_complex_set(mnew, i, j, (*f)(gsl_matrix_complex_get(m, i, j)));
1284
+ }
1285
+ }
1286
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1287
+ }
1288
+
1289
+ static VALUE rb_gsl_matrix_complex_sqrt(VALUE obj)
1290
+ {
1291
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sqrt);
1292
+ }
1293
+
1294
+ static VALUE rb_gsl_matrix_complex_exp(VALUE obj)
1295
+ {
1296
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_exp);
1297
+ }
1298
+
1299
+ static VALUE rb_gsl_matrix_complex_log(VALUE obj)
1300
+ {
1301
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_log);
1302
+ }
1303
+
1304
+ static VALUE rb_gsl_matrix_complex_log10(VALUE obj)
1305
+ {
1306
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_log10);
1307
+ }
1308
+
1309
+ static VALUE rb_gsl_matrix_complex_sin(VALUE obj)
1310
+ {
1311
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sin);
1312
+ }
1313
+
1314
+ static VALUE rb_gsl_matrix_complex_cos(VALUE obj)
1315
+ {
1316
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_cos);
1317
+ }
1318
+
1319
+ static VALUE rb_gsl_matrix_complex_tan(VALUE obj)
1320
+ {
1321
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_tan);
1322
+ }
1323
+
1324
+ static VALUE rb_gsl_matrix_complex_sec(VALUE obj)
1325
+ {
1326
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sec);
1327
+ }
1328
+
1329
+ static VALUE rb_gsl_matrix_complex_csc(VALUE obj)
1330
+ {
1331
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_csc);
1332
+ }
1333
+
1334
+ static VALUE rb_gsl_matrix_complex_cot(VALUE obj)
1335
+ {
1336
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_cot);
1337
+ }
1338
+
1339
+ static VALUE rb_gsl_matrix_complex_arcsin(VALUE obj)
1340
+ {
1341
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsin);
1342
+ }
1343
+
1344
+ static VALUE rb_gsl_matrix_complex_arccos(VALUE obj)
1345
+ {
1346
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccos);
1347
+ }
1348
+
1349
+ static VALUE rb_gsl_matrix_complex_arctan(VALUE obj)
1350
+ {
1351
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arctan);
1352
+ }
1353
+
1354
+ static VALUE rb_gsl_matrix_complex_arcsec(VALUE obj)
1355
+ {
1356
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsec);
1357
+ }
1358
+
1359
+ static VALUE rb_gsl_matrix_complex_arccsc(VALUE obj)
1360
+ {
1361
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccsc);
1362
+ }
1363
+
1364
+ static VALUE rb_gsl_matrix_complex_arccot(VALUE obj)
1365
+ {
1366
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccot);
1367
+ }
1368
+
1369
+ static VALUE rb_gsl_matrix_complex_sinh(VALUE obj)
1370
+ {
1371
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sinh);
1372
+ }
1373
+
1374
+ static VALUE rb_gsl_matrix_complex_cosh(VALUE obj)
1375
+ {
1376
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_cosh);
1377
+ }
1378
+
1379
+ static VALUE rb_gsl_matrix_complex_tanh(VALUE obj)
1380
+ {
1381
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_tanh);
1382
+ }
1383
+
1384
+ static VALUE rb_gsl_matrix_complex_sech(VALUE obj)
1385
+ {
1386
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sech);
1387
+ }
1388
+
1389
+ static VALUE rb_gsl_matrix_complex_csch(VALUE obj)
1390
+ {
1391
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_csch);
1392
+ }
1393
+ static VALUE rb_gsl_matrix_complex_coth(VALUE obj)
1394
+ {
1395
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_coth);
1396
+ }
1397
+
1398
+ static VALUE rb_gsl_matrix_complex_arcsinh(VALUE obj)
1399
+ {
1400
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsinh);
1401
+ }
1402
+
1403
+ static VALUE rb_gsl_matrix_complex_arccosh(VALUE obj)
1404
+ {
1405
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccosh);
1406
+ }
1407
+
1408
+ static VALUE rb_gsl_matrix_complex_arctanh(VALUE obj)
1409
+ {
1410
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arctanh);
1411
+ }
1412
+
1413
+ static VALUE rb_gsl_matrix_complex_arcsech(VALUE obj)
1414
+ {
1415
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsech);
1416
+ }
1417
+
1418
+ static VALUE rb_gsl_matrix_complex_arccsch(VALUE obj)
1419
+ {
1420
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccsch);
1421
+ }
1422
+
1423
+ static VALUE rb_gsl_matrix_complex_arccoth(VALUE obj)
1424
+ {
1425
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccoth);
1426
+ }
1427
+
1428
+ static VALUE rb_gsl_matrix_complex_indgen_bang(int argc, VALUE *argv[], VALUE obj)
1429
+ {
1430
+ gsl_matrix_complex *m = NULL;
1431
+ double start = 0, step = 1, x;
1432
+ size_t i, j;
1433
+ switch (argc) {
1434
+ case 0:
1435
+ break;
1436
+ case 1:
1437
+ start = NUM2DBL(argv[0]);
1438
+ break;
1439
+ case 2:
1440
+ start = NUM2DBL(argv[0]);
1441
+ step = NUM2DBL(argv[1]);
1442
+ break;
1443
+ default:
1444
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1445
+ }
1446
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1447
+ x = start;
1448
+ for (i = 0; i < m->size1; i++) {
1449
+ for (j = 0; j < m->size2; j++) {
1450
+ gsl_matrix_complex_set(m, i, j, gsl_complex_rect(x, 0));
1451
+ x += step;
1452
+ }
1453
+ }
1454
+ return obj;
1455
+ }
1456
+
1457
+ static VALUE rb_gsl_matrix_complex_indgen(int argc, VALUE *argv, VALUE obj)
1458
+ {
1459
+ gsl_matrix_complex *m = NULL, *mnew;
1460
+ double start = 0, step = 1, x;
1461
+ size_t i, j;
1462
+ switch (argc) {
1463
+ case 0:
1464
+ break;
1465
+ case 1:
1466
+ start = NUM2DBL(argv[0]);
1467
+ break;
1468
+ case 2:
1469
+ start = NUM2DBL(argv[0]);
1470
+ step = NUM2DBL(argv[1]);
1471
+ break;
1472
+ default:
1473
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1474
+ }
1475
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1476
+ mnew = gsl_matrix_complex_calloc(m->size1, m->size2);
1477
+ x = start;
1478
+ for (i = 0; i < mnew->size1; i++) {
1479
+ for (j = 0; j < mnew->size2; j++) {
1480
+ gsl_matrix_complex_set(mnew, i, j, gsl_complex_rect(x, 0));
1481
+ x += step;
1482
+ }
1483
+ }
1484
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1485
+ }
1486
+
1487
+ static VALUE rb_gsl_matrix_complex_indgen_singleton(int argc, VALUE *argv, VALUE obj)
1488
+ {
1489
+ gsl_matrix_complex *mnew;
1490
+ double start = 0, step = 1, x;
1491
+ size_t n1, n2, i, j;
1492
+ switch (argc) {
1493
+ case 2:
1494
+ n1 = (size_t) NUM2INT(argv[0]);
1495
+ n2 = (size_t) NUM2INT(argv[1]);
1496
+ break;
1497
+ case 3:
1498
+ n1 = (size_t) NUM2INT(argv[0]);
1499
+ n2 = (size_t) NUM2INT(argv[1]);
1500
+ start = NUM2DBL(argv[2]);
1501
+ break;
1502
+ case 4:
1503
+ n1 = (size_t) NUM2INT(argv[0]);
1504
+ n2 = (size_t) NUM2INT(argv[1]);
1505
+ start = NUM2DBL(argv[2]);
1506
+ step = NUM2DBL(argv[3]);
1507
+ break;
1508
+ default:
1509
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-4)", argc);
1510
+ }
1511
+ mnew = gsl_matrix_complex_calloc(n1, n2);
1512
+ x = start;
1513
+ for (i = 0; i < mnew->size1; i++) {
1514
+ for (j = 0; j < mnew->size2; j++) {
1515
+ gsl_matrix_complex_set(mnew, i, j, gsl_complex_rect(x, 0));
1516
+ x += step;
1517
+ }
1518
+ }
1519
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1520
+ }
1521
+
1522
+
1523
+ static int gsl_matrix_complex_equal(const gsl_matrix_complex *m1,
1524
+ const gsl_matrix_complex *m2, double eps)
1525
+ {
1526
+ gsl_complex z1, z2;
1527
+ size_t i, j;
1528
+ if (m1->size1 != m2->size1) return 0;
1529
+ if (m1->size2 != m2->size2) return 0;
1530
+ for (i = 0; i < m1->size1; i++) {
1531
+ for (j = 0; j < m1->size2; j++) {
1532
+ z1 = gsl_matrix_complex_get(m1, i, j);
1533
+ z2 = gsl_matrix_complex_get(m2, i, j);
1534
+ if (!rbgsl_complex_equal(&z1, &z2, eps)) return 0;
1535
+ }
1536
+ }
1537
+ return 1;
1538
+ }
1539
+
1540
+ static VALUE rb_gsl_matrix_complex_equal(int argc, VALUE *argv, VALUE obj)
1541
+ {
1542
+ gsl_matrix_complex *m1, *m2;
1543
+ double eps = 1e-8;
1544
+ int ret;
1545
+ switch (argc) {
1546
+ case 1:
1547
+ eps = 1e-8;
1548
+ break;
1549
+ case 2:
1550
+ eps = NUM2DBL(argv[1]);
1551
+ break;
1552
+ default:
1553
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)\n", argc);
1554
+ }
1555
+ Data_Get_Struct(obj, gsl_matrix_complex, m1);
1556
+ CHECK_MATRIX_COMPLEX(argv[0]);
1557
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m2);
1558
+ ret = gsl_matrix_complex_equal(m1, m2, eps);
1559
+ if (ret == 1) return Qtrue;
1560
+ else return Qfalse;
1561
+ }
1562
+
1563
+ static VALUE rb_gsl_matrix_complex_not_equal(int argc, VALUE *argv, VALUE obj)
1564
+ {
1565
+ VALUE ret;
1566
+ ret = rb_gsl_matrix_complex_equal(argc, argv, obj);
1567
+ if (ret == Qtrue) return Qfalse;
1568
+ else return Qtrue;
1569
+ }
1570
+
1571
+ void Init_gsl_matrix_complex(VALUE module)
1572
+ {
1573
+ // rb_define_singleton_method(cgsl_matrix_complex, "new", rb_gsl_matrix_complex_new, 2);
1574
+ rb_define_singleton_method(cgsl_matrix_complex, "alloc", rb_gsl_matrix_complex_new, 2);
1575
+ rb_define_singleton_method(cgsl_matrix_complex, "[]", rb_gsl_matrix_complex_new, 2);
1576
+ rb_define_singleton_method(cgsl_matrix_complex, "calloc", rb_gsl_matrix_complex_new, 2);
1577
+ rb_define_singleton_method(cgsl_matrix_complex, "eye", rb_gsl_matrix_complex_eye, -1);
1578
+ rb_define_singleton_method(cgsl_matrix_complex, "diagonal", rb_gsl_matrix_complex_eye, -1);
1579
+ rb_define_singleton_method(cgsl_matrix_complex, "identity", rb_gsl_matrix_complex_identity, 1);
1580
+ rb_define_singleton_method(cgsl_matrix_complex, "unit", rb_gsl_matrix_complex_identity, 1);
1581
+ rb_define_singleton_method(cgsl_matrix_complex, "I", rb_gsl_matrix_complex_identity, 1);
1582
+
1583
+ rb_define_method(cgsl_matrix_complex, "set", rb_gsl_matrix_complex_set, -1);
1584
+ rb_define_alias(cgsl_matrix_complex, "[]=", "set");
1585
+
1586
+ rb_define_method(cgsl_matrix_complex, "set_row", rb_gsl_matrix_complex_set_row, -1);
1587
+ rb_define_method(cgsl_matrix_complex, "set_col", rb_gsl_matrix_complex_set_col, -1);
1588
+
1589
+ rb_define_method(cgsl_matrix_complex, "get", rb_gsl_matrix_complex_get, -1);
1590
+ rb_define_alias(cgsl_matrix_complex, "[]", "get");
1591
+ rb_define_method(cgsl_matrix_complex, "ptr", rb_gsl_matrix_complex_ptr, 2);
1592
+
1593
+ rb_define_method(cgsl_matrix_complex, "to_s", rb_gsl_matrix_complex_to_s, -1);
1594
+ rb_define_method(cgsl_matrix_complex, "fprintf", rb_gsl_matrix_complex_fprintf, -1);
1595
+ rb_define_method(cgsl_matrix_complex, "printf", rb_gsl_matrix_complex_printf, -1);
1596
+ rb_define_method(cgsl_matrix_complex, "print", rb_gsl_matrix_complex_print, 0);
1597
+ rb_define_method(cgsl_matrix_complex, "inspect", rb_gsl_matrix_complex_inspect, -1);
1598
+ rb_define_method(cgsl_matrix_complex, "fwrite", rb_gsl_matrix_complex_fwrite, 1);
1599
+ rb_define_method(cgsl_matrix_complex, "fread", rb_gsl_matrix_complex_fread, 1);
1600
+ rb_define_method(cgsl_matrix_complex, "fscanf", rb_gsl_matrix_complex_fscanf, 1);
1601
+
1602
+ rb_define_singleton_method(cgsl_matrix_complex, "memcpy", rb_gsl_matrix_complex_memcpy, 2);
1603
+ rb_define_method(cgsl_matrix_complex, "clone", rb_gsl_matrix_complex_clone, 0);
1604
+ rb_define_alias(cgsl_matrix_complex, "duplicate", "clone");
1605
+ rb_define_alias(cgsl_matrix_complex, "dup", "clone");
1606
+ rb_define_method(cgsl_matrix_complex, "swap_rows", rb_gsl_matrix_complex_swap_rows, 2);
1607
+ rb_define_method(cgsl_matrix_complex, "swap_columns", rb_gsl_matrix_complex_swap_columns, 2);
1608
+ rb_define_method(cgsl_matrix_complex, "swap_rowcol", rb_gsl_matrix_complex_swap_rowcol, 2);
1609
+
1610
+ rb_define_method(cgsl_matrix_complex, "transpose", rb_gsl_matrix_complex_transpose, 0);
1611
+ rb_define_method(cgsl_matrix_complex, "isnull", rb_gsl_matrix_complex_isnull, 0);
1612
+
1613
+ rb_define_method(cgsl_matrix_complex, "add", rb_gsl_matrix_complex_add, 1);
1614
+ rb_define_alias(cgsl_matrix_complex, "add_constant", "add");
1615
+ rb_define_alias(cgsl_matrix_complex, "+", "add");
1616
+ rb_define_method(cgsl_matrix_complex, "sub", rb_gsl_matrix_complex_sub, 1);
1617
+ rb_define_alias(cgsl_matrix_complex, "-", "sub");
1618
+ rb_define_method(cgsl_matrix_complex, "mul_elements", rb_gsl_matrix_complex_mul_elements, 1);
1619
+ rb_define_method(cgsl_matrix_complex, "div_elements", rb_gsl_matrix_complex_div_elements, 1);
1620
+ rb_define_alias(cgsl_matrix_complex, "/", "div_elements");
1621
+ rb_define_method(cgsl_matrix_complex, "scale", rb_gsl_matrix_complex_scale, 1);
1622
+ rb_define_method(cgsl_matrix_complex, "scale!", rb_gsl_matrix_complex_scale_bang, 1);
1623
+
1624
+ rb_define_method(cgsl_matrix_complex, "add_diagonal", rb_gsl_matrix_complex_add_diagonal, 1);
1625
+
1626
+ rb_define_method(cgsl_matrix_complex, "set_zero", rb_gsl_matrix_complex_set_zero, 0);
1627
+ rb_define_method(cgsl_matrix_complex, "set_identity", rb_gsl_matrix_complex_set_identity, 0);
1628
+ rb_define_method(cgsl_matrix_complex, "set_all", rb_gsl_matrix_complex_set_all, 1);
1629
+
1630
+ rb_define_method(cgsl_matrix_complex, "submatrix", rb_gsl_matrix_complex_submatrix, -1);
1631
+ rb_define_alias(cgsl_matrix_complex, "view", "submatrix");
1632
+ rb_define_method(cgsl_matrix_complex, "row", rb_gsl_matrix_complex_row, 1);
1633
+ /* rb_define_alias(cgsl_matrix_complex, "[]", "row");*/
1634
+ rb_define_method(cgsl_matrix_complex, "column", rb_gsl_matrix_complex_column, 1);
1635
+ rb_define_alias(cgsl_matrix_complex, "col", "column");
1636
+ rb_define_method(cgsl_matrix_complex, "diagonal", rb_gsl_matrix_complex_diagonal, 0);
1637
+ rb_define_alias(cgsl_matrix_complex, "diag", "diagonal");
1638
+ rb_define_method(cgsl_matrix_complex, "set_diagonal", rb_gsl_matrix_complex_set_diagonal, 1);
1639
+ rb_define_method(cgsl_matrix_complex, "subdiagonal", rb_gsl_matrix_complex_subdiagonal, 1);
1640
+ rb_define_method(cgsl_matrix_complex, "superdiagonal", rb_gsl_matrix_complex_superdiagonal, 1);
1641
+
1642
+ rb_define_method(cgsl_matrix_complex, "coerce", rb_gsl_matrix_complex_coerce, 1);
1643
+
1644
+ rb_define_method(cgsl_matrix_complex, "mul", rb_gsl_matrix_complex_mul, 1);
1645
+ rb_define_alias(cgsl_matrix_complex, "*", "mul");
1646
+ rb_define_method(cgsl_matrix_complex, "mul!", rb_gsl_matrix_complex_mul2, 1);
1647
+
1648
+ rb_define_method(cgsl_matrix_complex, "real", rb_gsl_matrix_complex_real, 0);
1649
+ rb_define_alias(cgsl_matrix_complex, "to_real", "real");
1650
+ rb_define_alias(cgsl_matrix_complex, "re", "real");
1651
+ rb_define_method(cgsl_matrix_complex, "imag", rb_gsl_matrix_complex_imag, 0);
1652
+ rb_define_alias(cgsl_matrix_complex, "im", "imag");
1653
+
1654
+ /* 25.June.2004 */
1655
+ rb_define_method(cgsl_matrix_complex, "conjugate!", rb_gsl_matrix_complex_conjugate, 0);
1656
+ rb_define_alias(cgsl_matrix_complex, "conj!", "conjugate!");
1657
+ rb_define_method(cgsl_matrix_complex, "conjugate", rb_gsl_matrix_complex_conjugate2, 0);
1658
+ rb_define_alias(cgsl_matrix_complex, "conj", "conjugate");
1659
+ rb_define_method(cgsl_matrix_complex, "dagger!", rb_gsl_matrix_complex_dagger, 0);
1660
+ rb_define_method(cgsl_matrix_complex, "dagger", rb_gsl_matrix_complex_dagger2, 0);
1661
+
1662
+ rb_define_method(cgsl_matrix_complex, "trace", rb_gsl_matrix_complex_trace, 0);
1663
+ rb_define_method(cgsl_matrix_complex, "each_row", rb_gsl_matrix_complex_each_row, 0);
1664
+ rb_define_method(cgsl_matrix_complex, "each_col", rb_gsl_matrix_complex_each_col, 0);
1665
+ rb_define_alias(cgsl_matrix_complex, "each_column", "each_col");
1666
+ rb_define_method(cgsl_matrix_complex, "collect", rb_gsl_matrix_complex_collect, 0);
1667
+ rb_define_method(cgsl_matrix_complex, "collect!", rb_gsl_matrix_complex_collect_bang, 0);
1668
+ rb_define_alias(cgsl_matrix_complex, "map", "collect");
1669
+ rb_define_alias(cgsl_matrix_complex, "map!", "collect!");
1670
+
1671
+ rb_define_method(cgsl_matrix_complex, "to_a", rb_gsl_matrix_complex_to_a, 0);
1672
+
1673
+ rb_define_method(cgsl_matrix_complex, "size1", rb_gsl_matrix_complex_size1, 0);
1674
+ rb_define_method(cgsl_matrix_complex, "size2", rb_gsl_matrix_complex_size2, 0);
1675
+ rb_define_method(cgsl_matrix_complex, "shape", rb_gsl_matrix_complex_shape, 0);
1676
+ rb_define_alias(cgsl_matrix_complex, "size", "shape");
1677
+
1678
+ /*****/
1679
+ rb_define_method(cgsl_matrix_complex, "-@", rb_gsl_matrix_complex_uminus, 0);
1680
+ rb_define_method(cgsl_matrix_complex, "+@", rb_gsl_matrix_complex_uplus, 0);
1681
+
1682
+ /****/
1683
+ rb_define_method(cgsl_matrix_complex, "arg", rb_gsl_matrix_complex_arg, 0);
1684
+ rb_define_alias(cgsl_matrix_complex, "angle", "arg");
1685
+ rb_define_alias(cgsl_matrix_complex, "phase", "arg");
1686
+ rb_define_method(cgsl_matrix_complex, "abs", rb_gsl_matrix_complex_abs, 0);
1687
+ rb_define_alias(cgsl_matrix_complex, "amp", "abs");
1688
+ rb_define_method(cgsl_matrix_complex, "abs2", rb_gsl_matrix_complex_abs2, 0);
1689
+ rb_define_method(cgsl_matrix_complex, "logabs", rb_gsl_matrix_complex_logabs, 0);
1690
+
1691
+ rb_define_method(cgsl_matrix_complex, "sqrt", rb_gsl_matrix_complex_sqrt, 0);
1692
+ rb_define_method(cgsl_matrix_complex, "exp", rb_gsl_matrix_complex_exp, 0);
1693
+ rb_define_method(cgsl_matrix_complex, "log", rb_gsl_matrix_complex_log, 0);
1694
+ rb_define_method(cgsl_matrix_complex, "log10", rb_gsl_matrix_complex_log10, 0);
1695
+
1696
+ rb_define_method(cgsl_matrix_complex, "sin", rb_gsl_matrix_complex_sin, 0);
1697
+ rb_define_method(cgsl_matrix_complex, "cos", rb_gsl_matrix_complex_cos, 0);
1698
+ rb_define_method(cgsl_matrix_complex, "tan", rb_gsl_matrix_complex_tan, 0);
1699
+ rb_define_method(cgsl_matrix_complex, "sec", rb_gsl_matrix_complex_sec, 0);
1700
+ rb_define_method(cgsl_matrix_complex, "csc", rb_gsl_matrix_complex_csc, 0);
1701
+ rb_define_method(cgsl_matrix_complex, "cot", rb_gsl_matrix_complex_cot, 0);
1702
+
1703
+ rb_define_method(cgsl_matrix_complex, "arcsin", rb_gsl_matrix_complex_arcsin, 0);
1704
+ rb_define_method(cgsl_matrix_complex, "arccos", rb_gsl_matrix_complex_arccos, 0);
1705
+ rb_define_method(cgsl_matrix_complex, "arctan", rb_gsl_matrix_complex_arctan, 0);
1706
+ rb_define_method(cgsl_matrix_complex, "arcsec", rb_gsl_matrix_complex_arcsec, 0);
1707
+ rb_define_method(cgsl_matrix_complex, "arccsc", rb_gsl_matrix_complex_arccsc, 0);
1708
+ rb_define_method(cgsl_matrix_complex, "arccot", rb_gsl_matrix_complex_arccot, 0);
1709
+
1710
+ rb_define_method(cgsl_matrix_complex, "sinh", rb_gsl_matrix_complex_sinh, 0);
1711
+ rb_define_method(cgsl_matrix_complex, "cosh", rb_gsl_matrix_complex_cosh, 0);
1712
+ rb_define_method(cgsl_matrix_complex, "tanh", rb_gsl_matrix_complex_tanh, 0);
1713
+ rb_define_method(cgsl_matrix_complex, "sech", rb_gsl_matrix_complex_sech, 0);
1714
+ rb_define_method(cgsl_matrix_complex, "csch", rb_gsl_matrix_complex_csch, 0);
1715
+ rb_define_method(cgsl_matrix_complex, "coth", rb_gsl_matrix_complex_coth, 0);
1716
+
1717
+ rb_define_method(cgsl_matrix_complex, "arcsinh", rb_gsl_matrix_complex_arcsinh, 0);
1718
+ rb_define_method(cgsl_matrix_complex, "arccosh", rb_gsl_matrix_complex_arccosh, 0);
1719
+ rb_define_method(cgsl_matrix_complex, "arctanh", rb_gsl_matrix_complex_arctanh, 0);
1720
+ rb_define_method(cgsl_matrix_complex, "arcsech", rb_gsl_matrix_complex_arcsech, 0);
1721
+ rb_define_method(cgsl_matrix_complex, "arccsch", rb_gsl_matrix_complex_arccsch, 0);
1722
+ rb_define_method(cgsl_matrix_complex, "arccoth", rb_gsl_matrix_complex_arccoth, 0);
1723
+
1724
+ rb_define_method(cgsl_matrix_complex, "indgen", rb_gsl_matrix_complex_indgen, -1);
1725
+ rb_define_method(cgsl_matrix_complex, "indgen!", rb_gsl_matrix_complex_indgen_bang, -1);
1726
+ rb_define_singleton_method(cgsl_matrix_complex, "indgen", rb_gsl_matrix_complex_indgen_singleton, -1);
1727
+
1728
+ rb_define_method(cgsl_matrix_complex, "equal?", rb_gsl_matrix_complex_equal, -1);
1729
+ rb_define_alias(cgsl_matrix_complex, "==", "equal?");
1730
+ rb_define_method(cgsl_matrix_complex, "not_equal?", rb_gsl_matrix_complex_not_equal, -1);
1731
+ rb_define_alias(cgsl_matrix_complex, "!=", "not_equal?");
1732
+ }