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
@@ -15,17 +15,17 @@
|
|
15
15
|
#include <gsl/gsl_multimin.h>
|
16
16
|
|
17
17
|
#ifndef CHECK_MULTIMIN_FUNCTION
|
18
|
-
#define CHECK_MULTIMIN_FUNCTION(x) if(CLASS_OF(x)!=cgsl_multimin_function)\
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
#define CHECK_MULTIMIN_FUNCTION(x) if(CLASS_OF(x)!=cgsl_multimin_function) \
|
19
|
+
rb_raise(rb_eTypeError, \
|
20
|
+
"wrong argument type %s (GSL::MultiMin::Function expected)", \
|
21
|
+
rb_class2name(CLASS_OF(x)));
|
22
22
|
#endif
|
23
23
|
|
24
24
|
#ifndef CHECK_MULTIMIN_FUNCTION_FDF
|
25
|
-
#define CHECK_MULTIMIN_FUNCTION_FDF(x) if(CLASS_OF(x)!=cgsl_multimin_function_fdf)\
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
#define CHECK_MULTIMIN_FUNCTION_FDF(x) if(CLASS_OF(x)!=cgsl_multimin_function_fdf) \
|
26
|
+
rb_raise(rb_eTypeError, \
|
27
|
+
"wrong argument type %s (GSL::MultiMin::Function_fdf expected)", \
|
28
|
+
rb_class2name(CLASS_OF(x)));
|
29
29
|
#endif
|
30
30
|
|
31
31
|
VALUE cgsl_multimin_function_fdf; /* Used also in multimin_fsdf.c */
|
@@ -37,18 +37,12 @@ enum {
|
|
37
37
|
GSL_FDFMINIMIZER_VECTOR_BFGS,
|
38
38
|
GSL_FDFMINIMIZER_STEEPEST_DESCENT,
|
39
39
|
GSL_FMINIMIZER_NMSIMPLEX,
|
40
|
-
#ifdef GSL_1_9_LATER
|
41
40
|
GSL_FDFMINIMIZER_VECTOR_BFGS2,
|
42
|
-
#endif
|
43
|
-
#ifdef GSL_1_13_LATER
|
44
41
|
GSL_FMINIMIZER_NMSIMPLEX2RAND,
|
45
|
-
#endif
|
46
42
|
};
|
47
43
|
|
48
44
|
static const gsl_multimin_fdfminimizer_type* get_fdfminimizer_type(VALUE t);
|
49
|
-
#ifdef GSL_1_3_LATER
|
50
45
|
static const gsl_multimin_fminimizer_type* get_fminimizer_type(VALUE t);
|
51
|
-
#endif
|
52
46
|
static void define_const();
|
53
47
|
|
54
48
|
static void gsl_multimin_function_free(gsl_multimin_function *f);
|
@@ -57,11 +51,11 @@ static void set_function(int i, VALUE *argv, gsl_multimin_function *F);
|
|
57
51
|
|
58
52
|
static void gsl_multimin_function_fdf_free(gsl_multimin_function_fdf *f);
|
59
53
|
|
60
|
-
double rb_gsl_multimin_function_fdf_f(const gsl_vector *x, void *p);
|
61
|
-
void rb_gsl_multimin_function_fdf_df(const gsl_vector *x, void *p,
|
62
|
-
|
63
|
-
void rb_gsl_multimin_function_fdf_fdf(const gsl_vector *x, void *p,
|
64
|
-
|
54
|
+
double rb_gsl_multimin_function_fdf_f(const gsl_vector *x, void *p);
|
55
|
+
void rb_gsl_multimin_function_fdf_df(const gsl_vector *x, void *p,
|
56
|
+
gsl_vector *g);
|
57
|
+
void rb_gsl_multimin_function_fdf_fdf(const gsl_vector *x, void *p,
|
58
|
+
double *f, gsl_vector *g);
|
65
59
|
static void set_function_fdf(int i, VALUE *argv, gsl_multimin_function_fdf *F);
|
66
60
|
|
67
61
|
/*** multimin_funcion ***/
|
@@ -148,10 +142,10 @@ static void set_function(int i, VALUE *argv, gsl_multimin_function *F)
|
|
148
142
|
VALUE ary;
|
149
143
|
ary = (VALUE) F->params;
|
150
144
|
if (TYPE(argv[i]) == T_FIXNUM) F->n = FIX2INT(argv[i]);
|
151
|
-
else if (rb_obj_is_kind_of(argv[i], rb_cProc))
|
145
|
+
else if (rb_obj_is_kind_of(argv[i], rb_cProc))
|
152
146
|
rb_ary_store(ary, 0, argv[i]);
|
153
147
|
else if (TYPE(argv[i]) == T_ARRAY || rb_obj_is_kind_of(argv[i], cgsl_vector)
|
154
|
-
|
148
|
+
|| TYPE(argv[i]) == T_FIXNUM || TYPE(argv[i]) == T_FLOAT) {
|
155
149
|
rb_ary_store(ary, 1, argv[i]);
|
156
150
|
} else {
|
157
151
|
rb_raise(rb_eTypeError, "wrong type of argument %d (Fixnum or Proc)", i);
|
@@ -268,8 +262,8 @@ static void set_function_fdf(int argc, VALUE *argv, gsl_multimin_function_fdf *F
|
|
268
262
|
F->n = FIX2INT(argv[2]);
|
269
263
|
rb_ary_store(ary, 2, Qnil);
|
270
264
|
} else {
|
271
|
-
|
272
|
-
|
265
|
+
rb_ary_store(ary, 2, argv[2]);
|
266
|
+
}
|
273
267
|
break;
|
274
268
|
case 4:
|
275
269
|
case 5:
|
@@ -316,8 +310,8 @@ static VALUE rb_gsl_multimin_function_fdf_set_procs(int argc, VALUE *argv, VALUE
|
|
316
310
|
F->n = FIX2INT(argv[2]);
|
317
311
|
rb_ary_store(ary, 2, Qnil);
|
318
312
|
} else {
|
319
|
-
|
320
|
-
|
313
|
+
rb_ary_store(ary, 2, argv[2]);
|
314
|
+
}
|
321
315
|
break;
|
322
316
|
case 4:
|
323
317
|
case 5:
|
@@ -355,7 +349,7 @@ static VALUE rb_gsl_multimin_function_fdf_set_params(int argc, VALUE *argv, VALU
|
|
355
349
|
ary = (VALUE) F->params;
|
356
350
|
}
|
357
351
|
if (argc == 1) {
|
358
|
-
|
352
|
+
rb_ary_store(ary, 3, argv[0]);
|
359
353
|
} else {
|
360
354
|
ary2 = rb_ary_new2(argc);
|
361
355
|
for (i = 0; (int) i < argc; i++) rb_ary_store(ary2, i, argv[i]);
|
@@ -384,8 +378,8 @@ double rb_gsl_multimin_function_fdf_f(const gsl_vector *x, void *p)
|
|
384
378
|
return NUM2DBL(result);
|
385
379
|
}
|
386
380
|
|
387
|
-
void rb_gsl_multimin_function_fdf_df(const gsl_vector *x, void *p,
|
388
|
-
|
381
|
+
void rb_gsl_multimin_function_fdf_df(const gsl_vector *x, void *p,
|
382
|
+
gsl_vector *g)
|
389
383
|
{
|
390
384
|
VALUE vx, vg, proc, vp, ary;
|
391
385
|
vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
|
@@ -400,8 +394,8 @@ void rb_gsl_multimin_function_fdf_df(const gsl_vector *x, void *p,
|
|
400
394
|
}
|
401
395
|
}
|
402
396
|
|
403
|
-
void rb_gsl_multimin_function_fdf_fdf(const gsl_vector *x, void *p,
|
404
|
-
|
397
|
+
void rb_gsl_multimin_function_fdf_fdf(const gsl_vector *x, void *p,
|
398
|
+
double *f, gsl_vector *g)
|
405
399
|
{
|
406
400
|
VALUE vx, vg, proc_f, proc_df, vp, ary, result;
|
407
401
|
vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
|
@@ -431,26 +425,20 @@ static VALUE rb_gsl_multimin_function_fdf_params(VALUE obj)
|
|
431
425
|
|
432
426
|
static void define_const(VALUE klass1, VALUE klass2)
|
433
427
|
{
|
434
|
-
rb_define_const(klass1,
|
435
|
-
|
436
|
-
rb_define_const(klass1,
|
437
|
-
|
438
|
-
rb_define_const(klass1,
|
439
|
-
|
440
|
-
rb_define_const(klass1,
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
"VECTOR_BFGS2", INT2FIX(GSL_FDFMINIMIZER_VECTOR_BFGS2));
|
449
|
-
#endif
|
450
|
-
#ifdef GSL_1_13_LATER
|
451
|
-
rb_define_const(klass2,
|
452
|
-
"NMSIMPLEX2RAND", INT2FIX(GSL_FMINIMIZER_NMSIMPLEX2RAND));
|
453
|
-
#endif
|
428
|
+
rb_define_const(klass1,
|
429
|
+
"CONJUGATE_FR", INT2FIX(GSL_FDFMINIMIZER_CONJUGATE_FR));
|
430
|
+
rb_define_const(klass1,
|
431
|
+
"CONJUGATE_PR", INT2FIX(GSL_FDFMINIMIZER_CONJUGATE_PR));
|
432
|
+
rb_define_const(klass1,
|
433
|
+
"VECTOR_BFGS", INT2FIX(GSL_FDFMINIMIZER_VECTOR_BFGS));
|
434
|
+
rb_define_const(klass1,
|
435
|
+
"STEEPEST_DESCENT", INT2FIX(GSL_FDFMINIMIZER_STEEPEST_DESCENT));
|
436
|
+
rb_define_const(klass2,
|
437
|
+
"NMSIMPLEX", INT2FIX(GSL_FMINIMIZER_NMSIMPLEX));
|
438
|
+
rb_define_const(klass1,
|
439
|
+
"VECTOR_BFGS2", INT2FIX(GSL_FDFMINIMIZER_VECTOR_BFGS2));
|
440
|
+
rb_define_const(klass2,
|
441
|
+
"NMSIMPLEX2RAND", INT2FIX(GSL_FMINIMIZER_NMSIMPLEX2RAND));
|
454
442
|
}
|
455
443
|
|
456
444
|
static const gsl_multimin_fdfminimizer_type* get_fdfminimizer_type(VALUE t)
|
@@ -459,18 +447,16 @@ static const gsl_multimin_fdfminimizer_type* get_fdfminimizer_type(VALUE t)
|
|
459
447
|
switch (TYPE(t)) {
|
460
448
|
case T_STRING:
|
461
449
|
strcpy(name, STR2CSTR(t));
|
462
|
-
if (str_tail_grep(name, "conjugate_fr") == 0)
|
450
|
+
if (str_tail_grep(name, "conjugate_fr") == 0)
|
463
451
|
return gsl_multimin_fdfminimizer_conjugate_fr;
|
464
|
-
else if (str_tail_grep(name, "conjugate_pr") == 0)
|
452
|
+
else if (str_tail_grep(name, "conjugate_pr") == 0)
|
465
453
|
return gsl_multimin_fdfminimizer_conjugate_pr;
|
466
|
-
else if (str_tail_grep(name, "vector_bfgs") == 0)
|
454
|
+
else if (str_tail_grep(name, "vector_bfgs") == 0)
|
467
455
|
return gsl_multimin_fdfminimizer_vector_bfgs;
|
468
|
-
else if (str_tail_grep(name, "steepest_descent") == 0)
|
456
|
+
else if (str_tail_grep(name, "steepest_descent") == 0)
|
469
457
|
return gsl_multimin_fdfminimizer_steepest_descent;
|
470
|
-
|
471
|
-
else if (str_tail_grep(name, "vector_bfgs2") == 0)
|
458
|
+
else if (str_tail_grep(name, "vector_bfgs2") == 0)
|
472
459
|
return gsl_multimin_fdfminimizer_vector_bfgs2;
|
473
|
-
#endif
|
474
460
|
else
|
475
461
|
rb_raise(rb_eTypeError, "%s: unknown minimizer type", name);
|
476
462
|
break;
|
@@ -484,10 +470,8 @@ static const gsl_multimin_fdfminimizer_type* get_fdfminimizer_type(VALUE t)
|
|
484
470
|
return gsl_multimin_fdfminimizer_vector_bfgs; break;
|
485
471
|
case GSL_FDFMINIMIZER_STEEPEST_DESCENT:
|
486
472
|
return gsl_multimin_fdfminimizer_steepest_descent; break;
|
487
|
-
#ifdef GSL_1_9_LATER
|
488
473
|
case GSL_FDFMINIMIZER_VECTOR_BFGS2:
|
489
474
|
return gsl_multimin_fdfminimizer_vector_bfgs2; break;
|
490
|
-
#endif
|
491
475
|
default:
|
492
476
|
rb_raise(rb_eTypeError, "%d: unknown type", FIX2INT(t));
|
493
477
|
break;
|
@@ -508,8 +492,8 @@ static VALUE rb_gsl_fdfminimizer_new(VALUE klass, VALUE t, VALUE n)
|
|
508
492
|
return Data_Wrap_Struct(klass, 0, gsl_multimin_fdfminimizer_free, gmf);
|
509
493
|
}
|
510
494
|
|
511
|
-
static VALUE rb_gsl_fdfminimizer_set(VALUE obj, VALUE ff, VALUE xx, VALUE ss,
|
512
|
-
|
495
|
+
static VALUE rb_gsl_fdfminimizer_set(VALUE obj, VALUE ff, VALUE xx, VALUE ss,
|
496
|
+
VALUE tt)
|
513
497
|
{
|
514
498
|
gsl_multimin_fdfminimizer *gmf = NULL;
|
515
499
|
gsl_multimin_function_fdf *F = NULL;
|
@@ -601,7 +585,6 @@ static VALUE rb_gsl_multimin_test_gradient(VALUE obj, VALUE gg, VALUE ea)
|
|
601
585
|
}
|
602
586
|
|
603
587
|
/*****/
|
604
|
-
#ifdef GSL_1_3_LATER
|
605
588
|
static const gsl_multimin_fminimizer_type* get_fminimizer_type(VALUE t)
|
606
589
|
{
|
607
590
|
char name[64];
|
@@ -609,12 +592,10 @@ static const gsl_multimin_fminimizer_type* get_fminimizer_type(VALUE t)
|
|
609
592
|
switch (TYPE(t)) {
|
610
593
|
case T_STRING:
|
611
594
|
strcpy(name, STR2CSTR(t));
|
612
|
-
if (str_tail_grep(name, "nmsimplex") == 0)
|
595
|
+
if (str_tail_grep(name, "nmsimplex") == 0)
|
613
596
|
return gsl_multimin_fminimizer_nmsimplex;
|
614
|
-
|
615
|
-
if (str_tail_grep(name, "nmsimplex2rand") == 0)
|
597
|
+
if (str_tail_grep(name, "nmsimplex2rand") == 0)
|
616
598
|
return gsl_multimin_fminimizer_nmsimplex2rand;
|
617
|
-
#endif
|
618
599
|
else
|
619
600
|
rb_raise(rb_eTypeError, "unknown type %s (nmsimplex and nmsimplex2rand supported)", name);
|
620
601
|
break;
|
@@ -622,10 +603,8 @@ static const gsl_multimin_fminimizer_type* get_fminimizer_type(VALUE t)
|
|
622
603
|
switch (FIX2INT(t)) {
|
623
604
|
case GSL_FMINIMIZER_NMSIMPLEX:
|
624
605
|
return gsl_multimin_fminimizer_nmsimplex; break;
|
625
|
-
#ifdef GSL_1_13_LATER
|
626
606
|
case GSL_FMINIMIZER_NMSIMPLEX2RAND:
|
627
607
|
return gsl_multimin_fminimizer_nmsimplex2rand; break;
|
628
|
-
#endif
|
629
608
|
default:
|
630
609
|
rb_raise(rb_eTypeError, "%d: unknown type (not supported)", FIX2INT(t));
|
631
610
|
break;
|
@@ -633,7 +612,7 @@ static const gsl_multimin_fminimizer_type* get_fminimizer_type(VALUE t)
|
|
633
612
|
break;
|
634
613
|
default:
|
635
614
|
rb_raise(rb_eTypeError, "wrong argument type %s (String or Fixnum expected)",
|
636
|
-
|
615
|
+
rb_class2name(CLASS_OF(t)));
|
637
616
|
break;
|
638
617
|
}
|
639
618
|
}
|
@@ -720,8 +699,6 @@ static VALUE rb_gsl_multimin_test_size(VALUE obj, VALUE ss, VALUE ea)
|
|
720
699
|
return INT2FIX(gsl_multimin_test_size(NUM2DBL(ss), NUM2DBL(ea)));
|
721
700
|
}
|
722
701
|
|
723
|
-
#endif
|
724
|
-
|
725
702
|
#ifdef HAVE_GSL_GSL_MULTIMIN_FSDF_H
|
726
703
|
void Init_multimin_fsdf(VALUE module);
|
727
704
|
#endif
|
@@ -735,18 +712,16 @@ void Init_gsl_multimin(VALUE module)
|
|
735
712
|
|
736
713
|
mgsl_multimin = rb_define_module_under(module, "MultiMin");
|
737
714
|
rb_define_singleton_method(mgsl_multimin, "test_gradient", rb_gsl_multimin_test_gradient, 2);
|
738
|
-
#ifdef GSL_1_3_LATER
|
739
715
|
rb_define_singleton_method(mgsl_multimin, "test_size", rb_gsl_multimin_test_size, 2);
|
740
|
-
#endif
|
741
716
|
|
742
717
|
cgsl_multimin_fdfminimizer = rb_define_class_under(mgsl_multimin, "FdfMinimizer", cGSL_Object);
|
743
718
|
cgsl_multimin_fminimizer = rb_define_class_under(mgsl_multimin, "FMinimizer", cGSL_Object);
|
744
719
|
define_const(cgsl_multimin_fdfminimizer, cgsl_multimin_fminimizer);
|
745
720
|
|
746
721
|
cgsl_multimin_function = rb_define_class_under(mgsl_multimin, "Function",
|
747
|
-
|
722
|
+
cgsl_function);
|
748
723
|
rb_define_singleton_method(cgsl_multimin_function, "alloc",
|
749
|
-
|
724
|
+
rb_gsl_multimin_function_new, -1);
|
750
725
|
rb_define_method(cgsl_multimin_function, "eval", rb_gsl_multimin_function_eval, 1);
|
751
726
|
rb_define_alias(cgsl_multimin_function, "call", "eval");
|
752
727
|
rb_define_method(cgsl_multimin_function, "set_proc", rb_gsl_multimin_function_set_f, -1);
|
@@ -756,9 +731,9 @@ void Init_gsl_multimin(VALUE module)
|
|
756
731
|
rb_define_method(cgsl_multimin_function, "n", rb_gsl_multimin_function_n, 0);
|
757
732
|
|
758
733
|
cgsl_multimin_function_fdf = rb_define_class_under(mgsl_multimin, "Function_fdf",
|
759
|
-
|
734
|
+
cGSL_Object);
|
760
735
|
rb_define_singleton_method(cgsl_multimin_function_fdf, "alloc",
|
761
|
-
|
736
|
+
rb_gsl_multimin_function_fdf_new, -1);
|
762
737
|
|
763
738
|
rb_define_method(cgsl_multimin_function_fdf, "set", rb_gsl_multimin_function_fdf_set, -1);
|
764
739
|
rb_define_method(cgsl_multimin_function_fdf, "set_params", rb_gsl_multimin_function_fdf_set_params, -1);
|
@@ -779,7 +754,6 @@ void Init_gsl_multimin(VALUE module)
|
|
779
754
|
rb_define_method(cgsl_multimin_fdfminimizer, "test_gradient", rb_gsl_fdfminimizer_test_gradient, 1);
|
780
755
|
|
781
756
|
/*****/
|
782
|
-
#ifdef GSL_1_3_LATER
|
783
757
|
rb_define_singleton_method(cgsl_multimin_fminimizer, "alloc", rb_gsl_fminimizer_new, 2);
|
784
758
|
|
785
759
|
rb_define_method(cgsl_multimin_fminimizer, "set", rb_gsl_fminimizer_set, 3);
|
@@ -787,14 +761,12 @@ void Init_gsl_multimin(VALUE module)
|
|
787
761
|
rb_define_method(cgsl_multimin_fminimizer, "iterate", rb_gsl_fminimizer_iterate, 0);
|
788
762
|
rb_define_method(cgsl_multimin_fminimizer, "x", rb_gsl_fminimizer_x, 0);
|
789
763
|
rb_define_method(cgsl_multimin_fminimizer, "fval", rb_gsl_fminimizer_fval, 0);
|
790
|
-
rb_define_method(cgsl_multimin_fminimizer, "minimum", rb_gsl_fminimizer_minimum, 0);
|
791
|
-
|
764
|
+
rb_define_method(cgsl_multimin_fminimizer, "minimum", rb_gsl_fminimizer_minimum, 0);
|
765
|
+
rb_define_method(cgsl_multimin_fminimizer, "size", rb_gsl_fminimizer_size, 0);
|
792
766
|
rb_define_method(cgsl_multimin_fminimizer, "test_size", rb_gsl_fminimizer_test_size, 1);
|
793
|
-
#endif
|
794
|
-
|
795
767
|
|
796
768
|
#ifdef HAVE_GSL_GSL_MULTIMIN_FSDF_H
|
797
|
-
|
769
|
+
Init_multimin_fsdf(mgsl_multimin);
|
798
770
|
#endif
|
799
771
|
}
|
800
772
|
#ifdef CHECK_MULTIMIN_FUNCTION
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
static VALUE cfsdf;
|
6
6
|
#ifndef CHECK_MULTIMIN_FUNCTION_FSDF
|
7
|
-
#define CHECK_MULTIMIN_FUNCTION_FSDF(x) if(CLASS_OF(x)!=cfsdf)\
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
#define CHECK_MULTIMIN_FUNCTION_FSDF(x) if(CLASS_OF(x)!=cfsdf) \
|
8
|
+
rb_raise(rb_eTypeError, \
|
9
|
+
"wrong argument type %s (GSL::MultiMin::Function_fsdf expected)", \
|
10
|
+
rb_class2name(CLASS_OF(x)));
|
11
11
|
#endif
|
12
12
|
extern VALUE cgsl_multimin_function_fdf;
|
13
13
|
|
@@ -17,7 +17,7 @@ static const gsl_multimin_fsdfminimizer_type* get_fsdfminimizer_type(VALUE t)
|
|
17
17
|
switch (TYPE(t)) {
|
18
18
|
case T_STRING:
|
19
19
|
strcpy(name, STR2CSTR(t));
|
20
|
-
if (strcmp(name, "bundle") == 0 || strcmp(name, "bundle_method") == 0)
|
20
|
+
if (strcmp(name, "bundle") == 0 || strcmp(name, "bundle_method") == 0)
|
21
21
|
return gsl_multimin_fsdfminimizer_bundle_method;
|
22
22
|
else
|
23
23
|
rb_raise(rb_eTypeError, "%s: unknown minimizer type", name);
|
@@ -42,13 +42,13 @@ static VALUE rb_gsl_fsdfminimizer_set(VALUE obj, VALUE ff, VALUE xx, VALUE ss)
|
|
42
42
|
gsl_multimin_fsdfminimizer *gmf = NULL;
|
43
43
|
gsl_multimin_function_fsdf *F = NULL;
|
44
44
|
gsl_vector *x;
|
45
|
-
|
45
|
+
size_t bundle_size;
|
46
46
|
int status;
|
47
47
|
CHECK_MULTIMIN_FUNCTION_FSDF(ff);
|
48
48
|
Data_Get_Struct(obj, gsl_multimin_fsdfminimizer, gmf);
|
49
49
|
Data_Get_Struct(ff, gsl_multimin_function_fsdf, F);
|
50
50
|
Data_Get_Vector(xx, x);
|
51
|
-
|
51
|
+
bundle_size = (size_t) FIX2INT(ss);
|
52
52
|
status = gsl_multimin_fsdfminimizer_set(gmf, F, x, bundle_size);
|
53
53
|
return INT2FIX(status);
|
54
54
|
}
|
@@ -134,12 +134,12 @@ static VALUE rb_gsl_fsdfminimizer_eps(VALUE obj)
|
|
134
134
|
|
135
135
|
void Init_multimin_fsdf(VALUE module)
|
136
136
|
{
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
137
|
+
VALUE cmin;
|
138
|
+
|
139
|
+
cmin = rb_define_class_under(module, "FsdfMinimizer", cGSL_Object);
|
140
|
+
cfsdf = rb_define_class_under(module, "Function_fsdf", cgsl_multimin_function_fdf);
|
141
|
+
|
142
|
+
rb_define_singleton_method(cmin, "alloc", rb_gsl_fsdfminimizer_alloc, 2);
|
143
143
|
rb_define_method(cmin, "set", rb_gsl_fsdfminimizer_set, 3);
|
144
144
|
rb_define_method(cmin, "name", rb_gsl_fsdfminimizer_name, 0);
|
145
145
|
rb_define_method(cmin, "iterate", rb_gsl_fsdfminimizer_iterate, 0);
|
@@ -149,8 +149,8 @@ void Init_multimin_fsdf(VALUE module)
|
|
149
149
|
rb_define_method(cmin, "minimum", rb_gsl_fsdfminimizer_minimum, 0);
|
150
150
|
rb_define_method(cmin, "restart", rb_gsl_fsdfminimizer_restart, 0);
|
151
151
|
rb_define_method(cmin, "test_gradient", rb_gsl_fsdfminimizer_test_gradient, 1);
|
152
|
-
rb_define_method(cmin, "test_convergence", rb_gsl_fsdfminimizer_test_convergence, 1);
|
153
|
-
rb_define_method(cmin, "eps", rb_gsl_fsdfminimizer_eps, 0);
|
152
|
+
rb_define_method(cmin, "test_convergence", rb_gsl_fsdfminimizer_test_convergence, 1);
|
153
|
+
rb_define_method(cmin, "eps", rb_gsl_fsdfminimizer_eps, 0);
|
154
154
|
}
|
155
155
|
|
156
156
|
#endif
|
@@ -15,17 +15,17 @@
|
|
15
15
|
#include <gsl/gsl_multiroots.h>
|
16
16
|
|
17
17
|
#ifndef CHECK_MULTIROOT_FUNCTION
|
18
|
-
#define CHECK_MULTIROOT_FUNCTION(x) if(CLASS_OF(x)!=cgsl_multiroot_function)\
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
#define CHECK_MULTIROOT_FUNCTION(x) if(CLASS_OF(x)!=cgsl_multiroot_function) \
|
19
|
+
rb_raise(rb_eTypeError, \
|
20
|
+
"wrong argument type %s (GSL::MultiRoot::Function expected)", \
|
21
|
+
rb_class2name(CLASS_OF(x)));
|
22
22
|
#endif
|
23
23
|
|
24
24
|
#ifndef CHECK_MULTIROOT_FUNCTION_FDF
|
25
|
-
#define CHECK_MULTIROOT_FUNCTION_FDF(x) if(CLASS_OF(x)!=cgsl_multiroot_function_fdf)\
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
#define CHECK_MULTIROOT_FUNCTION_FDF(x) if(CLASS_OF(x)!=cgsl_multiroot_function_fdf) \
|
26
|
+
rb_raise(rb_eTypeError, \
|
27
|
+
"wrong argument type %s (GSL::MultiRoot::Function_fdf expected)", \
|
28
|
+
rb_class2name(CLASS_OF(x)));
|
29
29
|
#endif
|
30
30
|
|
31
31
|
static VALUE cgsl_multiroot_function;
|
@@ -49,12 +49,12 @@ static int rb_gsl_multiroot_function_f(const gsl_vector *x, void *p, gsl_vector
|
|
49
49
|
static void set_function(int i, VALUE *argv, gsl_multiroot_function *F);
|
50
50
|
|
51
51
|
static void gsl_multiroot_function_fdf_free(gsl_multiroot_function_fdf *f);
|
52
|
-
static int rb_gsl_multiroot_function_fdf_f(const gsl_vector *x, void *p,
|
53
|
-
|
54
|
-
static int rb_gsl_multiroot_function_fdf_df(const gsl_vector *x, void *p,
|
55
|
-
|
56
|
-
static int rb_gsl_multiroot_function_fdf_fdf(const gsl_vector *x, void *p,
|
57
|
-
|
52
|
+
static int rb_gsl_multiroot_function_fdf_f(const gsl_vector *x, void *p,
|
53
|
+
gsl_vector *f);
|
54
|
+
static int rb_gsl_multiroot_function_fdf_df(const gsl_vector *x, void *p,
|
55
|
+
gsl_matrix *J);
|
56
|
+
static int rb_gsl_multiroot_function_fdf_fdf(const gsl_vector *x, void *p,
|
57
|
+
gsl_vector *f, gsl_matrix *J);
|
58
58
|
static void set_function_fdf(int i, VALUE *argv, gsl_multiroot_function_fdf *F);
|
59
59
|
static const gsl_multiroot_fsolver_type* get_fsolver_type(VALUE t);
|
60
60
|
static const gsl_multiroot_fdfsolver_type* get_fdfsolver_type(VALUE t);
|
@@ -98,8 +98,8 @@ static void gsl_multiroot_function_mark(gsl_multiroot_function *f)
|
|
98
98
|
{
|
99
99
|
size_t i;
|
100
100
|
rb_gc_mark((VALUE) f->params);
|
101
|
-
// for (i = 0; i < RARRAY(f->params)->len; i++)
|
102
|
-
for (i = 0; (int) i < RARRAY_LEN(f->params); i++)
|
101
|
+
// for (i = 0; i < RARRAY(f->params)->len; i++)
|
102
|
+
for (i = 0; (int) i < RARRAY_LEN(f->params); i++)
|
103
103
|
rb_gc_mark(rb_ary_entry((VALUE) f->params, i));
|
104
104
|
}
|
105
105
|
|
@@ -137,10 +137,10 @@ static void set_function(int i, VALUE *argv, gsl_multiroot_function *F)
|
|
137
137
|
VALUE ary;
|
138
138
|
ary = (VALUE) F->params;
|
139
139
|
if (TYPE(argv[i]) == T_FIXNUM) F->n = FIX2INT(argv[i]);
|
140
|
-
else if (rb_obj_is_kind_of(argv[i], rb_cProc))
|
140
|
+
else if (rb_obj_is_kind_of(argv[i], rb_cProc))
|
141
141
|
rb_ary_store(ary, 0, argv[i]);
|
142
142
|
else if (TYPE(argv[i]) == T_ARRAY || rb_obj_is_kind_of(argv[i], cgsl_vector)
|
143
|
-
|
143
|
+
|| TYPE(argv[i]) == T_FIXNUM || TYPE(argv[i]) == T_FLOAT) {
|
144
144
|
rb_ary_store(ary, 1, argv[i]);
|
145
145
|
} else {
|
146
146
|
rb_raise(rb_eTypeError, "wrong type of argument %d (Fixnum or Proc)", i);
|
@@ -235,8 +235,8 @@ static void gsl_multiroot_function_fdf_mark(gsl_multiroot_function_fdf *f)
|
|
235
235
|
{
|
236
236
|
size_t i;
|
237
237
|
rb_gc_mark((VALUE) f->params);
|
238
|
-
// for (i = 0; i < RARRAY(f->params)->len; i++)
|
239
|
-
for (i = 0; (int) i < RARRAY_LEN(f->params); i++)
|
238
|
+
// for (i = 0; i < RARRAY(f->params)->len; i++)
|
239
|
+
for (i = 0; (int) i < RARRAY_LEN(f->params); i++)
|
240
240
|
rb_gc_mark(rb_ary_entry((VALUE) f->params, i));
|
241
241
|
}
|
242
242
|
|
@@ -336,8 +336,8 @@ static VALUE rb_gsl_multiroot_function_fdf_set(int argc, VALUE *argv, VALUE obj)
|
|
336
336
|
return obj;
|
337
337
|
}
|
338
338
|
|
339
|
-
static int rb_gsl_multiroot_function_fdf_f(const gsl_vector *x, void *p,
|
340
|
-
|
339
|
+
static int rb_gsl_multiroot_function_fdf_f(const gsl_vector *x, void *p,
|
340
|
+
gsl_vector *f)
|
341
341
|
{
|
342
342
|
VALUE vx, vf, ary;
|
343
343
|
VALUE proc, vp;
|
@@ -351,8 +351,8 @@ static int rb_gsl_multiroot_function_fdf_f(const gsl_vector *x, void *p,
|
|
351
351
|
return GSL_SUCCESS;
|
352
352
|
}
|
353
353
|
|
354
|
-
static int rb_gsl_multiroot_function_fdf_df(const gsl_vector *x, void *p,
|
355
|
-
|
354
|
+
static int rb_gsl_multiroot_function_fdf_df(const gsl_vector *x, void *p,
|
355
|
+
gsl_matrix *J)
|
356
356
|
{
|
357
357
|
VALUE vx, vJ, ary;
|
358
358
|
VALUE proc, vp;
|
@@ -366,8 +366,8 @@ static int rb_gsl_multiroot_function_fdf_df(const gsl_vector *x, void *p,
|
|
366
366
|
return GSL_SUCCESS;
|
367
367
|
}
|
368
368
|
|
369
|
-
static int rb_gsl_multiroot_function_fdf_fdf(const gsl_vector *x, void *p,
|
370
|
-
|
369
|
+
static int rb_gsl_multiroot_function_fdf_fdf(const gsl_vector *x, void *p,
|
370
|
+
gsl_vector *f, gsl_matrix *J)
|
371
371
|
{
|
372
372
|
VALUE vx, vf, vJ, ary;
|
373
373
|
VALUE proc_f, proc_df, proc_fdf, vp;
|
@@ -671,8 +671,8 @@ static VALUE rb_gsl_multiroot_fdfsolver_test_residual(VALUE obj, VALUE ea)
|
|
671
671
|
return INT2FIX(gsl_multiroot_test_residual(s->f, NUM2DBL(ea)));
|
672
672
|
}
|
673
673
|
|
674
|
-
static VALUE rb_gsl_multiroot_test_delta(VALUE obj, VALUE vdx, VALUE vx,
|
675
|
-
|
674
|
+
static VALUE rb_gsl_multiroot_test_delta(VALUE obj, VALUE vdx, VALUE vx,
|
675
|
+
VALUE ea, VALUE er)
|
676
676
|
{
|
677
677
|
gsl_vector *dx = NULL, *x = NULL;
|
678
678
|
Need_Float(ea); Need_Float(er);
|
@@ -717,22 +717,21 @@ static VALUE rb_gsl_multiroot_fsolver_fsolve(int argc, VALUE *argv, VALUE obj)
|
|
717
717
|
break;
|
718
718
|
default:
|
719
719
|
rb_raise(rb_eTypeError, "wrong type of argument %s (Fixnum or Float expected)",
|
720
|
-
|
720
|
+
rb_class2name(CLASS_OF(argv[i])));
|
721
721
|
break;
|
722
722
|
}
|
723
723
|
}
|
724
|
-
|
725
724
|
do {
|
726
|
-
iter
|
725
|
+
iter++;
|
727
726
|
status = gsl_multiroot_fsolver_iterate (s);
|
728
727
|
if (status) break;
|
729
728
|
status = gsl_multiroot_test_residual(s->f, eps);
|
730
729
|
} while (status == GSL_CONTINUE && iter < max_iter);
|
731
730
|
xnew = gsl_vector_alloc(s->x->size);
|
732
731
|
gsl_vector_memcpy(xnew, gsl_multiroot_fsolver_root(s));
|
733
|
-
return rb_ary_new3(3,
|
734
|
-
|
735
|
-
|
732
|
+
return rb_ary_new3(3,
|
733
|
+
Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, xnew),
|
734
|
+
INT2FIX(iter), INT2FIX(status));
|
736
735
|
}
|
737
736
|
|
738
737
|
/* singleton */
|
@@ -746,7 +745,6 @@ static VALUE rb_gsl_multiroot_fdjacobian(int argc, VALUE *argv, VALUE obj)
|
|
746
745
|
int status;
|
747
746
|
if (argc != 4 && argc != 5)
|
748
747
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 4 or 5)", argc);
|
749
|
-
|
750
748
|
if (rb_obj_is_kind_of(argv[0], cgsl_multiroot_function_fdf)) {
|
751
749
|
Data_Get_Struct(argv[0], gsl_multiroot_function_fdf, fdf);
|
752
750
|
func.f = fdf->f;
|
@@ -758,7 +756,6 @@ static VALUE rb_gsl_multiroot_fdjacobian(int argc, VALUE *argv, VALUE obj)
|
|
758
756
|
} else {
|
759
757
|
rb_raise(rb_eArgError, "wrong argument type %s (MultiRoot::Function or MultiRoot::Function_fdf expected)", rb_class2name(CLASS_OF(argv[0])));
|
760
758
|
}
|
761
|
-
|
762
759
|
Need_Float(argv[3]);
|
763
760
|
Data_Get_Vector(argv[1], x);
|
764
761
|
Data_Get_Vector(argv[2], f);
|
@@ -767,7 +764,7 @@ static VALUE rb_gsl_multiroot_fdjacobian(int argc, VALUE *argv, VALUE obj)
|
|
767
764
|
J = gsl_matrix_alloc(F->n, F->n);
|
768
765
|
status = gsl_multiroot_fdjacobian(F, x, f, eps, J);
|
769
766
|
return rb_ary_new3(2, Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, J),
|
770
|
-
|
767
|
+
INT2FIX(status));
|
771
768
|
} else {
|
772
769
|
Data_Get_Struct(argv[4], gsl_matrix, J);
|
773
770
|
status = gsl_multiroot_fdjacobian(F, x, f, eps, J);
|
@@ -803,7 +800,7 @@ static VALUE rb_gsl_multiroot_function_solve(int argc, VALUE *argv, VALUE obj)
|
|
803
800
|
int flag = 0;
|
804
801
|
double epsabs = 1e-7;
|
805
802
|
size_t max_iter = 10000, iter = 0, i;
|
806
|
-
gsl_multiroot_fsolver_type *T
|
803
|
+
gsl_multiroot_fsolver_type *T
|
807
804
|
= (gsl_multiroot_fsolver_type *) gsl_multiroot_fsolver_hybrids;
|
808
805
|
gsl_multiroot_fsolver *s = NULL;
|
809
806
|
int status;
|
@@ -816,25 +813,25 @@ static VALUE rb_gsl_multiroot_function_solve(int argc, VALUE *argv, VALUE obj)
|
|
816
813
|
for (i = 1; (int) i < argc; i++) {
|
817
814
|
switch (TYPE(argv[i])) {
|
818
815
|
case T_STRING:
|
819
|
-
|
820
|
-
|
816
|
+
T = (gsl_multiroot_fsolver_type *) get_fsolver_type(argv[i]);
|
817
|
+
break;
|
821
818
|
case T_FLOAT:
|
822
|
-
|
823
|
-
|
819
|
+
epsabs = NUM2DBL(argv[i]);
|
820
|
+
break;
|
824
821
|
case T_FIXNUM:
|
825
|
-
|
826
|
-
|
822
|
+
max_iter = FIX2INT(argv[i]);
|
823
|
+
break;
|
827
824
|
}
|
828
825
|
}
|
829
|
-
|
826
|
+
/* no break */
|
830
827
|
case 1:
|
831
828
|
if (TYPE(argv[0]) == T_ARRAY) {
|
832
829
|
// if (RARRAY(argv[0])->len != F->n)
|
833
830
|
if (RARRAY_LEN(argv[0]) != (int) F->n)
|
834
|
-
|
831
|
+
rb_raise(rb_eRangeError, "array size are different.");
|
835
832
|
x0 = gsl_vector_alloc(F->n);
|
836
|
-
for (i = 0; i < x0->size; i++)
|
837
|
-
|
833
|
+
for (i = 0; i < x0->size; i++)
|
834
|
+
gsl_vector_set(x0, i, NUM2DBL(rb_ary_entry(argv[0], i)));
|
838
835
|
flag = 1;
|
839
836
|
} else {
|
840
837
|
Data_Get_Vector(argv[0], x0);
|
@@ -858,7 +855,7 @@ static VALUE rb_gsl_multiroot_function_solve(int argc, VALUE *argv, VALUE obj)
|
|
858
855
|
gsl_multiroot_fsolver_free (s);
|
859
856
|
if (flag == 1) gsl_vector_free(x0);
|
860
857
|
return rb_ary_new3(3, Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, xnew),
|
861
|
-
|
858
|
+
INT2FIX(iter), INT2FIX(status));
|
862
859
|
}
|
863
860
|
|
864
861
|
void Init_gsl_multiroot(VALUE module)
|
@@ -868,19 +865,19 @@ void Init_gsl_multiroot(VALUE module)
|
|
868
865
|
|
869
866
|
mgsl_multiroot = rb_define_module_under(module, "MultiRoot");
|
870
867
|
|
871
|
-
rb_define_singleton_method(mgsl_multiroot, "test_delta",
|
872
|
-
|
873
|
-
rb_define_singleton_method(mgsl_multiroot, "test_residual",
|
874
|
-
|
868
|
+
rb_define_singleton_method(mgsl_multiroot, "test_delta",
|
869
|
+
rb_gsl_multiroot_test_delta, 4);
|
870
|
+
rb_define_singleton_method(mgsl_multiroot, "test_residual",
|
871
|
+
rb_gsl_multiroot_test_residual, 2);
|
875
872
|
|
876
|
-
rb_define_singleton_method(mgsl_multiroot, "fdjacobian",
|
877
|
-
|
873
|
+
rb_define_singleton_method(mgsl_multiroot, "fdjacobian",
|
874
|
+
rb_gsl_multiroot_fdjacobian, -1);
|
878
875
|
|
879
876
|
/* multiroot_function */
|
880
877
|
cgsl_multiroot_function = rb_define_class_under(mgsl_multiroot, "Function",
|
881
|
-
|
878
|
+
cgsl_function);
|
882
879
|
rb_define_singleton_method(cgsl_multiroot_function, "alloc",
|
883
|
-
|
880
|
+
rb_gsl_multiroot_function_new, -1);
|
884
881
|
rb_define_method(cgsl_multiroot_function, "eval", rb_gsl_multiroot_function_eval, 1);
|
885
882
|
rb_define_alias(cgsl_multiroot_function, "call", "eval");
|
886
883
|
rb_define_method(cgsl_multiroot_function, "set", rb_gsl_multiroot_function_set_f, -1);
|
@@ -891,9 +888,9 @@ void Init_gsl_multiroot(VALUE module)
|
|
891
888
|
|
892
889
|
/* multiroot_function_fdf */
|
893
890
|
cgsl_multiroot_function_fdf = rb_define_class_under(mgsl_multiroot, "Function_fdf",
|
894
|
-
|
891
|
+
cgsl_multiroot_function);
|
895
892
|
rb_define_singleton_method(cgsl_multiroot_function_fdf, "alloc",
|
896
|
-
|
893
|
+
rb_gsl_multiroot_function_fdf_new, -1);
|
897
894
|
rb_define_method(cgsl_multiroot_function_fdf, "set", rb_gsl_multiroot_function_fdf_set, -1);
|
898
895
|
rb_define_method(cgsl_multiroot_function_fdf, "set_params", rb_gsl_multiroot_function_fdf_set_params, -1);
|
899
896
|
rb_define_method(cgsl_multiroot_function_fdf, "params", rb_gsl_multiroot_function_fdf_params, 0);
|
@@ -905,10 +902,10 @@ void Init_gsl_multiroot(VALUE module)
|
|
905
902
|
cgsl_multiroot_fsolver = rb_define_class_under(mgsl_multiroot, "FSolver", cGSL_Object);
|
906
903
|
cgsl_multiroot_fdfsolver = rb_define_class_under(mgsl_multiroot, "FdfSolver", cgsl_multiroot_fsolver);
|
907
904
|
|
908
|
-
rb_define_singleton_method(cgsl_multiroot_fsolver, "alloc",
|
909
|
-
|
910
|
-
rb_define_singleton_method(cgsl_multiroot_fdfsolver, "alloc",
|
911
|
-
|
905
|
+
rb_define_singleton_method(cgsl_multiroot_fsolver, "alloc",
|
906
|
+
rb_gsl_multiroot_fsolver_new, 2);
|
907
|
+
rb_define_singleton_method(cgsl_multiroot_fdfsolver, "alloc",
|
908
|
+
rb_gsl_multiroot_fdfsolver_new, 2);
|
912
909
|
|
913
910
|
rb_define_method(cgsl_multiroot_fsolver, "set", rb_gsl_multiroot_fsolver_set, 2);
|
914
911
|
rb_define_method(cgsl_multiroot_fsolver, "name", rb_gsl_multiroot_fsolver_name, 0);
|
@@ -935,7 +932,7 @@ void Init_gsl_multiroot(VALUE module)
|
|
935
932
|
rb_define_method(cgsl_multiroot_fdfsolver, "test_residual", rb_gsl_multiroot_fdfsolver_test_residual, 1);
|
936
933
|
|
937
934
|
|
938
|
-
multiroot_define_const(cgsl_multiroot_fdfsolver, cgsl_multiroot_fsolver);
|
935
|
+
multiroot_define_const(cgsl_multiroot_fdfsolver, cgsl_multiroot_fsolver);
|
939
936
|
|
940
937
|
rb_define_method(cgsl_multiroot_fsolver, "fsolve", rb_gsl_multiroot_fsolver_fsolve, -1);
|
941
938
|
rb_define_alias(cgsl_multiroot_fsolver, "solve", "fsolve");
|