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.
- checksums.yaml +4 -4
- data/AUTHORS +2 -2
- data/ChangeLog +8 -0
- data/Rakefile +39 -96
- data/VERSION +1 -1
- data/ext/array.c +2 -2
- data/ext/block_source.c +1 -1
- data/ext/dirac.c +1 -1
- data/ext/eigen.c +13 -13
- data/ext/extconf.rb +17 -11
- data/ext/function.c +5 -5
- data/ext/gsl_narray.c +6 -6
- data/ext/histogram.c +7 -6
- data/ext/histogram2d.c +4 -4
- data/ext/interp.c +1 -1
- data/ext/linalg.c +13 -11
- data/ext/linalg_complex.c +8 -6
- data/ext/math.c +1 -1
- data/ext/matrix_complex.c +6 -6
- data/ext/matrix_source.c +10 -10
- data/ext/monte.c +2 -2
- data/ext/multimin.c +4 -4
- data/ext/multiroots.c +8 -8
- data/ext/nmf.c +6 -6
- data/ext/ntuple.c +4 -4
- data/ext/odeiv.c +2 -2
- data/ext/permutation.c +1 -1
- data/ext/poly2.c +6 -6
- data/ext/poly_source.c +9 -6
- data/ext/sf.c +31 -45
- data/ext/signal.c +2 -2
- data/ext/vector_complex.c +11 -10
- data/ext/vector_double.c +7 -4
- data/ext/vector_source.c +29 -26
- data/ext/wavelet.c +1 -1
- data/include/rb_gsl_common.h +12 -0
- data/include/rb_gsl_config.h +10 -1
- data/rdoc/blas.rdoc +4 -4
- data/rdoc/bspline.rdoc +8 -8
- data/rdoc/cheb.rdoc +9 -9
- data/rdoc/cholesky_complex.rdoc +1 -1
- data/rdoc/combi.rdoc +10 -10
- data/rdoc/complex.rdoc +12 -12
- data/rdoc/const.rdoc +21 -21
- data/rdoc/dht.rdoc +7 -7
- data/rdoc/diff.rdoc +7 -7
- data/rdoc/ehandling.rdoc +4 -4
- data/rdoc/eigen.rdoc +12 -12
- data/rdoc/fft.rdoc +27 -27
- data/rdoc/fit.rdoc +19 -19
- data/rdoc/function.rdoc +1 -1
- data/rdoc/graph.rdoc +3 -3
- data/rdoc/hist.rdoc +17 -17
- data/rdoc/hist2d.rdoc +5 -5
- data/rdoc/hist3d.rdoc +4 -4
- data/rdoc/index.rdoc +4 -4
- data/rdoc/integration.rdoc +17 -17
- data/rdoc/interp.rdoc +12 -12
- data/rdoc/intro.rdoc +4 -4
- data/rdoc/linalg.rdoc +21 -21
- data/rdoc/linalg_complex.rdoc +1 -1
- data/rdoc/math.rdoc +14 -14
- data/rdoc/matrix.rdoc +21 -21
- data/rdoc/min.rdoc +10 -10
- data/rdoc/monte.rdoc +4 -4
- data/rdoc/multimin.rdoc +13 -13
- data/rdoc/multiroot.rdoc +13 -13
- data/rdoc/narray.rdoc +10 -10
- data/rdoc/ndlinear.rdoc +5 -5
- data/rdoc/nonlinearfit.rdoc +18 -18
- data/rdoc/ntuple.rdoc +6 -6
- data/rdoc/odeiv.rdoc +13 -13
- data/rdoc/perm.rdoc +12 -12
- data/rdoc/poly.rdoc +18 -18
- data/rdoc/qrng.rdoc +10 -10
- data/rdoc/randist.rdoc +11 -11
- data/rdoc/ref.rdoc +50 -50
- data/rdoc/rng.rdoc +10 -10
- data/rdoc/rngextra.rdoc +5 -5
- data/rdoc/roots.rdoc +13 -13
- data/rdoc/sf.rdoc +36 -36
- data/rdoc/siman.rdoc +4 -4
- data/rdoc/sort.rdoc +7 -7
- data/rdoc/start.rdoc +1 -1
- data/rdoc/stats.rdoc +14 -14
- data/rdoc/sum.rdoc +5 -5
- data/rdoc/tensor.rdoc +4 -4
- data/rdoc/tut.rdoc +1 -1
- data/rdoc/use.rdoc +5 -5
- data/rdoc/vector.rdoc +29 -29
- data/rdoc/vector_complex.rdoc +6 -6
- data/rdoc/wavelet.rdoc +9 -9
- data/test/gsl/blas_test.rb +79 -0
- data/test/gsl/bspline_test.rb +63 -0
- data/test/gsl/cdf_test.rb +1512 -0
- data/test/gsl/cheb_test.rb +80 -0
- data/test/gsl/combination_test.rb +100 -0
- data/test/gsl/complex_test.rb +20 -0
- data/test/gsl/const_test.rb +29 -0
- data/test/gsl/deriv_test.rb +62 -0
- data/test/gsl/dht_test.rb +79 -0
- data/test/gsl/diff_test.rb +53 -0
- data/test/gsl/eigen_test.rb +563 -0
- data/test/gsl/err_test.rb +23 -0
- data/test/gsl/fit_test.rb +101 -0
- data/test/gsl/histo_test.rb +14 -0
- data/test/gsl/integration_test.rb +274 -0
- data/test/gsl/interp_test.rb +27 -0
- data/test/gsl/linalg_test.rb +463 -0
- data/test/gsl/matrix_nmf_test.rb +37 -0
- data/test/gsl/matrix_test.rb +77 -0
- data/test/gsl/min_test.rb +89 -0
- data/test/gsl/monte_test.rb +77 -0
- data/test/gsl/multifit_test.rb +753 -0
- data/test/gsl/multimin_test.rb +157 -0
- data/test/gsl/multiroot_test.rb +135 -0
- data/test/gsl/multiset_test.rb +52 -0
- data/test/gsl/odeiv_test.rb +275 -0
- data/test/gsl/poly_test.rb +338 -0
- data/test/gsl/qrng_test.rb +94 -0
- data/test/gsl/quartic_test.rb +28 -0
- data/test/gsl/randist_test.rb +122 -0
- data/test/gsl/rng_test.rb +303 -0
- data/test/gsl/roots_test.rb +78 -0
- data/test/gsl/sf_test.rb +2079 -0
- data/test/gsl/stats_test.rb +122 -0
- data/test/gsl/sum_test.rb +69 -0
- data/test/gsl/tensor_test.rb +396 -0
- data/test/gsl/vector_test.rb +223 -0
- data/test/gsl/wavelet_test.rb +130 -0
- data/test/gsl_test.rb +321 -0
- data/test/test_helper.rb +42 -0
- metadata +107 -150
- data/setup.rb +0 -1585
- data/tests/blas/amax.rb +0 -14
- data/tests/blas/asum.rb +0 -16
- data/tests/blas/axpy.rb +0 -25
- data/tests/blas/copy.rb +0 -23
- data/tests/blas/dot.rb +0 -23
- data/tests/bspline.rb +0 -53
- data/tests/cdf.rb +0 -1388
- data/tests/cheb.rb +0 -112
- data/tests/combination.rb +0 -123
- data/tests/complex.rb +0 -17
- data/tests/const.rb +0 -24
- data/tests/deriv.rb +0 -85
- data/tests/dht/dht1.rb +0 -17
- data/tests/dht/dht2.rb +0 -23
- data/tests/dht/dht3.rb +0 -23
- data/tests/dht/dht4.rb +0 -23
- data/tests/diff.rb +0 -78
- data/tests/eigen/eigen.rb +0 -220
- data/tests/eigen/gen.rb +0 -105
- data/tests/eigen/genherm.rb +0 -66
- data/tests/eigen/gensymm.rb +0 -68
- data/tests/eigen/nonsymm.rb +0 -53
- data/tests/eigen/nonsymmv.rb +0 -53
- data/tests/eigen/symm-herm.rb +0 -74
- data/tests/err.rb +0 -58
- data/tests/fit.rb +0 -124
- data/tests/gsl_test.rb +0 -118
- data/tests/gsl_test2.rb +0 -110
- data/tests/histo.rb +0 -12
- data/tests/integration/integration1.rb +0 -72
- data/tests/integration/integration2.rb +0 -71
- data/tests/integration/integration3.rb +0 -71
- data/tests/integration/integration4.rb +0 -71
- data/tests/interp.rb +0 -45
- data/tests/linalg/HH.rb +0 -64
- data/tests/linalg/LU.rb +0 -47
- data/tests/linalg/QR.rb +0 -77
- data/tests/linalg/SV.rb +0 -24
- data/tests/linalg/TDN.rb +0 -116
- data/tests/linalg/TDS.rb +0 -122
- data/tests/linalg/bidiag.rb +0 -73
- data/tests/linalg/cholesky.rb +0 -20
- data/tests/linalg/linalg.rb +0 -158
- data/tests/matrix/matrix_complex_test.rb +0 -36
- data/tests/matrix/matrix_nmf_test.rb +0 -39
- data/tests/matrix/matrix_test.rb +0 -48
- data/tests/min.rb +0 -99
- data/tests/monte/miser.rb +0 -31
- data/tests/monte/vegas.rb +0 -45
- data/tests/multifit/test_2dgauss.rb +0 -112
- data/tests/multifit/test_brown.rb +0 -90
- data/tests/multifit/test_enso.rb +0 -246
- data/tests/multifit/test_filip.rb +0 -155
- data/tests/multifit/test_gauss.rb +0 -97
- data/tests/multifit/test_longley.rb +0 -110
- data/tests/multifit/test_multifit.rb +0 -52
- data/tests/multimin.rb +0 -139
- data/tests/multiroot.rb +0 -131
- data/tests/multiset.rb +0 -52
- data/tests/narray/blas_dnrm2.rb +0 -20
- data/tests/odeiv.rb +0 -353
- data/tests/poly/poly.rb +0 -290
- data/tests/poly/special.rb +0 -65
- data/tests/qrng.rb +0 -131
- data/tests/quartic.rb +0 -29
- data/tests/randist.rb +0 -134
- data/tests/rng.rb +0 -305
- data/tests/roots.rb +0 -76
- data/tests/run-test.sh +0 -17
- data/tests/sf/gsl_test_sf.rb +0 -249
- data/tests/sf/test_airy.rb +0 -83
- data/tests/sf/test_bessel.rb +0 -306
- data/tests/sf/test_coulomb.rb +0 -17
- data/tests/sf/test_dilog.rb +0 -25
- data/tests/sf/test_gamma.rb +0 -209
- data/tests/sf/test_hyperg.rb +0 -356
- data/tests/sf/test_legendre.rb +0 -227
- data/tests/sf/test_mathieu.rb +0 -59
- data/tests/sf/test_mode.rb +0 -19
- data/tests/sf/test_sf.rb +0 -839
- data/tests/stats.rb +0 -174
- data/tests/stats_mt.rb +0 -16
- data/tests/sum.rb +0 -98
- data/tests/sys.rb +0 -323
- data/tests/tensor.rb +0 -419
- data/tests/vector/vector_complex_test.rb +0 -101
- data/tests/vector/vector_test.rb +0 -141
- data/tests/wavelet.rb +0 -142
data/tests/poly/poly.rb
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require("gsl")
|
3
|
-
require("../gsl_test2.rb")
|
4
|
-
include GSL::Test
|
5
|
-
include Math
|
6
|
-
|
7
|
-
eps = 100.0 * GSL::DBL_EPSILON
|
8
|
-
GSL::IEEE::env_setup()
|
9
|
-
|
10
|
-
c = GSL::Poly.alloc(1.0, 0.5, 0.3)
|
11
|
-
x = 0.5
|
12
|
-
y = c.eval(x)
|
13
|
-
GSL::Test::test_rel(y, 1 + 0.5 * x + 0.3 * x * x, eps,
|
14
|
-
"gsl_poly_eval({1, 0.5, 0.3}, 0.5)")
|
15
|
-
|
16
|
-
d = GSL::Poly.alloc( 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1)
|
17
|
-
x = 1.0
|
18
|
-
#y = d.eval(x)
|
19
|
-
y = GSL::Poly.eval(d, x)
|
20
|
-
#y = GSL::Poly.eval(d, 11, x)
|
21
|
-
GSL::Test::test_rel(y, 1.0, eps,
|
22
|
-
"gsl_poly_eval({1,-1, 1, -1, 1, -1, 1, -1, 1, -1, 1}, 1.0)")
|
23
|
-
|
24
|
-
x0, x1 = GSL::Poly.solve_quadratic(4.0, -20.0, 25.0).to_a
|
25
|
-
GSL::Test::test_rel(x0, 2.5, 1e-9, "x0, (2x - 5)^2 = 0")
|
26
|
-
GSL::Test::test_rel(x1, 2.5, 1e-9, "x1, (2x - 5)^2 = 0")
|
27
|
-
|
28
|
-
x0, x1 = GSL::Poly.solve_quadratic(4.0, 7.0, 0.0).to_a
|
29
|
-
GSL::Test::test_rel(x0, -1.75, 1e-9, "x0, x(4x + 7) = 0")
|
30
|
-
GSL::Test::test_rel(x1, 0.0, 1e-9, "x1, x(4x + 7) = 0")
|
31
|
-
|
32
|
-
x0, x1 = GSL::Poly.solve_quadratic(5.0, 0.0, -20.0).to_a
|
33
|
-
test_rel(x0, -2.0, 1e-9, "x0, 5 x^2 = 20")
|
34
|
-
test_rel(x1, 2.0, 1e-9, "x1, 5 x^2 = 20")
|
35
|
-
|
36
|
-
# Quadratic single real root (technically not a quadratic)
|
37
|
-
x0, x1 = GSL::Poly.solve_quadratic(0.0, 1.0, 0.0).to_a
|
38
|
-
test_rel(x0, 0.0, 0, "x0, x = 0")
|
39
|
-
test2(x1.nil?, "x1, x = 0 is nil")
|
40
|
-
|
41
|
-
# Quadratic no real root
|
42
|
-
x0, x1 = GSL::Poly.solve_quadratic(1.0, 0.0, 1.0).to_a
|
43
|
-
test2(x0.nil?, "x0, x^2 = -1 is nil")
|
44
|
-
test2(x1.nil?, "x1, x^2 = -1 is nil")
|
45
|
-
|
46
|
-
x0, x1, x2 = GSL::Poly.solve_cubic(0.0, 0.0, -27.0).to_a
|
47
|
-
test_rel(x0, 3.0, 1e-9, "x0, x^3 = 27")
|
48
|
-
|
49
|
-
# Cubic triple real root
|
50
|
-
x0, x1, x2 = GSL::Poly.solve_cubic(-51.0, 867.0, -4913.0).to_a
|
51
|
-
test_rel(x0, 17.0, 1e-9, "x0, (x-17)^3=0")
|
52
|
-
test_rel(x1, 17.0, 1e-9, "x1, (x-17)^3=0")
|
53
|
-
test_rel(x2, 17.0, 1e-9, "x2, (x-17)^3=0")
|
54
|
-
|
55
|
-
# Cubic double real root plus single real root
|
56
|
-
x0, x1, x2 = GSL::Poly.solve_cubic(-57.0, 1071.0, -6647.0).to_a
|
57
|
-
test_rel(x0, 17.0, 1e-9, "x0, (x-17)(x-17)(x-23)=0")
|
58
|
-
test_rel(x1, 17.0, 1e-9, "x1, (x-17)(x-17)(x-23)=0")
|
59
|
-
test_rel(x2, 23.0, 1e-9, "x2, (x-17)(x-17)(x-23)=0")
|
60
|
-
|
61
|
-
x0, x1, x2 = GSL::Poly.solve_cubic(-11.0, -493.0, +6647.0).to_a
|
62
|
-
test_rel(x0, -23.0, 1e-9, "x0, (x+23)(x-17)(x-17)=0")
|
63
|
-
test_rel(x1, 17.0, 1e-9, "x1, (x+23)(x-17)(x-17)=0")
|
64
|
-
test_rel(x2, 17.0, 1e-9, "x2, (x+23)(x-17)(x-17)=0")
|
65
|
-
|
66
|
-
x0, x1, x2 = GSL::Poly.solve_cubic(-143.0, 5087.0, -50065.0).to_a
|
67
|
-
test_rel(x0, 17.0, 1e-9, "x0, (x-17)(x-31)(x-95)=0")
|
68
|
-
test_rel(x1, 31.0, 1e-9, "x1, (x-17)(x-31)(x-95)=0")
|
69
|
-
test_rel(x2, 95.0, 1e-9, "x2, (x-17)(x-31)(x-95)=0")
|
70
|
-
|
71
|
-
x0, x1, x2 = GSL::Poly.solve_cubic(-109.0, 803.0, 50065.0).to_a
|
72
|
-
test_rel(x0, -17.0, 1e-9, "x0, (x+17)(x-31)(x-95)=0")
|
73
|
-
test_rel(x1, 31.0, 1e-9, "x1, (x+17)(x-31)(x-95)=0")
|
74
|
-
test_rel(x2, 95.0, 1e-9, "x2, (x+17)(x-31)(x-95)=0")
|
75
|
-
|
76
|
-
# Cubic double real root only is impossible
|
77
|
-
|
78
|
-
# Cubic single real root (and two complex roots, not returned)
|
79
|
-
x0, x1, x2 = GSL::Poly.solve_cubic(0.0, 0.0, -1.0).to_a
|
80
|
-
test_rel(x0, 1.0, 1e-9, "x0, x^3 = 1")
|
81
|
-
test2(x1.nil?, "x1, x^3 = 1 is nil")
|
82
|
-
test2(x2.nil?, "x2, x^3 = 1 is nil")
|
83
|
-
|
84
|
-
# Cubic no real root is impossible
|
85
|
-
|
86
|
-
#z0, z1 = GSL::Poly.complex_solve_quadratic(4.0, -20.0, 26.0).to_a
|
87
|
-
r = GSL::Poly::Complex.solve_quadratic(4.0, -20.0, 26.0)
|
88
|
-
z0 = r[0]
|
89
|
-
z1 = r[1]
|
90
|
-
test_rel(z0.re, 2.5, 1e-9, "z0.real, (2x - 5)^2 = -1")
|
91
|
-
test_rel(z0.im, -0.5, 1e-9, "z0.imag, (2x - 5)^2 = -1")
|
92
|
-
test_rel(z1.re, 2.5, 1e-9, "z1.real, (2x - 5)^2 = -1")
|
93
|
-
test_rel(z1.im, 0.5, 1e-9, "z1.imag, (2x - 5)^2 = -1")
|
94
|
-
|
95
|
-
z = GSL::Poly.complex_solve_quadratic(4.0, -20.0, 25.0)
|
96
|
-
test_rel(z[0].re, 2.5, 1e-9, "z0.real, (2x - 5)^2 = 0")
|
97
|
-
test_rel(z[0].im, 0.0, 1e-9, "z0.imag (2x - 5)^2 = 0")
|
98
|
-
test_rel(z[1].re, 2.5, 1e-9, "z1.real, (2x - 5)^2 = 0")
|
99
|
-
test_rel(z[1].im, 0.0, 1e-9, "z1.imag (2x - 5)^2 = 0")
|
100
|
-
test(z[0].re != z[1].re ? 1 : 0,
|
101
|
-
"z0.real == z1.real, (2x - 5)^2 = 0")
|
102
|
-
test(z[1].im != z[1].im ? 1 : 0,
|
103
|
-
"z0.imag == z1.imag, (2x - 5)^2 = 0")
|
104
|
-
|
105
|
-
z = GSL::Poly.complex_solve_quadratic(4.0, -20.0, 21.0)
|
106
|
-
test_rel(z[0].re, 1.5, 1e-9, "z0.real, (2x - 5)^2 = 4")
|
107
|
-
test_rel(z[0].im, 0.0, 1e-9, "z0.imag, (2x - 5)^2 = 4")
|
108
|
-
test_rel(z[1].re, 3.5, 1e-9, "z1.real, (2x - 5)^2 = 4")
|
109
|
-
test_rel(z[1].im, 0.0, 1e-9, "z1.imag, (2x - 5)^2 = 4")
|
110
|
-
|
111
|
-
z = GSL::Poly.complex_solve_quadratic(4.0, 7.0, 0.0)
|
112
|
-
test_rel(z[0].re, -1.75, 1e-9, "z[0].real, x(4x + 7) = 0")
|
113
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, x(4x + 7) = 0")
|
114
|
-
test_rel(z[1].re, 0.0, 1e-9, "z[1].real, x(4x + 7) = 0")
|
115
|
-
test_rel(z[1].im, 0.0, 1e-9, "z[1].imag, x(4x + 7) = 0")
|
116
|
-
|
117
|
-
z =GSL::Poly.complex_solve_quadratic(5.0, 0.0, -20.0)
|
118
|
-
test_rel(z[0].re, -2.0, 1e-9, "z[0].real, 5 x^2 = 20")
|
119
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, 5 x^2 = 20")
|
120
|
-
test_rel(z[1].re, 2.0, 1e-9, "z[1].real, 5 x^2 = 20")
|
121
|
-
test_rel(z[1].im, 0.0, 1e-9, "z[1].imag, 5 x^2 = 20")
|
122
|
-
|
123
|
-
z = GSL::Poly.complex_solve_quadratic(5.0, 0.0, 20.0)
|
124
|
-
test_rel(z[0].re, 0.0, 1e-9, "z[0].real, 5 x^2 = -20")
|
125
|
-
test_rel(z[0].im, -2.0, 1e-9, "z[0].imag, 5 x^2 = -20")
|
126
|
-
test_rel(z[1].re, 0.0, 1e-9, "z[1].real, 5 x^2 = -20")
|
127
|
-
test_rel(z[1].im, 2.0, 1e-9, "z[1].imag, 5 x^2 = -20")
|
128
|
-
|
129
|
-
# Quadratic single complex root (technically not quadratic and root not
|
130
|
-
# complex since imaginary component is 0, but the data type is complex)
|
131
|
-
z = GSL::Poly.complex_solve_quadratic(0.0, 1.0, -1.0)
|
132
|
-
test_rel(z[0].re, 1.0, 1e-9, "z[0].real, x = 1 (complex)")
|
133
|
-
test_rel(z[0].im, 0.0, 0.0, "z[0].imag, x = 1 (complex)")
|
134
|
-
test2(x1.nil?, "z[1], x = 0 is nil")
|
135
|
-
|
136
|
-
# Quadratic no complex root (technically not quadratic)
|
137
|
-
z = GSL::Poly.complex_solve_quadratic(0.0, 0.0, 1.0)
|
138
|
-
test2(z[0].nil?, "z[0], 1 = 0 is nil")
|
139
|
-
test2(z[1].nil?, "z[1], 1 = 0 is nil")
|
140
|
-
|
141
|
-
z = GSL::Poly.complex_solve_cubic(0.0, 0.0, -27.0)
|
142
|
-
test_rel(z[0].re, -1.5, 1e-9, "z[0].real, x^3 = 27");
|
143
|
-
test_rel(z[0].im, -1.5 * sqrt(3.0), 1e-9,
|
144
|
-
"z[0].imag, x^3 = 27");
|
145
|
-
test_rel(z[1].re, -1.5, 1e-9, "z[1].real, x^3 = 27");
|
146
|
-
test_rel(z[1].im, 1.5 * sqrt(3.0), 1e-9, "z[1].imag, x^3 = 27");
|
147
|
-
test_rel(z[2].re, 3.0, 1e-9, "z[2].real, x^3 = 27");
|
148
|
-
test_rel(z[2].im, 0.0, 1e-9, "z[2].imag, x^3 = 27")
|
149
|
-
|
150
|
-
z = GSL::Poly.complex_solve_cubic(-1.0, 1.0, 39.0)
|
151
|
-
test_rel(z[0].re, -3.0, 1e-9, "z[0].real, (x+3)(x^2+1) = 0");
|
152
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, (x+3)(x^2+1) = 0");
|
153
|
-
test_rel(z[1].re, 2.0, 1e-9, "z[1].real, (x+3)(x^2+1) = 0");
|
154
|
-
test_rel(z[1].im, -3.0, 1e-9, "z[1].imag, (x+3)(x^2+1) = 0");
|
155
|
-
test_rel(z[2].re, 2.0, 1e-9, "z[2].real, (x+3)(x^2+1) = 0");
|
156
|
-
test_rel(z[2].im, 3.0, 1e-9, "z[2].imag, (x+3)(x^2+1) = 0")
|
157
|
-
|
158
|
-
z = GSL::Poly.complex_solve_cubic(-51.0, 867.0, -4913.0)
|
159
|
-
test_rel(z[0].re, 17.0, 1e-9, "z[0].real, (x-17)^3=0");
|
160
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, (x-17)^3=0");
|
161
|
-
test_rel(z[1].re, 17.0, 1e-9, "z[1].real, (x-17)^3=0");
|
162
|
-
test_rel(z[1].im, 0.0, 1e-9, "z[1].imag, (x-17)^3=0");
|
163
|
-
test_rel(z[2].re, 17.0, 1e-9, "z[2].real, (x-17)^3=0");
|
164
|
-
test_rel(z[2].im, 0.0, 1e-9, "z[2].imag, (x-17)^3=0")
|
165
|
-
|
166
|
-
z = GSL::Poly.complex_solve_cubic(-57.0, 1071.0, -6647.0)
|
167
|
-
test_rel(z[0].re, 17.0, 1e-9, "z[0].real, (x-17)(x-17)(x-23)=0");
|
168
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, (x-17)(x-17)(x-23)=0");
|
169
|
-
test_rel(z[1].re, 17.0, 1e-9, "z[1].real, (x-17)(x-17)(x-23)=0");
|
170
|
-
test_rel(z[1].im, 0.0, 1e-9, "z[1].imag, (x-17)(x-17)(x-23)=0");
|
171
|
-
test_rel(z[2].re, 23.0, 1e-9, "z[2].real, (x-17)(x-17)(x-23)=0");
|
172
|
-
test_rel(z[2].im, 0.0, 1e-9, "z[2].imag, (x-17)(x-17)(x-23)=0")
|
173
|
-
|
174
|
-
z = GSL::Poly.complex_solve_cubic(-11.0, -493.0, +6647.0)
|
175
|
-
test_rel(z[0].re, -23.0, 1e-9,
|
176
|
-
"z[0].real, (x+23)(x-17)(x-17)=0");
|
177
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, (x+23)(x-17)(x-17)=0");
|
178
|
-
test_rel(z[1].re, 17.0, 1e-9, "z[1].real, (x+23)(x-17)(x-17)=0");
|
179
|
-
test_rel(z[1].im, 0.0, 1e-9, "z[1].imag, (x+23)(x-17)(x-17)=0");
|
180
|
-
test_rel(z[2].re, 17.0, 1e-9, "z[2].real, (x+23)(x-17)(x-17)=0");
|
181
|
-
test_rel(z[2].im, 0.0, 1e-9, "z[2].imag, (x+23)(x-17)(x-17)=0");
|
182
|
-
|
183
|
-
z = GSL::Poly.complex_solve_cubic(-143.0, 5087.0, -50065.0)
|
184
|
-
test_rel(z[0].re, 17.0, 1e-9, "z[0].real, (x-17)(x-31)(x-95)=0");
|
185
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, (x-17)(x-31)(x-95)=0");
|
186
|
-
test_rel(z[1].re, 31.0, 1e-9, "z[1].real, (x-17)(x-31)(x-95)=0");
|
187
|
-
test_rel(z[1].im, 0.0, 1e-9, "z[1].imag, (x-17)(x-31)(x-95)=0");
|
188
|
-
test_rel(z[2].re, 95.0, 1e-9, "z[2].real, (x-17)(x-31)(x-95)=0");
|
189
|
-
test_rel(z[2].im, 0.0, 1e-9, "z[2].imag, (x-17)(x-31)(x-95)=0")
|
190
|
-
|
191
|
-
a = GSL::Poly.alloc(-120, 274, -225, 85, -15, 1)
|
192
|
-
w = GSL::Poly::Complex::Workspace.alloc(a.size)
|
193
|
-
z = GSL::Poly.complex_solve(a, 6, w)
|
194
|
-
#z = GSL::Poly.complex_solve(a, w)
|
195
|
-
#z = GSL::Poly.complex_solve(a)
|
196
|
-
test_rel(z[0].re, 1.0, 1e-9, "z[0].real, 5th-order polynomial");
|
197
|
-
test_rel(z[0].im, 0.0, 1e-9, "z[0].imag, 5th-order polynomial");
|
198
|
-
test_rel(z[1].re, 2.0, 1e-9, "z[1].real, 5th-order polynomial");
|
199
|
-
test_rel(z[1].im, 0.0, 1e-9, "z[1].imag, 5th-order polynomial");
|
200
|
-
test_rel(z[2].re, 3.0, 1e-9, "z[2].real, 5th-order polynomial");
|
201
|
-
test_rel(z[2].im, 0.0, 1e-9, "z[2].imag, 5th-order polynomial");
|
202
|
-
test_rel(z[3].re, 4.0, 1e-9, "z3.real, 5th-order polynomial");
|
203
|
-
test_rel(z[3].im, 0.0, 1e-9, "z3.imag, 5th-order polynomial");
|
204
|
-
test_rel(z[4].re, 5.0, 1e-9, "z4.real, 5th-order polynomial");
|
205
|
-
test_rel(z[4].im, 0.0, 1e-9, "z4.imag, 5th-order polynomial")
|
206
|
-
|
207
|
-
a = GSL::Poly.alloc(1, 0, 0, 0, 1, 0, 0, 0, 1)
|
208
|
-
w = GSL::Poly::Complex::Workspace.alloc(a.size)
|
209
|
-
c = 0.5
|
210
|
-
s = sqrt(3)/2
|
211
|
-
z = GSL::Poly.complex_solve(a, w)
|
212
|
-
test_rel(z[0].re, -s, 1e-9, "z[0].real, 8th-order polynomial");
|
213
|
-
test_rel(z[0].im, c, 1e-9, "z[0].imag, 8th-order polynomial");
|
214
|
-
test_rel(z[1].re, -s, 1e-9, "z[1].real, 8th-order polynomial");
|
215
|
-
test_rel(z[1].im, -c, 1e-9, "z[1].imag, 8th-order polynomial");
|
216
|
-
test_rel(z[2].re, -c, 1e-9, "z[2].real, 8th-order polynomial");
|
217
|
-
test_rel(z[2].im, s, 1e-9, "z[2].imag, 8th-order polynomial");
|
218
|
-
test_rel(z[3].re, -c, 1e-9, "z3.real, 8th-order polynomial");
|
219
|
-
test_rel(z[3].im, -s, 1e-9, "z3.imag, 8th-order polynomial");
|
220
|
-
test_rel(z[4].re, c, 1e-9, "z4.real, 8th-order polynomial");
|
221
|
-
test_rel(z[4].im, s, 1e-9, "z4.imag, 8th-order polynomial");
|
222
|
-
test_rel(z[5].re, c, 1e-9, "z5.real, 8th-order polynomial");
|
223
|
-
test_rel(z[5].im, -s, 1e-9, "z5.imag, 8th-order polynomial");
|
224
|
-
test_rel(z[6].re, s, 1e-9, "z6.real, 8th-order polynomial");
|
225
|
-
test_rel(z[6].im, c, 1e-9, "z6.imag, 8th-order polynomial");
|
226
|
-
test_rel(z[7].re, s, 1e-9, "z7.real, 8th-order polynomial");
|
227
|
-
test_rel(z[7].im, -c, 1e-9, "z7.imag, 8th-order polynomial");
|
228
|
-
|
229
|
-
xa = GSL::Poly.alloc(0.16, 0.97, 1.94, 2.74, 3.58, 3.73, 4.70)
|
230
|
-
ya = GSL::Poly.alloc(0.73, 1.11, 1.49, 1.84, 2.30, 2.41, 3.07)
|
231
|
-
dd_expected = GSL::Vector.alloc(7.30000000000000e-01,
|
232
|
-
4.69135802469136e-01,
|
233
|
-
-4.34737219941284e-02,
|
234
|
-
2.68681098870099e-02,
|
235
|
-
-3.22937056934996e-03,
|
236
|
-
6.12763259971375e-03,
|
237
|
-
-6.45402453527083e-03)
|
238
|
-
dd = GSL::Poly.dd_init(xa, ya)
|
239
|
-
|
240
|
-
for i in 0...7
|
241
|
-
GSL::Test::test_rel(dd[i], dd_expected[i], 1e-10, "divided difference dd[#{i}]")
|
242
|
-
end
|
243
|
-
#p dd.class
|
244
|
-
|
245
|
-
for i in 0...7
|
246
|
-
y = dd.eval(xa, xa[i]);
|
247
|
-
test_rel(y, ya[i], 1e-10, "divided difference y[#{i}]");
|
248
|
-
end
|
249
|
-
|
250
|
-
coeff = dd.taylor(1.5, xa)
|
251
|
-
#coeff = dd.taylor(1.5, 7, GSL::Vector.alloc(7))
|
252
|
-
#coeff = dd.taylor(1.5, 7)
|
253
|
-
#coeff = dd.taylor(1.5, GSL::Vector.alloc(7))
|
254
|
-
|
255
|
-
#p coeff.class
|
256
|
-
|
257
|
-
for i in 0...7
|
258
|
-
y = coeff.eval(xa[i] - 1.5)
|
259
|
-
test_rel(y, ya[i], 1e-10, "taylor expansion about 1.5 y[#{i}]");
|
260
|
-
end
|
261
|
-
|
262
|
-
# Added GSL-1.12.90 (gsl-1.13)
|
263
|
-
# gsl_poly_eval_derivs()
|
264
|
-
exit unless GSL::Poly.method_defined?("eval_derivs")
|
265
|
-
|
266
|
-
c = GSL::Vector.alloc([1.0, -2.0, +3.0, -4.0, +5.0, -6.0])
|
267
|
-
x = -0.5
|
268
|
-
|
269
|
-
dc = GSL::Poly.eval_derivs(c, x)
|
270
|
-
|
271
|
-
test_rel(dc[0], c[0] + c[1]*x + c[2]*x*x + c[3]*x*x*x + c[4]*x*x*x*x + c[5]*x*x*x*x*x , eps, "eval_derivs({+1, -2, +3, -4, +5, -6}, 3.75)");
|
272
|
-
test_rel(dc[1], c[1] + 2.0*c[2]*x + 3.0*c[3]*x*x + 4.0*c[4]*x*x*x + 5.0*c[5]*x*x*x*x , eps, "eval_derivs({+1, -2, +3, -4, +5, -6} deriv 1, -12.375)");
|
273
|
-
test_rel(dc[2], 2.0*c[2] + 3.0*2.0*c[3]*x + 4.0*3.0*c[4]*x*x + 5.0*4.0*c[5]*x*x*x , eps, "eval_derivs({+1, -2, +3, -4, +5, -6} deriv 2, +48.0)");
|
274
|
-
test_rel(dc[3], 3.0*2.0*c[3] + 4.0*3.0*2.0*c[4]*x + 5.0*4.0*3.0*c[5]*x*x , eps,"eval_derivs({+1, -2, +3, -4, +5, -6} deriv 3, -174.0)");
|
275
|
-
test_rel(dc[4], 4.0*3.0*2.0*c[4] + 5.0*4.0*3.0*2.0*c[5]*x, eps, "eval_derivs({+1, -2, +3, -4, +5, -6} deriv 4, +480.0)");
|
276
|
-
test_rel(dc[5], 5.0*4.0*3.0*2.0*c[5] , eps, "eval_derivs({+1, -2, +3, -4, +5, -6} deriv 5, -720.0)");
|
277
|
-
|
278
|
-
# Test Poly::fit and Poly::wfit
|
279
|
-
x = GSL::Vector[0, 2, 2]
|
280
|
-
y = GSL::Vector[0, 1, -1]
|
281
|
-
coef, cov, chisq, status = Poly.fit(x, y, 1)
|
282
|
-
test_rel(coef[0], 0.0, 1e-9, "y intercept == 0")
|
283
|
-
test_rel(coef[1], 0.0, 1e-9, "slope == 0")
|
284
|
-
test_rel(chisq, 2.0, 1e-9, "chisq == 2")
|
285
|
-
|
286
|
-
w = GSL::Vector[1, 1, 0]
|
287
|
-
coef, cov, chisq, status = Poly.wfit(x, w, y, 1)
|
288
|
-
test_rel(coef[0], 0.0, 1e-9, "y intercept == 0")
|
289
|
-
test_rel(coef[1], 0.5, 1e-9, "slope == 0.5")
|
290
|
-
test_rel(chisq, 0.0, 1e-9, "chisq == 0")
|
data/tests/poly/special.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require("gsl")
|
3
|
-
require("../gsl_test2.rb")
|
4
|
-
include GSL::Test
|
5
|
-
include Math
|
6
|
-
|
7
|
-
eps = 100.0 * GSL::DBL_EPSILON
|
8
|
-
GSL::IEEE::env_setup()
|
9
|
-
|
10
|
-
HermitPoly = Array[7]
|
11
|
-
HermitPoly[0] = GSL::Poly::Int[1]
|
12
|
-
HermitPoly[0][0] = 1
|
13
|
-
HermitPoly[1] = GSL::Poly::Int[0, 2]
|
14
|
-
HermitPoly[2] = GSL::Poly::Int[-2, 0, 4]
|
15
|
-
HermitPoly[3] = GSL::Poly::Int[0, -12, 0, 8]
|
16
|
-
HermitPoly[4] = GSL::Poly::Int[12, 0, -48, 0, 16]
|
17
|
-
HermitPoly[5] = GSL::Poly::Int[0, 120, 0, -160, 0, 32]
|
18
|
-
HermitPoly[6] = GSL::Poly::Int[-120, 0, 720, 0, -480, 0, 64]
|
19
|
-
|
20
|
-
for n in 0...6 do
|
21
|
-
hn = GSL::Poly.hermite(n)
|
22
|
-
GSL::Test::test2(hn == HermitPoly[n], "Hermite polynomial, n = #{n}")
|
23
|
-
end
|
24
|
-
|
25
|
-
LaguerrePoly = Array[7]
|
26
|
-
LaguerrePoly[0] = GSL::Poly::Int[1]
|
27
|
-
LaguerrePoly[0][0] = 1
|
28
|
-
LaguerrePoly[1] = GSL::Poly::Int[1, -1]
|
29
|
-
LaguerrePoly[2] = GSL::Poly::Int[2, -4, 1]
|
30
|
-
LaguerrePoly[3] = GSL::Poly::Int[6, -18, 9, -1]
|
31
|
-
LaguerrePoly[4] = GSL::Poly::Int[24, -96, 72, -16, 1]
|
32
|
-
LaguerrePoly[5] = GSL::Poly::Int[120, -600, 600, -200, 25, -1]
|
33
|
-
LaguerrePoly[6] = GSL::Poly::Int[720, -4320, 5400, -2400, 450, -36, 1]
|
34
|
-
for n in 0...7 do
|
35
|
-
hn = GSL::Poly.laguerre(n)
|
36
|
-
GSL::Test::test2(hn == LaguerrePoly[n], "Laguerre polynomial, n = #{n}")
|
37
|
-
end
|
38
|
-
|
39
|
-
ChebPoly = Array[7]
|
40
|
-
ChebPoly[0] = GSL::Poly::Int[1]
|
41
|
-
ChebPoly[0][0] = 1
|
42
|
-
ChebPoly[1] = GSL::Poly::Int[0, 1]
|
43
|
-
ChebPoly[2] = GSL::Poly::Int[-1, 0, 2]
|
44
|
-
ChebPoly[3] = GSL::Poly::Int[0, -3, 0, 4]
|
45
|
-
ChebPoly[4] = GSL::Poly::Int[1, 0, -8, 0, 8]
|
46
|
-
ChebPoly[5] = GSL::Poly::Int[0, 5, 0, -20, 0, 16]
|
47
|
-
ChebPoly[6] = GSL::Poly::Int[-1, 0, 18, 0, -48, 0, 32]
|
48
|
-
for n in 0...7 do
|
49
|
-
hn = GSL::Poly.cheb(n)
|
50
|
-
GSL::Test::test2(hn == ChebPoly[n], "Chebyshev polynomial, n = #{n}")
|
51
|
-
end
|
52
|
-
|
53
|
-
Cheb_IIPoly = Array[7]
|
54
|
-
Cheb_IIPoly[0] = GSL::Poly::Int[1]
|
55
|
-
Cheb_IIPoly[0][0] = 1
|
56
|
-
Cheb_IIPoly[1] = GSL::Poly::Int[0, 2]
|
57
|
-
Cheb_IIPoly[2] = GSL::Poly::Int[-1, 0, 4]
|
58
|
-
Cheb_IIPoly[3] = GSL::Poly::Int[0, -4, 0, 8]
|
59
|
-
Cheb_IIPoly[4] = GSL::Poly::Int[1, 0, -12, 0, 16]
|
60
|
-
Cheb_IIPoly[5] = GSL::Poly::Int[0, 6, 0, -32, 0, 32]
|
61
|
-
Cheb_IIPoly[6] = GSL::Poly::Int[-1, 0, 24, 0, -80, 0, 64]
|
62
|
-
for n in 0...7 do
|
63
|
-
hn = GSL::Poly.cheb_II(n)
|
64
|
-
GSL::Test::test2(hn == Cheb_IIPoly[n], "Chebyshev II polynomial, n = #{n}")
|
65
|
-
end
|
data/tests/qrng.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Ruby/GSL implementation of GSL "qrng/test.c"
|
3
|
-
require("gsl")
|
4
|
-
require("./gsl_test2.rb")
|
5
|
-
include GSL::Test
|
6
|
-
include Math
|
7
|
-
|
8
|
-
GSL::IEEE::env_setup()
|
9
|
-
|
10
|
-
def test_sobol()
|
11
|
-
v = GSL::Vector.alloc(3)
|
12
|
-
|
13
|
-
status = 0
|
14
|
-
g = GSL::QRng.alloc(GSL::QRng::SOBOL, 2)
|
15
|
-
g.get(v)
|
16
|
-
g.get(v)
|
17
|
-
g.get(v)
|
18
|
-
status += (v[0] != 0.25 or v[1] != 0.75) ? 1 : 0
|
19
|
-
g.get(v)
|
20
|
-
status += (v[0] != 0.375 or v[1] != 0.375) ? 1 : 0
|
21
|
-
GSL::Test::test(status, "Sobol d=2")
|
22
|
-
|
23
|
-
status = 0
|
24
|
-
g = GSL::QRng.alloc(GSL::QRng::SOBOL, 3)
|
25
|
-
g.get(v)
|
26
|
-
g.get(v)
|
27
|
-
g.get(v)
|
28
|
-
status += (v[0] != 0.25 or v[1] != 0.75) ? 1 : 0
|
29
|
-
g.get(v)
|
30
|
-
status += (v[0] != 0.375 or v[1] != 0.375) ? 1 : 0
|
31
|
-
GSL::Test::test(status, "Sobol d=3")
|
32
|
-
|
33
|
-
status = 0
|
34
|
-
g.init
|
35
|
-
g.get(v)
|
36
|
-
g.get(v)
|
37
|
-
g.get(v)
|
38
|
-
status += (v[0] != 0.25 or v[1] != 0.75) ? 1 : 0
|
39
|
-
g.get(v)
|
40
|
-
status += (v[0] != 0.375 or v[1] != 0.375) ? 1 : 0
|
41
|
-
GSL::Test::test(status, "Sobol d=3 (reinitialized)")
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_nied2()
|
45
|
-
v = GSL::Vector.alloc(3)
|
46
|
-
|
47
|
-
status = 0
|
48
|
-
g = GSL::QRng.alloc(GSL::QRng::NIEDERREITER_2, 2)
|
49
|
-
g.get(v)
|
50
|
-
g.get(v)
|
51
|
-
g.get(v)
|
52
|
-
status += (v[0] != 0.75 or v[1] != 0.25) ? 1 : 0
|
53
|
-
g.get(v)
|
54
|
-
status += (v[0] != 0.25 or v[1] != 0.75) ? 1 : 0
|
55
|
-
g.get(v)
|
56
|
-
g.get(v)
|
57
|
-
g.get(v)
|
58
|
-
status += (v[0] != 0.625 or v[1] != 0.125) ? 1 : 0
|
59
|
-
GSL::Test::test(status, "Niederreiter d=2")
|
60
|
-
|
61
|
-
status = 0
|
62
|
-
g = GSL::QRng.alloc(GSL::QRng::NIEDERREITER_2, 3)
|
63
|
-
g.get(v)
|
64
|
-
g.get(v)
|
65
|
-
g.get(v)
|
66
|
-
status += (v[0] != 0.75 or v[1] != 0.25) ? 1 : 0
|
67
|
-
g.get(v)
|
68
|
-
status += (v[0] != 0.25 or v[1] != 0.75) ? 1 : 0
|
69
|
-
g.get(v)
|
70
|
-
g.get(v)
|
71
|
-
g.get(v)
|
72
|
-
status += (v[0] != 0.625 or v[1] != 0.125) ? 1 : 0
|
73
|
-
GSL::Test::test(status, "Niederreiter d=3")
|
74
|
-
|
75
|
-
status = 0
|
76
|
-
g.init
|
77
|
-
g.get(v)
|
78
|
-
g.get(v)
|
79
|
-
g.get(v)
|
80
|
-
status += (v[0] != 0.75 or v[1] != 0.25) ? 1 : 0
|
81
|
-
g.get(v)
|
82
|
-
status += (v[0] != 0.25 or v[1] != 0.75) ? 1 : 0
|
83
|
-
g.get(v)
|
84
|
-
g.get(v)
|
85
|
-
g.get(v)
|
86
|
-
status += (v[0] != 0.625 or v[1] != 0.125) ? 1 : 0
|
87
|
-
GSL::Test::test(status, "Niederreiter d=3 (reinitialized)")
|
88
|
-
end
|
89
|
-
|
90
|
-
test_sobol()
|
91
|
-
test_nied2()
|
92
|
-
|
93
|
-
# Tests for an extension package "qrngextra"
|
94
|
-
|
95
|
-
exit unless GSL::QRng.const_defined?("HDSOBOL")
|
96
|
-
|
97
|
-
def test_hdsobol()
|
98
|
-
v = GSL::Vector.alloc(3)
|
99
|
-
|
100
|
-
status = 0
|
101
|
-
g = GSL::QRng.alloc(GSL::QRng::HDSOBOL, 2)
|
102
|
-
g.get(v)
|
103
|
-
g.get(v)
|
104
|
-
g.get(v)
|
105
|
-
status += (v[0] != 0.25 or v[1] != 0.75) ? 1 : 0
|
106
|
-
g.get(v)
|
107
|
-
status += (v[0] != 0.375 or v[1] != 0.375) ? 1 : 0
|
108
|
-
GSL::Test::test(status, "HDSobol d=2")
|
109
|
-
|
110
|
-
status = 0
|
111
|
-
g = GSL::QRng.alloc(GSL::QRng::SOBOL, 3)
|
112
|
-
g.get(v)
|
113
|
-
g.get(v)
|
114
|
-
g.get(v)
|
115
|
-
status += (v[0] != 0.25 or v[1] != 0.75 or v[2] != 0.25) ? 1 : 0
|
116
|
-
g.get(v)
|
117
|
-
status += (v[0] != 0.375 or v[1] != 0.375 or v[2] != 0.625) ? 1 : 0
|
118
|
-
GSL::Test::test(status, "HDSobol d=3")
|
119
|
-
|
120
|
-
status = 0
|
121
|
-
g.init
|
122
|
-
g.get(v)
|
123
|
-
g.get(v)
|
124
|
-
g.get(v)
|
125
|
-
status += (v[0] != 0.25 or v[1] != 0.75 or v[2] != 0.25) ? 1 : 0
|
126
|
-
g.get(v)
|
127
|
-
status += (v[0] != 0.375 or v[1] != 0.375 or v[2] != 0.625) ? 1 : 0
|
128
|
-
GSL::Test::test(status, "HDSobol d=3 (reinitialized)")
|
129
|
-
end
|
130
|
-
|
131
|
-
test_hdsobol()
|