rb-gsl 1.15.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (660) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +6 -0
  3. data/COPYING +339 -0
  4. data/ChangeLog +567 -0
  5. data/README +32 -0
  6. data/Rakefile +99 -0
  7. data/THANKS +17 -0
  8. data/VERSION +1 -0
  9. data/examples/alf/alf.gp +15 -0
  10. data/examples/alf/alf.rb +32 -0
  11. data/examples/blas/blas.rb +13 -0
  12. data/examples/blas/dnrm2.rb +16 -0
  13. data/examples/blas/level1.rb +81 -0
  14. data/examples/blas/level2.rb +11 -0
  15. data/examples/blas/level3.rb +12 -0
  16. data/examples/bspline.rb +57 -0
  17. data/examples/cdf.rb +16 -0
  18. data/examples/cheb.rb +21 -0
  19. data/examples/combination.rb +23 -0
  20. data/examples/complex/RC-lpf.rb +47 -0
  21. data/examples/complex/add.rb +36 -0
  22. data/examples/complex/coerce.rb +14 -0
  23. data/examples/complex/complex.rb +25 -0
  24. data/examples/complex/fpmi.rb +70 -0
  25. data/examples/complex/functions.rb +77 -0
  26. data/examples/complex/michelson.rb +36 -0
  27. data/examples/complex/mul.rb +28 -0
  28. data/examples/complex/oscillator.rb +17 -0
  29. data/examples/complex/set.rb +37 -0
  30. data/examples/const/physconst.rb +151 -0
  31. data/examples/const/travel.rb +45 -0
  32. data/examples/deriv/demo.rb +13 -0
  33. data/examples/deriv/deriv.rb +36 -0
  34. data/examples/deriv/diff.rb +35 -0
  35. data/examples/dht.rb +42 -0
  36. data/examples/dirac.rb +56 -0
  37. data/examples/eigen/eigen.rb +34 -0
  38. data/examples/eigen/herm.rb +22 -0
  39. data/examples/eigen/narray.rb +9 -0
  40. data/examples/eigen/nonsymm.rb +37 -0
  41. data/examples/eigen/nonsymmv.rb +43 -0
  42. data/examples/eigen/qhoscillator.gp +35 -0
  43. data/examples/eigen/qhoscillator.rb +90 -0
  44. data/examples/eigen/vander.rb +41 -0
  45. data/examples/fft/fft.rb +17 -0
  46. data/examples/fft/fft2.rb +17 -0
  47. data/examples/fft/forward.rb +25 -0
  48. data/examples/fft/forward2.rb +26 -0
  49. data/examples/fft/radix2.rb +18 -0
  50. data/examples/fft/real-halfcomplex.rb +33 -0
  51. data/examples/fft/real-halfcomplex2.rb +30 -0
  52. data/examples/fft/realradix2.rb +19 -0
  53. data/examples/fft/sunspot.dat +256 -0
  54. data/examples/fft/sunspot.rb +16 -0
  55. data/examples/fit/expdata.dat +20 -0
  56. data/examples/fit/expfit.rb +31 -0
  57. data/examples/fit/gaussfit.rb +29 -0
  58. data/examples/fit/gaussian_2peaks.rb +34 -0
  59. data/examples/fit/hillfit.rb +40 -0
  60. data/examples/fit/lognormal.rb +26 -0
  61. data/examples/fit/lorentzfit.rb +22 -0
  62. data/examples/fit/multifit.rb +72 -0
  63. data/examples/fit/ndlinear.rb +133 -0
  64. data/examples/fit/nonlinearfit.rb +89 -0
  65. data/examples/fit/plot.gp +36 -0
  66. data/examples/fit/polyfit.rb +9 -0
  67. data/examples/fit/powerfit.rb +21 -0
  68. data/examples/fit/sigmoidfit.rb +40 -0
  69. data/examples/fit/sinfit.rb +22 -0
  70. data/examples/fit/wlinear.rb +46 -0
  71. data/examples/fresnel.rb +11 -0
  72. data/examples/function/function.rb +36 -0
  73. data/examples/function/log.rb +7 -0
  74. data/examples/function/min.rb +33 -0
  75. data/examples/function/sin.rb +10 -0
  76. data/examples/function/synchrotron.rb +18 -0
  77. data/examples/gallery/butterfly.rb +7 -0
  78. data/examples/gallery/cayley.rb +12 -0
  79. data/examples/gallery/cornu.rb +23 -0
  80. data/examples/gallery/eight.rb +11 -0
  81. data/examples/gallery/koch.rb +40 -0
  82. data/examples/gallery/lemniscate.rb +11 -0
  83. data/examples/gallery/polar.rb +11 -0
  84. data/examples/gallery/rgplot/cossin.rb +35 -0
  85. data/examples/gallery/rgplot/rgplot.replaced +0 -0
  86. data/examples/gallery/rgplot/roesller.rb +55 -0
  87. data/examples/gallery/roesller.rb +39 -0
  88. data/examples/gallery/scarabaeus.rb +14 -0
  89. data/examples/histogram/cauchy.rb +27 -0
  90. data/examples/histogram/cauchy.sh +2 -0
  91. data/examples/histogram/exponential.rb +19 -0
  92. data/examples/histogram/gauss.rb +16 -0
  93. data/examples/histogram/gsl-histogram.rb +40 -0
  94. data/examples/histogram/histo2d.rb +31 -0
  95. data/examples/histogram/histo3d.rb +34 -0
  96. data/examples/histogram/histogram-pdf.rb +27 -0
  97. data/examples/histogram/histogram.rb +26 -0
  98. data/examples/histogram/integral.rb +28 -0
  99. data/examples/histogram/poisson.rb +27 -0
  100. data/examples/histogram/power.rb +25 -0
  101. data/examples/histogram/rebin.rb +17 -0
  102. data/examples/histogram/smp.dat +5 -0
  103. data/examples/histogram/xexp.rb +21 -0
  104. data/examples/integration/ahmed.rb +21 -0
  105. data/examples/integration/cosmology.rb +75 -0
  106. data/examples/integration/friedmann.gp +16 -0
  107. data/examples/integration/friedmann.rb +35 -0
  108. data/examples/integration/gamma-zeta.rb +35 -0
  109. data/examples/integration/integration.rb +22 -0
  110. data/examples/integration/qag.rb +8 -0
  111. data/examples/integration/qag2.rb +14 -0
  112. data/examples/integration/qag3.rb +8 -0
  113. data/examples/integration/qagi.rb +28 -0
  114. data/examples/integration/qagi2.rb +49 -0
  115. data/examples/integration/qagiu.rb +29 -0
  116. data/examples/integration/qagp.rb +20 -0
  117. data/examples/integration/qags.rb +14 -0
  118. data/examples/integration/qawc.rb +18 -0
  119. data/examples/integration/qawf.rb +41 -0
  120. data/examples/integration/qawo.rb +29 -0
  121. data/examples/integration/qaws.rb +30 -0
  122. data/examples/integration/qng.rb +17 -0
  123. data/examples/interp/demo.gp +20 -0
  124. data/examples/interp/demo.rb +45 -0
  125. data/examples/interp/interp.rb +37 -0
  126. data/examples/interp/points +10 -0
  127. data/examples/interp/spline.rb +20 -0
  128. data/examples/jacobi/deriv.rb +40 -0
  129. data/examples/jacobi/integrate.rb +34 -0
  130. data/examples/jacobi/interp.rb +43 -0
  131. data/examples/jacobi/jacobi.rb +11 -0
  132. data/examples/linalg/HH.rb +15 -0
  133. data/examples/linalg/HH_narray.rb +13 -0
  134. data/examples/linalg/LQ_solve.rb +73 -0
  135. data/examples/linalg/LU.rb +84 -0
  136. data/examples/linalg/LU2.rb +31 -0
  137. data/examples/linalg/LU_narray.rb +24 -0
  138. data/examples/linalg/PTLQ.rb +47 -0
  139. data/examples/linalg/QR.rb +18 -0
  140. data/examples/linalg/QRPT.rb +47 -0
  141. data/examples/linalg/QR_solve.rb +78 -0
  142. data/examples/linalg/QR_solve_narray.rb +13 -0
  143. data/examples/linalg/SV.rb +16 -0
  144. data/examples/linalg/SV_narray.rb +12 -0
  145. data/examples/linalg/SV_solve.rb +49 -0
  146. data/examples/linalg/chol.rb +29 -0
  147. data/examples/linalg/chol_narray.rb +15 -0
  148. data/examples/linalg/complex.rb +57 -0
  149. data/examples/linalg/invert_narray.rb +10 -0
  150. data/examples/math/const.rb +67 -0
  151. data/examples/math/elementary.rb +35 -0
  152. data/examples/math/functions.rb +41 -0
  153. data/examples/math/inf_nan.rb +34 -0
  154. data/examples/math/minmax.rb +22 -0
  155. data/examples/math/power.rb +18 -0
  156. data/examples/math/test.rb +31 -0
  157. data/examples/matrix/a.dat +0 -0
  158. data/examples/matrix/add.rb +45 -0
  159. data/examples/matrix/b.dat +4 -0
  160. data/examples/matrix/cat.rb +31 -0
  161. data/examples/matrix/colvectors.rb +24 -0
  162. data/examples/matrix/complex.rb +41 -0
  163. data/examples/matrix/det.rb +29 -0
  164. data/examples/matrix/diagonal.rb +23 -0
  165. data/examples/matrix/get_all.rb +159 -0
  166. data/examples/matrix/hilbert.rb +31 -0
  167. data/examples/matrix/iterator.rb +19 -0
  168. data/examples/matrix/matrix.rb +57 -0
  169. data/examples/matrix/minmax.rb +53 -0
  170. data/examples/matrix/mul.rb +39 -0
  171. data/examples/matrix/rand.rb +20 -0
  172. data/examples/matrix/read.rb +29 -0
  173. data/examples/matrix/rowcol.rb +47 -0
  174. data/examples/matrix/set.rb +41 -0
  175. data/examples/matrix/set_all.rb +100 -0
  176. data/examples/matrix/view.rb +32 -0
  177. data/examples/matrix/view_all.rb +148 -0
  178. data/examples/matrix/write.rb +23 -0
  179. data/examples/min.rb +29 -0
  180. data/examples/monte/miser.rb +47 -0
  181. data/examples/monte/monte.rb +47 -0
  182. data/examples/monte/plain.rb +47 -0
  183. data/examples/monte/vegas.rb +46 -0
  184. data/examples/multimin/bundle.rb +66 -0
  185. data/examples/multimin/cqp.rb +109 -0
  186. data/examples/multimin/fdfminimizer.rb +40 -0
  187. data/examples/multimin/fminimizer.rb +41 -0
  188. data/examples/multiroot/demo.rb +36 -0
  189. data/examples/multiroot/fdfsolver.rb +50 -0
  190. data/examples/multiroot/fsolver.rb +33 -0
  191. data/examples/multiroot/fsolver2.rb +32 -0
  192. data/examples/multiroot/fsolver3.rb +26 -0
  193. data/examples/narray/histogram.rb +14 -0
  194. data/examples/narray/mandel.rb +27 -0
  195. data/examples/narray/narray.rb +28 -0
  196. data/examples/narray/narray2.rb +44 -0
  197. data/examples/narray/sf.rb +26 -0
  198. data/examples/ntuple/create.rb +17 -0
  199. data/examples/ntuple/project.rb +31 -0
  200. data/examples/odeiv/binarysystem.gp +23 -0
  201. data/examples/odeiv/binarysystem.rb +104 -0
  202. data/examples/odeiv/demo.gp +24 -0
  203. data/examples/odeiv/demo.rb +69 -0
  204. data/examples/odeiv/demo2.gp +26 -0
  205. data/examples/odeiv/duffing.rb +45 -0
  206. data/examples/odeiv/frei1.rb +109 -0
  207. data/examples/odeiv/frei2.rb +76 -0
  208. data/examples/odeiv/legendre.rb +52 -0
  209. data/examples/odeiv/odeiv.rb +32 -0
  210. data/examples/odeiv/odeiv2.rb +45 -0
  211. data/examples/odeiv/oscillator.rb +42 -0
  212. data/examples/odeiv/sedov.rb +97 -0
  213. data/examples/odeiv/whitedwarf.gp +40 -0
  214. data/examples/odeiv/whitedwarf.rb +158 -0
  215. data/examples/ool/conmin.rb +100 -0
  216. data/examples/ool/gencan.rb +99 -0
  217. data/examples/ool/pgrad.rb +100 -0
  218. data/examples/ool/spg.rb +100 -0
  219. data/examples/pdf/bernoulli.rb +5 -0
  220. data/examples/pdf/beta.rb +7 -0
  221. data/examples/pdf/binomiral.rb +10 -0
  222. data/examples/pdf/cauchy.rb +6 -0
  223. data/examples/pdf/chisq.rb +8 -0
  224. data/examples/pdf/exponential.rb +7 -0
  225. data/examples/pdf/exppow.rb +6 -0
  226. data/examples/pdf/fdist.rb +7 -0
  227. data/examples/pdf/flat.rb +7 -0
  228. data/examples/pdf/gamma.rb +8 -0
  229. data/examples/pdf/gauss-tail.rb +5 -0
  230. data/examples/pdf/gauss.rb +6 -0
  231. data/examples/pdf/geometric.rb +5 -0
  232. data/examples/pdf/gumbel.rb +6 -0
  233. data/examples/pdf/hypergeometric.rb +11 -0
  234. data/examples/pdf/landau.rb +5 -0
  235. data/examples/pdf/laplace.rb +7 -0
  236. data/examples/pdf/logarithmic.rb +5 -0
  237. data/examples/pdf/logistic.rb +6 -0
  238. data/examples/pdf/lognormal.rb +6 -0
  239. data/examples/pdf/neg-binomiral.rb +10 -0
  240. data/examples/pdf/pareto.rb +7 -0
  241. data/examples/pdf/pascal.rb +10 -0
  242. data/examples/pdf/poisson.rb +5 -0
  243. data/examples/pdf/rayleigh-tail.rb +6 -0
  244. data/examples/pdf/rayleigh.rb +6 -0
  245. data/examples/pdf/tdist.rb +6 -0
  246. data/examples/pdf/weibull.rb +8 -0
  247. data/examples/permutation/ex1.rb +22 -0
  248. data/examples/permutation/permutation.rb +16 -0
  249. data/examples/poly/bell.rb +6 -0
  250. data/examples/poly/bessel.rb +6 -0
  251. data/examples/poly/cheb.rb +6 -0
  252. data/examples/poly/cheb_II.rb +6 -0
  253. data/examples/poly/cubic.rb +9 -0
  254. data/examples/poly/demo.rb +20 -0
  255. data/examples/poly/eval.rb +28 -0
  256. data/examples/poly/eval_derivs.rb +14 -0
  257. data/examples/poly/fit.rb +21 -0
  258. data/examples/poly/hermite.rb +6 -0
  259. data/examples/poly/poly.rb +13 -0
  260. data/examples/poly/quadratic.rb +25 -0
  261. data/examples/random/diffusion.rb +34 -0
  262. data/examples/random/gaussian.rb +9 -0
  263. data/examples/random/generator.rb +27 -0
  264. data/examples/random/hdsobol.rb +21 -0
  265. data/examples/random/poisson.rb +9 -0
  266. data/examples/random/qrng.rb +19 -0
  267. data/examples/random/randomwalk.rb +37 -0
  268. data/examples/random/randomwalk2d.rb +19 -0
  269. data/examples/random/rayleigh.rb +36 -0
  270. data/examples/random/rng.rb +33 -0
  271. data/examples/random/rngextra.rb +14 -0
  272. data/examples/roots/bisection.rb +25 -0
  273. data/examples/roots/brent.rb +43 -0
  274. data/examples/roots/demo.rb +30 -0
  275. data/examples/roots/newton.rb +46 -0
  276. data/examples/roots/recombination.gp +12 -0
  277. data/examples/roots/recombination.rb +61 -0
  278. data/examples/roots/steffenson.rb +48 -0
  279. data/examples/sf/ShiChi.rb +6 -0
  280. data/examples/sf/SiCi.rb +6 -0
  281. data/examples/sf/airy_Ai.rb +8 -0
  282. data/examples/sf/airy_Bi.rb +8 -0
  283. data/examples/sf/bessel_IK.rb +12 -0
  284. data/examples/sf/bessel_JY.rb +13 -0
  285. data/examples/sf/beta_inc.rb +9 -0
  286. data/examples/sf/clausen.rb +6 -0
  287. data/examples/sf/dawson.rb +5 -0
  288. data/examples/sf/debye.rb +9 -0
  289. data/examples/sf/dilog.rb +6 -0
  290. data/examples/sf/ellint.rb +6 -0
  291. data/examples/sf/expint.rb +8 -0
  292. data/examples/sf/fermi.rb +10 -0
  293. data/examples/sf/gamma_inc_P.rb +9 -0
  294. data/examples/sf/gegenbauer.rb +8 -0
  295. data/examples/sf/hyperg.rb +7 -0
  296. data/examples/sf/laguerre.rb +19 -0
  297. data/examples/sf/lambertW.rb +5 -0
  298. data/examples/sf/legendre_P.rb +10 -0
  299. data/examples/sf/lngamma.rb +5 -0
  300. data/examples/sf/psi.rb +54 -0
  301. data/examples/sf/sphbessel.gp +27 -0
  302. data/examples/sf/sphbessel.rb +30 -0
  303. data/examples/sf/synchrotron.rb +5 -0
  304. data/examples/sf/transport.rb +10 -0
  305. data/examples/sf/zetam1.rb +5 -0
  306. data/examples/siman.rb +44 -0
  307. data/examples/sort/heapsort.rb +23 -0
  308. data/examples/sort/heapsort_vector_complex.rb +21 -0
  309. data/examples/sort/sort.rb +23 -0
  310. data/examples/sort/sort2.rb +16 -0
  311. data/examples/stats/mean.rb +17 -0
  312. data/examples/stats/statistics.rb +18 -0
  313. data/examples/stats/test.rb +9 -0
  314. data/examples/sum.rb +34 -0
  315. data/examples/tamu_anova.rb +18 -0
  316. data/examples/vector/a.dat +0 -0
  317. data/examples/vector/add.rb +56 -0
  318. data/examples/vector/b.dat +4 -0
  319. data/examples/vector/c.dat +3 -0
  320. data/examples/vector/collect.rb +26 -0
  321. data/examples/vector/compare.rb +28 -0
  322. data/examples/vector/complex.rb +51 -0
  323. data/examples/vector/complex_get_all.rb +85 -0
  324. data/examples/vector/complex_set_all.rb +131 -0
  325. data/examples/vector/complex_view_all.rb +77 -0
  326. data/examples/vector/connect.rb +22 -0
  327. data/examples/vector/decimate.rb +38 -0
  328. data/examples/vector/diff.rb +31 -0
  329. data/examples/vector/filescan.rb +17 -0
  330. data/examples/vector/floor.rb +23 -0
  331. data/examples/vector/get_all.rb +82 -0
  332. data/examples/vector/gnuplot.rb +38 -0
  333. data/examples/vector/graph.rb +28 -0
  334. data/examples/vector/histogram.rb +22 -0
  335. data/examples/vector/linspace.rb +24 -0
  336. data/examples/vector/log.rb +17 -0
  337. data/examples/vector/logic.rb +33 -0
  338. data/examples/vector/logspace.rb +25 -0
  339. data/examples/vector/minmax.rb +47 -0
  340. data/examples/vector/mul.rb +49 -0
  341. data/examples/vector/narray.rb +46 -0
  342. data/examples/vector/read.rb +29 -0
  343. data/examples/vector/set.rb +35 -0
  344. data/examples/vector/set_all.rb +121 -0
  345. data/examples/vector/smpv.dat +15 -0
  346. data/examples/vector/test.rb +43 -0
  347. data/examples/vector/test_gslblock.rb +58 -0
  348. data/examples/vector/vector.rb +110 -0
  349. data/examples/vector/view.rb +35 -0
  350. data/examples/vector/view_all.rb +73 -0
  351. data/examples/vector/where.rb +29 -0
  352. data/examples/vector/write.rb +24 -0
  353. data/examples/vector/zip.rb +34 -0
  354. data/examples/wavelet/ecg.dat +256 -0
  355. data/examples/wavelet/wavelet1.rb +50 -0
  356. data/ext/alf.c +206 -0
  357. data/ext/array.c +642 -0
  358. data/ext/array_complex.c +248 -0
  359. data/ext/blas.c +29 -0
  360. data/ext/blas1.c +734 -0
  361. data/ext/blas2.c +1093 -0
  362. data/ext/blas3.c +881 -0
  363. data/ext/block.c +44 -0
  364. data/ext/block_source.c +887 -0
  365. data/ext/bspline.c +130 -0
  366. data/ext/bundle.c +3 -0
  367. data/ext/cdf.c +754 -0
  368. data/ext/cheb.c +542 -0
  369. data/ext/combination.c +283 -0
  370. data/ext/common.c +325 -0
  371. data/ext/complex.c +1004 -0
  372. data/ext/const.c +673 -0
  373. data/ext/const_additional.c +120 -0
  374. data/ext/cqp.c +283 -0
  375. data/ext/deriv.c +195 -0
  376. data/ext/dht.c +361 -0
  377. data/ext/diff.c +166 -0
  378. data/ext/dirac.c +389 -0
  379. data/ext/eigen.c +2373 -0
  380. data/ext/error.c +193 -0
  381. data/ext/extconf.rb +303 -0
  382. data/ext/fcmp.c +66 -0
  383. data/ext/fft.c +1102 -0
  384. data/ext/fit.c +205 -0
  385. data/ext/fresnel.c +312 -0
  386. data/ext/function.c +524 -0
  387. data/ext/geometry.c +139 -0
  388. data/ext/graph.c +1640 -0
  389. data/ext/gsl.c +280 -0
  390. data/ext/gsl_narray.c +804 -0
  391. data/ext/histogram.c +1991 -0
  392. data/ext/histogram2d.c +1068 -0
  393. data/ext/histogram3d.c +884 -0
  394. data/ext/histogram3d_source.c +750 -0
  395. data/ext/histogram_find.c +101 -0
  396. data/ext/histogram_oper.c +159 -0
  397. data/ext/ieee.c +100 -0
  398. data/ext/integration.c +1179 -0
  399. data/ext/interp.c +512 -0
  400. data/ext/jacobi.c +739 -0
  401. data/ext/linalg.c +4042 -0
  402. data/ext/linalg_complex.c +739 -0
  403. data/ext/math.c +725 -0
  404. data/ext/matrix.c +39 -0
  405. data/ext/matrix_complex.c +1737 -0
  406. data/ext/matrix_double.c +560 -0
  407. data/ext/matrix_int.c +256 -0
  408. data/ext/matrix_source.c +2734 -0
  409. data/ext/min.c +250 -0
  410. data/ext/monte.c +992 -0
  411. data/ext/multifit.c +1871 -0
  412. data/ext/multimin.c +806 -0
  413. data/ext/multimin_fsdf.c +156 -0
  414. data/ext/multiroots.c +955 -0
  415. data/ext/multiset.c +214 -0
  416. data/ext/ndlinear.c +321 -0
  417. data/ext/nmf.c +171 -0
  418. data/ext/nmf_wrap.c +75 -0
  419. data/ext/ntuple.c +469 -0
  420. data/ext/odeiv.c +962 -0
  421. data/ext/ool.c +879 -0
  422. data/ext/oper_complex_source.c +253 -0
  423. data/ext/permutation.c +596 -0
  424. data/ext/poly.c +42 -0
  425. data/ext/poly2.c +265 -0
  426. data/ext/poly_source.c +1915 -0
  427. data/ext/qrng.c +171 -0
  428. data/ext/randist.c +1873 -0
  429. data/ext/rational.c +480 -0
  430. data/ext/rng.c +612 -0
  431. data/ext/root.c +408 -0
  432. data/ext/sf.c +1494 -0
  433. data/ext/sf_airy.c +200 -0
  434. data/ext/sf_bessel.c +871 -0
  435. data/ext/sf_clausen.c +28 -0
  436. data/ext/sf_coulomb.c +206 -0
  437. data/ext/sf_coupling.c +121 -0
  438. data/ext/sf_dawson.c +29 -0
  439. data/ext/sf_debye.c +157 -0
  440. data/ext/sf_dilog.c +43 -0
  441. data/ext/sf_elementary.c +46 -0
  442. data/ext/sf_ellint.c +206 -0
  443. data/ext/sf_elljac.c +30 -0
  444. data/ext/sf_erfc.c +93 -0
  445. data/ext/sf_exp.c +169 -0
  446. data/ext/sf_expint.c +211 -0
  447. data/ext/sf_fermi_dirac.c +148 -0
  448. data/ext/sf_gamma.c +347 -0
  449. data/ext/sf_gegenbauer.c +97 -0
  450. data/ext/sf_hyperg.c +203 -0
  451. data/ext/sf_laguerre.c +113 -0
  452. data/ext/sf_lambert.c +47 -0
  453. data/ext/sf_legendre.c +368 -0
  454. data/ext/sf_log.c +105 -0
  455. data/ext/sf_mathieu.c +238 -0
  456. data/ext/sf_power.c +47 -0
  457. data/ext/sf_psi.c +98 -0
  458. data/ext/sf_synchrotron.c +48 -0
  459. data/ext/sf_transport.c +76 -0
  460. data/ext/sf_trigonometric.c +210 -0
  461. data/ext/sf_zeta.c +119 -0
  462. data/ext/signal.c +308 -0
  463. data/ext/siman.c +717 -0
  464. data/ext/sort.c +208 -0
  465. data/ext/spline.c +395 -0
  466. data/ext/stats.c +800 -0
  467. data/ext/sum.c +168 -0
  468. data/ext/tamu_anova.c +56 -0
  469. data/ext/tensor.c +38 -0
  470. data/ext/tensor_source.c +1123 -0
  471. data/ext/vector.c +38 -0
  472. data/ext/vector_complex.c +2246 -0
  473. data/ext/vector_double.c +1438 -0
  474. data/ext/vector_int.c +204 -0
  475. data/ext/vector_source.c +3336 -0
  476. data/ext/wavelet.c +945 -0
  477. data/include/rb_gsl.h +158 -0
  478. data/include/rb_gsl_array.h +238 -0
  479. data/include/rb_gsl_cheb.h +21 -0
  480. data/include/rb_gsl_common.h +348 -0
  481. data/include/rb_gsl_complex.h +25 -0
  482. data/include/rb_gsl_config.h +62 -0
  483. data/include/rb_gsl_const.h +29 -0
  484. data/include/rb_gsl_dirac.h +13 -0
  485. data/include/rb_gsl_eigen.h +17 -0
  486. data/include/rb_gsl_fft.h +62 -0
  487. data/include/rb_gsl_fit.h +25 -0
  488. data/include/rb_gsl_function.h +27 -0
  489. data/include/rb_gsl_graph.h +70 -0
  490. data/include/rb_gsl_histogram.h +63 -0
  491. data/include/rb_gsl_histogram3d.h +97 -0
  492. data/include/rb_gsl_integration.h +17 -0
  493. data/include/rb_gsl_interp.h +46 -0
  494. data/include/rb_gsl_linalg.h +25 -0
  495. data/include/rb_gsl_math.h +26 -0
  496. data/include/rb_gsl_odeiv.h +21 -0
  497. data/include/rb_gsl_poly.h +71 -0
  498. data/include/rb_gsl_rational.h +37 -0
  499. data/include/rb_gsl_rng.h +21 -0
  500. data/include/rb_gsl_root.h +22 -0
  501. data/include/rb_gsl_sf.h +119 -0
  502. data/include/rb_gsl_statistics.h +17 -0
  503. data/include/rb_gsl_tensor.h +45 -0
  504. data/include/rb_gsl_with_narray.h +29 -0
  505. data/include/templates_off.h +87 -0
  506. data/include/templates_on.h +241 -0
  507. data/lib/gsl.rb +3 -0
  508. data/lib/gsl/gnuplot.rb +41 -0
  509. data/lib/gsl/oper.rb +68 -0
  510. data/lib/ool.rb +22 -0
  511. data/lib/ool/conmin.rb +30 -0
  512. data/lib/rbgsl.rb +3 -0
  513. data/rdoc/alf.rdoc +77 -0
  514. data/rdoc/blas.rdoc +269 -0
  515. data/rdoc/bspline.rdoc +42 -0
  516. data/rdoc/changes.rdoc +164 -0
  517. data/rdoc/cheb.rdoc +99 -0
  518. data/rdoc/cholesky_complex.rdoc +46 -0
  519. data/rdoc/combi.rdoc +125 -0
  520. data/rdoc/complex.rdoc +210 -0
  521. data/rdoc/const.rdoc +546 -0
  522. data/rdoc/dht.rdoc +122 -0
  523. data/rdoc/diff.rdoc +133 -0
  524. data/rdoc/ehandling.rdoc +50 -0
  525. data/rdoc/eigen.rdoc +401 -0
  526. data/rdoc/fft.rdoc +535 -0
  527. data/rdoc/fit.rdoc +284 -0
  528. data/rdoc/function.rdoc +94 -0
  529. data/rdoc/graph.rdoc +137 -0
  530. data/rdoc/hist.rdoc +409 -0
  531. data/rdoc/hist2d.rdoc +279 -0
  532. data/rdoc/hist3d.rdoc +112 -0
  533. data/rdoc/index.rdoc +62 -0
  534. data/rdoc/integration.rdoc +398 -0
  535. data/rdoc/interp.rdoc +231 -0
  536. data/rdoc/intro.rdoc +27 -0
  537. data/rdoc/linalg.rdoc +681 -0
  538. data/rdoc/linalg_complex.rdoc +88 -0
  539. data/rdoc/math.rdoc +276 -0
  540. data/rdoc/matrix.rdoc +1093 -0
  541. data/rdoc/min.rdoc +189 -0
  542. data/rdoc/monte.rdoc +234 -0
  543. data/rdoc/multimin.rdoc +312 -0
  544. data/rdoc/multiroot.rdoc +293 -0
  545. data/rdoc/narray.rdoc +177 -0
  546. data/rdoc/ndlinear.rdoc +250 -0
  547. data/rdoc/nonlinearfit.rdoc +348 -0
  548. data/rdoc/ntuple.rdoc +88 -0
  549. data/rdoc/odeiv.rdoc +378 -0
  550. data/rdoc/perm.rdoc +221 -0
  551. data/rdoc/poly.rdoc +335 -0
  552. data/rdoc/qrng.rdoc +90 -0
  553. data/rdoc/randist.rdoc +233 -0
  554. data/rdoc/ref.rdoc +93 -0
  555. data/rdoc/rng.rdoc +203 -0
  556. data/rdoc/rngextra.rdoc +11 -0
  557. data/rdoc/roots.rdoc +305 -0
  558. data/rdoc/screenshot.rdoc +40 -0
  559. data/rdoc/sf.rdoc +1622 -0
  560. data/rdoc/siman.rdoc +89 -0
  561. data/rdoc/sort.rdoc +94 -0
  562. data/rdoc/start.rdoc +16 -0
  563. data/rdoc/stats.rdoc +219 -0
  564. data/rdoc/sum.rdoc +65 -0
  565. data/rdoc/tensor.rdoc +251 -0
  566. data/rdoc/tut.rdoc +5 -0
  567. data/rdoc/use.rdoc +177 -0
  568. data/rdoc/vector.rdoc +1243 -0
  569. data/rdoc/vector_complex.rdoc +347 -0
  570. data/rdoc/wavelet.rdoc +218 -0
  571. data/setup.rb +1585 -0
  572. data/tests/blas/amax.rb +14 -0
  573. data/tests/blas/asum.rb +16 -0
  574. data/tests/blas/axpy.rb +25 -0
  575. data/tests/blas/copy.rb +23 -0
  576. data/tests/blas/dot.rb +23 -0
  577. data/tests/bspline.rb +53 -0
  578. data/tests/cdf.rb +1388 -0
  579. data/tests/cheb.rb +112 -0
  580. data/tests/combination.rb +123 -0
  581. data/tests/complex.rb +17 -0
  582. data/tests/const.rb +24 -0
  583. data/tests/deriv.rb +85 -0
  584. data/tests/dht/dht1.rb +17 -0
  585. data/tests/dht/dht2.rb +23 -0
  586. data/tests/dht/dht3.rb +23 -0
  587. data/tests/dht/dht4.rb +23 -0
  588. data/tests/diff.rb +78 -0
  589. data/tests/eigen/eigen.rb +220 -0
  590. data/tests/eigen/gen.rb +105 -0
  591. data/tests/eigen/genherm.rb +66 -0
  592. data/tests/eigen/gensymm.rb +68 -0
  593. data/tests/eigen/nonsymm.rb +53 -0
  594. data/tests/eigen/nonsymmv.rb +53 -0
  595. data/tests/eigen/symm-herm.rb +74 -0
  596. data/tests/err.rb +58 -0
  597. data/tests/fit.rb +124 -0
  598. data/tests/gsl_test.rb +118 -0
  599. data/tests/gsl_test2.rb +110 -0
  600. data/tests/histo.rb +12 -0
  601. data/tests/integration/integration1.rb +72 -0
  602. data/tests/integration/integration2.rb +71 -0
  603. data/tests/integration/integration3.rb +71 -0
  604. data/tests/integration/integration4.rb +71 -0
  605. data/tests/interp.rb +45 -0
  606. data/tests/linalg/HH.rb +64 -0
  607. data/tests/linalg/LU.rb +47 -0
  608. data/tests/linalg/QR.rb +77 -0
  609. data/tests/linalg/SV.rb +24 -0
  610. data/tests/linalg/TDN.rb +116 -0
  611. data/tests/linalg/TDS.rb +122 -0
  612. data/tests/linalg/bidiag.rb +73 -0
  613. data/tests/linalg/cholesky.rb +20 -0
  614. data/tests/linalg/linalg.rb +158 -0
  615. data/tests/matrix/matrix_complex_test.rb +36 -0
  616. data/tests/matrix/matrix_nmf_test.rb +39 -0
  617. data/tests/matrix/matrix_test.rb +48 -0
  618. data/tests/min.rb +99 -0
  619. data/tests/monte/miser.rb +31 -0
  620. data/tests/monte/vegas.rb +45 -0
  621. data/tests/multifit/test_2dgauss.rb +112 -0
  622. data/tests/multifit/test_brown.rb +90 -0
  623. data/tests/multifit/test_enso.rb +246 -0
  624. data/tests/multifit/test_filip.rb +155 -0
  625. data/tests/multifit/test_gauss.rb +97 -0
  626. data/tests/multifit/test_longley.rb +110 -0
  627. data/tests/multifit/test_multifit.rb +52 -0
  628. data/tests/multimin.rb +139 -0
  629. data/tests/multiroot.rb +131 -0
  630. data/tests/multiset.rb +52 -0
  631. data/tests/narray/blas_dnrm2.rb +20 -0
  632. data/tests/odeiv.rb +353 -0
  633. data/tests/poly/poly.rb +290 -0
  634. data/tests/poly/special.rb +65 -0
  635. data/tests/qrng.rb +131 -0
  636. data/tests/quartic.rb +29 -0
  637. data/tests/randist.rb +134 -0
  638. data/tests/rng.rb +305 -0
  639. data/tests/roots.rb +76 -0
  640. data/tests/run-test.sh +17 -0
  641. data/tests/sf/gsl_test_sf.rb +249 -0
  642. data/tests/sf/test_airy.rb +83 -0
  643. data/tests/sf/test_bessel.rb +306 -0
  644. data/tests/sf/test_coulomb.rb +17 -0
  645. data/tests/sf/test_dilog.rb +25 -0
  646. data/tests/sf/test_gamma.rb +209 -0
  647. data/tests/sf/test_hyperg.rb +356 -0
  648. data/tests/sf/test_legendre.rb +227 -0
  649. data/tests/sf/test_mathieu.rb +59 -0
  650. data/tests/sf/test_mode.rb +19 -0
  651. data/tests/sf/test_sf.rb +839 -0
  652. data/tests/stats.rb +174 -0
  653. data/tests/stats_mt.rb +16 -0
  654. data/tests/sum.rb +98 -0
  655. data/tests/sys.rb +323 -0
  656. data/tests/tensor.rb +419 -0
  657. data/tests/vector/vector_complex_test.rb +101 -0
  658. data/tests/vector/vector_test.rb +141 -0
  659. data/tests/wavelet.rb +142 -0
  660. metadata +789 -0
@@ -0,0 +1,204 @@
1
+ /*
2
+ vector_int.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2004 by Yoshiki Tsunesada
5
+ Modified by Seiya Nishizawa 14/Apr/2004
6
+
7
+ Ruby/GSL is free software: you can redistribute it and/or modify it
8
+ under the terms of the GNU General Public License.
9
+ This library is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY.
11
+ */
12
+ #include "rb_gsl_config.h"
13
+ #include "rb_gsl_array.h"
14
+ #include "rb_gsl_complex.h"
15
+ #ifdef HAVE_NARRAY_H
16
+ #include "rb_gsl_with_narray.h"
17
+ #endif
18
+
19
+ VALUE rb_gsl_vector_int_inner_product(int argc, VALUE *argv, VALUE obj);
20
+ VALUE rb_gsl_vector_int_do_something(VALUE obj, void (*func)(gsl_vector_int*));
21
+
22
+ static VALUE rb_gsl_vector_int_to_i(VALUE obj)
23
+ {
24
+ return obj;
25
+ }
26
+
27
+ VALUE rb_gsl_vector_int_to_f(VALUE obj)
28
+ {
29
+ gsl_vector_int *v;
30
+ gsl_vector *vnew;
31
+ size_t i;
32
+ Data_Get_Struct(obj, gsl_vector_int, v);
33
+ vnew = gsl_vector_alloc(v->size);
34
+ for (i = 0; i < v->size; i++)
35
+ gsl_vector_set(vnew, i, (double) gsl_vector_int_get(v, i));
36
+ if (VECTOR_INT_COL_P(obj))
37
+ return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, vnew);
38
+ else
39
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
40
+ }
41
+
42
+ static VALUE rb_gsl_vector_int_to_complex(VALUE obj)
43
+ {
44
+ gsl_vector_int *v;
45
+ gsl_vector_complex *vnew;
46
+ gsl_complex z;
47
+ size_t i;
48
+ Data_Get_Struct(obj, gsl_vector_int, v);
49
+ vnew = gsl_vector_complex_alloc(v->size);
50
+ for (i = 0; i < v->size; i++) {
51
+ GSL_SET_REAL(&z, (double) gsl_vector_int_get(v, i));
52
+ GSL_SET_IMAG(&z, 0.0);
53
+ gsl_vector_complex_set(vnew, i, z);
54
+ }
55
+ if (VECTOR_INT_COL_P(obj))
56
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, vnew);
57
+ else
58
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
59
+ }
60
+
61
+ static VALUE rb_gsl_vector_int_coerce(VALUE obj, VALUE other)
62
+ {
63
+ gsl_vector_int *v = NULL, *vnew = NULL;
64
+ VALUE vv;
65
+ Data_Get_Struct(obj, gsl_vector_int, v);
66
+ switch (TYPE(other)) {
67
+ case T_FIXNUM:
68
+ vnew = gsl_vector_int_alloc(v->size);
69
+ if (vnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_int_alloc failed");
70
+ gsl_vector_int_set_all(vnew, FIX2INT(other));
71
+ vv = Data_Wrap_Struct(VECTOR_INT_ROW_COL(obj), 0, gsl_vector_int_free, vnew);
72
+ return rb_ary_new3(2, vv, obj);
73
+ break;
74
+ default:
75
+ return rb_ary_new3(2, other, rb_gsl_vector_int_to_f(obj));
76
+ }
77
+ // return rb_ary_new3(2, other, rb_gsl_vector_int_to_f(obj));
78
+ }
79
+
80
+ VALUE rb_gsl_vector_add(VALUE obj, VALUE b);
81
+ VALUE rb_gsl_vector_sub(VALUE obj, VALUE b);
82
+ VALUE rb_gsl_vector_mul(VALUE obj, VALUE b);
83
+ VALUE rb_gsl_vector_div(VALUE obj, VALUE b);
84
+ static VALUE rb_gsl_vector_int_add(VALUE obj, VALUE b)
85
+ {
86
+ gsl_vector_int *v, *vnew, *vb;
87
+ switch (TYPE(b)) {
88
+ case T_FIXNUM:
89
+ return rb_gsl_vector_int_add_constant(obj, b);
90
+ break;
91
+ case T_FLOAT:
92
+ return rb_gsl_vector_add_constant(rb_gsl_vector_int_to_f(obj), b);
93
+ break;
94
+ default:
95
+ if (rb_obj_is_kind_of(b, cgsl_vector_int)) {
96
+ Data_Get_Struct(obj, gsl_vector_int, v);
97
+ Data_Get_Struct(b, gsl_vector_int, vb);
98
+ vnew = gsl_vector_int_alloc(v->size);
99
+ gsl_vector_int_memcpy(vnew, v);
100
+ gsl_vector_int_add(vnew, vb);
101
+ return Data_Wrap_Struct(VECTOR_INT_ROW_COL(obj), 0, gsl_vector_int_free, vnew);
102
+ } else {
103
+ return rb_gsl_vector_add(rb_gsl_vector_int_to_f(obj), b);
104
+ }
105
+ break;
106
+ }
107
+ }
108
+
109
+
110
+ static VALUE rb_gsl_vector_int_sub(VALUE obj, VALUE b)
111
+ {
112
+ gsl_vector_int *v, *vnew, *vb;
113
+ switch (TYPE(b)) {
114
+ case T_FIXNUM:
115
+ return rb_gsl_vector_int_add_constant(obj, INT2FIX(-FIX2INT(b)));
116
+ break;
117
+ case T_FLOAT:
118
+ return rb_gsl_vector_add_constant(rb_gsl_vector_int_to_f(obj), rb_float_new(-NUM2DBL(b)));
119
+ break;
120
+ default:
121
+ if (rb_obj_is_kind_of(b, cgsl_vector_int)) {
122
+ Data_Get_Struct(obj, gsl_vector_int, v);
123
+ Data_Get_Struct(b, gsl_vector_int, vb);
124
+ vnew = gsl_vector_int_alloc(v->size);
125
+ gsl_vector_int_memcpy(vnew, v);
126
+ gsl_vector_int_sub(vnew, vb);
127
+ return Data_Wrap_Struct(VECTOR_INT_ROW_COL(obj), 0, gsl_vector_int_free, vnew);
128
+ } else {
129
+ return rb_gsl_vector_sub(rb_gsl_vector_int_to_f(obj), b);
130
+ }
131
+ break;
132
+ }
133
+ }
134
+
135
+ gsl_vector_int* mygsl_vector_int_mul_matrix(gsl_vector_int *v, gsl_matrix_int *m);
136
+
137
+ static VALUE rb_gsl_vector_int_mul(VALUE obj, VALUE b)
138
+ {
139
+ VALUE argv[2];
140
+ gsl_vector_int *v, *vnew, *v2;
141
+ gsl_matrix_int *m;
142
+ int val;
143
+ size_t i, j;
144
+ switch (TYPE(b)) {
145
+ case T_FIXNUM:
146
+ case T_FLOAT:
147
+ return rb_gsl_vector_int_scale(obj, b);
148
+ break;
149
+ default:
150
+ if (VECTOR_INT_ROW_P(obj) && VECTOR_INT_COL_P(b)) {
151
+ argv[0] = obj;
152
+ argv[1] = b;
153
+ return rb_gsl_vector_int_inner_product(2, argv, CLASS_OF(obj));
154
+ } else if (VECTOR_INT_ROW_P(obj) && MATRIX_INT_P(b)) {
155
+ Data_Get_Struct(obj, gsl_vector_int, v);
156
+ Data_Get_Struct(b, gsl_matrix_int, m);
157
+ vnew = mygsl_vector_int_mul_matrix(v, m);
158
+ return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, vnew);
159
+ } else if (VECTOR_INT_COL_P(obj) && VECTOR_INT_ROW_P(b)) {
160
+ Data_Get_Struct(obj, gsl_vector_int, v);
161
+ Data_Get_Struct(b, gsl_vector_int, v2);
162
+ if (v->size != v2->size) rb_raise(rb_eIndexError, "Vector sizes does not match.");
163
+ m = gsl_matrix_int_alloc(v->size, v2->size);
164
+ for (i = 0; i < v->size; i++) {
165
+ for (j = 0; j < v2->size; j++) {
166
+ val = gsl_vector_int_get(v, i)*gsl_vector_int_get(v2, j);
167
+ gsl_matrix_int_set(m, i, j, val);
168
+ }
169
+ }
170
+ return Data_Wrap_Struct(cgsl_matrix_int, 0, gsl_matrix_int_free, m);
171
+ } else {
172
+ return rb_gsl_vector_mul(rb_gsl_vector_int_to_f(obj), b);
173
+ }
174
+ break;
175
+ }
176
+ }
177
+
178
+ static VALUE rb_gsl_vector_int_div(VALUE obj, VALUE b)
179
+ {
180
+ return rb_gsl_vector_div(rb_gsl_vector_int_to_f(obj), b);
181
+ }
182
+
183
+ void Init_gsl_vector_int(VALUE module)
184
+ {
185
+ rb_define_method(cgsl_vector_int, "to_f", rb_gsl_vector_int_to_f, 0);
186
+ rb_define_method(cgsl_vector_int, "to_i", rb_gsl_vector_int_to_i, 0);
187
+ rb_define_method(cgsl_vector_int, "to_complex", rb_gsl_vector_int_to_complex, 0);
188
+
189
+ /*****/
190
+ rb_define_method(cgsl_vector_int, "coerce", rb_gsl_vector_int_coerce, 1);
191
+
192
+ rb_define_method(cgsl_vector_int, "add", rb_gsl_vector_int_add, 1);
193
+ rb_define_method(cgsl_vector_int, "sub", rb_gsl_vector_int_sub, 1);
194
+ rb_define_method(cgsl_vector_int, "mul", rb_gsl_vector_int_mul, 1);
195
+ rb_define_method(cgsl_vector_int, "div", rb_gsl_vector_int_div, 1);
196
+
197
+ rb_define_alias(cgsl_vector_int, "+", "add");
198
+ rb_define_alias(cgsl_vector_int, "-", "sub");
199
+ rb_define_alias(cgsl_vector_int, "*", "mul");
200
+ rb_define_alias(cgsl_vector_int, "/", "div");
201
+
202
+ Init_gsl_vector_int_init(module);
203
+ }
204
+
@@ -0,0 +1,3336 @@
1
+ /*
2
+ vector_source.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2001-2005 by Yoshiki Tsunesada
5
+ Cameron McBride
6
+
7
+ Ruby/GSL is free software: you can redistribute it and/or modify it
8
+ under the terms of the GNU General Public License.
9
+ This library is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY.
11
+ */
12
+
13
+ #ifdef BASE_DOUBLE
14
+ #define NUMCONV(x) NUM2DBL(x)
15
+ #define NUMCONV2(x) NUM2DBL(x)
16
+ #define PRINTF_FORMAT "%5.3e "
17
+ #define VEC_ROW_COL VECTOR_ROW_COL
18
+ #define VEC_P VECTOR_P
19
+ #define VEC_ROW_P VECTOR_ROW_P
20
+ #define VEC_COL_P VECTOR_COL_P
21
+ #define C_TO_VALUE rb_float_new
22
+ #define C_TO_VALUE2 rb_float_new
23
+ #define CHECK_VEC CHECK_VECTOR
24
+ #define VEC_VIEW_P VECTOR_VIEW_P
25
+ #elif defined(BASE_INT)
26
+ #define NUMCONV(x) FIX2INT(x)
27
+ #define NUMCONV2(x) NUM2INT(x)
28
+ #define PRINTF_FORMAT "%d "
29
+ #define VEC_ROW_COL VECTOR_INT_ROW_COL
30
+ #define VEC_P VECTOR_INT_P
31
+ #define C_TO_VALUE INT2FIX
32
+ #define C_TO_VALUE2 INT2NUM
33
+ #define VEC_ROW_P VECTOR_INT_ROW_P
34
+ #define VEC_COL_P VECTOR_INT_COL_P
35
+ #define CHECK_VEC CHECK_VECTOR_INT
36
+ #define VEC_VIEW_P VECTOR_INT_VIEW_P
37
+ #endif
38
+
39
+ void FUNCTION(get_range,beg_en_n)(VALUE range, BASE *beg, BASE *en, size_t *n, int *step);
40
+
41
+ void get_range_beg_en_n_for_size(VALUE range,
42
+ int *beg, int *en, size_t *n, int *step, size_t size);
43
+
44
+ void parse_subvector_args(int argc, VALUE *argv, size_t size,
45
+ size_t *offset, size_t *stride, size_t *n);
46
+
47
+ void FUNCTION(get_range,beg_en_n)(VALUE range, BASE *beg, BASE *en, size_t *n, int *step)
48
+ {
49
+ *beg = NUMCONV2(rb_funcall3(range, rb_gsl_id_beg, 0, NULL));
50
+ *en = NUMCONV2(rb_funcall3(range, rb_gsl_id_end, 0, NULL));
51
+ *n = (size_t) fabs(*en - *beg);
52
+ if (!RTEST(rb_funcall3(range, rb_gsl_id_excl, 0, NULL))) *n += 1;
53
+ if (*en < *beg) *step = -1; else *step = 1;
54
+ }
55
+
56
+ #ifdef BASE_INT
57
+ void get_range_beg_en_n_for_size(VALUE range, int *beg, int *en, size_t *n, int *step, size_t size)
58
+ {
59
+ *beg = NUM2INT(rb_funcall3(range, rb_gsl_id_beg, 0, NULL));
60
+ if(*beg < 0) *beg += size;
61
+ *en = NUM2INT(rb_funcall3(range, rb_gsl_id_end, 0, NULL));
62
+ if(*en < 0) *en += size;
63
+ *n = (size_t) fabs(*en - *beg);
64
+ if (!RTEST(rb_funcall3(range, rb_gsl_id_excl, 0, NULL))) *n += 1;
65
+ if (*en < *beg) *step = -1; else *step = 1;
66
+ }
67
+
68
+ void parse_subvector_args(int argc, VALUE *argv, size_t size,
69
+ size_t *offset, size_t *stride, size_t *n)
70
+ {
71
+ int begin = 0, end, step, length;
72
+ *stride = 1;
73
+ switch (argc) {
74
+ case 0:
75
+ *n = size;
76
+ break;
77
+ case 1:
78
+ if(rb_obj_is_kind_of(argv[0], rb_cRange)) {
79
+ get_range_beg_en_n_for_size(argv[0], &begin, &end, n, &step, size);
80
+ // TODO Should we do bounds checking or risk letting GSL do it?
81
+ // On one hand, it seems like we should do as little as possible to stay as
82
+ // thin and fast as possible. On the other hand, it seems like we don't
83
+ // want to let Ruby crash if GSL does not have bounds checking enabled.
84
+ if(begin < 0 || (size_t)begin >= size) {
85
+ rb_raise(rb_eRangeError,
86
+ "begin value %d is out of range for Vector of length %d",
87
+ begin, (int) size);
88
+ }
89
+ if(end < 0 || (size_t)end >= size) {
90
+ rb_raise(rb_eRangeError,
91
+ "end value %d is out of range for Vector of length %d",
92
+ end, (int) size);
93
+ }
94
+ *stride = (size_t)step;
95
+ } else {
96
+ CHECK_FIXNUM(argv[0]);
97
+ length = FIX2INT(argv[0]);
98
+ if((length < 0 && -length > size) || (length > 0 && length > size)) {
99
+ rb_raise(rb_eRangeError,
100
+ "length %d is out of range for Vector of length %d",
101
+ length, (int) size);
102
+ } else if(length < 0) {
103
+ begin = length;
104
+ *n = (size_t)(-length);
105
+ } else {
106
+ // begin was initialized to 0
107
+ *n = (size_t)length;
108
+ }
109
+ }
110
+ break;
111
+ case 2:
112
+ if(rb_obj_is_kind_of(argv[0], rb_cRange)) {
113
+ get_range_beg_en_n_for_size(argv[0], &begin, &end, n, &step, size);
114
+ if(begin < 0 || (size_t)begin >= size) {
115
+ rb_raise(rb_eRangeError,
116
+ "begin value %d is out of range for Vector of length %d",
117
+ (int) begin, (int) size);
118
+ }
119
+ if(end < 0 || (size_t)end >= size) {
120
+ rb_raise(rb_eRangeError,
121
+ "end value %d is out of range for Vector of length %d",
122
+ (int) end, (int) size);
123
+ }
124
+ CHECK_FIXNUM(argv[1]);
125
+ step = FIX2INT(argv[1]);
126
+ if(step == 0 && begin != end) {
127
+ rb_raise(rb_eArgError, "stride must be non-zero");
128
+ } else if((step < 0 && begin <= end) || (step > 0 && end < begin)) {
129
+ step = -step;
130
+ }
131
+ if(step < 0) {
132
+ *n = (*n-1)/(-step) + 1;
133
+ } else if(step > 0) {
134
+ *n = (*n-1)/step + 1;
135
+ }
136
+ *stride = (size_t)step;
137
+ } else {
138
+ CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
139
+ begin = FIX2INT(argv[0]);
140
+ length = FIX2INT(argv[1]);
141
+ if(length < 0) {
142
+ length = -length;
143
+ *stride = -1;
144
+ }
145
+ *n = (size_t)length;
146
+ }
147
+ break;
148
+ case 3:
149
+ CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]); CHECK_FIXNUM(argv[2]);
150
+ begin = FIX2INT(argv[0]);
151
+ step = FIX2INT(argv[1]);
152
+ length = FIX2INT(argv[2]);
153
+ if(length < 0) {
154
+ step = -step;
155
+ length = -length;
156
+ }
157
+ *stride = (size_t)step;
158
+ *n = (size_t)length;
159
+ break;
160
+ default:
161
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-3)", argc);
162
+ break;
163
+ }
164
+ if(begin < 0) {
165
+ begin += size;
166
+ }
167
+ *offset = (size_t)begin;
168
+ }
169
+
170
+ #endif
171
+
172
+ void FUNCTION(set_ptr_data,by_range)(BASE *ptr, size_t n, VALUE range)
173
+ {
174
+ size_t n2, i;
175
+ BASE beg, en, val;
176
+ int step;
177
+ FUNCTION(get_range,beg_en_n)(range, &beg, &en, &n2, &step);
178
+ val = beg;
179
+ for (i = 0; i < n; i++) {
180
+ if (i < n2) ptr[i] = val;
181
+ else ptr[i] = (BASE) 0;
182
+ val += step;
183
+ }
184
+ }
185
+
186
+ void FUNCTION(cvector,set_from_rarray)(GSL_TYPE(gsl_vector) *v, VALUE ary)
187
+ {
188
+ size_t i;
189
+ if (CLASS_OF(ary) == rb_cRange) ary = rb_gsl_range2ary(ary);
190
+ Check_Type(ary, T_ARRAY);
191
+ #ifdef RUBY_1_9_LATER
192
+ if (RARRAY_LEN(ary) == 0) return;
193
+ #else
194
+ if (RARRAY_LEN(ary) == 0) return;
195
+ #endif
196
+ for (i = 0; i < v->size; i++) FUNCTION(gsl_vector,set)(v, i, NUMCONV(rb_ary_entry(ary, i)));
197
+ }
198
+
199
+ GSL_TYPE(gsl_vector)* FUNCTION(make_cvector,from_rarray)(VALUE ary)
200
+ {
201
+ GSL_TYPE(gsl_vector) *v = NULL;
202
+ if (CLASS_OF(ary) == rb_cRange) ary = rb_gsl_range2ary(ary);
203
+ Check_Type(ary, T_ARRAY);
204
+ v = FUNCTION(gsl_vector,alloc)(RARRAY_LEN(ary));
205
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
206
+ FUNCTION(cvector,set_from_rarray)(v, ary);
207
+ return v;
208
+ }
209
+
210
+ VALUE FUNCTION(rb_gsl_vector,new)(int argc, VALUE *argv, VALUE klass)
211
+ {
212
+ GSL_TYPE(gsl_vector) *v = NULL, *vtmp = NULL;
213
+ BASE xnative;
214
+ size_t n, i;
215
+ BASE beg, en;
216
+ int step;
217
+ #ifdef HAVE_NARRAY_H
218
+ VALUE ary2;
219
+ #endif
220
+ switch (argc) {
221
+ case 1:
222
+ #ifdef HAVE_NARRAY_H
223
+ if (NA_IsNArray(argv[0])) {
224
+ n = NA_TOTAL(argv[0]);
225
+ v = FUNCTION(gsl_vector,alloc)(n);
226
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
227
+ #ifdef BASE_DOUBLE
228
+ ary2 = na_change_type(argv[0], NA_DFLOAT);
229
+ #else
230
+ ary2 = na_change_type(argv[0], NA_LINT);
231
+ #endif
232
+ memcpy(v->data, NA_PTR_TYPE(ary2,BASE*), n*sizeof(BASE));
233
+ return Data_Wrap_Struct(klass, 0, FUNCTION(gsl_vector,free), v);
234
+ }
235
+ #endif
236
+ switch (TYPE(argv[0])) {
237
+ case T_FIXNUM:
238
+ /*! if an integer n is given, create an empty vector of length n */
239
+ CHECK_FIXNUM(argv[0]);
240
+ n = FIX2INT(argv[0]);
241
+ v = FUNCTION(gsl_vector,calloc)(n);
242
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
243
+ break;
244
+ case T_BIGNUM:
245
+ rb_raise(rb_eRangeError, "vector length is limited within the range of Fixnum.");
246
+ break;
247
+ case T_FLOAT:
248
+ v = FUNCTION(gsl_vector,alloc)(1);
249
+ switch(TYPE(argv[0])) {
250
+ case T_FIXNUM: case T_BIGNUM: case T_FLOAT:
251
+ xnative = NUMCONV2(argv[0]);
252
+ break;
253
+ default:
254
+ xnative = (BASE)0;
255
+ }
256
+ FUNCTION(gsl_vector,set)(v, 0, xnative);
257
+ break;
258
+ #ifdef BASE_DOUBLE
259
+ case T_ARRAY:
260
+ v = make_cvector_from_rarrays(argv[0]);
261
+ break;
262
+ #endif
263
+ default:
264
+ if (CLASS_OF(argv[0]) == rb_cRange) {
265
+ FUNCTION(get_range,beg_en_n)(argv[0], &beg, &en, &n, &step);
266
+ v = FUNCTION(gsl_vector,alloc)(n);
267
+ FUNCTION(set_ptr_data,by_range)(v->data, v->size, argv[0]);
268
+ return Data_Wrap_Struct(klass, 0, FUNCTION(gsl_vector,free), v);
269
+ } else if (VEC_P(argv[0])) {
270
+ /*! Create a new vector with the same elements of the vector given */
271
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), vtmp);
272
+ v = FUNCTION(gsl_vector,alloc)(vtmp->size);
273
+ for (i = 0; i < vtmp->size; i++)
274
+ FUNCTION(gsl_vector,set)(v, i, FUNCTION(gsl_vector,get)(vtmp, i));
275
+ return Data_Wrap_Struct(VEC_ROW_COL(argv[0]), 0, FUNCTION(gsl_vector,free), v);
276
+ } else {
277
+ rb_raise(rb_eTypeError,
278
+ "wrong argument type %s", rb_class2name(CLASS_OF(argv[0])));
279
+ }
280
+ break;
281
+ }
282
+ break;
283
+ default:
284
+ v = FUNCTION(gsl_vector,alloc)(argc);
285
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
286
+ for (i = 0; i < argc; i++) {
287
+ switch(TYPE(argv[i])) {
288
+ case T_FIXNUM: case T_BIGNUM: case T_FLOAT:
289
+ xnative = NUMCONV2(argv[i]);
290
+ break;
291
+ default:
292
+ xnative = (BASE)0;
293
+ }
294
+ FUNCTION(gsl_vector,set)(v, i, xnative);
295
+ }
296
+ break;
297
+ }
298
+ return Data_Wrap_Struct(klass, 0, FUNCTION(gsl_vector,free), v);
299
+ }
300
+
301
+ static VALUE FUNCTION(rb_gsl_vector,calloc)(VALUE klass, VALUE nn)
302
+ {
303
+ GSL_TYPE(gsl_vector) *v = NULL;
304
+ CHECK_FIXNUM(nn);
305
+ v = FUNCTION(gsl_vector,calloc)(FIX2INT(nn));
306
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_calloc failed");
307
+ return Data_Wrap_Struct(klass, 0, FUNCTION(gsl_vector,free), v);
308
+ }
309
+
310
+ static VALUE FUNCTION(rb_gsl_vector,subvector)(int argc, VALUE *argv, VALUE obj);
311
+ static VALUE FUNCTION(rb_gsl_vector,get)(int argc, VALUE *argv, VALUE obj)
312
+ {
313
+ VALUE retval = Qnil;
314
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
315
+ // QUALIFIED_VIEW(gsl_vector,view) *vv;
316
+ gsl_index *p;
317
+ int i; /*! not size_t, since a negative index is allowed */
318
+ size_t j, k;
319
+ // If argc is not 1 or argv[0] is a Range
320
+ if( argc != 1 || rb_obj_is_kind_of(argv[0], rb_cRange)) {
321
+ // Treat as call to subvector
322
+ retval = FUNCTION(rb_gsl_vector,subvector)(argc, argv, obj);
323
+ } else {
324
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
325
+
326
+ switch (TYPE(argv[0])) {
327
+ case T_FIXNUM:
328
+ i = FIX2INT(argv[0]);
329
+ if (i < 0)
330
+ retval = C_TO_VALUE2(FUNCTION(gsl_vector,get)(v, (size_t) (v->size + i)));
331
+ else
332
+ retval = C_TO_VALUE2(FUNCTION(gsl_vector,get)(v, (size_t) (i)));
333
+ break;
334
+ case T_ARRAY:
335
+ vnew = FUNCTION(gsl_vector,alloc)(RARRAY_LEN(argv[0]));
336
+ for (j = 0; j < vnew->size; j++) {
337
+ i = NUMCONV(rb_ary_entry(argv[0], j));
338
+ if (i < 0) k = v->size + i;
339
+ // else k = j;
340
+ else k = i;
341
+ FUNCTION(gsl_vector,set)(vnew, j, FUNCTION(gsl_vector,get)(v, k));
342
+ }
343
+ retval = Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
344
+ break;
345
+ default:
346
+ if (PERMUTATION_P(argv[0])) {
347
+ Data_Get_Struct(argv[0], gsl_index, p);
348
+ vnew = FUNCTION(gsl_vector,alloc)(p->size);
349
+ for (j = 0; j < p->size; j++) {
350
+ k = p->data[j];
351
+ if (k < 0) k = p->size + j;
352
+ FUNCTION(gsl_vector,set)(vnew, j, FUNCTION(gsl_vector,get)(v, k));
353
+ }
354
+ retval = Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
355
+ } else {
356
+ // TODO Support Vector::Int (and even Vector?)
357
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array, Range, GSL::Permutation, or Fixnum expected)", rb_class2name(CLASS_OF(argv[0])));
358
+ }
359
+ break;
360
+ }
361
+ }
362
+ return retval;
363
+ }
364
+
365
+ static VALUE FUNCTION(rb_gsl_vector,size)(VALUE obj)
366
+ {
367
+ GSL_TYPE(gsl_vector) *v = NULL;
368
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
369
+ return INT2FIX(v->size);
370
+ }
371
+
372
+ static VALUE FUNCTION(rb_gsl_vector,stride)(VALUE obj)
373
+ {
374
+ GSL_TYPE(gsl_vector) *v = NULL;
375
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
376
+ return INT2FIX(v->stride);
377
+ }
378
+
379
+ static VALUE FUNCTION(rb_gsl_vector,set_stride)(VALUE obj, VALUE ss)
380
+ {
381
+ GSL_TYPE(gsl_vector) *v = NULL;
382
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
383
+ v->stride = (size_t) FIX2INT(ss);
384
+ return obj;
385
+ }
386
+
387
+ static VALUE FUNCTION(rb_gsl_vector,owner)(VALUE obj)
388
+ {
389
+ GSL_TYPE(gsl_vector) *v = NULL;
390
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
391
+ return INT2FIX(v->owner);
392
+ }
393
+
394
+ void FUNCTION(rb_gsl_vector,set_subvector)(int argc, VALUE *argv, GSL_TYPE(gsl_vector) *v, VALUE other)
395
+ {
396
+ GSL_TYPE(gsl_vector) *vother;
397
+ QUALIFIED_VIEW(gsl_vector,view) vv;
398
+ int step;
399
+ size_t i, offset, stride, n, nother;
400
+ BASE beg, end;
401
+
402
+ // assignment to v.subvector(...)
403
+ parse_subvector_args(argc, argv, v->size, &offset, &stride, &n);
404
+ vv = FUNCTION(gsl_vector,subvector_with_stride)(v, offset, stride, n);
405
+ if(rb_obj_is_kind_of(other, GSL_TYPE(cgsl_vector))) {
406
+ Data_Get_Struct(other, GSL_TYPE(gsl_vector), vother);
407
+ if(n != vother->size) {
408
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)",(int) n, (int) vother->size);
409
+ }
410
+ // TODO Change to gsl_vector_memmove if/when GSL has such a function
411
+ // because gsl_vector_memcpy does not handle overlapping regions (e.g.
412
+ // Views) well.
413
+ FUNCTION(gsl_vector,memcpy)(&vv.vector, vother);
414
+ } else if(rb_obj_is_kind_of(other, rb_cArray)) {
415
+ if(n != RARRAY_LEN(other)) {
416
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) RARRAY_LEN(other));
417
+ }
418
+ for(i = 0; i < n; i++) {
419
+ FUNCTION(gsl_vector,set)(&vv.vector, i, NUMCONV2(rb_ary_entry(other, i)));
420
+ }
421
+ } else if(rb_obj_is_kind_of(other, rb_cRange)) {
422
+ FUNCTION(get_range,beg_en_n)(other, &beg, &end, &nother, &step);
423
+ if(n != nother) {
424
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) nother);
425
+ }
426
+ for(i = 0; i < n; i++) {
427
+ FUNCTION(gsl_vector,set)(&vv.vector, i, beg);
428
+ beg += step;
429
+ }
430
+ } else {
431
+ FUNCTION(gsl_vector,set_all)(&vv.vector, NUMCONV2(other));
432
+ }
433
+ }
434
+
435
+ static VALUE FUNCTION(rb_gsl_vector,set)(int argc, VALUE *argv, VALUE obj)
436
+ {
437
+ GSL_TYPE(gsl_vector) *v;
438
+ VALUE other;
439
+ int ii;
440
+
441
+ if(argc < 1 || argc > 4) {
442
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-4)", argc);
443
+ }
444
+
445
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
446
+ other = argv[argc-1];
447
+
448
+ if(argc == 1) {
449
+ // // If assigning from another vector
450
+ if(VECTOR_P(other) || VECTOR_INT_P(other)) {
451
+ // treat as assignment to v.subvector(...)
452
+ FUNCTION(rb_gsl_vector,set_subvector)(argc-1, argv, v, other);
453
+ } else {
454
+ FUNCTION(gsl_vector,set_all)(v, NUMCONV2(other));
455
+ }
456
+ } else if(argc == 2 && TYPE(argv[0]) == T_FIXNUM) {
457
+ // v[i] = x
458
+ ii = FIX2INT(argv[0]);
459
+ if(ii < 0) ii += v->size;
460
+ FUNCTION(gsl_vector,set)(v, (size_t)ii, NUMCONV2(other));
461
+ } else {
462
+ // assignment to v.subvector(...)
463
+ FUNCTION(rb_gsl_vector,set_subvector)(argc-1, argv, v, other);
464
+ }
465
+
466
+ return obj;
467
+ }
468
+
469
+ static VALUE FUNCTION(rb_gsl_vector,set_all)(VALUE obj, VALUE xx)
470
+ {
471
+ GSL_TYPE(gsl_vector) *v = NULL;
472
+ BASE xnative = NUMCONV2(xx);
473
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
474
+ FUNCTION(gsl_vector,set_all)(v, xnative);
475
+ return obj;
476
+ }
477
+
478
+ VALUE FUNCTION(rb_gsl_vector,do_something)(VALUE obj, void (*func)(GSL_TYPE(gsl_vector)*))
479
+ {
480
+ GSL_TYPE(gsl_vector) *v = NULL;
481
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
482
+ (*func)(v);
483
+ return obj;
484
+ }
485
+
486
+ static VALUE FUNCTION(rb_gsl_vector,set_zero)(VALUE obj)
487
+ {
488
+ return FUNCTION(rb_gsl_vector,do_something)(obj, FUNCTION(gsl_vector,set_zero));
489
+ }
490
+
491
+ static VALUE FUNCTION(rb_gsl_vector,set_basis)(VALUE obj, VALUE ii)
492
+ {
493
+ GSL_TYPE(gsl_vector) *v = NULL;
494
+ CHECK_FIXNUM(ii);
495
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
496
+ FUNCTION(gsl_vector,set_basis)(v, (size_t) FIX2INT(ii));
497
+ return obj;
498
+ }
499
+
500
+ static VALUE FUNCTION(rb_gsl_vector,each)(VALUE obj)
501
+ {
502
+ GSL_TYPE(gsl_vector) *v = NULL;
503
+ size_t i;
504
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
505
+ for (i = 0; i < v->size; i++) rb_yield(C_TO_VALUE2(FUNCTION(gsl_vector,get)(v, i)));
506
+ return Qnil;
507
+ }
508
+
509
+ static VALUE FUNCTION(rb_gsl_vector,reverse_each)(VALUE obj)
510
+ {
511
+ GSL_TYPE(gsl_vector) *v = NULL;
512
+ size_t i;
513
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
514
+ for (i = v->size-1; i >= 0; i--) {
515
+ rb_yield(C_TO_VALUE2(FUNCTION(gsl_vector,get)(v, i)));
516
+ if (i == 0) break;
517
+ }
518
+ return Qnil;
519
+ }
520
+
521
+ static VALUE FUNCTION(rb_gsl_vector,each_index)(VALUE obj)
522
+ {
523
+ GSL_TYPE(gsl_vector) *v = NULL;
524
+ size_t i;
525
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
526
+ for (i = 0; i < v->size; i++) rb_yield(INT2FIX(i));
527
+ return Qnil;
528
+ }
529
+
530
+ static VALUE FUNCTION(rb_gsl_vector,reverse_each_index)(VALUE obj)
531
+ {
532
+ GSL_TYPE(gsl_vector) *v = NULL;
533
+ size_t i;
534
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
535
+ for (i = v->size-1; i >= 0; i--) {
536
+ rb_yield(INT2FIX(i));
537
+ if (i == 0) break;
538
+ }
539
+ return Qnil;
540
+ }
541
+
542
+ static VALUE FUNCTION(rb_gsl_vector,to_a)(VALUE obj)
543
+ {
544
+ GSL_TYPE(gsl_vector) *v = NULL;
545
+ size_t i;
546
+ VALUE ary;
547
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
548
+ ary = rb_ary_new2(v->size);
549
+ for (i = 0; i < v->size; i++)
550
+ rb_ary_store(ary, i, C_TO_VALUE2(FUNCTION(gsl_vector,get)(v, i)));
551
+ return ary;
552
+ }
553
+
554
+ static VALUE FUNCTION(rb_gsl_vector,reverse_bang)(VALUE obj)
555
+ {
556
+ GSL_TYPE(gsl_vector) *v = NULL;
557
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
558
+ FUNCTION(gsl_vector,reverse)(v);
559
+ return obj;
560
+ }
561
+
562
+ static VALUE FUNCTION(rb_gsl_vector,reverse)(VALUE obj)
563
+ {
564
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
565
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
566
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
567
+ if (vnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_int_alloc failed");
568
+ FUNCTION(gsl_vector,memcpy)(vnew, v);
569
+ FUNCTION(gsl_vector,reverse)(vnew);
570
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
571
+ }
572
+
573
+ static VALUE FUNCTION(rb_gsl_vector,max)(VALUE obj)
574
+ {
575
+ GSL_TYPE(gsl_vector) *v = NULL;
576
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
577
+ return C_TO_VALUE2(FUNCTION(gsl_vector,max)(v));
578
+ }
579
+
580
+ static VALUE FUNCTION(rb_gsl_vector,min)(VALUE obj)
581
+ {
582
+ GSL_TYPE(gsl_vector) *v = NULL;
583
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
584
+ return C_TO_VALUE2(FUNCTION(gsl_vector,min)(v));
585
+ }
586
+
587
+ static VALUE FUNCTION(rb_gsl_vector,minmax)(VALUE obj)
588
+ {
589
+ GSL_TYPE(gsl_vector) *v = NULL;
590
+ BASE min, max;
591
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
592
+ FUNCTION(gsl_vector,minmax)(v, &min, &max);
593
+ return rb_ary_new3(2, C_TO_VALUE2(min), C_TO_VALUE2(max));
594
+ }
595
+
596
+ static VALUE FUNCTION(rb_gsl_vector,maxmin)(VALUE obj)
597
+ {
598
+ GSL_TYPE(gsl_vector) *v = NULL;
599
+ BASE min, max;
600
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
601
+ FUNCTION(gsl_vector,minmax)(v, &min, &max);
602
+ return rb_ary_new3(2, C_TO_VALUE2(max), C_TO_VALUE2(min));
603
+ }
604
+
605
+ static VALUE FUNCTION(rb_gsl_vector,max_index)(VALUE obj)
606
+ {
607
+ GSL_TYPE(gsl_vector) *v = NULL;
608
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
609
+ return INT2FIX(FUNCTION(gsl_vector,max_index)(v));
610
+ }
611
+
612
+ static VALUE FUNCTION(rb_gsl_vector,min_index)(VALUE obj)
613
+ {
614
+ GSL_TYPE(gsl_vector) *v = NULL;
615
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
616
+ return INT2FIX(FUNCTION(gsl_vector,min_index)(v));
617
+ }
618
+
619
+ static VALUE FUNCTION(rb_gsl_vector,minmax_index)(VALUE obj)
620
+ {
621
+ GSL_TYPE(gsl_vector) *v = NULL;
622
+ size_t imin, imax;
623
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
624
+ FUNCTION(gsl_vector,minmax_index)(v, &imin, &imax);
625
+ return rb_ary_new3(2, INT2FIX(imin), INT2FIX(imax));
626
+ }
627
+
628
+ static VALUE FUNCTION(rb_gsl_vector,maxmin_index)(VALUE obj)
629
+ {
630
+ GSL_TYPE(gsl_vector) *v = NULL;
631
+ size_t imin, imax;
632
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
633
+ FUNCTION(gsl_vector,minmax_index)(v, &imin, &imax);
634
+ return rb_ary_new3(2, INT2FIX(imax), INT2FIX(imin));
635
+ }
636
+
637
+ static VALUE FUNCTION(rb_gsl_vector,isnull)(VALUE obj)
638
+ {
639
+ GSL_TYPE(gsl_vector) *v = NULL;
640
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
641
+ return INT2FIX(FUNCTION(gsl_vector,isnull)(v));
642
+ }
643
+
644
+ static VALUE FUNCTION(rb_gsl_vector,isnull2)(VALUE obj)
645
+ {
646
+ GSL_TYPE(gsl_vector) *v = NULL;
647
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
648
+ if (FUNCTION(gsl_vector,isnull)(v)) return Qtrue;
649
+ else return Qfalse;
650
+ }
651
+
652
+ static VALUE FUNCTION(rb_gsl_vector,trans)(VALUE obj)
653
+ {
654
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
655
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
656
+ vnew = FUNCTION(make_vector,clone)(v);
657
+ #ifdef BASE_DOUBLE
658
+ if (VECTOR_COL_P(obj))
659
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
660
+ else return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, vnew);
661
+ #elif defined(BASE_INT)
662
+ if (VECTOR_INT_ROW_P(obj))
663
+ return Data_Wrap_Struct(cgsl_vector_int_col, 0, gsl_vector_int_free, vnew);
664
+ else if (VECTOR_INT_COL_P(obj))
665
+ return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, vnew);
666
+ else rb_raise(rb_eTypeError,
667
+ "wrong type %s (Vector::Int or Vector::Int::Col expected)",
668
+ rb_class2name(CLASS_OF(obj)));
669
+ #endif
670
+ return Qnil;
671
+ }
672
+
673
+ static VALUE FUNCTION(rb_gsl_vector,trans_bang)(VALUE obj)
674
+ {
675
+ #ifdef BASE_DOUBLE
676
+ if (CLASS_OF(obj) == cgsl_vector) RBASIC(obj)->klass = cgsl_vector_col;
677
+ else if (CLASS_OF(obj) == cgsl_vector_col) RBASIC(obj)->klass = cgsl_vector;
678
+ else {
679
+ rb_raise(rb_eRuntimeError, "method trans! for %s is not permitted.",
680
+ rb_class2name(CLASS_OF(obj)));
681
+ }
682
+ #elif defined(BASE_INT)
683
+ if (CLASS_OF(obj) == cgsl_vector_int) RBASIC(obj)->klass = cgsl_vector_int_col;
684
+ else if (CLASS_OF(obj) == cgsl_vector_int_col) RBASIC(obj)->klass = cgsl_vector_int;
685
+ else {
686
+ rb_raise(rb_eRuntimeError, "method trans! for %s is not permitted.",
687
+ rb_class2name(CLASS_OF(obj)));
688
+ }
689
+ #endif
690
+ return obj;
691
+ }
692
+
693
+ static VALUE FUNCTION(rb_gsl_vector,uplus)(VALUE obj)
694
+ {
695
+ return obj;
696
+ }
697
+
698
+ EXTERN VALUE cgsl_poly;
699
+
700
+ VALUE FUNCTION(rb_gsl_vector,uminus)(VALUE obj)
701
+ {
702
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
703
+ size_t i;
704
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
705
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
706
+ for (i = 0; i < v->size; i++) {
707
+ FUNCTION(gsl_vector,set)(vnew, i, -FUNCTION(gsl_vector,get)(v, i));
708
+ }
709
+ if (CLASS_OF(obj) == GSL_TYPE(cgsl_poly))
710
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), vnew);
711
+ else
712
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
713
+ }
714
+
715
+ static VALUE FUNCTION(rb_gsl_vector,sum)(VALUE obj)
716
+ {
717
+ GSL_TYPE(gsl_vector) *v = NULL;
718
+ BASE sum = 0;
719
+ size_t i;
720
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
721
+ for (i = 0; i < v->size; i++) sum += FUNCTION(gsl_vector,get)(v, i);
722
+ return C_TO_VALUE2(sum);
723
+ }
724
+
725
+ /* Vector#sumsq is defined in blas1.c */
726
+ #ifdef BASE_INT
727
+ static VALUE FUNCTION(rb_gsl_vector,sumsq)(VALUE obj)
728
+ {
729
+ GSL_TYPE(gsl_vector) *v = NULL;
730
+ BASE sum = 0, x;
731
+ size_t i;
732
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
733
+ for (i = 0; i < v->size; i++) {
734
+ x = FUNCTION(gsl_vector,get)(v, i);
735
+ sum += x*x;
736
+ }
737
+ return C_TO_VALUE2(sum);
738
+ }
739
+ #endif
740
+
741
+ static VALUE FUNCTION(rb_gsl_vector,prod)(VALUE obj)
742
+ {
743
+ GSL_TYPE(gsl_vector) *v = NULL;
744
+ BASE x = 1;
745
+ size_t i;
746
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
747
+ for (i = 0; i < v->size; i++) x *= FUNCTION(gsl_vector,get)(v, i);
748
+ return C_TO_VALUE(x);
749
+ }
750
+
751
+ static VALUE FUNCTION(rb_gsl_vector,connect)(int argc, VALUE *argv, VALUE obj)
752
+ {
753
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
754
+ BASE *ptr = NULL;
755
+ size_t i, total = 0;
756
+ if (VEC_P(obj)) {
757
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
758
+ total += v->size;
759
+ }
760
+ for (i = 0; i < argc; i++) {
761
+ CHECK_VEC(argv[i]);
762
+ Data_Get_Struct(argv[i], GSL_TYPE(gsl_vector), v);
763
+ total += v->size;
764
+ }
765
+ vnew = FUNCTION(gsl_vector,alloc)(total);
766
+ ptr = vnew->data;
767
+ if (VEC_P(obj)) {
768
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
769
+ memcpy(ptr, v->data, sizeof(BASE)*v->size);
770
+ ptr += v->size;
771
+ }
772
+ for (i = 0; i < argc; i++) {
773
+ Data_Get_Struct(argv[i], GSL_TYPE(gsl_vector), v);
774
+ memcpy(ptr, v->data, sizeof(BASE)*v->size);
775
+ ptr += v->size;
776
+ }
777
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
778
+ }
779
+
780
+ GSL_TYPE(gsl_vector)* FUNCTION(mygsl_vector,up)(GSL_TYPE(gsl_vector) *p)
781
+ {
782
+ GSL_TYPE(gsl_vector) *pnew;
783
+ pnew = FUNCTION(gsl_vector,alloc)(p->size + 1);
784
+ FUNCTION(gsl_vector,set)(pnew, 0, 0);
785
+ memcpy(pnew->data+1, p->data, sizeof(BASE)*p->size);
786
+ return pnew;
787
+ }
788
+
789
+ void FUNCTION(mygsl_vector,up2)(GSL_TYPE(gsl_vector) *pnew, GSL_TYPE(gsl_vector) *p)
790
+ {
791
+ FUNCTION(gsl_vector,set_all)(pnew, 0);
792
+ memcpy(pnew->data+1, p->data, sizeof(BASE)*p->size);
793
+ }
794
+
795
+ GSL_TYPE(gsl_vector)* FUNCTION(mygsl_vector,down)(GSL_TYPE(gsl_vector) *p)
796
+ {
797
+ GSL_TYPE(gsl_vector) *pnew;
798
+ if (p->size <= 1) {
799
+ rb_raise(rb_eRangeError, "Length <= 1, cannot be shortened.");
800
+ }
801
+ pnew = FUNCTION(gsl_vector,alloc)(p->size - 1);
802
+ memcpy(pnew->data, p->data + 1, sizeof(BASE)*(p->size-1));
803
+ return pnew;
804
+ }
805
+
806
+ static VALUE FUNCTION(rb_gsl_vector,sgn)(VALUE obj)
807
+ {
808
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
809
+ BASE x;
810
+ size_t i;
811
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
812
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
813
+ for (i = 0; i < v->size; i++) {
814
+ x = FUNCTION(gsl_vector,get)(v, i);
815
+ FUNCTION(gsl_vector,set)(vnew, i, (BASE)(x>0 ? 1 : (x<0 ? -1 : 0)));
816
+ }
817
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
818
+ }
819
+
820
+ static VALUE FUNCTION(rb_gsl_vector,abs)(VALUE obj)
821
+ {
822
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
823
+ size_t i;
824
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
825
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
826
+ for (i = 0; i < v->size; i++) {
827
+ FUNCTION(gsl_vector,set)(vnew, i, (BASE) fabs(FUNCTION(gsl_vector,get)(v, i)));
828
+ }
829
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
830
+ }
831
+
832
+ static VALUE FUNCTION(rb_gsl_vector,square)(VALUE obj)
833
+ {
834
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
835
+ size_t i;
836
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
837
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
838
+ for (i = 0; i < v->size; i++) {
839
+ FUNCTION(gsl_vector,set)(vnew, i, gsl_pow_2(FUNCTION(gsl_vector,get)(v, i)));
840
+ }
841
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
842
+ }
843
+
844
+ static VALUE FUNCTION(rb_gsl_vector,sqrt)(VALUE obj)
845
+ {
846
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
847
+ size_t i;
848
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
849
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
850
+ for (i = 0; i < v->size; i++) {
851
+ FUNCTION(gsl_vector,set)(vnew, i, sqrt(FUNCTION(gsl_vector,get)(v, i)));
852
+ }
853
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
854
+ }
855
+
856
+ static VALUE FUNCTION(rb_gsl_vector,memcpy)(VALUE obj, VALUE dest, VALUE src)
857
+ {
858
+ GSL_TYPE(gsl_vector) *vdest = NULL, *vsrc = NULL;
859
+ Data_Get_Struct(dest, GSL_TYPE(gsl_vector), vdest);
860
+ Data_Get_Struct(src, GSL_TYPE(gsl_vector), vsrc);
861
+ FUNCTION(gsl_vector,memcpy)(vdest, vsrc);
862
+ return dest;
863
+ }
864
+
865
+ static VALUE FUNCTION(rb_gsl_vector,clone)(VALUE obj)
866
+ {
867
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
868
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
869
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
870
+ if (vnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
871
+ FUNCTION(gsl_vector,memcpy)(vnew, v);
872
+ if (!VEC_VIEW_P(obj))
873
+ return Data_Wrap_Struct(CLASS_OF(obj), 0, FUNCTION(gsl_vector,free), vnew);
874
+ else
875
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
876
+ }
877
+
878
+ /* singleton */
879
+ static VALUE FUNCTION(rb_gsl_vector,swap)(VALUE obj, VALUE vv, VALUE ww)
880
+ {
881
+ GSL_TYPE(gsl_vector) *v = NULL, *w = NULL;
882
+ Data_Get_Struct(vv, GSL_TYPE(gsl_vector), v);
883
+ Data_Get_Struct(ww, GSL_TYPE(gsl_vector), w);
884
+ FUNCTION(gsl_vector,swap)(v, w);
885
+ return obj;
886
+ }
887
+
888
+ static VALUE FUNCTION(rb_gsl_vector,swap_elements)(VALUE obj, VALUE i, VALUE j)
889
+ {
890
+ GSL_TYPE(gsl_vector) *v = NULL;
891
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
892
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
893
+ FUNCTION(gsl_vector,swap_elements)(v, FIX2INT(i), FIX2INT(j));
894
+ return obj;
895
+ }
896
+
897
+ static VALUE FUNCTION(rb_gsl_vector,fwrite)(VALUE obj, VALUE io)
898
+ {
899
+ GSL_TYPE(gsl_vector) *h = NULL;
900
+ FILE *f = NULL;
901
+ int status, flag = 0;
902
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), h);
903
+ f = rb_gsl_open_writefile(io, &flag);
904
+ status = FUNCTION(gsl_vector,fwrite)(f, h);
905
+ if (flag == 1) fclose(f);
906
+ return INT2FIX(status);
907
+ }
908
+
909
+ static VALUE FUNCTION(rb_gsl_vector,fread)(VALUE obj, VALUE io)
910
+ {
911
+ GSL_TYPE(gsl_vector) *h = NULL;
912
+ FILE *f = NULL;
913
+ int status, flag = 0;
914
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), h);
915
+ f = rb_gsl_open_readfile(io, &flag);
916
+ status = FUNCTION(gsl_vector,fread)(f, h);
917
+ if (flag == 1) fclose(f);
918
+ return INT2FIX(status);
919
+ }
920
+
921
+ static VALUE FUNCTION(rb_gsl_vector,fprintf)(int argc, VALUE *argv, VALUE obj)
922
+ {
923
+ GSL_TYPE(gsl_vector) *h = NULL;
924
+ FILE *fp = NULL;
925
+ int status, flag = 0;
926
+ if (argc != 1 && argc != 2)
927
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
928
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), h);
929
+ fp = rb_gsl_open_writefile(argv[0], &flag);
930
+ if (argc == 2) {
931
+ if (TYPE(argv[1]) == T_STRING)
932
+ status = FUNCTION(gsl_vector,fprintf)(fp, h, STR2CSTR(argv[1]));
933
+ else
934
+ rb_raise(rb_eTypeError, "argv 2 String expected");
935
+ } else {
936
+ status = FUNCTION(gsl_vector,fprintf)(fp, h, "%g");
937
+ }
938
+ if (flag == 1) fclose(fp);
939
+ return INT2FIX(status);
940
+ }
941
+
942
+ static VALUE FUNCTION(rb_gsl_vector,printf)(int argc, VALUE *argv, VALUE obj)
943
+ {
944
+ GSL_TYPE(gsl_vector) *h = NULL;
945
+ int status;
946
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), h);
947
+ if (argc == 1) {
948
+ if (TYPE(argv[0]) != T_STRING)
949
+ rb_raise(rb_eTypeError, "String expected");
950
+ else
951
+ status = FUNCTION(gsl_vector,fprintf)(stdout, h, STR2CSTR(argv[0]));
952
+ } else {
953
+ status = FUNCTION(gsl_vector,fprintf)(stdout, h, "%g");
954
+ }
955
+ return INT2FIX(status);
956
+ }
957
+
958
+ static VALUE FUNCTION(rb_gsl_vector,fscanf)(VALUE obj, VALUE io)
959
+ {
960
+ GSL_TYPE(gsl_vector) *h = NULL;
961
+ FILE *fp = NULL;
962
+ int status, flag = 0;
963
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), h);
964
+ fp = rb_gsl_open_readfile(io, &flag);
965
+ status = FUNCTION(gsl_vector,fscanf)(fp, h);
966
+ if (flag == 1) fclose(fp);
967
+ return INT2FIX(status);
968
+ }
969
+
970
+ /* 2.Aug.2004 */
971
+ VALUE FUNCTION(rb_gsl_vector,inner_product)(int argc, VALUE *argv, VALUE obj)
972
+ {
973
+ GSL_TYPE(gsl_vector) *v = NULL, *v2 = NULL;
974
+ BASE prod = 0;
975
+ #ifndef BASE_DOUBLE
976
+ size_t i;
977
+ #endif
978
+ switch (TYPE(obj)) {
979
+ case T_MODULE: case T_CLASS: case T_OBJECT:
980
+ if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
981
+ argc);
982
+ CHECK_VEC(argv[0]);
983
+ CHECK_VEC(argv[1]);
984
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v);
985
+ Data_Get_Struct(argv[1], GSL_TYPE(gsl_vector), v2);
986
+ break;
987
+ default:
988
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
989
+ argc);
990
+ CHECK_VEC(argv[0]);
991
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
992
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v2);
993
+ break;
994
+ }
995
+ if (v->size != v2->size) rb_raise(rb_eRangeError, "vector lengths are different.");
996
+ #ifdef BASE_DOUBLE
997
+ gsl_blas_ddot(v, v2, &prod);
998
+ #else
999
+ for (i = 0; i < v->size; i++) {
1000
+ prod += FUNCTION(gsl_vector,get)(v, i)*FUNCTION(gsl_vector,get)(v2, i);
1001
+ }
1002
+ #endif
1003
+ return C_TO_VALUE2(prod);
1004
+ }
1005
+
1006
+ int FUNCTION(rbgsl_vector,equal)(const GSL_TYPE(gsl_vector) *v1, const GSL_TYPE(gsl_vector) *v2, double eps)
1007
+ {
1008
+ size_t i;
1009
+ BASE x, y;
1010
+ if (v1->size != v2->size) return 0;
1011
+ for (i = 0; i < v2->size; i++) {
1012
+ x = FUNCTION(gsl_vector,get)(v1, i);
1013
+ y = FUNCTION(gsl_vector,get)(v2, i);
1014
+ if (fabs(x - y) > eps) return 0;
1015
+ }
1016
+ return 1;
1017
+ }
1018
+
1019
+ #ifdef HAVE_TENSOR_TENSOR_H
1020
+ EXTERN VALUE cgsl_tensor, cgsl_tensor_int;
1021
+ VALUE rb_gsl_tensor_equal(int argc, VALUE *argv, VALUE obj);
1022
+ VALUE rb_gsl_tensor_int_equal(int argc, VALUE *argv, VALUE obj);
1023
+ #ifdef BASE_DOUBLE
1024
+ #define TEN_P(x) TENSOR_P(x)
1025
+ #else
1026
+ #define TEN_P(x) TENSOR_INT_P(x)
1027
+ #endif
1028
+ #endif
1029
+
1030
+ static VALUE FUNCTION(rb_gsl_vector,equal)(int argc, VALUE *argv, VALUE obj)
1031
+ {
1032
+ GSL_TYPE(gsl_vector) *v1, *v2;
1033
+ VALUE other;
1034
+ size_t i;
1035
+ double eps = 1e-10;
1036
+ double x;
1037
+ switch (argc) {
1038
+ case 2:
1039
+ other = argv[0];
1040
+ eps = NUM2DBL(argv[1]);
1041
+ break;
1042
+ case 1:
1043
+ other = argv[0];
1044
+ break;
1045
+ default:
1046
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
1047
+ break;
1048
+ }
1049
+ #ifdef HAVE_TENSOR_TENSOR_H
1050
+ if (TEN_P(other)) {
1051
+ return FUNCTION(rb_gsl_tensor,equal)(argc, argv, obj);
1052
+ }
1053
+ #endif
1054
+ switch (TYPE(other)) {
1055
+ case T_FIXNUM:
1056
+ case T_FLOAT:
1057
+ x = NUM2DBL(other);
1058
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v1);
1059
+ for (i = 0; i < v1->size; i++)
1060
+ if (fabs(x-FUNCTION(gsl_vector,get)(v1, i)) > eps) return Qfalse;
1061
+ return Qtrue;
1062
+ break;
1063
+ default:
1064
+ CHECK_VEC(other);
1065
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v1);
1066
+ Data_Get_Struct(other, GSL_TYPE(gsl_vector), v2);
1067
+ if (FUNCTION(rbgsl_vector,equal)(v1, v2, eps)) return Qtrue;
1068
+ else return Qfalse;
1069
+ break;
1070
+ }
1071
+ return Qnil;
1072
+ }
1073
+
1074
+ #ifdef HAVE_TENSOR_TENSOR_H
1075
+ #ifdef TEN_P
1076
+ #undef TEN_P
1077
+ #endif
1078
+ #endif
1079
+
1080
+ static VALUE FUNCTION(rb_gsl_vector,to_poly)(VALUE obj)
1081
+ {
1082
+ GSL_TYPE(gsl_vector) *v = NULL;
1083
+ GSL_TYPE(gsl_poly) *p = NULL;
1084
+ if (CLASS_OF(obj) == GSL_TYPE(cgsl_poly)) return obj;
1085
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1086
+ p = FUNCTION(make_vector,clone)(v);
1087
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_poly), 0, FUNCTION(gsl_vector,free), p);
1088
+ }
1089
+
1090
+ static VALUE FUNCTION(rb_gsl_vector,graph)(int argc, VALUE *argv, VALUE obj)
1091
+ {
1092
+ #ifdef HAVE_GNU_GRAPH
1093
+ GSL_TYPE(gsl_vector) *x = NULL, *y = NULL;
1094
+ FILE *fp = NULL;
1095
+ size_t i;
1096
+ char command[1024];
1097
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), y);
1098
+ switch (argc) {
1099
+ case 0:
1100
+ strcpy(command, "graph -T X -g 3");
1101
+ break;
1102
+ case 1:
1103
+ if (TYPE(argv[0]) == T_STRING) {
1104
+ make_graphcommand(command, argv[0]);
1105
+ } else if (VEC_P(argv[0])) {
1106
+ strcpy(command, "graph -T X -g 3");
1107
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), x);
1108
+ } else {
1109
+ }
1110
+ break;
1111
+ case 2:
1112
+ if (TYPE(argv[1]) == T_STRING) {
1113
+ make_graphcommand(command, argv[1]);
1114
+ if (VEC_P(argv[0])) {
1115
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), x);
1116
+ } else {
1117
+ rb_raise(rb_eTypeError, "argv[0] wrong type %s (String or Vector expected)",
1118
+ rb_class2name(CLASS_OF(argv[0])));
1119
+ }
1120
+ } else {
1121
+ rb_raise(rb_eTypeError, "argv[1] wrong type %s (String or Vector expected)",
1122
+ rb_class2name(CLASS_OF(argv[1])));
1123
+ }
1124
+ break;
1125
+ default:
1126
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
1127
+ break;
1128
+ }
1129
+ if (y == NULL) rb_raise(rb_eRuntimeError, "ydata not given");
1130
+ fp = popen(command, "w");
1131
+ for (i = 0; i < y->size; i++) {
1132
+ if (x == NULL)
1133
+ fprintf(fp, "%d %e\n", (int) i, (double) FUNCTION(gsl_vector,get)(y, i));
1134
+ else
1135
+ fprintf(fp, "%e %e\n", (double) FUNCTION(gsl_vector,get)(x, i), (double) FUNCTION(gsl_vector,get)(y, i));
1136
+ }
1137
+ fflush(fp);
1138
+ pclose(fp);
1139
+ fp = NULL;
1140
+ return Qtrue;
1141
+ #else
1142
+ rb_raise(rb_eNoMethodError, "not implemented");
1143
+ return Qfalse;
1144
+ #endif
1145
+ }
1146
+
1147
+ static VALUE FUNCTION(rb_gsl_vector,graph_step)(int argc, VALUE *argv, VALUE obj)
1148
+ {
1149
+ #ifdef HAVE_GNU_GRAPH
1150
+ GSL_TYPE(gsl_vector) *x = NULL, *y = NULL;
1151
+ FILE *fp = NULL;
1152
+ size_t i;
1153
+ char command[1024];
1154
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), y);
1155
+ switch (argc) {
1156
+ case 0:
1157
+ strcpy(command, "graph -T X -g 3");
1158
+ break;
1159
+ case 1:
1160
+ if (TYPE(argv[0]) == T_STRING) {
1161
+ make_graphcommand(command, argv[0]);
1162
+ } else if (VECTOR_P(argv[0])) {
1163
+ strcpy(command, "graph -T X -g 3");
1164
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), x);
1165
+ } else {
1166
+ }
1167
+ break;
1168
+ case 2:
1169
+ if (TYPE(argv[1]) == T_STRING) {
1170
+ make_graphcommand(command, argv[1]);
1171
+ if (VEC_P(argv[0])) {
1172
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), x);
1173
+ } else {
1174
+ rb_raise(rb_eTypeError, "argv[0] wrong type %s (String or Vector expected)",
1175
+ rb_class2name(CLASS_OF(argv[0])));
1176
+ }
1177
+ } else {
1178
+ rb_raise(rb_eTypeError, "argv[1] wrong type %s (String or Vector expected)",
1179
+ rb_class2name(CLASS_OF(argv[1])));
1180
+ }
1181
+ break;
1182
+ default:
1183
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
1184
+ break;
1185
+ }
1186
+ if (y == NULL) rb_raise(rb_eRuntimeError, "ydata not given");
1187
+ fp = popen(command, "w");
1188
+ for (i = 0; i < y->size; i++) {
1189
+ if (x == NULL) {
1190
+ fprintf(fp, "%d %e\n%d %e\n", (int) i, (double) FUNCTION(gsl_vector,get)(y, i),
1191
+ (int) (i+1), (double) FUNCTION(gsl_vector,get)(y, i));
1192
+ } else {
1193
+ if (i != y->size-1)
1194
+ fprintf(fp, "%e %e\n%e %e\n", (double) FUNCTION(gsl_vector,get)(x, i),
1195
+ (double) FUNCTION(gsl_vector,get)(y, i),
1196
+ (double) FUNCTION(gsl_vector,get)(x, i+1),
1197
+ (double) FUNCTION(gsl_vector,get)(y, i));
1198
+ else
1199
+ fprintf(fp, "%e %e\n%e %e",
1200
+ (double) FUNCTION(gsl_vector,get)(x, i),
1201
+ (double) FUNCTION(gsl_vector,get)(y, i),
1202
+ 2.0*FUNCTION(gsl_vector,get)(x, i)-FUNCTION(gsl_vector,get)(x, i-1),
1203
+ (double) FUNCTION(gsl_vector,get)(y, i));
1204
+ }
1205
+ }
1206
+ fflush(fp);
1207
+ pclose(fp);
1208
+ fp = NULL;
1209
+ return Qtrue;
1210
+ #else
1211
+ rb_raise(rb_eNoMethodError, "not implemented");
1212
+ return Qfalse;
1213
+ #endif
1214
+ }
1215
+
1216
+ static VALUE FUNCTION(rb_gsl_vector,plot)(int argc, VALUE *argv, VALUE obj)
1217
+ {
1218
+ GSL_TYPE(gsl_vector) *x = NULL, *y = NULL;
1219
+ FILE *fp = NULL;
1220
+ size_t i;
1221
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), y);
1222
+ fp = popen("gnuplot -persist", "w");
1223
+ switch (argc) {
1224
+ case 0:
1225
+ fprintf(fp, "plot '-'\n");
1226
+ break;
1227
+ case 1:
1228
+ if (TYPE(argv[0]) == T_STRING) {
1229
+ fprintf(fp, "plot '-' %s\n", STR2CSTR(argv[0]));
1230
+ } else if (VEC_P(argv[0])) {
1231
+ fprintf(fp, "plot '-'\n");
1232
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), x);
1233
+ } else {
1234
+ rb_raise(rb_eTypeError, "wrong argument type %s (String or Vector expected)",
1235
+ rb_class2name(CLASS_OF(argv[0])));
1236
+ }
1237
+ break;
1238
+ case 2:
1239
+ if (TYPE(argv[1]) == T_STRING)
1240
+ fprintf(fp, "plot '-' %s\n", STR2CSTR(argv[1]));
1241
+ if (VEC_P(argv[0]))
1242
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), x);
1243
+ break;
1244
+ default:
1245
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
1246
+ break;
1247
+ }
1248
+ if (y == NULL) rb_raise(rb_eRuntimeError, "ydata not given");
1249
+ for (i = 0; i < y->size; i++) {
1250
+ if (x == NULL)
1251
+ fprintf(fp, "%d %e\n", (int) i, (double) FUNCTION(gsl_vector,get)(y, i));
1252
+ else
1253
+ fprintf(fp, "%e %e\n", (double) FUNCTION(gsl_vector,get)(x, i),
1254
+ (double) FUNCTION(gsl_vector,get)(y, i));
1255
+ }
1256
+ fprintf(fp, "e\n");
1257
+ fflush(fp);
1258
+ pclose(fp);
1259
+ fp = NULL;
1260
+ return Qtrue;
1261
+ }
1262
+
1263
+ void FUNCTION(gsl_vector,print)(const GSL_TYPE(gsl_vector) *v, VALUE klass)
1264
+ {
1265
+ size_t i;
1266
+ printf("[ ");
1267
+ if (klass == cgsl_vector_col || klass == cgsl_vector_col_view
1268
+ || klass == cgsl_vector_col_view_ro
1269
+ || klass == cgsl_vector_int_col || klass == cgsl_vector_int_col_view
1270
+ || klass == cgsl_vector_int_col_view_ro) {
1271
+ printf(PRINTF_FORMAT, FUNCTION(gsl_vector,get)(v, 0));
1272
+ for (i = 1; i < v->size; i++) {
1273
+ printf(PRINTF_FORMAT, FUNCTION(gsl_vector,get)(v, i));
1274
+ if (i != v->size-1) printf("\n");
1275
+ }
1276
+ } else {
1277
+ for (i = 0; i < v->size; i++) printf(PRINTF_FORMAT, FUNCTION(gsl_vector,get)(v, i));
1278
+ }
1279
+ printf("]\n");
1280
+ }
1281
+
1282
+ VALUE FUNCTION(rb_gsl_vector,print)(VALUE obj)
1283
+ {
1284
+ GSL_TYPE(gsl_vector) *v = NULL;
1285
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1286
+ FUNCTION(gsl_vector,print)(v, CLASS_OF(obj));
1287
+ return Qnil;
1288
+ }
1289
+
1290
+ #ifdef BASE_DOUBLE
1291
+ #define SHOW_ELM 6
1292
+ #else
1293
+ #define SHOW_ELM 15
1294
+ #endif
1295
+
1296
+ VALUE FUNCTION(rb_gsl_vector,to_s)(VALUE obj)
1297
+ {
1298
+ GSL_TYPE(gsl_vector) *v = NULL;
1299
+ char buf[32], format[32], format2[32];
1300
+ size_t i;
1301
+ VALUE str;
1302
+ BASE x;
1303
+ int dig = 8;
1304
+ #ifdef BASE_INT
1305
+ BASE min;
1306
+ BASE max;
1307
+ dig = 1;
1308
+ #endif
1309
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1310
+ if (v->size == 0) return rb_str_new2("[ ]");
1311
+ str = rb_str_new2("[ ");
1312
+ if (VEC_COL_P(obj)) {
1313
+ #ifdef BASE_INT
1314
+ min = FUNCTION(gsl_vector,min)(v);
1315
+ max = gsl_vector_int_max(v);
1316
+ dig = (int) GSL_MAX(fabs(max),fabs(min));
1317
+ if (dig > 0) dig = ceil(log10(dig+1e-10));
1318
+ else dig = 1;
1319
+ if (min < 0) dig += 1;
1320
+ sprintf(format, "%%%dd ", (int) dig);
1321
+ strcpy(format2, format);
1322
+ #else
1323
+ strcpy(format, PRINTF_FORMAT);
1324
+ strcpy(format2, " "PRINTF_FORMAT);
1325
+ #endif
1326
+ for (i = 0; i < v->size; i++) {
1327
+ if (i != 0) {
1328
+ strcpy(buf, " ");
1329
+ rb_str_cat(str, buf, strlen(buf));
1330
+ }
1331
+ x = FUNCTION(gsl_vector,get)(v, i);
1332
+ if (x < 0) sprintf(buf, format, x);
1333
+ else sprintf(buf, format2, x);
1334
+ if (i != v->size-1) strcat(buf, "\n");
1335
+ rb_str_cat(str, buf, strlen(buf));
1336
+ if (i >= 20 && i != v->size-1) {
1337
+ strcpy(buf, " ...");
1338
+ rb_str_cat(str, buf, strlen(buf));
1339
+ break;
1340
+ }
1341
+ }
1342
+ } else {
1343
+ sprintf(buf, PRINTF_FORMAT, FUNCTION(gsl_vector,get)(v, 0));
1344
+ rb_str_cat(str, buf, strlen(buf));
1345
+ for (i = 1; i < v->size; i++) {
1346
+ sprintf(buf, PRINTF_FORMAT, FUNCTION(gsl_vector,get)(v, i));
1347
+ rb_str_cat(str, buf, strlen(buf));
1348
+ if (i >= (55/dig) && i != v->size-1) {
1349
+ strcpy(buf, "... ");
1350
+ rb_str_cat(str, buf, strlen(buf));
1351
+ break;
1352
+ }
1353
+ }
1354
+ }
1355
+ sprintf(buf, "]");
1356
+ rb_str_cat(str, buf, strlen(buf));
1357
+ return str;
1358
+ }
1359
+ #undef SHOW_ELM
1360
+
1361
+ static VALUE FUNCTION(rb_gsl_vector,inspect)(VALUE obj)
1362
+ {
1363
+ VALUE str;
1364
+ char buf[64];
1365
+ sprintf(buf, "%s\n", rb_class2name(CLASS_OF(obj)));
1366
+ str = rb_str_new2(buf);
1367
+ return rb_str_concat(str, FUNCTION(rb_gsl_vector,to_s)(obj));
1368
+ }
1369
+
1370
+ static VALUE FUNCTION(rb_gsl_vector,subvector)(int argc, VALUE *argv, VALUE obj)
1371
+ {
1372
+ GSL_TYPE(gsl_vector) *v = NULL;
1373
+ QUALIFIED_VIEW(gsl_vector,view) *vv = NULL;
1374
+ size_t offset, stride, n;
1375
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1376
+ parse_subvector_args(argc, argv, v->size, &offset, &stride, &n);
1377
+ vv = ALLOC(QUALIFIED_VIEW(gsl_vector,view));
1378
+ *vv = FUNCTION(gsl_vector,subvector_with_stride)(v, offset, stride, n);
1379
+ if (VEC_COL_P(obj))
1380
+ return Data_Wrap_Struct(QUALIFIED_VIEW(cgsl_vector,col_view), 0, free, vv);
1381
+ else
1382
+ return Data_Wrap_Struct(QUALIFIED_VIEW(cgsl_vector,view), 0, free, vv);
1383
+ }
1384
+
1385
+ static VALUE FUNCTION(rb_gsl_vector,subvector_with_stride)(int argc, VALUE *argv, VALUE obj)
1386
+ {
1387
+ GSL_TYPE(gsl_vector) *v = NULL;
1388
+ QUALIFIED_VIEW(gsl_vector,view) *vv = NULL;
1389
+ int offset = 0, step, length;
1390
+ size_t stride = 1, n;
1391
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1392
+ switch (argc) {
1393
+ case 1:
1394
+ CHECK_FIXNUM(argv[0]);
1395
+ step = FIX2INT(argv[0]);
1396
+ if(step == 0) {
1397
+ rb_raise(rb_eArgError, "stride must be non-zero");
1398
+ }
1399
+ stride = (size_t)step;
1400
+ //n = v->size/stride;
1401
+ n = (v->size-1)/stride + 1;
1402
+ break;
1403
+ case 2:
1404
+ CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
1405
+ offset = FIX2INT(argv[0]);
1406
+ step = FIX2INT(argv[1]);
1407
+ if(offset < 0) {
1408
+ offset += v->size;
1409
+ if(offset < 0) {
1410
+ rb_raise(rb_eRangeError, "offset %d out of range", offset - (int)v->size);
1411
+ }
1412
+ } else if(offset >= v->size) {
1413
+ rb_raise(rb_eRangeError, "offset %d out of range", offset);
1414
+ }
1415
+ if(step == 0) {
1416
+ rb_raise(rb_eArgError, "stride must be non-zero");
1417
+ }
1418
+ stride = (size_t)step;
1419
+ //n = (v->size-(size_t)offset)/stride;
1420
+ n = (v->size-(size_t)offset-1)/stride + 1;
1421
+ break;
1422
+ case 3:
1423
+ CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]); CHECK_FIXNUM(argv[2]);
1424
+ offset = FIX2INT(argv[0]);
1425
+ step = FIX2INT(argv[1]);
1426
+ length = FIX2INT(argv[2]);
1427
+ if(offset < 0) {
1428
+ offset += v->size;
1429
+ if(offset < 0) {
1430
+ rb_raise(rb_eRangeError, "offset %d out of range", offset - (int)v->size);
1431
+ }
1432
+ }
1433
+ if(step == 0) {
1434
+ rb_raise(rb_eArgError, "stride must be non-zero");
1435
+ }
1436
+ if(length < 0) {
1437
+ rb_raise(rb_eArgError, "length must be non-negative");
1438
+ }
1439
+ stride = (size_t)step;
1440
+ n = (size_t)length;
1441
+ break;
1442
+ default:
1443
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 - 3)", argc);
1444
+ break;
1445
+ }
1446
+ vv = ALLOC(QUALIFIED_VIEW(gsl_vector,view));
1447
+ *vv = FUNCTION(gsl_vector,subvector_with_stride)(v, (size_t)offset, stride, n);
1448
+ if (VEC_COL_P(obj))
1449
+ return Data_Wrap_Struct(QUALIFIED_VIEW(cgsl_vector,col_view), 0, free, vv);
1450
+ else
1451
+ return Data_Wrap_Struct(QUALIFIED_VIEW(cgsl_vector,view), 0, free, vv);
1452
+ }
1453
+
1454
+ static VALUE FUNCTION(rb_gsl_vector,matrix_view)(int argc, VALUE *argv, VALUE obj)
1455
+ {
1456
+ GSL_TYPE(gsl_vector) *v = NULL;
1457
+ QUALIFIED_VIEW(gsl_matrix,view) *mv = NULL;
1458
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1459
+ switch (argc) {
1460
+ case 2:
1461
+ mv = ALLOC(QUALIFIED_VIEW(gsl_matrix,view));
1462
+ *mv = FUNCTION(gsl_matrix,view_vector)(v, FIX2INT(argv[0]), FIX2INT(argv[1]));
1463
+ break;
1464
+ case 3:
1465
+ mv = ALLOC(QUALIFIED_VIEW(gsl_matrix,view));
1466
+ *mv = FUNCTION(gsl_matrix,view_vector_with_tda)(v, FIX2INT(argv[0]), FIX2INT(argv[1]),
1467
+ FIX2INT(argv[2]));
1468
+ break;
1469
+ default:
1470
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
1471
+ break;
1472
+ }
1473
+ return Data_Wrap_Struct(QUALIFIED_VIEW(cgsl_matrix,view), 0, free, mv);
1474
+ }
1475
+
1476
+ static VALUE FUNCTION(rb_gsl_vector,matrix_view_with_tda)(VALUE obj, VALUE nn1, VALUE nn2,
1477
+ VALUE tda)
1478
+ {
1479
+ GSL_TYPE(gsl_vector) *v = NULL;
1480
+ QUALIFIED_VIEW(gsl_matrix,view) *mv = NULL;
1481
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1482
+ mv = ALLOC(QUALIFIED_VIEW(gsl_matrix,view));
1483
+ *mv = FUNCTION(gsl_matrix,view_vector_with_tda)(v, FIX2INT(nn1), FIX2INT(nn2), FIX2INT(tda));
1484
+ return Data_Wrap_Struct(QUALIFIED_VIEW(cgsl_matrix,view), 0, free, mv);
1485
+ }
1486
+
1487
+ void FUNCTION(mygsl_vector,shift)(GSL_TYPE(gsl_vector) *p, size_t n)
1488
+ {
1489
+ size_t i;
1490
+ for (i = n; i >= 0; i--) {
1491
+ FUNCTION(gsl_vector,set)(p, i+1, FUNCTION(gsl_vector,get)(p, i));
1492
+ if (i == 0) break;
1493
+ }
1494
+ FUNCTION(gsl_vector,set)(p, 0, 0);
1495
+ }
1496
+
1497
+ void FUNCTION(mygsl_vector,shift_scale2)(GSL_TYPE(gsl_vector) *p, size_t n)
1498
+ {
1499
+ size_t i;
1500
+ for (i = n; i >= 0; i--) {
1501
+ FUNCTION(gsl_vector,set)(p, i+1, 2*FUNCTION(gsl_vector,get)(p, i));
1502
+ if (i == 0) break;
1503
+ }
1504
+ FUNCTION(gsl_vector,set)(p, 0, 0);
1505
+ }
1506
+
1507
+ GSL_TYPE(gsl_vector)* FUNCTION(make_vector,clone)(const GSL_TYPE(gsl_vector) *v)
1508
+ {
1509
+ GSL_TYPE(gsl_vector) *vnew = NULL;
1510
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
1511
+ if (v->stride == 1) memcpy(vnew->data, v->data, sizeof(BASE)*v->size);
1512
+ else FUNCTION(gsl_vector,memcpy)(vnew, v);
1513
+ return vnew;
1514
+ }
1515
+
1516
+ VALUE FUNCTION(rb_gsl_vector,scale)(VALUE obj, VALUE x)
1517
+ {
1518
+ GSL_TYPE(gsl_vector) *v, *vnew;
1519
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1520
+ vnew = FUNCTION(make_vector,clone)(v);
1521
+ FUNCTION(gsl_vector,scale)(vnew, NUMCONV(x));
1522
+ // return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
1523
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
1524
+ }
1525
+
1526
+ VALUE FUNCTION(rb_gsl_vector,scale_bang)(VALUE obj, VALUE x)
1527
+ {
1528
+ GSL_TYPE(gsl_vector) *v = NULL;
1529
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1530
+ FUNCTION(gsl_vector,scale)(v, NUMCONV(x));
1531
+ return obj;
1532
+ }
1533
+
1534
+ VALUE FUNCTION(rb_gsl_vector,add_constant)(VALUE obj, VALUE x)
1535
+ {
1536
+ GSL_TYPE(gsl_vector) *v, *vnew;
1537
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1538
+ vnew = FUNCTION(make_vector,clone)(v);
1539
+ FUNCTION(gsl_vector,add_constant)(vnew, NUMCONV(x));
1540
+ // return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
1541
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
1542
+ }
1543
+
1544
+ VALUE FUNCTION(rb_gsl_vector,add_constant_bang)(VALUE obj, VALUE x)
1545
+ {
1546
+ GSL_TYPE(gsl_vector) *v = NULL;
1547
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1548
+ FUNCTION(gsl_vector,add_constant)(v, NUMCONV(x));
1549
+ return obj;
1550
+ }
1551
+
1552
+ QUALIFIED_VIEW(gsl_vector,view)* FUNCTION(rb_gsl_make_vector,view)(BASE *data, size_t size, size_t stride)
1553
+ {
1554
+ QUALIFIED_VIEW(gsl_vector,view) *v = NULL;
1555
+ v = ALLOC(QUALIFIED_VIEW(gsl_vector,view));
1556
+ v->vector.size = size;
1557
+ v->vector.stride = stride;
1558
+ v->vector.owner = 0;
1559
+ v->vector.data = data;
1560
+ return v;
1561
+ }
1562
+
1563
+ #ifdef HAVE_TENSOR_TENSOR_H
1564
+ #include "rb_gsl_tensor.h"
1565
+ static VALUE FUNCTION(rb_gsl_vector,to_tensor)(int argc, VALUE *argv, VALUE obj)
1566
+ {
1567
+ GSL_TYPE(gsl_vector) *v = NULL;
1568
+ GSL_TYPE(rbgsl_tensor) *t;
1569
+ unsigned int rank;
1570
+ size_t dim;
1571
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1572
+ switch (argc) {
1573
+ case 0:
1574
+ rank = 1;
1575
+ dim = v->size;
1576
+ break;
1577
+ case 2:
1578
+ rank = FIX2UINT(argv[0]);
1579
+ dim = FIX2UINT(argv[1]);
1580
+ break;
1581
+ default:
1582
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 2)", argc);
1583
+ break;
1584
+ }
1585
+ t = FUNCTION(rbgsl_tensor,alloc)(rank, dim);
1586
+ memcpy(t->tensor->data, v->data, sizeof(BASE)*v->size);
1587
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_tensor), 0, FUNCTION(rbgsl_tensor,free), t);
1588
+ }
1589
+ #endif
1590
+
1591
+ #ifdef BASE_DOUBLE
1592
+ #define PRINTF_FORMAT2 "%g "
1593
+ #else
1594
+ #define PRINTF_FORMAT2 "%d "
1595
+ #endif
1596
+ static VALUE FUNCTION(rb_gsl_vector,to_gplot)(int argc, VALUE *argv, VALUE obj)
1597
+ {
1598
+ char buf[1024] = "";
1599
+ size_t i, j, len = 0, nv, istart;
1600
+ VALUE str, tmp;
1601
+ GSL_TYPE(gsl_vector) *v, **vp;
1602
+ switch (TYPE(obj)) {
1603
+ case T_MODULE: case T_CLASS: case T_OBJECT:
1604
+ if (argc < 1) rb_raise(rb_eArgError, "no vectors given");
1605
+ if (TYPE(argv[0]) == T_ARRAY) nv = RARRAY_LEN(argv[0]);
1606
+ else nv = argc;
1607
+ vp = (GSL_TYPE(gsl_vector)**) ALLOC_N(GSL_TYPE(gsl_vector)*, nv);
1608
+ istart = 0;
1609
+ break;
1610
+ default:
1611
+ CHECK_VEC(obj);
1612
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1613
+ if (argc >= 1 && TYPE(argv[0]) == T_ARRAY) nv = 1 + RARRAY_LEN(argv[0]);
1614
+ else nv = argc + 1;
1615
+ vp = (GSL_TYPE(gsl_vector)**) ALLOC_N(GSL_TYPE(gsl_vector)*, nv);
1616
+ vp[0] = v; len = v->size;
1617
+ istart = 1;
1618
+ break;
1619
+ }
1620
+ for (i = 0; i < argc; i++) {
1621
+ if (TYPE(argv[0]) == T_ARRAY) tmp = rb_ary_entry(argv[0], i);
1622
+ else tmp = argv[i];
1623
+ CHECK_VEC(tmp);
1624
+ Data_Get_Struct(tmp, GSL_TYPE(gsl_vector), v);
1625
+ if (len == 0) len = v->size;
1626
+ if (len != v->size)
1627
+ rb_raise(rb_eRuntimeError, "vectors must have equal lengths");
1628
+ vp[i+istart] = v;
1629
+ }
1630
+ str = rb_str_new2(buf);
1631
+ for (j = 0; j < len; j++) {
1632
+ for (i = 0; i < nv; i++) {
1633
+ sprintf(buf, PRINTF_FORMAT2, FUNCTION(gsl_vector,get)(vp[i], j));
1634
+ rb_str_buf_cat(str, buf, strlen(buf));
1635
+ }
1636
+ rb_str_buf_cat2(str, "\n");
1637
+ }
1638
+ rb_str_buf_cat2(str, "\n");
1639
+ free((GSL_TYPE(gsl_vector)**)vp);
1640
+ return str;
1641
+ }
1642
+ #undef PRINTF_FORMAT2
1643
+
1644
+ static VALUE FUNCTION(rb_gsl_vector,to_m_diagonal)(VALUE obj)
1645
+ {
1646
+ GSL_TYPE(gsl_vector) *v = NULL;
1647
+ GSL_TYPE(gsl_matrix) *m = NULL;
1648
+ size_t i;
1649
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1650
+ m = FUNCTION(gsl_matrix,calloc)(v->size, v->size);
1651
+ for (i = 0; i < v->size; i++)
1652
+ FUNCTION(gsl_matrix,set)(m, i, i, FUNCTION(gsl_vector,get)(v, i));
1653
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_matrix), 0, FUNCTION(gsl_matrix,free), m);
1654
+ }
1655
+
1656
+ static VALUE FUNCTION(rb_gsl_vector,collect)(VALUE obj)
1657
+ {
1658
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew;
1659
+ size_t i;
1660
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1661
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
1662
+ for (i = 0; i < v->size; i++) {
1663
+ FUNCTION(gsl_vector,set)(vnew, i, NUMCONV(rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))));
1664
+ }
1665
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
1666
+ }
1667
+
1668
+ /* 2004/May/03 */
1669
+ static VALUE FUNCTION(rb_gsl_vector,collect_bang)(VALUE obj)
1670
+ {
1671
+ GSL_TYPE(gsl_vector) *v = NULL;
1672
+ size_t i;
1673
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1674
+ for (i = 0; i < v->size; i++) {
1675
+ FUNCTION(gsl_vector,set)(v, i, NUMCONV(rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))));
1676
+ }
1677
+ return obj;
1678
+ }
1679
+
1680
+ /* Modified 2006/Sep/26 */
1681
+ GSL_TYPE(gsl_vector)* FUNCTION(mygsl_vector,mul_matrix)(GSL_TYPE(gsl_vector) *v,
1682
+ GSL_TYPE(gsl_matrix) *m)
1683
+ {
1684
+ GSL_TYPE(gsl_vector) *vnew;
1685
+ size_t i, j;
1686
+ BASE sum;
1687
+ if (v->size != m->size1) rb_raise(rb_eRuntimeError, "vector/matrix sizes are different.");
1688
+ vnew = FUNCTION(gsl_vector,alloc)(m->size2);
1689
+ for (i = 0; i < m->size2; i++) {
1690
+ sum = 0;
1691
+ for (j = 0; j < m->size1; j++) {
1692
+ sum += FUNCTION(gsl_vector,get)(v, j)*FUNCTION(gsl_matrix,get)(m, j, i);
1693
+ }
1694
+ FUNCTION(gsl_vector,set)(vnew, i, sum);
1695
+ }
1696
+ return vnew;
1697
+ }
1698
+
1699
+ void FUNCTION(mygsl_vector,to_m_circulant)(GSL_TYPE(gsl_matrix) *m, GSL_TYPE(gsl_vector) *v)
1700
+ {
1701
+ size_t i, j;
1702
+ for (i = v->size-1; i >= 0; i--) {
1703
+ for (j = 0; j < v->size; j++) {
1704
+ if (j <= i) FUNCTION(gsl_matrix,set)(m, i, j, FUNCTION(gsl_vector,get)(v, v->size-1-i+j));
1705
+ else FUNCTION(gsl_matrix,set)(m, i, j, FUNCTION(gsl_vector,get)(v, j-i-1));
1706
+ }
1707
+ if (i == 0) break;
1708
+ }
1709
+ }
1710
+
1711
+ static VALUE FUNCTION(rb_gsl_vector,to_m_circulant)(VALUE obj)
1712
+ {
1713
+ GSL_TYPE(gsl_matrix) *m;
1714
+ GSL_TYPE(gsl_vector) *v = NULL;
1715
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1716
+ m = FUNCTION(gsl_matrix,alloc)(v->size, v->size);
1717
+ FUNCTION(mygsl_vector,to_m_circulant)(m, v);
1718
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_matrix), 0, FUNCTION(gsl_matrix,free), m);
1719
+ }
1720
+
1721
+ static void FUNCTION(mygsl_vector,indgen)(GSL_TYPE(gsl_vector) *v,
1722
+ BASE start, BASE step)
1723
+ {
1724
+ size_t k = 0;
1725
+ BASE i;
1726
+ i = start;
1727
+ for (k = 0; k < v->size; k++) {
1728
+ FUNCTION(gsl_vector,set)(v, k, i);
1729
+ i += step;
1730
+ }
1731
+ }
1732
+
1733
+ static VALUE FUNCTION(rb_gsl_vector,indgen_singleton)(int argc, VALUE *argv, VALUE obj)
1734
+ {
1735
+ GSL_TYPE(gsl_vector) *v = NULL;
1736
+ size_t n;
1737
+ BASE start = 0, step = 1;
1738
+ switch (argc) {
1739
+ case 3:
1740
+ step = NUMCONV2(argv[2]);
1741
+ /* no break */
1742
+ case 2:
1743
+ start = NUMCONV2(argv[1]);
1744
+ /* no break */
1745
+ case 1:
1746
+ n = NUM2INT(argv[0]);
1747
+ break;
1748
+ default:
1749
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-3)", argc);
1750
+ break;
1751
+ }
1752
+ v = FUNCTION(gsl_vector,alloc)(n);
1753
+ FUNCTION(mygsl_vector,indgen)(v, start, step);
1754
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), v);
1755
+ }
1756
+
1757
+ static VALUE FUNCTION(rb_gsl_vector,indgen)(int argc, VALUE *argv, VALUE obj)
1758
+ {
1759
+ GSL_TYPE(gsl_vector) *v, *vnew;
1760
+ BASE start = 0, step = 1;
1761
+ switch (argc) {
1762
+ case 2:
1763
+ step = NUMCONV2(argv[1]);
1764
+ /* no break */
1765
+ case 1:
1766
+ start = NUMCONV2(argv[0]);
1767
+ break;
1768
+ case 0:
1769
+ break;
1770
+ default:
1771
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-2)", argc);
1772
+ break;
1773
+ }
1774
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1775
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
1776
+ FUNCTION(mygsl_vector,indgen)(vnew, start, step);
1777
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
1778
+ }
1779
+
1780
+ static VALUE FUNCTION(rb_gsl_vector,indgen_bang)(int argc, VALUE *argv, VALUE obj)
1781
+ {
1782
+ GSL_TYPE(gsl_vector) *v = NULL;
1783
+ BASE start = 0, step = 1;
1784
+ switch (argc) {
1785
+ case 2:
1786
+ step = NUMCONV2(argv[1]);
1787
+ /* no break */
1788
+ case 1:
1789
+ start = NUMCONV2(argv[0]);
1790
+ break;
1791
+ case 0:
1792
+ break;
1793
+ default:
1794
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-2)", argc);
1795
+ break;
1796
+ }
1797
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1798
+ FUNCTION(mygsl_vector,indgen)(v, start, step);
1799
+ return obj;
1800
+ }
1801
+
1802
+ static VALUE FUNCTION(rb_gsl_vector,to_m)(VALUE obj, VALUE ii, VALUE jj)
1803
+ {
1804
+ GSL_TYPE(gsl_matrix) *m;
1805
+ GSL_TYPE(gsl_vector) *v = NULL;
1806
+ size_t i, j, n;
1807
+ CHECK_FIXNUM(ii); CHECK_FIXNUM(jj);
1808
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1809
+ i = (size_t) FIX2INT(ii); j = (size_t) FIX2INT(jj);
1810
+ n = i*j;
1811
+ m = FUNCTION(gsl_matrix,alloc)(i, j);
1812
+ memcpy(m->data, v->data, sizeof(BASE)*v->size);
1813
+ for (i = n; i < v->size; i++) m->data[i] = (BASE) 0;
1814
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_matrix), 0, FUNCTION(gsl_matrix,free), m);
1815
+ }
1816
+
1817
+ static VALUE FUNCTION(rb_gsl_vector,block)(VALUE obj)
1818
+ {
1819
+ GSL_TYPE(gsl_vector) *v = NULL;
1820
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1821
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_block), 0, NULL, v->block);
1822
+ }
1823
+
1824
+ /*****/
1825
+ static VALUE GSL_TYPE(rb_gsl_sort_vector)(VALUE obj)
1826
+ {
1827
+ GSL_TYPE(gsl_vector) *v = NULL;
1828
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1829
+ GSL_TYPE(gsl_sort_vector)(v);
1830
+ return obj;
1831
+ }
1832
+
1833
+ static VALUE GSL_TYPE(rb_gsl_sort_vector2)(VALUE obj)
1834
+ {
1835
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
1836
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1837
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
1838
+ FUNCTION(gsl_vector,memcpy)(vnew, v);
1839
+ GSL_TYPE(gsl_sort_vector)(vnew);
1840
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
1841
+ }
1842
+
1843
+ static VALUE FUNCTION(rb_gsl_sort_vector,index)(VALUE obj)
1844
+ {
1845
+ GSL_TYPE(gsl_vector) *v = NULL;
1846
+ gsl_index *p = NULL;
1847
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1848
+ p = gsl_permutation_alloc(v->size);
1849
+ FUNCTION(gsl_sort_vector,index)(p, v);
1850
+ return Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, p);
1851
+ }
1852
+
1853
+ static VALUE FUNCTION(rb_gsl_sort_vector,smallest)(VALUE obj, VALUE kk)
1854
+ {
1855
+ GSL_TYPE(gsl_vector) *v = NULL, *v2 = NULL;
1856
+ size_t k;
1857
+ CHECK_FIXNUM(kk);
1858
+ k = FIX2INT(kk);
1859
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1860
+ v2 = FUNCTION(gsl_vector,alloc)(k);
1861
+ FUNCTION(gsl_sort_vector,smallest)(v2->data, k, v);
1862
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), v2);
1863
+ }
1864
+
1865
+ static VALUE FUNCTION(rb_gsl_sort_vector,largest)(VALUE obj, VALUE kk)
1866
+ {
1867
+ GSL_TYPE(gsl_vector) *v = NULL, *v2 = NULL;
1868
+ size_t k;
1869
+ CHECK_FIXNUM(kk);
1870
+ k = FIX2INT(kk);
1871
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1872
+ v2 = FUNCTION(gsl_vector,alloc)(k);
1873
+ FUNCTION(gsl_sort_vector,largest)(v2->data, k, v);
1874
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), v2);
1875
+ }
1876
+
1877
+ static VALUE FUNCTION(rb_gsl_sort_vector,smallest_index)(VALUE obj, VALUE kk)
1878
+ {
1879
+ GSL_TYPE(gsl_vector) *v = NULL;
1880
+ gsl_index *p = NULL;
1881
+ size_t k;
1882
+ CHECK_FIXNUM(kk);
1883
+ k = FIX2INT(kk);
1884
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1885
+ p = gsl_permutation_alloc(k);
1886
+ FUNCTION(gsl_sort_vector,smallest_index)(p->data, k, v);
1887
+ return Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, p);
1888
+ }
1889
+
1890
+ static VALUE FUNCTION(rb_gsl_sort_vector,largest_index)(VALUE obj, VALUE kk)
1891
+ {
1892
+ GSL_TYPE(gsl_vector) *v = NULL;
1893
+ gsl_index *p = NULL;
1894
+ size_t k;
1895
+ CHECK_FIXNUM(kk);
1896
+ k = FIX2INT(kk);
1897
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1898
+ p = gsl_permutation_alloc(k);
1899
+ FUNCTION(gsl_sort_vector,largest_index)(p->data, k, v);
1900
+ return Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, p);
1901
+ }
1902
+
1903
+ static VALUE FUNCTION(rb_gsl_vector,histogram)(int argc, VALUE *argv, VALUE obj)
1904
+ {
1905
+ GSL_TYPE(gsl_vector) *v = NULL;
1906
+ gsl_histogram *h;
1907
+ gsl_vector *ranges;
1908
+ double min, max;
1909
+ size_t i, n;
1910
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1911
+ switch (argc) {
1912
+ case 1:
1913
+ if (rb_obj_is_kind_of(argv[0], rb_cRange))
1914
+ argv[0] = rb_gsl_range2ary(argv[0]);
1915
+ switch (TYPE(argv[0])) {
1916
+ case T_FIXNUM:
1917
+ n = NUM2INT(argv[0]);
1918
+ min = FUNCTION(gsl_vector,min)(v) - 4*GSL_DBL_EPSILON;
1919
+ max = FUNCTION(gsl_vector,max)(v) + 4*GSL_DBL_EPSILON;
1920
+ h = gsl_histogram_alloc(n);
1921
+ gsl_histogram_set_ranges_uniform(h, min, max);
1922
+ break;
1923
+ case T_ARRAY:
1924
+ n = RARRAY_LEN(argv[0]) - 1;
1925
+ h = gsl_histogram_alloc(n);
1926
+ for (i = 0; i <= n; i++) h->range[i] = NUM2DBL(rb_ary_entry(argv[0], i));
1927
+ break;
1928
+ default:
1929
+ CHECK_VECTOR(argv[0]);
1930
+ Data_Get_Struct(argv[0], gsl_vector, ranges);
1931
+ n = ranges->size - 1;
1932
+ h = gsl_histogram_alloc(n);
1933
+ gsl_histogram_set_ranges(h, ranges->data, ranges->size);
1934
+ break;
1935
+ }
1936
+ break;
1937
+ case 2:
1938
+ n = NUM2INT(argv[0]);
1939
+ switch (TYPE(argv[1])) {
1940
+ case T_ARRAY:
1941
+ min = NUM2DBL(rb_ary_entry(argv[1], 0));
1942
+ max = NUM2DBL(rb_ary_entry(argv[1], 1));
1943
+ break;
1944
+ default:
1945
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array expected)",
1946
+ rb_class2name(CLASS_OF(argv[1])));
1947
+ break;
1948
+ }
1949
+ h = gsl_histogram_alloc(n);
1950
+ gsl_histogram_set_ranges_uniform(h, min, max);
1951
+ break;
1952
+ case 3:
1953
+ n = NUM2INT(argv[0]);
1954
+ min = NUM2DBL(argv[1]); max = NUM2DBL(argv[2]);
1955
+ h = gsl_histogram_alloc(n);
1956
+ gsl_histogram_set_ranges_uniform(h, min, max);
1957
+ break;
1958
+ default:
1959
+ rb_raise(rb_eArgError, "wrong number of arguments %d", argc);
1960
+ break;
1961
+ }
1962
+ for (i = 0; i < v->size; i++)
1963
+ gsl_histogram_increment(h, FUNCTION(gsl_vector,get)(v, i));
1964
+ return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, h);
1965
+ }
1966
+
1967
+ static VALUE FUNCTION(rb_gsl_vector,last)(VALUE obj)
1968
+ {
1969
+ GSL_TYPE(gsl_vector) *v = NULL;
1970
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1971
+ return C_TO_VALUE(FUNCTION(gsl_vector,get)(v, v->size-1));
1972
+ }
1973
+
1974
+ static VALUE FUNCTION(rb_gsl_vector,first)(VALUE obj)
1975
+ {
1976
+ GSL_TYPE(gsl_vector) *v = NULL;
1977
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1978
+ return C_TO_VALUE(FUNCTION(gsl_vector,get)(v, 0));
1979
+ }
1980
+
1981
+ static VALUE FUNCTION(rb_gsl_vector,concat)(VALUE obj, VALUE other)
1982
+ {
1983
+ GSL_TYPE(gsl_vector) *v = NULL, *v2 = NULL, *vnew = NULL;
1984
+ QUALIFIED_VIEW(gsl_vector,view) vv;
1985
+ VALUE x;
1986
+ BASE beg, end;
1987
+ int step;
1988
+ size_t i, size2;
1989
+
1990
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
1991
+
1992
+ switch(TYPE(other)) {
1993
+ case T_FIXNUM:
1994
+ case T_BIGNUM:
1995
+ case T_FLOAT:
1996
+ vnew = FUNCTION(gsl_vector,alloc)(v->size + 1);
1997
+ vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size);
1998
+ FUNCTION(gsl_vector,memcpy)(&vv.vector, v);
1999
+ FUNCTION(gsl_vector,set)(vnew, v->size, NUMCONV2(other));
2000
+ break;
2001
+
2002
+ case T_ARRAY:
2003
+ size2 = RARRAY_LEN(other);
2004
+ vnew = FUNCTION(gsl_vector,alloc)(v->size + size2);
2005
+ vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size);
2006
+ FUNCTION(gsl_vector,memcpy)(&vv.vector, v);
2007
+ for (i = 0; i < size2; i++) {
2008
+ x = rb_ary_entry(other, i);
2009
+ FUNCTION(gsl_vector,set)(vnew, v->size + i, NUMCONV2(x));
2010
+ }
2011
+ break;
2012
+
2013
+ default:
2014
+ if(rb_obj_is_kind_of(other, rb_cRange)) {
2015
+ FUNCTION(get_range,beg_en_n)(other, &beg, &end, &size2, &step);
2016
+ vnew = FUNCTION(gsl_vector,alloc)(v->size + size2);
2017
+ vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size);
2018
+ FUNCTION(gsl_vector,memcpy)(&vv.vector, v);
2019
+ for (i = 0; i < size2; i++) {
2020
+ FUNCTION(gsl_vector,set)(vnew, v->size + i, beg);
2021
+ beg += step;
2022
+ }
2023
+ } else if (rb_obj_is_kind_of(other, GSL_TYPE(cgsl_vector))) {
2024
+ Data_Get_Struct(other, GSL_TYPE(gsl_vector), v2);
2025
+ size2 = v2->size;
2026
+ vnew = FUNCTION(gsl_vector,alloc)(v->size + size2);
2027
+ vv = FUNCTION(gsl_vector,subvector)(vnew, 0, v->size);
2028
+ FUNCTION(gsl_vector,memcpy)(&vv.vector, v);
2029
+ vv = FUNCTION(gsl_vector,subvector)(vnew, v->size, size2);
2030
+ FUNCTION(gsl_vector,memcpy)(&vv.vector, v2);
2031
+ } else {
2032
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array, Numeric, Range, or %s expected)",
2033
+ rb_class2name(CLASS_OF(other)), rb_class2name(GSL_TYPE(cgsl_vector)));
2034
+ }
2035
+ break;
2036
+ }
2037
+
2038
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
2039
+ }
2040
+
2041
+ void FUNCTION(mygsl_vector,diff)(GSL_TYPE(gsl_vector) *vdst,
2042
+ GSL_TYPE(gsl_vector) *vsrc, size_t n)
2043
+ {
2044
+ BASE a, b;
2045
+ int coef, fac, nn, ff;
2046
+ size_t i, k;
2047
+ nn = gsl_sf_fact((unsigned int) n);
2048
+ if (GSL_IS_EVEN(n)) ff = 1;
2049
+ else ff = -1;
2050
+ for (i = 0; i < vsrc->size-n; i++) {
2051
+ fac = ff;
2052
+ a = 0;
2053
+ for (k = 0; k <= n; k++) {
2054
+ b = FUNCTION(gsl_vector,get)(vsrc, i+k);
2055
+ coef = nn/gsl_sf_fact(k)/gsl_sf_fact(n-k);
2056
+ a += fac*coef*b;
2057
+ fac *= -1;
2058
+ }
2059
+ FUNCTION(gsl_vector,set)(vdst, i, a);
2060
+ }
2061
+ }
2062
+
2063
+ static VALUE FUNCTION(rb_gsl_vector,diff)(int argc, VALUE *argv, VALUE obj)
2064
+ {
2065
+ GSL_TYPE(gsl_vector) *v = NULL, *vnew = NULL;
2066
+ size_t n;
2067
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2068
+ switch (argc) {
2069
+ case 0:
2070
+ n = 1;
2071
+ break;
2072
+ case 1:
2073
+ n = FIX2INT(argv[0]);
2074
+ break;
2075
+ default:
2076
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
2077
+ break;
2078
+ }
2079
+ if (n <= 0) return obj;
2080
+ if (v->size <= n) return obj;
2081
+ vnew = FUNCTION(gsl_vector,alloc)(v->size - n);
2082
+ FUNCTION(mygsl_vector,diff)(vnew, v, n);
2083
+ return Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew);
2084
+ }
2085
+
2086
+ static VALUE FUNCTION(rb_gsl_vector,test)(VALUE obj, int (*f)(const double))
2087
+ {
2088
+ GSL_TYPE(gsl_vector) *v = NULL;
2089
+ gsl_vector_int *vi = NULL;
2090
+ size_t i;
2091
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2092
+ vi = gsl_vector_int_alloc(v->size);
2093
+ for (i = 0; i < v->size; i++)
2094
+ gsl_vector_int_set(vi, i, (*f)(FUNCTION(gsl_vector,get)(v, i)));
2095
+ return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, vi);
2096
+ }
2097
+
2098
+ static VALUE FUNCTION(rb_gsl_vector,test2)(VALUE obj, int (*f)(const double))
2099
+ {
2100
+ GSL_TYPE(gsl_vector) *v = NULL;
2101
+ VALUE ary;
2102
+ size_t i;
2103
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2104
+ ary = rb_ary_new2(v->size);
2105
+ for (i = 0; i < v->size; i++) {
2106
+ if ((*f)(FUNCTION(gsl_vector,get)(v, i)))
2107
+ rb_ary_store(ary, i, Qtrue);
2108
+ else
2109
+ rb_ary_store(ary, i, Qfalse);
2110
+ }
2111
+ return ary;
2112
+ }
2113
+
2114
+ static VALUE FUNCTION(rb_gsl_vector,isnan)(VALUE obj)
2115
+ {
2116
+ return FUNCTION(rb_gsl_vector,test)(obj, gsl_isnan);
2117
+ }
2118
+
2119
+ static VALUE FUNCTION(rb_gsl_vector,isinf)(VALUE obj)
2120
+ {
2121
+ return FUNCTION(rb_gsl_vector,test)(obj, gsl_isinf);
2122
+ }
2123
+
2124
+ static VALUE FUNCTION(rb_gsl_vector,finite)(VALUE obj)
2125
+ {
2126
+ return FUNCTION(rb_gsl_vector,test)(obj, gsl_finite);
2127
+ }
2128
+
2129
+ static VALUE FUNCTION(rb_gsl_vector,isnan2)(VALUE obj)
2130
+ {
2131
+ return FUNCTION(rb_gsl_vector,test2)(obj, gsl_isnan);
2132
+ }
2133
+
2134
+ static VALUE FUNCTION(rb_gsl_vector,isinf2)(VALUE obj)
2135
+ {
2136
+ return FUNCTION(rb_gsl_vector,test2)(obj, gsl_isinf);
2137
+ }
2138
+
2139
+ static VALUE FUNCTION(rb_gsl_vector,finite2)(VALUE obj)
2140
+ {
2141
+ return FUNCTION(rb_gsl_vector,test2)(obj, gsl_finite);
2142
+ }
2143
+
2144
+ static VALUE FUNCTION(rb_gsl_vector,delete_at)(VALUE obj, VALUE ii)
2145
+ {
2146
+ int i2;
2147
+ size_t i;
2148
+ GSL_TYPE(gsl_vector) *v;
2149
+ BASE x;
2150
+ if (rb_obj_is_kind_of(obj,QUALIFIED_VIEW(cgsl_vector,view)))
2151
+ rb_raise(rb_eRuntimeError, "prohibited for %s", rb_class2name(CLASS_OF(obj)));
2152
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2153
+ if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1");
2154
+ if (v->size == 0) return Qnil;
2155
+ CHECK_FIXNUM(ii);
2156
+ i2 = FIX2INT(ii);
2157
+ if (i2 < 0) {
2158
+ i2 += v->size;
2159
+ }
2160
+ if (i2 < 0 || i2 > v->size-1) return Qnil;
2161
+ i = (size_t) i2;
2162
+ x = FUNCTION(gsl_vector,get)(v, i);
2163
+ memmove(v->data+i, v->data+i+1, sizeof(BASE)*(v->size-1-i));
2164
+ v->size -= 1;
2165
+ return C_TO_VALUE(x);
2166
+ }
2167
+
2168
+ static VALUE FUNCTION(rb_gsl_vector,delete_if)(VALUE obj)
2169
+ {
2170
+ GSL_TYPE(gsl_vector) *v;
2171
+ BASE x;
2172
+ VALUE val;
2173
+ size_t i, count = 0;
2174
+ if (!rb_block_given_p()) rb_raise(rb_eRuntimeError, "block is not given");
2175
+ if (rb_obj_is_kind_of(obj,QUALIFIED_VIEW(cgsl_vector,view)))
2176
+ rb_raise(rb_eRuntimeError, "prohibited for %s", rb_class2name(CLASS_OF(obj)));
2177
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2178
+ if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1");
2179
+ for (i = 0; i < v->size; i++) {
2180
+ x = FUNCTION(gsl_vector,get)(v, i);
2181
+ val = rb_yield(C_TO_VALUE(x));
2182
+ if(RTEST(val)) {
2183
+ count++;
2184
+ } else if(count > 0) {
2185
+ FUNCTION(gsl_vector,set)(v, i-count, x);
2186
+ }
2187
+ }
2188
+ v->size -= count;
2189
+ return obj;
2190
+ }
2191
+
2192
+ static VALUE FUNCTION(rb_gsl_vector,delete)(VALUE obj, VALUE yy)
2193
+ {
2194
+ GSL_TYPE(gsl_vector) *v;
2195
+ BASE x, y;
2196
+ size_t i, count = 0;
2197
+ y = NUMCONV(yy);
2198
+ if (rb_obj_is_kind_of(obj,QUALIFIED_VIEW(cgsl_vector,view)))
2199
+ rb_raise(rb_eRuntimeError, "prohibited for %s", rb_class2name(CLASS_OF(obj)));
2200
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2201
+ if (v->stride != 1) rb_raise(rb_eRuntimeError, "vector must have stride 1");
2202
+ if (v->size == 0) return obj;
2203
+ for (i = 0; i < v->size; i++) {
2204
+ x = FUNCTION(gsl_vector,get)(v, i);
2205
+ if (x == y) {
2206
+ count++;
2207
+ } else if(count > 0) {
2208
+ FUNCTION(gsl_vector,set)(v, i-count, x);
2209
+ }
2210
+ }
2211
+ v->size -= count;
2212
+ return count ? y : Qnil;
2213
+ }
2214
+
2215
+ /* singleton method */
2216
+ #ifdef BASE_INT
2217
+ #define FORMAT_TMP "%d"
2218
+ #else
2219
+ #define FORMAT_TMP "%lf"
2220
+ #endif
2221
+ static VALUE FUNCTION(rb_gsl_vector,filescan)(VALUE klass, VALUE file)
2222
+ {
2223
+ FILE *fp = NULL;
2224
+ int nn, k;
2225
+ char buf[1024], filename[1024];
2226
+ size_t n, lines, i, j, ii = 0, jj;
2227
+ long pos;
2228
+ GSL_TYPE(gsl_vector) **x;
2229
+ BASE val;
2230
+ VALUE ary;
2231
+ Check_Type(file, T_STRING);
2232
+ strcpy(filename, STR2CSTR(file));
2233
+ sprintf(buf, "sed '/^#/d' %s | wc", filename);
2234
+ if ((fp = popen(buf, "r")) == NULL)
2235
+ rb_raise(rb_eIOError, "popen failed.");
2236
+ fgets(buf, 1024, fp);
2237
+ pclose(fp);
2238
+ sscanf(buf, "%d", &nn);
2239
+ lines = (size_t) nn; /* vector length */
2240
+ if ((fp = fopen(filename, "r")) == NULL)
2241
+ rb_raise(rb_eIOError, "cannot open file %s.", filename);
2242
+ while (1) {
2243
+ fgets(buf, 1024, fp); /* read the first line to count number of columns */
2244
+ if (buf[0] == '#') continue;
2245
+ else break;
2246
+ }
2247
+ n = count_columns(buf); /* number of vectors to be created */
2248
+ x = (GSL_TYPE(gsl_vector)**) xmalloc(sizeof(GSL_TYPE(gsl_vector)*)*n);
2249
+ ary = rb_ary_new2(n);
2250
+ for (j = 0; j < n; j++) {
2251
+ x[j] = FUNCTION(gsl_vector,alloc)(lines);
2252
+ rb_ary_store(ary, j, Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), x[j]));
2253
+ }
2254
+ rewind(fp);
2255
+ for (i = 0, ii = 0; ii < lines; i++) {
2256
+ pos = ftell(fp);
2257
+ fgets(buf, 1024, fp);
2258
+ if (buf[0] == '#') continue;
2259
+ fseek(fp, pos, SEEK_SET);
2260
+ for (j = 0, jj = 0; jj < n; j++) {
2261
+ k = fscanf(fp, FORMAT_TMP, &val);
2262
+ if (k != 1) continue;
2263
+ FUNCTION(gsl_vector,set)(x[jj++], ii, val);
2264
+ }
2265
+ ii += 1;
2266
+ }
2267
+ fclose(fp);
2268
+ free(x);
2269
+ return ary;
2270
+ }
2271
+ #undef FORMAT_TMP
2272
+
2273
+ static int FUNCTION(gsl_vector,eq)(const GSL_TYPE(gsl_vector) *a,
2274
+ const GSL_TYPE(gsl_vector) *b,
2275
+ gsl_block_uchar *c)
2276
+ {
2277
+ size_t i;
2278
+ BASE x, y;
2279
+ if (a->size != b->size) return -1;
2280
+ if (a->size != c->size) return -2;
2281
+ for (i = 0; i < a->size; i++) {
2282
+ x = a->data[i*a->stride];
2283
+ y = b->data[i*b->stride];
2284
+ c->data[i] = (x > y || x < y) ? 0 : 1;
2285
+ }
2286
+ return 0;
2287
+ }
2288
+
2289
+ static int FUNCTION(gsl_vector,ne)(const GSL_TYPE(gsl_vector) *a,
2290
+ const GSL_TYPE(gsl_vector) *b,
2291
+ gsl_block_uchar *c)
2292
+ {
2293
+ size_t i;
2294
+ BASE x, y;
2295
+ if (a->size != b->size) return -1;
2296
+ if (a->size != c->size) return -2;
2297
+ for (i = 0; i < a->size; i++) {
2298
+ x = a->data[i*a->stride];
2299
+ y = b->data[i*b->stride];
2300
+ c->data[i] = (x > y || x < y) ? 1 : 0;
2301
+ }
2302
+ return 0;
2303
+ }
2304
+
2305
+ static int FUNCTION(gsl_vector,gt)(const GSL_TYPE(gsl_vector) *a,
2306
+ const GSL_TYPE(gsl_vector) *b,
2307
+ gsl_block_uchar *c)
2308
+ {
2309
+ size_t i;
2310
+ BASE x, y;
2311
+ if (a->size != b->size) return -1;
2312
+ if (a->size != c->size) return -2;
2313
+ for (i = 0; i < a->size; i++) {
2314
+ x = a->data[i*a->stride];
2315
+ y = b->data[i*b->stride];
2316
+ c->data[i] = (x > y) ? 1 : 0;
2317
+ }
2318
+ return 0;
2319
+ }
2320
+
2321
+ static int FUNCTION(gsl_vector,ge)(const GSL_TYPE(gsl_vector) *a,
2322
+ const GSL_TYPE(gsl_vector) *b,
2323
+ gsl_block_uchar *c)
2324
+ {
2325
+ size_t i;
2326
+ BASE x, y;
2327
+ if (a->size != b->size) return -1;
2328
+ if (a->size != c->size) return -2;
2329
+ for (i = 0; i < a->size; i++) {
2330
+ x = a->data[i*a->stride];
2331
+ y = b->data[i*b->stride];
2332
+ c->data[i] = (x >= y) ? 1 : 0;
2333
+ }
2334
+ return 0;
2335
+ }
2336
+
2337
+ static int FUNCTION(gsl_vector,lt)(const GSL_TYPE(gsl_vector) *a,
2338
+ const GSL_TYPE(gsl_vector) *b,
2339
+ gsl_block_uchar *c)
2340
+ {
2341
+ size_t i;
2342
+ BASE x, y;
2343
+ if (a->size != b->size) return -1;
2344
+ if (a->size != c->size) return -2;
2345
+ for (i = 0; i < a->size; i++) {
2346
+ x = a->data[i*a->stride];
2347
+ y = b->data[i*b->stride];
2348
+ c->data[i] = (x < y) ? 1 : 0;
2349
+ }
2350
+ return 0;
2351
+ }
2352
+
2353
+ static int FUNCTION(gsl_vector,le)(const GSL_TYPE(gsl_vector) *a,
2354
+ const GSL_TYPE(gsl_vector) *b,
2355
+ gsl_block_uchar *c)
2356
+ {
2357
+ size_t i;
2358
+ BASE x, y;
2359
+ if (a->size != b->size) return -1;
2360
+ if (a->size != c->size) return -2;
2361
+ for (i = 0; i < a->size; i++) {
2362
+ x = a->data[i*a->stride];
2363
+ y = b->data[i*b->stride];
2364
+ c->data[i] = (x <= y) ? 1 : 0;
2365
+ }
2366
+ return 0;
2367
+ }
2368
+
2369
+ static int FUNCTION(gsl_vector,and)(const GSL_TYPE(gsl_vector) *a,
2370
+ const GSL_TYPE(gsl_vector) *b,
2371
+ gsl_block_uchar *c)
2372
+ {
2373
+ size_t i;
2374
+ BASE x, y;
2375
+ if (a->size != b->size) return -1;
2376
+ if (a->size != c->size) return -2;
2377
+ for (i = 0; i < a->size; i++) {
2378
+ x = a->data[i*a->stride];
2379
+ y = b->data[i*b->stride];
2380
+ c->data[i] = (x != 0 && y != 0) ? 1 : 0;
2381
+ }
2382
+ return 0;
2383
+ }
2384
+
2385
+ static int FUNCTION(gsl_vector,or)(const GSL_TYPE(gsl_vector) *a,
2386
+ const GSL_TYPE(gsl_vector) *b,
2387
+ gsl_block_uchar *c)
2388
+ {
2389
+ size_t i;
2390
+ BASE x, y;
2391
+ if (a->size != b->size) return -1;
2392
+ if (a->size != c->size) return -2;
2393
+ for (i = 0; i < a->size; i++) {
2394
+ x = a->data[i*a->stride];
2395
+ y = b->data[i*b->stride];
2396
+ c->data[i] = (x != 0 || y != 0) ? 1 : 0;
2397
+ }
2398
+ return 0;
2399
+ }
2400
+
2401
+ static int FUNCTION(gsl_vector,xor)(const GSL_TYPE(gsl_vector) *a,
2402
+ const GSL_TYPE(gsl_vector) *b,
2403
+ gsl_block_uchar *c)
2404
+ {
2405
+ size_t i;
2406
+ BASE x, y;
2407
+ if (a->size != b->size) return -1;
2408
+ if (a->size != c->size) return -2;
2409
+ for (i = 0; i < a->size; i++) {
2410
+ x = a->data[i*a->stride];
2411
+ y = b->data[i*b->stride];
2412
+ c->data[i] = ((x != 0) == (y != 0)) ? 0 : 1;
2413
+ }
2414
+ return 0;
2415
+ }
2416
+
2417
+ static int FUNCTION(gsl_vector,eq2)(const GSL_TYPE(gsl_vector) *a,
2418
+ BASE b, gsl_block_uchar *c)
2419
+ {
2420
+ size_t i;
2421
+ BASE x, y;
2422
+ if (a->size != c->size) return -2;
2423
+ for (i = 0; i < a->size; i++) {
2424
+ x = a->data[i*a->stride];
2425
+ y = b;
2426
+ c->data[i] = (x > y || x < y) ? 0 : 1;
2427
+ }
2428
+ return 0;
2429
+ }
2430
+
2431
+ static int FUNCTION(gsl_vector,ne2)(const GSL_TYPE(gsl_vector) *a,
2432
+ BASE b,
2433
+ gsl_block_uchar *c)
2434
+ {
2435
+ size_t i;
2436
+ BASE x, y;
2437
+ if (a->size != c->size) return -2;
2438
+ for (i = 0; i < a->size; i++) {
2439
+ x = a->data[i*a->stride];
2440
+ y = b;
2441
+ c->data[i] = (x > y || x < y) ? 1 : 0;
2442
+ }
2443
+ return 0;
2444
+ }
2445
+
2446
+ static int FUNCTION(gsl_vector,gt2)(const GSL_TYPE(gsl_vector) *a,
2447
+ BASE b,
2448
+ gsl_block_uchar *c)
2449
+ {
2450
+ size_t i;
2451
+ BASE x, y;
2452
+ if (a->size != c->size) return -2;
2453
+ for (i = 0; i < a->size; i++) {
2454
+ x = a->data[i*a->stride];
2455
+ y = b;
2456
+ c->data[i] = (x > y) ? 1 : 0;
2457
+ }
2458
+ return 0;
2459
+ }
2460
+
2461
+ static int FUNCTION(gsl_vector,ge2)(const GSL_TYPE(gsl_vector) *a,
2462
+ BASE b,
2463
+ gsl_block_uchar *c)
2464
+ {
2465
+ size_t i;
2466
+ BASE x, y;
2467
+ if (a->size != c->size) return -2;
2468
+ for (i = 0; i < a->size; i++) {
2469
+ x = a->data[i*a->stride];
2470
+ y = b;
2471
+ c->data[i] = (x >= y) ? 1 : 0;
2472
+ }
2473
+ return 0;
2474
+ }
2475
+
2476
+ static int FUNCTION(gsl_vector,lt2)(const GSL_TYPE(gsl_vector) *a,
2477
+ BASE b,
2478
+ gsl_block_uchar *c)
2479
+ {
2480
+ size_t i;
2481
+ BASE x, y;
2482
+ if (a->size != c->size) return -2;
2483
+ for (i = 0; i < a->size; i++) {
2484
+ x = a->data[i*a->stride];
2485
+ y = b;
2486
+ c->data[i] = (x < y) ? 1 : 0;
2487
+ }
2488
+ return 0;
2489
+ }
2490
+
2491
+ static int FUNCTION(gsl_vector,le2)(const GSL_TYPE(gsl_vector) *a,
2492
+ BASE b,
2493
+ gsl_block_uchar *c)
2494
+ {
2495
+ size_t i;
2496
+ BASE x, y;
2497
+ if (a->size != c->size) return -2;
2498
+ for (i = 0; i < a->size; i++) {
2499
+ x = a->data[i*a->stride];
2500
+ y = b;
2501
+ c->data[i] = (x <= y) ? 1 : 0;
2502
+ }
2503
+ return 0;
2504
+ }
2505
+
2506
+ static int FUNCTION(gsl_vector,and2)(const GSL_TYPE(gsl_vector) *a,
2507
+ BASE b,
2508
+ gsl_block_uchar *c)
2509
+ {
2510
+ size_t i;
2511
+ BASE x, y;
2512
+ if (a->size != c->size) return -2;
2513
+ for (i = 0; i < a->size; i++) {
2514
+ x = a->data[i*a->stride];
2515
+ y = b;
2516
+ c->data[i] = (x != 0 && y != 0) ? 1 : 0;
2517
+ }
2518
+ return 0;
2519
+ }
2520
+
2521
+ static int FUNCTION(gsl_vector,or2)(const GSL_TYPE(gsl_vector) *a,
2522
+ BASE b,
2523
+ gsl_block_uchar *c)
2524
+ {
2525
+ size_t i;
2526
+ BASE x, y;
2527
+ if (a->size != c->size) return -2;
2528
+ for (i = 0; i < a->size; i++) {
2529
+ x = a->data[i*a->stride];
2530
+ y = b;
2531
+ c->data[i] = (x != 0 || y != 0) ? 1 : 0;
2532
+ }
2533
+ return 0;
2534
+ }
2535
+
2536
+ static int FUNCTION(gsl_vector,xor2)(const GSL_TYPE(gsl_vector) *a,
2537
+ BASE b,
2538
+ gsl_block_uchar *c)
2539
+ {
2540
+ size_t i;
2541
+ BASE x, y;
2542
+ if (a->size != c->size) return -2;
2543
+ for (i = 0; i < a->size; i++) {
2544
+ x = a->data[i*a->stride];
2545
+ y = b;
2546
+ c->data[i] = ((x != 0) == (y != 0)) ? 0 : 1;
2547
+ }
2548
+ return 0;
2549
+ }
2550
+
2551
+
2552
+ static VALUE FUNCTION(rb_gsl_vector,compare)(VALUE aa, VALUE bb,
2553
+ int (*cmp)(const GSL_TYPE(gsl_vector)*,
2554
+ const GSL_TYPE(gsl_vector)*,
2555
+ gsl_block_uchar*),
2556
+ int (*cmp2)(const GSL_TYPE(gsl_vector)*,
2557
+ BASE,
2558
+ gsl_block_uchar*))
2559
+ {
2560
+ GSL_TYPE(gsl_vector) *a, *b;
2561
+ /* gsl_vector_int *c;*/
2562
+ gsl_block_uchar *c;
2563
+ //int status;
2564
+ Data_Get_Struct(aa, GSL_TYPE(gsl_vector), a);
2565
+ c = gsl_block_uchar_alloc(a->size);
2566
+ if (VEC_P(bb)) {
2567
+ Data_Get_Struct(bb, GSL_TYPE(gsl_vector), b);
2568
+ if (a->size != b->size)
2569
+ rb_raise(rb_eRuntimeError, "Vector size mismatch, %d and %d", (int) a->size,
2570
+ (int) b->size);
2571
+ /*status =*/ (*cmp)(a, b, c);
2572
+ } else {
2573
+ /*status =*/ (*cmp2)(a, NUMCONV(bb), c);
2574
+ }
2575
+ return Data_Wrap_Struct(cgsl_block_uchar, 0, gsl_block_uchar_free, c);
2576
+ }
2577
+
2578
+ static VALUE FUNCTION(rb_gsl_vector,eq)(VALUE aa, VALUE bb)
2579
+ {
2580
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,eq),
2581
+ FUNCTION(gsl_vector,eq2));
2582
+ }
2583
+
2584
+ static VALUE FUNCTION(rb_gsl_vector,ne)(VALUE aa, VALUE bb)
2585
+ {
2586
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,ne),
2587
+ FUNCTION(gsl_vector,ne2));
2588
+ }
2589
+
2590
+ static VALUE FUNCTION(rb_gsl_vector,gt)(VALUE aa, VALUE bb)
2591
+ {
2592
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,gt),
2593
+ FUNCTION(gsl_vector,gt2));
2594
+ }
2595
+
2596
+ static VALUE FUNCTION(rb_gsl_vector,ge)(VALUE aa, VALUE bb)
2597
+ {
2598
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,ge),
2599
+ FUNCTION(gsl_vector,ge2));
2600
+ }
2601
+
2602
+ static VALUE FUNCTION(rb_gsl_vector,lt)(VALUE aa, VALUE bb)
2603
+ {
2604
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,lt),
2605
+ FUNCTION(gsl_vector,lt2));
2606
+ }
2607
+
2608
+ static VALUE FUNCTION(rb_gsl_vector,le)(VALUE aa, VALUE bb)
2609
+ {
2610
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,le),
2611
+ FUNCTION(gsl_vector,le2));
2612
+ }
2613
+
2614
+ static VALUE FUNCTION(rb_gsl_vector,and)(VALUE aa, VALUE bb)
2615
+ {
2616
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,and),
2617
+ FUNCTION(gsl_vector,and2));
2618
+ }
2619
+
2620
+ static VALUE FUNCTION(rb_gsl_vector,or)(VALUE aa, VALUE bb)
2621
+ {
2622
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,or),
2623
+ FUNCTION(gsl_vector,or2));
2624
+ }
2625
+
2626
+ static VALUE FUNCTION(rb_gsl_vector,xor)(VALUE aa, VALUE bb)
2627
+ {
2628
+ return FUNCTION(rb_gsl_vector,compare)(aa, bb, FUNCTION(gsl_vector,xor),
2629
+ FUNCTION(gsl_vector,xor2));
2630
+ }
2631
+
2632
+ static VALUE FUNCTION(rb_gsl_vector,not)(VALUE obj)
2633
+ {
2634
+ GSL_TYPE(gsl_vector) *v;
2635
+ gsl_block_uchar *vv;
2636
+ size_t i;
2637
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2638
+ vv = gsl_block_uchar_alloc(v->size);
2639
+ for (i = 0; i < v->size; i++) vv->data[i] = (v->data[i*v->stride] != 0) ? 0 : 1;
2640
+ return Data_Wrap_Struct(cgsl_block_uchar, 0, gsl_block_uchar_free, vv);
2641
+ }
2642
+
2643
+ static VALUE FUNCTION(rb_gsl_vector,any)(VALUE obj)
2644
+ {
2645
+ GSL_TYPE(gsl_vector) *v = NULL;
2646
+ size_t i;
2647
+
2648
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2649
+ if (rb_block_given_p()) {
2650
+ for (i = 0; i < v->size; i++) {
2651
+ if (rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))) return INT2FIX(1);
2652
+ }
2653
+ return INT2FIX(0);
2654
+ } else {
2655
+ if (FUNCTION(gsl_vector,isnull)(v)) return INT2FIX(0);
2656
+ return INT2FIX(1);
2657
+ }
2658
+ }
2659
+
2660
+ static VALUE FUNCTION(rb_gsl_vector,any2)(VALUE obj)
2661
+ {
2662
+ GSL_TYPE(gsl_vector) *v = NULL;
2663
+ size_t i;
2664
+
2665
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2666
+ if (rb_block_given_p()) {
2667
+ for (i = 0; i < v->size; i++)
2668
+ if (rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))) return Qtrue;
2669
+ return Qfalse;
2670
+ } else {
2671
+ for (i = 0; i < v->size; i++)
2672
+ if (v->data[i*v->stride]) return Qtrue;
2673
+ return Qfalse;
2674
+ }
2675
+ }
2676
+
2677
+ static VALUE FUNCTION(rb_gsl_vector,none)(VALUE obj)
2678
+ {
2679
+ GSL_TYPE(gsl_vector) *v;
2680
+ size_t i;
2681
+
2682
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2683
+ if (rb_block_given_p()) {
2684
+ for (i = 0; i < v->size; i++)
2685
+ if (rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))) return Qfalse;
2686
+ return Qtrue;
2687
+ } else {
2688
+ for (i = 0; i < v->size; i++)
2689
+ if (v->data[i*v->stride]) return Qfalse;
2690
+ return Qtrue;
2691
+ }
2692
+ }
2693
+
2694
+ static VALUE FUNCTION(rb_gsl_vector,all)(VALUE obj)
2695
+ {
2696
+ GSL_TYPE(gsl_vector) *v;
2697
+ size_t i;
2698
+
2699
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2700
+ if (rb_block_given_p()) {
2701
+ for (i = 0; i < v->size; i++)
2702
+ if (!rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))) return Qfalse;
2703
+ return Qtrue;
2704
+ } else {
2705
+ for (i = 0; i < v->size; i++)
2706
+ if (!v->data[i*v->stride]) return Qfalse;
2707
+ return Qtrue;
2708
+ }
2709
+ }
2710
+
2711
+ static VALUE FUNCTION(rb_gsl_vector,where)(VALUE obj)
2712
+ {
2713
+ GSL_TYPE(gsl_vector) *v;
2714
+ gsl_index *vv;
2715
+ gsl_block_uchar *btmp = NULL;
2716
+ size_t i, j, n = 0;
2717
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2718
+ /* count true elements */
2719
+ if (rb_block_given_p()) {
2720
+ btmp = gsl_block_uchar_alloc(v->size);
2721
+ for (i = 0; i < v->size; i++) {
2722
+ if (rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))) {
2723
+ btmp->data[i] = 1;
2724
+ n++;
2725
+ } else {
2726
+ btmp->data[i] = 0;
2727
+ }
2728
+ } /* for */
2729
+ } else { /* block is not given */
2730
+ for (i = 0; i < v->size; i++) { if (FUNCTION(gsl_vector,get)(v, i)) n++; }
2731
+ }
2732
+ if (n == 0) {
2733
+ if (btmp) gsl_block_uchar_free(btmp);
2734
+ return Qnil;
2735
+ }
2736
+ vv = gsl_permutation_alloc(n);
2737
+ for (i = 0, j = 0; i < v->size; i++) {
2738
+ if ((!btmp && FUNCTION(gsl_vector,get)(v, i)) || (btmp && btmp->data[i])) {
2739
+ vv->data[j++] = i;
2740
+ }
2741
+ }
2742
+ if (btmp) gsl_block_uchar_free(btmp);
2743
+ return Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, vv);
2744
+ }
2745
+
2746
+ static VALUE FUNCTION(rb_gsl_vector,where2)(VALUE obj)
2747
+ {
2748
+ GSL_TYPE(gsl_vector) *v;
2749
+ gsl_index *v1, *v2;
2750
+ gsl_block_uchar *btmp = NULL;
2751
+ VALUE vv1, vv2;
2752
+ size_t i, j, k, n = 0;
2753
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2754
+ if (rb_block_given_p()) {
2755
+ btmp = gsl_block_uchar_alloc(v->size);
2756
+ for (i = 0; i < v->size; i++) {
2757
+ if (rb_yield(C_TO_VALUE(FUNCTION(gsl_vector,get)(v, i)))) {
2758
+ btmp->data[i] = 1;
2759
+ n++;
2760
+ } else {
2761
+ btmp->data[i] = 0;
2762
+ }
2763
+ } /* for */
2764
+ } else { /* block is not given */
2765
+ for (i = 0; i < v->size; i++) { if (FUNCTION(gsl_vector,get)(v, i)) n++; }
2766
+ }
2767
+ /* true and false logic. need to handle both */
2768
+ if (n == 0) {
2769
+ v2 = gsl_permutation_calloc(v->size); /* calloc() initializes v2 */
2770
+ vv1 = Qnil;
2771
+ vv2 = Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, v2);
2772
+ } else if (v->size-n == 0) {
2773
+ v1 = gsl_permutation_calloc(n); /* calloc() initializes v1 */
2774
+ vv1 = Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, v1);
2775
+ vv2 = Qnil;
2776
+ } else {
2777
+ /* same case as 'where' */
2778
+ v1 = gsl_permutation_alloc(n);
2779
+ v2 = gsl_permutation_alloc(v->size-n);
2780
+ for (i = 0, j = 0, k = 0; i < v->size; i++) {
2781
+ if ((!btmp && FUNCTION(gsl_vector,get)(v, i)) || (btmp && btmp->data[i])) v1->data[j++] = i;
2782
+ else v2->data[k++] = i;
2783
+ }
2784
+ vv1 = Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, v1);
2785
+ vv2 = Data_Wrap_Struct(cgsl_index, 0, gsl_permutation_free, v2);
2786
+ }
2787
+ if (btmp) gsl_block_uchar_free(btmp);
2788
+ return rb_ary_new3(2, vv1, vv2);
2789
+ }
2790
+
2791
+ static VALUE FUNCTION(rb_gsl_vector,op_inplace)(VALUE vv1, VALUE vv2,
2792
+ int (*f)(GSL_TYPE(gsl_vector)*, const GSL_TYPE(gsl_vector)*))
2793
+ {
2794
+ GSL_TYPE(gsl_vector) *v1, *v2;
2795
+ Data_Get_Struct(vv1, GSL_TYPE(gsl_vector), v1);
2796
+ Data_Get_Struct(vv2, GSL_TYPE(gsl_vector), v2);
2797
+ (*f)(v1, v2);
2798
+ return vv1;
2799
+ }
2800
+
2801
+ static VALUE FUNCTION(rb_gsl_vector,add_inplace)(VALUE vv1, VALUE vv2)
2802
+ {
2803
+ GSL_TYPE(gsl_vector) *v1;
2804
+ double x;
2805
+ if(VEC_P(vv2)) {
2806
+ return FUNCTION(rb_gsl_vector,op_inplace)(vv1, vv2, FUNCTION(gsl_vector,add));
2807
+ } else {
2808
+ x = NUM2DBL(vv2);
2809
+ Data_Get_Struct(vv1, GSL_TYPE(gsl_vector), v1);
2810
+ FUNCTION(gsl_vector,add_constant)(v1, x);
2811
+ return vv1;
2812
+ }
2813
+ }
2814
+
2815
+ static VALUE FUNCTION(rb_gsl_vector,sub_inplace)(VALUE vv1, VALUE vv2)
2816
+ {
2817
+ GSL_TYPE(gsl_vector) *v1;
2818
+ double x;
2819
+ if(VEC_P(vv2)) {
2820
+ return FUNCTION(rb_gsl_vector,op_inplace)(vv1, vv2, FUNCTION(gsl_vector,sub));
2821
+ } else {
2822
+ x = NUM2DBL(vv2);
2823
+ Data_Get_Struct(vv1, GSL_TYPE(gsl_vector), v1);
2824
+ FUNCTION(gsl_vector,add_constant)(v1, -x);
2825
+ return vv1;
2826
+ }
2827
+ }
2828
+
2829
+ static VALUE FUNCTION(rb_gsl_vector,mul_inplace)(VALUE vv1, VALUE vv2)
2830
+ {
2831
+ GSL_TYPE(gsl_vector) *v1;
2832
+ double x;
2833
+ if(VEC_P(vv2)) {
2834
+ return FUNCTION(rb_gsl_vector,op_inplace)(vv1, vv2, FUNCTION(gsl_vector,mul));
2835
+ } else {
2836
+ x = NUM2DBL(vv2);
2837
+ Data_Get_Struct(vv1, GSL_TYPE(gsl_vector), v1);
2838
+ FUNCTION(gsl_vector,scale)(v1, x);
2839
+ return vv1;
2840
+ }
2841
+ }
2842
+
2843
+ static VALUE FUNCTION(rb_gsl_vector,div_inplace)(VALUE vv1, VALUE vv2)
2844
+ {
2845
+ GSL_TYPE(gsl_vector) *v1;
2846
+ double x;
2847
+ if(VEC_P(vv2)) {
2848
+ return FUNCTION(rb_gsl_vector,op_inplace)(vv1, vv2, FUNCTION(gsl_vector,div));
2849
+ } else {
2850
+ x = NUM2DBL(vv2);
2851
+ Data_Get_Struct(vv1, GSL_TYPE(gsl_vector), v1);
2852
+ FUNCTION(gsl_vector,scale)(v1, 1.0/x);
2853
+ return vv1;
2854
+ }
2855
+ }
2856
+
2857
+ static VALUE FUNCTION(rb_gsl_vector,zip)(int argc, VALUE *argv, VALUE obj)
2858
+ {
2859
+ GSL_TYPE(gsl_vector) *v0, **vp, *vnew;
2860
+ VALUE ary;
2861
+ size_t i, j;
2862
+ int argc2;
2863
+ VALUE *argv2;
2864
+ if (VEC_P(obj)) {
2865
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v0);
2866
+ argc2 = argc;
2867
+ argv2 = argv;
2868
+ } else {
2869
+ if (argc < 1) rb_raise(rb_eArgError, "Too few arguments.");
2870
+ Data_Get_Struct(argv[0], GSL_TYPE(gsl_vector), v0);
2871
+ argc2 = argc - 1;
2872
+ argv2 = argv + 1;
2873
+ }
2874
+ for (i = 0; i < argc2; i++) {
2875
+ CHECK_VEC(argv2[i]);
2876
+ }
2877
+ vp = (GSL_TYPE(gsl_vector)**) malloc(sizeof(GSL_TYPE(gsl_vector)**));
2878
+ for (i = 0; i < argc2; i++) {
2879
+ Data_Get_Struct(argv2[i], GSL_TYPE(gsl_vector), vp[i]);
2880
+ }
2881
+ ary = rb_ary_new2(v0->size);
2882
+ for (i = 0; i < v0->size; i++) {
2883
+ vnew = FUNCTION(gsl_vector,alloc)(argc2 + 1);
2884
+ FUNCTION(gsl_vector,set)(vnew, 0, FUNCTION(gsl_vector,get)(v0, i));
2885
+ for (j = 0; j < argc2; j++) {
2886
+ if (i < vp[j]->size) {
2887
+ FUNCTION(gsl_vector,set)(vnew, j+1, FUNCTION(gsl_vector,get)(vp[j], i));
2888
+ } else {
2889
+ FUNCTION(gsl_vector,set)(vnew, j+1, 0.0);
2890
+ }
2891
+ }
2892
+ rb_ary_store(ary, i, Data_Wrap_Struct(GSL_TYPE(cgsl_vector), 0, FUNCTION(gsl_vector,free), vnew));
2893
+ }
2894
+
2895
+ free((GSL_TYPE(gsl_vector)**) vp);
2896
+ return ary;
2897
+ }
2898
+
2899
+ static VALUE FUNCTION(rb_gsl_vector,join)(int argc, VALUE *argv, VALUE obj)
2900
+ {
2901
+ GSL_TYPE(gsl_vector) *v;
2902
+ VALUE str, sep;
2903
+ char *p, buf[16];
2904
+ size_t i;
2905
+ switch (argc) {
2906
+ case 0:
2907
+ sep = rb_str_new2(" ");
2908
+ break;
2909
+ case 1:
2910
+ sep = argv[0];
2911
+ break;
2912
+ default:
2913
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0 or 1)", argc);
2914
+ }
2915
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2916
+ // p = (char *) malloc((10+RSTRING(sep))*v->size + 1);
2917
+ p = (char *) malloc((10+RSTRING_LEN(sep))*v->size + 1);
2918
+ str = rb_str_new2(p);
2919
+ for (i = 0; i < v->size; i++) {
2920
+ #ifdef BASE_DOUBLE
2921
+ sprintf(buf, "%4.3e", FUNCTION(gsl_vector,get)(v, i));
2922
+ #else
2923
+ sprintf(buf, "%d", FUNCTION(gsl_vector,get)(v, i));
2924
+ #endif
2925
+ rb_str_concat(str, rb_str_new2(buf));
2926
+ if (i != v->size-1) rb_str_concat(str, sep);
2927
+ }
2928
+ return str;
2929
+ }
2930
+
2931
+ static VALUE FUNCTION(rb_gsl_vector,cumsum)(VALUE obj)
2932
+ {
2933
+ GSL_TYPE(gsl_vector) *v, *vnew;
2934
+ BASE sum = 0;
2935
+ size_t i;
2936
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2937
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
2938
+ for (i = 0; i < v->size; i++) {
2939
+ sum += FUNCTION(gsl_vector,get)(v, i);
2940
+ FUNCTION(gsl_vector,set)(vnew, i, sum);
2941
+ }
2942
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
2943
+ }
2944
+
2945
+ static VALUE FUNCTION(rb_gsl_vector,cumprod)(VALUE obj)
2946
+ {
2947
+ GSL_TYPE(gsl_vector) *v, *vnew;
2948
+ BASE prod = 1;
2949
+ size_t i;
2950
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2951
+ vnew = FUNCTION(gsl_vector,alloc)(v->size);
2952
+ for (i = 0; i < v->size; i++) {
2953
+ prod *= FUNCTION(gsl_vector,get)(v, i);
2954
+ FUNCTION(gsl_vector,set)(vnew, i, prod);
2955
+ }
2956
+ return Data_Wrap_Struct(VEC_ROW_COL(obj), 0, FUNCTION(gsl_vector,free), vnew);
2957
+ }
2958
+
2959
+ #ifdef GSL_1_9_LATER
2960
+ static VALUE FUNCTION(rb_gsl_vector,property)(VALUE obj,
2961
+ int (*f)(const GSL_TYPE(gsl_vector) *)) {
2962
+ GSL_TYPE(gsl_vector) *v;
2963
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2964
+ return INT2FIX((*f)(v));
2965
+ }
2966
+
2967
+ static VALUE FUNCTION(rb_gsl_vector,property2)(VALUE obj,
2968
+ int (*f)(const GSL_TYPE(gsl_vector) *)) {
2969
+ GSL_TYPE(gsl_vector) *v;
2970
+ Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
2971
+ if ((*f)(v)) return Qtrue;
2972
+ else return Qfalse;
2973
+ }
2974
+
2975
+ static VALUE FUNCTION(rb_gsl_vector,ispos)(VALUE obj)
2976
+ {
2977
+ return FUNCTION(rb_gsl_vector,property)(obj, FUNCTION(gsl_vector, ispos));
2978
+ }
2979
+ static VALUE FUNCTION(rb_gsl_vector,ispos2)(VALUE obj)
2980
+ {
2981
+ return FUNCTION(rb_gsl_vector,property2)(obj, FUNCTION(gsl_vector, ispos));
2982
+ }
2983
+ static VALUE FUNCTION(rb_gsl_vector,isneg)(VALUE obj)
2984
+ {
2985
+ return FUNCTION(rb_gsl_vector,property)(obj, FUNCTION(gsl_vector, isneg));
2986
+ }
2987
+ static VALUE FUNCTION(rb_gsl_vector,isneg2)(VALUE obj)
2988
+ {
2989
+ return FUNCTION(rb_gsl_vector,property2)(obj, FUNCTION(gsl_vector, isneg));
2990
+ }
2991
+ #endif
2992
+
2993
+ #ifdef GSL_1_10_LATER
2994
+ static VALUE FUNCTION(rb_gsl_vector,isnonneg)(VALUE obj)
2995
+ {
2996
+ return FUNCTION(rb_gsl_vector,property)(obj, FUNCTION(gsl_vector, isnonneg));
2997
+ }
2998
+ static VALUE FUNCTION(rb_gsl_vector,isnonneg2)(VALUE obj)
2999
+ {
3000
+ return FUNCTION(rb_gsl_vector,property2)(obj, FUNCTION(gsl_vector, isnonneg));
3001
+ }
3002
+ #endif
3003
+
3004
+ void FUNCTION(Init_gsl_vector,init)(VALUE module)
3005
+ {
3006
+ /* rb_define_singleton_method(GSL_TYPE(cgsl_vector), "new",
3007
+ FUNCTION(rb_gsl_vector,new), -1);*/
3008
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "[]",
3009
+ FUNCTION(rb_gsl_vector,new), -1);
3010
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "alloc",
3011
+ FUNCTION(rb_gsl_vector,new), -1);
3012
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "calloc",
3013
+ FUNCTION(rb_gsl_vector,calloc), 1);
3014
+
3015
+ /*****/
3016
+ rb_define_method(GSL_TYPE(cgsl_vector), "get", FUNCTION(rb_gsl_vector,get), -1);
3017
+ rb_define_alias(GSL_TYPE(cgsl_vector), "[]", "get");
3018
+ rb_define_method(GSL_TYPE(cgsl_vector), "size", FUNCTION(rb_gsl_vector,size), 0);
3019
+ rb_define_alias(GSL_TYPE(cgsl_vector), "len", "size");
3020
+ rb_define_alias(GSL_TYPE(cgsl_vector), "length", "size");
3021
+ rb_define_method(GSL_TYPE(cgsl_vector), "stride", FUNCTION(rb_gsl_vector,stride), 0);
3022
+ rb_define_method(GSL_TYPE(cgsl_vector), "set_stride", FUNCTION(rb_gsl_vector,set_stride), 1);
3023
+ rb_define_alias(GSL_TYPE(cgsl_vector), "stride=", "set_stride");
3024
+ rb_define_method(GSL_TYPE(cgsl_vector), "owner", FUNCTION(rb_gsl_vector,owner), 0);
3025
+
3026
+ rb_define_method(GSL_TYPE(cgsl_vector), "set", FUNCTION(rb_gsl_vector,set), -1);
3027
+ rb_define_alias(GSL_TYPE(cgsl_vector), "[]=", "set");
3028
+ rb_define_method(GSL_TYPE(cgsl_vector), "set_all", FUNCTION(rb_gsl_vector,set_all), 1);
3029
+ rb_define_method(GSL_TYPE(cgsl_vector), "set_zero", FUNCTION(rb_gsl_vector,set_zero), 0);
3030
+ rb_define_method(GSL_TYPE(cgsl_vector), "set_basis", FUNCTION(rb_gsl_vector,set_basis), 1);
3031
+ rb_define_method(GSL_TYPE(cgsl_vector), "each", FUNCTION(rb_gsl_vector,each), 0);
3032
+ rb_define_method(GSL_TYPE(cgsl_vector), "reverse_each", FUNCTION(rb_gsl_vector,reverse_each), 0);
3033
+ rb_define_method(GSL_TYPE(cgsl_vector), "each_index", FUNCTION(rb_gsl_vector,each_index), 0);
3034
+ rb_define_method(GSL_TYPE(cgsl_vector), "reverse_each_index", FUNCTION(rb_gsl_vector,reverse_each_index), 0);
3035
+
3036
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_a", FUNCTION(rb_gsl_vector,to_a), 0);
3037
+
3038
+ rb_define_method(GSL_TYPE(cgsl_vector), "reverse", FUNCTION(rb_gsl_vector,reverse), 0);
3039
+ rb_define_method(GSL_TYPE(cgsl_vector), "reverse!", FUNCTION(rb_gsl_vector,reverse_bang), 0);
3040
+
3041
+ rb_define_method(GSL_TYPE(cgsl_vector), "max", FUNCTION(rb_gsl_vector,max), 0);
3042
+ rb_define_method(GSL_TYPE(cgsl_vector), "min", FUNCTION(rb_gsl_vector,min), 0);
3043
+ rb_define_method(GSL_TYPE(cgsl_vector), "minmax", FUNCTION(rb_gsl_vector,minmax), 0);
3044
+ rb_define_method(GSL_TYPE(cgsl_vector), "maxmin", FUNCTION(rb_gsl_vector,maxmin), 0);
3045
+ rb_define_method(GSL_TYPE(cgsl_vector), "max_index", FUNCTION(rb_gsl_vector,max_index), 0);
3046
+ rb_define_method(GSL_TYPE(cgsl_vector), "min_index", FUNCTION(rb_gsl_vector,min_index), 0);
3047
+ rb_define_method(GSL_TYPE(cgsl_vector), "minmax_index", FUNCTION(rb_gsl_vector,minmax_index), 0);
3048
+ rb_define_method(GSL_TYPE(cgsl_vector), "maxmin_index", FUNCTION(rb_gsl_vector,maxmin_index), 0);
3049
+ rb_define_method(GSL_TYPE(cgsl_vector), "isnull", FUNCTION(rb_gsl_vector,isnull), 0);
3050
+ rb_define_method(GSL_TYPE(cgsl_vector), "isnull?", FUNCTION(rb_gsl_vector,isnull2), 0);
3051
+ /* rb_define_alias(GSL_TYPE(cgsl_vector), "none?", "isnull?");*/
3052
+ /* none? method is define below, which can have a block. */
3053
+
3054
+ rb_define_method(GSL_TYPE(cgsl_vector), "trans", FUNCTION(rb_gsl_vector,trans), 0);
3055
+ rb_define_alias(GSL_TYPE(cgsl_vector), "transpose", "trans");
3056
+ rb_define_alias(GSL_TYPE(cgsl_vector), "col", "trans");
3057
+
3058
+ rb_define_method(GSL_TYPE(cgsl_vector), "trans!", FUNCTION(rb_gsl_vector,trans_bang), 0);
3059
+ rb_define_alias(GSL_TYPE(cgsl_vector), "transpose!", "trans!");
3060
+ rb_define_alias(GSL_TYPE(cgsl_vector), "col!", "trans!");
3061
+ #ifdef BASE_DOUBLE
3062
+ rb_define_alias(cgsl_vector_col, "row", "trans");
3063
+ rb_define_alias(cgsl_vector_col, "row!", "trans!");
3064
+ #elif defined(BASE_INT)
3065
+ rb_define_alias(cgsl_vector_int_col, "row", "trans");
3066
+ rb_define_alias(cgsl_vector_int_col, "row!", "trans!");
3067
+ #endif
3068
+
3069
+ rb_define_method(GSL_TYPE(cgsl_vector), "-@", FUNCTION(rb_gsl_vector,uminus), 0);
3070
+ rb_define_method(GSL_TYPE(cgsl_vector), "+@", FUNCTION(rb_gsl_vector,uplus), 0);
3071
+
3072
+ rb_define_method(GSL_TYPE(cgsl_vector), "sum", FUNCTION(rb_gsl_vector,sum), 0);
3073
+ #ifdef BASE_INT
3074
+ /* Vector#sumsq is defined in blas1.c */
3075
+ rb_define_method(GSL_TYPE(cgsl_vector), "sumsq", FUNCTION(rb_gsl_vector,sumsq), 0);
3076
+ #endif
3077
+ rb_define_method(GSL_TYPE(cgsl_vector), "prod", FUNCTION(rb_gsl_vector,prod), 0);
3078
+
3079
+ rb_define_method(GSL_TYPE(cgsl_vector), "cumsum", FUNCTION(rb_gsl_vector,cumsum), 0);
3080
+ rb_define_method(GSL_TYPE(cgsl_vector), "cumprod", FUNCTION(rb_gsl_vector,cumprod), 0);
3081
+
3082
+ rb_define_method(GSL_TYPE(cgsl_vector), "connect",
3083
+ FUNCTION(rb_gsl_vector,connect), -1);
3084
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "connect",
3085
+ FUNCTION(rb_gsl_vector,connect), -1);
3086
+
3087
+
3088
+ rb_define_method(GSL_TYPE(cgsl_vector), "sgn", FUNCTION(rb_gsl_vector,sgn), 0);
3089
+ rb_define_alias(GSL_TYPE(cgsl_vector), "signum", "sgn");
3090
+ rb_define_method(GSL_TYPE(cgsl_vector), "abs", FUNCTION(rb_gsl_vector,abs), 0);
3091
+ rb_define_alias(GSL_TYPE(cgsl_vector), "fabs", "abs");
3092
+ rb_define_method(GSL_TYPE(cgsl_vector), "square",
3093
+ FUNCTION(rb_gsl_vector,square), 0);
3094
+ rb_define_alias(GSL_TYPE(cgsl_vector), "abs2", "square");
3095
+ rb_define_method(GSL_TYPE(cgsl_vector), "sqrt", FUNCTION(rb_gsl_vector,sqrt), 0);
3096
+
3097
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "memcpy",
3098
+ FUNCTION(rb_gsl_vector,memcpy), 2);
3099
+ rb_define_method(GSL_TYPE(cgsl_vector), "clone",
3100
+ FUNCTION(rb_gsl_vector,clone), 0);
3101
+ rb_define_alias(GSL_TYPE(cgsl_vector), "duplicate", "clone");
3102
+ rb_define_alias(GSL_TYPE(cgsl_vector), "dup", "clone");
3103
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "swap",
3104
+ FUNCTION(rb_gsl_vector,swap), 2);
3105
+ rb_define_method(GSL_TYPE(cgsl_vector), "swap_elements",
3106
+ FUNCTION(rb_gsl_vector,swap_elements), 2);
3107
+
3108
+ rb_define_method(GSL_TYPE(cgsl_vector), "fwrite",
3109
+ FUNCTION(rb_gsl_vector,fwrite), 1);
3110
+ rb_define_method(GSL_TYPE(cgsl_vector), "fread",
3111
+ FUNCTION(rb_gsl_vector,fread), 1);
3112
+ rb_define_method(GSL_TYPE(cgsl_vector), "fprintf",
3113
+ FUNCTION(rb_gsl_vector,fprintf), -1);
3114
+ rb_define_method(GSL_TYPE(cgsl_vector), "printf",
3115
+ FUNCTION(rb_gsl_vector,printf), -1);
3116
+ rb_define_method(GSL_TYPE(cgsl_vector), "fscanf",
3117
+ FUNCTION(rb_gsl_vector,fscanf), 1);
3118
+
3119
+ /* 2.Aug.2004 */
3120
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "inner_product",
3121
+ FUNCTION(rb_gsl_vector,inner_product), -1);
3122
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "dot",
3123
+ FUNCTION(rb_gsl_vector,inner_product), -1);
3124
+ rb_define_method(GSL_TYPE(cgsl_vector), "inner_product",
3125
+ FUNCTION(rb_gsl_vector,inner_product), -1);
3126
+ rb_define_alias(GSL_TYPE(cgsl_vector), "dot", "inner_product");
3127
+
3128
+ rb_define_method(GSL_TYPE(cgsl_vector), "equal?",
3129
+ FUNCTION(rb_gsl_vector,equal), -1);
3130
+ rb_define_alias(GSL_TYPE(cgsl_vector), "==", "equal?");
3131
+
3132
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_poly",
3133
+ FUNCTION(rb_gsl_vector,to_poly), 0);
3134
+
3135
+ /*****/
3136
+ rb_define_method(GSL_TYPE(cgsl_vector), "graph",
3137
+ FUNCTION(rb_gsl_vector,graph), -1);
3138
+ rb_define_method(GSL_TYPE(cgsl_vector), "graph_step",
3139
+ FUNCTION(rb_gsl_vector,graph_step), -1);
3140
+ rb_define_method(GSL_TYPE(cgsl_vector), "plot",
3141
+ FUNCTION(rb_gsl_vector,plot), -1);
3142
+
3143
+ rb_define_method(GSL_TYPE(cgsl_vector), "print",
3144
+ FUNCTION(rb_gsl_vector,print), 0);
3145
+ rb_define_method(GSL_TYPE(cgsl_vector), "inspect",
3146
+ FUNCTION(rb_gsl_vector,inspect), 0);
3147
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_s",
3148
+ FUNCTION(rb_gsl_vector,to_s), 0);
3149
+
3150
+ /*****/
3151
+ rb_define_method(GSL_TYPE(cgsl_vector), "subvector",
3152
+ FUNCTION(rb_gsl_vector,subvector), -1);
3153
+ rb_define_alias(GSL_TYPE(cgsl_vector), "view", "subvector");
3154
+ rb_define_method(GSL_TYPE(cgsl_vector), "subvector_with_stride",
3155
+ FUNCTION(rb_gsl_vector,subvector_with_stride), -1);
3156
+ rb_define_alias(GSL_TYPE(cgsl_vector), "view_with_stride", "subvector_with_stride");
3157
+
3158
+ rb_define_method(GSL_TYPE(cgsl_vector), "matrix_view",
3159
+ FUNCTION(rb_gsl_vector,matrix_view), -1);
3160
+ rb_define_method(GSL_TYPE(cgsl_vector), "matrix_view_with_tda",
3161
+ FUNCTION(rb_gsl_vector,matrix_view_with_tda), 3);
3162
+
3163
+ #ifdef BASE_DOUBLE
3164
+ rb_undef_method(cgsl_vector_view_ro, "set");
3165
+ rb_undef_method(cgsl_vector_view_ro, "[]=");
3166
+ rb_undef_method(cgsl_vector_col_view_ro, "set");
3167
+ rb_undef_method(cgsl_vector_col_view_ro, "[]=");
3168
+ #elif defined(BASE_INT)
3169
+ rb_undef_method(cgsl_vector_int_view_ro, "set");
3170
+ rb_undef_method(cgsl_vector_int_view_ro, "[]=");
3171
+ rb_undef_method(cgsl_vector_int_col_view_ro, "set");
3172
+ rb_undef_method(cgsl_vector_int_col_view_ro, "[]=");
3173
+ #endif
3174
+
3175
+ rb_define_method(GSL_TYPE(cgsl_vector), "scale",
3176
+ FUNCTION(rb_gsl_vector,scale), 1);
3177
+ rb_define_method(GSL_TYPE(cgsl_vector), "scale!",
3178
+ FUNCTION(rb_gsl_vector,scale_bang), 1);
3179
+ rb_define_method(GSL_TYPE(cgsl_vector), "add_constant",
3180
+ FUNCTION(rb_gsl_vector,add_constant), 1);
3181
+ rb_define_alias(GSL_TYPE(cgsl_vector), "add_const", "add_constant");
3182
+ rb_define_method(GSL_TYPE(cgsl_vector), "add_constant!",
3183
+ FUNCTION(rb_gsl_vector,add_constant_bang), 1);
3184
+ rb_define_alias(GSL_TYPE(cgsl_vector), "add_const!", "add_constant!");
3185
+
3186
+ #ifdef HAVE_TENSOR_TENSOR_H
3187
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_tensor",
3188
+ FUNCTION(rb_gsl_vector,to_tensor), -1);
3189
+ #endif
3190
+
3191
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "to_gplot",
3192
+ FUNCTION(rb_gsl_vector,to_gplot), -1);
3193
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "to_gsplot",
3194
+ FUNCTION(rb_gsl_vector,to_gplot), -1);
3195
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_gplot",
3196
+ FUNCTION(rb_gsl_vector,to_gplot), -1);
3197
+ rb_define_alias(GSL_TYPE(cgsl_vector), "to_gsplot", "to_gplot");
3198
+
3199
+ /*****/
3200
+ rb_define_method(GSL_TYPE(cgsl_vector), "collect",
3201
+ FUNCTION(rb_gsl_vector,collect), 0);
3202
+ rb_define_method(GSL_TYPE(cgsl_vector), "collect!",
3203
+ FUNCTION(rb_gsl_vector,collect_bang), 0);
3204
+ rb_define_alias(GSL_TYPE(cgsl_vector), "map", "collect");
3205
+ rb_define_alias(GSL_TYPE(cgsl_vector), "map!", "collect!");
3206
+
3207
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_m", FUNCTION(rb_gsl_vector,to_m), 2);
3208
+ rb_define_alias(GSL_TYPE(cgsl_vector), "to_matrix", "to_m");
3209
+ rb_define_alias(GSL_TYPE(cgsl_vector), "reshape", "to_m");
3210
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_m_diagonal",
3211
+ FUNCTION(rb_gsl_vector,to_m_diagonal), 0);
3212
+ rb_define_method(GSL_TYPE(cgsl_vector), "block",
3213
+ FUNCTION(rb_gsl_vector,block), 0);
3214
+ rb_define_method(GSL_TYPE(cgsl_vector), "to_m_circulant",
3215
+ FUNCTION(rb_gsl_vector,to_m_circulant), 0);
3216
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "indgen",
3217
+ FUNCTION(rb_gsl_vector,indgen_singleton), -1);
3218
+ rb_define_method(GSL_TYPE(cgsl_vector), "indgen",
3219
+ FUNCTION(rb_gsl_vector,indgen), -1);
3220
+ rb_define_method(GSL_TYPE(cgsl_vector), "indgen!",
3221
+ FUNCTION(rb_gsl_vector,indgen_bang), -1);
3222
+ /*****/
3223
+ rb_define_method(GSL_TYPE(cgsl_vector), "sort!",
3224
+ GSL_TYPE(rb_gsl_sort_vector), 0);
3225
+ rb_define_method(GSL_TYPE(cgsl_vector), "sort",
3226
+ GSL_TYPE(rb_gsl_sort_vector2), 0);
3227
+ rb_define_method(GSL_TYPE(cgsl_vector), "sort_index",
3228
+ FUNCTION(rb_gsl_sort_vector,index), 0);
3229
+ rb_define_method(GSL_TYPE(cgsl_vector), "sort_smallest",
3230
+ FUNCTION(rb_gsl_sort_vector,smallest), 1);
3231
+ rb_define_alias(GSL_TYPE(cgsl_vector), "smallest", "sort_smallest");
3232
+ rb_define_method(GSL_TYPE(cgsl_vector), "sort_largest",
3233
+ FUNCTION(rb_gsl_sort_vector,largest), 1);
3234
+ rb_define_alias(GSL_TYPE(cgsl_vector), "largest", "sort_largest");
3235
+ rb_define_method(GSL_TYPE(cgsl_vector), "sort_smallest_index",
3236
+ FUNCTION(rb_gsl_sort_vector,smallest_index), 1);
3237
+ rb_define_alias(GSL_TYPE(cgsl_vector), "smallest_index", "sort_smallest_index");
3238
+ rb_define_method(GSL_TYPE(cgsl_vector), "sort_largest_index",
3239
+ FUNCTION(rb_gsl_sort_vector,largest_index), 1);
3240
+ rb_define_alias(GSL_TYPE(cgsl_vector), "largest_index", "sort_largest_index");
3241
+
3242
+ /*****/
3243
+ rb_define_method(GSL_TYPE(cgsl_vector), "histogram",
3244
+ FUNCTION(rb_gsl_vector,histogram), -1);
3245
+
3246
+ rb_define_method(GSL_TYPE(cgsl_vector), "last",
3247
+ FUNCTION(rb_gsl_vector,last), 0);
3248
+ rb_define_method(GSL_TYPE(cgsl_vector), "first",
3249
+ FUNCTION(rb_gsl_vector,first), 0);
3250
+ rb_define_method(GSL_TYPE(cgsl_vector), "concat",
3251
+ FUNCTION(rb_gsl_vector,concat), 1);
3252
+
3253
+ rb_define_method(GSL_TYPE(cgsl_vector), "diff",
3254
+ FUNCTION(rb_gsl_vector,diff), -1);
3255
+ rb_define_method(GSL_TYPE(cgsl_vector), "isnan",
3256
+ FUNCTION(rb_gsl_vector,isnan), 0);
3257
+ rb_define_method(GSL_TYPE(cgsl_vector), "isinf",
3258
+ FUNCTION(rb_gsl_vector,isinf), 0);
3259
+ rb_define_method(GSL_TYPE(cgsl_vector), "finite",
3260
+ FUNCTION(rb_gsl_vector,finite), 0);
3261
+
3262
+ rb_define_method(GSL_TYPE(cgsl_vector), "isnan?",
3263
+ FUNCTION(rb_gsl_vector,isnan2), 0);
3264
+ rb_define_method(GSL_TYPE(cgsl_vector), "isinf?",
3265
+ FUNCTION(rb_gsl_vector,isinf2), 0);
3266
+ rb_define_method(GSL_TYPE(cgsl_vector), "finite?",
3267
+ FUNCTION(rb_gsl_vector,finite2), 0);
3268
+
3269
+ rb_define_method(GSL_TYPE(cgsl_vector), "delete_at",
3270
+ FUNCTION(rb_gsl_vector,delete_at), 1);
3271
+ rb_define_method(GSL_TYPE(cgsl_vector), "delete_if",
3272
+ FUNCTION(rb_gsl_vector,delete_if), 0);
3273
+ rb_define_method(GSL_TYPE(cgsl_vector), "delete",
3274
+ FUNCTION(rb_gsl_vector,delete), 1);
3275
+ /***/
3276
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "filescan", FUNCTION(rb_gsl_vector,filescan), 1);
3277
+
3278
+ /*****/
3279
+ rb_define_method(GSL_TYPE(cgsl_vector), "eq", FUNCTION(rb_gsl_vector,eq), 1);
3280
+ rb_define_method(GSL_TYPE(cgsl_vector), "ne", FUNCTION(rb_gsl_vector,ne), 1);
3281
+ rb_define_method(GSL_TYPE(cgsl_vector), "gt", FUNCTION(rb_gsl_vector,gt), 1);
3282
+ rb_define_alias(GSL_TYPE(cgsl_vector), ">", "gt");
3283
+ rb_define_method(GSL_TYPE(cgsl_vector), "ge", FUNCTION(rb_gsl_vector,ge), 1);
3284
+ rb_define_alias(GSL_TYPE(cgsl_vector), ">=", "ge");
3285
+ rb_define_method(GSL_TYPE(cgsl_vector), "lt", FUNCTION(rb_gsl_vector,lt), 1);
3286
+ rb_define_alias(GSL_TYPE(cgsl_vector), "<", "lt");
3287
+ rb_define_method(GSL_TYPE(cgsl_vector), "le", FUNCTION(rb_gsl_vector,le), 1);
3288
+ rb_define_alias(GSL_TYPE(cgsl_vector), "<=", "le");
3289
+
3290
+ rb_define_method(GSL_TYPE(cgsl_vector), "and", FUNCTION(rb_gsl_vector,and), 1);
3291
+ rb_define_method(GSL_TYPE(cgsl_vector), "or", FUNCTION(rb_gsl_vector,or), 1);
3292
+ rb_define_method(GSL_TYPE(cgsl_vector), "xor", FUNCTION(rb_gsl_vector,xor), 1);
3293
+ rb_define_method(GSL_TYPE(cgsl_vector), "not", FUNCTION(rb_gsl_vector,not), 0);
3294
+
3295
+ rb_define_method(GSL_TYPE(cgsl_vector), "all?", FUNCTION(rb_gsl_vector,all), 0);
3296
+ rb_define_method(GSL_TYPE(cgsl_vector), "none?", FUNCTION(rb_gsl_vector,none), 0);
3297
+ rb_define_method(GSL_TYPE(cgsl_vector), "any",
3298
+ FUNCTION(rb_gsl_vector,any), 0);
3299
+ rb_define_method(GSL_TYPE(cgsl_vector), "any?",
3300
+ FUNCTION(rb_gsl_vector,any2), 0);
3301
+
3302
+ rb_define_method(GSL_TYPE(cgsl_vector), "where", FUNCTION(rb_gsl_vector,where), 0);
3303
+ rb_define_method(GSL_TYPE(cgsl_vector), "where2", FUNCTION(rb_gsl_vector,where2), 0);
3304
+
3305
+ rb_define_method(GSL_TYPE(cgsl_vector), "add!", FUNCTION(rb_gsl_vector,add_inplace), 1);
3306
+ rb_define_method(GSL_TYPE(cgsl_vector), "sub!", FUNCTION(rb_gsl_vector,sub_inplace), 1);
3307
+ rb_define_method(GSL_TYPE(cgsl_vector), "mul!", FUNCTION(rb_gsl_vector,mul_inplace), 1);
3308
+ rb_define_method(GSL_TYPE(cgsl_vector), "div!", FUNCTION(rb_gsl_vector,div_inplace), 1);
3309
+
3310
+ rb_define_singleton_method(GSL_TYPE(cgsl_vector), "zip", FUNCTION(rb_gsl_vector,zip), -1);
3311
+ rb_define_method(GSL_TYPE(cgsl_vector), "zip", FUNCTION(rb_gsl_vector,zip), -1);
3312
+ rb_define_method(GSL_TYPE(cgsl_vector), "join", FUNCTION(rb_gsl_vector,join), -1);
3313
+ #ifdef GSL_1_9_LATER
3314
+ rb_define_method(GSL_TYPE(cgsl_vector), "ispos", FUNCTION(rb_gsl_vector,ispos), 0);
3315
+ rb_define_method(GSL_TYPE(cgsl_vector), "ispos?", FUNCTION(rb_gsl_vector,ispos2), 0);
3316
+ rb_define_method(GSL_TYPE(cgsl_vector), "isneg", FUNCTION(rb_gsl_vector,isneg), 0);
3317
+ rb_define_method(GSL_TYPE(cgsl_vector), "isneg?", FUNCTION(rb_gsl_vector,isneg2), 0);
3318
+ #endif
3319
+
3320
+ #ifdef GSL_1_10_LATER
3321
+ rb_define_method(GSL_TYPE(cgsl_vector), "isnonneg", FUNCTION(rb_gsl_vector,isnonneg), 0);
3322
+ rb_define_method(GSL_TYPE(cgsl_vector), "isnonneg?", FUNCTION(rb_gsl_vector,isnonneg2), 0);
3323
+ #endif
3324
+ }
3325
+
3326
+ #undef NUMCONV
3327
+ #undef NUMCONV2
3328
+ #undef PRINTF_FORMAT
3329
+ #undef VEC_ROW_COL
3330
+ #undef VEC_P
3331
+ #undef C_TO_VALUE
3332
+ #undef C_TO_VALUE2
3333
+ #undef VEC_COL_P
3334
+ #undef VEC_ROW_P
3335
+ #undef CHECK_VEC
3336
+ #undef VEC_VIEW_P