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/dirac.c
ADDED
@@ -0,0 +1,389 @@
|
|
1
|
+
#include "rb_gsl_dirac.h"
|
2
|
+
|
3
|
+
static VALUE cgsl_matrix_complex_const;
|
4
|
+
static VALUE cPauli;
|
5
|
+
static VALUE cAlpha;
|
6
|
+
static VALUE cGamma;
|
7
|
+
static VALUE cLambda;
|
8
|
+
|
9
|
+
static gsl_matrix_complex *Pauli[3];
|
10
|
+
static gsl_matrix_complex *Alpha[3];
|
11
|
+
static gsl_matrix_complex *Beta;
|
12
|
+
static gsl_matrix_complex *Gamma[5];
|
13
|
+
static gsl_matrix_complex *Eye2, *Eye4;
|
14
|
+
static gsl_matrix_complex *IEye2, *IEye4;
|
15
|
+
static gsl_matrix_complex *Lambda[8];
|
16
|
+
|
17
|
+
static VALUE VPauli[3];
|
18
|
+
static VALUE VAlpha[3];
|
19
|
+
static VALUE VGamma[5];
|
20
|
+
static VALUE VEye2, VEye4, VIEye2, VIEye4;
|
21
|
+
static VALUE VLambda[8];
|
22
|
+
|
23
|
+
static void Init_gsl_dirac_const(VALUE module);
|
24
|
+
static void Init_gsl_dirac_common(VALUE module);
|
25
|
+
static void Init_gsl_dirac_test(VALUE module);
|
26
|
+
|
27
|
+
static VALUE rb_dirac_refuse_set(int argc, VALUE *argv, VALUE obj)
|
28
|
+
{
|
29
|
+
rb_raise(rb_eRuntimeError, "Cannot modify this object.");
|
30
|
+
}
|
31
|
+
|
32
|
+
static VALUE rb_dirac_commute(VALUE obj, VALUE mm1, VALUE mm2)
|
33
|
+
{
|
34
|
+
gsl_matrix_complex *m1, *m2;
|
35
|
+
gsl_matrix_complex *mnew1, *mnew2;
|
36
|
+
CHECK_MATRIX_COMPLEX(mm1);
|
37
|
+
CHECK_MATRIX_COMPLEX(mm2);
|
38
|
+
Data_Get_Struct(mm1, gsl_matrix_complex, m1);
|
39
|
+
Data_Get_Struct(mm2, gsl_matrix_complex, m2);
|
40
|
+
mnew1 = gsl_matrix_complex_alloc(m1->size1, m1->size2);
|
41
|
+
mnew2 = gsl_matrix_complex_alloc(m1->size1, m1->size2);
|
42
|
+
gsl_matrix_complex_mul(mnew1, m1, m2);
|
43
|
+
gsl_matrix_complex_mul(mnew2, m2, m1);
|
44
|
+
gsl_matrix_complex_sub(mnew1, mnew2);
|
45
|
+
gsl_matrix_complex_free(mnew2);
|
46
|
+
return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free,
|
47
|
+
mnew1);
|
48
|
+
}
|
49
|
+
|
50
|
+
static VALUE rb_dirac_anticommute(VALUE obj, VALUE mm1, VALUE mm2)
|
51
|
+
{
|
52
|
+
gsl_matrix_complex *m1, *m2;
|
53
|
+
gsl_matrix_complex *mnew1, *mnew2;
|
54
|
+
CHECK_MATRIX_COMPLEX(mm1);
|
55
|
+
CHECK_MATRIX_COMPLEX(mm2);
|
56
|
+
Data_Get_Struct(mm1, gsl_matrix_complex, m1);
|
57
|
+
Data_Get_Struct(mm2, gsl_matrix_complex, m2);
|
58
|
+
mnew1 = gsl_matrix_complex_alloc(m1->size1, m1->size2);
|
59
|
+
mnew2 = gsl_matrix_complex_alloc(m1->size1, m1->size2);
|
60
|
+
gsl_matrix_complex_mul(mnew1, m1, m2);
|
61
|
+
gsl_matrix_complex_mul(mnew2, m2, m1);
|
62
|
+
gsl_matrix_complex_add(mnew1, mnew2);
|
63
|
+
gsl_matrix_complex_free(mnew2);
|
64
|
+
return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free,
|
65
|
+
mnew1);
|
66
|
+
}
|
67
|
+
|
68
|
+
static void Init_gsl_dirac_common(VALUE module)
|
69
|
+
{
|
70
|
+
/* VALUE cBeta;*/
|
71
|
+
rb_define_singleton_method(module, "commute", rb_dirac_commute, 2);
|
72
|
+
rb_define_singleton_method(module, "anticommute", rb_dirac_anticommute, 2);
|
73
|
+
|
74
|
+
cgsl_matrix_complex_const = rb_define_class_under(module, "Const",
|
75
|
+
cgsl_matrix_complex);
|
76
|
+
rb_define_method(cgsl_matrix_complex_const, "set", rb_dirac_refuse_set, -1);
|
77
|
+
|
78
|
+
cPauli = rb_define_class_under(module, "Pauli", cgsl_matrix_complex_const);
|
79
|
+
cAlpha = rb_define_class_under(module, "Alpha", cgsl_matrix_complex_const);
|
80
|
+
/* cBeta = rb_define_class_under(module, "BetaMatrix", cgsl_matrix_complex_const);*/
|
81
|
+
cGamma = rb_define_class_under(module, "Gamma", cgsl_matrix_complex_const);
|
82
|
+
cLambda = rb_define_class_under(module, "Lambda", cgsl_matrix_complex_const);
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
static void define_eye(VALUE module)
|
87
|
+
{
|
88
|
+
gsl_complex z;
|
89
|
+
|
90
|
+
Eye2 = gsl_matrix_complex_calloc(2, 2);
|
91
|
+
VEye2 = Data_Wrap_Struct(cgsl_matrix_complex_const, 0,
|
92
|
+
gsl_matrix_complex_free, Eye2);
|
93
|
+
z.dat[0] = 1; z.dat[1] = 0;
|
94
|
+
gsl_matrix_complex_set(Eye2, 0, 0, z);
|
95
|
+
gsl_matrix_complex_set(Eye2, 1, 1, z);
|
96
|
+
rb_define_const(module, "Eye2", VEye2);
|
97
|
+
|
98
|
+
Eye4 = gsl_matrix_complex_calloc(4, 4);
|
99
|
+
VEye4 = Data_Wrap_Struct(cgsl_matrix_complex_const, 0,
|
100
|
+
gsl_matrix_complex_free, Eye4);
|
101
|
+
z.dat[0] = 1; z.dat[1] = 0;
|
102
|
+
gsl_matrix_complex_set(Eye4, 0, 0, z);
|
103
|
+
gsl_matrix_complex_set(Eye4, 1, 1, z);
|
104
|
+
gsl_matrix_complex_set(Eye4, 2, 2, z);
|
105
|
+
gsl_matrix_complex_set(Eye4, 3, 3, z);
|
106
|
+
rb_define_const(module, "Eye4", VEye4);
|
107
|
+
|
108
|
+
IEye2 = gsl_matrix_complex_calloc(2, 2);
|
109
|
+
VIEye2 = Data_Wrap_Struct(cgsl_matrix_complex_const, 0,
|
110
|
+
gsl_matrix_complex_free, IEye2);
|
111
|
+
z.dat[0] = 0; z.dat[1] = 1;
|
112
|
+
gsl_matrix_complex_set(IEye2, 0, 0, z);
|
113
|
+
gsl_matrix_complex_set(IEye2, 1, 1, z);
|
114
|
+
rb_define_const(module, "IEye2", VIEye2);
|
115
|
+
|
116
|
+
IEye4 = gsl_matrix_complex_calloc(4, 4);
|
117
|
+
VIEye4 = Data_Wrap_Struct(cgsl_matrix_complex_const, 0,
|
118
|
+
gsl_matrix_complex_free, IEye4);
|
119
|
+
gsl_matrix_complex_set(IEye4, 0, 0, z);
|
120
|
+
gsl_matrix_complex_set(IEye4, 1, 1, z);
|
121
|
+
gsl_matrix_complex_set(IEye4, 2, 2, z);
|
122
|
+
gsl_matrix_complex_set(IEye4, 3, 3, z);
|
123
|
+
rb_define_const(module, "IEye4", VIEye4);
|
124
|
+
}
|
125
|
+
|
126
|
+
static void define_pauli(VALUE module)
|
127
|
+
{
|
128
|
+
gsl_complex z;
|
129
|
+
|
130
|
+
Pauli[0] = gsl_matrix_complex_calloc(2, 2);
|
131
|
+
VPauli[0] = Data_Wrap_Struct(cPauli, 0,
|
132
|
+
gsl_matrix_complex_free, Pauli[0]);
|
133
|
+
z.dat[0] = 1; z.dat[1] = 0;
|
134
|
+
gsl_matrix_complex_set(Pauli[0], 0, 1, z);
|
135
|
+
gsl_matrix_complex_set(Pauli[0], 1, 0, z);
|
136
|
+
rb_define_const(module, "Pauli1", VPauli[0]);
|
137
|
+
|
138
|
+
Pauli[1] = gsl_matrix_complex_calloc(2, 2);
|
139
|
+
VPauli[1] = Data_Wrap_Struct(cPauli, 0,
|
140
|
+
gsl_matrix_complex_free, Pauli[1]);
|
141
|
+
z.dat[0] = 0; z.dat[1] = -1;
|
142
|
+
gsl_matrix_complex_set(Pauli[1], 0, 1, z);
|
143
|
+
z.dat[0] = 0; z.dat[1] = 1;
|
144
|
+
gsl_matrix_complex_set(Pauli[1], 1, 0, z);
|
145
|
+
rb_define_const(module, "Pauli2", VPauli[1]);
|
146
|
+
|
147
|
+
Pauli[2] = gsl_matrix_complex_calloc(2, 2);
|
148
|
+
VPauli[2] = Data_Wrap_Struct(cPauli, 0,
|
149
|
+
gsl_matrix_complex_free, Pauli[2]);
|
150
|
+
z.dat[0] = 1; z.dat[1] = 0;
|
151
|
+
gsl_matrix_complex_set(Pauli[2], 0, 0, z);
|
152
|
+
z.dat[0] = -1; z.dat[1] = 0;
|
153
|
+
gsl_matrix_complex_set(Pauli[2], 1, 1, z);
|
154
|
+
rb_define_const(module, "Pauli3", VPauli[2]);
|
155
|
+
}
|
156
|
+
|
157
|
+
static void define_beta(VALUE module)
|
158
|
+
{
|
159
|
+
gsl_complex z;
|
160
|
+
|
161
|
+
Beta = gsl_matrix_complex_calloc(4, 4);
|
162
|
+
VGamma[0] = Data_Wrap_Struct(cGamma, 0,
|
163
|
+
gsl_matrix_complex_free, Beta);
|
164
|
+
z.dat[0] = 1; z.dat[1] = 0;
|
165
|
+
gsl_matrix_complex_set(Beta, 0, 0, z);
|
166
|
+
gsl_matrix_complex_set(Beta, 1, 1, z);
|
167
|
+
z.dat[0] = -1; z.dat[1] = 0;
|
168
|
+
gsl_matrix_complex_set(Beta, 2, 2, z);
|
169
|
+
gsl_matrix_complex_set(Beta, 3, 3, z);
|
170
|
+
rb_define_const(module, "Beta", VGamma[0]);
|
171
|
+
rb_define_const(module, "Gamma0", VGamma[0]);
|
172
|
+
}
|
173
|
+
|
174
|
+
static void define_alpha(VALUE module)
|
175
|
+
{
|
176
|
+
size_t i, j, k;
|
177
|
+
char name[7];
|
178
|
+
for (i = 0; i < 3; i++) {
|
179
|
+
Alpha[i] = gsl_matrix_complex_calloc(4, 4);
|
180
|
+
|
181
|
+
for (j = 2; j < 4; j++) {
|
182
|
+
for (k = 0; k < 2; k++) {
|
183
|
+
gsl_matrix_complex_set(Alpha[i], j, k,
|
184
|
+
gsl_matrix_complex_get(Pauli[i], j-2, k));
|
185
|
+
}
|
186
|
+
}
|
187
|
+
for (j = 0; j < 2; j++) {
|
188
|
+
for (k = 2; k < 4; k++) {
|
189
|
+
gsl_matrix_complex_set(Alpha[i], j, k,
|
190
|
+
gsl_matrix_complex_get(Pauli[i], j, k-2));
|
191
|
+
}
|
192
|
+
}
|
193
|
+
VAlpha[i] = Data_Wrap_Struct(cAlpha, 0,
|
194
|
+
gsl_matrix_complex_free, Alpha[i]);
|
195
|
+
sprintf(name, "Alpha%d", (int) i+1);
|
196
|
+
rb_define_const(module, name, VAlpha[i]);
|
197
|
+
}
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
static void define_gamma(VALUE module)
|
202
|
+
{
|
203
|
+
size_t i;
|
204
|
+
char name[7];
|
205
|
+
gsl_complex z;
|
206
|
+
for (i = 1; i <= 3; i++) {
|
207
|
+
Gamma[i] = gsl_matrix_complex_calloc(4, 4);
|
208
|
+
gsl_matrix_complex_mul(Gamma[i], Beta, Alpha[i-1]);
|
209
|
+
VGamma[i] = Data_Wrap_Struct(cGamma, 0,
|
210
|
+
gsl_matrix_complex_free, Gamma[i]);
|
211
|
+
sprintf(name, "Gamma%d", (int) i);
|
212
|
+
rb_define_const(module, name, VGamma[i]);
|
213
|
+
}
|
214
|
+
Gamma[4] = gsl_matrix_complex_calloc(4, 4);
|
215
|
+
z.dat[0] = 1.0; z.dat[1] = 0.0;
|
216
|
+
gsl_matrix_complex_set(Gamma[4], 0, 2, z);
|
217
|
+
gsl_matrix_complex_set(Gamma[4], 1, 3, z);
|
218
|
+
gsl_matrix_complex_set(Gamma[4], 2, 0, z);
|
219
|
+
gsl_matrix_complex_set(Gamma[4], 3, 1, z);
|
220
|
+
VGamma[4] = Data_Wrap_Struct(cGamma, 0,
|
221
|
+
gsl_matrix_complex_free, Gamma[4]);
|
222
|
+
rb_define_const(module, "Gamma5", VGamma[4]);
|
223
|
+
}
|
224
|
+
|
225
|
+
static void define_lambda(VALUE module)
|
226
|
+
{
|
227
|
+
gsl_complex z1, zm1, zi, zmi;
|
228
|
+
size_t i;
|
229
|
+
char name[8];
|
230
|
+
double sqrt3 = sqrt(3.0);
|
231
|
+
z1.dat[0] = 1; z1.dat[1] = 0;
|
232
|
+
zm1.dat[0] = -1; zm1.dat[1] = 0;
|
233
|
+
zi.dat[0] = 0; zi.dat[1] = 1;
|
234
|
+
zmi.dat[0] = 0; zmi.dat[1] = -1;
|
235
|
+
for (i = 0; i < 8; i++) {
|
236
|
+
Lambda[i] = gsl_matrix_complex_calloc(3, 3);
|
237
|
+
VLambda[i] = Data_Wrap_Struct(cLambda, 0,
|
238
|
+
gsl_matrix_complex_free, Lambda[i]);
|
239
|
+
sprintf(name, "Lambda%d", (int) i+1);
|
240
|
+
rb_define_const(module, name, VLambda[i]);
|
241
|
+
}
|
242
|
+
gsl_matrix_complex_set(Lambda[0], 0, 1, z1);
|
243
|
+
gsl_matrix_complex_set(Lambda[0], 1, 0, z1);
|
244
|
+
gsl_matrix_complex_set(Lambda[1], 0, 1, zmi);
|
245
|
+
gsl_matrix_complex_set(Lambda[1], 1, 0, zi);
|
246
|
+
gsl_matrix_complex_set(Lambda[2], 0, 0, z1);
|
247
|
+
gsl_matrix_complex_set(Lambda[2], 1, 1, zm1);
|
248
|
+
gsl_matrix_complex_set(Lambda[3], 0, 2, z1);
|
249
|
+
gsl_matrix_complex_set(Lambda[3], 2, 0, z1);
|
250
|
+
gsl_matrix_complex_set(Lambda[4], 0, 2, zmi);
|
251
|
+
gsl_matrix_complex_set(Lambda[4], 2, 0, zi);
|
252
|
+
gsl_matrix_complex_set(Lambda[5], 1, 2, z1);
|
253
|
+
gsl_matrix_complex_set(Lambda[5], 2, 1, z1);
|
254
|
+
gsl_matrix_complex_set(Lambda[6], 1, 2, zmi);
|
255
|
+
gsl_matrix_complex_set(Lambda[6], 2, 1, zi);
|
256
|
+
gsl_matrix_complex_set(Lambda[7], 0, 0, gsl_complex_mul_real(z1, 1.0/sqrt3));
|
257
|
+
gsl_matrix_complex_set(Lambda[7], 1, 1, gsl_complex_mul_real(z1, 1.0/sqrt3));
|
258
|
+
gsl_matrix_complex_set(Lambda[7], 2, 2, gsl_complex_mul_real(z1, -2.0/sqrt3));
|
259
|
+
}
|
260
|
+
|
261
|
+
static void Init_gsl_dirac_const(VALUE module)
|
262
|
+
{
|
263
|
+
define_eye(module);
|
264
|
+
define_pauli(module);
|
265
|
+
define_beta(module);
|
266
|
+
define_alpha(module);
|
267
|
+
define_gamma(module);
|
268
|
+
define_lambda(module);
|
269
|
+
}
|
270
|
+
|
271
|
+
static int matrix_is_equal(gsl_matrix_complex *m1, gsl_matrix_complex *m2, gsl_complex *c)
|
272
|
+
{
|
273
|
+
gsl_complex a, b, ab, absave;
|
274
|
+
double eps = 1e-6;
|
275
|
+
size_t i, j;
|
276
|
+
absave.dat[0] = 99999;
|
277
|
+
absave.dat[1] = 99999;
|
278
|
+
if (m1->size1 != m2->size1 || m1->size2 != m2->size2) return 0;
|
279
|
+
for (i = 0; i < m1->size1; i++) {
|
280
|
+
for (j = 0; j < m1->size2; j++) {
|
281
|
+
a = gsl_matrix_complex_get(m1, i, j);
|
282
|
+
b = gsl_matrix_complex_get(m2, i, j);
|
283
|
+
if (!gsl_fcmp(gsl_complex_abs(b), 0.0, eps)) continue;
|
284
|
+
ab = gsl_complex_div(a, b);
|
285
|
+
if (!gsl_fcmp(gsl_complex_abs(ab), 0.0, eps)) continue;
|
286
|
+
if ((int) absave.dat[0] == 99999) absave = ab;
|
287
|
+
if (gsl_fcmp(ab.dat[0], absave.dat[0], eps)) return 0;
|
288
|
+
if (gsl_fcmp(ab.dat[1], absave.dat[1], eps)) return 0;
|
289
|
+
}
|
290
|
+
}
|
291
|
+
if ((int) absave.dat[0] == 99999) return 0;
|
292
|
+
*c = ab;
|
293
|
+
return 1;
|
294
|
+
}
|
295
|
+
|
296
|
+
static VALUE rb_Dirac_matrix_is_equal(int argc, VALUE *argv, VALUE obj)
|
297
|
+
{
|
298
|
+
gsl_complex ztmp, *z;
|
299
|
+
gsl_matrix_complex *m1, *m2;
|
300
|
+
VALUE vz;
|
301
|
+
switch (TYPE(obj)) {
|
302
|
+
case T_MODULE:
|
303
|
+
case T_CLASS:
|
304
|
+
case T_OBJECT:
|
305
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
306
|
+
CHECK_MATRIX_COMPLEX(argv[1]);
|
307
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, m1);
|
308
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, m2);
|
309
|
+
if (matrix_is_equal(m1, m2, &ztmp)) {
|
310
|
+
vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, z);
|
311
|
+
*z = ztmp;
|
312
|
+
return vz;
|
313
|
+
} else {
|
314
|
+
return Qfalse;
|
315
|
+
}
|
316
|
+
break;
|
317
|
+
default:
|
318
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
319
|
+
Data_Get_Struct(obj, gsl_matrix_complex, m1);
|
320
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, m2);
|
321
|
+
if (matrix_is_equal(m1, m2, &ztmp)) {
|
322
|
+
vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, z);
|
323
|
+
*z = ztmp;
|
324
|
+
return vz;
|
325
|
+
} else {
|
326
|
+
return Qfalse;
|
327
|
+
}
|
328
|
+
break;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
#define NUM 20
|
333
|
+
static VALUE rb_Dirac_matrix_whoami(int argc, VALUE *argv, VALUE obj)
|
334
|
+
{
|
335
|
+
VALUE array[NUM] = {VPauli[0], VPauli[1], VPauli[2],
|
336
|
+
VGamma[0], VGamma[1], VGamma[2], VGamma[3],
|
337
|
+
VGamma[4], VEye2, VEye4, VIEye2, VIEye4,
|
338
|
+
VLambda[0], VLambda[1], VLambda[2], VLambda[3],
|
339
|
+
VLambda[4], VLambda[5], VLambda[6], VLambda[7]};
|
340
|
+
|
341
|
+
char *name[NUM] = {"Pauli1", "Pauli2", "Pauli3",
|
342
|
+
"Gamma0", "Gamma1", "Gamma2", "Gamma3", "Gamma5",
|
343
|
+
"Eye2", "Eye4", "IEye2", "IEye4", "Lambda1", "Lambda2",
|
344
|
+
"Lambda3", "Lambda4", "Lambda5", "Lambda6",
|
345
|
+
"Lambda7", "Lambda8"};
|
346
|
+
gsl_matrix_complex *m1, *m2;
|
347
|
+
VALUE vz;
|
348
|
+
gsl_complex ztmp, *z;
|
349
|
+
size_t i;
|
350
|
+
switch (TYPE(obj)) {
|
351
|
+
case T_MODULE:
|
352
|
+
case T_CLASS:
|
353
|
+
case T_OBJECT:
|
354
|
+
if (argc != 1) rb_raise(rb_eArgError, "matrix not given");
|
355
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
356
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, m1);
|
357
|
+
break;
|
358
|
+
default:
|
359
|
+
Data_Get_Struct(obj, gsl_matrix_complex, m1);
|
360
|
+
break;
|
361
|
+
}
|
362
|
+
for (i = 0; i < NUM; i++) {
|
363
|
+
Data_Get_Struct(array[i], gsl_matrix_complex, m2);
|
364
|
+
if(matrix_is_equal(m1, m2, &ztmp)) {
|
365
|
+
vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, z);
|
366
|
+
*z = ztmp;
|
367
|
+
return rb_ary_new3(3, array[i], rb_str_new2(name[i]), vz);
|
368
|
+
}
|
369
|
+
}
|
370
|
+
return Qfalse;
|
371
|
+
}
|
372
|
+
#undef NUM
|
373
|
+
|
374
|
+
static void Init_gsl_dirac_test(VALUE module)
|
375
|
+
{
|
376
|
+
rb_define_singleton_method(module, "is_equal?", rb_Dirac_matrix_is_equal, -1);
|
377
|
+
rb_define_method(cgsl_matrix_complex, "is_equal?", rb_Dirac_matrix_is_equal, -1);
|
378
|
+
rb_define_singleton_method(module, "whatisthis", rb_Dirac_matrix_whoami, -1);
|
379
|
+
rb_define_method(cgsl_matrix_complex, "whoami", rb_Dirac_matrix_whoami, -1);
|
380
|
+
}
|
381
|
+
|
382
|
+
void Init_gsl_dirac(VALUE module)
|
383
|
+
{
|
384
|
+
VALUE mDirac;
|
385
|
+
mDirac = rb_define_module_under(module, "Dirac");
|
386
|
+
Init_gsl_dirac_common(mDirac);
|
387
|
+
Init_gsl_dirac_const(mDirac);
|
388
|
+
Init_gsl_dirac_test(mDirac);
|
389
|
+
}
|
data/ext/eigen.c
ADDED
@@ -0,0 +1,2373 @@
|
|
1
|
+
/*
|
2
|
+
eigen.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2001-2006 by Yoshiki Tsunesada
|
5
|
+
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
7
|
+
under the terms of the GNU General Public License.
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "rb_gsl.h"
|
13
|
+
#include "rb_gsl_array.h"
|
14
|
+
|
15
|
+
#include "rb_gsl_eigen.h"
|
16
|
+
#include "rb_gsl_complex.h"
|
17
|
+
#include <gsl/gsl_complex.h>
|
18
|
+
#include <gsl/gsl_complex_math.h>
|
19
|
+
#include <gsl/gsl_math.h>
|
20
|
+
#include <gsl/gsl_eigen.h>
|
21
|
+
|
22
|
+
static VALUE cgsl_eigen_symm_workspace;
|
23
|
+
static VALUE cgsl_eigen_symmv_workspace;
|
24
|
+
static VALUE cgsl_eigen_herm_workspace;
|
25
|
+
static VALUE cgsl_eigen_hermv_workspace;
|
26
|
+
static VALUE cgsl_eigen_values;
|
27
|
+
static VALUE cgsl_eigen_vectors;
|
28
|
+
static VALUE cgsl_eigen_vector;
|
29
|
+
static VALUE cgsl_eigen_vector_complex;
|
30
|
+
static VALUE cgsl_eigen_herm_vectors;
|
31
|
+
|
32
|
+
#ifdef HAVE_EIGEN_FRANCIS
|
33
|
+
static VALUE cgsl_eigen_francis_workspace;
|
34
|
+
|
35
|
+
#endif
|
36
|
+
#ifdef GSL_1_9_LATER
|
37
|
+
static VALUE cgsl_eigen_nonsymm_workspace;
|
38
|
+
static VALUE cgsl_eigen_nonsymmv_workspace;
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#ifdef GSL_1_10_LATER
|
42
|
+
static VALUE cgensymm, mgensymm;
|
43
|
+
static VALUE cgensymmv, mgensymmv;
|
44
|
+
static VALUE cgenherm, mgenherm;
|
45
|
+
static VALUE cgenhermv, mgenhermv;
|
46
|
+
|
47
|
+
static VALUE mgen, mgenv;
|
48
|
+
static VALUE cgenw, cgenvw;
|
49
|
+
#endif
|
50
|
+
|
51
|
+
static VALUE rb_gsl_eigen_symm_alloc(VALUE klass, VALUE nn)
|
52
|
+
{
|
53
|
+
gsl_eigen_symm_workspace *w = NULL;
|
54
|
+
CHECK_FIXNUM(nn);
|
55
|
+
w = gsl_eigen_symm_alloc(FIX2INT(nn));
|
56
|
+
return Data_Wrap_Struct(cgsl_eigen_symm_workspace, 0,
|
57
|
+
gsl_eigen_symm_free, w);
|
58
|
+
}
|
59
|
+
|
60
|
+
static VALUE rb_gsl_eigen_symmv_alloc(VALUE klass, VALUE nn)
|
61
|
+
{
|
62
|
+
gsl_eigen_symmv_workspace *w = NULL;
|
63
|
+
CHECK_FIXNUM(nn);
|
64
|
+
w = gsl_eigen_symmv_alloc(FIX2INT(nn));
|
65
|
+
return Data_Wrap_Struct(cgsl_eigen_symmv_workspace, 0, gsl_eigen_symmv_free, w);
|
66
|
+
}
|
67
|
+
|
68
|
+
static VALUE rb_gsl_eigen_herm_alloc(VALUE klass, VALUE nn)
|
69
|
+
{
|
70
|
+
gsl_eigen_herm_workspace *w = NULL;
|
71
|
+
CHECK_FIXNUM(nn);
|
72
|
+
w = gsl_eigen_herm_alloc(FIX2INT(nn));
|
73
|
+
return Data_Wrap_Struct(cgsl_eigen_herm_workspace, 0,
|
74
|
+
gsl_eigen_herm_free, w);
|
75
|
+
}
|
76
|
+
|
77
|
+
static VALUE rb_gsl_eigen_hermv_alloc(VALUE klass, VALUE nn)
|
78
|
+
{
|
79
|
+
gsl_eigen_hermv_workspace *w = NULL;
|
80
|
+
CHECK_FIXNUM(nn);
|
81
|
+
w = gsl_eigen_hermv_alloc(FIX2INT(nn));
|
82
|
+
return Data_Wrap_Struct(cgsl_eigen_hermv_workspace, 0,
|
83
|
+
gsl_eigen_hermv_free, w);
|
84
|
+
}
|
85
|
+
|
86
|
+
#ifdef HAVE_NARRAY_H
|
87
|
+
static VALUE rb_gsl_eigen_symm_narray(int argc, VALUE *argv, VALUE obj);
|
88
|
+
#endif
|
89
|
+
|
90
|
+
static VALUE rb_gsl_eigen_symm(int argc, VALUE *argv, VALUE obj)
|
91
|
+
{
|
92
|
+
gsl_matrix *Atmp = NULL, *A = NULL;
|
93
|
+
gsl_eigen_symm_workspace *w = NULL;
|
94
|
+
gsl_vector *v = NULL;
|
95
|
+
int flagw = 0;
|
96
|
+
switch (TYPE(obj)) {
|
97
|
+
case T_MODULE:
|
98
|
+
case T_CLASS:
|
99
|
+
case T_OBJECT:
|
100
|
+
switch (argc) {
|
101
|
+
case 2:
|
102
|
+
#ifdef HAVE_NARRAY_H
|
103
|
+
if (NA_IsNArray(argv[0])) return rb_gsl_eigen_symm_narray(argc, argv, obj);
|
104
|
+
#endif
|
105
|
+
CHECK_MATRIX(argv[0]);
|
106
|
+
Data_Get_Struct(argv[0], gsl_matrix, Atmp);
|
107
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_symm_workspace)
|
108
|
+
rb_raise(rb_eTypeError,
|
109
|
+
"argv[1]: wrong argument type %s (Eigen::Symm::Workspace expected)",
|
110
|
+
rb_class2name(CLASS_OF(argv[1])));
|
111
|
+
Data_Get_Struct(argv[1], gsl_eigen_symm_workspace, w);
|
112
|
+
break;
|
113
|
+
case 1:
|
114
|
+
#ifdef HAVE_NARRAY_H
|
115
|
+
if (NA_IsNArray(argv[0])) return rb_gsl_eigen_symm_narray(argc, argv, obj);
|
116
|
+
#endif
|
117
|
+
CHECK_MATRIX(argv[0]);
|
118
|
+
Data_Get_Struct(argv[0], gsl_matrix, Atmp);
|
119
|
+
w = gsl_eigen_symm_alloc(Atmp->size1);
|
120
|
+
flagw = 1;
|
121
|
+
break;
|
122
|
+
default:
|
123
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
124
|
+
break;
|
125
|
+
}
|
126
|
+
break;
|
127
|
+
default:
|
128
|
+
CHECK_MATRIX(obj);
|
129
|
+
Data_Get_Struct(obj, gsl_matrix, Atmp);
|
130
|
+
switch (argc) {
|
131
|
+
case 1:
|
132
|
+
if (CLASS_OF(argv[0]) != cgsl_eigen_symm_workspace)
|
133
|
+
rb_raise(rb_eTypeError,
|
134
|
+
"argv[0]: wrong argument type %s (Eigen::Symm::Workspace expected",
|
135
|
+
rb_class2name(CLASS_OF(argv[0])));
|
136
|
+
|
137
|
+
Data_Get_Struct(argv[0], gsl_eigen_symm_workspace, w);
|
138
|
+
break;
|
139
|
+
case 0:
|
140
|
+
w = gsl_eigen_symm_alloc(Atmp->size1);
|
141
|
+
flagw = 1;
|
142
|
+
break;
|
143
|
+
default:
|
144
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
A = make_matrix_clone(Atmp);
|
148
|
+
v = gsl_vector_alloc(A->size1);
|
149
|
+
gsl_eigen_symm(A, v, w);
|
150
|
+
/* gsl_sort_vector(v);*/
|
151
|
+
gsl_matrix_free(A);
|
152
|
+
if (flagw == 1) gsl_eigen_symm_free(w);
|
153
|
+
return Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, v);
|
154
|
+
}
|
155
|
+
|
156
|
+
#ifdef HAVE_NARRAY_H
|
157
|
+
static VALUE rb_gsl_eigen_symm_narray(int argc, VALUE *argv, VALUE obj)
|
158
|
+
{
|
159
|
+
struct NARRAY *na;
|
160
|
+
VALUE nary;
|
161
|
+
gsl_matrix *A = NULL;
|
162
|
+
gsl_eigen_symm_workspace *w = NULL;
|
163
|
+
gsl_vector_view vv;
|
164
|
+
int shape[1];
|
165
|
+
int flagw = 0;
|
166
|
+
switch (argc) {
|
167
|
+
case 2:
|
168
|
+
if (!NA_IsNArray(argv[0]))
|
169
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
170
|
+
rb_class2name(CLASS_OF(argv[0])));
|
171
|
+
GetNArray(argv[0], na);
|
172
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
173
|
+
if (na->shape[0] != na->shape[1])
|
174
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
175
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
176
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
177
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_symm_workspace)
|
178
|
+
rb_raise(rb_eTypeError,
|
179
|
+
"argv[1]: wrong argument type %s (Eigen::Symm::Workspace expected",
|
180
|
+
rb_class2name(CLASS_OF(argv[1])));
|
181
|
+
Data_Get_Struct(argv[1], gsl_eigen_symm_workspace, w);
|
182
|
+
flagw = 0;
|
183
|
+
break;
|
184
|
+
case 1:
|
185
|
+
if (!NA_IsNArray(argv[0]))
|
186
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
187
|
+
rb_class2name(CLASS_OF(argv[0])));
|
188
|
+
GetNArray(argv[0], na);
|
189
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
190
|
+
if (na->shape[0] != na->shape[1])
|
191
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
192
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
193
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
194
|
+
w = gsl_eigen_symm_alloc(A->size1);
|
195
|
+
flagw = 1;
|
196
|
+
break;
|
197
|
+
default:
|
198
|
+
rb_raise(rb_eArgError, "matrix not given");
|
199
|
+
break;
|
200
|
+
}
|
201
|
+
shape[0] = A->size1;
|
202
|
+
nary = na_make_object(NA_DFLOAT, 1, shape, cNVector);
|
203
|
+
vv = gsl_vector_view_array(NA_PTR_TYPE(nary,double*), A->size1);
|
204
|
+
gsl_eigen_symm(A, &vv.vector, w);
|
205
|
+
/* gsl_sort_vector(v);*/
|
206
|
+
gsl_matrix_free(A);
|
207
|
+
if (flagw == 1) gsl_eigen_symm_free(w);
|
208
|
+
return nary;
|
209
|
+
}
|
210
|
+
#endif
|
211
|
+
|
212
|
+
#ifdef HAVE_NARRAY_H
|
213
|
+
static VALUE rb_gsl_eigen_symmv_narray(int argc, VALUE *argv, VALUE obj);
|
214
|
+
#endif
|
215
|
+
|
216
|
+
static VALUE rb_gsl_eigen_symmv(int argc, VALUE *argv, VALUE obj)
|
217
|
+
{
|
218
|
+
gsl_matrix *Atmp = NULL, *A = NULL, *em = NULL;
|
219
|
+
gsl_eigen_symmv_workspace *w = NULL;
|
220
|
+
gsl_vector *v = NULL;
|
221
|
+
int flagw = 0;
|
222
|
+
VALUE vval, vvec;
|
223
|
+
switch (TYPE(obj)) {
|
224
|
+
case T_MODULE:
|
225
|
+
case T_CLASS:
|
226
|
+
case T_OBJECT:
|
227
|
+
switch (argc) {
|
228
|
+
case 2:
|
229
|
+
#ifdef HAVE_NARRAY_H
|
230
|
+
if (NA_IsNArray(argv[0])) return rb_gsl_eigen_symmv_narray(argc, argv, obj);
|
231
|
+
#endif
|
232
|
+
CHECK_MATRIX(argv[0]);
|
233
|
+
Data_Get_Struct(argv[0], gsl_matrix, Atmp);
|
234
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_symmv_workspace)
|
235
|
+
rb_raise(rb_eTypeError,
|
236
|
+
"argv[1]: wrong argument type %s (Eigen::Symmv::Workspace expected)",
|
237
|
+
rb_class2name(CLASS_OF(argv[1])));
|
238
|
+
Data_Get_Struct(argv[1], gsl_eigen_symmv_workspace, w);
|
239
|
+
break;
|
240
|
+
case 1:
|
241
|
+
#ifdef HAVE_NARRAY_H
|
242
|
+
if (NA_IsNArray(argv[0])) return rb_gsl_eigen_symmv_narray(argc, argv, obj);
|
243
|
+
#endif
|
244
|
+
CHECK_MATRIX(argv[0]);
|
245
|
+
Data_Get_Struct(argv[0], gsl_matrix, Atmp);
|
246
|
+
w = gsl_eigen_symmv_alloc(Atmp->size1);
|
247
|
+
flagw = 1;
|
248
|
+
break;
|
249
|
+
default:
|
250
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
251
|
+
}
|
252
|
+
break;
|
253
|
+
default:
|
254
|
+
CHECK_MATRIX(obj);
|
255
|
+
Data_Get_Struct(obj, gsl_matrix, Atmp);
|
256
|
+
switch (argc) {
|
257
|
+
case 1:
|
258
|
+
if (CLASS_OF(argv[0]) != cgsl_eigen_symmv_workspace)
|
259
|
+
rb_raise(rb_eTypeError,
|
260
|
+
"argv[0]: wrong argument type %s (Eigen::Symmv::Workspace expected)",
|
261
|
+
rb_class2name(CLASS_OF(argv[0])));
|
262
|
+
|
263
|
+
Data_Get_Struct(argv[0], gsl_eigen_symmv_workspace, w);
|
264
|
+
break;
|
265
|
+
case 0:
|
266
|
+
w = gsl_eigen_symmv_alloc(Atmp->size1);
|
267
|
+
flagw = 1;
|
268
|
+
break;
|
269
|
+
default:
|
270
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
271
|
+
break;
|
272
|
+
}
|
273
|
+
}
|
274
|
+
A = make_matrix_clone(Atmp);
|
275
|
+
em = gsl_matrix_alloc(A->size1, A->size2);
|
276
|
+
v = gsl_vector_alloc(A->size1);
|
277
|
+
gsl_eigen_symmv(A, v, em, w);
|
278
|
+
/* gsl_eigen_symmv_sort(v, em, GSL_EIGEN_SORT_VAL_DESC);*/
|
279
|
+
gsl_matrix_free(A);
|
280
|
+
if (flagw == 1) gsl_eigen_symmv_free(w);
|
281
|
+
vval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, v);
|
282
|
+
vvec = Data_Wrap_Struct(cgsl_eigen_vectors, 0, gsl_matrix_free, em);
|
283
|
+
return rb_ary_new3(2, vval, vvec);
|
284
|
+
}
|
285
|
+
|
286
|
+
#ifdef HAVE_NARRAY_H
|
287
|
+
static VALUE rb_gsl_eigen_symmv_narray(int argc, VALUE *argv, VALUE obj)
|
288
|
+
{
|
289
|
+
struct NARRAY *na;
|
290
|
+
VALUE eval, evec;
|
291
|
+
gsl_matrix *A = NULL;
|
292
|
+
gsl_eigen_symmv_workspace *w = NULL;
|
293
|
+
gsl_matrix_view mv;
|
294
|
+
gsl_vector_view vv;
|
295
|
+
int shape1[1], shape2[2];
|
296
|
+
int flagw = 0;
|
297
|
+
switch (argc) {
|
298
|
+
case 2:
|
299
|
+
if (!NA_IsNArray(argv[0]))
|
300
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
301
|
+
rb_class2name(CLASS_OF(argv[0])));
|
302
|
+
GetNArray(argv[0], na);
|
303
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
304
|
+
if (na->shape[0] != na->shape[1])
|
305
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
306
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
307
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
308
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_symmv_workspace)
|
309
|
+
rb_raise(rb_eTypeError,
|
310
|
+
"argv[1]: wrong argument type %s (Eigen::Symm::Workspace expected",
|
311
|
+
rb_class2name(CLASS_OF(argv[1])));
|
312
|
+
Data_Get_Struct(argv[1], gsl_eigen_symmv_workspace, w);
|
313
|
+
flagw = 0;
|
314
|
+
break;
|
315
|
+
case 1:
|
316
|
+
if (!NA_IsNArray(argv[0]))
|
317
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
318
|
+
rb_class2name(CLASS_OF(argv[0])));
|
319
|
+
GetNArray(argv[0], na);
|
320
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
321
|
+
if (na->shape[0] != na->shape[1])
|
322
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
323
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
324
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
325
|
+
w = gsl_eigen_symmv_alloc(A->size1);
|
326
|
+
flagw = 1;
|
327
|
+
break;
|
328
|
+
default:
|
329
|
+
rb_raise(rb_eArgError, "matrix not given");
|
330
|
+
break;
|
331
|
+
}
|
332
|
+
shape1[0] = A->size1;
|
333
|
+
shape2[0] = A->size1;
|
334
|
+
shape2[1] = A->size1;
|
335
|
+
eval = na_make_object(NA_DFLOAT, 1, shape1, cNVector);
|
336
|
+
evec = na_make_object(NA_DFLOAT, 2, shape2, CLASS_OF(argv[0]));
|
337
|
+
vv = gsl_vector_view_array(NA_PTR_TYPE(eval,double*), A->size1);
|
338
|
+
mv = gsl_matrix_view_array(NA_PTR_TYPE(evec,double*), A->size1, A->size2);
|
339
|
+
gsl_eigen_symmv(A, &vv.vector, &mv.matrix, w);
|
340
|
+
/* gsl_sort_vector(v);*/
|
341
|
+
gsl_matrix_free(A);
|
342
|
+
if (flagw == 1) gsl_eigen_symmv_free(w);
|
343
|
+
return rb_ary_new3(2, eval, evec);
|
344
|
+
}
|
345
|
+
#endif
|
346
|
+
|
347
|
+
static VALUE rb_gsl_eigen_herm(int argc, VALUE *argv, VALUE obj)
|
348
|
+
{
|
349
|
+
gsl_matrix_complex *Atmp = NULL, *A = NULL;
|
350
|
+
gsl_eigen_herm_workspace *w = NULL;
|
351
|
+
gsl_vector *v = NULL;
|
352
|
+
int flagw = 0;
|
353
|
+
|
354
|
+
switch (TYPE(obj)) {
|
355
|
+
case T_MODULE:
|
356
|
+
case T_CLASS:
|
357
|
+
case T_OBJECT:
|
358
|
+
switch (argc) {
|
359
|
+
case 2:
|
360
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
361
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, Atmp);
|
362
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_herm_workspace)
|
363
|
+
rb_raise(rb_eTypeError,
|
364
|
+
"argv[1]: wrong argument type %s (Eigen::Herm::Workspace expected)",
|
365
|
+
rb_class2name(CLASS_OF(argv[1])));
|
366
|
+
Data_Get_Struct(argv[1], gsl_eigen_herm_workspace, w);
|
367
|
+
break;
|
368
|
+
case 1:
|
369
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
370
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, Atmp);
|
371
|
+
w = gsl_eigen_herm_alloc(Atmp->size1);
|
372
|
+
flagw = 1;
|
373
|
+
break;
|
374
|
+
default:
|
375
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
376
|
+
}
|
377
|
+
break;
|
378
|
+
default:
|
379
|
+
CHECK_MATRIX_COMPLEX(obj);
|
380
|
+
Data_Get_Struct(obj, gsl_matrix_complex, Atmp);
|
381
|
+
switch (argc) {
|
382
|
+
case 1:
|
383
|
+
if (CLASS_OF(argv[0]) != cgsl_eigen_herm_workspace)
|
384
|
+
rb_raise(rb_eTypeError,
|
385
|
+
"argv[0]: wrong argument type %s (Eigen::Herm::Workspace expected)",
|
386
|
+
rb_class2name(CLASS_OF(argv[0])));
|
387
|
+
|
388
|
+
Data_Get_Struct(argv[0], gsl_eigen_herm_workspace, w);
|
389
|
+
break;
|
390
|
+
case 0:
|
391
|
+
w = gsl_eigen_herm_alloc(Atmp->size1);
|
392
|
+
flagw = 1;
|
393
|
+
break;
|
394
|
+
default:
|
395
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
396
|
+
}
|
397
|
+
}
|
398
|
+
A = make_matrix_complex_clone(Atmp);
|
399
|
+
v = gsl_vector_alloc(A->size1);
|
400
|
+
gsl_eigen_herm(A, v, w);
|
401
|
+
/* gsl_sort_vector(v);*/
|
402
|
+
gsl_matrix_complex_free(A);
|
403
|
+
if (flagw == 1) gsl_eigen_herm_free(w);
|
404
|
+
return Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, v);
|
405
|
+
}
|
406
|
+
|
407
|
+
static VALUE rb_gsl_eigen_hermv(int argc, VALUE *argv, VALUE obj)
|
408
|
+
{
|
409
|
+
gsl_matrix_complex *Atmp = NULL, *A = NULL, *em = NULL;
|
410
|
+
gsl_eigen_hermv_workspace *w = NULL;
|
411
|
+
gsl_vector *v = NULL;
|
412
|
+
int flagw = 0;
|
413
|
+
VALUE vval, vvec;
|
414
|
+
switch (TYPE(obj)) {
|
415
|
+
case T_MODULE:
|
416
|
+
case T_CLASS:
|
417
|
+
case T_OBJECT:
|
418
|
+
switch (argc) {
|
419
|
+
case 2:
|
420
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
421
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, Atmp);
|
422
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_hermv_workspace)
|
423
|
+
rb_raise(rb_eTypeError,
|
424
|
+
"argv[1]: wrong argument type %s (Eigen::Hermv::Workspace expected)",
|
425
|
+
rb_class2name(CLASS_OF(argv[1])));
|
426
|
+
Data_Get_Struct(argv[1], gsl_eigen_hermv_workspace, w);
|
427
|
+
break;
|
428
|
+
case 1:
|
429
|
+
CHECK_MATRIX_COMPLEX(argv[0]);
|
430
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, Atmp);
|
431
|
+
w = gsl_eigen_hermv_alloc(Atmp->size1);
|
432
|
+
flagw = 1;
|
433
|
+
break;
|
434
|
+
default:
|
435
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
436
|
+
}
|
437
|
+
break;
|
438
|
+
default:
|
439
|
+
CHECK_MATRIX_COMPLEX(obj);
|
440
|
+
Data_Get_Struct(obj, gsl_matrix_complex, Atmp);
|
441
|
+
switch (argc) {
|
442
|
+
case 1:
|
443
|
+
if (CLASS_OF(argv[0]) != cgsl_eigen_hermv_workspace)
|
444
|
+
rb_raise(rb_eTypeError,
|
445
|
+
"argv[0]: wrong argument type %s (Eigen::Hermv::Workspace expected)",
|
446
|
+
rb_class2name(CLASS_OF(argv[0])));
|
447
|
+
|
448
|
+
Data_Get_Struct(argv[0], gsl_eigen_hermv_workspace, w);
|
449
|
+
break;
|
450
|
+
case 0:
|
451
|
+
w = gsl_eigen_hermv_alloc(Atmp->size1);
|
452
|
+
flagw = 1;
|
453
|
+
break;
|
454
|
+
default:
|
455
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
456
|
+
}
|
457
|
+
}
|
458
|
+
A = make_matrix_complex_clone(Atmp);
|
459
|
+
em = gsl_matrix_complex_alloc(A->size1, A->size2);
|
460
|
+
v = gsl_vector_alloc(A->size1);
|
461
|
+
gsl_eigen_hermv(A, v, em, w);
|
462
|
+
/* gsl_eigen_hermv_sort(v, em, GSL_EIGEN_SORT_VAL_DESC);*/
|
463
|
+
gsl_matrix_complex_free(A);
|
464
|
+
if (flagw == 1) gsl_eigen_hermv_free(w);
|
465
|
+
vval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, v);
|
466
|
+
vvec = Data_Wrap_Struct(cgsl_eigen_herm_vectors, 0, gsl_matrix_complex_free, em);
|
467
|
+
return rb_ary_new3(2, vval, vvec);
|
468
|
+
}
|
469
|
+
|
470
|
+
static VALUE rb_gsl_eigen_vectors_unpack(VALUE obj)
|
471
|
+
{
|
472
|
+
gsl_matrix *m = NULL;
|
473
|
+
gsl_vector *v = NULL;
|
474
|
+
size_t i, j;
|
475
|
+
double val;
|
476
|
+
VALUE ary, tmp;
|
477
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
478
|
+
ary = rb_ary_new2(m->size1);
|
479
|
+
for (i = 0; i < m->size1; i++) {
|
480
|
+
v = gsl_vector_alloc(m->size2);
|
481
|
+
for (j = 0; j < m->size2; j++) {
|
482
|
+
val = gsl_matrix_get(m, j, i);
|
483
|
+
gsl_vector_set(v, j, val);
|
484
|
+
}
|
485
|
+
tmp = Data_Wrap_Struct(cgsl_eigen_vector, 0, gsl_vector_free, v);
|
486
|
+
rb_ary_store(ary, i, tmp);
|
487
|
+
}
|
488
|
+
return ary;
|
489
|
+
}
|
490
|
+
|
491
|
+
static VALUE rb_gsl_eigen_vectors_complex_unpack(VALUE obj)
|
492
|
+
{
|
493
|
+
gsl_matrix_complex *m = NULL;
|
494
|
+
gsl_vector_complex *v = NULL;
|
495
|
+
size_t i, j;
|
496
|
+
gsl_complex z;
|
497
|
+
VALUE ary, tmp;
|
498
|
+
Data_Get_Struct(obj, gsl_matrix_complex, m);
|
499
|
+
ary = rb_ary_new2(m->size1);
|
500
|
+
for (i = 0; i < m->size1; i++) {
|
501
|
+
v = gsl_vector_complex_alloc(m->size2);
|
502
|
+
for (j = 0; j < m->size2; j++) {
|
503
|
+
z= gsl_matrix_complex_get(m, j, i);
|
504
|
+
gsl_vector_complex_set(v, j, z);
|
505
|
+
}
|
506
|
+
tmp = Data_Wrap_Struct(cgsl_eigen_vector_complex, 0, gsl_vector_complex_free, v);
|
507
|
+
rb_ary_store(ary, i, tmp);
|
508
|
+
}
|
509
|
+
return ary;
|
510
|
+
}
|
511
|
+
|
512
|
+
static void rb_gsl_eigen_define_const(VALUE topmodule, VALUE module)
|
513
|
+
{
|
514
|
+
rb_define_const(topmodule, "EIGEN_SORT_VAL_ASC", INT2FIX(GSL_EIGEN_SORT_VAL_ASC));
|
515
|
+
rb_define_const(topmodule, "EIGEN_SORT_VAL_DESC", INT2FIX(GSL_EIGEN_SORT_VAL_DESC));
|
516
|
+
rb_define_const(topmodule, "EIGEN_SORT_ABS_ASC", INT2FIX(GSL_EIGEN_SORT_ABS_ASC));
|
517
|
+
rb_define_const(topmodule, "EIGEN_SORT_ABS_DESC", INT2FIX(GSL_EIGEN_SORT_ABS_DESC));
|
518
|
+
|
519
|
+
rb_define_const(module, "SORT_VAL_ASC", INT2FIX(GSL_EIGEN_SORT_VAL_ASC));
|
520
|
+
rb_define_const(module, "SORT_VAL_DESC", INT2FIX(GSL_EIGEN_SORT_VAL_DESC));
|
521
|
+
rb_define_const(module, "SORT_ABS_ASC", INT2FIX(GSL_EIGEN_SORT_ABS_ASC));
|
522
|
+
rb_define_const(module, "SORT_ABS_DESC", INT2FIX(GSL_EIGEN_SORT_ABS_DESC));
|
523
|
+
|
524
|
+
rb_define_const(module, "VAL_ASC", INT2FIX(GSL_EIGEN_SORT_VAL_ASC));
|
525
|
+
rb_define_const(module, "VAL_DESC", INT2FIX(GSL_EIGEN_SORT_VAL_DESC));
|
526
|
+
rb_define_const(module, "ABS_ASC", INT2FIX(GSL_EIGEN_SORT_ABS_ASC));
|
527
|
+
rb_define_const(module, "ABS_DESC", INT2FIX(GSL_EIGEN_SORT_ABS_DESC));
|
528
|
+
}
|
529
|
+
|
530
|
+
static VALUE rb_gsl_eigen_real_sort(int argc, VALUE *argv, VALUE obj,
|
531
|
+
int (*sortfunc)(gsl_vector*, gsl_matrix*, gsl_eigen_sort_t))
|
532
|
+
{
|
533
|
+
gsl_vector *v = NULL;
|
534
|
+
gsl_matrix *m = NULL;
|
535
|
+
gsl_eigen_sort_t type = GSL_EIGEN_SORT_VAL_DESC;
|
536
|
+
switch (argc) {
|
537
|
+
case 3:
|
538
|
+
CHECK_FIXNUM(argv[2]);
|
539
|
+
type = FIX2INT(argv[2]);
|
540
|
+
/* no break, do next */
|
541
|
+
case 2:
|
542
|
+
if (argv[0] == Qnil) {
|
543
|
+
v = NULL;
|
544
|
+
} else {
|
545
|
+
CHECK_VECTOR(argv[0]);
|
546
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
547
|
+
}
|
548
|
+
if (argv[1] == Qnil) {
|
549
|
+
m = NULL;
|
550
|
+
} else {
|
551
|
+
CHECK_MATRIX(argv[1]);
|
552
|
+
Data_Get_Struct(argv[1], gsl_matrix, m);
|
553
|
+
}
|
554
|
+
break;
|
555
|
+
default:
|
556
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
557
|
+
}
|
558
|
+
return INT2FIX((*sortfunc)(v, m, type));
|
559
|
+
}
|
560
|
+
|
561
|
+
|
562
|
+
static VALUE rb_gsl_eigen_complex_sort(int argc, VALUE *argv, VALUE obj,
|
563
|
+
int (*sortfunc)(gsl_vector*, gsl_matrix_complex*, gsl_eigen_sort_t))
|
564
|
+
{
|
565
|
+
gsl_vector *v = NULL;
|
566
|
+
gsl_matrix_complex *m = NULL;
|
567
|
+
gsl_eigen_sort_t type = GSL_EIGEN_SORT_VAL_DESC;
|
568
|
+
|
569
|
+
switch (argc) {
|
570
|
+
case 3:
|
571
|
+
CHECK_FIXNUM(argv[2]);
|
572
|
+
type = FIX2INT(argv[2]);
|
573
|
+
/* no break, do next */
|
574
|
+
case 2:
|
575
|
+
if (argv[0] == Qnil) {
|
576
|
+
v = NULL;
|
577
|
+
} else {
|
578
|
+
CHECK_VECTOR(argv[0]);
|
579
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
580
|
+
}
|
581
|
+
if (argv[1] == Qnil) {
|
582
|
+
m = NULL;
|
583
|
+
} else {
|
584
|
+
CHECK_MATRIX_COMPLEX(argv[1]);
|
585
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, m);
|
586
|
+
}
|
587
|
+
break;
|
588
|
+
default:
|
589
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
590
|
+
}
|
591
|
+
return INT2FIX((*sortfunc)(v, m, type));
|
592
|
+
}
|
593
|
+
static VALUE rb_gsl_eigen_symmv_sort(int argc, VALUE *argv, VALUE obj)
|
594
|
+
{
|
595
|
+
return rb_gsl_eigen_real_sort(argc, argv, obj, gsl_eigen_symmv_sort);
|
596
|
+
}
|
597
|
+
static VALUE rb_gsl_eigen_hermv_sort(int argc, VALUE *argv, VALUE obj)
|
598
|
+
{
|
599
|
+
return rb_gsl_eigen_complex_sort(argc, argv, obj, gsl_eigen_hermv_sort);
|
600
|
+
}
|
601
|
+
|
602
|
+
|
603
|
+
#ifdef HAVE_EIGEN_FRANCIS
|
604
|
+
static VALUE rb_gsl_eigen_francis_alloc(VALUE klass)
|
605
|
+
{
|
606
|
+
gsl_eigen_francis_workspace *w = NULL;
|
607
|
+
w = gsl_eigen_francis_alloc();
|
608
|
+
return Data_Wrap_Struct(klass, 0, gsl_eigen_francis_free, w);
|
609
|
+
}
|
610
|
+
|
611
|
+
static VALUE rb_gsl_eigen_francis_T(int argc, VALUE *argv, VALUE obj)
|
612
|
+
{
|
613
|
+
gsl_eigen_francis_workspace *w = NULL;
|
614
|
+
int istart = 0;
|
615
|
+
if (CLASS_OF(obj) == cgsl_eigen_francis_workspace) {
|
616
|
+
Data_Get_Struct(obj, gsl_eigen_francis_workspace, w);
|
617
|
+
istart = 0;
|
618
|
+
} else {
|
619
|
+
if (argc != 1) rb_raise(rb_eArgError, "too few arguments (%d for 1)\n", argc);
|
620
|
+
Data_Get_Struct(argv[0], gsl_eigen_francis_workspace, w);
|
621
|
+
istart = 1;
|
622
|
+
}
|
623
|
+
gsl_eigen_francis_T(FIX2INT(argv[istart]), w);
|
624
|
+
|
625
|
+
return Qtrue;
|
626
|
+
}
|
627
|
+
|
628
|
+
#ifdef HAVE_NARRAY_H
|
629
|
+
static VALUE rb_gsl_eigen_francis_narray(int argc, VALUE *argv, VALUE obj);
|
630
|
+
#endif
|
631
|
+
|
632
|
+
static VALUE rb_gsl_eigen_francis(int argc, VALUE *argv, VALUE obj)
|
633
|
+
{
|
634
|
+
gsl_matrix *m, *mtmp;
|
635
|
+
gsl_vector_complex *v;
|
636
|
+
gsl_eigen_francis_workspace *w;
|
637
|
+
int vflag = 0, wflag = 0;
|
638
|
+
int istart = 0;
|
639
|
+
VALUE *argv2;
|
640
|
+
|
641
|
+
#ifdef HAVE_NARRAY_H
|
642
|
+
if (NA_IsNArray(obj)) return rb_gsl_eigen_francis_narray(argc, argv, obj);
|
643
|
+
if (argc >= 1 && NA_IsNArray(argv[0]))
|
644
|
+
return rb_gsl_eigen_francis_narray(argc, argv, obj);
|
645
|
+
#endif
|
646
|
+
|
647
|
+
if (MATRIX_P(obj)) {
|
648
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
649
|
+
argv2 = argv;
|
650
|
+
istart = 0;
|
651
|
+
} else {
|
652
|
+
if (argc < 1) rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
653
|
+
Data_Get_Struct(argv[0], gsl_matrix, m);
|
654
|
+
istart = 1;
|
655
|
+
argv2 = argv + 1;
|
656
|
+
}
|
657
|
+
|
658
|
+
switch (argc-istart) {
|
659
|
+
case 0:
|
660
|
+
v = gsl_vector_complex_alloc(m->size1);
|
661
|
+
w = gsl_eigen_francis_alloc();
|
662
|
+
vflag = 1;
|
663
|
+
wflag = 1;
|
664
|
+
break;
|
665
|
+
case 1:
|
666
|
+
if (CLASS_OF(argv2[0]) == cgsl_vector_complex) {
|
667
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
668
|
+
w = gsl_eigen_francis_alloc();
|
669
|
+
wflag = 1;
|
670
|
+
} else if (CLASS_OF(argv2[0]) == cgsl_eigen_francis_workspace) {
|
671
|
+
v = gsl_vector_complex_alloc(m->size1);
|
672
|
+
vflag = 1;
|
673
|
+
Data_Get_Struct(argv2[0], gsl_eigen_francis_workspace, w);
|
674
|
+
} else {
|
675
|
+
rb_raise(rb_eArgError, "Wrong argument type.\n");
|
676
|
+
}
|
677
|
+
break;
|
678
|
+
case 2:
|
679
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
680
|
+
if (CLASS_OF(argv2[1]) != cgsl_eigen_francis_workspace) {
|
681
|
+
rb_raise(rb_eArgError, "argv[1] must be a GSL::Eigen::francis::Workspace.\n");
|
682
|
+
}
|
683
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
684
|
+
Data_Get_Struct(argv2[1], gsl_eigen_francis_workspace, w);
|
685
|
+
break;
|
686
|
+
default:
|
687
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2).\n", argc);
|
688
|
+
}
|
689
|
+
mtmp = make_matrix_clone(m);
|
690
|
+
gsl_eigen_francis(mtmp, v, w);
|
691
|
+
gsl_matrix_free(mtmp);
|
692
|
+
if (wflag == 1) gsl_eigen_francis_free(w);
|
693
|
+
if (vflag == 1)
|
694
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
|
695
|
+
else
|
696
|
+
return argv2[0];
|
697
|
+
}
|
698
|
+
|
699
|
+
#ifdef HAVE_NARRAY_H
|
700
|
+
static VALUE rb_gsl_eigen_francis_narray(int argc, VALUE *argv, VALUE obj)
|
701
|
+
{
|
702
|
+
struct NARRAY *na;
|
703
|
+
VALUE nary;
|
704
|
+
gsl_matrix *A = NULL;
|
705
|
+
gsl_eigen_francis_workspace *w = NULL;
|
706
|
+
gsl_vector_complex_view vv;
|
707
|
+
int shape[1];
|
708
|
+
int flagw = 0;
|
709
|
+
switch (argc) {
|
710
|
+
case 2:
|
711
|
+
if (!NA_IsNArray(argv[0]))
|
712
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
713
|
+
rb_class2name(CLASS_OF(argv[0])));
|
714
|
+
GetNArray(argv[0], na);
|
715
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
716
|
+
if (na->shape[0] != na->shape[1])
|
717
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
718
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
719
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
720
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_francis_workspace)
|
721
|
+
rb_raise(rb_eTypeError,
|
722
|
+
"argv[1]: wrong argument type %s (Eigen::Symm::Workspace expected",
|
723
|
+
rb_class2name(CLASS_OF(argv[1])));
|
724
|
+
Data_Get_Struct(argv[1], gsl_eigen_francis_workspace, w);
|
725
|
+
flagw = 0;
|
726
|
+
break;
|
727
|
+
case 1:
|
728
|
+
if (!NA_IsNArray(argv[0]))
|
729
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
730
|
+
rb_class2name(CLASS_OF(argv[0])));
|
731
|
+
GetNArray(argv[0], na);
|
732
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
733
|
+
if (na->shape[0] != na->shape[1])
|
734
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
735
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
736
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
737
|
+
w = gsl_eigen_francis_alloc();
|
738
|
+
flagw = 1;
|
739
|
+
break;
|
740
|
+
default:
|
741
|
+
rb_raise(rb_eArgError, "matrix not given");
|
742
|
+
break;
|
743
|
+
}
|
744
|
+
shape[0] = A->size1;
|
745
|
+
nary = na_make_object(NA_DCOMPLEX, 1, shape, cNVector);
|
746
|
+
vv = gsl_vector_complex_view_array(NA_PTR_TYPE(nary,double*), A->size1);
|
747
|
+
gsl_eigen_francis(A, &vv.vector, w);
|
748
|
+
/* gsl_sort_vector(v);*/
|
749
|
+
gsl_matrix_free(A);
|
750
|
+
if (flagw == 1) gsl_eigen_francis_free(w);
|
751
|
+
return nary;
|
752
|
+
}
|
753
|
+
#endif
|
754
|
+
|
755
|
+
static VALUE rb_gsl_eigen_francis_Z(int argc, VALUE *argv, VALUE obj)
|
756
|
+
{
|
757
|
+
gsl_matrix *m, *mtmp, *Z;
|
758
|
+
gsl_vector_complex *v;
|
759
|
+
gsl_eigen_francis_workspace *w;
|
760
|
+
int vflag = 0, wflag = 0;
|
761
|
+
int istart = 0;
|
762
|
+
VALUE *argv2, vv, ZZ;
|
763
|
+
|
764
|
+
if (MATRIX_P(obj)) {
|
765
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
766
|
+
argv2 = argv;
|
767
|
+
istart = 0;
|
768
|
+
} else {
|
769
|
+
if (argc < 1) rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
770
|
+
Data_Get_Struct(argv[0], gsl_matrix, m);
|
771
|
+
istart = 1;
|
772
|
+
argv2 = argv + 1;
|
773
|
+
}
|
774
|
+
|
775
|
+
switch (argc-istart) {
|
776
|
+
case 0:
|
777
|
+
v = gsl_vector_complex_alloc(m->size1);
|
778
|
+
Z = gsl_matrix_alloc(m->size1, m->size2);
|
779
|
+
w = gsl_eigen_francis_alloc();
|
780
|
+
vflag = 1;
|
781
|
+
wflag = 1;
|
782
|
+
break;
|
783
|
+
case 1:
|
784
|
+
if (CLASS_OF(argv2[0]) == cgsl_eigen_francis_workspace) {
|
785
|
+
v = gsl_vector_complex_alloc(m->size1);
|
786
|
+
Z = gsl_matrix_alloc(m->size1, m->size2);
|
787
|
+
vflag = 1;
|
788
|
+
Data_Get_Struct(argv2[0], gsl_eigen_francis_workspace, w);
|
789
|
+
} else {
|
790
|
+
rb_raise(rb_eArgError, "Wrong argument type.\n");
|
791
|
+
}
|
792
|
+
break;
|
793
|
+
case 3:
|
794
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
795
|
+
CHECK_MATRIX(argv2[1]);
|
796
|
+
if (CLASS_OF(argv2[2]) != cgsl_eigen_francis_workspace) {
|
797
|
+
rb_raise(rb_eArgError, "argv[1] must be a GSL::Eigen::francis::Workspace.\n");
|
798
|
+
}
|
799
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
800
|
+
Data_Get_Struct(argv2[1], gsl_matrix, Z);
|
801
|
+
Data_Get_Struct(argv2[2], gsl_eigen_francis_workspace, w);
|
802
|
+
break;
|
803
|
+
default:
|
804
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2).\n", argc);
|
805
|
+
}
|
806
|
+
mtmp = make_matrix_clone(m);
|
807
|
+
gsl_eigen_francis_Z(mtmp, v, Z, w);
|
808
|
+
gsl_matrix_free(mtmp);
|
809
|
+
|
810
|
+
if (wflag == 1) gsl_eigen_francis_free(w);
|
811
|
+
if (vflag == 1) {
|
812
|
+
vv = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
|
813
|
+
ZZ = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Z);
|
814
|
+
} else {
|
815
|
+
vv = argv2[0];
|
816
|
+
ZZ = argv2[1];
|
817
|
+
}
|
818
|
+
return rb_ary_new3(2, vv, ZZ);
|
819
|
+
}
|
820
|
+
#endif
|
821
|
+
|
822
|
+
#ifdef GSL_1_9_LATER
|
823
|
+
static VALUE rb_gsl_eigen_nonsymm_alloc(VALUE klass, VALUE nn)
|
824
|
+
{
|
825
|
+
size_t n;
|
826
|
+
gsl_eigen_nonsymm_workspace *w = NULL;
|
827
|
+
n = (size_t) FIX2UINT(nn);
|
828
|
+
w = gsl_eigen_nonsymm_alloc(n);
|
829
|
+
return Data_Wrap_Struct(cgsl_eigen_nonsymm_workspace, 0, gsl_eigen_nonsymm_free, w);
|
830
|
+
}
|
831
|
+
|
832
|
+
static VALUE rb_gsl_eigen_nonsymm_params(int argc, VALUE *argv, VALUE obj)
|
833
|
+
{
|
834
|
+
gsl_eigen_nonsymm_workspace *w = NULL;
|
835
|
+
int istart = 0;
|
836
|
+
if (CLASS_OF(obj) == cgsl_eigen_nonsymm_workspace) {
|
837
|
+
Data_Get_Struct(obj, gsl_eigen_nonsymm_workspace, w);
|
838
|
+
istart = 0;
|
839
|
+
} else {
|
840
|
+
if (argc != 3) rb_raise(rb_eArgError, "too few arguments (%d for 3)\n", argc);
|
841
|
+
Data_Get_Struct(argv[2], gsl_eigen_nonsymm_workspace, w);
|
842
|
+
istart = 1;
|
843
|
+
}
|
844
|
+
switch (argc - istart) {
|
845
|
+
case 2:
|
846
|
+
gsl_eigen_nonsymm_params(FIX2INT(argv[0]), FIX2INT(argv[1]), w);
|
847
|
+
break;
|
848
|
+
default:
|
849
|
+
rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
850
|
+
}
|
851
|
+
return Qtrue;
|
852
|
+
}
|
853
|
+
|
854
|
+
#ifdef HAVE_NARRAY_H
|
855
|
+
static VALUE rb_gsl_eigen_nonsymm_narray(int argc, VALUE *argv, VALUE obj);
|
856
|
+
#endif
|
857
|
+
|
858
|
+
static VALUE rb_gsl_eigen_nonsymm(int argc, VALUE *argv, VALUE obj)
|
859
|
+
{
|
860
|
+
gsl_matrix *m;
|
861
|
+
gsl_vector_complex *v;
|
862
|
+
gsl_eigen_nonsymm_workspace *w;
|
863
|
+
int vflag = 0, wflag = 0;
|
864
|
+
int istart = 0;
|
865
|
+
VALUE *argv2;
|
866
|
+
|
867
|
+
#ifdef HAVE_NARRAY_H
|
868
|
+
if (NA_IsNArray(obj)) return rb_gsl_eigen_nonsymm_narray(argc, argv, obj);
|
869
|
+
if (argc >= 1 && NA_IsNArray(argv[0]))
|
870
|
+
return rb_gsl_eigen_nonsymm_narray(argc, argv, obj);
|
871
|
+
#endif
|
872
|
+
|
873
|
+
if (MATRIX_P(obj)) {
|
874
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
875
|
+
argv2 = argv;
|
876
|
+
istart = 0;
|
877
|
+
} else {
|
878
|
+
if (argc < 1) rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
879
|
+
Data_Get_Struct(argv[0], gsl_matrix, m);
|
880
|
+
istart = 1;
|
881
|
+
argv2 = argv + 1;
|
882
|
+
}
|
883
|
+
|
884
|
+
switch (argc-istart) {
|
885
|
+
case 0:
|
886
|
+
v = gsl_vector_complex_alloc(m->size1);
|
887
|
+
w = gsl_eigen_nonsymm_alloc(m->size1);
|
888
|
+
vflag = 1;
|
889
|
+
wflag = 1;
|
890
|
+
break;
|
891
|
+
case 1:
|
892
|
+
if (CLASS_OF(argv2[0]) == cgsl_vector_complex) {
|
893
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
894
|
+
w = gsl_eigen_nonsymm_alloc(m->size1);
|
895
|
+
wflag = 1;
|
896
|
+
} else if (CLASS_OF(argv2[0]) == cgsl_eigen_nonsymm_workspace) {
|
897
|
+
v = gsl_vector_complex_alloc(m->size1);
|
898
|
+
vflag = 1;
|
899
|
+
Data_Get_Struct(argv2[0], gsl_eigen_nonsymm_workspace, w);
|
900
|
+
} else {
|
901
|
+
rb_raise(rb_eArgError, "Wrong argument type.\n");
|
902
|
+
}
|
903
|
+
break;
|
904
|
+
case 2:
|
905
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
906
|
+
if (CLASS_OF(argv2[1]) != cgsl_eigen_nonsymm_workspace) {
|
907
|
+
rb_raise(rb_eArgError, "argv[1] must be a GSL::Eigen::Nonsymm::Workspace.\n");
|
908
|
+
}
|
909
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
910
|
+
Data_Get_Struct(argv2[1], gsl_eigen_nonsymm_workspace, w);
|
911
|
+
break;
|
912
|
+
default:
|
913
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2).\n", argc);
|
914
|
+
}
|
915
|
+
// mtmp = make_matrix_clone(m);
|
916
|
+
gsl_eigen_nonsymm(m, v, w);
|
917
|
+
// gsl_matrix_free(mtmp);
|
918
|
+
if (wflag == 1) gsl_eigen_nonsymm_free(w);
|
919
|
+
if (vflag == 1)
|
920
|
+
return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
|
921
|
+
else
|
922
|
+
return argv2[0];
|
923
|
+
}
|
924
|
+
|
925
|
+
#ifdef HAVE_NARRAY_H
|
926
|
+
static VALUE rb_gsl_eigen_nonsymm_narray(int argc, VALUE *argv, VALUE obj)
|
927
|
+
{
|
928
|
+
struct NARRAY *na;
|
929
|
+
VALUE nary;
|
930
|
+
gsl_matrix *A = NULL;
|
931
|
+
gsl_eigen_nonsymm_workspace *w = NULL;
|
932
|
+
gsl_vector_complex_view vv;
|
933
|
+
int shape[1];
|
934
|
+
int flagw = 0;
|
935
|
+
switch (argc) {
|
936
|
+
case 2:
|
937
|
+
if (!NA_IsNArray(argv[0]))
|
938
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
939
|
+
rb_class2name(CLASS_OF(argv[0])));
|
940
|
+
GetNArray(argv[0], na);
|
941
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
942
|
+
if (na->shape[0] != na->shape[1])
|
943
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
944
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
945
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
946
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_nonsymm_workspace)
|
947
|
+
rb_raise(rb_eTypeError,
|
948
|
+
"argv[1]: wrong argument type %s (Eigen::Symm::Workspace expected",
|
949
|
+
rb_class2name(CLASS_OF(argv[1])));
|
950
|
+
Data_Get_Struct(argv[1], gsl_eigen_nonsymm_workspace, w);
|
951
|
+
flagw = 0;
|
952
|
+
break;
|
953
|
+
case 1:
|
954
|
+
if (!NA_IsNArray(argv[0]))
|
955
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
956
|
+
rb_class2name(CLASS_OF(argv[0])));
|
957
|
+
GetNArray(argv[0], na);
|
958
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
959
|
+
if (na->shape[0] != na->shape[1])
|
960
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
961
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
962
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
963
|
+
w = gsl_eigen_nonsymm_alloc(A->size1);
|
964
|
+
flagw = 1;
|
965
|
+
break;
|
966
|
+
default:
|
967
|
+
rb_raise(rb_eArgError, "matrix not given");
|
968
|
+
break;
|
969
|
+
}
|
970
|
+
shape[0] = A->size1;
|
971
|
+
nary = na_make_object(NA_DCOMPLEX, 1, shape, cNVector);
|
972
|
+
vv = gsl_vector_complex_view_array(NA_PTR_TYPE(nary,double*), A->size1);
|
973
|
+
gsl_eigen_nonsymm(A, &vv.vector, w);
|
974
|
+
/* gsl_sort_vector(v);*/
|
975
|
+
gsl_matrix_free(A);
|
976
|
+
if (flagw == 1) gsl_eigen_nonsymm_free(w);
|
977
|
+
return nary;
|
978
|
+
}
|
979
|
+
#endif
|
980
|
+
|
981
|
+
static VALUE rb_gsl_eigen_nonsymm_Z(int argc, VALUE *argv, VALUE obj)
|
982
|
+
{
|
983
|
+
gsl_matrix *m, *Z;
|
984
|
+
gsl_vector_complex *v;
|
985
|
+
gsl_eigen_nonsymm_workspace *w;
|
986
|
+
int vflag = 0, wflag = 0;
|
987
|
+
int istart = 0;
|
988
|
+
VALUE *argv2, vv, ZZ;
|
989
|
+
|
990
|
+
if (MATRIX_P(obj)) {
|
991
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
992
|
+
argv2 = argv;
|
993
|
+
istart = 0;
|
994
|
+
} else {
|
995
|
+
if (argc < 1) rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
996
|
+
Data_Get_Struct(argv[0], gsl_matrix, m);
|
997
|
+
istart = 1;
|
998
|
+
argv2 = argv + 1;
|
999
|
+
}
|
1000
|
+
|
1001
|
+
switch (argc-istart) {
|
1002
|
+
case 0:
|
1003
|
+
v = gsl_vector_complex_alloc(m->size1);
|
1004
|
+
Z = gsl_matrix_alloc(m->size1, m->size2);
|
1005
|
+
w = gsl_eigen_nonsymm_alloc(m->size1);
|
1006
|
+
vflag = 1;
|
1007
|
+
wflag = 1;
|
1008
|
+
break;
|
1009
|
+
case 1:
|
1010
|
+
if (CLASS_OF(argv2[0]) == cgsl_eigen_nonsymm_workspace) {
|
1011
|
+
v = gsl_vector_complex_alloc(m->size1);
|
1012
|
+
Z = gsl_matrix_alloc(m->size1, m->size2);
|
1013
|
+
vflag = 1;
|
1014
|
+
Data_Get_Struct(argv2[0], gsl_eigen_nonsymm_workspace, w);
|
1015
|
+
} else {
|
1016
|
+
rb_raise(rb_eArgError, "Wrong argument type.\n");
|
1017
|
+
}
|
1018
|
+
break;
|
1019
|
+
case 3:
|
1020
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
1021
|
+
CHECK_MATRIX(argv2[1]);
|
1022
|
+
if (CLASS_OF(argv2[2]) != cgsl_eigen_nonsymm_workspace) {
|
1023
|
+
rb_raise(rb_eArgError, "argv[1] must be a GSL::Eigen::Nonsymm::Workspace.\n");
|
1024
|
+
}
|
1025
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
1026
|
+
Data_Get_Struct(argv2[1], gsl_matrix, Z);
|
1027
|
+
Data_Get_Struct(argv2[2], gsl_eigen_nonsymm_workspace, w);
|
1028
|
+
break;
|
1029
|
+
default:
|
1030
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2).\n", argc);
|
1031
|
+
}
|
1032
|
+
// mtmp = make_matrix_clone(m);
|
1033
|
+
gsl_eigen_nonsymm_Z(m, v, Z, w);
|
1034
|
+
// gsl_matrix_free(mtmp);
|
1035
|
+
|
1036
|
+
if (wflag == 1) gsl_eigen_nonsymm_free(w);
|
1037
|
+
if (vflag == 1) {
|
1038
|
+
vv = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
|
1039
|
+
ZZ = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Z);
|
1040
|
+
} else {
|
1041
|
+
vv = argv2[0];
|
1042
|
+
ZZ = argv2[1];
|
1043
|
+
}
|
1044
|
+
return rb_ary_new3(2, vv, ZZ);
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
static VALUE rb_gsl_eigen_nonsymmv_alloc(VALUE klass, VALUE nn)
|
1048
|
+
{
|
1049
|
+
size_t n;
|
1050
|
+
gsl_eigen_nonsymmv_workspace *w = NULL;
|
1051
|
+
n = (size_t) FIX2UINT(nn);
|
1052
|
+
w = gsl_eigen_nonsymmv_alloc(n);
|
1053
|
+
return Data_Wrap_Struct(cgsl_eigen_nonsymmv_workspace, 0, gsl_eigen_nonsymmv_free, w);
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
#ifdef HAVE_NARRAY_H
|
1057
|
+
static VALUE rb_gsl_eigen_nonsymmv_narray(int argc, VALUE *argv, VALUE obj);
|
1058
|
+
#endif
|
1059
|
+
|
1060
|
+
static VALUE rb_gsl_eigen_nonsymmv(int argc, VALUE *argv, VALUE obj)
|
1061
|
+
{
|
1062
|
+
gsl_matrix *m;
|
1063
|
+
gsl_vector_complex *v;
|
1064
|
+
gsl_matrix_complex *evec;
|
1065
|
+
gsl_eigen_nonsymmv_workspace *w;
|
1066
|
+
int vflag = 0, wflag = 0;
|
1067
|
+
int istart = 0;
|
1068
|
+
VALUE *argv2;
|
1069
|
+
|
1070
|
+
#ifdef HAVE_NARRAY_H
|
1071
|
+
if (NA_IsNArray(obj)) return rb_gsl_eigen_nonsymmv_narray(argc, argv, obj);
|
1072
|
+
if (argc >= 1 && NA_IsNArray(argv[0]))
|
1073
|
+
return rb_gsl_eigen_nonsymmv_narray(argc, argv, obj);
|
1074
|
+
#endif
|
1075
|
+
|
1076
|
+
if (MATRIX_P(obj)) {
|
1077
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
1078
|
+
argv2 = argv;
|
1079
|
+
istart = 0;
|
1080
|
+
} else {
|
1081
|
+
if (argc < 1) rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
1082
|
+
Data_Get_Struct(argv[0], gsl_matrix, m);
|
1083
|
+
istart = 1;
|
1084
|
+
argv2 = argv + 1;
|
1085
|
+
}
|
1086
|
+
|
1087
|
+
switch (argc-istart) {
|
1088
|
+
case 0:
|
1089
|
+
v = gsl_vector_complex_alloc(m->size1);
|
1090
|
+
evec = gsl_matrix_complex_alloc(m->size1, m->size2);
|
1091
|
+
w = gsl_eigen_nonsymmv_alloc(m->size1);
|
1092
|
+
vflag = 1;
|
1093
|
+
wflag = 1;
|
1094
|
+
break;
|
1095
|
+
case 1:
|
1096
|
+
if (CLASS_OF(argv2[0]) == cgsl_eigen_nonsymmv_workspace) {
|
1097
|
+
v = gsl_vector_complex_alloc(m->size1);
|
1098
|
+
evec = gsl_matrix_complex_alloc(m->size1, m->size2);
|
1099
|
+
vflag = 1;
|
1100
|
+
Data_Get_Struct(argv2[0], gsl_eigen_nonsymmv_workspace, w);
|
1101
|
+
} else {
|
1102
|
+
rb_raise(rb_eArgError, "Wrong argument type.\n");
|
1103
|
+
}
|
1104
|
+
break;
|
1105
|
+
case 2:
|
1106
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
1107
|
+
CHECK_MATRIX_COMPLEX(argv2[1]);
|
1108
|
+
w = gsl_eigen_nonsymmv_alloc(m->size1);
|
1109
|
+
wflag = 1;
|
1110
|
+
break;
|
1111
|
+
case 3:
|
1112
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
1113
|
+
CHECK_MATRIX_COMPLEX(argv2[1]);
|
1114
|
+
if (CLASS_OF(argv2[2]) != cgsl_eigen_nonsymmv_workspace) {
|
1115
|
+
rb_raise(rb_eArgError, "argv[1] must be a GSL::Eigen::Nonsymm::Workspace.\n");
|
1116
|
+
}
|
1117
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
1118
|
+
Data_Get_Struct(argv2[1], gsl_matrix_complex, evec);
|
1119
|
+
Data_Get_Struct(argv2[2], gsl_eigen_nonsymmv_workspace, w);
|
1120
|
+
break;
|
1121
|
+
default:
|
1122
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-3).\n", argc);
|
1123
|
+
}
|
1124
|
+
// mtmp = make_matrix_clone(m);
|
1125
|
+
gsl_eigen_nonsymmv(m, v, evec, w);
|
1126
|
+
// gsl_matrix_free(mtmp);
|
1127
|
+
|
1128
|
+
if (wflag == 1) gsl_eigen_nonsymmv_free(w);
|
1129
|
+
if (vflag == 1) {
|
1130
|
+
return rb_ary_new3(2,
|
1131
|
+
Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v),
|
1132
|
+
Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, evec));
|
1133
|
+
} else {
|
1134
|
+
return rb_ary_new3(2, argv2[0], argv2[1]);
|
1135
|
+
}
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
#ifdef HAVE_NARRAY_H
|
1139
|
+
static VALUE rb_gsl_eigen_nonsymmv_narray(int argc, VALUE *argv, VALUE obj)
|
1140
|
+
{
|
1141
|
+
struct NARRAY *na;
|
1142
|
+
VALUE nary, nvec;
|
1143
|
+
gsl_matrix *A = NULL;
|
1144
|
+
gsl_eigen_nonsymmv_workspace *w = NULL;
|
1145
|
+
gsl_vector_complex_view vv;
|
1146
|
+
gsl_matrix_complex_view mm;
|
1147
|
+
int shape[1], shape2[2];
|
1148
|
+
int flagw = 0;
|
1149
|
+
switch (argc) {
|
1150
|
+
case 2:
|
1151
|
+
if (!NA_IsNArray(argv[0]))
|
1152
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
1153
|
+
rb_class2name(CLASS_OF(argv[0])));
|
1154
|
+
GetNArray(argv[0], na);
|
1155
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
1156
|
+
if (na->shape[0] != na->shape[1])
|
1157
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
1158
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
1159
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
1160
|
+
if (CLASS_OF(argv[1]) != cgsl_eigen_nonsymmv_workspace)
|
1161
|
+
rb_raise(rb_eTypeError,
|
1162
|
+
"argv[1]: wrong argument type %s (Eigen::Symm::Workspace expected",
|
1163
|
+
rb_class2name(CLASS_OF(argv[1])));
|
1164
|
+
Data_Get_Struct(argv[1], gsl_eigen_nonsymmv_workspace, w);
|
1165
|
+
flagw = 0;
|
1166
|
+
break;
|
1167
|
+
case 1:
|
1168
|
+
if (!NA_IsNArray(argv[0]))
|
1169
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (NArray expected)",
|
1170
|
+
rb_class2name(CLASS_OF(argv[0])));
|
1171
|
+
GetNArray(argv[0], na);
|
1172
|
+
if (na->rank < 2) rb_raise(rb_eRuntimeError, "rank >= 2 required");
|
1173
|
+
if (na->shape[0] != na->shape[1])
|
1174
|
+
rb_raise(rb_eRuntimeError, "square matrix required");
|
1175
|
+
A = gsl_matrix_alloc(na->shape[1], na->shape[0]);
|
1176
|
+
memcpy(A->data, (double*) na->ptr, sizeof(double)*A->size1*A->size2);
|
1177
|
+
w = gsl_eigen_nonsymmv_alloc(A->size1);
|
1178
|
+
flagw = 1;
|
1179
|
+
break;
|
1180
|
+
default:
|
1181
|
+
rb_raise(rb_eArgError, "matrix not given");
|
1182
|
+
break;
|
1183
|
+
}
|
1184
|
+
shape[0] = A->size1; shape2[0] = A->size1; shape2[1] = A->size2;
|
1185
|
+
nary = na_make_object(NA_DCOMPLEX, 1, shape, cNVector);
|
1186
|
+
vv = gsl_vector_complex_view_array(NA_PTR_TYPE(nary,double*), A->size1);
|
1187
|
+
nvec = na_make_object(NA_DCOMPLEX, 2, shape2, CLASS_OF(argv[0]));
|
1188
|
+
mm = gsl_matrix_complex_view_array(NA_PTR_TYPE(nvec,double*), A->size1, A->size2);
|
1189
|
+
gsl_eigen_nonsymmv(A, &vv.vector, &mm.matrix, w);
|
1190
|
+
/* gsl_sort_vector(v);*/
|
1191
|
+
gsl_matrix_free(A);
|
1192
|
+
if (flagw == 1) gsl_eigen_nonsymmv_free(w);
|
1193
|
+
return rb_ary_new3(2, nary, nvec);
|
1194
|
+
}
|
1195
|
+
#endif
|
1196
|
+
|
1197
|
+
static VALUE rb_gsl_eigen_nonsymmv_Z(int argc, VALUE *argv, VALUE obj)
|
1198
|
+
{
|
1199
|
+
gsl_matrix *m, *Z;
|
1200
|
+
gsl_vector_complex *v;
|
1201
|
+
gsl_matrix_complex *evec;
|
1202
|
+
gsl_eigen_nonsymmv_workspace *w;
|
1203
|
+
int vflag = 0, wflag = 0;
|
1204
|
+
int istart = 0;
|
1205
|
+
VALUE *argv2;
|
1206
|
+
|
1207
|
+
if (MATRIX_P(obj)) {
|
1208
|
+
Data_Get_Struct(obj, gsl_matrix, m);
|
1209
|
+
argv2 = argv;
|
1210
|
+
istart = 0;
|
1211
|
+
} else {
|
1212
|
+
if (argc < 1) rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
1213
|
+
Data_Get_Struct(argv[0], gsl_matrix, m);
|
1214
|
+
istart = 1;
|
1215
|
+
argv2 = argv + 1;
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
switch (argc-istart) {
|
1219
|
+
case 0:
|
1220
|
+
v = gsl_vector_complex_alloc(m->size1);
|
1221
|
+
evec = gsl_matrix_complex_alloc(m->size1, m->size2);
|
1222
|
+
Z = gsl_matrix_alloc(m->size1, m->size2);
|
1223
|
+
w = gsl_eigen_nonsymmv_alloc(m->size1);
|
1224
|
+
vflag = 1;
|
1225
|
+
wflag = 1;
|
1226
|
+
break;
|
1227
|
+
case 1:
|
1228
|
+
if (CLASS_OF(argv2[0]) == cgsl_eigen_nonsymm_workspace) {
|
1229
|
+
v = gsl_vector_complex_alloc(m->size1);
|
1230
|
+
evec = gsl_matrix_complex_alloc(m->size1, m->size2);
|
1231
|
+
vflag = 1;
|
1232
|
+
Data_Get_Struct(argv2[0], gsl_eigen_nonsymmv_workspace, w);
|
1233
|
+
} else {
|
1234
|
+
rb_raise(rb_eArgError, "Wrong argument type.\n");
|
1235
|
+
}
|
1236
|
+
break;
|
1237
|
+
case 3:
|
1238
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
1239
|
+
CHECK_MATRIX_COMPLEX(argv2[1]);
|
1240
|
+
CHECK_MATRIX(argv2[2]);
|
1241
|
+
w = gsl_eigen_nonsymmv_alloc(m->size1);
|
1242
|
+
wflag = 1;
|
1243
|
+
break;
|
1244
|
+
case 4:
|
1245
|
+
CHECK_VECTOR_COMPLEX(argv2[0]);
|
1246
|
+
CHECK_MATRIX_COMPLEX(argv2[1]);
|
1247
|
+
CHECK_MATRIX(argv2[2]);
|
1248
|
+
if (CLASS_OF(argv2[3]) != cgsl_eigen_nonsymm_workspace) {
|
1249
|
+
rb_raise(rb_eArgError, "argv[1] must be a GSL::Eigen::Nonsymm::Workspace.\n");
|
1250
|
+
}
|
1251
|
+
Data_Get_Struct(argv2[0], gsl_vector_complex, v);
|
1252
|
+
Data_Get_Struct(argv2[1], gsl_matrix_complex, evec);
|
1253
|
+
Data_Get_Struct(argv2[1], gsl_matrix, Z);
|
1254
|
+
Data_Get_Struct(argv2[3], gsl_eigen_nonsymmv_workspace, w);
|
1255
|
+
break;
|
1256
|
+
default:
|
1257
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-3).\n", argc);
|
1258
|
+
}
|
1259
|
+
// mtmp = make_matrix_clone(m);
|
1260
|
+
gsl_eigen_nonsymmv_Z(m, v, evec, Z, w);
|
1261
|
+
// gsl_matrix_free(mtmp);
|
1262
|
+
|
1263
|
+
if (wflag == 1) gsl_eigen_nonsymmv_free(w);
|
1264
|
+
if (vflag == 1) {
|
1265
|
+
return rb_ary_new3(3,
|
1266
|
+
Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v),
|
1267
|
+
Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, evec),
|
1268
|
+
Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Z));
|
1269
|
+
} else {
|
1270
|
+
return rb_ary_new3(2, argv2[0], argv2[1], argv2[2]);
|
1271
|
+
}
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
static VALUE rb_gsl_eigen_complex_sort2(int argc, VALUE *argv, VALUE obj,
|
1275
|
+
int (*sortfunc)(gsl_vector_complex*, gsl_matrix_complex*, gsl_eigen_sort_t))
|
1276
|
+
{
|
1277
|
+
gsl_vector_complex *v = NULL;
|
1278
|
+
gsl_matrix_complex *m = NULL;
|
1279
|
+
gsl_eigen_sort_t type = GSL_EIGEN_SORT_ABS_DESC;
|
1280
|
+
|
1281
|
+
switch (argc) {
|
1282
|
+
case 3:
|
1283
|
+
CHECK_FIXNUM(argv[2]);
|
1284
|
+
type = FIX2INT(argv[2]);
|
1285
|
+
/* no break, do next */
|
1286
|
+
case 2:
|
1287
|
+
if (argv[0] == Qnil) {
|
1288
|
+
v = NULL;
|
1289
|
+
} else {
|
1290
|
+
CHECK_VECTOR_COMPLEX(argv[0]);
|
1291
|
+
Data_Get_Struct(argv[0], gsl_vector_complex, v);
|
1292
|
+
}
|
1293
|
+
if (argv[1] == Qnil) {
|
1294
|
+
m = NULL;
|
1295
|
+
} else {
|
1296
|
+
CHECK_MATRIX_COMPLEX(argv[1]);
|
1297
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, m);
|
1298
|
+
}
|
1299
|
+
break;
|
1300
|
+
default:
|
1301
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
1302
|
+
}
|
1303
|
+
return INT2FIX((*sortfunc)(v, m, type));
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
|
1307
|
+
static VALUE rb_gsl_eigen_nonsymmv_sort(int argc, VALUE *argv, VALUE obj)
|
1308
|
+
{
|
1309
|
+
return rb_gsl_eigen_complex_sort2(argc, argv, obj, gsl_eigen_nonsymmv_sort);
|
1310
|
+
}
|
1311
|
+
|
1312
|
+
#endif
|
1313
|
+
|
1314
|
+
#ifdef GSL_1_10_LATER
|
1315
|
+
|
1316
|
+
static VALUE rb_gsl_eigen_gensymm_alloc(VALUE klass, VALUE nn)
|
1317
|
+
{
|
1318
|
+
gsl_eigen_gensymm_workspace *w = NULL;
|
1319
|
+
CHECK_FIXNUM(nn);
|
1320
|
+
w = gsl_eigen_gensymm_alloc(FIX2INT(nn));
|
1321
|
+
return Data_Wrap_Struct(cgensymm, 0, gsl_eigen_gensymm_free, w);
|
1322
|
+
}
|
1323
|
+
static VALUE rb_gsl_eigen_gensymmv_alloc(VALUE klass, VALUE nn)
|
1324
|
+
{
|
1325
|
+
gsl_eigen_gensymmv_workspace *w = NULL;
|
1326
|
+
CHECK_FIXNUM(nn);
|
1327
|
+
w = gsl_eigen_gensymmv_alloc(FIX2INT(nn));
|
1328
|
+
return Data_Wrap_Struct(cgensymmv, 0, gsl_eigen_gensymmv_free, w);
|
1329
|
+
}
|
1330
|
+
static VALUE rb_gsl_eigen_genherm_alloc(VALUE klass, VALUE nn)
|
1331
|
+
{
|
1332
|
+
gsl_eigen_genherm_workspace *w = NULL;
|
1333
|
+
CHECK_FIXNUM(nn);
|
1334
|
+
w = gsl_eigen_genherm_alloc(FIX2INT(nn));
|
1335
|
+
return Data_Wrap_Struct(cgenherm, 0, gsl_eigen_genherm_free, w);
|
1336
|
+
}
|
1337
|
+
static VALUE rb_gsl_eigen_genhermv_alloc(VALUE klass, VALUE nn)
|
1338
|
+
{
|
1339
|
+
gsl_eigen_genhermv_workspace *w = NULL;
|
1340
|
+
CHECK_FIXNUM(nn);
|
1341
|
+
w = gsl_eigen_genhermv_alloc(FIX2INT(nn));
|
1342
|
+
return Data_Wrap_Struct(cgenhermv, 0, gsl_eigen_genhermv_free, w);
|
1343
|
+
}
|
1344
|
+
|
1345
|
+
static int check_argv_gensymm(int argc, VALUE *argv, VALUE obj, gsl_matrix **A, gsl_matrix **B,
|
1346
|
+
gsl_vector **eval, gsl_eigen_gensymm_workspace **w)
|
1347
|
+
{
|
1348
|
+
int argc2 = argc;
|
1349
|
+
int flag = 0;
|
1350
|
+
if (CLASS_OF(obj) == cgensymm) {
|
1351
|
+
Data_Get_Struct(obj, gsl_eigen_gensymm_workspace, *w);
|
1352
|
+
} else {
|
1353
|
+
if (rb_obj_is_kind_of(argv[argc-1], cgensymm)) {
|
1354
|
+
Data_Get_Struct(argv[argc-1], gsl_eigen_gensymm_workspace, *w);
|
1355
|
+
argc2 = argc-1;
|
1356
|
+
} else {
|
1357
|
+
/* workspace is not given */
|
1358
|
+
}
|
1359
|
+
}
|
1360
|
+
switch (argc2) {
|
1361
|
+
case 2:
|
1362
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1363
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1364
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1365
|
+
break;
|
1366
|
+
case 3:
|
1367
|
+
if (rb_obj_is_kind_of(argv[2], cgensymm)) {
|
1368
|
+
Data_Get_Struct(argv[2], gsl_eigen_gensymm_workspace, *w);
|
1369
|
+
} else {
|
1370
|
+
CHECK_VECTOR(argv[2]);
|
1371
|
+
Data_Get_Struct(argv[2], gsl_vector, *eval);
|
1372
|
+
}
|
1373
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1374
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1375
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1376
|
+
break;
|
1377
|
+
default:
|
1378
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
1379
|
+
}
|
1380
|
+
if (*eval == NULL) {
|
1381
|
+
*eval = gsl_vector_alloc((*A)->size1);
|
1382
|
+
flag += 1;
|
1383
|
+
}
|
1384
|
+
if (*w == NULL) {
|
1385
|
+
*w = gsl_eigen_gensymm_alloc((*A)->size1);
|
1386
|
+
flag += 2;
|
1387
|
+
}
|
1388
|
+
return flag;
|
1389
|
+
}
|
1390
|
+
|
1391
|
+
static int check_argv_gensymmv(int argc, VALUE *argv, VALUE obj, gsl_matrix **A, gsl_matrix **B,
|
1392
|
+
gsl_vector **eval, gsl_matrix **evec, gsl_eigen_gensymmv_workspace **w)
|
1393
|
+
{
|
1394
|
+
int argc2 = argc;
|
1395
|
+
int flag = 0;
|
1396
|
+
if (CLASS_OF(obj) == cgensymmv) {
|
1397
|
+
Data_Get_Struct(obj, gsl_eigen_gensymmv_workspace, *w);
|
1398
|
+
} else {
|
1399
|
+
if (rb_obj_is_kind_of(argv[argc-1], cgensymmv)) {
|
1400
|
+
Data_Get_Struct(argv[argc-1], gsl_eigen_gensymmv_workspace, *w);
|
1401
|
+
argc2 = argc-1;
|
1402
|
+
} else {
|
1403
|
+
|
1404
|
+
/* workspace is not given */
|
1405
|
+
}
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
switch (argc2) {
|
1409
|
+
case 2:
|
1410
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1411
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1412
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1413
|
+
break;
|
1414
|
+
case 3:
|
1415
|
+
if (rb_obj_is_kind_of(argv[2], cgensymmv)) {
|
1416
|
+
Data_Get_Struct(argv[2], gsl_eigen_gensymmv_workspace, *w);
|
1417
|
+
} else {
|
1418
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigen::Gensymmv::Workspace expected)",
|
1419
|
+
rb_class2name(CLASS_OF(argv[2])));
|
1420
|
+
}
|
1421
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1422
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1423
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1424
|
+
|
1425
|
+
break;
|
1426
|
+
case 5:
|
1427
|
+
if (rb_obj_is_kind_of(argv[4], cgensymmv)) {
|
1428
|
+
Data_Get_Struct(argv[4], gsl_eigen_gensymmv_workspace, *w);
|
1429
|
+
} else {
|
1430
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigen::Gensymmv::Workspace expected)",
|
1431
|
+
rb_class2name(CLASS_OF(argv[4])));
|
1432
|
+
}
|
1433
|
+
CHECK_VECTOR(argv[2]);
|
1434
|
+
Data_Get_Struct(argv[2], gsl_vector, *eval);
|
1435
|
+
CHECK_MATRIX(argv[3]);
|
1436
|
+
Data_Get_Struct(argv[3], gsl_matrix, *evec);
|
1437
|
+
|
1438
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1439
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1440
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1441
|
+
break;
|
1442
|
+
default:
|
1443
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2, 3 or 5)", argc);
|
1444
|
+
}
|
1445
|
+
if (*eval == NULL && *evec == NULL) {
|
1446
|
+
*eval = gsl_vector_alloc((*A)->size1);
|
1447
|
+
*evec = gsl_matrix_alloc((*A)->size1, (*A)->size2);
|
1448
|
+
flag += 1;
|
1449
|
+
}
|
1450
|
+
if (*w == NULL) {
|
1451
|
+
*w = gsl_eigen_gensymmv_alloc((*A)->size1);
|
1452
|
+
flag += 2;
|
1453
|
+
}
|
1454
|
+
return flag;
|
1455
|
+
}
|
1456
|
+
|
1457
|
+
static int check_argv_genherm(int argc, VALUE *argv, VALUE obj, gsl_matrix_complex **A, gsl_matrix_complex **B,
|
1458
|
+
gsl_vector **eval, gsl_eigen_genherm_workspace **w)
|
1459
|
+
{
|
1460
|
+
int argc2 = argc;
|
1461
|
+
int flag = 0;
|
1462
|
+
if (CLASS_OF(obj) == cgenherm) {
|
1463
|
+
Data_Get_Struct(obj, gsl_eigen_genherm_workspace, *w);
|
1464
|
+
} else {
|
1465
|
+
if (rb_obj_is_kind_of(argv[argc-1], cgenherm)) {
|
1466
|
+
Data_Get_Struct(argv[argc-1], gsl_eigen_genherm_workspace, *w);
|
1467
|
+
argc2 = argc-1;
|
1468
|
+
} else {
|
1469
|
+
/* workspace is not given */
|
1470
|
+
}
|
1471
|
+
}
|
1472
|
+
switch (argc2) {
|
1473
|
+
case 2:
|
1474
|
+
CHECK_MATRIX_COMPLEX(argv[0]); CHECK_MATRIX_COMPLEX(argv[1]);
|
1475
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, *A);
|
1476
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, *B);
|
1477
|
+
break;
|
1478
|
+
case 3:
|
1479
|
+
if (rb_obj_is_kind_of(argv[2], cgenherm)) {
|
1480
|
+
Data_Get_Struct(argv[2], gsl_eigen_genherm_workspace, *w);
|
1481
|
+
} else {
|
1482
|
+
CHECK_VECTOR(argv[2]);
|
1483
|
+
Data_Get_Struct(argv[2], gsl_vector, *eval);
|
1484
|
+
}
|
1485
|
+
CHECK_MATRIX_COMPLEX(argv[0]); CHECK_MATRIX_COMPLEX(argv[1]);
|
1486
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, *A);
|
1487
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, *B);
|
1488
|
+
break;
|
1489
|
+
default:
|
1490
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
1491
|
+
}
|
1492
|
+
if (*eval == NULL) {
|
1493
|
+
*eval = gsl_vector_alloc((*A)->size1);
|
1494
|
+
flag += 1;
|
1495
|
+
}
|
1496
|
+
if (*w == NULL) {
|
1497
|
+
*w = gsl_eigen_genherm_alloc((*A)->size1);
|
1498
|
+
flag += 2;
|
1499
|
+
}
|
1500
|
+
return flag;
|
1501
|
+
}
|
1502
|
+
static int check_argv_genhermv(int argc, VALUE *argv, VALUE obj, gsl_matrix_complex **A, gsl_matrix_complex **B,
|
1503
|
+
gsl_vector **eval, gsl_matrix_complex **evec, gsl_eigen_genhermv_workspace **w)
|
1504
|
+
{
|
1505
|
+
int argc2 = argc;
|
1506
|
+
int flag = 0;
|
1507
|
+
if (CLASS_OF(obj) == cgenhermv) {
|
1508
|
+
Data_Get_Struct(obj, gsl_eigen_genhermv_workspace, *w);
|
1509
|
+
} else {
|
1510
|
+
if (rb_obj_is_kind_of(argv[argc-1], cgenhermv)) {
|
1511
|
+
Data_Get_Struct(argv[argc-1], gsl_eigen_genhermv_workspace, *w);
|
1512
|
+
argc2 = argc-1;
|
1513
|
+
} else {
|
1514
|
+
|
1515
|
+
/* workspace is not given */
|
1516
|
+
}
|
1517
|
+
}
|
1518
|
+
|
1519
|
+
switch (argc2) {
|
1520
|
+
case 2:
|
1521
|
+
CHECK_MATRIX_COMPLEX(argv[0]); CHECK_MATRIX_COMPLEX(argv[1]);
|
1522
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, *A);
|
1523
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, *B);
|
1524
|
+
break;
|
1525
|
+
case 3:
|
1526
|
+
if (rb_obj_is_kind_of(argv[2], cgenhermv)) {
|
1527
|
+
Data_Get_Struct(argv[2], gsl_eigen_genhermv_workspace, *w);
|
1528
|
+
} else {
|
1529
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigen::Genhermv::Workspace expected)",
|
1530
|
+
rb_class2name(CLASS_OF(argv[2])));
|
1531
|
+
}
|
1532
|
+
CHECK_MATRIX_COMPLEX(argv[0]); CHECK_MATRIX_COMPLEX(argv[1]);
|
1533
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, *A);
|
1534
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, *B);
|
1535
|
+
|
1536
|
+
break;
|
1537
|
+
case 5:
|
1538
|
+
if (rb_obj_is_kind_of(argv[4], cgenhermv)) {
|
1539
|
+
Data_Get_Struct(argv[4], gsl_eigen_genhermv_workspace, *w);
|
1540
|
+
} else {
|
1541
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigen::Genhermv::Workspace expected)",
|
1542
|
+
rb_class2name(CLASS_OF(argv[4])));
|
1543
|
+
}
|
1544
|
+
CHECK_VECTOR(argv[2]);
|
1545
|
+
Data_Get_Struct(argv[2], gsl_vector, *eval);
|
1546
|
+
CHECK_MATRIX_COMPLEX(argv[3]);
|
1547
|
+
Data_Get_Struct(argv[3], gsl_matrix_complex, *evec);
|
1548
|
+
|
1549
|
+
CHECK_MATRIX_COMPLEX(argv[0]); CHECK_MATRIX_COMPLEX(argv[1]);
|
1550
|
+
Data_Get_Struct(argv[0], gsl_matrix_complex, *A);
|
1551
|
+
Data_Get_Struct(argv[1], gsl_matrix_complex, *B);
|
1552
|
+
break;
|
1553
|
+
default:
|
1554
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2, 3 or 5)", argc);
|
1555
|
+
}
|
1556
|
+
if (*eval == NULL && *evec == NULL) {
|
1557
|
+
*eval = gsl_vector_alloc((*A)->size1);
|
1558
|
+
*evec = gsl_matrix_complex_alloc((*A)->size1, (*A)->size2);
|
1559
|
+
flag += 1;
|
1560
|
+
}
|
1561
|
+
if (*w == NULL) {
|
1562
|
+
*w = gsl_eigen_genhermv_alloc((*A)->size1);
|
1563
|
+
flag += 2;
|
1564
|
+
}
|
1565
|
+
return flag;
|
1566
|
+
}
|
1567
|
+
static VALUE rb_gsl_eigen_gensymm(int argc, VALUE *argv, VALUE obj)
|
1568
|
+
{
|
1569
|
+
gsl_matrix *A = NULL, *B = NULL;
|
1570
|
+
gsl_matrix *Atmp = NULL;
|
1571
|
+
gsl_vector *eval = NULL;
|
1572
|
+
gsl_eigen_gensymm_workspace *w = NULL;
|
1573
|
+
int flag;
|
1574
|
+
VALUE veval;
|
1575
|
+
flag = check_argv_gensymm(argc, argv, obj, &A, &B, &eval, &w);
|
1576
|
+
Atmp = make_matrix_clone(A);
|
1577
|
+
// Btmp = make_matrix_clone(B);
|
1578
|
+
gsl_eigen_gensymm(Atmp, B, eval, w);
|
1579
|
+
gsl_matrix_free(Atmp);
|
1580
|
+
// gsl_matrix_free(Btmp);
|
1581
|
+
switch (flag) {
|
1582
|
+
case 0:
|
1583
|
+
veval = argv[2];
|
1584
|
+
break;
|
1585
|
+
case 1:
|
1586
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1587
|
+
break;
|
1588
|
+
case 2:
|
1589
|
+
veval = argv[2];
|
1590
|
+
gsl_eigen_gensymm_free(w);
|
1591
|
+
break;
|
1592
|
+
case 3:
|
1593
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1594
|
+
gsl_eigen_gensymm_free(w);
|
1595
|
+
break;
|
1596
|
+
}
|
1597
|
+
|
1598
|
+
return veval;
|
1599
|
+
}
|
1600
|
+
|
1601
|
+
static VALUE rb_gsl_eigen_gensymmv(int argc, VALUE *argv, VALUE obj)
|
1602
|
+
{
|
1603
|
+
gsl_matrix *A = NULL, *B = NULL;
|
1604
|
+
gsl_matrix *Atmp = NULL;
|
1605
|
+
gsl_vector *eval = NULL;
|
1606
|
+
gsl_matrix *evec = NULL;
|
1607
|
+
gsl_eigen_gensymmv_workspace *w = NULL;
|
1608
|
+
int flag;
|
1609
|
+
VALUE veval, vevec;
|
1610
|
+
flag = check_argv_gensymmv(argc, argv, obj, &A, &B, &eval, &evec, &w);
|
1611
|
+
Atmp = make_matrix_clone(A);
|
1612
|
+
// Btmp = make_matrix_clone(B);
|
1613
|
+
gsl_eigen_gensymmv(Atmp, B, eval, evec, w);
|
1614
|
+
gsl_matrix_free(Atmp);
|
1615
|
+
// gsl_matrix_free(Btmp);
|
1616
|
+
|
1617
|
+
switch (flag) {
|
1618
|
+
case 0:
|
1619
|
+
veval = argv[2];
|
1620
|
+
vevec = argv[3];
|
1621
|
+
break;
|
1622
|
+
case 1:
|
1623
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1624
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_vectors, 0, gsl_matrix_free, evec);
|
1625
|
+
break;
|
1626
|
+
case 2:
|
1627
|
+
veval = argv[2];
|
1628
|
+
vevec = argv[3];
|
1629
|
+
gsl_eigen_gensymmv_free(w);
|
1630
|
+
break;
|
1631
|
+
case 3:
|
1632
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1633
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_vectors, 0, gsl_matrix_free, evec);
|
1634
|
+
gsl_eigen_gensymmv_free(w);
|
1635
|
+
break;
|
1636
|
+
}
|
1637
|
+
|
1638
|
+
return rb_ary_new3(2, veval, vevec);
|
1639
|
+
}
|
1640
|
+
|
1641
|
+
static VALUE rb_gsl_eigen_genherm(int argc, VALUE *argv, VALUE obj)
|
1642
|
+
{
|
1643
|
+
gsl_matrix_complex *A = NULL, *B = NULL;
|
1644
|
+
gsl_matrix_complex *Atmp = NULL, *Btmp = NULL;
|
1645
|
+
gsl_vector *eval = NULL;
|
1646
|
+
gsl_eigen_genherm_workspace *w = NULL;
|
1647
|
+
int flag;
|
1648
|
+
VALUE veval;
|
1649
|
+
flag = check_argv_genherm(argc, argv, obj, &A, &B, &eval, &w);
|
1650
|
+
Atmp = make_matrix_complex_clone(A);
|
1651
|
+
Btmp = make_matrix_complex_clone(B);
|
1652
|
+
gsl_eigen_genherm(Atmp, Btmp, eval, w);
|
1653
|
+
gsl_matrix_complex_free(Atmp);
|
1654
|
+
gsl_matrix_complex_free(Btmp);
|
1655
|
+
switch (flag) {
|
1656
|
+
case 0:
|
1657
|
+
veval = argv[2];
|
1658
|
+
break;
|
1659
|
+
case 1:
|
1660
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1661
|
+
break;
|
1662
|
+
case 2:
|
1663
|
+
veval = argv[2];
|
1664
|
+
gsl_eigen_genherm_free(w);
|
1665
|
+
break;
|
1666
|
+
case 3:
|
1667
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1668
|
+
gsl_eigen_genherm_free(w);
|
1669
|
+
break;
|
1670
|
+
}
|
1671
|
+
|
1672
|
+
return veval;
|
1673
|
+
}
|
1674
|
+
|
1675
|
+
static VALUE rb_gsl_eigen_genhermv(int argc, VALUE *argv, VALUE obj)
|
1676
|
+
{
|
1677
|
+
gsl_matrix_complex *A = NULL, *B = NULL;
|
1678
|
+
gsl_matrix_complex *Atmp = NULL, *Btmp = NULL;
|
1679
|
+
gsl_vector *eval = NULL;
|
1680
|
+
gsl_matrix_complex *evec = NULL;
|
1681
|
+
gsl_eigen_genhermv_workspace *w = NULL;
|
1682
|
+
int flag;
|
1683
|
+
VALUE veval, vevec;
|
1684
|
+
flag = check_argv_genhermv(argc, argv, obj, &A, &B, &eval, &evec, &w);
|
1685
|
+
Atmp = make_matrix_complex_clone(A);
|
1686
|
+
Btmp = make_matrix_complex_clone(B);
|
1687
|
+
gsl_eigen_genhermv(Atmp, Btmp, eval, evec, w);
|
1688
|
+
gsl_matrix_complex_free(Atmp);
|
1689
|
+
gsl_matrix_complex_free(Btmp);
|
1690
|
+
|
1691
|
+
switch (flag) {
|
1692
|
+
case 0:
|
1693
|
+
veval = argv[2];
|
1694
|
+
vevec = argv[3];
|
1695
|
+
break;
|
1696
|
+
case 1:
|
1697
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1698
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_herm_vectors, 0, gsl_matrix_complex_free, evec);
|
1699
|
+
break;
|
1700
|
+
case 2:
|
1701
|
+
veval = argv[2];
|
1702
|
+
vevec = argv[3];
|
1703
|
+
gsl_eigen_genhermv_free(w);
|
1704
|
+
break;
|
1705
|
+
case 3:
|
1706
|
+
veval = Data_Wrap_Struct(cgsl_eigen_values, 0, gsl_vector_free, eval);
|
1707
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_herm_vectors, 0, gsl_matrix_complex_free, evec);
|
1708
|
+
gsl_eigen_genhermv_free(w);
|
1709
|
+
break;
|
1710
|
+
}
|
1711
|
+
|
1712
|
+
return rb_ary_new3(2, veval, vevec);
|
1713
|
+
}
|
1714
|
+
|
1715
|
+
static VALUE rb_gsl_eigen_gensymmv_sort(int argc, VALUE *argv, VALUE obj)
|
1716
|
+
{
|
1717
|
+
return rb_gsl_eigen_real_sort(argc, argv, obj, gsl_eigen_gensymmv_sort);
|
1718
|
+
}
|
1719
|
+
static VALUE rb_gsl_eigen_genhermv_sort(int argc, VALUE *argv, VALUE obj)
|
1720
|
+
{
|
1721
|
+
return rb_gsl_eigen_complex_sort(argc, argv, obj, gsl_eigen_genhermv_sort);
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
static VALUE rb_gsl_eigen_gen_alloc(VALUE klass, VALUE n)
|
1725
|
+
{
|
1726
|
+
gsl_eigen_gen_workspace *w;
|
1727
|
+
w = gsl_eigen_gen_alloc(FIX2INT(n));
|
1728
|
+
return Data_Wrap_Struct(cgenw, 0, gsl_eigen_gen_free, w);
|
1729
|
+
}
|
1730
|
+
|
1731
|
+
static VALUE rb_gsl_eigen_genv_alloc(VALUE klass, VALUE n)
|
1732
|
+
{
|
1733
|
+
gsl_eigen_genv_workspace *w;
|
1734
|
+
w = gsl_eigen_genv_alloc(FIX2INT(n));
|
1735
|
+
return Data_Wrap_Struct(cgenvw, 0, gsl_eigen_genv_free, w);
|
1736
|
+
}
|
1737
|
+
|
1738
|
+
static VALUE rb_gsl_eigen_gen_params(int argc, VALUE *argv, VALUE obj)
|
1739
|
+
{
|
1740
|
+
gsl_eigen_gen_workspace *w = NULL;
|
1741
|
+
int istart = 0;
|
1742
|
+
if (CLASS_OF(obj) == cgenw) {
|
1743
|
+
Data_Get_Struct(obj, gsl_eigen_gen_workspace, w);
|
1744
|
+
istart = 0;
|
1745
|
+
} else {
|
1746
|
+
if (argc != 4) rb_raise(rb_eArgError, "too few arguments (%d for 3)\n", argc);
|
1747
|
+
if (CLASS_OF(argv[3]) != cgenw)
|
1748
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigen::Gen::Workspace expected)",
|
1749
|
+
rb_class2name(CLASS_OF(argv[3])));
|
1750
|
+
Data_Get_Struct(argv[3], gsl_eigen_gen_workspace, w);
|
1751
|
+
istart = 1;
|
1752
|
+
}
|
1753
|
+
switch (argc - istart) {
|
1754
|
+
case 3:
|
1755
|
+
gsl_eigen_gen_params(FIX2INT(argv[0]), FIX2INT(argv[1]), FIX2INT(argv[2]), w);
|
1756
|
+
break;
|
1757
|
+
default:
|
1758
|
+
rb_raise(rb_eArgError, "Wrong number of arguments.\n");
|
1759
|
+
}
|
1760
|
+
return Qtrue;
|
1761
|
+
}
|
1762
|
+
|
1763
|
+
static int check_argv_gen(int argc, VALUE *argv, VALUE obj, gsl_matrix **A, gsl_matrix **B,
|
1764
|
+
gsl_vector_complex **alpha, gsl_vector **beta, gsl_eigen_gen_workspace **w)
|
1765
|
+
{
|
1766
|
+
int argc2 = argc;
|
1767
|
+
int flag = 0;
|
1768
|
+
if (CLASS_OF(obj) == cgenw) {
|
1769
|
+
Data_Get_Struct(obj, gsl_eigen_gen_workspace, *w);
|
1770
|
+
} else {
|
1771
|
+
if (rb_obj_is_kind_of(argv[argc-1], cgenw)) {
|
1772
|
+
Data_Get_Struct(argv[argc-1], gsl_eigen_gen_workspace, *w);
|
1773
|
+
argc2 = argc-1;
|
1774
|
+
} else {
|
1775
|
+
|
1776
|
+
/* workspace is not given */
|
1777
|
+
}
|
1778
|
+
}
|
1779
|
+
|
1780
|
+
switch (argc2) {
|
1781
|
+
case 2:
|
1782
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1783
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1784
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1785
|
+
break;
|
1786
|
+
case 3:
|
1787
|
+
if (rb_obj_is_kind_of(argv[2], cgenw)) {
|
1788
|
+
Data_Get_Struct(argv[2], gsl_eigen_gen_workspace, *w);
|
1789
|
+
} else {
|
1790
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigen::Gen::Workspace expected)",
|
1791
|
+
rb_class2name(CLASS_OF(argv[2])));
|
1792
|
+
}
|
1793
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1794
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1795
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1796
|
+
break;
|
1797
|
+
case 5:
|
1798
|
+
if (rb_obj_is_kind_of(argv[4], cgenw)) {
|
1799
|
+
Data_Get_Struct(argv[4], gsl_eigen_gen_workspace, *w);
|
1800
|
+
} else {
|
1801
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigen::Gen::Workspace expected)",
|
1802
|
+
rb_class2name(CLASS_OF(argv[4])));
|
1803
|
+
}
|
1804
|
+
CHECK_VECTOR_COMPLEX(argv[2]);
|
1805
|
+
Data_Get_Struct(argv[2], gsl_vector_complex, *alpha);
|
1806
|
+
CHECK_VECTOR(argv[3]);
|
1807
|
+
Data_Get_Struct(argv[3], gsl_vector, *beta);
|
1808
|
+
|
1809
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1810
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1811
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1812
|
+
break;
|
1813
|
+
default:
|
1814
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2, 3 or 5)", argc);
|
1815
|
+
}
|
1816
|
+
if (*alpha == NULL && *beta == NULL) {
|
1817
|
+
*alpha = gsl_vector_complex_alloc((*A)->size1);
|
1818
|
+
*beta = gsl_vector_alloc((*A)->size1);
|
1819
|
+
flag += 1;
|
1820
|
+
}
|
1821
|
+
if (*w == NULL) {
|
1822
|
+
*w = gsl_eigen_gen_alloc((*A)->size1);
|
1823
|
+
flag += 2;
|
1824
|
+
}
|
1825
|
+
return flag;
|
1826
|
+
}
|
1827
|
+
|
1828
|
+
static VALUE rb_gsl_eigen_gen(int argc, VALUE *argv, VALUE obj)
|
1829
|
+
{
|
1830
|
+
gsl_matrix *A = NULL, *B = NULL;
|
1831
|
+
// gsl_matrix *Atmp = NULL, *Btmp = NULL;
|
1832
|
+
gsl_vector_complex *alpha = NULL;
|
1833
|
+
gsl_vector *beta = NULL;
|
1834
|
+
gsl_eigen_gen_workspace *w = NULL;
|
1835
|
+
int flag;
|
1836
|
+
VALUE valpha, vbeta;
|
1837
|
+
flag = check_argv_gen(argc, argv, obj, &A, &B, &alpha, &beta, &w);
|
1838
|
+
// Atmp = make_matrix_clone(A);
|
1839
|
+
// Btmp = make_matrix_clone(B);
|
1840
|
+
gsl_eigen_gen(A, B, alpha, beta, w);
|
1841
|
+
// gsl_matrix_free(Atmp);
|
1842
|
+
// gsl_matrix_free(Btmp);
|
1843
|
+
|
1844
|
+
switch (flag) {
|
1845
|
+
case 0:
|
1846
|
+
valpha = argv[2];
|
1847
|
+
vbeta = argv[3];
|
1848
|
+
break;
|
1849
|
+
case 1:
|
1850
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
1851
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
1852
|
+
break;
|
1853
|
+
case 2:
|
1854
|
+
valpha = argv[2];
|
1855
|
+
vbeta = argv[3];
|
1856
|
+
gsl_eigen_gen_free(w);
|
1857
|
+
break;
|
1858
|
+
case 3:
|
1859
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
1860
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
1861
|
+
gsl_eigen_gen_free(w);
|
1862
|
+
break;
|
1863
|
+
}
|
1864
|
+
|
1865
|
+
return rb_ary_new3(2, valpha, vbeta);
|
1866
|
+
}
|
1867
|
+
|
1868
|
+
static VALUE rb_gsl_eigen_gen_QZ(int argc, VALUE *argv, VALUE obj)
|
1869
|
+
{
|
1870
|
+
gsl_matrix *A = NULL, *B = NULL;
|
1871
|
+
// gsl_matrix *Atmp = NULL, *Btmp = NULL;
|
1872
|
+
gsl_vector_complex *alpha = NULL;
|
1873
|
+
gsl_vector *beta = NULL;
|
1874
|
+
gsl_matrix *Q, *Z;
|
1875
|
+
gsl_eigen_gen_workspace *w = NULL;
|
1876
|
+
int flag;
|
1877
|
+
VALUE valpha, vbeta, vQ, vZ;
|
1878
|
+
flag = check_argv_gen(argc, argv, obj, &A, &B, &alpha, &beta, &w);
|
1879
|
+
/* Atmp = make_matrix_clone(A);
|
1880
|
+
Btmp = make_matrix_clone(B); */
|
1881
|
+
Q = gsl_matrix_alloc(A->size1, A->size2);
|
1882
|
+
Z = gsl_matrix_alloc(A->size1, A->size2);
|
1883
|
+
// gsl_eigen_gen_QZ(Atmp, Btmp, alpha, beta, Q, Z, w);
|
1884
|
+
gsl_eigen_gen_QZ(A, B, alpha, beta, Q, Z, w);
|
1885
|
+
/* gsl_matrix_free(Atmp);
|
1886
|
+
gsl_matrix_free(Btmp); */
|
1887
|
+
|
1888
|
+
switch (flag) {
|
1889
|
+
case 0:
|
1890
|
+
valpha = argv[2];
|
1891
|
+
vbeta = argv[3];
|
1892
|
+
break;
|
1893
|
+
case 1:
|
1894
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
1895
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
1896
|
+
break;
|
1897
|
+
case 2:
|
1898
|
+
valpha = argv[2];
|
1899
|
+
vbeta = argv[3];
|
1900
|
+
gsl_eigen_gen_free(w);
|
1901
|
+
break;
|
1902
|
+
case 3:
|
1903
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
1904
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
1905
|
+
gsl_eigen_gen_free(w);
|
1906
|
+
break;
|
1907
|
+
}
|
1908
|
+
vQ = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Q);
|
1909
|
+
vZ = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Z);
|
1910
|
+
return rb_ary_new3(4, valpha, vbeta, vQ, vZ);
|
1911
|
+
}
|
1912
|
+
|
1913
|
+
static int check_argv_genv(int argc, VALUE *argv, VALUE obj, gsl_matrix **A, gsl_matrix **B,
|
1914
|
+
gsl_vector_complex **alpha, gsl_vector **beta, gsl_matrix_complex **evec, gsl_eigen_genv_workspace **w)
|
1915
|
+
{
|
1916
|
+
int argc2 = argc;
|
1917
|
+
int flag = 0;
|
1918
|
+
if (CLASS_OF(obj) == cgenvw) {
|
1919
|
+
Data_Get_Struct(obj, gsl_eigen_genv_workspace, *w);
|
1920
|
+
} else {
|
1921
|
+
if (rb_obj_is_kind_of(argv[argc-1], cgenvw)) {
|
1922
|
+
Data_Get_Struct(argv[argc-1], gsl_eigen_genv_workspace, *w);
|
1923
|
+
argc2 = argc-1;
|
1924
|
+
} else {
|
1925
|
+
|
1926
|
+
/* workspace is not given */
|
1927
|
+
}
|
1928
|
+
}
|
1929
|
+
|
1930
|
+
switch (argc2) {
|
1931
|
+
case 2:
|
1932
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1933
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1934
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1935
|
+
break;
|
1936
|
+
case 3:
|
1937
|
+
if (rb_obj_is_kind_of(argv[2], cgenvw)) {
|
1938
|
+
Data_Get_Struct(argv[2], gsl_eigen_genv_workspace, *w);
|
1939
|
+
} else {
|
1940
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigenv::Gen::Workspace expected)",
|
1941
|
+
rb_class2name(CLASS_OF(argv[2])));
|
1942
|
+
}
|
1943
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1944
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1945
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1946
|
+
break;
|
1947
|
+
case 6:
|
1948
|
+
if (rb_obj_is_kind_of(argv[4], cgenvw)) {
|
1949
|
+
Data_Get_Struct(argv[4], gsl_eigen_genv_workspace, *w);
|
1950
|
+
} else {
|
1951
|
+
rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::Eigenv::Gen::Workspace expected)",
|
1952
|
+
rb_class2name(CLASS_OF(argv[4])));
|
1953
|
+
}
|
1954
|
+
CHECK_VECTOR_COMPLEX(argv[2]);
|
1955
|
+
Data_Get_Struct(argv[2], gsl_vector_complex, *alpha);
|
1956
|
+
CHECK_VECTOR(argv[3]);
|
1957
|
+
Data_Get_Struct(argv[3], gsl_vector, *beta);
|
1958
|
+
CHECK_MATRIX_COMPLEX(argv[3]);
|
1959
|
+
Data_Get_Struct(argv[4], gsl_matrix_complex, *evec);
|
1960
|
+
|
1961
|
+
CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]);
|
1962
|
+
Data_Get_Struct(argv[0], gsl_matrix, *A);
|
1963
|
+
Data_Get_Struct(argv[1], gsl_matrix, *B);
|
1964
|
+
break;
|
1965
|
+
default:
|
1966
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2, 3 or 6)", argc);
|
1967
|
+
}
|
1968
|
+
if (*alpha == NULL && *beta == NULL) {
|
1969
|
+
*alpha = gsl_vector_complex_alloc((*A)->size1);
|
1970
|
+
*beta = gsl_vector_alloc((*A)->size1);
|
1971
|
+
*evec = gsl_matrix_complex_alloc((*A)->size1, (*A)->size2);
|
1972
|
+
flag += 1;
|
1973
|
+
}
|
1974
|
+
if (*w == NULL) {
|
1975
|
+
*w = gsl_eigen_genv_alloc((*A)->size1);
|
1976
|
+
flag += 2;
|
1977
|
+
}
|
1978
|
+
return flag;
|
1979
|
+
}
|
1980
|
+
|
1981
|
+
static VALUE rb_gsl_eigen_genv(int argc, VALUE *argv, VALUE obj)
|
1982
|
+
{
|
1983
|
+
gsl_matrix *A = NULL, *B = NULL;
|
1984
|
+
// gsl_matrix *Atmp = NULL, *Btmp = NULL;
|
1985
|
+
gsl_vector_complex *alpha = NULL;
|
1986
|
+
gsl_vector *beta = NULL;
|
1987
|
+
gsl_matrix_complex *evec = NULL;
|
1988
|
+
gsl_eigen_genv_workspace *w = NULL;
|
1989
|
+
int flag;
|
1990
|
+
VALUE valpha, vbeta, vevec;
|
1991
|
+
flag = check_argv_genv(argc, argv, obj, &A, &B, &alpha, &beta, &evec, &w);
|
1992
|
+
// Atmp = make_matrix_clone(A);
|
1993
|
+
// Btmp = make_matrix_clone(B);
|
1994
|
+
// gsl_eigen_genv(Atmp, Btmp, alpha, beta, evec, w);
|
1995
|
+
gsl_eigen_genv(A, B, alpha, beta, evec, w);
|
1996
|
+
// gsl_matrix_free(Atmp);
|
1997
|
+
// gsl_matrix_free(Btmp);
|
1998
|
+
|
1999
|
+
switch (flag) {
|
2000
|
+
case 0:
|
2001
|
+
valpha = argv[2];
|
2002
|
+
vbeta = argv[3];
|
2003
|
+
vevec = argv[4];
|
2004
|
+
break;
|
2005
|
+
case 1:
|
2006
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
2007
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
2008
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_herm_vectors, 0, gsl_matrix_complex_free, evec);
|
2009
|
+
break;
|
2010
|
+
case 2:
|
2011
|
+
valpha = argv[2];
|
2012
|
+
vbeta = argv[3];
|
2013
|
+
vevec = argv[4];
|
2014
|
+
gsl_eigen_genv_free(w);
|
2015
|
+
break;
|
2016
|
+
case 3:
|
2017
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
2018
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
2019
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_herm_vectors, 0, gsl_matrix_complex_free, evec);
|
2020
|
+
gsl_eigen_genv_free(w);
|
2021
|
+
break;
|
2022
|
+
}
|
2023
|
+
|
2024
|
+
return rb_ary_new3(3, valpha, vbeta, vevec);
|
2025
|
+
}
|
2026
|
+
|
2027
|
+
|
2028
|
+
static VALUE rb_gsl_eigen_genv_QZ(int argc, VALUE *argv, VALUE obj)
|
2029
|
+
{
|
2030
|
+
gsl_matrix *A = NULL, *B = NULL;
|
2031
|
+
// gsl_matrix *Atmp = NULL, *Btmp = NULL;
|
2032
|
+
gsl_vector_complex *alpha = NULL;
|
2033
|
+
gsl_vector *beta = NULL;
|
2034
|
+
gsl_matrix_complex *evec = NULL;
|
2035
|
+
gsl_matrix *Q, *Z;
|
2036
|
+
gsl_eigen_genv_workspace *w = NULL;
|
2037
|
+
int flag;
|
2038
|
+
VALUE valpha, vbeta, vevec, vQ, vZ;
|
2039
|
+
flag = check_argv_genv(argc, argv, obj, &A, &B, &alpha, &beta, &evec, &w);
|
2040
|
+
/* Atmp = make_matrix_clone(A);
|
2041
|
+
Btmp = make_matrix_clone(B); */
|
2042
|
+
Q = gsl_matrix_alloc(A->size1, A->size2);
|
2043
|
+
Z = gsl_matrix_alloc(A->size1, A->size2);
|
2044
|
+
// gsl_eigen_genv_QZ(Atmp, Btmp, alpha, beta, evec, Q, Z, w);
|
2045
|
+
gsl_eigen_genv_QZ(A, B, alpha, beta, evec, Q, Z, w);
|
2046
|
+
/* gsl_matrix_free(Atmp);
|
2047
|
+
gsl_matrix_free(Btmp); */
|
2048
|
+
|
2049
|
+
switch (flag) {
|
2050
|
+
case 0:
|
2051
|
+
valpha = argv[2];
|
2052
|
+
vbeta = argv[3];
|
2053
|
+
vevec = argv[4];
|
2054
|
+
break;
|
2055
|
+
case 1:
|
2056
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
2057
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
2058
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_herm_vectors, 0, gsl_matrix_complex_free, evec);
|
2059
|
+
break;
|
2060
|
+
case 2:
|
2061
|
+
valpha = argv[2];
|
2062
|
+
vbeta = argv[3];
|
2063
|
+
vevec = argv[4];
|
2064
|
+
gsl_eigen_genv_free(w);
|
2065
|
+
break;
|
2066
|
+
case 3:
|
2067
|
+
valpha = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, alpha);
|
2068
|
+
vbeta = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, beta);
|
2069
|
+
vevec = Data_Wrap_Struct(cgsl_eigen_herm_vectors, 0, gsl_matrix_complex_free, evec);
|
2070
|
+
gsl_eigen_genv_free(w);
|
2071
|
+
break;
|
2072
|
+
}
|
2073
|
+
vQ = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Q);
|
2074
|
+
vZ = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, Z);
|
2075
|
+
return rb_ary_new3(5, valpha, vbeta, vevec, vQ, vZ);
|
2076
|
+
}
|
2077
|
+
|
2078
|
+
static VALUE rb_gsl_eigen_genv_sort(int argc, VALUE *argv, VALUE obj)
|
2079
|
+
{
|
2080
|
+
gsl_vector_complex *alpha = NULL;
|
2081
|
+
gsl_vector *beta = NULL;
|
2082
|
+
gsl_matrix_complex *evec = NULL;
|
2083
|
+
gsl_eigen_sort_t type = GSL_EIGEN_SORT_VAL_DESC;
|
2084
|
+
|
2085
|
+
switch (argc) {
|
2086
|
+
case 4:
|
2087
|
+
CHECK_FIXNUM(argv[3]);
|
2088
|
+
type = FIX2INT(argv[3]);
|
2089
|
+
/* no break, do next */
|
2090
|
+
case 3:
|
2091
|
+
if (argv[0] == Qnil) {
|
2092
|
+
alpha = NULL;
|
2093
|
+
} else {
|
2094
|
+
CHECK_VECTOR_COMPLEX(argv[0]);
|
2095
|
+
Data_Get_Struct(argv[0], gsl_vector_complex, alpha);
|
2096
|
+
}
|
2097
|
+
if (argv[1] == Qnil) {
|
2098
|
+
beta = NULL;
|
2099
|
+
} else {
|
2100
|
+
CHECK_VECTOR(argv[1]);
|
2101
|
+
Data_Get_Struct(argv[1], gsl_vector, beta);
|
2102
|
+
}
|
2103
|
+
if (argv[2] == Qnil) {
|
2104
|
+
evec = NULL;
|
2105
|
+
} else {
|
2106
|
+
CHECK_MATRIX_COMPLEX(argv[2]);
|
2107
|
+
Data_Get_Struct(argv[2], gsl_matrix_complex, evec);
|
2108
|
+
}
|
2109
|
+
break;
|
2110
|
+
default:
|
2111
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
|
2112
|
+
}
|
2113
|
+
return INT2FIX(gsl_eigen_genv_sort(alpha, beta, evec, type));
|
2114
|
+
}
|
2115
|
+
#endif
|
2116
|
+
|
2117
|
+
void Init_gsl_eigen(VALUE module)
|
2118
|
+
{
|
2119
|
+
VALUE mgsl_eigen;
|
2120
|
+
VALUE mgsl_eigen_symm;
|
2121
|
+
VALUE mgsl_eigen_symmv;
|
2122
|
+
VALUE mgsl_eigen_herm;
|
2123
|
+
VALUE mgsl_eigen_hermv;
|
2124
|
+
#ifdef HAVE_EIGEN_FRANCIS
|
2125
|
+
VALUE mgsl_eigen_francis;
|
2126
|
+
#endif
|
2127
|
+
#ifdef GSL_1_9_LATER
|
2128
|
+
VALUE mgsl_eigen_nonsymmv;
|
2129
|
+
VALUE mgsl_eigen_nonsymm;
|
2130
|
+
#endif
|
2131
|
+
|
2132
|
+
mgsl_eigen = rb_define_module_under(module, "Eigen");
|
2133
|
+
mgsl_eigen_symm = rb_define_module_under(mgsl_eigen, "Symm");
|
2134
|
+
mgsl_eigen_symmv = rb_define_module_under(mgsl_eigen, "Symmv");
|
2135
|
+
|
2136
|
+
mgsl_eigen_herm = rb_define_module_under(mgsl_eigen, "Herm");
|
2137
|
+
mgsl_eigen_hermv = rb_define_module_under(mgsl_eigen, "Hermv");
|
2138
|
+
|
2139
|
+
cgsl_eigen_values = rb_define_class_under(mgsl_eigen, "EigenValues",
|
2140
|
+
cgsl_vector);
|
2141
|
+
cgsl_eigen_vectors = rb_define_class_under(mgsl_eigen, "EigenVectors",
|
2142
|
+
cgsl_matrix);
|
2143
|
+
cgsl_eigen_vector = rb_define_class_under(mgsl_eigen, "EigenVector",
|
2144
|
+
cgsl_vector);
|
2145
|
+
cgsl_eigen_herm_vectors = rb_define_class_under(mgsl_eigen, "ComplexEigenVectors",
|
2146
|
+
cgsl_matrix_complex);
|
2147
|
+
cgsl_eigen_vector_complex = rb_define_class_under(mgsl_eigen, "ComplexEigenVector",
|
2148
|
+
cgsl_vector_complex);
|
2149
|
+
cgsl_eigen_symm_workspace = rb_define_class_under(mgsl_eigen_symm,
|
2150
|
+
"Workspace", cGSL_Object);
|
2151
|
+
cgsl_eigen_symmv_workspace = rb_define_class_under(mgsl_eigen_symmv,
|
2152
|
+
"Workspace", cGSL_Object);
|
2153
|
+
cgsl_eigen_herm_workspace = rb_define_class_under(mgsl_eigen_herm,
|
2154
|
+
"Workspace", cGSL_Object);
|
2155
|
+
|
2156
|
+
cgsl_eigen_hermv_workspace = rb_define_class_under(mgsl_eigen_hermv,
|
2157
|
+
"Workspace", cGSL_Object);
|
2158
|
+
|
2159
|
+
rb_define_singleton_method(cgsl_eigen_symm_workspace, "alloc",
|
2160
|
+
rb_gsl_eigen_symm_alloc, 1);
|
2161
|
+
rb_define_singleton_method(cgsl_eigen_symmv_workspace, "alloc",
|
2162
|
+
rb_gsl_eigen_symmv_alloc, 1);
|
2163
|
+
rb_define_singleton_method(cgsl_eigen_herm_workspace, "alloc",
|
2164
|
+
rb_gsl_eigen_herm_alloc, 1);
|
2165
|
+
rb_define_singleton_method(cgsl_eigen_hermv_workspace, "alloc",
|
2166
|
+
rb_gsl_eigen_hermv_alloc, 1);
|
2167
|
+
|
2168
|
+
rb_define_singleton_method(mgsl_eigen_symm, "alloc",
|
2169
|
+
rb_gsl_eigen_symm_alloc, 1);
|
2170
|
+
rb_define_singleton_method(mgsl_eigen_symmv, "alloc",
|
2171
|
+
rb_gsl_eigen_symmv_alloc, 1);
|
2172
|
+
rb_define_singleton_method(mgsl_eigen_herm, "alloc",
|
2173
|
+
rb_gsl_eigen_herm_alloc, 1);
|
2174
|
+
rb_define_singleton_method(mgsl_eigen_hermv, "alloc",
|
2175
|
+
rb_gsl_eigen_hermv_alloc, 1);
|
2176
|
+
|
2177
|
+
rb_define_module_function(mgsl_eigen, "symm",
|
2178
|
+
rb_gsl_eigen_symm, -1);
|
2179
|
+
rb_define_module_function(mgsl_eigen, "symmv",
|
2180
|
+
rb_gsl_eigen_symmv, -1);
|
2181
|
+
rb_define_module_function(mgsl_eigen, "herm",
|
2182
|
+
rb_gsl_eigen_herm, -1);
|
2183
|
+
rb_define_module_function(mgsl_eigen, "hermv",
|
2184
|
+
rb_gsl_eigen_hermv, -1);
|
2185
|
+
|
2186
|
+
rb_define_module_function(module, "eigen_symm",
|
2187
|
+
rb_gsl_eigen_symm, -1);
|
2188
|
+
rb_define_module_function(module, "eigen_symmv",
|
2189
|
+
rb_gsl_eigen_symmv, -1);
|
2190
|
+
rb_define_module_function(module, "eigen_herm",
|
2191
|
+
rb_gsl_eigen_herm, -1);
|
2192
|
+
rb_define_module_function(module, "eigen_hermv",
|
2193
|
+
rb_gsl_eigen_hermv, -1);
|
2194
|
+
|
2195
|
+
rb_define_method(cgsl_matrix, "eigen_symm", rb_gsl_eigen_symm, -1);
|
2196
|
+
rb_define_method(cgsl_matrix, "eigen_symmv", rb_gsl_eigen_symmv, -1);
|
2197
|
+
rb_define_method(cgsl_matrix_complex, "eigen_herm", rb_gsl_eigen_herm, -1);
|
2198
|
+
rb_define_method(cgsl_matrix_complex, "eigen_hermv", rb_gsl_eigen_hermv, -1);
|
2199
|
+
|
2200
|
+
rb_define_method(cgsl_eigen_vectors, "unpack", rb_gsl_eigen_vectors_unpack, 0);
|
2201
|
+
rb_define_method(cgsl_eigen_herm_vectors, "unpack", rb_gsl_eigen_vectors_complex_unpack, 0);
|
2202
|
+
|
2203
|
+
rb_gsl_eigen_define_const(module, mgsl_eigen);
|
2204
|
+
|
2205
|
+
rb_define_module_function(mgsl_eigen, "symmv_sort",
|
2206
|
+
rb_gsl_eigen_symmv_sort, -1);
|
2207
|
+
rb_define_module_function(mgsl_eigen, "hermv_sort",
|
2208
|
+
rb_gsl_eigen_hermv_sort, -1);
|
2209
|
+
rb_define_module_function(mgsl_eigen_symmv, "sort",
|
2210
|
+
rb_gsl_eigen_symmv_sort, -1);
|
2211
|
+
rb_define_module_function(mgsl_eigen_hermv, "sort",
|
2212
|
+
rb_gsl_eigen_hermv_sort, -1);
|
2213
|
+
|
2214
|
+
#ifdef HAVE_EIGEN_FRANCIS
|
2215
|
+
mgsl_eigen_francis = rb_define_module_under(mgsl_eigen, "francis");
|
2216
|
+
cgsl_eigen_francis_workspace = rb_define_class_under(mgsl_eigen_francis,
|
2217
|
+
"Workspace", cGSL_Object);
|
2218
|
+
rb_define_singleton_method(cgsl_eigen_francis_workspace, "alloc",
|
2219
|
+
rb_gsl_eigen_francis_alloc, 0);
|
2220
|
+
|
2221
|
+
rb_define_method(cgsl_matrix, "eigen_francis", rb_gsl_eigen_francis, -1);
|
2222
|
+
rb_define_module_function(mgsl_eigen, "francis", rb_gsl_eigen_francis, -1);
|
2223
|
+
rb_define_module_function(module, "eigen_francis", rb_gsl_eigen_francis, -1);
|
2224
|
+
rb_define_method(cgsl_matrix, "eigen_francis_Z", rb_gsl_eigen_francis_Z, -1);
|
2225
|
+
rb_define_module_function(mgsl_eigen, "francis_Z", rb_gsl_eigen_francis_Z, -1);
|
2226
|
+
rb_define_module_function(module, "eigen_francis_Z", rb_gsl_eigen_francis_Z, -1);
|
2227
|
+
|
2228
|
+
rb_define_method(cgsl_eigen_francis_workspace, "T", rb_gsl_eigen_francis_T, -1);
|
2229
|
+
rb_define_module_function(mgsl_eigen_francis, "T", rb_gsl_eigen_francis_T, -1);
|
2230
|
+
|
2231
|
+
#endif
|
2232
|
+
|
2233
|
+
#ifdef GSL_1_9_LATER
|
2234
|
+
mgsl_eigen_nonsymm = rb_define_module_under(mgsl_eigen, "Nonsymm");
|
2235
|
+
mgsl_eigen_nonsymmv = rb_define_module_under(mgsl_eigen, "Nonsymmv");
|
2236
|
+
cgsl_eigen_nonsymm_workspace = rb_define_class_under(mgsl_eigen_nonsymm,
|
2237
|
+
"Workspace", cGSL_Object);
|
2238
|
+
rb_define_singleton_method(cgsl_eigen_nonsymm_workspace, "alloc",
|
2239
|
+
rb_gsl_eigen_nonsymm_alloc, 1);
|
2240
|
+
rb_define_singleton_method(mgsl_eigen_nonsymm, "alloc",
|
2241
|
+
rb_gsl_eigen_nonsymm_alloc, 1);
|
2242
|
+
|
2243
|
+
rb_define_method(cgsl_matrix, "eigen_nonsymm", rb_gsl_eigen_nonsymm, -1);
|
2244
|
+
rb_define_module_function(mgsl_eigen, "nonsymm", rb_gsl_eigen_nonsymm, -1);
|
2245
|
+
rb_define_module_function(module, "eigen_nonsymm", rb_gsl_eigen_nonsymm, -1);
|
2246
|
+
rb_define_method(cgsl_matrix, "eigen_nonsymm_Z", rb_gsl_eigen_nonsymm_Z, -1);
|
2247
|
+
rb_define_module_function(mgsl_eigen, "nonsymm_Z", rb_gsl_eigen_nonsymm_Z, -1);
|
2248
|
+
rb_define_module_function(module, "eigen_nonsymm_Z", rb_gsl_eigen_nonsymm_Z, -1);
|
2249
|
+
|
2250
|
+
rb_define_method(cgsl_eigen_nonsymm_workspace, "params", rb_gsl_eigen_nonsymm_params, -1);
|
2251
|
+
rb_define_module_function(mgsl_eigen_nonsymm, "params", rb_gsl_eigen_nonsymm_params, -1);
|
2252
|
+
|
2253
|
+
cgsl_eigen_nonsymmv_workspace = rb_define_class_under(mgsl_eigen_nonsymmv,
|
2254
|
+
"Workspace", cGSL_Object);
|
2255
|
+
rb_define_singleton_method(cgsl_eigen_nonsymmv_workspace, "alloc",
|
2256
|
+
rb_gsl_eigen_nonsymmv_alloc, 1);
|
2257
|
+
rb_define_singleton_method(mgsl_eigen_nonsymmv, "alloc",
|
2258
|
+
rb_gsl_eigen_nonsymmv_alloc, 1);
|
2259
|
+
rb_define_method(cgsl_matrix, "eigen_nonsymmv", rb_gsl_eigen_nonsymmv, -1);
|
2260
|
+
rb_define_module_function(mgsl_eigen, "nonsymmv", rb_gsl_eigen_nonsymmv, -1);
|
2261
|
+
rb_define_module_function(module, "eigen_nonsymmv", rb_gsl_eigen_nonsymmv, -1);
|
2262
|
+
rb_define_method(cgsl_matrix, "eigen", rb_gsl_eigen_nonsymmv, -1);
|
2263
|
+
rb_define_alias(cgsl_matrix, "eig", "eigen");
|
2264
|
+
rb_define_method(cgsl_matrix, "eigen_nonsymmv_Z", rb_gsl_eigen_nonsymmv_Z, -1);
|
2265
|
+
rb_define_module_function(mgsl_eigen, "nonsymmv_Z", rb_gsl_eigen_nonsymmv_Z, -1);
|
2266
|
+
rb_define_module_function(module, "eigen_nonsymmv_Z", rb_gsl_eigen_nonsymmv_Z, -1);
|
2267
|
+
|
2268
|
+
rb_define_module_function(mgsl_eigen, "nonsymmv_sort",
|
2269
|
+
rb_gsl_eigen_nonsymmv_sort, -1);
|
2270
|
+
rb_define_module_function(mgsl_eigen_nonsymmv, "sort",
|
2271
|
+
rb_gsl_eigen_nonsymmv_sort, -1);
|
2272
|
+
rb_define_module_function(module, "eigen_nonsymmv_sort",
|
2273
|
+
rb_gsl_eigen_nonsymmv_sort, -1);
|
2274
|
+
#endif
|
2275
|
+
|
2276
|
+
#ifdef GSL_1_10_LATER
|
2277
|
+
/** gensymm, gensymmv **/
|
2278
|
+
mgensymm = rb_define_module_under(mgsl_eigen, "Gensymm");
|
2279
|
+
cgensymm = rb_define_class_under(mgensymm, "Workspace", cGSL_Object);
|
2280
|
+
mgensymmv = rb_define_module_under(mgsl_eigen, "Gensymmv");
|
2281
|
+
cgensymmv = rb_define_class_under(mgensymmv, "Workspace", cGSL_Object);
|
2282
|
+
|
2283
|
+
rb_define_singleton_method(cgensymm, "alloc", rb_gsl_eigen_gensymm_alloc, 1);
|
2284
|
+
rb_define_singleton_method(cgensymmv, "alloc", rb_gsl_eigen_gensymmv_alloc, 1);
|
2285
|
+
rb_define_singleton_method(mgensymm, "alloc", rb_gsl_eigen_gensymm_alloc, 1);
|
2286
|
+
rb_define_singleton_method(mgensymmv, "alloc", rb_gsl_eigen_gensymmv_alloc, 1);
|
2287
|
+
|
2288
|
+
rb_define_method(cgensymm, "gensymm", rb_gsl_eigen_gensymm, -1);
|
2289
|
+
rb_define_module_function(module, "eigen_gensymm", rb_gsl_eigen_gensymm, -1);
|
2290
|
+
rb_define_module_function(mgsl_eigen, "gensymm", rb_gsl_eigen_gensymm, -1);
|
2291
|
+
rb_define_module_function(mgensymm, "gensymm", rb_gsl_eigen_gensymm, -1);
|
2292
|
+
|
2293
|
+
rb_define_method(cgensymmv, "gensymmv", rb_gsl_eigen_gensymmv, -1);
|
2294
|
+
rb_define_module_function(module, "eigen_gensymmv", rb_gsl_eigen_gensymmv, -1);
|
2295
|
+
rb_define_module_function(mgsl_eigen, "gensymmv", rb_gsl_eigen_gensymmv, -1);
|
2296
|
+
rb_define_module_function(mgensymmv, "gensymmv", rb_gsl_eigen_gensymmv, -1);
|
2297
|
+
|
2298
|
+
rb_define_module_function(mgsl_eigen, "gensymmv_sort",
|
2299
|
+
rb_gsl_eigen_gensymmv_sort, -1);
|
2300
|
+
rb_define_module_function(mgensymmv, "sort",
|
2301
|
+
rb_gsl_eigen_gensymmv_sort, -1);
|
2302
|
+
rb_define_module_function(module, "eigen_gensymmv_sort",
|
2303
|
+
rb_gsl_eigen_gensymmv_sort, -1);
|
2304
|
+
|
2305
|
+
/** genherm, genhermv **/
|
2306
|
+
mgenherm = rb_define_module_under(mgsl_eigen, "Genherm");
|
2307
|
+
cgenherm = rb_define_class_under(mgenherm, "Workspace", cGSL_Object);
|
2308
|
+
mgenhermv = rb_define_module_under(mgsl_eigen, "Genhermv");
|
2309
|
+
cgenhermv = rb_define_class_under(mgenhermv, "Workspace", cGSL_Object);
|
2310
|
+
|
2311
|
+
rb_define_singleton_method(cgenherm, "alloc", rb_gsl_eigen_genherm_alloc, 1);
|
2312
|
+
rb_define_singleton_method(cgenhermv, "alloc", rb_gsl_eigen_genhermv_alloc, 1);
|
2313
|
+
rb_define_singleton_method(mgenherm, "alloc", rb_gsl_eigen_genherm_alloc, 1);
|
2314
|
+
rb_define_singleton_method(mgenhermv, "alloc", rb_gsl_eigen_genhermv_alloc, 1);
|
2315
|
+
|
2316
|
+
rb_define_method(cgenherm, "genherm", rb_gsl_eigen_genherm, -1);
|
2317
|
+
rb_define_module_function(module, "eigen_genherm", rb_gsl_eigen_genherm, -1);
|
2318
|
+
rb_define_module_function(mgsl_eigen, "genherm", rb_gsl_eigen_genherm, -1);
|
2319
|
+
rb_define_module_function(mgenherm, "genherm", rb_gsl_eigen_genherm, -1);
|
2320
|
+
|
2321
|
+
rb_define_method(cgenhermv, "genhermv", rb_gsl_eigen_genhermv, -1);
|
2322
|
+
rb_define_module_function(module, "eigen_genhermv", rb_gsl_eigen_genhermv, -1);
|
2323
|
+
rb_define_module_function(mgsl_eigen, "genhermv", rb_gsl_eigen_genhermv, -1);
|
2324
|
+
rb_define_module_function(mgenhermv, "genhermv", rb_gsl_eigen_genhermv, -1);
|
2325
|
+
|
2326
|
+
rb_define_module_function(mgsl_eigen, "genhermv_sort",
|
2327
|
+
rb_gsl_eigen_genhermv_sort, -1);
|
2328
|
+
rb_define_module_function(mgenhermv, "sort",
|
2329
|
+
rb_gsl_eigen_genhermv_sort, -1);
|
2330
|
+
rb_define_module_function(module, "eigen_genhermv_sort",
|
2331
|
+
rb_gsl_eigen_genhermv_sort, -1);
|
2332
|
+
|
2333
|
+
/* gen */
|
2334
|
+
mgen = rb_define_module_under(mgsl_eigen, "Gen");
|
2335
|
+
mgenv = rb_define_module_under(mgsl_eigen, "Genv");
|
2336
|
+
cgenw = rb_define_class_under(mgen, "Workspace", cGSL_Object);
|
2337
|
+
cgenvw = rb_define_class_under(mgenv, "Workspace", cGSL_Object);
|
2338
|
+
rb_define_singleton_method(mgen, "alloc", rb_gsl_eigen_gen_alloc, 1);
|
2339
|
+
rb_define_singleton_method(cgenw, "alloc", rb_gsl_eigen_gen_alloc, 1);
|
2340
|
+
rb_define_singleton_method(mgenv, "alloc", rb_gsl_eigen_genv_alloc, 1);
|
2341
|
+
rb_define_singleton_method(cgenvw, "alloc", rb_gsl_eigen_genv_alloc, 1);
|
2342
|
+
|
2343
|
+
rb_define_module_function(mgen, "params", rb_gsl_eigen_gen_params, -1);
|
2344
|
+
rb_define_method(cgenw, "params", rb_gsl_eigen_gen_params, -1);
|
2345
|
+
rb_define_module_function(mgsl_eigen, "gen_params", rb_gsl_eigen_gen_params, -1);
|
2346
|
+
|
2347
|
+
|
2348
|
+
rb_define_module_function(mgen, "gen", rb_gsl_eigen_gen, -1);
|
2349
|
+
rb_define_module_function(mgsl_eigen, "gen", rb_gsl_eigen_gen, -1);
|
2350
|
+
rb_define_method(cgenw, "gen", rb_gsl_eigen_gen, -1);
|
2351
|
+
|
2352
|
+
rb_define_module_function(mgenv, "genv", rb_gsl_eigen_genv, -1);
|
2353
|
+
rb_define_module_function(mgsl_eigen, "genv", rb_gsl_eigen_genv, -1);
|
2354
|
+
rb_define_method(cgenvw, "genv", rb_gsl_eigen_genv, -1);
|
2355
|
+
|
2356
|
+
rb_define_module_function(mgen, "gen_QZ", rb_gsl_eigen_gen_QZ, -1);
|
2357
|
+
rb_define_module_function(mgsl_eigen, "gen_QZ", rb_gsl_eigen_gen_QZ, -1);
|
2358
|
+
rb_define_method(cgenw, "gen_QZ", rb_gsl_eigen_gen_QZ, -1);
|
2359
|
+
|
2360
|
+
rb_define_module_function(mgenv, "genv_QZ", rb_gsl_eigen_genv_QZ, -1);
|
2361
|
+
rb_define_module_function(mgsl_eigen, "genv_QZ", rb_gsl_eigen_genv_QZ, -1);
|
2362
|
+
rb_define_method(cgenvw, "genv_QZ", rb_gsl_eigen_genv_QZ, -1);
|
2363
|
+
|
2364
|
+
rb_define_module_function(mgsl_eigen, "genv_sort",
|
2365
|
+
rb_gsl_eigen_genv_sort, -1);
|
2366
|
+
rb_define_module_function(mgenv, "sort",
|
2367
|
+
rb_gsl_eigen_genv_sort, -1);
|
2368
|
+
rb_define_module_function(module, "eigen_genv_sort",
|
2369
|
+
rb_gsl_eigen_genv_sort, -1);
|
2370
|
+
#endif
|
2371
|
+
|
2372
|
+
}
|
2373
|
+
|