romanbsd-gsl 1.11.2.2

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