rb-gsl 1.15.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS +6 -0
- data/COPYING +339 -0
- data/ChangeLog +567 -0
- data/README +32 -0
- data/Rakefile +99 -0
- data/THANKS +17 -0
- data/VERSION +1 -0
- data/examples/alf/alf.gp +15 -0
- data/examples/alf/alf.rb +32 -0
- data/examples/blas/blas.rb +13 -0
- data/examples/blas/dnrm2.rb +16 -0
- data/examples/blas/level1.rb +81 -0
- data/examples/blas/level2.rb +11 -0
- data/examples/blas/level3.rb +12 -0
- data/examples/bspline.rb +57 -0
- data/examples/cdf.rb +16 -0
- data/examples/cheb.rb +21 -0
- data/examples/combination.rb +23 -0
- data/examples/complex/RC-lpf.rb +47 -0
- data/examples/complex/add.rb +36 -0
- data/examples/complex/coerce.rb +14 -0
- data/examples/complex/complex.rb +25 -0
- data/examples/complex/fpmi.rb +70 -0
- data/examples/complex/functions.rb +77 -0
- data/examples/complex/michelson.rb +36 -0
- data/examples/complex/mul.rb +28 -0
- data/examples/complex/oscillator.rb +17 -0
- data/examples/complex/set.rb +37 -0
- data/examples/const/physconst.rb +151 -0
- data/examples/const/travel.rb +45 -0
- data/examples/deriv/demo.rb +13 -0
- data/examples/deriv/deriv.rb +36 -0
- data/examples/deriv/diff.rb +35 -0
- data/examples/dht.rb +42 -0
- data/examples/dirac.rb +56 -0
- data/examples/eigen/eigen.rb +34 -0
- data/examples/eigen/herm.rb +22 -0
- data/examples/eigen/narray.rb +9 -0
- data/examples/eigen/nonsymm.rb +37 -0
- data/examples/eigen/nonsymmv.rb +43 -0
- data/examples/eigen/qhoscillator.gp +35 -0
- data/examples/eigen/qhoscillator.rb +90 -0
- data/examples/eigen/vander.rb +41 -0
- data/examples/fft/fft.rb +17 -0
- data/examples/fft/fft2.rb +17 -0
- data/examples/fft/forward.rb +25 -0
- data/examples/fft/forward2.rb +26 -0
- data/examples/fft/radix2.rb +18 -0
- data/examples/fft/real-halfcomplex.rb +33 -0
- data/examples/fft/real-halfcomplex2.rb +30 -0
- data/examples/fft/realradix2.rb +19 -0
- data/examples/fft/sunspot.dat +256 -0
- data/examples/fft/sunspot.rb +16 -0
- data/examples/fit/expdata.dat +20 -0
- data/examples/fit/expfit.rb +31 -0
- data/examples/fit/gaussfit.rb +29 -0
- data/examples/fit/gaussian_2peaks.rb +34 -0
- data/examples/fit/hillfit.rb +40 -0
- data/examples/fit/lognormal.rb +26 -0
- data/examples/fit/lorentzfit.rb +22 -0
- data/examples/fit/multifit.rb +72 -0
- data/examples/fit/ndlinear.rb +133 -0
- data/examples/fit/nonlinearfit.rb +89 -0
- data/examples/fit/plot.gp +36 -0
- data/examples/fit/polyfit.rb +9 -0
- data/examples/fit/powerfit.rb +21 -0
- data/examples/fit/sigmoidfit.rb +40 -0
- data/examples/fit/sinfit.rb +22 -0
- data/examples/fit/wlinear.rb +46 -0
- data/examples/fresnel.rb +11 -0
- data/examples/function/function.rb +36 -0
- data/examples/function/log.rb +7 -0
- data/examples/function/min.rb +33 -0
- data/examples/function/sin.rb +10 -0
- data/examples/function/synchrotron.rb +18 -0
- data/examples/gallery/butterfly.rb +7 -0
- data/examples/gallery/cayley.rb +12 -0
- data/examples/gallery/cornu.rb +23 -0
- data/examples/gallery/eight.rb +11 -0
- data/examples/gallery/koch.rb +40 -0
- data/examples/gallery/lemniscate.rb +11 -0
- data/examples/gallery/polar.rb +11 -0
- data/examples/gallery/rgplot/cossin.rb +35 -0
- data/examples/gallery/rgplot/rgplot.replaced +0 -0
- data/examples/gallery/rgplot/roesller.rb +55 -0
- data/examples/gallery/roesller.rb +39 -0
- data/examples/gallery/scarabaeus.rb +14 -0
- data/examples/histogram/cauchy.rb +27 -0
- data/examples/histogram/cauchy.sh +2 -0
- data/examples/histogram/exponential.rb +19 -0
- data/examples/histogram/gauss.rb +16 -0
- data/examples/histogram/gsl-histogram.rb +40 -0
- data/examples/histogram/histo2d.rb +31 -0
- data/examples/histogram/histo3d.rb +34 -0
- data/examples/histogram/histogram-pdf.rb +27 -0
- data/examples/histogram/histogram.rb +26 -0
- data/examples/histogram/integral.rb +28 -0
- data/examples/histogram/poisson.rb +27 -0
- data/examples/histogram/power.rb +25 -0
- data/examples/histogram/rebin.rb +17 -0
- data/examples/histogram/smp.dat +5 -0
- data/examples/histogram/xexp.rb +21 -0
- data/examples/integration/ahmed.rb +21 -0
- data/examples/integration/cosmology.rb +75 -0
- data/examples/integration/friedmann.gp +16 -0
- data/examples/integration/friedmann.rb +35 -0
- data/examples/integration/gamma-zeta.rb +35 -0
- data/examples/integration/integration.rb +22 -0
- data/examples/integration/qag.rb +8 -0
- data/examples/integration/qag2.rb +14 -0
- data/examples/integration/qag3.rb +8 -0
- data/examples/integration/qagi.rb +28 -0
- data/examples/integration/qagi2.rb +49 -0
- data/examples/integration/qagiu.rb +29 -0
- data/examples/integration/qagp.rb +20 -0
- data/examples/integration/qags.rb +14 -0
- data/examples/integration/qawc.rb +18 -0
- data/examples/integration/qawf.rb +41 -0
- data/examples/integration/qawo.rb +29 -0
- data/examples/integration/qaws.rb +30 -0
- data/examples/integration/qng.rb +17 -0
- data/examples/interp/demo.gp +20 -0
- data/examples/interp/demo.rb +45 -0
- data/examples/interp/interp.rb +37 -0
- data/examples/interp/points +10 -0
- data/examples/interp/spline.rb +20 -0
- data/examples/jacobi/deriv.rb +40 -0
- data/examples/jacobi/integrate.rb +34 -0
- data/examples/jacobi/interp.rb +43 -0
- data/examples/jacobi/jacobi.rb +11 -0
- data/examples/linalg/HH.rb +15 -0
- data/examples/linalg/HH_narray.rb +13 -0
- data/examples/linalg/LQ_solve.rb +73 -0
- data/examples/linalg/LU.rb +84 -0
- data/examples/linalg/LU2.rb +31 -0
- data/examples/linalg/LU_narray.rb +24 -0
- data/examples/linalg/PTLQ.rb +47 -0
- data/examples/linalg/QR.rb +18 -0
- data/examples/linalg/QRPT.rb +47 -0
- data/examples/linalg/QR_solve.rb +78 -0
- data/examples/linalg/QR_solve_narray.rb +13 -0
- data/examples/linalg/SV.rb +16 -0
- data/examples/linalg/SV_narray.rb +12 -0
- data/examples/linalg/SV_solve.rb +49 -0
- data/examples/linalg/chol.rb +29 -0
- data/examples/linalg/chol_narray.rb +15 -0
- data/examples/linalg/complex.rb +57 -0
- data/examples/linalg/invert_narray.rb +10 -0
- data/examples/math/const.rb +67 -0
- data/examples/math/elementary.rb +35 -0
- data/examples/math/functions.rb +41 -0
- data/examples/math/inf_nan.rb +34 -0
- data/examples/math/minmax.rb +22 -0
- data/examples/math/power.rb +18 -0
- data/examples/math/test.rb +31 -0
- data/examples/matrix/a.dat +0 -0
- data/examples/matrix/add.rb +45 -0
- data/examples/matrix/b.dat +4 -0
- data/examples/matrix/cat.rb +31 -0
- data/examples/matrix/colvectors.rb +24 -0
- data/examples/matrix/complex.rb +41 -0
- data/examples/matrix/det.rb +29 -0
- data/examples/matrix/diagonal.rb +23 -0
- data/examples/matrix/get_all.rb +159 -0
- data/examples/matrix/hilbert.rb +31 -0
- data/examples/matrix/iterator.rb +19 -0
- data/examples/matrix/matrix.rb +57 -0
- data/examples/matrix/minmax.rb +53 -0
- data/examples/matrix/mul.rb +39 -0
- data/examples/matrix/rand.rb +20 -0
- data/examples/matrix/read.rb +29 -0
- data/examples/matrix/rowcol.rb +47 -0
- data/examples/matrix/set.rb +41 -0
- data/examples/matrix/set_all.rb +100 -0
- data/examples/matrix/view.rb +32 -0
- data/examples/matrix/view_all.rb +148 -0
- data/examples/matrix/write.rb +23 -0
- data/examples/min.rb +29 -0
- data/examples/monte/miser.rb +47 -0
- data/examples/monte/monte.rb +47 -0
- data/examples/monte/plain.rb +47 -0
- data/examples/monte/vegas.rb +46 -0
- data/examples/multimin/bundle.rb +66 -0
- data/examples/multimin/cqp.rb +109 -0
- data/examples/multimin/fdfminimizer.rb +40 -0
- data/examples/multimin/fminimizer.rb +41 -0
- data/examples/multiroot/demo.rb +36 -0
- data/examples/multiroot/fdfsolver.rb +50 -0
- data/examples/multiroot/fsolver.rb +33 -0
- data/examples/multiroot/fsolver2.rb +32 -0
- data/examples/multiroot/fsolver3.rb +26 -0
- data/examples/narray/histogram.rb +14 -0
- data/examples/narray/mandel.rb +27 -0
- data/examples/narray/narray.rb +28 -0
- data/examples/narray/narray2.rb +44 -0
- data/examples/narray/sf.rb +26 -0
- data/examples/ntuple/create.rb +17 -0
- data/examples/ntuple/project.rb +31 -0
- data/examples/odeiv/binarysystem.gp +23 -0
- data/examples/odeiv/binarysystem.rb +104 -0
- data/examples/odeiv/demo.gp +24 -0
- data/examples/odeiv/demo.rb +69 -0
- data/examples/odeiv/demo2.gp +26 -0
- data/examples/odeiv/duffing.rb +45 -0
- data/examples/odeiv/frei1.rb +109 -0
- data/examples/odeiv/frei2.rb +76 -0
- data/examples/odeiv/legendre.rb +52 -0
- data/examples/odeiv/odeiv.rb +32 -0
- data/examples/odeiv/odeiv2.rb +45 -0
- data/examples/odeiv/oscillator.rb +42 -0
- data/examples/odeiv/sedov.rb +97 -0
- data/examples/odeiv/whitedwarf.gp +40 -0
- data/examples/odeiv/whitedwarf.rb +158 -0
- data/examples/ool/conmin.rb +100 -0
- data/examples/ool/gencan.rb +99 -0
- data/examples/ool/pgrad.rb +100 -0
- data/examples/ool/spg.rb +100 -0
- data/examples/pdf/bernoulli.rb +5 -0
- data/examples/pdf/beta.rb +7 -0
- data/examples/pdf/binomiral.rb +10 -0
- data/examples/pdf/cauchy.rb +6 -0
- data/examples/pdf/chisq.rb +8 -0
- data/examples/pdf/exponential.rb +7 -0
- data/examples/pdf/exppow.rb +6 -0
- data/examples/pdf/fdist.rb +7 -0
- data/examples/pdf/flat.rb +7 -0
- data/examples/pdf/gamma.rb +8 -0
- data/examples/pdf/gauss-tail.rb +5 -0
- data/examples/pdf/gauss.rb +6 -0
- data/examples/pdf/geometric.rb +5 -0
- data/examples/pdf/gumbel.rb +6 -0
- data/examples/pdf/hypergeometric.rb +11 -0
- data/examples/pdf/landau.rb +5 -0
- data/examples/pdf/laplace.rb +7 -0
- data/examples/pdf/logarithmic.rb +5 -0
- data/examples/pdf/logistic.rb +6 -0
- data/examples/pdf/lognormal.rb +6 -0
- data/examples/pdf/neg-binomiral.rb +10 -0
- data/examples/pdf/pareto.rb +7 -0
- data/examples/pdf/pascal.rb +10 -0
- data/examples/pdf/poisson.rb +5 -0
- data/examples/pdf/rayleigh-tail.rb +6 -0
- data/examples/pdf/rayleigh.rb +6 -0
- data/examples/pdf/tdist.rb +6 -0
- data/examples/pdf/weibull.rb +8 -0
- data/examples/permutation/ex1.rb +22 -0
- data/examples/permutation/permutation.rb +16 -0
- data/examples/poly/bell.rb +6 -0
- data/examples/poly/bessel.rb +6 -0
- data/examples/poly/cheb.rb +6 -0
- data/examples/poly/cheb_II.rb +6 -0
- data/examples/poly/cubic.rb +9 -0
- data/examples/poly/demo.rb +20 -0
- data/examples/poly/eval.rb +28 -0
- data/examples/poly/eval_derivs.rb +14 -0
- data/examples/poly/fit.rb +21 -0
- data/examples/poly/hermite.rb +6 -0
- data/examples/poly/poly.rb +13 -0
- data/examples/poly/quadratic.rb +25 -0
- data/examples/random/diffusion.rb +34 -0
- data/examples/random/gaussian.rb +9 -0
- data/examples/random/generator.rb +27 -0
- data/examples/random/hdsobol.rb +21 -0
- data/examples/random/poisson.rb +9 -0
- data/examples/random/qrng.rb +19 -0
- data/examples/random/randomwalk.rb +37 -0
- data/examples/random/randomwalk2d.rb +19 -0
- data/examples/random/rayleigh.rb +36 -0
- data/examples/random/rng.rb +33 -0
- data/examples/random/rngextra.rb +14 -0
- data/examples/roots/bisection.rb +25 -0
- data/examples/roots/brent.rb +43 -0
- data/examples/roots/demo.rb +30 -0
- data/examples/roots/newton.rb +46 -0
- data/examples/roots/recombination.gp +12 -0
- data/examples/roots/recombination.rb +61 -0
- data/examples/roots/steffenson.rb +48 -0
- data/examples/sf/ShiChi.rb +6 -0
- data/examples/sf/SiCi.rb +6 -0
- data/examples/sf/airy_Ai.rb +8 -0
- data/examples/sf/airy_Bi.rb +8 -0
- data/examples/sf/bessel_IK.rb +12 -0
- data/examples/sf/bessel_JY.rb +13 -0
- data/examples/sf/beta_inc.rb +9 -0
- data/examples/sf/clausen.rb +6 -0
- data/examples/sf/dawson.rb +5 -0
- data/examples/sf/debye.rb +9 -0
- data/examples/sf/dilog.rb +6 -0
- data/examples/sf/ellint.rb +6 -0
- data/examples/sf/expint.rb +8 -0
- data/examples/sf/fermi.rb +10 -0
- data/examples/sf/gamma_inc_P.rb +9 -0
- data/examples/sf/gegenbauer.rb +8 -0
- data/examples/sf/hyperg.rb +7 -0
- data/examples/sf/laguerre.rb +19 -0
- data/examples/sf/lambertW.rb +5 -0
- data/examples/sf/legendre_P.rb +10 -0
- data/examples/sf/lngamma.rb +5 -0
- data/examples/sf/psi.rb +54 -0
- data/examples/sf/sphbessel.gp +27 -0
- data/examples/sf/sphbessel.rb +30 -0
- data/examples/sf/synchrotron.rb +5 -0
- data/examples/sf/transport.rb +10 -0
- data/examples/sf/zetam1.rb +5 -0
- data/examples/siman.rb +44 -0
- data/examples/sort/heapsort.rb +23 -0
- data/examples/sort/heapsort_vector_complex.rb +21 -0
- data/examples/sort/sort.rb +23 -0
- data/examples/sort/sort2.rb +16 -0
- data/examples/stats/mean.rb +17 -0
- data/examples/stats/statistics.rb +18 -0
- data/examples/stats/test.rb +9 -0
- data/examples/sum.rb +34 -0
- data/examples/tamu_anova.rb +18 -0
- data/examples/vector/a.dat +0 -0
- data/examples/vector/add.rb +56 -0
- data/examples/vector/b.dat +4 -0
- data/examples/vector/c.dat +3 -0
- data/examples/vector/collect.rb +26 -0
- data/examples/vector/compare.rb +28 -0
- data/examples/vector/complex.rb +51 -0
- data/examples/vector/complex_get_all.rb +85 -0
- data/examples/vector/complex_set_all.rb +131 -0
- data/examples/vector/complex_view_all.rb +77 -0
- data/examples/vector/connect.rb +22 -0
- data/examples/vector/decimate.rb +38 -0
- data/examples/vector/diff.rb +31 -0
- data/examples/vector/filescan.rb +17 -0
- data/examples/vector/floor.rb +23 -0
- data/examples/vector/get_all.rb +82 -0
- data/examples/vector/gnuplot.rb +38 -0
- data/examples/vector/graph.rb +28 -0
- data/examples/vector/histogram.rb +22 -0
- data/examples/vector/linspace.rb +24 -0
- data/examples/vector/log.rb +17 -0
- data/examples/vector/logic.rb +33 -0
- data/examples/vector/logspace.rb +25 -0
- data/examples/vector/minmax.rb +47 -0
- data/examples/vector/mul.rb +49 -0
- data/examples/vector/narray.rb +46 -0
- data/examples/vector/read.rb +29 -0
- data/examples/vector/set.rb +35 -0
- data/examples/vector/set_all.rb +121 -0
- data/examples/vector/smpv.dat +15 -0
- data/examples/vector/test.rb +43 -0
- data/examples/vector/test_gslblock.rb +58 -0
- data/examples/vector/vector.rb +110 -0
- data/examples/vector/view.rb +35 -0
- data/examples/vector/view_all.rb +73 -0
- data/examples/vector/where.rb +29 -0
- data/examples/vector/write.rb +24 -0
- data/examples/vector/zip.rb +34 -0
- data/examples/wavelet/ecg.dat +256 -0
- data/examples/wavelet/wavelet1.rb +50 -0
- data/ext/alf.c +206 -0
- data/ext/array.c +642 -0
- data/ext/array_complex.c +248 -0
- data/ext/blas.c +29 -0
- data/ext/blas1.c +734 -0
- data/ext/blas2.c +1093 -0
- data/ext/blas3.c +881 -0
- data/ext/block.c +44 -0
- data/ext/block_source.c +887 -0
- data/ext/bspline.c +130 -0
- data/ext/bundle.c +3 -0
- data/ext/cdf.c +754 -0
- data/ext/cheb.c +542 -0
- data/ext/combination.c +283 -0
- data/ext/common.c +325 -0
- data/ext/complex.c +1004 -0
- data/ext/const.c +673 -0
- data/ext/const_additional.c +120 -0
- data/ext/cqp.c +283 -0
- data/ext/deriv.c +195 -0
- data/ext/dht.c +361 -0
- data/ext/diff.c +166 -0
- data/ext/dirac.c +389 -0
- data/ext/eigen.c +2373 -0
- data/ext/error.c +193 -0
- data/ext/extconf.rb +303 -0
- data/ext/fcmp.c +66 -0
- data/ext/fft.c +1102 -0
- data/ext/fit.c +205 -0
- data/ext/fresnel.c +312 -0
- data/ext/function.c +524 -0
- data/ext/geometry.c +139 -0
- data/ext/graph.c +1640 -0
- data/ext/gsl.c +280 -0
- data/ext/gsl_narray.c +804 -0
- data/ext/histogram.c +1991 -0
- data/ext/histogram2d.c +1068 -0
- data/ext/histogram3d.c +884 -0
- data/ext/histogram3d_source.c +750 -0
- data/ext/histogram_find.c +101 -0
- data/ext/histogram_oper.c +159 -0
- data/ext/ieee.c +100 -0
- data/ext/integration.c +1179 -0
- data/ext/interp.c +512 -0
- data/ext/jacobi.c +739 -0
- data/ext/linalg.c +4042 -0
- data/ext/linalg_complex.c +739 -0
- data/ext/math.c +725 -0
- data/ext/matrix.c +39 -0
- data/ext/matrix_complex.c +1737 -0
- data/ext/matrix_double.c +560 -0
- data/ext/matrix_int.c +256 -0
- data/ext/matrix_source.c +2734 -0
- data/ext/min.c +250 -0
- data/ext/monte.c +992 -0
- data/ext/multifit.c +1871 -0
- data/ext/multimin.c +806 -0
- data/ext/multimin_fsdf.c +156 -0
- data/ext/multiroots.c +955 -0
- data/ext/multiset.c +214 -0
- data/ext/ndlinear.c +321 -0
- data/ext/nmf.c +171 -0
- data/ext/nmf_wrap.c +75 -0
- data/ext/ntuple.c +469 -0
- data/ext/odeiv.c +962 -0
- data/ext/ool.c +879 -0
- data/ext/oper_complex_source.c +253 -0
- data/ext/permutation.c +596 -0
- data/ext/poly.c +42 -0
- data/ext/poly2.c +265 -0
- data/ext/poly_source.c +1915 -0
- data/ext/qrng.c +171 -0
- data/ext/randist.c +1873 -0
- data/ext/rational.c +480 -0
- data/ext/rng.c +612 -0
- data/ext/root.c +408 -0
- data/ext/sf.c +1494 -0
- data/ext/sf_airy.c +200 -0
- data/ext/sf_bessel.c +871 -0
- data/ext/sf_clausen.c +28 -0
- data/ext/sf_coulomb.c +206 -0
- data/ext/sf_coupling.c +121 -0
- data/ext/sf_dawson.c +29 -0
- data/ext/sf_debye.c +157 -0
- data/ext/sf_dilog.c +43 -0
- data/ext/sf_elementary.c +46 -0
- data/ext/sf_ellint.c +206 -0
- data/ext/sf_elljac.c +30 -0
- data/ext/sf_erfc.c +93 -0
- data/ext/sf_exp.c +169 -0
- data/ext/sf_expint.c +211 -0
- data/ext/sf_fermi_dirac.c +148 -0
- data/ext/sf_gamma.c +347 -0
- data/ext/sf_gegenbauer.c +97 -0
- data/ext/sf_hyperg.c +203 -0
- data/ext/sf_laguerre.c +113 -0
- data/ext/sf_lambert.c +47 -0
- data/ext/sf_legendre.c +368 -0
- data/ext/sf_log.c +105 -0
- data/ext/sf_mathieu.c +238 -0
- data/ext/sf_power.c +47 -0
- data/ext/sf_psi.c +98 -0
- data/ext/sf_synchrotron.c +48 -0
- data/ext/sf_transport.c +76 -0
- data/ext/sf_trigonometric.c +210 -0
- data/ext/sf_zeta.c +119 -0
- data/ext/signal.c +308 -0
- data/ext/siman.c +717 -0
- data/ext/sort.c +208 -0
- data/ext/spline.c +395 -0
- data/ext/stats.c +800 -0
- data/ext/sum.c +168 -0
- data/ext/tamu_anova.c +56 -0
- data/ext/tensor.c +38 -0
- data/ext/tensor_source.c +1123 -0
- data/ext/vector.c +38 -0
- data/ext/vector_complex.c +2246 -0
- data/ext/vector_double.c +1438 -0
- data/ext/vector_int.c +204 -0
- data/ext/vector_source.c +3336 -0
- data/ext/wavelet.c +945 -0
- data/include/rb_gsl.h +158 -0
- data/include/rb_gsl_array.h +238 -0
- data/include/rb_gsl_cheb.h +21 -0
- data/include/rb_gsl_common.h +348 -0
- data/include/rb_gsl_complex.h +25 -0
- data/include/rb_gsl_config.h +62 -0
- data/include/rb_gsl_const.h +29 -0
- data/include/rb_gsl_dirac.h +13 -0
- data/include/rb_gsl_eigen.h +17 -0
- data/include/rb_gsl_fft.h +62 -0
- data/include/rb_gsl_fit.h +25 -0
- data/include/rb_gsl_function.h +27 -0
- data/include/rb_gsl_graph.h +70 -0
- data/include/rb_gsl_histogram.h +63 -0
- data/include/rb_gsl_histogram3d.h +97 -0
- data/include/rb_gsl_integration.h +17 -0
- data/include/rb_gsl_interp.h +46 -0
- data/include/rb_gsl_linalg.h +25 -0
- data/include/rb_gsl_math.h +26 -0
- data/include/rb_gsl_odeiv.h +21 -0
- data/include/rb_gsl_poly.h +71 -0
- data/include/rb_gsl_rational.h +37 -0
- data/include/rb_gsl_rng.h +21 -0
- data/include/rb_gsl_root.h +22 -0
- data/include/rb_gsl_sf.h +119 -0
- data/include/rb_gsl_statistics.h +17 -0
- data/include/rb_gsl_tensor.h +45 -0
- data/include/rb_gsl_with_narray.h +29 -0
- data/include/templates_off.h +87 -0
- data/include/templates_on.h +241 -0
- data/lib/gsl.rb +3 -0
- data/lib/gsl/gnuplot.rb +41 -0
- data/lib/gsl/oper.rb +68 -0
- data/lib/ool.rb +22 -0
- data/lib/ool/conmin.rb +30 -0
- data/lib/rbgsl.rb +3 -0
- data/rdoc/alf.rdoc +77 -0
- data/rdoc/blas.rdoc +269 -0
- data/rdoc/bspline.rdoc +42 -0
- data/rdoc/changes.rdoc +164 -0
- data/rdoc/cheb.rdoc +99 -0
- data/rdoc/cholesky_complex.rdoc +46 -0
- data/rdoc/combi.rdoc +125 -0
- data/rdoc/complex.rdoc +210 -0
- data/rdoc/const.rdoc +546 -0
- data/rdoc/dht.rdoc +122 -0
- data/rdoc/diff.rdoc +133 -0
- data/rdoc/ehandling.rdoc +50 -0
- data/rdoc/eigen.rdoc +401 -0
- data/rdoc/fft.rdoc +535 -0
- data/rdoc/fit.rdoc +284 -0
- data/rdoc/function.rdoc +94 -0
- data/rdoc/graph.rdoc +137 -0
- data/rdoc/hist.rdoc +409 -0
- data/rdoc/hist2d.rdoc +279 -0
- data/rdoc/hist3d.rdoc +112 -0
- data/rdoc/index.rdoc +62 -0
- data/rdoc/integration.rdoc +398 -0
- data/rdoc/interp.rdoc +231 -0
- data/rdoc/intro.rdoc +27 -0
- data/rdoc/linalg.rdoc +681 -0
- data/rdoc/linalg_complex.rdoc +88 -0
- data/rdoc/math.rdoc +276 -0
- data/rdoc/matrix.rdoc +1093 -0
- data/rdoc/min.rdoc +189 -0
- data/rdoc/monte.rdoc +234 -0
- data/rdoc/multimin.rdoc +312 -0
- data/rdoc/multiroot.rdoc +293 -0
- data/rdoc/narray.rdoc +177 -0
- data/rdoc/ndlinear.rdoc +250 -0
- data/rdoc/nonlinearfit.rdoc +348 -0
- data/rdoc/ntuple.rdoc +88 -0
- data/rdoc/odeiv.rdoc +378 -0
- data/rdoc/perm.rdoc +221 -0
- data/rdoc/poly.rdoc +335 -0
- data/rdoc/qrng.rdoc +90 -0
- data/rdoc/randist.rdoc +233 -0
- data/rdoc/ref.rdoc +93 -0
- data/rdoc/rng.rdoc +203 -0
- data/rdoc/rngextra.rdoc +11 -0
- data/rdoc/roots.rdoc +305 -0
- data/rdoc/screenshot.rdoc +40 -0
- data/rdoc/sf.rdoc +1622 -0
- data/rdoc/siman.rdoc +89 -0
- data/rdoc/sort.rdoc +94 -0
- data/rdoc/start.rdoc +16 -0
- data/rdoc/stats.rdoc +219 -0
- data/rdoc/sum.rdoc +65 -0
- data/rdoc/tensor.rdoc +251 -0
- data/rdoc/tut.rdoc +5 -0
- data/rdoc/use.rdoc +177 -0
- data/rdoc/vector.rdoc +1243 -0
- data/rdoc/vector_complex.rdoc +347 -0
- data/rdoc/wavelet.rdoc +218 -0
- data/setup.rb +1585 -0
- data/tests/blas/amax.rb +14 -0
- data/tests/blas/asum.rb +16 -0
- data/tests/blas/axpy.rb +25 -0
- data/tests/blas/copy.rb +23 -0
- data/tests/blas/dot.rb +23 -0
- data/tests/bspline.rb +53 -0
- data/tests/cdf.rb +1388 -0
- data/tests/cheb.rb +112 -0
- data/tests/combination.rb +123 -0
- data/tests/complex.rb +17 -0
- data/tests/const.rb +24 -0
- data/tests/deriv.rb +85 -0
- data/tests/dht/dht1.rb +17 -0
- data/tests/dht/dht2.rb +23 -0
- data/tests/dht/dht3.rb +23 -0
- data/tests/dht/dht4.rb +23 -0
- data/tests/diff.rb +78 -0
- data/tests/eigen/eigen.rb +220 -0
- data/tests/eigen/gen.rb +105 -0
- data/tests/eigen/genherm.rb +66 -0
- data/tests/eigen/gensymm.rb +68 -0
- data/tests/eigen/nonsymm.rb +53 -0
- data/tests/eigen/nonsymmv.rb +53 -0
- data/tests/eigen/symm-herm.rb +74 -0
- data/tests/err.rb +58 -0
- data/tests/fit.rb +124 -0
- data/tests/gsl_test.rb +118 -0
- data/tests/gsl_test2.rb +110 -0
- data/tests/histo.rb +12 -0
- data/tests/integration/integration1.rb +72 -0
- data/tests/integration/integration2.rb +71 -0
- data/tests/integration/integration3.rb +71 -0
- data/tests/integration/integration4.rb +71 -0
- data/tests/interp.rb +45 -0
- data/tests/linalg/HH.rb +64 -0
- data/tests/linalg/LU.rb +47 -0
- data/tests/linalg/QR.rb +77 -0
- data/tests/linalg/SV.rb +24 -0
- data/tests/linalg/TDN.rb +116 -0
- data/tests/linalg/TDS.rb +122 -0
- data/tests/linalg/bidiag.rb +73 -0
- data/tests/linalg/cholesky.rb +20 -0
- data/tests/linalg/linalg.rb +158 -0
- data/tests/matrix/matrix_complex_test.rb +36 -0
- data/tests/matrix/matrix_nmf_test.rb +39 -0
- data/tests/matrix/matrix_test.rb +48 -0
- data/tests/min.rb +99 -0
- data/tests/monte/miser.rb +31 -0
- data/tests/monte/vegas.rb +45 -0
- data/tests/multifit/test_2dgauss.rb +112 -0
- data/tests/multifit/test_brown.rb +90 -0
- data/tests/multifit/test_enso.rb +246 -0
- data/tests/multifit/test_filip.rb +155 -0
- data/tests/multifit/test_gauss.rb +97 -0
- data/tests/multifit/test_longley.rb +110 -0
- data/tests/multifit/test_multifit.rb +52 -0
- data/tests/multimin.rb +139 -0
- data/tests/multiroot.rb +131 -0
- data/tests/multiset.rb +52 -0
- data/tests/narray/blas_dnrm2.rb +20 -0
- data/tests/odeiv.rb +353 -0
- data/tests/poly/poly.rb +290 -0
- data/tests/poly/special.rb +65 -0
- data/tests/qrng.rb +131 -0
- data/tests/quartic.rb +29 -0
- data/tests/randist.rb +134 -0
- data/tests/rng.rb +305 -0
- data/tests/roots.rb +76 -0
- data/tests/run-test.sh +17 -0
- data/tests/sf/gsl_test_sf.rb +249 -0
- data/tests/sf/test_airy.rb +83 -0
- data/tests/sf/test_bessel.rb +306 -0
- data/tests/sf/test_coulomb.rb +17 -0
- data/tests/sf/test_dilog.rb +25 -0
- data/tests/sf/test_gamma.rb +209 -0
- data/tests/sf/test_hyperg.rb +356 -0
- data/tests/sf/test_legendre.rb +227 -0
- data/tests/sf/test_mathieu.rb +59 -0
- data/tests/sf/test_mode.rb +19 -0
- data/tests/sf/test_sf.rb +839 -0
- data/tests/stats.rb +174 -0
- data/tests/stats_mt.rb +16 -0
- data/tests/sum.rb +98 -0
- data/tests/sys.rb +323 -0
- data/tests/tensor.rb +419 -0
- data/tests/vector/vector_complex_test.rb +101 -0
- data/tests/vector/vector_test.rb +141 -0
- data/tests/wavelet.rb +142 -0
- metadata +789 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
/* histogram/find.c
|
2
|
+
*
|
3
|
+
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
|
4
|
+
*
|
5
|
+
* This program is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
7
|
+
* the Free Software Foundation; either version 2 of the License, or (at
|
8
|
+
* your option) any later version.
|
9
|
+
*
|
10
|
+
* This program is distributed in the hope that it will be useful, but
|
11
|
+
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
* General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU General Public License
|
16
|
+
* along with this program; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
18
|
+
*/
|
19
|
+
|
20
|
+
#include "rb_gsl_histogram.h"
|
21
|
+
/* determines whether to optimize for linear ranges */
|
22
|
+
#define LINEAR_OPT 1
|
23
|
+
|
24
|
+
int mygsl_find (const size_t n, const double range[], const double x, size_t * i)
|
25
|
+
{
|
26
|
+
size_t i_linear, lower, upper, mid;
|
27
|
+
if (x < range[0]) return -1;
|
28
|
+
if (x >= range[n]) return +1;
|
29
|
+
|
30
|
+
/* optimize for linear case */
|
31
|
+
|
32
|
+
#ifdef LINEAR_OPT
|
33
|
+
{
|
34
|
+
double u = (x - range[0]) / (range[n] - range[0]);
|
35
|
+
i_linear = (size_t) (n*u);
|
36
|
+
}
|
37
|
+
|
38
|
+
if (x >= range[i_linear] && x < range[i_linear + 1])
|
39
|
+
{
|
40
|
+
*i = i_linear;
|
41
|
+
return 0;
|
42
|
+
}
|
43
|
+
#endif
|
44
|
+
|
45
|
+
/* perform binary search */
|
46
|
+
|
47
|
+
upper = n ;
|
48
|
+
lower = 0 ;
|
49
|
+
|
50
|
+
while (upper - lower > 1)
|
51
|
+
{
|
52
|
+
mid = (upper + lower) / 2 ;
|
53
|
+
|
54
|
+
if (x >= range[mid])
|
55
|
+
{
|
56
|
+
lower = mid ;
|
57
|
+
}
|
58
|
+
else
|
59
|
+
{
|
60
|
+
upper = mid ;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
*i = lower ;
|
65
|
+
|
66
|
+
/* sanity check the result */
|
67
|
+
|
68
|
+
if (x < range[lower] || x >= range[lower + 1])
|
69
|
+
{
|
70
|
+
GSL_ERROR ("x not found in range", GSL_ESANITY);
|
71
|
+
}
|
72
|
+
|
73
|
+
return 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
int mygsl_find2d (const size_t nx, const double xrange[],
|
77
|
+
const size_t ny, const double yrange[],
|
78
|
+
const double x, const double y,
|
79
|
+
size_t * i, size_t * j)
|
80
|
+
{
|
81
|
+
int status = mygsl_find (nx, xrange, x, i);
|
82
|
+
if (status) return status;
|
83
|
+
status = mygsl_find (ny, yrange, y, j);
|
84
|
+
if (status) return status;
|
85
|
+
return 0;
|
86
|
+
}
|
87
|
+
|
88
|
+
int mygsl_find3d (const size_t nx, const double xrange[],
|
89
|
+
const size_t ny, const double yrange[],
|
90
|
+
const size_t nz, const double zrange[],
|
91
|
+
const double x, const double y, const double z,
|
92
|
+
size_t * i, size_t * j, size_t *k)
|
93
|
+
{
|
94
|
+
int status = mygsl_find (nx, xrange, x, i);
|
95
|
+
if (status) return status;
|
96
|
+
status = mygsl_find (ny, yrange, y, j);
|
97
|
+
if (status) return status;
|
98
|
+
status = mygsl_find (nz, zrange, z, k);
|
99
|
+
if (status) return status;
|
100
|
+
return 0;
|
101
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
/* gsl_histogram_oper.c
|
2
|
+
* Copyright (C) 2000 Simone Piccardi
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU General Public License as
|
6
|
+
* published by the Free Software Foundation; either version 2 of the
|
7
|
+
* License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
* General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU General Public
|
15
|
+
* License along with this library; if not, write to the
|
16
|
+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
17
|
+
* Boston, MA 02111-1307, USA.
|
18
|
+
*/
|
19
|
+
/***************************************************************
|
20
|
+
*
|
21
|
+
* File gsl_histogram_oper.c:
|
22
|
+
* Routine to make operation on histograms.
|
23
|
+
* Need GSL library and header.
|
24
|
+
* Contains the routines:
|
25
|
+
* gsl_histogram_same_binning check if two histograms have the same binning
|
26
|
+
* gsl_histogram_add add two histograms
|
27
|
+
* gsl_histogram_sub subctract two histograms
|
28
|
+
* gsl_histogram_mult multiply two histograms
|
29
|
+
* gsl_histogram_div divide two histograms
|
30
|
+
* gsl_histogram_scale scale histogram contents
|
31
|
+
*
|
32
|
+
* Author: S. Piccardi
|
33
|
+
* Jan. 2000
|
34
|
+
*
|
35
|
+
***************************************************************/
|
36
|
+
#include <stdlib.h>
|
37
|
+
#include <gsl/gsl_errno.h>
|
38
|
+
#include <gsl/gsl_math.h>
|
39
|
+
#include <gsl/gsl_histogram.h>
|
40
|
+
|
41
|
+
/*
|
42
|
+
* gsl_histogram_same_binning:
|
43
|
+
* control if two histograms have the
|
44
|
+
* same binning
|
45
|
+
*/
|
46
|
+
|
47
|
+
int
|
48
|
+
mygsl_histogram_equal_bins_p (const gsl_histogram * h1, const gsl_histogram * h2)
|
49
|
+
{
|
50
|
+
if (h1->n != h2->n)
|
51
|
+
{
|
52
|
+
return 0;
|
53
|
+
}
|
54
|
+
|
55
|
+
{
|
56
|
+
size_t i;
|
57
|
+
/* init ranges */
|
58
|
+
|
59
|
+
for (i = 0; i <= h1->n; i++)
|
60
|
+
{
|
61
|
+
if (gsl_fcmp(h1->range[i],h2->range[i], 1e-12))
|
62
|
+
{
|
63
|
+
return 0;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
return 1;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* gsl_histogram_add:
|
73
|
+
* add two histograms
|
74
|
+
*/
|
75
|
+
int
|
76
|
+
mygsl_histogram_add (gsl_histogram * h1, const gsl_histogram * h2)
|
77
|
+
{
|
78
|
+
size_t i;
|
79
|
+
|
80
|
+
if (!mygsl_histogram_equal_bins_p (h1, h2))
|
81
|
+
{
|
82
|
+
GSL_ERROR ("histograms have different binning", GSL_EINVAL);
|
83
|
+
}
|
84
|
+
|
85
|
+
for (i = 0; i < h1->n; i++)
|
86
|
+
{
|
87
|
+
h1->bin[i] += h2->bin[i];
|
88
|
+
}
|
89
|
+
|
90
|
+
return GSL_SUCCESS;
|
91
|
+
}
|
92
|
+
|
93
|
+
/*
|
94
|
+
* gsl_histogram_sub:
|
95
|
+
* subtract two histograms
|
96
|
+
*/
|
97
|
+
|
98
|
+
int
|
99
|
+
mygsl_histogram_sub (gsl_histogram * h1, const gsl_histogram * h2)
|
100
|
+
{
|
101
|
+
size_t i;
|
102
|
+
|
103
|
+
if (!mygsl_histogram_equal_bins_p (h1, h2))
|
104
|
+
{
|
105
|
+
GSL_ERROR ("histograms have different binning", GSL_EINVAL);
|
106
|
+
}
|
107
|
+
|
108
|
+
for (i = 0; i < h1->n; i++)
|
109
|
+
{
|
110
|
+
h1->bin[i] -= h2->bin[i];
|
111
|
+
}
|
112
|
+
|
113
|
+
return GSL_SUCCESS;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
/*
|
118
|
+
* gsl_histogram_mult:
|
119
|
+
* multiply two histograms
|
120
|
+
*/
|
121
|
+
|
122
|
+
int
|
123
|
+
mygsl_histogram_mul (gsl_histogram * h1, const gsl_histogram * h2)
|
124
|
+
{
|
125
|
+
size_t i;
|
126
|
+
|
127
|
+
if (!mygsl_histogram_equal_bins_p (h1, h2))
|
128
|
+
{
|
129
|
+
GSL_ERROR ("histograms have different binning", GSL_EINVAL);
|
130
|
+
}
|
131
|
+
|
132
|
+
for (i = 0; i < h1->n; i++)
|
133
|
+
{
|
134
|
+
h1->bin[i] *= h2->bin[i];
|
135
|
+
}
|
136
|
+
|
137
|
+
return GSL_SUCCESS;
|
138
|
+
}
|
139
|
+
/*
|
140
|
+
* gsl_histogram_div:
|
141
|
+
* divide two histograms
|
142
|
+
*/
|
143
|
+
int
|
144
|
+
mygsl_histogram_div (gsl_histogram * h1, const gsl_histogram * h2)
|
145
|
+
{
|
146
|
+
size_t i;
|
147
|
+
|
148
|
+
if (!mygsl_histogram_equal_bins_p (h1, h2))
|
149
|
+
{
|
150
|
+
GSL_ERROR ("histograms have different binning", GSL_EINVAL);
|
151
|
+
}
|
152
|
+
|
153
|
+
for (i = 0; i < h1->n; i++)
|
154
|
+
{
|
155
|
+
h1->bin[i] /= h2->bin[i];
|
156
|
+
}
|
157
|
+
|
158
|
+
return GSL_SUCCESS;
|
159
|
+
}
|
data/ext/ieee.c
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
/*
|
2
|
+
ieee.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2001-2006 by Yoshiki Tsunesada
|
5
|
+
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
7
|
+
under the terms of the GNU General Public License.
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "rb_gsl.h"
|
13
|
+
|
14
|
+
static VALUE rb_gsl_ieee_env_setup(VALUE obj)
|
15
|
+
{
|
16
|
+
gsl_ieee_env_setup();
|
17
|
+
return obj;
|
18
|
+
}
|
19
|
+
|
20
|
+
static VALUE rb_gsl_ieee_fprintf_double(int argc, VALUE *argv, VALUE obj)
|
21
|
+
{
|
22
|
+
#ifdef RUBY_1_9_LATER
|
23
|
+
rb_io_t *fptr = NULL;
|
24
|
+
double ftmp;
|
25
|
+
#else
|
26
|
+
OpenFile *fptr = NULL;
|
27
|
+
#endif
|
28
|
+
FILE *fp = NULL;
|
29
|
+
int flag = 0;
|
30
|
+
VALUE vtmp;
|
31
|
+
|
32
|
+
switch (argc) {
|
33
|
+
case 2:
|
34
|
+
switch (TYPE(argv[0])) {
|
35
|
+
case T_STRING:
|
36
|
+
fp = fopen(RSTRING_PTR(argv[0]), "w");
|
37
|
+
flag = 1;
|
38
|
+
break;
|
39
|
+
case T_FILE:
|
40
|
+
GetOpenFile(argv[0], fptr);
|
41
|
+
rb_io_check_writable(fptr);
|
42
|
+
#ifdef RUBY_1_9_LATER
|
43
|
+
fp = rb_io_stdio_file(fptr);
|
44
|
+
#else
|
45
|
+
fp = GetWriteFile(fptr);
|
46
|
+
#endif
|
47
|
+
break;
|
48
|
+
default:
|
49
|
+
rb_raise(rb_eTypeError, "wrong type argument %s (IO or String expected)",
|
50
|
+
rb_class2name(CLASS_OF(argv[0])));
|
51
|
+
}
|
52
|
+
vtmp = argv[1];
|
53
|
+
break;
|
54
|
+
case 1:
|
55
|
+
vtmp = argv[0];
|
56
|
+
fp = stdout;
|
57
|
+
break;
|
58
|
+
default:
|
59
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
60
|
+
}
|
61
|
+
if (TYPE(vtmp) != T_FLOAT)
|
62
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (Float expected)",
|
63
|
+
rb_class2name(CLASS_OF(vtmp)));
|
64
|
+
#ifdef RUBY_1_9_LATER
|
65
|
+
ftmp = RFLOAT_VALUE(vtmp);
|
66
|
+
gsl_ieee_fprintf_double(fp, &ftmp);
|
67
|
+
#else
|
68
|
+
gsl_ieee_fprintf_double(fp, &(RFLOAT(vtmp)->value));
|
69
|
+
#endif
|
70
|
+
if (fp == stdout) fprintf(stdout, "\n");
|
71
|
+
if (flag == 1) fclose(fp);
|
72
|
+
return obj;
|
73
|
+
}
|
74
|
+
|
75
|
+
static VALUE rb_gsl_ieee_printf_double(VALUE obj, VALUE xx)
|
76
|
+
{
|
77
|
+
double x;
|
78
|
+
x = NUM2DBL(xx);
|
79
|
+
gsl_ieee_printf_double(&x);
|
80
|
+
return xx;
|
81
|
+
}
|
82
|
+
|
83
|
+
void Init_gsl_ieee(VALUE module)
|
84
|
+
{
|
85
|
+
VALUE mgsl_ieee;
|
86
|
+
mgsl_ieee = rb_define_module_under(module, "IEEE");
|
87
|
+
|
88
|
+
rb_define_singleton_method(mgsl_ieee, "env_setup",
|
89
|
+
rb_gsl_ieee_env_setup, 0);
|
90
|
+
rb_define_module_function(module, "ieee_env_setup", rb_gsl_ieee_env_setup, 0);
|
91
|
+
rb_define_singleton_method(mgsl_ieee, "fprintf_double",
|
92
|
+
rb_gsl_ieee_fprintf_double, -1);
|
93
|
+
rb_define_singleton_method(mgsl_ieee, "fprintf",
|
94
|
+
rb_gsl_ieee_fprintf_double, -1);
|
95
|
+
rb_define_singleton_method(mgsl_ieee, "printf",
|
96
|
+
rb_gsl_ieee_printf_double, -1);
|
97
|
+
rb_define_singleton_method(mgsl_ieee, "printf_double",
|
98
|
+
rb_gsl_ieee_printf_double, -1);
|
99
|
+
|
100
|
+
}
|
data/ext/integration.c
ADDED
@@ -0,0 +1,1179 @@
|
|
1
|
+
/*
|
2
|
+
integration.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2001-2006 by Yoshiki Tsunesada
|
5
|
+
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
7
|
+
under the terms of the GNU General Public License.
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "rb_gsl_config.h"
|
13
|
+
|
14
|
+
#include "rb_gsl_array.h"
|
15
|
+
#include "rb_gsl_function.h"
|
16
|
+
#include "rb_gsl_integration.h"
|
17
|
+
#include "rb_gsl_common.h"
|
18
|
+
|
19
|
+
#ifndef CHECK_WORKSPACE
|
20
|
+
#define CHECK_WORKSPACE(x) if(CLASS_OF(x)!=cgsl_integration_workspace)\
|
21
|
+
rb_raise(rb_eTypeError,\
|
22
|
+
"wrong argument type %s (Integration::Workspace expected)",\
|
23
|
+
rb_class2name(CLASS_OF(x)));
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#define EPSABS_DEFAULT 0.0
|
27
|
+
#define EPSREL_DEFAULT 1e-10
|
28
|
+
#define LIMIT_DEFAULT 1000
|
29
|
+
#define KEY_DEFAULT GSL_INTEG_GAUSS61
|
30
|
+
|
31
|
+
static VALUE cgsl_integration_qaws_table, cgsl_integration_qawo_table;
|
32
|
+
|
33
|
+
static VALUE cgsl_integration_workspace;
|
34
|
+
|
35
|
+
#ifdef GSL_1_14_LATER
|
36
|
+
static VALUE cgsl_integration_glfixed_table;
|
37
|
+
#endif
|
38
|
+
|
39
|
+
static int get_a_b(int argc, VALUE *argv, int argstart, double *a, double *b);
|
40
|
+
static int get_epsabs_epsrel(int argc, VALUE *argv, int argstart,
|
41
|
+
double *epsabs, double *epsrel);
|
42
|
+
static int get_a_b_epsabs_epsrel(int argc, VALUE *argv, int argstart,
|
43
|
+
double *a, double *b, double *epsabs,
|
44
|
+
double *epsrel);
|
45
|
+
static int get_limit_key_workspace(int argc, VALUE *argv, int argstart,
|
46
|
+
size_t *limit, int *key,
|
47
|
+
gsl_integration_workspace **w);
|
48
|
+
static int get_limit_workspace(int argc, VALUE *argv, int argstart,
|
49
|
+
size_t *limit,
|
50
|
+
gsl_integration_workspace **w);
|
51
|
+
static int get_epsabs_epsrel_limit_workspace(int argc, VALUE *argv, int argstart,
|
52
|
+
double *epsabs, double *epsrel,
|
53
|
+
size_t *limit,
|
54
|
+
gsl_integration_workspace **w);
|
55
|
+
|
56
|
+
static int get_a_b(int argc, VALUE *argv, int argstart, double *a, double *b)
|
57
|
+
{
|
58
|
+
int itmp;
|
59
|
+
VALUE aa, bb;
|
60
|
+
if (argstart >= argc) return argstart;
|
61
|
+
if (TYPE(argv[argstart]) == T_ARRAY) {
|
62
|
+
aa = rb_ary_entry(argv[argstart], 0);
|
63
|
+
bb = rb_ary_entry(argv[argstart], 1);
|
64
|
+
Need_Float(aa); Need_Float(bb);
|
65
|
+
// *a = RFLOAT(aa)->value;
|
66
|
+
// *b = RFLOAT(bb)->value;
|
67
|
+
*a = NUM2DBL(aa);
|
68
|
+
*b = NUM2DBL(bb);
|
69
|
+
itmp = argstart + 1;
|
70
|
+
} else {
|
71
|
+
Need_Float(argv[argstart]); Need_Float(argv[argstart+1]);
|
72
|
+
*a = NUM2DBL(argv[argstart]);
|
73
|
+
*b = NUM2DBL(argv[argstart+1]);
|
74
|
+
itmp = argstart + 2;
|
75
|
+
}
|
76
|
+
return itmp;
|
77
|
+
}
|
78
|
+
|
79
|
+
static int get_epsabs_epsrel(int argc, VALUE *argv, int argstart,
|
80
|
+
double *epsabs, double *epsrel)
|
81
|
+
{
|
82
|
+
int itmp;
|
83
|
+
VALUE aa, bb;
|
84
|
+
*epsabs = EPSABS_DEFAULT;
|
85
|
+
*epsrel = EPSREL_DEFAULT;
|
86
|
+
if (argstart >= argc) return argstart;
|
87
|
+
if (TYPE(argv[argstart]) == T_ARRAY) {
|
88
|
+
aa = rb_ary_entry(argv[argstart], 0);
|
89
|
+
bb = rb_ary_entry(argv[argstart], 1);
|
90
|
+
Need_Float(aa); Need_Float(bb);
|
91
|
+
*epsabs = NUM2DBL(aa);
|
92
|
+
*epsrel = NUM2DBL(bb);
|
93
|
+
itmp = 1;
|
94
|
+
} else {
|
95
|
+
Need_Float(argv[argstart]); Need_Float(argv[argstart+1]);
|
96
|
+
*epsabs = NUM2DBL(argv[argstart]);
|
97
|
+
*epsrel = NUM2DBL(argv[argstart+1]);
|
98
|
+
itmp = 2;
|
99
|
+
}
|
100
|
+
return argstart + itmp;
|
101
|
+
}
|
102
|
+
|
103
|
+
static int get_a_b_epsabs_epsrel(int argc, VALUE *argv, int argstart,
|
104
|
+
double *a, double *b, double *epsabs,
|
105
|
+
double *epsrel)
|
106
|
+
{
|
107
|
+
int itmp;
|
108
|
+
*epsabs = EPSABS_DEFAULT;
|
109
|
+
*epsrel = EPSREL_DEFAULT;
|
110
|
+
itmp = get_a_b(argc, argv, argstart, a, b);
|
111
|
+
itmp = get_epsabs_epsrel(argc, argv, itmp, epsabs, epsrel);
|
112
|
+
return itmp;
|
113
|
+
}
|
114
|
+
|
115
|
+
static int get_limit_key_workspace(int argc, VALUE *argv, int argstart,
|
116
|
+
size_t *limit, int *key,
|
117
|
+
gsl_integration_workspace **w)
|
118
|
+
{
|
119
|
+
int flag = 0;
|
120
|
+
switch (argc-argstart) {
|
121
|
+
case 3:
|
122
|
+
CHECK_FIXNUM(argv[argstart]);
|
123
|
+
CHECK_FIXNUM(argv[argstart+1]);
|
124
|
+
CHECK_WORKSPACE(argv[argstart+2]);
|
125
|
+
*limit = FIX2INT(argv[argstart]);
|
126
|
+
*key = FIX2INT(argv[argstart+1]);
|
127
|
+
Data_Get_Struct(argv[argstart+2], gsl_integration_workspace, *w);
|
128
|
+
flag = 0;
|
129
|
+
break;
|
130
|
+
case 1:
|
131
|
+
CHECK_FIXNUM(argv[argstart]);
|
132
|
+
*key = FIX2INT(argv[argstart]);
|
133
|
+
*limit = LIMIT_DEFAULT;
|
134
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
135
|
+
flag = 1;
|
136
|
+
break;
|
137
|
+
case 2:
|
138
|
+
if (TYPE(argv[argc-1]) == T_FIXNUM) {
|
139
|
+
CHECK_FIXNUM(argv[argc-2]);
|
140
|
+
*limit = FIX2INT(argv[argc-2]);
|
141
|
+
*key = FIX2INT(argv[argc-1]);
|
142
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
143
|
+
flag = 1;
|
144
|
+
} else {
|
145
|
+
CHECK_FIXNUM(argv[argc-2]);
|
146
|
+
CHECK_WORKSPACE(argv[argc-1]);
|
147
|
+
*key = FIX2INT(argv[argc-2]);
|
148
|
+
Data_Get_Struct(argv[argc-1], gsl_integration_workspace, *w);
|
149
|
+
*limit = (*w)->limit;
|
150
|
+
flag = 0;
|
151
|
+
}
|
152
|
+
break;
|
153
|
+
case 0:
|
154
|
+
*key = KEY_DEFAULT;
|
155
|
+
*limit = LIMIT_DEFAULT;
|
156
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
157
|
+
flag = 1;
|
158
|
+
break;
|
159
|
+
default:
|
160
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
161
|
+
break;
|
162
|
+
}
|
163
|
+
if (*w == NULL) rb_raise(rb_eRuntimeError, "something wrong with workspace");
|
164
|
+
return flag;
|
165
|
+
}
|
166
|
+
|
167
|
+
static int get_limit_workspace(int argc, VALUE *argv, int argstart,
|
168
|
+
size_t *limit,
|
169
|
+
gsl_integration_workspace **w)
|
170
|
+
{
|
171
|
+
int flag = 0;
|
172
|
+
|
173
|
+
switch (argc-argstart) {
|
174
|
+
case 2:
|
175
|
+
CHECK_FIXNUM(argv[argstart]);
|
176
|
+
*limit = FIX2INT(argv[argstart]);
|
177
|
+
CHECK_WORKSPACE(argv[argstart+1]);
|
178
|
+
Data_Get_Struct(argv[argstart+1], gsl_integration_workspace, *w);
|
179
|
+
flag = 0;
|
180
|
+
break;
|
181
|
+
case 0:
|
182
|
+
*limit = LIMIT_DEFAULT;
|
183
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
184
|
+
flag = 1;
|
185
|
+
break;
|
186
|
+
case 1:
|
187
|
+
switch (TYPE(argv[argstart])) {
|
188
|
+
case T_FIXNUM:
|
189
|
+
case T_BIGNUM:
|
190
|
+
CHECK_FIXNUM(argv[argstart]);
|
191
|
+
*limit = FIX2INT(argv[argstart]);
|
192
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
193
|
+
flag = 1;
|
194
|
+
break;
|
195
|
+
default:
|
196
|
+
CHECK_WORKSPACE(argv[argc-1]);
|
197
|
+
Data_Get_Struct(argv[argc-1], gsl_integration_workspace, *w);
|
198
|
+
*limit = (*w)->limit;
|
199
|
+
flag = 0;
|
200
|
+
break;
|
201
|
+
}
|
202
|
+
break;
|
203
|
+
default:
|
204
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
205
|
+
break;
|
206
|
+
}
|
207
|
+
if (*w == NULL) rb_raise(rb_eRuntimeError, "something wrong with workspace");
|
208
|
+
return flag;
|
209
|
+
}
|
210
|
+
|
211
|
+
static int get_epsabs_epsrel_limit_workspace(int argc, VALUE *argv, int argstart,
|
212
|
+
double *epsabs, double *epsrel,
|
213
|
+
size_t *limit,
|
214
|
+
gsl_integration_workspace **w)
|
215
|
+
{
|
216
|
+
int flag = 0, itmp;
|
217
|
+
itmp = argstart;
|
218
|
+
*epsabs = EPSABS_DEFAULT;
|
219
|
+
*epsrel = EPSREL_DEFAULT;
|
220
|
+
*limit = LIMIT_DEFAULT;
|
221
|
+
switch (argc-itmp) {
|
222
|
+
case 0:
|
223
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
224
|
+
flag = 1;
|
225
|
+
break;
|
226
|
+
case 1:
|
227
|
+
if (TYPE(argv[itmp]) == T_ARRAY) {
|
228
|
+
get_epsabs_epsrel(argc, argv, itmp, epsabs, epsrel);
|
229
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
230
|
+
flag = 1;
|
231
|
+
} else {
|
232
|
+
flag = get_limit_workspace(argc, argv, itmp, limit, w);
|
233
|
+
}
|
234
|
+
break;
|
235
|
+
case 2:
|
236
|
+
case 3:
|
237
|
+
switch (TYPE(argv[itmp])) {
|
238
|
+
case T_ARRAY:
|
239
|
+
itmp = get_epsabs_epsrel(argc, argv, itmp, epsabs, epsrel);
|
240
|
+
flag = get_limit_workspace(argc, argv, itmp, limit, w);
|
241
|
+
break;
|
242
|
+
case T_FLOAT:
|
243
|
+
get_epsabs_epsrel(argc, argv, itmp, epsabs, epsrel);
|
244
|
+
*w = gsl_integration_workspace_alloc(*limit);
|
245
|
+
flag = 1;
|
246
|
+
break;
|
247
|
+
default:
|
248
|
+
flag = get_limit_workspace(argc, argv, itmp, limit, w);
|
249
|
+
break;
|
250
|
+
}
|
251
|
+
break;
|
252
|
+
case 4:
|
253
|
+
itmp = get_epsabs_epsrel(argc, argv, itmp, epsabs, epsrel);
|
254
|
+
flag = get_limit_workspace(argc, argv, itmp, limit, w);
|
255
|
+
break;
|
256
|
+
default:
|
257
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
258
|
+
break;
|
259
|
+
}
|
260
|
+
if (*w == NULL) rb_raise(rb_eRuntimeError, "something wrong with workspace");
|
261
|
+
return flag;
|
262
|
+
}
|
263
|
+
|
264
|
+
static VALUE rb_gsl_integration_qng(int argc, VALUE *argv, VALUE obj)
|
265
|
+
{
|
266
|
+
double a, b, epsabs = EPSABS_DEFAULT, epsrel = EPSREL_DEFAULT;
|
267
|
+
double result, abserr;
|
268
|
+
size_t neval;
|
269
|
+
gsl_function *F = NULL;
|
270
|
+
int status;
|
271
|
+
// local variable 'itmp' declared and set, but never used
|
272
|
+
//int itmp;
|
273
|
+
|
274
|
+
if (argc < 1) rb_raise(rb_eArgError,
|
275
|
+
"wrong number of arguments (%d for >= 1)", argc);
|
276
|
+
|
277
|
+
switch (TYPE(obj)) {
|
278
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
279
|
+
CHECK_FUNCTION(argv[0]);
|
280
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
281
|
+
/*itmp =*/ get_a_b_epsabs_epsrel(argc, argv, 1, &a, &b, &epsabs, &epsrel);
|
282
|
+
break;
|
283
|
+
default:
|
284
|
+
/*itmp =*/ get_a_b_epsabs_epsrel(argc, argv, 0, &a, &b, &epsabs, &epsrel);
|
285
|
+
Data_Get_Struct(obj, gsl_function, F);
|
286
|
+
break;
|
287
|
+
}
|
288
|
+
status = gsl_integration_qng(F, a, b, epsabs, epsrel,
|
289
|
+
&result, &abserr, &neval);
|
290
|
+
|
291
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
292
|
+
INT2FIX(neval), INT2FIX(status));
|
293
|
+
}
|
294
|
+
|
295
|
+
static VALUE rb_gsl_integration_qag(int argc, VALUE *argv, VALUE obj)
|
296
|
+
{
|
297
|
+
double a, b, epsabs = EPSABS_DEFAULT, epsrel = EPSREL_DEFAULT;
|
298
|
+
double result, abserr;
|
299
|
+
size_t limit = LIMIT_DEFAULT;
|
300
|
+
gsl_function *F = NULL;
|
301
|
+
gsl_integration_workspace *w = NULL;
|
302
|
+
int key = KEY_DEFAULT, status, intervals, itmp, flag = 0;
|
303
|
+
if (argc < 1) rb_raise(rb_eArgError,
|
304
|
+
"wrong number of arguments (%d for >= 1)", argc);
|
305
|
+
|
306
|
+
switch (TYPE(obj)) {
|
307
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
308
|
+
CHECK_FUNCTION(argv[0]);
|
309
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
310
|
+
if (argc == 3) {
|
311
|
+
CHECK_FIXNUM(argv[2]);
|
312
|
+
get_a_b(argc, argv, 1, &a, &b);
|
313
|
+
key = FIX2INT(argv[2]);
|
314
|
+
w = gsl_integration_workspace_alloc(limit);
|
315
|
+
flag = 1;
|
316
|
+
} else if (argc == 4) {
|
317
|
+
CHECK_FIXNUM(argv[3]);
|
318
|
+
get_a_b(argc, argv, 1, &a, &b);
|
319
|
+
key = FIX2INT(argv[3]);
|
320
|
+
w = gsl_integration_workspace_alloc(limit);
|
321
|
+
flag = 1;
|
322
|
+
} else {
|
323
|
+
itmp = get_a_b_epsabs_epsrel(argc, argv, 1, &a, &b, &epsabs, &epsrel);
|
324
|
+
flag = get_limit_key_workspace(argc, argv, itmp, &limit, &key, &w);
|
325
|
+
}
|
326
|
+
break;
|
327
|
+
default:
|
328
|
+
if (argc == 2) {
|
329
|
+
if (FIXNUM_P(argv[1])) {
|
330
|
+
key = FIX2INT(argv[1]);
|
331
|
+
w = gsl_integration_workspace_alloc(limit);
|
332
|
+
flag = 1;
|
333
|
+
} else if (rb_obj_is_kind_of(argv[1], cgsl_integration_workspace)) {
|
334
|
+
Data_Get_Struct(argv[1], gsl_integration_workspace, w);
|
335
|
+
flag = 0;
|
336
|
+
} else {
|
337
|
+
rb_raise(rb_eTypeError, "Key or Workspace expected");
|
338
|
+
}
|
339
|
+
itmp = get_a_b(argc, argv, 0, &a, &b);
|
340
|
+
} else if (argc == 3) {
|
341
|
+
if (FIXNUM_P(argv[2])) {
|
342
|
+
key = FIX2INT(argv[2]);
|
343
|
+
w = gsl_integration_workspace_alloc(limit);
|
344
|
+
flag = 1;
|
345
|
+
} else if (rb_obj_is_kind_of(argv[2], cgsl_integration_workspace)) {
|
346
|
+
Data_Get_Struct(argv[2], gsl_integration_workspace, w);
|
347
|
+
flag = 0;
|
348
|
+
} else {
|
349
|
+
rb_raise(rb_eTypeError, "Key or Workspace expected");
|
350
|
+
}
|
351
|
+
itmp = get_a_b(argc, argv, 0, &a, &b);
|
352
|
+
} else {
|
353
|
+
itmp = get_a_b_epsabs_epsrel(argc, argv, 0, &a, &b, &epsabs, &epsrel);
|
354
|
+
flag = get_limit_key_workspace(argc, argv, itmp, &limit, &key, &w);
|
355
|
+
}
|
356
|
+
Data_Get_Struct(obj, gsl_function, F);
|
357
|
+
break;
|
358
|
+
}
|
359
|
+
status = gsl_integration_qag(F, a, b, epsabs, epsrel, limit, key, w,
|
360
|
+
&result, &abserr);
|
361
|
+
intervals = w->size;
|
362
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
363
|
+
|
364
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
365
|
+
INT2FIX(intervals), INT2FIX(status));
|
366
|
+
}
|
367
|
+
|
368
|
+
static VALUE rb_gsl_integration_qags(int argc, VALUE *argv, VALUE obj)
|
369
|
+
{
|
370
|
+
double a, b, epsabs = EPSABS_DEFAULT, epsrel = EPSREL_DEFAULT;
|
371
|
+
double result, abserr;
|
372
|
+
size_t limit = LIMIT_DEFAULT;
|
373
|
+
gsl_function *F = NULL;
|
374
|
+
gsl_integration_workspace *w = NULL;
|
375
|
+
int status, intervals, flag = 0, itmp;
|
376
|
+
switch (TYPE(obj)) {
|
377
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
378
|
+
CHECK_FUNCTION(argv[0]);
|
379
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
380
|
+
itmp = get_a_b(argc, argv, 1, &a, &b);
|
381
|
+
break;
|
382
|
+
default:
|
383
|
+
Data_Get_Struct(obj, gsl_function, F);
|
384
|
+
itmp = get_a_b(argc, argv, 0, &a, &b);
|
385
|
+
break;
|
386
|
+
}
|
387
|
+
flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp, &epsabs, &epsrel,
|
388
|
+
&limit, &w);
|
389
|
+
|
390
|
+
status = gsl_integration_qags(F, a, b, epsabs, epsrel, limit, w,
|
391
|
+
&result, &abserr);
|
392
|
+
intervals = w->size;
|
393
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
394
|
+
|
395
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
396
|
+
INT2FIX(intervals), INT2FIX(status));
|
397
|
+
}
|
398
|
+
|
399
|
+
static VALUE rb_gsl_integration_qagp(int argc, VALUE *argv, VALUE obj)
|
400
|
+
{
|
401
|
+
double epsabs, epsrel;
|
402
|
+
double result, abserr;
|
403
|
+
size_t limit;
|
404
|
+
gsl_function *F = NULL;
|
405
|
+
gsl_vector *v = NULL;
|
406
|
+
gsl_integration_workspace *w = NULL;
|
407
|
+
int status, intervals, flag = 0, flag2 = 0, itmp;
|
408
|
+
switch (TYPE(obj)) {
|
409
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
410
|
+
CHECK_FUNCTION(argv[0]);
|
411
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
412
|
+
itmp = 1;
|
413
|
+
break;
|
414
|
+
default:
|
415
|
+
Data_Get_Struct(obj, gsl_function, F);
|
416
|
+
itmp = 0;
|
417
|
+
break;
|
418
|
+
}
|
419
|
+
if (TYPE(argv[itmp]) == T_ARRAY) {
|
420
|
+
v = make_cvector_from_rarray(argv[itmp]);
|
421
|
+
flag2 = 1;
|
422
|
+
} else {
|
423
|
+
Data_Get_Vector(argv[itmp], v);
|
424
|
+
flag2 = 0;
|
425
|
+
}
|
426
|
+
itmp += 1;
|
427
|
+
flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp, &epsabs, &epsrel,
|
428
|
+
&limit, &w);
|
429
|
+
|
430
|
+
status = gsl_integration_qagp(F, v->data, v->size, epsabs, epsrel, limit, w,
|
431
|
+
&result, &abserr);
|
432
|
+
intervals = w->size;
|
433
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
434
|
+
if (flag2 == 1) gsl_vector_free(v);
|
435
|
+
|
436
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
437
|
+
INT2FIX(intervals), INT2FIX(status));
|
438
|
+
}
|
439
|
+
|
440
|
+
/* (-infty --- +infty) */
|
441
|
+
static VALUE rb_gsl_integration_qagi(int argc, VALUE *argv, VALUE obj)
|
442
|
+
{
|
443
|
+
double epsabs, epsrel;
|
444
|
+
double result, abserr;
|
445
|
+
size_t limit;
|
446
|
+
gsl_function *F = NULL;
|
447
|
+
gsl_integration_workspace *w = NULL;
|
448
|
+
int status, intervals, flag = 0, itmp;
|
449
|
+
switch (TYPE(obj)) {
|
450
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
451
|
+
CHECK_FUNCTION(argv[0]);
|
452
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
453
|
+
itmp = 1;
|
454
|
+
break;
|
455
|
+
default:
|
456
|
+
Data_Get_Struct(obj, gsl_function, F);
|
457
|
+
itmp = 0;
|
458
|
+
break;
|
459
|
+
}
|
460
|
+
flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp, &epsabs, &epsrel,
|
461
|
+
&limit, &w);
|
462
|
+
status = gsl_integration_qagi(F, epsabs, epsrel, limit, w,
|
463
|
+
&result, &abserr);
|
464
|
+
intervals = w->size;
|
465
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
466
|
+
|
467
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
468
|
+
INT2FIX(intervals), INT2FIX(status));
|
469
|
+
}
|
470
|
+
|
471
|
+
/* (a --- +infty) */
|
472
|
+
static VALUE rb_gsl_integration_qagiu(int argc, VALUE *argv, VALUE obj)
|
473
|
+
{
|
474
|
+
double a, epsabs, epsrel;
|
475
|
+
double result, abserr;
|
476
|
+
size_t limit;
|
477
|
+
gsl_function *F = NULL;
|
478
|
+
gsl_integration_workspace *w = NULL;
|
479
|
+
int status, intervals, flag = 0, itmp;
|
480
|
+
switch (TYPE(obj)) {
|
481
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
482
|
+
CHECK_FUNCTION(argv[0]);
|
483
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
484
|
+
itmp = 1;
|
485
|
+
break;
|
486
|
+
default:
|
487
|
+
Data_Get_Struct(obj, gsl_function, F);
|
488
|
+
itmp = 0;
|
489
|
+
break;
|
490
|
+
}
|
491
|
+
Need_Float(argv[itmp]);
|
492
|
+
a = NUM2DBL(argv[itmp]);
|
493
|
+
itmp += 1;
|
494
|
+
flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp, &epsabs, &epsrel,
|
495
|
+
&limit, &w);
|
496
|
+
status = gsl_integration_qagiu(F, a, epsabs, epsrel, limit, w,
|
497
|
+
&result, &abserr);
|
498
|
+
intervals = w->size;
|
499
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
500
|
+
|
501
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
502
|
+
INT2FIX(intervals), INT2FIX(status));
|
503
|
+
}
|
504
|
+
|
505
|
+
/* (-infty --- b) */
|
506
|
+
static VALUE rb_gsl_integration_qagil(int argc, VALUE *argv, VALUE obj)
|
507
|
+
{
|
508
|
+
double b, epsabs, epsrel;
|
509
|
+
double result, abserr;
|
510
|
+
size_t limit;
|
511
|
+
gsl_function *F = NULL;
|
512
|
+
gsl_integration_workspace *w = NULL;
|
513
|
+
int status, intervals, flag = 0, itmp;
|
514
|
+
switch (TYPE(obj)) {
|
515
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
516
|
+
CHECK_FUNCTION(argv[0]);
|
517
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
518
|
+
itmp = 1;
|
519
|
+
break;
|
520
|
+
default:
|
521
|
+
Data_Get_Struct(obj, gsl_function, F);
|
522
|
+
itmp = 0;
|
523
|
+
break;
|
524
|
+
}
|
525
|
+
Need_Float(argv[itmp]);
|
526
|
+
b = NUM2DBL(argv[itmp]);
|
527
|
+
flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp+1, &epsabs, &epsrel,
|
528
|
+
&limit, &w);
|
529
|
+
Data_Get_Struct(obj, gsl_function, F);
|
530
|
+
|
531
|
+
status = gsl_integration_qagil(F, b, epsabs, epsrel, limit, w,
|
532
|
+
&result, &abserr);
|
533
|
+
intervals = w->size;
|
534
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
535
|
+
|
536
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
537
|
+
INT2FIX(intervals), INT2FIX(status));
|
538
|
+
}
|
539
|
+
|
540
|
+
static VALUE rb_gsl_integration_qawc(int argc, VALUE *argv, VALUE obj)
|
541
|
+
{
|
542
|
+
double a, b, c, epsabs, epsrel;
|
543
|
+
double result, abserr;
|
544
|
+
size_t limit;
|
545
|
+
gsl_function *F = NULL;
|
546
|
+
gsl_integration_workspace *w = NULL;
|
547
|
+
int status, intervals, itmp, flag = 0;
|
548
|
+
switch (TYPE(obj)) {
|
549
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
550
|
+
CHECK_FUNCTION(argv[0]);
|
551
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
552
|
+
itmp = 1;
|
553
|
+
break;
|
554
|
+
default:
|
555
|
+
Data_Get_Struct(obj, gsl_function, F);
|
556
|
+
itmp = 0;
|
557
|
+
break;
|
558
|
+
}
|
559
|
+
itmp = get_a_b(argc, argv, itmp, &a, &b);
|
560
|
+
if (argc-itmp <= 0) rb_raise(rb_eArgError, "The pole is not given");
|
561
|
+
Need_Float(argv[itmp]);
|
562
|
+
c = NUM2DBL(argv[itmp]);
|
563
|
+
flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp+1, &epsabs, &epsrel,
|
564
|
+
&limit, &w);
|
565
|
+
status = gsl_integration_qawc(F, a, b, c, epsabs, epsrel, limit, w, &result, &abserr);
|
566
|
+
intervals = w->size;
|
567
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
568
|
+
|
569
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr), INT2FIX(intervals),
|
570
|
+
INT2FIX(status));
|
571
|
+
}
|
572
|
+
|
573
|
+
VALUE rb_gsl_integration_qaws_table_alloc(int argc, VALUE *argv, VALUE klass)
|
574
|
+
{
|
575
|
+
gsl_integration_qaws_table *t = NULL;
|
576
|
+
VALUE alpha, beta, mu, nu;
|
577
|
+
|
578
|
+
if (TYPE(argv[0]) == T_ARRAY) {
|
579
|
+
alpha = rb_ary_entry(argv[0], 0);
|
580
|
+
beta = rb_ary_entry(argv[0], 1);
|
581
|
+
mu = rb_ary_entry(argv[0], 2);
|
582
|
+
nu = rb_ary_entry(argv[0], 3);
|
583
|
+
} else {
|
584
|
+
Need_Float(argv[0]); Need_Float(argv[1]);
|
585
|
+
CHECK_FIXNUM(argv[2]); CHECK_FIXNUM(argv[3]);
|
586
|
+
alpha = argv[0];
|
587
|
+
beta = argv[1];
|
588
|
+
mu = argv[2];
|
589
|
+
nu = argv[3];
|
590
|
+
}
|
591
|
+
t = gsl_integration_qaws_table_alloc(NUM2DBL(alpha), NUM2DBL(beta),
|
592
|
+
FIX2INT(mu), FIX2INT(nu));
|
593
|
+
return Data_Wrap_Struct(klass, 0, gsl_integration_qaws_table_free, t);
|
594
|
+
}
|
595
|
+
|
596
|
+
static VALUE rb_gsl_integration_qaws_table_set(int argc, VALUE *argv, VALUE obj)
|
597
|
+
{
|
598
|
+
gsl_integration_qaws_table *t = NULL;
|
599
|
+
double alpha, beta;
|
600
|
+
int mu, nu, type;
|
601
|
+
if (argc != 1 && argc != 4)
|
602
|
+
rb_raise(rb_eArgError, "wrong number of argument (%d for 1 or 3)", argc);
|
603
|
+
type = TYPE(argv[0]);
|
604
|
+
Data_Get_Struct(obj, gsl_integration_qaws_table, t);
|
605
|
+
|
606
|
+
if (type == T_FIXNUM || type == T_BIGNUM || type == T_FLOAT) {
|
607
|
+
alpha = NUM2DBL(argv[0]);
|
608
|
+
beta = NUM2DBL(argv[1]);
|
609
|
+
mu = FIX2INT(argv[2]);
|
610
|
+
nu = FIX2INT(argv[3]);
|
611
|
+
} else if (type == T_ARRAY) {
|
612
|
+
alpha = NUM2DBL(rb_ary_entry(argv[0], 0));
|
613
|
+
beta = NUM2DBL(rb_ary_entry(argv[0], 1));
|
614
|
+
mu = FIX2INT(rb_ary_entry(argv[0], 2));
|
615
|
+
nu = FIX2INT(rb_ary_entry(argv[0], 3));
|
616
|
+
} else {
|
617
|
+
rb_raise(rb_eTypeError, "wrong argument type %s", rb_class2name(CLASS_OF(argv[0])));
|
618
|
+
}
|
619
|
+
|
620
|
+
gsl_integration_qaws_table_set(t, alpha, beta, mu, nu);
|
621
|
+
return obj;
|
622
|
+
}
|
623
|
+
|
624
|
+
static VALUE rb_gsl_integration_qaws_table_to_a(VALUE obj)
|
625
|
+
{
|
626
|
+
gsl_integration_qaws_table *t = NULL;
|
627
|
+
VALUE ary;
|
628
|
+
Data_Get_Struct(obj, gsl_integration_qaws_table, t);
|
629
|
+
ary = rb_ary_new2(4);
|
630
|
+
rb_ary_store(ary, 0, rb_float_new(t->alpha));
|
631
|
+
rb_ary_store(ary, 1, rb_float_new(t->beta));
|
632
|
+
rb_ary_store(ary, 2, INT2FIX(t->mu));
|
633
|
+
rb_ary_store(ary, 3, INT2FIX(t->nu));
|
634
|
+
return ary;
|
635
|
+
}
|
636
|
+
|
637
|
+
static gsl_integration_qaws_table* make_qaws_table(VALUE ary);
|
638
|
+
static VALUE rb_gsl_ary_to_integration_qaws_table(VALUE ary)
|
639
|
+
{
|
640
|
+
gsl_integration_qaws_table *t = NULL;
|
641
|
+
t = make_qaws_table(ary);
|
642
|
+
return Data_Wrap_Struct(cgsl_integration_qaws_table,
|
643
|
+
0, gsl_integration_qaws_table_free, t);
|
644
|
+
}
|
645
|
+
|
646
|
+
static gsl_integration_qaws_table* make_qaws_table(VALUE ary)
|
647
|
+
{
|
648
|
+
double alpha, beta;
|
649
|
+
int mu, nu;
|
650
|
+
alpha = NUM2DBL(rb_ary_entry(ary, 0));
|
651
|
+
beta = NUM2DBL(rb_ary_entry(ary, 1));
|
652
|
+
mu = FIX2INT(rb_ary_entry(ary, 2));
|
653
|
+
nu = FIX2INT(rb_ary_entry(ary, 3));
|
654
|
+
return gsl_integration_qaws_table_alloc(alpha, beta, mu, nu);
|
655
|
+
}
|
656
|
+
|
657
|
+
static VALUE rb_gsl_integration_qaws(int argc, VALUE *argv, VALUE obj)
|
658
|
+
{
|
659
|
+
double a, b, epsabs, epsrel;
|
660
|
+
double result, abserr;
|
661
|
+
size_t limit;
|
662
|
+
gsl_function *F = NULL;
|
663
|
+
gsl_integration_workspace *w = NULL;
|
664
|
+
gsl_integration_qaws_table *t = NULL;
|
665
|
+
int status, intervals, itmp, flag = 0, flagt = 0;
|
666
|
+
switch (TYPE(obj)) {
|
667
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
668
|
+
if (argc < 2) rb_raise(rb_eArgError, "too few arguments");
|
669
|
+
CHECK_FUNCTION(argv[0]);
|
670
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
671
|
+
itmp = 1;
|
672
|
+
break;
|
673
|
+
default:
|
674
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
|
675
|
+
Data_Get_Struct(obj, gsl_function, F);
|
676
|
+
itmp = 0;
|
677
|
+
break;
|
678
|
+
}
|
679
|
+
itmp = get_a_b(argc, argv, itmp, &a, &b);
|
680
|
+
|
681
|
+
if (TYPE(argv[itmp]) == T_ARRAY) {
|
682
|
+
flagt = 1;
|
683
|
+
t = make_qaws_table(argv[itmp]);
|
684
|
+
} else {
|
685
|
+
flagt = 0;
|
686
|
+
if (!rb_obj_is_kind_of(argv[itmp], cgsl_integration_qaws_table))
|
687
|
+
rb_raise(rb_eTypeError, "Integration::QAWS_Table expected");
|
688
|
+
|
689
|
+
Data_Get_Struct(argv[itmp], gsl_integration_qaws_table, t);
|
690
|
+
}
|
691
|
+
flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp+1, &epsabs, &epsrel,
|
692
|
+
&limit, &w);
|
693
|
+
status = gsl_integration_qaws(F, a, b, t, epsabs, epsrel, limit, w, &result, &abserr);
|
694
|
+
intervals = w->size;
|
695
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
696
|
+
if (flagt == 1) gsl_integration_qaws_table_free(t);
|
697
|
+
|
698
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr), INT2FIX(intervals),
|
699
|
+
INT2FIX(status));
|
700
|
+
}
|
701
|
+
|
702
|
+
static gsl_integration_qawo_table* make_qawo_table(VALUE ary);
|
703
|
+
|
704
|
+
static VALUE rb_gsl_integration_qawo_table_alloc(int argc, VALUE *argv,
|
705
|
+
VALUE klass)
|
706
|
+
{
|
707
|
+
gsl_integration_qawo_table *t = NULL;
|
708
|
+
double omega, L;
|
709
|
+
enum gsl_integration_qawo_enum sine;
|
710
|
+
size_t n;
|
711
|
+
if (argc != 1 && argc != 4)
|
712
|
+
rb_raise(rb_eArgError, "wrong nubmer of arguments (%d for 1 or 4)", argc);
|
713
|
+
|
714
|
+
if (TYPE(argv[0]) == T_ARRAY) {
|
715
|
+
omega = NUM2DBL(rb_ary_entry(argv[0], 0));
|
716
|
+
L = NUM2DBL(rb_ary_entry(argv[0], 1));
|
717
|
+
sine = FIX2INT(rb_ary_entry(argv[0], 2));
|
718
|
+
n = FIX2INT(rb_ary_entry(argv[0], 3));
|
719
|
+
} else {
|
720
|
+
omega = NUM2DBL(argv[0]);
|
721
|
+
L = NUM2DBL(argv[1]);
|
722
|
+
sine = FIX2INT(argv[2]);
|
723
|
+
n = FIX2INT(argv[3]);
|
724
|
+
}
|
725
|
+
|
726
|
+
t = gsl_integration_qawo_table_alloc(omega, L, sine, n);
|
727
|
+
|
728
|
+
return Data_Wrap_Struct(klass, 0, gsl_integration_qawo_table_free, t);
|
729
|
+
}
|
730
|
+
|
731
|
+
static VALUE rb_gsl_integration_qawo_table_to_a(VALUE obj)
|
732
|
+
{
|
733
|
+
gsl_integration_qawo_table *t = NULL;
|
734
|
+
VALUE ary;
|
735
|
+
Data_Get_Struct(obj, gsl_integration_qawo_table, t);
|
736
|
+
ary = rb_ary_new2(4);
|
737
|
+
rb_ary_store(ary, 0, rb_float_new(t->omega));
|
738
|
+
rb_ary_store(ary, 1, rb_float_new(t->L));
|
739
|
+
rb_ary_store(ary, 2, INT2FIX(t->sine));
|
740
|
+
rb_ary_store(ary, 3, INT2FIX(t->n));
|
741
|
+
return ary;
|
742
|
+
}
|
743
|
+
|
744
|
+
static VALUE rb_gsl_ary_to_integration_qawo_table(VALUE ary)
|
745
|
+
{
|
746
|
+
gsl_integration_qawo_table *t = NULL;
|
747
|
+
t = make_qawo_table(ary);
|
748
|
+
return Data_Wrap_Struct(cgsl_integration_qawo_table,
|
749
|
+
0, gsl_integration_qawo_table_free, t);
|
750
|
+
}
|
751
|
+
|
752
|
+
static gsl_integration_qawo_table* make_qawo_table(VALUE ary)
|
753
|
+
{
|
754
|
+
double omega, L;
|
755
|
+
enum gsl_integration_qawo_enum sine;
|
756
|
+
size_t n;
|
757
|
+
omega = NUM2DBL(rb_ary_entry(ary, 0));
|
758
|
+
L = NUM2DBL(rb_ary_entry(ary, 1));
|
759
|
+
sine = FIX2INT(rb_ary_entry(ary, 2));
|
760
|
+
n = FIX2INT(rb_ary_entry(ary, 3));
|
761
|
+
return gsl_integration_qawo_table_alloc(omega, L, sine, n);
|
762
|
+
}
|
763
|
+
|
764
|
+
static VALUE rb_gsl_integration_qawo_table_set(int argc, VALUE *argv, VALUE obj)
|
765
|
+
{
|
766
|
+
gsl_integration_qawo_table *t = NULL;
|
767
|
+
double omega, L;
|
768
|
+
enum gsl_integration_qawo_enum sine;
|
769
|
+
int type;
|
770
|
+
if (argc != 1 && argc != 3)
|
771
|
+
rb_raise(rb_eArgError, "wrong number of argument (%d for 1 or 3)", argc);
|
772
|
+
type = TYPE(argv[0]);
|
773
|
+
Data_Get_Struct(obj, gsl_integration_qawo_table, t);
|
774
|
+
if (type == T_FIXNUM || type == T_BIGNUM || type == T_FLOAT) {
|
775
|
+
omega = NUM2DBL(argv[0]);
|
776
|
+
L = NUM2DBL(argv[1]);
|
777
|
+
sine = FIX2INT(argv[2]);
|
778
|
+
} else if (type == T_ARRAY) {
|
779
|
+
omega = NUM2DBL(rb_ary_entry(argv[0], 0));
|
780
|
+
L = NUM2DBL(rb_ary_entry(argv[0], 1));
|
781
|
+
sine = FIX2INT(rb_ary_entry(argv[0], 2));
|
782
|
+
} else {
|
783
|
+
rb_raise(rb_eTypeError, "wrong argument type %s", rb_class2name(CLASS_OF(argv[0])));
|
784
|
+
}
|
785
|
+
gsl_integration_qawo_table_set(t, omega, L, sine);
|
786
|
+
return obj;
|
787
|
+
}
|
788
|
+
|
789
|
+
static VALUE rb_gsl_integration_qawo_table_set_length(VALUE obj, VALUE L)
|
790
|
+
{
|
791
|
+
gsl_integration_qawo_table *t = NULL;
|
792
|
+
Need_Float(L);
|
793
|
+
Data_Get_Struct(obj, gsl_integration_qawo_table, t);
|
794
|
+
gsl_integration_qawo_table_set_length(t, NUM2DBL(L));
|
795
|
+
return obj;
|
796
|
+
}
|
797
|
+
|
798
|
+
static int get_qawo_table(VALUE tt, gsl_integration_qawo_table **t);
|
799
|
+
|
800
|
+
static VALUE rb_gsl_integration_qawo(int argc, VALUE *argv, VALUE obj)
|
801
|
+
{
|
802
|
+
double a, epsabs, epsrel;
|
803
|
+
double result, abserr;
|
804
|
+
size_t limit;
|
805
|
+
gsl_function *F = NULL;
|
806
|
+
gsl_integration_workspace *w = NULL;
|
807
|
+
gsl_integration_qawo_table *t = NULL;
|
808
|
+
int status, intervals, itmp, flag = 0, flagt = 0;
|
809
|
+
switch (TYPE(obj)) {
|
810
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
811
|
+
if (argc < 2) rb_raise(rb_eArgError, "too few arguments");
|
812
|
+
CHECK_FUNCTION(argv[0]);
|
813
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
814
|
+
itmp = 1;
|
815
|
+
break;
|
816
|
+
default:
|
817
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
|
818
|
+
Data_Get_Struct(obj, gsl_function, F);
|
819
|
+
itmp = 0;
|
820
|
+
break;
|
821
|
+
}
|
822
|
+
Need_Float(argv[itmp]);
|
823
|
+
a = NUM2DBL(argv[itmp]);
|
824
|
+
flagt = get_qawo_table(argv[argc-1], &t);
|
825
|
+
flag = get_epsabs_epsrel_limit_workspace(argc-1, argv, itmp+1, &epsabs, &epsrel,
|
826
|
+
&limit, &w);
|
827
|
+
status = gsl_integration_qawo(F, a, epsabs, epsrel, limit, w, t, &result, &abserr);
|
828
|
+
intervals = w->size;
|
829
|
+
if (flag == 1) gsl_integration_workspace_free(w);
|
830
|
+
if (flagt == 1) gsl_integration_qawo_table_free(t);
|
831
|
+
|
832
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr), INT2FIX(intervals),
|
833
|
+
INT2FIX(status));
|
834
|
+
}
|
835
|
+
|
836
|
+
static int get_qawo_table(VALUE tt,
|
837
|
+
gsl_integration_qawo_table **t)
|
838
|
+
{
|
839
|
+
int flagt;
|
840
|
+
|
841
|
+
if (TYPE(tt) == T_ARRAY) {
|
842
|
+
flagt = 1;
|
843
|
+
*t = make_qawo_table(tt);
|
844
|
+
} else {
|
845
|
+
flagt = 0;
|
846
|
+
if (!rb_obj_is_kind_of(tt, cgsl_integration_qawo_table))
|
847
|
+
rb_raise(rb_eTypeError, "Integration::QAWO_Table expected");
|
848
|
+
Data_Get_Struct(tt, gsl_integration_qawo_table, *t);
|
849
|
+
}
|
850
|
+
return flagt;
|
851
|
+
}
|
852
|
+
|
853
|
+
static VALUE rb_gsl_integration_qawf(int argc, VALUE *argv, VALUE obj)
|
854
|
+
{
|
855
|
+
double a, epsabs = EPSREL_DEFAULT;
|
856
|
+
double result, abserr;
|
857
|
+
size_t limit = LIMIT_DEFAULT;
|
858
|
+
gsl_function *F = NULL;
|
859
|
+
gsl_integration_workspace *w = NULL, *cw = NULL;
|
860
|
+
gsl_integration_qawo_table *t = NULL;
|
861
|
+
int status, intervals, flag = 0, flagt = 0, itmp;
|
862
|
+
VALUE *vtmp;
|
863
|
+
switch (TYPE(obj)) {
|
864
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
865
|
+
if (argc < 2) rb_raise(rb_eArgError, "too few arguments");
|
866
|
+
CHECK_FUNCTION(argv[0]);
|
867
|
+
Data_Get_Struct(argv[0], gsl_function, F);
|
868
|
+
itmp = 1;
|
869
|
+
break;
|
870
|
+
default:
|
871
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
|
872
|
+
Data_Get_Struct(obj, gsl_function, F);
|
873
|
+
itmp = 0;
|
874
|
+
break;
|
875
|
+
}
|
876
|
+
Need_Float(argv[itmp]);
|
877
|
+
a = NUM2DBL(argv[itmp]);
|
878
|
+
itmp += 1;
|
879
|
+
if (TYPE(argv[itmp]) == T_FLOAT) {
|
880
|
+
epsabs = NUM2DBL(argv[itmp]);
|
881
|
+
itmp += 1;
|
882
|
+
}
|
883
|
+
vtmp = argv + itmp;
|
884
|
+
flagt = get_qawo_table(argv[argc-1], &t);
|
885
|
+
|
886
|
+
switch (argc - 1 - itmp) {
|
887
|
+
case 0:
|
888
|
+
w = gsl_integration_workspace_alloc(limit);
|
889
|
+
cw = gsl_integration_workspace_alloc(limit);
|
890
|
+
flag = 1;
|
891
|
+
break;
|
892
|
+
case 1:
|
893
|
+
CHECK_FIXNUM(vtmp[0]);
|
894
|
+
limit = FIX2INT(vtmp[0]);
|
895
|
+
w = gsl_integration_workspace_alloc(limit);
|
896
|
+
cw = gsl_integration_workspace_alloc(limit);
|
897
|
+
flag = 1;
|
898
|
+
break;
|
899
|
+
case 2:
|
900
|
+
CHECK_WORKSPACE(vtmp[0]); CHECK_WORKSPACE(vtmp[1]);
|
901
|
+
Data_Get_Struct(vtmp[0], gsl_integration_workspace, w);
|
902
|
+
Data_Get_Struct(vtmp[1], gsl_integration_workspace, cw);
|
903
|
+
flag = 0;
|
904
|
+
break;
|
905
|
+
case 3:
|
906
|
+
CHECK_FIXNUM(vtmp[0]);
|
907
|
+
CHECK_WORKSPACE(vtmp[1]); CHECK_WORKSPACE(vtmp[2]);
|
908
|
+
limit = FIX2INT(vtmp[0]);
|
909
|
+
Data_Get_Struct(vtmp[1], gsl_integration_workspace, w);
|
910
|
+
Data_Get_Struct(vtmp[2], gsl_integration_workspace, cw);
|
911
|
+
flag = 0;
|
912
|
+
break;
|
913
|
+
default:
|
914
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
915
|
+
break;
|
916
|
+
}
|
917
|
+
|
918
|
+
status = gsl_integration_qawf(F, a, epsabs, limit, w, cw, t, &result, &abserr);
|
919
|
+
intervals = w->size;
|
920
|
+
if (flag == 1) {
|
921
|
+
gsl_integration_workspace_free(w);
|
922
|
+
gsl_integration_workspace_free(cw);
|
923
|
+
}
|
924
|
+
if (flagt == 1) gsl_integration_qawo_table_free(t);
|
925
|
+
|
926
|
+
return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr),
|
927
|
+
INT2FIX(intervals), INT2FIX(status));
|
928
|
+
}
|
929
|
+
|
930
|
+
|
931
|
+
static void rb_gsl_integration_define_symbols(VALUE module)
|
932
|
+
{
|
933
|
+
rb_define_const(module, "GAUSS15", INT2FIX(GSL_INTEG_GAUSS15));
|
934
|
+
rb_define_const(module, "GAUSS21", INT2FIX(GSL_INTEG_GAUSS21));
|
935
|
+
rb_define_const(module, "GAUSS31", INT2FIX(GSL_INTEG_GAUSS31));
|
936
|
+
rb_define_const(module, "GAUSS41", INT2FIX(GSL_INTEG_GAUSS41));
|
937
|
+
rb_define_const(module, "GAUSS51", INT2FIX(GSL_INTEG_GAUSS51));
|
938
|
+
rb_define_const(module, "GAUSS61", INT2FIX(GSL_INTEG_GAUSS61));
|
939
|
+
rb_define_const(module, "COSINE", INT2FIX(GSL_INTEG_COSINE));
|
940
|
+
rb_define_const(module, "SINE", INT2FIX(GSL_INTEG_SINE));
|
941
|
+
}
|
942
|
+
|
943
|
+
static VALUE rb_gsl_integration_workspace_alloc(int argc, VALUE *argv,
|
944
|
+
VALUE klass)
|
945
|
+
{
|
946
|
+
size_t limit;
|
947
|
+
if (argc == 1) limit = FIX2INT(argv[0]);
|
948
|
+
else limit = LIMIT_DEFAULT;
|
949
|
+
return Data_Wrap_Struct(klass, 0,
|
950
|
+
gsl_integration_workspace_free,
|
951
|
+
gsl_integration_workspace_alloc(limit));
|
952
|
+
}
|
953
|
+
|
954
|
+
static VALUE rb_gsl_integration_workspace_limit(VALUE obj)
|
955
|
+
{
|
956
|
+
gsl_integration_workspace *w = NULL;
|
957
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
958
|
+
return INT2FIX(w->limit);
|
959
|
+
}
|
960
|
+
|
961
|
+
static VALUE rb_gsl_integration_workspace_size(VALUE obj)
|
962
|
+
{
|
963
|
+
gsl_integration_workspace *w = NULL;
|
964
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
965
|
+
return INT2FIX(w->size);
|
966
|
+
}
|
967
|
+
|
968
|
+
static VALUE rb_gsl_integration_workspace_nrmax(VALUE obj)
|
969
|
+
{
|
970
|
+
gsl_integration_workspace *w = NULL;
|
971
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
972
|
+
return INT2FIX(w->nrmax);
|
973
|
+
}
|
974
|
+
|
975
|
+
static VALUE rb_gsl_integration_workspace_i(VALUE obj)
|
976
|
+
{
|
977
|
+
gsl_integration_workspace *w = NULL;
|
978
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
979
|
+
return INT2FIX(w->i);
|
980
|
+
}
|
981
|
+
|
982
|
+
static VALUE rb_gsl_integration_workspace_maximum_level(VALUE obj)
|
983
|
+
{
|
984
|
+
gsl_integration_workspace *w = NULL;
|
985
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
986
|
+
return INT2FIX(w->maximum_level);
|
987
|
+
}
|
988
|
+
|
989
|
+
static VALUE rb_gsl_integration_workspace_to_a(VALUE obj)
|
990
|
+
{
|
991
|
+
gsl_integration_workspace *w = NULL;
|
992
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
993
|
+
return rb_ary_new3(5, INT2FIX(w->limit), INT2FIX(w->size), INT2FIX(w->nrmax),
|
994
|
+
INT2FIX(w->i), INT2FIX(w->maximum_level));
|
995
|
+
}
|
996
|
+
|
997
|
+
static VALUE rb_gsl_integration_workspace_alist(VALUE obj)
|
998
|
+
{
|
999
|
+
gsl_integration_workspace *w = NULL;
|
1000
|
+
gsl_vector_view *v = NULL;
|
1001
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
1002
|
+
v = rb_gsl_make_vector_view(w->alist, w->limit, 1);
|
1003
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, free, v);
|
1004
|
+
}
|
1005
|
+
|
1006
|
+
static VALUE rb_gsl_integration_workspace_blist(VALUE obj)
|
1007
|
+
{
|
1008
|
+
gsl_integration_workspace *w = NULL;
|
1009
|
+
gsl_vector_view *v = NULL;
|
1010
|
+
|
1011
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
1012
|
+
v = rb_gsl_make_vector_view(w->blist, w->limit, 1);
|
1013
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, free, v);
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
static VALUE rb_gsl_integration_workspace_rlist(VALUE obj)
|
1017
|
+
{
|
1018
|
+
gsl_integration_workspace *w = NULL;
|
1019
|
+
gsl_vector_view *v = NULL;
|
1020
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
1021
|
+
v = rb_gsl_make_vector_view(w->rlist, w->limit, 1);
|
1022
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, free, v);
|
1023
|
+
}
|
1024
|
+
|
1025
|
+
static VALUE rb_gsl_integration_workspace_elist(VALUE obj)
|
1026
|
+
{
|
1027
|
+
gsl_integration_workspace *w = NULL;
|
1028
|
+
gsl_vector_view *v = NULL;
|
1029
|
+
Data_Get_Struct(obj, gsl_integration_workspace, w);
|
1030
|
+
v = rb_gsl_make_vector_view(w->elist, w->limit, 1);
|
1031
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, free, v);
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
#ifdef GSL_1_14_LATER
|
1035
|
+
static VALUE rb_gsl_integration_glfixed_table_alloc(VALUE klass, VALUE n)
|
1036
|
+
{
|
1037
|
+
gsl_integration_glfixed_table *t;
|
1038
|
+
t = gsl_integration_glfixed_table_alloc(FIX2INT(n));
|
1039
|
+
return Data_Wrap_Struct(cgsl_integration_glfixed_table, 0, gsl_integration_glfixed_table_free, t);
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
static VALUE rb_gsl_integration_glfixed(VALUE obj, VALUE aa, VALUE bb, VALUE tt)
|
1043
|
+
{
|
1044
|
+
gsl_function *f;
|
1045
|
+
double a, b;
|
1046
|
+
gsl_integration_glfixed_table *t;
|
1047
|
+
double res;
|
1048
|
+
if (!rb_obj_is_kind_of(tt, cgsl_integration_glfixed_table)) {
|
1049
|
+
rb_raise(rb_eTypeError, "Wrong arugment type (%s for GSL::Integration::Glfixed_table)",
|
1050
|
+
rb_class2name(CLASS_OF(tt)));
|
1051
|
+
}
|
1052
|
+
Data_Get_Struct(tt, gsl_integration_glfixed_table, t);
|
1053
|
+
a = NUM2DBL(aa);
|
1054
|
+
b = NUM2DBL(bb);
|
1055
|
+
Data_Get_Struct(obj, gsl_function, f);
|
1056
|
+
res = gsl_integration_glfixed(f, a, b, t);
|
1057
|
+
return rb_float_new(res);
|
1058
|
+
}
|
1059
|
+
#endif
|
1060
|
+
|
1061
|
+
void Init_gsl_integration(VALUE module)
|
1062
|
+
{
|
1063
|
+
VALUE mgsl_integ;
|
1064
|
+
|
1065
|
+
mgsl_integ = rb_define_module_under(module, "Integration");
|
1066
|
+
rb_gsl_integration_define_symbols(mgsl_integ);
|
1067
|
+
|
1068
|
+
rb_define_method(cgsl_function, "integration_qng", rb_gsl_integration_qng, -1);
|
1069
|
+
rb_define_method(cgsl_function, "integration_qag", rb_gsl_integration_qag, -1);
|
1070
|
+
rb_define_method(cgsl_function, "integration_qags", rb_gsl_integration_qags, -1);
|
1071
|
+
rb_define_method(cgsl_function, "integration_qagp", rb_gsl_integration_qagp, -1);
|
1072
|
+
rb_define_method(cgsl_function, "integration_qagi", rb_gsl_integration_qagi, -1);
|
1073
|
+
rb_define_method(cgsl_function, "integration_qagiu", rb_gsl_integration_qagiu, -1);
|
1074
|
+
rb_define_method(cgsl_function, "integration_qagil", rb_gsl_integration_qagil, -1);
|
1075
|
+
rb_define_method(cgsl_function, "integration_qawc", rb_gsl_integration_qawc, -1);
|
1076
|
+
rb_define_alias(cgsl_function, "qng", "integration_qng");
|
1077
|
+
rb_define_alias(cgsl_function, "qag", "integration_qag");
|
1078
|
+
rb_define_alias(cgsl_function, "qags", "integration_qags");
|
1079
|
+
rb_define_alias(cgsl_function, "qagp", "integration_qagp");
|
1080
|
+
rb_define_alias(cgsl_function, "qagi", "integration_qagi");
|
1081
|
+
rb_define_alias(cgsl_function, "qagiu", "integration_qagiu");
|
1082
|
+
rb_define_alias(cgsl_function, "qagil", "integration_qagil");
|
1083
|
+
rb_define_alias(cgsl_function, "qawc", "integration_qawc");
|
1084
|
+
|
1085
|
+
cgsl_integration_qaws_table = rb_define_class_under(mgsl_integ, "QAWS_Table",
|
1086
|
+
cGSL_Object);
|
1087
|
+
rb_define_singleton_method(cgsl_integration_qaws_table, "alloc",
|
1088
|
+
rb_gsl_integration_qaws_table_alloc, -1);
|
1089
|
+
/* rb_define_singleton_method(cgsl_integration_qaws_table, "new",
|
1090
|
+
rb_gsl_integration_qaws_table_alloc, -1);*/
|
1091
|
+
rb_define_method(cgsl_integration_qaws_table, "to_a",
|
1092
|
+
rb_gsl_integration_qaws_table_to_a, 0);
|
1093
|
+
rb_define_method(cgsl_integration_qaws_table, "set",
|
1094
|
+
rb_gsl_integration_qaws_table_set, -1);
|
1095
|
+
rb_define_method(rb_cArray, "to_gsl_integration_qaws_table",
|
1096
|
+
rb_gsl_ary_to_integration_qaws_table, 0);
|
1097
|
+
rb_define_alias(rb_cArray, "to_qaws_table", "to_gsl_integration_qaws_table");
|
1098
|
+
rb_define_method(cgsl_function, "integration_qaws", rb_gsl_integration_qaws, -1);
|
1099
|
+
rb_define_alias(cgsl_function, "qaws", "integration_qaws");
|
1100
|
+
|
1101
|
+
cgsl_integration_qawo_table = rb_define_class_under(mgsl_integ, "QAWO_Table",
|
1102
|
+
cGSL_Object);
|
1103
|
+
rb_define_singleton_method(cgsl_integration_qawo_table, "alloc",
|
1104
|
+
rb_gsl_integration_qawo_table_alloc, -1);
|
1105
|
+
/* rb_define_singleton_method(cgsl_integration_qawo_table, "new",
|
1106
|
+
rb_gsl_integration_qawo_table_alloc, -1);*/
|
1107
|
+
rb_define_method(cgsl_integration_qawo_table, "to_a",
|
1108
|
+
rb_gsl_integration_qawo_table_to_a, 0);
|
1109
|
+
rb_define_method(rb_cArray, "to_gsl_integration_qawo_table",
|
1110
|
+
rb_gsl_ary_to_integration_qawo_table, 0);
|
1111
|
+
rb_define_method(cgsl_integration_qawo_table, "set",
|
1112
|
+
rb_gsl_integration_qawo_table_set, -1);
|
1113
|
+
rb_define_method(cgsl_integration_qawo_table, "set_length",
|
1114
|
+
rb_gsl_integration_qawo_table_set_length, 1);
|
1115
|
+
rb_define_method(cgsl_function, "integration_qawo", rb_gsl_integration_qawo, -1);
|
1116
|
+
rb_define_method(cgsl_function, "integration_qawf", rb_gsl_integration_qawf, -1);
|
1117
|
+
rb_define_alias(cgsl_function, "qawo", "integration_qawo");
|
1118
|
+
rb_define_alias(cgsl_function, "qawf", "integration_qawf");
|
1119
|
+
|
1120
|
+
cgsl_integration_workspace = rb_define_class_under(mgsl_integ,
|
1121
|
+
"Workspace", cGSL_Object);
|
1122
|
+
|
1123
|
+
/* rb_define_singleton_method(cgsl_integration_workspace, "new",
|
1124
|
+
rb_gsl_integration_workspace_alloc, -1);*/
|
1125
|
+
rb_define_singleton_method(cgsl_integration_workspace, "alloc",
|
1126
|
+
rb_gsl_integration_workspace_alloc, -1);
|
1127
|
+
|
1128
|
+
rb_define_method(cgsl_integration_workspace, "limit",
|
1129
|
+
rb_gsl_integration_workspace_limit, 0);
|
1130
|
+
rb_define_method(cgsl_integration_workspace, "size",
|
1131
|
+
rb_gsl_integration_workspace_size, 0);
|
1132
|
+
rb_define_method(cgsl_integration_workspace, "nrmax",
|
1133
|
+
rb_gsl_integration_workspace_nrmax, 0);
|
1134
|
+
rb_define_method(cgsl_integration_workspace, "i",
|
1135
|
+
rb_gsl_integration_workspace_i, 0);
|
1136
|
+
rb_define_method(cgsl_integration_workspace, "maximum_level",
|
1137
|
+
rb_gsl_integration_workspace_maximum_level, 0);
|
1138
|
+
rb_define_method(cgsl_integration_workspace, "to_a",
|
1139
|
+
rb_gsl_integration_workspace_to_a, 0);
|
1140
|
+
rb_define_method(cgsl_integration_workspace, "alist",
|
1141
|
+
rb_gsl_integration_workspace_alist, 0);
|
1142
|
+
rb_define_method(cgsl_integration_workspace, "blist",
|
1143
|
+
rb_gsl_integration_workspace_blist, 0);
|
1144
|
+
rb_define_method(cgsl_integration_workspace, "rlist",
|
1145
|
+
rb_gsl_integration_workspace_rlist, 0);
|
1146
|
+
rb_define_method(cgsl_integration_workspace, "elist",
|
1147
|
+
rb_gsl_integration_workspace_elist, 0);
|
1148
|
+
|
1149
|
+
/*****/
|
1150
|
+
rb_define_module_function(mgsl_integ, "qng", rb_gsl_integration_qng, -1);
|
1151
|
+
rb_define_module_function(mgsl_integ, "qag", rb_gsl_integration_qag, -1);
|
1152
|
+
rb_define_module_function(mgsl_integ, "qags", rb_gsl_integration_qags, -1);
|
1153
|
+
rb_define_module_function(mgsl_integ, "qagp", rb_gsl_integration_qagp, -1);
|
1154
|
+
rb_define_module_function(mgsl_integ, "qagi", rb_gsl_integration_qagi, -1);
|
1155
|
+
rb_define_module_function(mgsl_integ, "qagiu", rb_gsl_integration_qagiu, -1);
|
1156
|
+
rb_define_module_function(mgsl_integ, "qagil", rb_gsl_integration_qagil, -1);
|
1157
|
+
rb_define_module_function(mgsl_integ, "qawc", rb_gsl_integration_qawc, -1);
|
1158
|
+
rb_define_module_function(mgsl_integ, "qaws", rb_gsl_integration_qaws, -1);
|
1159
|
+
rb_define_module_function(mgsl_integ, "qawo", rb_gsl_integration_qawo, -1);
|
1160
|
+
rb_define_module_function(mgsl_integ, "qawf", rb_gsl_integration_qawf, -1);
|
1161
|
+
|
1162
|
+
#ifdef GSL_1_14_LATER
|
1163
|
+
cgsl_integration_glfixed_table = rb_define_class_under(mgsl_integ, "Glfixed_table", cGSL_Object);
|
1164
|
+
rb_define_singleton_method(cgsl_integration_glfixed_table, "alloc",
|
1165
|
+
rb_gsl_integration_glfixed_table_alloc, 1);
|
1166
|
+
rb_define_method(cgsl_function, "glfixed", rb_gsl_integration_glfixed, 3);
|
1167
|
+
#endif
|
1168
|
+
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
#undef EPSABS_DEFAULT
|
1172
|
+
#undef EPSREL_DEFAULT
|
1173
|
+
#undef LIMIT_DEFAULT
|
1174
|
+
#undef KEY_DEFAULT
|
1175
|
+
|
1176
|
+
#ifdef CHECK_WORKSPACE
|
1177
|
+
#undef CHECK_WORKSPACE
|
1178
|
+
#endif
|
1179
|
+
|