rb-gsl 1.16.0.5 → 1.16.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (612) hide show
  1. checksums.yaml +4 -4
  2. data/rb-gsl.gemspec +5 -10
  3. metadata +10 -713
  4. data/.gitignore +0 -12
  5. data/.travis.yml +0 -24
  6. data/AUTHORS +0 -12
  7. data/COPYING +0 -341
  8. data/ChangeLog +0 -621
  9. data/Gemfile +0 -4
  10. data/README.md +0 -77
  11. data/Rakefile +0 -20
  12. data/THANKS +0 -17
  13. data/examples/alf/alf.gp +0 -15
  14. data/examples/alf/alf.rb +0 -32
  15. data/examples/blas/blas.rb +0 -13
  16. data/examples/blas/dnrm2.rb +0 -16
  17. data/examples/blas/level1.rb +0 -81
  18. data/examples/blas/level2.rb +0 -11
  19. data/examples/blas/level3.rb +0 -12
  20. data/examples/bspline.rb +0 -57
  21. data/examples/cdf.rb +0 -16
  22. data/examples/cheb.rb +0 -21
  23. data/examples/combination.rb +0 -23
  24. data/examples/complex/RC-lpf.rb +0 -47
  25. data/examples/complex/add.rb +0 -36
  26. data/examples/complex/coerce.rb +0 -14
  27. data/examples/complex/complex.rb +0 -25
  28. data/examples/complex/fpmi.rb +0 -70
  29. data/examples/complex/functions.rb +0 -77
  30. data/examples/complex/michelson.rb +0 -36
  31. data/examples/complex/mul.rb +0 -28
  32. data/examples/complex/oscillator.rb +0 -17
  33. data/examples/complex/set.rb +0 -37
  34. data/examples/const/physconst.rb +0 -151
  35. data/examples/const/travel.rb +0 -45
  36. data/examples/deriv/demo.rb +0 -13
  37. data/examples/deriv/deriv.rb +0 -36
  38. data/examples/deriv/diff.rb +0 -35
  39. data/examples/dht.rb +0 -42
  40. data/examples/dirac.rb +0 -56
  41. data/examples/eigen/eigen.rb +0 -34
  42. data/examples/eigen/herm.rb +0 -22
  43. data/examples/eigen/narray.rb +0 -9
  44. data/examples/eigen/nonsymm.rb +0 -37
  45. data/examples/eigen/nonsymmv.rb +0 -43
  46. data/examples/eigen/qhoscillator.gp +0 -35
  47. data/examples/eigen/qhoscillator.rb +0 -90
  48. data/examples/eigen/vander.rb +0 -41
  49. data/examples/fft/fft.rb +0 -17
  50. data/examples/fft/fft2.rb +0 -17
  51. data/examples/fft/forward.rb +0 -25
  52. data/examples/fft/forward2.rb +0 -26
  53. data/examples/fft/radix2.rb +0 -18
  54. data/examples/fft/real-halfcomplex.rb +0 -33
  55. data/examples/fft/real-halfcomplex2.rb +0 -30
  56. data/examples/fft/realradix2.rb +0 -19
  57. data/examples/fft/sunspot.dat +0 -256
  58. data/examples/fft/sunspot.rb +0 -16
  59. data/examples/fit/expdata.dat +0 -20
  60. data/examples/fit/expfit.rb +0 -31
  61. data/examples/fit/gaussfit.rb +0 -29
  62. data/examples/fit/gaussian_2peaks.rb +0 -34
  63. data/examples/fit/hillfit.rb +0 -40
  64. data/examples/fit/lognormal.rb +0 -26
  65. data/examples/fit/lorentzfit.rb +0 -22
  66. data/examples/fit/multifit.rb +0 -72
  67. data/examples/fit/ndlinear.rb +0 -133
  68. data/examples/fit/nonlinearfit.rb +0 -89
  69. data/examples/fit/plot.gp +0 -36
  70. data/examples/fit/polyfit.rb +0 -9
  71. data/examples/fit/powerfit.rb +0 -21
  72. data/examples/fit/sigmoidfit.rb +0 -40
  73. data/examples/fit/sinfit.rb +0 -22
  74. data/examples/fit/wlinear.rb +0 -46
  75. data/examples/fresnel.rb +0 -11
  76. data/examples/function/function.rb +0 -36
  77. data/examples/function/log.rb +0 -7
  78. data/examples/function/min.rb +0 -33
  79. data/examples/function/sin.rb +0 -10
  80. data/examples/function/synchrotron.rb +0 -18
  81. data/examples/gallery/butterfly.rb +0 -7
  82. data/examples/gallery/cayley.rb +0 -12
  83. data/examples/gallery/cornu.rb +0 -23
  84. data/examples/gallery/eight.rb +0 -11
  85. data/examples/gallery/koch.rb +0 -40
  86. data/examples/gallery/lemniscate.rb +0 -11
  87. data/examples/gallery/polar.rb +0 -11
  88. data/examples/gallery/rgplot/cossin.rb +0 -35
  89. data/examples/gallery/rgplot/rgplot.replaced +0 -0
  90. data/examples/gallery/rgplot/roesller.rb +0 -55
  91. data/examples/gallery/roesller.rb +0 -39
  92. data/examples/gallery/scarabaeus.rb +0 -14
  93. data/examples/histogram/cauchy.rb +0 -27
  94. data/examples/histogram/cauchy.sh +0 -2
  95. data/examples/histogram/exponential.rb +0 -19
  96. data/examples/histogram/gauss.rb +0 -16
  97. data/examples/histogram/gsl-histogram.rb +0 -40
  98. data/examples/histogram/histo2d.rb +0 -31
  99. data/examples/histogram/histo3d.rb +0 -34
  100. data/examples/histogram/histogram-pdf.rb +0 -27
  101. data/examples/histogram/histogram.rb +0 -26
  102. data/examples/histogram/integral.rb +0 -28
  103. data/examples/histogram/poisson.rb +0 -27
  104. data/examples/histogram/power.rb +0 -25
  105. data/examples/histogram/rebin.rb +0 -17
  106. data/examples/histogram/smp.dat +0 -5
  107. data/examples/histogram/xexp.rb +0 -21
  108. data/examples/integration/ahmed.rb +0 -21
  109. data/examples/integration/cosmology.rb +0 -75
  110. data/examples/integration/friedmann.gp +0 -16
  111. data/examples/integration/friedmann.rb +0 -35
  112. data/examples/integration/gamma-zeta.rb +0 -35
  113. data/examples/integration/integration.rb +0 -22
  114. data/examples/integration/qag.rb +0 -8
  115. data/examples/integration/qag2.rb +0 -14
  116. data/examples/integration/qag3.rb +0 -8
  117. data/examples/integration/qagi.rb +0 -28
  118. data/examples/integration/qagi2.rb +0 -49
  119. data/examples/integration/qagiu.rb +0 -29
  120. data/examples/integration/qagp.rb +0 -20
  121. data/examples/integration/qags.rb +0 -14
  122. data/examples/integration/qawc.rb +0 -18
  123. data/examples/integration/qawf.rb +0 -41
  124. data/examples/integration/qawo.rb +0 -29
  125. data/examples/integration/qaws.rb +0 -30
  126. data/examples/integration/qng.rb +0 -17
  127. data/examples/interp/demo.gp +0 -20
  128. data/examples/interp/demo.rb +0 -45
  129. data/examples/interp/interp.rb +0 -37
  130. data/examples/interp/points +0 -10
  131. data/examples/interp/spline.rb +0 -20
  132. data/examples/jacobi/deriv.rb +0 -40
  133. data/examples/jacobi/integrate.rb +0 -34
  134. data/examples/jacobi/interp.rb +0 -43
  135. data/examples/jacobi/jacobi.rb +0 -11
  136. data/examples/linalg/HH.rb +0 -15
  137. data/examples/linalg/HH_narray.rb +0 -13
  138. data/examples/linalg/LQ_solve.rb +0 -73
  139. data/examples/linalg/LU.rb +0 -84
  140. data/examples/linalg/LU2.rb +0 -31
  141. data/examples/linalg/LU_narray.rb +0 -24
  142. data/examples/linalg/PTLQ.rb +0 -47
  143. data/examples/linalg/QR.rb +0 -18
  144. data/examples/linalg/QRPT.rb +0 -47
  145. data/examples/linalg/QR_solve.rb +0 -78
  146. data/examples/linalg/QR_solve_narray.rb +0 -13
  147. data/examples/linalg/SV.rb +0 -16
  148. data/examples/linalg/SV_narray.rb +0 -12
  149. data/examples/linalg/SV_solve.rb +0 -49
  150. data/examples/linalg/chol.rb +0 -29
  151. data/examples/linalg/chol_narray.rb +0 -15
  152. data/examples/linalg/complex.rb +0 -57
  153. data/examples/linalg/invert_narray.rb +0 -10
  154. data/examples/math/const.rb +0 -67
  155. data/examples/math/elementary.rb +0 -35
  156. data/examples/math/functions.rb +0 -41
  157. data/examples/math/inf_nan.rb +0 -34
  158. data/examples/math/minmax.rb +0 -22
  159. data/examples/math/power.rb +0 -18
  160. data/examples/math/test.rb +0 -31
  161. data/examples/matrix/a.dat +0 -0
  162. data/examples/matrix/add.rb +0 -45
  163. data/examples/matrix/b.dat +0 -4
  164. data/examples/matrix/cat.rb +0 -31
  165. data/examples/matrix/colvectors.rb +0 -24
  166. data/examples/matrix/complex.rb +0 -41
  167. data/examples/matrix/det.rb +0 -29
  168. data/examples/matrix/diagonal.rb +0 -23
  169. data/examples/matrix/get_all.rb +0 -159
  170. data/examples/matrix/hilbert.rb +0 -31
  171. data/examples/matrix/iterator.rb +0 -19
  172. data/examples/matrix/matrix.rb +0 -57
  173. data/examples/matrix/minmax.rb +0 -53
  174. data/examples/matrix/mul.rb +0 -39
  175. data/examples/matrix/rand.rb +0 -20
  176. data/examples/matrix/read.rb +0 -29
  177. data/examples/matrix/rowcol.rb +0 -47
  178. data/examples/matrix/set.rb +0 -41
  179. data/examples/matrix/set_all.rb +0 -100
  180. data/examples/matrix/view.rb +0 -32
  181. data/examples/matrix/view_all.rb +0 -148
  182. data/examples/matrix/write.rb +0 -23
  183. data/examples/min.rb +0 -29
  184. data/examples/monte/miser.rb +0 -47
  185. data/examples/monte/monte.rb +0 -47
  186. data/examples/monte/plain.rb +0 -47
  187. data/examples/monte/vegas.rb +0 -46
  188. data/examples/multimin/bundle.rb +0 -66
  189. data/examples/multimin/cqp.rb +0 -109
  190. data/examples/multimin/fdfminimizer.rb +0 -40
  191. data/examples/multimin/fminimizer.rb +0 -41
  192. data/examples/multiroot/demo.rb +0 -36
  193. data/examples/multiroot/fdfsolver.rb +0 -50
  194. data/examples/multiroot/fsolver.rb +0 -33
  195. data/examples/multiroot/fsolver2.rb +0 -32
  196. data/examples/multiroot/fsolver3.rb +0 -26
  197. data/examples/narray/histogram.rb +0 -14
  198. data/examples/narray/mandel.rb +0 -27
  199. data/examples/narray/narray.rb +0 -28
  200. data/examples/narray/narray2.rb +0 -44
  201. data/examples/narray/sf.rb +0 -26
  202. data/examples/ntuple/create.rb +0 -17
  203. data/examples/ntuple/project.rb +0 -31
  204. data/examples/odeiv/binarysystem.gp +0 -23
  205. data/examples/odeiv/binarysystem.rb +0 -104
  206. data/examples/odeiv/demo.gp +0 -24
  207. data/examples/odeiv/demo.rb +0 -69
  208. data/examples/odeiv/demo2.gp +0 -26
  209. data/examples/odeiv/duffing.rb +0 -45
  210. data/examples/odeiv/frei1.rb +0 -109
  211. data/examples/odeiv/frei2.rb +0 -76
  212. data/examples/odeiv/legendre.rb +0 -52
  213. data/examples/odeiv/odeiv.rb +0 -32
  214. data/examples/odeiv/odeiv2.rb +0 -45
  215. data/examples/odeiv/oscillator.rb +0 -42
  216. data/examples/odeiv/sedov.rb +0 -97
  217. data/examples/odeiv/whitedwarf.gp +0 -40
  218. data/examples/odeiv/whitedwarf.rb +0 -158
  219. data/examples/ool/conmin.rb +0 -100
  220. data/examples/ool/gencan.rb +0 -99
  221. data/examples/ool/pgrad.rb +0 -100
  222. data/examples/ool/spg.rb +0 -100
  223. data/examples/pdf/bernoulli.rb +0 -5
  224. data/examples/pdf/beta.rb +0 -7
  225. data/examples/pdf/binomiral.rb +0 -10
  226. data/examples/pdf/cauchy.rb +0 -6
  227. data/examples/pdf/chisq.rb +0 -8
  228. data/examples/pdf/exponential.rb +0 -7
  229. data/examples/pdf/exppow.rb +0 -6
  230. data/examples/pdf/fdist.rb +0 -7
  231. data/examples/pdf/flat.rb +0 -7
  232. data/examples/pdf/gamma.rb +0 -8
  233. data/examples/pdf/gauss-tail.rb +0 -5
  234. data/examples/pdf/gauss.rb +0 -6
  235. data/examples/pdf/geometric.rb +0 -5
  236. data/examples/pdf/gumbel.rb +0 -6
  237. data/examples/pdf/hypergeometric.rb +0 -11
  238. data/examples/pdf/landau.rb +0 -5
  239. data/examples/pdf/laplace.rb +0 -7
  240. data/examples/pdf/logarithmic.rb +0 -5
  241. data/examples/pdf/logistic.rb +0 -6
  242. data/examples/pdf/lognormal.rb +0 -6
  243. data/examples/pdf/neg-binomiral.rb +0 -10
  244. data/examples/pdf/pareto.rb +0 -7
  245. data/examples/pdf/pascal.rb +0 -10
  246. data/examples/pdf/poisson.rb +0 -5
  247. data/examples/pdf/rayleigh-tail.rb +0 -6
  248. data/examples/pdf/rayleigh.rb +0 -6
  249. data/examples/pdf/tdist.rb +0 -6
  250. data/examples/pdf/weibull.rb +0 -8
  251. data/examples/permutation/ex1.rb +0 -22
  252. data/examples/permutation/permutation.rb +0 -16
  253. data/examples/poly/bell.rb +0 -6
  254. data/examples/poly/bessel.rb +0 -6
  255. data/examples/poly/cheb.rb +0 -6
  256. data/examples/poly/cheb_II.rb +0 -6
  257. data/examples/poly/cubic.rb +0 -9
  258. data/examples/poly/demo.rb +0 -20
  259. data/examples/poly/eval.rb +0 -28
  260. data/examples/poly/eval_derivs.rb +0 -14
  261. data/examples/poly/fit.rb +0 -21
  262. data/examples/poly/hermite.rb +0 -6
  263. data/examples/poly/poly.rb +0 -13
  264. data/examples/poly/quadratic.rb +0 -25
  265. data/examples/random/diffusion.rb +0 -34
  266. data/examples/random/gaussian.rb +0 -9
  267. data/examples/random/generator.rb +0 -27
  268. data/examples/random/hdsobol.rb +0 -21
  269. data/examples/random/poisson.rb +0 -9
  270. data/examples/random/qrng.rb +0 -19
  271. data/examples/random/randomwalk.rb +0 -37
  272. data/examples/random/randomwalk2d.rb +0 -19
  273. data/examples/random/rayleigh.rb +0 -36
  274. data/examples/random/rng.rb +0 -33
  275. data/examples/random/rngextra.rb +0 -14
  276. data/examples/roots/bisection.rb +0 -25
  277. data/examples/roots/brent.rb +0 -43
  278. data/examples/roots/demo.rb +0 -30
  279. data/examples/roots/newton.rb +0 -46
  280. data/examples/roots/recombination.gp +0 -11
  281. data/examples/roots/recombination.rb +0 -61
  282. data/examples/roots/steffenson.rb +0 -48
  283. data/examples/sf/ShiChi.rb +0 -6
  284. data/examples/sf/SiCi.rb +0 -6
  285. data/examples/sf/airy_Ai.rb +0 -8
  286. data/examples/sf/airy_Bi.rb +0 -8
  287. data/examples/sf/bessel_IK.rb +0 -12
  288. data/examples/sf/bessel_JY.rb +0 -13
  289. data/examples/sf/beta_inc.rb +0 -9
  290. data/examples/sf/clausen.rb +0 -6
  291. data/examples/sf/dawson.rb +0 -5
  292. data/examples/sf/debye.rb +0 -9
  293. data/examples/sf/dilog.rb +0 -6
  294. data/examples/sf/ellint.rb +0 -6
  295. data/examples/sf/expint.rb +0 -8
  296. data/examples/sf/fermi.rb +0 -10
  297. data/examples/sf/gamma_inc_P.rb +0 -9
  298. data/examples/sf/gegenbauer.rb +0 -8
  299. data/examples/sf/hyperg.rb +0 -7
  300. data/examples/sf/laguerre.rb +0 -19
  301. data/examples/sf/lambertW.rb +0 -5
  302. data/examples/sf/legendre_P.rb +0 -10
  303. data/examples/sf/lngamma.rb +0 -5
  304. data/examples/sf/psi.rb +0 -54
  305. data/examples/sf/sphbessel.gp +0 -27
  306. data/examples/sf/sphbessel.rb +0 -30
  307. data/examples/sf/synchrotron.rb +0 -5
  308. data/examples/sf/transport.rb +0 -10
  309. data/examples/sf/zetam1.rb +0 -5
  310. data/examples/siman.rb +0 -44
  311. data/examples/sort/heapsort.rb +0 -23
  312. data/examples/sort/heapsort_vector_complex.rb +0 -21
  313. data/examples/sort/sort.rb +0 -23
  314. data/examples/sort/sort2.rb +0 -16
  315. data/examples/stats/mean.rb +0 -17
  316. data/examples/stats/statistics.rb +0 -18
  317. data/examples/stats/test.rb +0 -9
  318. data/examples/sum.rb +0 -34
  319. data/examples/tamu_anova.rb +0 -18
  320. data/examples/vector/a.dat +0 -0
  321. data/examples/vector/add.rb +0 -56
  322. data/examples/vector/b.dat +0 -4
  323. data/examples/vector/c.dat +0 -3
  324. data/examples/vector/collect.rb +0 -26
  325. data/examples/vector/compare.rb +0 -28
  326. data/examples/vector/complex.rb +0 -51
  327. data/examples/vector/complex_get_all.rb +0 -85
  328. data/examples/vector/complex_set_all.rb +0 -131
  329. data/examples/vector/complex_view_all.rb +0 -77
  330. data/examples/vector/connect.rb +0 -22
  331. data/examples/vector/decimate.rb +0 -38
  332. data/examples/vector/diff.rb +0 -31
  333. data/examples/vector/filescan.rb +0 -17
  334. data/examples/vector/floor.rb +0 -23
  335. data/examples/vector/get_all.rb +0 -82
  336. data/examples/vector/gnuplot.rb +0 -38
  337. data/examples/vector/graph.rb +0 -28
  338. data/examples/vector/histogram.rb +0 -22
  339. data/examples/vector/linspace.rb +0 -24
  340. data/examples/vector/log.rb +0 -17
  341. data/examples/vector/logic.rb +0 -33
  342. data/examples/vector/logspace.rb +0 -25
  343. data/examples/vector/minmax.rb +0 -47
  344. data/examples/vector/mul.rb +0 -49
  345. data/examples/vector/narray.rb +0 -46
  346. data/examples/vector/read.rb +0 -29
  347. data/examples/vector/set.rb +0 -35
  348. data/examples/vector/set_all.rb +0 -121
  349. data/examples/vector/smpv.dat +0 -15
  350. data/examples/vector/test.rb +0 -43
  351. data/examples/vector/test_gslblock.rb +0 -58
  352. data/examples/vector/vector.rb +0 -110
  353. data/examples/vector/view.rb +0 -35
  354. data/examples/vector/view_all.rb +0 -73
  355. data/examples/vector/where.rb +0 -29
  356. data/examples/vector/write.rb +0 -24
  357. data/examples/vector/zip.rb +0 -34
  358. data/examples/wavelet/ecg.dat +0 -256
  359. data/examples/wavelet/wavelet1.rb +0 -50
  360. data/ext/gsl_native/alf.c +0 -206
  361. data/ext/gsl_native/array.c +0 -553
  362. data/ext/gsl_native/array_complex.c +0 -245
  363. data/ext/gsl_native/blas.c +0 -28
  364. data/ext/gsl_native/blas1.c +0 -733
  365. data/ext/gsl_native/blas2.c +0 -1088
  366. data/ext/gsl_native/blas3.c +0 -880
  367. data/ext/gsl_native/block.c +0 -40
  368. data/ext/gsl_native/block_source.h +0 -885
  369. data/ext/gsl_native/bspline.c +0 -122
  370. data/ext/gsl_native/bundle.c +0 -3
  371. data/ext/gsl_native/cdf.c +0 -740
  372. data/ext/gsl_native/cheb.c +0 -531
  373. data/ext/gsl_native/combination.c +0 -275
  374. data/ext/gsl_native/common.c +0 -293
  375. data/ext/gsl_native/complex.c +0 -1002
  376. data/ext/gsl_native/const.c +0 -331
  377. data/ext/gsl_native/const_additional.c +0 -99
  378. data/ext/gsl_native/cqp.c +0 -283
  379. data/ext/gsl_native/deriv.c +0 -187
  380. data/ext/gsl_native/dht.c +0 -353
  381. data/ext/gsl_native/diff.c +0 -164
  382. data/ext/gsl_native/dirac.c +0 -388
  383. data/ext/gsl_native/eigen.c +0 -2322
  384. data/ext/gsl_native/error.c +0 -193
  385. data/ext/gsl_native/extconf.rb +0 -118
  386. data/ext/gsl_native/fft.c +0 -1095
  387. data/ext/gsl_native/fit.c +0 -204
  388. data/ext/gsl_native/fresnel.c +0 -312
  389. data/ext/gsl_native/function.c +0 -518
  390. data/ext/gsl_native/geometry.c +0 -139
  391. data/ext/gsl_native/graph.c +0 -1590
  392. data/ext/gsl_native/gsl.c +0 -259
  393. data/ext/gsl_native/gsl_narray.c +0 -794
  394. data/ext/gsl_native/histogram.c +0 -1964
  395. data/ext/gsl_native/histogram2d.c +0 -1042
  396. data/ext/gsl_native/histogram3d.c +0 -884
  397. data/ext/gsl_native/histogram3d_source.c +0 -749
  398. data/ext/gsl_native/histogram_find.c +0 -99
  399. data/ext/gsl_native/histogram_oper.c +0 -150
  400. data/ext/gsl_native/ieee.c +0 -88
  401. data/ext/gsl_native/include/rb_gsl.h +0 -136
  402. data/ext/gsl_native/include/rb_gsl_array.h +0 -214
  403. data/ext/gsl_native/include/rb_gsl_cheb.h +0 -19
  404. data/ext/gsl_native/include/rb_gsl_common.h +0 -348
  405. data/ext/gsl_native/include/rb_gsl_complex.h +0 -25
  406. data/ext/gsl_native/include/rb_gsl_const.h +0 -23
  407. data/ext/gsl_native/include/rb_gsl_dirac.h +0 -6
  408. data/ext/gsl_native/include/rb_gsl_eigen.h +0 -17
  409. data/ext/gsl_native/include/rb_gsl_fft.h +0 -49
  410. data/ext/gsl_native/include/rb_gsl_fit.h +0 -23
  411. data/ext/gsl_native/include/rb_gsl_function.h +0 -23
  412. data/ext/gsl_native/include/rb_gsl_graph.h +0 -68
  413. data/ext/gsl_native/include/rb_gsl_histogram.h +0 -63
  414. data/ext/gsl_native/include/rb_gsl_histogram3d.h +0 -97
  415. data/ext/gsl_native/include/rb_gsl_integration.h +0 -17
  416. data/ext/gsl_native/include/rb_gsl_interp.h +0 -41
  417. data/ext/gsl_native/include/rb_gsl_linalg.h +0 -21
  418. data/ext/gsl_native/include/rb_gsl_math.h +0 -20
  419. data/ext/gsl_native/include/rb_gsl_odeiv.h +0 -18
  420. data/ext/gsl_native/include/rb_gsl_poly.h +0 -67
  421. data/ext/gsl_native/include/rb_gsl_rational.h +0 -30
  422. data/ext/gsl_native/include/rb_gsl_rng.h +0 -20
  423. data/ext/gsl_native/include/rb_gsl_root.h +0 -22
  424. data/ext/gsl_native/include/rb_gsl_sf.h +0 -110
  425. data/ext/gsl_native/include/rb_gsl_statistics.h +0 -17
  426. data/ext/gsl_native/include/rb_gsl_tensor.h +0 -43
  427. data/ext/gsl_native/include/rb_gsl_with_narray.h +0 -31
  428. data/ext/gsl_native/include/templates_off.h +0 -87
  429. data/ext/gsl_native/include/templates_on.h +0 -241
  430. data/ext/gsl_native/integration.c +0 -1154
  431. data/ext/gsl_native/interp.c +0 -499
  432. data/ext/gsl_native/jacobi.c +0 -733
  433. data/ext/gsl_native/linalg.c +0 -3915
  434. data/ext/gsl_native/linalg_complex.c +0 -726
  435. data/ext/gsl_native/math.c +0 -706
  436. data/ext/gsl_native/matrix.c +0 -36
  437. data/ext/gsl_native/matrix_complex.c +0 -1733
  438. data/ext/gsl_native/matrix_double.c +0 -557
  439. data/ext/gsl_native/matrix_int.c +0 -255
  440. data/ext/gsl_native/matrix_source.h +0 -2708
  441. data/ext/gsl_native/min.c +0 -219
  442. data/ext/gsl_native/monte.c +0 -978
  443. data/ext/gsl_native/multifit.c +0 -1862
  444. data/ext/gsl_native/multimin.c +0 -778
  445. data/ext/gsl_native/multimin_fsdf.c +0 -156
  446. data/ext/gsl_native/multiroots.c +0 -952
  447. data/ext/gsl_native/multiset.c +0 -210
  448. data/ext/gsl_native/ndlinear.c +0 -320
  449. data/ext/gsl_native/nmf.c +0 -171
  450. data/ext/gsl_native/nmf_wrap.c +0 -75
  451. data/ext/gsl_native/ntuple.c +0 -469
  452. data/ext/gsl_native/odeiv.c +0 -947
  453. data/ext/gsl_native/ool.c +0 -879
  454. data/ext/gsl_native/permutation.c +0 -598
  455. data/ext/gsl_native/poly.c +0 -39
  456. data/ext/gsl_native/poly2.c +0 -265
  457. data/ext/gsl_native/poly_source.h +0 -1871
  458. data/ext/gsl_native/qrng.c +0 -160
  459. data/ext/gsl_native/randist.c +0 -1848
  460. data/ext/gsl_native/rational.c +0 -480
  461. data/ext/gsl_native/rng.c +0 -595
  462. data/ext/gsl_native/root.c +0 -407
  463. data/ext/gsl_native/sf.c +0 -1446
  464. data/ext/gsl_native/sf_airy.c +0 -200
  465. data/ext/gsl_native/sf_bessel.c +0 -871
  466. data/ext/gsl_native/sf_clausen.c +0 -28
  467. data/ext/gsl_native/sf_coulomb.c +0 -206
  468. data/ext/gsl_native/sf_coupling.c +0 -121
  469. data/ext/gsl_native/sf_dawson.c +0 -29
  470. data/ext/gsl_native/sf_debye.c +0 -148
  471. data/ext/gsl_native/sf_dilog.c +0 -43
  472. data/ext/gsl_native/sf_elementary.c +0 -46
  473. data/ext/gsl_native/sf_ellint.c +0 -206
  474. data/ext/gsl_native/sf_elljac.c +0 -30
  475. data/ext/gsl_native/sf_erfc.c +0 -89
  476. data/ext/gsl_native/sf_exp.c +0 -169
  477. data/ext/gsl_native/sf_expint.c +0 -201
  478. data/ext/gsl_native/sf_fermi_dirac.c +0 -148
  479. data/ext/gsl_native/sf_gamma.c +0 -343
  480. data/ext/gsl_native/sf_gegenbauer.c +0 -97
  481. data/ext/gsl_native/sf_hyperg.c +0 -203
  482. data/ext/gsl_native/sf_laguerre.c +0 -113
  483. data/ext/gsl_native/sf_lambert.c +0 -47
  484. data/ext/gsl_native/sf_legendre.c +0 -368
  485. data/ext/gsl_native/sf_log.c +0 -105
  486. data/ext/gsl_native/sf_mathieu.c +0 -235
  487. data/ext/gsl_native/sf_power.c +0 -47
  488. data/ext/gsl_native/sf_psi.c +0 -89
  489. data/ext/gsl_native/sf_synchrotron.c +0 -48
  490. data/ext/gsl_native/sf_transport.c +0 -76
  491. data/ext/gsl_native/sf_trigonometric.c +0 -210
  492. data/ext/gsl_native/sf_zeta.c +0 -115
  493. data/ext/gsl_native/signal.c +0 -303
  494. data/ext/gsl_native/siman.c +0 -713
  495. data/ext/gsl_native/sort.c +0 -207
  496. data/ext/gsl_native/spline.c +0 -377
  497. data/ext/gsl_native/stats.c +0 -787
  498. data/ext/gsl_native/sum.c +0 -168
  499. data/ext/gsl_native/tamu_anova.c +0 -56
  500. data/ext/gsl_native/tensor.c +0 -35
  501. data/ext/gsl_native/tensor_source.h +0 -1122
  502. data/ext/gsl_native/vector.c +0 -35
  503. data/ext/gsl_native/vector_complex.c +0 -2241
  504. data/ext/gsl_native/vector_double.c +0 -1433
  505. data/ext/gsl_native/vector_int.c +0 -202
  506. data/ext/gsl_native/vector_source.h +0 -3321
  507. data/ext/gsl_native/wavelet.c +0 -923
  508. data/lib/gsl.rb +0 -8
  509. data/lib/gsl/gnuplot.rb +0 -41
  510. data/lib/gsl/oper.rb +0 -43
  511. data/lib/gsl/version.rb +0 -3
  512. data/lib/ool.rb +0 -22
  513. data/lib/ool/conmin.rb +0 -30
  514. data/lib/rbgsl.rb +0 -1
  515. data/rdoc/alf.rdoc +0 -77
  516. data/rdoc/blas.rdoc +0 -269
  517. data/rdoc/bspline.rdoc +0 -42
  518. data/rdoc/changes.rdoc +0 -159
  519. data/rdoc/cheb.rdoc +0 -99
  520. data/rdoc/cholesky_complex.rdoc +0 -46
  521. data/rdoc/combi.rdoc +0 -125
  522. data/rdoc/complex.rdoc +0 -210
  523. data/rdoc/const.rdoc +0 -546
  524. data/rdoc/dht.rdoc +0 -122
  525. data/rdoc/diff.rdoc +0 -133
  526. data/rdoc/ehandling.rdoc +0 -50
  527. data/rdoc/eigen.rdoc +0 -401
  528. data/rdoc/fft.rdoc +0 -535
  529. data/rdoc/fit.rdoc +0 -284
  530. data/rdoc/function.rdoc +0 -94
  531. data/rdoc/graph.rdoc +0 -137
  532. data/rdoc/hist.rdoc +0 -409
  533. data/rdoc/hist2d.rdoc +0 -279
  534. data/rdoc/hist3d.rdoc +0 -112
  535. data/rdoc/integration.rdoc +0 -398
  536. data/rdoc/interp.rdoc +0 -231
  537. data/rdoc/intro.rdoc +0 -27
  538. data/rdoc/linalg.rdoc +0 -681
  539. data/rdoc/linalg_complex.rdoc +0 -88
  540. data/rdoc/math.rdoc +0 -276
  541. data/rdoc/matrix.rdoc +0 -1093
  542. data/rdoc/min.rdoc +0 -189
  543. data/rdoc/monte.rdoc +0 -234
  544. data/rdoc/multimin.rdoc +0 -312
  545. data/rdoc/multiroot.rdoc +0 -293
  546. data/rdoc/narray.rdoc +0 -177
  547. data/rdoc/ndlinear.rdoc +0 -250
  548. data/rdoc/nonlinearfit.rdoc +0 -348
  549. data/rdoc/ntuple.rdoc +0 -88
  550. data/rdoc/odeiv.rdoc +0 -378
  551. data/rdoc/perm.rdoc +0 -221
  552. data/rdoc/poly.rdoc +0 -335
  553. data/rdoc/qrng.rdoc +0 -90
  554. data/rdoc/randist.rdoc +0 -233
  555. data/rdoc/ref.rdoc +0 -93
  556. data/rdoc/rng.rdoc +0 -203
  557. data/rdoc/roots.rdoc +0 -305
  558. data/rdoc/sf.rdoc +0 -1622
  559. data/rdoc/siman.rdoc +0 -89
  560. data/rdoc/sort.rdoc +0 -94
  561. data/rdoc/start.rdoc +0 -16
  562. data/rdoc/stats.rdoc +0 -219
  563. data/rdoc/sum.rdoc +0 -65
  564. data/rdoc/tensor.rdoc +0 -251
  565. data/rdoc/tut.rdoc +0 -5
  566. data/rdoc/use.rdoc +0 -177
  567. data/rdoc/vector.rdoc +0 -1243
  568. data/rdoc/vector_complex.rdoc +0 -347
  569. data/rdoc/wavelet.rdoc +0 -218
  570. data/test/gsl/blas_test.rb +0 -79
  571. data/test/gsl/bspline_test.rb +0 -63
  572. data/test/gsl/cdf_test.rb +0 -1512
  573. data/test/gsl/cheb_test.rb +0 -80
  574. data/test/gsl/combination_test.rb +0 -100
  575. data/test/gsl/complex_test.rb +0 -20
  576. data/test/gsl/const_test.rb +0 -29
  577. data/test/gsl/deriv_test.rb +0 -62
  578. data/test/gsl/dht_test.rb +0 -79
  579. data/test/gsl/diff_test.rb +0 -53
  580. data/test/gsl/eigen_test.rb +0 -563
  581. data/test/gsl/err_test.rb +0 -23
  582. data/test/gsl/fit_test.rb +0 -101
  583. data/test/gsl/histo_test.rb +0 -14
  584. data/test/gsl/index_test.rb +0 -61
  585. data/test/gsl/integration_test.rb +0 -274
  586. data/test/gsl/interp_test.rb +0 -27
  587. data/test/gsl/linalg_test.rb +0 -463
  588. data/test/gsl/matrix_nmf_test.rb +0 -37
  589. data/test/gsl/matrix_test.rb +0 -98
  590. data/test/gsl/min_test.rb +0 -89
  591. data/test/gsl/monte_test.rb +0 -77
  592. data/test/gsl/multifit_test.rb +0 -753
  593. data/test/gsl/multimin_test.rb +0 -157
  594. data/test/gsl/multiroot_test.rb +0 -135
  595. data/test/gsl/multiset_test.rb +0 -52
  596. data/test/gsl/odeiv_test.rb +0 -275
  597. data/test/gsl/oper_test.rb +0 -98
  598. data/test/gsl/poly_test.rb +0 -338
  599. data/test/gsl/qrng_test.rb +0 -94
  600. data/test/gsl/quartic_test.rb +0 -28
  601. data/test/gsl/randist_test.rb +0 -122
  602. data/test/gsl/rng_test.rb +0 -303
  603. data/test/gsl/roots_test.rb +0 -78
  604. data/test/gsl/sf_test.rb +0 -2079
  605. data/test/gsl/stats_test.rb +0 -122
  606. data/test/gsl/sum_test.rb +0 -69
  607. data/test/gsl/tensor_test.rb +0 -396
  608. data/test/gsl/vector_test.rb +0 -223
  609. data/test/gsl/wavelet_test.rb +0 -130
  610. data/test/gsl_test.rb +0 -321
  611. data/test/test_helper.rb +0 -42
  612. data/uncrustify.cfg +0 -1693
@@ -1,1964 +0,0 @@
1
- /*
2
- histogram.c
3
- Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
- (C) Copyright 2001-2006 by Yoshiki Tsunesada
5
-
6
- Ruby/GSL is free software: you can redistribute it and/or modify it
7
- under the terms of the GNU General Public License.
8
- This library is distributed in the hope that it will be useful, but
9
- WITHOUT ANY WARRANTY.
10
- */
11
-
12
- #include "include/rb_gsl_histogram.h"
13
- #include "include/rb_gsl_array.h"
14
- #include <gsl/gsl_fit.h>
15
- #include <gsl/gsl_multifit_nlin.h>
16
- #include <gsl/gsl_blas.h>
17
-
18
- VALUE cgsl_histogram;
19
- VALUE cgsl_histogram_range;
20
- VALUE cgsl_histogram_bin;
21
- static VALUE cgsl_histogram_integ;
22
-
23
- static VALUE rb_gsl_histogram_alloc_from_file(VALUE klass, VALUE name);
24
- static VALUE rb_gsl_histogram_alloc(int argc, VALUE *argv, VALUE klass)
25
- {
26
- gsl_histogram *h = NULL;
27
- gsl_vector *v;
28
- double min, max;
29
- size_t n, size;
30
- switch (argc) {
31
- case 1:
32
- switch (TYPE(argv[0])) {
33
- case T_FIXNUM:
34
- n = FIX2INT(argv[0]);
35
- h = gsl_histogram_alloc(n);
36
- break;
37
- case T_ARRAY:
38
- v = make_cvector_from_rarray(argv[0]);
39
- h = gsl_histogram_alloc(v->size-1);
40
- gsl_histogram_set_ranges(h, v->data, v->size);
41
- gsl_vector_free(v);
42
- break;
43
- case T_STRING:
44
- return rb_gsl_histogram_alloc_from_file(klass, argv[0]);
45
- break;
46
- default:
47
- CHECK_VECTOR(argv[0]);
48
- Data_Get_Struct(argv[0], gsl_vector, v);
49
- h = gsl_histogram_alloc(v->size-1);
50
- gsl_histogram_set_ranges(h, v->data, v->size);
51
- break;
52
- }
53
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
54
- break;
55
- case 3:
56
- CHECK_FIXNUM(argv[0]);
57
- Need_Float(argv[1]); Need_Float(argv[2]);
58
- n = FIX2INT(argv[0]);
59
- min = NUM2DBL(argv[1]);
60
- max = NUM2DBL(argv[2]);
61
- h = gsl_histogram_calloc(n);
62
- gsl_histogram_set_ranges_uniform(h, min, max);
63
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
64
- break;
65
- case 2:
66
- switch (TYPE(argv[0])) {
67
- case T_FIXNUM:
68
- CHECK_FIXNUM(argv[0]);
69
- if (TYPE(argv[1]) != T_ARRAY) {
70
- rb_raise(rb_eTypeError, "wrong argument type %s (Array expected)",
71
- rb_class2name(CLASS_OF(argv[1])));
72
- }
73
- n = FIX2INT(argv[0]);
74
- min = NUM2DBL(rb_ary_entry(argv[1], 0));
75
- max = NUM2DBL(rb_ary_entry(argv[1], 1));
76
- h = gsl_histogram_calloc(n);
77
- gsl_histogram_set_ranges_uniform(h, min, max);
78
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
79
- break;
80
- case T_ARRAY:
81
- CHECK_FIXNUM(argv[1]);
82
- v = make_cvector_from_rarray(argv[0]);
83
- size = FIX2INT(argv[1]);
84
- h = gsl_histogram_calloc(size-1);
85
- gsl_histogram_set_ranges(h, v->data, size);
86
- gsl_vector_free(v);
87
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
88
- break;
89
- default:
90
- CHECK_VECTOR(argv[0]);
91
- CHECK_FIXNUM(argv[1]);
92
- Data_Get_Struct(argv[0], gsl_vector, v);
93
- size = FIX2INT(argv[1]);
94
- h = gsl_histogram_calloc(size-1);
95
- gsl_histogram_set_ranges(h, v->data, size);
96
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
97
- break;
98
- }
99
- break;
100
- default:
101
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1, 2, 3)", argc);
102
- break;
103
- }
104
-
105
- }
106
-
107
- static VALUE rb_gsl_histogram_alloc_from_file(VALUE klass, VALUE name)
108
- {
109
- char filename[1024], buf[1024];
110
- gsl_histogram *h;
111
- int nn;
112
- size_t n, i;
113
- FILE *fp = NULL;
114
- double upper;
115
- strcpy(filename, StringValuePtr(name));
116
- sprintf(buf, "wc %s", filename);
117
- fp = popen(buf, "r");
118
- if (fp == NULL) rb_raise(rb_eIOError, "popen failed.");
119
- if (fgets(buf, 1024, fp) == NULL)
120
- rb_sys_fail(0);
121
- pclose(fp);
122
- sscanf(buf, "%d", &nn);
123
- n = (size_t) nn; /* vector length */
124
- fp = fopen(filename, "r");
125
- if (fp == NULL) rb_raise(rb_eIOError, "cannot open file %s.", filename);
126
- h = gsl_histogram_alloc(n);
127
- i = 0;
128
- while (fgets(buf, 1024, fp)) {
129
- sscanf(buf, "%lg %lg %lg", h->range+i, &upper, h->bin+i);
130
- i++;
131
- }
132
- h->range[n] = upper;
133
- fclose(fp);
134
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
135
-
136
- }
137
-
138
- /* initialization + set uniform ranges (equal spacing from min to max) */
139
- static VALUE rb_gsl_histogram_alloc_uniform(int argc, VALUE *argv, VALUE klass)
140
- {
141
- gsl_histogram *h = NULL;
142
- double min, max, tmp;
143
- size_t n;
144
- switch (argc) {
145
- case 3:
146
- CHECK_FIXNUM(argv[0]);
147
- Need_Float(argv[1]); Need_Float(argv[2]);
148
- n = FIX2INT(argv[0]);
149
- min = NUM2DBL(argv[1]);
150
- max = NUM2DBL(argv[2]);
151
- break;
152
- case 2:
153
- CHECK_FIXNUM(argv[0]);
154
- n = FIX2INT(argv[0]);
155
- Check_Type(argv[1], T_ARRAY);
156
- min = NUM2DBL(rb_ary_entry(argv[1], 0));
157
- max = NUM2DBL(rb_ary_entry(argv[1], 1));
158
- break;
159
- default:
160
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
161
- break;
162
- }
163
- if (min > max) {
164
- tmp = min;
165
- min = max;
166
- max = tmp;
167
- }
168
- h = gsl_histogram_alloc(n);
169
- gsl_histogram_set_ranges_uniform(h, min, max);
170
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
171
- }
172
-
173
- /* initialization + set ranges with a given spacing from min to max */
174
- static VALUE rb_gsl_histogram_alloc_with_min_max_step(VALUE klass, VALUE vmin,
175
- VALUE vmax, VALUE ss)
176
- {
177
- gsl_histogram *h = NULL;
178
- gsl_vector *v = NULL;
179
- double min, max, tmp, step;
180
- size_t i, n;
181
- Need_Float(vmin); Need_Float(vmax); Need_Float(ss);
182
- min = NUM2DBL(vmin);
183
- max = NUM2DBL(vmax);
184
- step = NUM2DBL(ss);
185
- if (min > max) {
186
- tmp = min;
187
- min = max;
188
- max = tmp;
189
- }
190
- n = (int) ((max - min)/step);
191
- h = gsl_histogram_alloc(n);
192
- v = gsl_vector_alloc(n + 1);
193
- for (i = 0; i < n + 1; i++) gsl_vector_set(v, i, min + step*i);
194
- gsl_histogram_set_ranges(h, v->data, v->size);
195
- gsl_vector_free(v);
196
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
197
- }
198
-
199
- static VALUE rb_gsl_histogram_calloc(VALUE klass, VALUE nn)
200
- {
201
- gsl_histogram *h = NULL;
202
- CHECK_FIXNUM(nn);
203
- h = gsl_histogram_calloc(FIX2INT(nn));
204
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
205
- }
206
-
207
- static VALUE rb_gsl_histogram_calloc_range(int argc, VALUE *argv, VALUE klass)
208
- {
209
- gsl_histogram *h = NULL;
210
- gsl_vector *v = NULL;
211
- size_t n;
212
- switch (argc) {
213
- case 1:
214
- CHECK_VECTOR(argv[0]);
215
- Data_Get_Struct(argv[0], gsl_vector, v);
216
- n = v->size;
217
- break;
218
- case 2:
219
- CHECK_FIXNUM(argv[0]);
220
- CHECK_VECTOR(argv[1]);
221
- n = FIX2INT(argv[0]);
222
- Data_Get_Struct(argv[1], gsl_vector, v);
223
- break;
224
- default:
225
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
226
- break;
227
- }
228
- h = gsl_histogram_calloc_range(n, v->data);
229
- return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
230
- }
231
-
232
- static VALUE rb_gsl_histogram_bins(VALUE obj)
233
- {
234
- gsl_histogram *h = NULL;
235
- Data_Get_Struct(obj, gsl_histogram, h);
236
- return INT2FIX(gsl_histogram_bins(h));
237
- }
238
-
239
- static VALUE rb_gsl_histogram_set_ranges(int argc, VALUE *argv, VALUE obj)
240
- {
241
- gsl_histogram *h = NULL;
242
- gsl_vector *v = NULL;
243
- size_t size;
244
- Data_Get_Struct(obj, gsl_histogram, h);
245
- if (argc != 1 && argc != 2)
246
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
247
- if (TYPE(argv[0]) == T_ARRAY) {
248
- v = make_cvector_from_rarray(argv[0]);
249
- if (argc == 1) size = v->size;
250
- else size = FIX2INT(argv[1]);
251
- gsl_histogram_set_ranges(h, v->data, size);
252
- gsl_vector_free(v);
253
- } else {
254
- CHECK_VECTOR(argv[0]);
255
- Data_Get_Struct(argv[0], gsl_vector, v);
256
- if (argc == 1) size = v->size;
257
- else size = FIX2INT(argv[1]);
258
- gsl_histogram_set_ranges(h, v->data, size);
259
- }
260
- return obj;
261
- }
262
-
263
- static VALUE rb_gsl_histogram_range(VALUE obj)
264
- {
265
- gsl_histogram *h = NULL;
266
- gsl_vector_view *v = NULL;
267
- Data_Get_Struct(obj, gsl_histogram, h);
268
- v = gsl_vector_view_alloc();
269
- v->vector.data = h->range;
270
- v->vector.size = h->n + 1;
271
- v->vector.stride = 1;
272
- return Data_Wrap_Struct(cgsl_histogram_range, 0, gsl_vector_view_free, v);
273
- }
274
-
275
- static VALUE rb_gsl_histogram_bin(VALUE obj)
276
- {
277
- gsl_histogram *h = NULL;
278
- gsl_vector_view *v = NULL;
279
- Data_Get_Struct(obj, gsl_histogram, h);
280
- v = gsl_vector_view_alloc();
281
- v->vector.data = h->bin;
282
- v->vector.size = h->n;
283
- v->vector.stride = 1;
284
- return Data_Wrap_Struct(cgsl_histogram_bin, 0, gsl_vector_view_free, v);
285
- }
286
-
287
- static VALUE rb_gsl_histogram_set_ranges_uniform(int argc, VALUE *argv, VALUE obj)
288
- {
289
- gsl_histogram *h = NULL;
290
- double xmin, xmax;
291
- switch (argc) {
292
- case 1:
293
- Check_Type(argv[0], T_ARRAY);
294
- xmin = NUM2DBL(rb_ary_entry(argv[0], 0));
295
- xmax = NUM2DBL(rb_ary_entry(argv[0], 1));
296
- break;
297
- case 2:
298
- xmin = NUM2DBL(argv[0]);
299
- xmax = NUM2DBL(argv[1]);
300
- break;
301
- default:
302
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
303
- break;
304
- }
305
- Data_Get_Struct(obj, gsl_histogram, h);
306
- gsl_histogram_set_ranges_uniform(h, xmin, xmax);
307
- return obj;
308
- }
309
-
310
- /* singleton */
311
- static VALUE rb_gsl_histogram_memcpy(VALUE obj, VALUE vhdest, VALUE vhsrc)
312
- {
313
- gsl_histogram *hdest = NULL, *hsrc = NULL;
314
- CHECK_HISTOGRAM(vhdest);
315
- CHECK_HISTOGRAM(vhsrc);
316
- Data_Get_Struct(vhdest, gsl_histogram, hdest);
317
- Data_Get_Struct(vhsrc, gsl_histogram, hsrc);
318
- gsl_histogram_memcpy(hdest, hsrc);
319
- return vhdest;
320
- }
321
-
322
- static VALUE rb_gsl_histogram_clone(VALUE obj)
323
- {
324
- gsl_histogram *hsrc = NULL, *hnew = NULL;
325
- Data_Get_Struct(obj, gsl_histogram, hsrc);
326
- hnew = gsl_histogram_clone(hsrc);
327
- return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
328
- }
329
-
330
- static VALUE rb_gsl_histogram_accumulate(int argc, VALUE *argv, VALUE obj)
331
- {
332
- gsl_histogram *h = NULL;
333
- gsl_vector *v;
334
- gsl_vector_int *vi;
335
- size_t i;
336
- double weight = 1;
337
- switch (argc) {
338
- case 2:
339
- Need_Float(argv[1]);
340
- weight = NUM2DBL(argv[1]);
341
- break;
342
- case 1:
343
- weight = 1;
344
- break;
345
- default:
346
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
347
- break;
348
- }
349
- Data_Get_Struct(obj, gsl_histogram, h);
350
- if (TYPE(argv[0]) == T_ARRAY) {
351
- // for (i = 0; i < RARRAY(argv[0])->len; i++)
352
- for (i = 0; (int) i < RARRAY_LEN(argv[0]); i++)
353
- gsl_histogram_accumulate(h, NUM2DBL(rb_ary_entry(argv[0], i)), weight);
354
- } else if (VECTOR_P(argv[0])) {
355
- Data_Get_Struct(argv[0], gsl_vector, v);
356
- for (i = 0; i < v->size; i++)
357
- gsl_histogram_accumulate(h, gsl_vector_get(v, i), weight);
358
- } else if (VECTOR_INT_P(argv[0])) {
359
- Data_Get_Struct(argv[0], gsl_vector_int, vi);
360
- for (i = 0; i < vi->size; i++)
361
- gsl_histogram_accumulate(h, (double)gsl_vector_int_get(vi, i), weight);
362
- #ifdef HAVE_NARRAY_H
363
- } else if (NA_IsNArray(argv[0])) {
364
- double *ptr;
365
- size_t size, stride;
366
- ptr = get_vector_ptr(argv[0], &stride, &size);
367
- for (i = 0; i < size; i++)
368
- gsl_histogram_accumulate(h, ptr[i], weight);
369
- #endif
370
- } else {
371
- gsl_histogram_accumulate(h, NUM2DBL(argv[0]), weight);
372
- }
373
- return argv[0];
374
- }
375
-
376
- static VALUE rb_gsl_histogram_accumulate2(int argc, VALUE *argv, VALUE obj)
377
- {
378
- gsl_histogram *h = NULL;
379
- double weight = 1;
380
- double x;
381
- switch (argc) {
382
- case 2:
383
- Need_Float(argv[1]);
384
- weight = NUM2DBL(argv[1]);
385
- /* no break; */
386
- case 1:
387
- Need_Float(argv[0]);
388
- x = NUM2DBL(argv[0]);
389
- break;
390
- default:
391
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
392
- break;
393
- }
394
- Data_Get_Struct(obj, gsl_histogram, h);
395
- if (x < h->range[0]) x = h->range[0] + 4*GSL_DBL_EPSILON;
396
- if (x > h->range[h->n]) x = h->range[h->n] - 4*GSL_DBL_EPSILON;
397
- gsl_histogram_accumulate(h, x, weight);
398
- return argv[0];
399
- }
400
-
401
- static VALUE rb_gsl_histogram_get(VALUE obj, VALUE i)
402
- {
403
- gsl_histogram *h = NULL;
404
- CHECK_FIXNUM(i);
405
- Data_Get_Struct(obj, gsl_histogram, h);
406
- return rb_float_new(gsl_histogram_get(h, FIX2INT(i)));
407
- }
408
-
409
- static VALUE rb_gsl_histogram_get_range(VALUE obj, VALUE i)
410
- {
411
- gsl_histogram *h = NULL;
412
- double lower, upper;
413
- CHECK_FIXNUM(i);
414
- Data_Get_Struct(obj, gsl_histogram, h);
415
- gsl_histogram_get_range(h, FIX2INT(i), &lower, &upper);
416
- return rb_ary_new3(2, rb_float_new(lower), rb_float_new(upper));
417
- }
418
-
419
- static VALUE rb_gsl_histogram_max(VALUE obj)
420
- {
421
- gsl_histogram *h = NULL;
422
- Data_Get_Struct(obj, gsl_histogram, h);
423
- return rb_float_new(gsl_histogram_max(h));
424
- }
425
-
426
- static VALUE rb_gsl_histogram_min(VALUE obj)
427
- {
428
- gsl_histogram *h = NULL;
429
- Data_Get_Struct(obj, gsl_histogram, h);
430
- return rb_float_new(gsl_histogram_min(h));
431
- }
432
-
433
- static VALUE rb_gsl_histogram_reset(VALUE obj)
434
- {
435
- gsl_histogram *h = NULL;
436
- Data_Get_Struct(obj, gsl_histogram, h);
437
- gsl_histogram_reset(h);
438
- return obj;
439
- }
440
-
441
- static VALUE rb_gsl_histogram_find(VALUE obj, VALUE x)
442
- {
443
- gsl_histogram *h = NULL;
444
- size_t i;
445
- Need_Float(x);
446
- Data_Get_Struct(obj, gsl_histogram, h);
447
- gsl_histogram_find(h, NUM2DBL(x), &i);
448
- return INT2FIX(i);
449
- }
450
-
451
- static VALUE rb_gsl_histogram_max_val(VALUE obj)
452
- {
453
- gsl_histogram *h = NULL;
454
- Data_Get_Struct(obj, gsl_histogram, h);
455
- return rb_float_new(gsl_histogram_max_val(h));
456
- }
457
-
458
- static VALUE rb_gsl_histogram_max_bin(VALUE obj)
459
- {
460
- gsl_histogram *h = NULL;
461
- Data_Get_Struct(obj, gsl_histogram, h);
462
- return INT2FIX(gsl_histogram_max_bin(h));
463
- }
464
-
465
- static VALUE rb_gsl_histogram_min_val(VALUE obj)
466
- {
467
- gsl_histogram *h = NULL;
468
- Data_Get_Struct(obj, gsl_histogram, h);
469
- return rb_float_new(gsl_histogram_min_val(h));
470
- }
471
-
472
- static VALUE rb_gsl_histogram_min_bin(VALUE obj)
473
- {
474
- gsl_histogram *h = NULL;
475
- Data_Get_Struct(obj, gsl_histogram, h);
476
- return INT2FIX(gsl_histogram_min_bin(h));
477
- }
478
-
479
- static VALUE rb_gsl_histogram_mean(VALUE obj)
480
- {
481
- gsl_histogram *h = NULL;
482
- Data_Get_Struct(obj, gsl_histogram, h);
483
- return rb_float_new(gsl_histogram_mean(h));
484
- }
485
-
486
- static VALUE rb_gsl_histogram_sigma(VALUE obj)
487
- {
488
- gsl_histogram *h = NULL;
489
- Data_Get_Struct(obj, gsl_histogram, h);
490
- return rb_float_new(gsl_histogram_sigma(h));
491
- }
492
-
493
- static VALUE rb_gsl_histogram_sum(VALUE obj)
494
- {
495
- gsl_histogram *h = NULL;
496
- Data_Get_Struct(obj, gsl_histogram, h);
497
- if (CLASS_OF(obj) == cgsl_histogram_integ)
498
- return rb_float_new(gsl_histogram_get(h, h->n-1));
499
- else
500
- return rb_float_new(gsl_histogram_sum(h));
501
- }
502
-
503
- static VALUE rb_gsl_histogram_normalize_bang(VALUE obj)
504
- {
505
- gsl_histogram *h = NULL;
506
- double scale;
507
- Data_Get_Struct(obj, gsl_histogram, h);
508
- if (CLASS_OF(obj) == cgsl_histogram_integ)
509
- scale = 1.0/gsl_histogram_get(h, h->n-1);
510
- else
511
- scale = 1.0/gsl_histogram_sum(h);
512
- gsl_histogram_scale(h, scale);
513
- return obj;
514
- }
515
-
516
- static VALUE rb_gsl_histogram_normalize(VALUE obj)
517
- {
518
- gsl_histogram *h = NULL, *hnew = NULL;
519
- Data_Get_Struct(obj, gsl_histogram, h);
520
- hnew = gsl_histogram_clone(h);
521
- return rb_gsl_histogram_normalize_bang(Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew));
522
- }
523
-
524
- static VALUE rb_gsl_histogram_integral(int argc, VALUE *argv, VALUE obj)
525
- {
526
- gsl_histogram *h = NULL;
527
- size_t istart = 0, iend, i = 0;
528
- double sum = 0.0;
529
- Data_Get_Struct(obj, gsl_histogram, h);
530
- switch (argc) {
531
- case 0:
532
- return rb_gsl_histogram_sum(obj);
533
- break;
534
- case 1:
535
- CHECK_FIXNUM(argv[0]);
536
- istart = 0; iend = FIX2INT(argv[0]);
537
- break;
538
- case 2:
539
- CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
540
- istart = FIX2INT(argv[0]);
541
- iend = FIX2INT(argv[1]);
542
- break;
543
- default:
544
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-2)", argc);
545
- break;
546
- }
547
- if (iend >= h->n) iend = h->n - 1;
548
- i = istart;
549
- while (i <= iend) sum += h->bin[i++];
550
- return rb_float_new(sum);
551
- }
552
-
553
- static VALUE rb_gsl_histogram_equal_bins_p(int argc, VALUE *argv, VALUE obj)
554
- {
555
- gsl_histogram *h1 = NULL, *h2 = NULL;
556
- switch (TYPE(obj)) {
557
- case T_MODULE:
558
- case T_CLASS:
559
- case T_OBJECT:
560
- if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
561
- argc);
562
- CHECK_HISTOGRAM(argv[0]);
563
- CHECK_HISTOGRAM(argv[1]);
564
- Data_Get_Struct(argv[0], gsl_histogram, h1);
565
- Data_Get_Struct(argv[1], gsl_histogram, h2);
566
- break;
567
- default:
568
- if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
569
- argc);
570
- Data_Get_Struct(obj, gsl_histogram, h1);
571
- CHECK_HISTOGRAM(argv[0]);
572
- Data_Get_Struct(argv[0], gsl_histogram, h2);
573
- break;
574
- }
575
- return INT2FIX(gsl_histogram_equal_bins_p(h1, h2));
576
- }
577
-
578
- static VALUE rb_gsl_histogram_equal_bins_p2(int argc, VALUE *argv, VALUE obj)
579
- {
580
- gsl_histogram *h1 = NULL, *h2 = NULL;
581
- switch (TYPE(obj)) {
582
- case T_MODULE:
583
- case T_CLASS:
584
- case T_OBJECT:
585
- if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
586
- argc);
587
- CHECK_HISTOGRAM(argv[0]);
588
- CHECK_HISTOGRAM(argv[1]);
589
- Data_Get_Struct(argv[0], gsl_histogram, h1);
590
- Data_Get_Struct(argv[1], gsl_histogram, h2);
591
- break;
592
- default:
593
- if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
594
- argc);
595
- Data_Get_Struct(obj, gsl_histogram, h1);
596
- CHECK_HISTOGRAM(argv[0]);
597
- Data_Get_Struct(argv[0], gsl_histogram, h2);
598
- break;
599
- }
600
- if (gsl_histogram_equal_bins_p(h1, h2)) return Qtrue;
601
- else return Qfalse;
602
- }
603
-
604
- static VALUE rb_gsl_histogram_add(VALUE obj, VALUE hh2)
605
- {
606
- gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
607
- Data_Get_Struct(obj, gsl_histogram, h1);
608
- hnew = gsl_histogram_clone(h1);
609
- if (HISTOGRAM_P(hh2)) {
610
- Data_Get_Struct(hh2, gsl_histogram, h2);
611
- mygsl_histogram_add(hnew, h2);
612
- } else {
613
- Need_Float(hh2);
614
- gsl_histogram_shift(hnew, NUM2DBL(hh2));
615
- }
616
- return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
617
- }
618
-
619
- static VALUE rb_gsl_histogram_add2(VALUE obj, VALUE hh2)
620
- {
621
- gsl_histogram *h1 = NULL, *h2 = NULL;
622
- Data_Get_Struct(obj, gsl_histogram, h1);
623
- if (HISTOGRAM_P(hh2)) {
624
- Data_Get_Struct(hh2, gsl_histogram, h2);
625
- mygsl_histogram_add(h1, h2);
626
- } else {
627
- Need_Float(hh2);
628
- gsl_histogram_shift(h1, NUM2DBL(hh2));
629
- }
630
- return obj;
631
- }
632
-
633
- static VALUE rb_gsl_histogram_sub(VALUE obj, VALUE hh2)
634
- {
635
- gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
636
- Data_Get_Struct(obj, gsl_histogram, h1);
637
- hnew = gsl_histogram_clone(h1);
638
- if (HISTOGRAM_P(hh2)) {
639
- Data_Get_Struct(hh2, gsl_histogram, h2);
640
- mygsl_histogram_sub(hnew, h2);
641
- } else {
642
- Need_Float(hh2);
643
- gsl_histogram_shift(hnew, -NUM2DBL(hh2));
644
- }
645
- return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
646
- }
647
-
648
- static VALUE rb_gsl_histogram_sub2(VALUE obj, VALUE hh2)
649
- {
650
- gsl_histogram *h1 = NULL, *h2 = NULL;
651
- Data_Get_Struct(obj, gsl_histogram, h1);
652
- if (HISTOGRAM_P(hh2)) {
653
- Data_Get_Struct(hh2, gsl_histogram, h2);
654
- mygsl_histogram_sub(h1, h2);
655
- } else {
656
- Need_Float(hh2);
657
- gsl_histogram_shift(h1, -NUM2DBL(hh2));
658
- }
659
- return obj;
660
- }
661
-
662
- static VALUE rb_gsl_histogram_mul(VALUE obj, VALUE hh2)
663
- {
664
- gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
665
- Data_Get_Struct(obj, gsl_histogram, h1);
666
- hnew = gsl_histogram_clone(h1);
667
- if (HISTOGRAM_P(hh2)) {
668
- Data_Get_Struct(hh2, gsl_histogram, h2);
669
- mygsl_histogram_mul(hnew, h2);
670
- } else {
671
- Need_Float(hh2);
672
- gsl_histogram_scale(hnew, NUM2DBL(hh2));
673
- }
674
- return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
675
- }
676
-
677
- static VALUE rb_gsl_histogram_mul2(VALUE obj, VALUE hh2)
678
- {
679
- gsl_histogram *h1 = NULL, *h2 = NULL;
680
- Data_Get_Struct(obj, gsl_histogram, h1);
681
- if (HISTOGRAM_P(hh2)) {
682
- Data_Get_Struct(hh2, gsl_histogram, h2);
683
- mygsl_histogram_mul(h1, h2);
684
- } else {
685
- Need_Float(hh2);
686
- gsl_histogram_scale(h1, NUM2DBL(hh2));
687
- }
688
- return obj;
689
- }
690
-
691
- static VALUE rb_gsl_histogram_div(VALUE obj, VALUE hh2)
692
- {
693
- gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
694
- Data_Get_Struct(obj, gsl_histogram, h1);
695
- hnew = gsl_histogram_clone(h1);
696
- if (HISTOGRAM_P(hh2)) {
697
- Data_Get_Struct(hh2, gsl_histogram, h2);
698
- mygsl_histogram_div(hnew, h2);
699
- } else {
700
- Need_Float(hh2);
701
- gsl_histogram_scale(hnew, 1.0/NUM2DBL(hh2));
702
- }
703
- return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
704
- }
705
-
706
- static VALUE rb_gsl_histogram_div2(VALUE obj, VALUE hh2)
707
- {
708
- gsl_histogram *h1 = NULL, *h2 = NULL;
709
- Data_Get_Struct(obj, gsl_histogram, h1);
710
- if (HISTOGRAM_P(hh2)) {
711
- Data_Get_Struct(hh2, gsl_histogram, h2);
712
- mygsl_histogram_div(h1, h2);
713
- } else {
714
- Need_Float(hh2);
715
- gsl_histogram_scale(h1, 1.0/NUM2DBL(hh2));
716
- }
717
- return obj;
718
- }
719
-
720
- static VALUE rb_gsl_histogram_scale_bang(int argc, VALUE *argv, VALUE obj)
721
- {
722
- gsl_histogram *h = NULL;
723
- double scale;
724
- Data_Get_Struct(obj, gsl_histogram, h);
725
- switch (argc) {
726
- case 0:
727
- if (CLASS_OF(obj) == cgsl_histogram_integ)
728
- scale = 1.0/h->bin[h->n-1];
729
- else
730
- scale = 1.0/gsl_histogram_sum(h);
731
- break;
732
- case 1:
733
- scale = NUM2DBL(argv[0]);
734
- break;
735
- default:
736
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
737
- break;
738
- }
739
- gsl_histogram_scale(h, scale);
740
- return obj;
741
- }
742
-
743
- static VALUE rb_gsl_histogram_scale(int argc, VALUE *argv, VALUE obj)
744
- {
745
- gsl_histogram *h = NULL, *hnew = NULL;
746
- double scale;
747
- Data_Get_Struct(obj, gsl_histogram, h);
748
- switch (argc) {
749
- case 0:
750
- if (CLASS_OF(obj) == cgsl_histogram_integ)
751
- scale = 1.0/h->bin[h->n-1];
752
- else
753
- scale = 1.0/gsl_histogram_sum(h);
754
- break;
755
- case 1:
756
- scale = NUM2DBL(argv[0]);
757
- break;
758
- default:
759
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
760
- break;
761
- }
762
- hnew = gsl_histogram_clone(h);
763
- gsl_histogram_scale(hnew, scale);
764
- return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
765
- }
766
-
767
- static VALUE rb_gsl_histogram_shift(VALUE obj, VALUE shift)
768
- {
769
- gsl_histogram *h = NULL;
770
- Need_Float(shift);
771
- Data_Get_Struct(obj, gsl_histogram, h);
772
- gsl_histogram_shift(h, NUM2DBL(shift));
773
- return obj;
774
- }
775
-
776
- static VALUE rb_gsl_histogram_shift2(VALUE obj, VALUE shift)
777
- {
778
- gsl_histogram *h = NULL, *hnew = NULL;
779
- Need_Float(shift);
780
- Data_Get_Struct(obj, gsl_histogram, h);
781
- hnew = gsl_histogram_clone(h);
782
- gsl_histogram_shift(hnew, NUM2DBL(shift));
783
- return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
784
- }
785
-
786
- static VALUE rb_gsl_histogram_fwrite(VALUE obj, VALUE io)
787
- {
788
- gsl_histogram *h = NULL;
789
- FILE *f;
790
- int status, flag = 0;
791
- Data_Get_Struct(obj, gsl_histogram, h);
792
- f = rb_gsl_open_writefile(io, &flag);
793
- status = gsl_histogram_fwrite(f, h);
794
- if (flag == 1) fclose(f);
795
- return INT2FIX(status);
796
- }
797
-
798
- static VALUE rb_gsl_histogram_fread(VALUE obj, VALUE io)
799
- {
800
- gsl_histogram *h = NULL;
801
- FILE *f;
802
- int status, flag = 0;
803
- Data_Get_Struct(obj, gsl_histogram, h);
804
- f = rb_gsl_open_readfile(io, &flag);
805
- status = gsl_histogram_fread(f, h);
806
- if (flag == 1) fclose(f);
807
- return INT2FIX(status);
808
- }
809
-
810
- static VALUE rb_gsl_histogram_fprintf(int argc, VALUE *argv, VALUE obj)
811
- {
812
- gsl_histogram *h = NULL;
813
- FILE *fp;
814
- int status, flag = 0;
815
-
816
- if (argc != 1 && argc != 3) {
817
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 3)", argc);
818
- }
819
- Data_Get_Struct(obj, gsl_histogram, h);
820
- fp = rb_gsl_open_writefile(argv[0], &flag);
821
- if (argc == 3) {
822
- Check_Type(argv[1], T_STRING);
823
- Check_Type(argv[2], T_STRING);
824
- status = gsl_histogram_fprintf(fp, h, STR2CSTR(argv[1]), STR2CSTR(argv[2]));
825
- } else {
826
- status = gsl_histogram_fprintf(fp, h, "%g", "%g");
827
- }
828
- if (flag == 1) fclose(fp);
829
- return INT2FIX(status);
830
- }
831
-
832
- static VALUE rb_gsl_histogram_printf(int argc, VALUE *argv, VALUE obj)
833
- {
834
- gsl_histogram *h = NULL;
835
- int status;
836
- Data_Get_Struct(obj, gsl_histogram, h);
837
- if (argc == 2) {
838
- Check_Type(argv[0], T_STRING);
839
- Check_Type(argv[1], T_STRING);
840
- status = gsl_histogram_fprintf(stdout, h, STR2CSTR(argv[0]), STR2CSTR(argv[1]));
841
- } else {
842
- status = gsl_histogram_fprintf(stdout, h, "%g", "%g");
843
- }
844
- return INT2FIX(status);
845
- }
846
-
847
- static VALUE rb_gsl_histogram_fscanf(VALUE obj, VALUE io)
848
- {
849
- gsl_histogram *h = NULL;
850
- FILE *fp;
851
- int status, flag = 0;
852
- Data_Get_Struct(obj, gsl_histogram, h);
853
- fp = rb_gsl_open_readfile(io, &flag);
854
- status = gsl_histogram_fscanf(fp, h);
855
- if (flag == 1) fclose(fp);
856
- return INT2FIX(status);
857
- }
858
-
859
- static VALUE rb_gsl_histogram_print(VALUE obj)
860
- {
861
- gsl_histogram *h = NULL;
862
- int status;
863
- Data_Get_Struct(obj, gsl_histogram, h);
864
- status = gsl_histogram_fprintf(stdout, h, "%g", "%g");
865
- return INT2FIX(status);
866
- }
867
-
868
- static VALUE rb_gsl_histogram_pdf_alloc(VALUE klass, VALUE nn)
869
- {
870
- gsl_histogram_pdf *h = NULL;
871
- gsl_histogram *h0 = NULL;
872
- if (rb_obj_is_kind_of(nn, cgsl_histogram)) {
873
- Data_Get_Struct(nn, gsl_histogram, h0);
874
- h = gsl_histogram_pdf_alloc(h0->n);
875
- gsl_histogram_pdf_init(h, h0);
876
- } else {
877
- CHECK_FIXNUM(nn);
878
- h = gsl_histogram_pdf_alloc(FIX2INT(nn));
879
- }
880
- return Data_Wrap_Struct(klass, 0, gsl_histogram_pdf_free, h);
881
- }
882
-
883
- static VALUE rb_gsl_histogram_pdf_init(VALUE obj, VALUE hh)
884
- {
885
- gsl_histogram_pdf *p = NULL;
886
- gsl_histogram *h = NULL;
887
- CHECK_HISTOGRAM(hh);
888
- Data_Get_Struct(obj, gsl_histogram_pdf, p);
889
- Data_Get_Struct(hh, gsl_histogram, h);
890
- gsl_histogram_pdf_init(p, h);
891
- return obj;
892
- }
893
-
894
- static VALUE rb_gsl_histogram_pdf_sample(VALUE obj, VALUE r)
895
- {
896
- gsl_histogram_pdf *p = NULL;
897
- Need_Float(r);
898
- Data_Get_Struct(obj, gsl_histogram_pdf, p);
899
- return rb_float_new(gsl_histogram_pdf_sample(p, NUM2DBL(r)));
900
- }
901
-
902
- static VALUE rb_gsl_histogram_pdf_range(VALUE obj)
903
- {
904
- gsl_histogram_pdf *h = NULL;
905
- gsl_vector_view *v = NULL;
906
- Data_Get_Struct(obj, gsl_histogram_pdf, h);
907
- v = gsl_vector_view_alloc(h->n);
908
- v->vector.data = h->range;
909
- v->vector.size = h->n + 1;
910
- v->vector.stride = 1;
911
- return Data_Wrap_Struct(cgsl_histogram_range, 0, gsl_vector_view_free, v);
912
- }
913
-
914
- static VALUE rb_gsl_histogram_pdf_sum(VALUE obj)
915
- {
916
- gsl_histogram_pdf *h = NULL;
917
- gsl_vector_view *v = NULL;
918
- Data_Get_Struct(obj, gsl_histogram_pdf, h);
919
- v = gsl_vector_view_alloc(h->n);
920
- v->vector.data = h->sum;
921
- v->vector.size = h->n + 1;
922
- v->vector.stride = 1;
923
- return Data_Wrap_Struct(cgsl_vector_view_ro, 0, gsl_vector_view_free, v);
924
- }
925
-
926
- static VALUE rb_gsl_histogram_graph(int argc, VALUE *argv, VALUE obj)
927
- {
928
- #ifdef HAVE_GNU_GRAPH
929
- gsl_histogram *v = NULL;
930
- FILE *fp = NULL;
931
- size_t i;
932
- char command[1024];
933
- Data_Get_Struct(obj, gsl_histogram, v);
934
- switch (argc) {
935
- case 0:
936
- strcpy(command, "graph -T X -g 3");
937
- break;
938
- case 1:
939
- make_graphcommand(command, argv[0]);
940
- break;
941
- default:
942
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
943
- break;
944
- }
945
- fp = popen(command, "w");
946
- if (fp == NULL) rb_raise(rb_eIOError, "GNU graph not found.");
947
- for (i = 0; i < v->n; i++) {
948
- fprintf(fp, "%e %e\n%e %e\n", v->range[i], v->bin[i], v->range[i+1], v->bin[i]);
949
- }
950
- fflush(fp);
951
- pclose(fp);
952
- fp = NULL;
953
- return Qtrue;
954
- #else
955
- rb_raise(rb_eNoMethodError, "not implemented");
956
- return Qfalse;
957
- #endif
958
- }
959
-
960
- static VALUE rb_gsl_histogram_plot(int argc, VALUE *argv, VALUE obj)
961
- {
962
- #ifdef HAVE_GNU_GRAPH
963
- gsl_histogram *v = NULL;
964
- FILE *fp = NULL;
965
- size_t i;
966
- Data_Get_Struct(obj, gsl_histogram, v);
967
- switch (argc) {
968
- case 0:
969
- fp = popen("gnuplot -persist", "w");
970
- if (fp == NULL) rb_raise(rb_eIOError, "GNU graph not found.");
971
- fprintf(fp, "plot '-' with fsteps\n");
972
- break;
973
- case 1:
974
- fp = popen("gnuplot -persist", "w");
975
- if (fp == NULL) rb_raise(rb_eIOError, "GNU graph not found.");
976
- if (TYPE(argv[0]) == T_STRING)
977
- fprintf(fp, "plot '-' %s\n", STR2CSTR(argv[0]));
978
- else
979
- fprintf(fp, "plot '-' with fsteps\n");
980
- break;
981
- default:
982
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
983
- break;
984
- }
985
- for (i = 0; i < v->n; i++) {
986
- fprintf(fp, "%e %e\n", v->range[i], v->bin[i]);
987
- }
988
- fprintf(fp, "e\n");
989
- fflush(fp);
990
- pclose(fp);
991
- fp = NULL;
992
- return Qtrue;
993
- #else
994
- rb_raise(rb_eNoMethodError, "not implemented");
995
- return Qfalse;
996
- #endif
997
- }
998
-
999
- struct fit_histogram {
1000
- gsl_histogram *h;
1001
- size_t binstart, binend;
1002
- };
1003
-
1004
- static VALUE rb_gsl_histogram_fit_exponential(int argc, VALUE *argv, VALUE obj)
1005
- {
1006
- gsl_histogram *h;
1007
- gsl_vector *x, *lny, *w;
1008
- size_t binstart = 0, binend, n, p = 2, dof, i;
1009
- double c0, c1, cov00, cov01, cov11, sumsq, xl, xh;
1010
- Data_Get_Struct(obj, gsl_histogram, h);
1011
- binstart = 0;
1012
- binend = h->n - 1;
1013
- switch (argc) {
1014
- case 2:
1015
- CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
1016
- binstart = FIX2INT(argv[0]);
1017
- binend = FIX2INT(argv[1]);
1018
- if (binend >= h->n) binend = h->n - 1;
1019
- break;
1020
- case 0:
1021
- break;
1022
- default:
1023
- rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
1024
- break;
1025
- }
1026
- n = binend - binstart + 1;
1027
- dof = n - p;
1028
-
1029
- x = gsl_vector_alloc(n);
1030
- w = gsl_vector_alloc(n);
1031
- lny = gsl_vector_alloc(n);
1032
- for (i = 0; i < n; i++) {
1033
- if (gsl_histogram_get_range(h, i+binstart, &xl, &xh))
1034
- rb_raise(rb_eIndexError, "wrong index");
1035
- gsl_vector_set(x, i, (xl+xh)/2.0);
1036
- gsl_vector_set(lny, i, log(h->bin[i+binstart]));
1037
- gsl_vector_set(w, i, h->bin[i+binstart]);
1038
- }
1039
- gsl_fit_wlinear(x->data, 1, w->data, 1, lny->data, 1, n,
1040
- &c0, &c1, &cov00, &cov01, &cov11, &sumsq);
1041
- gsl_vector_free(lny);
1042
- gsl_vector_free(w);
1043
- gsl_vector_free(x);
1044
- c0 = exp(c0);
1045
- return rb_ary_new3(6, rb_float_new(c0), rb_float_new(c1),
1046
- rb_float_new(c0*sqrt(cov00)), rb_float_new(sqrt(cov11)),
1047
- rb_float_new(sumsq), INT2FIX(dof));
1048
- }
1049
-
1050
- static VALUE rb_gsl_histogram_fit_power(int argc, VALUE *argv, VALUE obj)
1051
- {
1052
- gsl_histogram *h;
1053
- gsl_vector *lnx, *lny, *w;
1054
- size_t binstart = 0, binend, n, p = 2, dof, i;
1055
- double c0, c1, cov00, cov01, cov11, sumsq, xl, xh;
1056
- Data_Get_Struct(obj, gsl_histogram, h);
1057
- binstart = 0;
1058
- binend = h->n - 1;
1059
- switch (argc) {
1060
- case 2:
1061
- CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
1062
- binstart = FIX2INT(argv[0]);
1063
- binend = FIX2INT(argv[1]);
1064
- if (binend >= h->n) binend = h->n - 1;
1065
- break;
1066
- case 0:
1067
- break;
1068
- default:
1069
- rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
1070
- break;
1071
- }
1072
- n = binend - binstart + 1;
1073
- dof = n - p;
1074
-
1075
- lnx = gsl_vector_alloc(n);
1076
- w = gsl_vector_alloc(n);
1077
- lny = gsl_vector_alloc(n);
1078
- for (i = 0; i < n; i++) {
1079
- if (gsl_histogram_get_range(h, i+binstart, &xl, &xh))
1080
- rb_raise(rb_eIndexError, "wrong index");
1081
- gsl_vector_set(lnx, i, (log(xl)+log(xh))/2.0);
1082
- gsl_vector_set(lny, i, log(h->bin[i+binstart]));
1083
- gsl_vector_set(w, i, h->bin[i+binstart]);
1084
- }
1085
- gsl_fit_wlinear(lnx->data, 1, w->data, 1, lny->data, 1, n,
1086
- &c0, &c1, &cov00, &cov01, &cov11, &sumsq);
1087
- gsl_vector_free(lny);
1088
- gsl_vector_free(w);
1089
- gsl_vector_free(lnx);
1090
- c0 = exp(c0);
1091
- return rb_ary_new3(6, rb_float_new(c0), rb_float_new(c1),
1092
- rb_float_new(c0*sqrt(cov00)), rb_float_new(sqrt(cov11)),
1093
- rb_float_new(sumsq), INT2FIX(dof));
1094
- }
1095
-
1096
- static int Gaussian_f(const gsl_vector *v, void *params, gsl_vector *f);
1097
- static int Gaussian_df(const gsl_vector *v, void *params, gsl_matrix * J);
1098
- static int Gaussian_f(const gsl_vector *v, void *params, gsl_vector *f)
1099
- {
1100
- struct fit_histogram *hh;
1101
- gsl_histogram *h = NULL;
1102
- double amp, mu, var, xl, xh, xi, yi, sqw;
1103
- size_t i, binstart, binend;
1104
- hh = (struct fit_histogram *) params;
1105
- h = hh->h;
1106
- binstart = hh->binstart;
1107
- binend = hh->binend;
1108
- var = gsl_vector_get(v, 0);
1109
- mu = gsl_vector_get(v, 1);
1110
- amp = gsl_vector_get(v, 2);
1111
- for (i = binstart; i <= binend; i++) {
1112
- if (gsl_histogram_get_range(h, i, &xl, &xh))
1113
- rb_raise(rb_eIndexError, "wrong index");
1114
- xi = (xl + xh)/2.0;
1115
- yi = h->bin[i];
1116
- // sqw = sqrt(yi);
1117
- if (yi >= 1.0) sqw = 1.0/sqrt(yi);
1118
- else sqw = 1.0;
1119
- gsl_vector_set(f, i-binstart, (amp*exp(-(xi - mu)*(xi - mu)/var/2.0) - yi)*sqw);
1120
- }
1121
- return GSL_SUCCESS;
1122
- }
1123
-
1124
- static int Gaussian_df(const gsl_vector *v, void *params, gsl_matrix *J)
1125
- {
1126
- struct fit_histogram *hh;
1127
- gsl_histogram *h = NULL;
1128
- double amp, mu, var, xl, xh, xi, yi, y, sqw;
1129
- size_t i, binstart, binend;
1130
- hh = (struct fit_histogram *) params;
1131
- h = hh->h;
1132
- binstart = hh->binstart;
1133
- binend = hh->binend;
1134
- var = gsl_vector_get(v, 0);
1135
- mu = gsl_vector_get(v, 1);
1136
- amp = gsl_vector_get(v, 2);
1137
- for (i = binstart; i <= binend; i++) {
1138
- if (gsl_histogram_get_range(h, i, &xl, &xh))
1139
- rb_raise(rb_eIndexError, "wrong index");
1140
- xi = (xl + xh)/2.0;
1141
- yi = h->bin[i];
1142
- // sqw = sqrt(yi);
1143
- if (yi >= 1.0) sqw = 1.0/sqrt(yi);
1144
- else sqw = 1.0;
1145
- y = exp(-(xi - mu)*(xi - mu)/var/2.0);
1146
- gsl_matrix_set(J, i-binstart, 0, amp*y*(xi - mu)*(xi - mu)/2/var/var*sqw);
1147
- gsl_matrix_set(J, i-binstart, 1, amp*y*(xi - mu)/var*sqw);
1148
- gsl_matrix_set(J, i-binstart, 2, y*sqw);
1149
- }
1150
- return GSL_SUCCESS;
1151
- }
1152
-
1153
- static int Gaussian_fdf(const gsl_vector *v, void *params, gsl_vector *f,
1154
- gsl_matrix *J)
1155
- {
1156
- Gaussian_f(v, params, f);
1157
- Gaussian_df(v, params, J);
1158
- return GSL_SUCCESS;
1159
- }
1160
-
1161
- static VALUE rb_gsl_histogram_fit_gaussian(int argc, VALUE *argv, VALUE obj)
1162
- {
1163
- gsl_histogram *h = NULL;
1164
- struct fit_histogram hh;
1165
- const gsl_multifit_fdfsolver_type *T;
1166
- gsl_multifit_fdfsolver *s;
1167
- int status;
1168
- size_t iter = 0, binstart, binend;
1169
- size_t n, dof; /* # of data points */
1170
- size_t p = 3; /* # of fitting parameters */
1171
- gsl_multifit_function_fdf f;
1172
- gsl_matrix *covar = NULL;
1173
- gsl_vector *x = NULL;
1174
- double sigma, mean, height, errs, errm, errh, chi2;
1175
- Data_Get_Struct(obj, gsl_histogram, h);
1176
- binstart = 0;
1177
- binend = h->n - 1;
1178
- switch (argc) {
1179
- case 2:
1180
- CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
1181
- binstart = FIX2INT(argv[0]);
1182
- binend = FIX2INT(argv[1]);
1183
- if (binend >= h->n) binend = h->n - 1;
1184
- break;
1185
- case 0:
1186
- break;
1187
- default:
1188
- rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
1189
- break;
1190
- }
1191
- x = gsl_vector_alloc(p);
1192
- gsl_vector_set(x, 0, gsl_pow_2(gsl_histogram_sigma(h))); /* initial values, var = 1 */
1193
- gsl_vector_set(x, 1, gsl_histogram_mean(h)); /* mu = 0 */
1194
- gsl_vector_set(x, 2, gsl_histogram_max_val(h)); /* amp = 1 */
1195
- hh.h = h;
1196
- hh.binstart = binstart;
1197
- hh.binend = binend;
1198
- n = binend - binstart + 1;
1199
-
1200
- covar = gsl_matrix_alloc(p, p);
1201
-
1202
- f.f = Gaussian_f;
1203
- f.df = Gaussian_df;
1204
- f.fdf = Gaussian_fdf;
1205
- f.n = n;
1206
- f.p = p;
1207
- f.params = &hh;
1208
-
1209
- T = gsl_multifit_fdfsolver_lmsder;
1210
- s = gsl_multifit_fdfsolver_alloc(T, n, p);
1211
- gsl_multifit_fdfsolver_set(s, &f, x);
1212
-
1213
- do {
1214
- iter++;
1215
- status = gsl_multifit_fdfsolver_iterate(s);
1216
- if (status) break;
1217
- status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4);
1218
- } while (status == GSL_CONTINUE);
1219
- sigma = sqrt(gsl_vector_get(s->x, 0));
1220
- mean = gsl_vector_get(s->x, 1);
1221
- height = gsl_vector_get(s->x, 2)*sigma*sqrt(2*M_PI);
1222
- gsl_multifit_covar(s->J, 0.0, covar);
1223
- chi2 = gsl_pow_2(gsl_blas_dnrm2(s->f)); /* not reduced chi-square */
1224
- dof = n - p;
1225
- errs = sqrt(chi2/dof*gsl_matrix_get(covar, 0, 0))/sigma/2;
1226
- errm = sqrt(chi2/dof*gsl_matrix_get(covar, 1, 1));
1227
- errh = sqrt(chi2/dof*gsl_matrix_get(covar, 2, 2));
1228
-
1229
- gsl_multifit_fdfsolver_free(s);
1230
- gsl_vector_free(x);
1231
- gsl_matrix_free(covar);
1232
- return rb_ary_new3(8, rb_float_new(sigma), rb_float_new(mean),
1233
- rb_float_new(height), rb_float_new(errs),
1234
- rb_float_new(errm), rb_float_new(errh),
1235
- rb_float_new(chi2), INT2FIX(dof));
1236
- }
1237
-
1238
- static int Rayleigh_f(const gsl_vector *v, void *params, gsl_vector *f);
1239
- static int Rayleigh_df(const gsl_vector *v, void *params, gsl_matrix * J);
1240
- static int Rayleigh_f(const gsl_vector *v, void *params, gsl_vector *f)
1241
- {
1242
- struct fit_histogram *hh;
1243
- gsl_histogram *h = NULL;
1244
- double amp, var, xl, xh, xi, yi, sqw;
1245
- size_t i, binstart, binend;
1246
- hh = (struct fit_histogram *) params;
1247
- h = hh->h;
1248
- binstart = hh->binstart;
1249
- binend = hh->binend;
1250
- var = gsl_vector_get(v, 0);
1251
- amp = gsl_vector_get(v, 1);
1252
- for (i = binstart; i <= binend; i++) {
1253
- if (gsl_histogram_get_range(h, i, &xl, &xh))
1254
- rb_raise(rb_eIndexError, "wrong index");
1255
- xi = (xl + xh)/2.0;
1256
- yi = h->bin[i];
1257
- sqw = sqrt(yi);
1258
- gsl_vector_set(f, i-binstart, (amp*xi*exp(-xi*xi/var/2.0) - yi)*sqw);
1259
- }
1260
- return GSL_SUCCESS;
1261
- }
1262
-
1263
- static int Rayleigh_df(const gsl_vector *v, void *params, gsl_matrix *J)
1264
- {
1265
- struct fit_histogram *hh;
1266
- gsl_histogram *h = NULL;
1267
- double amp, var, xl, xh, xi, yi, y, sqw;
1268
- size_t i, binstart, binend;
1269
- hh = (struct fit_histogram *) params;
1270
- h = hh->h;
1271
- binstart = hh->binstart;
1272
- binend = hh->binend;
1273
- var = gsl_vector_get(v, 0);
1274
- amp = gsl_vector_get(v, 1);
1275
- for (i = binstart; i <= binend; i++) {
1276
- if (gsl_histogram_get_range(h, i, &xl, &xh))
1277
- rb_raise(rb_eIndexError, "wrong index");
1278
- xi = (xl + xh)/2.0;
1279
- yi = h->bin[i];
1280
- sqw = sqrt(yi);
1281
- y = xi*exp(-xi*xi/var/2.0);
1282
- gsl_matrix_set(J, i-binstart, 0, amp*y*xi*xi/2/var/var*sqw);
1283
- gsl_matrix_set(J, i-binstart, 1, y*sqw);
1284
- }
1285
- return GSL_SUCCESS;
1286
- }
1287
-
1288
- static int Rayleigh_fdf(const gsl_vector *v, void *params, gsl_vector *f,
1289
- gsl_matrix *J)
1290
- {
1291
- Rayleigh_f(v, params, f);
1292
- Rayleigh_df(v, params, J);
1293
- return GSL_SUCCESS;
1294
- }
1295
-
1296
-
1297
- static VALUE rb_gsl_histogram_fit_rayleigh(int argc, VALUE *argv, VALUE obj)
1298
- {
1299
- gsl_histogram *h = NULL;
1300
- struct fit_histogram hh;
1301
- const gsl_multifit_fdfsolver_type *T;
1302
- gsl_multifit_fdfsolver *s;
1303
- int status;
1304
- size_t iter = 0, binstart, binend;
1305
- size_t n, dof; /* # of data points */
1306
- size_t p = 2; /* # of fitting parameters */
1307
- gsl_multifit_function_fdf f;
1308
- gsl_matrix *covar = NULL;
1309
- gsl_vector *x = NULL;
1310
- double sigma, height, errs, errh, chi2;
1311
- Data_Get_Struct(obj, gsl_histogram, h);
1312
- binstart = 0;
1313
- binend = h->n - 1;
1314
- switch (argc) {
1315
- case 2:
1316
- CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
1317
- binstart = FIX2INT(argv[0]);
1318
- binend = FIX2INT(argv[1]);
1319
- if (binend >= h->n) binend = h->n - 1;
1320
- break;
1321
- case 0:
1322
- break;
1323
- default:
1324
- rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
1325
- break;
1326
- }
1327
- x = gsl_vector_alloc(p);
1328
- gsl_vector_set(x, 0, gsl_pow_2(gsl_histogram_sigma(h))); /* initial values, var = 1 */
1329
- gsl_vector_set(x, 1, gsl_histogram_max_val(h));
1330
- hh.h = h;
1331
- hh.binstart = binstart;
1332
- hh.binend = binend;
1333
- n = binend - binstart + 1;
1334
-
1335
- covar = gsl_matrix_alloc(p, p);
1336
-
1337
- f.f = Rayleigh_f;
1338
- f.df = Rayleigh_df;
1339
- f.fdf = Rayleigh_fdf;
1340
- f.n = n;
1341
- f.p = p;
1342
- f.params = &hh;
1343
-
1344
- T = gsl_multifit_fdfsolver_lmsder;
1345
- s = gsl_multifit_fdfsolver_alloc(T, n, p);
1346
- gsl_multifit_fdfsolver_set(s, &f, x);
1347
-
1348
- do {
1349
- iter++;
1350
- status = gsl_multifit_fdfsolver_iterate(s);
1351
- if (status) break;
1352
- status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4);
1353
- } while (status == GSL_CONTINUE);
1354
- sigma = sqrt(gsl_vector_get(s->x, 0));
1355
- height = gsl_vector_get(s->x, 1)*sigma*sigma;
1356
- gsl_multifit_covar(s->J, 0.0, covar);
1357
- chi2 = gsl_pow_2(gsl_blas_dnrm2(s->f)); /* not reduced chi-square */
1358
- dof = n - p;
1359
- errs = sqrt(chi2/dof*gsl_matrix_get(covar, 0, 0))/sigma/2;
1360
- errh = sqrt(chi2/dof*gsl_matrix_get(covar, 1, 1));
1361
-
1362
- gsl_multifit_fdfsolver_free(s);
1363
- gsl_vector_free(x);
1364
- gsl_matrix_free(covar);
1365
- return rb_ary_new3(6, rb_float_new(sigma),
1366
- rb_float_new(height), rb_float_new(errs),
1367
- rb_float_new(errh),
1368
- rb_float_new(chi2), INT2FIX(dof));
1369
- }
1370
-
1371
- /*
1372
- * y(x) = Amp*exp(-a*x)
1373
- */
1374
- static int xExponential_f(const gsl_vector *v, void *params, gsl_vector *f);
1375
- static int xExponential_df(const gsl_vector *v, void *params, gsl_matrix * J);
1376
- static int xExponential_f(const gsl_vector *v, void *params, gsl_vector *f)
1377
- {
1378
- struct fit_histogram *hh;
1379
- gsl_histogram *h = NULL;
1380
- double amp, b, xl, xh, xi, yi, sqw;
1381
- size_t i, binstart, binend;
1382
- hh = (struct fit_histogram *) params;
1383
- h = hh->h;
1384
- binstart = hh->binstart;
1385
- binend = hh->binend;
1386
- b = gsl_vector_get(v, 0);
1387
- amp = gsl_vector_get(v, 1);
1388
- for (i = binstart; i <= binend; i++) {
1389
- if (gsl_histogram_get_range(h, i, &xl, &xh))
1390
- rb_raise(rb_eIndexError, "wrong index");
1391
- xi = (xl + xh)/2.0;
1392
- yi = h->bin[i];
1393
- sqw = sqrt(yi);
1394
- gsl_vector_set(f, i-binstart, (amp*xi*exp(-b*xi) - yi)*sqw);
1395
- }
1396
- return GSL_SUCCESS;
1397
- }
1398
-
1399
- static int xExponential_df(const gsl_vector *v, void *params, gsl_matrix *J)
1400
- {
1401
- struct fit_histogram *hh;
1402
- gsl_histogram *h = NULL;
1403
- double amp, b, xl, xh, xi, yi, y, sqw;
1404
- size_t i, binstart, binend;
1405
- hh = (struct fit_histogram *) params;
1406
- h = hh->h;
1407
- binstart = hh->binstart;
1408
- binend = hh->binend;
1409
- b = gsl_vector_get(v, 0);
1410
- amp = gsl_vector_get(v, 1);
1411
- for (i = binstart; i <= binend; i++) {
1412
- if (gsl_histogram_get_range(h, i, &xl, &xh))
1413
- rb_raise(rb_eIndexError, "wrong index");
1414
- xi = (xl + xh)/2.0;
1415
- yi = h->bin[i];
1416
- sqw = sqrt(yi);
1417
- y = xi*exp(-b*xi);
1418
- gsl_matrix_set(J, i-binstart, 0, -amp*y*xi*sqw);
1419
- gsl_matrix_set(J, i-binstart, 1, y*sqw);
1420
- }
1421
- return GSL_SUCCESS;
1422
- }
1423
-
1424
- static int xExponential_fdf(const gsl_vector *v, void *params, gsl_vector *f,
1425
- gsl_matrix *J)
1426
- {
1427
- xExponential_f(v, params, f);
1428
- xExponential_df(v, params, J);
1429
- return GSL_SUCCESS;
1430
- }
1431
-
1432
-
1433
- static VALUE rb_gsl_histogram_fit_xexponential(int argc, VALUE *argv, VALUE obj)
1434
- {
1435
- gsl_histogram *h = NULL;
1436
- struct fit_histogram hh;
1437
- const gsl_multifit_fdfsolver_type *T;
1438
- gsl_multifit_fdfsolver *s;
1439
- int status;
1440
- size_t iter = 0, binstart, binend;
1441
- size_t n, dof; /* # of data points */
1442
- size_t p = 2; /* # of fitting parameters */
1443
- gsl_multifit_function_fdf f;
1444
- gsl_matrix *covar = NULL;
1445
- gsl_vector *x = NULL;
1446
- double b, height, errs, errh, chi2;
1447
- Data_Get_Struct(obj, gsl_histogram, h);
1448
- binstart = 0;
1449
- binend = h->n - 1;
1450
- switch (argc) {
1451
- case 2:
1452
- CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
1453
- binstart = FIX2INT(argv[0]);
1454
- binend = FIX2INT(argv[1]);
1455
- if (binend >= h->n) binend = h->n - 1;
1456
- break;
1457
- case 0:
1458
- break;
1459
- default:
1460
- rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
1461
- break;
1462
- }
1463
- x = gsl_vector_alloc(p);
1464
- gsl_vector_set(x, 0, gsl_histogram_sigma(h)); /* initial values, var = 1 */
1465
- gsl_vector_set(x, 1, gsl_histogram_max_val(h));
1466
- hh.h = h;
1467
- hh.binstart = binstart;
1468
- hh.binend = binend;
1469
- n = binend - binstart + 1;
1470
-
1471
- covar = gsl_matrix_alloc(p, p);
1472
-
1473
- f.f = xExponential_f;
1474
- f.df = xExponential_df;
1475
- f.fdf = xExponential_fdf;
1476
- f.n = n;
1477
- f.p = p;
1478
- f.params = &hh;
1479
-
1480
- T = gsl_multifit_fdfsolver_lmsder;
1481
- s = gsl_multifit_fdfsolver_alloc(T, n, p);
1482
- gsl_multifit_fdfsolver_set(s, &f, x);
1483
-
1484
- do {
1485
- iter++;
1486
- status = gsl_multifit_fdfsolver_iterate(s);
1487
- if (status) break;
1488
- status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4);
1489
- } while (status == GSL_CONTINUE);
1490
- b = gsl_vector_get(s->x, 0);
1491
- height = gsl_vector_get(s->x, 1);
1492
- gsl_multifit_covar(s->J, 0.0, covar);
1493
- chi2 = gsl_pow_2(gsl_blas_dnrm2(s->f)); /* not reduced chi-square */
1494
- dof = n - p;
1495
- errs = sqrt(chi2/dof*gsl_matrix_get(covar, 0, 0));
1496
- errh = sqrt(chi2/dof*gsl_matrix_get(covar, 1, 1));
1497
-
1498
- gsl_multifit_fdfsolver_free(s);
1499
- gsl_vector_free(x);
1500
- gsl_matrix_free(covar);
1501
- return rb_ary_new3(6, rb_float_new(b),
1502
- rb_float_new(height), rb_float_new(errs),
1503
- rb_float_new(errh),
1504
- rb_float_new(chi2), INT2FIX(dof));
1505
- }
1506
-
1507
- static VALUE rb_gsl_histogram_fit(int argc, VALUE *argv, VALUE obj)
1508
- {
1509
- char fittype[32];
1510
- if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
1511
- Check_Type(argv[0], T_STRING);
1512
- strcpy(fittype, STR2CSTR(argv[0]));
1513
- if (str_head_grep(fittype, "exp") == 0) {
1514
- return rb_gsl_histogram_fit_exponential(argc-1, argv+1, obj);
1515
- } else if (str_head_grep(fittype, "power") == 0) {
1516
- return rb_gsl_histogram_fit_power(argc-1, argv+1, obj);
1517
- } else if (str_head_grep(fittype, "gaus") == 0) {
1518
- return rb_gsl_histogram_fit_gaussian(argc-1, argv+1, obj);
1519
- } else if (str_head_grep(fittype, "rayleigh") == 0) {
1520
- return rb_gsl_histogram_fit_rayleigh(argc-1, argv+1, obj);
1521
- } else if (str_head_grep(fittype, "xexp") == 0) {
1522
- return rb_gsl_histogram_fit_xexponential(argc-1, argv+1, obj);
1523
- } else {
1524
- rb_raise(rb_eRuntimeError,
1525
- "unknown fitting type %s (exp, power, gaus expected)", fittype);
1526
- }
1527
- return Qnil;
1528
- }
1529
-
1530
- /* Integrate histogram: the two histograms must have the same range and bins. */
1531
- void mygsl_histogram_integrate(const gsl_histogram *h, gsl_histogram *hi,
1532
- size_t istart, size_t iend)
1533
- {
1534
- size_t i;
1535
- if (iend >= istart) {
1536
- //if (istart < 0) istart = 0;
1537
- if (iend >= h->n) iend = h->n-1;
1538
- hi->bin[istart] = h->bin[istart];
1539
- for (i = istart+1; i <= iend; i++) hi->bin[i] = hi->bin[i-1] + h->bin[i];
1540
- } else {
1541
- if (istart >= h->n) istart = h->n-1;
1542
- //if (iend < 0) iend = 0;
1543
- hi->bin[istart] = h->bin[istart];
1544
- for (i = istart-1; i >= iend; i--) {
1545
- hi->bin[i] = hi->bin[i+1] + h->bin[i];
1546
- if (i == 0) break;
1547
- }
1548
- }
1549
- }
1550
-
1551
- void mygsl_histogram_differentiate(const gsl_histogram *hi, gsl_histogram *h)
1552
- {
1553
- size_t i;
1554
- h->bin[0] = hi->bin[0];
1555
- for (i = 1; i < hi->n; i++) h->bin[i] = hi->bin[i] - hi->bin[i-1];
1556
- }
1557
-
1558
- /* Create a histogram integrating the given histogram h */
1559
- gsl_histogram* mygsl_histogram_calloc_integrate(const gsl_histogram *h,
1560
- size_t istart, size_t iend)
1561
- {
1562
- gsl_histogram *hi = NULL;
1563
- hi = gsl_histogram_calloc_range(h->n, h->range);
1564
- mygsl_histogram_integrate(h, hi, istart, iend);
1565
- return hi;
1566
- }
1567
-
1568
- gsl_histogram* mygsl_histogram_calloc_differentiate(const gsl_histogram *hi)
1569
- {
1570
- gsl_histogram *h = NULL;
1571
- h = gsl_histogram_calloc_range(hi->n, hi->range);
1572
- mygsl_histogram_differentiate(hi, h);
1573
- return h;
1574
- }
1575
-
1576
- static VALUE rb_gsl_histogram_integrate(int argc, VALUE *argv, VALUE obj)
1577
- {
1578
- gsl_histogram *h, *hi;
1579
- size_t istart, iend;
1580
- int itmp;
1581
- Data_Get_Struct(obj, gsl_histogram, h);
1582
- switch (argc) {
1583
- case 2:
1584
- istart = FIX2INT(argv[0]);
1585
- iend = FIX2INT(argv[1]);
1586
- break;
1587
- case 1:
1588
- switch (TYPE(argv[0])) {
1589
- case T_ARRAY:
1590
- istart = FIX2INT(rb_ary_entry(argv[0], 0));
1591
- iend = FIX2INT(rb_ary_entry(argv[0], 1));
1592
- break;
1593
- case T_FIXNUM:
1594
- itmp = FIX2INT(argv[0]);
1595
- if (itmp == -1) {
1596
- istart = h->n - 1;
1597
- iend = 0;
1598
- } else {
1599
- istart = 0;
1600
- iend = h->n - 1;
1601
- }
1602
- break;
1603
- default:
1604
- rb_raise(rb_eArgError, "wrong argument type %s (Arran or Fixnum expected)",
1605
- rb_class2name(CLASS_OF(argv[0])));
1606
- break;
1607
- }
1608
- break;
1609
- case 0:
1610
- istart = 0;
1611
- iend = h->n - 1;
1612
- break;
1613
- default:
1614
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-2)", argc);
1615
- break;
1616
- }
1617
- hi = mygsl_histogram_calloc_integrate(h, istart, iend);
1618
- return Data_Wrap_Struct(cgsl_histogram_integ, 0, gsl_histogram_free, hi);
1619
- }
1620
-
1621
- static VALUE rb_gsl_histogram_differentiate(VALUE obj)
1622
- {
1623
- gsl_histogram *h, *hi;
1624
- Data_Get_Struct(obj, gsl_histogram, hi);
1625
- h = mygsl_histogram_calloc_differentiate(hi);
1626
- return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, h);
1627
- }
1628
-
1629
- static gsl_histogram* mygsl_histogram_rebin(const gsl_histogram *h, size_t m)
1630
- {
1631
- gsl_histogram *hnew;
1632
- double w;
1633
- size_t n, i, j, k;
1634
- if (m > h->n) m = h->n;
1635
- n = (size_t) h->n/m;
1636
- if (n*m != h->n) n += 1;
1637
- w = (h->range[h->n] - h->range[0])/h->n;
1638
- hnew = gsl_histogram_alloc(n);
1639
- for (i = 0, j = 0; i <= n; i++) {
1640
- if (i*m <= h->n) hnew->range[i] = h->range[i*m];
1641
- else hnew->range[i] = w*m*i;
1642
- }
1643
- for (i = 0, j = 0; i < n; i++) {
1644
- hnew->bin[i] = 0;
1645
- for (k = 0; k < m && j < h->n; k++) hnew->bin[i] += h->bin[j++];
1646
- }
1647
- return hnew;
1648
- }
1649
-
1650
- static VALUE rb_gsl_histogram_rebin(int argc, VALUE *argv, VALUE obj)
1651
- {
1652
- gsl_histogram *h, *hnew;
1653
- size_t m = 2;
1654
- switch (argc) {
1655
- case 1:
1656
- CHECK_FIXNUM(argv[0]);
1657
- m = (size_t) FIX2INT(argv[0]);
1658
- break;
1659
- case 0:
1660
- m = 2;
1661
- break;
1662
- default:
1663
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
1664
- break;
1665
- }
1666
- Data_Get_Struct(obj, gsl_histogram, h);
1667
- hnew = mygsl_histogram_rebin(h, m);
1668
- return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, hnew);
1669
- }
1670
-
1671
- static int mygsl_histogram_fread2(FILE * stream, gsl_histogram * h)
1672
- {
1673
- double min, max;
1674
- int status;
1675
- status = gsl_block_raw_fread(stream, &min, 1, 1);
1676
- if (status) return status;
1677
- status = gsl_block_raw_fread(stream, &max, 1, 1);
1678
- if (status) return status;
1679
- gsl_histogram_set_ranges_uniform(h, min, max);
1680
- status = gsl_block_raw_fread (stream, h->bin, h->n, 1);
1681
- if (status) return status;
1682
- return status;
1683
- }
1684
-
1685
- static int mygsl_histogram_fwrite2(FILE * stream, const gsl_histogram * h)
1686
- {
1687
- int status;
1688
- status = gsl_block_raw_fwrite (stream, h->range, 1, 1);
1689
- if (status) return status;
1690
- status = gsl_block_raw_fwrite (stream, h->range+h->n, 1, 1);
1691
- if (status) return status;
1692
- status = gsl_block_raw_fwrite (stream, h->bin, h->n, 1);
1693
- return status;
1694
- }
1695
-
1696
- static VALUE rb_gsl_histogram_fwrite2(VALUE obj, VALUE io)
1697
- {
1698
- gsl_histogram *h = NULL;
1699
- FILE *f;
1700
- int status, flag = 0;
1701
- Data_Get_Struct(obj, gsl_histogram, h);
1702
- f = rb_gsl_open_writefile(io, &flag);
1703
- status = mygsl_histogram_fwrite2(f, h);
1704
- if (flag == 1) fclose(f);
1705
- return INT2FIX(status);
1706
- }
1707
-
1708
- static VALUE rb_gsl_histogram_fread2(VALUE obj, VALUE io)
1709
- {
1710
- gsl_histogram *h = NULL;
1711
- FILE *f;
1712
- int status, flag = 0;
1713
- Data_Get_Struct(obj, gsl_histogram, h);
1714
- f = rb_gsl_open_readfile(io, &flag);
1715
- status = mygsl_histogram_fread2(f, h);
1716
- if (flag == 1) fclose(f);
1717
- return INT2FIX(status);
1718
- }
1719
-
1720
- static gsl_histogram* mygsl_histogram_calloc_reverse(const gsl_histogram *h)
1721
- {
1722
- gsl_histogram *hnew;
1723
- size_t i, n;
1724
- hnew = gsl_histogram_alloc(h->n);
1725
- n = h->n;
1726
- for (i = 0; i <= n; i++) hnew->range[i] = h->range[n-i];
1727
- for (i = 0; i < n; i++) hnew->bin[i] = h->bin[n-1-i];
1728
- return hnew;
1729
- }
1730
-
1731
- static VALUE rb_gsl_histogram_reverse(VALUE obj)
1732
- {
1733
- gsl_histogram *h, *hnew;
1734
- Data_Get_Struct(obj, gsl_histogram, h);
1735
- hnew = mygsl_histogram_calloc_reverse(h);
1736
- return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, hnew);
1737
- }
1738
-
1739
- /* The functions below are not included in GSL */
1740
- /*
1741
- * Returns an x value at which the histogram integration
1742
- * reaches the given percentile. The x value is calculated
1743
- * by an interpolation between the ranges in which the percentile
1744
- * is found.
1745
- */
1746
- static double histogram_percentile(const gsl_histogram *h, double f)
1747
- {
1748
- double sum = gsl_histogram_sum(h), sf;
1749
- double val = 0, s = 0, x;
1750
- double ri, ri1;
1751
- size_t i;
1752
- sf = sum * f;
1753
- for (i = 0; i < h->n; i++) {
1754
- val = gsl_histogram_get(h, i);
1755
- if ((s+val) > sf) break;
1756
- s += val;
1757
- }
1758
- ri = h->range[i];
1759
- ri1 = h->range[i+1];
1760
- x = (sf - s)*(ri1 - ri)/val + ri;
1761
- return x;
1762
- }
1763
-
1764
- static double histogram_median(const gsl_histogram *h)
1765
- {
1766
- return histogram_percentile(h, 0.5);
1767
- }
1768
-
1769
- static VALUE rb_gsl_histogram_percentile(VALUE obj, VALUE f)
1770
- {
1771
- gsl_histogram *h;
1772
- Data_Get_Struct(obj, gsl_histogram, h);
1773
- return rb_float_new(histogram_percentile(h, NUM2DBL(f)));
1774
- }
1775
-
1776
- static VALUE rb_gsl_histogram_median(VALUE obj)
1777
- {
1778
- gsl_histogram *h;
1779
- Data_Get_Struct(obj, gsl_histogram, h);
1780
- return rb_float_new(histogram_median(h));
1781
- }
1782
-
1783
- static double histogram_percentile_inv(const gsl_histogram *h, double x)
1784
- {
1785
- double sum = gsl_histogram_sum(h);
1786
- double val = 0, s = 0;
1787
- double ri, ri1, q;
1788
- size_t i;
1789
-
1790
- for (i = 0; i < h->n; i++) {
1791
- val = gsl_histogram_get(h, i);
1792
- if (h->range[i+1] > x) break;
1793
- s += val;
1794
- }
1795
- ri = h->range[i];
1796
- ri1 = h->range[i+1];
1797
- q = s + val/(ri1 - ri)*(x - ri);
1798
- return q/sum;
1799
- }
1800
-
1801
- static VALUE rb_gsl_histogram_percentile_inv(VALUE obj, VALUE x)
1802
- {
1803
- gsl_histogram *h;
1804
- Data_Get_Struct(obj, gsl_histogram, h);
1805
- return rb_float_new(histogram_percentile_inv(h, NUM2DBL(x)));
1806
- }
1807
-
1808
- void Init_gsl_histogram(VALUE module)
1809
- {
1810
- VALUE cgsl_histogram_pdf;
1811
-
1812
- cgsl_histogram = rb_define_class_under(module, "Histogram", cGSL_Object);
1813
- cgsl_histogram_range = rb_define_class_under(cgsl_histogram, "Range",
1814
- cgsl_vector_view_ro);
1815
- cgsl_histogram_bin = rb_define_class_under(cgsl_histogram, "Bin",
1816
- cgsl_vector_view);
1817
- cgsl_histogram_integ = rb_define_class_under(cgsl_histogram, "Integral",
1818
- cgsl_histogram);
1819
-
1820
- rb_define_singleton_method(cgsl_histogram, "alloc", rb_gsl_histogram_alloc, -1);
1821
- /* rb_define_singleton_method(cgsl_histogram, "new", rb_gsl_histogram_alloc, -1);*/
1822
- rb_define_singleton_method(cgsl_histogram, "[]", rb_gsl_histogram_alloc, -1);
1823
-
1824
- rb_define_singleton_method(cgsl_histogram, "alloc_uniform",
1825
- rb_gsl_histogram_alloc_uniform, -1);
1826
- rb_define_singleton_method(cgsl_histogram, "new_uniform",
1827
- rb_gsl_histogram_alloc_uniform, -1);
1828
-
1829
- rb_define_singleton_method(cgsl_histogram, "alloc_with_min_max_step",
1830
- rb_gsl_histogram_alloc_with_min_max_step, 3);
1831
- rb_define_singleton_method(cgsl_histogram, "new_with_min_max_step",
1832
- rb_gsl_histogram_alloc_with_min_max_step, 3);
1833
-
1834
- rb_define_singleton_method(cgsl_histogram, "calloc",
1835
- rb_gsl_histogram_calloc, 1);
1836
- rb_define_singleton_method(cgsl_histogram, "calloc_range",
1837
- rb_gsl_histogram_calloc_range, -1);
1838
-
1839
- rb_define_method(cgsl_histogram, "bins", rb_gsl_histogram_bins, 0);
1840
- rb_define_alias(cgsl_histogram, "n", "bins");
1841
- rb_define_alias(cgsl_histogram, "size", "bins");
1842
- rb_define_method(cgsl_histogram, "set_ranges", rb_gsl_histogram_set_ranges, -1);
1843
- rb_define_method(cgsl_histogram, "range", rb_gsl_histogram_range, 0);
1844
- rb_define_method(cgsl_histogram, "bin", rb_gsl_histogram_bin, 0);
1845
- rb_define_method(cgsl_histogram, "set_ranges_uniform",
1846
- rb_gsl_histogram_set_ranges_uniform, -1);
1847
- rb_define_singleton_method(cgsl_histogram, "memcpy", rb_gsl_histogram_memcpy, 2);
1848
- rb_define_method(cgsl_histogram, "clone", rb_gsl_histogram_clone, 0);
1849
- rb_define_alias(cgsl_histogram, "duplicate", "clone");
1850
- rb_define_method(cgsl_histogram, "increment", rb_gsl_histogram_accumulate, -1);
1851
- rb_define_alias(cgsl_histogram, "fill", "increment");
1852
- rb_define_alias(cgsl_histogram, "accumulate", "increment");
1853
- rb_define_method(cgsl_histogram, "increment2", rb_gsl_histogram_accumulate2, -1);
1854
- rb_define_alias(cgsl_histogram, "accumulate2", "increment2");
1855
- rb_define_alias(cgsl_histogram, "fill2", "increment2");
1856
-
1857
- rb_define_method(cgsl_histogram, "get", rb_gsl_histogram_get, 1);
1858
- rb_define_alias(cgsl_histogram, "[]", "get");
1859
- rb_define_method(cgsl_histogram, "get_range", rb_gsl_histogram_get_range, 1);
1860
- rb_define_method(cgsl_histogram, "max", rb_gsl_histogram_max, 0);
1861
- rb_define_method(cgsl_histogram, "min", rb_gsl_histogram_min, 0);
1862
- rb_define_method(cgsl_histogram, "reset", rb_gsl_histogram_reset, 0);
1863
- rb_define_method(cgsl_histogram, "find", rb_gsl_histogram_find, 1);
1864
- rb_define_method(cgsl_histogram, "max_val", rb_gsl_histogram_max_val, 0);
1865
- rb_define_method(cgsl_histogram, "max_bin", rb_gsl_histogram_max_bin, 0);
1866
- rb_define_method(cgsl_histogram, "min_val", rb_gsl_histogram_min_val, 0);
1867
- rb_define_method(cgsl_histogram, "min_bin", rb_gsl_histogram_min_bin, 0);
1868
- rb_define_method(cgsl_histogram, "mean", rb_gsl_histogram_mean, 0);
1869
- rb_define_method(cgsl_histogram, "sigma", rb_gsl_histogram_sigma, 0);
1870
-
1871
- rb_define_method(cgsl_histogram, "sum", rb_gsl_histogram_integral, -1);
1872
- rb_define_alias(cgsl_histogram, "integral", "sum");
1873
-
1874
- rb_define_method(cgsl_histogram, "equal_bins_p",
1875
- rb_gsl_histogram_equal_bins_p, -1);
1876
- rb_define_alias(cgsl_histogram, "equal_bins", "equal_bins_p");
1877
- rb_define_singleton_method(cgsl_histogram, "equal_bins_p",
1878
- rb_gsl_histogram_equal_bins_p, -1);
1879
- rb_define_singleton_method(cgsl_histogram, "equal_bins",
1880
- rb_gsl_histogram_equal_bins_p, -1);
1881
- rb_define_method(cgsl_histogram, "equal_bins_p?",
1882
- rb_gsl_histogram_equal_bins_p2, -1);
1883
- rb_define_alias(cgsl_histogram, "equal_bins?", "equal_bins_p?");
1884
- rb_define_singleton_method(cgsl_histogram, "equal_bins_p?",
1885
- rb_gsl_histogram_equal_bins_p2, -1);
1886
- rb_define_singleton_method(cgsl_histogram, "equal_bins?",
1887
- rb_gsl_histogram_equal_bins_p2, -1);
1888
-
1889
- rb_define_method(cgsl_histogram, "add", rb_gsl_histogram_add, 1);
1890
- rb_define_alias(cgsl_histogram, "+", "add");
1891
- rb_define_method(cgsl_histogram, "sub", rb_gsl_histogram_sub, 1);
1892
- rb_define_alias(cgsl_histogram, "-", "sub");
1893
- rb_define_method(cgsl_histogram, "mul", rb_gsl_histogram_mul, 1);
1894
- rb_define_alias(cgsl_histogram, "*", "mul");
1895
- rb_define_method(cgsl_histogram, "div", rb_gsl_histogram_div, 1);
1896
- rb_define_alias(cgsl_histogram, "/", "div");
1897
-
1898
- rb_define_method(cgsl_histogram, "add!", rb_gsl_histogram_add2, 1);
1899
- rb_define_method(cgsl_histogram, "sub!", rb_gsl_histogram_sub2, 1);
1900
- rb_define_method(cgsl_histogram, "mul!", rb_gsl_histogram_mul2, 1);
1901
- rb_define_method(cgsl_histogram, "div!", rb_gsl_histogram_div2, 1);
1902
-
1903
- rb_define_method(cgsl_histogram, "scale!", rb_gsl_histogram_scale_bang, -1);
1904
- rb_define_method(cgsl_histogram, "scale", rb_gsl_histogram_scale, -1);
1905
- rb_define_method(cgsl_histogram, "shift!", rb_gsl_histogram_shift, 1);
1906
- rb_define_method(cgsl_histogram, "shift", rb_gsl_histogram_shift2, 1);
1907
-
1908
- rb_define_method(cgsl_histogram, "fwrite", rb_gsl_histogram_fwrite, 1);
1909
- rb_define_method(cgsl_histogram, "fread", rb_gsl_histogram_fread, 1);
1910
- rb_define_method(cgsl_histogram, "fwrite2", rb_gsl_histogram_fwrite2, 1);
1911
- rb_define_method(cgsl_histogram, "fread2", rb_gsl_histogram_fread2, 1);
1912
- rb_define_method(cgsl_histogram, "fprintf", rb_gsl_histogram_fprintf, -1);
1913
- rb_define_method(cgsl_histogram, "printf", rb_gsl_histogram_printf, -1);
1914
- rb_define_method(cgsl_histogram, "fscanf", rb_gsl_histogram_fscanf, 1);
1915
- rb_define_method(cgsl_histogram, "print", rb_gsl_histogram_print, 0);
1916
-
1917
- cgsl_histogram_pdf = rb_define_class_under(cgsl_histogram, "Pdf", cGSL_Object);
1918
- rb_define_singleton_method(cgsl_histogram_pdf, "alloc",
1919
- rb_gsl_histogram_pdf_alloc, 1);
1920
- /* rb_define_singleton_method(cgsl_histogram_pdf, "new",
1921
- rb_gsl_histogram_pdf_alloc, 1);*/
1922
- rb_define_method(cgsl_histogram_pdf, "init", rb_gsl_histogram_pdf_init, 1);
1923
- rb_define_method(cgsl_histogram_pdf, "sample", rb_gsl_histogram_pdf_sample, 1);
1924
-
1925
- rb_define_method(cgsl_histogram_pdf, "range", rb_gsl_histogram_pdf_range, 0);
1926
- rb_define_method(cgsl_histogram_pdf, "sum", rb_gsl_histogram_pdf_sum, 0);
1927
-
1928
- /*****/
1929
- rb_define_method(cgsl_histogram, "graph", rb_gsl_histogram_graph, -1);
1930
- rb_define_alias(cgsl_histogram, "draw", "graph");
1931
-
1932
- rb_define_method(cgsl_histogram, "plot", rb_gsl_histogram_plot, -1);
1933
-
1934
- rb_define_method(cgsl_histogram, "fit_gaussian",
1935
- rb_gsl_histogram_fit_gaussian, -1);
1936
- rb_define_method(cgsl_histogram, "fit_exponential",
1937
- rb_gsl_histogram_fit_exponential, -1);
1938
- rb_define_method(cgsl_histogram, "fit_xexponential",
1939
- rb_gsl_histogram_fit_xexponential, -1);
1940
- rb_define_method(cgsl_histogram, "fit_power",
1941
- rb_gsl_histogram_fit_power, -1);
1942
- rb_define_method(cgsl_histogram, "fit_rayleigh",
1943
- rb_gsl_histogram_fit_rayleigh, -1);
1944
- rb_define_method(cgsl_histogram, "fit",
1945
- rb_gsl_histogram_fit, -1);
1946
-
1947
- rb_define_method(cgsl_histogram, "integrate", rb_gsl_histogram_integrate, -1);
1948
- rb_undef_method(cgsl_histogram_integ, "integrate");
1949
- rb_define_method(cgsl_histogram_integ, "differentiate",
1950
- rb_gsl_histogram_differentiate, 0);
1951
- rb_define_alias(cgsl_histogram_integ, "diff", "differentiate");
1952
-
1953
- rb_define_method(cgsl_histogram, "normalize", rb_gsl_histogram_normalize, 0);
1954
- rb_define_method(cgsl_histogram, "normalize!", rb_gsl_histogram_normalize_bang, 0);
1955
-
1956
- rb_define_method(cgsl_histogram, "rebin", rb_gsl_histogram_rebin, -1);
1957
- rb_define_alias(cgsl_histogram, "mergebin", "rebin");
1958
-
1959
- rb_define_method(cgsl_histogram, "reverse", rb_gsl_histogram_reverse, 0);
1960
-
1961
- rb_define_method(cgsl_histogram, "percentile", rb_gsl_histogram_percentile, 1);
1962
- rb_define_method(cgsl_histogram, "median", rb_gsl_histogram_median, 0);
1963
- rb_define_method(cgsl_histogram, "percentile_inv", rb_gsl_histogram_percentile_inv, 1);
1964
- }