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,171 @@
1
+ /*
2
+ qrng.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2001-2006 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+ #include "rb_gsl_config.h"
12
+ #include "rb_gsl_rng.h"
13
+ #include "rb_gsl_array.h"
14
+ #include <gsl/gsl_qrng.h>
15
+ #ifdef HAVE_QRNGEXTRA_QRNGEXTRA_H
16
+ #include <qrngextra/qrngextra.h>
17
+ #endif
18
+
19
+ enum rb_gsl_qrng_generator {
20
+ GSL_QRNG_NIEDERREITER_2,
21
+ GSL_QRNG_SOBOL,
22
+ GSL_QRNG_HALTON,
23
+ GSL_QRNG_REVERSEHALTON,
24
+ #ifdef HAVE_QRNGEXTRA_QRNGEXTRA_H
25
+ GSL_QRNG_HDSOBOL,
26
+ #endif
27
+ };
28
+
29
+ static const gsl_qrng_type* get_gsl_qrng_type(VALUE t);
30
+
31
+ static const gsl_qrng_type* get_gsl_qrng_type(VALUE t)
32
+ {
33
+ const gsl_qrng_type *T;
34
+ char name[32];
35
+
36
+ switch (TYPE(t)) {
37
+ case T_STRING:
38
+ strcpy(name, STR2CSTR(t));
39
+ if (strstr(name, "niederreiter_2")) return T = gsl_qrng_niederreiter_2;
40
+ #ifdef HAVE_QRNGEXTRA_QRNGEXTRA_H
41
+ else if (strstr(name, "hdsobol")) return T = qrngextra_hdsobol;
42
+ #endif
43
+ else if (strstr(name, "sobol")) return T = gsl_qrng_sobol;
44
+ #ifdef GSL_1_11_LATER
45
+ else if (strstr(name, "reversehalton")) return T = gsl_qrng_reversehalton;
46
+ else if (strstr(name, "halton")) return T = gsl_qrng_halton;
47
+
48
+ #endif
49
+ else rb_raise(rb_eArgError, "unknown type");
50
+ break;
51
+ case T_FIXNUM:
52
+ switch (FIX2INT(t)) {
53
+ case GSL_QRNG_NIEDERREITER_2: T = gsl_qrng_niederreiter_2; break;
54
+ case GSL_QRNG_SOBOL: T = gsl_qrng_sobol; break;
55
+ #ifdef GSL_1_11_LATER
56
+ case GSL_QRNG_HALTON: T = gsl_qrng_halton; break;
57
+ case GSL_QRNG_REVERSEHALTON: T = gsl_qrng_reversehalton; break;
58
+ #endif
59
+ #ifdef HAVE_QRNGEXTRA_QRNGEXTRA_H
60
+ case GSL_QRNG_HDSOBOL: T = qrngextra_hdsobol; break;
61
+ #endif
62
+ default:
63
+ rb_raise(rb_eArgError, "unknown type");
64
+ }
65
+ break;
66
+ default:
67
+ rb_raise(rb_eTypeError, "wrong argument type %s (String or Fixnum expected)",
68
+ rb_class2name(CLASS_OF(t)));
69
+ }
70
+ return T;
71
+ }
72
+
73
+ static VALUE rb_gsl_qrng_new(VALUE klass, VALUE t, VALUE dd)
74
+ {
75
+ unsigned int d;
76
+ gsl_qrng *q;
77
+ const gsl_qrng_type *T;
78
+ d = NUM2UINT(dd);
79
+ T = get_gsl_qrng_type(t);
80
+ q = gsl_qrng_alloc(T, d);
81
+ return Data_Wrap_Struct(klass, 0, gsl_qrng_free, q);
82
+ }
83
+
84
+ #ifdef GSL_1_2_LATER
85
+ static VALUE rb_gsl_qrng_init(VALUE obj)
86
+ {
87
+ gsl_qrng *q = NULL;
88
+ Data_Get_Struct(obj, gsl_qrng, q);
89
+ gsl_qrng_init(q);
90
+ return obj;
91
+ }
92
+ #endif
93
+
94
+ static VALUE rb_gsl_qrng_name(VALUE obj)
95
+ {
96
+ gsl_qrng *q = NULL;
97
+ Data_Get_Struct(obj, gsl_qrng, q);
98
+ return rb_str_new2(gsl_qrng_name(q));
99
+ }
100
+
101
+ static VALUE rb_gsl_qrng_size(VALUE obj)
102
+ {
103
+ gsl_qrng *q = NULL;
104
+ Data_Get_Struct(obj, gsl_qrng, q);
105
+ return INT2FIX(gsl_qrng_size(q));
106
+ }
107
+
108
+ static VALUE rb_gsl_qrng_clone(VALUE obj)
109
+ {
110
+ gsl_qrng *q = NULL, *q2 = NULL;
111
+ Data_Get_Struct(obj, gsl_qrng, q);
112
+ q2 = gsl_qrng_clone(q);
113
+ return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_qrng_free, q2);
114
+ }
115
+
116
+ /* singleton */
117
+ static VALUE rb_gsl_qrng_memcpy(VALUE obj, VALUE dest, VALUE src)
118
+ {
119
+ gsl_qrng *q = NULL, *q2 = NULL;
120
+ Data_Get_Struct(dest, gsl_qrng, q);
121
+ Data_Get_Struct(src, gsl_qrng, q2);
122
+ gsl_qrng_memcpy(q, q2);
123
+ return dest;
124
+ }
125
+
126
+ static VALUE rb_gsl_qrng_get(int argc, VALUE *argv, VALUE obj)
127
+ {
128
+ gsl_qrng *q = NULL;
129
+ gsl_vector *v;
130
+ Data_Get_Struct(obj, gsl_qrng, q);
131
+ if (argc == 0) {
132
+ v = gsl_vector_alloc(q->dimension);
133
+ gsl_qrng_get(q, v->data);
134
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
135
+ } else {
136
+ if (!rb_obj_is_kind_of(argv[0], cgsl_vector)) {
137
+ rb_raise(rb_eArgError, "wrong type argument (GSL_Vector required)");
138
+ }
139
+ Data_Get_Struct(argv[0], gsl_vector, v);
140
+ return INT2FIX(gsl_qrng_get(q, v->data));
141
+ }
142
+ }
143
+
144
+ void Init_gsl_qrng(VALUE module)
145
+ {
146
+ VALUE cgsl_qrng;
147
+ cgsl_qrng = rb_define_class_under(module, "QRng", cGSL_Object);
148
+
149
+ rb_define_singleton_method(cgsl_qrng, "new", rb_gsl_qrng_new, 2);
150
+ rb_define_singleton_method(cgsl_qrng, "alloc", rb_gsl_qrng_new, 2);
151
+ #ifdef GSL_1_2_LATER
152
+ rb_define_method(cgsl_qrng, "init", rb_gsl_qrng_init, 0);
153
+ #endif
154
+ rb_define_method(cgsl_qrng, "name", rb_gsl_qrng_name, 0);
155
+ rb_define_method(cgsl_qrng, "size", rb_gsl_qrng_size, 0);
156
+ rb_define_method(cgsl_qrng, "clone", rb_gsl_qrng_clone, 0);
157
+ rb_define_alias(cgsl_qrng, "duplicate", "clone");
158
+ rb_define_singleton_method(cgsl_qrng, "memcpy", rb_gsl_qrng_memcpy, 2);
159
+
160
+ rb_define_method(cgsl_qrng, "get", rb_gsl_qrng_get, -1);
161
+
162
+ rb_define_const(cgsl_qrng, "NIEDERREITER_2", INT2FIX(GSL_QRNG_NIEDERREITER_2));
163
+ rb_define_const(cgsl_qrng, "SOBOL", INT2FIX(GSL_QRNG_SOBOL));
164
+ #ifdef GSL_1_11_LATER
165
+ rb_define_const(cgsl_qrng, "HALTON", INT2FIX(GSL_QRNG_HALTON));
166
+ rb_define_const(cgsl_qrng, "REVERSEHALTON", INT2FIX(GSL_QRNG_REVERSEHALTON));
167
+ #endif
168
+ #ifdef HAVE_QRNGEXTRA_QRNGEXTRA_H
169
+ rb_define_const(cgsl_qrng, "HDSOBOL", INT2FIX(GSL_QRNG_HDSOBOL));
170
+ #endif
171
+ }
@@ -0,0 +1,1873 @@
1
+ /*
2
+ randist.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2001-2006 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+ #include "rb_gsl_config.h"
12
+ #include "rb_gsl_array.h"
13
+ #include "rb_gsl_common.h"
14
+ #include "rb_gsl_rng.h"
15
+ #include <gsl/gsl_randist.h>
16
+
17
+ VALUE rb_gsl_eval_pdf_cdf(VALUE xx, double (*f)(double));
18
+ VALUE rb_gsl_eval_pdf_cdf2(VALUE xx, VALUE aa, double (*f)(double, double));
19
+ VALUE rb_gsl_eval_pdf_cdf3(VALUE xx, VALUE aa, VALUE bb,
20
+ double (*f)(double, double, double));
21
+ VALUE rb_gsl_eval_pdf_cdf2_uint(VALUE xx, VALUE aa,
22
+ double (*f)(unsigned int, double));
23
+
24
+ static VALUE rb_gsl_ran_eval0(int argc, VALUE *argv, VALUE obj,
25
+ double (*f)(const gsl_rng*))
26
+ {
27
+ gsl_rng *r;
28
+ switch (TYPE(obj)) {
29
+ case T_MODULE: case T_CLASS: case T_OBJECT:
30
+ switch (argc) {
31
+ case 1:
32
+ CHECK_RNG(argv[0]);
33
+ Data_Get_Struct(argv[0], gsl_rng, r);
34
+ break;
35
+ default:
36
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
37
+ break;
38
+ }
39
+ break;
40
+ default:
41
+ switch (argc) {
42
+ case 0:
43
+ break;
44
+ default:
45
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
46
+ break;
47
+ }
48
+ Data_Get_Struct(obj, gsl_rng, r);
49
+ break;
50
+ }
51
+ return rb_float_new((*f)(r));
52
+ }
53
+
54
+ static VALUE rb_gsl_ran_eval1(int argc, VALUE *argv, VALUE obj,
55
+ double (*f)(const gsl_rng*, double))
56
+ {
57
+ gsl_rng *r;
58
+ gsl_vector *v;
59
+ size_t n, i;
60
+ double a;
61
+ switch (TYPE(obj)) {
62
+ case T_MODULE: case T_CLASS: case T_OBJECT:
63
+ switch (argc) {
64
+ case 3:
65
+ n = NUM2INT(argv[2]);
66
+ a = NUM2DBL(argv[1]);
67
+ CHECK_RNG(argv[0]);
68
+ Data_Get_Struct(argv[0], gsl_rng, r);
69
+ v = gsl_vector_alloc(n);
70
+ for (i = 0; i < n; i++)
71
+ gsl_vector_set(v, i, (*f)(r, a));
72
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
73
+ break;
74
+ case 2:
75
+ CHECK_RNG(argv[0]);
76
+ Data_Get_Struct(argv[0], gsl_rng, r);
77
+ a = NUM2DBL(argv[1]);
78
+ break;
79
+ default:
80
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
81
+ break;
82
+ }
83
+ break;
84
+ default:
85
+ switch (argc) {
86
+ case 2:
87
+ n = NUM2INT(argv[1]);
88
+ a = NUM2DBL(argv[0]);
89
+ Data_Get_Struct(obj, gsl_rng, r);
90
+ v = gsl_vector_alloc(n);
91
+ for (i = 0; i < n; i++)
92
+ gsl_vector_set(v, i, (*f)(r, a));
93
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
94
+ break;
95
+ case 1:
96
+ a = NUM2DBL(argv[0]);
97
+ break;
98
+ default:
99
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
100
+ break;
101
+ }
102
+ Data_Get_Struct(obj, gsl_rng, r);
103
+ break;
104
+ }
105
+ return rb_float_new((*f)(r, a));
106
+ }
107
+
108
+ static VALUE rb_gsl_ran_eval1_uint(int argc, VALUE *argv, VALUE obj,
109
+ unsigned int (*f)(const gsl_rng*, double))
110
+ {
111
+ gsl_rng *r;
112
+ gsl_vector_int *v;
113
+ size_t n, i;
114
+ double a;
115
+ switch (TYPE(obj)) {
116
+ case T_MODULE: case T_CLASS: case T_OBJECT:
117
+ switch (argc) {
118
+ case 3:
119
+ n = NUM2INT(argv[2]);
120
+ a = NUM2DBL(argv[1]);
121
+ CHECK_RNG(argv[0]);
122
+ Data_Get_Struct(argv[0], gsl_rng, r);
123
+ v = gsl_vector_int_alloc(n);
124
+ for (i = 0; i < n; i++)
125
+ gsl_vector_int_set(v, i, (int) (*f)(r, a));
126
+ return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, v);
127
+ break;
128
+ case 2:
129
+ CHECK_RNG(argv[0]);
130
+ Data_Get_Struct(argv[0], gsl_rng, r);
131
+ a = NUM2DBL(argv[1]);
132
+ break;
133
+ default:
134
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
135
+ break;
136
+ }
137
+ break;
138
+ default:
139
+ switch (argc) {
140
+ case 2:
141
+ n = NUM2INT(argv[1]);
142
+ a = NUM2DBL(argv[0]);
143
+ Data_Get_Struct(obj, gsl_rng, r);
144
+ v = gsl_vector_int_alloc(n);
145
+ for (i = 0; i < n; i++)
146
+ gsl_vector_int_set(v, i, (*f)(r, a));
147
+ return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, v);
148
+ break;
149
+ case 1:
150
+ a = NUM2DBL(argv[0]);
151
+ break;
152
+ default:
153
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
154
+ break;
155
+ }
156
+ Data_Get_Struct(obj, gsl_rng, r);
157
+ break;
158
+ }
159
+ return INT2FIX((*f)(r, a));
160
+ }
161
+
162
+ static VALUE rb_gsl_ran_eval2(int argc, VALUE *argv, VALUE obj,
163
+ double (*f)(const gsl_rng*, double, double))
164
+ {
165
+ gsl_rng *r;
166
+ gsl_vector *v;
167
+ size_t n, i;
168
+ double a, b;
169
+ switch (TYPE(obj)) {
170
+ case T_MODULE: case T_CLASS: case T_OBJECT:
171
+ switch (argc) {
172
+ case 4:
173
+ CHECK_RNG(argv[0]);
174
+ Data_Get_Struct(argv[0], gsl_rng, r);
175
+ a = NUM2DBL(argv[1]); b = NUM2DBL(argv[2]);
176
+ n = NUM2INT(argv[3]);
177
+ v = gsl_vector_alloc(n);
178
+ for (i = 0; i < n; i++) gsl_vector_set(v, i, (*f)(r, a, b));
179
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
180
+ break;
181
+ case 3:
182
+ CHECK_RNG(argv[0]);
183
+ Data_Get_Struct(argv[0], gsl_rng, r);
184
+ a = NUM2DBL(argv[1]); b = NUM2DBL(argv[2]);
185
+ break;
186
+ default:
187
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
188
+ break;
189
+ }
190
+ break;
191
+ default:
192
+ switch (argc) {
193
+ case 3:
194
+ Data_Get_Struct(obj, gsl_rng, r);
195
+ a = NUM2DBL(argv[0]); b = NUM2DBL(argv[1]);
196
+ n = NUM2INT(argv[2]);
197
+ v = gsl_vector_alloc(n);
198
+ for (i = 0; i < n; i++) gsl_vector_set(v, i, (*f)(r, a, b));
199
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
200
+ break;
201
+ case 2:
202
+ a = NUM2DBL(argv[0]); b = NUM2DBL(argv[1]);
203
+ break;
204
+ default:
205
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
206
+ break;
207
+ }
208
+ Data_Get_Struct(obj, gsl_rng, r);
209
+ break;
210
+ }
211
+ return rb_float_new((*f)(r, a, b));
212
+ }
213
+
214
+ static VALUE rb_gsl_ran_eval3(int argc, VALUE *argv, VALUE obj,
215
+ double (*f)(const gsl_rng*, double, double, double))
216
+ {
217
+ gsl_rng *r;
218
+ gsl_vector *v;
219
+ size_t n, i;
220
+ double a, b, c;
221
+ switch (TYPE(obj)) {
222
+ case T_MODULE: case T_CLASS: case T_OBJECT:
223
+ switch (argc) {
224
+ case 5:
225
+ CHECK_RNG(argv[0]);
226
+ Data_Get_Struct(argv[0], gsl_rng, r);
227
+ a = NUM2DBL(argv[1]); b = NUM2DBL(argv[2]); c = NUM2DBL(argv[3]);
228
+ n = NUM2INT(argv[4]);
229
+ v = gsl_vector_alloc(n);
230
+ for (i = 0; i < n; i++) gsl_vector_set(v, i, (*f)(r, a, b, c));
231
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
232
+ break;
233
+ case 4:
234
+ CHECK_RNG(argv[0]);
235
+ Data_Get_Struct(argv[0], gsl_rng, r);
236
+ a = NUM2DBL(argv[1]); b = NUM2DBL(argv[2]); c = NUM2DBL(argv[3]);
237
+ break;
238
+ default:
239
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 4)", argc);
240
+ break;
241
+ }
242
+ break;
243
+ default:
244
+ switch (argc) {
245
+ case 4:
246
+ Data_Get_Struct(obj, gsl_rng, r);
247
+ a = NUM2DBL(argv[0]); b = NUM2DBL(argv[1]); c = NUM2DBL(argv[2]);
248
+ n = NUM2INT(argv[3]);
249
+ v = gsl_vector_alloc(n);
250
+ for (i = 0; i < n; i++) gsl_vector_set(v, i, (*f)(r, a, b, c));
251
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
252
+ break;
253
+ case 3:
254
+ a = NUM2DBL(argv[0]); b = NUM2DBL(argv[1]); c = NUM2DBL(argv[2]);
255
+ break;
256
+ default:
257
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
258
+ break;
259
+ }
260
+ Data_Get_Struct(obj, gsl_rng, r);
261
+ break;
262
+ }
263
+ return rb_float_new((*f)(r, a, b, c));
264
+ }
265
+
266
+ static VALUE rb_gsl_ran_gaussian(int argc, VALUE *argv, VALUE obj)
267
+ {
268
+ gsl_rng *r = NULL;
269
+ gsl_vector *v;
270
+ size_t n, i;
271
+ double sigma = 1.0;
272
+ switch (TYPE(obj)) {
273
+ case T_MODULE: case T_CLASS: case T_OBJECT:
274
+ switch (argc) {
275
+ case 3:
276
+ n = NUM2INT(argv[2]);
277
+ sigma = NUM2DBL(argv[1]);
278
+ CHECK_RNG(argv[0]);
279
+ Data_Get_Struct(argv[0], gsl_rng, r);
280
+ v = gsl_vector_alloc(n);
281
+ for (i = 0; i < n; i++)
282
+ gsl_vector_set(v, i, gsl_ran_gaussian(r, sigma));
283
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
284
+ break;
285
+ case 2:
286
+ sigma = NUM2DBL(argv[1]);
287
+ /* no break */
288
+ case 1:
289
+ CHECK_RNG(argv[0]);
290
+ Data_Get_Struct(argv[0], gsl_rng, r);
291
+ return rb_float_new(gsl_ran_gaussian(r, sigma));
292
+ break;
293
+ default:
294
+ rb_raise(rb_eArgError, "too many arguments (%d for 1 or 2)", argc);
295
+ return Qnil;
296
+ break;
297
+ }
298
+ break;
299
+ default:
300
+ Data_Get_Struct(obj, gsl_rng, r);
301
+ switch (argc) {
302
+ case 2:
303
+ n = NUM2INT(argv[1]);
304
+ sigma = NUM2DBL(argv[0]);
305
+ v = gsl_vector_alloc(n);
306
+ for (i = 0; i < n; i++)
307
+ gsl_vector_set(v, i, gsl_ran_gaussian(r, sigma));
308
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
309
+ break;
310
+ case 1:
311
+ sigma = NUM2DBL(argv[0]);
312
+ /* no break */
313
+ case 0:
314
+ return rb_float_new(gsl_ran_gaussian(r, sigma));
315
+ break;
316
+ default:
317
+ rb_raise(rb_eArgError, "too many arguments (%d for 0 or 1)", argc);
318
+ return Qnil;
319
+ break;
320
+ }
321
+ break;
322
+ }
323
+ return Qnil;
324
+ }
325
+
326
+ static VALUE rb_gsl_ran_gaussian_ratio_method(int argc, VALUE *argv, VALUE obj)
327
+ {
328
+ gsl_rng *r = NULL;
329
+ double sigma = 1.0;
330
+ switch (TYPE(obj)) {
331
+ case T_MODULE: case T_CLASS: case T_OBJECT:
332
+ switch (argc) {
333
+ case 2:
334
+ sigma = NUM2DBL(argv[1]);
335
+ /* no break */
336
+ case 1:
337
+ CHECK_RNG(argv[0]);
338
+ Data_Get_Struct(argv[0], gsl_rng, r);
339
+ return rb_float_new(gsl_ran_gaussian_ratio_method(r, sigma));
340
+ break;
341
+ default:
342
+ rb_raise(rb_eArgError, "too many arguments (%d for 1 or 2)", argc);
343
+ break;
344
+ }
345
+ break;
346
+ default:
347
+ Data_Get_Struct(obj, gsl_rng, r);
348
+ switch (argc) {
349
+ case 1:
350
+ sigma = NUM2DBL(argv[0]);
351
+ /* no break */
352
+ case 0:
353
+ return rb_float_new(gsl_ran_gaussian_ratio_method(r, sigma));
354
+ break;
355
+ default:
356
+ rb_raise(rb_eArgError, "too many arguments (%d for 0 or 1)", argc);
357
+ break;
358
+ }
359
+ break;
360
+ }
361
+ return Qnil;
362
+ }
363
+
364
+ static VALUE rb_gsl_ran_gaussian_pdf(int argc, VALUE *argv, VALUE obj)
365
+ {
366
+ if (argc == 1) {
367
+ return rb_gsl_eval_pdf_cdf(argv[0], gsl_ran_ugaussian_pdf);
368
+ } else if (argc == 2) {
369
+ return rb_gsl_eval_pdf_cdf2(argv[0], argv[1], gsl_ran_gaussian_pdf);
370
+ } else {
371
+ rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
372
+ }
373
+ }
374
+
375
+ static VALUE rb_gsl_ran_gaussian_tail(int argc, VALUE *argv, VALUE obj)
376
+ {
377
+ gsl_rng *r = NULL;
378
+ gsl_vector *v;
379
+ size_t n, i;
380
+ double a, sigma = 1.0;
381
+ switch (TYPE(obj)) {
382
+ case T_MODULE: case T_CLASS: case T_OBJECT:
383
+ switch (argc) {
384
+ case 4:
385
+ n = NUM2INT(argv[3]);
386
+ sigma = NUM2DBL(argv[2]);
387
+ a = NUM2DBL(argv[1]);
388
+ CHECK_RNG(argv[0]);
389
+ Data_Get_Struct(argv[0], gsl_rng, r);
390
+ v = gsl_vector_alloc(n);
391
+ for (i = 0; i < n; i++)
392
+ gsl_vector_set(v, i, gsl_ran_gaussian_tail(r, a, sigma));
393
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
394
+ break;
395
+ case 3:
396
+ sigma = NUM2DBL(argv[2]);
397
+ /* no break */
398
+ case 2:
399
+ CHECK_RNG(argv[0]);
400
+ Data_Get_Struct(argv[0], gsl_rng, r);
401
+ a = NUM2DBL(argv[1]);
402
+ return rb_float_new(gsl_ran_gaussian_tail(r, a, sigma));
403
+ break;
404
+ default:
405
+ rb_raise(rb_eArgError, "too many arguments (%d for 2 or 3)", argc);
406
+ break;
407
+ }
408
+ break;
409
+ default:
410
+ Data_Get_Struct(obj, gsl_rng, r);
411
+ switch (argc) {
412
+ case 3:
413
+ n = NUM2INT(argv[2]);
414
+ sigma = NUM2DBL(argv[1]);
415
+ a = NUM2DBL(argv[0]);
416
+ v = gsl_vector_alloc(n);
417
+ for (i = 0; i < n; i++)
418
+ gsl_vector_set(v, i, gsl_ran_gaussian_tail(r, a, sigma));
419
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
420
+ break;
421
+ case 2:
422
+ sigma = NUM2DBL(argv[1]);
423
+ /* no break */
424
+ case 1:
425
+ a = NUM2DBL(argv[0]);
426
+ return rb_float_new(gsl_ran_gaussian_tail(r, a, sigma));
427
+ break;
428
+ default:
429
+ rb_raise(rb_eArgError, "too many arguments (%d for 1 or 2)", argc);
430
+ break;
431
+ }
432
+ break;
433
+ }
434
+ }
435
+
436
+ static VALUE rb_gsl_ran_gaussian_tail_pdf(int argc, VALUE *argv, VALUE obj)
437
+ {
438
+ switch (argc) {
439
+ case 2:
440
+ return rb_gsl_eval_pdf_cdf2(argv[0], argv[1], gsl_ran_ugaussian_tail_pdf);
441
+ break;
442
+ case 3:
443
+ return rb_gsl_eval_pdf_cdf3(argv[0], argv[1], argv[2], gsl_ran_gaussian_tail_pdf);
444
+ break;
445
+ default:
446
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
447
+ break;
448
+ }
449
+ }
450
+
451
+ static VALUE rb_gsl_ran_bivariate_gaussian(int argc, VALUE *argv, VALUE obj)
452
+ {
453
+ gsl_rng *r = NULL;
454
+ double sigmax, sigmay, x, y, rho;
455
+ switch (TYPE(obj)) {
456
+ case T_MODULE: case T_CLASS: case T_OBJECT:
457
+ switch (argc) {
458
+ case 4:
459
+ CHECK_RNG(argv[0]);
460
+ Data_Get_Struct(argv[0], gsl_rng, r);
461
+ sigmax = NUM2DBL(argv[1]); sigmay = NUM2DBL(argv[2]);
462
+ rho = NUM2DBL(argv[3]);
463
+ break;
464
+ default:
465
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 4)", argc);
466
+ break;
467
+ }
468
+ break;
469
+ default:
470
+ switch (argc) {
471
+ case 3:
472
+ Data_Get_Struct(obj, gsl_rng, r);
473
+ sigmax = NUM2DBL(argv[0]); sigmay = NUM2DBL(argv[1]);
474
+ rho = NUM2DBL(argv[2]);
475
+ break;
476
+ default:
477
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
478
+ break;
479
+ }
480
+ break;
481
+ }
482
+ gsl_ran_bivariate_gaussian(r, sigmax, sigmay, rho, &x, &y);
483
+ return rb_ary_new3(2, rb_float_new(x), rb_float_new(y));
484
+ }
485
+
486
+ static VALUE rb_gsl_ran_bivariate_gaussian_pdf(VALUE obj, VALUE x, VALUE y, VALUE sx, VALUE sy, VALUE rr)
487
+ {
488
+ Need_Float(x); Need_Float(y);
489
+ Need_Float(sx); Need_Float(sy); Need_Float(rr);
490
+ return rb_float_new(gsl_ran_bivariate_gaussian_pdf(NUM2DBL(x), NUM2DBL(y), NUM2DBL(sx), NUM2DBL(sy), NUM2DBL(rr)));
491
+ }
492
+
493
+ static VALUE rb_gsl_ran_exponential(int argc, VALUE *argv, VALUE obj)
494
+ {
495
+ return rb_gsl_ran_eval1(argc, argv, obj, gsl_ran_exponential);
496
+ }
497
+
498
+ static VALUE rb_gsl_ran_exponential_pdf(VALUE obj, VALUE x, VALUE mu)
499
+ {
500
+ return rb_gsl_eval_pdf_cdf2(x, mu, gsl_ran_exponential_pdf);
501
+ }
502
+
503
+ static VALUE rb_gsl_ran_laplace(int argc, VALUE *argv, VALUE obj)
504
+ {
505
+ return rb_gsl_ran_eval1(argc, argv, obj, gsl_ran_laplace);
506
+ }
507
+
508
+ static VALUE rb_gsl_ran_laplace_pdf(VALUE obj, VALUE x, VALUE mu)
509
+ {
510
+ return rb_gsl_eval_pdf_cdf2(x, mu, gsl_ran_laplace_pdf);
511
+ }
512
+
513
+ static VALUE rb_gsl_ran_exppow(int argc, VALUE *argv, VALUE obj)
514
+ {
515
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_exppow);
516
+ }
517
+
518
+ static VALUE rb_gsl_ran_exppow_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
519
+ {
520
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_exppow_pdf);
521
+ }
522
+
523
+ static VALUE rb_gsl_ran_cauchy(int argc, VALUE *argv, VALUE obj)
524
+ {
525
+ return rb_gsl_ran_eval1(argc, argv, obj, gsl_ran_cauchy);
526
+ }
527
+
528
+ static VALUE rb_gsl_ran_cauchy_pdf(VALUE obj, VALUE x, VALUE mu)
529
+ {
530
+ return rb_gsl_eval_pdf_cdf2(x, mu, gsl_ran_cauchy_pdf);
531
+ }
532
+
533
+ static VALUE rb_gsl_ran_rayleigh(int argc, VALUE *argv, VALUE obj)
534
+ {
535
+ return rb_gsl_ran_eval1(argc, argv, obj, gsl_ran_rayleigh);
536
+ }
537
+
538
+ static VALUE rb_gsl_ran_rayleigh_pdf(VALUE obj, VALUE x, VALUE a)
539
+ {
540
+ return rb_gsl_eval_pdf_cdf2(x, a, gsl_ran_rayleigh_pdf);
541
+ }
542
+
543
+ static VALUE rb_gsl_ran_rayleigh_tail(int argc, VALUE *argv, VALUE obj)
544
+ {
545
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_rayleigh_tail);
546
+ }
547
+
548
+ static VALUE rb_gsl_ran_rayleigh_tail_pdf(VALUE obj, VALUE x, VALUE a, VALUE s)
549
+ {
550
+ return rb_gsl_eval_pdf_cdf3(x, a, s, gsl_ran_rayleigh_tail_pdf);
551
+ }
552
+
553
+ static VALUE rb_gsl_ran_landau(int argc, VALUE *argv, VALUE obj)
554
+ {
555
+ return rb_gsl_ran_eval0(argc, argv, obj, gsl_ran_landau);
556
+ }
557
+
558
+ static VALUE rb_gsl_ran_landau_pdf(VALUE obj, VALUE x)
559
+ {
560
+ return rb_gsl_eval_pdf_cdf(x, gsl_ran_landau_pdf);
561
+ }
562
+
563
+ static VALUE rb_gsl_ran_levy(int argc, VALUE *argv, VALUE obj)
564
+ {
565
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_levy);
566
+ }
567
+
568
+ static VALUE rb_gsl_ran_levy_skew(int argc, VALUE *argv, VALUE obj)
569
+ {
570
+ return rb_gsl_ran_eval3(argc, argv, obj, gsl_ran_levy_skew);
571
+ }
572
+
573
+ static VALUE rb_gsl_ran_gamma(int argc, VALUE *argv, VALUE obj)
574
+ {
575
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_gamma);
576
+ }
577
+
578
+ static VALUE rb_gsl_ran_gamma_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
579
+ {
580
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_gamma_pdf);
581
+ }
582
+
583
+ static VALUE rb_gsl_ran_flat(int argc, VALUE *argv, VALUE obj)
584
+ {
585
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_flat);
586
+ }
587
+
588
+ static VALUE rb_gsl_ran_flat_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
589
+ {
590
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_flat_pdf);
591
+ }
592
+
593
+ static VALUE rb_gsl_ran_lognormal(int argc, VALUE *argv, VALUE obj)
594
+ {
595
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_lognormal);
596
+ }
597
+
598
+ static VALUE rb_gsl_ran_lognormal_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
599
+ {
600
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_lognormal_pdf);
601
+ }
602
+
603
+ static VALUE rb_gsl_ran_chisq(int argc, VALUE *argv, VALUE obj)
604
+ {
605
+ return rb_gsl_ran_eval1(argc, argv, obj, gsl_ran_chisq);
606
+ }
607
+
608
+ static VALUE rb_gsl_ran_chisq_pdf(VALUE obj, VALUE x, VALUE mu)
609
+ {
610
+ return rb_gsl_eval_pdf_cdf2(x, mu, gsl_ran_chisq_pdf);
611
+ }
612
+
613
+ static VALUE rb_gsl_ran_fdist(int argc, VALUE *argv, VALUE obj)
614
+ {
615
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_fdist);
616
+ }
617
+
618
+ static VALUE rb_gsl_ran_fdist_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
619
+ {
620
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_fdist_pdf);
621
+ }
622
+
623
+ static VALUE rb_gsl_ran_tdist(int argc, VALUE *argv, VALUE obj)
624
+ {
625
+ return rb_gsl_ran_eval1(argc, argv, obj, gsl_ran_tdist);
626
+ }
627
+
628
+ static VALUE rb_gsl_ran_tdist_pdf(VALUE obj, VALUE x, VALUE mu)
629
+ {
630
+ return rb_gsl_eval_pdf_cdf2(x, mu, gsl_ran_tdist_pdf);
631
+ }
632
+
633
+ static VALUE rb_gsl_ran_beta(int argc, VALUE *argv, VALUE obj)
634
+ {
635
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_beta);
636
+ }
637
+
638
+ static VALUE rb_gsl_ran_beta_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
639
+ {
640
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_beta_pdf);
641
+ }
642
+
643
+ static VALUE rb_gsl_ran_logistic(int argc, VALUE *argv, VALUE obj)
644
+ {
645
+ return rb_gsl_ran_eval1(argc, argv, obj, gsl_ran_logistic);
646
+ }
647
+
648
+ static VALUE rb_gsl_ran_logistic_pdf(VALUE obj, VALUE x, VALUE mu)
649
+ {
650
+ return rb_gsl_eval_pdf_cdf2(x, mu, gsl_ran_logistic_pdf);
651
+ }
652
+
653
+ static VALUE rb_gsl_ran_pareto(int argc, VALUE *argv, VALUE obj)
654
+ {
655
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_pareto);
656
+ }
657
+
658
+ static VALUE rb_gsl_ran_pareto_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
659
+ {
660
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_pareto_pdf);
661
+ }
662
+
663
+ static VALUE rb_gsl_ran_weibull(int argc, VALUE *argv, VALUE obj)
664
+ {
665
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_weibull);
666
+ }
667
+
668
+ static VALUE rb_gsl_ran_weibull_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
669
+ {
670
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_weibull_pdf);
671
+ }
672
+
673
+ static VALUE rb_gsl_ran_gumbel1(int argc, VALUE *argv, VALUE obj)
674
+ {
675
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_gumbel1);
676
+ }
677
+
678
+ static VALUE rb_gsl_ran_gumbel1_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
679
+ {
680
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_gumbel1_pdf);
681
+ }
682
+
683
+ static VALUE rb_gsl_ran_gumbel2(int argc, VALUE *argv, VALUE obj)
684
+ {
685
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_gumbel2);
686
+ }
687
+
688
+ static VALUE rb_gsl_ran_gumbel2_pdf(VALUE obj, VALUE x, VALUE a, VALUE b)
689
+ {
690
+ return rb_gsl_eval_pdf_cdf3(x, a, b, gsl_ran_gumbel2_pdf);
691
+ }
692
+
693
+ static VALUE rb_gsl_ran_poisson(int argc, VALUE *argv, VALUE obj)
694
+ {
695
+ return rb_gsl_ran_eval1_uint(argc, argv, obj, gsl_ran_poisson);
696
+ }
697
+
698
+ static VALUE rb_gsl_ran_poisson_pdf(VALUE obj, VALUE x, VALUE mu)
699
+ {
700
+ return rb_gsl_eval_pdf_cdf2_uint(x, mu, gsl_ran_poisson_pdf);
701
+ }
702
+
703
+ static VALUE rb_gsl_ran_bernoulli(int argc, VALUE *argv, VALUE obj)
704
+ {
705
+ return rb_gsl_ran_eval1_uint(argc, argv, obj, gsl_ran_bernoulli);
706
+ }
707
+
708
+ static VALUE rb_gsl_ran_bernoulli_pdf(VALUE obj, VALUE x, VALUE mu)
709
+ {
710
+ return rb_gsl_eval_pdf_cdf2_uint(x, mu, gsl_ran_bernoulli_pdf);
711
+ }
712
+
713
+ static VALUE rb_gsl_ran_binomial(int argc, VALUE *argv, VALUE obj)
714
+ {
715
+ gsl_rng *r;
716
+ double p;
717
+ unsigned int n;
718
+ switch (TYPE(obj)) {
719
+ case T_MODULE: case T_CLASS: case T_OBJECT:
720
+ switch (argc) {
721
+ case 3:
722
+ CHECK_RNG(argv[0]);
723
+ Data_Get_Struct(argv[0], gsl_rng, r);
724
+ p = NUM2DBL(argv[1]);
725
+ n = FIX2UINT(argv[2]);
726
+ break;
727
+ default:
728
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
729
+ break;
730
+ }
731
+ break;
732
+ default:
733
+ switch (argc) {
734
+ case 2:
735
+ p = NUM2DBL(argv[0]);
736
+ n = FIX2UINT(argv[1]);
737
+ break;
738
+ default:
739
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
740
+ break;
741
+ }
742
+ Data_Get_Struct(obj, gsl_rng, r);
743
+ break;
744
+ }
745
+ return UINT2NUM(gsl_ran_binomial(r, p, n));
746
+ }
747
+
748
+ #ifdef GSL_1_4_LATER
749
+ static VALUE rb_gsl_ran_binomial_tpe(int argc, VALUE *argv, VALUE obj)
750
+ {
751
+ gsl_rng *r = NULL;
752
+ double p;
753
+ unsigned int n;
754
+ switch (TYPE(obj)) {
755
+ case T_MODULE: case T_CLASS: case T_OBJECT:
756
+ switch (argc) {
757
+ case 3:
758
+ CHECK_RNG(argv[0]);
759
+ Data_Get_Struct(argv[0], gsl_rng, r);
760
+ p = NUM2DBL(argv[1]);
761
+ n = FIX2UINT(argv[2]);
762
+ break;
763
+ default:
764
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
765
+ break;
766
+ }
767
+ break;
768
+ default:
769
+ switch (argc) {
770
+ case 2:
771
+ p = NUM2DBL(argv[0]);
772
+ n = FIX2UINT(argv[1]);
773
+ break;
774
+ default:
775
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
776
+ break;
777
+ }
778
+ Data_Get_Struct(obj, gsl_rng, r);
779
+ break;
780
+ }
781
+ return UINT2NUM(gsl_ran_binomial_tpe(r, p, n));
782
+ }
783
+ #endif
784
+
785
+ static VALUE rb_gsl_ran_binomial_pdf(VALUE obj, VALUE x, VALUE p, VALUE n)
786
+ {
787
+ return rb_float_new(gsl_ran_binomial_pdf(NUM2UINT(x), NUM2DBL(p), NUM2UINT(n)));
788
+ }
789
+
790
+ static VALUE rb_gsl_ran_negative_binomial(int argc, VALUE *argv, VALUE obj)
791
+ {
792
+ gsl_rng *r;
793
+ double p;
794
+ unsigned int n;
795
+ switch (TYPE(obj)) {
796
+ case T_MODULE: case T_CLASS: case T_OBJECT:
797
+ switch (argc) {
798
+ case 3:
799
+ CHECK_RNG(argv[0]);
800
+ Data_Get_Struct(argv[0], gsl_rng, r);
801
+ p = NUM2DBL(argv[1]);
802
+ n = FIX2UINT(argv[2]);
803
+ break;
804
+ default:
805
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
806
+ break;
807
+ }
808
+ break;
809
+ default:
810
+ switch (argc) {
811
+ case 2:
812
+ p = NUM2DBL(argv[0]);
813
+ n = FIX2UINT(argv[1]);
814
+ break;
815
+ default:
816
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
817
+ break;
818
+ }
819
+ Data_Get_Struct(obj, gsl_rng, r);
820
+ break;
821
+ }
822
+ return UINT2NUM(gsl_ran_negative_binomial(r, p, n));
823
+ }
824
+
825
+ static VALUE rb_gsl_ran_negative_binomial_pdf(VALUE obj, VALUE x, VALUE p, VALUE n)
826
+ {
827
+ return rb_float_new(gsl_ran_negative_binomial_pdf(NUM2UINT(x), NUM2DBL(p), NUM2DBL(n)));
828
+ }
829
+
830
+ static VALUE rb_gsl_ran_pascal(int argc, VALUE *argv, VALUE obj)
831
+ {
832
+ gsl_rng *r = NULL;
833
+ double p;
834
+ unsigned int n;
835
+ switch (TYPE(obj)) {
836
+ case T_MODULE: case T_CLASS: case T_OBJECT:
837
+ switch (argc) {
838
+ case 3:
839
+ CHECK_RNG(argv[0]);
840
+ Data_Get_Struct(argv[0], gsl_rng, r);
841
+ p = NUM2DBL(argv[1]);
842
+ n = FIX2UINT(argv[2]);
843
+ break;
844
+ default:
845
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
846
+ break;
847
+ }
848
+ break;
849
+ default:
850
+ switch (argc) {
851
+ case 2:
852
+ p = NUM2DBL(argv[0]);
853
+ n = FIX2UINT(argv[1]);
854
+ break;
855
+ default:
856
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
857
+ break;
858
+ }
859
+ Data_Get_Struct(obj, gsl_rng, r);
860
+ break;
861
+ }
862
+ return UINT2NUM(gsl_ran_pascal(r, p, n));
863
+ }
864
+
865
+ static VALUE rb_gsl_ran_pascal_pdf(VALUE obj, VALUE x, VALUE p, VALUE n)
866
+ {
867
+ return rb_float_new(gsl_ran_pascal_pdf(NUM2UINT(x), NUM2DBL(p), NUM2UINT(n)));
868
+ }
869
+
870
+ static VALUE rb_gsl_ran_geometric(int argc, VALUE *argv, VALUE obj)
871
+ {
872
+ return rb_gsl_ran_eval1_uint(argc, argv, obj, gsl_ran_geometric);
873
+ }
874
+
875
+ static VALUE rb_gsl_ran_geometric_pdf(VALUE obj, VALUE x, VALUE p)
876
+ {
877
+ return rb_gsl_eval_pdf_cdf2_uint(x, p, gsl_ran_geometric_pdf);
878
+ }
879
+
880
+ static VALUE rb_gsl_ran_hypergeometric(int argc, VALUE *argv, VALUE obj)
881
+ {
882
+ gsl_rng *r;
883
+ unsigned int n1, n2, t;
884
+ switch (TYPE(obj)) {
885
+ case T_MODULE: case T_CLASS: case T_OBJECT:
886
+ switch (argc) {
887
+ case 4:
888
+ CHECK_RNG(argv[0]);
889
+ Data_Get_Struct(argv[0], gsl_rng, r);
890
+ n1 = FIX2UINT(argv[1]);
891
+ n2 = FIX2UINT(argv[2]);
892
+ t = FIX2UINT(argv[3]);
893
+ break;
894
+ default:
895
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 4)", argc);
896
+ break;
897
+ }
898
+ break;
899
+ default:
900
+ switch (argc) {
901
+ case 3:
902
+ n1 = FIX2UINT(argv[0]);
903
+ n2 = FIX2UINT(argv[1]);
904
+ t = FIX2UINT(argv[2]);
905
+ break;
906
+ default:
907
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3)", argc);
908
+ break;
909
+ }
910
+ Data_Get_Struct(obj, gsl_rng, r);
911
+ break;
912
+ }
913
+ return UINT2NUM(gsl_ran_hypergeometric(r, n1, n2, t));
914
+ }
915
+
916
+ static VALUE rb_gsl_ran_hypergeometric_pdf(VALUE obj, VALUE k, VALUE n1, VALUE n2, VALUE t)
917
+ {
918
+ return rb_float_new(gsl_ran_hypergeometric_pdf(NUM2UINT(k), NUM2UINT(n1), NUM2UINT(n2), NUM2UINT(t)));
919
+ }
920
+
921
+ static VALUE rb_gsl_ran_logarithmic(int argc, VALUE *argv, VALUE obj)
922
+ {
923
+ return rb_gsl_ran_eval1_uint(argc, argv, obj, gsl_ran_logarithmic);
924
+ }
925
+
926
+ static VALUE rb_gsl_ran_logarithmic_pdf(VALUE obj, VALUE x, VALUE mu)
927
+ {
928
+ return rb_gsl_eval_pdf_cdf2_uint(x, mu, gsl_ran_logarithmic_pdf);
929
+ }
930
+
931
+ static VALUE rb_gsl_ran_dir_2d(int argc, VALUE *argv, VALUE obj)
932
+ {
933
+ gsl_rng *r = NULL;
934
+ double x, y;
935
+ switch (TYPE(obj)) {
936
+ case T_MODULE: case T_CLASS: case T_OBJECT:
937
+ switch (argc) {
938
+ case 1:
939
+ CHECK_RNG(argv[0]);
940
+ Data_Get_Struct(argv[0], gsl_rng, r);
941
+ break;
942
+ default:
943
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
944
+ break;
945
+ }
946
+ break;
947
+ default:
948
+ switch (argc) {
949
+ case 0:
950
+ Data_Get_Struct(obj, gsl_rng, r);
951
+ break;
952
+ default:
953
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
954
+ break;
955
+ }
956
+ }
957
+ gsl_ran_dir_2d(r, &x, &y);
958
+ return rb_ary_new3(2, rb_float_new(x), rb_float_new(y));
959
+ }
960
+
961
+ static VALUE rb_gsl_ran_dir_2d_trig_method(int argc, VALUE *argv, VALUE obj)
962
+ {
963
+ gsl_rng *r = NULL;
964
+ double x, y;
965
+ switch (TYPE(obj)) {
966
+ case T_MODULE: case T_CLASS: case T_OBJECT:
967
+ switch (argc) {
968
+ case 1:
969
+ CHECK_RNG(argv[0]);
970
+ Data_Get_Struct(argv[0], gsl_rng, r);
971
+ break;
972
+ default:
973
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
974
+ break;
975
+ }
976
+ break;
977
+ default:
978
+ switch (argc) {
979
+ case 0:
980
+ Data_Get_Struct(obj, gsl_rng, r);
981
+ break;
982
+ default:
983
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
984
+ break;
985
+ }
986
+ }
987
+ gsl_ran_dir_2d_trig_method(r, &x, &y);
988
+ return rb_ary_new3(2, rb_float_new(x), rb_float_new(y));
989
+ }
990
+
991
+ static VALUE rb_gsl_ran_dir_3d(int argc, VALUE *argv, VALUE obj)
992
+ {
993
+ gsl_rng *r = NULL;
994
+ double x, y, z;
995
+ switch (TYPE(obj)) {
996
+ case T_MODULE: case T_CLASS: case T_OBJECT:
997
+ switch (argc) {
998
+ case 1:
999
+ CHECK_RNG(argv[0]);
1000
+ Data_Get_Struct(argv[0], gsl_rng, r);
1001
+ break;
1002
+ default:
1003
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
1004
+ break;
1005
+ }
1006
+ break;
1007
+ default:
1008
+ switch (argc) {
1009
+ case 0:
1010
+ Data_Get_Struct(obj, gsl_rng, r);
1011
+ break;
1012
+ default:
1013
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
1014
+ break;
1015
+ }
1016
+ }
1017
+ gsl_ran_dir_3d(r, &x, &y, &z);
1018
+ return rb_ary_new3(3, rb_float_new(x), rb_float_new(y), rb_float_new(z));
1019
+ }
1020
+
1021
+ static VALUE rb_gsl_ran_dir_nd(int argc, VALUE *argv, VALUE obj)
1022
+ {
1023
+ gsl_rng *r = NULL;
1024
+ size_t n;
1025
+ gsl_vector *v;
1026
+ switch (TYPE(obj)) {
1027
+ case T_MODULE: case T_CLASS: case T_OBJECT:
1028
+ switch (argc) {
1029
+ case 2:
1030
+ CHECK_RNG(argv[0]); CHECK_FIXNUM(argv[1]);
1031
+ Data_Get_Struct(argv[0], gsl_rng, r);
1032
+ n = FIX2INT(argv[1]);
1033
+ break;
1034
+ default:
1035
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
1036
+ break;
1037
+ }
1038
+ break;
1039
+ default:
1040
+ switch (argc) {
1041
+ case 1:
1042
+ CHECK_FIXNUM(argv[0]);
1043
+ n = FIX2INT(argv[0]);
1044
+ Data_Get_Struct(obj, gsl_rng, r);
1045
+ break;
1046
+ default:
1047
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
1048
+ break;
1049
+ }
1050
+ }
1051
+ v = gsl_vector_alloc(n);
1052
+ gsl_ran_dir_nd(r, n, v->data);
1053
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
1054
+ }
1055
+
1056
+ static VALUE rb_gsl_ran_shuffle(int argc, VALUE *argv, VALUE obj)
1057
+ {
1058
+ gsl_rng *r = NULL;
1059
+ gsl_vector *v = NULL;
1060
+ gsl_permutation *p = NULL;
1061
+ switch (TYPE(obj)) {
1062
+ case T_MODULE:
1063
+ case T_CLASS:
1064
+ case T_OBJECT:
1065
+ switch (argc) {
1066
+ case 2:
1067
+ CHECK_RNG(argv[0]);
1068
+ Data_Get_Struct(argv[0], gsl_rng, r);
1069
+ if (VECTOR_P(argv[1])) {
1070
+ Data_Get_Struct(argv[1], gsl_vector, v);
1071
+ gsl_ran_shuffle(r, v->data, v->size, sizeof(double));
1072
+ } else if (PERMUTATION_P(argv[1])) {
1073
+ Data_Get_Struct(argv[1], gsl_permutation, p);
1074
+ gsl_ran_shuffle(r, p->data, p->size, sizeof(size_t));
1075
+ } else {
1076
+ rb_raise(rb_eTypeError, "wrong argument type %s (Vector or Permutation expected)", rb_class2name(CLASS_OF(argv[1])));
1077
+ }
1078
+ break;
1079
+ case 3:
1080
+ CHECK_RNG(argv[0]);
1081
+ CHECK_FIXNUM(argv[2]);
1082
+ Data_Get_Struct(argv[0], gsl_rng, r);
1083
+ if (VECTOR_P(argv[1])) {
1084
+ Data_Get_Struct(argv[1], gsl_vector, v);
1085
+ gsl_ran_shuffle(r, v->data, FIX2INT(argv[2]), sizeof(double));
1086
+ } else if (PERMUTATION_P(argv[1])) {
1087
+ Data_Get_Struct(argv[1], gsl_permutation, p);
1088
+ gsl_ran_shuffle(r, p->data, FIX2INT(argv[2]), sizeof(size_t));
1089
+ } else {
1090
+ rb_raise(rb_eTypeError,
1091
+ "wrong argument type %s (Vector or Permutation expected)",
1092
+ rb_class2name(CLASS_OF(argv[1])));
1093
+ }
1094
+ break;
1095
+ default:
1096
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
1097
+ break;
1098
+ }
1099
+ break;
1100
+ default:
1101
+ Data_Get_Struct(obj, gsl_rng, r);
1102
+ switch (argc) {
1103
+ case 1:
1104
+ if (VECTOR_P(argv[0])) {
1105
+ Data_Get_Struct(argv[0], gsl_vector, v);
1106
+ gsl_ran_shuffle(r, v->data, v->size, sizeof(double));
1107
+ } else if (PERMUTATION_P(argv[0])) {
1108
+ Data_Get_Struct(argv[0], gsl_permutation, p);
1109
+ gsl_ran_shuffle(r, p->data, p->size, sizeof(size_t));
1110
+ } else {
1111
+ rb_raise(rb_eTypeError, "wrong argument type %s (Vector or Permutation expected)", rb_class2name(CLASS_OF(argv[0])));
1112
+ }
1113
+ break;
1114
+ case 2:
1115
+ CHECK_FIXNUM(argv[1]);
1116
+ if (VECTOR_P(argv[0])) {
1117
+ Data_Get_Struct(argv[0], gsl_vector, v);
1118
+ gsl_ran_shuffle(r, v->data, FIX2INT(argv[1]), sizeof(double));
1119
+ } else if (PERMUTATION_P(argv[0])) {
1120
+ Data_Get_Struct(argv[0], gsl_permutation, p);
1121
+ gsl_ran_shuffle(r, p->data, FIX2INT(argv[1]), sizeof(size_t));
1122
+ } else {
1123
+ rb_raise(rb_eTypeError,
1124
+ "wrong argument type %s (Vector or Permutation expected)",
1125
+ rb_class2name(CLASS_OF(argv[0])));
1126
+ }
1127
+ default:
1128
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
1129
+ break;
1130
+ }
1131
+ break;
1132
+ }
1133
+ return Qnil;
1134
+ }
1135
+
1136
+ static VALUE rb_gsl_ran_choose(int argc, VALUE *argv, VALUE obj)
1137
+ {
1138
+ gsl_rng *r = NULL;
1139
+ gsl_vector *v = NULL, *v2 = NULL;
1140
+ size_t k, n;
1141
+ Data_Get_Struct(obj, gsl_rng, r);
1142
+ switch (argc) {
1143
+ case 2:
1144
+ CHECK_VECTOR(argv[0]);
1145
+ CHECK_FIXNUM(argv[1]);
1146
+ Data_Get_Struct(argv[0], gsl_vector, v);
1147
+ n = v->size;
1148
+ k = FIX2INT(argv[1]);
1149
+ if (k > n) rb_raise(rb_eArgError, "the argument 1 must be less than or equal to the size of the vector.");
1150
+ v2 = gsl_vector_alloc(k);
1151
+ gsl_ran_choose(r, v2->data, k, v->data, n, sizeof(double));
1152
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v2);;
1153
+ break;
1154
+ case 1:
1155
+ CHECK_VECTOR(argv[0]);
1156
+ Data_Get_Struct(argv[0], gsl_vector, v);
1157
+ n = v->size;
1158
+ k = v->size;
1159
+ if (k > n) rb_raise(rb_eArgError, "the argument 1 must be less than or equal to the size of the vector.");
1160
+ v2 = gsl_vector_alloc(k);
1161
+ gsl_ran_choose(r, v2->data, k, v->data, n, sizeof(double));
1162
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v2);;
1163
+ break;
1164
+ default:
1165
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
1166
+ break;
1167
+ }
1168
+ }
1169
+
1170
+ static VALUE rb_gsl_ran_choose_singleton(int argc, VALUE *argv, VALUE obj)
1171
+ {
1172
+ gsl_rng *r = NULL;
1173
+ gsl_vector *v = NULL, *v2 = NULL;
1174
+ size_t k, n;
1175
+ switch (argc) {
1176
+ case 3:
1177
+ CHECK_RNG(argv[0]);
1178
+ CHECK_VECTOR(argv[1]);
1179
+ CHECK_FIXNUM(argv[2]);
1180
+ Data_Get_Struct(argv[0], gsl_rng, r);
1181
+ Data_Get_Struct(argv[1], gsl_vector, v);
1182
+ n = v->size;
1183
+ k = FIX2INT(argv[2]);
1184
+ if (k > n) rb_raise(rb_eArgError, "the argument 1 must be less than or equal to the size of the vector.");
1185
+ v2 = gsl_vector_alloc(k);
1186
+ gsl_ran_choose(r, v2->data, k, v->data, n, sizeof(double));
1187
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v2);;
1188
+ break;
1189
+ case 2:
1190
+ CHECK_RNG(argv[0]);
1191
+ CHECK_VECTOR(argv[1]);
1192
+ Data_Get_Struct(argv[0], gsl_rng, r);
1193
+ Data_Get_Struct(argv[1], gsl_vector, v);
1194
+ n = v->size;
1195
+ k = v->size;
1196
+ if (k > n) rb_raise(rb_eArgError, "the argument 1 must be less than or equal to the size of the vector.");
1197
+ v2 = gsl_vector_alloc(k);
1198
+ gsl_ran_choose(r, v2->data, k, v->data, n, sizeof(double));
1199
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v2);;
1200
+ break;
1201
+ default:
1202
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
1203
+ break;
1204
+ }
1205
+ }
1206
+
1207
+ static VALUE rb_gsl_ran_sample(VALUE obj, VALUE vv, VALUE kk)
1208
+ {
1209
+ gsl_rng *r = NULL;
1210
+ gsl_vector *v = NULL, *v2 = NULL;
1211
+ size_t k, n;
1212
+ Data_Get_Struct(obj, gsl_rng, r);
1213
+ Data_Get_Struct(vv, gsl_vector, v);
1214
+ n = v->size;
1215
+ k = FIX2INT(kk);
1216
+ v2 = gsl_vector_alloc(k);
1217
+ gsl_ran_sample(r, v2->data, k, v->data, n, sizeof(double));
1218
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v2);;
1219
+ }
1220
+
1221
+ #ifdef GSL_1_3_LATER
1222
+ static VALUE rb_gsl_ran_dirichlet(int argc, VALUE *argv, VALUE obj)
1223
+ {
1224
+ gsl_rng *r = NULL;
1225
+ gsl_vector *v = NULL, *v2 = NULL;
1226
+ Data_Get_Struct(obj, gsl_rng, r);
1227
+ if (argc == 1) {
1228
+ Data_Get_Struct(argv[0], gsl_vector, v);
1229
+ v2 = gsl_vector_alloc(v->size);
1230
+ gsl_ran_dirichlet(r, v->size, v->data, v2->data);
1231
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v2);
1232
+ } else if (argc == 2) {
1233
+ Data_Get_Struct(argv[0], gsl_vector, v);
1234
+ Data_Get_Struct(argv[1], gsl_vector, v2);
1235
+ gsl_ran_dirichlet(r, v->size, v->data, v2->data);
1236
+ return obj;
1237
+ } else {
1238
+ rb_raise(rb_eArgError, "wrong number of arguments (1 or 2 GSL_Vectors)");
1239
+ }
1240
+ }
1241
+
1242
+ static VALUE rb_gsl_ran_dirichlet_pdf(VALUE obj, VALUE a, VALUE t)
1243
+ {
1244
+ gsl_vector *alpha = NULL, *theta = NULL;
1245
+ Data_Get_Struct(a, gsl_vector, alpha);
1246
+ Data_Get_Struct(t, gsl_vector, theta);
1247
+ return rb_float_new(gsl_ran_dirichlet_pdf(alpha->size, alpha->data, theta->data));
1248
+ }
1249
+ static VALUE rb_gsl_ran_dirichlet_lnpdf(VALUE obj, VALUE a, VALUE t)
1250
+ {
1251
+ gsl_vector *alpha = NULL, *theta = NULL;
1252
+ Data_Get_Struct(a, gsl_vector, alpha);
1253
+ Data_Get_Struct(t, gsl_vector, theta);
1254
+ return rb_float_new(gsl_ran_dirichlet_lnpdf(alpha->size, alpha->data, theta->data));
1255
+ }
1256
+ #endif
1257
+
1258
+ static VALUE rb_gsl_ran_discrete_new(VALUE klass, VALUE vv)
1259
+ {
1260
+ gsl_vector *v = NULL;
1261
+ gsl_ran_discrete_t *g = NULL;
1262
+ Data_Get_Struct(vv, gsl_vector, v);
1263
+ g = gsl_ran_discrete_preproc(v->size, v->data);
1264
+ return Data_Wrap_Struct(klass, 0, gsl_ran_discrete_free, g);
1265
+ }
1266
+
1267
+ static VALUE rb_gsl_ran_discrete(VALUE obj, VALUE gg)
1268
+ {
1269
+ gsl_rng *r = NULL;
1270
+ gsl_ran_discrete_t *g = NULL;
1271
+ Data_Get_Struct(obj, gsl_rng, r);
1272
+ Data_Get_Struct(gg, gsl_ran_discrete_t, g);
1273
+ return INT2FIX(gsl_ran_discrete(r, g));
1274
+ }
1275
+
1276
+ static VALUE rb_gsl_ran_discrete_pdf(VALUE obj, VALUE k, VALUE gg)
1277
+ {
1278
+ gsl_ran_discrete_t *g = NULL;
1279
+ Data_Get_Struct(gg, gsl_ran_discrete_t, g);
1280
+ return rb_float_new(gsl_ran_discrete_pdf(FIX2INT(k), g));
1281
+ }
1282
+
1283
+ #ifdef HAVE_NARRAY_H
1284
+ #include "narray.h"
1285
+ #endif
1286
+
1287
+ /*****/
1288
+ VALUE rb_gsl_eval_pdf_cdf(VALUE xx, double (*f)(double))
1289
+ {
1290
+ VALUE x, ary;
1291
+ gsl_vector *v = NULL, *vnew = NULL;
1292
+ gsl_matrix *m = NULL, *mnew = NULL;
1293
+ size_t i, j, n;
1294
+ #ifdef HAVE_NARRAY_H
1295
+ struct NARRAY *na;
1296
+ double *ptr1, *ptr2;
1297
+ #endif
1298
+ if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
1299
+ switch(TYPE(xx)) {
1300
+ case T_FIXNUM:
1301
+ case T_BIGNUM:
1302
+ case T_FLOAT:
1303
+ return rb_float_new((*f)(NUM2DBL(xx)));
1304
+ break;
1305
+ case T_ARRAY:
1306
+ // n = RARRAY(xx)->len;
1307
+ n = RARRAY_LEN(xx);
1308
+ ary = rb_ary_new2(n);
1309
+ for (i = 0; i < n; i++) {
1310
+ x = rb_ary_entry(xx, i);
1311
+ Need_Float(x);
1312
+ rb_ary_store(ary, i, rb_float_new((*f)(NUM2DBL(x))));
1313
+ }
1314
+ return ary;
1315
+ break;
1316
+ default:
1317
+ #ifdef HAVE_NARRAY_H
1318
+ if (NA_IsNArray(xx)) {
1319
+ xx = na_change_type(xx, NA_DFLOAT);
1320
+ GetNArray(xx, na);
1321
+ ptr1 = (double *) na->ptr;
1322
+ n = na->total;
1323
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
1324
+ ptr2 = NA_PTR_TYPE(ary, double*);
1325
+ for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i]);
1326
+ return ary;
1327
+ }
1328
+ #endif
1329
+ if (VECTOR_P(xx)) {
1330
+ Data_Get_Struct(xx, gsl_vector, v);
1331
+ vnew = gsl_vector_alloc(v->size);
1332
+ for (i = 0; i < v->size; i++) {
1333
+ gsl_vector_set(vnew, i, (*f)(gsl_vector_get(v, i)));
1334
+ }
1335
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1336
+ } else if (MATRIX_P(xx)) {
1337
+ Data_Get_Struct(xx, gsl_matrix, m);
1338
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
1339
+ for (i = 0; i < m->size1; i++) {
1340
+ for (j = 0; j < m->size2; j++) {
1341
+ gsl_matrix_set(mnew, i, j, (*f)(gsl_matrix_get(m, i, j)));
1342
+ }
1343
+ }
1344
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1345
+ } else {
1346
+ rb_raise(rb_eTypeError, "wrong argument type");
1347
+ }
1348
+ break;
1349
+ }
1350
+ /* never reach here */
1351
+ return Qnil;
1352
+ }
1353
+
1354
+ VALUE rb_gsl_eval_pdf_cdf2(VALUE xx, VALUE aa,
1355
+ double (*f)(double, double))
1356
+ {
1357
+ VALUE x, ary;
1358
+ double a;
1359
+ gsl_vector *v = NULL, *vnew = NULL;
1360
+ gsl_matrix *m = NULL, *mnew = NULL;
1361
+ size_t i, j, n;
1362
+ #ifdef HAVE_NARRAY_H
1363
+ struct NARRAY *na;
1364
+ double *ptr1, *ptr2;
1365
+ #endif
1366
+ Need_Float(aa);
1367
+ a = NUM2DBL(aa);
1368
+ if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
1369
+ switch(TYPE(xx)) {
1370
+ case T_FIXNUM:
1371
+ case T_BIGNUM:
1372
+ case T_FLOAT:
1373
+ return rb_float_new((*f)(NUM2DBL(xx), a));
1374
+ break;
1375
+ case T_ARRAY:
1376
+ // n = RARRAY(xx)->len;
1377
+ n = RARRAY_LEN(xx);
1378
+ ary = rb_ary_new2(n);
1379
+ for (i = 0; i < n; i++) {
1380
+ x = rb_ary_entry(xx, i);
1381
+ Need_Float(x);
1382
+ rb_ary_store(ary, i, rb_float_new((*f)(NUM2DBL(x), a)));
1383
+ }
1384
+ return ary;
1385
+ break;
1386
+ default:
1387
+ #ifdef HAVE_NARRAY_H
1388
+ if (NA_IsNArray(xx)) {
1389
+ xx = na_change_type(xx, NA_DFLOAT);
1390
+ GetNArray(xx, na);
1391
+ ptr1 = (double *) na->ptr;
1392
+ n = na->total;
1393
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
1394
+ ptr2 = NA_PTR_TYPE(ary, double*);
1395
+ for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i], a);
1396
+ return ary;
1397
+ }
1398
+ #endif
1399
+ if (VECTOR_P(xx)) {
1400
+ Data_Get_Struct(xx, gsl_vector, v);
1401
+ vnew = gsl_vector_alloc(v->size);
1402
+ for (i = 0; i < v->size; i++) {
1403
+ gsl_vector_set(vnew, i, (*f)(gsl_vector_get(v, i), a));
1404
+ }
1405
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1406
+ } else if (MATRIX_P(xx)) {
1407
+ Data_Get_Struct(xx, gsl_matrix, m);
1408
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
1409
+ for (i = 0; i < m->size1; i++) {
1410
+ for (j = 0; j < m->size2; j++) {
1411
+ gsl_matrix_set(mnew, i, j, (*f)(gsl_matrix_get(m, i, j), a));
1412
+ }
1413
+ }
1414
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1415
+ } else {
1416
+ rb_raise(rb_eTypeError, "wrong argument type");
1417
+ }
1418
+ break;
1419
+ }
1420
+ /* never reach here */
1421
+ return Qnil;
1422
+ }
1423
+
1424
+ VALUE rb_gsl_eval_pdf_cdf3(VALUE xx, VALUE aa, VALUE bb,
1425
+ double (*f)(double, double, double))
1426
+ {
1427
+ VALUE x, ary;
1428
+ double a, b;
1429
+ gsl_vector *v = NULL, *vnew = NULL;
1430
+ gsl_matrix *m = NULL, *mnew = NULL;
1431
+ size_t i, j, n;
1432
+ #ifdef HAVE_NARRAY_H
1433
+ struct NARRAY *na;
1434
+ double *ptr1, *ptr2;
1435
+ #endif
1436
+ Need_Float(aa); Need_Float(bb);
1437
+ a = NUM2DBL(aa); b = NUM2DBL(bb);
1438
+ if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
1439
+ switch(TYPE(xx)) {
1440
+ case T_FIXNUM:
1441
+ case T_BIGNUM:
1442
+ case T_FLOAT:
1443
+ return rb_float_new((*f)(NUM2DBL(xx), a, b));
1444
+ break;
1445
+ case T_ARRAY:
1446
+ // n = RARRAY(xx)->len;
1447
+ n = RARRAY_LEN(xx);
1448
+ ary = rb_ary_new2(n);
1449
+ for (i = 0; i < n; i++) {
1450
+ x = rb_ary_entry(xx, i);
1451
+ Need_Float(x);
1452
+ rb_ary_store(ary, i, rb_float_new((*f)(NUM2DBL(x), a, b)));
1453
+ }
1454
+ return ary;
1455
+ break;
1456
+ default:
1457
+ #ifdef HAVE_NARRAY_H
1458
+ if (NA_IsNArray(xx)) {
1459
+ xx = na_change_type(xx, NA_DFLOAT);
1460
+ GetNArray(xx, na);
1461
+ ptr1 = (double *) na->ptr;
1462
+ n = na->total;
1463
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
1464
+ ptr2 = NA_PTR_TYPE(ary, double*);
1465
+ for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i], a, b);
1466
+ return ary;
1467
+ }
1468
+ #endif
1469
+ if (VECTOR_P(xx)) {
1470
+ Data_Get_Struct(xx, gsl_vector, v);
1471
+ vnew = gsl_vector_alloc(v->size);
1472
+ for (i = 0; i < v->size; i++) {
1473
+ gsl_vector_set(vnew, i, (*f)(gsl_vector_get(v, i), a, b));
1474
+ }
1475
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1476
+ } else if (MATRIX_P(xx)) {
1477
+ Data_Get_Struct(xx, gsl_matrix, m);
1478
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
1479
+ for (i = 0; i < m->size1; i++) {
1480
+ for (j = 0; j < m->size2; j++) {
1481
+ gsl_matrix_set(mnew, i, j, (*f)(gsl_matrix_get(m, i, j), a, b));
1482
+ }
1483
+ }
1484
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1485
+ } else {
1486
+ rb_raise(rb_eTypeError, "wrong argument type");
1487
+ }
1488
+ break;
1489
+ }
1490
+ /* never reach here */
1491
+ return Qnil;
1492
+ }
1493
+
1494
+ VALUE rb_gsl_eval_pdf_cdf2_uint(VALUE xx, VALUE aa,
1495
+ double (*f)(unsigned int, double))
1496
+ {
1497
+ VALUE x, ary;
1498
+ double a;
1499
+ gsl_vector *v = NULL, *vnew = NULL;
1500
+ gsl_vector_int *vi = NULL;
1501
+ gsl_matrix *m = NULL, *mnew = NULL;
1502
+ gsl_matrix_int *mi = NULL;
1503
+ size_t i, j, n;
1504
+ #ifdef HAVE_NARRAY_H
1505
+ struct NARRAY *na;
1506
+ char *ptr1, *ptr2;
1507
+ #endif
1508
+ Need_Float(aa);
1509
+ a = NUM2DBL(aa);
1510
+ if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
1511
+ switch(TYPE(xx)) {
1512
+ case T_FIXNUM:
1513
+ case T_BIGNUM:
1514
+ case T_FLOAT:
1515
+ return rb_float_new((*f)(NUM2UINT(xx), a));
1516
+ break;
1517
+ case T_ARRAY:
1518
+ // n = RARRAY(xx)->len;
1519
+ n = RARRAY_LEN(xx);
1520
+ ary = rb_ary_new2(n);
1521
+ for (i = 0; i < n; i++) {
1522
+ x = rb_ary_entry(xx, i);
1523
+ rb_ary_store(ary, i, rb_float_new((*f)(NUM2UINT(x), a)));
1524
+ }
1525
+ return ary;
1526
+ break;
1527
+ default:
1528
+ #ifdef HAVE_NARRAY_H
1529
+ if (NA_IsNArray(xx)) {
1530
+ GetNArray(xx, na);
1531
+ n = na->total;
1532
+ ary = na_make_object(na->type, na->rank, na->shape, CLASS_OF(xx));
1533
+ ptr1 = (char *)na->ptr;
1534
+ ptr2 = (char *)NA_STRUCT(ary)->ptr;
1535
+ switch (na->type) {
1536
+ case NA_LINT:
1537
+ for (i = 0; i < n; i++)
1538
+ ((int*)ptr2)[i] = (*f)((unsigned int) ((int*)ptr1)[i], a);
1539
+ break;
1540
+ default:
1541
+ for (i = 0; i < n; i++)
1542
+ ((double*)ptr2)[i] = (*f)((unsigned int) ((double*)ptr1)[i], a);
1543
+ break;
1544
+ }
1545
+ return ary;
1546
+ }
1547
+ #endif
1548
+ if (VECTOR_P(xx)) {
1549
+ Data_Get_Struct(xx, gsl_vector, v);
1550
+ vnew = gsl_vector_alloc(v->size);
1551
+ for (i = 0; i < v->size; i++) {
1552
+ gsl_vector_set(vnew, i, (*f)((unsigned int) gsl_vector_get(v, i), a));
1553
+ }
1554
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1555
+ } else if (VECTOR_INT_P(xx)) {
1556
+ Data_Get_Struct(xx, gsl_vector_int, vi);
1557
+ vnew = gsl_vector_alloc(vi->size);
1558
+ for (i = 0; i < vi->size; i++) {
1559
+ gsl_vector_set(vnew, i, (*f)((unsigned int) gsl_vector_int_get(vi, i), a));
1560
+ }
1561
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1562
+ } else if (MATRIX_P(xx)) {
1563
+ Data_Get_Struct(xx, gsl_matrix, m);
1564
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
1565
+ for (i = 0; i < m->size1; i++) {
1566
+ for (j = 0; j < m->size2; j++) {
1567
+ gsl_matrix_set(mnew, i, j, (*f)((unsigned int) gsl_matrix_get(m, i, j), a));
1568
+ }
1569
+ }
1570
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1571
+ } else if (MATRIX_INT_P(xx)) {
1572
+ Data_Get_Struct(xx, gsl_matrix_int, mi);
1573
+ mnew = gsl_matrix_alloc(mi->size1, mi->size2);
1574
+ for (i = 0; i < mi->size1; i++) {
1575
+ for (j = 0; j < mi->size2; j++) {
1576
+ gsl_matrix_set(mnew, i, j, (*f)((unsigned int) gsl_matrix_int_get(mi, i, j), a));
1577
+ }
1578
+ }
1579
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1580
+ } else {
1581
+ rb_raise(rb_eTypeError, "wrong argument type");
1582
+ }
1583
+ break;
1584
+ }
1585
+ /* never reach here */
1586
+ return Qnil;
1587
+ }
1588
+
1589
+ /*
1590
+ static VALUE rb_gsl_ran_erlang(VALUE obj, VALUE a, VALUE n)
1591
+ {
1592
+ gsl_rng *r = NULL;
1593
+ Data_Get_Struct(obj, gsl_rng, r);
1594
+ return rb_float_new(gsl_ran_erlang(r, NUM2DBL(a), NUM2DBL(n)));
1595
+ }
1596
+
1597
+ static VALUE rb_gsl_ran_erlang_pdf(VALUE obj, VALUE x, VALUE a, VALUE n)
1598
+ {
1599
+ return rb_float_new(gsl_ran_erlang_pdf(NUM2DBL(x), NUM2DBL(a), NUM2DBL(n)));
1600
+ }
1601
+ */
1602
+
1603
+ #ifdef GSL_1_8_LATER
1604
+
1605
+ static VALUE rb_gsl_ran_gaussian_ziggurat(int argc, VALUE *argv, VALUE obj)
1606
+ {
1607
+ gsl_rng *r = NULL;
1608
+ gsl_vector *v;
1609
+ size_t n, i;
1610
+ double sigma = 1.0;
1611
+ switch (TYPE(obj)) {
1612
+ case T_MODULE: case T_CLASS: case T_OBJECT:
1613
+ switch (argc) {
1614
+ case 3:
1615
+ n = NUM2INT(argv[2]);
1616
+ sigma = NUM2DBL(argv[1]);
1617
+ CHECK_RNG(argv[0]);
1618
+ Data_Get_Struct(argv[0], gsl_rng, r);
1619
+ v = gsl_vector_alloc(n);
1620
+ for (i = 0; i < n; i++)
1621
+ gsl_vector_set(v, i, gsl_ran_gaussian_ziggurat(r, sigma));
1622
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
1623
+ break;
1624
+ case 2:
1625
+ sigma = NUM2DBL(argv[1]);
1626
+ /* no break */
1627
+ case 1:
1628
+ CHECK_RNG(argv[0]);
1629
+ Data_Get_Struct(argv[0], gsl_rng, r);
1630
+ return rb_float_new(gsl_ran_gaussian_ziggurat(r, sigma));
1631
+ break;
1632
+ default:
1633
+ rb_raise(rb_eArgError, "too many arguments (%d for 1 or 2)", argc);
1634
+ return Qnil;
1635
+ break;
1636
+ }
1637
+ break;
1638
+ default:
1639
+ Data_Get_Struct(obj, gsl_rng, r);
1640
+ switch (argc) {
1641
+ case 2:
1642
+ n = NUM2INT(argv[1]);
1643
+ sigma = NUM2DBL(argv[0]);
1644
+ v = gsl_vector_alloc(n);
1645
+ for (i = 0; i < n; i++)
1646
+ gsl_vector_set(v, i, gsl_ran_gaussian_ziggurat(r, sigma));
1647
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
1648
+ break;
1649
+ case 1:
1650
+ sigma = NUM2DBL(argv[0]);
1651
+ /* no break */
1652
+ case 0:
1653
+ return rb_float_new(gsl_ran_gaussian_ziggurat(r, sigma));
1654
+ break;
1655
+ default:
1656
+ rb_raise(rb_eArgError, "too many arguments (%d for 0 or 1)", argc);
1657
+ return Qnil;
1658
+ break;
1659
+ }
1660
+ break;
1661
+ }
1662
+ return Qnil;
1663
+ }
1664
+
1665
+ static VALUE rb_gsl_ran_gamma_mt(int argc, VALUE *argv, VALUE obj)
1666
+ {
1667
+ return rb_gsl_ran_eval2(argc, argv, obj, gsl_ran_gamma_mt);
1668
+ }
1669
+ #endif
1670
+
1671
+ void Init_gsl_ran(VALUE module)
1672
+ {
1673
+ VALUE mgsl_ran;
1674
+ VALUE cgsl_ran_discrete;
1675
+
1676
+ mgsl_ran = rb_define_module_under(module, "Ran");
1677
+
1678
+ rb_define_module_function(mgsl_ran, "gaussian", rb_gsl_ran_gaussian, -1);
1679
+ rb_define_module_function(mgsl_ran, "ugaussian", rb_gsl_ran_gaussian, -1);
1680
+ rb_define_method(cgsl_rng, "gaussian", rb_gsl_ran_gaussian, -1);
1681
+ rb_define_alias(cgsl_rng, "ugaussian", "gaussian");
1682
+
1683
+ rb_define_module_function(mgsl_ran, "gaussian_ratio_method",
1684
+ rb_gsl_ran_gaussian_ratio_method, -1);
1685
+ rb_define_module_function(mgsl_ran, "ugaussian_ratio_method",
1686
+ rb_gsl_ran_gaussian_ratio_method, -1);
1687
+ rb_define_method(cgsl_rng, "gaussian_ratio_method",
1688
+ rb_gsl_ran_gaussian_ratio_method, -1);
1689
+ rb_define_alias(cgsl_rng, "ugaussian_ratio_method", "gaussian_ratio_method");
1690
+ rb_define_module_function(mgsl_ran, "gaussian_pdf", rb_gsl_ran_gaussian_pdf, -1);
1691
+ rb_define_module_function(mgsl_ran, "ugaussian_pdf", rb_gsl_ran_gaussian_pdf, -1);
1692
+
1693
+ rb_define_module_function(mgsl_ran, "gaussian_tail", rb_gsl_ran_gaussian_tail, -1);
1694
+ rb_define_module_function(mgsl_ran, "ugaussian_tail", rb_gsl_ran_gaussian_tail, -1);
1695
+ rb_define_method(cgsl_rng, "gaussian_tail", rb_gsl_ran_gaussian_tail, -1);
1696
+ rb_define_alias(cgsl_rng, "ugaussian_tail", "gaussian_tail");
1697
+ rb_define_module_function(mgsl_ran, "gaussian_tail_pdf",
1698
+ rb_gsl_ran_gaussian_tail_pdf, -1);
1699
+ rb_define_module_function(mgsl_ran, "ugaussian_tail_pdf",
1700
+ rb_gsl_ran_gaussian_tail_pdf, -1);
1701
+
1702
+ rb_define_module_function(mgsl_ran, "bivariate_gaussian",
1703
+ rb_gsl_ran_bivariate_gaussian, -1);
1704
+ rb_define_method(cgsl_rng, "bivariate_gaussian",
1705
+ rb_gsl_ran_bivariate_gaussian, -1);
1706
+ rb_define_module_function(mgsl_ran, "bivariate_gaussian_pdf",
1707
+ rb_gsl_ran_bivariate_gaussian_pdf, 5);
1708
+
1709
+ rb_define_module_function(mgsl_ran, "exponential", rb_gsl_ran_exponential, -1);
1710
+ rb_define_method(cgsl_rng, "exponential", rb_gsl_ran_exponential, -1);
1711
+ rb_define_module_function(mgsl_ran, "exponential_pdf",
1712
+ rb_gsl_ran_exponential_pdf, 2);
1713
+
1714
+ rb_define_module_function(mgsl_ran, "laplace", rb_gsl_ran_laplace, -1);
1715
+ rb_define_method(cgsl_rng, "laplace", rb_gsl_ran_laplace, -1);
1716
+ rb_define_module_function(mgsl_ran, "laplace_pdf", rb_gsl_ran_laplace_pdf, 2);
1717
+
1718
+ rb_define_module_function(mgsl_ran, "exppow", rb_gsl_ran_exppow, -1);
1719
+ rb_define_method(cgsl_rng, "exppow", rb_gsl_ran_exppow, -1);
1720
+ rb_define_module_function(mgsl_ran, "exppow_pdf", rb_gsl_ran_exppow_pdf, 3);
1721
+
1722
+ rb_define_module_function(mgsl_ran, "cauchy", rb_gsl_ran_cauchy, -1);
1723
+ rb_define_method(cgsl_rng, "cauchy", rb_gsl_ran_cauchy, -1);
1724
+ rb_define_module_function(mgsl_ran, "cauchy_pdf", rb_gsl_ran_cauchy_pdf, 2);
1725
+
1726
+ rb_define_module_function(mgsl_ran, "rayleigh", rb_gsl_ran_rayleigh, -1);
1727
+ rb_define_method(cgsl_rng, "rayleigh", rb_gsl_ran_rayleigh, -1);
1728
+ rb_define_module_function(mgsl_ran, "rayleigh_pdf", rb_gsl_ran_rayleigh_pdf, 2);
1729
+
1730
+ rb_define_module_function(mgsl_ran, "rayleigh_tail", rb_gsl_ran_rayleigh_tail, -1);
1731
+ rb_define_method(cgsl_rng, "rayleigh_tail", rb_gsl_ran_rayleigh_tail, -1);
1732
+ rb_define_module_function(mgsl_ran, "rayleigh_tail_pdf",
1733
+ rb_gsl_ran_rayleigh_tail_pdf, 3);
1734
+
1735
+ rb_define_module_function(mgsl_ran, "landau", rb_gsl_ran_landau, -1);
1736
+ rb_define_method(cgsl_rng, "landau", rb_gsl_ran_landau, -1);
1737
+ rb_define_module_function(mgsl_ran, "landau_pdf", rb_gsl_ran_landau_pdf, 1);
1738
+
1739
+ rb_define_method(cgsl_rng, "levy", rb_gsl_ran_levy, -1);
1740
+ rb_define_method(cgsl_rng, "levy_skew", rb_gsl_ran_levy_skew, -1);
1741
+ rb_define_module_function(mgsl_ran, "levy", rb_gsl_ran_levy, -1);
1742
+ rb_define_module_function(mgsl_ran, "levy_skew", rb_gsl_ran_levy_skew, -1);
1743
+
1744
+ rb_define_module_function(mgsl_ran, "gamma", rb_gsl_ran_gamma, -1);
1745
+ rb_define_method(cgsl_rng, "gamma", rb_gsl_ran_gamma, -1);
1746
+ rb_define_module_function(mgsl_ran, "gamma_pdf", rb_gsl_ran_gamma_pdf, 3);
1747
+
1748
+ rb_define_module_function(mgsl_ran, "flat", rb_gsl_ran_flat, -1);
1749
+ rb_define_method(cgsl_rng, "flat", rb_gsl_ran_flat, -1);
1750
+ rb_define_module_function(mgsl_ran, "flat_pdf", rb_gsl_ran_flat_pdf, 3);
1751
+
1752
+ rb_define_module_function(mgsl_ran, "lognormal", rb_gsl_ran_lognormal, -1);
1753
+ rb_define_method(cgsl_rng, "lognormal", rb_gsl_ran_lognormal, -1);
1754
+ rb_define_module_function(mgsl_ran, "lognormal_pdf", rb_gsl_ran_lognormal_pdf, 3);
1755
+
1756
+ rb_define_module_function(mgsl_ran, "chisq", rb_gsl_ran_chisq, -1);
1757
+ rb_define_method(cgsl_rng, "chisq", rb_gsl_ran_chisq, -1);
1758
+ rb_define_module_function(mgsl_ran, "chisq_pdf", rb_gsl_ran_chisq_pdf, 2);
1759
+
1760
+ rb_define_module_function(mgsl_ran, "fdist", rb_gsl_ran_fdist, -1);
1761
+ rb_define_method(cgsl_rng, "fdist", rb_gsl_ran_fdist, -1);
1762
+ rb_define_module_function(mgsl_ran, "fdist_pdf", rb_gsl_ran_fdist_pdf, 3);
1763
+
1764
+ rb_define_module_function(mgsl_ran, "tdist", rb_gsl_ran_tdist, -1);
1765
+ rb_define_method(cgsl_rng, "tdist", rb_gsl_ran_tdist, -1);
1766
+ rb_define_module_function(mgsl_ran, "tdist_pdf", rb_gsl_ran_tdist_pdf, 2);
1767
+
1768
+ rb_define_module_function(mgsl_ran, "beta", rb_gsl_ran_beta, -1);
1769
+ rb_define_method(cgsl_rng, "beta", rb_gsl_ran_beta, -1);
1770
+ rb_define_module_function(mgsl_ran, "beta_pdf", rb_gsl_ran_beta_pdf, 3);
1771
+
1772
+ rb_define_module_function(mgsl_ran, "logistic", rb_gsl_ran_logistic, -1);
1773
+ rb_define_method(cgsl_rng, "logistic", rb_gsl_ran_logistic, -1);
1774
+ rb_define_module_function(mgsl_ran, "logistic_pdf", rb_gsl_ran_logistic_pdf, 2);
1775
+
1776
+ rb_define_module_function(mgsl_ran, "pareto", rb_gsl_ran_pareto, -1);
1777
+ rb_define_method(cgsl_rng, "pareto", rb_gsl_ran_pareto, -1);
1778
+ rb_define_module_function(mgsl_ran, "pareto_pdf", rb_gsl_ran_pareto_pdf, 3);
1779
+
1780
+ rb_define_module_function(mgsl_ran, "weibull", rb_gsl_ran_weibull, -1);
1781
+ rb_define_method(cgsl_rng, "weibull", rb_gsl_ran_weibull, -1);
1782
+ rb_define_module_function(mgsl_ran, "weibull_pdf", rb_gsl_ran_weibull_pdf, 3);
1783
+
1784
+ rb_define_module_function(mgsl_ran, "gumbel1", rb_gsl_ran_gumbel1, -1);
1785
+ rb_define_method(cgsl_rng, "gumbel1", rb_gsl_ran_gumbel1, -1);
1786
+ rb_define_module_function(mgsl_ran, "gumbel1_pdf", rb_gsl_ran_gumbel1_pdf, 3);
1787
+
1788
+ rb_define_module_function(mgsl_ran, "gumbel2", rb_gsl_ran_gumbel2, -1);
1789
+ rb_define_method(cgsl_rng, "gumbel2", rb_gsl_ran_gumbel2, -1);
1790
+ rb_define_module_function(mgsl_ran, "gumbel2_pdf", rb_gsl_ran_gumbel2_pdf, 3);
1791
+
1792
+ rb_define_module_function(mgsl_ran, "poisson", rb_gsl_ran_poisson, -1);
1793
+ rb_define_method(cgsl_rng, "poisson", rb_gsl_ran_poisson, -1);
1794
+ rb_define_module_function(mgsl_ran, "poisson_pdf", rb_gsl_ran_poisson_pdf, 2);
1795
+
1796
+ rb_define_module_function(mgsl_ran, "bernoulli", rb_gsl_ran_bernoulli, -1);
1797
+ rb_define_method(cgsl_rng, "bernoulli", rb_gsl_ran_bernoulli, -1);
1798
+ rb_define_module_function(mgsl_ran, "bernoulli_pdf", rb_gsl_ran_bernoulli_pdf, 2);
1799
+
1800
+ rb_define_module_function(mgsl_ran, "binomial", rb_gsl_ran_binomial, -1);
1801
+ rb_define_method(cgsl_rng, "binomial", rb_gsl_ran_binomial, -1);
1802
+ #ifdef GSL_1_4_LATER
1803
+ rb_define_module_function(mgsl_ran, "binomial_tpe", rb_gsl_ran_binomial_tpe, -1);
1804
+ rb_define_method(cgsl_rng, "binomial_tpe", rb_gsl_ran_binomial_tpe, -1);
1805
+ #endif
1806
+ rb_define_module_function(mgsl_ran, "binomial_pdf", rb_gsl_ran_binomial_pdf, 3);
1807
+
1808
+ rb_define_module_function(mgsl_ran, "negative_binomial",
1809
+ rb_gsl_ran_negative_binomial, -1);
1810
+ rb_define_method(cgsl_rng, "negative_binomial", rb_gsl_ran_negative_binomial, -1);
1811
+ rb_define_module_function(mgsl_ran, "negative_binomial_pdf", rb_gsl_ran_negative_binomial_pdf, 3);
1812
+
1813
+ rb_define_module_function(mgsl_ran, "pascal", rb_gsl_ran_pascal, -1);
1814
+ rb_define_method(cgsl_rng, "pascal", rb_gsl_ran_pascal, -1);
1815
+ rb_define_module_function(mgsl_ran, "pascal_pdf", rb_gsl_ran_pascal_pdf, 3);
1816
+
1817
+ rb_define_module_function(mgsl_ran, "geometric", rb_gsl_ran_geometric, -1);
1818
+ rb_define_method(cgsl_rng, "geometric", rb_gsl_ran_geometric, -1);
1819
+ rb_define_module_function(mgsl_ran, "geometric_pdf", rb_gsl_ran_geometric_pdf, 2);
1820
+
1821
+ rb_define_module_function(mgsl_ran, "hypergeometric", rb_gsl_ran_hypergeometric, -1);
1822
+ rb_define_method(cgsl_rng, "hypergeometric", rb_gsl_ran_hypergeometric, -1);
1823
+ rb_define_module_function(mgsl_ran, "hypergeometric_pdf",
1824
+ rb_gsl_ran_hypergeometric_pdf, 4);
1825
+
1826
+ rb_define_module_function(mgsl_ran, "logarithmic", rb_gsl_ran_logarithmic, -1);
1827
+ rb_define_method(cgsl_rng, "logarithmic", rb_gsl_ran_logarithmic, -1);
1828
+ rb_define_module_function(mgsl_ran, "logarithmic_pdf",
1829
+ rb_gsl_ran_logarithmic_pdf, 2);
1830
+
1831
+ rb_define_module_function(mgsl_ran, "dir_2d", rb_gsl_ran_dir_2d, -1);
1832
+ rb_define_module_function(mgsl_ran, "dir_2d_trig_method",
1833
+ rb_gsl_ran_dir_2d_trig_method, -1);
1834
+ rb_define_module_function(mgsl_ran, "dir_3d", rb_gsl_ran_dir_3d, -1);
1835
+ rb_define_module_function(mgsl_ran, "dir_nd", rb_gsl_ran_dir_nd, -1);
1836
+
1837
+ rb_define_method(cgsl_rng, "dir_2d", rb_gsl_ran_dir_2d, -1);
1838
+ rb_define_method(cgsl_rng, "dir_2d_trig_method", rb_gsl_ran_dir_2d_trig_method, -1);
1839
+ rb_define_method(cgsl_rng, "dir_3d", rb_gsl_ran_dir_3d, -1);
1840
+ rb_define_method(cgsl_rng, "dir_nd", rb_gsl_ran_dir_nd, -1);
1841
+
1842
+ rb_define_method(cgsl_rng, "shuffle", rb_gsl_ran_shuffle, -1);
1843
+ rb_define_module_function(mgsl_ran, "shuffle", rb_gsl_ran_shuffle, -1);
1844
+ rb_define_method(cgsl_rng, "choose", rb_gsl_ran_choose, -1);
1845
+ rb_define_singleton_method(mgsl_ran, "choose", rb_gsl_ran_choose_singleton, -1);
1846
+ rb_define_method(cgsl_rng, "sample", rb_gsl_ran_sample, 2);
1847
+
1848
+ /*****/
1849
+
1850
+ cgsl_ran_discrete = rb_define_class_under(mgsl_ran, "Discrete", cGSL_Object);
1851
+ rb_define_singleton_method(cgsl_ran_discrete, "alloc", rb_gsl_ran_discrete_new, 1);
1852
+ rb_define_singleton_method(cgsl_ran_discrete, "preproc", rb_gsl_ran_discrete_new, 1);
1853
+ rb_define_method(cgsl_rng, "discrete", rb_gsl_ran_discrete, 1);
1854
+ rb_define_module_function(mgsl_ran, "discrete_pdf", rb_gsl_ran_discrete_pdf, 2);
1855
+
1856
+ #ifdef GSL_1_3_LATER
1857
+ rb_define_method(cgsl_rng, "dirichlet", rb_gsl_ran_dirichlet, -1);
1858
+ rb_define_module_function(mgsl_ran, "dirichlet_pdf", rb_gsl_ran_dirichlet_pdf, 2);
1859
+ rb_define_module_function(mgsl_ran, "dirichlet_lnpdf", rb_gsl_ran_dirichlet_lnpdf, 2);
1860
+ #endif
1861
+
1862
+ /* rb_define_method(cgsl_rng, "erlang", rb_gsl_ran_erlang, 2);
1863
+ rb_define_method(module, "ran_erlang_pdf", rb_gsl_ran_erlang_pdf, 3);
1864
+ rb_define_method(mgsl_ran, "erlang_pdf", rb_gsl_ran_erlang_pdf, 3);*/
1865
+
1866
+ #ifdef GSL_1_8_LATER
1867
+ rb_define_module_function(mgsl_ran, "gaussian_ziggurat", rb_gsl_ran_gaussian_ziggurat, -1);
1868
+ rb_define_method(cgsl_rng, "gaussian_ziggurat", rb_gsl_ran_gaussian_ziggurat, -1);
1869
+ rb_define_module_function(mgsl_ran, "gamma_mt", rb_gsl_ran_gamma_mt, -1);
1870
+ rb_define_method(cgsl_rng, "gamma_mt", rb_gsl_ran_gamma_mt, -1);
1871
+ #endif
1872
+
1873
+ }