rb-gsl 1.15.3.1 → 1.15.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +2 -2
  3. data/ChangeLog +8 -0
  4. data/Rakefile +39 -96
  5. data/VERSION +1 -1
  6. data/ext/array.c +2 -2
  7. data/ext/block_source.c +1 -1
  8. data/ext/dirac.c +1 -1
  9. data/ext/eigen.c +13 -13
  10. data/ext/extconf.rb +17 -11
  11. data/ext/function.c +5 -5
  12. data/ext/gsl_narray.c +6 -6
  13. data/ext/histogram.c +7 -6
  14. data/ext/histogram2d.c +4 -4
  15. data/ext/interp.c +1 -1
  16. data/ext/linalg.c +13 -11
  17. data/ext/linalg_complex.c +8 -6
  18. data/ext/math.c +1 -1
  19. data/ext/matrix_complex.c +6 -6
  20. data/ext/matrix_source.c +10 -10
  21. data/ext/monte.c +2 -2
  22. data/ext/multimin.c +4 -4
  23. data/ext/multiroots.c +8 -8
  24. data/ext/nmf.c +6 -6
  25. data/ext/ntuple.c +4 -4
  26. data/ext/odeiv.c +2 -2
  27. data/ext/permutation.c +1 -1
  28. data/ext/poly2.c +6 -6
  29. data/ext/poly_source.c +9 -6
  30. data/ext/sf.c +31 -45
  31. data/ext/signal.c +2 -2
  32. data/ext/vector_complex.c +11 -10
  33. data/ext/vector_double.c +7 -4
  34. data/ext/vector_source.c +29 -26
  35. data/ext/wavelet.c +1 -1
  36. data/include/rb_gsl_common.h +12 -0
  37. data/include/rb_gsl_config.h +10 -1
  38. data/rdoc/blas.rdoc +4 -4
  39. data/rdoc/bspline.rdoc +8 -8
  40. data/rdoc/cheb.rdoc +9 -9
  41. data/rdoc/cholesky_complex.rdoc +1 -1
  42. data/rdoc/combi.rdoc +10 -10
  43. data/rdoc/complex.rdoc +12 -12
  44. data/rdoc/const.rdoc +21 -21
  45. data/rdoc/dht.rdoc +7 -7
  46. data/rdoc/diff.rdoc +7 -7
  47. data/rdoc/ehandling.rdoc +4 -4
  48. data/rdoc/eigen.rdoc +12 -12
  49. data/rdoc/fft.rdoc +27 -27
  50. data/rdoc/fit.rdoc +19 -19
  51. data/rdoc/function.rdoc +1 -1
  52. data/rdoc/graph.rdoc +3 -3
  53. data/rdoc/hist.rdoc +17 -17
  54. data/rdoc/hist2d.rdoc +5 -5
  55. data/rdoc/hist3d.rdoc +4 -4
  56. data/rdoc/index.rdoc +4 -4
  57. data/rdoc/integration.rdoc +17 -17
  58. data/rdoc/interp.rdoc +12 -12
  59. data/rdoc/intro.rdoc +4 -4
  60. data/rdoc/linalg.rdoc +21 -21
  61. data/rdoc/linalg_complex.rdoc +1 -1
  62. data/rdoc/math.rdoc +14 -14
  63. data/rdoc/matrix.rdoc +21 -21
  64. data/rdoc/min.rdoc +10 -10
  65. data/rdoc/monte.rdoc +4 -4
  66. data/rdoc/multimin.rdoc +13 -13
  67. data/rdoc/multiroot.rdoc +13 -13
  68. data/rdoc/narray.rdoc +10 -10
  69. data/rdoc/ndlinear.rdoc +5 -5
  70. data/rdoc/nonlinearfit.rdoc +18 -18
  71. data/rdoc/ntuple.rdoc +6 -6
  72. data/rdoc/odeiv.rdoc +13 -13
  73. data/rdoc/perm.rdoc +12 -12
  74. data/rdoc/poly.rdoc +18 -18
  75. data/rdoc/qrng.rdoc +10 -10
  76. data/rdoc/randist.rdoc +11 -11
  77. data/rdoc/ref.rdoc +50 -50
  78. data/rdoc/rng.rdoc +10 -10
  79. data/rdoc/rngextra.rdoc +5 -5
  80. data/rdoc/roots.rdoc +13 -13
  81. data/rdoc/sf.rdoc +36 -36
  82. data/rdoc/siman.rdoc +4 -4
  83. data/rdoc/sort.rdoc +7 -7
  84. data/rdoc/start.rdoc +1 -1
  85. data/rdoc/stats.rdoc +14 -14
  86. data/rdoc/sum.rdoc +5 -5
  87. data/rdoc/tensor.rdoc +4 -4
  88. data/rdoc/tut.rdoc +1 -1
  89. data/rdoc/use.rdoc +5 -5
  90. data/rdoc/vector.rdoc +29 -29
  91. data/rdoc/vector_complex.rdoc +6 -6
  92. data/rdoc/wavelet.rdoc +9 -9
  93. data/test/gsl/blas_test.rb +79 -0
  94. data/test/gsl/bspline_test.rb +63 -0
  95. data/test/gsl/cdf_test.rb +1512 -0
  96. data/test/gsl/cheb_test.rb +80 -0
  97. data/test/gsl/combination_test.rb +100 -0
  98. data/test/gsl/complex_test.rb +20 -0
  99. data/test/gsl/const_test.rb +29 -0
  100. data/test/gsl/deriv_test.rb +62 -0
  101. data/test/gsl/dht_test.rb +79 -0
  102. data/test/gsl/diff_test.rb +53 -0
  103. data/test/gsl/eigen_test.rb +563 -0
  104. data/test/gsl/err_test.rb +23 -0
  105. data/test/gsl/fit_test.rb +101 -0
  106. data/test/gsl/histo_test.rb +14 -0
  107. data/test/gsl/integration_test.rb +274 -0
  108. data/test/gsl/interp_test.rb +27 -0
  109. data/test/gsl/linalg_test.rb +463 -0
  110. data/test/gsl/matrix_nmf_test.rb +37 -0
  111. data/test/gsl/matrix_test.rb +77 -0
  112. data/test/gsl/min_test.rb +89 -0
  113. data/test/gsl/monte_test.rb +77 -0
  114. data/test/gsl/multifit_test.rb +753 -0
  115. data/test/gsl/multimin_test.rb +157 -0
  116. data/test/gsl/multiroot_test.rb +135 -0
  117. data/test/gsl/multiset_test.rb +52 -0
  118. data/test/gsl/odeiv_test.rb +275 -0
  119. data/test/gsl/poly_test.rb +338 -0
  120. data/test/gsl/qrng_test.rb +94 -0
  121. data/test/gsl/quartic_test.rb +28 -0
  122. data/test/gsl/randist_test.rb +122 -0
  123. data/test/gsl/rng_test.rb +303 -0
  124. data/test/gsl/roots_test.rb +78 -0
  125. data/test/gsl/sf_test.rb +2079 -0
  126. data/test/gsl/stats_test.rb +122 -0
  127. data/test/gsl/sum_test.rb +69 -0
  128. data/test/gsl/tensor_test.rb +396 -0
  129. data/test/gsl/vector_test.rb +223 -0
  130. data/test/gsl/wavelet_test.rb +130 -0
  131. data/test/gsl_test.rb +321 -0
  132. data/test/test_helper.rb +42 -0
  133. metadata +107 -150
  134. data/setup.rb +0 -1585
  135. data/tests/blas/amax.rb +0 -14
  136. data/tests/blas/asum.rb +0 -16
  137. data/tests/blas/axpy.rb +0 -25
  138. data/tests/blas/copy.rb +0 -23
  139. data/tests/blas/dot.rb +0 -23
  140. data/tests/bspline.rb +0 -53
  141. data/tests/cdf.rb +0 -1388
  142. data/tests/cheb.rb +0 -112
  143. data/tests/combination.rb +0 -123
  144. data/tests/complex.rb +0 -17
  145. data/tests/const.rb +0 -24
  146. data/tests/deriv.rb +0 -85
  147. data/tests/dht/dht1.rb +0 -17
  148. data/tests/dht/dht2.rb +0 -23
  149. data/tests/dht/dht3.rb +0 -23
  150. data/tests/dht/dht4.rb +0 -23
  151. data/tests/diff.rb +0 -78
  152. data/tests/eigen/eigen.rb +0 -220
  153. data/tests/eigen/gen.rb +0 -105
  154. data/tests/eigen/genherm.rb +0 -66
  155. data/tests/eigen/gensymm.rb +0 -68
  156. data/tests/eigen/nonsymm.rb +0 -53
  157. data/tests/eigen/nonsymmv.rb +0 -53
  158. data/tests/eigen/symm-herm.rb +0 -74
  159. data/tests/err.rb +0 -58
  160. data/tests/fit.rb +0 -124
  161. data/tests/gsl_test.rb +0 -118
  162. data/tests/gsl_test2.rb +0 -110
  163. data/tests/histo.rb +0 -12
  164. data/tests/integration/integration1.rb +0 -72
  165. data/tests/integration/integration2.rb +0 -71
  166. data/tests/integration/integration3.rb +0 -71
  167. data/tests/integration/integration4.rb +0 -71
  168. data/tests/interp.rb +0 -45
  169. data/tests/linalg/HH.rb +0 -64
  170. data/tests/linalg/LU.rb +0 -47
  171. data/tests/linalg/QR.rb +0 -77
  172. data/tests/linalg/SV.rb +0 -24
  173. data/tests/linalg/TDN.rb +0 -116
  174. data/tests/linalg/TDS.rb +0 -122
  175. data/tests/linalg/bidiag.rb +0 -73
  176. data/tests/linalg/cholesky.rb +0 -20
  177. data/tests/linalg/linalg.rb +0 -158
  178. data/tests/matrix/matrix_complex_test.rb +0 -36
  179. data/tests/matrix/matrix_nmf_test.rb +0 -39
  180. data/tests/matrix/matrix_test.rb +0 -48
  181. data/tests/min.rb +0 -99
  182. data/tests/monte/miser.rb +0 -31
  183. data/tests/monte/vegas.rb +0 -45
  184. data/tests/multifit/test_2dgauss.rb +0 -112
  185. data/tests/multifit/test_brown.rb +0 -90
  186. data/tests/multifit/test_enso.rb +0 -246
  187. data/tests/multifit/test_filip.rb +0 -155
  188. data/tests/multifit/test_gauss.rb +0 -97
  189. data/tests/multifit/test_longley.rb +0 -110
  190. data/tests/multifit/test_multifit.rb +0 -52
  191. data/tests/multimin.rb +0 -139
  192. data/tests/multiroot.rb +0 -131
  193. data/tests/multiset.rb +0 -52
  194. data/tests/narray/blas_dnrm2.rb +0 -20
  195. data/tests/odeiv.rb +0 -353
  196. data/tests/poly/poly.rb +0 -290
  197. data/tests/poly/special.rb +0 -65
  198. data/tests/qrng.rb +0 -131
  199. data/tests/quartic.rb +0 -29
  200. data/tests/randist.rb +0 -134
  201. data/tests/rng.rb +0 -305
  202. data/tests/roots.rb +0 -76
  203. data/tests/run-test.sh +0 -17
  204. data/tests/sf/gsl_test_sf.rb +0 -249
  205. data/tests/sf/test_airy.rb +0 -83
  206. data/tests/sf/test_bessel.rb +0 -306
  207. data/tests/sf/test_coulomb.rb +0 -17
  208. data/tests/sf/test_dilog.rb +0 -25
  209. data/tests/sf/test_gamma.rb +0 -209
  210. data/tests/sf/test_hyperg.rb +0 -356
  211. data/tests/sf/test_legendre.rb +0 -227
  212. data/tests/sf/test_mathieu.rb +0 -59
  213. data/tests/sf/test_mode.rb +0 -19
  214. data/tests/sf/test_sf.rb +0 -839
  215. data/tests/stats.rb +0 -174
  216. data/tests/stats_mt.rb +0 -16
  217. data/tests/sum.rb +0 -98
  218. data/tests/sys.rb +0 -323
  219. data/tests/tensor.rb +0 -419
  220. data/tests/vector/vector_complex_test.rb +0 -101
  221. data/tests/vector/vector_test.rb +0 -141
  222. data/tests/wavelet.rb +0 -142
@@ -1,78 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Ruby/GSL implementation of GSL "diff/test.c"
3
- require("gsl")
4
- require("./gsl_test.rb")
5
- include GSL::Test
6
-
7
- include Math
8
-
9
- f1 = GSL::Function.alloc { |x| exp(x) }
10
- df1 = GSL::Function.alloc { |x| exp(x) }
11
-
12
- f2 = GSL::Function.alloc { |x|
13
- if x >= 0.0; x*sqrt(x);
14
- else; 0.0; end
15
- }
16
- df2 = GSL::Function.alloc { |x|
17
- if x >= 0.0; 1.5*sqrt(x);
18
- else; 0.0; end
19
- }
20
-
21
- f3 = GSL::Function.alloc { |x|
22
- if x != 0.0; sin(1.0/x);
23
- else; 0.0; end
24
- }
25
- df3 = GSL::Function.alloc { |x|
26
- if x != 0.0; -cos(1.0/x)/(x*x);
27
- else; 0.0; end
28
- }
29
-
30
- f4 = GSL::Function.alloc { |x| exp(-x*x) }
31
- df4 = GSL::Function.alloc { |x| -2.0*x*exp(-x*x) }
32
-
33
- f5 = GSL::Function.alloc { |x| x*x }
34
- df5 = GSL::Function.alloc { |x| 2.0*x }
35
-
36
- f6 = GSL::Function.alloc { |x| 1.0/x }
37
- df6 = GSL::Function.alloc { |x| -1.0/(x*x) }
38
-
39
- def test_diff(diff, f, df, x, desc)
40
- expected = df.eval(x)
41
- case diff
42
- when "central"
43
- result, abserr = f.diff_central(x)
44
- when "forward"
45
- result, abserr = f.diff_forward(x)
46
- when "backward"
47
- result, abserr = f.diff_backward(x)
48
- else
49
- raise("undefined operation")
50
- end
51
- GSL::Test::test_abs(result, expected, abserr, desc)
52
- desc2 = sprintf("%s, valid error estimate", desc)
53
- GSL::Test::test((result - expected).abs > abserr, desc2)
54
- end
55
-
56
- test_diff("central", f1, df1, 1.0, "exp(x), x=1, central diff")
57
- test_diff("forward", f1, df1, 1.0, "exp(x), x=1, forward diff")
58
- test_diff("backward", f1, df1, 1.0, "exp(x), x=1, backward diff")
59
-
60
- test_diff("central", f2, df2, 0.1, "x^(3/2), x=0.1, central diff")
61
- test_diff("forward", f2, df2, 0.1, "x^(3/2), x=0.1, forward diff")
62
- test_diff("backward", f2, df2, 0.1, "x^(3/2), x=0.1, backward diff")
63
-
64
- test_diff("central", f3, df3, 0.45, "sin(1/x), x=0.45, central diff")
65
- test_diff("forward", f3, df3, 0.45, "sin(1/x), x=0.45, forward diff")
66
- test_diff("backward", f3, df3, 0.45, "sin(1/x), x=0.45, backward diff")
67
-
68
- test_diff("central", f4, df4, 0.5, "exp(-x^2), x=0.5, central diff")
69
- test_diff("forward", f4, df4, 0.5, "exp(-x^2), x=0.5, forward diff")
70
- test_diff("backward", f4, df4, 0.5, "exp(-x^2), x=0.5, backward diff")
71
-
72
- test_diff("central", f5, df5, 0.0, "x^2, x=0, central diff")
73
- test_diff("forward", f5, df5, 0.0, "x^2, x=0, forward diff")
74
- test_diff("backward", f5, df5, 0.0, "x^2, x=0, backward diff")
75
-
76
- test_diff("central", f6, df6, 10.0, "1/x, x=10, central diff")
77
- test_diff("forward", f6, df6, 10.0, "1/x, x=10, forward diff")
78
- test_diff("backward", f6, df6, 10.0, "1/x, x=10, backward diff")
@@ -1,220 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Ruby/GSL implementation of GSL "eigen/test.c"
3
- require("gsl")
4
- require("../gsl_test.rb")
5
- include GSL::Test
6
-
7
- def create_random_symm_matrix(size1, size2, rng, lower, upper)
8
- m = GSL::Matrix.alloc(size1, size2)
9
- for i in 0...size1 do
10
- for j in i...size2 do
11
- x = rng.uniform()*(upper-lower) + lower
12
- m[i,j] = x
13
- m[j,i] = x
14
- end
15
- end
16
- m
17
- end
18
-
19
- def create_random_herm_matrix(size1, size2, rng, lower, upper)
20
- m = GSL::Matrix::Complex.alloc(size1, size2)
21
- for i in 0...size1 do
22
- for j in i...size2 do
23
- re = rng.uniform()* (upper - lower) + lower
24
- if i == j
25
- im = 0.0
26
- else
27
- im = rng.uniform()* (upper - lower) + lower
28
- end
29
- z = GSL::Complex.alloc(re, im)
30
- m[i,j] = z
31
- m[j,i] = z.conjugate
32
- end
33
- end
34
- m
35
- end
36
-
37
- def create_random_posdef_matrix(size1, size2, rng)
38
- m = GSL::Matrix.alloc(size1, size2)
39
- x = rng.uniform()
40
- for i in 0...size1 do
41
- for j in i...size2 do
42
- a = pow(x, (j - i).to_f)
43
- m[i,j] = a
44
- m[j,i] = a
45
- end
46
- end
47
- m
48
- end
49
-
50
- def create_random_complex_posdef_matrix(size1, size2, rng)
51
- m = GSL::Matrix::Complex.calloc(size1, size2)
52
- n = size1
53
-
54
- for i in 0...n do
55
- x = rng.uniform()
56
- z = GSL::Complex.alloc(x, 0.0)
57
- m[i,i] = z
58
- end
59
-
60
- work = GSL::Vector::Complex.alloc(n)
61
- for i in 0...n do
62
- for j in 0...n do
63
- x = 2.0*rng.uniform() - 1.0
64
- y = 2.0*rng.uniform() - 1.0
65
- z = GSL::Complex.alloc(x, y)
66
- work[j]
67
- end
68
- tau = GSL::Linalg::Complex::householder_transform(work)
69
- GSL::Linalg::Complex::householder_hm(tau, work, m)
70
- GSL::Linalg::Complex::householder_mh(tau.conjugate, work, m)
71
- end
72
- m
73
- end
74
-
75
- def create_random_nonsymm_matrix(size1, size2, rng, lower, upper)
76
- m = GSL::Matrix.alloc(size1, size2)
77
- for i in 0...size1 do
78
- for j in 0...size2 do
79
- m[i,j] = rng.uniform()*(upper - lower) + lower
80
- end
81
- end
82
- m
83
- end
84
-
85
- def test_eigen_results(n, m, eval, evec, desc, desc2)
86
- x = GSL::Vector.alloc(n)
87
- y = GSL::Vector.alloc(n)
88
-
89
- # check eigenvalues
90
- for i in 0...n
91
- ei = eval[i]
92
- vi = evec.col(i)
93
- GSL::Vector.memcpy(x, vi)
94
- y = GSL::Blas.dgemv(GSL::Blas::NoTrans, 1.0, m, x, 0.0, y)
95
- # y = GSL::Blas.dgemv(GSL::Blas::NoTrans, 1.0, m, x)
96
- for j in 0...n
97
- xj = x[j]
98
- yj = y[j]
99
- desc3 = sprintf("%s, eigenvalue(%d,%d), %s", desc, i, j, desc2)
100
- GSL::Test::test_rel(yj, ei*xj, 1e8*DBL_EPSILON, desc3)
101
- end
102
- end
103
- # check eigenvectors are orthonormal
104
- for i in 0...n
105
- vi = evec.col(i)
106
- nrm_v = GSL::Blas.dnrm2(vi)
107
- desc3 = sprintf("%s, normalized(%d), %s", desc, i, desc2)
108
- GSL::Test::test_rel(nrm_v, 1.0, n*DBL_EPSILON, desc3)
109
- end
110
-
111
- for i in 0...n
112
- vi = evec.col(i)
113
- for j in (i+1)...n
114
- vj = evec.col(j)
115
- vivj = GSL::Blas.ddot(vi, vj)
116
- desc3 = sprintf("%s, orthogonal(%d,%d), %s", desc, i, j, desc2)
117
- GSL::Test::test_abs(vivj, 0.0, n*DBL_EPSILON, desc3)
118
- end
119
- end
120
- end
121
-
122
- def test_eigen_complex_results(n, m, eval, evec, desc, desc2)
123
- x = GSL::Vector::Complex.alloc(n)
124
- y = GSL::Vector::Complex.alloc(n)
125
-
126
- # check eigenvalues
127
- for i in 0...n
128
- ei = eval[i]
129
- vi = evec.col(i)
130
- GSL::Vector::Complex.memcpy(x, vi)
131
- c1 = GSL::Complex.alloc(1.0, 0.0)
132
- c0 = GSL::Complex.alloc(0.0, 0.0)
133
- y = GSL::Blas.zgemv(GSL::Blas::NoTrans, c1, m, x, c0, y)
134
- for j in 0...n
135
- xj = x[j]
136
- yj = y[j]
137
- desc3 = sprintf("%s, eigenvalue(%d,%d), real, %s", desc, i, j, desc2)
138
- GSL::Test::test_rel(yj.re, ei*xj.re, 1e8*DBL_EPSILON, desc3)
139
- desc3 = sprintf("%s, eigenvalue(%d,%d), imag, %s", desc, i, j, desc2)
140
- GSL::Test::test_rel(yj.im, ei*xj.im, 1e8*DBL_EPSILON, desc3)
141
- end
142
- end
143
- # check eigenvectors are orthonormal
144
- for i in 0...n
145
- vi = evec.col(i)
146
- nrm_v = GSL::Blas.dznrm2(vi)
147
- desc3 = sprintf("%s, normalized(%d), %s", desc, i, desc2)
148
- GSL::Test::test_rel(nrm_v, 1.0, n*DBL_EPSILON, desc3)
149
- end
150
-
151
- for i in 0...n
152
- vi = evec.col(i)
153
- for j in (i+1)...n
154
- vj = evec.col(j)
155
- vivj = GSL::Blas.zdotc(vi, vj)
156
- desc3 = sprintf("%s, orthogonal(%d,%d), %s", desc, i, j, desc2)
157
- GSL::Test::test_abs(vivj.abs, 0.0, n*DBL_EPSILON, desc3)
158
- end
159
- end
160
- end
161
-
162
- def test_eigenvalues(n, eval, eval2, desc, desc2)
163
- for i in 0...n
164
- ei = eval[i]
165
- e2i = eval2[i]
166
- desc3 = sprintf("%s, direct eigenvalue(%d), %s", desc, i, desc2)
167
- GSL::Test::test_rel(ei, e2i, GSL::DBL_EPSILON, desc3)
168
- end
169
- end
170
-
171
- def chop_subnormals(x)
172
- # Chop any subnormal values */
173
- return x.abs < GSL::DBL_MIN ? 0 : x
174
- end
175
-
176
- def test_eigenvalues_real(eval, eval2, desc, desc2)
177
- n = eval.size
178
- emax = 0
179
- # check eigenvalues
180
- for i in 0...n do
181
- ei = eval[i]
182
- if ei.abs > emax
183
- emax = ei.abs
184
- end
185
- end
186
-
187
- for i in 0...n do
188
- ei = eval[i]
189
- e2i = chop_subnormals(eval2[i])
190
- GSL::Test::test_abs(ei, e2i, emax * 1e8 * GSL::DBL_EPSILON, "#{desc}, direct eigenvalue(#{i}), #{desc2}")
191
- end
192
- end
193
-
194
- def test_eigenvalues_complex(eval, eval2, desc, desc2)
195
- n = eval.size
196
- for i in 0...n do
197
- ei = eval[i]
198
- e2i = eval2[i]
199
- GSL::Test::test_rel(ei.real, e2i.real, 10*n*GSL::DBL_EPSILON,
200
- "#{desc}, direct eigenvalue(#{i}) real, #{desc2}")
201
-
202
- GSL::Test::test_rel(ei.imag, e2i.imag, 10*n*GSL::DBL_EPSILON,
203
- "#{desc}, direct eigenvalue(#{i}) imag, #{desc2}")
204
- end
205
- end
206
-
207
- def test_eigen_schur(a, s, q, z, count, desc, desc2)
208
- n = a.size1
209
-
210
- t1 = a*z
211
- t2 = q*s
212
- for i in 0...n do
213
- for j in 0...n do
214
- x = t1[i,j]
215
- y = t2[i,j]
216
- GSL::test_abs(x, y, 1.0e8 * GSL::DBL_EPSILON,
217
- "#{desc}(N=#{n},cnt=#{count}), #{desc2}, schur(#{i},#{j})")
218
- end
219
- end
220
- end
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require("gsl")
3
- require("../gsl_test.rb")
4
- require("eigen.rb")
5
- include GSL::Test
6
-
7
- def test_eigen_gen_results(a, b, alpha, beta, evec, count, desc, desc2)
8
- n = a.size1
9
- ma = a.to_complex
10
- mb = b.to_complex
11
-
12
- for i in 0...n do
13
- vi = evec.column(i)
14
- ai = alpha[i]
15
- bi = beta[i]
16
-
17
- x = mb*vi
18
- x *= ai
19
-
20
- y = ma*vi
21
- y *= bi
22
-
23
- for j in 0...n do
24
- GSL::Test::test_abs(y[j].real, x[j].real, 1e8*GSL::DBL_EPSILON,
25
- "gen(N=#{n},cnt=#{count}), #{desc}, eigenvalue(#{i},#{j}), real, #{desc2}")
26
- GSL::Test::test_abs(y[j].imag, x[j].imag, 1e8*GSL::DBL_EPSILON,
27
- "gen(N=#{n},cnt=#{count}), #{desc}, eigenvalue(#{i},#{j}), imag, #{desc2}")
28
- end
29
- end
30
- end
31
-
32
- def test_eigen_gen_pencil(a, b, count, desc, test_schur, w, wv)
33
- n = a.size1
34
-
35
- aa = a.clone
36
- bb = b.clone
37
-
38
- if test_schur == 1
39
- alphav, betav, evec, q, z = GSL::Eigen::genv_QZ(aa, bb, wv)
40
- test_eigen_schur(a, aa, q, z, count, "genv/A", desc)
41
- test_eigen_schur(b, bb, q, z, count, "genv/B", desc)
42
- else
43
- alphav, betav, evec = GSL::Eigen::genv(aa, bb, wv)
44
- end
45
-
46
- test_eigen_gen_results(a, b, alphav, betav, evec, count, desc, "unsorted")
47
-
48
- aa = a.clone
49
- bb = b.clone
50
- if test_schur == 1
51
- GSL::Eigen::gen_params(1, 1, 0, w)
52
- alpha, beta, q, z = GSL::Eigen::gen_QZ(aa, bb, w)
53
- test_eigen_schur(a, aa, q, z, count, "gen/A", desc)
54
- test_eigen_schur(b, bb, q, z, count, "gen/B", desc)
55
- else
56
- GSL::Eigen::gen_params(0, 0, 0, w)
57
- alpha, beta = GSL::Eigen::gen(aa, bb, w)
58
- end
59
-
60
- eval = GSL::Vector::Complex.alloc(n)
61
- evalv = GSL::Vector::Complex.alloc(n)
62
- for i in 0...n do
63
- ai = alpha[i]
64
- bi = beta[i]
65
- z = GSL::Complex.alloc(ai.real/bi, ai.imag/bi)
66
- eval[i] = z
67
-
68
- ai = alphav[i]
69
- bi = betav[i]
70
- z = GSL::Complex.alloc(ai.real/bi, ai.imag/bi)
71
- evalv[i] = z
72
- end
73
-
74
- GSL::Eigen::nonsymmv_sort(eval, nil, GSL::EIGEN_SORT_ABS_ASC)
75
- GSL::Eigen::nonsymmv_sort(evalv, nil, GSL::EIGEN_SORT_ABS_ASC)
76
- test_eigenvalues_complex(evalv, eval, "gen", desc)
77
-
78
- GSL::Eigen::genv_sort(alphav, betav, evec, GSL::EIGEN_SORT_ABS_ASC)
79
- test_eigen_gen_results(a, b, alphav, betav, evec, count, desc, "abs/asc")
80
- GSL::Eigen::genv_sort(alphav, betav, evec, GSL::EIGEN_SORT_ABS_DESC)
81
- test_eigen_gen_results(a, b, alphav, betav, evec, count, desc, "abs/desc")
82
- end
83
-
84
- def test_eigen_gen()
85
- n_max = 20
86
- rng = GSL::Rng.alloc()
87
- for n in 1..n_max do
88
- w = GSL::Eigen::Gen.alloc(n)
89
- wv = GSL::Eigen::Genv.alloc(n)
90
- for i in 0...5 do
91
- a = create_random_nonsymm_matrix(n, n, rng, -10, 10)
92
- b = create_random_nonsymm_matrix(n, n, rng, -10, 10)
93
- test_eigen_gen_pencil(a, b, i, "random", 0, w, wv);
94
- test_eigen_gen_pencil(a, b, i, "random", 1, w, wv);
95
- end
96
- end
97
- ma = GSL::Matrix.alloc([1, 1, 0, 0, 0, -1, 1, 0, 0], 3, 3)
98
- mb = GSL::Matrix.alloc([-1, 0, -1, 0, -1, 0, 0, 0, -1], 3, 3)
99
- w = GSL::Eigen::Gen.alloc(3)
100
- wv = GSL::Eigen::Genv.alloc(3)
101
- test_eigen_gen_pencil(ma, mb, 0, "integer", 0, w, wv);
102
- test_eigen_gen_pencil(ma, mb, 0, "integer", 1, w, wv);
103
- end
104
-
105
- test_eigen_gen()
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require("gsl")
3
- require("../gsl_test.rb")
4
- require("eigen.rb")
5
- include GSL::Test
6
-
7
- def test_eigen_genherm_results(a, b, eval, evec, count, desc, desc2)
8
- n = a.size1
9
-
10
- # check A v = lambda B v
11
- for i in 0...n do
12
- ei = eval[i]
13
- vi = evec.column(i)
14
- norm = vi.nrm2
15
- # check that eigenvector is normalized
16
- GSL::Test::test_rel(norm, 1.0, n * GSL::DBL_EPSILON,
17
- "genherm(N=#{n},cnt=#{count}), #{desc}, normalized(#{i}), #{desc2}")
18
-
19
- y = a*vi
20
- x = b*vi
21
- x *= ei
22
-
23
- for j in 0...n do
24
- GSL::Test::test_rel(y[j].real, x[j].real, 1e9 * GSL::DBL_EPSILON,
25
- "genherm(N=#{n},cnt=#{count}), #{desc}, eigenvalue(#{i},#{j}), real, #{desc2}")
26
- GSL::Test::test_rel(y[j].imag, x[j].imag, 1e9 * GSL::DBL_EPSILON,
27
- "genherm(N=#{n},cnt=#{count}), #{desc}, eigenvalue(#{i},#{j}), imag, #{desc2}")
28
- end
29
- end
30
- end
31
-
32
- def test_eigen_genherm()
33
- n_max = 20
34
- rng = GSL::Rng.alloc()
35
- for n in 1..n_max do
36
- w = GSL::Eigen::Genherm.alloc(n)
37
- wv = GSL::Eigen::Genhermv.alloc(n)
38
- for i in 0...5 do
39
- a = create_random_herm_matrix(n, n, rng, -10, 10)
40
- b = create_random_complex_posdef_matrix(n, n, rng)
41
-
42
- evalv, evec = GSL::Eigen::genhermv(a, b, wv)
43
- test_eigen_genherm_results(a, b, evalv, evec, i, "random", "unsorted")
44
-
45
- eval = GSL::Eigen::genherm(a, b, w)
46
-
47
- x = eval.sort
48
- y = evalv.sort
49
-
50
- test_eigenvalues_real(y, x, "genherm, random", "unsorted")
51
-
52
- GSL::Eigen::genhermv_sort(evalv, evec, GSL::EIGEN_SORT_VAL_ASC);
53
- test_eigen_genherm_results(a, b, evalv, evec, i, "random", "val/asc");
54
-
55
- GSL::Eigen::genhermv_sort(evalv, evec, GSL::EIGEN_SORT_VAL_DESC);
56
- test_eigen_genherm_results(a, b, evalv, evec, i, "random", "val/desc");
57
-
58
- GSL::Eigen::genhermv_sort(evalv, evec, GSL::EIGEN_SORT_ABS_ASC);
59
- test_eigen_genherm_results(a, b, evalv, evec, i, "random", "abs/asc");
60
- GSL::Eigen::genhermv_sort(evalv, evec, GSL::EIGEN_SORT_ABS_DESC);
61
- test_eigen_genherm_results(a, b, evalv, evec, i, "random", "abs/desc");
62
- end
63
- end
64
- end
65
-
66
- test_eigen_genherm()