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,741 @@
1
+ /*
2
+ linalg_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 <gsl/gsl_math.h>
14
+ #include "rb_gsl_array.h"
15
+ #include "rb_gsl_common.h"
16
+ #include "rb_gsl_linalg.h"
17
+
18
+ EXTERN VALUE mgsl_linalg;
19
+ EXTERN VALUE cgsl_complex;
20
+
21
+ static VALUE cgsl_matrix_complex_LU;
22
+ #ifdef GSL_1_10_LATER
23
+ static VALUE cgsl_matrix_complex_C;
24
+ #endif
25
+
26
+ VALUE rb_gsl_linalg_complex_LU_decomp(int argc, VALUE *argv, VALUE obj)
27
+ {
28
+ gsl_matrix_complex *m = NULL;
29
+ gsl_permutation *p = NULL;
30
+ int signum, itmp;
31
+ size_t size;
32
+ VALUE obj2;
33
+
34
+ switch (TYPE(obj)) {
35
+ case T_MODULE:
36
+ case T_CLASS:
37
+ case T_OBJECT:
38
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
39
+ argc);
40
+ CHECK_MATRIX_COMPLEX(argv[0]);
41
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
42
+ itmp = 1;
43
+ break;
44
+ default:
45
+ CHECK_MATRIX_COMPLEX(obj);
46
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
47
+ itmp = 0;
48
+ }
49
+ size = m->size1;
50
+ switch (argc-itmp) {
51
+ case 0:
52
+ p = gsl_permutation_alloc(size);
53
+ gsl_linalg_complex_LU_decomp(m, p, &signum);
54
+ if (itmp == 1) RBASIC(argv[0])->klass = cgsl_matrix_complex_LU;
55
+ else RBASIC(obj)->klass = cgsl_matrix_complex_LU;
56
+ obj2 = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
57
+ return rb_ary_new3(2, obj2, INT2FIX(signum));
58
+ break;
59
+ case 1: /* when a permutation object is given */
60
+ CHECK_PERMUTATION(argv[itmp]);
61
+ Data_Get_Struct(argv[itmp], gsl_permutation, p);
62
+ gsl_linalg_complex_LU_decomp(m, p, &signum);
63
+ if (itmp == 1) RBASIC(argv[0])->klass = cgsl_matrix_complex_LU;
64
+ else RBASIC(obj)->klass = cgsl_matrix_complex_LU;
65
+ return INT2FIX(signum);
66
+ break;
67
+ default:
68
+ rb_raise(rb_eArgError, "Usage: LU_decomp!() or LU_decomp!(permutation)");
69
+ }
70
+ }
71
+
72
+ VALUE rb_gsl_linalg_complex_LU_decomp2(int argc, VALUE *argv, VALUE obj)
73
+ {
74
+ gsl_matrix_complex *m = NULL, *mnew = NULL;
75
+ gsl_permutation *p = NULL;
76
+ int signum, itmp;
77
+ size_t size;
78
+ VALUE objm, obj2;
79
+
80
+ switch (TYPE(obj)) {
81
+ case T_MODULE:
82
+ case T_CLASS:
83
+ case T_OBJECT:
84
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
85
+ argc);
86
+ CHECK_MATRIX_COMPLEX(argv[0]);
87
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
88
+ itmp = 1;
89
+ break;
90
+ default:
91
+ CHECK_MATRIX_COMPLEX(obj);
92
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
93
+ itmp = 0;
94
+ }
95
+ size = m->size1;
96
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
97
+ gsl_matrix_complex_memcpy(mnew, m);
98
+ objm = Data_Wrap_Struct(cgsl_matrix_complex_LU, 0, gsl_matrix_complex_free, mnew);
99
+ switch (argc-itmp) {
100
+ case 0:
101
+ p = gsl_permutation_alloc(size);
102
+ gsl_linalg_complex_LU_decomp(mnew, p, &signum);
103
+ obj2 = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
104
+ return rb_ary_new3(3, objm ,obj2, INT2FIX(signum));
105
+ break;
106
+ case 1: /* when a permutation object is given */
107
+ CHECK_PERMUTATION(argv[itmp]);
108
+ Data_Get_Struct(argv[itmp], gsl_permutation, p);
109
+ gsl_linalg_complex_LU_decomp(m, p, &signum);
110
+ return rb_ary_new3(3, objm , argv[itmp], INT2FIX(signum));
111
+ break;
112
+ default:
113
+ rb_raise(rb_eArgError, "Usage: LU_decomp!() or LU_decomp!(permutation)");
114
+ }
115
+ }
116
+
117
+ static VALUE rb_gsl_linalg_complex_LU_solve(int argc, VALUE *argv, VALUE obj)
118
+ {
119
+ gsl_matrix_complex *m = NULL, *mtmp = NULL;
120
+ gsl_permutation *p = NULL;
121
+ gsl_vector_complex *b = NULL, *x = NULL;
122
+ int flagm = 0, flagx = 0, itmp, signum;
123
+
124
+ switch (TYPE(obj)) {
125
+ case T_MODULE:
126
+ case T_CLASS:
127
+ case T_OBJECT:
128
+ if (argc < 2 || argc > 4)
129
+ rb_raise(rb_eArgError, "Usage: solve(m, b), solve(m, b, x), solve(lu, p, b), solve(lu, p, b, x)");
130
+
131
+ CHECK_MATRIX(argv[0]);
132
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
133
+ if (CLASS_OF(argv[0]) != cgsl_matrix_complex_LU) {
134
+ flagm = 1;
135
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
136
+ gsl_matrix_complex_memcpy(mtmp, m);
137
+ } else {
138
+ mtmp = m;
139
+ }
140
+ itmp = 1;
141
+ break;
142
+ default:
143
+ if (argc < 1 || argc > 3)
144
+ rb_raise(rb_eArgError, "Usage: LU_solve(b), LU_solve(p, b), LU_solve(b, x), solve(p, b, x)");
145
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
146
+ if (CLASS_OF(obj) != cgsl_matrix_complex_LU) {
147
+ flagm = 1;
148
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
149
+ gsl_matrix_complex_memcpy(mtmp, m);
150
+ } else {
151
+ mtmp = m;
152
+ }
153
+ itmp = 0;
154
+ }
155
+ if (flagm == 1) {
156
+ if (itmp != argc-1) rb_raise(rb_eArgError, "Usage: m.LU_solve(b)");
157
+ Data_Get_Struct(argv[itmp], gsl_vector_complex, b);
158
+ x = gsl_vector_complex_alloc(b->size);
159
+ p = gsl_permutation_alloc(b->size);
160
+ gsl_linalg_complex_LU_decomp(mtmp, p, &signum);
161
+ } else {
162
+ Data_Get_Struct(argv[itmp], gsl_permutation, p);
163
+ itmp++;
164
+ Data_Get_Struct(argv[itmp], gsl_vector_complex, b);
165
+ itmp++;
166
+ if (itmp == argc-1) {
167
+ Data_Get_Struct(argv[itmp], gsl_vector_complex, x);
168
+ flagx = 1;
169
+ } else {
170
+ x = gsl_vector_complex_alloc(m->size1);
171
+ }
172
+ }
173
+ gsl_linalg_complex_LU_solve(mtmp, p, b, x);
174
+ if (flagm == 1) {
175
+ gsl_matrix_complex_free(mtmp);
176
+ gsl_permutation_free(p);
177
+ }
178
+ if (flagx == 0) return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, x);
179
+ else return argv[argc-1];
180
+ }
181
+
182
+
183
+ static VALUE rb_gsl_linalg_complex_LU_svx(int argc, VALUE *argv, VALUE obj)
184
+ {
185
+ gsl_matrix_complex *m = NULL, *mtmp = NULL;
186
+ gsl_permutation *p = NULL;
187
+ gsl_vector_complex *x = NULL;
188
+ int flagm = 0, itmp, signum;
189
+
190
+ switch (TYPE(obj)) {
191
+ case T_MODULE:
192
+ case T_CLASS:
193
+ case T_OBJECT:
194
+ CHECK_MATRIX(argv[0]);
195
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
196
+ if (CLASS_OF(argv[0]) != cgsl_matrix_complex_LU) {
197
+ flagm = 1;
198
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
199
+ gsl_matrix_complex_memcpy(mtmp, m);
200
+ } else {
201
+ mtmp = m;
202
+ }
203
+ itmp = 1;
204
+ break;
205
+ default:
206
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
207
+ if (CLASS_OF(obj) != cgsl_matrix_complex_LU) {
208
+ flagm = 1;
209
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
210
+ gsl_matrix_complex_memcpy(mtmp, m);
211
+ } else {
212
+ mtmp = m;
213
+ }
214
+ itmp = 0;
215
+ }
216
+ if (flagm == 1) {
217
+ if (itmp != argc-1) rb_raise(rb_eArgError, "Usage: m.LU_solve(b)");
218
+ Data_Get_Struct(argv[itmp], gsl_vector_complex, x);
219
+ p = gsl_permutation_alloc(x->size);
220
+ gsl_linalg_complex_LU_decomp(mtmp, p, &signum);
221
+ } else {
222
+ Data_Get_Struct(argv[itmp], gsl_permutation, p);
223
+ itmp++;
224
+ Data_Get_Struct(argv[itmp], gsl_vector_complex, x);
225
+ itmp++;
226
+ }
227
+ gsl_linalg_complex_LU_svx(mtmp, p, x);
228
+ if (flagm == 1) {
229
+ gsl_matrix_complex_free(mtmp);
230
+ gsl_permutation_free(p);
231
+ }
232
+ return argv[argc-1];
233
+ }
234
+
235
+ static VALUE rb_gsl_linalg_complex_LU_refine(VALUE obj, VALUE vm,
236
+ VALUE lu, VALUE pp, VALUE bb,
237
+ VALUE xx)
238
+ {
239
+ gsl_matrix_complex *m = NULL, *mlu = NULL;
240
+ gsl_permutation *p = NULL;
241
+ gsl_vector_complex *b = NULL, *x = NULL, *r = NULL;
242
+ int flagb = 0;
243
+ VALUE vr;
244
+
245
+ if (CLASS_OF(obj) != cgsl_matrix_complex_LU)
246
+ rb_raise(rb_eRuntimeError, "Decompose first!");
247
+ CHECK_MATRIX_COMPLEX(vm);
248
+ CHECK_MATRIX_COMPLEX(lu);
249
+ CHECK_PERMUTATION(pp);
250
+ CHECK_VECTOR_COMPLEX(xx);
251
+ Data_Get_Struct(vm, gsl_matrix_complex, m);
252
+ Data_Get_Struct(lu, gsl_matrix_complex, mlu);
253
+ Data_Get_Struct(pp, gsl_permutation, p);
254
+ CHECK_VECTOR_COMPLEX(bb);
255
+ Data_Get_Struct(bb, gsl_vector_complex, b);
256
+ Data_Get_Struct(xx, gsl_vector_complex, x);
257
+ r = gsl_vector_complex_alloc(m->size1);
258
+ gsl_linalg_complex_LU_refine(m, mlu, p, b, x, r);
259
+ vr = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, r);
260
+ if (flagb == 1) gsl_vector_complex_free(b);
261
+ return rb_ary_new3(2, xx, vr);
262
+ }
263
+
264
+ static VALUE rb_gsl_linalg_complex_LU_invert(int argc, VALUE *argv, VALUE obj)
265
+ {
266
+ gsl_matrix_complex *m = NULL, *mtmp = NULL, *inverse = NULL;
267
+ gsl_permutation *p = NULL;
268
+ int flagm = 0, signum, itmp;
269
+ switch (TYPE(obj)) {
270
+ case T_MODULE:
271
+ case T_CLASS:
272
+ case T_OBJECT:
273
+ CHECK_MATRIX_COMPLEX(argv[0]);
274
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
275
+ if (CLASS_OF(argv[0]) != cgsl_matrix_complex_LU) {
276
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
277
+ gsl_matrix_complex_memcpy(mtmp, m);
278
+ flagm = 1;
279
+ } else {
280
+ mtmp = m;
281
+ }
282
+ itmp = 1;
283
+ break;
284
+ default:
285
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
286
+ if (CLASS_OF(obj) != cgsl_matrix_complex_LU) {
287
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
288
+ gsl_matrix_complex_memcpy(mtmp, m);
289
+ flagm = 1;
290
+ } else {
291
+ mtmp = m;
292
+ }
293
+ itmp = 0;
294
+ }
295
+
296
+ if (flagm == 1) {
297
+ p = gsl_permutation_alloc(m->size1);
298
+ gsl_linalg_complex_LU_decomp(mtmp, p, &signum);
299
+ } else {
300
+ Data_Get_Struct(argv[itmp], gsl_permutation, p);
301
+ }
302
+ inverse = gsl_matrix_complex_alloc(m->size1, m->size2);
303
+ gsl_linalg_complex_LU_invert(mtmp, p, inverse);
304
+ if (flagm == 1) {
305
+ gsl_matrix_complex_free(mtmp);
306
+ gsl_permutation_free(p);
307
+ }
308
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, inverse);
309
+ }
310
+ #ifdef GSL_1_1_1_LATER
311
+ static VALUE rb_gsl_linalg_complex_LU_det(int argc, VALUE *argv, VALUE obj)
312
+ {
313
+ gsl_matrix_complex *m = NULL, *mtmp = NULL;
314
+ gsl_permutation *p = NULL;
315
+ gsl_complex *z = NULL;
316
+ VALUE vz;
317
+ int flagm = 0, signum, itmp;
318
+ switch (TYPE(obj)) {
319
+ case T_MODULE:
320
+ case T_CLASS:
321
+ case T_OBJECT:
322
+ CHECK_MATRIX_COMPLEX(argv[0]);
323
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
324
+ if (CLASS_OF(argv[0]) != cgsl_matrix_complex_LU) {
325
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
326
+ gsl_matrix_complex_memcpy(mtmp, m);
327
+ flagm = 1;
328
+ } else {
329
+ mtmp = m;
330
+ }
331
+ itmp = 1;
332
+ break;
333
+ default:
334
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
335
+ if (CLASS_OF(obj) != cgsl_matrix_complex_LU) {
336
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
337
+ gsl_matrix_complex_memcpy(mtmp, m);
338
+ flagm = 1;
339
+ } else {
340
+ mtmp = m;
341
+ }
342
+ itmp = 0;
343
+ }
344
+ if (flagm == 1) {
345
+ p = gsl_permutation_alloc(m->size1);
346
+ gsl_linalg_complex_LU_decomp(mtmp, p, &signum);
347
+ } else {
348
+ if (itmp != argc-1) rb_raise(rb_eArgError, "signum not given");
349
+ signum = NUM2DBL(argv[itmp]);
350
+ }
351
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, z);
352
+ *z = gsl_linalg_complex_LU_det(mtmp, signum);
353
+ if (flagm == 1) {
354
+ gsl_matrix_complex_free(mtmp);
355
+ gsl_permutation_free(p);
356
+ }
357
+ return vz;
358
+ }
359
+
360
+ static VALUE rb_gsl_linalg_complex_LU_lndet(int argc, VALUE *argv, VALUE obj)
361
+ {
362
+ gsl_matrix_complex *m = NULL, *mtmp = NULL;
363
+ gsl_permutation *p = NULL;
364
+ double lndet;
365
+ int flagm = 0, signum, itmp;
366
+ switch (TYPE(obj)) {
367
+ case T_MODULE:
368
+ case T_CLASS:
369
+ case T_OBJECT:
370
+ CHECK_MATRIX_COMPLEX(argv[0]);
371
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
372
+ if (CLASS_OF(argv[0]) != cgsl_matrix_complex_LU) {
373
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
374
+ gsl_matrix_complex_memcpy(mtmp, m);
375
+ flagm = 1;
376
+ } else {
377
+ mtmp = m;
378
+ }
379
+ itmp = 1;
380
+ break;
381
+ default:
382
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
383
+ if (CLASS_OF(obj) != cgsl_matrix_complex_LU) {
384
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
385
+ gsl_matrix_complex_memcpy(mtmp, m);
386
+ flagm = 1;
387
+ } else {
388
+ mtmp = m;
389
+ }
390
+ itmp = 0;
391
+ }
392
+ if (flagm == 1) {
393
+ p = gsl_permutation_alloc(m->size1);
394
+ gsl_linalg_complex_LU_decomp(mtmp, p, &signum);
395
+ }
396
+ lndet = gsl_linalg_complex_LU_lndet(mtmp);
397
+ if (flagm == 1) {
398
+ gsl_matrix_complex_free(mtmp);
399
+ gsl_permutation_free(p);
400
+ }
401
+ return rb_float_new(lndet);
402
+ }
403
+
404
+ static VALUE rb_gsl_linalg_complex_LU_sgndet(int argc, VALUE *argv, VALUE obj)
405
+ {
406
+ gsl_matrix_complex *m = NULL, *mtmp = NULL;
407
+ gsl_permutation *p = NULL;
408
+ gsl_complex *z = NULL;
409
+ VALUE vz;
410
+ int flagm = 0, signum, itmp;
411
+ switch (TYPE(obj)) {
412
+ case T_MODULE:
413
+ case T_CLASS:
414
+ case T_OBJECT:
415
+ CHECK_MATRIX_COMPLEX(argv[0]);
416
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m);
417
+ if (CLASS_OF(argv[0]) != cgsl_matrix_complex_LU) {
418
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
419
+ gsl_matrix_complex_memcpy(mtmp, m);
420
+ flagm = 1;
421
+ } else {
422
+ mtmp = m;
423
+ }
424
+ itmp = 1;
425
+ break;
426
+ default:
427
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
428
+ if (CLASS_OF(obj) != cgsl_matrix_complex_LU) {
429
+ mtmp = gsl_matrix_complex_alloc(m->size1, m->size2);
430
+ gsl_matrix_complex_memcpy(mtmp, m);
431
+ flagm = 1;
432
+ } else {
433
+ mtmp = m;
434
+ }
435
+ itmp = 0;
436
+ }
437
+ if (flagm == 1) {
438
+ p = gsl_permutation_alloc(m->size1);
439
+ gsl_linalg_complex_LU_decomp(mtmp, p, &signum);
440
+ } else {
441
+ if (itmp != argc-1) rb_raise(rb_eArgError, "signum not given");
442
+ signum = NUM2DBL(argv[itmp]);
443
+ }
444
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, z);
445
+ *z = gsl_linalg_complex_LU_sgndet(mtmp, signum);
446
+ if (flagm == 1) {
447
+ gsl_matrix_complex_free(mtmp);
448
+ gsl_permutation_free(p);
449
+ }
450
+ return vz;
451
+ }
452
+ #endif
453
+
454
+ #ifdef GSL_1_10_LATER
455
+
456
+ static VALUE rb_gsl_linalg_cholesky_decomp(int argc, VALUE *argv, VALUE obj)
457
+ {
458
+ gsl_matrix_complex *A = NULL, *Atmp = NULL;
459
+ switch(TYPE(obj)) {
460
+ case T_MODULE: case T_CLASS: case T_OBJECT:
461
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
462
+ argc);
463
+ CHECK_MATRIX_COMPLEX(argv[0]);
464
+ Data_Get_Struct(argv[0], gsl_matrix_complex, Atmp);
465
+ break;
466
+ default:
467
+ CHECK_MATRIX_COMPLEX(obj);
468
+ Data_Get_Struct(obj, gsl_matrix_complex, Atmp);
469
+ break;
470
+ }
471
+ A = make_matrix_complex_clone(Atmp);
472
+ gsl_linalg_complex_cholesky_decomp(A);
473
+ return Data_Wrap_Struct(cgsl_matrix_complex_C, 0, gsl_matrix_complex_free, A);
474
+ }
475
+
476
+ static VALUE rb_gsl_linalg_cholesky_solve(int argc, VALUE *argv, VALUE obj)
477
+ {
478
+ gsl_matrix_complex *A = NULL, *Atmp = NULL;
479
+ gsl_vector_complex *b = NULL, *x = NULL;
480
+ int flagb = 0, flaga = 0;
481
+ VALUE vA, vb;
482
+ switch(TYPE(obj)) {
483
+ case T_MODULE: case T_CLASS: case T_OBJECT:
484
+ if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
485
+ argc);
486
+ vA = argv[0];
487
+ vb = argv[1];
488
+ break;
489
+ default:
490
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
491
+ argc);
492
+ vA = obj;
493
+ vb = argv[0];
494
+ break;
495
+ }
496
+ CHECK_MATRIX_COMPLEX(vA);
497
+ Data_Get_Struct(vA, gsl_matrix_complex, Atmp);
498
+ CHECK_VECTOR_COMPLEX(vb);
499
+ Data_Get_Struct(vb, gsl_vector_complex, b);
500
+
501
+ if (CLASS_OF(vA) == cgsl_matrix_complex_C) {
502
+ A = Atmp;
503
+ } else {
504
+ A = make_matrix_complex_clone(Atmp);
505
+ flaga = 1;
506
+ gsl_linalg_complex_cholesky_decomp(A);
507
+ }
508
+ x = gsl_vector_complex_alloc(b->size);
509
+ gsl_linalg_complex_cholesky_solve(A, b, x);
510
+ if (flaga == 1) gsl_matrix_complex_free(A);
511
+ if (flagb == 1) gsl_vector_complex_free(b);
512
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, x);
513
+ }
514
+
515
+
516
+ static VALUE rb_gsl_linalg_cholesky_svx(int argc, VALUE *argv, VALUE obj)
517
+ {
518
+ gsl_matrix_complex *A = NULL, *Atmp = NULL;
519
+ gsl_vector_complex *b = NULL;
520
+ int flaga = 0;
521
+ VALUE vA, vb;
522
+ switch(TYPE(obj)) {
523
+ case T_MODULE: case T_CLASS: case T_OBJECT:
524
+ if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
525
+ argc);
526
+ vA = argv[0];
527
+ vb = argv[1];
528
+ break;
529
+ default:
530
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
531
+ argc);
532
+ vA = obj;
533
+ vb = argv[0];
534
+ break;
535
+ }
536
+ CHECK_MATRIX_COMPLEX(vA);
537
+ Data_Get_Struct(vA, gsl_matrix_complex, Atmp);
538
+ CHECK_VECTOR_COMPLEX(vb);
539
+ Data_Get_Struct(vb, gsl_vector_complex, b);
540
+ if (CLASS_OF(vA) == cgsl_matrix_complex_C) {
541
+ A = Atmp;
542
+ } else {
543
+ A = make_matrix_complex_clone(Atmp);
544
+ flaga = 1;
545
+ gsl_linalg_complex_cholesky_decomp(A);
546
+ }
547
+ gsl_linalg_complex_cholesky_svx(A, b);
548
+ if (flaga == 1) gsl_matrix_complex_free(A);
549
+ return vb;
550
+ }
551
+
552
+
553
+ static VALUE rb_gsl_linalg_complex_householder_transform(int argc, VALUE *argv, VALUE obj)
554
+ {
555
+ gsl_vector_complex *v = NULL;
556
+ gsl_complex *z;
557
+ switch (TYPE(obj)) {
558
+ case T_MODULE: case T_CLASS: case T_OBJECT:
559
+ if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
560
+ CHECK_VECTOR_COMPLEX(argv[0]);
561
+ Data_Get_Struct(argv[0], gsl_vector_complex, v);
562
+ break;
563
+ default:
564
+ Data_Get_Struct(obj, gsl_vector_complex, v);
565
+ break;
566
+ }
567
+ z = (gsl_complex*) malloc(sizeof(gsl_complex));
568
+ *z = gsl_linalg_complex_householder_transform(v);
569
+ return Data_Wrap_Struct(cgsl_complex, 0, free, z);
570
+ }
571
+
572
+ /* singleton */
573
+ static VALUE rb_gsl_linalg_complex_householder_hm(VALUE obj, VALUE t, VALUE vv, VALUE aa)
574
+ {
575
+ gsl_vector_complex *v = NULL;
576
+ gsl_complex *tau;
577
+ gsl_matrix_complex *A = NULL;
578
+ CHECK_COMPLEX(t);
579
+ CHECK_VECTOR_COMPLEX(vv);
580
+ CHECK_MATRIX_COMPLEX(aa);
581
+ Data_Get_Struct(t, gsl_complex, tau);
582
+ Data_Get_Struct(vv, gsl_vector_complex, v);
583
+ Data_Get_Struct(aa, gsl_matrix_complex, A);
584
+ gsl_linalg_complex_householder_hm(*tau, v, A);
585
+ return aa;
586
+ }
587
+
588
+ static VALUE rb_gsl_linalg_complex_householder_mh(VALUE obj, VALUE t, VALUE vv, VALUE aa)
589
+ {
590
+ gsl_vector_complex *v = NULL;
591
+ gsl_complex *tau;
592
+ gsl_matrix_complex *A = NULL;
593
+ CHECK_COMPLEX(t);
594
+ CHECK_VECTOR_COMPLEX(vv);
595
+ CHECK_MATRIX_COMPLEX(aa);
596
+ Data_Get_Struct(t, gsl_complex, tau);
597
+ Data_Get_Struct(vv, gsl_vector_complex, v);
598
+ Data_Get_Struct(aa, gsl_matrix_complex, A);
599
+ gsl_linalg_complex_householder_hm(*tau, v, A);
600
+ return aa;
601
+ }
602
+
603
+ static VALUE rb_gsl_linalg_complex_householder_hv(VALUE obj, VALUE t, VALUE vv, VALUE ww)
604
+ {
605
+ gsl_vector_complex *v = NULL, *w = NULL;
606
+ gsl_complex *tau;
607
+ CHECK_COMPLEX(t);
608
+ CHECK_VECTOR_COMPLEX(vv);
609
+ CHECK_VECTOR_COMPLEX(ww);
610
+ Data_Get_Struct(t, gsl_complex, tau);
611
+ Data_Get_Struct(vv, gsl_vector_complex, v);
612
+ Data_Get_Struct(ww, gsl_vector_complex, w);
613
+ gsl_linalg_complex_householder_hv(*tau, v, w);
614
+ return ww;
615
+ }
616
+ #endif
617
+
618
+ void Init_gsl_linalg_complex(VALUE module)
619
+ {
620
+ VALUE mgsl_linalg_complex;
621
+ VALUE mgsl_linalg_complex_LU;
622
+
623
+ mgsl_linalg_complex = rb_define_module_under(module, "Complex");
624
+ mgsl_linalg_complex_LU = rb_define_module_under(mgsl_linalg_complex, "LU");
625
+
626
+ cgsl_matrix_complex_LU = rb_define_class_under(mgsl_linalg_complex_LU,
627
+ "LUMatrix", cgsl_matrix_complex);
628
+
629
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_decomp!",
630
+ rb_gsl_linalg_complex_LU_decomp, -1);
631
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "decomp!",
632
+ rb_gsl_linalg_complex_LU_decomp, -1);
633
+ rb_define_method(cgsl_matrix_complex, "LU_decomp!",
634
+ rb_gsl_linalg_complex_LU_decomp, -1);
635
+ rb_define_alias(cgsl_matrix_complex, "decomp!", "LU_decomp!");
636
+
637
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_decomp",
638
+ rb_gsl_linalg_complex_LU_decomp2, -1);
639
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "decomp",
640
+ rb_gsl_linalg_complex_LU_decomp2, -1);
641
+ rb_define_method(cgsl_matrix_complex, "LU_decomp",
642
+ rb_gsl_linalg_complex_LU_decomp2, -1);
643
+ rb_define_alias(cgsl_matrix_complex, "decomp", "LU_decomp");
644
+
645
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_solve",
646
+ rb_gsl_linalg_complex_LU_solve, -1);
647
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "solve",
648
+ rb_gsl_linalg_complex_LU_solve, -1);
649
+ rb_define_method(cgsl_matrix_complex, "LU_solve",
650
+ rb_gsl_linalg_complex_LU_solve, -1);
651
+ rb_define_method(cgsl_matrix_complex_LU, "solve",
652
+ rb_gsl_linalg_complex_LU_solve, -1);
653
+
654
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_svx",
655
+ rb_gsl_linalg_complex_LU_svx, -1);
656
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "svx",
657
+ rb_gsl_linalg_complex_LU_svx, -1);
658
+ rb_define_method(cgsl_matrix_complex, "LU_svx",
659
+ rb_gsl_linalg_complex_LU_svx, -1);
660
+ rb_define_method(cgsl_matrix_complex_LU, "svx",
661
+ rb_gsl_linalg_complex_LU_svx, -1);
662
+
663
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_refine",
664
+ rb_gsl_linalg_complex_LU_refine, 5);
665
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "refine",
666
+ rb_gsl_linalg_complex_LU_refine, 5);
667
+
668
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_invert",
669
+ rb_gsl_linalg_complex_LU_invert, -1);
670
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "invert",
671
+ rb_gsl_linalg_complex_LU_invert, -1);
672
+ rb_define_method(cgsl_matrix_complex, "LU_invert",
673
+ rb_gsl_linalg_complex_LU_invert, -1);
674
+ rb_define_alias(cgsl_matrix_complex, "invert", "LU_invert");
675
+ rb_define_alias(cgsl_matrix_complex, "inv", "LU_invert");
676
+ rb_define_method(cgsl_matrix_complex_LU, "invert",
677
+ rb_gsl_linalg_complex_LU_invert, -1);
678
+
679
+ #ifdef GSL_1_1_1_LATER
680
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_det",
681
+ rb_gsl_linalg_complex_LU_det, -1);
682
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "det",
683
+ rb_gsl_linalg_complex_LU_det, -1);
684
+ rb_define_method(cgsl_matrix_complex, "LU_det", rb_gsl_linalg_complex_LU_det, -1);
685
+ rb_define_alias(cgsl_matrix_complex, "det", "LU_det");
686
+ rb_define_method(cgsl_matrix_complex_LU, "det", rb_gsl_linalg_complex_LU_det, -1);
687
+
688
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_lndet",
689
+ rb_gsl_linalg_complex_LU_lndet, -1);
690
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "lndet",
691
+ rb_gsl_linalg_complex_LU_lndet, -1);
692
+ rb_define_method(cgsl_matrix_complex, "LU_lndet", rb_gsl_linalg_complex_LU_lndet, -1);
693
+ rb_define_alias(cgsl_matrix_complex, "lndet", "LU_lndet");
694
+ rb_define_method(cgsl_matrix_complex_LU, "LU_lndet", rb_gsl_linalg_complex_LU_lndet, -1);
695
+
696
+ rb_define_singleton_method(mgsl_linalg_complex, "LU_sgndet",
697
+ rb_gsl_linalg_complex_LU_sgndet, -1);
698
+ rb_define_singleton_method(mgsl_linalg_complex_LU, "sgndet",
699
+ rb_gsl_linalg_complex_LU_sgndet, -1);
700
+ rb_define_method(cgsl_matrix_complex, "LU_sgndet", rb_gsl_linalg_complex_LU_sgndet, -1);
701
+ rb_define_alias(cgsl_matrix_complex, "sgndet", "LU_sgndet");
702
+ rb_define_method(cgsl_matrix_complex_LU, "LU_sgndet", rb_gsl_linalg_complex_LU_sgndet, -1);
703
+ #endif
704
+
705
+ #ifdef GSL_1_10_LATER
706
+ VALUE mgsl_linalg_complex_chol;
707
+ mgsl_linalg_complex_chol = rb_define_module_under(mgsl_linalg_complex, "Cholesky");
708
+ cgsl_matrix_complex_C = rb_define_class_under(mgsl_linalg_complex_chol, "CholeskyMatrix", cgsl_matrix_complex);
709
+ rb_define_singleton_method(mgsl_linalg_complex_chol, "decomp", rb_gsl_linalg_cholesky_decomp, -1);
710
+ rb_define_method(cgsl_matrix_complex, "cholesky_decomp", rb_gsl_linalg_cholesky_decomp, -1);
711
+ rb_define_singleton_method(mgsl_linalg_complex_chol, "solve", rb_gsl_linalg_cholesky_solve, -1);
712
+ rb_define_method(cgsl_matrix_complex, "cholesky_solve", rb_gsl_linalg_cholesky_solve, -1);
713
+ rb_define_method(cgsl_matrix_complex_C, "solve", rb_gsl_linalg_cholesky_solve, -1);
714
+ rb_define_singleton_method(mgsl_linalg_complex_chol, "svx", rb_gsl_linalg_cholesky_svx, -1);
715
+ rb_define_method(cgsl_matrix_complex, "cholesky_svx", rb_gsl_linalg_cholesky_svx, -1);
716
+ rb_define_method(cgsl_matrix_complex_C, "svx", rb_gsl_linalg_cholesky_svx, -1);
717
+
718
+ VALUE mgsl_linalg_complex_Householder = rb_define_module_under(mgsl_linalg_complex, "Householder");
719
+ rb_define_singleton_method(mgsl_linalg_complex, "householder_transform",
720
+ rb_gsl_linalg_complex_householder_transform, -1);
721
+ rb_define_singleton_method(mgsl_linalg_complex_Householder, "transform",
722
+ rb_gsl_linalg_complex_householder_transform, -1);
723
+ rb_define_method(cgsl_vector_complex, "householder_transform",
724
+ rb_gsl_linalg_complex_householder_transform, -1);
725
+
726
+ rb_define_singleton_method(mgsl_linalg_complex, "householder_hm",
727
+ rb_gsl_linalg_complex_householder_hm, 3);
728
+ rb_define_singleton_method(mgsl_linalg_complex_Householder, "hm",
729
+ rb_gsl_linalg_complex_householder_hm, 3);
730
+
731
+ rb_define_singleton_method(mgsl_linalg_complex, "householder_mh",
732
+ rb_gsl_linalg_complex_householder_mh, 3);
733
+ rb_define_singleton_method(mgsl_linalg_complex_Householder, "mh",
734
+ rb_gsl_linalg_complex_householder_mh, 3);
735
+
736
+ rb_define_singleton_method(mgsl_linalg_complex, "householder_hv",
737
+ rb_gsl_linalg_complex_householder_hv, 3);
738
+ rb_define_singleton_method(mgsl_linalg_complex_Householder, "hv",
739
+ rb_gsl_linalg_complex_householder_hv, 3);
740
+ #endif
741
+ }