rb-gsl 1.15.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (660) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +6 -0
  3. data/COPYING +339 -0
  4. data/ChangeLog +567 -0
  5. data/README +32 -0
  6. data/Rakefile +99 -0
  7. data/THANKS +17 -0
  8. data/VERSION +1 -0
  9. data/examples/alf/alf.gp +15 -0
  10. data/examples/alf/alf.rb +32 -0
  11. data/examples/blas/blas.rb +13 -0
  12. data/examples/blas/dnrm2.rb +16 -0
  13. data/examples/blas/level1.rb +81 -0
  14. data/examples/blas/level2.rb +11 -0
  15. data/examples/blas/level3.rb +12 -0
  16. data/examples/bspline.rb +57 -0
  17. data/examples/cdf.rb +16 -0
  18. data/examples/cheb.rb +21 -0
  19. data/examples/combination.rb +23 -0
  20. data/examples/complex/RC-lpf.rb +47 -0
  21. data/examples/complex/add.rb +36 -0
  22. data/examples/complex/coerce.rb +14 -0
  23. data/examples/complex/complex.rb +25 -0
  24. data/examples/complex/fpmi.rb +70 -0
  25. data/examples/complex/functions.rb +77 -0
  26. data/examples/complex/michelson.rb +36 -0
  27. data/examples/complex/mul.rb +28 -0
  28. data/examples/complex/oscillator.rb +17 -0
  29. data/examples/complex/set.rb +37 -0
  30. data/examples/const/physconst.rb +151 -0
  31. data/examples/const/travel.rb +45 -0
  32. data/examples/deriv/demo.rb +13 -0
  33. data/examples/deriv/deriv.rb +36 -0
  34. data/examples/deriv/diff.rb +35 -0
  35. data/examples/dht.rb +42 -0
  36. data/examples/dirac.rb +56 -0
  37. data/examples/eigen/eigen.rb +34 -0
  38. data/examples/eigen/herm.rb +22 -0
  39. data/examples/eigen/narray.rb +9 -0
  40. data/examples/eigen/nonsymm.rb +37 -0
  41. data/examples/eigen/nonsymmv.rb +43 -0
  42. data/examples/eigen/qhoscillator.gp +35 -0
  43. data/examples/eigen/qhoscillator.rb +90 -0
  44. data/examples/eigen/vander.rb +41 -0
  45. data/examples/fft/fft.rb +17 -0
  46. data/examples/fft/fft2.rb +17 -0
  47. data/examples/fft/forward.rb +25 -0
  48. data/examples/fft/forward2.rb +26 -0
  49. data/examples/fft/radix2.rb +18 -0
  50. data/examples/fft/real-halfcomplex.rb +33 -0
  51. data/examples/fft/real-halfcomplex2.rb +30 -0
  52. data/examples/fft/realradix2.rb +19 -0
  53. data/examples/fft/sunspot.dat +256 -0
  54. data/examples/fft/sunspot.rb +16 -0
  55. data/examples/fit/expdata.dat +20 -0
  56. data/examples/fit/expfit.rb +31 -0
  57. data/examples/fit/gaussfit.rb +29 -0
  58. data/examples/fit/gaussian_2peaks.rb +34 -0
  59. data/examples/fit/hillfit.rb +40 -0
  60. data/examples/fit/lognormal.rb +26 -0
  61. data/examples/fit/lorentzfit.rb +22 -0
  62. data/examples/fit/multifit.rb +72 -0
  63. data/examples/fit/ndlinear.rb +133 -0
  64. data/examples/fit/nonlinearfit.rb +89 -0
  65. data/examples/fit/plot.gp +36 -0
  66. data/examples/fit/polyfit.rb +9 -0
  67. data/examples/fit/powerfit.rb +21 -0
  68. data/examples/fit/sigmoidfit.rb +40 -0
  69. data/examples/fit/sinfit.rb +22 -0
  70. data/examples/fit/wlinear.rb +46 -0
  71. data/examples/fresnel.rb +11 -0
  72. data/examples/function/function.rb +36 -0
  73. data/examples/function/log.rb +7 -0
  74. data/examples/function/min.rb +33 -0
  75. data/examples/function/sin.rb +10 -0
  76. data/examples/function/synchrotron.rb +18 -0
  77. data/examples/gallery/butterfly.rb +7 -0
  78. data/examples/gallery/cayley.rb +12 -0
  79. data/examples/gallery/cornu.rb +23 -0
  80. data/examples/gallery/eight.rb +11 -0
  81. data/examples/gallery/koch.rb +40 -0
  82. data/examples/gallery/lemniscate.rb +11 -0
  83. data/examples/gallery/polar.rb +11 -0
  84. data/examples/gallery/rgplot/cossin.rb +35 -0
  85. data/examples/gallery/rgplot/rgplot.replaced +0 -0
  86. data/examples/gallery/rgplot/roesller.rb +55 -0
  87. data/examples/gallery/roesller.rb +39 -0
  88. data/examples/gallery/scarabaeus.rb +14 -0
  89. data/examples/histogram/cauchy.rb +27 -0
  90. data/examples/histogram/cauchy.sh +2 -0
  91. data/examples/histogram/exponential.rb +19 -0
  92. data/examples/histogram/gauss.rb +16 -0
  93. data/examples/histogram/gsl-histogram.rb +40 -0
  94. data/examples/histogram/histo2d.rb +31 -0
  95. data/examples/histogram/histo3d.rb +34 -0
  96. data/examples/histogram/histogram-pdf.rb +27 -0
  97. data/examples/histogram/histogram.rb +26 -0
  98. data/examples/histogram/integral.rb +28 -0
  99. data/examples/histogram/poisson.rb +27 -0
  100. data/examples/histogram/power.rb +25 -0
  101. data/examples/histogram/rebin.rb +17 -0
  102. data/examples/histogram/smp.dat +5 -0
  103. data/examples/histogram/xexp.rb +21 -0
  104. data/examples/integration/ahmed.rb +21 -0
  105. data/examples/integration/cosmology.rb +75 -0
  106. data/examples/integration/friedmann.gp +16 -0
  107. data/examples/integration/friedmann.rb +35 -0
  108. data/examples/integration/gamma-zeta.rb +35 -0
  109. data/examples/integration/integration.rb +22 -0
  110. data/examples/integration/qag.rb +8 -0
  111. data/examples/integration/qag2.rb +14 -0
  112. data/examples/integration/qag3.rb +8 -0
  113. data/examples/integration/qagi.rb +28 -0
  114. data/examples/integration/qagi2.rb +49 -0
  115. data/examples/integration/qagiu.rb +29 -0
  116. data/examples/integration/qagp.rb +20 -0
  117. data/examples/integration/qags.rb +14 -0
  118. data/examples/integration/qawc.rb +18 -0
  119. data/examples/integration/qawf.rb +41 -0
  120. data/examples/integration/qawo.rb +29 -0
  121. data/examples/integration/qaws.rb +30 -0
  122. data/examples/integration/qng.rb +17 -0
  123. data/examples/interp/demo.gp +20 -0
  124. data/examples/interp/demo.rb +45 -0
  125. data/examples/interp/interp.rb +37 -0
  126. data/examples/interp/points +10 -0
  127. data/examples/interp/spline.rb +20 -0
  128. data/examples/jacobi/deriv.rb +40 -0
  129. data/examples/jacobi/integrate.rb +34 -0
  130. data/examples/jacobi/interp.rb +43 -0
  131. data/examples/jacobi/jacobi.rb +11 -0
  132. data/examples/linalg/HH.rb +15 -0
  133. data/examples/linalg/HH_narray.rb +13 -0
  134. data/examples/linalg/LQ_solve.rb +73 -0
  135. data/examples/linalg/LU.rb +84 -0
  136. data/examples/linalg/LU2.rb +31 -0
  137. data/examples/linalg/LU_narray.rb +24 -0
  138. data/examples/linalg/PTLQ.rb +47 -0
  139. data/examples/linalg/QR.rb +18 -0
  140. data/examples/linalg/QRPT.rb +47 -0
  141. data/examples/linalg/QR_solve.rb +78 -0
  142. data/examples/linalg/QR_solve_narray.rb +13 -0
  143. data/examples/linalg/SV.rb +16 -0
  144. data/examples/linalg/SV_narray.rb +12 -0
  145. data/examples/linalg/SV_solve.rb +49 -0
  146. data/examples/linalg/chol.rb +29 -0
  147. data/examples/linalg/chol_narray.rb +15 -0
  148. data/examples/linalg/complex.rb +57 -0
  149. data/examples/linalg/invert_narray.rb +10 -0
  150. data/examples/math/const.rb +67 -0
  151. data/examples/math/elementary.rb +35 -0
  152. data/examples/math/functions.rb +41 -0
  153. data/examples/math/inf_nan.rb +34 -0
  154. data/examples/math/minmax.rb +22 -0
  155. data/examples/math/power.rb +18 -0
  156. data/examples/math/test.rb +31 -0
  157. data/examples/matrix/a.dat +0 -0
  158. data/examples/matrix/add.rb +45 -0
  159. data/examples/matrix/b.dat +4 -0
  160. data/examples/matrix/cat.rb +31 -0
  161. data/examples/matrix/colvectors.rb +24 -0
  162. data/examples/matrix/complex.rb +41 -0
  163. data/examples/matrix/det.rb +29 -0
  164. data/examples/matrix/diagonal.rb +23 -0
  165. data/examples/matrix/get_all.rb +159 -0
  166. data/examples/matrix/hilbert.rb +31 -0
  167. data/examples/matrix/iterator.rb +19 -0
  168. data/examples/matrix/matrix.rb +57 -0
  169. data/examples/matrix/minmax.rb +53 -0
  170. data/examples/matrix/mul.rb +39 -0
  171. data/examples/matrix/rand.rb +20 -0
  172. data/examples/matrix/read.rb +29 -0
  173. data/examples/matrix/rowcol.rb +47 -0
  174. data/examples/matrix/set.rb +41 -0
  175. data/examples/matrix/set_all.rb +100 -0
  176. data/examples/matrix/view.rb +32 -0
  177. data/examples/matrix/view_all.rb +148 -0
  178. data/examples/matrix/write.rb +23 -0
  179. data/examples/min.rb +29 -0
  180. data/examples/monte/miser.rb +47 -0
  181. data/examples/monte/monte.rb +47 -0
  182. data/examples/monte/plain.rb +47 -0
  183. data/examples/monte/vegas.rb +46 -0
  184. data/examples/multimin/bundle.rb +66 -0
  185. data/examples/multimin/cqp.rb +109 -0
  186. data/examples/multimin/fdfminimizer.rb +40 -0
  187. data/examples/multimin/fminimizer.rb +41 -0
  188. data/examples/multiroot/demo.rb +36 -0
  189. data/examples/multiroot/fdfsolver.rb +50 -0
  190. data/examples/multiroot/fsolver.rb +33 -0
  191. data/examples/multiroot/fsolver2.rb +32 -0
  192. data/examples/multiroot/fsolver3.rb +26 -0
  193. data/examples/narray/histogram.rb +14 -0
  194. data/examples/narray/mandel.rb +27 -0
  195. data/examples/narray/narray.rb +28 -0
  196. data/examples/narray/narray2.rb +44 -0
  197. data/examples/narray/sf.rb +26 -0
  198. data/examples/ntuple/create.rb +17 -0
  199. data/examples/ntuple/project.rb +31 -0
  200. data/examples/odeiv/binarysystem.gp +23 -0
  201. data/examples/odeiv/binarysystem.rb +104 -0
  202. data/examples/odeiv/demo.gp +24 -0
  203. data/examples/odeiv/demo.rb +69 -0
  204. data/examples/odeiv/demo2.gp +26 -0
  205. data/examples/odeiv/duffing.rb +45 -0
  206. data/examples/odeiv/frei1.rb +109 -0
  207. data/examples/odeiv/frei2.rb +76 -0
  208. data/examples/odeiv/legendre.rb +52 -0
  209. data/examples/odeiv/odeiv.rb +32 -0
  210. data/examples/odeiv/odeiv2.rb +45 -0
  211. data/examples/odeiv/oscillator.rb +42 -0
  212. data/examples/odeiv/sedov.rb +97 -0
  213. data/examples/odeiv/whitedwarf.gp +40 -0
  214. data/examples/odeiv/whitedwarf.rb +158 -0
  215. data/examples/ool/conmin.rb +100 -0
  216. data/examples/ool/gencan.rb +99 -0
  217. data/examples/ool/pgrad.rb +100 -0
  218. data/examples/ool/spg.rb +100 -0
  219. data/examples/pdf/bernoulli.rb +5 -0
  220. data/examples/pdf/beta.rb +7 -0
  221. data/examples/pdf/binomiral.rb +10 -0
  222. data/examples/pdf/cauchy.rb +6 -0
  223. data/examples/pdf/chisq.rb +8 -0
  224. data/examples/pdf/exponential.rb +7 -0
  225. data/examples/pdf/exppow.rb +6 -0
  226. data/examples/pdf/fdist.rb +7 -0
  227. data/examples/pdf/flat.rb +7 -0
  228. data/examples/pdf/gamma.rb +8 -0
  229. data/examples/pdf/gauss-tail.rb +5 -0
  230. data/examples/pdf/gauss.rb +6 -0
  231. data/examples/pdf/geometric.rb +5 -0
  232. data/examples/pdf/gumbel.rb +6 -0
  233. data/examples/pdf/hypergeometric.rb +11 -0
  234. data/examples/pdf/landau.rb +5 -0
  235. data/examples/pdf/laplace.rb +7 -0
  236. data/examples/pdf/logarithmic.rb +5 -0
  237. data/examples/pdf/logistic.rb +6 -0
  238. data/examples/pdf/lognormal.rb +6 -0
  239. data/examples/pdf/neg-binomiral.rb +10 -0
  240. data/examples/pdf/pareto.rb +7 -0
  241. data/examples/pdf/pascal.rb +10 -0
  242. data/examples/pdf/poisson.rb +5 -0
  243. data/examples/pdf/rayleigh-tail.rb +6 -0
  244. data/examples/pdf/rayleigh.rb +6 -0
  245. data/examples/pdf/tdist.rb +6 -0
  246. data/examples/pdf/weibull.rb +8 -0
  247. data/examples/permutation/ex1.rb +22 -0
  248. data/examples/permutation/permutation.rb +16 -0
  249. data/examples/poly/bell.rb +6 -0
  250. data/examples/poly/bessel.rb +6 -0
  251. data/examples/poly/cheb.rb +6 -0
  252. data/examples/poly/cheb_II.rb +6 -0
  253. data/examples/poly/cubic.rb +9 -0
  254. data/examples/poly/demo.rb +20 -0
  255. data/examples/poly/eval.rb +28 -0
  256. data/examples/poly/eval_derivs.rb +14 -0
  257. data/examples/poly/fit.rb +21 -0
  258. data/examples/poly/hermite.rb +6 -0
  259. data/examples/poly/poly.rb +13 -0
  260. data/examples/poly/quadratic.rb +25 -0
  261. data/examples/random/diffusion.rb +34 -0
  262. data/examples/random/gaussian.rb +9 -0
  263. data/examples/random/generator.rb +27 -0
  264. data/examples/random/hdsobol.rb +21 -0
  265. data/examples/random/poisson.rb +9 -0
  266. data/examples/random/qrng.rb +19 -0
  267. data/examples/random/randomwalk.rb +37 -0
  268. data/examples/random/randomwalk2d.rb +19 -0
  269. data/examples/random/rayleigh.rb +36 -0
  270. data/examples/random/rng.rb +33 -0
  271. data/examples/random/rngextra.rb +14 -0
  272. data/examples/roots/bisection.rb +25 -0
  273. data/examples/roots/brent.rb +43 -0
  274. data/examples/roots/demo.rb +30 -0
  275. data/examples/roots/newton.rb +46 -0
  276. data/examples/roots/recombination.gp +12 -0
  277. data/examples/roots/recombination.rb +61 -0
  278. data/examples/roots/steffenson.rb +48 -0
  279. data/examples/sf/ShiChi.rb +6 -0
  280. data/examples/sf/SiCi.rb +6 -0
  281. data/examples/sf/airy_Ai.rb +8 -0
  282. data/examples/sf/airy_Bi.rb +8 -0
  283. data/examples/sf/bessel_IK.rb +12 -0
  284. data/examples/sf/bessel_JY.rb +13 -0
  285. data/examples/sf/beta_inc.rb +9 -0
  286. data/examples/sf/clausen.rb +6 -0
  287. data/examples/sf/dawson.rb +5 -0
  288. data/examples/sf/debye.rb +9 -0
  289. data/examples/sf/dilog.rb +6 -0
  290. data/examples/sf/ellint.rb +6 -0
  291. data/examples/sf/expint.rb +8 -0
  292. data/examples/sf/fermi.rb +10 -0
  293. data/examples/sf/gamma_inc_P.rb +9 -0
  294. data/examples/sf/gegenbauer.rb +8 -0
  295. data/examples/sf/hyperg.rb +7 -0
  296. data/examples/sf/laguerre.rb +19 -0
  297. data/examples/sf/lambertW.rb +5 -0
  298. data/examples/sf/legendre_P.rb +10 -0
  299. data/examples/sf/lngamma.rb +5 -0
  300. data/examples/sf/psi.rb +54 -0
  301. data/examples/sf/sphbessel.gp +27 -0
  302. data/examples/sf/sphbessel.rb +30 -0
  303. data/examples/sf/synchrotron.rb +5 -0
  304. data/examples/sf/transport.rb +10 -0
  305. data/examples/sf/zetam1.rb +5 -0
  306. data/examples/siman.rb +44 -0
  307. data/examples/sort/heapsort.rb +23 -0
  308. data/examples/sort/heapsort_vector_complex.rb +21 -0
  309. data/examples/sort/sort.rb +23 -0
  310. data/examples/sort/sort2.rb +16 -0
  311. data/examples/stats/mean.rb +17 -0
  312. data/examples/stats/statistics.rb +18 -0
  313. data/examples/stats/test.rb +9 -0
  314. data/examples/sum.rb +34 -0
  315. data/examples/tamu_anova.rb +18 -0
  316. data/examples/vector/a.dat +0 -0
  317. data/examples/vector/add.rb +56 -0
  318. data/examples/vector/b.dat +4 -0
  319. data/examples/vector/c.dat +3 -0
  320. data/examples/vector/collect.rb +26 -0
  321. data/examples/vector/compare.rb +28 -0
  322. data/examples/vector/complex.rb +51 -0
  323. data/examples/vector/complex_get_all.rb +85 -0
  324. data/examples/vector/complex_set_all.rb +131 -0
  325. data/examples/vector/complex_view_all.rb +77 -0
  326. data/examples/vector/connect.rb +22 -0
  327. data/examples/vector/decimate.rb +38 -0
  328. data/examples/vector/diff.rb +31 -0
  329. data/examples/vector/filescan.rb +17 -0
  330. data/examples/vector/floor.rb +23 -0
  331. data/examples/vector/get_all.rb +82 -0
  332. data/examples/vector/gnuplot.rb +38 -0
  333. data/examples/vector/graph.rb +28 -0
  334. data/examples/vector/histogram.rb +22 -0
  335. data/examples/vector/linspace.rb +24 -0
  336. data/examples/vector/log.rb +17 -0
  337. data/examples/vector/logic.rb +33 -0
  338. data/examples/vector/logspace.rb +25 -0
  339. data/examples/vector/minmax.rb +47 -0
  340. data/examples/vector/mul.rb +49 -0
  341. data/examples/vector/narray.rb +46 -0
  342. data/examples/vector/read.rb +29 -0
  343. data/examples/vector/set.rb +35 -0
  344. data/examples/vector/set_all.rb +121 -0
  345. data/examples/vector/smpv.dat +15 -0
  346. data/examples/vector/test.rb +43 -0
  347. data/examples/vector/test_gslblock.rb +58 -0
  348. data/examples/vector/vector.rb +110 -0
  349. data/examples/vector/view.rb +35 -0
  350. data/examples/vector/view_all.rb +73 -0
  351. data/examples/vector/where.rb +29 -0
  352. data/examples/vector/write.rb +24 -0
  353. data/examples/vector/zip.rb +34 -0
  354. data/examples/wavelet/ecg.dat +256 -0
  355. data/examples/wavelet/wavelet1.rb +50 -0
  356. data/ext/alf.c +206 -0
  357. data/ext/array.c +642 -0
  358. data/ext/array_complex.c +248 -0
  359. data/ext/blas.c +29 -0
  360. data/ext/blas1.c +734 -0
  361. data/ext/blas2.c +1093 -0
  362. data/ext/blas3.c +881 -0
  363. data/ext/block.c +44 -0
  364. data/ext/block_source.c +887 -0
  365. data/ext/bspline.c +130 -0
  366. data/ext/bundle.c +3 -0
  367. data/ext/cdf.c +754 -0
  368. data/ext/cheb.c +542 -0
  369. data/ext/combination.c +283 -0
  370. data/ext/common.c +325 -0
  371. data/ext/complex.c +1004 -0
  372. data/ext/const.c +673 -0
  373. data/ext/const_additional.c +120 -0
  374. data/ext/cqp.c +283 -0
  375. data/ext/deriv.c +195 -0
  376. data/ext/dht.c +361 -0
  377. data/ext/diff.c +166 -0
  378. data/ext/dirac.c +389 -0
  379. data/ext/eigen.c +2373 -0
  380. data/ext/error.c +193 -0
  381. data/ext/extconf.rb +303 -0
  382. data/ext/fcmp.c +66 -0
  383. data/ext/fft.c +1102 -0
  384. data/ext/fit.c +205 -0
  385. data/ext/fresnel.c +312 -0
  386. data/ext/function.c +524 -0
  387. data/ext/geometry.c +139 -0
  388. data/ext/graph.c +1640 -0
  389. data/ext/gsl.c +280 -0
  390. data/ext/gsl_narray.c +804 -0
  391. data/ext/histogram.c +1991 -0
  392. data/ext/histogram2d.c +1068 -0
  393. data/ext/histogram3d.c +884 -0
  394. data/ext/histogram3d_source.c +750 -0
  395. data/ext/histogram_find.c +101 -0
  396. data/ext/histogram_oper.c +159 -0
  397. data/ext/ieee.c +100 -0
  398. data/ext/integration.c +1179 -0
  399. data/ext/interp.c +512 -0
  400. data/ext/jacobi.c +739 -0
  401. data/ext/linalg.c +4042 -0
  402. data/ext/linalg_complex.c +739 -0
  403. data/ext/math.c +725 -0
  404. data/ext/matrix.c +39 -0
  405. data/ext/matrix_complex.c +1737 -0
  406. data/ext/matrix_double.c +560 -0
  407. data/ext/matrix_int.c +256 -0
  408. data/ext/matrix_source.c +2734 -0
  409. data/ext/min.c +250 -0
  410. data/ext/monte.c +992 -0
  411. data/ext/multifit.c +1871 -0
  412. data/ext/multimin.c +806 -0
  413. data/ext/multimin_fsdf.c +156 -0
  414. data/ext/multiroots.c +955 -0
  415. data/ext/multiset.c +214 -0
  416. data/ext/ndlinear.c +321 -0
  417. data/ext/nmf.c +171 -0
  418. data/ext/nmf_wrap.c +75 -0
  419. data/ext/ntuple.c +469 -0
  420. data/ext/odeiv.c +962 -0
  421. data/ext/ool.c +879 -0
  422. data/ext/oper_complex_source.c +253 -0
  423. data/ext/permutation.c +596 -0
  424. data/ext/poly.c +42 -0
  425. data/ext/poly2.c +265 -0
  426. data/ext/poly_source.c +1915 -0
  427. data/ext/qrng.c +171 -0
  428. data/ext/randist.c +1873 -0
  429. data/ext/rational.c +480 -0
  430. data/ext/rng.c +612 -0
  431. data/ext/root.c +408 -0
  432. data/ext/sf.c +1494 -0
  433. data/ext/sf_airy.c +200 -0
  434. data/ext/sf_bessel.c +871 -0
  435. data/ext/sf_clausen.c +28 -0
  436. data/ext/sf_coulomb.c +206 -0
  437. data/ext/sf_coupling.c +121 -0
  438. data/ext/sf_dawson.c +29 -0
  439. data/ext/sf_debye.c +157 -0
  440. data/ext/sf_dilog.c +43 -0
  441. data/ext/sf_elementary.c +46 -0
  442. data/ext/sf_ellint.c +206 -0
  443. data/ext/sf_elljac.c +30 -0
  444. data/ext/sf_erfc.c +93 -0
  445. data/ext/sf_exp.c +169 -0
  446. data/ext/sf_expint.c +211 -0
  447. data/ext/sf_fermi_dirac.c +148 -0
  448. data/ext/sf_gamma.c +347 -0
  449. data/ext/sf_gegenbauer.c +97 -0
  450. data/ext/sf_hyperg.c +203 -0
  451. data/ext/sf_laguerre.c +113 -0
  452. data/ext/sf_lambert.c +47 -0
  453. data/ext/sf_legendre.c +368 -0
  454. data/ext/sf_log.c +105 -0
  455. data/ext/sf_mathieu.c +238 -0
  456. data/ext/sf_power.c +47 -0
  457. data/ext/sf_psi.c +98 -0
  458. data/ext/sf_synchrotron.c +48 -0
  459. data/ext/sf_transport.c +76 -0
  460. data/ext/sf_trigonometric.c +210 -0
  461. data/ext/sf_zeta.c +119 -0
  462. data/ext/signal.c +308 -0
  463. data/ext/siman.c +717 -0
  464. data/ext/sort.c +208 -0
  465. data/ext/spline.c +395 -0
  466. data/ext/stats.c +800 -0
  467. data/ext/sum.c +168 -0
  468. data/ext/tamu_anova.c +56 -0
  469. data/ext/tensor.c +38 -0
  470. data/ext/tensor_source.c +1123 -0
  471. data/ext/vector.c +38 -0
  472. data/ext/vector_complex.c +2246 -0
  473. data/ext/vector_double.c +1438 -0
  474. data/ext/vector_int.c +204 -0
  475. data/ext/vector_source.c +3336 -0
  476. data/ext/wavelet.c +945 -0
  477. data/include/rb_gsl.h +158 -0
  478. data/include/rb_gsl_array.h +238 -0
  479. data/include/rb_gsl_cheb.h +21 -0
  480. data/include/rb_gsl_common.h +348 -0
  481. data/include/rb_gsl_complex.h +25 -0
  482. data/include/rb_gsl_config.h +62 -0
  483. data/include/rb_gsl_const.h +29 -0
  484. data/include/rb_gsl_dirac.h +13 -0
  485. data/include/rb_gsl_eigen.h +17 -0
  486. data/include/rb_gsl_fft.h +62 -0
  487. data/include/rb_gsl_fit.h +25 -0
  488. data/include/rb_gsl_function.h +27 -0
  489. data/include/rb_gsl_graph.h +70 -0
  490. data/include/rb_gsl_histogram.h +63 -0
  491. data/include/rb_gsl_histogram3d.h +97 -0
  492. data/include/rb_gsl_integration.h +17 -0
  493. data/include/rb_gsl_interp.h +46 -0
  494. data/include/rb_gsl_linalg.h +25 -0
  495. data/include/rb_gsl_math.h +26 -0
  496. data/include/rb_gsl_odeiv.h +21 -0
  497. data/include/rb_gsl_poly.h +71 -0
  498. data/include/rb_gsl_rational.h +37 -0
  499. data/include/rb_gsl_rng.h +21 -0
  500. data/include/rb_gsl_root.h +22 -0
  501. data/include/rb_gsl_sf.h +119 -0
  502. data/include/rb_gsl_statistics.h +17 -0
  503. data/include/rb_gsl_tensor.h +45 -0
  504. data/include/rb_gsl_with_narray.h +29 -0
  505. data/include/templates_off.h +87 -0
  506. data/include/templates_on.h +241 -0
  507. data/lib/gsl.rb +3 -0
  508. data/lib/gsl/gnuplot.rb +41 -0
  509. data/lib/gsl/oper.rb +68 -0
  510. data/lib/ool.rb +22 -0
  511. data/lib/ool/conmin.rb +30 -0
  512. data/lib/rbgsl.rb +3 -0
  513. data/rdoc/alf.rdoc +77 -0
  514. data/rdoc/blas.rdoc +269 -0
  515. data/rdoc/bspline.rdoc +42 -0
  516. data/rdoc/changes.rdoc +164 -0
  517. data/rdoc/cheb.rdoc +99 -0
  518. data/rdoc/cholesky_complex.rdoc +46 -0
  519. data/rdoc/combi.rdoc +125 -0
  520. data/rdoc/complex.rdoc +210 -0
  521. data/rdoc/const.rdoc +546 -0
  522. data/rdoc/dht.rdoc +122 -0
  523. data/rdoc/diff.rdoc +133 -0
  524. data/rdoc/ehandling.rdoc +50 -0
  525. data/rdoc/eigen.rdoc +401 -0
  526. data/rdoc/fft.rdoc +535 -0
  527. data/rdoc/fit.rdoc +284 -0
  528. data/rdoc/function.rdoc +94 -0
  529. data/rdoc/graph.rdoc +137 -0
  530. data/rdoc/hist.rdoc +409 -0
  531. data/rdoc/hist2d.rdoc +279 -0
  532. data/rdoc/hist3d.rdoc +112 -0
  533. data/rdoc/index.rdoc +62 -0
  534. data/rdoc/integration.rdoc +398 -0
  535. data/rdoc/interp.rdoc +231 -0
  536. data/rdoc/intro.rdoc +27 -0
  537. data/rdoc/linalg.rdoc +681 -0
  538. data/rdoc/linalg_complex.rdoc +88 -0
  539. data/rdoc/math.rdoc +276 -0
  540. data/rdoc/matrix.rdoc +1093 -0
  541. data/rdoc/min.rdoc +189 -0
  542. data/rdoc/monte.rdoc +234 -0
  543. data/rdoc/multimin.rdoc +312 -0
  544. data/rdoc/multiroot.rdoc +293 -0
  545. data/rdoc/narray.rdoc +177 -0
  546. data/rdoc/ndlinear.rdoc +250 -0
  547. data/rdoc/nonlinearfit.rdoc +348 -0
  548. data/rdoc/ntuple.rdoc +88 -0
  549. data/rdoc/odeiv.rdoc +378 -0
  550. data/rdoc/perm.rdoc +221 -0
  551. data/rdoc/poly.rdoc +335 -0
  552. data/rdoc/qrng.rdoc +90 -0
  553. data/rdoc/randist.rdoc +233 -0
  554. data/rdoc/ref.rdoc +93 -0
  555. data/rdoc/rng.rdoc +203 -0
  556. data/rdoc/rngextra.rdoc +11 -0
  557. data/rdoc/roots.rdoc +305 -0
  558. data/rdoc/screenshot.rdoc +40 -0
  559. data/rdoc/sf.rdoc +1622 -0
  560. data/rdoc/siman.rdoc +89 -0
  561. data/rdoc/sort.rdoc +94 -0
  562. data/rdoc/start.rdoc +16 -0
  563. data/rdoc/stats.rdoc +219 -0
  564. data/rdoc/sum.rdoc +65 -0
  565. data/rdoc/tensor.rdoc +251 -0
  566. data/rdoc/tut.rdoc +5 -0
  567. data/rdoc/use.rdoc +177 -0
  568. data/rdoc/vector.rdoc +1243 -0
  569. data/rdoc/vector_complex.rdoc +347 -0
  570. data/rdoc/wavelet.rdoc +218 -0
  571. data/setup.rb +1585 -0
  572. data/tests/blas/amax.rb +14 -0
  573. data/tests/blas/asum.rb +16 -0
  574. data/tests/blas/axpy.rb +25 -0
  575. data/tests/blas/copy.rb +23 -0
  576. data/tests/blas/dot.rb +23 -0
  577. data/tests/bspline.rb +53 -0
  578. data/tests/cdf.rb +1388 -0
  579. data/tests/cheb.rb +112 -0
  580. data/tests/combination.rb +123 -0
  581. data/tests/complex.rb +17 -0
  582. data/tests/const.rb +24 -0
  583. data/tests/deriv.rb +85 -0
  584. data/tests/dht/dht1.rb +17 -0
  585. data/tests/dht/dht2.rb +23 -0
  586. data/tests/dht/dht3.rb +23 -0
  587. data/tests/dht/dht4.rb +23 -0
  588. data/tests/diff.rb +78 -0
  589. data/tests/eigen/eigen.rb +220 -0
  590. data/tests/eigen/gen.rb +105 -0
  591. data/tests/eigen/genherm.rb +66 -0
  592. data/tests/eigen/gensymm.rb +68 -0
  593. data/tests/eigen/nonsymm.rb +53 -0
  594. data/tests/eigen/nonsymmv.rb +53 -0
  595. data/tests/eigen/symm-herm.rb +74 -0
  596. data/tests/err.rb +58 -0
  597. data/tests/fit.rb +124 -0
  598. data/tests/gsl_test.rb +118 -0
  599. data/tests/gsl_test2.rb +110 -0
  600. data/tests/histo.rb +12 -0
  601. data/tests/integration/integration1.rb +72 -0
  602. data/tests/integration/integration2.rb +71 -0
  603. data/tests/integration/integration3.rb +71 -0
  604. data/tests/integration/integration4.rb +71 -0
  605. data/tests/interp.rb +45 -0
  606. data/tests/linalg/HH.rb +64 -0
  607. data/tests/linalg/LU.rb +47 -0
  608. data/tests/linalg/QR.rb +77 -0
  609. data/tests/linalg/SV.rb +24 -0
  610. data/tests/linalg/TDN.rb +116 -0
  611. data/tests/linalg/TDS.rb +122 -0
  612. data/tests/linalg/bidiag.rb +73 -0
  613. data/tests/linalg/cholesky.rb +20 -0
  614. data/tests/linalg/linalg.rb +158 -0
  615. data/tests/matrix/matrix_complex_test.rb +36 -0
  616. data/tests/matrix/matrix_nmf_test.rb +39 -0
  617. data/tests/matrix/matrix_test.rb +48 -0
  618. data/tests/min.rb +99 -0
  619. data/tests/monte/miser.rb +31 -0
  620. data/tests/monte/vegas.rb +45 -0
  621. data/tests/multifit/test_2dgauss.rb +112 -0
  622. data/tests/multifit/test_brown.rb +90 -0
  623. data/tests/multifit/test_enso.rb +246 -0
  624. data/tests/multifit/test_filip.rb +155 -0
  625. data/tests/multifit/test_gauss.rb +97 -0
  626. data/tests/multifit/test_longley.rb +110 -0
  627. data/tests/multifit/test_multifit.rb +52 -0
  628. data/tests/multimin.rb +139 -0
  629. data/tests/multiroot.rb +131 -0
  630. data/tests/multiset.rb +52 -0
  631. data/tests/narray/blas_dnrm2.rb +20 -0
  632. data/tests/odeiv.rb +353 -0
  633. data/tests/poly/poly.rb +290 -0
  634. data/tests/poly/special.rb +65 -0
  635. data/tests/qrng.rb +131 -0
  636. data/tests/quartic.rb +29 -0
  637. data/tests/randist.rb +134 -0
  638. data/tests/rng.rb +305 -0
  639. data/tests/roots.rb +76 -0
  640. data/tests/run-test.sh +17 -0
  641. data/tests/sf/gsl_test_sf.rb +249 -0
  642. data/tests/sf/test_airy.rb +83 -0
  643. data/tests/sf/test_bessel.rb +306 -0
  644. data/tests/sf/test_coulomb.rb +17 -0
  645. data/tests/sf/test_dilog.rb +25 -0
  646. data/tests/sf/test_gamma.rb +209 -0
  647. data/tests/sf/test_hyperg.rb +356 -0
  648. data/tests/sf/test_legendre.rb +227 -0
  649. data/tests/sf/test_mathieu.rb +59 -0
  650. data/tests/sf/test_mode.rb +19 -0
  651. data/tests/sf/test_sf.rb +839 -0
  652. data/tests/stats.rb +174 -0
  653. data/tests/stats_mt.rb +16 -0
  654. data/tests/sum.rb +98 -0
  655. data/tests/sys.rb +323 -0
  656. data/tests/tensor.rb +419 -0
  657. data/tests/vector/vector_complex_test.rb +101 -0
  658. data/tests/vector/vector_test.rb +141 -0
  659. data/tests/wavelet.rb +142 -0
  660. metadata +789 -0
@@ -0,0 +1,408 @@
1
+ /*
2
+ root.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2004 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+
12
+ #include "rb_gsl_config.h"
13
+ #include "rb_gsl_array.h"
14
+ #include "rb_gsl_common.h"
15
+ #include "rb_gsl_function.h"
16
+ #include "rb_gsl_root.h"
17
+
18
+ EXTERN VALUE cgsl_function_fdf;
19
+
20
+ enum {
21
+ GSL_ROOT_FSOLVER_BISECTION,
22
+ GSL_ROOT_FSOLVER_FALSEPOS,
23
+ GSL_ROOT_FSOLVER_BRENT,
24
+ GSL_ROOT_FDFSOLVER_NEWTON,
25
+ GSL_ROOT_FDFSOLVER_SECANT,
26
+ GSL_ROOT_FDFSOLVER_STEFFENSON,
27
+ };
28
+
29
+ /*****/
30
+
31
+ static VALUE rb_gsl_fsolver_new(VALUE klass, VALUE t)
32
+ {
33
+ gsl_root_fsolver *s = NULL;
34
+ const gsl_root_fsolver_type *T;
35
+ char name[32];
36
+ switch (TYPE(t)) {
37
+ case T_STRING:
38
+ strcpy(name, STR2CSTR(t));
39
+ if (!str_tail_grep(name, "bisection")) {
40
+ T = gsl_root_fsolver_bisection;
41
+ } else if (!str_tail_grep(name, "falsepos")) {
42
+ T = gsl_root_fsolver_falsepos;
43
+ } else if (!str_tail_grep(name, "brent")) {
44
+ T = gsl_root_fsolver_brent;
45
+ } else {
46
+ rb_raise(rb_eTypeError,
47
+ "type must be \"bisection\" or \"falsepos\", or \"brent\".");
48
+ }
49
+ break;
50
+ case T_FIXNUM:
51
+ switch (FIX2INT(t)) {
52
+ case GSL_ROOT_FSOLVER_BISECTION:
53
+ T = gsl_root_fsolver_bisection;
54
+ break;
55
+ case GSL_ROOT_FSOLVER_FALSEPOS:
56
+ T = gsl_root_fsolver_falsepos;
57
+ break;
58
+ case GSL_ROOT_FSOLVER_BRENT:
59
+ T = gsl_root_fsolver_brent;
60
+ break;
61
+ default:
62
+ rb_raise(rb_eTypeError, "type must be BISECTION or FALSEPOS, or BRENT.");
63
+ break;
64
+ }
65
+ break;
66
+ default:
67
+ rb_raise(rb_eTypeError, "wrong argument type %s (String or Fixnum expected)",
68
+ rb_class2name(CLASS_OF(t)));
69
+ break;
70
+ }
71
+ s = gsl_root_fsolver_alloc(T);
72
+ return Data_Wrap_Struct(klass, 0, gsl_root_fsolver_free, s);
73
+ }
74
+
75
+ static VALUE rb_gsl_fsolver_set(VALUE obj, VALUE func, VALUE xl, VALUE xh)
76
+ {
77
+ gsl_root_fsolver *s = NULL;
78
+ gsl_function *fff = NULL;
79
+ double xlow, xup;
80
+ Need_Float(xl); Need_Float(xh);
81
+ CHECK_FUNCTION(func);
82
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
83
+ Data_Get_Struct(func, gsl_function, fff);
84
+ xlow = NUM2DBL(xl);
85
+ xup = NUM2DBL(xh);
86
+ gsl_root_fsolver_set(s, fff, xlow, xup);
87
+ return obj;
88
+ }
89
+
90
+ static VALUE rb_gsl_fsolver_iterate(VALUE obj)
91
+ {
92
+ gsl_root_fsolver *s = NULL;
93
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
94
+ return INT2FIX(gsl_root_fsolver_iterate(s));
95
+ }
96
+
97
+ static VALUE rb_gsl_fsolver_root(VALUE obj)
98
+ {
99
+ gsl_root_fsolver *s = NULL;
100
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
101
+ return rb_float_new(gsl_root_fsolver_root(s));
102
+ }
103
+
104
+ static VALUE rb_gsl_fsolver_x_lower(VALUE obj)
105
+ {
106
+ gsl_root_fsolver *s = NULL;
107
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
108
+ return rb_float_new(gsl_root_fsolver_x_lower(s));
109
+ }
110
+
111
+ static VALUE rb_gsl_fsolver_x_upper(VALUE obj)
112
+ {
113
+ gsl_root_fsolver *s = NULL;
114
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
115
+ return rb_float_new(gsl_root_fsolver_x_upper(s));
116
+ }
117
+
118
+ static VALUE rb_gsl_fsolver_name(VALUE obj)
119
+ {
120
+ gsl_root_fsolver *s = NULL;
121
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
122
+ return rb_str_new2(gsl_root_fsolver_name(s));
123
+ }
124
+
125
+ static VALUE rb_gsl_fsolver_test_interval(VALUE obj, VALUE eabs, VALUE erel)
126
+ {
127
+ gsl_root_fsolver *s = NULL;
128
+ Need_Float(eabs); Need_Float(erel);
129
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
130
+ return INT2FIX(gsl_root_test_interval(s->x_lower, s->x_upper,
131
+ NUM2DBL(eabs), NUM2DBL(erel)));
132
+ }
133
+
134
+ static VALUE rb_gsl_root_test_interval(VALUE obj, VALUE xl, VALUE xu, VALUE eabs,
135
+ VALUE erel)
136
+ {
137
+ Need_Float(xl); Need_Float(xu);
138
+ Need_Float(eabs); Need_Float(erel);
139
+ return INT2FIX(gsl_root_test_interval(NUM2DBL(xl), NUM2DBL(xu),
140
+ NUM2DBL(eabs), NUM2DBL(erel)));
141
+ }
142
+
143
+ static VALUE rb_gsl_root_test_delta(VALUE obj, VALUE xl, VALUE xu, VALUE eabs,
144
+ VALUE erel)
145
+ {
146
+ Need_Float(xl); Need_Float(xu);
147
+ Need_Float(eabs); Need_Float(erel);
148
+ return INT2FIX(gsl_root_test_delta(NUM2DBL(xl), NUM2DBL(xu),
149
+ NUM2DBL(eabs), NUM2DBL(erel)));
150
+ }
151
+
152
+ static VALUE rb_gsl_root_test_residual(VALUE obj, VALUE xl,VALUE eabs)
153
+ {
154
+ Need_Float(xl); Need_Float(eabs);
155
+ return INT2FIX(gsl_root_test_residual(NUM2DBL(xl), NUM2DBL(eabs)));
156
+ }
157
+
158
+ static VALUE rb_gsl_fsolver_solve(int argc, VALUE *argv, VALUE *obj)
159
+ {
160
+ gsl_root_fsolver *s = NULL;
161
+ gsl_function *F = NULL;
162
+ double x, xl, xh, epsabs = 0.0, epsrel = 1e-6;
163
+ int status, iter = 0, max_iter = 100;
164
+ switch (argc) {
165
+ case 3:
166
+ Check_Type(argv[2], T_ARRAY);
167
+ epsabs = NUM2DBL(rb_ary_entry(argv[2], 0));
168
+ epsrel = NUM2DBL(rb_ary_entry(argv[2], 1));
169
+ /* no break */
170
+ case 2:
171
+ Check_Type(argv[1], T_ARRAY);
172
+ xl = NUM2DBL(rb_ary_entry(argv[1], 0));
173
+ xh = NUM2DBL(rb_ary_entry(argv[1], 1));
174
+ break;
175
+ default:
176
+ rb_raise(rb_eArgError,
177
+ "Usage: solve(f = Function, range = Array, eps = Array)");
178
+ break;
179
+ }
180
+ CHECK_FUNCTION(argv[0]);
181
+ Data_Get_Struct(argv[0], gsl_function, F);
182
+ Data_Get_Struct(obj, gsl_root_fsolver, s);
183
+ gsl_root_fsolver_set(s, F, xl, xh);
184
+ do {
185
+ iter++;
186
+ status = gsl_root_fsolver_iterate (s);
187
+ x = gsl_root_fsolver_root (s);
188
+ xl = gsl_root_fsolver_x_lower (s);
189
+ xh = gsl_root_fsolver_x_upper (s);
190
+ status = gsl_root_test_interval (xl, xh, epsabs, epsrel);
191
+ if (status == GSL_SUCCESS) break;
192
+ } while (status == GSL_CONTINUE && iter < max_iter);
193
+ return rb_ary_new3(3, rb_float_new(x), INT2FIX(iter), INT2FIX(status));
194
+ }
195
+
196
+ static VALUE rb_gsl_fdfsolver_new(VALUE klass, VALUE t)
197
+ {
198
+ gsl_root_fdfsolver *s = NULL;
199
+ const gsl_root_fdfsolver_type *T;
200
+ char name[32];
201
+ switch (TYPE(t)) {
202
+ case T_STRING:
203
+ strcpy(name, STR2CSTR(t));
204
+ if (!str_tail_grep(name, "newton")) {
205
+ T = gsl_root_fdfsolver_newton;
206
+ } else if (!str_tail_grep(name, "secant")) {
207
+ T = gsl_root_fdfsolver_secant;
208
+ } else if (!str_tail_grep(name, "steffenson")) {
209
+ T = gsl_root_fdfsolver_steffenson;
210
+ } else {
211
+ rb_raise(rb_eTypeError, "type must be NEWTON or SECANT, or STEFFENSON.");
212
+ }
213
+ break;
214
+ case T_FIXNUM:
215
+ switch (FIX2INT(t)) {
216
+ case GSL_ROOT_FDFSOLVER_NEWTON:
217
+ T = gsl_root_fdfsolver_newton;
218
+ break;
219
+ case GSL_ROOT_FDFSOLVER_SECANT:
220
+ T = gsl_root_fdfsolver_secant;
221
+ break;
222
+ case GSL_ROOT_FDFSOLVER_STEFFENSON:
223
+ T = gsl_root_fdfsolver_steffenson;
224
+ break;
225
+ default:
226
+ rb_raise(rb_eTypeError, "type must be NEWTON or SECANT, or STEFFENSON.");
227
+ break;
228
+ }
229
+ break;
230
+ default:
231
+ rb_raise(rb_eTypeError, "wrong argument type %s (String or Fixnum expected)",
232
+ rb_class2name(CLASS_OF(t)));
233
+ break;
234
+ }
235
+ s = gsl_root_fdfsolver_alloc(T);
236
+ return Data_Wrap_Struct(klass, 0, gsl_root_fdfsolver_free, s);
237
+ }
238
+
239
+ static VALUE rb_gsl_fdfsolver_set(VALUE obj, VALUE func, VALUE r)
240
+ {
241
+ gsl_root_fdfsolver *s = NULL;
242
+ gsl_function_fdf *fff = NULL;
243
+ double root;
244
+ CHECK_FUNCTION_FDF(func);
245
+ Data_Get_Struct(obj, gsl_root_fdfsolver, s);
246
+ Data_Get_Struct(func, gsl_function_fdf, fff);
247
+ root = NUM2DBL(r);
248
+ gsl_root_fdfsolver_set(s, fff, root);
249
+ return obj;
250
+ }
251
+
252
+ static VALUE rb_gsl_fdfsolver_iterate(VALUE obj)
253
+ {
254
+ gsl_root_fdfsolver *s = NULL;
255
+ Data_Get_Struct(obj, gsl_root_fdfsolver, s);
256
+ return INT2FIX(gsl_root_fdfsolver_iterate(s));
257
+ }
258
+
259
+ static VALUE rb_gsl_fdfsolver_root(VALUE obj)
260
+ {
261
+ gsl_root_fdfsolver *s = NULL;
262
+ Data_Get_Struct(obj, gsl_root_fdfsolver, s);
263
+ return rb_float_new(gsl_root_fdfsolver_root(s));
264
+ }
265
+
266
+ static VALUE rb_gsl_fdfsolver_name(VALUE obj)
267
+ {
268
+ gsl_root_fdfsolver *s = NULL;
269
+ Data_Get_Struct(obj, gsl_root_fdfsolver, s);
270
+ return rb_str_new2(gsl_root_fdfsolver_name(s));
271
+ }
272
+
273
+ static VALUE rb_gsl_fdfsolver_solve(int argc, VALUE *argv, VALUE *obj)
274
+ {
275
+ gsl_root_fdfsolver *s = NULL;
276
+ double x = 0.0, x0, epsabs = 0.0, epsrel = 1e-6;
277
+ gsl_function_fdf *F = NULL;
278
+ int status, iter = 0, max_iter = 100;
279
+ switch (argc) {
280
+ case 3:
281
+ Check_Type(argv[2], T_ARRAY);
282
+ epsabs = NUM2DBL(rb_ary_entry(argv[2], 0));
283
+ epsrel = NUM2DBL(rb_ary_entry(argv[2], 1));
284
+ /* no break */
285
+ case 2:
286
+ Need_Float(argv[1]);
287
+ x0 = NUM2DBL(argv[1]);
288
+ break;
289
+ default:
290
+ rb_raise(rb_eArgError, "Usage: solve(f = Function, range = Array, eps = Array)");
291
+ break;
292
+ }
293
+ CHECK_FUNCTION_FDF(argv[0]);
294
+ Data_Get_Struct(argv[0], gsl_function_fdf, F);
295
+ Data_Get_Struct(obj, gsl_root_fdfsolver, s);
296
+ gsl_root_fdfsolver_set(s, F, x0);
297
+ do {
298
+ iter++;
299
+ status = gsl_root_fdfsolver_iterate (s);
300
+ x0 = x;
301
+ x = gsl_root_fdfsolver_root (s);
302
+ status = gsl_root_test_delta(x, x0, epsabs, epsrel);
303
+ if (status == GSL_SUCCESS) break;
304
+ } while (status == GSL_CONTINUE && iter < max_iter);
305
+ return rb_ary_new3(3, rb_float_new(x), INT2FIX(iter), INT2FIX(status));
306
+ }
307
+
308
+ static VALUE rb_gsl_function_rootfinder(int argc, VALUE *argv, VALUE obj)
309
+ {
310
+ int status, iter = 0, max_iter = 1000;
311
+ const gsl_root_fsolver_type *T;
312
+ gsl_root_fsolver *s = NULL;
313
+ gsl_function *F = NULL;
314
+ double r, a, b, epsabs = 0.0, epsrel = 1e-6;
315
+ Data_Get_Struct(obj, gsl_function, F);
316
+ switch (argc) {
317
+ case 2:
318
+ a = NUM2DBL(argv[0]);
319
+ b = NUM2DBL(argv[1]);
320
+ break;
321
+ case 1:
322
+ switch (TYPE(argv[0])) {
323
+ case T_ARRAY:
324
+ a = NUM2DBL(rb_ary_entry(argv[0], 0));
325
+ b = NUM2DBL(rb_ary_entry(argv[0], 1));
326
+ break;
327
+ default:
328
+ rb_raise(rb_eTypeError, "interval must be given by an array [a, b]");
329
+ }
330
+ break;
331
+ default:
332
+ rb_raise(rb_eArgError, "interval must be given");
333
+ break;
334
+ }
335
+ T = gsl_root_fsolver_brent;
336
+ s = gsl_root_fsolver_alloc (T);
337
+ gsl_root_fsolver_set (s, F, a, b);
338
+ do {
339
+ iter++;
340
+ status = gsl_root_fsolver_iterate (s);
341
+ r = gsl_root_fsolver_root (s);
342
+ a = gsl_root_fsolver_x_lower (s);
343
+ b = gsl_root_fsolver_x_upper (s);
344
+ status = gsl_root_test_interval (a, b, epsabs, epsrel);
345
+ if (status == GSL_SUCCESS) break;
346
+ } while (status == GSL_CONTINUE && iter < max_iter);
347
+ gsl_root_fsolver_free(s);
348
+ if (status == GSL_SUCCESS) {
349
+ return rb_ary_new3(3, rb_float_new(r), INT2FIX(iter), INT2FIX(status));
350
+ } else {
351
+ printf("not converged\n");
352
+ return Qfalse;
353
+ }
354
+ }
355
+
356
+ void Init_gsl_root(VALUE module)
357
+ {
358
+ VALUE mgsl_root;
359
+ VALUE cgsl_fsolver;
360
+ VALUE cgsl_fdfsolver;
361
+
362
+ mgsl_root = rb_define_module_under(module, "Root");
363
+
364
+ cgsl_fsolver = rb_define_class_under(mgsl_root, "FSolver", cGSL_Object);
365
+ rb_define_singleton_method(cgsl_fsolver, "alloc", rb_gsl_fsolver_new, 1);
366
+
367
+ rb_define_method(cgsl_fsolver, "set", rb_gsl_fsolver_set, 3);
368
+ rb_define_method(cgsl_fsolver, "iterate", rb_gsl_fsolver_iterate, 0);
369
+ rb_define_method(cgsl_fsolver, "root", rb_gsl_fsolver_root, 0);
370
+ rb_define_method(cgsl_fsolver, "name", rb_gsl_fsolver_name, 0);
371
+ rb_define_method(cgsl_fsolver, "x_lower", rb_gsl_fsolver_x_lower, 0);
372
+ rb_define_method(cgsl_fsolver, "x_upper", rb_gsl_fsolver_x_upper, 0);
373
+ rb_define_method(cgsl_fsolver, "test_interval", rb_gsl_fsolver_test_interval, 2);
374
+ rb_define_method(cgsl_fsolver, "solve", rb_gsl_fsolver_solve, -1);
375
+
376
+ rb_define_singleton_method(mgsl_root, "test_interval",
377
+ rb_gsl_root_test_interval, 4);
378
+ rb_define_singleton_method(mgsl_root, "test_delta",
379
+ rb_gsl_root_test_delta, 4);
380
+ rb_define_singleton_method(mgsl_root, "test_residual",
381
+ rb_gsl_root_test_residual, 2);
382
+
383
+ cgsl_fdfsolver = rb_define_class_under(mgsl_root, "FdfSolver", cGSL_Object);
384
+ rb_define_singleton_method(cgsl_fdfsolver, "alloc", rb_gsl_fdfsolver_new, 1);
385
+
386
+ rb_define_method(cgsl_fdfsolver, "set", rb_gsl_fdfsolver_set, 2);
387
+ rb_define_method(cgsl_fdfsolver, "iterate", rb_gsl_fdfsolver_iterate, 0);
388
+ rb_define_method(cgsl_fdfsolver, "root", rb_gsl_fdfsolver_root, 0);
389
+ rb_define_method(cgsl_fdfsolver, "name", rb_gsl_fdfsolver_name, 0);
390
+ rb_define_method(cgsl_fdfsolver, "solve", rb_gsl_fdfsolver_solve, -1);
391
+
392
+ rb_define_method(cgsl_function, "fsolve", rb_gsl_function_rootfinder, -1);
393
+ rb_define_alias(cgsl_function, "solve", "fsolve");
394
+
395
+ rb_define_const(cgsl_fsolver, "BISECTION", INT2FIX(GSL_ROOT_FSOLVER_BISECTION));
396
+ rb_define_const(cgsl_fsolver, "FALSEPOS", INT2FIX(GSL_ROOT_FSOLVER_FALSEPOS));
397
+ rb_define_const(cgsl_fsolver, "BRENT", INT2FIX(GSL_ROOT_FSOLVER_BRENT));
398
+ rb_define_const(cgsl_fsolver, "Bisection", INT2FIX(GSL_ROOT_FSOLVER_BISECTION));
399
+ rb_define_const(cgsl_fsolver, "Falsepos", INT2FIX(GSL_ROOT_FSOLVER_FALSEPOS));
400
+ rb_define_const(cgsl_fsolver, "Brent", INT2FIX(GSL_ROOT_FSOLVER_BRENT));
401
+
402
+ rb_define_const(cgsl_fdfsolver, "NEWTON", INT2FIX(GSL_ROOT_FDFSOLVER_NEWTON));
403
+ rb_define_const(cgsl_fdfsolver, "SECANT", INT2FIX(GSL_ROOT_FDFSOLVER_SECANT));
404
+ rb_define_const(cgsl_fdfsolver, "STEFFENSON", INT2FIX(GSL_ROOT_FDFSOLVER_STEFFENSON));
405
+ rb_define_const(cgsl_fdfsolver, "Newton", INT2FIX(GSL_ROOT_FDFSOLVER_NEWTON));
406
+ rb_define_const(cgsl_fdfsolver, "Secant", INT2FIX(GSL_ROOT_FDFSOLVER_SECANT));
407
+ rb_define_const(cgsl_fdfsolver, "Steffenson", INT2FIX(GSL_ROOT_FDFSOLVER_STEFFENSON));
408
+ }
@@ -0,0 +1,1494 @@
1
+ /*
2
+ sf.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; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
+ */
12
+
13
+ #include "rb_gsl_array.h"
14
+ #include "rb_gsl_sf.h"
15
+ #ifdef HAVE_NARRAY_H
16
+ #include "narray.h"
17
+ #endif
18
+
19
+ VALUE cgsl_sf_result, cgsl_sf_result_e10;
20
+
21
+ VALUE rb_gsl_sf_result_new(VALUE klass)
22
+ {
23
+ gsl_sf_result *rslt = NULL;
24
+ return Data_Make_Struct(klass, gsl_sf_result, 0, free, rslt);
25
+ }
26
+
27
+ static VALUE rb_gsl_sf_result_print(VALUE obj)
28
+ {
29
+ gsl_sf_result *rslt = NULL;
30
+ Data_Get_Struct(obj, gsl_sf_result, rslt);
31
+ printf("%10.9e %10.9e\n", rslt->val, rslt->err);
32
+ return obj;
33
+ }
34
+
35
+ static VALUE rb_gsl_sf_result_to_s(VALUE obj);
36
+
37
+ static VALUE rb_gsl_sf_result_inspect(VALUE obj)
38
+ {
39
+ char buf[64];
40
+ VALUE str;
41
+ sprintf(buf, "%s\n", rb_class2name(CLASS_OF(obj)));
42
+ str = rb_str_new2(buf);
43
+ return rb_str_concat(str, rb_gsl_sf_result_to_s(obj));
44
+ }
45
+
46
+ static VALUE rb_gsl_sf_result_val(VALUE obj)
47
+ {
48
+ gsl_sf_result *rslt = NULL;
49
+ Data_Get_Struct(obj, gsl_sf_result, rslt);
50
+ return rb_float_new(rslt->val);
51
+ }
52
+
53
+ static VALUE rb_gsl_sf_result_err(VALUE obj)
54
+ {
55
+ gsl_sf_result *rslt = NULL;
56
+ Data_Get_Struct(obj, gsl_sf_result, rslt);
57
+ return rb_float_new(rslt->err);
58
+ }
59
+
60
+ static VALUE rb_gsl_sf_result_to_a(VALUE obj)
61
+ {
62
+ gsl_sf_result *rslt = NULL;
63
+ Data_Get_Struct(obj, gsl_sf_result, rslt);
64
+ return rb_ary_new3(2, rb_float_new(rslt->val), rb_float_new(rslt->err));
65
+ }
66
+
67
+ static VALUE rb_gsl_sf_result_to_s(VALUE obj)
68
+ {
69
+ gsl_sf_result *rslt = NULL;
70
+ char str[32];
71
+ Data_Get_Struct(obj, gsl_sf_result, rslt);
72
+ sprintf(str, "%10.9e %10.9e", rslt->val, rslt->err);
73
+ return rb_str_new2(str);
74
+ }
75
+
76
+ static VALUE rb_gsl_sf_result_e10_new(VALUE klass)
77
+ {
78
+ gsl_sf_result_e10 *rslt = NULL;
79
+ return Data_Make_Struct(cgsl_sf_result, gsl_sf_result_e10, 0, free, rslt);
80
+ }
81
+
82
+ static VALUE rb_gsl_sf_result_e10_val(VALUE obj)
83
+ {
84
+ gsl_sf_result_e10 *rslt = NULL;
85
+ Data_Get_Struct(obj, gsl_sf_result_e10, rslt);
86
+ return rb_float_new(rslt->val);
87
+ }
88
+
89
+ static VALUE rb_gsl_sf_result_e10_err(VALUE obj)
90
+ {
91
+ gsl_sf_result_e10 *rslt = NULL;
92
+ Data_Get_Struct(obj, gsl_sf_result_e10, rslt);
93
+ return rb_float_new(rslt->err);
94
+ }
95
+
96
+ static VALUE rb_gsl_sf_result_e10_e10(VALUE obj)
97
+ {
98
+ gsl_sf_result_e10 *rslt = NULL;
99
+ Data_Get_Struct(obj, gsl_sf_result_e10, rslt);
100
+ return INT2FIX(rslt->e10);
101
+ }
102
+
103
+ static VALUE rb_gsl_sf_result_e10_to_a(VALUE obj)
104
+ {
105
+ gsl_sf_result_e10 *rslt = NULL;
106
+ Data_Get_Struct(obj, gsl_sf_result_e10, rslt);
107
+ return rb_ary_new3(2, rb_float_new(rslt->val), rb_float_new(rslt->err));
108
+ }
109
+
110
+ static VALUE rb_gsl_sf_result_e10_to_s(VALUE obj)
111
+ {
112
+ gsl_sf_result_e10 *rslt = NULL;
113
+ char str[32];
114
+ Data_Get_Struct(obj, gsl_sf_result_e10, rslt);
115
+ sprintf(str, "%10.9e %10.9e\n", rslt->val, rslt->err);
116
+ return rb_str_new2(str);
117
+ }
118
+
119
+ VALUE rb_gsl_sf_eval1(double (*func)(double), VALUE argv)
120
+ {
121
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
122
+ switch (TYPE(argv)) {
123
+ case T_FLOAT:
124
+ case T_FIXNUM:
125
+ case T_BIGNUM:
126
+ return rb_float_new((*func)(NUM2DBL(argv)));
127
+ break;
128
+ case T_ARRAY:
129
+ return rb_gsl_ary_eval1(argv, func);
130
+ break;
131
+ default:
132
+ #ifdef HAVE_NARRAY_H
133
+ if (NA_IsNArray(argv)) {
134
+ return rb_gsl_nary_eval1(argv, func);
135
+ }
136
+ #endif
137
+ if (MATRIX_P(argv)) {
138
+ return matrix_eval_create(argv, func);
139
+ } else if (VECTOR_P(argv)) {
140
+ return vector_eval_create(argv, func);
141
+ } else if (COMPLEX_P(argv) || VECTOR_COMPLEX_P(argv) || MATRIX_COMPLEX_P(argv)) {
142
+ return rb_gsl_sf_eval_complex(func, argv);
143
+ } else {
144
+ rb_raise(rb_eTypeError, "wrong argument type %s", rb_class2name(CLASS_OF(argv)));
145
+ }
146
+ break;
147
+ }
148
+ }
149
+
150
+ VALUE rb_gsl_sf_eval_int_double(double (*func)(int, double), VALUE jj, VALUE argv)
151
+ {
152
+ gsl_vector *v = NULL, *vnew = NULL;
153
+ gsl_matrix *m = NULL, *mnew = NULL;
154
+ VALUE ary, xx;
155
+ size_t i, j, k, n;
156
+ double val;
157
+ #ifdef HAVE_NARRAY_H
158
+ double *ptr1, *ptr2;
159
+ struct NARRAY *na;
160
+ #endif
161
+ CHECK_FIXNUM(jj);
162
+ j = FIX2INT(jj);
163
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
164
+ switch (TYPE(argv)) {
165
+ case T_FLOAT:
166
+ case T_FIXNUM:
167
+ case T_BIGNUM:
168
+ return rb_float_new((*func)(j, NUM2DBL(argv)));
169
+ break;
170
+ case T_ARRAY:
171
+ n = RARRAY_LEN(argv);
172
+ ary = rb_ary_new2(n);
173
+ for (i = 0; i < n; i++) {
174
+ xx = rb_ary_entry(argv, i);
175
+ Need_Float(xx);
176
+ val = (*func)(j, NUM2DBL(xx));
177
+ rb_ary_store(ary, i, rb_float_new(val));
178
+ }
179
+ return ary;
180
+ break;
181
+ default:
182
+ #ifdef HAVE_NARRAY_H
183
+ if (NA_IsNArray(argv)) {
184
+ argv = na_change_type(argv, NA_DFLOAT);
185
+ ptr1 = NA_PTR_TYPE(argv, double*);
186
+ GetNArray(argv, na);
187
+ n = na->total;
188
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
189
+ ptr2 = NA_PTR_TYPE(ary, double*);
190
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(j, ptr1[i]);
191
+ return ary;
192
+ }
193
+ #endif
194
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
195
+ Data_Get_Struct(argv, gsl_matrix, m);
196
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
197
+ for (i = 0; i < m->size1; i++) {
198
+ for (k = 0; k < m->size2; k++) {
199
+ val = (*func)(j, gsl_matrix_get(m, i, k));
200
+ gsl_matrix_set(mnew, i, k, val);
201
+ }
202
+ }
203
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
204
+ } else {
205
+ CHECK_VECTOR(argv);
206
+ Data_Get_Struct(argv, gsl_vector, v);
207
+ n = v->size;
208
+ vnew = gsl_vector_alloc(n);
209
+ for (i = 0; i < n; i++) {
210
+ val = (*func)(j, gsl_vector_get(v, i));
211
+ gsl_vector_set(vnew, i, val);
212
+ }
213
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
214
+ }
215
+ break;
216
+ }
217
+ }
218
+
219
+ VALUE rb_gsl_sf_eval_double_int(double (*func)(double, int), VALUE argv, VALUE jj)
220
+ {
221
+ gsl_vector *v = NULL, *vnew = NULL;
222
+ gsl_matrix *m = NULL, *mnew = NULL;
223
+ VALUE ary, xx;
224
+ size_t i, j, k, n;
225
+ double val;
226
+ #ifdef HAVE_NARRAY_H
227
+ double *ptr1, *ptr2;
228
+ struct NARRAY *na;
229
+ #endif
230
+ CHECK_FIXNUM(jj);
231
+ j = FIX2INT(jj);
232
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
233
+ switch (TYPE(argv)) {
234
+ case T_FLOAT:
235
+ case T_FIXNUM:
236
+ case T_BIGNUM:
237
+ return rb_float_new((*func)(NUM2DBL(argv), j));
238
+ break;
239
+ case T_ARRAY:
240
+ n = RARRAY_LEN(argv);
241
+ ary = rb_ary_new2(n);
242
+ for (i = 0; i < n; i++) {
243
+ xx = rb_ary_entry(argv, i);
244
+ Need_Float(xx);
245
+ val = (*func)(NUM2DBL(xx), j);
246
+ rb_ary_store(ary, i, rb_float_new(val));
247
+ }
248
+ return ary;
249
+ break;
250
+ default:
251
+ #ifdef HAVE_NARRAY_H
252
+ if (NA_IsNArray(argv)) {
253
+ argv = na_change_type(argv, NA_DFLOAT);
254
+ ptr1 = NA_PTR_TYPE(argv, double*);
255
+ GetNArray(argv, na);
256
+ n = na->total;
257
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
258
+ ptr2 = NA_PTR_TYPE(ary, double*);
259
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(ptr1[i], j);
260
+ return ary;
261
+ }
262
+ #endif
263
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
264
+ Data_Get_Struct(argv, gsl_matrix, m);
265
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
266
+ for (i = 0; i < m->size1; i++) {
267
+ for (k = 0; k < m->size2; k++) {
268
+ val = (*func)(gsl_matrix_get(m, i, k), j);
269
+ gsl_matrix_set(mnew, i, k, val);
270
+ }
271
+ }
272
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
273
+ } else {
274
+ CHECK_VECTOR(argv);
275
+ Data_Get_Struct(argv, gsl_vector, v);
276
+ n = v->size;
277
+ vnew = gsl_vector_alloc(n);
278
+ for (i = 0; i < n; i++) {
279
+ val = (*func)(gsl_vector_get(v, i), j);
280
+ gsl_vector_set(vnew, i, val);
281
+ }
282
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
283
+ }
284
+ break;
285
+ }
286
+ return Qnil;
287
+ }
288
+
289
+ VALUE rb_gsl_sf_eval_int_int_double(double (*func)(int, int, double), VALUE jj,
290
+ VALUE jj2, VALUE argv)
291
+ {
292
+ gsl_vector *v = NULL, *vnew = NULL;
293
+ gsl_matrix *m = NULL, *mnew = NULL;
294
+ VALUE ary, xx;
295
+ size_t i, j, k, j2, n;
296
+ double val;
297
+ #ifdef HAVE_NARRAY_H
298
+ double *ptr1, *ptr2;
299
+ struct NARRAY *na;
300
+ #endif
301
+ CHECK_FIXNUM(jj); CHECK_FIXNUM(jj2);
302
+ j = FIX2INT(jj);
303
+ j2 = FIX2INT(jj2);
304
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
305
+ switch (TYPE(argv)) {
306
+ case T_FLOAT:
307
+ case T_FIXNUM:
308
+ case T_BIGNUM:
309
+ return rb_float_new((*func)(j, j2, NUM2DBL(argv)));
310
+ break;
311
+ case T_ARRAY:
312
+ n = RARRAY_LEN(argv);
313
+ ary = rb_ary_new2(n);
314
+ for (i = 0; i < n; i++) {
315
+ xx = rb_ary_entry(argv, i);
316
+ Need_Float(xx);
317
+ val = (*func)(j, j2, NUM2DBL(xx));
318
+ rb_ary_store(ary, i, rb_float_new(val));
319
+ }
320
+ return ary;
321
+ break;
322
+ default:
323
+ #ifdef HAVE_NARRAY_H
324
+ if (NA_IsNArray(argv)) {
325
+ argv = na_change_type(argv, NA_DFLOAT);
326
+ ptr1 = NA_PTR_TYPE(argv, double*);
327
+ GetNArray(argv, na);
328
+ n = na->total;
329
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
330
+ ptr2 = NA_PTR_TYPE(ary, double*);
331
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(j, j2, ptr1[i]);
332
+ return ary;
333
+ }
334
+ #endif
335
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
336
+ Data_Get_Struct(argv, gsl_matrix, m);
337
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
338
+ for (i = 0; i < m->size1; i++) {
339
+ for (k = 0; k < m->size2; k++) {
340
+ val = (*func)(j, j2, gsl_matrix_get(m, i, k));
341
+ gsl_matrix_set(mnew, i, k, val);
342
+ }
343
+ }
344
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
345
+ } else {
346
+ CHECK_VECTOR(argv);
347
+ Data_Get_Struct(argv, gsl_vector, v);
348
+ n = v->size;
349
+ vnew = gsl_vector_alloc(n);
350
+ for (i = 0; i < n; i++) {
351
+ val = (*func)(j, j2, gsl_vector_get(v, i));
352
+ gsl_vector_set(vnew, i, val);
353
+ }
354
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
355
+ }
356
+ break;
357
+ }
358
+ }
359
+
360
+ VALUE rb_gsl_sf_eval_int_double_double(double (*func)(int, double, double), VALUE jj,
361
+ VALUE ff, VALUE argv)
362
+ {
363
+ gsl_vector *v = NULL, *vnew = NULL;
364
+ gsl_matrix *m = NULL, *mnew = NULL;
365
+ VALUE ary, xx;
366
+ size_t i, j, k, n;
367
+ double f, val;
368
+ #ifdef HAVE_NARRAY_H
369
+ double *ptr1, *ptr2;
370
+ struct NARRAY *na;
371
+ #endif
372
+ CHECK_FIXNUM(jj);
373
+ Need_Float(ff);
374
+ j = FIX2INT(jj);
375
+ f = NUM2DBL(ff);
376
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
377
+ switch (TYPE(argv)) {
378
+ case T_FLOAT:
379
+ case T_FIXNUM:
380
+ case T_BIGNUM:
381
+ return rb_float_new((*func)(j, f, NUM2DBL(argv)));
382
+ break;
383
+ case T_ARRAY:
384
+ n = RARRAY_LEN(argv);
385
+ ary = rb_ary_new2(n);
386
+ for (i = 0; i < n; i++) {
387
+ xx = rb_ary_entry(argv, i);
388
+ Need_Float(xx);
389
+ val = (*func)(j, f, NUM2DBL(xx));
390
+ rb_ary_store(ary, i, rb_float_new(val));
391
+ }
392
+ return ary;
393
+ break;
394
+ default:
395
+ #ifdef HAVE_NARRAY_H
396
+ if (NA_IsNArray(argv)) {
397
+ argv = na_change_type(argv, NA_DFLOAT);
398
+ ptr1 = NA_PTR_TYPE(argv, double*);
399
+ GetNArray(argv, na);
400
+ n = na->total;
401
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
402
+ ptr2 = NA_PTR_TYPE(ary, double*);
403
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(j, f, ptr1[i]);
404
+ return ary;
405
+ }
406
+ #endif
407
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
408
+ Data_Get_Struct(argv, gsl_matrix, m);
409
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
410
+ for (i = 0; i < m->size1; i++) {
411
+ for (k = 0; k < m->size2; k++) {
412
+ val = (*func)(j, f, gsl_matrix_get(m, i, k));
413
+ gsl_matrix_set(mnew, i, k, val);
414
+ }
415
+ }
416
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
417
+ } else {
418
+ CHECK_VECTOR(argv);
419
+ Data_Get_Struct(argv, gsl_vector, v);
420
+ n = v->size;
421
+ vnew = gsl_vector_alloc(n);
422
+ for (i = 0; i < n; i++) {
423
+ val = (*func)(j, f, gsl_vector_get(v, i));
424
+ gsl_vector_set(vnew, i, val);
425
+ }
426
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
427
+ }
428
+ break;
429
+ }
430
+ }
431
+
432
+ VALUE rb_gsl_sf_eval_double_double(double (*func)(double, double), VALUE ff, VALUE argv)
433
+ {
434
+ gsl_vector *v = NULL, *vnew = NULL;
435
+ gsl_matrix *m = NULL, *mnew = NULL;
436
+ VALUE ary, xx;
437
+ size_t i, k, n;
438
+ double val, f;
439
+ #ifdef HAVE_NARRAY_H
440
+ double *ptr1, *ptr2;
441
+ struct NARRAY *na;
442
+ #endif
443
+ Need_Float(ff);
444
+ f = NUM2DBL(ff);
445
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
446
+ switch (TYPE(argv)) {
447
+ case T_FLOAT:
448
+ case T_FIXNUM:
449
+ case T_BIGNUM:
450
+ return rb_float_new((*func)(f, NUM2DBL(argv)));
451
+ break;
452
+ case T_ARRAY:
453
+ n = RARRAY_LEN(argv);
454
+ ary = rb_ary_new2(n);
455
+ for (i = 0; i < n; i++) {
456
+ xx = rb_ary_entry(argv, i);
457
+ Need_Float(xx);
458
+ val = (*func)(f, NUM2DBL(xx));
459
+ rb_ary_store(ary, i, rb_float_new(val));
460
+ }
461
+ return ary;
462
+ break;
463
+ default:
464
+ #ifdef HAVE_NARRAY_H
465
+ if (NA_IsNArray(argv)) {
466
+ argv = na_change_type(argv, NA_DFLOAT);
467
+ ptr1 = NA_PTR_TYPE(argv, double*);
468
+ GetNArray(argv, na);
469
+ n = na->total;
470
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
471
+ ptr2 = NA_PTR_TYPE(ary, double*);
472
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(f, ptr1[i]);
473
+ return ary;
474
+ }
475
+ #endif
476
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
477
+ Data_Get_Struct(argv, gsl_matrix, m);
478
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
479
+ for (i = 0; i < m->size1; i++) {
480
+ for (k = 0; k < m->size2; k++) {
481
+ gsl_matrix_set(mnew, i, k, (*func)(f, gsl_matrix_get(m, i, k)));
482
+ }
483
+ }
484
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
485
+ } else {
486
+ CHECK_VECTOR(argv);
487
+ Data_Get_Struct(argv, gsl_vector, v);
488
+ vnew = gsl_vector_alloc(v->size);
489
+ for (i = 0; i < v->size; i++) {
490
+ gsl_vector_set(vnew, i, (*func)(f, gsl_vector_get(v, i)));
491
+ }
492
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
493
+ }
494
+ break;
495
+ }
496
+ }
497
+
498
+ VALUE rb_gsl_sf_eval_double3(double (*func)(double, double, double),
499
+ VALUE ff, VALUE ff2, VALUE argv)
500
+ {
501
+ gsl_vector *v = NULL, *vnew = NULL;
502
+ gsl_matrix *m = NULL, *mnew = NULL;
503
+ VALUE ary, xx;
504
+ size_t i, k, n;
505
+ double val, f, f2;
506
+ #ifdef HAVE_NARRAY_H
507
+ double *ptr1, *ptr2;
508
+ struct NARRAY *na;
509
+ #endif
510
+ Need_Float(ff); Need_Float(ff2);
511
+ f = NUM2DBL(ff);
512
+ f2 = NUM2DBL(ff2);
513
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
514
+ switch (TYPE(argv)) {
515
+ case T_FLOAT:
516
+ case T_FIXNUM:
517
+ case T_BIGNUM:
518
+ return rb_float_new((*func)(f, f2, NUM2DBL(argv)));
519
+ break;
520
+ case T_ARRAY:
521
+ n = RARRAY_LEN(argv);
522
+ ary = rb_ary_new2(n);
523
+ for (i = 0; i < n; i++) {
524
+ xx = rb_ary_entry(argv, i);
525
+ Need_Float(xx);
526
+ val = (*func)(f, f2, NUM2DBL(xx));
527
+ rb_ary_store(ary, i, rb_float_new(val));
528
+ }
529
+ return ary;
530
+ break;
531
+ default:
532
+ #ifdef HAVE_NARRAY_H
533
+ if (NA_IsNArray(argv)) {
534
+ argv = na_change_type(argv, NA_DFLOAT);
535
+ ptr1 = NA_PTR_TYPE(argv, double*);
536
+ GetNArray(argv, na);
537
+ n = na->total;
538
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
539
+ ptr2 = NA_PTR_TYPE(ary, double*);
540
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(f, f2, ptr1[i]);
541
+ return ary;
542
+ }
543
+ #endif
544
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
545
+ Data_Get_Struct(argv, gsl_matrix, m);
546
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
547
+ for (i = 0; i < m->size1; i++) {
548
+ for (k = 0; k < m->size2; k++) {
549
+ val = (*func)(f, f2, gsl_matrix_get(m, i, k));
550
+ gsl_matrix_set(mnew, i, k, val);
551
+ }
552
+ }
553
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
554
+ } else {
555
+ CHECK_VECTOR(argv);
556
+ Data_Get_Struct(argv, gsl_vector, v);
557
+ n = v->size;
558
+ vnew = gsl_vector_alloc(n);
559
+ for (i = 0; i < n; i++) {
560
+ val = (*func)(f, f2, gsl_vector_get(v, i));
561
+ gsl_vector_set(vnew, i, val);
562
+ }
563
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
564
+ }
565
+ break;
566
+ }
567
+ }
568
+
569
+ VALUE rb_gsl_sf_eval_double4(double (*func)(double, double, double, double),
570
+ VALUE ff, VALUE ff2, VALUE ff3, VALUE argv)
571
+ {
572
+ gsl_vector *v = NULL, *vnew = NULL;
573
+ gsl_matrix *m = NULL, *mnew = NULL;
574
+ VALUE ary, xx;
575
+ size_t i, k, n;
576
+ double val, f, f2, f3;
577
+ #ifdef HAVE_NARRAY_H
578
+ double *ptr1, *ptr2;
579
+ struct NARRAY *na;
580
+ #endif
581
+ Need_Float(ff); Need_Float(ff2); Need_Float(ff3);
582
+ f = NUM2DBL(ff);
583
+ f2 = NUM2DBL(ff2);
584
+ f3 = NUM2DBL(ff3);
585
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
586
+ switch (TYPE(argv)) {
587
+ case T_FLOAT:
588
+ case T_FIXNUM:
589
+ case T_BIGNUM:
590
+ return rb_float_new((*func)(f, f2, f3, NUM2DBL(argv)));
591
+ break;
592
+ case T_ARRAY:
593
+ n = RARRAY_LEN(argv);
594
+ ary = rb_ary_new2(n);
595
+ for (i = 0; i < n; i++) {
596
+ xx = rb_ary_entry(argv, i);
597
+ Need_Float(xx);
598
+ val = (*func)(f, f2, f3, NUM2DBL(xx));
599
+ rb_ary_store(ary, i, rb_float_new(val));
600
+ }
601
+ return ary;
602
+ break;
603
+ default:
604
+ #ifdef HAVE_NARRAY_H
605
+ if (NA_IsNArray(argv)) {
606
+ argv = na_change_type(argv, NA_DFLOAT);
607
+ ptr1 = NA_PTR_TYPE(argv, double*);
608
+ GetNArray(argv, na);
609
+ n = na->total;
610
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
611
+ ptr2 = NA_PTR_TYPE(ary, double*);
612
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(f, f2, f3, ptr1[i]);
613
+ return ary;
614
+ }
615
+ #endif
616
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
617
+ Data_Get_Struct(argv, gsl_matrix, m);
618
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
619
+ for (i = 0; i < m->size1; i++) {
620
+ for (k = 0; k < m->size2; k++) {
621
+ val = (*func)(f, f2, f3, gsl_matrix_get(m, i, k));
622
+ gsl_matrix_set(mnew, i, k, val);
623
+ }
624
+ }
625
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
626
+ } else {
627
+ CHECK_VECTOR(argv);
628
+ Data_Get_Struct(argv, gsl_vector, v);
629
+ n = v->size;
630
+ vnew = gsl_vector_alloc(n);
631
+ for (i = 0; i < n; i++) {
632
+ val = (*func)(f, f2, f3, gsl_vector_get(v, i));
633
+ gsl_vector_set(vnew, i, val);
634
+ }
635
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
636
+ }
637
+ break;
638
+ }
639
+ }
640
+
641
+ VALUE rb_gsl_sf_eval1_int(double (*func)(int), VALUE argv)
642
+ {
643
+ gsl_vector *v = NULL, *vnew = NULL;
644
+ gsl_matrix *m = NULL, *mnew = NULL;
645
+ VALUE ary;
646
+ size_t i, k, n;
647
+ double val;
648
+ #ifdef HAVE_NARRAY_H
649
+ double *ptr1, *ptr2;
650
+ struct NARRAY *na;
651
+ #endif
652
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
653
+ switch (TYPE(argv)) {
654
+ case T_FIXNUM:
655
+ case T_BIGNUM:
656
+ case T_FLOAT:
657
+ return rb_float_new((*func)(NUM2INT(argv)));
658
+ break;
659
+ case T_ARRAY:
660
+ n = RARRAY_LEN(argv);
661
+ ary = rb_ary_new2(n);
662
+ for (i = 0; i < n; i++) {
663
+ val = (*func)(NUM2INT(rb_ary_entry(argv, i)));
664
+ rb_ary_store(ary, i, rb_float_new(val));
665
+ }
666
+ return ary;
667
+ break;
668
+ default:
669
+ #ifdef HAVE_NARRAY_H
670
+ if (NA_IsNArray(argv)) {
671
+ argv = na_change_type(argv, NA_DFLOAT);
672
+ ptr1 = NA_PTR_TYPE(argv, double*);
673
+ GetNArray(argv, na);
674
+ n = na->total;
675
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
676
+ ptr2 = NA_PTR_TYPE(ary, double*);
677
+ for (i = 0; i < n; i++) ptr2[i] = (*func)((int) ptr1[i]);
678
+ return ary;
679
+ }
680
+ #endif
681
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
682
+ Data_Get_Struct(argv, gsl_matrix, m);
683
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
684
+ for (i = 0; i < m->size1; i++) {
685
+ for (k = 0; k < m->size2; k++) {
686
+ val = (*func)((int) gsl_matrix_get(m, i, k));
687
+ gsl_matrix_set(mnew, i, k, val);
688
+ }
689
+ }
690
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
691
+ } else {
692
+ CHECK_VECTOR(argv);
693
+ Data_Get_Struct(argv, gsl_vector, v);
694
+ n = v->size;
695
+ vnew = gsl_vector_alloc(n);
696
+ for (i = 0; i < n; i++) {
697
+ val = (*func)((int) gsl_vector_get(v, i));
698
+ gsl_vector_set(vnew, i, val);
699
+ }
700
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
701
+ }
702
+ break;
703
+ }
704
+ }
705
+
706
+ VALUE rb_gsl_sf_eval1_uint(double (*func)(unsigned int), VALUE argv)
707
+ {
708
+ gsl_vector *v = NULL, *vnew = NULL;
709
+ gsl_matrix *m = NULL, *mnew = NULL;
710
+ VALUE ary;
711
+ size_t i, k, n;
712
+ double val;
713
+ #ifdef HAVE_NARRAY_H
714
+ double *ptr1, *ptr2;
715
+ struct NARRAY *na;
716
+ #endif
717
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
718
+ switch (TYPE(argv)) {
719
+ case T_FIXNUM:
720
+ case T_BIGNUM:
721
+ case T_FLOAT:
722
+ return rb_float_new((*func)(NUM2UINT(argv)));
723
+ break;
724
+ case T_ARRAY:
725
+ n = RARRAY_LEN(argv);
726
+ ary = rb_ary_new2(n);
727
+ for (i = 0; i < n; i++) {
728
+ val = (*func)(NUM2UINT(rb_ary_entry(argv, i)));
729
+ rb_ary_store(ary, i, rb_float_new(val));
730
+ }
731
+ return ary;
732
+ break;
733
+ default:
734
+ #ifdef HAVE_NARRAY_H
735
+ if (NA_IsNArray(argv)) {
736
+ argv = na_change_type(argv, NA_DFLOAT);
737
+ ptr1 = NA_PTR_TYPE(argv, double*);
738
+ GetNArray(argv, na);
739
+ n = na->total;
740
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
741
+ ptr2 = NA_PTR_TYPE(ary, double*);
742
+ for (i = 0; i < n; i++) ptr2[i] = (*func)((unsigned int) ptr1[i]);
743
+ return ary;
744
+ }
745
+ #endif
746
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
747
+ Data_Get_Struct(argv, gsl_matrix, m);
748
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
749
+ for (i = 0; i < m->size1; i++) {
750
+ for (k = 0; k < m->size2; k++) {
751
+ val = (*func)((unsigned int) gsl_matrix_get(m, i, k));
752
+ gsl_matrix_set(mnew, i, k, val);
753
+ }
754
+ }
755
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
756
+ } else {
757
+ CHECK_VECTOR(argv);
758
+ Data_Get_Struct(argv, gsl_vector, v);
759
+ n = v->size;
760
+ vnew = gsl_vector_alloc(n);
761
+ for (i = 0; i < n; i++) {
762
+ val = (*func)((unsigned int) gsl_vector_get(v, i));
763
+ gsl_vector_set(vnew, i, val);
764
+ }
765
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
766
+ }
767
+ break;
768
+ }
769
+ }
770
+
771
+ VALUE rb_gsl_sf_eval_double_m(double (*func)(double, gsl_mode_t), VALUE argv, VALUE m)
772
+ {
773
+ gsl_vector *v = NULL, *vnew = NULL;
774
+ gsl_matrix *mm = NULL, *mnew = NULL;
775
+ VALUE ary, xx;
776
+ size_t i, k, n;
777
+ double val;
778
+ gsl_mode_t mode;
779
+ char c;
780
+ #ifdef HAVE_NARRAY_H
781
+ double *ptr1, *ptr2;
782
+ struct NARRAY *na;
783
+ #endif
784
+ switch (TYPE(m)) {
785
+ case T_STRING:
786
+ c = tolower(NUM2CHR(m));
787
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
788
+ else if (c == 's') mode = GSL_PREC_SINGLE;
789
+ else if (c == 'a') mode = GSL_PREC_APPROX;
790
+ else mode = GSL_PREC_DOUBLE;
791
+ break;
792
+ case T_FIXNUM:
793
+ mode = FIX2INT(m);
794
+ break;
795
+ default:
796
+ rb_raise(rb_eArgError, "wrong type argument %s (String or Fixnum expected)",
797
+ rb_class2name(CLASS_OF(m)));
798
+ }
799
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
800
+ switch (TYPE(argv)) {
801
+ case T_FLOAT:
802
+ case T_FIXNUM:
803
+ case T_BIGNUM:
804
+ return rb_float_new((*func)(NUM2DBL(argv), m));
805
+ break;
806
+ case T_ARRAY:
807
+ n = RARRAY_LEN(argv);
808
+ ary = rb_ary_new2(n);
809
+ for (i = 0; i < n; i++) {
810
+ xx = rb_ary_entry(argv, i);
811
+ Need_Float(xx);
812
+ val = (*func)(NUM2DBL(xx), m);
813
+ rb_ary_store(ary, i, rb_float_new(val));
814
+ }
815
+ return ary;
816
+ break;
817
+ default:
818
+ #ifdef HAVE_NARRAY_H
819
+ if (NA_IsNArray(argv)) {
820
+ ptr1 = NA_PTR_TYPE(argv, double*);
821
+ GetNArray(argv, na);
822
+ n = na->total;
823
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
824
+ ptr2 = NA_PTR_TYPE(ary, double*);
825
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(ptr1[i], m);
826
+ return ary;
827
+ }
828
+ #endif
829
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
830
+ Data_Get_Struct(argv, gsl_matrix, mm);
831
+ mnew = gsl_matrix_alloc(mm->size1, mm->size2);
832
+ for (i = 0; i < mm->size1; i++) {
833
+ for (k = 0; k < mm->size2; k++) {
834
+ val = (*func)(gsl_matrix_get(mm, i, k), m);
835
+ gsl_matrix_set(mnew, i, k, val);
836
+ }
837
+ }
838
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
839
+ } else {
840
+ CHECK_VECTOR(argv);
841
+ Data_Get_Struct(argv, gsl_vector, v);
842
+ n = v->size;
843
+ vnew = gsl_vector_alloc(n);
844
+ for (i = 0; i < n; i++) {
845
+ val = (*func)(gsl_vector_get(v, i), m);
846
+ gsl_vector_set(vnew, i, val);
847
+ }
848
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
849
+ }
850
+ break;
851
+ }
852
+ }
853
+
854
+ VALUE rb_gsl_sf_eval_double2_m(double (*func)(double, double, gsl_mode_t),
855
+ VALUE argv, VALUE x2, VALUE m)
856
+ {
857
+ gsl_vector *v = NULL, *vnew = NULL;
858
+ gsl_matrix *mm = NULL, *mnew = NULL;
859
+ VALUE ary, xx;
860
+ size_t i, k, n;
861
+ double val, xx2;
862
+ gsl_mode_t mode;
863
+ char c;
864
+ #ifdef HAVE_NARRAY_H
865
+ double *ptr1, *ptr2;
866
+ struct NARRAY *na;
867
+ #endif
868
+ Need_Float(x2);
869
+ xx2 = NUM2DBL(x2);
870
+ c = tolower(NUM2CHR(m));
871
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
872
+ else if (c == 's') mode = GSL_PREC_SINGLE;
873
+ else if (c == 'a') mode = GSL_PREC_APPROX;
874
+ else mode = GSL_PREC_DOUBLE;
875
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
876
+ switch (TYPE(argv)) {
877
+ case T_FLOAT:
878
+ case T_FIXNUM:
879
+ case T_BIGNUM:
880
+ return rb_float_new((*func)(NUM2DBL(argv), xx2, m));
881
+ break;
882
+ case T_ARRAY:
883
+ n = RARRAY_LEN(argv);
884
+ ary = rb_ary_new2(n);
885
+ for (i = 0; i < n; i++) {
886
+ xx = rb_ary_entry(argv, i);
887
+ Need_Float(xx);
888
+ val = (*func)(NUM2DBL(xx), xx2, m);
889
+ rb_ary_store(ary, i, rb_float_new(val));
890
+ }
891
+ return ary;
892
+ break;
893
+ default:
894
+ #ifdef HAVE_NARRAY_H
895
+ if (NA_IsNArray(argv)) {
896
+ ptr1 = NA_PTR_TYPE(argv, double*);
897
+ GetNArray(argv, na);
898
+ n = na->total;
899
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
900
+ ptr2 = NA_PTR_TYPE(ary, double*);
901
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(ptr1[i], xx2, m);
902
+ return ary;
903
+ }
904
+ #endif
905
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
906
+ Data_Get_Struct(argv, gsl_matrix, mm);
907
+ mnew = gsl_matrix_alloc(mm->size1, mm->size2);
908
+ for (i = 0; i < mm->size1; i++) {
909
+ for (k = 0; k < mm->size2; k++) {
910
+ val = (*func)(gsl_matrix_get(mm, i, k), xx2, m);
911
+ gsl_matrix_set(mnew, i, k, val);
912
+ }
913
+ }
914
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
915
+ } else {
916
+ CHECK_VECTOR(argv);
917
+ Data_Get_Struct(argv, gsl_vector, v);
918
+ n = v->size;
919
+ vnew = gsl_vector_alloc(n);
920
+ for (i = 0; i < n; i++) {
921
+ val = (*func)(gsl_vector_get(v, i), xx2, m);
922
+ gsl_vector_set(vnew, i, val);
923
+ }
924
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
925
+ }
926
+ break;
927
+ }
928
+ }
929
+
930
+ VALUE rb_gsl_sf_eval_double3_m(double (*func)(double, double, double, gsl_mode_t),
931
+ VALUE argv, VALUE x2, VALUE x3, VALUE m)
932
+ {
933
+ gsl_vector *v = NULL, *vnew = NULL;
934
+ gsl_matrix *mm = NULL, *mnew = NULL;
935
+ VALUE ary, xx;
936
+ size_t i, k, n;
937
+ double val, xx2, xx3;
938
+ gsl_mode_t mode;
939
+ char c;
940
+ #ifdef HAVE_NARRAY_H
941
+ double *ptr1, *ptr2;
942
+ struct NARRAY *na;
943
+ #endif
944
+ Need_Float(x2); Need_Float(x3);
945
+ xx2 = NUM2DBL(x2);
946
+ xx3 = NUM2DBL(x3);
947
+ c = tolower(NUM2CHR(m));
948
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
949
+ else if (c == 's') mode = GSL_PREC_SINGLE;
950
+ else if (c == 'a') mode = GSL_PREC_APPROX;
951
+ else mode = GSL_PREC_DOUBLE;
952
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
953
+ switch (TYPE(argv)) {
954
+ case T_FLOAT:
955
+ case T_FIXNUM:
956
+ case T_BIGNUM:
957
+ return rb_float_new((*func)(NUM2DBL(argv), xx2, xx3, m));
958
+ break;
959
+ case T_ARRAY:
960
+ n = RARRAY_LEN(argv);
961
+ ary = rb_ary_new2(n);
962
+ for (i = 0; i < n; i++) {
963
+ xx = rb_ary_entry(argv, i);
964
+ Need_Float(xx);
965
+ val = (*func)(NUM2DBL(xx), xx2, xx3, m);
966
+ rb_ary_store(ary, i, rb_float_new(val));
967
+ }
968
+ return ary;
969
+ break;
970
+ default:
971
+ #ifdef HAVE_NARRAY_H
972
+ if (NA_IsNArray(argv)) {
973
+ ptr1 = NA_PTR_TYPE(argv, double*);
974
+ GetNArray(argv, na);
975
+ n = na->total;
976
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
977
+ ptr2 = NA_PTR_TYPE(ary, double*);
978
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(ptr1[i], xx2, xx3, m);
979
+ return ary;
980
+ }
981
+ #endif
982
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
983
+ Data_Get_Struct(argv, gsl_matrix, mm);
984
+ mnew = gsl_matrix_alloc(mm->size1, mm->size2);
985
+ for (i = 0; i < mm->size1; i++) {
986
+ for (k = 0; k < mm->size2; k++) {
987
+ val = (*func)(gsl_matrix_get(mm, i, k), xx2, xx3, m);
988
+ gsl_matrix_set(mnew, i, k, val);
989
+ }
990
+ }
991
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
992
+ } else {
993
+ CHECK_VECTOR(argv);
994
+ Data_Get_Struct(argv, gsl_vector, v);
995
+ n = v->size;
996
+ vnew = gsl_vector_alloc(n);
997
+ for (i = 0; i < n; i++) {
998
+ val = (*func)(gsl_vector_get(v, i), xx2, xx3, m);
999
+ gsl_vector_set(vnew, i, val);
1000
+ }
1001
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1002
+ }
1003
+ break;
1004
+ }
1005
+ }
1006
+
1007
+ VALUE rb_gsl_sf_eval_double4_m(double (*func)(double, double, double, double,
1008
+ gsl_mode_t),
1009
+ VALUE argv, VALUE x2, VALUE x3, VALUE x4, VALUE m)
1010
+ {
1011
+ gsl_vector *v = NULL, *vnew = NULL;
1012
+ gsl_matrix *mm = NULL, *mnew = NULL;
1013
+ VALUE ary, xx;
1014
+ size_t i, k, n;
1015
+ double val, xx2, xx3, xx4;
1016
+ gsl_mode_t mode;
1017
+ char c;
1018
+ #ifdef HAVE_NARRAY_H
1019
+ double *ptr1, *ptr2;
1020
+ struct NARRAY *na;
1021
+ #endif
1022
+ Need_Float(x2); Need_Float(x3); Need_Float(x4);
1023
+ xx2 = NUM2DBL(x2); xx3 = NUM2DBL(x3); xx4 = NUM2DBL(x4);
1024
+ c = tolower(NUM2CHR(m));
1025
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
1026
+ else if (c == 's') mode = GSL_PREC_SINGLE;
1027
+ else if (c == 'a') mode = GSL_PREC_APPROX;
1028
+ else mode = GSL_PREC_DOUBLE;
1029
+ if (CLASS_OF(argv) == rb_cRange) argv = rb_gsl_range2ary(argv);
1030
+ switch (TYPE(argv)) {
1031
+ case T_FLOAT:
1032
+ case T_FIXNUM:
1033
+ case T_BIGNUM:
1034
+ return rb_float_new((*func)(NUM2DBL(argv), NUM2DBL(x2), NUM2DBL(x3),
1035
+ NUM2DBL(x4), m));
1036
+ break;
1037
+ case T_ARRAY:
1038
+ n = RARRAY_LEN(argv);
1039
+ ary = rb_ary_new2(n);
1040
+ for (i = 0; i < n; i++) {
1041
+ xx = rb_ary_entry(argv, i);
1042
+ Need_Float(xx);
1043
+ val = (*func)(NUM2DBL(xx), xx2, xx3, xx4, m);
1044
+ rb_ary_store(ary, i, rb_float_new(val));
1045
+ }
1046
+ return ary;
1047
+ break;
1048
+ default:
1049
+ #ifdef HAVE_NARRAY_H
1050
+ if (NA_IsNArray(argv)) {
1051
+ ptr1 = NA_PTR_TYPE(argv, double*);
1052
+ GetNArray(argv, na);
1053
+ n = na->total;
1054
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
1055
+ ptr2 = NA_PTR_TYPE(ary, double*);
1056
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(ptr1[i], xx2, xx3, xx4, m);
1057
+ return ary;
1058
+ }
1059
+ #endif
1060
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
1061
+ Data_Get_Struct(argv, gsl_matrix, mm);
1062
+ mnew = gsl_matrix_alloc(mm->size1, mm->size2);
1063
+ for (i = 0; i < mm->size1; i++) {
1064
+ for (k = 0; k < mm->size2; k++) {
1065
+ val = (*func)(gsl_matrix_get(mm, i, k), xx2, xx3, xx4, m);
1066
+ gsl_matrix_set(mnew, i, k, val);
1067
+ }
1068
+ }
1069
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1070
+ } else {
1071
+ CHECK_VECTOR(argv);
1072
+ Data_Get_Struct(argv, gsl_vector, v);
1073
+ n = v->size;
1074
+ vnew = gsl_vector_alloc(n);
1075
+ for (i = 0; i < n; i++) {
1076
+ val = (*func)(gsl_vector_get(v, i), xx2, xx3, xx4, m);
1077
+ gsl_vector_set(vnew, i, val);
1078
+ }
1079
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1080
+ }
1081
+ break;
1082
+ }
1083
+ }
1084
+
1085
+ VALUE rb_gsl_sf_eval_e(int (*func)(double, gsl_sf_result*), VALUE x)
1086
+ {
1087
+ gsl_sf_result *rslt = NULL;
1088
+ VALUE v;
1089
+ int status;
1090
+ Need_Float(x);
1091
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1092
+ status = (*func)(NUM2DBL(x), rslt);
1093
+ return v;
1094
+ }
1095
+
1096
+ VALUE rb_gsl_sf_eval_e_int(int (*func)(int, gsl_sf_result*), VALUE x)
1097
+ {
1098
+ gsl_sf_result *rslt = NULL;
1099
+ VALUE v;
1100
+ int status;
1101
+ CHECK_FIXNUM(x);
1102
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1103
+ status = (*func)(NUM2INT(x), rslt);
1104
+ return v;
1105
+ }
1106
+
1107
+ VALUE rb_gsl_sf_eval_e_uint(int (*func)(unsigned int, gsl_sf_result*), VALUE x)
1108
+ {
1109
+ gsl_sf_result *rslt = NULL;
1110
+ VALUE v;
1111
+ int status;
1112
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1113
+ status = (*func)(NUM2UINT(x), rslt);
1114
+ return v;
1115
+ }
1116
+
1117
+ VALUE rb_gsl_sf_eval_e_int_uint(int (*func)(int, unsigned int, gsl_sf_result*),
1118
+ VALUE n, VALUE x)
1119
+ {
1120
+ gsl_sf_result *rslt = NULL;
1121
+ VALUE v;
1122
+ int status;
1123
+ CHECK_FIXNUM(n);
1124
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1125
+ status = (*func)(FIX2INT(n), NUM2UINT(x), rslt);
1126
+ return v;
1127
+ }
1128
+
1129
+ VALUE rb_gsl_sf_eval_e_double_uint(int (*func)(double, unsigned int, gsl_sf_result*),
1130
+ VALUE y, VALUE x)
1131
+ {
1132
+ gsl_sf_result *rslt = NULL;
1133
+ VALUE v;
1134
+ int status;
1135
+ Need_Float(y);
1136
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1137
+ status = (*func)(NUM2DBL(y), NUM2UINT(x), rslt);
1138
+ return v;
1139
+ }
1140
+
1141
+ VALUE rb_gsl_sf_eval_e_int_double(int (*func)(int, double, gsl_sf_result*),
1142
+ VALUE n, VALUE x)
1143
+ {
1144
+ gsl_sf_result *rslt = NULL;
1145
+ VALUE v;
1146
+ int status;
1147
+ CHECK_FIXNUM(n);
1148
+ Need_Float(x);
1149
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1150
+ status = (*func)(FIX2INT(n), NUM2DBL(x), rslt);
1151
+ return v;
1152
+ }
1153
+
1154
+ VALUE rb_gsl_sf_eval_e_int_double2(int (*func)(int, double, double, gsl_sf_result*),
1155
+ VALUE n, VALUE x1, VALUE x2)
1156
+ {
1157
+ gsl_sf_result *rslt = NULL;
1158
+ VALUE v;
1159
+ int status;
1160
+ CHECK_FIXNUM(n);
1161
+ Need_Float(x1); Need_Float(x2);
1162
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1163
+ status = (*func)(FIX2INT(n), NUM2DBL(x1), NUM2DBL(x2), rslt);
1164
+ return v;
1165
+ }
1166
+
1167
+
1168
+ VALUE rb_gsl_sf_eval_e_int_int_double(int (*func)(int, int, double, gsl_sf_result*),
1169
+ VALUE n1, VALUE n2, VALUE x)
1170
+ {
1171
+ gsl_sf_result *rslt = NULL;
1172
+ VALUE v;
1173
+ int status;
1174
+ CHECK_FIXNUM(n1); CHECK_FIXNUM(n2);
1175
+ Need_Float(x);
1176
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1177
+ status = (*func)(FIX2INT(n1), FIX2INT(n2), NUM2DBL(x), rslt);
1178
+ return v;
1179
+ }
1180
+
1181
+ VALUE rb_gsl_sf_eval_e_double2(int (*func)(double, double, gsl_sf_result*),
1182
+ VALUE x1, VALUE x2)
1183
+ {
1184
+ gsl_sf_result *rslt = NULL;
1185
+ VALUE v;
1186
+ int status;
1187
+ Need_Float(x1); Need_Float(x2);
1188
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1189
+ status = (*func)(NUM2DBL(x1), NUM2DBL(x2), rslt);
1190
+ return v;
1191
+ }
1192
+
1193
+
1194
+ VALUE rb_gsl_sf_eval_e_double3(int (*func)(double, double, double, gsl_sf_result*),
1195
+ VALUE x1, VALUE x2, VALUE x3)
1196
+ {
1197
+ gsl_sf_result *rslt = NULL;
1198
+ VALUE v;
1199
+ int status;
1200
+ Need_Float(x1); Need_Float(x2); Need_Float(x3);
1201
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1202
+ status = (*func)(NUM2DBL(x1), NUM2DBL(x2),NUM2DBL(x3), rslt);
1203
+ return v;
1204
+ }
1205
+
1206
+ VALUE rb_gsl_sf_eval_e_m(int (*func)(double, gsl_mode_t, gsl_sf_result*),
1207
+ VALUE x, VALUE m)
1208
+ {
1209
+ gsl_mode_t mode;
1210
+ char c;
1211
+ gsl_sf_result *rslt = NULL;
1212
+ VALUE v;
1213
+ int status;
1214
+ Need_Float(x);
1215
+ switch (TYPE(m)) {
1216
+ case T_STRING:
1217
+ c = tolower(NUM2CHR(m));
1218
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
1219
+ else if (c == 's') mode = GSL_PREC_SINGLE;
1220
+ else if (c == 'a') mode = GSL_PREC_APPROX;
1221
+ else mode = GSL_PREC_DOUBLE;
1222
+ break;
1223
+ case T_FIXNUM:
1224
+ mode = FIX2INT(m);
1225
+ break;
1226
+ default:
1227
+ rb_raise(rb_eArgError, "wrong type argument %s (String or Fixnum expected)",
1228
+ rb_class2name(CLASS_OF(m)));
1229
+ break;
1230
+ }
1231
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1232
+ status = (*func)(NUM2DBL(x), mode, rslt);
1233
+ return v;
1234
+ }
1235
+
1236
+
1237
+ VALUE rb_gsl_sf_eval_e_double2_m(int (*func)(double, double, gsl_mode_t, gsl_sf_result*),
1238
+ VALUE x1, VALUE x2, VALUE m)
1239
+ {
1240
+ gsl_mode_t mode;
1241
+ char c;
1242
+ gsl_sf_result *rslt = NULL;
1243
+ VALUE v;
1244
+ int status;
1245
+ Need_Float(x1); Need_Float(x2);
1246
+ switch (TYPE(m)) {
1247
+ case T_STRING:
1248
+ c = tolower(NUM2CHR(m));
1249
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
1250
+ else if (c == 's') mode = GSL_PREC_SINGLE;
1251
+ else if (c == 'a') mode = GSL_PREC_APPROX;
1252
+ else mode = GSL_PREC_DOUBLE;
1253
+ break;
1254
+ case T_FIXNUM:
1255
+ mode = FIX2INT(m);
1256
+ break;
1257
+ default:
1258
+ rb_raise(rb_eArgError, "wrong type argument %s (String or Fixnum expected)",
1259
+ rb_class2name(CLASS_OF(m)));
1260
+ break;
1261
+ }
1262
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1263
+ status = (*func)(NUM2DBL(x1), NUM2DBL(x2), mode, rslt);
1264
+ return v;
1265
+ }
1266
+
1267
+ VALUE rb_gsl_sf_eval_e_double3_m(int (*func)(double, double, double, gsl_mode_t, gsl_sf_result*),
1268
+ VALUE x1, VALUE x2, VALUE x3, VALUE m)
1269
+ {
1270
+ gsl_mode_t mode;
1271
+ char c;
1272
+ gsl_sf_result *rslt = NULL;
1273
+ VALUE v;
1274
+ int status;
1275
+ Need_Float(x1); Need_Float(x2); Need_Float(x3);
1276
+ switch (TYPE(m)) {
1277
+ case T_STRING:
1278
+ c = tolower(NUM2CHR(m));
1279
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
1280
+ else if (c == 's') mode = GSL_PREC_SINGLE;
1281
+ else if (c == 'a') mode = GSL_PREC_APPROX;
1282
+ else mode = GSL_PREC_DOUBLE;
1283
+ break;
1284
+ case T_FIXNUM:
1285
+ mode = FIX2INT(m);
1286
+ break;
1287
+ default:
1288
+ rb_raise(rb_eArgError, "wrong type argument %s (String or Fixnum expected)",
1289
+ rb_class2name(CLASS_OF(m)));
1290
+ break;
1291
+ }
1292
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1293
+ status = (*func)(NUM2DBL(x1), NUM2DBL(x2),NUM2DBL(x3), mode, rslt);
1294
+ return v;
1295
+ }
1296
+
1297
+
1298
+ VALUE rb_gsl_sf_eval_e_double4_m(int (*func)(double, double, double, double, gsl_mode_t, gsl_sf_result*),
1299
+ VALUE x1, VALUE x2, VALUE x3, VALUE x4, VALUE m)
1300
+ {
1301
+ gsl_mode_t mode;
1302
+ char c;
1303
+ gsl_sf_result *rslt = NULL;
1304
+ VALUE v;
1305
+ int status;
1306
+ Need_Float(x1); Need_Float(x2); Need_Float(x3); Need_Float(x4);
1307
+ switch (TYPE(m)) {
1308
+ case T_STRING:
1309
+ c = tolower(NUM2CHR(m));
1310
+ if (c == 'd') mode = GSL_PREC_DOUBLE;
1311
+ else if (c == 's') mode = GSL_PREC_SINGLE;
1312
+ else if (c == 'a') mode = GSL_PREC_APPROX;
1313
+ else mode = GSL_PREC_DOUBLE;
1314
+ break;
1315
+ case T_FIXNUM:
1316
+ mode = FIX2INT(m);
1317
+ break;
1318
+ default:
1319
+ rb_raise(rb_eArgError, "wrong type argument %s (String or Fixnum expected)",
1320
+ rb_class2name(CLASS_OF(m)));
1321
+ break;
1322
+ }
1323
+ v = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, rslt);
1324
+ status = (*func)(NUM2DBL(x1), NUM2DBL(x2),NUM2DBL(x3), NUM2DBL(x4), mode, rslt);
1325
+ return v;
1326
+ }
1327
+
1328
+
1329
+ VALUE eval_sf(double (*func)(double, gsl_mode_t), VALUE argv)
1330
+ {
1331
+ VALUE ary, xx;
1332
+ size_t i, k, n;
1333
+ double val;
1334
+ gsl_vector *v = NULL, *vnew = NULL;
1335
+ gsl_matrix *mm = NULL, *mnew = NULL;
1336
+ #ifdef HAVE_NARRAY_H
1337
+ double *ptr1, *ptr2;
1338
+ struct NARRAY *na;
1339
+ #endif
1340
+ switch (TYPE(argv)) {
1341
+ case T_FLOAT:
1342
+ case T_FIXNUM:
1343
+ case T_BIGNUM:
1344
+ return rb_float_new((*func)(NUM2DBL(argv), GSL_PREC_DOUBLE));
1345
+ break;
1346
+ case T_ARRAY:
1347
+ n = RARRAY_LEN(argv);
1348
+ ary = rb_ary_new2(n);
1349
+ for (i = 0; i < n; i++) {
1350
+ xx = rb_ary_entry(argv, i);
1351
+ Need_Float(xx);
1352
+ val = (*func)(NUM2DBL(xx), GSL_PREC_DOUBLE);
1353
+ rb_ary_store(ary, i, rb_float_new(val));
1354
+ }
1355
+ return ary;
1356
+ break;
1357
+ default:
1358
+ #ifdef HAVE_NARRAY_H
1359
+ if (NA_IsNArray(argv)) {
1360
+ ptr1 = NA_PTR_TYPE(argv, double*);
1361
+ GetNArray(argv, na);
1362
+ n = na->total;
1363
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv));
1364
+ ptr2 = NA_PTR_TYPE(ary, double*);
1365
+ for (i = 0; i < n; i++) ptr2[i] = (*func)(ptr1[i], GSL_PREC_DOUBLE);
1366
+ return ary;
1367
+ }
1368
+ #endif
1369
+ if (rb_obj_is_kind_of(argv, cgsl_matrix)) {
1370
+ Data_Get_Struct(argv, gsl_matrix, mm);
1371
+ mnew = gsl_matrix_alloc(mm->size1, mm->size2);
1372
+ for (i = 0; i < mm->size1; i++) {
1373
+ for (k = 0; k < mm->size2; k++) {
1374
+ val = (*func)(gsl_matrix_get(mm, i, k), GSL_PREC_DOUBLE);
1375
+ gsl_matrix_set(mnew, i, k, val);
1376
+ }
1377
+ }
1378
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1379
+ } else {
1380
+ CHECK_VECTOR(argv);
1381
+ Data_Get_Struct(argv, gsl_vector, v);
1382
+ n = v->size;
1383
+ vnew = gsl_vector_alloc(n);
1384
+ for (i = 0; i < n; i++) {
1385
+ val = (*func)(gsl_vector_get(v, i), GSL_PREC_DOUBLE);
1386
+ gsl_vector_set(vnew, i, val);
1387
+ }
1388
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
1389
+ }
1390
+ break;
1391
+ }
1392
+ }
1393
+
1394
+ VALUE rb_gsl_sf_eval_complex(double (*f)(double), VALUE obj)
1395
+ {
1396
+ gsl_complex *z, *znew, c;
1397
+ gsl_vector_complex *v, *vnew;
1398
+ gsl_matrix_complex *m, *mnew;
1399
+ size_t i, j;
1400
+ if (COMPLEX_P(obj)) {
1401
+ Data_Get_Struct(obj, gsl_complex, z);
1402
+ znew = xmalloc(sizeof(gsl_complex));
1403
+ GSL_SET_REAL(znew, (*f)(GSL_REAL(*z)));
1404
+ GSL_SET_IMAG(znew, (*f)(GSL_IMAG(*z)));
1405
+ return Data_Wrap_Struct(cgsl_complex, 0, free, znew);
1406
+ } else if (VECTOR_COMPLEX_P(obj)) {
1407
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1408
+ vnew = gsl_vector_complex_alloc(v->size);
1409
+ for (i = 0; i < v->size; i++) {
1410
+ z = GSL_COMPLEX_AT(v, i);
1411
+ GSL_SET_REAL(&c, (*f)(GSL_REAL(*z)));
1412
+ GSL_SET_IMAG(&c, (*f)(GSL_IMAG(*z)));
1413
+ gsl_vector_complex_set(vnew, i, c);
1414
+ }
1415
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
1416
+ } else if (MATRIX_COMPLEX_P(obj)) {
1417
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1418
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
1419
+ for (i = 0; i < m->size1; i++) {
1420
+ for (j = 0; j < m->size2; j++) {
1421
+ c = gsl_matrix_complex_get(m, i, j);
1422
+ GSL_SET_REAL(&c, (*f)(GSL_REAL(c)));
1423
+ GSL_SET_IMAG(&c, (*f)(GSL_IMAG(c)));
1424
+ gsl_matrix_complex_set(mnew, i, j, c);
1425
+ }
1426
+ }
1427
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1428
+ } else {
1429
+ rb_raise(rb_eTypeError,
1430
+ "wrong argument type %s "
1431
+ " (GSL::Complex or GSL::Vector::Complex expected)",
1432
+ rb_class2name(CLASS_OF(obj)));
1433
+ }
1434
+ }
1435
+
1436
+ void Init_gsl_sf(VALUE module)
1437
+ {
1438
+ VALUE mgsl_sf;
1439
+ mgsl_sf = rb_define_module_under(module, "Sf");
1440
+
1441
+ cgsl_sf_result = rb_define_class_under(mgsl_sf, "Result",
1442
+ cGSL_Object);
1443
+ rb_define_singleton_method(cgsl_sf_result, "new", rb_gsl_sf_result_new,
1444
+ 0);
1445
+ rb_define_method(cgsl_sf_result, "print", rb_gsl_sf_result_print, 0);
1446
+ rb_define_method(cgsl_sf_result, "inspect", rb_gsl_sf_result_inspect, 0);
1447
+ rb_define_method(cgsl_sf_result, "val", rb_gsl_sf_result_val, 0);
1448
+ rb_define_method(cgsl_sf_result, "err", rb_gsl_sf_result_err, 0);
1449
+ rb_define_method(cgsl_sf_result, "to_a", rb_gsl_sf_result_to_a, 0);
1450
+ rb_define_method(cgsl_sf_result, "to_s", rb_gsl_sf_result_to_s, 0);
1451
+
1452
+ cgsl_sf_result_e10 = rb_define_class_under(mgsl_sf, "Result_e10",
1453
+ cGSL_Object);
1454
+ rb_define_singleton_method(cgsl_sf_result_e10, "new",
1455
+ rb_gsl_sf_result_e10_new, 0);
1456
+ rb_define_method(cgsl_sf_result_e10, "val", rb_gsl_sf_result_e10_val, 0);
1457
+ rb_define_method(cgsl_sf_result_e10, "err", rb_gsl_sf_result_e10_err, 0);
1458
+ rb_define_method(cgsl_sf_result_e10, "e10", rb_gsl_sf_result_e10_e10, 0);
1459
+ rb_define_method(cgsl_sf_result_e10, "to_a", rb_gsl_sf_result_e10_to_a, 0);
1460
+ rb_define_method(cgsl_sf_result_e10, "to_s", rb_gsl_sf_result_e10_to_s, 0);
1461
+
1462
+ Init_gsl_sf_airy(mgsl_sf);
1463
+ Init_gsl_sf_bessel(mgsl_sf);
1464
+ Init_gsl_sf_clausen(mgsl_sf);
1465
+ Init_gsl_sf_coulomb(mgsl_sf);
1466
+ Init_gsl_sf_coupling(mgsl_sf);
1467
+ Init_gsl_sf_dawson(mgsl_sf);
1468
+ Init_gsl_sf_debye(mgsl_sf);
1469
+ Init_gsl_sf_dilog(mgsl_sf);
1470
+ Init_gsl_sf_elementary(mgsl_sf);
1471
+ Init_gsl_sf_ellint(mgsl_sf);
1472
+ Init_gsl_sf_elljac(mgsl_sf);
1473
+ Init_gsl_sf_erfc(mgsl_sf);
1474
+ Init_gsl_sf_exp(mgsl_sf);
1475
+ Init_gsl_sf_expint(mgsl_sf);
1476
+ Init_gsl_sf_fermi_dirac(mgsl_sf);
1477
+ Init_gsl_sf_gamma(mgsl_sf);
1478
+ Init_gsl_sf_gegenbauer(mgsl_sf);
1479
+ Init_gsl_sf_hyperg(mgsl_sf);
1480
+ Init_gsl_sf_laguerre(mgsl_sf);
1481
+ Init_gsl_sf_lambert(mgsl_sf);
1482
+ Init_gsl_sf_legendre(mgsl_sf);
1483
+ Init_gsl_sf_log(mgsl_sf);
1484
+ Init_gsl_sf_power(mgsl_sf);
1485
+ Init_gsl_sf_psi(mgsl_sf);
1486
+ Init_gsl_sf_synchrotron(mgsl_sf);
1487
+ Init_gsl_sf_transport(mgsl_sf);
1488
+ Init_gsl_sf_trigonometric(mgsl_sf);
1489
+ Init_gsl_sf_zeta(mgsl_sf);
1490
+
1491
+ #ifdef GSL_1_9_LATER
1492
+ Init_sf_mathieu(mgsl_sf);
1493
+ #endif
1494
+ }