rb-gsl 1.16.0.4 → 1.16.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -0
- data/.travis.yml +24 -0
- data/AUTHORS +6 -0
- data/COPYING +341 -339
- data/ChangeLog +608 -587
- data/Gemfile +4 -0
- data/README.md +77 -0
- data/Rakefile +14 -33
- data/THANKS +1 -1
- data/examples/blas/blas.rb +1 -1
- data/examples/bspline.rb +3 -3
- data/examples/complex/functions.rb +4 -4
- data/examples/complex/mul.rb +1 -1
- data/examples/const/physconst.rb +4 -4
- data/examples/const/travel.rb +4 -4
- data/examples/eigen/nonsymmv.rb +1 -1
- data/examples/eigen/qhoscillator.rb +3 -3
- data/examples/fft/radix2.rb +1 -1
- data/examples/fft/real-halfcomplex.rb +3 -3
- data/examples/fft/real-halfcomplex2.rb +3 -3
- data/examples/fit/expfit.rb +1 -1
- data/examples/fit/multifit.rb +1 -1
- data/examples/fit/ndlinear.rb +44 -44
- data/examples/fit/nonlinearfit.rb +1 -1
- data/examples/fit/wlinear.rb +3 -3
- data/examples/function/function.rb +1 -1
- data/examples/function/min.rb +1 -1
- data/examples/function/synchrotron.rb +2 -2
- data/examples/gallery/koch.rb +1 -1
- data/examples/histogram/cauchy.rb +2 -2
- data/examples/histogram/exponential.rb +1 -1
- data/examples/histogram/histo3d.rb +1 -1
- data/examples/histogram/histogram-pdf.rb +2 -2
- data/examples/histogram/xexp.rb +1 -1
- data/examples/integration/ahmed.rb +2 -2
- data/examples/integration/cosmology.rb +7 -7
- data/examples/integration/friedmann.rb +4 -4
- data/examples/integration/qng.rb +1 -1
- data/examples/interp/demo.rb +2 -2
- data/examples/linalg/LQ_solve.rb +1 -1
- data/examples/linalg/LU.rb +1 -1
- data/examples/linalg/LU2.rb +1 -1
- data/examples/linalg/LU_narray.rb +1 -1
- data/examples/linalg/PTLQ.rb +1 -1
- data/examples/linalg/QRPT.rb +1 -1
- data/examples/linalg/chol.rb +1 -1
- data/examples/linalg/chol_narray.rb +1 -1
- data/examples/linalg/complex.rb +1 -1
- data/examples/math/elementary.rb +1 -1
- data/examples/math/functions.rb +1 -1
- data/examples/math/inf_nan.rb +1 -1
- data/examples/math/minmax.rb +1 -1
- data/examples/math/power.rb +1 -1
- data/examples/math/test.rb +1 -1
- data/examples/min.rb +1 -1
- data/examples/multimin/bundle.rb +1 -1
- data/examples/multimin/cqp.rb +17 -17
- data/examples/multiroot/fsolver3.rb +1 -1
- data/examples/odeiv/binarysystem.rb +12 -12
- data/examples/odeiv/demo.rb +3 -3
- data/examples/odeiv/frei1.rb +7 -7
- data/examples/odeiv/frei2.rb +4 -4
- data/examples/odeiv/oscillator.rb +1 -1
- data/examples/odeiv/sedov.rb +3 -3
- data/examples/odeiv/whitedwarf.rb +11 -11
- data/examples/permutation/ex1.rb +2 -2
- data/examples/permutation/permutation.rb +1 -1
- data/examples/poly/demo.rb +1 -1
- data/examples/random/diffusion.rb +1 -1
- data/examples/random/generator.rb +2 -2
- data/examples/random/randomwalk.rb +3 -3
- data/examples/random/rng.rb +1 -1
- data/examples/roots/bisection.rb +1 -1
- data/examples/roots/brent.rb +1 -1
- data/examples/roots/demo.rb +1 -1
- data/examples/roots/newton.rb +2 -2
- data/examples/roots/recombination.gp +0 -1
- data/examples/sf/hyperg.rb +1 -1
- data/examples/sf/sphbessel.rb +1 -1
- data/examples/sort/sort.rb +1 -1
- data/examples/tamu_anova.rb +4 -4
- data/examples/vector/add.rb +1 -1
- data/examples/vector/decimate.rb +1 -1
- data/examples/vector/gnuplot.rb +8 -8
- data/examples/vector/vector.rb +2 -2
- data/examples/wavelet/wavelet1.rb +1 -1
- data/ext/{gsl → gsl_native}/alf.c +9 -9
- data/ext/{gsl → gsl_native}/array.c +64 -151
- data/ext/{gsl → gsl_native}/array_complex.c +61 -63
- data/ext/{gsl → gsl_native}/blas.c +0 -0
- data/ext/{gsl → gsl_native}/blas1.c +32 -32
- data/ext/{gsl → gsl_native}/blas2.c +54 -58
- data/ext/{gsl → gsl_native}/blas3.c +54 -54
- data/ext/{gsl → gsl_native}/block.c +3 -6
- data/ext/{gsl/block_source.c → gsl_native/block_source.h} +109 -111
- data/ext/gsl_native/bspline.c +122 -0
- data/ext/{gsl → gsl_native}/bundle.c +0 -0
- data/ext/{gsl → gsl_native}/cdf.c +76 -88
- data/ext/{gsl → gsl_native}/cheb.c +74 -85
- data/ext/{gsl → gsl_native}/combination.c +9 -16
- data/ext/{gsl → gsl_native}/common.c +7 -37
- data/ext/{gsl → gsl_native}/complex.c +113 -115
- data/ext/gsl_native/const.c +331 -0
- data/ext/{gsl → gsl_native}/const_additional.c +12 -33
- data/ext/gsl_native/cqp.c +283 -0
- data/ext/{gsl → gsl_native}/deriv.c +22 -30
- data/ext/{gsl → gsl_native}/dht.c +20 -28
- data/ext/{gsl → gsl_native}/diff.c +23 -25
- data/ext/{gsl → gsl_native}/dirac.c +44 -45
- data/ext/{gsl → gsl_native}/eigen.c +1031 -1082
- data/ext/{gsl → gsl_native}/error.c +13 -13
- data/ext/{gsl → gsl_native}/extconf.rb +5 -13
- data/ext/{gsl → gsl_native}/fft.c +192 -198
- data/ext/{gsl → gsl_native}/fit.c +16 -16
- data/ext/gsl_native/fresnel.c +312 -0
- data/ext/{gsl → gsl_native}/function.c +29 -35
- data/ext/{gsl → gsl_native}/geometry.c +15 -15
- data/ext/{gsl → gsl_native}/graph.c +37 -87
- data/ext/{gsl → gsl_native}/gsl.c +10 -23
- data/ext/{gsl → gsl_native}/gsl_narray.c +15 -24
- data/ext/{gsl → gsl_native}/histogram.c +123 -150
- data/ext/{gsl → gsl_native}/histogram2d.c +71 -96
- data/ext/{gsl → gsl_native}/histogram3d.c +72 -72
- data/ext/{gsl → gsl_native}/histogram3d_source.c +195 -196
- data/ext/{gsl → gsl_native}/histogram_find.c +31 -33
- data/ext/{gsl → gsl_native}/histogram_oper.c +43 -52
- data/ext/{gsl → gsl_native}/ieee.c +7 -15
- data/ext/{gsl → gsl_native}/include/rb_gsl.h +0 -7
- data/ext/{gsl → gsl_native}/include/rb_gsl_array.h +15 -25
- data/ext/{gsl → gsl_native}/include/rb_gsl_cheb.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_common.h +44 -52
- data/ext/{gsl → gsl_native}/include/rb_gsl_complex.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_const.h +0 -5
- data/ext/{gsl → gsl_native}/include/rb_gsl_dirac.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_eigen.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_fft.h +0 -3
- data/ext/{gsl → gsl_native}/include/rb_gsl_fit.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_function.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_graph.h +2 -2
- data/ext/{gsl → gsl_native}/include/rb_gsl_histogram.h +8 -8
- data/ext/{gsl → gsl_native}/include/rb_gsl_histogram3d.h +50 -50
- data/ext/{gsl → gsl_native}/include/rb_gsl_integration.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_interp.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_linalg.h +0 -1
- data/ext/{gsl → gsl_native}/include/rb_gsl_math.h +0 -4
- data/ext/{gsl → gsl_native}/include/rb_gsl_odeiv.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_poly.h +3 -3
- data/ext/{gsl → gsl_native}/include/rb_gsl_rational.h +1 -1
- data/ext/{gsl → gsl_native}/include/rb_gsl_rng.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_root.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_sf.h +39 -43
- data/ext/{gsl → gsl_native}/include/rb_gsl_statistics.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_tensor.h +0 -0
- data/ext/{gsl → gsl_native}/include/rb_gsl_with_narray.h +0 -0
- data/ext/{gsl → gsl_native}/include/templates_off.h +0 -0
- data/ext/{gsl → gsl_native}/include/templates_on.h +1 -1
- data/ext/{gsl → gsl_native}/integration.c +160 -183
- data/ext/{gsl → gsl_native}/interp.c +23 -31
- data/ext/gsl_native/jacobi.c +733 -0
- data/ext/{gsl → gsl_native}/linalg.c +448 -576
- data/ext/{gsl → gsl_native}/linalg_complex.c +84 -98
- data/ext/{gsl → gsl_native}/math.c +45 -63
- data/ext/{gsl → gsl_native}/matrix.c +4 -6
- data/ext/{gsl → gsl_native}/matrix_complex.c +111 -114
- data/ext/{gsl → gsl_native}/matrix_double.c +74 -77
- data/ext/{gsl → gsl_native}/matrix_int.c +49 -50
- data/ext/{gsl/matrix_source.c → gsl_native/matrix_source.h} +280 -302
- data/ext/{gsl → gsl_native}/min.c +43 -74
- data/ext/{gsl → gsl_native}/monte.c +45 -59
- data/ext/{gsl → gsl_native}/multifit.c +138 -147
- data/ext/{gsl → gsl_native}/multimin.c +55 -83
- data/ext/{gsl → gsl_native}/multimin_fsdf.c +15 -15
- data/ext/{gsl → gsl_native}/multiroots.c +61 -64
- data/ext/{gsl → gsl_native}/multiset.c +3 -7
- data/ext/{gsl → gsl_native}/ndlinear.c +320 -321
- data/ext/{gsl → gsl_native}/nmf.c +11 -11
- data/ext/{gsl → gsl_native}/nmf_wrap.c +1 -1
- data/ext/{gsl → gsl_native}/ntuple.c +13 -13
- data/ext/{gsl → gsl_native}/odeiv.c +95 -106
- data/ext/gsl_native/ool.c +879 -0
- data/ext/{gsl → gsl_native}/permutation.c +36 -34
- data/ext/{gsl → gsl_native}/poly.c +2 -5
- data/ext/{gsl → gsl_native}/poly2.c +6 -6
- data/ext/{gsl/poly_source.c → gsl_native/poly_source.h} +232 -275
- data/ext/{gsl → gsl_native}/qrng.c +6 -17
- data/ext/{gsl → gsl_native}/randist.c +218 -243
- data/ext/{gsl → gsl_native}/rational.c +9 -9
- data/ext/{gsl → gsl_native}/rng.c +29 -45
- data/ext/{gsl → gsl_native}/root.c +43 -43
- data/ext/{gsl → gsl_native}/sf.c +163 -197
- data/ext/{gsl → gsl_native}/sf_airy.c +0 -0
- data/ext/{gsl → gsl_native}/sf_bessel.c +6 -6
- data/ext/{gsl → gsl_native}/sf_clausen.c +0 -0
- data/ext/{gsl → gsl_native}/sf_coulomb.c +39 -39
- data/ext/{gsl → gsl_native}/sf_coupling.c +29 -29
- data/ext/{gsl → gsl_native}/sf_dawson.c +0 -0
- data/ext/{gsl → gsl_native}/sf_debye.c +0 -9
- data/ext/{gsl → gsl_native}/sf_dilog.c +0 -0
- data/ext/{gsl → gsl_native}/sf_elementary.c +2 -2
- data/ext/{gsl → gsl_native}/sf_ellint.c +42 -42
- data/ext/{gsl → gsl_native}/sf_elljac.c +2 -2
- data/ext/{gsl → gsl_native}/sf_erfc.c +0 -4
- data/ext/{gsl → gsl_native}/sf_exp.c +2 -2
- data/ext/{gsl → gsl_native}/sf_expint.c +1 -11
- data/ext/{gsl → gsl_native}/sf_fermi_dirac.c +0 -0
- data/ext/{gsl → gsl_native}/sf_gamma.c +1 -5
- data/ext/{gsl → gsl_native}/sf_gegenbauer.c +0 -0
- data/ext/{gsl → gsl_native}/sf_hyperg.c +0 -0
- data/ext/{gsl → gsl_native}/sf_laguerre.c +3 -3
- data/ext/{gsl → gsl_native}/sf_lambert.c +0 -0
- data/ext/{gsl → gsl_native}/sf_legendre.c +0 -0
- data/ext/{gsl → gsl_native}/sf_log.c +3 -3
- data/ext/gsl_native/sf_mathieu.c +235 -0
- data/ext/{gsl → gsl_native}/sf_power.c +0 -0
- data/ext/{gsl → gsl_native}/sf_psi.c +2 -11
- data/ext/{gsl → gsl_native}/sf_synchrotron.c +0 -0
- data/ext/{gsl → gsl_native}/sf_transport.c +0 -0
- data/ext/{gsl → gsl_native}/sf_trigonometric.c +3 -3
- data/ext/{gsl → gsl_native}/sf_zeta.c +0 -4
- data/ext/{gsl → gsl_native}/signal.c +60 -64
- data/ext/{gsl → gsl_native}/siman.c +36 -40
- data/ext/{gsl → gsl_native}/sort.c +3 -4
- data/ext/{gsl → gsl_native}/spline.c +25 -43
- data/ext/{gsl → gsl_native}/stats.c +102 -115
- data/ext/{gsl → gsl_native}/sum.c +32 -32
- data/ext/{gsl → gsl_native}/tamu_anova.c +0 -0
- data/ext/{gsl → gsl_native}/tensor.c +2 -4
- data/ext/{gsl/tensor_source.c → gsl_native/tensor_source.h} +144 -144
- data/ext/{gsl → gsl_native}/vector.c +2 -4
- data/ext/{gsl → gsl_native}/vector_complex.c +165 -171
- data/ext/{gsl → gsl_native}/vector_double.c +167 -174
- data/ext/{gsl → gsl_native}/vector_int.c +23 -25
- data/ext/{gsl/vector_source.c → gsl_native/vector_source.h} +400 -414
- data/ext/{gsl → gsl_native}/wavelet.c +215 -236
- data/lib/gsl.rb +1 -7
- data/lib/gsl/gnuplot.rb +2 -2
- data/lib/gsl/version.rb +1 -3
- data/rb-gsl.gemspec +29 -0
- data/rdoc/blas.rdoc +3 -3
- data/rdoc/bspline.rdoc +7 -7
- data/rdoc/cheb.rdoc +8 -8
- data/rdoc/cholesky_complex.rdoc +1 -1
- data/rdoc/combi.rdoc +9 -9
- data/rdoc/complex.rdoc +11 -11
- data/rdoc/const.rdoc +20 -20
- data/rdoc/dht.rdoc +6 -6
- data/rdoc/diff.rdoc +6 -6
- data/rdoc/ehandling.rdoc +3 -3
- data/rdoc/eigen.rdoc +11 -11
- data/rdoc/fft.rdoc +26 -26
- data/rdoc/fit.rdoc +18 -18
- data/rdoc/graph.rdoc +2 -2
- data/rdoc/hist.rdoc +16 -16
- data/rdoc/hist2d.rdoc +4 -4
- data/rdoc/hist3d.rdoc +3 -3
- data/rdoc/integration.rdoc +16 -16
- data/rdoc/interp.rdoc +11 -11
- data/rdoc/intro.rdoc +3 -3
- data/rdoc/linalg.rdoc +20 -20
- data/rdoc/linalg_complex.rdoc +1 -1
- data/rdoc/math.rdoc +13 -13
- data/rdoc/matrix.rdoc +22 -22
- data/rdoc/min.rdoc +9 -9
- data/rdoc/monte.rdoc +3 -3
- data/rdoc/multimin.rdoc +12 -12
- data/rdoc/multiroot.rdoc +12 -12
- data/rdoc/narray.rdoc +9 -9
- data/rdoc/ndlinear.rdoc +4 -4
- data/rdoc/nonlinearfit.rdoc +17 -17
- data/rdoc/ntuple.rdoc +5 -5
- data/rdoc/odeiv.rdoc +12 -12
- data/rdoc/perm.rdoc +11 -11
- data/rdoc/poly.rdoc +17 -17
- data/rdoc/qrng.rdoc +9 -9
- data/rdoc/randist.rdoc +10 -10
- data/rdoc/ref.rdoc +49 -49
- data/rdoc/rng.rdoc +9 -9
- data/rdoc/roots.rdoc +12 -12
- data/rdoc/sf.rdoc +35 -35
- data/rdoc/siman.rdoc +3 -3
- data/rdoc/sort.rdoc +6 -6
- data/rdoc/start.rdoc +2 -2
- data/rdoc/stats.rdoc +13 -13
- data/rdoc/sum.rdoc +4 -4
- data/rdoc/tensor.rdoc +3 -3
- data/rdoc/tut.rdoc +1 -1
- data/rdoc/use.rdoc +3 -3
- data/rdoc/vector.rdoc +28 -28
- data/rdoc/vector_complex.rdoc +6 -6
- data/rdoc/wavelet.rdoc +8 -8
- data/test/gsl/blas_test.rb +1 -1
- data/test/gsl/index_test.rb +61 -0
- data/test/gsl/matrix_test.rb +21 -0
- data/uncrustify.cfg +1693 -0
- metadata +212 -243
- data/README +0 -28
- data/ext/gsl/bspline.c +0 -130
- data/ext/gsl/const.c +0 -672
- data/ext/gsl/cqp.c +0 -283
- data/ext/gsl/fcmp.c +0 -64
- data/ext/gsl/fresnel.c +0 -312
- data/ext/gsl/jacobi.c +0 -739
- data/ext/gsl/ool.c +0 -879
- data/ext/gsl/oper_complex_source.c +0 -251
- data/ext/gsl/sf_mathieu.c +0 -238
- data/rdoc/index.rdoc +0 -50
@@ -14,9 +14,7 @@
|
|
14
14
|
#include "include/rb_gsl_histogram.h"
|
15
15
|
#include "include/rb_gsl_complex.h"
|
16
16
|
#include "include/rb_gsl_poly.h"
|
17
|
-
#ifdef HAVE_NARRAY_H
|
18
17
|
#include "include/rb_gsl_with_narray.h"
|
19
|
-
#endif
|
20
18
|
|
21
19
|
VALUE rb_gsl_vector_inner_product(int argc, VALUE *argv, VALUE obj);
|
22
20
|
static VALUE rb_gsl_vector_product_to_m(int argc, VALUE *argv, VALUE obj);
|
@@ -24,7 +22,7 @@ VALUE rb_gsl_vector_int_to_f(VALUE obj);
|
|
24
22
|
VALUE rb_ary_to_gv(VALUE klass, VALUE ary);
|
25
23
|
|
26
24
|
static VALUE rb_gsl_vector_Xspace(double min, double max, int i,
|
27
|
-
|
25
|
+
gsl_vector* (*f)(const double, const double, const size_t))
|
28
26
|
{
|
29
27
|
gsl_vector *v = NULL;
|
30
28
|
size_t n;
|
@@ -35,8 +33,8 @@ static VALUE rb_gsl_vector_Xspace(double min, double max, int i,
|
|
35
33
|
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
|
36
34
|
}
|
37
35
|
|
38
|
-
static gsl_vector* gsl_vector_linspace(const double min,
|
39
|
-
|
36
|
+
static gsl_vector* gsl_vector_linspace(const double min,
|
37
|
+
const double max, const size_t n)
|
40
38
|
{
|
41
39
|
gsl_vector *v = NULL;
|
42
40
|
double dx;
|
@@ -53,8 +51,8 @@ static gsl_vector* gsl_vector_linspace(const double min,
|
|
53
51
|
return v;
|
54
52
|
}
|
55
53
|
|
56
|
-
static gsl_vector* gsl_vector_logspace(const double min,
|
57
|
-
|
54
|
+
static gsl_vector* gsl_vector_logspace(const double min,
|
55
|
+
const double max, const size_t n)
|
58
56
|
{
|
59
57
|
gsl_vector *v = NULL;
|
60
58
|
double dx;
|
@@ -86,9 +84,9 @@ static VALUE rb_gsl_vector_linspace(int argc, VALUE *argv, VALUE klass)
|
|
86
84
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
87
85
|
break;
|
88
86
|
}
|
89
|
-
Need_Float(argv[0]); Need_Float(argv[1]);
|
87
|
+
Need_Float(argv[0]); Need_Float(argv[1]);
|
90
88
|
return rb_gsl_vector_Xspace(NUM2DBL(argv[0]), NUM2DBL(argv[1]), n,
|
91
|
-
|
89
|
+
gsl_vector_linspace);
|
92
90
|
}
|
93
91
|
|
94
92
|
static VALUE rb_gsl_vector_logspace(int argc, VALUE *argv, VALUE klass)
|
@@ -106,9 +104,9 @@ static VALUE rb_gsl_vector_logspace(int argc, VALUE *argv, VALUE klass)
|
|
106
104
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
107
105
|
break;
|
108
106
|
}
|
109
|
-
Need_Float(argv[0]); Need_Float(argv[1]);
|
107
|
+
Need_Float(argv[0]); Need_Float(argv[1]);
|
110
108
|
return rb_gsl_vector_Xspace(NUM2DBL(argv[0]), NUM2DBL(argv[1]), n,
|
111
|
-
|
109
|
+
gsl_vector_logspace);
|
112
110
|
}
|
113
111
|
|
114
112
|
static VALUE rb_gsl_vector_logspace2(int argc, VALUE *argv, VALUE klass)
|
@@ -126,10 +124,10 @@ static VALUE rb_gsl_vector_logspace2(int argc, VALUE *argv, VALUE klass)
|
|
126
124
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
127
125
|
break;
|
128
126
|
}
|
129
|
-
Need_Float(argv[0]); Need_Float(argv[1]);
|
130
|
-
return rb_gsl_vector_Xspace(log10(NUM2DBL(argv[0])),
|
131
|
-
|
132
|
-
|
127
|
+
Need_Float(argv[0]); Need_Float(argv[1]);
|
128
|
+
return rb_gsl_vector_Xspace(log10(NUM2DBL(argv[0])),
|
129
|
+
log10(NUM2DBL(argv[1])), n,
|
130
|
+
gsl_vector_logspace);
|
133
131
|
}
|
134
132
|
|
135
133
|
/********************************************************/
|
@@ -144,7 +142,7 @@ enum {
|
|
144
142
|
GSL_VECTOR_DIV,
|
145
143
|
};
|
146
144
|
|
147
|
-
static VALUE rb_gsl_vector_arithmetics(int flag, VALUE obj, VALUE bb)
|
145
|
+
static VALUE rb_gsl_vector_arithmetics(int flag, VALUE obj, VALUE bb)
|
148
146
|
{
|
149
147
|
gsl_vector *v = NULL, *vnew = NULL, *b = NULL;
|
150
148
|
gsl_vector_complex *cvnew = NULL, *cb = NULL;
|
@@ -171,9 +169,9 @@ static VALUE rb_gsl_vector_arithmetics(int flag, VALUE obj, VALUE bb)
|
|
171
169
|
gsl_vector_scale(vnew, 1.0/NUM2DBL(bb));
|
172
170
|
break;
|
173
171
|
}
|
174
|
-
if (!VECTOR_VIEW_P(obj))
|
172
|
+
if (!VECTOR_VIEW_P(obj))
|
175
173
|
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_vector_free, vnew);
|
176
|
-
else
|
174
|
+
else
|
177
175
|
return Data_Wrap_Struct(VECTOR_ROW_COL(obj), 0, gsl_vector_free, vnew);
|
178
176
|
break;
|
179
177
|
default:
|
@@ -182,68 +180,68 @@ static VALUE rb_gsl_vector_arithmetics(int flag, VALUE obj, VALUE bb)
|
|
182
180
|
Data_Get_Struct(bb, gsl_vector, b);
|
183
181
|
switch (flag) {
|
184
182
|
case GSL_VECTOR_ADD:
|
185
|
-
|
186
|
-
|
187
|
-
|
183
|
+
vnew = make_vector_clone(v);
|
184
|
+
gsl_vector_add(vnew, b);
|
185
|
+
break;
|
188
186
|
case GSL_VECTOR_SUB:
|
189
|
-
|
190
|
-
|
191
|
-
|
187
|
+
vnew = make_vector_clone(v);
|
188
|
+
gsl_vector_sub(vnew, b);
|
189
|
+
break;
|
192
190
|
case GSL_VECTOR_MUL:
|
193
|
-
|
194
|
-
|
195
|
-
|
191
|
+
vnew = make_vector_clone(v);
|
192
|
+
gsl_vector_mul(vnew, b);
|
193
|
+
break;
|
196
194
|
case GSL_VECTOR_DIV:
|
197
|
-
|
198
|
-
|
199
|
-
|
195
|
+
vnew = make_vector_clone(v);
|
196
|
+
gsl_vector_div(vnew, b);
|
197
|
+
break;
|
200
198
|
}
|
201
|
-
if (!VECTOR_VIEW_P(obj))
|
202
|
-
|
203
|
-
else
|
204
|
-
|
199
|
+
if (!VECTOR_VIEW_P(obj))
|
200
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_vector_free, vnew);
|
201
|
+
else
|
202
|
+
return Data_Wrap_Struct(VECTOR_ROW_COL(obj), 0, gsl_vector_free, vnew);
|
205
203
|
} else if (VECTOR_COMPLEX_P(bb)) {
|
206
204
|
Data_Get_Struct(bb, gsl_vector_complex, cb);
|
207
205
|
cvnew = vector_to_complex(v);
|
208
206
|
switch (flag) {
|
209
207
|
case GSL_VECTOR_ADD:
|
210
|
-
|
211
|
-
|
208
|
+
gsl_vector_complex_add(cvnew, cb);
|
209
|
+
break;
|
212
210
|
case GSL_VECTOR_SUB:
|
213
|
-
|
214
|
-
|
211
|
+
gsl_vector_complex_sub(cvnew, cb);
|
212
|
+
break;
|
215
213
|
case GSL_VECTOR_MUL:
|
216
|
-
|
217
|
-
|
214
|
+
gsl_vector_complex_mul(cvnew, cb);
|
215
|
+
break;
|
218
216
|
case GSL_VECTOR_DIV:
|
219
|
-
|
220
|
-
|
217
|
+
gsl_vector_complex_div(cvnew, cb);
|
218
|
+
break;
|
221
219
|
}
|
222
220
|
if (VECTOR_COL_P(obj))
|
223
|
-
|
221
|
+
return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, cvnew);
|
224
222
|
else
|
225
|
-
|
223
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cvnew);
|
226
224
|
} else if (COMPLEX_P(bb)) {
|
227
225
|
Data_Get_Struct(bb, gsl_complex, c);
|
228
226
|
cvnew = vector_to_complex(v);
|
229
227
|
switch (flag) {
|
230
228
|
case GSL_VECTOR_ADD:
|
231
|
-
|
232
|
-
|
229
|
+
gsl_vector_complex_add_constant(cvnew, *c);
|
230
|
+
break;
|
233
231
|
case GSL_VECTOR_SUB:
|
234
|
-
|
235
|
-
|
232
|
+
gsl_vector_complex_add_constant(cvnew, gsl_complex_negative(*c));
|
233
|
+
break;
|
236
234
|
case GSL_VECTOR_MUL:
|
237
|
-
|
238
|
-
|
235
|
+
gsl_vector_complex_scale(cvnew, *c);
|
236
|
+
break;
|
239
237
|
case GSL_VECTOR_DIV:
|
240
|
-
|
241
|
-
|
238
|
+
gsl_vector_complex_scale(cvnew, gsl_complex_inverse(*c));
|
239
|
+
break;
|
242
240
|
}
|
243
|
-
if (VECTOR_COL_P(obj))
|
244
|
-
|
241
|
+
if (VECTOR_COL_P(obj))
|
242
|
+
return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, cvnew);
|
245
243
|
else
|
246
|
-
|
244
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cvnew);
|
247
245
|
} else {
|
248
246
|
rb_raise(rb_eTypeError, "wrong type argument %s", rb_class2name(CLASS_OF(bb)));
|
249
247
|
}
|
@@ -412,17 +410,17 @@ static VALUE rb_gsl_vector_coerce(VALUE obj, VALUE other)
|
|
412
410
|
cv = gsl_vector_complex_alloc(v->size);
|
413
411
|
if (cv == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
|
414
412
|
gsl_vector_complex_set_all(cv, *c);
|
415
|
-
if (VECTOR_ROW_P(obj))
|
416
|
-
|
413
|
+
if (VECTOR_ROW_P(obj))
|
414
|
+
vv = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cv);
|
417
415
|
else
|
418
|
-
|
416
|
+
vv = Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, cv);
|
419
417
|
return rb_ary_new3(2, vv, obj);
|
420
418
|
} else if (VECTOR_COMPLEX_P(other)) {
|
421
419
|
cv = vector_to_complex(v);
|
422
|
-
if (VECTOR_ROW_P(obj))
|
423
|
-
|
420
|
+
if (VECTOR_ROW_P(obj))
|
421
|
+
vv = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cv);
|
424
422
|
else
|
425
|
-
|
423
|
+
vv = Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, cv);
|
426
424
|
return rb_ary_new3(2, other, vv);
|
427
425
|
} else {
|
428
426
|
rb_raise(rb_eTypeError, "cannot coerced");
|
@@ -442,25 +440,25 @@ static VALUE rb_gsl_vector_product_to_m(int argc, VALUE *argv, VALUE obj)
|
|
442
440
|
case T_CLASS:
|
443
441
|
case T_OBJECT:
|
444
442
|
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
445
|
-
|
443
|
+
argc);
|
446
444
|
if (!VECTOR_COL_P(argv[0]))
|
447
445
|
rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Col expected)",
|
448
|
-
|
446
|
+
rb_class2name(CLASS_OF(argv[0])));
|
449
447
|
if (!VECTOR_ROW_P(argv[1]))
|
450
448
|
rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector expected)",
|
451
|
-
|
449
|
+
rb_class2name(CLASS_OF(argv[1])));
|
452
450
|
Data_Get_Struct(argv[0], gsl_vector, v);
|
453
451
|
Data_Get_Struct(argv[1], gsl_vector, v2);
|
454
452
|
break;
|
455
453
|
default:
|
456
454
|
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
457
|
-
|
455
|
+
argc);
|
458
456
|
if (!VECTOR_COL_P(obj))
|
459
457
|
rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Col expected)",
|
460
|
-
|
458
|
+
rb_class2name(CLASS_OF(obj)));
|
461
459
|
if (!VECTOR_ROW_P(argv[0]))
|
462
460
|
rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector expected)",
|
463
|
-
|
461
|
+
rb_class2name(CLASS_OF(argv[0])));
|
464
462
|
Data_Get_Struct(obj, gsl_vector, v);
|
465
463
|
Data_Get_Struct(argv[0], gsl_vector, v2);
|
466
464
|
break;
|
@@ -491,7 +489,7 @@ VALUE rb_gsl_vector_to_i(VALUE obj)
|
|
491
489
|
val = (int) gsl_vector_get(v, i);
|
492
490
|
gsl_vector_int_set(vi, i, val);
|
493
491
|
}
|
494
|
-
if (VECTOR_COL_P(obj))
|
492
|
+
if (VECTOR_COL_P(obj))
|
495
493
|
return Data_Wrap_Struct(cgsl_vector_int_col, 0, gsl_vector_int_free, vi);
|
496
494
|
else
|
497
495
|
return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, vi);
|
@@ -503,9 +501,21 @@ static void draw_hist(VALUE obj, FILE *fp);
|
|
503
501
|
static void draw_vector(VALUE obj, FILE *fp);
|
504
502
|
static void draw_vector2(VALUE xx, VALUE yy, FILE *fp);
|
505
503
|
static void draw_vector_array(VALUE ary, FILE *fp);
|
504
|
+
|
506
505
|
#ifdef HAVE_NARRAY_H
|
507
|
-
static void draw_narray(VALUE obj, FILE *fp)
|
506
|
+
static void draw_narray(VALUE obj, FILE *fp)
|
507
|
+
{
|
508
|
+
struct NARRAY *na;
|
509
|
+
double *ptr;
|
510
|
+
size_t j;
|
511
|
+
GetNArray(obj, na);
|
512
|
+
ptr = (double *) na->ptr;
|
513
|
+
for (j = 0; j < na->total; j++)
|
514
|
+
fprintf(fp, "%d %g\n", (int) j, ptr[j]);
|
515
|
+
fflush(fp);
|
516
|
+
}
|
508
517
|
#endif // HAVE_NARRAY_H
|
518
|
+
|
509
519
|
#endif // HAVE_GNU_GRAPH
|
510
520
|
|
511
521
|
static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
@@ -520,7 +530,6 @@ static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
|
520
530
|
FILE *fp = NULL;
|
521
531
|
if (argc < 1)
|
522
532
|
rb_raise(rb_eArgError, "two few arguments");
|
523
|
-
|
524
533
|
if (TYPE(argv[argc-1]) == T_STRING) {
|
525
534
|
sprintf(command, "graph -T X %s", STR2CSTR(argv[argc-1]));
|
526
535
|
iend = argc-1;
|
@@ -528,7 +537,6 @@ static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
|
528
537
|
strcpy(command, "graph -T X -C -g 3");
|
529
538
|
iend = argc;
|
530
539
|
}
|
531
|
-
|
532
540
|
if (iend == 1) {
|
533
541
|
fp = popen(command, "w");
|
534
542
|
if (fp == NULL) rb_raise(rb_eIOError, "GNU graph not found.");
|
@@ -544,8 +552,8 @@ static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
|
544
552
|
#endif
|
545
553
|
} else {
|
546
554
|
if (fp) pclose(fp);
|
547
|
-
rb_raise(rb_eTypeError, "wrong argument type %s",
|
548
|
-
|
555
|
+
rb_raise(rb_eTypeError, "wrong argument type %s",
|
556
|
+
rb_class2name(CLASS_OF(argv[0])));
|
549
557
|
}
|
550
558
|
if (fp) pclose(fp);
|
551
559
|
return Qtrue;
|
@@ -562,7 +570,7 @@ static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
|
562
570
|
x = gsl_vector_alloc(h->n);
|
563
571
|
n = x->size;
|
564
572
|
for (j = 0; j < x->size; j++)
|
565
|
-
|
573
|
+
gsl_vector_set(x, j, h->range[j]);
|
566
574
|
flag = 1;
|
567
575
|
draw_hist(argv[0], fp);
|
568
576
|
fprintf(fp, "\n");
|
@@ -578,26 +586,26 @@ static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
|
578
586
|
} else if (NIL_P(argv[0])) {
|
579
587
|
if (argc < 2) rb_raise(rb_eArgError, "too few arguments");
|
580
588
|
if (VECTOR_P(argv[1])) {
|
581
|
-
|
582
|
-
|
589
|
+
Data_Get_Struct(argv[1], gsl_vector, y);
|
590
|
+
n = y->size;
|
583
591
|
} else if (HISTOGRAM_P(argv[1])) {
|
584
|
-
|
585
|
-
|
592
|
+
Data_Get_Struct(argv[1], gsl_histogram, h);
|
593
|
+
n = h->n;
|
586
594
|
#ifdef HAVE_NARRAY_H
|
587
595
|
} else if (NA_IsNArray(argv[1])) {
|
588
|
-
|
596
|
+
n = NA_TOTAL(argv[1]);
|
589
597
|
#endif
|
590
598
|
} else {
|
591
|
-
|
592
|
-
|
599
|
+
rb_raise(rb_eTypeError, "wrong argument type %s",
|
600
|
+
rb_class2name(CLASS_OF(argv[0])));
|
593
601
|
}
|
594
602
|
x = gsl_vector_alloc(n);
|
595
603
|
for (j = 0; j < n; j++) gsl_vector_set(x, j, (double) j);
|
596
604
|
flag = 1;
|
597
605
|
} else {
|
598
606
|
if (fp) pclose(fp);
|
599
|
-
rb_raise(rb_eTypeError, "wrong argument type %s",
|
600
|
-
|
607
|
+
rb_raise(rb_eTypeError, "wrong argument type %s",
|
608
|
+
rb_class2name(CLASS_OF(argv[0])));
|
601
609
|
}
|
602
610
|
if (flag == 1) vx = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, x);
|
603
611
|
for (i = 1; i < iend; i++) {
|
@@ -607,9 +615,9 @@ static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
|
607
615
|
#ifdef HAVE_NARRAY_H
|
608
616
|
else if (NA_IsNArray(argv[i])) draw_vector2(vx, argv[i], fp);
|
609
617
|
#endif
|
610
|
-
else
|
611
|
-
|
612
|
-
|
618
|
+
else
|
619
|
+
rb_raise(rb_eTypeError, "wrong argument type %s",
|
620
|
+
rb_class2name(CLASS_OF(argv[i])));
|
613
621
|
fprintf(fp, "\n");
|
614
622
|
fflush(fp);
|
615
623
|
}
|
@@ -636,9 +644,6 @@ static void draw_vector(VALUE obj, FILE *fp)
|
|
636
644
|
|
637
645
|
static void draw_vector2(VALUE xx, VALUE yy, FILE *fp)
|
638
646
|
{
|
639
|
-
#ifdef HAVE_NARRAY_H
|
640
|
-
struct NARRAY *nax, *nay;
|
641
|
-
#endif // HAVE_NARRAY_H
|
642
647
|
double *ptr1 = NULL, *ptr2 = NULL;
|
643
648
|
gsl_vector *vx, *vy;
|
644
649
|
size_t j, n, stridex = 1, stridey = 1;
|
@@ -649,6 +654,7 @@ static void draw_vector2(VALUE xx, VALUE yy, FILE *fp)
|
|
649
654
|
stridex = vx->stride;
|
650
655
|
#ifdef HAVE_NARRAY_H
|
651
656
|
} else if (NA_IsNArray(xx)) {
|
657
|
+
struct NARRAY *nax;
|
652
658
|
GetNArray(xx, nax);
|
653
659
|
ptr1 = (double *) nax->ptr;
|
654
660
|
n = nax->total;
|
@@ -656,7 +662,7 @@ static void draw_vector2(VALUE xx, VALUE yy, FILE *fp)
|
|
656
662
|
#endif // HAVE_NARRAY_H
|
657
663
|
} else {
|
658
664
|
rb_raise(rb_eTypeError, "wrong argument type %s (Vector expected)",
|
659
|
-
|
665
|
+
rb_class2name(CLASS_OF(xx)));
|
660
666
|
}
|
661
667
|
if (VECTOR_P(yy)) {
|
662
668
|
Data_Get_Struct(yy, gsl_vector, vy);
|
@@ -665,41 +671,28 @@ static void draw_vector2(VALUE xx, VALUE yy, FILE *fp)
|
|
665
671
|
stridey = vy->stride;
|
666
672
|
#ifdef HAVE_NARRAY_H
|
667
673
|
} else if (NA_IsNArray(yy)) {
|
674
|
+
struct NARRAY *nay;
|
668
675
|
GetNArray(yy, nay);
|
669
676
|
ptr2 = (double *) nay->ptr;
|
670
677
|
stridey = 1;
|
671
678
|
#endif // HAVE_NARRAY_H
|
672
679
|
} else {
|
673
680
|
rb_raise(rb_eTypeError, "wrong argument type %s (Vector expected)",
|
674
|
-
|
681
|
+
rb_class2name(CLASS_OF(yy)));
|
675
682
|
}
|
676
683
|
for (j = 0; j < n; j++)
|
677
684
|
fprintf(fp, "%g %g\n", ptr1[j*stridex], ptr2[j*stridey]);
|
678
685
|
fflush(fp);
|
679
686
|
}
|
680
687
|
|
681
|
-
#ifdef HAVE_NARRAY_H
|
682
|
-
static void draw_narray(VALUE obj, FILE *fp)
|
683
|
-
{
|
684
|
-
struct NARRAY *na;
|
685
|
-
double *ptr;
|
686
|
-
size_t j;
|
687
|
-
GetNArray(obj, na);
|
688
|
-
ptr = (double *) na->ptr;
|
689
|
-
for (j = 0; j < na->total; j++)
|
690
|
-
fprintf(fp, "%d %g\n", (int) j, ptr[j]);
|
691
|
-
fflush(fp);
|
692
|
-
}
|
693
|
-
#endif // HAVE_NARRAY_H
|
694
|
-
|
695
688
|
static void draw_hist(VALUE obj, FILE *fp)
|
696
689
|
{
|
697
690
|
gsl_histogram *h = NULL;
|
698
691
|
size_t j;
|
699
692
|
Data_Get_Struct(obj, gsl_histogram, h);
|
700
693
|
for (j = 0; j < h->n; j++) {
|
701
|
-
fprintf(fp, "%g %g\n%g %g\n",
|
702
|
-
|
694
|
+
fprintf(fp, "%g %g\n%g %g\n",
|
695
|
+
h->range[j], h->bin[j], h->range[j+1], h->bin[j]);
|
703
696
|
}
|
704
697
|
fflush(fp);
|
705
698
|
}
|
@@ -718,7 +711,7 @@ static void draw_vector_array(VALUE ary, FILE *fp)
|
|
718
711
|
case 2:
|
719
712
|
ptry = get_vector_ptr(rb_ary_entry(ary, 1), &stridey, &n);
|
720
713
|
vx = rb_ary_entry(ary, 0);
|
721
|
-
if (NIL_P(vx)) {flag = 1;}
|
714
|
+
if (NIL_P(vx)) {flag = 1; }
|
722
715
|
else {
|
723
716
|
ptrx = get_vector_ptr(vx, &stridex, &n);
|
724
717
|
}
|
@@ -727,32 +720,32 @@ static void draw_vector_array(VALUE ary, FILE *fp)
|
|
727
720
|
ptrz = get_vector_ptr(rb_ary_entry(ary, 2), &stridez, &n);
|
728
721
|
ptry = get_vector_ptr(rb_ary_entry(ary, 1), &stridey, &n);
|
729
722
|
vx = rb_ary_entry(ary, 0);
|
730
|
-
if (NIL_P(vx)) {flag = 2;}
|
723
|
+
if (NIL_P(vx)) {flag = 2; }
|
731
724
|
else {
|
732
725
|
ptrx = get_vector_ptr(vx, &stridex, &n);
|
733
726
|
flag = 3;
|
734
727
|
}
|
735
728
|
break;
|
736
729
|
default:
|
737
|
-
rb_raise(rb_eRuntimeError, "wrong array length (%d for 1 or 2)",
|
738
|
-
|
730
|
+
rb_raise(rb_eRuntimeError, "wrong array length (%d for 1 or 2)",
|
731
|
+
(int) RARRAY_LEN(ary));
|
739
732
|
break;
|
740
733
|
}
|
741
734
|
switch (flag) {
|
742
735
|
case 0:
|
743
|
-
for (j = 0; j < n; j++)
|
736
|
+
for (j = 0; j < n; j++)
|
744
737
|
fprintf(fp, "%g %g\n", ptrx[j*stridex], ptry[j*stridey]);
|
745
738
|
break;
|
746
739
|
case 1:
|
747
|
-
for (j = 0; j < n; j++)
|
740
|
+
for (j = 0; j < n; j++)
|
748
741
|
fprintf(fp, "%d %g\n", (int) j, ptry[j*stridey]);
|
749
742
|
break;
|
750
743
|
case 2:
|
751
|
-
for (j = 0; j < n; j++)
|
744
|
+
for (j = 0; j < n; j++)
|
752
745
|
fprintf(fp, "%d %g %g\n", (int) j, ptry[j*stridey], ptrz[j*stridez]);
|
753
746
|
break;
|
754
747
|
case 3:
|
755
|
-
for (j = 0; j < n; j++)
|
748
|
+
for (j = 0; j < n; j++)
|
756
749
|
fprintf(fp, "%g %g %g\n", ptrx[j*stridex], ptry[j*stridey], ptrz[j*stridez]);
|
757
750
|
break;
|
758
751
|
default:
|
@@ -776,7 +769,7 @@ static VALUE rb_gsl_vector_plot2(int argc, VALUE *argv, VALUE obj)
|
|
776
769
|
case 5:
|
777
770
|
if (TYPE(argv[4]) == T_STRING)
|
778
771
|
sprintf(command, "%s %s", command, STR2CSTR(argv[4]));
|
779
|
-
|
772
|
+
/* no break */
|
780
773
|
case 4:
|
781
774
|
if (TYPE(argv[3]) == T_STRING) {
|
782
775
|
sprintf(command, "%s %s", command, STR2CSTR(argv[3]));
|
@@ -784,9 +777,9 @@ static VALUE rb_gsl_vector_plot2(int argc, VALUE *argv, VALUE obj)
|
|
784
777
|
Data_Get_Struct(argv[3], gsl_vector, yerr);
|
785
778
|
} else {
|
786
779
|
rb_raise(rb_eTypeError, "argv[3] wrong type %s (String or Vector expected)",
|
787
|
-
|
780
|
+
rb_class2name(CLASS_OF(argv[3])));
|
788
781
|
}
|
789
|
-
|
782
|
+
/* no break */
|
790
783
|
case 3:
|
791
784
|
if (TYPE(argv[2]) == T_STRING) {
|
792
785
|
sprintf(command, "%s %s", command, STR2CSTR(argv[2]));
|
@@ -794,9 +787,9 @@ static VALUE rb_gsl_vector_plot2(int argc, VALUE *argv, VALUE obj)
|
|
794
787
|
Data_Get_Struct(argv[2], gsl_vector, xerr);
|
795
788
|
} else {
|
796
789
|
rb_raise(rb_eTypeError, "argv[2] wrong type %s (String or Vector expected)",
|
797
|
-
|
790
|
+
rb_class2name(CLASS_OF(argv[2])));
|
798
791
|
}
|
799
|
-
|
792
|
+
/* no break */
|
800
793
|
case 2:
|
801
794
|
if (TYPE(argv[1]) == T_STRING) {
|
802
795
|
sprintf(command, "%s %s", command, STR2CSTR(argv[1]));
|
@@ -804,9 +797,9 @@ static VALUE rb_gsl_vector_plot2(int argc, VALUE *argv, VALUE obj)
|
|
804
797
|
Data_Get_Struct(argv[1], gsl_vector, y);
|
805
798
|
} else {
|
806
799
|
rb_raise(rb_eTypeError, "argv[1] wrong type %s (String or Vector expected)",
|
807
|
-
|
800
|
+
rb_class2name(CLASS_OF(argv[1])));
|
808
801
|
}
|
809
|
-
|
802
|
+
/* no break */
|
810
803
|
case 1:
|
811
804
|
if (TYPE(argv[0]) == T_STRING) {
|
812
805
|
sprintf(command, "%s %s", command, STR2CSTR(argv[0]));
|
@@ -814,7 +807,7 @@ static VALUE rb_gsl_vector_plot2(int argc, VALUE *argv, VALUE obj)
|
|
814
807
|
Data_Get_Struct(argv[0], gsl_vector, x);
|
815
808
|
} else {
|
816
809
|
rb_raise(rb_eTypeError, "argv[0] wrong type %s (String or Vector expected)",
|
817
|
-
|
810
|
+
rb_class2name(CLASS_OF(argv[0])));
|
818
811
|
}
|
819
812
|
break;
|
820
813
|
default:
|
@@ -825,16 +818,16 @@ static VALUE rb_gsl_vector_plot2(int argc, VALUE *argv, VALUE obj)
|
|
825
818
|
n = x->size;
|
826
819
|
fprintf(fp, "%s\n", command);
|
827
820
|
for (i = 0; i < n; i++) {
|
828
|
-
if (y == NULL)
|
821
|
+
if (y == NULL)
|
829
822
|
fprintf(fp, "%d %g\n", (int) i, gsl_vector_get(x, i));
|
830
823
|
else if (yerr == NULL)
|
831
824
|
fprintf(fp, "%g %g\n", gsl_vector_get(x, i), gsl_vector_get(y, i));
|
832
|
-
else if (xerr)
|
825
|
+
else if (xerr)
|
833
826
|
fprintf(fp, "%g %g %g %g\n", gsl_vector_get(x, i), gsl_vector_get(y, i),
|
834
|
-
|
827
|
+
gsl_vector_get(xerr, i), gsl_vector_get(yerr, i));
|
835
828
|
else
|
836
|
-
|
837
|
-
|
829
|
+
fprintf(fp, "%g %g %g\n", gsl_vector_get(x, i), gsl_vector_get(y, i),
|
830
|
+
gsl_vector_get(yerr, i));
|
838
831
|
}
|
839
832
|
fprintf(fp, "e\n");
|
840
833
|
fflush(fp);
|
@@ -864,10 +857,10 @@ static VALUE rb_gsl_vector_normalize(int argc, VALUE *argv, VALUE obj)
|
|
864
857
|
vnew = make_vector_clone(v);
|
865
858
|
/* mean = gsl_stats_mean(v->data, v->stride, v->size);
|
866
859
|
gsl_vector_add_constant(vnew, -mean);
|
867
|
-
sd = gsl_stats_sd(vnew->data, vnew->stride, vnew->size);
|
860
|
+
sd = gsl_stats_sd(vnew->data, vnew->stride, vnew->size);
|
868
861
|
gsl_vector_scale(vnew, sqrt(nrm)/sd);*/
|
869
862
|
gsl_vector_scale(vnew, nrm/gsl_blas_dnrm2(v));
|
870
|
-
return Data_Wrap_Struct(VECTOR_ROW_COL(obj), 0, gsl_vector_free, vnew);
|
863
|
+
return Data_Wrap_Struct(VECTOR_ROW_COL(obj), 0, gsl_vector_free, vnew);
|
871
864
|
}
|
872
865
|
|
873
866
|
static VALUE rb_gsl_vector_normalize_bang(int argc, VALUE *argv, VALUE obj)
|
@@ -891,7 +884,7 @@ static VALUE rb_gsl_vector_normalize_bang(int argc, VALUE *argv, VALUE obj)
|
|
891
884
|
Data_Get_Vector(obj, v);
|
892
885
|
/* mean = gsl_stats_mean(v->data, v->stride, v->size);
|
893
886
|
gsl_vector_add_constant(v, -mean);
|
894
|
-
sd = gsl_stats_sd(v->data, v->stride, v->size);
|
887
|
+
sd = gsl_stats_sd(v->data, v->stride, v->size);
|
895
888
|
gsl_vector_scale(v, sqrt(nrm)/sd);*/
|
896
889
|
factor = nrm/gsl_blas_dnrm2(v);
|
897
890
|
gsl_vector_scale(v, factor);
|
@@ -941,7 +934,7 @@ static VALUE rb_gsl_vector_filescan_na(VALUE klass, VALUE file)
|
|
941
934
|
for (j = 0; j < n; j++) {
|
942
935
|
p = str_scan_double(p, &val);
|
943
936
|
if (p) ptr[j][i] = val;
|
944
|
-
else break;
|
937
|
+
else break;
|
945
938
|
}
|
946
939
|
}
|
947
940
|
fclose(fp);
|
@@ -958,9 +951,9 @@ static VALUE rb_gsl_vector_decimate(VALUE obj, VALUE nn)
|
|
958
951
|
CHECK_FIXNUM(nn);
|
959
952
|
Data_Get_Vector(obj, v);
|
960
953
|
n = (size_t) FIX2INT(nn);
|
961
|
-
if (n > v->size)
|
962
|
-
rb_raise(rb_eArgError,
|
963
|
-
|
954
|
+
if (n > v->size)
|
955
|
+
rb_raise(rb_eArgError,
|
956
|
+
"decimation factor must be smaller than the vector length.");
|
964
957
|
if (n == 0) rb_raise(rb_eArgError, "decimation factor must be greater than 1");
|
965
958
|
n2 = (size_t) ceil((double)v->size/n);
|
966
959
|
vnew = gsl_vector_alloc(n2);
|
@@ -969,7 +962,7 @@ static VALUE rb_gsl_vector_decimate(VALUE obj, VALUE nn)
|
|
969
962
|
if (i == n2-1) vv = gsl_vector_subvector(v, i*n, n3);
|
970
963
|
else vv = gsl_vector_subvector(v, i*n, n);
|
971
964
|
gsl_vector_set(vnew, i, gsl_stats_mean(vv.vector.data, vv.vector.stride,
|
972
|
-
|
965
|
+
vv.vector.size));
|
973
966
|
}
|
974
967
|
return Data_Wrap_Struct(VECTOR_ROW_COL(obj), 0, gsl_vector_free, vnew);
|
975
968
|
}
|
@@ -1077,21 +1070,21 @@ static VALUE rb_gsl_vector_rotate_bang(int argc, VALUE *argv, VALUE klass)
|
|
1077
1070
|
v0 = rb_ary_entry(argv[0], 0);
|
1078
1071
|
v1 = rb_ary_entry(argv[0], 1);
|
1079
1072
|
if (VECTOR_P(v0) && VECTOR_P(v1)) {
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1073
|
+
Data_Get_Struct(v0, gsl_vector, vx);
|
1074
|
+
Data_Get_Struct(v1, gsl_vector, vy);
|
1075
|
+
n = (size_t) GSL_MIN(vx->size, vy->size);
|
1076
|
+
rad = NUM2DBL(argv[1]);
|
1077
|
+
retval = argv[0];
|
1085
1078
|
} else {
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1079
|
+
x = NUM2DBL(rb_ary_entry(argv[0], 0));
|
1080
|
+
y = NUM2DBL(rb_ary_entry(argv[0], 1));
|
1081
|
+
rad = NUM2DBL(argv[1]);
|
1082
|
+
c = cos(rad); s = sin(rad);
|
1083
|
+
return rb_ary_new3(2, rb_float_new(c*x - s*y), rb_float_new(s*x + c*y));
|
1091
1084
|
}
|
1092
1085
|
} else {
|
1093
1086
|
rb_raise(rb_eTypeError, "wrong argument type %s (Array expected)",
|
1094
|
-
|
1087
|
+
rb_class2name(CLASS_OF(argv[0])));
|
1095
1088
|
}
|
1096
1089
|
break;
|
1097
1090
|
case 3:
|
@@ -1136,19 +1129,19 @@ static VALUE rb_gsl_vector_rotate(int argc, VALUE *argv, VALUE klass)
|
|
1136
1129
|
v0 = rb_ary_entry(argv[0], 0);
|
1137
1130
|
v1 = rb_ary_entry(argv[0], 1);
|
1138
1131
|
if (VECTOR_P(v0) && VECTOR_P(v1)) {
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1132
|
+
Data_Get_Struct(v0, gsl_vector, vx);
|
1133
|
+
Data_Get_Struct(v1, gsl_vector, vy);
|
1134
|
+
rad = NUM2DBL(argv[1]);
|
1142
1135
|
} else {
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1136
|
+
x = NUM2DBL(rb_ary_entry(argv[0], 0));
|
1137
|
+
y = NUM2DBL(rb_ary_entry(argv[0], 1));
|
1138
|
+
rad = NUM2DBL(argv[1]);
|
1139
|
+
c = cos(rad); s = sin(rad);
|
1140
|
+
return rb_ary_new3(2, rb_float_new(c*x - s*y), rb_float_new(s*x + c*y));
|
1148
1141
|
}
|
1149
1142
|
} else {
|
1150
1143
|
rb_raise(rb_eTypeError, "wrong argument type %s (Array expected)",
|
1151
|
-
|
1144
|
+
rb_class2name(CLASS_OF(argv[0])));
|
1152
1145
|
}
|
1153
1146
|
break;
|
1154
1147
|
case 3:
|
@@ -1179,7 +1172,7 @@ static VALUE rb_gsl_vector_rotate(int argc, VALUE *argv, VALUE klass)
|
|
1179
1172
|
gsl_vector_set(vynew, i, s*x + c*y);
|
1180
1173
|
}
|
1181
1174
|
return rb_ary_new3(2, Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vxnew),
|
1182
|
-
|
1175
|
+
Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vynew));
|
1183
1176
|
}
|
1184
1177
|
|
1185
1178
|
#include "gsl/gsl_fit.h"
|
@@ -1195,21 +1188,21 @@ static VALUE rb_gsl_vector_linearfit(int argc, VALUE *argv, VALUE klass)
|
|
1195
1188
|
Data_Get_Struct(argv[1], gsl_vector, w);
|
1196
1189
|
Data_Get_Struct(argv[2], gsl_vector, y);
|
1197
1190
|
gsl_fit_wlinear(x->data, x->stride, w->data, w->stride,
|
1198
|
-
|
1199
|
-
|
1191
|
+
y->data, y->stride, y->size, &c0, &c1, &c00, &c01, &c11,
|
1192
|
+
&sumsq);
|
1200
1193
|
break;
|
1201
1194
|
case 2:
|
1202
|
-
CHECK_VECTOR(argv[0]); CHECK_VECTOR(argv[1]);
|
1195
|
+
CHECK_VECTOR(argv[0]); CHECK_VECTOR(argv[1]);
|
1203
1196
|
Data_Get_Struct(argv[0], gsl_vector, x);
|
1204
1197
|
Data_Get_Struct(argv[1], gsl_vector, y);
|
1205
|
-
gsl_fit_linear(x->data, x->stride, y->data,y->stride, y->size,
|
1206
|
-
|
1198
|
+
gsl_fit_linear(x->data, x->stride, y->data,y->stride, y->size,
|
1199
|
+
&c0, &c1, &c00, &c01, &c11, &sumsq);
|
1207
1200
|
break;
|
1208
1201
|
default:
|
1209
1202
|
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 2 or 3).\n", argc);
|
1210
1203
|
}
|
1211
1204
|
return rb_ary_new3(6, rb_float_new(c0), rb_float_new(c1), rb_float_new(c00),
|
1212
|
-
|
1205
|
+
rb_float_new(c01), rb_float_new(c11), rb_float_new(sumsq));
|
1213
1206
|
}
|
1214
1207
|
|
1215
1208
|
static VALUE rb_gsl_vector_center(VALUE obj)
|
@@ -1226,7 +1219,7 @@ static VALUE rb_gsl_vector_center(VALUE obj)
|
|
1226
1219
|
|
1227
1220
|
static VALUE rb_gsl_vector_clip(int argc, VALUE *argv, VALUE obj)
|
1228
1221
|
{
|
1229
|
-
gsl_vector *v, *vnew;
|
1222
|
+
gsl_vector *v, *vnew;
|
1230
1223
|
double hi = 1.0, lo = 0.0;
|
1231
1224
|
double x;
|
1232
1225
|
size_t i;
|
@@ -1254,7 +1247,7 @@ static VALUE rb_gsl_vector_clip(int argc, VALUE *argv, VALUE obj)
|
|
1254
1247
|
x = gsl_vector_get(v, i);
|
1255
1248
|
if (x > hi) x = hi;
|
1256
1249
|
else if (x < lo) x = lo;
|
1257
|
-
else {}
|
1250
|
+
else {}
|
1258
1251
|
gsl_vector_set(vnew, i, x);
|
1259
1252
|
}
|
1260
1253
|
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
|
@@ -1271,12 +1264,12 @@ static VALUE rb_gsl_vector_amp_phase(VALUE obj)
|
|
1271
1264
|
amp = gsl_vector_alloc(v->size/2);
|
1272
1265
|
phase = gsl_vector_alloc(v->size/2);
|
1273
1266
|
gsl_vector_set(amp, 0, gsl_vector_get(v, 0));
|
1274
|
-
gsl_vector_set(phase, 0, 0);
|
1267
|
+
gsl_vector_set(phase, 0, 0);
|
1275
1268
|
gsl_vector_set(amp, amp->size-1, gsl_vector_get(v, v->size-1));
|
1276
|
-
gsl_vector_set(phase, phase->size-1, 0);
|
1277
|
-
for (i = 1; i < v->size-1; i+=2) {
|
1269
|
+
gsl_vector_set(phase, phase->size-1, 0);
|
1270
|
+
for (i = 1; i < v->size-1; i += 2) {
|
1278
1271
|
re = gsl_vector_get(v, i);
|
1279
|
-
im = gsl_vector_get(v, i+1);
|
1272
|
+
im = gsl_vector_get(v, i+1);
|
1280
1273
|
gsl_vector_set(amp, i/2+1, sqrt(re*re + im*im));
|
1281
1274
|
gsl_vector_set(phase, i/2+1, atan2(im, re));
|
1282
1275
|
}
|
@@ -1307,7 +1300,7 @@ static VALUE rb_gsl_vector_clean(int argc, VALUE *argv, VALUE obj)
|
|
1307
1300
|
vnew = make_vector_clone(v);
|
1308
1301
|
n = v->size;
|
1309
1302
|
for (i = 0; i < n; i++) if (fabs(vnew->data[i]) < eps) vnew->data[i] = 0.0;
|
1310
|
-
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew)
|
1303
|
+
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
|
1311
1304
|
}
|
1312
1305
|
|
1313
1306
|
static VALUE rb_gsl_vector_clean_bang(int argc, VALUE *argv, VALUE obj)
|
@@ -1430,11 +1423,11 @@ void Init_gsl_vector(VALUE module)
|
|
1430
1423
|
rb_define_method(cgsl_vector, "amp_phase", rb_gsl_vector_amp_phase, 0);
|
1431
1424
|
rb_define_method(cgsl_vector, "clean", rb_gsl_vector_clean, -1);
|
1432
1425
|
rb_define_method(cgsl_vector, "clean!", rb_gsl_vector_clean_bang, -1);
|
1433
|
-
|
1426
|
+
|
1434
1427
|
rb_define_method(cgsl_vector, "pow", rb_gsl_vector_pow, 1);
|
1435
1428
|
rb_define_alias(cgsl_vector, "**", "pow");
|
1436
|
-
|
1437
|
-
rb_define_method(cgsl_vector, "pow!", rb_gsl_vector_pow_bang, 1);
|
1438
|
-
|
1429
|
+
|
1430
|
+
rb_define_method(cgsl_vector, "pow!", rb_gsl_vector_pow_bang, 1);
|
1431
|
+
|
1439
1432
|
Init_gsl_vector_init(module);
|
1440
1433
|
}
|