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
data/ext/linalg.c
ADDED
@@ -0,0 +1,4042 @@
|
|
1
|
+
/*
|
2
|
+
linalg.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
|
+
#include <gsl/gsl_math.h>
|
14
|
+
#include "rb_gsl_array.h"
|
15
|
+
#include "rb_gsl_common.h"
|
16
|
+
#include "rb_gsl_linalg.h"
|
17
|
+
|
18
|
+
static VALUE cgsl_matrix_LU;
|
19
|
+
static VALUE cgsl_matrix_QR;
|
20
|
+
static VALUE cgsl_matrix_QRPT;
|
21
|
+
static VALUE cgsl_vector_tau;
|
22
|
+
static VALUE cgsl_matrix_Q;
|
23
|
+
static VALUE cgsl_matrix_R;
|
24
|
+
|
25
|
+
static VALUE cgsl_matrix_LQ;
|
26
|
+
static VALUE cgsl_matrix_PTLQ;
|
27
|
+
static VALUE cgsl_matrix_L;
|
28
|
+
|
29
|
+
static VALUE cgsl_matrix_SV;
|
30
|
+
static VALUE cgsl_matrix_U;
|
31
|
+
static VALUE cgsl_matrix_V;
|
32
|
+
static VALUE cgsl_vector_S;
|
33
|
+
static VALUE cgsl_matrix_C;
|
34
|
+
|
35
|
+
enum {
|
36
|
+
LINALG_DECOMP,
|
37
|
+
LINALG_DECOMP_BANG,
|
38
|
+
};
|
39
|
+
|
40
|
+
#ifdef HAVE_NARRAY_H
|
41
|
+
static VALUE rb_gsl_linalg_LU_decomp_narray(int argc, VALUE *argv, VALUE obj,
|
42
|
+
int flag);
|
43
|
+
#endif
|
44
|
+
|
45
|
+
static VALUE rb_gsl_linalg_LU_decomposition(int argc, VALUE *argv, VALUE obj, int flag)
|
46
|
+
{
|
47
|
+
gsl_matrix *mtmp = NULL, *m = NULL;
|
48
|
+
gsl_permutation *p = NULL;
|
49
|
+
int signum, itmp;
|
50
|
+
size_t size;
|
51
|
+
VALUE objp, objm, omatrix;
|
52
|
+
switch (TYPE(obj)) {
|
53
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
54
|
+
#ifdef HAVE_NARRAY_H
|
55
|
+
if (NA_IsNArray(argv[0]))
|
56
|
+
return rb_gsl_linalg_LU_decomp_narray(argc, argv, obj, flag);
|
57
|
+
#endif
|
58
|
+
if (MATRIX_COMPLEX_P(argv[0]))
|
59
|
+
return rb_gsl_linalg_complex_LU_decomp2(argc, argv, obj);
|
60
|
+
omatrix = argv[0];
|
61
|
+
itmp = 1;
|
62
|
+
break;
|
63
|
+
default:
|
64
|
+
if (MATRIX_COMPLEX_P(obj))
|
65
|
+
return rb_gsl_linalg_complex_LU_decomp2(argc, argv, obj);
|
66
|
+
omatrix = obj;
|
67
|
+
itmp = 0;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
CHECK_MATRIX(omatrix);
|
71
|
+
Data_Get_Struct(omatrix, gsl_matrix, mtmp);
|
72
|
+
if (flag == LINALG_DECOMP_BANG) {
|
73
|
+
m = mtmp;
|
74
|
+
RBASIC(omatrix)->klass = cgsl_matrix_LU;
|
75
|
+
objm = omatrix;
|
76
|
+
} else {
|
77
|
+
m = make_matrix_clone(mtmp);
|
78
|
+
objm = Data_Wrap_Struct(cgsl_matrix_LU, 0, gsl_matrix_free, m);
|
79
|
+
}
|
80
|
+
size = m->size1;
|
81
|
+
switch (argc-itmp) {
|
82
|
+
case 0:
|
83
|
+
p = gsl_permutation_alloc(size);
|
84
|
+
gsl_linalg_LU_decomp(m, p, &signum);
|
85
|
+
objp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
|
86
|
+
if (flag == LINALG_DECOMP_BANG) return rb_ary_new3(2, objp, INT2FIX(signum));
|
87
|
+
else return rb_ary_new3(3, objm, objp, INT2FIX(signum));
|
88
|
+
break;
|
89
|
+
case 1:
|
90
|
+
CHECK_PERMUTATION(argv[itmp]);
|
91
|
+
Data_Get_Struct(argv[itmp], gsl_permutation, p);
|
92
|
+
gsl_linalg_LU_decomp(m, p, &signum);
|
93
|
+
if (flag == LINALG_DECOMP_BANG) return INT2FIX(signum);
|
94
|
+
else return rb_ary_new3(2, objm, INT2FIX(signum));
|
95
|
+
break;
|
96
|
+
default:
|
97
|
+
rb_raise(rb_eArgError, "Usage: LU_decomp() or LU_decomp(permutation)");
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
return Qnil; /* never reach here */
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE rb_gsl_linalg_LU_decomp(int argc, VALUE *argv, VALUE obj)
|
104
|
+
{
|
105
|
+
return rb_gsl_linalg_LU_decomposition(argc, argv, obj, LINALG_DECOMP);
|
106
|
+
}
|
107
|
+
|
108
|
+
static VALUE rb_gsl_linalg_LU_decomp_bang(int argc, VALUE *argv, VALUE obj)
|
109
|
+
{
|
110
|
+
return rb_gsl_linalg_LU_decomposition(argc, argv, obj, LINALG_DECOMP_BANG);
|
111
|
+
}
|
112
|
+
|
113
|
+
#ifdef HAVE_NARRAY_H
|
114
|
+
static VALUE rb_gsl_linalg_LU_decomp_narray(int argc, VALUE *argv, VALUE obj,
|
115
|
+
int flag)
|
116
|
+
{
|
117
|
+
struct NARRAY *na, *na2;
|
118
|
+
VALUE m;
|
119
|
+
gsl_matrix_view mv;
|
120
|
+
gsl_permutation *p;
|
121
|
+
int signum;
|
122
|
+
|
123
|
+
if (argc != 1)
|
124
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
|
125
|
+
GetNArray(argv[0], na);
|
126
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
127
|
+
if (na->shape[0] != na->shape[1])
|
128
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
129
|
+
if (flag == LINALG_DECOMP) {
|
130
|
+
m = na_make_object(NA_DFLOAT, 2, na->shape, CLASS_OF(argv[0]));
|
131
|
+
GetNArray(m, na2);
|
132
|
+
memcpy((double*)na2->ptr, (double*)na->ptr, sizeof(double)*na2->total);
|
133
|
+
mv = gsl_matrix_view_array((double*)na2->ptr, na->shape[1], na->shape[0]);
|
134
|
+
} else {
|
135
|
+
mv = gsl_matrix_view_array((double*)na->ptr, na->shape[1], na->shape[0]);
|
136
|
+
}
|
137
|
+
p = gsl_permutation_alloc(mv.matrix.size1);
|
138
|
+
gsl_linalg_LU_decomp(&mv.matrix, p, &signum);
|
139
|
+
if (flag == LINALG_DECOMP) {
|
140
|
+
return rb_ary_new3(3, m,
|
141
|
+
Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p),
|
142
|
+
INT2FIX(signum));
|
143
|
+
} else {
|
144
|
+
return rb_ary_new3(3, argv[0],
|
145
|
+
Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p),
|
146
|
+
INT2FIX(signum));
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
#endif
|
151
|
+
|
152
|
+
static gsl_matrix* get_matrix(VALUE obj, VALUE klass,int *flagm);
|
153
|
+
static gsl_permutation* get_permutation(VALUE obj, size_t size, int *flagp);
|
154
|
+
static gsl_vector* get_vector2(VALUE obj, int *flagv);
|
155
|
+
|
156
|
+
static gsl_matrix* get_matrix(VALUE obj, VALUE klass, int *flagm)
|
157
|
+
{
|
158
|
+
gsl_matrix *mtmp = NULL, *m = NULL;
|
159
|
+
#ifdef HAVE_NARRAY_H
|
160
|
+
gsl_matrix_view mv;
|
161
|
+
struct NARRAY *na;
|
162
|
+
#endif
|
163
|
+
if (CLASS_OF(obj) == klass) {
|
164
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
165
|
+
*flagm = 0;
|
166
|
+
#ifdef HAVE_NARRAY_H
|
167
|
+
} else if (NA_IsNArray(obj)) {
|
168
|
+
GetNArray(obj, na);
|
169
|
+
mv = gsl_matrix_view_array((double*)na->ptr, na->shape[1], na->shape[0]);
|
170
|
+
m = &mv.matrix;
|
171
|
+
*flagm = -1;
|
172
|
+
#endif
|
173
|
+
} else {
|
174
|
+
CHECK_MATRIX(obj);
|
175
|
+
Data_Get_Struct(obj, gsl_matrix, mtmp);
|
176
|
+
m = make_matrix_clone(mtmp);
|
177
|
+
*flagm = 1;
|
178
|
+
}
|
179
|
+
return m;
|
180
|
+
}
|
181
|
+
|
182
|
+
static gsl_permutation* get_permutation(VALUE obj, size_t size, int *flagp)
|
183
|
+
{
|
184
|
+
gsl_permutation *p = NULL;
|
185
|
+
if (CLASS_OF(obj) == cgsl_permutation) {
|
186
|
+
Data_Get_Struct(obj, gsl_permutation, p);
|
187
|
+
*flagp = 0;
|
188
|
+
} else {
|
189
|
+
p = gsl_permutation_alloc(size);
|
190
|
+
*flagp = 1;
|
191
|
+
}
|
192
|
+
return p;
|
193
|
+
}
|
194
|
+
|
195
|
+
static gsl_vector* get_vector2(VALUE obj, int *flagv)
|
196
|
+
{
|
197
|
+
gsl_vector *v = NULL;
|
198
|
+
#ifdef HAVE_NARRAY_H
|
199
|
+
gsl_vector_view vv;
|
200
|
+
struct NARRAY *na;
|
201
|
+
#endif
|
202
|
+
if (TYPE(obj) == T_ARRAY) {
|
203
|
+
v = make_cvector_from_rarray(obj);
|
204
|
+
*flagv = 1;
|
205
|
+
#ifdef HAVE_NARRAY_H
|
206
|
+
} else if (NA_IsNArray(obj)) {
|
207
|
+
GetNArray(obj, na);
|
208
|
+
vv = gsl_vector_view_array((double*) na->ptr, na->total);
|
209
|
+
v = &vv.vector;
|
210
|
+
*flagv = -1;
|
211
|
+
#endif
|
212
|
+
} else {
|
213
|
+
CHECK_VECTOR(obj);
|
214
|
+
Data_Get_Struct(obj, gsl_vector, v);
|
215
|
+
*flagv = 0;
|
216
|
+
}
|
217
|
+
return v;
|
218
|
+
}
|
219
|
+
|
220
|
+
#ifdef HAVE_NARRAY_H
|
221
|
+
static VALUE rb_gsl_linalg_LU_solve_narray(int argc, VALUE *argv, VALUE obj);
|
222
|
+
#endif
|
223
|
+
|
224
|
+
VALUE rb_gsl_linalg_LU_solve(int argc, VALUE *argv, VALUE obj)
|
225
|
+
{
|
226
|
+
gsl_matrix *m = NULL;
|
227
|
+
gsl_permutation *p = NULL;
|
228
|
+
gsl_vector *b = NULL, *x = NULL;
|
229
|
+
int signum, flagm = 0, flagp = 0, flagb = 0, flagx = 0, itmp;
|
230
|
+
size_t size;
|
231
|
+
VALUE bb;
|
232
|
+
switch (TYPE(obj)) {
|
233
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
234
|
+
if (argc < 2 || argc > 4)
|
235
|
+
rb_raise(rb_eArgError, "Usage: solve(m, b), solve(m, b, x), solve(lu, p, b), solve(lu, p, b, x)");
|
236
|
+
#ifdef HAVE_NARRAY_H
|
237
|
+
if (NA_IsNArray(argv[0]))
|
238
|
+
return rb_gsl_linalg_LU_solve_narray(argc, argv, obj);
|
239
|
+
#endif
|
240
|
+
m = get_matrix(argv[0], cgsl_matrix_LU, &flagm);
|
241
|
+
itmp = 1;
|
242
|
+
break;
|
243
|
+
default:
|
244
|
+
if (argc < 1 || argc > 3)
|
245
|
+
rb_raise(rb_eArgError, "Usage: LU_solve(b), LU_solve(p, b), LU_solve(b, x), solve(p, b, x)");
|
246
|
+
|
247
|
+
m = get_matrix(obj, cgsl_matrix_LU, &flagm);
|
248
|
+
itmp = 0;
|
249
|
+
break;
|
250
|
+
}
|
251
|
+
size = m->size1;
|
252
|
+
|
253
|
+
p = get_permutation(argv[itmp], size, &flagp);
|
254
|
+
if (flagp == 1 && flagm == 0) rb_raise(rb_eArgError, "permutation must be given");
|
255
|
+
if (flagp == 0) itmp++;
|
256
|
+
|
257
|
+
bb = argv[itmp];
|
258
|
+
b = get_vector2(argv[itmp], &flagb);
|
259
|
+
itmp++;
|
260
|
+
|
261
|
+
if (itmp == argc) {
|
262
|
+
x = gsl_vector_alloc(size);
|
263
|
+
flagx = 1;
|
264
|
+
} else {
|
265
|
+
CHECK_VECTOR(argv[itmp]);
|
266
|
+
Data_Get_Struct(argv[itmp], gsl_vector, x);
|
267
|
+
}
|
268
|
+
if (flagm == 1) gsl_linalg_LU_decomp(m, p, &signum);
|
269
|
+
gsl_linalg_LU_solve(m, p, b, x);
|
270
|
+
if (flagm == 1) gsl_matrix_free(m);
|
271
|
+
if (flagp == 1) gsl_permutation_free(p);
|
272
|
+
if (flagb == 1) gsl_vector_free(b);
|
273
|
+
if (flagx == 1) return Data_Wrap_Struct(VECTOR_ROW_COL(bb), 0, gsl_vector_free, x);
|
274
|
+
else return argv[argc-1];
|
275
|
+
}
|
276
|
+
|
277
|
+
#ifdef HAVE_NARRAY_H
|
278
|
+
static VALUE rb_gsl_linalg_LU_solve_narray(int argc, VALUE *argv, VALUE obj)
|
279
|
+
{
|
280
|
+
struct NARRAY *na, *b;
|
281
|
+
VALUE ret;
|
282
|
+
gsl_permutation *p;
|
283
|
+
gsl_matrix_view mv;
|
284
|
+
gsl_vector_view bv, xv;
|
285
|
+
double *x;
|
286
|
+
int shape[1];
|
287
|
+
if (argc < 3)
|
288
|
+
rb_raise(rb_eArgError,
|
289
|
+
"wrong number of arguments %d(NArray, GSL::Permutation and NArray expected",
|
290
|
+
argc);
|
291
|
+
GetNArray(argv[0], na);
|
292
|
+
mv = gsl_matrix_view_array((double*) na->ptr, na->shape[1], na->shape[0]);
|
293
|
+
CHECK_PERMUTATION(argv[1]);
|
294
|
+
Data_Get_Struct(argv[1], gsl_permutation, p);
|
295
|
+
GetNArray(argv[2], b);
|
296
|
+
bv = gsl_vector_view_array((double*) b->ptr, b->total);
|
297
|
+
if (argc == 3) {
|
298
|
+
shape[0] = b->total;
|
299
|
+
ret = na_make_object(NA_DFLOAT, 1, shape, CLASS_OF(argv[0]));
|
300
|
+
} else {
|
301
|
+
ret = argv[3];
|
302
|
+
}
|
303
|
+
x = NA_PTR_TYPE(ret,double*);
|
304
|
+
xv = gsl_vector_view_array(x, b->total);
|
305
|
+
gsl_linalg_LU_solve(&mv.matrix, p, &bv.vector, &xv.vector);
|
306
|
+
return ret;
|
307
|
+
}
|
308
|
+
#endif
|
309
|
+
|
310
|
+
#ifdef HAVE_NARRAY_H
|
311
|
+
static VALUE rb_gsl_linalg_LU_svx_narray(int argc, VALUE *argv, VALUE obj);
|
312
|
+
#endif
|
313
|
+
|
314
|
+
/* bb must be Vector, it is replaced by the root of the system */
|
315
|
+
static VALUE rb_gsl_linalg_LU_svx(int argc, VALUE *argv, VALUE obj)
|
316
|
+
{
|
317
|
+
gsl_matrix *m = NULL;
|
318
|
+
gsl_permutation *p = NULL;
|
319
|
+
gsl_vector *b = NULL;
|
320
|
+
int signum, flagm = 0, flagp = 0, flagb = 0, itmp;
|
321
|
+
size_t size;
|
322
|
+
|
323
|
+
switch (TYPE(obj)) {
|
324
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
325
|
+
if (argc < 2 || argc > 3)
|
326
|
+
rb_raise(rb_eArgError, "Usage: svx(m, b), svx(lu, p, b)");
|
327
|
+
#ifdef HAVE_NARRAY_H
|
328
|
+
if (NA_IsNArray(argv[0]))
|
329
|
+
return rb_gsl_linalg_LU_svx_narray(argc, argv, obj);
|
330
|
+
#endif
|
331
|
+
m = get_matrix(argv[0], cgsl_matrix_LU, &flagm);
|
332
|
+
itmp = 1;
|
333
|
+
break;
|
334
|
+
default:
|
335
|
+
if (argc < 1 || argc > 2)
|
336
|
+
rb_raise(rb_eArgError, "Usage: LU_svx(b), LU_svx(p, b)");
|
337
|
+
m = get_matrix(obj, cgsl_matrix_LU, &flagm);
|
338
|
+
itmp = 0;
|
339
|
+
break;
|
340
|
+
}
|
341
|
+
size = m->size1;
|
342
|
+
p = get_permutation(argv[itmp], size, &flagp);
|
343
|
+
if (flagp == 1 && flagm == 0) rb_raise(rb_eArgError, "permutation must be given");
|
344
|
+
if (flagp == 0) itmp++;
|
345
|
+
CHECK_VECTOR(argv[itmp]);
|
346
|
+
b = get_vector2(argv[itmp], &flagb);
|
347
|
+
if (flagm == 1) gsl_linalg_LU_decomp(m, p, &signum);
|
348
|
+
gsl_linalg_LU_svx(m, p, b);
|
349
|
+
if (flagm == 1) gsl_matrix_free(m);
|
350
|
+
if (flagp == 1) gsl_permutation_free(p);
|
351
|
+
return argv[itmp];
|
352
|
+
}
|
353
|
+
|
354
|
+
#ifdef HAVE_NARRAY_H
|
355
|
+
static VALUE rb_gsl_linalg_LU_svx_narray(int argc, VALUE *argv, VALUE obj)
|
356
|
+
{
|
357
|
+
struct NARRAY *na, *b;
|
358
|
+
gsl_permutation *p;
|
359
|
+
gsl_matrix_view mv;
|
360
|
+
gsl_vector_view bv;
|
361
|
+
if (argc != 3)
|
362
|
+
rb_raise(rb_eArgError,
|
363
|
+
"wrong number of arguments %d(NArray, GSL::Permutation and NArray expected",
|
364
|
+
argc);
|
365
|
+
GetNArray(argv[0], na);
|
366
|
+
mv = gsl_matrix_view_array((double*) na->ptr, na->shape[1], na->shape[0]);
|
367
|
+
CHECK_PERMUTATION(argv[1]);
|
368
|
+
Data_Get_Struct(argv[1], gsl_permutation, p);
|
369
|
+
GetNArray(argv[2], b);
|
370
|
+
bv = gsl_vector_view_array((double*) b->ptr, b->total);
|
371
|
+
gsl_linalg_LU_svx(&mv.matrix, p, &bv.vector);
|
372
|
+
return argv[2];
|
373
|
+
}
|
374
|
+
#endif
|
375
|
+
|
376
|
+
/* singleton */
|
377
|
+
static VALUE rb_gsl_linalg_LU_refine(VALUE obj, VALUE vm,
|
378
|
+
VALUE lu, VALUE pp, VALUE bb,
|
379
|
+
VALUE xx)
|
380
|
+
{
|
381
|
+
gsl_matrix *m = NULL, *mlu = NULL;
|
382
|
+
gsl_permutation *p = NULL;
|
383
|
+
gsl_vector *b = NULL, *x = NULL, *r = NULL;
|
384
|
+
int flagb = 0;
|
385
|
+
VALUE vr;
|
386
|
+
CHECK_MATRIX(vm); CHECK_MATRIX(lu);
|
387
|
+
CHECK_PERMUTATION(pp); CHECK_VECTOR(xx);
|
388
|
+
Data_Get_Struct(vm, gsl_matrix, m);
|
389
|
+
Data_Get_Struct(lu, gsl_matrix, mlu);
|
390
|
+
Data_Get_Struct(pp, gsl_permutation, p);
|
391
|
+
if (TYPE(bb) == T_ARRAY) {
|
392
|
+
b = make_cvector_from_rarray(bb);
|
393
|
+
flagb = 1;
|
394
|
+
} else {
|
395
|
+
CHECK_VECTOR(bb);
|
396
|
+
Data_Get_Struct(bb, gsl_vector, b);
|
397
|
+
}
|
398
|
+
Data_Get_Struct(xx, gsl_vector, x);
|
399
|
+
r = gsl_vector_alloc(m->size1);
|
400
|
+
gsl_linalg_LU_refine(m, mlu, p, b, x, r);
|
401
|
+
vr = Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, r);
|
402
|
+
if (flagb == 1) gsl_vector_free(b);
|
403
|
+
return rb_ary_new3(2, xx, vr);
|
404
|
+
}
|
405
|
+
|
406
|
+
#ifdef HAVE_NARRAY_H
|
407
|
+
static VALUE rb_gsl_linalg_LU_invert_narray(int argc, VALUE *argv, VALUE obj);
|
408
|
+
#endif
|
409
|
+
|
410
|
+
static VALUE rb_gsl_linalg_LU_invert(int argc, VALUE *argv, VALUE obj)
|
411
|
+
{
|
412
|
+
gsl_matrix *m = NULL, *inverse = NULL;
|
413
|
+
gsl_permutation *p = NULL;
|
414
|
+
int signum, flagm = 0, flagp = 0, itmp;
|
415
|
+
size_t size;
|
416
|
+
switch (TYPE(obj)) {
|
417
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
418
|
+
#ifdef HAVE_NARRAY_H
|
419
|
+
if (NA_IsNArray(argv[0]))
|
420
|
+
return rb_gsl_linalg_LU_invert_narray(argc, argv, obj);
|
421
|
+
#endif
|
422
|
+
m = get_matrix(argv[0], cgsl_matrix_LU, &flagm);
|
423
|
+
itmp = 1;
|
424
|
+
break;
|
425
|
+
default:
|
426
|
+
m = get_matrix(obj, cgsl_matrix_LU, &flagm);
|
427
|
+
itmp = 0;
|
428
|
+
}
|
429
|
+
size = m->size1;
|
430
|
+
|
431
|
+
if (argc == itmp) {
|
432
|
+
p = gsl_permutation_alloc(size);
|
433
|
+
flagp = 1;
|
434
|
+
} else {
|
435
|
+
CHECK_PERMUTATION(argv[itmp]);
|
436
|
+
p = get_permutation(argv[itmp], size, &flagp);
|
437
|
+
}
|
438
|
+
if (flagp == 1 && flagm == 0) rb_raise(rb_eArgError, "permutation must be given");
|
439
|
+
if (flagp == 0) itmp++;
|
440
|
+
|
441
|
+
if (flagm == 1 || flagp == 1) {
|
442
|
+
gsl_linalg_LU_decomp(m, p, &signum);
|
443
|
+
}
|
444
|
+
|
445
|
+
if (argc-1 == itmp) {
|
446
|
+
CHECK_MATRIX(argv[itmp]);
|
447
|
+
Data_Get_Struct(argv[itmp], gsl_matrix, inverse);
|
448
|
+
} else {
|
449
|
+
inverse = gsl_matrix_alloc(size, size);
|
450
|
+
}
|
451
|
+
gsl_linalg_LU_invert(m, p, inverse);
|
452
|
+
if (flagm == 1) gsl_matrix_free(m);
|
453
|
+
if (flagp == 1) gsl_permutation_free(p);
|
454
|
+
if (argc-1 == itmp) return argv[itmp];
|
455
|
+
else return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, inverse);
|
456
|
+
|
457
|
+
}
|
458
|
+
|
459
|
+
#ifdef HAVE_NARRAY_H
|
460
|
+
static VALUE rb_gsl_linalg_LU_invert_narray(int argc, VALUE *argv, VALUE obj)
|
461
|
+
{
|
462
|
+
struct NARRAY *na;
|
463
|
+
VALUE inv;
|
464
|
+
gsl_permutation *p;
|
465
|
+
gsl_matrix_view mv1, mv2;
|
466
|
+
if (argc != 2) {
|
467
|
+
rb_raise(rb_eArgError, "Usage: LU.invert(lu, perm)");
|
468
|
+
}
|
469
|
+
CHECK_PERMUTATION(argv[1]);
|
470
|
+
GetNArray(argv[0], na);
|
471
|
+
inv = na_make_object(NA_DFLOAT, 2, na->shape, CLASS_OF(argv[0]));
|
472
|
+
mv1 = gsl_matrix_view_array((double*)na->ptr, na->shape[1], na->shape[0]);
|
473
|
+
mv2 = gsl_matrix_view_array(NA_PTR_TYPE(inv, double*), na->shape[1], na->shape[0]);
|
474
|
+
CHECK_PERMUTATION(argv[1]);
|
475
|
+
Data_Get_Struct(argv[1], gsl_permutation, p);
|
476
|
+
gsl_linalg_LU_invert(&mv1.matrix, p, &mv2.matrix);
|
477
|
+
return inv;
|
478
|
+
}
|
479
|
+
static VALUE rb_gsl_linalg_LU_det_narray(int argc, VALUE *argv, VALUE obj)
|
480
|
+
{
|
481
|
+
struct NARRAY *na;
|
482
|
+
gsl_matrix_view mv;
|
483
|
+
int signum = 1;
|
484
|
+
switch (argc) {
|
485
|
+
case 2:
|
486
|
+
signum = FIX2INT(argv[1]);
|
487
|
+
/* no break */
|
488
|
+
case 1:
|
489
|
+
GetNArray(argv[0], na);
|
490
|
+
mv = gsl_matrix_view_array((double*)na->ptr, na->shape[1], na->shape[0]);
|
491
|
+
break;
|
492
|
+
default:
|
493
|
+
rb_raise(rb_eArgError, "Usage: LU.det(lu, perm)");
|
494
|
+
break;
|
495
|
+
}
|
496
|
+
return rb_float_new(gsl_linalg_LU_det(&mv.matrix, signum));
|
497
|
+
}
|
498
|
+
static VALUE rb_gsl_linalg_LU_lndet_narray(int argc, VALUE *argv, VALUE obj)
|
499
|
+
{
|
500
|
+
struct NARRAY *na;
|
501
|
+
gsl_matrix_view mv;
|
502
|
+
switch (argc) {
|
503
|
+
case 1:
|
504
|
+
GetNArray(argv[0], na);
|
505
|
+
mv = gsl_matrix_view_array((double*)na->ptr, na->shape[1], na->shape[0]);
|
506
|
+
break;
|
507
|
+
default:
|
508
|
+
rb_raise(rb_eArgError, "Usage: LU.lndet(lu)");
|
509
|
+
break;
|
510
|
+
}
|
511
|
+
return rb_float_new(gsl_linalg_LU_lndet(&mv.matrix));
|
512
|
+
}
|
513
|
+
|
514
|
+
#endif
|
515
|
+
|
516
|
+
static VALUE rb_gsl_linalg_LU_det(int argc, VALUE *argv, VALUE obj)
|
517
|
+
{
|
518
|
+
gsl_matrix *m = NULL;
|
519
|
+
gsl_permutation *p = NULL;
|
520
|
+
int flagm = 0, flagp = 0, itmp, sign;
|
521
|
+
size_t size;
|
522
|
+
double det;
|
523
|
+
switch (TYPE(obj)) {
|
524
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
525
|
+
if (argc < 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
526
|
+
argc);
|
527
|
+
#ifdef HAVE_NARRAY_H
|
528
|
+
if (NA_IsNArray(argv[0]))
|
529
|
+
return rb_gsl_linalg_LU_det_narray(argc, argv, obj);
|
530
|
+
#endif
|
531
|
+
|
532
|
+
m = get_matrix(argv[0], cgsl_matrix_LU, &flagm);
|
533
|
+
itmp = 1;
|
534
|
+
break;
|
535
|
+
default:
|
536
|
+
m = get_matrix(obj, cgsl_matrix_LU, &flagm);
|
537
|
+
itmp = 0;
|
538
|
+
break;
|
539
|
+
}
|
540
|
+
size = m->size1;
|
541
|
+
if (flagm == 0) {
|
542
|
+
if (argc-itmp == 1) sign = FIX2INT(argv[itmp]);
|
543
|
+
else sign = 1;
|
544
|
+
} else {
|
545
|
+
if (argc-itmp >= 2) {
|
546
|
+
get_permutation(argv[itmp], size, &flagp);
|
547
|
+
} else {
|
548
|
+
p = gsl_permutation_alloc(size);
|
549
|
+
flagp = 1;
|
550
|
+
}
|
551
|
+
}
|
552
|
+
if (flagm == 1) gsl_linalg_LU_decomp(m, p, &sign);
|
553
|
+
det = gsl_linalg_LU_det(m, sign);
|
554
|
+
if (flagm == 1) gsl_matrix_free(m);
|
555
|
+
if (flagp == 1) gsl_permutation_free(p);
|
556
|
+
return rb_float_new(det);
|
557
|
+
}
|
558
|
+
|
559
|
+
static VALUE rb_gsl_linalg_LU_lndet(int argc, VALUE *argv, VALUE obj)
|
560
|
+
{
|
561
|
+
gsl_matrix *m = NULL;
|
562
|
+
gsl_permutation *p = NULL;
|
563
|
+
int flagm = 0, sign;
|
564
|
+
double lndet;
|
565
|
+
|
566
|
+
switch (TYPE(obj)) {
|
567
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
568
|
+
if (argc < 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
569
|
+
argc);
|
570
|
+
#ifdef HAVE_NARRAY_H
|
571
|
+
if (NA_IsNArray(argv[0]))
|
572
|
+
return rb_gsl_linalg_LU_lndet_narray(argc, argv, obj);
|
573
|
+
#endif
|
574
|
+
|
575
|
+
m = get_matrix(argv[0], cgsl_matrix_LU, &flagm);
|
576
|
+
break;
|
577
|
+
default:
|
578
|
+
m = get_matrix(obj, cgsl_matrix_LU, &flagm);
|
579
|
+
break;
|
580
|
+
}
|
581
|
+
if (flagm == 1) {
|
582
|
+
p = gsl_permutation_alloc(m->size1);
|
583
|
+
gsl_linalg_LU_decomp(m, p, &sign);
|
584
|
+
}
|
585
|
+
lndet = gsl_linalg_LU_lndet(m);
|
586
|
+
if (flagm == 1) {
|
587
|
+
gsl_matrix_free(m);
|
588
|
+
gsl_permutation_free(p);
|
589
|
+
}
|
590
|
+
return rb_float_new(lndet);
|
591
|
+
}
|
592
|
+
|
593
|
+
static VALUE rb_gsl_linalg_LU_sgndet(int argc, VALUE *argv, VALUE obj)
|
594
|
+
{
|
595
|
+
gsl_matrix *m = NULL;
|
596
|
+
gsl_permutation *p = NULL;
|
597
|
+
int flagm = 0, sign, signdet, itmp;
|
598
|
+
switch (TYPE(obj)) {
|
599
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
600
|
+
m = get_matrix(argv[0], cgsl_matrix_LU, &flagm);
|
601
|
+
itmp = 1;
|
602
|
+
break;
|
603
|
+
default:
|
604
|
+
m = get_matrix(obj, cgsl_matrix_LU, &flagm);
|
605
|
+
itmp = 0;
|
606
|
+
break;
|
607
|
+
}
|
608
|
+
if (flagm == 1) {
|
609
|
+
p = gsl_permutation_alloc(m->size1);
|
610
|
+
gsl_linalg_LU_decomp(m, p, &sign);
|
611
|
+
} else {
|
612
|
+
if (argc-itmp != 1) rb_raise(rb_eArgError, "sign must be given");
|
613
|
+
sign = FIX2INT(argv[itmp]);
|
614
|
+
}
|
615
|
+
signdet = gsl_linalg_LU_sgndet(m, sign);
|
616
|
+
if (flagm == 1) {
|
617
|
+
gsl_matrix_free(m);
|
618
|
+
gsl_permutation_free(p);
|
619
|
+
}
|
620
|
+
return INT2FIX(signdet);
|
621
|
+
}
|
622
|
+
|
623
|
+
#ifdef GSL_1_6_LATER
|
624
|
+
int gsl_linalg_LQ_solve_T(const gsl_matrix*, const gsl_vector*, const gsl_vector*, gsl_vector*);
|
625
|
+
int gsl_linalg_LQ_svx_T (const gsl_matrix*, const gsl_vector*, gsl_vector*);
|
626
|
+
int gsl_linalg_LQ_lssolve_T(const gsl_matrix * LQ, const gsl_vector * tau,
|
627
|
+
const gsl_vector * b, gsl_vector * x,
|
628
|
+
gsl_vector * residual);
|
629
|
+
int
|
630
|
+
gsl_linalg_LQ_Lsolve_T (const gsl_matrix * LQ, const gsl_vector * b, gsl_vector* x);
|
631
|
+
int
|
632
|
+
gsl_linalg_LQ_Lsvx_T (const gsl_matrix * LQ, gsl_vector * x);
|
633
|
+
int
|
634
|
+
gsl_linalg_L_solve_T (const gsl_matrix * L, const gsl_vector * b, gsl_vector * x);
|
635
|
+
|
636
|
+
|
637
|
+
#endif
|
638
|
+
|
639
|
+
enum {
|
640
|
+
LINALG_QR_DECOMP,
|
641
|
+
LINALG_QR_DECOMP_BANG,
|
642
|
+
LINALG_LQ_DECOMP,
|
643
|
+
LINALG_LQ_DECOMP_BANG,
|
644
|
+
LINALG_QR_SOLVE,
|
645
|
+
LINALG_LQ_SOLVE,
|
646
|
+
LINALG_QR_QTvec,
|
647
|
+
LINALG_QR_Qvec,
|
648
|
+
LINALG_LQ_vecQ,
|
649
|
+
LINALG_LQ_vecQT,
|
650
|
+
LINALG_QR_RSOLVE,
|
651
|
+
LINALG_LQ_LSOLVE,
|
652
|
+
LINALG_QR_RSVX,
|
653
|
+
LINALG_LQ_LSVX,
|
654
|
+
LINALG_R_SOLVE,
|
655
|
+
LINALG_R_SVX,
|
656
|
+
LINALG_L_SOLVE,
|
657
|
+
LINALG_L_SVX,
|
658
|
+
LINALG_QR_UNPACK,
|
659
|
+
LINALG_LQ_UNPACK,
|
660
|
+
};
|
661
|
+
|
662
|
+
static VALUE rb_gsl_linalg_QR_LQ_decomposition(int argc, VALUE *argv, VALUE obj,
|
663
|
+
int flag)
|
664
|
+
{
|
665
|
+
gsl_matrix *m = NULL, *mtmp = NULL;
|
666
|
+
gsl_vector *tau = NULL;
|
667
|
+
int (*fdecomp)(gsl_matrix *, gsl_vector *);
|
668
|
+
int itmp, status;
|
669
|
+
VALUE vtau, mdecomp, omatrix;
|
670
|
+
|
671
|
+
switch (TYPE(obj)) {
|
672
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
673
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
674
|
+
omatrix = argv[0];
|
675
|
+
itmp = 1;
|
676
|
+
break;
|
677
|
+
default:
|
678
|
+
omatrix = obj;
|
679
|
+
itmp = 0;
|
680
|
+
break;
|
681
|
+
}
|
682
|
+
CHECK_MATRIX(omatrix);
|
683
|
+
Data_Get_Struct(omatrix, gsl_matrix, mtmp);
|
684
|
+
|
685
|
+
switch (flag) {
|
686
|
+
case LINALG_QR_DECOMP:
|
687
|
+
fdecomp = &gsl_linalg_QR_decomp;
|
688
|
+
m = make_matrix_clone(mtmp);
|
689
|
+
mdecomp = Data_Wrap_Struct(cgsl_matrix_QR, 0, gsl_matrix_free, m);
|
690
|
+
break;
|
691
|
+
case LINALG_QR_DECOMP_BANG:
|
692
|
+
fdecomp = &gsl_linalg_QR_decomp;
|
693
|
+
m = mtmp;
|
694
|
+
mdecomp = omatrix;
|
695
|
+
RBASIC(mdecomp)->klass = cgsl_matrix_QR;
|
696
|
+
break;
|
697
|
+
#ifdef GSL_1_6_LATER
|
698
|
+
case LINALG_LQ_DECOMP:
|
699
|
+
fdecomp = &gsl_linalg_LQ_decomp;
|
700
|
+
m = make_matrix_clone(mtmp);
|
701
|
+
mdecomp = Data_Wrap_Struct(cgsl_matrix_LQ, 0, gsl_matrix_free, m);
|
702
|
+
break;
|
703
|
+
case LINALG_LQ_DECOMP_BANG:
|
704
|
+
fdecomp = &gsl_linalg_LQ_decomp;
|
705
|
+
m = mtmp;
|
706
|
+
mdecomp = omatrix;
|
707
|
+
RBASIC(mdecomp)->klass = cgsl_matrix_LQ;
|
708
|
+
break;
|
709
|
+
#endif
|
710
|
+
default:
|
711
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
712
|
+
break;
|
713
|
+
}
|
714
|
+
switch (argc - itmp) {
|
715
|
+
case 0:
|
716
|
+
tau = gsl_vector_alloc(GSL_MIN(mtmp->size1, mtmp->size2));
|
717
|
+
break;
|
718
|
+
case 1:
|
719
|
+
CHECK_VECTOR(argv[itmp]);
|
720
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
721
|
+
break;
|
722
|
+
default:
|
723
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
724
|
+
break;
|
725
|
+
}
|
726
|
+
status = (*fdecomp)(m, tau);
|
727
|
+
switch (flag) {
|
728
|
+
case LINALG_QR_DECOMP:
|
729
|
+
case LINALG_LQ_DECOMP:
|
730
|
+
if (argc == itmp) {
|
731
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
732
|
+
return rb_ary_new3(2, mdecomp, vtau);
|
733
|
+
} else {
|
734
|
+
RBASIC(argv[itmp])->klass = cgsl_vector_tau;
|
735
|
+
return mdecomp;
|
736
|
+
}
|
737
|
+
break;
|
738
|
+
case LINALG_QR_DECOMP_BANG:
|
739
|
+
case LINALG_LQ_DECOMP_BANG:
|
740
|
+
if (argc == itmp) {
|
741
|
+
return Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
742
|
+
} else {
|
743
|
+
RBASIC(argv[itmp])->klass = cgsl_vector_tau;
|
744
|
+
return INT2FIX(status);
|
745
|
+
}
|
746
|
+
break;
|
747
|
+
default:
|
748
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
749
|
+
break;
|
750
|
+
}
|
751
|
+
return Qnil;
|
752
|
+
}
|
753
|
+
|
754
|
+
#ifdef HAVE_NARRAY_H
|
755
|
+
static VALUE rb_gsl_linalg_QR_decomp_narray(int argc, VALUE *argv, VALUE obj);
|
756
|
+
#endif
|
757
|
+
|
758
|
+
static VALUE rb_gsl_linalg_QR_decomp(int argc, VALUE *argv, VALUE obj)
|
759
|
+
{
|
760
|
+
#ifdef HAVE_NARRAY_H
|
761
|
+
if (argc >= 1 && NA_IsNArray(argv[0]))
|
762
|
+
return rb_gsl_linalg_QR_decomp_narray(argc, argv, obj);
|
763
|
+
#endif
|
764
|
+
return rb_gsl_linalg_QR_LQ_decomposition(argc, argv, obj, LINALG_QR_DECOMP);
|
765
|
+
}
|
766
|
+
|
767
|
+
static VALUE rb_gsl_linalg_QR_decomp_bang(int argc, VALUE *argv, VALUE obj)
|
768
|
+
{
|
769
|
+
return rb_gsl_linalg_QR_LQ_decomposition(argc, argv, obj, LINALG_QR_DECOMP_BANG);
|
770
|
+
}
|
771
|
+
|
772
|
+
#ifdef GSL_1_6_LATER
|
773
|
+
static VALUE rb_gsl_linalg_LQ_decomp(int argc, VALUE *argv, VALUE obj)
|
774
|
+
{
|
775
|
+
return rb_gsl_linalg_QR_LQ_decomposition(argc, argv, obj, LINALG_LQ_DECOMP);
|
776
|
+
}
|
777
|
+
|
778
|
+
static VALUE rb_gsl_linalg_LQ_decomp_bang(int argc, VALUE *argv, VALUE obj)
|
779
|
+
{
|
780
|
+
return rb_gsl_linalg_QR_LQ_decomposition(argc, argv, obj, LINALG_LQ_DECOMP_BANG);
|
781
|
+
}
|
782
|
+
#endif
|
783
|
+
|
784
|
+
static VALUE rb_gsl_linalg_QR_LQ_solve(int argc, VALUE *argv, VALUE obj, int flag)
|
785
|
+
{
|
786
|
+
gsl_matrix *m = NULL;
|
787
|
+
gsl_vector *b = NULL, *x = NULL, *tau = NULL;
|
788
|
+
VALUE omatrix;
|
789
|
+
int flagm = 0, flagt = 0, flagb = 0, flagx = 0, itmp;
|
790
|
+
size_t size;
|
791
|
+
int (*fdecomp)(gsl_matrix*, gsl_vector*);
|
792
|
+
int (*fsolve)(const gsl_matrix*, const gsl_vector*, const gsl_vector*, gsl_vector*);
|
793
|
+
|
794
|
+
switch (TYPE(obj)) {
|
795
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
796
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
797
|
+
omatrix = argv[0];
|
798
|
+
itmp = 1;
|
799
|
+
break;
|
800
|
+
default:
|
801
|
+
omatrix = obj;
|
802
|
+
itmp = 0;
|
803
|
+
break;
|
804
|
+
}
|
805
|
+
if (argc-itmp < 1 || argc-itmp > 3)
|
806
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
807
|
+
CHECK_MATRIX(omatrix);
|
808
|
+
switch (flag) {
|
809
|
+
case LINALG_QR_SOLVE:
|
810
|
+
m = get_matrix(omatrix, cgsl_matrix_QR, &flagm);
|
811
|
+
fdecomp = &gsl_linalg_QR_decomp;
|
812
|
+
fsolve = &gsl_linalg_QR_solve;
|
813
|
+
break;
|
814
|
+
#ifdef GSL_1_6_LATER
|
815
|
+
case LINALG_LQ_SOLVE:
|
816
|
+
m = get_matrix(omatrix, cgsl_matrix_LQ, &flagm);
|
817
|
+
fdecomp = &gsl_linalg_LQ_decomp;
|
818
|
+
fsolve = &gsl_linalg_LQ_solve_T;
|
819
|
+
break;
|
820
|
+
#endif
|
821
|
+
default:
|
822
|
+
rb_raise(rb_eRuntimeError, "unknown operatioin");
|
823
|
+
break;
|
824
|
+
}
|
825
|
+
size = m->size1;
|
826
|
+
if (flagm == 0) { /* the matrix given is already decomped */
|
827
|
+
if (CLASS_OF(argv[itmp]) != cgsl_vector_tau)
|
828
|
+
rb_raise(rb_eArgError, "tau vector must be given");
|
829
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
830
|
+
flagt = 0;
|
831
|
+
itmp++;
|
832
|
+
} else {
|
833
|
+
if (CLASS_OF(argv[itmp]) == cgsl_vector_tau) {
|
834
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
835
|
+
flagt = 0;
|
836
|
+
itmp++;
|
837
|
+
} else {
|
838
|
+
tau = gsl_vector_alloc(size);
|
839
|
+
flagt = 1;
|
840
|
+
}
|
841
|
+
}
|
842
|
+
b = get_vector2(argv[itmp], &flagb);
|
843
|
+
itmp++;
|
844
|
+
if (itmp == argc) {
|
845
|
+
x = gsl_vector_alloc(m->size1);
|
846
|
+
flagx = 1;
|
847
|
+
} else {
|
848
|
+
CHECK_VECTOR(argv[itmp]);
|
849
|
+
Data_Get_Struct(argv[itmp], gsl_vector, x);
|
850
|
+
flagx = 0;
|
851
|
+
}
|
852
|
+
if (flagm == 1) (*fdecomp)(m, tau);
|
853
|
+
(*fsolve)(m, tau, b, x);
|
854
|
+
if (flagm == 1) gsl_matrix_free(m);
|
855
|
+
if (flagt == 1) gsl_vector_free(tau);
|
856
|
+
if (flagb == 1) gsl_vector_free(b);
|
857
|
+
if (flagx == 1) return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
858
|
+
else return argv[itmp];
|
859
|
+
}
|
860
|
+
|
861
|
+
static VALUE rb_gsl_linalg_QR_LQ_svx(int argc, VALUE *argv, VALUE obj, int flag)
|
862
|
+
{
|
863
|
+
gsl_matrix *m = NULL;
|
864
|
+
gsl_vector *b = NULL, *tau = NULL;
|
865
|
+
VALUE omatrix;
|
866
|
+
int flagm = 0, flagt = 0, flagb = 0, itmp;
|
867
|
+
size_t size;
|
868
|
+
int (*fdecomp)(gsl_matrix*, gsl_vector*);
|
869
|
+
int (*fsvx)(const gsl_matrix*, const gsl_vector*, gsl_vector*);
|
870
|
+
|
871
|
+
switch (TYPE(obj)) {
|
872
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
873
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
874
|
+
omatrix = argv[0];
|
875
|
+
itmp = 1;
|
876
|
+
break;
|
877
|
+
default:
|
878
|
+
omatrix = obj;
|
879
|
+
itmp = 0;
|
880
|
+
break;
|
881
|
+
}
|
882
|
+
if (argc-itmp < 1 || argc-itmp > 2)
|
883
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
884
|
+
CHECK_MATRIX(omatrix);
|
885
|
+
switch (flag) {
|
886
|
+
case LINALG_QR_SOLVE:
|
887
|
+
m = get_matrix(omatrix, cgsl_matrix_QR, &flagm);
|
888
|
+
fdecomp = &gsl_linalg_QR_decomp;
|
889
|
+
fsvx = &gsl_linalg_QR_svx;
|
890
|
+
break;
|
891
|
+
#ifdef GSL_1_6_LATER
|
892
|
+
case LINALG_LQ_SOLVE:
|
893
|
+
m = get_matrix(omatrix, cgsl_matrix_LQ, &flagm);
|
894
|
+
fdecomp = &gsl_linalg_LQ_decomp;
|
895
|
+
fsvx = &gsl_linalg_LQ_svx_T;
|
896
|
+
break;
|
897
|
+
#endif
|
898
|
+
default:
|
899
|
+
rb_raise(rb_eRuntimeError, "unknown operatioin");
|
900
|
+
break;
|
901
|
+
}
|
902
|
+
size = m->size1;
|
903
|
+
if (flagm == 0) { /* the matrix given is already decomped */
|
904
|
+
if (CLASS_OF(argv[itmp]) != cgsl_vector_tau)
|
905
|
+
rb_raise(rb_eArgError, "tau vector must be given");
|
906
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
907
|
+
flagt = 0;
|
908
|
+
itmp++;
|
909
|
+
} else {
|
910
|
+
if (CLASS_OF(argv[itmp]) == cgsl_vector_tau) {
|
911
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
912
|
+
flagt = 0;
|
913
|
+
itmp++;
|
914
|
+
} else {
|
915
|
+
tau = gsl_vector_alloc(size);
|
916
|
+
flagt = 1;
|
917
|
+
}
|
918
|
+
}
|
919
|
+
b = get_vector2(argv[itmp], &flagb);
|
920
|
+
if (flagm == 1 && flagt == 1) (*fdecomp)(m, tau);
|
921
|
+
(*fsvx)(m, tau, b);
|
922
|
+
if (flagm == 1) gsl_matrix_free(m);
|
923
|
+
if (flagt == 1) gsl_vector_free(tau);
|
924
|
+
return argv[itmp];
|
925
|
+
}
|
926
|
+
|
927
|
+
static VALUE rb_gsl_linalg_QR_LQ_lssolve(int argc, VALUE *argv, VALUE obj, int flag)
|
928
|
+
{
|
929
|
+
gsl_matrix *m = NULL;
|
930
|
+
gsl_vector *b = NULL, *x = NULL, *tau = NULL, *r = NULL;
|
931
|
+
VALUE omatrix;
|
932
|
+
int flagm = 0, flagt = 0, flagb = 0, itmp, status;
|
933
|
+
size_t size;
|
934
|
+
int (*fdecomp)(gsl_matrix*, gsl_vector*);
|
935
|
+
int (*flssolve)(const gsl_matrix*, const gsl_vector*, const gsl_vector*, gsl_vector*,
|
936
|
+
gsl_vector*);
|
937
|
+
|
938
|
+
switch (TYPE(obj)) {
|
939
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
940
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
941
|
+
omatrix = argv[0];
|
942
|
+
itmp = 1;
|
943
|
+
break;
|
944
|
+
default:
|
945
|
+
omatrix = obj;
|
946
|
+
itmp = 0;
|
947
|
+
break;
|
948
|
+
}
|
949
|
+
if (argc-itmp < 1 || argc-itmp > 4)
|
950
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
951
|
+
CHECK_MATRIX(omatrix);
|
952
|
+
switch (flag) {
|
953
|
+
case LINALG_QR_SOLVE:
|
954
|
+
m = get_matrix(omatrix, cgsl_matrix_QR, &flagm);
|
955
|
+
fdecomp = &gsl_linalg_QR_decomp;
|
956
|
+
flssolve = &gsl_linalg_QR_lssolve;
|
957
|
+
break;
|
958
|
+
#ifdef GSL_1_6_LATER
|
959
|
+
case LINALG_LQ_SOLVE:
|
960
|
+
m = get_matrix(omatrix, cgsl_matrix_LQ, &flagm);
|
961
|
+
fdecomp = &gsl_linalg_LQ_decomp;
|
962
|
+
flssolve = &gsl_linalg_LQ_lssolve_T;
|
963
|
+
break;
|
964
|
+
#endif
|
965
|
+
default:
|
966
|
+
rb_raise(rb_eRuntimeError, "unknown operatioin");
|
967
|
+
break;
|
968
|
+
}
|
969
|
+
size = m->size1;
|
970
|
+
if (flagm == 0) { /* the matrix given is already decomped */
|
971
|
+
if (CLASS_OF(argv[itmp]) != cgsl_vector_tau)
|
972
|
+
rb_raise(rb_eArgError, "tau vector must be given");
|
973
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
974
|
+
flagt = 0;
|
975
|
+
itmp++;
|
976
|
+
} else {
|
977
|
+
if (CLASS_OF(argv[itmp]) == cgsl_vector_tau) {
|
978
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
979
|
+
flagt = 0;
|
980
|
+
itmp++;
|
981
|
+
} else {
|
982
|
+
tau = gsl_vector_alloc(size);
|
983
|
+
flagt = 1;
|
984
|
+
}
|
985
|
+
}
|
986
|
+
b = get_vector2(argv[itmp], &flagb);
|
987
|
+
itmp++;
|
988
|
+
switch (argc - itmp) {
|
989
|
+
case 2:
|
990
|
+
CHECK_VECTOR(argv[argc-2]);
|
991
|
+
Data_Get_Struct(argv[argc-2], gsl_vector, x);
|
992
|
+
CHECK_VECTOR(argv[argc-1]);
|
993
|
+
Data_Get_Struct(argv[argc-1], gsl_vector, r);
|
994
|
+
break;
|
995
|
+
case 1:
|
996
|
+
CHECK_VECTOR(argv[argc-1]);
|
997
|
+
Data_Get_Struct(argv[argc-1], gsl_vector, x);
|
998
|
+
r = gsl_vector_alloc(x->size);
|
999
|
+
break;
|
1000
|
+
case 0:
|
1001
|
+
x = gsl_vector_alloc(m->size1);
|
1002
|
+
r = gsl_vector_alloc(m->size1);
|
1003
|
+
break;
|
1004
|
+
default:
|
1005
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
1006
|
+
break;
|
1007
|
+
}
|
1008
|
+
if (flagm == 1) (*fdecomp)(m, tau);
|
1009
|
+
status = (*flssolve)(m, tau, b, x, r);
|
1010
|
+
if (flagm == 1) gsl_matrix_free(m);
|
1011
|
+
if (flagt == 1) gsl_vector_free(tau);
|
1012
|
+
if (flagb == 1) gsl_vector_free(b);
|
1013
|
+
|
1014
|
+
switch (argc - itmp) {
|
1015
|
+
case 2:
|
1016
|
+
return INT2FIX(status);
|
1017
|
+
break;
|
1018
|
+
case 1:
|
1019
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, r);
|
1020
|
+
break;
|
1021
|
+
default:
|
1022
|
+
return rb_ary_new3(2, Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x),
|
1023
|
+
Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, r));
|
1024
|
+
}
|
1025
|
+
return Qnil;
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
#ifdef HAVE_NARRAY_H
|
1029
|
+
static VALUE rb_gsl_linalg_QR_solve_narray(int argc, VALUE *argv, VALUE obj);
|
1030
|
+
static VALUE rb_gsl_linalg_QR_svx_narray(int argc, VALUE *argv, VALUE obj);
|
1031
|
+
#endif
|
1032
|
+
|
1033
|
+
static VALUE rb_gsl_linalg_QR_solve(int argc, VALUE *argv, VALUE obj)
|
1034
|
+
{
|
1035
|
+
#ifdef HAVE_NARRAY_H
|
1036
|
+
if (argc == 3 && NA_IsNArray(argv[0]))
|
1037
|
+
return rb_gsl_linalg_QR_solve_narray(argc, argv, obj);
|
1038
|
+
#endif
|
1039
|
+
return rb_gsl_linalg_QR_LQ_solve(argc, argv, obj, LINALG_QR_SOLVE);
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
static VALUE rb_gsl_linalg_QR_svx(int argc, VALUE *argv, VALUE obj)
|
1043
|
+
{
|
1044
|
+
#ifdef HAVE_NARRAY_H
|
1045
|
+
if (argc == 2 && NA_IsNArray(argv[0]))
|
1046
|
+
return rb_gsl_linalg_QR_svx_narray(argc, argv, obj);
|
1047
|
+
#endif
|
1048
|
+
return rb_gsl_linalg_QR_LQ_svx(argc, argv, obj, LINALG_QR_SOLVE);
|
1049
|
+
}
|
1050
|
+
|
1051
|
+
static VALUE rb_gsl_linalg_QR_lssolve(int argc, VALUE *argv, VALUE obj)
|
1052
|
+
{
|
1053
|
+
return rb_gsl_linalg_QR_LQ_lssolve(argc, argv, obj, LINALG_QR_SOLVE);
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
#ifdef GSL_1_6_LATER
|
1057
|
+
static VALUE rb_gsl_linalg_LQ_solve(int argc, VALUE *argv, VALUE obj)
|
1058
|
+
{
|
1059
|
+
return rb_gsl_linalg_QR_LQ_solve(argc, argv, obj, LINALG_LQ_SOLVE);
|
1060
|
+
}
|
1061
|
+
|
1062
|
+
static VALUE rb_gsl_linalg_LQ_svx(int argc, VALUE *argv, VALUE obj)
|
1063
|
+
{
|
1064
|
+
return rb_gsl_linalg_QR_LQ_svx(argc, argv, obj, LINALG_LQ_SOLVE);
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
static VALUE rb_gsl_linalg_LQ_lssolve(int argc, VALUE *argv, VALUE obj)
|
1068
|
+
{
|
1069
|
+
return rb_gsl_linalg_QR_LQ_lssolve(argc, argv, obj, LINALG_LQ_SOLVE);
|
1070
|
+
}
|
1071
|
+
#endif
|
1072
|
+
|
1073
|
+
static VALUE rb_gsl_linalg_QRLQ_QTvec(int argc, VALUE *argv, VALUE obj,
|
1074
|
+
int flag)
|
1075
|
+
{
|
1076
|
+
gsl_matrix *QR = NULL;
|
1077
|
+
gsl_vector *tau = NULL, *v = NULL;
|
1078
|
+
VALUE ret;
|
1079
|
+
switch (TYPE(obj)) {
|
1080
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1081
|
+
if (argc != 3) rb_raise(rb_eArgError,
|
1082
|
+
"wrong number of arguments (%d for 3)", argc);
|
1083
|
+
CHECK_MATRIX(argv[0]); CHECK_VECTOR(argv[1]); CHECK_VECTOR(argv[2]);
|
1084
|
+
Data_Get_Struct(argv[0], gsl_matrix, QR);
|
1085
|
+
Data_Get_Struct(argv[1], gsl_vector, tau);
|
1086
|
+
Data_Get_Struct(argv[2], gsl_vector, v);
|
1087
|
+
ret = argv[2];
|
1088
|
+
break;
|
1089
|
+
default:
|
1090
|
+
if (argc != 2) rb_raise(rb_eArgError,
|
1091
|
+
"wrong number of arguments (%d for 2)", argc);
|
1092
|
+
CHECK_VECTOR(argv[2]); CHECK_VECTOR(argv[1]);
|
1093
|
+
Data_Get_Struct(obj, gsl_matrix, QR);
|
1094
|
+
Data_Get_Struct(argv[0], gsl_vector, tau);
|
1095
|
+
Data_Get_Struct(argv[1], gsl_vector, v);
|
1096
|
+
ret = argv[1];
|
1097
|
+
break;
|
1098
|
+
}
|
1099
|
+
switch (flag) {
|
1100
|
+
case LINALG_QR_QTvec:
|
1101
|
+
gsl_linalg_QR_QTvec(QR, tau, v);
|
1102
|
+
break;
|
1103
|
+
case LINALG_QR_Qvec:
|
1104
|
+
gsl_linalg_QR_Qvec(QR, tau, v);
|
1105
|
+
break;
|
1106
|
+
#ifdef GSL_1_6_LATER
|
1107
|
+
case LINALG_LQ_vecQ:
|
1108
|
+
gsl_linalg_LQ_vecQ(QR, tau, v);
|
1109
|
+
break;
|
1110
|
+
case LINALG_LQ_vecQT:
|
1111
|
+
gsl_linalg_LQ_vecQT(QR, tau, v);
|
1112
|
+
break;
|
1113
|
+
#endif
|
1114
|
+
default:
|
1115
|
+
break;
|
1116
|
+
}
|
1117
|
+
return ret;
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
static VALUE rb_gsl_linalg_QR_QTvec(int argc, VALUE *argv, VALUE obj)
|
1121
|
+
{
|
1122
|
+
return rb_gsl_linalg_QRLQ_QTvec(argc, argv, obj, LINALG_QR_QTvec);
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
static VALUE rb_gsl_linalg_QR_Qvec(int argc, VALUE *argv, VALUE obj)
|
1126
|
+
{
|
1127
|
+
return rb_gsl_linalg_QRLQ_QTvec(argc, argv, obj, LINALG_QR_Qvec);
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
#ifdef GSL_1_6_LATER
|
1131
|
+
static VALUE rb_gsl_linalg_LQ_vecQT(int argc, VALUE *argv, VALUE obj)
|
1132
|
+
{
|
1133
|
+
return rb_gsl_linalg_QRLQ_QTvec(argc, argv, obj, LINALG_LQ_vecQT);
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
static VALUE rb_gsl_linalg_LQ_vecQ(int argc, VALUE *argv, VALUE obj)
|
1137
|
+
{
|
1138
|
+
return rb_gsl_linalg_QRLQ_QTvec(argc, argv, obj, LINALG_LQ_vecQ);
|
1139
|
+
}
|
1140
|
+
#endif
|
1141
|
+
|
1142
|
+
static VALUE rb_gsl_linalg_QRLQ_unpack(int argc, VALUE *argv, VALUE obj,
|
1143
|
+
int flag)
|
1144
|
+
{
|
1145
|
+
gsl_matrix *QR = NULL, *Q = NULL, *R = NULL;
|
1146
|
+
gsl_vector *tau = NULL;
|
1147
|
+
int itmp;
|
1148
|
+
VALUE vtmp, vQ, vR, klass;
|
1149
|
+
switch (flag) {
|
1150
|
+
case LINALG_QR_UNPACK:
|
1151
|
+
klass = cgsl_matrix_QR;
|
1152
|
+
break;
|
1153
|
+
case LINALG_LQ_UNPACK:
|
1154
|
+
klass = cgsl_matrix_LQ;
|
1155
|
+
break;
|
1156
|
+
default:
|
1157
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1158
|
+
break;
|
1159
|
+
}
|
1160
|
+
switch (TYPE(obj)) {
|
1161
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1162
|
+
if (argc != 2) rb_raise(rb_eArgError,
|
1163
|
+
"wrong number of arguments (%d for 2)", argc);
|
1164
|
+
vtmp = argv[0];
|
1165
|
+
itmp = 1;
|
1166
|
+
break;
|
1167
|
+
default:
|
1168
|
+
if (argc != 1) rb_raise(rb_eArgError,
|
1169
|
+
"wrong number of arguments (%d for 1)", argc);
|
1170
|
+
vtmp = obj;
|
1171
|
+
itmp = 0;
|
1172
|
+
break;
|
1173
|
+
}
|
1174
|
+
CHECK_MATRIX(vtmp);
|
1175
|
+
if (CLASS_OF(vtmp) != klass) {
|
1176
|
+
rb_raise(rb_eTypeError, "not a QR matrix");
|
1177
|
+
}
|
1178
|
+
Data_Get_Struct(vtmp, gsl_matrix, QR);
|
1179
|
+
if (CLASS_OF(argv[itmp]) != cgsl_vector_tau)
|
1180
|
+
rb_raise(rb_eTypeError, "tau vector must be given.");
|
1181
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
1182
|
+
Q = gsl_matrix_alloc(QR->size1, QR->size1);
|
1183
|
+
R = gsl_matrix_alloc(QR->size1, QR->size2);
|
1184
|
+
switch (flag) {
|
1185
|
+
case LINALG_QR_UNPACK:
|
1186
|
+
gsl_linalg_QR_unpack(QR, tau, Q, R);
|
1187
|
+
vQ = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, Q);
|
1188
|
+
vR = Data_Wrap_Struct(cgsl_matrix_R, 0, gsl_matrix_free, R);
|
1189
|
+
break;
|
1190
|
+
#ifdef GSL_1_6_LATER
|
1191
|
+
case LINALG_LQ_UNPACK:
|
1192
|
+
gsl_linalg_LQ_unpack(QR, tau, Q, R);
|
1193
|
+
vQ = Data_Wrap_Struct(cgsl_matrix_L, 0, gsl_matrix_free, Q);
|
1194
|
+
vR = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, R);
|
1195
|
+
break;
|
1196
|
+
#endif
|
1197
|
+
default:
|
1198
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1199
|
+
break;
|
1200
|
+
}
|
1201
|
+
return rb_ary_new3(2, vQ, vR);
|
1202
|
+
}
|
1203
|
+
|
1204
|
+
#ifdef HAVE_NARRAY_H
|
1205
|
+
static VALUE rb_gsl_linalg_QR_unpack_narray(int argc, VALUE *argv, VALUE obj);
|
1206
|
+
#endif
|
1207
|
+
|
1208
|
+
static VALUE rb_gsl_linalg_QR_unpack(int argc, VALUE *argv, VALUE obj)
|
1209
|
+
{
|
1210
|
+
#ifdef HAVE_NARRAY_H
|
1211
|
+
if (argc == 2 && NA_IsNArray(argv[0]))
|
1212
|
+
return rb_gsl_linalg_QR_unpack_narray(argc, argv, obj);
|
1213
|
+
#endif
|
1214
|
+
return rb_gsl_linalg_QRLQ_unpack(argc, argv, obj, LINALG_QR_UNPACK);
|
1215
|
+
}
|
1216
|
+
|
1217
|
+
#ifdef GSL_1_6_LATER
|
1218
|
+
static VALUE rb_gsl_linalg_LQ_unpack(int argc, VALUE *argv, VALUE obj)
|
1219
|
+
{
|
1220
|
+
return rb_gsl_linalg_QRLQ_unpack(argc, argv, obj, LINALG_LQ_UNPACK);
|
1221
|
+
}
|
1222
|
+
#endif
|
1223
|
+
|
1224
|
+
/* singleton */
|
1225
|
+
static VALUE rb_gsl_linalg_QRLQ_QRLQsolve(int argc, VALUE *argv, VALUE obj,
|
1226
|
+
int flag)
|
1227
|
+
{
|
1228
|
+
gsl_matrix *Q = NULL, *R = NULL;
|
1229
|
+
gsl_vector *b = NULL, *x = NULL;
|
1230
|
+
int (*fsolve)(gsl_matrix*, gsl_matrix *, const gsl_vector*, gsl_vector *);
|
1231
|
+
int flagb = 0;
|
1232
|
+
VALUE retval;
|
1233
|
+
switch (argc) {
|
1234
|
+
case 3:
|
1235
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1236
|
+
Data_Get_Struct(argv[0], gsl_matrix, Q);
|
1237
|
+
Data_Get_Struct(argv[1], gsl_matrix, R);
|
1238
|
+
x = gsl_vector_alloc(Q->size1);
|
1239
|
+
retval = Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
1240
|
+
break;
|
1241
|
+
case 4:
|
1242
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1243
|
+
CHECK_VECTOR(argv[3]);
|
1244
|
+
Data_Get_Struct(argv[0], gsl_matrix, Q);
|
1245
|
+
Data_Get_Struct(argv[1], gsl_matrix, R);
|
1246
|
+
Data_Get_Struct(argv[3], gsl_vector, x);
|
1247
|
+
retval = argv[3];
|
1248
|
+
break;
|
1249
|
+
default:
|
1250
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
|
1251
|
+
break;
|
1252
|
+
}
|
1253
|
+
switch (flag) {
|
1254
|
+
case LINALG_QR_DECOMP:
|
1255
|
+
if (CLASS_OF(argv[0]) != cgsl_matrix_Q)
|
1256
|
+
rb_raise(rb_eTypeError, "not a Q matrix");
|
1257
|
+
if (CLASS_OF(argv[1]) != cgsl_matrix_R)
|
1258
|
+
rb_raise(rb_eTypeError, "not a R matrix");
|
1259
|
+
fsolve = &gsl_linalg_QR_QRsolve;
|
1260
|
+
break;
|
1261
|
+
#ifdef GSL_1_6_LATER
|
1262
|
+
case LINALG_LQ_DECOMP:
|
1263
|
+
/* if (CLASS_OF(argv[0]) != cgsl_matrix_L)
|
1264
|
+
rb_raise(rb_eTypeError, "not a L matrix");
|
1265
|
+
if (CLASS_OF(argv[1]) != cgsl_matrix_Q)
|
1266
|
+
rb_raise(rb_eTypeError, "not a Q matrix");*/
|
1267
|
+
fsolve = &gsl_linalg_LQ_LQsolve;
|
1268
|
+
break;
|
1269
|
+
#endif
|
1270
|
+
default:
|
1271
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1272
|
+
break;
|
1273
|
+
}
|
1274
|
+
if (TYPE(argv[2]) == T_ARRAY) {
|
1275
|
+
b = make_cvector_from_rarray(argv[2]);
|
1276
|
+
flagb = 1;
|
1277
|
+
} else {
|
1278
|
+
CHECK_VECTOR(argv[2]);
|
1279
|
+
Data_Get_Struct(argv[2], gsl_vector, b);
|
1280
|
+
}
|
1281
|
+
(*fsolve)(Q, R, b, x);
|
1282
|
+
if (flagb == 1) gsl_vector_free(b);
|
1283
|
+
return retval;
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
/*****/
|
1287
|
+
static VALUE rb_gsl_linalg_QRLQ_RLsolve(int argc, VALUE *argv, VALUE obj,
|
1288
|
+
int flag)
|
1289
|
+
{
|
1290
|
+
gsl_matrix *QR = NULL, *mtmp;
|
1291
|
+
gsl_vector *b = NULL, *x = NULL, *tau = NULL;
|
1292
|
+
size_t istart;
|
1293
|
+
int (*fsolve)(const gsl_matrix*, const gsl_vector*, gsl_vector *);
|
1294
|
+
int flagb = 0, flagq = 0;
|
1295
|
+
VALUE omatrix,retval;
|
1296
|
+
switch (TYPE(obj)) {
|
1297
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1298
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
|
1299
|
+
omatrix = argv[0];
|
1300
|
+
istart = 1;
|
1301
|
+
break;
|
1302
|
+
default:
|
1303
|
+
omatrix = obj;
|
1304
|
+
istart = 0;
|
1305
|
+
break;
|
1306
|
+
}
|
1307
|
+
CHECK_MATRIX(omatrix);
|
1308
|
+
Data_Get_Struct(omatrix, gsl_matrix, mtmp);
|
1309
|
+
switch (argc - istart) {
|
1310
|
+
case 1:
|
1311
|
+
x = gsl_vector_alloc(mtmp->size1);
|
1312
|
+
retval = Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
1313
|
+
break;
|
1314
|
+
case 2:
|
1315
|
+
Data_Get_Struct(argv[istart+1], gsl_vector, x);
|
1316
|
+
retval = argv[istart+1];
|
1317
|
+
break;
|
1318
|
+
default:
|
1319
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
|
1320
|
+
break;
|
1321
|
+
}
|
1322
|
+
QR = mtmp; flagq = 0;
|
1323
|
+
switch (flag) {
|
1324
|
+
case LINALG_QR_RSOLVE:
|
1325
|
+
if (CLASS_OF(omatrix) != cgsl_matrix_QR) {
|
1326
|
+
QR = make_matrix_clone(mtmp);
|
1327
|
+
tau = gsl_vector_alloc(QR->size1);
|
1328
|
+
gsl_linalg_QR_decomp(QR, tau);
|
1329
|
+
flagq = 1;
|
1330
|
+
}
|
1331
|
+
fsolve = &gsl_linalg_QR_Rsolve;
|
1332
|
+
break;
|
1333
|
+
case LINALG_R_SOLVE:
|
1334
|
+
if (CLASS_OF(omatrix) != cgsl_matrix_QR) {
|
1335
|
+
QR = make_matrix_clone(mtmp);
|
1336
|
+
tau = gsl_vector_alloc(QR->size1);
|
1337
|
+
gsl_linalg_QR_decomp(QR, tau);
|
1338
|
+
flagq = 1;
|
1339
|
+
}
|
1340
|
+
fsolve = &gsl_linalg_R_solve;
|
1341
|
+
break;
|
1342
|
+
#ifdef GSL_1_6_LATER
|
1343
|
+
case LINALG_LQ_LSOLVE:
|
1344
|
+
if (CLASS_OF(omatrix) != cgsl_matrix_LQ) {
|
1345
|
+
QR = make_matrix_clone(mtmp);
|
1346
|
+
tau = gsl_vector_alloc(QR->size1);
|
1347
|
+
gsl_linalg_LQ_decomp(QR, tau);
|
1348
|
+
flagq = 1;
|
1349
|
+
}
|
1350
|
+
fsolve = &gsl_linalg_LQ_Lsolve_T;
|
1351
|
+
break;
|
1352
|
+
case LINALG_L_SOLVE:
|
1353
|
+
if (CLASS_OF(omatrix) != cgsl_matrix_LQ) {
|
1354
|
+
QR = make_matrix_clone(mtmp);
|
1355
|
+
tau = gsl_vector_alloc(QR->size1);
|
1356
|
+
gsl_linalg_LQ_decomp(QR, tau);
|
1357
|
+
flagq = 1;
|
1358
|
+
}
|
1359
|
+
fsolve = &gsl_linalg_L_solve_T;
|
1360
|
+
break;
|
1361
|
+
#endif
|
1362
|
+
default:
|
1363
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1364
|
+
break;
|
1365
|
+
}
|
1366
|
+
if (TYPE(argv[istart]) == T_ARRAY) {
|
1367
|
+
b = make_cvector_from_rarray(argv[istart]);
|
1368
|
+
flagb = 1;
|
1369
|
+
} else {
|
1370
|
+
CHECK_VECTOR(argv[istart]);
|
1371
|
+
Data_Get_Struct(argv[istart], gsl_vector, b);
|
1372
|
+
}
|
1373
|
+
(*fsolve)(QR, b, x);
|
1374
|
+
if (flagb == 1) gsl_vector_free(b);
|
1375
|
+
if (flagq == 1) {
|
1376
|
+
gsl_matrix_free(QR);
|
1377
|
+
gsl_vector_free(tau);
|
1378
|
+
}
|
1379
|
+
return retval;
|
1380
|
+
}
|
1381
|
+
|
1382
|
+
static VALUE rb_gsl_linalg_QRLQ_RLsvx(int argc, VALUE *argv, VALUE obj,
|
1383
|
+
int flag)
|
1384
|
+
{
|
1385
|
+
gsl_matrix *QR = NULL, *mtmp;
|
1386
|
+
gsl_vector *x = NULL, *tau = NULL;
|
1387
|
+
size_t istart;
|
1388
|
+
int (*fsolve)(const gsl_matrix*, gsl_vector *);
|
1389
|
+
int flagq = 0;
|
1390
|
+
VALUE omatrix,retval;
|
1391
|
+
switch (TYPE(obj)) {
|
1392
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1393
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
|
1394
|
+
omatrix = argv[0];
|
1395
|
+
istart = 1;
|
1396
|
+
break;
|
1397
|
+
default:
|
1398
|
+
omatrix = obj;
|
1399
|
+
istart = 0;
|
1400
|
+
break;
|
1401
|
+
}
|
1402
|
+
CHECK_MATRIX(omatrix);
|
1403
|
+
Data_Get_Struct(omatrix, gsl_matrix, mtmp);
|
1404
|
+
switch (argc - istart) {
|
1405
|
+
case 0:
|
1406
|
+
x = gsl_vector_alloc(mtmp->size1);
|
1407
|
+
retval = Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
1408
|
+
break;
|
1409
|
+
case 1:
|
1410
|
+
Data_Get_Struct(argv[istart+1], gsl_vector, x);
|
1411
|
+
retval = argv[istart+1];
|
1412
|
+
break;
|
1413
|
+
default:
|
1414
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
|
1415
|
+
break;
|
1416
|
+
}
|
1417
|
+
QR = mtmp; flagq = 0;
|
1418
|
+
switch (flag) {
|
1419
|
+
case LINALG_QR_RSVX:
|
1420
|
+
if (CLASS_OF(omatrix) != cgsl_matrix_QR) {
|
1421
|
+
QR = make_matrix_clone(mtmp);
|
1422
|
+
tau = gsl_vector_alloc(QR->size1);
|
1423
|
+
gsl_linalg_QR_decomp(QR, tau);
|
1424
|
+
flagq = 1;
|
1425
|
+
}
|
1426
|
+
fsolve = &gsl_linalg_QR_Rsvx;
|
1427
|
+
break;
|
1428
|
+
/*
|
1429
|
+
case LINALG_R_SVX:
|
1430
|
+
if (CLASS_OF(omatrix) != cgsl_matrix_QR) {
|
1431
|
+
QR = make_matrix_clone(mtmp);
|
1432
|
+
tau = gsl_vector_alloc(QR->size1);
|
1433
|
+
gsl_linalg_QR_decomp(QR, tau);
|
1434
|
+
flagq = 1;
|
1435
|
+
}
|
1436
|
+
fsolve = &gsl_linalg_R_svx;
|
1437
|
+
break;
|
1438
|
+
*/
|
1439
|
+
#ifdef GSL_1_6_LATER
|
1440
|
+
case LINALG_LQ_LSVX:
|
1441
|
+
if (CLASS_OF(omatrix) != cgsl_matrix_LQ) {
|
1442
|
+
QR = make_matrix_clone(mtmp);
|
1443
|
+
tau = gsl_vector_alloc(QR->size1);
|
1444
|
+
gsl_linalg_LQ_decomp(QR, tau);
|
1445
|
+
flagq = 1;
|
1446
|
+
}
|
1447
|
+
fsolve = &gsl_linalg_LQ_Lsvx_T;
|
1448
|
+
break;
|
1449
|
+
#endif
|
1450
|
+
default:
|
1451
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1452
|
+
break;
|
1453
|
+
}
|
1454
|
+
(*fsolve)(QR, x);
|
1455
|
+
if (flagq == 1) {
|
1456
|
+
gsl_matrix_free(QR);
|
1457
|
+
gsl_vector_free(tau);
|
1458
|
+
}
|
1459
|
+
return retval;
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
static VALUE rb_gsl_linalg_QR_Rsolve(int argc, VALUE *argv, VALUE obj)
|
1463
|
+
{
|
1464
|
+
return rb_gsl_linalg_QRLQ_RLsolve(argc, argv, obj, LINALG_QR_RSOLVE);
|
1465
|
+
}
|
1466
|
+
|
1467
|
+
static VALUE rb_gsl_linalg_QR_Rsvx(int argc, VALUE *argv, VALUE obj)
|
1468
|
+
{
|
1469
|
+
return rb_gsl_linalg_QRLQ_RLsvx(argc, argv, obj, LINALG_QR_RSVX);
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
static VALUE rb_gsl_linalg_R_solve(int argc, VALUE *argv, VALUE obj)
|
1473
|
+
{
|
1474
|
+
return rb_gsl_linalg_QRLQ_RLsolve(argc, argv, obj, LINALG_R_SOLVE);
|
1475
|
+
}
|
1476
|
+
|
1477
|
+
/* singleton */
|
1478
|
+
static VALUE rb_gsl_linalg_QR_QRsolve(int argc, VALUE *argv, VALUE obj,
|
1479
|
+
int flag)
|
1480
|
+
{
|
1481
|
+
return rb_gsl_linalg_QRLQ_QRLQsolve(argc, argv, obj, LINALG_QR_DECOMP);
|
1482
|
+
}
|
1483
|
+
|
1484
|
+
#ifdef GSL_1_6_LATER
|
1485
|
+
static VALUE rb_gsl_linalg_LQ_Lsolve(int argc, VALUE *argv, VALUE obj)
|
1486
|
+
{
|
1487
|
+
return rb_gsl_linalg_QRLQ_RLsolve(argc, argv, obj, LINALG_LQ_LSOLVE);
|
1488
|
+
}
|
1489
|
+
|
1490
|
+
static VALUE rb_gsl_linalg_LQ_Lsvx(int argc, VALUE *argv, VALUE obj)
|
1491
|
+
{
|
1492
|
+
return rb_gsl_linalg_QRLQ_RLsvx(argc, argv, obj, LINALG_LQ_LSVX);
|
1493
|
+
}
|
1494
|
+
|
1495
|
+
static VALUE rb_gsl_linalg_L_solve(int argc, VALUE *argv, VALUE obj)
|
1496
|
+
{
|
1497
|
+
return rb_gsl_linalg_QRLQ_RLsolve(argc, argv, obj, LINALG_L_SOLVE);
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
/* singleton */
|
1501
|
+
static VALUE rb_gsl_linalg_LQ_LQsolve(int argc, VALUE *argv, VALUE obj,
|
1502
|
+
int flag)
|
1503
|
+
{
|
1504
|
+
return rb_gsl_linalg_QRLQ_QRLQsolve(argc, argv, obj, LINALG_LQ_DECOMP);
|
1505
|
+
}
|
1506
|
+
#endif
|
1507
|
+
|
1508
|
+
static VALUE rb_gsl_linalg_QRLQ_update(VALUE obj, VALUE qq, VALUE rr, VALUE ww,
|
1509
|
+
VALUE vv, int flag)
|
1510
|
+
{
|
1511
|
+
gsl_matrix *Q = NULL, *R = NULL;
|
1512
|
+
gsl_vector *w = NULL, *v = NULL;
|
1513
|
+
int status;
|
1514
|
+
CHECK_MATRIX(qq); CHECK_MATRIX(rr);
|
1515
|
+
CHECK_VECTOR(ww); CHECK_VECTOR(vv);
|
1516
|
+
Data_Get_Struct(qq, gsl_matrix, Q);
|
1517
|
+
Data_Get_Struct(rr, gsl_matrix, R);
|
1518
|
+
Data_Get_Struct(ww, gsl_vector, w);
|
1519
|
+
Data_Get_Struct(vv, gsl_vector, v);
|
1520
|
+
switch (flag) {
|
1521
|
+
case LINALG_QR_DECOMP:
|
1522
|
+
status = gsl_linalg_QR_update(Q, R, w, v);
|
1523
|
+
break;
|
1524
|
+
#ifdef GSL_1_6_LATER
|
1525
|
+
case LINALG_LQ_DECOMP:
|
1526
|
+
status = gsl_linalg_LQ_update(Q, R, w, v);
|
1527
|
+
break;
|
1528
|
+
#endif
|
1529
|
+
default:
|
1530
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1531
|
+
break;
|
1532
|
+
}
|
1533
|
+
return INT2FIX(status);
|
1534
|
+
}
|
1535
|
+
|
1536
|
+
/* singleton */
|
1537
|
+
static VALUE rb_gsl_linalg_QR_update(VALUE obj, VALUE qq, VALUE rr, VALUE ww,
|
1538
|
+
VALUE vv)
|
1539
|
+
{
|
1540
|
+
return rb_gsl_linalg_QRLQ_update(obj, qq, rr, ww, vv, LINALG_QR_DECOMP);
|
1541
|
+
}
|
1542
|
+
|
1543
|
+
#ifdef GSL_1_6_LATER
|
1544
|
+
static VALUE rb_gsl_linalg_LQ_update(VALUE obj, VALUE qq, VALUE rr, VALUE ww,
|
1545
|
+
VALUE vv)
|
1546
|
+
{
|
1547
|
+
return rb_gsl_linalg_QRLQ_update(obj, qq, rr, ww, vv, LINALG_LQ_DECOMP);
|
1548
|
+
}
|
1549
|
+
#endif
|
1550
|
+
|
1551
|
+
/******/
|
1552
|
+
enum {
|
1553
|
+
LINALG_QRPT,
|
1554
|
+
LINALG_PTLQ,
|
1555
|
+
};
|
1556
|
+
|
1557
|
+
static VALUE rb_gsl_linalg_QRLQPT_decomp(int argc, VALUE *argv, VALUE obj, int flag)
|
1558
|
+
{
|
1559
|
+
gsl_matrix *A = NULL, *QR = NULL;
|
1560
|
+
gsl_vector *tau = NULL, *norm = NULL;
|
1561
|
+
gsl_permutation *p = NULL;
|
1562
|
+
int signum;
|
1563
|
+
size_t size0;
|
1564
|
+
VALUE vtau, vp, vA, vQR;
|
1565
|
+
switch (TYPE(obj)) {
|
1566
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1567
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
1568
|
+
argc);
|
1569
|
+
vA = argv[0];
|
1570
|
+
break;
|
1571
|
+
default:
|
1572
|
+
vA = obj;
|
1573
|
+
break;
|
1574
|
+
}
|
1575
|
+
CHECK_MATRIX(vA);
|
1576
|
+
Data_Get_Struct(vA, gsl_matrix, A);
|
1577
|
+
QR = make_matrix_clone(A);
|
1578
|
+
size0 = GSL_MIN(A->size1, A->size2);
|
1579
|
+
tau = gsl_vector_alloc(size0);
|
1580
|
+
p = gsl_permutation_alloc(size0);
|
1581
|
+
norm = gsl_vector_alloc(size0);
|
1582
|
+
switch (flag) {
|
1583
|
+
case LINALG_QRPT:
|
1584
|
+
vQR = Data_Wrap_Struct(cgsl_matrix_QRPT, 0, gsl_matrix_free, QR);
|
1585
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
1586
|
+
vp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
|
1587
|
+
gsl_linalg_QRPT_decomp(QR, tau, p, &signum, norm);
|
1588
|
+
break;
|
1589
|
+
#ifdef GSL_1_6_LATER
|
1590
|
+
case LINALG_PTLQ:
|
1591
|
+
vQR = Data_Wrap_Struct(cgsl_matrix_PTLQ, 0, gsl_matrix_free, QR);
|
1592
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
1593
|
+
vp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
|
1594
|
+
gsl_linalg_PTLQ_decomp(QR, tau, p, &signum, norm);
|
1595
|
+
break;
|
1596
|
+
#endif
|
1597
|
+
default:
|
1598
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1599
|
+
break;
|
1600
|
+
}
|
1601
|
+
gsl_vector_free(norm);
|
1602
|
+
return rb_ary_new3(4, vQR, vtau, vp, INT2FIX(signum));
|
1603
|
+
}
|
1604
|
+
|
1605
|
+
static VALUE rb_gsl_linalg_QRLQPT_decomp_bang(int argc, VALUE *argv, VALUE obj, int flag)
|
1606
|
+
{
|
1607
|
+
gsl_matrix *A = NULL;
|
1608
|
+
gsl_vector *tau = NULL, *norm = NULL;
|
1609
|
+
gsl_permutation *p = NULL;
|
1610
|
+
int signum;
|
1611
|
+
size_t size0;
|
1612
|
+
VALUE vtau, vp, vA;
|
1613
|
+
switch (TYPE(obj)) {
|
1614
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1615
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
1616
|
+
argc);
|
1617
|
+
vA = argv[0];
|
1618
|
+
break;
|
1619
|
+
default:
|
1620
|
+
vA = obj;
|
1621
|
+
break;
|
1622
|
+
}
|
1623
|
+
CHECK_MATRIX(vA);
|
1624
|
+
Data_Get_Struct(vA, gsl_matrix, A);
|
1625
|
+
size0 = GSL_MIN(A->size1, A->size2);
|
1626
|
+
tau = gsl_vector_alloc(size0);
|
1627
|
+
p = gsl_permutation_alloc(size0);
|
1628
|
+
norm = gsl_vector_alloc(size0);
|
1629
|
+
switch (flag) {
|
1630
|
+
case LINALG_QRPT:
|
1631
|
+
RBASIC(vA)->klass = cgsl_matrix_QRPT;
|
1632
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
1633
|
+
vp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
|
1634
|
+
gsl_linalg_QRPT_decomp(A, tau, p, &signum, norm);
|
1635
|
+
break;
|
1636
|
+
#ifdef GSL_1_6_LATER
|
1637
|
+
case LINALG_PTLQ:
|
1638
|
+
RBASIC(vA)->klass = cgsl_matrix_PTLQ;
|
1639
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
1640
|
+
vp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
|
1641
|
+
gsl_linalg_PTLQ_decomp(A, tau, p, &signum, norm);
|
1642
|
+
break;
|
1643
|
+
#endif
|
1644
|
+
default:
|
1645
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1646
|
+
break;
|
1647
|
+
}
|
1648
|
+
gsl_vector_free(norm);
|
1649
|
+
return rb_ary_new3(3, vtau, vp, INT2FIX(signum));
|
1650
|
+
}
|
1651
|
+
|
1652
|
+
static VALUE rb_gsl_linalg_QRPT_decomp(int argc, VALUE *argv, VALUE obj)
|
1653
|
+
{
|
1654
|
+
return rb_gsl_linalg_QRLQPT_decomp(argc, argv, obj, LINALG_QRPT);
|
1655
|
+
}
|
1656
|
+
|
1657
|
+
static VALUE rb_gsl_linalg_QRPT_decomp_bang(int argc, VALUE *argv, VALUE obj)
|
1658
|
+
{
|
1659
|
+
return rb_gsl_linalg_QRLQPT_decomp_bang(argc, argv, obj, LINALG_QRPT);
|
1660
|
+
}
|
1661
|
+
|
1662
|
+
#ifdef GSL_1_6_LATER
|
1663
|
+
static VALUE rb_gsl_linalg_PTLQ_decomp(int argc, VALUE *argv, VALUE obj)
|
1664
|
+
{
|
1665
|
+
return rb_gsl_linalg_QRLQPT_decomp(argc, argv, obj, LINALG_PTLQ);
|
1666
|
+
}
|
1667
|
+
|
1668
|
+
static VALUE rb_gsl_linalg_PTLQ_decomp_bang(int argc, VALUE *argv, VALUE obj)
|
1669
|
+
{
|
1670
|
+
return rb_gsl_linalg_QRLQPT_decomp_bang(argc, argv, obj, LINALG_PTLQ);
|
1671
|
+
}
|
1672
|
+
#endif
|
1673
|
+
|
1674
|
+
static VALUE rb_gsl_linalg_QRLQPT_decomp2(int argc, VALUE *argv, VALUE obj,int flag)
|
1675
|
+
{
|
1676
|
+
gsl_matrix *A = NULL, *Q = NULL, *R = NULL;
|
1677
|
+
gsl_vector *tau = NULL, *norm = NULL;
|
1678
|
+
gsl_permutation *p = NULL;
|
1679
|
+
int signum;
|
1680
|
+
size_t size0;
|
1681
|
+
VALUE vtau, vp, vA, vQ, vR;
|
1682
|
+
switch (TYPE(obj)) {
|
1683
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1684
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments");
|
1685
|
+
vA = argv[0];
|
1686
|
+
break;
|
1687
|
+
default:
|
1688
|
+
if (argc != 0) rb_raise(rb_eArgError, "wrong number of arguments");
|
1689
|
+
vA = obj;
|
1690
|
+
break;
|
1691
|
+
}
|
1692
|
+
CHECK_MATRIX(vA);
|
1693
|
+
Data_Get_Struct(vA, gsl_matrix, A);
|
1694
|
+
Q = gsl_matrix_alloc(A->size1, A->size2);
|
1695
|
+
R = gsl_matrix_alloc(A->size1, A->size2);
|
1696
|
+
size0 = GSL_MIN(A->size1, A->size2);
|
1697
|
+
tau = gsl_vector_alloc(size0);
|
1698
|
+
p = gsl_permutation_alloc(size0);
|
1699
|
+
norm = gsl_vector_alloc(size0);
|
1700
|
+
/* vQ = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, Q);
|
1701
|
+
vR = Data_Wrap_Struct(cgsl_matrix_R, 0, gsl_matrix_free, R);*/
|
1702
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
1703
|
+
vp = Data_Wrap_Struct(cgsl_permutation, 0, gsl_permutation_free, p);
|
1704
|
+
switch (flag) {
|
1705
|
+
case LINALG_QRPT:
|
1706
|
+
vQ = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, Q);
|
1707
|
+
vR = Data_Wrap_Struct(cgsl_matrix_R, 0, gsl_matrix_free, R);
|
1708
|
+
gsl_linalg_QRPT_decomp2(A, Q, R, tau, p, &signum, norm);
|
1709
|
+
break;
|
1710
|
+
#ifdef GSL_1_6_LATER
|
1711
|
+
case LINALG_PTLQ:
|
1712
|
+
vR = Data_Wrap_Struct(cgsl_matrix_L, 0, gsl_matrix_free, R);
|
1713
|
+
vQ = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, Q);
|
1714
|
+
gsl_linalg_PTLQ_decomp2(A, Q, R, tau, p, &signum, norm);
|
1715
|
+
break;
|
1716
|
+
#endif
|
1717
|
+
default:
|
1718
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1719
|
+
}
|
1720
|
+
gsl_vector_free(norm);
|
1721
|
+
return rb_ary_new3(5, vQ, vR, vtau, vp, INT2FIX(signum));
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
static VALUE rb_gsl_linalg_QRPT_decomp2(int argc, VALUE *argv, VALUE obj)
|
1725
|
+
{
|
1726
|
+
return rb_gsl_linalg_QRLQPT_decomp2(argc, argv, obj, LINALG_QRPT);
|
1727
|
+
}
|
1728
|
+
|
1729
|
+
#ifdef GSL_1_6_LATER
|
1730
|
+
static VALUE rb_gsl_linalg_PTLQ_decomp2(int argc, VALUE *argv, VALUE obj)
|
1731
|
+
{
|
1732
|
+
return rb_gsl_linalg_QRLQPT_decomp2(argc, argv, obj, LINALG_PTLQ);
|
1733
|
+
}
|
1734
|
+
#endif
|
1735
|
+
|
1736
|
+
#ifdef GSL_1_6_LATER
|
1737
|
+
int gsl_linalg_PTLQ_solve_T(const gsl_matrix * QR, const gsl_vector * tau,
|
1738
|
+
const gsl_permutation * p, const gsl_vector * b,
|
1739
|
+
gsl_vector * x);
|
1740
|
+
int gsl_linalg_PTLQ_svx_T(const gsl_matrix * LQ,
|
1741
|
+
const gsl_vector * tau,
|
1742
|
+
const gsl_permutation * p,
|
1743
|
+
gsl_vector * x);
|
1744
|
+
int gsl_linalg_PTLQ_LQsolve_T (const gsl_matrix * Q, const gsl_matrix * L,
|
1745
|
+
const gsl_permutation * p,
|
1746
|
+
const gsl_vector * b,
|
1747
|
+
gsl_vector * x);
|
1748
|
+
int gsl_linalg_PTLQ_Lsolve_T (const gsl_matrix * LQ,
|
1749
|
+
const gsl_permutation * p,
|
1750
|
+
const gsl_vector * b,
|
1751
|
+
gsl_vector * x);
|
1752
|
+
int gsl_linalg_PTLQ_Lsvx_T (const gsl_matrix * LQ,
|
1753
|
+
const gsl_permutation * p,
|
1754
|
+
gsl_vector * x);
|
1755
|
+
#endif
|
1756
|
+
|
1757
|
+
static VALUE rb_gsl_linalg_QRLQPT_solve(int argc, VALUE *argv, VALUE obj, int flag)
|
1758
|
+
{
|
1759
|
+
gsl_matrix *QR = NULL, *A = NULL;
|
1760
|
+
gsl_vector *tau = NULL, *b = NULL, *x = NULL, *norm = NULL;
|
1761
|
+
gsl_permutation *p = NULL;
|
1762
|
+
int signum, itmp, flagb = 0, flagq = 0;
|
1763
|
+
VALUE vtmp, klass;
|
1764
|
+
size_t size0;
|
1765
|
+
int (*fdecomp)(gsl_matrix*, gsl_vector*, gsl_permutation*, int *, gsl_vector*);
|
1766
|
+
int (*fsolve)(const gsl_matrix*, const gsl_vector*, const gsl_permutation*,
|
1767
|
+
const gsl_vector*, gsl_vector *);
|
1768
|
+
switch (flag) {
|
1769
|
+
case LINALG_QRPT:
|
1770
|
+
klass = cgsl_matrix_QRPT;
|
1771
|
+
fdecomp = &gsl_linalg_QRPT_decomp;
|
1772
|
+
fsolve = &gsl_linalg_QRPT_solve;
|
1773
|
+
break;
|
1774
|
+
#ifdef GSL_1_6_LATER
|
1775
|
+
case LINALG_PTLQ:
|
1776
|
+
klass = cgsl_matrix_PTLQ;
|
1777
|
+
fdecomp = &gsl_linalg_PTLQ_decomp;
|
1778
|
+
fsolve = &gsl_linalg_PTLQ_solve_T;
|
1779
|
+
break;
|
1780
|
+
#endif
|
1781
|
+
default:
|
1782
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1783
|
+
break;
|
1784
|
+
}
|
1785
|
+
switch (TYPE(obj)) {
|
1786
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1787
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
1788
|
+
vtmp = argv[0];
|
1789
|
+
itmp = 1;
|
1790
|
+
break;
|
1791
|
+
default:
|
1792
|
+
vtmp = obj;
|
1793
|
+
itmp = 0;
|
1794
|
+
break;
|
1795
|
+
}
|
1796
|
+
CHECK_MATRIX(vtmp);
|
1797
|
+
if (CLASS_OF(vtmp) == klass) {
|
1798
|
+
if (argc-itmp != 3) rb_raise(rb_eArgError,
|
1799
|
+
"wrong number of arguments (%d for %d)",
|
1800
|
+
argc, 4-itmp);
|
1801
|
+
CHECK_VECTOR(argv[itmp]);
|
1802
|
+
if (CLASS_OF(argv[itmp]) != cgsl_vector_tau)
|
1803
|
+
rb_raise(rb_eTypeError, "not a tau vector");
|
1804
|
+
CHECK_PERMUTATION(argv[itmp+1]);
|
1805
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
1806
|
+
Data_Get_Struct(argv[itmp+1], gsl_permutation, p);
|
1807
|
+
Data_Get_Struct(vtmp, gsl_matrix, QR);
|
1808
|
+
size0 = GSL_MIN(QR->size1, QR->size2);
|
1809
|
+
itmp += 2;
|
1810
|
+
} else {
|
1811
|
+
if (argc-itmp != 1) rb_raise(rb_eArgError,
|
1812
|
+
"wrong number of arguments (%d for %d)", argc, 2-itmp);
|
1813
|
+
Data_Get_Struct(vtmp, gsl_matrix, A);
|
1814
|
+
QR = make_matrix_clone(A);
|
1815
|
+
size0 = GSL_MIN(QR->size1, QR->size2);
|
1816
|
+
flagq = 1;
|
1817
|
+
p = gsl_permutation_alloc(size0);
|
1818
|
+
tau = gsl_vector_alloc(size0);
|
1819
|
+
}
|
1820
|
+
norm = gsl_vector_alloc(size0);
|
1821
|
+
if (TYPE(argv[itmp]) == T_ARRAY) {
|
1822
|
+
b = make_cvector_from_rarray(argv[itmp]);
|
1823
|
+
flagb = 1;
|
1824
|
+
} else {
|
1825
|
+
CHECK_VECTOR(argv[itmp]);
|
1826
|
+
Data_Get_Struct(argv[itmp], gsl_vector, b);
|
1827
|
+
}
|
1828
|
+
x = gsl_vector_alloc(b->size);
|
1829
|
+
if (flagq == 1) (*fdecomp)(QR, tau, p, &signum, norm);
|
1830
|
+
(*fsolve)(QR, tau, p, b, x);
|
1831
|
+
if (flagb == 1) gsl_vector_free(b);
|
1832
|
+
if (flagq == 1) {
|
1833
|
+
gsl_matrix_free(QR);
|
1834
|
+
gsl_permutation_free(p);
|
1835
|
+
gsl_vector_free(tau);
|
1836
|
+
gsl_vector_free(norm);
|
1837
|
+
}
|
1838
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
1839
|
+
}
|
1840
|
+
|
1841
|
+
static VALUE rb_gsl_linalg_QRPT_solve(int argc, VALUE *argv, VALUE obj)
|
1842
|
+
{
|
1843
|
+
return rb_gsl_linalg_QRLQPT_solve(argc, argv, obj, LINALG_QRPT);
|
1844
|
+
}
|
1845
|
+
|
1846
|
+
#ifdef GSL_1_6_LATER
|
1847
|
+
static VALUE rb_gsl_linalg_PTLQ_solve(int argc, VALUE *argv, VALUE obj)
|
1848
|
+
{
|
1849
|
+
return rb_gsl_linalg_QRLQPT_solve(argc, argv, obj, LINALG_PTLQ);
|
1850
|
+
}
|
1851
|
+
#endif
|
1852
|
+
|
1853
|
+
static VALUE rb_gsl_linalg_QRLQPT_svx(int argc, VALUE *argv, VALUE obj, int flag)
|
1854
|
+
{
|
1855
|
+
gsl_matrix *QR = NULL, *A = NULL;
|
1856
|
+
gsl_vector *tau = NULL, *b = NULL, *norm = NULL;
|
1857
|
+
gsl_permutation *p = NULL;
|
1858
|
+
int signum, itmp, flagq = 0;
|
1859
|
+
VALUE vtmp, klass;
|
1860
|
+
size_t size0;
|
1861
|
+
int (*fdecomp)(gsl_matrix*, gsl_vector*, gsl_permutation*, int *, gsl_vector*);
|
1862
|
+
int (*fsvx)(const gsl_matrix*, const gsl_vector*, const gsl_permutation*,
|
1863
|
+
gsl_vector *);
|
1864
|
+
switch (flag) {
|
1865
|
+
case LINALG_QRPT:
|
1866
|
+
klass = cgsl_matrix_QRPT;
|
1867
|
+
fdecomp = &gsl_linalg_QRPT_decomp;
|
1868
|
+
fsvx = &gsl_linalg_QRPT_svx;
|
1869
|
+
break;
|
1870
|
+
#ifdef GSL_1_6_LATER
|
1871
|
+
case LINALG_PTLQ:
|
1872
|
+
klass = cgsl_matrix_PTLQ;
|
1873
|
+
fdecomp = &gsl_linalg_PTLQ_decomp;
|
1874
|
+
fsvx = &gsl_linalg_PTLQ_svx_T;
|
1875
|
+
break;
|
1876
|
+
#endif
|
1877
|
+
default:
|
1878
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1879
|
+
break;
|
1880
|
+
}
|
1881
|
+
|
1882
|
+
switch (TYPE(obj)) {
|
1883
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
1884
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
1885
|
+
argc);
|
1886
|
+
vtmp = argv[0];
|
1887
|
+
itmp = 1;
|
1888
|
+
break;
|
1889
|
+
default:
|
1890
|
+
vtmp = obj;
|
1891
|
+
itmp = 0;
|
1892
|
+
break;
|
1893
|
+
}
|
1894
|
+
CHECK_MATRIX(vtmp);
|
1895
|
+
if (CLASS_OF(vtmp) == klass) {
|
1896
|
+
if (argc-itmp != 3) rb_raise(rb_eArgError,
|
1897
|
+
"wrong number of arguments (%d for %d)",
|
1898
|
+
argc, 3+itmp);
|
1899
|
+
CHECK_VECTOR(argv[itmp]);
|
1900
|
+
if (CLASS_OF(argv[itmp]) != cgsl_vector_tau)
|
1901
|
+
rb_raise(rb_eTypeError, "not a tau vector");
|
1902
|
+
CHECK_PERMUTATION(argv[itmp+1]);
|
1903
|
+
Data_Get_Struct(argv[itmp], gsl_vector, tau);
|
1904
|
+
Data_Get_Struct(argv[itmp+1], gsl_permutation, p);
|
1905
|
+
Data_Get_Struct(vtmp, gsl_matrix, QR);
|
1906
|
+
size0 = GSL_MIN(QR->size1, QR->size2);
|
1907
|
+
itmp += 2;
|
1908
|
+
} else {
|
1909
|
+
if (argc-itmp != 1) rb_raise(rb_eArgError,
|
1910
|
+
"wrong number of arguments (%d for %d)", argc, 2+itmp);
|
1911
|
+
Data_Get_Struct(vtmp, gsl_matrix, A);
|
1912
|
+
QR = make_matrix_clone(A);
|
1913
|
+
size0 = GSL_MIN(QR->size1, QR->size2);
|
1914
|
+
flagq = 1;
|
1915
|
+
p = gsl_permutation_alloc(size0);
|
1916
|
+
tau = gsl_vector_alloc(size0);
|
1917
|
+
}
|
1918
|
+
norm = gsl_vector_alloc(size0);
|
1919
|
+
CHECK_VECTOR(argv[itmp]);
|
1920
|
+
Data_Get_Struct(argv[itmp], gsl_vector, b);
|
1921
|
+
if (flagq == 1) (*fdecomp)(QR, tau, p, &signum, norm);
|
1922
|
+
(*fsvx)(QR, tau, p, b);
|
1923
|
+
if (flagq == 1) {
|
1924
|
+
gsl_matrix_free(QR);
|
1925
|
+
gsl_permutation_free(p);
|
1926
|
+
gsl_vector_free(tau);
|
1927
|
+
gsl_vector_free(norm);
|
1928
|
+
}
|
1929
|
+
return argv[itmp];
|
1930
|
+
}
|
1931
|
+
|
1932
|
+
static VALUE rb_gsl_linalg_QRPT_svx(int argc, VALUE *argv, VALUE obj)
|
1933
|
+
{
|
1934
|
+
return rb_gsl_linalg_QRLQPT_svx(argc, argv, obj, LINALG_QRPT);
|
1935
|
+
}
|
1936
|
+
|
1937
|
+
#ifdef GSL_1_6_LATER
|
1938
|
+
static VALUE rb_gsl_linalg_PTLQ_svx(int argc, VALUE *argv, VALUE obj)
|
1939
|
+
{
|
1940
|
+
return rb_gsl_linalg_QRLQPT_svx(argc, argv, obj, LINALG_PTLQ);
|
1941
|
+
}
|
1942
|
+
#endif
|
1943
|
+
|
1944
|
+
/* singleton */
|
1945
|
+
static VALUE rb_gsl_linalg_QRLQPT_QRLQsolve(VALUE obj, VALUE qq, VALUE rr,
|
1946
|
+
VALUE pp, VALUE bb, int flag)
|
1947
|
+
{
|
1948
|
+
gsl_matrix *Q = NULL, *R = NULL;
|
1949
|
+
gsl_vector *b = NULL, *x = NULL;
|
1950
|
+
gsl_permutation *p = NULL;
|
1951
|
+
int flagb = 0;
|
1952
|
+
int (*fsolve)(const gsl_matrix*, const gsl_matrix*, const gsl_permutation*,
|
1953
|
+
const gsl_vector*, gsl_vector*);
|
1954
|
+
switch (flag) {
|
1955
|
+
case LINALG_QRPT:
|
1956
|
+
if (CLASS_OF(qq) != cgsl_matrix_Q) rb_raise(rb_eTypeError, "not a Q matrix");
|
1957
|
+
if (CLASS_OF(rr) != cgsl_matrix_R) rb_raise(rb_eTypeError, "not a R matrix");
|
1958
|
+
fsolve = &gsl_linalg_QRPT_QRsolve;
|
1959
|
+
break;
|
1960
|
+
#ifdef GSL_1_6_LATER
|
1961
|
+
case LINALG_PTLQ:
|
1962
|
+
if (CLASS_OF(qq) != cgsl_matrix_Q) rb_raise(rb_eTypeError, "not a Q matrix");
|
1963
|
+
if (CLASS_OF(rr) != cgsl_matrix_L) rb_raise(rb_eTypeError, "not a L matrix");
|
1964
|
+
fsolve = &gsl_linalg_PTLQ_LQsolve_T;
|
1965
|
+
break;
|
1966
|
+
#endif
|
1967
|
+
default:
|
1968
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
1969
|
+
break;
|
1970
|
+
}
|
1971
|
+
if (TYPE(bb) == T_ARRAY) {
|
1972
|
+
b = make_cvector_from_rarray(bb);
|
1973
|
+
flagb = 1;
|
1974
|
+
} else {
|
1975
|
+
CHECK_VECTOR(bb);
|
1976
|
+
Data_Get_Struct(bb, gsl_vector, b);
|
1977
|
+
}
|
1978
|
+
CHECK_PERMUTATION(pp);
|
1979
|
+
Data_Get_Struct(qq, gsl_matrix, Q);
|
1980
|
+
Data_Get_Struct(rr, gsl_matrix, R);
|
1981
|
+
Data_Get_Struct(pp, gsl_permutation, p);
|
1982
|
+
x = gsl_vector_alloc(b->size);
|
1983
|
+
(*fsolve)(Q, R, p, b, x);
|
1984
|
+
if (flagb == 1) gsl_vector_free(b);
|
1985
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
1986
|
+
}
|
1987
|
+
|
1988
|
+
static VALUE rb_gsl_linalg_QRPT_QRsolve(VALUE obj, VALUE qq, VALUE rr,
|
1989
|
+
VALUE pp, VALUE bb)
|
1990
|
+
{
|
1991
|
+
return rb_gsl_linalg_QRLQPT_QRLQsolve(obj, qq, rr, pp, bb, LINALG_QRPT);
|
1992
|
+
}
|
1993
|
+
|
1994
|
+
#ifdef GSL_1_6_LATER
|
1995
|
+
static VALUE rb_gsl_linalg_PTLQ_LQsolve(VALUE obj, VALUE qq, VALUE rr,
|
1996
|
+
VALUE pp, VALUE bb)
|
1997
|
+
{
|
1998
|
+
return rb_gsl_linalg_QRLQPT_QRLQsolve(obj, qq, rr, pp, bb, LINALG_PTLQ);
|
1999
|
+
}
|
2000
|
+
#endif
|
2001
|
+
|
2002
|
+
/* singleton */
|
2003
|
+
static VALUE rb_gsl_linalg_QRLQPT_update(VALUE obj, VALUE qq, VALUE rr,
|
2004
|
+
VALUE pp, VALUE ww, VALUE vv, int flag)
|
2005
|
+
{
|
2006
|
+
gsl_matrix *Q = NULL, *R = NULL;
|
2007
|
+
gsl_vector *w = NULL, *v = NULL;
|
2008
|
+
gsl_permutation *p = NULL;
|
2009
|
+
switch (flag) {
|
2010
|
+
case LINALG_QRPT:
|
2011
|
+
if (CLASS_OF(qq) != cgsl_matrix_Q) rb_raise(rb_eTypeError, "not a Q matrix");
|
2012
|
+
if (CLASS_OF(rr) != cgsl_matrix_R) rb_raise(rb_eTypeError, "not a R matrix");
|
2013
|
+
break;
|
2014
|
+
#ifdef GSL_1_6_LATER
|
2015
|
+
case LINALG_PTLQ:
|
2016
|
+
if (CLASS_OF(qq) != cgsl_matrix_Q) rb_raise(rb_eTypeError, "not a Q matrix");
|
2017
|
+
if (CLASS_OF(rr) != cgsl_matrix_L) rb_raise(rb_eTypeError, "not a L matrix");
|
2018
|
+
break;
|
2019
|
+
#endif
|
2020
|
+
}
|
2021
|
+
CHECK_PERMUTATION(pp);
|
2022
|
+
Data_Get_Struct(qq, gsl_matrix, Q);
|
2023
|
+
Data_Get_Struct(rr, gsl_matrix, R);
|
2024
|
+
Data_Get_Struct(pp, gsl_permutation, p);
|
2025
|
+
Data_Get_Struct(ww, gsl_vector, w);
|
2026
|
+
Data_Get_Struct(vv, gsl_vector, v);
|
2027
|
+
switch (flag) {
|
2028
|
+
case LINALG_QRPT:
|
2029
|
+
gsl_linalg_QRPT_update(Q, R, p, w, v);
|
2030
|
+
break;
|
2031
|
+
#ifdef GSL_1_6_LATER
|
2032
|
+
case LINALG_PTLQ:
|
2033
|
+
gsl_linalg_PTLQ_update(Q, R, p, w, v);
|
2034
|
+
break;
|
2035
|
+
#endif
|
2036
|
+
}
|
2037
|
+
return obj;
|
2038
|
+
}
|
2039
|
+
|
2040
|
+
static VALUE rb_gsl_linalg_QRPT_update(VALUE obj, VALUE qq, VALUE rr,
|
2041
|
+
VALUE pp, VALUE ww, VALUE vv)
|
2042
|
+
{
|
2043
|
+
return rb_gsl_linalg_QRLQPT_update(obj, qq, rr, pp, ww, vv, LINALG_QRPT);
|
2044
|
+
}
|
2045
|
+
|
2046
|
+
#ifdef GSL_1_6_LATER
|
2047
|
+
static VALUE rb_gsl_linalg_PTLQ_update(VALUE obj, VALUE qq, VALUE rr,
|
2048
|
+
VALUE pp, VALUE ww, VALUE vv)
|
2049
|
+
{
|
2050
|
+
return rb_gsl_linalg_QRLQPT_update(obj, qq, rr, pp, ww, vv, LINALG_PTLQ);
|
2051
|
+
}
|
2052
|
+
#endif
|
2053
|
+
|
2054
|
+
static VALUE rb_gsl_linalg_QRLQPT_RLsolve(int argc, VALUE *argv, VALUE obj, int flag)
|
2055
|
+
{
|
2056
|
+
gsl_matrix *QR = NULL;
|
2057
|
+
gsl_vector *b = NULL, *x = NULL;
|
2058
|
+
gsl_permutation *p = NULL;
|
2059
|
+
int itmp, flagb = 0;
|
2060
|
+
VALUE vtmp, klass;
|
2061
|
+
int (*fsolve)(const gsl_matrix*, const gsl_permutation*, const gsl_vector*,
|
2062
|
+
gsl_vector*);
|
2063
|
+
switch (flag) {
|
2064
|
+
case LINALG_QRPT:
|
2065
|
+
klass = cgsl_matrix_QRPT;
|
2066
|
+
fsolve = &gsl_linalg_QRPT_Rsolve;
|
2067
|
+
break;
|
2068
|
+
#ifdef GSL_1_6_LATER
|
2069
|
+
case LINALG_PTLQ:
|
2070
|
+
klass = cgsl_matrix_PTLQ;
|
2071
|
+
fsolve = &gsl_linalg_PTLQ_Lsolve_T;
|
2072
|
+
break;
|
2073
|
+
#endif
|
2074
|
+
default:
|
2075
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
2076
|
+
break;
|
2077
|
+
}
|
2078
|
+
switch (TYPE(obj)) {
|
2079
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2080
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
2081
|
+
argc);
|
2082
|
+
vtmp = argv[0];
|
2083
|
+
itmp = 1;
|
2084
|
+
break;
|
2085
|
+
default:
|
2086
|
+
vtmp = obj;
|
2087
|
+
itmp = 0;
|
2088
|
+
break;
|
2089
|
+
}
|
2090
|
+
if (argc-itmp != 2)
|
2091
|
+
rb_raise(rb_eArgError, "wrong number of argument (%d for %d)", argc, 2+itmp);
|
2092
|
+
CHECK_MATRIX(vtmp);
|
2093
|
+
if (CLASS_OF(vtmp) != klass) {
|
2094
|
+
rb_raise(rb_eArgError, "not a QR matrix");
|
2095
|
+
}
|
2096
|
+
CHECK_PERMUTATION(argv[itmp]);
|
2097
|
+
Data_Get_Struct(argv[itmp], gsl_permutation, p);
|
2098
|
+
Data_Get_Struct(vtmp, gsl_matrix, QR);
|
2099
|
+
itmp++;
|
2100
|
+
if (TYPE(argv[itmp]) == T_ARRAY) {
|
2101
|
+
b = make_cvector_from_rarray(argv[itmp]);
|
2102
|
+
flagb = 1;
|
2103
|
+
} else {
|
2104
|
+
CHECK_VECTOR(argv[itmp]);
|
2105
|
+
Data_Get_Struct(argv[itmp], gsl_vector, b);
|
2106
|
+
}
|
2107
|
+
x = gsl_vector_alloc(b->size);
|
2108
|
+
(*fsolve)(QR, p, b, x);
|
2109
|
+
if (flagb == 1) gsl_vector_free(b);
|
2110
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
2111
|
+
}
|
2112
|
+
|
2113
|
+
static VALUE rb_gsl_linalg_QRPT_Rsolve(int argc, VALUE *argv, VALUE obj)
|
2114
|
+
{
|
2115
|
+
return rb_gsl_linalg_QRLQPT_RLsolve(argc, argv, obj, LINALG_QRPT);
|
2116
|
+
}
|
2117
|
+
#ifdef GSL_1_6_LATER
|
2118
|
+
static VALUE rb_gsl_linalg_PTLQ_Lsolve(int argc, VALUE *argv, VALUE obj)
|
2119
|
+
{
|
2120
|
+
return rb_gsl_linalg_QRLQPT_RLsolve(argc, argv, obj, LINALG_PTLQ);
|
2121
|
+
}
|
2122
|
+
#endif
|
2123
|
+
|
2124
|
+
static VALUE rb_gsl_linalg_QRLQPT_RLsvx(int argc, VALUE *argv, VALUE obj, int flag)
|
2125
|
+
{
|
2126
|
+
gsl_matrix *QR = NULL;
|
2127
|
+
gsl_vector *b = NULL;
|
2128
|
+
gsl_permutation *p = NULL;
|
2129
|
+
int itmp;
|
2130
|
+
VALUE vtmp, klass;
|
2131
|
+
int (*fsvx)(const gsl_matrix*, const gsl_permutation*, gsl_vector*);
|
2132
|
+
switch (flag) {
|
2133
|
+
case LINALG_QRPT:
|
2134
|
+
klass = cgsl_matrix_QRPT;
|
2135
|
+
fsvx = &gsl_linalg_QRPT_Rsvx;
|
2136
|
+
break;
|
2137
|
+
#ifdef GSL_1_6_LATER
|
2138
|
+
case LINALG_PTLQ:
|
2139
|
+
klass = cgsl_matrix_PTLQ;
|
2140
|
+
fsvx = &gsl_linalg_PTLQ_Lsvx_T;
|
2141
|
+
#endif
|
2142
|
+
default:
|
2143
|
+
rb_raise(rb_eRuntimeError, "unknown operation");
|
2144
|
+
break;
|
2145
|
+
}
|
2146
|
+
switch (TYPE(obj)) {
|
2147
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2148
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
2149
|
+
argc);
|
2150
|
+
vtmp = argv[0];
|
2151
|
+
itmp = 1;
|
2152
|
+
break;
|
2153
|
+
default:
|
2154
|
+
vtmp = obj;
|
2155
|
+
itmp = 0;
|
2156
|
+
break;
|
2157
|
+
}
|
2158
|
+
if (argc-itmp != 2)
|
2159
|
+
rb_raise(rb_eArgError, "wrong number of argument (%d for %d)", argc, 2+itmp);
|
2160
|
+
CHECK_MATRIX(vtmp);
|
2161
|
+
if (CLASS_OF(vtmp) != klass) {
|
2162
|
+
rb_raise(rb_eArgError, "not a QR matrix");
|
2163
|
+
}
|
2164
|
+
CHECK_PERMUTATION(argv[itmp]);
|
2165
|
+
Data_Get_Struct(argv[itmp], gsl_permutation, p);
|
2166
|
+
Data_Get_Struct(vtmp, gsl_matrix, QR);
|
2167
|
+
itmp++;
|
2168
|
+
if (TYPE(argv[itmp]) == T_ARRAY) {
|
2169
|
+
b = make_cvector_from_rarray(argv[itmp]);
|
2170
|
+
} else {
|
2171
|
+
CHECK_VECTOR(argv[itmp]);
|
2172
|
+
Data_Get_Struct(argv[itmp], gsl_vector, b);
|
2173
|
+
}
|
2174
|
+
(*fsvx)(QR, p, b);
|
2175
|
+
return argv[itmp];
|
2176
|
+
}
|
2177
|
+
|
2178
|
+
static VALUE rb_gsl_linalg_QRPT_Rsvx(int argc, VALUE *argv, VALUE obj)
|
2179
|
+
{
|
2180
|
+
return rb_gsl_linalg_QRLQPT_RLsvx(argc, argv, obj, LINALG_QRPT);
|
2181
|
+
}
|
2182
|
+
#ifdef GSL_1_6_LATER
|
2183
|
+
static VALUE rb_gsl_linalg_PTLQ_Lsvx(int argc, VALUE *argv, VALUE obj)
|
2184
|
+
{
|
2185
|
+
return rb_gsl_linalg_QRLQPT_RLsvx(argc, argv, obj, LINALG_PTLQ);
|
2186
|
+
}
|
2187
|
+
#endif
|
2188
|
+
|
2189
|
+
/*******/
|
2190
|
+
#ifdef HAVE_NARRAY_H
|
2191
|
+
static VALUE rb_gsl_linalg_SV_decomp_narray(int argc, VALUE *argv, VALUE obj)
|
2192
|
+
{
|
2193
|
+
struct NARRAY *A;
|
2194
|
+
gsl_matrix_view uv, vv;
|
2195
|
+
gsl_vector_view sv;
|
2196
|
+
gsl_vector *work;
|
2197
|
+
VALUE u, s, v;
|
2198
|
+
int shape[2];
|
2199
|
+
GetNArray(argv[0], A);
|
2200
|
+
shape[0] = A->shape[0];
|
2201
|
+
shape[1] = A->shape[0];
|
2202
|
+
u = na_make_object(NA_DFLOAT, 2, A->shape, CLASS_OF(argv[0]));
|
2203
|
+
v = na_make_object(NA_DFLOAT, 2, shape, CLASS_OF(argv[0]));
|
2204
|
+
s = na_make_object(NA_DFLOAT, 1, &(shape[0]), cNVector);
|
2205
|
+
uv = gsl_matrix_view_array(NA_PTR_TYPE(u,double*), A->shape[1], A->shape[0]);
|
2206
|
+
vv = gsl_matrix_view_array(NA_PTR_TYPE(v,double*), shape[1], shape[0]);
|
2207
|
+
sv = gsl_vector_view_array(NA_PTR_TYPE(s,double*), shape[0]);
|
2208
|
+
work = gsl_vector_alloc(shape[0]);
|
2209
|
+
memcpy(NA_PTR_TYPE(u,double*), (double*)A->ptr, sizeof(double)*A->total);
|
2210
|
+
gsl_linalg_SV_decomp(&uv.matrix, &vv.matrix, &sv.vector, work);
|
2211
|
+
gsl_vector_free(work);
|
2212
|
+
return rb_ary_new3(3, u, v, s);
|
2213
|
+
}
|
2214
|
+
|
2215
|
+
static VALUE rb_gsl_linalg_SV_decomp_jacobi_narray(int argc, VALUE *argv, VALUE obj)
|
2216
|
+
{
|
2217
|
+
struct NARRAY *A;
|
2218
|
+
gsl_matrix_view uv, vv;
|
2219
|
+
gsl_vector_view sv;
|
2220
|
+
VALUE u, s, v;
|
2221
|
+
int shape[2];
|
2222
|
+
GetNArray(argv[0], A);
|
2223
|
+
shape[0] = A->shape[0];
|
2224
|
+
shape[1] = A->shape[0];
|
2225
|
+
u = na_make_object(NA_DFLOAT, 2, A->shape, CLASS_OF(argv[0]));
|
2226
|
+
v = na_make_object(NA_DFLOAT, 2, shape, CLASS_OF(argv[0]));
|
2227
|
+
s = na_make_object(NA_DFLOAT, 1, &(shape[0]), cNVector);
|
2228
|
+
uv = gsl_matrix_view_array(NA_PTR_TYPE(u,double*), A->shape[1], A->shape[0]);
|
2229
|
+
vv = gsl_matrix_view_array(NA_PTR_TYPE(v,double*), shape[1], shape[0]);
|
2230
|
+
sv = gsl_vector_view_array(NA_PTR_TYPE(s,double*), shape[0]);
|
2231
|
+
memcpy(NA_PTR_TYPE(u,double*), (double*)A->ptr, sizeof(double)*A->total);
|
2232
|
+
gsl_linalg_SV_decomp_jacobi(&uv.matrix, &vv.matrix, &sv.vector);
|
2233
|
+
return rb_ary_new3(3, u, v, s);
|
2234
|
+
}
|
2235
|
+
|
2236
|
+
static VALUE rb_gsl_linalg_SV_solve_narray(int argc, VALUE *argv, VALUE obj)
|
2237
|
+
{
|
2238
|
+
struct NARRAY *A;
|
2239
|
+
gsl_matrix_view uv, vv;
|
2240
|
+
gsl_vector_view sv, bv, xv;
|
2241
|
+
VALUE x;
|
2242
|
+
if (argc != 4)
|
2243
|
+
rb_raise(rb_eArgError, "Usage: SV.solve(u, v, s, b)");
|
2244
|
+
GetNArray(argv[0], A);
|
2245
|
+
uv = gsl_matrix_view_array(NA_PTR_TYPE(argv[0],double*), A->shape[1], A->shape[0]);
|
2246
|
+
vv = gsl_matrix_view_array(NA_PTR_TYPE(argv[1],double*), A->shape[0], A->shape[0]);
|
2247
|
+
sv = gsl_vector_view_array(NA_PTR_TYPE(argv[2],double*), A->shape[0]);
|
2248
|
+
bv = gsl_vector_view_array(NA_PTR_TYPE(argv[3],double*), A->shape[0]);
|
2249
|
+
x = na_make_object(NA_DFLOAT, 1, &(A->shape[0]), CLASS_OF(argv[3]));
|
2250
|
+
xv = gsl_vector_view_array(NA_PTR_TYPE(x,double*), A->shape[0]);
|
2251
|
+
gsl_linalg_SV_solve(&uv.matrix, &vv.matrix, &sv.vector, &bv.vector, &xv.vector);
|
2252
|
+
return x;
|
2253
|
+
}
|
2254
|
+
|
2255
|
+
#endif
|
2256
|
+
|
2257
|
+
static VALUE rb_gsl_linalg_SV_decomp(int argc, VALUE *argv, VALUE obj)
|
2258
|
+
{
|
2259
|
+
gsl_matrix *A = NULL, *V = NULL, *U = NULL;
|
2260
|
+
gsl_vector *w = NULL, *S = NULL;
|
2261
|
+
int flag = 1;
|
2262
|
+
VALUE vs, vv, vu;
|
2263
|
+
switch (TYPE(obj)) {
|
2264
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2265
|
+
switch (argc) {
|
2266
|
+
case 2:
|
2267
|
+
CHECK_VECTOR(argv[1]);
|
2268
|
+
Data_Get_Struct(argv[1], gsl_vector, w);
|
2269
|
+
flag = 0;
|
2270
|
+
/* no break, do next */
|
2271
|
+
case 1:
|
2272
|
+
#ifdef HAVE_NARRAY_H
|
2273
|
+
if (NA_IsNArray(argv[0]))
|
2274
|
+
return rb_gsl_linalg_SV_decomp_narray(argc, argv, obj);
|
2275
|
+
#endif
|
2276
|
+
CHECK_MATRIX(argv[0]);
|
2277
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2278
|
+
break;
|
2279
|
+
default:
|
2280
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
2281
|
+
break;
|
2282
|
+
}
|
2283
|
+
break;
|
2284
|
+
default:
|
2285
|
+
switch (argc) {
|
2286
|
+
case 0:
|
2287
|
+
/* do nothing */
|
2288
|
+
break;
|
2289
|
+
case 1:
|
2290
|
+
CHECK_VECTOR(argv[0]);
|
2291
|
+
Data_Get_Struct(argv[0], gsl_vector, w);
|
2292
|
+
flag = 0;
|
2293
|
+
break;
|
2294
|
+
default:
|
2295
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
2296
|
+
break;
|
2297
|
+
}
|
2298
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2299
|
+
break;
|
2300
|
+
}
|
2301
|
+
U = make_matrix_clone(A);
|
2302
|
+
S = gsl_vector_alloc(A->size2); /* see manual p 123 */
|
2303
|
+
V = gsl_matrix_alloc(A->size2, A->size2);
|
2304
|
+
if (flag == 1) w = gsl_vector_alloc(A->size2);
|
2305
|
+
gsl_linalg_SV_decomp(U, V, S, w);
|
2306
|
+
if (flag == 1) gsl_vector_free(w);
|
2307
|
+
vu = Data_Wrap_Struct(cgsl_matrix_U, 0, gsl_matrix_free, U);
|
2308
|
+
vv = Data_Wrap_Struct(cgsl_matrix_V, 0, gsl_matrix_free, V);
|
2309
|
+
vs = Data_Wrap_Struct(cgsl_vector_S, 0, gsl_vector_free, S);
|
2310
|
+
return rb_ary_new3(3, vu, vv, vs);
|
2311
|
+
}
|
2312
|
+
|
2313
|
+
static VALUE rb_gsl_linalg_SV_decomp_mod(int argc, VALUE *argv, VALUE obj)
|
2314
|
+
{
|
2315
|
+
gsl_matrix *A = NULL, *V = NULL, *U = NULL, *X = NULL;
|
2316
|
+
gsl_vector *w = NULL, *S = NULL;
|
2317
|
+
VALUE vs, vv, vu;
|
2318
|
+
switch (TYPE(obj)) {
|
2319
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2320
|
+
if (argc != 1) rb_raise(rb_eArgError,
|
2321
|
+
"wrong number of argument (%d for 1)", argc);
|
2322
|
+
CHECK_MATRIX(argv[0]);
|
2323
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2324
|
+
break;
|
2325
|
+
default:
|
2326
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2327
|
+
break;
|
2328
|
+
}
|
2329
|
+
U = make_matrix_clone(A);
|
2330
|
+
S = gsl_vector_alloc(A->size2); /* see manual p 123 */
|
2331
|
+
V = gsl_matrix_alloc(A->size2, A->size2);
|
2332
|
+
X = gsl_matrix_alloc(A->size2, A->size2);
|
2333
|
+
w = gsl_vector_alloc(A->size2);
|
2334
|
+
gsl_linalg_SV_decomp_mod(U, X, V, S, w);
|
2335
|
+
gsl_vector_free(w);
|
2336
|
+
gsl_matrix_free(X);
|
2337
|
+
vu = Data_Wrap_Struct(cgsl_matrix_U, 0, gsl_matrix_free, U);
|
2338
|
+
vv = Data_Wrap_Struct(cgsl_matrix_V, 0, gsl_matrix_free, V);
|
2339
|
+
vs = Data_Wrap_Struct(cgsl_vector_S, 0, gsl_vector_free, S);
|
2340
|
+
return rb_ary_new3(3, vu, vv, vs);
|
2341
|
+
}
|
2342
|
+
|
2343
|
+
static VALUE rb_gsl_linalg_SV_decomp_jacobi(int argc, VALUE *argv, VALUE obj)
|
2344
|
+
{
|
2345
|
+
gsl_matrix *A = NULL, *V = NULL, *U = NULL;
|
2346
|
+
gsl_vector *S = NULL;
|
2347
|
+
VALUE vs, vv, vu;
|
2348
|
+
switch (TYPE(obj)) {
|
2349
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2350
|
+
if (argc != 1) rb_raise(rb_eArgError,
|
2351
|
+
"wrong number of argument (%d for 1)", argc);
|
2352
|
+
#ifdef HAVE_NARRAY_H
|
2353
|
+
if (NA_IsNArray(argv[0]))
|
2354
|
+
return rb_gsl_linalg_SV_decomp_jacobi_narray(argc, argv, obj);
|
2355
|
+
#endif
|
2356
|
+
CHECK_MATRIX(argv[0]);
|
2357
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2358
|
+
break;
|
2359
|
+
default:
|
2360
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2361
|
+
break;
|
2362
|
+
}
|
2363
|
+
U = make_matrix_clone(A);
|
2364
|
+
S = gsl_vector_alloc(A->size2); /* see manual p 123 */
|
2365
|
+
V = gsl_matrix_alloc(A->size2, A->size2);
|
2366
|
+
gsl_linalg_SV_decomp_jacobi(U, V, S);
|
2367
|
+
vu = Data_Wrap_Struct(cgsl_matrix_U, 0, gsl_matrix_free, U);
|
2368
|
+
vv = Data_Wrap_Struct(cgsl_matrix_V, 0, gsl_matrix_free, V);
|
2369
|
+
vs = Data_Wrap_Struct(cgsl_vector_S, 0, gsl_vector_free, S);
|
2370
|
+
return rb_ary_new3(3, vu, vv, vs);
|
2371
|
+
}
|
2372
|
+
|
2373
|
+
static VALUE rb_gsl_linalg_SV_solve(int argc, VALUE *argv, VALUE obj)
|
2374
|
+
{
|
2375
|
+
gsl_matrix *A = NULL, *U = NULL, *V = NULL;
|
2376
|
+
gsl_vector *S = NULL, *b = NULL, *x = NULL;
|
2377
|
+
int flagb = 0, flagv = 0;
|
2378
|
+
|
2379
|
+
switch (TYPE(obj)) {
|
2380
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2381
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
2382
|
+
#ifdef HAVE_NARRAY_H
|
2383
|
+
if (NA_IsNArray(argv[0]))
|
2384
|
+
return rb_gsl_linalg_SV_solve_narray(argc, argv, obj);
|
2385
|
+
#endif
|
2386
|
+
|
2387
|
+
CHECK_MATRIX(argv[0]);
|
2388
|
+
if (CLASS_OF(argv[0]) == cgsl_matrix_U) {
|
2389
|
+
if (argc != 4) rb_raise(rb_eArgError,
|
2390
|
+
"wrong number of arguments (%d for 4)", argc);
|
2391
|
+
Data_Get_Struct(argv[0], gsl_matrix, U);
|
2392
|
+
CHECK_MATRIX(argv[1]);
|
2393
|
+
if (CLASS_OF(argv[1]) != cgsl_matrix_V)
|
2394
|
+
rb_raise(rb_eTypeError, "not a V matrix");
|
2395
|
+
Data_Get_Struct(argv[1], gsl_matrix, V);
|
2396
|
+
CHECK_VECTOR(argv[2]);
|
2397
|
+
if (CLASS_OF(argv[2]) != cgsl_vector_S)
|
2398
|
+
rb_raise(rb_eTypeError, "not a S vector");
|
2399
|
+
Data_Get_Struct(argv[2], gsl_vector, S);
|
2400
|
+
if (TYPE(argv[3]) == T_ARRAY) {
|
2401
|
+
b = make_cvector_from_rarray(argv[3]);
|
2402
|
+
flagb = 1;
|
2403
|
+
} else {
|
2404
|
+
CHECK_VECTOR(argv[3]);
|
2405
|
+
Data_Get_Struct(argv[3], gsl_vector, b);
|
2406
|
+
}
|
2407
|
+
} else {
|
2408
|
+
if (argc != 2) rb_raise(rb_eArgError,
|
2409
|
+
"wrong number of arguments (%d for 2)", argc);
|
2410
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2411
|
+
U = make_matrix_clone(A);
|
2412
|
+
if (TYPE(argv[1]) == T_ARRAY) {
|
2413
|
+
b = make_cvector_from_rarray(argv[1]);
|
2414
|
+
flagb = 1;
|
2415
|
+
} else {
|
2416
|
+
CHECK_VECTOR(argv[1]);
|
2417
|
+
Data_Get_Struct(argv[1], gsl_vector, b);
|
2418
|
+
}
|
2419
|
+
S = gsl_vector_alloc(A->size2); /* see manual p 123 */
|
2420
|
+
V = gsl_matrix_alloc(A->size2, A->size2);
|
2421
|
+
gsl_linalg_SV_decomp_jacobi(U, V, S);
|
2422
|
+
flagv = 1;
|
2423
|
+
}
|
2424
|
+
break;
|
2425
|
+
default:
|
2426
|
+
if (argc != 1) rb_raise(rb_eArgError,
|
2427
|
+
"wrong number of arguments (%d for 1)", argc);
|
2428
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2429
|
+
U = make_matrix_clone(A);
|
2430
|
+
if (TYPE(argv[0]) == T_ARRAY) {
|
2431
|
+
b = make_cvector_from_rarray(argv[0]);
|
2432
|
+
flagb = 1;
|
2433
|
+
} else {
|
2434
|
+
CHECK_VECTOR(argv[0]);
|
2435
|
+
Data_Get_Struct(argv[0], gsl_vector, b);
|
2436
|
+
}
|
2437
|
+
S = gsl_vector_alloc(A->size2); /* see manual p 123 */
|
2438
|
+
V = gsl_matrix_alloc(A->size2, A->size2);
|
2439
|
+
gsl_linalg_SV_decomp_jacobi(U, V, S);
|
2440
|
+
flagv = 1;
|
2441
|
+
break;
|
2442
|
+
}
|
2443
|
+
// x = gsl_vector_alloc(b->size);
|
2444
|
+
// Bug report #25842
|
2445
|
+
x = gsl_vector_alloc(S->size);
|
2446
|
+
gsl_linalg_SV_solve(U, V, S, b, x);
|
2447
|
+
if (flagv == 1) {
|
2448
|
+
gsl_matrix_free(U);
|
2449
|
+
gsl_matrix_free(V);
|
2450
|
+
gsl_vector_free(S);
|
2451
|
+
}
|
2452
|
+
if (flagb == 1) gsl_vector_free(b);
|
2453
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
2454
|
+
}
|
2455
|
+
|
2456
|
+
/*****/
|
2457
|
+
|
2458
|
+
#ifdef HAVE_NARRAY_H
|
2459
|
+
static VALUE rb_gsl_linalg_cholesky_decomp_narray(int argc, VALUE *argv, VALUE obj)
|
2460
|
+
{
|
2461
|
+
struct NARRAY *na;
|
2462
|
+
VALUE chol;
|
2463
|
+
gsl_matrix_view mv;
|
2464
|
+
GetNArray(argv[0], na);
|
2465
|
+
chol = na_make_object(NA_DFLOAT, 2, na->shape, CLASS_OF(argv[0]));
|
2466
|
+
memcpy(NA_PTR_TYPE(chol,double*), (double*)na->ptr, sizeof(double)*na->total);
|
2467
|
+
mv = gsl_matrix_view_array(NA_PTR_TYPE(chol,double*), na->shape[1], na->shape[0]);
|
2468
|
+
gsl_linalg_cholesky_decomp(&mv.matrix);
|
2469
|
+
return chol;
|
2470
|
+
}
|
2471
|
+
|
2472
|
+
static VALUE rb_gsl_linalg_cholesky_solve_narray(int argc, VALUE *argv, VALUE obj)
|
2473
|
+
{
|
2474
|
+
struct NARRAY *nm, *nb;
|
2475
|
+
VALUE x;
|
2476
|
+
gsl_matrix_view mv;
|
2477
|
+
gsl_vector_view bv, xv;
|
2478
|
+
switch (argc) {
|
2479
|
+
case 2:
|
2480
|
+
GetNArray(argv[0], nm);
|
2481
|
+
GetNArray(argv[1], nb);
|
2482
|
+
x = na_make_object(NA_DFLOAT, 1, nb->shape, CLASS_OF(argv[1]));
|
2483
|
+
break;
|
2484
|
+
case 3:
|
2485
|
+
GetNArray(argv[0], nm);
|
2486
|
+
GetNArray(argv[1], nb);
|
2487
|
+
x = argv[2];
|
2488
|
+
break;
|
2489
|
+
default:
|
2490
|
+
rb_raise(rb_eArgError,
|
2491
|
+
"Usage: Cholesky.solve(chol, b) or Cholesky.solve(chol, b, x)");
|
2492
|
+
break;
|
2493
|
+
}
|
2494
|
+
mv = gsl_matrix_view_array((double*)nm->ptr, nm->shape[1], nm->shape[0]);
|
2495
|
+
bv = gsl_vector_view_array((double*)nb->ptr, nb->shape[0]);
|
2496
|
+
xv = gsl_vector_view_array(NA_PTR_TYPE(x,double*), nb->shape[0]);
|
2497
|
+
gsl_linalg_cholesky_solve(&mv.matrix, &bv.vector, &xv.vector);
|
2498
|
+
return x;
|
2499
|
+
}
|
2500
|
+
|
2501
|
+
static VALUE rb_gsl_linalg_cholesky_svx_narray(int argc, VALUE *argv, VALUE obj)
|
2502
|
+
{
|
2503
|
+
struct NARRAY *nm, *nb;
|
2504
|
+
gsl_matrix_view mv;
|
2505
|
+
gsl_vector_view bv;
|
2506
|
+
GetNArray(argv[0], nm); GetNArray(argv[1], nb);
|
2507
|
+
mv = gsl_matrix_view_array((double*)nm->ptr, nm->shape[1], nm->shape[0]);
|
2508
|
+
bv = gsl_vector_view_array((double*)nb->ptr, nb->shape[0]);
|
2509
|
+
gsl_linalg_cholesky_svx(&mv.matrix, &bv.vector);
|
2510
|
+
return argv[1];
|
2511
|
+
}
|
2512
|
+
|
2513
|
+
#endif
|
2514
|
+
|
2515
|
+
static VALUE rb_gsl_linalg_cholesky_decomp(int argc, VALUE *argv, VALUE obj)
|
2516
|
+
{
|
2517
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
2518
|
+
switch(TYPE(obj)) {
|
2519
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2520
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2521
|
+
argc);
|
2522
|
+
#ifdef HAVE_NARRAY_H
|
2523
|
+
if (NA_IsNArray(argv[0]))
|
2524
|
+
return rb_gsl_linalg_cholesky_decomp_narray(argc, argv, obj);
|
2525
|
+
#endif
|
2526
|
+
CHECK_MATRIX(argv[0]);
|
2527
|
+
Data_Get_Struct(argv[0], gsl_matrix, Atmp);
|
2528
|
+
break;
|
2529
|
+
default:
|
2530
|
+
CHECK_MATRIX(obj);
|
2531
|
+
Data_Get_Struct(obj, gsl_matrix, Atmp);
|
2532
|
+
break;
|
2533
|
+
}
|
2534
|
+
A = make_matrix_clone(Atmp);
|
2535
|
+
gsl_linalg_cholesky_decomp(A);
|
2536
|
+
return Data_Wrap_Struct(cgsl_matrix_C, 0, gsl_matrix_free, A);
|
2537
|
+
}
|
2538
|
+
|
2539
|
+
static VALUE rb_gsl_linalg_cholesky_solve(int argc, VALUE *argv, VALUE obj)
|
2540
|
+
{
|
2541
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
2542
|
+
gsl_vector *b = NULL, *x = NULL;
|
2543
|
+
int flagb = 0, flaga = 0;
|
2544
|
+
VALUE vA, vb;
|
2545
|
+
switch(TYPE(obj)) {
|
2546
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2547
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
|
2548
|
+
argc);
|
2549
|
+
#ifdef HAVE_NARRAY_H
|
2550
|
+
if (NA_IsNArray(argv[0]))
|
2551
|
+
return rb_gsl_linalg_cholesky_solve_narray(argc, argv, obj);
|
2552
|
+
#endif
|
2553
|
+
vA = argv[0];
|
2554
|
+
vb = argv[1];
|
2555
|
+
break;
|
2556
|
+
default:
|
2557
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2558
|
+
argc);
|
2559
|
+
vA = obj;
|
2560
|
+
vb = argv[0];
|
2561
|
+
break;
|
2562
|
+
}
|
2563
|
+
CHECK_MATRIX(vA);
|
2564
|
+
Data_Get_Struct(vA, gsl_matrix, Atmp);
|
2565
|
+
if (TYPE(vb) == T_ARRAY) {
|
2566
|
+
b = make_cvector_from_rarray(vb);
|
2567
|
+
flagb = 1;
|
2568
|
+
} else {
|
2569
|
+
CHECK_VECTOR(vb);
|
2570
|
+
Data_Get_Struct(vb, gsl_vector, b);
|
2571
|
+
}
|
2572
|
+
if (CLASS_OF(vA) == cgsl_matrix_C) {
|
2573
|
+
A = Atmp;
|
2574
|
+
} else {
|
2575
|
+
A = make_matrix_clone(Atmp);
|
2576
|
+
flaga = 1;
|
2577
|
+
gsl_linalg_cholesky_decomp(A);
|
2578
|
+
}
|
2579
|
+
x = gsl_vector_alloc(b->size);
|
2580
|
+
gsl_linalg_cholesky_solve(A, b, x);
|
2581
|
+
if (flaga == 1) gsl_matrix_free(A);
|
2582
|
+
if (flagb == 1) gsl_vector_free(b);
|
2583
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
2584
|
+
}
|
2585
|
+
|
2586
|
+
|
2587
|
+
static VALUE rb_gsl_linalg_cholesky_svx(int argc, VALUE *argv, VALUE obj)
|
2588
|
+
{
|
2589
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
2590
|
+
gsl_vector *b = NULL;
|
2591
|
+
int flaga = 0;
|
2592
|
+
VALUE vA, vb;
|
2593
|
+
switch(TYPE(obj)) {
|
2594
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2595
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
|
2596
|
+
argc);
|
2597
|
+
#ifdef HAVE_NARRAY_H
|
2598
|
+
if (NA_IsNArray(argv[0]))
|
2599
|
+
return rb_gsl_linalg_cholesky_svx_narray(argc, argv, obj);
|
2600
|
+
#endif
|
2601
|
+
vA = argv[0];
|
2602
|
+
vb = argv[1];
|
2603
|
+
break;
|
2604
|
+
default:
|
2605
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2606
|
+
argc);
|
2607
|
+
vA = obj;
|
2608
|
+
vb = argv[0];
|
2609
|
+
break;
|
2610
|
+
}
|
2611
|
+
CHECK_MATRIX(vA);
|
2612
|
+
Data_Get_Struct(vA, gsl_matrix, Atmp);
|
2613
|
+
CHECK_VECTOR(vb);
|
2614
|
+
Data_Get_Struct(vb, gsl_vector, b);
|
2615
|
+
if (CLASS_OF(vA) == cgsl_matrix_C) {
|
2616
|
+
A = Atmp;
|
2617
|
+
} else {
|
2618
|
+
A = make_matrix_clone(Atmp);
|
2619
|
+
flaga = 1;
|
2620
|
+
gsl_linalg_cholesky_decomp(A);
|
2621
|
+
}
|
2622
|
+
gsl_linalg_cholesky_svx(A, b);
|
2623
|
+
if (flaga == 1) gsl_matrix_free(A);
|
2624
|
+
return vb;
|
2625
|
+
}
|
2626
|
+
|
2627
|
+
static VALUE rb_gsl_linalg_symmtd_decomp(int argc, VALUE *argv, VALUE obj)
|
2628
|
+
{
|
2629
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
2630
|
+
gsl_vector *tau = NULL;
|
2631
|
+
VALUE vQ, vtau;
|
2632
|
+
switch (TYPE(obj)) {
|
2633
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2634
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2635
|
+
argc);
|
2636
|
+
CHECK_MATRIX(argv[0]);
|
2637
|
+
Data_Get_Struct(argv[0], gsl_matrix, Atmp);
|
2638
|
+
break;
|
2639
|
+
default:
|
2640
|
+
CHECK_MATRIX(obj);
|
2641
|
+
Data_Get_Struct(obj, gsl_matrix, Atmp);
|
2642
|
+
break;
|
2643
|
+
}
|
2644
|
+
A = make_matrix_clone(Atmp);
|
2645
|
+
tau = gsl_vector_alloc(A->size1);
|
2646
|
+
gsl_linalg_symmtd_decomp(A, tau);
|
2647
|
+
vQ = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, A);
|
2648
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
2649
|
+
return rb_ary_new3(2, vQ, vtau);
|
2650
|
+
}
|
2651
|
+
|
2652
|
+
|
2653
|
+
static VALUE rb_gsl_linalg_symmtd_decomp2(int argc, VALUE *argv, VALUE obj)
|
2654
|
+
{
|
2655
|
+
gsl_matrix *A = NULL;
|
2656
|
+
gsl_vector *tau = NULL;
|
2657
|
+
switch (TYPE(obj)) {
|
2658
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2659
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2660
|
+
argc);
|
2661
|
+
CHECK_MATRIX(argv[0]);
|
2662
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2663
|
+
break;
|
2664
|
+
default:
|
2665
|
+
CHECK_MATRIX(obj);
|
2666
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2667
|
+
break;
|
2668
|
+
}
|
2669
|
+
tau = gsl_vector_alloc(A->size1);
|
2670
|
+
gsl_linalg_symmtd_decomp(A, tau);
|
2671
|
+
return Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
2672
|
+
}
|
2673
|
+
|
2674
|
+
static VALUE rb_gsl_linalg_symmtd_unpack(int argc, VALUE *argv, VALUE obj)
|
2675
|
+
{
|
2676
|
+
gsl_matrix *A = NULL, *Q = NULL;
|
2677
|
+
gsl_vector *tau = NULL, *d = NULL, *sd = NULL;
|
2678
|
+
VALUE vq, vd, vsd;
|
2679
|
+
switch (TYPE(obj)) {
|
2680
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2681
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
|
2682
|
+
argc);
|
2683
|
+
CHECK_MATRIX(argv[0]);
|
2684
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2685
|
+
Data_Get_Struct(argv[1], gsl_vector, tau);
|
2686
|
+
break;
|
2687
|
+
default:
|
2688
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2689
|
+
argc);
|
2690
|
+
CHECK_MATRIX(obj);
|
2691
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2692
|
+
Data_Get_Struct(argv[0], gsl_vector, tau);
|
2693
|
+
break;
|
2694
|
+
}
|
2695
|
+
Q = gsl_matrix_alloc(A->size1, A->size2);
|
2696
|
+
d = gsl_vector_alloc(tau->size);
|
2697
|
+
sd = gsl_vector_alloc(tau->size);
|
2698
|
+
gsl_linalg_symmtd_unpack(A, tau, Q, d, sd);
|
2699
|
+
|
2700
|
+
vq = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, Q);
|
2701
|
+
vd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, d);
|
2702
|
+
vsd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, sd);
|
2703
|
+
|
2704
|
+
return rb_ary_new3(3, vq, vd, vsd);
|
2705
|
+
}
|
2706
|
+
|
2707
|
+
static VALUE rb_gsl_linalg_symmtd_unpack_T(int argc, VALUE *argv, VALUE obj)
|
2708
|
+
{
|
2709
|
+
gsl_matrix *A = NULL;
|
2710
|
+
gsl_vector *d = NULL, *sd = NULL;
|
2711
|
+
VALUE vd, vsd;
|
2712
|
+
switch (TYPE(obj)) {
|
2713
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2714
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
|
2715
|
+
argc);
|
2716
|
+
CHECK_MATRIX(argv[0]);
|
2717
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2718
|
+
break;
|
2719
|
+
default:
|
2720
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2721
|
+
break;
|
2722
|
+
}
|
2723
|
+
d = gsl_vector_alloc(A->size1);
|
2724
|
+
sd = gsl_vector_alloc(A->size1);
|
2725
|
+
gsl_linalg_symmtd_unpack_T(A, d, sd);
|
2726
|
+
|
2727
|
+
vd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, d);
|
2728
|
+
vsd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, sd);
|
2729
|
+
|
2730
|
+
return rb_ary_new3(2, vd, vsd);
|
2731
|
+
}
|
2732
|
+
|
2733
|
+
/*****/
|
2734
|
+
|
2735
|
+
static VALUE rb_gsl_linalg_hermtd_decomp(int argc, VALUE *argv, VALUE obj)
|
2736
|
+
{
|
2737
|
+
gsl_matrix_complex *A = NULL, *Atmp = NULL;
|
2738
|
+
gsl_vector_complex *tau = NULL;
|
2739
|
+
VALUE vQ, vtau;
|
2740
|
+
switch (TYPE(obj)) {
|
2741
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2742
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2743
|
+
argc);
|
2744
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
2745
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, Atmp);
|
2746
|
+
break;
|
2747
|
+
default:
|
2748
|
+
CHECK_MATRIX_COMPLEX(obj);
|
2749
|
+
Data_Get_Struct(obj, gsl_matrix_complex, Atmp);
|
2750
|
+
break;
|
2751
|
+
}
|
2752
|
+
A = make_matrix_complex_clone(Atmp);
|
2753
|
+
tau = gsl_vector_complex_alloc(A->size1);
|
2754
|
+
gsl_linalg_hermtd_decomp(A, tau);
|
2755
|
+
vQ = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, A);
|
2756
|
+
vtau = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, tau);
|
2757
|
+
return rb_ary_new3(2, vQ, vtau);
|
2758
|
+
}
|
2759
|
+
|
2760
|
+
static VALUE rb_gsl_linalg_hermtd_decomp2(int argc, VALUE *argv, VALUE obj)
|
2761
|
+
{
|
2762
|
+
gsl_matrix_complex *A = NULL;
|
2763
|
+
gsl_vector_complex *tau = NULL;
|
2764
|
+
switch (TYPE(obj)) {
|
2765
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2766
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2767
|
+
argc);
|
2768
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
2769
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, A);
|
2770
|
+
break;
|
2771
|
+
default:
|
2772
|
+
CHECK_MATRIX_COMPLEX(obj);
|
2773
|
+
Data_Get_Struct(obj, gsl_matrix_complex, A);
|
2774
|
+
break;
|
2775
|
+
}
|
2776
|
+
tau = gsl_vector_complex_alloc(A->size1);
|
2777
|
+
gsl_linalg_hermtd_decomp(A, tau);
|
2778
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, tau);
|
2779
|
+
}
|
2780
|
+
|
2781
|
+
static VALUE rb_gsl_linalg_hermtd_unpack(int argc, VALUE *argv, VALUE obj)
|
2782
|
+
{
|
2783
|
+
gsl_matrix_complex *A = NULL, *Q = NULL;
|
2784
|
+
gsl_vector_complex *tau = NULL;
|
2785
|
+
gsl_vector *d = NULL, *sd = NULL;
|
2786
|
+
VALUE vq, vd, vsd;
|
2787
|
+
switch (TYPE(obj)) {
|
2788
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2789
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2790
|
+
argc);
|
2791
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
2792
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, A);
|
2793
|
+
Data_Get_Struct(argv[1], gsl_vector_complex, tau);
|
2794
|
+
break;
|
2795
|
+
default:
|
2796
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2797
|
+
argc);
|
2798
|
+
CHECK_MATRIX_COMPLEX(obj);
|
2799
|
+
Data_Get_Struct(obj, gsl_matrix_complex, A);
|
2800
|
+
Data_Get_Struct(argv[0], gsl_vector_complex, tau);
|
2801
|
+
break;
|
2802
|
+
}
|
2803
|
+
Q = gsl_matrix_complex_alloc(A->size1, A->size2);
|
2804
|
+
d = gsl_vector_alloc(tau->size);
|
2805
|
+
sd = gsl_vector_alloc(tau->size);
|
2806
|
+
gsl_linalg_hermtd_unpack(A, tau, Q, d, sd);
|
2807
|
+
|
2808
|
+
vq = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, Q);
|
2809
|
+
vd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, d);
|
2810
|
+
vsd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, sd);
|
2811
|
+
|
2812
|
+
return rb_ary_new3(3, vq, vd, vsd);
|
2813
|
+
}
|
2814
|
+
|
2815
|
+
static VALUE rb_gsl_linalg_hermtd_unpack_T(int argc, VALUE *argv, VALUE obj)
|
2816
|
+
{
|
2817
|
+
gsl_matrix_complex *A = NULL;
|
2818
|
+
gsl_vector *d = NULL, *sd = NULL;
|
2819
|
+
VALUE vd, vsd;
|
2820
|
+
switch (TYPE(obj)) {
|
2821
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2822
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
2823
|
+
argc);
|
2824
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
2825
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, A);
|
2826
|
+
break;
|
2827
|
+
default:
|
2828
|
+
Data_Get_Struct(obj, gsl_matrix_complex, A);
|
2829
|
+
break;
|
2830
|
+
}
|
2831
|
+
d = gsl_vector_alloc(A->size1);
|
2832
|
+
sd = gsl_vector_alloc(A->size1);
|
2833
|
+
gsl_linalg_hermtd_unpack_T(A, d, sd);
|
2834
|
+
|
2835
|
+
vd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, d);
|
2836
|
+
vsd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, sd);
|
2837
|
+
|
2838
|
+
return rb_ary_new3(2, vd, vsd);
|
2839
|
+
}
|
2840
|
+
|
2841
|
+
/******/
|
2842
|
+
|
2843
|
+
static VALUE rb_gsl_linalg_bidiag_decomp(int argc, VALUE *argv, VALUE obj)
|
2844
|
+
{
|
2845
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
2846
|
+
gsl_vector *tau_U = NULL, *tau_V = NULL;
|
2847
|
+
size_t size0;
|
2848
|
+
// local variable "status" was defined and set, but never used
|
2849
|
+
//int status;
|
2850
|
+
VALUE vu, vv, vA;
|
2851
|
+
|
2852
|
+
switch (TYPE(obj)) {
|
2853
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2854
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
2855
|
+
argc);
|
2856
|
+
Data_Get_Struct(argv[0], gsl_matrix, Atmp);
|
2857
|
+
break;
|
2858
|
+
default:
|
2859
|
+
Data_Get_Struct(obj, gsl_matrix, Atmp);
|
2860
|
+
break;
|
2861
|
+
}
|
2862
|
+
A = make_matrix_clone(Atmp);
|
2863
|
+
size0 = GSL_MIN(A->size1, A->size2);
|
2864
|
+
tau_U = gsl_vector_alloc(size0);
|
2865
|
+
tau_V = gsl_vector_alloc(size0-1);
|
2866
|
+
/*status =*/ gsl_linalg_bidiag_decomp(A, tau_U, tau_V);
|
2867
|
+
vA = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, A);
|
2868
|
+
vu = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, tau_U);
|
2869
|
+
vv = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, tau_V);
|
2870
|
+
return rb_ary_new3(3, vA, vu, vv);
|
2871
|
+
}
|
2872
|
+
|
2873
|
+
static VALUE rb_gsl_linalg_bidiag_decomp2(int argc, VALUE *argv, VALUE obj)
|
2874
|
+
{
|
2875
|
+
gsl_matrix *A = NULL;
|
2876
|
+
gsl_vector *tau_U = NULL, *tau_V = NULL;
|
2877
|
+
size_t size0;
|
2878
|
+
VALUE vu, vv;
|
2879
|
+
|
2880
|
+
switch (TYPE(obj)) {
|
2881
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2882
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
2883
|
+
argc);
|
2884
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2885
|
+
break;
|
2886
|
+
default:
|
2887
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2888
|
+
break;
|
2889
|
+
}
|
2890
|
+
size0 = GSL_MIN(A->size1, A->size2);
|
2891
|
+
tau_U = gsl_vector_alloc(size0);
|
2892
|
+
tau_V = gsl_vector_alloc(size0-1);
|
2893
|
+
gsl_linalg_bidiag_decomp(A, tau_U, tau_V);
|
2894
|
+
vu = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, tau_U);
|
2895
|
+
vv = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, tau_V);
|
2896
|
+
return rb_ary_new3(2, vu, vv);
|
2897
|
+
}
|
2898
|
+
|
2899
|
+
static VALUE rb_gsl_linalg_bidiag_unpack(int argc, VALUE *argv, VALUE obj)
|
2900
|
+
{
|
2901
|
+
gsl_matrix *A = NULL, *U = NULL, *V = NULL;
|
2902
|
+
gsl_vector *tau_U = NULL, *tau_V = NULL, *d = NULL, *s = NULL;
|
2903
|
+
size_t size0;
|
2904
|
+
VALUE vu, vv, vd, vs;
|
2905
|
+
|
2906
|
+
switch (TYPE(obj)) {
|
2907
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2908
|
+
if (argc != 3) rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)",
|
2909
|
+
argc);
|
2910
|
+
CHECK_MATRIX(argv[0]);
|
2911
|
+
CHECK_VECTOR(argv[1]);
|
2912
|
+
CHECK_VECTOR(argv[2]);
|
2913
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2914
|
+
Data_Get_Struct(argv[1], gsl_vector, tau_U);
|
2915
|
+
Data_Get_Struct(argv[2], gsl_vector, tau_V);
|
2916
|
+
break;
|
2917
|
+
default:
|
2918
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
2919
|
+
argc);
|
2920
|
+
CHECK_MATRIX(obj);
|
2921
|
+
CHECK_VECTOR(argv[0]);
|
2922
|
+
CHECK_VECTOR(argv[1]);
|
2923
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2924
|
+
Data_Get_Struct(argv[0], gsl_vector, tau_U);
|
2925
|
+
Data_Get_Struct(argv[1], gsl_vector, tau_V);
|
2926
|
+
break;
|
2927
|
+
}
|
2928
|
+
size0 = GSL_MIN(A->size1, A->size2);
|
2929
|
+
U = gsl_matrix_alloc(A->size1, A->size2);
|
2930
|
+
V = gsl_matrix_alloc(size0, size0);
|
2931
|
+
|
2932
|
+
d = gsl_vector_alloc(size0);
|
2933
|
+
s = gsl_vector_alloc(size0-1);
|
2934
|
+
gsl_linalg_bidiag_unpack(A, tau_U, U, tau_V, V, d, s);
|
2935
|
+
vu = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, U);
|
2936
|
+
vv = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, V);
|
2937
|
+
vd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, d);
|
2938
|
+
vs = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, s);
|
2939
|
+
return rb_ary_new3(4, vu, vv, vd, vs);
|
2940
|
+
}
|
2941
|
+
|
2942
|
+
static VALUE rb_gsl_linalg_bidiag_unpack2(int argc, VALUE *argv, VALUE obj)
|
2943
|
+
{
|
2944
|
+
gsl_matrix *A = NULL, *V = NULL;
|
2945
|
+
gsl_vector *tau_V = NULL, *tau_U = NULL;
|
2946
|
+
VALUE vv;
|
2947
|
+
|
2948
|
+
switch (TYPE(obj)) {
|
2949
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2950
|
+
if (argc != 3) rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)",
|
2951
|
+
argc);
|
2952
|
+
CHECK_MATRIX(argv[0]);
|
2953
|
+
CHECK_VECTOR(argv[1]);
|
2954
|
+
CHECK_VECTOR(argv[2]);
|
2955
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2956
|
+
Data_Get_Struct(argv[1], gsl_vector, tau_U);
|
2957
|
+
Data_Get_Struct(argv[2], gsl_vector, tau_V);
|
2958
|
+
break;
|
2959
|
+
default:
|
2960
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
2961
|
+
argc);
|
2962
|
+
CHECK_MATRIX(obj);
|
2963
|
+
CHECK_VECTOR(argv[0]);
|
2964
|
+
CHECK_VECTOR(argv[1]);
|
2965
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2966
|
+
Data_Get_Struct(argv[0], gsl_vector, tau_U);
|
2967
|
+
Data_Get_Struct(argv[1], gsl_vector, tau_V);
|
2968
|
+
break;
|
2969
|
+
}
|
2970
|
+
V = gsl_matrix_alloc(A->size2, A->size2);
|
2971
|
+
gsl_linalg_bidiag_unpack2(A, tau_U, tau_V, V);
|
2972
|
+
vv = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, V);
|
2973
|
+
return vv;
|
2974
|
+
}
|
2975
|
+
|
2976
|
+
static VALUE rb_gsl_linalg_bidiag_unpack_B(int argc, VALUE *argv, VALUE obj)
|
2977
|
+
{
|
2978
|
+
gsl_matrix *A = NULL;
|
2979
|
+
gsl_vector *d = NULL, *s = NULL;
|
2980
|
+
size_t size0;
|
2981
|
+
VALUE vd, vs;
|
2982
|
+
|
2983
|
+
switch (TYPE(obj)) {
|
2984
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
2985
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)",
|
2986
|
+
argc);
|
2987
|
+
CHECK_MATRIX(argv[0]);
|
2988
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
2989
|
+
break;
|
2990
|
+
default:
|
2991
|
+
CHECK_MATRIX(obj);
|
2992
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
2993
|
+
break;
|
2994
|
+
}
|
2995
|
+
size0 = GSL_MIN(A->size1, A->size2);
|
2996
|
+
d = gsl_vector_alloc(size0);
|
2997
|
+
s = gsl_vector_alloc(size0);
|
2998
|
+
gsl_linalg_bidiag_unpack_B(A, d, s);
|
2999
|
+
vd = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, d);
|
3000
|
+
vs = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, s);
|
3001
|
+
return rb_ary_new3(2, vd, vs);
|
3002
|
+
}
|
3003
|
+
|
3004
|
+
/* Householder Transformations 11.Jul.2004 */
|
3005
|
+
static VALUE rb_gsl_linalg_householder_transform(int argc, VALUE *argv, VALUE obj)
|
3006
|
+
{
|
3007
|
+
gsl_vector *v = NULL;
|
3008
|
+
switch (TYPE(obj)) {
|
3009
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
3010
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
3011
|
+
CHECK_VECTOR(argv[0]);
|
3012
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
3013
|
+
break;
|
3014
|
+
default:
|
3015
|
+
Data_Get_Struct(obj, gsl_vector, v);
|
3016
|
+
break;
|
3017
|
+
}
|
3018
|
+
return rb_float_new(gsl_linalg_householder_transform(v));
|
3019
|
+
}
|
3020
|
+
|
3021
|
+
/* singleton */
|
3022
|
+
static VALUE rb_gsl_linalg_householder_hm(VALUE obj, VALUE t, VALUE vv, VALUE aa)
|
3023
|
+
{
|
3024
|
+
gsl_vector *v = NULL;
|
3025
|
+
double tau;
|
3026
|
+
gsl_matrix *A = NULL;
|
3027
|
+
CHECK_VECTOR(vv);
|
3028
|
+
CHECK_MATRIX(aa);
|
3029
|
+
tau = NUM2DBL(t);
|
3030
|
+
Data_Get_Struct(vv, gsl_vector, v);
|
3031
|
+
Data_Get_Struct(aa, gsl_matrix, A);
|
3032
|
+
gsl_linalg_householder_hm(tau, v, A);
|
3033
|
+
return aa;
|
3034
|
+
}
|
3035
|
+
|
3036
|
+
static VALUE rb_gsl_linalg_householder_mh(VALUE obj, VALUE t, VALUE vv, VALUE aa)
|
3037
|
+
{
|
3038
|
+
gsl_vector *v = NULL;
|
3039
|
+
double tau;
|
3040
|
+
gsl_matrix *A = NULL;
|
3041
|
+
CHECK_VECTOR(vv);
|
3042
|
+
CHECK_MATRIX(aa);
|
3043
|
+
tau = NUM2DBL(t);
|
3044
|
+
Data_Get_Struct(vv, gsl_vector, v);
|
3045
|
+
Data_Get_Struct(aa, gsl_matrix, A);
|
3046
|
+
gsl_linalg_householder_mh(tau, v, A);
|
3047
|
+
return aa;
|
3048
|
+
}
|
3049
|
+
|
3050
|
+
static VALUE rb_gsl_linalg_householder_hv(VALUE obj, VALUE t, VALUE vv, VALUE ww)
|
3051
|
+
{
|
3052
|
+
gsl_vector *v = NULL, *w = NULL;
|
3053
|
+
double tau;
|
3054
|
+
CHECK_VECTOR(vv);
|
3055
|
+
CHECK_VECTOR(ww);
|
3056
|
+
tau = NUM2DBL(t);
|
3057
|
+
Data_Get_Struct(vv, gsl_vector, v);
|
3058
|
+
Data_Get_Struct(ww, gsl_vector, w);
|
3059
|
+
gsl_linalg_householder_hv(tau, v, w);
|
3060
|
+
return ww;
|
3061
|
+
}
|
3062
|
+
|
3063
|
+
#ifdef HAVE_NARRAY_H
|
3064
|
+
static VALUE rb_gsl_linalg_HH_solve_narray(int argc, VALUE *argv, VALUE obj)
|
3065
|
+
{
|
3066
|
+
struct NARRAY *na;
|
3067
|
+
gsl_vector_view bv, xv;
|
3068
|
+
VALUE x;
|
3069
|
+
gsl_matrix *mtmp;
|
3070
|
+
GetNArray(argv[0], na);
|
3071
|
+
bv = gsl_vector_view_array(NA_PTR_TYPE(argv[1],double*), na->shape[1]);
|
3072
|
+
x = na_make_object(NA_DFLOAT, 1, &na->shape[1], CLASS_OF(argv[1]));
|
3073
|
+
xv = gsl_vector_view_array(NA_PTR_TYPE(x,double*), na->shape[1]);
|
3074
|
+
mtmp = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
3075
|
+
memcpy(mtmp->data, (double*)na->ptr, sizeof(double)*na->total);
|
3076
|
+
gsl_linalg_HH_solve(mtmp, &bv.vector, &xv.vector);
|
3077
|
+
gsl_matrix_free(mtmp);
|
3078
|
+
return x;
|
3079
|
+
}
|
3080
|
+
static VALUE rb_gsl_linalg_HH_svx_narray(int argc, VALUE *argv, VALUE obj)
|
3081
|
+
{
|
3082
|
+
struct NARRAY *na;
|
3083
|
+
gsl_matrix *mtmp;
|
3084
|
+
gsl_vector_view bv;
|
3085
|
+
GetNArray(argv[0], na);
|
3086
|
+
bv = gsl_vector_view_array(NA_PTR_TYPE(argv[1],double*), na->shape[1]);
|
3087
|
+
mtmp = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
3088
|
+
memcpy(mtmp->data, (double*)na->ptr, sizeof(double)*na->total);
|
3089
|
+
gsl_linalg_HH_svx(mtmp, &bv.vector);
|
3090
|
+
gsl_matrix_free(mtmp);
|
3091
|
+
return argv[1];
|
3092
|
+
}
|
3093
|
+
#endif
|
3094
|
+
|
3095
|
+
/* 17.Apr.2004 */
|
3096
|
+
static VALUE rb_gsl_linalg_HH_solve(int argc, VALUE *argv, VALUE obj)
|
3097
|
+
{
|
3098
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
3099
|
+
gsl_vector *b = NULL, *x = NULL;
|
3100
|
+
int flagb = 0;
|
3101
|
+
VALUE vA, vb;
|
3102
|
+
switch (TYPE(obj)) {
|
3103
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
3104
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
|
3105
|
+
argc);
|
3106
|
+
#ifdef HAVE_NARRAY_H
|
3107
|
+
if (NA_IsNArray(argv[0]))
|
3108
|
+
return rb_gsl_linalg_HH_solve_narray(argc, argv, obj);
|
3109
|
+
#endif
|
3110
|
+
vA = argv[0];
|
3111
|
+
vb = argv[1];
|
3112
|
+
break;
|
3113
|
+
default:
|
3114
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
3115
|
+
argc);
|
3116
|
+
vA = obj;
|
3117
|
+
vb = argv[0];
|
3118
|
+
break;
|
3119
|
+
}
|
3120
|
+
CHECK_MATRIX(vA);
|
3121
|
+
Data_Get_Struct(vA, gsl_matrix, Atmp);
|
3122
|
+
if (TYPE(vb) == T_ARRAY) {
|
3123
|
+
b = make_cvector_from_rarray(vb);
|
3124
|
+
flagb = 1;
|
3125
|
+
} else {
|
3126
|
+
CHECK_VECTOR(vb);
|
3127
|
+
Data_Get_Struct(vb, gsl_vector, b);
|
3128
|
+
}
|
3129
|
+
A = make_matrix_clone(Atmp);
|
3130
|
+
x = gsl_vector_alloc(b->size);
|
3131
|
+
gsl_linalg_HH_solve(A, b, x);
|
3132
|
+
gsl_matrix_free(A);
|
3133
|
+
if (flagb == 1) gsl_vector_free(b);
|
3134
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
3135
|
+
}
|
3136
|
+
|
3137
|
+
static VALUE rb_gsl_linalg_HH_solve_bang(int argc, VALUE *argv, VALUE obj)
|
3138
|
+
{
|
3139
|
+
gsl_matrix *A = NULL;
|
3140
|
+
gsl_vector *b = NULL, *x = NULL;
|
3141
|
+
int flagb = 0;
|
3142
|
+
VALUE vA, vb;
|
3143
|
+
switch (TYPE(obj)) {
|
3144
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
3145
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
|
3146
|
+
argc);
|
3147
|
+
vA = argv[0];
|
3148
|
+
vb = argv[1];
|
3149
|
+
break;
|
3150
|
+
default:
|
3151
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
3152
|
+
argc);
|
3153
|
+
vA = obj;
|
3154
|
+
vb = argv[0];
|
3155
|
+
break;
|
3156
|
+
}
|
3157
|
+
CHECK_MATRIX(vA);
|
3158
|
+
Data_Get_Struct(vA, gsl_matrix, A);
|
3159
|
+
if (TYPE(vb) == T_ARRAY) {
|
3160
|
+
b = make_cvector_from_rarray(vb);
|
3161
|
+
flagb = 1;
|
3162
|
+
} else {
|
3163
|
+
CHECK_VECTOR(vb);
|
3164
|
+
Data_Get_Struct(vb, gsl_vector, b);
|
3165
|
+
}
|
3166
|
+
x = gsl_vector_alloc(b->size);
|
3167
|
+
gsl_linalg_HH_solve(A, b, x);
|
3168
|
+
if (flagb == 1) gsl_vector_free(b);
|
3169
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
3170
|
+
}
|
3171
|
+
|
3172
|
+
static VALUE rb_gsl_linalg_HH_svx(int argc, VALUE *argv, VALUE obj)
|
3173
|
+
{
|
3174
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
3175
|
+
gsl_vector *b = NULL;
|
3176
|
+
VALUE vA, vb;
|
3177
|
+
switch (TYPE(obj)) {
|
3178
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
3179
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of argument (%d for 2)",
|
3180
|
+
argc);
|
3181
|
+
#ifdef HAVE_NARRAY_H
|
3182
|
+
if (NA_IsNArray(argv[0]))
|
3183
|
+
return rb_gsl_linalg_HH_svx_narray(argc, argv, obj);
|
3184
|
+
#endif
|
3185
|
+
vA = argv[0];
|
3186
|
+
vb = argv[1];
|
3187
|
+
break;
|
3188
|
+
default:
|
3189
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of argument (%d for 1)",
|
3190
|
+
argc);
|
3191
|
+
vA = obj;
|
3192
|
+
vb = argv[0];
|
3193
|
+
break;
|
3194
|
+
}
|
3195
|
+
CHECK_MATRIX(vA);
|
3196
|
+
Data_Get_Struct(vA, gsl_matrix, Atmp);
|
3197
|
+
CHECK_VECTOR(vb);
|
3198
|
+
Data_Get_Struct(vb, gsl_vector, b);
|
3199
|
+
A = make_matrix_clone(Atmp);
|
3200
|
+
gsl_linalg_HH_svx(A, b);
|
3201
|
+
gsl_matrix_free(A);
|
3202
|
+
return vb;
|
3203
|
+
}
|
3204
|
+
|
3205
|
+
static VALUE rb_gsl_linalg_solve_symm_tridiag(VALUE obj, VALUE dd, VALUE ee, VALUE bb)
|
3206
|
+
{
|
3207
|
+
gsl_vector *b = NULL, *x = NULL, *d = NULL, *e = NULL;
|
3208
|
+
|
3209
|
+
Data_Get_Struct(dd, gsl_vector, d);
|
3210
|
+
Data_Get_Struct(ee, gsl_vector, e);
|
3211
|
+
Data_Get_Struct(bb, gsl_vector, b);
|
3212
|
+
x = gsl_vector_alloc(b->size);
|
3213
|
+
|
3214
|
+
gsl_linalg_solve_symm_tridiag(d, e, b, x);
|
3215
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
3216
|
+
}
|
3217
|
+
|
3218
|
+
#ifdef GSL_1_2_LATER
|
3219
|
+
static VALUE rb_gsl_linalg_solve_tridiag(VALUE obj, VALUE dd, VALUE ee, VALUE ff,
|
3220
|
+
VALUE bb)
|
3221
|
+
{
|
3222
|
+
gsl_vector *b = NULL, *x = NULL, *d = NULL, *e = NULL, *f = NULL;
|
3223
|
+
|
3224
|
+
Data_Get_Struct(dd, gsl_vector, d);
|
3225
|
+
Data_Get_Struct(ee, gsl_vector, e);
|
3226
|
+
Data_Get_Struct(ff, gsl_vector, f);
|
3227
|
+
Data_Get_Struct(bb, gsl_vector, b);
|
3228
|
+
x = gsl_vector_alloc(b->size);
|
3229
|
+
|
3230
|
+
gsl_linalg_solve_tridiag(d, e, f, b, x);
|
3231
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
3232
|
+
}
|
3233
|
+
|
3234
|
+
static VALUE rb_gsl_linalg_solve_symm_cyc_tridiag(VALUE obj, VALUE dd, VALUE ee, VALUE bb)
|
3235
|
+
{
|
3236
|
+
gsl_vector *b = NULL, *x = NULL, *d = NULL, *e = NULL;
|
3237
|
+
|
3238
|
+
Data_Get_Struct(dd, gsl_vector, d);
|
3239
|
+
Data_Get_Struct(ee, gsl_vector, e);
|
3240
|
+
Data_Get_Struct(bb, gsl_vector, b);
|
3241
|
+
x = gsl_vector_alloc(b->size);
|
3242
|
+
|
3243
|
+
gsl_linalg_solve_symm_cyc_tridiag(d, e, b, x);
|
3244
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
3245
|
+
}
|
3246
|
+
|
3247
|
+
static VALUE rb_gsl_linalg_solve_cyc_tridiag(VALUE obj, VALUE dd, VALUE ee,
|
3248
|
+
VALUE ff, VALUE bb)
|
3249
|
+
{
|
3250
|
+
gsl_vector *b = NULL, *x = NULL, *d = NULL, *e = NULL, *f = NULL;
|
3251
|
+
Data_Get_Struct(dd, gsl_vector, d);
|
3252
|
+
Data_Get_Struct(ee, gsl_vector, e);
|
3253
|
+
Data_Get_Struct(ff, gsl_vector, f);
|
3254
|
+
Data_Get_Struct(bb, gsl_vector, b);
|
3255
|
+
x = gsl_vector_alloc(b->size);
|
3256
|
+
gsl_linalg_solve_cyc_tridiag(d, e, f, b, x);
|
3257
|
+
return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, x);
|
3258
|
+
}
|
3259
|
+
#endif
|
3260
|
+
|
3261
|
+
static void rb_gsl_linalg_balance_columns_init(int argc, VALUE *argv, VALUE obj,
|
3262
|
+
VALUE *mat, VALUE *vec,
|
3263
|
+
gsl_matrix **M, gsl_vector **V)
|
3264
|
+
{
|
3265
|
+
gsl_matrix *A = NULL;
|
3266
|
+
gsl_vector *D = NULL;
|
3267
|
+
switch (TYPE(obj)) {
|
3268
|
+
case T_MODULE: case T_CLASS: case T_OBJECT:
|
3269
|
+
switch (argc) {
|
3270
|
+
case 2:
|
3271
|
+
CHECK_MATRIX(argv[0]); CHECK_VECTOR(argv[1]);
|
3272
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3273
|
+
Data_Get_Struct(argv[1], gsl_vector, D);
|
3274
|
+
*vec = argv[1];
|
3275
|
+
break;
|
3276
|
+
case 1:
|
3277
|
+
CHECK_MATRIX(argv[0]);
|
3278
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3279
|
+
D = gsl_vector_alloc(A->size2);
|
3280
|
+
*vec = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, D);
|
3281
|
+
break;
|
3282
|
+
default:
|
3283
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
3284
|
+
break;
|
3285
|
+
}
|
3286
|
+
*mat = argv[0];
|
3287
|
+
break;
|
3288
|
+
default:
|
3289
|
+
Data_Get_Struct(obj, gsl_matrix, A);
|
3290
|
+
switch (argc) {
|
3291
|
+
case 1:
|
3292
|
+
CHECK_VECTOR(argv[0]);
|
3293
|
+
Data_Get_Struct(argv[0], gsl_vector, D);
|
3294
|
+
*vec = argv[0];
|
3295
|
+
break;
|
3296
|
+
case 0:
|
3297
|
+
D = gsl_vector_alloc(A->size2);
|
3298
|
+
*vec = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, D);
|
3299
|
+
break;
|
3300
|
+
default:
|
3301
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
3302
|
+
break;
|
3303
|
+
}
|
3304
|
+
*mat = obj;
|
3305
|
+
break;
|
3306
|
+
}
|
3307
|
+
*M = A;
|
3308
|
+
*V = D;
|
3309
|
+
}
|
3310
|
+
|
3311
|
+
static VALUE rb_gsl_linalg_balance_columns_bang(int argc, VALUE *argv, VALUE obj)
|
3312
|
+
{
|
3313
|
+
gsl_matrix *A = NULL;
|
3314
|
+
gsl_vector *D = NULL;
|
3315
|
+
VALUE mat, vec;
|
3316
|
+
// local variable "status" was defined and set, but never used
|
3317
|
+
//int status;
|
3318
|
+
rb_gsl_linalg_balance_columns_init(argc, argv, obj, &mat, &vec, &A, &D);
|
3319
|
+
/*status =*/ gsl_linalg_balance_columns(A, D);
|
3320
|
+
return rb_ary_new3(2, mat, vec);
|
3321
|
+
}
|
3322
|
+
|
3323
|
+
static VALUE rb_gsl_linalg_balance_columns(int argc, VALUE *argv, VALUE obj)
|
3324
|
+
{
|
3325
|
+
gsl_matrix *A = NULL, *Anew;
|
3326
|
+
gsl_vector *D = NULL;
|
3327
|
+
VALUE mat, vec;
|
3328
|
+
// local variable "status" was defined and set, but never used
|
3329
|
+
//int status;
|
3330
|
+
rb_gsl_linalg_balance_columns_init(argc, argv, obj, &mat, &vec, &A, &D);
|
3331
|
+
Anew = make_matrix_clone(A);
|
3332
|
+
mat = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Anew);
|
3333
|
+
/*status =*/ gsl_linalg_balance_columns(Anew, D);
|
3334
|
+
return rb_ary_new3(2, mat, vec);
|
3335
|
+
}
|
3336
|
+
|
3337
|
+
#ifdef HAVE_NARRAY_H
|
3338
|
+
static VALUE rb_gsl_linalg_QR_decomp_narray(int argc, VALUE *argv, VALUE obj)
|
3339
|
+
{
|
3340
|
+
struct NARRAY *na;
|
3341
|
+
gsl_matrix_view mv;
|
3342
|
+
gsl_vector_view vv;
|
3343
|
+
int shapem[2], shapev[1];
|
3344
|
+
VALUE qr, tau;
|
3345
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments.");
|
3346
|
+
GetNArray(argv[0], na);
|
3347
|
+
shapem[0] = na->shape[1];
|
3348
|
+
shapem[1] = na->shape[1];
|
3349
|
+
shapev[0] = shapem[0];
|
3350
|
+
qr = na_make_object(NA_DFLOAT, 2, shapem, CLASS_OF(argv[0]));
|
3351
|
+
tau = na_make_object(NA_DFLOAT, 1, shapev, cNVector);
|
3352
|
+
memcpy(NA_PTR_TYPE(qr,double*),na->ptr,sizeof(double)*shapem[0]*shapem[1]);
|
3353
|
+
mv = gsl_matrix_view_array(NA_PTR_TYPE(qr,double*), shapem[0], shapem[1]);
|
3354
|
+
vv = gsl_vector_view_array(NA_PTR_TYPE(tau,double*), shapev[0]);
|
3355
|
+
gsl_linalg_QR_decomp(&mv.matrix, &vv.vector);
|
3356
|
+
return rb_ary_new3(2, qr, tau);
|
3357
|
+
}
|
3358
|
+
|
3359
|
+
static VALUE rb_gsl_linalg_QR_unpack_narray(int argc, VALUE *argv, VALUE obj)
|
3360
|
+
{
|
3361
|
+
struct NARRAY *m, *tau;
|
3362
|
+
gsl_matrix_view mv, mq, mr;
|
3363
|
+
gsl_vector_view vv;
|
3364
|
+
int shape[2];
|
3365
|
+
VALUE q, r;
|
3366
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
3367
|
+
argc);
|
3368
|
+
GetNArray(argv[0], m);
|
3369
|
+
GetNArray(argv[1], tau);
|
3370
|
+
mv = gsl_matrix_view_array((double*)m->ptr, m->shape[1], m->shape[0]);
|
3371
|
+
vv = gsl_vector_view_array((double*)tau->ptr, tau->shape[0]);
|
3372
|
+
shape[0] = m->shape[1];
|
3373
|
+
shape[1] = m->shape[1];
|
3374
|
+
q = na_make_object(NA_DFLOAT, 2, shape, CLASS_OF(argv[0]));
|
3375
|
+
shape[0] = m->shape[1];
|
3376
|
+
shape[1] = m->shape[0];
|
3377
|
+
r = na_make_object(NA_DFLOAT, 2, shape, CLASS_OF(argv[0]));
|
3378
|
+
mq = gsl_matrix_view_array(NA_PTR_TYPE(q,double*), m->shape[1], m->shape[1]);
|
3379
|
+
mr = gsl_matrix_view_array(NA_PTR_TYPE(r,double*), m->shape[1], m->shape[0]);
|
3380
|
+
// printf("OK 4 %d %d\n", mq.matrix.size1, mr.matrix.size2);
|
3381
|
+
gsl_linalg_QR_unpack(&mv.matrix, &vv.vector, &mq.matrix, &mr.matrix);
|
3382
|
+
// printf("OK 5\n");
|
3383
|
+
return rb_ary_new3(2, q, r);
|
3384
|
+
}
|
3385
|
+
|
3386
|
+
static VALUE rb_gsl_linalg_QR_solve_narray(int argc, VALUE *argv, VALUE obj)
|
3387
|
+
{
|
3388
|
+
struct NARRAY *qr, *tau, *b;
|
3389
|
+
VALUE x;
|
3390
|
+
gsl_matrix_view mv;
|
3391
|
+
gsl_vector_view tv, bv, xv;
|
3392
|
+
if (argc != 3) rb_raise(rb_eArgError, "Usage: QR.solve(qr, tau, b)");
|
3393
|
+
GetNArray(argv[0], qr);
|
3394
|
+
GetNArray(argv[1], tau);
|
3395
|
+
GetNArray(argv[2], b);
|
3396
|
+
x = na_make_object(NA_DFLOAT, 1, b->shape, CLASS_OF(argv[2]));
|
3397
|
+
mv = gsl_matrix_view_array((double*)qr->ptr, qr->shape[1], qr->shape[0]);
|
3398
|
+
tv = gsl_vector_view_array((double*)tau->ptr, tau->shape[0]);
|
3399
|
+
bv = gsl_vector_view_array((double*)b->ptr, b->shape[0]);
|
3400
|
+
xv = gsl_vector_view_array(NA_PTR_TYPE(x,double*), b->shape[0]);
|
3401
|
+
gsl_linalg_QR_solve(&mv.matrix, &tv.vector, &bv.vector, &xv.vector);
|
3402
|
+
return x;
|
3403
|
+
}
|
3404
|
+
static VALUE rb_gsl_linalg_QR_svx_narray(int argc, VALUE *argv, VALUE obj)
|
3405
|
+
{
|
3406
|
+
struct NARRAY *qr, *tau, *b;
|
3407
|
+
gsl_matrix_view mv;
|
3408
|
+
gsl_vector_view tv, bv;
|
3409
|
+
if (argc != 3) rb_raise(rb_eArgError, "Usage: QR.solve(qr, tau, b)");
|
3410
|
+
GetNArray(argv[0], qr);
|
3411
|
+
GetNArray(argv[1], tau);
|
3412
|
+
GetNArray(argv[2], b);
|
3413
|
+
mv = gsl_matrix_view_array((double*)qr->ptr, qr->shape[1], qr->shape[0]);
|
3414
|
+
tv = gsl_vector_view_array((double*)tau->ptr, tau->shape[0]);
|
3415
|
+
bv = gsl_vector_view_array((double*)b->ptr, b->shape[0]);
|
3416
|
+
gsl_linalg_QR_svx(&mv.matrix, &tv.vector, &bv.vector);
|
3417
|
+
return argv[2];
|
3418
|
+
}
|
3419
|
+
|
3420
|
+
#endif
|
3421
|
+
|
3422
|
+
#ifdef GSL_1_9_LATER
|
3423
|
+
static VALUE rb_gsl_linalg_hessenberg_decomp(VALUE module, VALUE AA)
|
3424
|
+
{
|
3425
|
+
gsl_matrix *A = NULL, *Atmp = NULL;
|
3426
|
+
gsl_vector *tau = NULL;
|
3427
|
+
VALUE vH, vtau;
|
3428
|
+
CHECK_MATRIX(AA);
|
3429
|
+
Data_Get_Struct(AA, gsl_matrix, Atmp);
|
3430
|
+
A = make_matrix_clone(Atmp);
|
3431
|
+
tau = gsl_vector_alloc(A->size1);
|
3432
|
+
gsl_linalg_hessenberg_decomp(A, tau);
|
3433
|
+
vH = Data_Wrap_Struct(cgsl_matrix_Q, 0, gsl_matrix_free, A);
|
3434
|
+
vtau = Data_Wrap_Struct(cgsl_vector_tau, 0, gsl_vector_free, tau);
|
3435
|
+
return rb_ary_new3(2, vH, vtau);
|
3436
|
+
}
|
3437
|
+
|
3438
|
+
static VALUE rb_gsl_linalg_hessenberg_unpack(VALUE module, VALUE HH, VALUE tt)
|
3439
|
+
{
|
3440
|
+
gsl_matrix *H = NULL, *U = NULL;
|
3441
|
+
gsl_vector *tau = NULL;
|
3442
|
+
CHECK_MATRIX(HH);
|
3443
|
+
CHECK_VECTOR(tt);
|
3444
|
+
Data_Get_Struct(HH, gsl_matrix, H);
|
3445
|
+
Data_Get_Struct(tt, gsl_vector, tau);
|
3446
|
+
U = gsl_matrix_alloc(H->size1, H->size2);
|
3447
|
+
gsl_linalg_hessenberg_unpack(H, tau, U);
|
3448
|
+
|
3449
|
+
return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, U);
|
3450
|
+
}
|
3451
|
+
|
3452
|
+
static VALUE rb_gsl_linalg_hessenberg_unpack_accum(int argc, VALUE *argv, VALUE module)
|
3453
|
+
{
|
3454
|
+
gsl_matrix *H = NULL, *V = NULL;
|
3455
|
+
gsl_vector *tau = NULL;
|
3456
|
+
size_t i;
|
3457
|
+
VALUE val;
|
3458
|
+
switch (argc) {
|
3459
|
+
case 2:
|
3460
|
+
/* nothing to do */
|
3461
|
+
break;
|
3462
|
+
case 3:
|
3463
|
+
CHECK_MATRIX(argv[2]);
|
3464
|
+
Data_Get_Struct(argv[2], gsl_matrix, V);
|
3465
|
+
val = argv[2];
|
3466
|
+
break;
|
3467
|
+
default:
|
3468
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 2 or 3)", argc);
|
3469
|
+
}
|
3470
|
+
CHECK_MATRIX(argv[0]);
|
3471
|
+
CHECK_VECTOR(argv[1]);
|
3472
|
+
Data_Get_Struct(argv[0], gsl_matrix, H);
|
3473
|
+
Data_Get_Struct(argv[1], gsl_vector, tau);
|
3474
|
+
if (argc == 2) {
|
3475
|
+
V = gsl_matrix_alloc(H->size1, H->size2);
|
3476
|
+
val = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, V);
|
3477
|
+
for (i = 0; i < V->size1; i++) gsl_matrix_set(V, i, i, 1.0);
|
3478
|
+
}
|
3479
|
+
gsl_linalg_hessenberg_unpack_accum(H, tau, V);
|
3480
|
+
return val;
|
3481
|
+
}
|
3482
|
+
static VALUE rb_gsl_linalg_hessenberg_set_zero(VALUE module, VALUE HH)
|
3483
|
+
{
|
3484
|
+
gsl_matrix *H;
|
3485
|
+
CHECK_MATRIX(HH);
|
3486
|
+
Data_Get_Struct(HH, gsl_matrix, H);
|
3487
|
+
return INT2FIX(gsl_linalg_hessenberg_set_zero(H));
|
3488
|
+
/* gsl_linalg_hessenberg_set_zero(H);
|
3489
|
+
return INT2FIX(0);*/
|
3490
|
+
}
|
3491
|
+
static VALUE rb_gsl_linalg_hesstri_decomp(int argc, VALUE *argv, VALUE module)
|
3492
|
+
{
|
3493
|
+
gsl_matrix *A = NULL, *B = NULL, *Anew, *Bnew;
|
3494
|
+
gsl_matrix *U = NULL, *V = NULL;
|
3495
|
+
gsl_vector *work = NULL;
|
3496
|
+
VALUE vH, vR, vU, vV, ary;
|
3497
|
+
int flag = 0;
|
3498
|
+
switch (argc) {
|
3499
|
+
case 2:
|
3500
|
+
flag = 1;
|
3501
|
+
break;
|
3502
|
+
case 3:
|
3503
|
+
CHECK_VECTOR(argv[2]);
|
3504
|
+
Data_Get_Struct(argv[2], gsl_vector, work);
|
3505
|
+
break;
|
3506
|
+
case 4:
|
3507
|
+
CHECK_MATRIX(argv[2]);
|
3508
|
+
CHECK_MATRIX(argv[3]);
|
3509
|
+
Data_Get_Struct(argv[2], gsl_matrix, U);
|
3510
|
+
Data_Get_Struct(argv[3], gsl_matrix, V);
|
3511
|
+
flag = 1;
|
3512
|
+
break;
|
3513
|
+
case 5:
|
3514
|
+
CHECK_MATRIX(argv[2]);
|
3515
|
+
CHECK_MATRIX(argv[3]);
|
3516
|
+
CHECK_VECTOR(argv[4]);
|
3517
|
+
Data_Get_Struct(argv[2], gsl_matrix, U);
|
3518
|
+
Data_Get_Struct(argv[3], gsl_matrix, V);
|
3519
|
+
Data_Get_Struct(argv[4], gsl_vector, work);
|
3520
|
+
vU = argv[2];
|
3521
|
+
vV = argv[3];
|
3522
|
+
break;
|
3523
|
+
default:
|
3524
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 2-55)", argc);
|
3525
|
+
}
|
3526
|
+
CHECK_MATRIX(argv[0]);
|
3527
|
+
CHECK_MATRIX(argv[1]);
|
3528
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3529
|
+
Data_Get_Struct(argv[1], gsl_matrix, B);
|
3530
|
+
Anew = make_matrix_clone(A);
|
3531
|
+
Bnew = make_matrix_clone(B);
|
3532
|
+
if (flag == 1) work = gsl_vector_alloc(A->size1);
|
3533
|
+
gsl_linalg_hesstri_decomp(Anew, Bnew, U, V, work);
|
3534
|
+
if (flag == 1) gsl_vector_free(work);
|
3535
|
+
vH = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Anew);
|
3536
|
+
vR = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Bnew);
|
3537
|
+
if (argc == 2 || argc == 3) {
|
3538
|
+
ary = rb_ary_new3(2, vH, vR);
|
3539
|
+
} else {
|
3540
|
+
ary = rb_ary_new3(4, vH, vR, vU, vV);
|
3541
|
+
}
|
3542
|
+
return ary;
|
3543
|
+
}
|
3544
|
+
static VALUE rb_gsl_linalg_hesstri_decomp_bang(int argc, VALUE *argv, VALUE module)
|
3545
|
+
{
|
3546
|
+
gsl_matrix *A = NULL, *B = NULL;
|
3547
|
+
gsl_matrix *U = NULL, *V = NULL;
|
3548
|
+
gsl_vector *work = NULL;
|
3549
|
+
VALUE vH, vR, vU, vV, ary;
|
3550
|
+
int flag = 0;
|
3551
|
+
switch (argc) {
|
3552
|
+
case 2:
|
3553
|
+
flag = 1;
|
3554
|
+
break;
|
3555
|
+
case 3:
|
3556
|
+
CHECK_VECTOR(argv[2]);
|
3557
|
+
Data_Get_Struct(argv[2], gsl_vector, work);
|
3558
|
+
break;
|
3559
|
+
case 4:
|
3560
|
+
CHECK_MATRIX(argv[2]);
|
3561
|
+
CHECK_MATRIX(argv[3]);
|
3562
|
+
Data_Get_Struct(argv[2], gsl_matrix, U);
|
3563
|
+
Data_Get_Struct(argv[3], gsl_matrix, V);
|
3564
|
+
flag = 1;
|
3565
|
+
break;
|
3566
|
+
case 5:
|
3567
|
+
CHECK_MATRIX(argv[2]);
|
3568
|
+
CHECK_MATRIX(argv[3]);
|
3569
|
+
CHECK_VECTOR(argv[4]);
|
3570
|
+
Data_Get_Struct(argv[2], gsl_matrix, U);
|
3571
|
+
Data_Get_Struct(argv[3], gsl_matrix, V);
|
3572
|
+
Data_Get_Struct(argv[4], gsl_vector, work);
|
3573
|
+
vU = argv[2];
|
3574
|
+
vV = argv[3];
|
3575
|
+
break;
|
3576
|
+
default:
|
3577
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 2-55)", argc);
|
3578
|
+
}
|
3579
|
+
CHECK_MATRIX(argv[0]);
|
3580
|
+
CHECK_MATRIX(argv[1]);
|
3581
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3582
|
+
Data_Get_Struct(argv[1], gsl_matrix, B);
|
3583
|
+
if (flag == 1) work = gsl_vector_alloc(A->size1);
|
3584
|
+
gsl_linalg_hesstri_decomp(A, B, U, V, work);
|
3585
|
+
if (flag == 1) gsl_vector_free(work);
|
3586
|
+
vH = argv[0];
|
3587
|
+
vR = argv[1];
|
3588
|
+
if (argc == 2 || argc == 3) {
|
3589
|
+
ary = rb_ary_new3(2, vH, vR);
|
3590
|
+
} else {
|
3591
|
+
ary = rb_ary_new3(4, vH, vR, vU, vV);
|
3592
|
+
}
|
3593
|
+
return ary;
|
3594
|
+
}
|
3595
|
+
|
3596
|
+
static VALUE rb_gsl_linalg_balance_matrix(int argc, VALUE *argv, VALUE module)
|
3597
|
+
{
|
3598
|
+
gsl_matrix *A, *Anew;
|
3599
|
+
gsl_vector *D;
|
3600
|
+
VALUE vA, vD;
|
3601
|
+
switch (argc) {
|
3602
|
+
case 1:
|
3603
|
+
CHECK_MATRIX(argv[0]);
|
3604
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3605
|
+
Anew = make_matrix_clone(A);
|
3606
|
+
D = gsl_vector_alloc(A->size1);
|
3607
|
+
vD = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, D);
|
3608
|
+
break;
|
3609
|
+
case 2:
|
3610
|
+
CHECK_MATRIX(argv[0]);
|
3611
|
+
CHECK_VECTOR(argv[1]);
|
3612
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3613
|
+
Data_Get_Struct(argv[1], gsl_vector, D);
|
3614
|
+
Anew = make_matrix_clone(A);
|
3615
|
+
vD = argv[1];
|
3616
|
+
break;
|
3617
|
+
default:
|
3618
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)", argc);
|
3619
|
+
}
|
3620
|
+
gsl_linalg_balance_matrix(Anew, D);
|
3621
|
+
vA = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Anew);
|
3622
|
+
return rb_ary_new3(2, vA, vD);
|
3623
|
+
|
3624
|
+
}
|
3625
|
+
static VALUE rb_gsl_linalg_balance_matrix2(int argc, VALUE *argv, VALUE module)
|
3626
|
+
{
|
3627
|
+
gsl_matrix *A;
|
3628
|
+
gsl_vector *D;
|
3629
|
+
switch (argc) {
|
3630
|
+
case 1:
|
3631
|
+
CHECK_MATRIX(argv[0]);
|
3632
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3633
|
+
D = gsl_vector_alloc(A->size1);
|
3634
|
+
gsl_linalg_balance_matrix(A, D);
|
3635
|
+
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, D);
|
3636
|
+
break;
|
3637
|
+
case 2:
|
3638
|
+
CHECK_MATRIX(argv[0]);
|
3639
|
+
CHECK_VECTOR(argv[1]);
|
3640
|
+
Data_Get_Struct(argv[0], gsl_matrix, A);
|
3641
|
+
Data_Get_Struct(argv[1], gsl_vector, D);
|
3642
|
+
return INT2FIX(gsl_linalg_balance_matrix(A, D));
|
3643
|
+
break;
|
3644
|
+
default:
|
3645
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)", argc);
|
3646
|
+
}
|
3647
|
+
return Qtrue;
|
3648
|
+
}
|
3649
|
+
#endif
|
3650
|
+
|
3651
|
+
void Init_gsl_linalg_complex(VALUE module);
|
3652
|
+
void Init_gsl_linalg(VALUE module)
|
3653
|
+
{
|
3654
|
+
VALUE mgsl_linalg;
|
3655
|
+
VALUE mgsl_linalg_LU;
|
3656
|
+
VALUE mgsl_linalg_QR;
|
3657
|
+
VALUE mgsl_linalg_QRPT;
|
3658
|
+
VALUE mgsl_linalg_LQ;
|
3659
|
+
VALUE mgsl_linalg_PTLQ;
|
3660
|
+
VALUE mgsl_linalg_SV;
|
3661
|
+
VALUE mgsl_linalg_cholesky;
|
3662
|
+
VALUE mgsl_linalg_symmtd;
|
3663
|
+
VALUE mgsl_linalg_hermtd;
|
3664
|
+
VALUE mgsl_linalg_bidiag;
|
3665
|
+
VALUE mgsl_linalg_tridiag;
|
3666
|
+
VALUE mgsl_linalg_HH;
|
3667
|
+
VALUE mgsl_linalg_Householder;
|
3668
|
+
|
3669
|
+
mgsl_linalg = rb_define_module_under(module, "Linalg");
|
3670
|
+
mgsl_linalg_LU = rb_define_module_under(mgsl_linalg, "LU");
|
3671
|
+
cgsl_matrix_LU = rb_define_class_under(mgsl_linalg_LU, "LUMatrix", cgsl_matrix);
|
3672
|
+
mgsl_linalg_QR = rb_define_module_under(mgsl_linalg, "QR");
|
3673
|
+
mgsl_linalg_QRPT = rb_define_module_under(mgsl_linalg, "QRPT");
|
3674
|
+
cgsl_matrix_QR = rb_define_class_under(mgsl_linalg, "QRMatrix", cgsl_matrix);
|
3675
|
+
cgsl_matrix_QRPT = rb_define_class_under(mgsl_linalg, "QRPTMatrix", cgsl_matrix);
|
3676
|
+
cgsl_vector_tau = rb_define_class_under(mgsl_linalg, "TauVector", cgsl_vector);
|
3677
|
+
cgsl_matrix_Q = rb_define_class_under(mgsl_linalg, "QMatrix", cgsl_matrix);
|
3678
|
+
cgsl_matrix_R = rb_define_class_under(mgsl_linalg, "RMatrix", cgsl_matrix);
|
3679
|
+
|
3680
|
+
mgsl_linalg_LQ = rb_define_module_under(mgsl_linalg, "LQ");
|
3681
|
+
mgsl_linalg_PTLQ = rb_define_module_under(mgsl_linalg, "PTLQ");
|
3682
|
+
cgsl_matrix_LQ = rb_define_class_under(mgsl_linalg, "LQMatrix", cgsl_matrix);
|
3683
|
+
cgsl_matrix_PTLQ = rb_define_class_under(mgsl_linalg, "PTLQMatrix", cgsl_matrix);
|
3684
|
+
cgsl_matrix_L = rb_define_class_under(mgsl_linalg, "LMatrix", cgsl_matrix);
|
3685
|
+
|
3686
|
+
/*****/
|
3687
|
+
mgsl_linalg_SV = rb_define_module_under(mgsl_linalg, "SV");
|
3688
|
+
cgsl_matrix_SV = rb_define_class_under(mgsl_linalg_SV, "SVMatrix", cgsl_matrix);
|
3689
|
+
cgsl_matrix_U = rb_define_class_under(mgsl_linalg_SV, "UMatrix", cgsl_matrix);
|
3690
|
+
cgsl_matrix_V = rb_define_class_under(mgsl_linalg_SV, "VMatrix", cgsl_matrix);
|
3691
|
+
cgsl_vector_S = rb_define_class_under(mgsl_linalg_SV, "SingularValues", cgsl_vector);
|
3692
|
+
|
3693
|
+
/*****/
|
3694
|
+
mgsl_linalg_cholesky = rb_define_module_under(mgsl_linalg, "Cholesky");
|
3695
|
+
cgsl_matrix_C = rb_define_class_under(mgsl_linalg_cholesky, "CholeskyMatrix", cgsl_matrix);
|
3696
|
+
mgsl_linalg_symmtd = rb_define_module_under(mgsl_linalg, "Symmtd");
|
3697
|
+
|
3698
|
+
mgsl_linalg_hermtd = rb_define_module_under(mgsl_linalg, "Hermtd");
|
3699
|
+
mgsl_linalg_bidiag = rb_define_module_under(mgsl_linalg, "Bidiag");
|
3700
|
+
mgsl_linalg_tridiag = rb_define_module_under(mgsl_linalg, "Tridiag");
|
3701
|
+
|
3702
|
+
mgsl_linalg_HH = rb_define_module_under(mgsl_linalg, "HH");
|
3703
|
+
mgsl_linalg_Householder = rb_define_module_under(mgsl_linalg, "Householder");
|
3704
|
+
|
3705
|
+
/*****/
|
3706
|
+
rb_define_module_function(mgsl_linalg, "LU_decomp!", rb_gsl_linalg_LU_decomp_bang, -1);
|
3707
|
+
rb_define_module_function(mgsl_linalg_LU, "decomp!", rb_gsl_linalg_LU_decomp_bang, -1);
|
3708
|
+
rb_define_module_function(mgsl_linalg, "LU_decomp", rb_gsl_linalg_LU_decomp, -1);
|
3709
|
+
rb_define_module_function(mgsl_linalg_LU, "decomp", rb_gsl_linalg_LU_decomp, -1);
|
3710
|
+
rb_define_method(cgsl_matrix, "LU_decomp!", rb_gsl_linalg_LU_decomp_bang, -1);
|
3711
|
+
rb_define_method(cgsl_matrix, "LU_decomp", rb_gsl_linalg_LU_decomp, -1);
|
3712
|
+
|
3713
|
+
rb_define_module_function(mgsl_linalg, "LU_solve", rb_gsl_linalg_LU_solve, -1);
|
3714
|
+
rb_define_module_function(mgsl_linalg_LU, "solve", rb_gsl_linalg_LU_solve, -1);
|
3715
|
+
rb_define_method(cgsl_matrix, "LU_solve", rb_gsl_linalg_LU_solve, -1);
|
3716
|
+
rb_define_method(cgsl_matrix_LU, "solve", rb_gsl_linalg_LU_solve, -1);
|
3717
|
+
|
3718
|
+
rb_define_module_function(mgsl_linalg, "LU_svx", rb_gsl_linalg_LU_svx, -1);
|
3719
|
+
rb_define_module_function(mgsl_linalg_LU, "svx", rb_gsl_linalg_LU_svx, -1);
|
3720
|
+
rb_define_method(cgsl_matrix, "LU_svx", rb_gsl_linalg_LU_svx, -1);
|
3721
|
+
rb_define_method(cgsl_matrix_LU, "svx", rb_gsl_linalg_LU_svx, -1);
|
3722
|
+
|
3723
|
+
rb_define_module_function(mgsl_linalg, "LU_invert", rb_gsl_linalg_LU_invert, -1);
|
3724
|
+
rb_define_module_function(mgsl_linalg_LU, "invert", rb_gsl_linalg_LU_invert, -1);
|
3725
|
+
rb_define_module_function(mgsl_linalg_LU, "inv", rb_gsl_linalg_LU_invert, -1);
|
3726
|
+
rb_define_module_function(mgsl_linalg_LU, "refine", rb_gsl_linalg_LU_refine, 5);
|
3727
|
+
|
3728
|
+
rb_define_method(cgsl_matrix, "invert", rb_gsl_linalg_LU_invert, -1);
|
3729
|
+
rb_define_alias(cgsl_matrix, "LU_invert", "invert");
|
3730
|
+
rb_define_alias(cgsl_matrix, "inv", "invert");
|
3731
|
+
|
3732
|
+
rb_define_module_function(mgsl_linalg, "LU_det", rb_gsl_linalg_LU_det, -1);
|
3733
|
+
rb_define_module_function(mgsl_linalg_LU, "det", rb_gsl_linalg_LU_det, -1);
|
3734
|
+
rb_define_method(cgsl_matrix, "LU_det", rb_gsl_linalg_LU_det, -1);
|
3735
|
+
rb_define_alias(cgsl_matrix, "det", "LU_det");
|
3736
|
+
|
3737
|
+
rb_define_module_function(mgsl_linalg, "LU_lndet", rb_gsl_linalg_LU_lndet, -1);
|
3738
|
+
rb_define_module_function(mgsl_linalg_LU, "lndet", rb_gsl_linalg_LU_lndet, -1);
|
3739
|
+
rb_define_method(cgsl_matrix, "LU_lndet", rb_gsl_linalg_LU_lndet, -1);
|
3740
|
+
rb_define_alias(cgsl_matrix, "lndet", "LU_lndet");
|
3741
|
+
|
3742
|
+
rb_define_module_function(mgsl_linalg, "LU_sgndet", rb_gsl_linalg_LU_sgndet, -1);
|
3743
|
+
rb_define_module_function(mgsl_linalg_LU, "sgndet", rb_gsl_linalg_LU_sgndet, -1);
|
3744
|
+
rb_define_method(cgsl_matrix, "LU_sgndet", rb_gsl_linalg_LU_sgndet, -1);
|
3745
|
+
rb_define_alias(cgsl_matrix, "sgndet", "LU_sgndet");
|
3746
|
+
|
3747
|
+
/*****/
|
3748
|
+
rb_define_module_function(mgsl_linalg, "QR_decomp", rb_gsl_linalg_QR_decomp, -1);
|
3749
|
+
rb_define_module_function(mgsl_linalg_QR, "decomp", rb_gsl_linalg_QR_decomp, -1);
|
3750
|
+
rb_define_method(cgsl_matrix, "QR_decomp", rb_gsl_linalg_QR_decomp, -1);
|
3751
|
+
rb_define_module_function(mgsl_linalg, "QR_decomp!", rb_gsl_linalg_QR_decomp_bang, -1);
|
3752
|
+
rb_define_module_function(mgsl_linalg_QR, "decomp!", rb_gsl_linalg_QR_decomp_bang, -1);
|
3753
|
+
rb_define_method(cgsl_matrix, "QR_decomp!", rb_gsl_linalg_QR_decomp_bang, -1);
|
3754
|
+
|
3755
|
+
rb_define_module_function(mgsl_linalg, "QR_solve", rb_gsl_linalg_QR_solve, -1);
|
3756
|
+
rb_define_module_function(mgsl_linalg_QR, "solve", rb_gsl_linalg_QR_solve, -1);
|
3757
|
+
rb_define_module_function(mgsl_linalg, "QR_svx", rb_gsl_linalg_QR_svx, -1);
|
3758
|
+
rb_define_module_function(mgsl_linalg_QR, "svx", rb_gsl_linalg_QR_svx, -1);
|
3759
|
+
rb_define_method(cgsl_matrix, "QR_solve", rb_gsl_linalg_QR_solve, -1);
|
3760
|
+
rb_define_method(cgsl_matrix_QR, "solve", rb_gsl_linalg_QR_solve, -1);
|
3761
|
+
rb_define_method(cgsl_matrix, "QR_svx", rb_gsl_linalg_QR_svx, -1);
|
3762
|
+
rb_define_method(cgsl_matrix_QR, "svx", rb_gsl_linalg_QR_svx, -1);
|
3763
|
+
|
3764
|
+
rb_define_module_function(mgsl_linalg_QR, "lssolve", rb_gsl_linalg_QR_lssolve, -1);
|
3765
|
+
rb_define_method(cgsl_matrix, "QR_lssolve", rb_gsl_linalg_QR_lssolve, -1);
|
3766
|
+
rb_define_method(cgsl_matrix_QR, "lssolve", rb_gsl_linalg_QR_lssolve, -1);
|
3767
|
+
|
3768
|
+
rb_define_module_function(mgsl_linalg_QR, "QTvec", rb_gsl_linalg_QR_QTvec, -1);
|
3769
|
+
rb_define_method(cgsl_matrix_QR, "QTvec", rb_gsl_linalg_QR_QTvec, -1);
|
3770
|
+
rb_define_module_function(mgsl_linalg_QR, "Qvec", rb_gsl_linalg_QR_Qvec, -1);
|
3771
|
+
rb_define_method(cgsl_matrix_QR, "Qvec", rb_gsl_linalg_QR_Qvec, -1);
|
3772
|
+
|
3773
|
+
rb_define_module_function(mgsl_linalg_QR, "Rsolve", rb_gsl_linalg_QR_Rsolve, -1);
|
3774
|
+
rb_define_method(cgsl_matrix, "QR_Rsolve", rb_gsl_linalg_QR_Rsolve, -1);
|
3775
|
+
rb_define_method(cgsl_matrix_QR, "Rsolve", rb_gsl_linalg_QR_Rsolve, -1);
|
3776
|
+
|
3777
|
+
rb_define_module_function(mgsl_linalg_QR, "Rsvx", rb_gsl_linalg_QR_Rsvx, -1);
|
3778
|
+
rb_define_method(cgsl_matrix_QR, "Rsvx", rb_gsl_linalg_QR_Rsvx, 1);
|
3779
|
+
|
3780
|
+
rb_define_module_function(mgsl_linalg_QR, "unpack", rb_gsl_linalg_QR_unpack, -1);
|
3781
|
+
rb_define_method(cgsl_matrix_QR, "unpack", rb_gsl_linalg_QR_unpack, -1);
|
3782
|
+
|
3783
|
+
rb_define_module_function(mgsl_linalg_QR, "QRsolve", rb_gsl_linalg_QR_QRsolve, -1);
|
3784
|
+
rb_define_module_function(mgsl_linalg_QR, "update", rb_gsl_linalg_QR_update, 4);
|
3785
|
+
|
3786
|
+
rb_define_method(mgsl_linalg, "R_solve", rb_gsl_linalg_R_solve, -1);
|
3787
|
+
rb_define_method(cgsl_matrix_R, "solve", rb_gsl_linalg_R_solve, -1);
|
3788
|
+
/*
|
3789
|
+
rb_define_method(cgsl_matrix_R, "svx", rb_gsl_linalg_R_svx, -1);
|
3790
|
+
*/
|
3791
|
+
rb_define_module_function(mgsl_linalg_QRPT, "decomp", rb_gsl_linalg_QRPT_decomp, -1);
|
3792
|
+
rb_define_method(cgsl_matrix, "QRPT_decomp", rb_gsl_linalg_QRPT_decomp, -1);
|
3793
|
+
rb_define_module_function(mgsl_linalg_QRPT, "decomp!", rb_gsl_linalg_QRPT_decomp_bang, -1);
|
3794
|
+
rb_define_method(cgsl_matrix, "QRPT_decomp!", rb_gsl_linalg_QRPT_decomp_bang, -1);
|
3795
|
+
|
3796
|
+
rb_define_module_function(mgsl_linalg_QRPT, "decomp2", rb_gsl_linalg_QRPT_decomp2, -1);
|
3797
|
+
rb_define_method(cgsl_matrix, "QRPT_decomp2", rb_gsl_linalg_QRPT_decomp2, -1);
|
3798
|
+
|
3799
|
+
rb_define_module_function(mgsl_linalg_QRPT, "solve", rb_gsl_linalg_QRPT_solve, -1);
|
3800
|
+
rb_define_method(cgsl_matrix, "QRPT_solve", rb_gsl_linalg_QRPT_solve, -1);
|
3801
|
+
rb_define_method(cgsl_matrix_QRPT, "solve", rb_gsl_linalg_QRPT_solve, -1);
|
3802
|
+
|
3803
|
+
rb_define_module_function(mgsl_linalg_QRPT, "svx", rb_gsl_linalg_QRPT_svx, -1);
|
3804
|
+
rb_define_method(cgsl_matrix, "QRPT_svx", rb_gsl_linalg_QRPT_svx, -1);
|
3805
|
+
rb_define_method(cgsl_matrix_QRPT, "svx", rb_gsl_linalg_QRPT_svx, -1);
|
3806
|
+
|
3807
|
+
rb_define_module_function(mgsl_linalg_QRPT, "QRsolve", rb_gsl_linalg_QRPT_QRsolve, 4);
|
3808
|
+
rb_define_module_function(mgsl_linalg_QRPT, "update", rb_gsl_linalg_QRPT_update, 5);
|
3809
|
+
|
3810
|
+
rb_define_module_function(mgsl_linalg_QRPT, "Rsolve", rb_gsl_linalg_QRPT_Rsolve, -1);
|
3811
|
+
rb_define_method(cgsl_matrix_QRPT, "Rsolve", rb_gsl_linalg_QRPT_Rsolve, -1);
|
3812
|
+
rb_define_module_function(mgsl_linalg_QRPT, "Rsvx", rb_gsl_linalg_QRPT_Rsvx, -1);
|
3813
|
+
rb_define_method(cgsl_matrix_QRPT, "Rsvx", rb_gsl_linalg_QRPT_Rsvx, -1);
|
3814
|
+
|
3815
|
+
/*****/
|
3816
|
+
rb_define_module_function(mgsl_linalg_SV, "decomp", rb_gsl_linalg_SV_decomp, -1);
|
3817
|
+
rb_define_method(cgsl_matrix, "SV_decomp", rb_gsl_linalg_SV_decomp, -1);
|
3818
|
+
rb_define_alias(cgsl_matrix, "SVD", "SV_decomp");
|
3819
|
+
rb_define_alias(cgsl_matrix, "svd", "SV_decomp");
|
3820
|
+
rb_define_module_function(mgsl_linalg_SV, "decomp_mod", rb_gsl_linalg_SV_decomp_mod, -1);
|
3821
|
+
rb_define_method(cgsl_matrix, "SV_decomp_mod", rb_gsl_linalg_SV_decomp_mod, -1);
|
3822
|
+
rb_define_module_function(mgsl_linalg_SV, "decomp_jacobi", rb_gsl_linalg_SV_decomp_jacobi, -1);
|
3823
|
+
rb_define_method(cgsl_matrix, "SV_decomp_jacobi", rb_gsl_linalg_SV_decomp_jacobi, -1);
|
3824
|
+
|
3825
|
+
rb_define_module_function(mgsl_linalg_SV, "solve", rb_gsl_linalg_SV_solve, -1);
|
3826
|
+
|
3827
|
+
rb_define_method(cgsl_matrix, "SV_solve", rb_gsl_linalg_SV_solve, -1);
|
3828
|
+
|
3829
|
+
/*****/
|
3830
|
+
rb_define_module_function(mgsl_linalg_cholesky, "decomp", rb_gsl_linalg_cholesky_decomp, -1);
|
3831
|
+
rb_define_method(cgsl_matrix, "cholesky_decomp", rb_gsl_linalg_cholesky_decomp, -1);
|
3832
|
+
|
3833
|
+
rb_define_module_function(mgsl_linalg_cholesky, "solve", rb_gsl_linalg_cholesky_solve, -1);
|
3834
|
+
rb_define_method(cgsl_matrix, "cholesky_solve", rb_gsl_linalg_cholesky_solve, -1);
|
3835
|
+
rb_define_method(cgsl_matrix_C, "solve", rb_gsl_linalg_cholesky_solve, -1);
|
3836
|
+
rb_define_module_function(mgsl_linalg_cholesky, "svx", rb_gsl_linalg_cholesky_svx, -1);
|
3837
|
+
rb_define_method(cgsl_matrix, "cholesky_svx", rb_gsl_linalg_cholesky_svx, -1);
|
3838
|
+
rb_define_method(cgsl_matrix_C, "svx", rb_gsl_linalg_cholesky_svx, -1);
|
3839
|
+
|
3840
|
+
/*****/
|
3841
|
+
|
3842
|
+
rb_define_module_function(mgsl_linalg_symmtd, "decomp", rb_gsl_linalg_symmtd_decomp, -1);
|
3843
|
+
rb_define_method(cgsl_matrix, "symmtd_decomp", rb_gsl_linalg_symmtd_decomp, -1);
|
3844
|
+
rb_define_module_function(mgsl_linalg_symmtd, "decomp!", rb_gsl_linalg_symmtd_decomp2, -1);
|
3845
|
+
rb_define_method(cgsl_matrix, "symmtd_decomp!", rb_gsl_linalg_symmtd_decomp2, -1);
|
3846
|
+
|
3847
|
+
rb_define_method(cgsl_matrix, "symmtd_unpack", rb_gsl_linalg_symmtd_unpack, -1);
|
3848
|
+
rb_define_method(cgsl_matrix, "symmtd_unpack_T", rb_gsl_linalg_symmtd_unpack_T, -1);
|
3849
|
+
|
3850
|
+
rb_define_module_function(mgsl_linalg_symmtd, "unpack", rb_gsl_linalg_symmtd_unpack, -1);
|
3851
|
+
rb_define_module_function(mgsl_linalg_symmtd, "unpack_T", rb_gsl_linalg_symmtd_unpack_T, -1);
|
3852
|
+
/*****/
|
3853
|
+
rb_define_module_function(mgsl_linalg_hermtd, "decomp", rb_gsl_linalg_hermtd_decomp, -1);
|
3854
|
+
rb_define_method(cgsl_matrix, "hermtd_decomp", rb_gsl_linalg_hermtd_decomp, -1);
|
3855
|
+
rb_define_module_function(mgsl_linalg_hermtd, "decomp!", rb_gsl_linalg_hermtd_decomp2, -1);
|
3856
|
+
rb_define_method(cgsl_matrix, "hermtd_decomp!", rb_gsl_linalg_hermtd_decomp2, -1);
|
3857
|
+
|
3858
|
+
rb_define_method(cgsl_matrix_complex, "hermtd_unpack", rb_gsl_linalg_hermtd_unpack, -1);
|
3859
|
+
rb_define_module_function(mgsl_linalg_hermtd, "unpack", rb_gsl_linalg_hermtd_unpack, -1);
|
3860
|
+
rb_define_method(cgsl_matrix_complex, "hermtd_unpack_T", rb_gsl_linalg_hermtd_unpack_T, -1);
|
3861
|
+
rb_define_module_function(mgsl_linalg_hermtd, "unpack_T", rb_gsl_linalg_hermtd_unpack_T, -1);
|
3862
|
+
|
3863
|
+
/*****/
|
3864
|
+
rb_define_method(cgsl_matrix, "bidiag_decomp", rb_gsl_linalg_bidiag_decomp, -1);
|
3865
|
+
rb_define_method(cgsl_matrix, "bidiag_decomp!", rb_gsl_linalg_bidiag_decomp2, -1);
|
3866
|
+
|
3867
|
+
rb_define_module_function(mgsl_linalg, "bidiag_decomp", rb_gsl_linalg_bidiag_decomp, -1);
|
3868
|
+
rb_define_module_function(mgsl_linalg, "bidiag_decomp!", rb_gsl_linalg_bidiag_decomp2, -1);
|
3869
|
+
rb_define_module_function(mgsl_linalg_bidiag, "decomp", rb_gsl_linalg_bidiag_decomp, -1);
|
3870
|
+
rb_define_module_function(mgsl_linalg_bidiag, "decomp!", rb_gsl_linalg_bidiag_decomp2, -1);
|
3871
|
+
|
3872
|
+
rb_define_method(cgsl_matrix, "bidiag_unpack", rb_gsl_linalg_bidiag_unpack, -1);
|
3873
|
+
rb_define_method(cgsl_matrix, "bidiag_unpack2", rb_gsl_linalg_bidiag_unpack2, -1);
|
3874
|
+
rb_define_module_function(mgsl_linalg, "bidiag_unpack", rb_gsl_linalg_bidiag_unpack, -1);
|
3875
|
+
rb_define_module_function(mgsl_linalg, "bidiag_unpack2", rb_gsl_linalg_bidiag_unpack2, -1);
|
3876
|
+
rb_define_module_function(mgsl_linalg_bidiag, "unpack", rb_gsl_linalg_bidiag_unpack, -1);
|
3877
|
+
rb_define_module_function(mgsl_linalg_bidiag, "unpack2", rb_gsl_linalg_bidiag_unpack2, -1);
|
3878
|
+
|
3879
|
+
rb_define_method(cgsl_matrix, "bidiag_unpack_B", rb_gsl_linalg_bidiag_unpack_B, -1);
|
3880
|
+
rb_define_module_function(mgsl_linalg, "bidiag_unpack_B", rb_gsl_linalg_bidiag_unpack_B, -1);
|
3881
|
+
rb_define_module_function(mgsl_linalg_bidiag, "unpack_B", rb_gsl_linalg_bidiag_unpack_B, -1);
|
3882
|
+
/*****/
|
3883
|
+
rb_define_module_function(mgsl_linalg, "householder_transform",
|
3884
|
+
rb_gsl_linalg_householder_transform, -1);
|
3885
|
+
rb_define_module_function(mgsl_linalg_Householder, "transform",
|
3886
|
+
rb_gsl_linalg_householder_transform, -1);
|
3887
|
+
rb_define_module_function(mgsl_linalg_HH, "transform",
|
3888
|
+
rb_gsl_linalg_householder_transform, -1);
|
3889
|
+
rb_define_method(cgsl_vector, "householder_transform",
|
3890
|
+
rb_gsl_linalg_householder_transform, -1);
|
3891
|
+
|
3892
|
+
rb_define_module_function(mgsl_linalg, "householder_hm",
|
3893
|
+
rb_gsl_linalg_householder_hm, 3);
|
3894
|
+
rb_define_module_function(mgsl_linalg_Householder, "hm",
|
3895
|
+
rb_gsl_linalg_householder_hm, 3);
|
3896
|
+
rb_define_module_function(mgsl_linalg_HH, "hm",
|
3897
|
+
rb_gsl_linalg_householder_hm, 3);
|
3898
|
+
|
3899
|
+
rb_define_module_function(mgsl_linalg, "householder_mh",
|
3900
|
+
rb_gsl_linalg_householder_mh, 3);
|
3901
|
+
rb_define_module_function(mgsl_linalg_Householder, "mh",
|
3902
|
+
rb_gsl_linalg_householder_mh, 3);
|
3903
|
+
rb_define_module_function(mgsl_linalg_HH, "mh",
|
3904
|
+
rb_gsl_linalg_householder_mh, 3);
|
3905
|
+
|
3906
|
+
rb_define_module_function(mgsl_linalg, "householder_hv",
|
3907
|
+
rb_gsl_linalg_householder_hv, 3);
|
3908
|
+
rb_define_module_function(mgsl_linalg_Householder, "hv",
|
3909
|
+
rb_gsl_linalg_householder_hv, 3);
|
3910
|
+
rb_define_module_function(mgsl_linalg_HH, "hv",
|
3911
|
+
rb_gsl_linalg_householder_hv, 3);
|
3912
|
+
|
3913
|
+
rb_define_module_function(mgsl_linalg_HH, "solve", rb_gsl_linalg_HH_solve, -1);
|
3914
|
+
rb_define_module_function(mgsl_linalg_HH, "solve!", rb_gsl_linalg_HH_solve_bang, -1);
|
3915
|
+
rb_define_method(cgsl_matrix, "HH_solve", rb_gsl_linalg_HH_solve, -1);
|
3916
|
+
rb_define_method(cgsl_matrix, "HH_solve!", rb_gsl_linalg_HH_solve_bang, -1);
|
3917
|
+
rb_define_module_function(mgsl_linalg_HH, "svx", rb_gsl_linalg_HH_svx, -1);
|
3918
|
+
rb_define_method(cgsl_matrix, "HH_svx", rb_gsl_linalg_HH_svx, -1);
|
3919
|
+
|
3920
|
+
/*****/
|
3921
|
+
|
3922
|
+
rb_define_module_function(mgsl_linalg, "solve_symm_tridiag", rb_gsl_linalg_solve_symm_tridiag, 3);
|
3923
|
+
|
3924
|
+
rb_define_module_function(mgsl_linalg_tridiag, "solve_symm", rb_gsl_linalg_solve_symm_tridiag, 3);
|
3925
|
+
|
3926
|
+
#ifdef GSL_1_2_LATER
|
3927
|
+
rb_define_module_function(mgsl_linalg, "solve_tridiag", rb_gsl_linalg_solve_tridiag, 4);
|
3928
|
+
rb_define_module_function(mgsl_linalg_tridiag, "solve", rb_gsl_linalg_solve_tridiag, 4);
|
3929
|
+
rb_define_module_function(mgsl_linalg, "solve_symm_cyc_tridiag", rb_gsl_linalg_solve_symm_cyc_tridiag, 3);
|
3930
|
+
rb_define_module_function(mgsl_linalg, "solve_cyc_tridiag", rb_gsl_linalg_solve_cyc_tridiag, 4);
|
3931
|
+
rb_define_module_function(mgsl_linalg_tridiag, "solve_symm_cyc", rb_gsl_linalg_solve_symm_cyc_tridiag, 3);
|
3932
|
+
rb_define_module_function(mgsl_linalg_tridiag, "solve_cyc", rb_gsl_linalg_solve_cyc_tridiag, 4);
|
3933
|
+
#endif
|
3934
|
+
|
3935
|
+
/*****/
|
3936
|
+
rb_define_module_function(mgsl_linalg, "balance_columns!",
|
3937
|
+
rb_gsl_linalg_balance_columns_bang, -1);
|
3938
|
+
rb_define_method(cgsl_matrix, "balance_columns!",
|
3939
|
+
rb_gsl_linalg_balance_columns_bang, -1);
|
3940
|
+
rb_define_module_function(mgsl_linalg, "balance_columns",
|
3941
|
+
rb_gsl_linalg_balance_columns, -1);
|
3942
|
+
rb_define_method(cgsl_matrix, "balance_columns",
|
3943
|
+
rb_gsl_linalg_balance_columns, -1);
|
3944
|
+
rb_define_alias(cgsl_matrix, "balance", "balance_columns");
|
3945
|
+
rb_define_alias(cgsl_matrix, "balanc", "balance_columns");
|
3946
|
+
/*****/
|
3947
|
+
|
3948
|
+
Init_gsl_linalg_complex(mgsl_linalg);
|
3949
|
+
|
3950
|
+
/** GSL-1.6 **/
|
3951
|
+
#ifdef GSL_1_6_LATER
|
3952
|
+
rb_define_module_function(mgsl_linalg, "LQ_decomp", rb_gsl_linalg_LQ_decomp, -1);
|
3953
|
+
rb_define_module_function(mgsl_linalg_LQ, "decomp", rb_gsl_linalg_LQ_decomp, -1);
|
3954
|
+
rb_define_method(cgsl_matrix, "LQ_decomp", rb_gsl_linalg_LQ_decomp, -1);
|
3955
|
+
rb_define_module_function(mgsl_linalg, "LQ_decomp!", rb_gsl_linalg_LQ_decomp_bang, -1);
|
3956
|
+
rb_define_module_function(mgsl_linalg_LQ, "decomp!", rb_gsl_linalg_LQ_decomp_bang, -1);
|
3957
|
+
rb_define_method(cgsl_matrix, "LQ_decomp!", rb_gsl_linalg_LQ_decomp_bang, -1);
|
3958
|
+
|
3959
|
+
rb_define_module_function(mgsl_linalg, "LQ_solve_T", rb_gsl_linalg_LQ_solve, -1);
|
3960
|
+
rb_define_module_function(mgsl_linalg_LQ, "solve_T", rb_gsl_linalg_LQ_solve, -1);
|
3961
|
+
rb_define_module_function(mgsl_linalg, "LQ_svx_T", rb_gsl_linalg_LQ_svx, -1);
|
3962
|
+
rb_define_module_function(mgsl_linalg_LQ, "svx_T", rb_gsl_linalg_LQ_svx, -1);
|
3963
|
+
rb_define_method(cgsl_matrix, "LQ_solve_T", rb_gsl_linalg_LQ_solve, -1);
|
3964
|
+
rb_define_method(cgsl_matrix_LQ, "solve_T", rb_gsl_linalg_LQ_solve, -1);
|
3965
|
+
rb_define_method(cgsl_matrix, "LQ_svx_T", rb_gsl_linalg_LQ_svx, -1);
|
3966
|
+
rb_define_method(cgsl_matrix_LQ, "svx_T", rb_gsl_linalg_LQ_svx, -1);
|
3967
|
+
|
3968
|
+
rb_define_module_function(mgsl_linalg_LQ, "lssolve_T", rb_gsl_linalg_LQ_lssolve, -1);
|
3969
|
+
rb_define_method(cgsl_matrix, "LQ_lssolve_T", rb_gsl_linalg_LQ_lssolve, -1);
|
3970
|
+
rb_define_method(cgsl_matrix_LQ, "lssolve_T", rb_gsl_linalg_LQ_lssolve, -1);
|
3971
|
+
|
3972
|
+
rb_define_module_function(mgsl_linalg_LQ, "vecQT", rb_gsl_linalg_LQ_vecQT, -1);
|
3973
|
+
rb_define_method(cgsl_matrix_LQ, "vecQT", rb_gsl_linalg_LQ_vecQT, -1);
|
3974
|
+
rb_define_module_function(mgsl_linalg_LQ, "vecQ", rb_gsl_linalg_LQ_vecQ, -1);
|
3975
|
+
rb_define_method(cgsl_matrix_LQ, "vecQ", rb_gsl_linalg_LQ_vecQ, -1);
|
3976
|
+
|
3977
|
+
rb_define_module_function(mgsl_linalg_LQ, "Lsolve_T", rb_gsl_linalg_LQ_Lsolve, -1);
|
3978
|
+
rb_define_method(cgsl_matrix, "LQ_Lsolve_T", rb_gsl_linalg_LQ_Lsolve, -1);
|
3979
|
+
rb_define_method(cgsl_matrix_LQ, "Lsolve_T", rb_gsl_linalg_LQ_Lsolve, -1);
|
3980
|
+
|
3981
|
+
rb_define_module_function(mgsl_linalg_LQ, "Lsvx_T", rb_gsl_linalg_LQ_Lsvx, -1);
|
3982
|
+
rb_define_method(cgsl_matrix_LQ, "Lsvx_T", rb_gsl_linalg_LQ_Lsvx, 1);
|
3983
|
+
|
3984
|
+
rb_define_module_function(mgsl_linalg_LQ, "unpack", rb_gsl_linalg_LQ_unpack, -1);
|
3985
|
+
rb_define_method(cgsl_matrix_LQ, "unpack", rb_gsl_linalg_LQ_unpack, -1);
|
3986
|
+
|
3987
|
+
rb_define_module_function(mgsl_linalg_LQ, "LQsolve_T", rb_gsl_linalg_LQ_LQsolve, -1);
|
3988
|
+
rb_define_module_function(mgsl_linalg_LQ, "update", rb_gsl_linalg_LQ_update, 4);
|
3989
|
+
|
3990
|
+
rb_define_method(mgsl_linalg, "L_solve_T", rb_gsl_linalg_L_solve, -1);
|
3991
|
+
rb_define_method(cgsl_matrix_L, "solve_T", rb_gsl_linalg_L_solve, -1);
|
3992
|
+
/*
|
3993
|
+
rb_define_method(cgsl_matrix_R, "svx", rb_gsl_linalg_R_svx, -1);
|
3994
|
+
*/
|
3995
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "decomp", rb_gsl_linalg_PTLQ_decomp, -1);
|
3996
|
+
rb_define_method(cgsl_matrix, "PTLQ_decomp", rb_gsl_linalg_PTLQ_decomp, -1);
|
3997
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "decomp!", rb_gsl_linalg_PTLQ_decomp_bang, -1);
|
3998
|
+
rb_define_method(cgsl_matrix, "PTLQ_decomp!", rb_gsl_linalg_PTLQ_decomp_bang, -1);
|
3999
|
+
|
4000
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "decomp2", rb_gsl_linalg_PTLQ_decomp2, -1);
|
4001
|
+
rb_define_method(cgsl_matrix, "PTLQ_decomp2", rb_gsl_linalg_PTLQ_decomp2, -1);
|
4002
|
+
|
4003
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "solve_T", rb_gsl_linalg_PTLQ_solve, -1);
|
4004
|
+
rb_define_method(cgsl_matrix, "PTLQ_solve_T", rb_gsl_linalg_PTLQ_solve, -1);
|
4005
|
+
rb_define_method(cgsl_matrix_PTLQ, "solve_T", rb_gsl_linalg_PTLQ_solve, -1);
|
4006
|
+
|
4007
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "svx_T", rb_gsl_linalg_PTLQ_svx, -1);
|
4008
|
+
rb_define_method(cgsl_matrix, "PTLQ_svx_T", rb_gsl_linalg_PTLQ_svx, -1);
|
4009
|
+
rb_define_method(cgsl_matrix_PTLQ, "svx_T", rb_gsl_linalg_PTLQ_svx, -1);
|
4010
|
+
|
4011
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "LQsolve_T", rb_gsl_linalg_PTLQ_LQsolve, 4);
|
4012
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "update", rb_gsl_linalg_PTLQ_update, 5);
|
4013
|
+
|
4014
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "Lsolve_T", rb_gsl_linalg_PTLQ_Lsolve, -1);
|
4015
|
+
rb_define_method(cgsl_matrix_PTLQ, "Lsolve_T", rb_gsl_linalg_PTLQ_Lsolve, -1);
|
4016
|
+
rb_define_module_function(mgsl_linalg_PTLQ, "Lsvx_T", rb_gsl_linalg_PTLQ_Lsvx, -1);
|
4017
|
+
rb_define_method(cgsl_matrix_PTLQ, "Lsvx_T", rb_gsl_linalg_PTLQ_Lsvx, -1);
|
4018
|
+
|
4019
|
+
#endif
|
4020
|
+
|
4021
|
+
#ifdef GSL_1_9_LATER
|
4022
|
+
VALUE mhessen;
|
4023
|
+
mhessen = rb_define_module_under(mgsl_linalg, "Hessenberg");
|
4024
|
+
rb_define_module_function(mhessen, "decomp", rb_gsl_linalg_hessenberg_decomp, 1);
|
4025
|
+
rb_define_module_function(mgsl_linalg, "heesenberg_decomp", rb_gsl_linalg_hessenberg_decomp, 1);
|
4026
|
+
rb_define_module_function(mhessen, "unpack", rb_gsl_linalg_hessenberg_unpack, 2);
|
4027
|
+
rb_define_module_function(mgsl_linalg, "hessenberg_unpack", rb_gsl_linalg_hessenberg_unpack, 2);
|
4028
|
+
rb_define_module_function(mhessen, "unpack_accum", rb_gsl_linalg_hessenberg_unpack_accum, -1);
|
4029
|
+
rb_define_module_function(mgsl_linalg, "hessenberg_unpack_accum", rb_gsl_linalg_hessenberg_unpack_accum, -1);
|
4030
|
+
rb_define_module_function(mhessen, "set_zero", rb_gsl_linalg_hessenberg_set_zero, 1);
|
4031
|
+
rb_define_module_function(mgsl_linalg, "hessenberg_set_zero", rb_gsl_linalg_hessenberg_set_zero, 1);
|
4032
|
+
|
4033
|
+
rb_define_module_function(mgsl_linalg, "hesstri_decomp", rb_gsl_linalg_hesstri_decomp, -1);
|
4034
|
+
rb_define_module_function(mgsl_linalg, "hesstri_decomp!", rb_gsl_linalg_hesstri_decomp_bang, -1);
|
4035
|
+
|
4036
|
+
rb_define_module_function(mgsl_linalg, "balance_matrix", rb_gsl_linalg_balance_matrix, -1);
|
4037
|
+
rb_define_module_function(mgsl_linalg, "balance_matrix!", rb_gsl_linalg_balance_matrix2, -1);
|
4038
|
+
rb_define_module_function(mgsl_linalg, "balance", rb_gsl_linalg_balance_matrix, -1);
|
4039
|
+
rb_define_module_function(mgsl_linalg, "balance!", rb_gsl_linalg_balance_matrix2, -1);
|
4040
|
+
#endif
|
4041
|
+
|
4042
|
+
}
|