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,38 @@
1
+ /*
2
+ vector.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
+ /*
13
+ This code uses "templates_on.h" and "templates_off.h",
14
+ which are provided by the GSL source.
15
+ */
16
+
17
+ #include "rb_gsl_config.h"
18
+ #include "rb_gsl_array.h"
19
+ #include "rb_gsl_histogram.h"
20
+ #include "rb_gsl_complex.h"
21
+ #include "rb_gsl_poly.h"
22
+ #ifdef HAVE_NARRAY_H
23
+ #include "rb_gsl_with_narray.h"
24
+ #endif
25
+
26
+ #define BASE_DOUBLE
27
+ #include "templates_on.h"
28
+ #include "vector_source.c"
29
+ #include "templates_off.h"
30
+ #undef BASE_DOUBLE
31
+
32
+ #define BASE_INT
33
+ #include "templates_on.h"
34
+ #include "vector_source.c"
35
+ #include "templates_off.h"
36
+ #undef BASE_INT
37
+
38
+
@@ -0,0 +1,2246 @@
1
+ /*
2
+ vector_complex.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2001-2006 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+ #include "rb_gsl_config.h"
12
+ #include "rb_gsl_array.h"
13
+ #include "rb_gsl_complex.h"
14
+
15
+ EXTERN VALUE cgsl_complex;
16
+ static VALUE rb_gsl_vector_complex_inner_product(int argc, VALUE *argv, VALUE obj);
17
+ static VALUE rb_gsl_vector_complex_product_to_m(int argc, VALUE *argv, VALUE obj);
18
+
19
+ // From vector_source.c
20
+ void get_range_beg_en_n(VALUE range, double *beg, double *en, size_t *n, int *step);
21
+ //
22
+ // From vector_source.c
23
+ void parse_subvector_args(int argc, VALUE *argv, size_t size,
24
+ size_t *offset, size_t *stride, size_t *n);
25
+
26
+ // From complex.c
27
+ gsl_complex rb_gsl_obj_to_gsl_complex(VALUE obj, gsl_complex *z);
28
+
29
+ static VALUE rb_gsl_vector_complex_new(int argc, VALUE *argv, VALUE klass)
30
+ {
31
+ VALUE tmp;
32
+ gsl_vector_complex *v = NULL;
33
+ gsl_vector *x, *y;
34
+ gsl_complex z, *z2 = NULL;
35
+ size_t n, i;
36
+ switch (argc) {
37
+ case 1:
38
+ switch (TYPE(argv[0])) {
39
+ case T_FIXNUM:
40
+ n = FIX2INT(argv[0]);
41
+ v = gsl_vector_complex_calloc(n);
42
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
43
+ break;
44
+ case T_ARRAY:
45
+ n = RARRAY_LEN(argv[0]);
46
+ v = gsl_vector_complex_alloc(n);
47
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
48
+ for (i = 0; i < n; i++) {
49
+ z2 = &z;
50
+ tmp = rb_ary_entry(argv[0], i);
51
+ if (TYPE(tmp) == T_ARRAY) {
52
+ GSL_SET_REAL(z2, NUM2DBL(rb_ary_entry(tmp, 0)));
53
+ GSL_SET_IMAG(z2, NUM2DBL(rb_ary_entry(tmp, 1)));
54
+ } else if (COMPLEX_P(tmp)) {
55
+ Data_Get_Struct(tmp, gsl_complex, z2);
56
+ } else {
57
+ rb_raise(rb_eTypeError,
58
+ "wrong argument type %s (Array or Complex expected)",
59
+ rb_class2name(CLASS_OF(tmp)));
60
+
61
+ }
62
+ gsl_vector_complex_set(v, i, *z2);
63
+ }
64
+ break;
65
+ default:
66
+ rb_raise(rb_eTypeError,
67
+ "wrong argument type %s", rb_class2name(CLASS_OF(argv[0])));
68
+ break;
69
+ }
70
+ break;
71
+ default:
72
+ if (argc == 2 && (VECTOR_P(argv[0]) && VECTOR_P(argv[1]))) {
73
+ Data_Get_Struct(argv[0], gsl_vector, x);
74
+ Data_Get_Struct(argv[1], gsl_vector, y);
75
+ n = GSL_MIN_INT(x->size, y->size);
76
+ v = gsl_vector_complex_alloc(n);
77
+ for (i = 0; i < n; i++) {
78
+ z.dat[0] = gsl_vector_get(x, i);
79
+ z.dat[1] = gsl_vector_get(y, i);
80
+ gsl_vector_complex_set(v, i, z);
81
+ }
82
+ break;
83
+ }
84
+ n = argc;
85
+ v = gsl_vector_complex_alloc(n);
86
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
87
+ for (i = 0; i < n; i++) {
88
+ if (TYPE(argv[i]) == T_ARRAY) {
89
+ GSL_SET_REAL(&z, NUM2DBL(rb_ary_entry(argv[i], 0)));
90
+ GSL_SET_IMAG(&z, NUM2DBL(rb_ary_entry(argv[i], 1)));
91
+ z2 = &z;
92
+ } else if (COMPLEX_P(argv[i])) {
93
+ Data_Get_Struct(argv[i], gsl_complex, z2);
94
+ } else {
95
+ rb_raise(rb_eTypeError,
96
+ "wrong argument type %s (Array or Complex expected)",
97
+ rb_class2name(CLASS_OF(argv[i])));
98
+ }
99
+ gsl_vector_complex_set(v, i, *z2);
100
+ }
101
+ break;
102
+ }
103
+ return Data_Wrap_Struct(klass, 0, gsl_vector_complex_free, v);
104
+ }
105
+
106
+ static VALUE rb_gsl_vector_complex_row_new(int argc, VALUE *argv, VALUE klass)
107
+ {
108
+ return rb_gsl_vector_complex_new(argc, argv, klass);
109
+ }
110
+
111
+ static VALUE rb_gsl_vector_complex_calloc(VALUE klass, VALUE nn)
112
+ {
113
+ gsl_vector_complex *vc = NULL;
114
+ CHECK_FIXNUM(nn);
115
+ vc = gsl_vector_complex_calloc(FIX2INT(nn));
116
+ if (vc == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
117
+ return Data_Wrap_Struct(klass, 0, gsl_vector_complex_free, vc);
118
+ }
119
+
120
+ static VALUE rb_gsl_vector_complex_size(VALUE obj)
121
+ {
122
+ gsl_vector_complex *v = NULL;
123
+ Data_Get_Struct(obj, gsl_vector_complex, v);
124
+ return INT2FIX(v->size);
125
+ }
126
+
127
+ static VALUE rb_gsl_vector_complex_stride(VALUE obj)
128
+ {
129
+ gsl_vector_complex *v = NULL;
130
+ Data_Get_Struct(obj, gsl_vector_complex, v);
131
+ return INT2FIX(v->stride);
132
+ }
133
+
134
+ static VALUE rb_gsl_vector_complex_owner(VALUE obj)
135
+ {
136
+ gsl_vector_complex *v = NULL;
137
+ Data_Get_Struct(obj, gsl_vector_complex, v);
138
+ return INT2FIX(v->owner);
139
+ }
140
+
141
+ static VALUE rb_gsl_vector_complex_ptr(VALUE obj, VALUE i)
142
+ {
143
+ gsl_vector_complex *v = NULL;
144
+ Data_Get_Struct(obj, gsl_vector_complex, v);
145
+ return Data_Wrap_Struct(cgsl_complex, 0, NULL, gsl_vector_complex_ptr(v, FIX2INT(i)));
146
+ }
147
+
148
+ // TODO return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj),..." where appropriate
149
+ static VALUE rb_gsl_vector_complex_subvector(int argc, VALUE *argv, VALUE obj);
150
+ static VALUE rb_gsl_vector_complex_get(int argc, VALUE *argv, VALUE obj)
151
+ {
152
+ VALUE retval = Qnil;
153
+ gsl_vector_complex *v = NULL, *vnew;
154
+ gsl_complex *c = NULL;
155
+ gsl_index *p;
156
+ int i, k;
157
+ size_t index, j;
158
+ // If argc is not 1 or argv[0] is a Range
159
+ if( argc != 1 || rb_obj_is_kind_of(argv[0], rb_cRange)) {
160
+ // Treat as call to subvector
161
+ retval = rb_gsl_vector_complex_subvector(argc, argv, obj);
162
+ } else {
163
+ Data_Get_Struct(obj, gsl_vector_complex, v);
164
+
165
+ switch (TYPE(argv[0])) {
166
+ case T_FIXNUM:
167
+ CHECK_FIXNUM(argv[0]);
168
+ i = FIX2INT(argv[0]);
169
+ if (i < 0) index = (size_t) (v->size + i);
170
+ else index = (size_t) i;
171
+ c = ALLOC(gsl_complex);
172
+ *c = gsl_vector_complex_get(v, index);
173
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
174
+ break;
175
+ case T_ARRAY:
176
+ vnew = gsl_vector_complex_alloc(RARRAY_LEN(argv[0]));
177
+ for (j = 0; j < vnew->size; j++) {
178
+ i = FIX2INT(rb_ary_entry(argv[0], j));
179
+ if (i < 0) i = v->size + i;
180
+ gsl_vector_complex_set(vnew, j, gsl_vector_complex_get(v, i));
181
+ }
182
+ retval = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
183
+ break;
184
+ default:
185
+ if (PERMUTATION_P(argv[0])) {
186
+ Data_Get_Struct(argv[0], gsl_index, p);
187
+ vnew = gsl_vector_complex_alloc(p->size);
188
+ for (j = 0; j < p->size; j++) {
189
+ k = p->data[j];
190
+ if (k < 0) k = p->size + j;
191
+ gsl_vector_complex_set(vnew, j, gsl_vector_complex_get(v, k));
192
+ }
193
+ retval = Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
194
+ } else {
195
+ // TODO Support Vector::Int (and even Vector?)
196
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array, Range, GSL::Permutation, or Fixnum expected)", rb_class2name(CLASS_OF(argv[0])));
197
+ }
198
+ break;
199
+ }
200
+ }
201
+ return retval;
202
+ }
203
+
204
+ static VALUE rb_gsl_vector_complex_set_all(int argc, VALUE *argv, VALUE obj)
205
+ {
206
+ gsl_vector_complex *v = NULL;
207
+ gsl_complex tmp;
208
+
209
+ if (argc < 1) rb_raise(rb_eArgError, "wrong number of arguments");
210
+
211
+ Data_Get_Struct(obj, gsl_vector_complex, v);
212
+
213
+ switch (argc) {
214
+ case 1:
215
+ tmp = rb_gsl_obj_to_gsl_complex(argv[0], NULL);
216
+ break;
217
+ case 2:
218
+ GSL_SET_COMPLEX(&tmp, NUM2DBL(argv[0]), NUM2DBL(argv[1]));
219
+ break;
220
+ default:
221
+ rb_raise(rb_eArgError, "wrong number of arguments");
222
+ break;
223
+ }
224
+
225
+ gsl_vector_complex_set_all(v, tmp);
226
+
227
+ return obj;
228
+ }
229
+
230
+ void rb_gsl_vector_complex_set_subvector(int argc, VALUE *argv, gsl_vector_complex *v, VALUE other)
231
+ {
232
+ gsl_vector_complex *vother;
233
+ gsl_vector_complex_view vv;
234
+ gsl_complex tmp;
235
+ int step;
236
+ size_t i, offset, stride, n, nother;
237
+ double beg, end;
238
+
239
+ // assignment to v.subvector(...)
240
+ parse_subvector_args(argc, argv, v->size, &offset, &stride, &n);
241
+ vv = gsl_vector_complex_subvector_with_stride(v, offset, stride, n);
242
+ if(rb_obj_is_kind_of(other, cgsl_vector_complex)) {
243
+ Data_Get_Struct(other, gsl_vector_complex, vother);
244
+ if(n != vother->size) {
245
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) vother->size);
246
+ }
247
+ // TODO Change to gsl_vector_complex_memmove if/when GSL has such a
248
+ // function because gsl_vector_memcpy does not handle overlapping regions
249
+ // (e.g. Views) well.
250
+ gsl_vector_complex_memcpy(&vv.vector, vother);
251
+ } else if(rb_obj_is_kind_of(other, rb_cArray)) {
252
+ // TODO Support other forms of Array contents as well
253
+ if(n != RARRAY_LEN(other)) {
254
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) RARRAY_LEN(other));
255
+ }
256
+ for(i = 0; i < n; i++) {
257
+ tmp = rb_gsl_obj_to_gsl_complex(rb_ary_entry(other, i), NULL);
258
+ gsl_vector_complex_set(&vv.vector, i, tmp);
259
+ }
260
+ } else if(rb_obj_is_kind_of(other, rb_cRange)) {
261
+ get_range_beg_en_n(other, &beg, &end, &nother, &step);
262
+ if(n != nother) {
263
+ rb_raise(rb_eRangeError, "lengths do not match (%d != %d)", (int) n, (int) nother);
264
+ }
265
+ GSL_SET_IMAG(&tmp, 0.0);
266
+ for(i = 0; i < n; i++) {
267
+ GSL_SET_REAL(&tmp, beg);
268
+ gsl_vector_complex_set(&vv.vector, i, tmp);
269
+ beg += step;
270
+ }
271
+ } else {
272
+ tmp = rb_gsl_obj_to_gsl_complex(argv[1], NULL);
273
+ gsl_vector_complex_set_all(&vv.vector, tmp);
274
+ }
275
+ }
276
+
277
+ static VALUE rb_gsl_vector_complex_set(int argc, VALUE *argv, VALUE obj)
278
+ {
279
+ gsl_vector_complex *v = NULL;
280
+ gsl_complex tmp;
281
+ VALUE other;
282
+ int ii;
283
+
284
+ if(argc < 1 || argc > 4) {
285
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-4)", argc);
286
+ }
287
+
288
+ Data_Get_Struct(obj, gsl_vector_complex, v);
289
+ other = argv[argc-1];
290
+
291
+ if(argc == 1) {
292
+ // // If assigning from another vector
293
+ if(VECTOR_P(other) || VECTOR_COMPLEX_P(other)) {
294
+ // treat as assignment to v.subvector(...)
295
+ rb_gsl_vector_complex_set_subvector(argc-1, argv, v, other);
296
+ } else {
297
+ // treat as set_all
298
+ rb_gsl_vector_complex_set_all(argc, argv, obj);
299
+ }
300
+ } else if(argc == 2 && TYPE(argv[0]) == T_FIXNUM) {
301
+ // v[i] = x
302
+ ii = FIX2INT(argv[0]);
303
+ if(ii < 0) ii += v->size;
304
+ // Get/make GSL::Complex from second arg
305
+ tmp = gsl_vector_complex_get(v, ii);
306
+ rb_gsl_obj_to_gsl_complex(argv[1], &tmp);
307
+ gsl_vector_complex_set(v, (size_t)ii, tmp);
308
+ } else {
309
+ // assignment to v.subvector(...)
310
+ rb_gsl_vector_complex_set_subvector(argc-1, argv, v, other);
311
+ }
312
+
313
+ return obj;
314
+ }
315
+
316
+ static VALUE rb_gsl_vector_complex_each(VALUE obj)
317
+ {
318
+ gsl_vector_complex *v = NULL;
319
+ VALUE vz;
320
+ gsl_complex * zp;
321
+ size_t i;
322
+ Data_Get_Struct(obj, gsl_vector_complex, v);
323
+ for (i = 0; i < v->size; i++) {
324
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
325
+ *zp = gsl_vector_complex_get(v, i);
326
+ rb_yield(vz);
327
+ }
328
+ return obj;
329
+ }
330
+
331
+ static VALUE rb_gsl_vector_complex_reverse_each(VALUE obj)
332
+ {
333
+ gsl_vector_complex *v = NULL;
334
+ VALUE vz;
335
+ gsl_complex * zp;
336
+ size_t i;
337
+ Data_Get_Struct(obj, gsl_vector_complex, v);
338
+ for (i = v->size-1; i >= 0; i--) {
339
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
340
+ *zp = gsl_vector_complex_get(v, i);
341
+ rb_yield(vz);
342
+ }
343
+ return obj;
344
+ }
345
+
346
+ static VALUE rb_gsl_vector_complex_each_index(VALUE obj)
347
+ {
348
+ gsl_vector_complex *v = NULL;
349
+ size_t i;
350
+ Data_Get_Struct(obj, gsl_vector_complex, v);
351
+ for (i = 0; i < v->size; i++) rb_yield(INT2FIX(i));
352
+ return obj;
353
+ }
354
+
355
+ static VALUE rb_gsl_vector_complex_reverse_each_index(VALUE obj)
356
+ {
357
+ gsl_vector_complex *v = NULL;
358
+ size_t i;
359
+ Data_Get_Struct(obj, gsl_vector_complex, v);
360
+ for (i = v->size-1; i >= 0; i--) {
361
+ rb_yield(INT2FIX(i));
362
+ if (i == 0) break;
363
+ }
364
+ return obj;
365
+ }
366
+
367
+ static void rb_gsl_vector_complex_collect_native(gsl_vector_complex *src, gsl_vector_complex *dst)
368
+ {
369
+ VALUE vz;
370
+ gsl_complex * zp;
371
+ size_t i;
372
+ for (i = 0; i < src->size; i++) {
373
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
374
+ *zp = gsl_vector_complex_get(src, i);
375
+ vz = rb_yield(vz);
376
+ CHECK_COMPLEX(vz);
377
+ Data_Get_Struct(vz, gsl_complex, zp);
378
+ gsl_vector_complex_set(dst, i, *zp);
379
+ }
380
+ }
381
+
382
+ static VALUE rb_gsl_vector_complex_collect(VALUE obj)
383
+ {
384
+ gsl_vector_complex *v = NULL, *vnew;
385
+ Data_Get_Struct(obj, gsl_vector_complex, v);
386
+ vnew = gsl_vector_complex_alloc(v->size);
387
+ rb_gsl_vector_complex_collect_native(v, vnew);
388
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
389
+ }
390
+
391
+ static VALUE rb_gsl_vector_complex_collect_bang(VALUE obj)
392
+ {
393
+ gsl_vector_complex *v = NULL;
394
+ Data_Get_Struct(obj, gsl_vector_complex, v);
395
+ rb_gsl_vector_complex_collect_native(v, v);
396
+ return obj;
397
+ }
398
+
399
+ static VALUE rb_gsl_vector_complex_set_zero(VALUE obj)
400
+ {
401
+ gsl_vector_complex *v = NULL;
402
+ Data_Get_Struct(obj, gsl_vector_complex, v);
403
+ gsl_vector_complex_set_zero(v);
404
+ return obj;
405
+ }
406
+
407
+ static VALUE rb_gsl_vector_complex_set_basis(VALUE obj, VALUE ii)
408
+ {
409
+ gsl_vector_complex *v = NULL;
410
+ CHECK_FIXNUM(ii);
411
+ Data_Get_Struct(obj, gsl_vector_complex, v);
412
+ gsl_vector_complex_set_basis(v, FIX2INT(ii));
413
+ return obj;
414
+ }
415
+
416
+ static VALUE rb_gsl_vector_complex_to_s(VALUE obj)
417
+ {
418
+ gsl_vector_complex *v = NULL;
419
+ char buf[64];
420
+ size_t i;
421
+ VALUE str;
422
+ gsl_complex * z;
423
+
424
+ Data_Get_Struct(obj, gsl_vector_complex, v);
425
+ if (v->size == 0) return rb_str_new2("[ ]");
426
+ str = rb_str_new2("[ ");
427
+ if (VECTOR_COMPLEX_COL_P(obj)) {
428
+ for (i = 0; i < v->size; i++) {
429
+ if (i != 0) {
430
+ rb_str_cat(str, " ", 2);
431
+ }
432
+ z = GSL_COMPLEX_AT(v, i);
433
+ sprintf(buf, "[%4.3e %4.3e]", GSL_REAL(*z), GSL_IMAG(*z));
434
+ if (i != v->size-1) strcat(buf, "\n");
435
+ rb_str_cat(str, buf, strlen(buf));
436
+ if (i >= 10 && i != v->size-1) {
437
+ rb_str_cat(str, " ...", 5);
438
+ break;
439
+ }
440
+ }
441
+ } else {
442
+ z = GSL_COMPLEX_AT(v, 0);
443
+ sprintf(buf, "[%4.3e %4.3e]", GSL_REAL(*z), GSL_IMAG(*z));
444
+ rb_str_cat(str, buf, strlen(buf));
445
+ for (i = 1; i < v->size; i++) {
446
+ z = GSL_COMPLEX_AT(v, i);
447
+ sprintf(buf, " [%4.3e %4.3e]", GSL_REAL(*z), GSL_IMAG(*z));
448
+ rb_str_cat(str, buf, strlen(buf));
449
+ if (i >= 10 && i != v->size-1) {
450
+ rb_str_cat(str, " ...", 4);
451
+ break;
452
+ }
453
+ }
454
+ }
455
+ rb_str_cat(str, " ]", 2);
456
+ return str;
457
+ }
458
+
459
+ static VALUE rb_gsl_vector_complex_inspect(VALUE obj)
460
+ {
461
+ VALUE str;
462
+ char buf[128];
463
+ gsl_vector_complex *v;
464
+
465
+ Data_Get_Struct(obj, gsl_vector_complex, v);
466
+ sprintf(buf, "#<%s[%lu]:%#lx>\n", rb_class2name(CLASS_OF(obj)), v->size, NUM2ULONG(rb_obj_id(obj)));
467
+ str = rb_str_new2(buf);
468
+ return rb_str_concat(str, rb_gsl_vector_complex_to_s(obj));
469
+ }
470
+
471
+ /*static VALUE rb_gsl_vector_complex_fprintf(VALUE obj, VALUE io, VALUE format)*/
472
+ static VALUE rb_gsl_vector_complex_fprintf(int argc, VALUE *argv, VALUE obj)
473
+ {
474
+ gsl_vector_complex *h = NULL;
475
+ FILE *fp = NULL;
476
+ int status, flag = 0;
477
+ if (argc != 1 && argc != 2) {
478
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
479
+ }
480
+ Data_Get_Struct(obj, gsl_vector_complex, h);
481
+ fp = rb_gsl_open_writefile(argv[0], &flag);
482
+ if (argc == 2) {
483
+ Check_Type(argv[1], T_STRING);
484
+ status = gsl_vector_complex_fprintf(fp, h, STR2CSTR(argv[1]));
485
+ } else {
486
+ status = gsl_vector_complex_fprintf(fp, h, "%4.3e");
487
+ }
488
+ if (flag == 1) fclose(fp);
489
+ return INT2FIX(status);
490
+ }
491
+
492
+ /*static VALUE rb_gsl_vector_complex_printf(VALUE obj, VALUE format)*/
493
+ static VALUE rb_gsl_vector_complex_printf(int argc, VALUE *argv, VALUE obj)
494
+ {
495
+ gsl_vector_complex *h = NULL;
496
+ int status;
497
+ Data_Get_Struct(obj, gsl_vector_complex, h);
498
+ if (argc == 1) {
499
+ Check_Type(argv[0], T_STRING);
500
+ status = gsl_vector_complex_fprintf(stdout, h, STR2CSTR(argv[0]));
501
+ } else {
502
+ status = gsl_vector_complex_fprintf(stdout, h, "%4.3e");
503
+ }
504
+ return INT2FIX(status);
505
+ }
506
+ /*
507
+ static VALUE rb_gsl_vector_complex_print(VALUE obj);
508
+ static VALUE rb_gsl_vector_complex_inspect(VALUE obj)
509
+ {
510
+ gsl_vector_complex *h = NULL;
511
+ Data_Get_Struct(obj, gsl_vector_complex, h);
512
+ printf("%s\n", rb_class2name(CLASS_OF(obj)));
513
+ rb_gsl_vector_complex_print(obj);
514
+ return Qtrue;
515
+ }
516
+ */
517
+ static VALUE rb_gsl_vector_complex_print(VALUE obj)
518
+ {
519
+ gsl_vector_complex *h = NULL;
520
+ gsl_complex *z = NULL;
521
+ size_t i;
522
+ Data_Get_Struct(obj, gsl_vector_complex, h);
523
+ printf("[ ");
524
+ if (VECTOR_COMPLEX_COL_P(obj)) {
525
+ printf("\n");
526
+ for (i = 0; i < h->size; i++) {
527
+ z = GSL_COMPLEX_AT(h, i);
528
+ printf(" [%4.3e %4.3e]\n", GSL_REAL(*z), GSL_IMAG(*z));
529
+ }
530
+ } else {
531
+ for (i = 0; i < h->size; i++) {
532
+ z = GSL_COMPLEX_AT(h, i);
533
+ printf("[%4.3e %4.3e] ", GSL_REAL(*z), GSL_IMAG(*z));
534
+ }
535
+ }
536
+ printf("]\n");
537
+ return obj;
538
+ }
539
+
540
+ static VALUE rb_gsl_vector_complex_fwrite(VALUE obj, VALUE io)
541
+ {
542
+ gsl_vector_complex *h = NULL;
543
+ FILE *fp = NULL;
544
+ int status, flag = 0;
545
+ Data_Get_Struct(obj, gsl_vector_complex, h);
546
+ fp = rb_gsl_open_writefile(io, &flag);
547
+ status = gsl_vector_complex_fwrite(fp, h);
548
+ if (flag == 1) fclose(fp);
549
+ return INT2FIX(status);
550
+ }
551
+
552
+ static VALUE rb_gsl_vector_complex_fread(VALUE obj, VALUE io)
553
+ {
554
+ gsl_vector_complex *h = NULL;
555
+ FILE *f = NULL;
556
+ int status, flag = 0;
557
+ Data_Get_Struct(obj, gsl_vector_complex, h);
558
+ f = rb_gsl_open_writefile(io, &flag);
559
+ status = gsl_vector_complex_fread(f, h);
560
+ if (flag == 1) fclose(f);
561
+ return INT2FIX(status);
562
+ }
563
+
564
+ static VALUE rb_gsl_vector_complex_fscanf(VALUE obj, VALUE io)
565
+ {
566
+ gsl_vector_complex *h = NULL;
567
+ FILE *f = NULL;
568
+ int status, flag = 0;
569
+ Data_Get_Struct(obj, gsl_vector_complex, h);
570
+ f = rb_gsl_open_writefile(io, &flag);
571
+ status = gsl_vector_complex_fscanf(f, h);
572
+ if (flag == 1) fclose(f);
573
+ return INT2FIX(status);
574
+ }
575
+
576
+ static VALUE rb_gsl_vector_complex_real(VALUE obj)
577
+ {
578
+ gsl_vector_complex *c = NULL;
579
+ gsl_vector_view *vv = NULL;
580
+ Data_Get_Struct(obj, gsl_vector_complex, c);
581
+ vv = gsl_vector_view_alloc();
582
+ *vv = gsl_vector_complex_real(c);
583
+ if (VECTOR_COMPLEX_ROW_P(obj))
584
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, vv);
585
+ else
586
+ return Data_Wrap_Struct(cgsl_vector_col_view, 0, gsl_vector_view_free, vv);
587
+ }
588
+
589
+ static VALUE rb_gsl_vector_complex_imag(VALUE obj)
590
+ {
591
+ gsl_vector_complex *c = NULL;
592
+ gsl_vector_view *vv = NULL;
593
+ Data_Get_Struct(obj, gsl_vector_complex, c);
594
+ vv = gsl_vector_view_alloc();
595
+ *vv = gsl_vector_complex_imag(c);
596
+ if (VECTOR_COMPLEX_ROW_P(obj))
597
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, vv);
598
+ else
599
+ return Data_Wrap_Struct(cgsl_vector_col_view, 0, gsl_vector_view_free, vv);
600
+ }
601
+
602
+ static VALUE rb_gsl_vector_complex_set_real(VALUE obj, VALUE val)
603
+ {
604
+ gsl_vector_complex *v = NULL;
605
+ gsl_vector_view vv;
606
+ double d = NUM2DBL(val);
607
+ Data_Get_Struct(obj, gsl_vector_complex, v);
608
+ vv = gsl_vector_complex_real(v);
609
+ gsl_vector_set_all(&vv.vector, d);
610
+ return obj;
611
+ }
612
+
613
+ static VALUE rb_gsl_vector_complex_set_imag(VALUE obj, VALUE val)
614
+ {
615
+ gsl_vector_complex *v = NULL;
616
+ gsl_vector_view vv;
617
+ double d = NUM2DBL(val);
618
+ Data_Get_Struct(obj, gsl_vector_complex, v);
619
+ vv = gsl_vector_complex_imag(v);
620
+ gsl_vector_set_all(&vv.vector, d);
621
+ return obj;
622
+ }
623
+
624
+ static VALUE rb_gsl_vector_complex_conj(VALUE obj)
625
+ {
626
+ size_t i;
627
+ gsl_vector_complex *vin = NULL;
628
+ gsl_vector_complex *vout = NULL;
629
+ Data_Get_Struct(obj, gsl_vector_complex, vin);
630
+ vout = gsl_vector_complex_alloc(vin->size);
631
+ for(i=0; i<vin->size; i++) {
632
+ gsl_vector_complex_set(vout, i,
633
+ gsl_complex_conjugate(
634
+ gsl_vector_complex_get(vin, i)));
635
+ }
636
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vout);
637
+ }
638
+
639
+ static VALUE rb_gsl_vector_complex_conj_bang(VALUE obj)
640
+ {
641
+ size_t i;
642
+ gsl_vector_complex *v = NULL;
643
+ Data_Get_Struct(obj, gsl_vector_complex, v);
644
+ for(i=0; i<v->size; i++) {
645
+ gsl_vector_complex_set(v, i,
646
+ gsl_complex_conjugate(
647
+ gsl_vector_complex_get(v, i)));
648
+ }
649
+ return obj;
650
+ }
651
+
652
+ static VALUE rb_gsl_vector_complex_to_a(VALUE obj)
653
+ {
654
+ gsl_vector_complex *c = NULL;
655
+ gsl_complex *z = NULL;
656
+ size_t i, j;
657
+ VALUE ary;
658
+ Data_Get_Struct(obj, gsl_vector_complex, c);
659
+ ary = rb_ary_new2(c->size*2);
660
+ for (i = 0, j = 0; i < c->size; i++, j+=2) {
661
+ z = GSL_COMPLEX_AT(c, i);
662
+ rb_ary_store(ary, j, rb_float_new(GSL_REAL(*z)));
663
+ rb_ary_store(ary, j+1, rb_float_new(GSL_IMAG(*z)));
664
+ }
665
+ return ary;
666
+ }
667
+
668
+ static VALUE rb_gsl_vector_complex_to_a2(VALUE obj)
669
+ {
670
+ gsl_vector_complex *c = NULL;
671
+ gsl_complex *znew = NULL, *z = NULL;
672
+ size_t i;
673
+ VALUE ary, vz;
674
+ Data_Get_Struct(obj, gsl_vector_complex, c);
675
+ ary = rb_ary_new2(c->size);
676
+ for (i = 0; i < c->size; i++) {
677
+ z = GSL_COMPLEX_AT(c, i);
678
+ znew = make_complex(z->dat[0], z->dat[1]);
679
+ vz = Data_Wrap_Struct(cgsl_complex, 0, free, znew);
680
+ rb_ary_store(ary, i, vz);
681
+ }
682
+ return ary;
683
+ }
684
+
685
+ gsl_vector_complex_view* gsl_vector_complex_view_alloc()
686
+ {
687
+ gsl_vector_complex_view *vv = NULL;
688
+ vv = ALLOC(gsl_vector_complex_view);
689
+ if (vv == NULL) rb_raise(rb_eRuntimeError, "malloc failed");
690
+ return vv;
691
+ }
692
+
693
+ void gsl_vector_complex_view_free(gsl_vector_view * vv)
694
+ {
695
+ free((gsl_vector_complex_view *) vv);
696
+ }
697
+
698
+ static VALUE rb_gsl_vector_complex_subvector(int argc, VALUE *argv, VALUE obj)
699
+ {
700
+ gsl_vector_complex *v = NULL;
701
+ gsl_vector_complex_view *vv = NULL;
702
+ size_t offset, stride, n;
703
+ Data_Get_Struct(obj, gsl_vector_complex, v);
704
+ parse_subvector_args(argc, argv, v->size, &offset, &stride, &n);
705
+ vv = gsl_vector_complex_view_alloc();
706
+ *vv = gsl_vector_complex_subvector_with_stride(v, offset, stride, n);
707
+ if (VECTOR_COMPLEX_ROW_P(obj))
708
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
709
+ else
710
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, gsl_vector_complex_view_free, vv);
711
+ }
712
+
713
+ static VALUE rb_gsl_vector_complex_subvector_with_stride(VALUE obj, VALUE o, VALUE s, VALUE nn)
714
+ {
715
+ gsl_vector_complex *v = NULL;
716
+ gsl_vector_complex_view *vv = NULL;
717
+ int offset;
718
+ CHECK_FIXNUM(o); CHECK_FIXNUM(nn); CHECK_FIXNUM(s);
719
+ offset = NUM2INT(o);
720
+ Data_Get_Struct(obj, gsl_vector_complex, v);
721
+ if(offset < 0) {
722
+ offset += v->size;
723
+ }
724
+ vv = gsl_vector_complex_view_alloc();
725
+ *vv = gsl_vector_complex_subvector_with_stride(v, (size_t)offset, FIX2INT(s), FIX2INT(nn));
726
+ if (VECTOR_COMPLEX_ROW_P(obj))
727
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
728
+ else
729
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, gsl_vector_complex_view_free, vv);
730
+ }
731
+
732
+ /* singleton */
733
+ static VALUE rb_gsl_vector_complex_memcpy(VALUE obj, VALUE dst, VALUE src)
734
+ {
735
+ gsl_vector_complex *v = NULL, *dest = NULL;
736
+ CHECK_VECTOR_COMPLEX(dst);
737
+ CHECK_VECTOR_COMPLEX(src);
738
+ Data_Get_Struct(dst, gsl_vector_complex, dest);
739
+ Data_Get_Struct(src, gsl_vector_complex, v);
740
+ gsl_vector_complex_memcpy(dest, v);
741
+ return dst;
742
+ }
743
+
744
+ static VALUE rb_gsl_vector_complex_clone(VALUE obj)
745
+ {
746
+ gsl_vector_complex *v = NULL, *vnew = NULL;
747
+ Data_Get_Struct(obj, gsl_vector_complex, v);
748
+ vnew = gsl_vector_complex_alloc(v->size);
749
+ if (vnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
750
+ gsl_vector_complex_memcpy(vnew, v);
751
+ if (VECTOR_COMPLEX_ROW_P(obj))
752
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
753
+ else
754
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, vnew);
755
+ }
756
+
757
+ static VALUE rb_gsl_vector_complex_reverse(VALUE obj)
758
+ {
759
+ gsl_vector_complex *v = NULL;
760
+ Data_Get_Struct(obj, gsl_vector_complex, v);
761
+ gsl_vector_complex_reverse(v);
762
+ return obj;
763
+ }
764
+
765
+ static VALUE rb_gsl_vector_complex_reverse2(VALUE obj)
766
+ {
767
+ gsl_vector_complex *v = NULL, *vnew = NULL;
768
+ Data_Get_Struct(obj, gsl_vector_complex, v);
769
+ vnew = gsl_vector_complex_alloc(v->size);
770
+ gsl_vector_complex_memcpy(vnew, v);
771
+ gsl_vector_complex_reverse(vnew);
772
+ if (VECTOR_COMPLEX_ROW_P(obj))
773
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
774
+ else
775
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, vnew);
776
+ }
777
+
778
+ static VALUE rb_gsl_vector_complex_swap_elements(VALUE obj, VALUE i, VALUE j)
779
+ {
780
+ gsl_vector_complex *v = NULL;
781
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
782
+ Data_Get_Struct(obj, gsl_vector_complex, v);
783
+ gsl_vector_complex_swap_elements(v, FIX2INT(i), FIX2INT(j));
784
+ return obj;
785
+ }
786
+
787
+ static VALUE rb_gsl_vector_complex_fftshift_bang(VALUE obj)
788
+ {
789
+ gsl_vector_complex *v = NULL;
790
+ gsl_complex tmp;
791
+ size_t i, n;
792
+
793
+ Data_Get_Struct(obj, gsl_vector_complex, v);
794
+ n = v->size;
795
+ if(n & 1) {
796
+ // length is odd
797
+ tmp = gsl_vector_complex_get(v,0);
798
+ for(i = 0; i < n/2; i++) {
799
+ gsl_vector_complex_set(v, i, gsl_vector_complex_get(v, i+n/2+1));
800
+ gsl_vector_complex_set(v, i+n/2+1, gsl_vector_complex_get(v, i+1));
801
+ }
802
+ gsl_vector_complex_set(v, n/2, tmp);
803
+ } else {
804
+ // length is even
805
+ for(i = 0; i < n/2; i++) {
806
+ gsl_vector_complex_swap_elements(v, i, i+n/2);
807
+ }
808
+ }
809
+
810
+ return obj;
811
+ }
812
+
813
+ static VALUE rb_gsl_vector_complex_fftshift(VALUE obj)
814
+ {
815
+ gsl_vector_complex *v, *vnew;
816
+ gsl_vector_complex_view vv, vvnew;
817
+ size_t n;
818
+
819
+ Data_Get_Struct(obj, gsl_vector_complex, v);
820
+ n = v->size;
821
+ vnew = gsl_vector_complex_alloc(n);
822
+ // Copy low to high
823
+ vv = gsl_vector_complex_subvector(v, 0, (n+1)/2);
824
+ vvnew = gsl_vector_complex_subvector(vnew, n/2, (n+1)/2);
825
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
826
+ // Copy high to low
827
+ vv = gsl_vector_complex_subvector(v, (n+1)/2, n/2);
828
+ vvnew = gsl_vector_complex_subvector(vnew, 0, n/2);
829
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
830
+
831
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
832
+ }
833
+
834
+ static VALUE rb_gsl_vector_complex_ifftshift_bang(VALUE obj)
835
+ {
836
+ gsl_vector_complex *v = NULL;
837
+ gsl_complex tmp;
838
+ size_t i, n;
839
+
840
+ Data_Get_Struct(obj, gsl_vector_complex, v);
841
+ n = v->size;
842
+ if(n & 1) {
843
+ // length is odd
844
+ tmp = gsl_vector_complex_get(v,n/2);
845
+ for(i = n/2; i > 0; i--) {
846
+ gsl_vector_complex_set(v, i, gsl_vector_complex_get(v, i+n/2));
847
+ gsl_vector_complex_set(v, i+n/2, gsl_vector_complex_get(v, i-1));
848
+ }
849
+ gsl_vector_complex_set(v, 0, tmp);
850
+ } else {
851
+ // length is even
852
+ for(i = 0; i < n/2; i++) {
853
+ gsl_vector_complex_swap_elements(v, i, i+n/2);
854
+ }
855
+ }
856
+
857
+ return obj;
858
+ }
859
+
860
+ static VALUE rb_gsl_vector_complex_ifftshift(VALUE obj)
861
+ {
862
+ return rb_gsl_vector_complex_ifftshift_bang(rb_gsl_vector_complex_clone(obj));
863
+ gsl_vector_complex *v, *vnew;
864
+ gsl_vector_complex_view vv, vvnew;
865
+ size_t n;
866
+
867
+ Data_Get_Struct(obj, gsl_vector_complex, v);
868
+ n = v->size;
869
+ vnew = gsl_vector_complex_alloc(n);
870
+ // Copy high to low
871
+ vv = gsl_vector_complex_subvector(vnew, n/2, (n+1)/2);
872
+ vvnew = gsl_vector_complex_subvector(v, 0, (n+1)/2);
873
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
874
+ // Copy low to high
875
+ vv = gsl_vector_complex_subvector(vnew, 0, n/2);
876
+ vvnew = gsl_vector_complex_subvector(v, (n+1)/2, n/2);
877
+ gsl_vector_complex_memcpy(&vvnew.vector, &vv.vector);
878
+
879
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
880
+ }
881
+
882
+ static VALUE rb_gsl_vector_complex_isnull(VALUE obj)
883
+ {
884
+ gsl_vector_complex *v = NULL;
885
+ Data_Get_Struct(obj, gsl_vector_complex, v);
886
+ if (gsl_vector_complex_isnull(v)) return Qtrue;
887
+ else return Qfalse;
888
+ }
889
+
890
+ static VALUE rb_gsl_vector_complex_matrix_view(int argc, VALUE *argv, VALUE obj)
891
+ {
892
+ gsl_vector_complex *v = NULL;
893
+ gsl_matrix_complex_view *mv = NULL;
894
+ Data_Get_Struct(obj, gsl_vector_complex, v);
895
+ switch (argc) {
896
+ case 2:
897
+ mv = gsl_matrix_complex_view_alloc();
898
+ *mv = gsl_matrix_complex_view_vector(v, FIX2INT(argv[0]), FIX2INT(argv[1]));
899
+ break;
900
+ case 3:
901
+ mv = gsl_matrix_complex_view_alloc();
902
+ *mv = gsl_matrix_complex_view_vector_with_tda(v, FIX2INT(argv[0]), FIX2INT(argv[1]),
903
+ FIX2INT(argv[2]));
904
+ break;
905
+ default:
906
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
907
+ break;
908
+ }
909
+ return Data_Wrap_Struct(cgsl_matrix_complex_view, 0, gsl_matrix_complex_view_free, mv);
910
+ }
911
+
912
+ static VALUE rb_gsl_vector_complex_matrix_view_with_tda(VALUE obj, VALUE nn1, VALUE nn2,
913
+ VALUE tda)
914
+ {
915
+ gsl_vector_complex *v = NULL;
916
+ gsl_matrix_complex_view *mv = NULL;
917
+ CHECK_FIXNUM(nn1); CHECK_FIXNUM(nn2); CHECK_FIXNUM(tda);
918
+ Data_Get_Struct(obj, gsl_vector_complex, v);
919
+ mv = gsl_matrix_complex_view_alloc();
920
+ if (mv == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
921
+ *mv = gsl_matrix_complex_view_vector_with_tda(v, FIX2INT(nn1), FIX2INT(nn2), FIX2INT(tda));
922
+ return Data_Wrap_Struct(cgsl_matrix_complex_view, 0, gsl_matrix_complex_view_free, mv);
923
+ }
924
+
925
+ static VALUE rb_gsl_vector_complex_trans(VALUE obj)
926
+ {
927
+ gsl_vector_complex *v = NULL, *vnew = NULL;
928
+ Data_Get_Struct(obj, gsl_vector_complex, v);
929
+ vnew = make_vector_complex_clone(v);
930
+ if (VECTOR_COMPLEX_ROW_P(obj))
931
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, vnew);
932
+ else if (VECTOR_COMPLEX_COL_P(obj))
933
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
934
+ else {
935
+ rb_raise(rb_eTypeError, "wrong type");
936
+ }
937
+ }
938
+
939
+ static VALUE rb_gsl_vector_complex_trans2(VALUE obj)
940
+ {
941
+ if (CLASS_OF(obj) == cgsl_vector_complex)
942
+ RBASIC(obj)->klass = cgsl_vector_complex_col;
943
+ else if (CLASS_OF(obj) == cgsl_vector_complex_col)
944
+ RBASIC(obj)->klass = cgsl_vector_complex;
945
+ else {
946
+ rb_raise(rb_eRuntimeError, "method trans! for %s is forbidden",
947
+ rb_class2name(CLASS_OF(obj)));
948
+ }
949
+ return obj;
950
+ }
951
+
952
+ static VALUE rb_gsl_vector_complex_to_real(VALUE obj)
953
+ {
954
+ gsl_vector_complex *cv = NULL;
955
+ gsl_vector *v = NULL;
956
+ gsl_complex z;
957
+ size_t i;
958
+ Data_Get_Struct(obj, gsl_vector_complex, cv);
959
+ v = gsl_vector_alloc(cv->size);
960
+ if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
961
+ for (i = 0; i < cv->size; i++) {
962
+ z = gsl_vector_complex_get(cv, i);
963
+ gsl_vector_set(v, i, GSL_REAL(z));
964
+ }
965
+ if (VECTOR_COMPLEX_ROW_P(obj))
966
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
967
+ else
968
+ return Data_Wrap_Struct(cgsl_vector_col, 0, gsl_vector_free, v);
969
+ }
970
+
971
+ enum {
972
+ GSL_VECTOR_COMPLEX_ADD,
973
+ GSL_VECTOR_COMPLEX_SUB,
974
+ GSL_VECTOR_COMPLEX_MUL,
975
+ GSL_VECTOR_COMPLEX_DIV,
976
+ GSL_VECTOR_COMPLEX_ADD_BANG,
977
+ GSL_VECTOR_COMPLEX_SUB_BANG,
978
+ GSL_VECTOR_COMPLEX_MUL_BANG,
979
+ GSL_VECTOR_COMPLEX_DIV_BANG,
980
+ };
981
+
982
+ static VALUE rb_gsl_vector_complex_arithmetics(int flag, VALUE obj, VALUE bb);
983
+
984
+ static VALUE rb_gsl_vector_complex_arithmetics(int flag, VALUE obj, VALUE bb)
985
+ {
986
+ gsl_vector *b = NULL;
987
+ gsl_vector_complex *cv = NULL, *cvnew = NULL, *cb = NULL;
988
+ gsl_complex *c = NULL, z;
989
+ Data_Get_Struct(obj, gsl_vector_complex, cv);
990
+ switch (flag) {
991
+ case GSL_VECTOR_COMPLEX_ADD:
992
+ case GSL_VECTOR_COMPLEX_SUB:
993
+ case GSL_VECTOR_COMPLEX_MUL:
994
+ case GSL_VECTOR_COMPLEX_DIV:
995
+ cvnew = make_vector_complex_clone(cv);
996
+ obj = Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, cvnew);
997
+ break;
998
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
999
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1000
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1001
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1002
+ cvnew = cv;
1003
+ break;
1004
+ default:
1005
+ rb_raise(rb_eRuntimeError, "unknown operation");
1006
+ break;
1007
+ }
1008
+ switch (TYPE(bb)) {
1009
+ case T_FLOAT:
1010
+ case T_FIXNUM:
1011
+ case T_BIGNUM:
1012
+ z = gsl_complex_rect(NUM2DBL(bb), 0.0);
1013
+ switch (flag) {
1014
+ case GSL_VECTOR_COMPLEX_ADD:
1015
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1016
+ gsl_vector_complex_add_constant(cvnew, z);
1017
+ break;
1018
+ case GSL_VECTOR_COMPLEX_SUB:
1019
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1020
+ gsl_vector_complex_add_constant(cvnew, gsl_complex_negative(z));
1021
+ break;
1022
+ case GSL_VECTOR_COMPLEX_MUL:
1023
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1024
+ gsl_vector_complex_scale(cvnew, z);
1025
+ break;
1026
+ case GSL_VECTOR_COMPLEX_DIV:
1027
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1028
+ gsl_vector_complex_scale(cvnew, gsl_complex_inverse(z));
1029
+ break;
1030
+ }
1031
+ break;
1032
+ default:
1033
+ if (VECTOR_P(bb)) {
1034
+ Data_Get_Struct(bb, gsl_vector, b);
1035
+ cb = vector_to_complex(b);
1036
+ switch (flag) {
1037
+ case GSL_VECTOR_COMPLEX_ADD:
1038
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1039
+ gsl_vector_complex_add(cvnew, cb);
1040
+ break;
1041
+ case GSL_VECTOR_COMPLEX_SUB:
1042
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1043
+ gsl_vector_complex_sub(cvnew, cb);
1044
+ break;
1045
+ case GSL_VECTOR_COMPLEX_MUL:
1046
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1047
+ gsl_vector_complex_mul(cvnew, cb);
1048
+ break;
1049
+ case GSL_VECTOR_COMPLEX_DIV:
1050
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1051
+ gsl_vector_complex_div(cvnew, cb);
1052
+ break;
1053
+ }
1054
+ gsl_vector_complex_free(cb);
1055
+ } else if (VECTOR_COMPLEX_P(bb)) {
1056
+ Data_Get_Struct(bb, gsl_vector_complex, cb);
1057
+ switch (flag) {
1058
+ case GSL_VECTOR_COMPLEX_ADD:
1059
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1060
+ gsl_vector_complex_add(cvnew, cb);
1061
+ break;
1062
+ case GSL_VECTOR_COMPLEX_SUB:
1063
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1064
+ gsl_vector_complex_sub(cvnew, cb);
1065
+ break;
1066
+ case GSL_VECTOR_COMPLEX_MUL:
1067
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1068
+ gsl_vector_complex_mul(cvnew, cb);
1069
+ break;
1070
+ case GSL_VECTOR_COMPLEX_DIV:
1071
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1072
+ gsl_vector_complex_div(cvnew, cb);
1073
+ break;
1074
+ }
1075
+ } else if (COMPLEX_P(bb)) {
1076
+ Data_Get_Struct(bb, gsl_complex, c);
1077
+ switch (flag) {
1078
+ case GSL_VECTOR_COMPLEX_ADD:
1079
+ case GSL_VECTOR_COMPLEX_ADD_BANG:
1080
+ gsl_vector_complex_add_constant(cvnew, *c);
1081
+ break;
1082
+ case GSL_VECTOR_COMPLEX_SUB:
1083
+ case GSL_VECTOR_COMPLEX_SUB_BANG:
1084
+ gsl_vector_complex_add_constant(cvnew, gsl_complex_negative(*c));
1085
+ break;
1086
+ case GSL_VECTOR_COMPLEX_MUL:
1087
+ case GSL_VECTOR_COMPLEX_MUL_BANG:
1088
+ gsl_vector_complex_scale(cvnew, *c);
1089
+ break;
1090
+ case GSL_VECTOR_COMPLEX_DIV:
1091
+ case GSL_VECTOR_COMPLEX_DIV_BANG:
1092
+ gsl_vector_complex_scale(cvnew, gsl_complex_inverse(*c));
1093
+ break;
1094
+ }
1095
+ } else {
1096
+ rb_raise(rb_eTypeError, "wrong type argument %s", rb_class2name(CLASS_OF(bb)));
1097
+ }
1098
+ break;
1099
+ }
1100
+ return obj;
1101
+ }
1102
+
1103
+ static VALUE rb_gsl_vector_complex_add(VALUE obj, VALUE bb)
1104
+ {
1105
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_ADD, obj, bb);
1106
+ }
1107
+
1108
+ static VALUE rb_gsl_vector_complex_sub(VALUE obj, VALUE bb)
1109
+ {
1110
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_SUB, obj, bb);
1111
+ }
1112
+
1113
+ static VALUE rb_gsl_vector_complex_mul(VALUE obj, VALUE bb)
1114
+ {
1115
+ VALUE argv[2];
1116
+ if (VECTOR_COMPLEX_ROW_P(obj) && VECTOR_COMPLEX_COL_P(bb)) {
1117
+ argv[0] = obj;
1118
+ argv[1] = bb;
1119
+ return rb_gsl_vector_complex_inner_product(2, argv, CLASS_OF(obj));
1120
+ }
1121
+ if (VECTOR_COMPLEX_COL_P(obj) && VECTOR_COMPLEX_ROW_P(bb)) {
1122
+ argv[0] = obj;
1123
+ argv[1] = bb;
1124
+ return rb_gsl_vector_complex_product_to_m(2, argv, CLASS_OF(obj));
1125
+ }
1126
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_MUL, obj, bb);
1127
+ }
1128
+
1129
+ static VALUE rb_gsl_vector_complex_div(VALUE obj, VALUE bb)
1130
+ {
1131
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_DIV, obj, bb);
1132
+ }
1133
+
1134
+ static VALUE rb_gsl_vector_complex_add_bang(VALUE obj, VALUE bb)
1135
+ {
1136
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_ADD_BANG, obj, bb);
1137
+ }
1138
+
1139
+ static VALUE rb_gsl_vector_complex_sub_bang(VALUE obj, VALUE bb)
1140
+ {
1141
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_SUB_BANG, obj, bb);
1142
+ }
1143
+
1144
+ static VALUE rb_gsl_vector_complex_mul_bang(VALUE obj, VALUE bb)
1145
+ {
1146
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_MUL_BANG, obj, bb);
1147
+ }
1148
+
1149
+ static VALUE rb_gsl_vector_complex_div_bang(VALUE obj, VALUE bb)
1150
+ {
1151
+ return rb_gsl_vector_complex_arithmetics(GSL_VECTOR_COMPLEX_DIV_BANG, obj, bb);
1152
+ }
1153
+
1154
+ static VALUE rb_gsl_vector_complex_coerce(VALUE obj, VALUE other)
1155
+ {
1156
+ gsl_vector_complex *cv = NULL, *cb = NULL;
1157
+ gsl_complex z;
1158
+ VALUE vv;
1159
+ Data_Get_Struct(obj, gsl_vector_complex, cv);
1160
+ switch (TYPE(other)) {
1161
+ case T_FLOAT:
1162
+ case T_FIXNUM:
1163
+ case T_BIGNUM:
1164
+ z = gsl_complex_rect(NUM2DBL(other), 0.0);
1165
+ cb = gsl_vector_complex_alloc(cv->size);
1166
+ if (cb == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
1167
+ gsl_vector_complex_set_all(cb, z);
1168
+ vv = Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, cb);
1169
+ return rb_ary_new3(2, vv, obj);
1170
+ break;
1171
+ default:
1172
+ rb_raise(rb_eTypeError, "GSL::Vector::Complex, operation not defined");
1173
+ break;
1174
+ }
1175
+ }
1176
+
1177
+ /* 2.Aug.2004 */
1178
+ static VALUE rb_gsl_vector_complex_inner_product(int argc, VALUE *argv, VALUE obj)
1179
+ {
1180
+ gsl_vector_complex *v = NULL, *v2 = NULL;
1181
+ gsl_complex prod, a, b, *z = NULL;
1182
+ size_t i;
1183
+ switch (TYPE(obj)) {
1184
+ case T_MODULE:
1185
+ case T_CLASS:
1186
+ case T_OBJECT:
1187
+ if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
1188
+ argc);
1189
+ if (!VECTOR_COMPLEX_ROW_P(argv[0]))
1190
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Complex expected)",
1191
+ rb_class2name(CLASS_OF(argv[0])));
1192
+ if (!VECTOR_COMPLEX_COL_P(argv[1]))
1193
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Complex::Col expected)",
1194
+ rb_class2name(CLASS_OF(argv[1])));
1195
+ Data_Get_Struct(argv[0], gsl_vector_complex, v);
1196
+ Data_Get_Struct(argv[1], gsl_vector_complex, v2);
1197
+ break;
1198
+ default:
1199
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
1200
+ argc);
1201
+ if (!VECTOR_COMPLEX_COL_P(argv[0]))
1202
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector::Complex::Col expected)",
1203
+ rb_class2name(CLASS_OF(argv[0])));
1204
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1205
+ Data_Get_Struct(argv[0], gsl_vector_complex, v2);
1206
+ break;
1207
+ }
1208
+ if (v->size != v2->size) rb_raise(rb_eRangeError, "vector lengths are different.");
1209
+ prod = gsl_complex_rect(0.0, 0.0);
1210
+ for (i = 0; i < v->size; i++) {
1211
+ a = gsl_vector_complex_get(v, i);
1212
+ b = gsl_vector_complex_get(v2, i);
1213
+ prod = gsl_complex_add(prod, gsl_complex_mul(a, b));
1214
+ }
1215
+ z = ALLOC(gsl_complex);
1216
+ *z = prod;
1217
+ return Data_Wrap_Struct(cgsl_complex, 0, free, z);
1218
+ }
1219
+
1220
+ static VALUE rb_gsl_vector_complex_product_to_m(int argc, VALUE *argv, VALUE obj)
1221
+ {
1222
+ gsl_vector_complex *v = NULL, *v2 = NULL;
1223
+ gsl_matrix_complex *m = NULL;
1224
+ gsl_complex a, b;
1225
+ size_t i, j;
1226
+ switch (TYPE(obj)) {
1227
+ case T_MODULE:
1228
+ case T_CLASS:
1229
+ case T_OBJECT:
1230
+ if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
1231
+ argc);
1232
+ if (!VECTOR_COMPLEX_COL_P(argv[0]))
1233
+ rb_raise(rb_eTypeError,
1234
+ "wrong argument type %s (GSL::Vector::Complex::Col expected)",
1235
+ rb_class2name(CLASS_OF(argv[0])));
1236
+ if (!VECTOR_COMPLEX_ROW_P(argv[1]))
1237
+ rb_raise(rb_eTypeError,
1238
+ "wrong argument type %s (GSL::Vector::Complex expected)",
1239
+ rb_class2name(CLASS_OF(argv[1])));
1240
+ Data_Get_Struct(argv[0], gsl_vector_complex, v);
1241
+ Data_Get_Struct(argv[1], gsl_vector_complex, v2);
1242
+ break;
1243
+ default:
1244
+ if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
1245
+ argc);
1246
+ if (!VECTOR_COMPLEX_ROW_P(argv[0]))
1247
+ rb_raise(rb_eTypeError,
1248
+ "wrong argument type %s (GSL::Vector::Complex expected)",
1249
+ rb_class2name(CLASS_OF(argv[0])));
1250
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1251
+ Data_Get_Struct(argv[0], gsl_vector_complex, v2);
1252
+ break;
1253
+ }
1254
+ m = gsl_matrix_complex_alloc(v->size, v2->size);
1255
+ for (i = 0; i < v->size; i++) {
1256
+ for (j = 0; j < v2->size; j++) {
1257
+ a = gsl_vector_complex_get(v, i);
1258
+ b = gsl_vector_complex_get(v2, j);
1259
+ gsl_matrix_complex_set(m, i, j, gsl_complex_mul(a, b));
1260
+ }
1261
+ }
1262
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, m);
1263
+ }
1264
+
1265
+ static VALUE rb_gsl_vector_complex_uplus(VALUE obj)
1266
+ {
1267
+ return obj;
1268
+ }
1269
+
1270
+ static VALUE rb_gsl_vector_complex_uminus(VALUE obj)
1271
+ {
1272
+ gsl_vector_complex *v = NULL, *vnew;
1273
+ size_t i;
1274
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1275
+ vnew = gsl_vector_complex_alloc(v->size);
1276
+ for (i = 0; i < v->size; i++) {
1277
+ gsl_vector_complex_set(vnew, i, gsl_complex_negative(gsl_vector_complex_get(v, i)));
1278
+ }
1279
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
1280
+ }
1281
+
1282
+ /*****/
1283
+ static VALUE rb_gsl_vector_complex_XXX(VALUE obj, double (*f)(gsl_complex))
1284
+ {
1285
+ gsl_vector_complex *m;
1286
+ gsl_vector *v;
1287
+ gsl_complex c;
1288
+ size_t i;
1289
+ Data_Get_Struct(obj, gsl_vector_complex, m);
1290
+ v = gsl_vector_alloc(m->size);
1291
+ for (i = 0; i < m->size; i++) {
1292
+ c = gsl_vector_complex_get(m, i);
1293
+ gsl_vector_set(v, i, (*f)(c));
1294
+ }
1295
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
1296
+ }
1297
+
1298
+ static VALUE rb_gsl_vector_complex_XXXz(VALUE obj, gsl_complex (*f)(gsl_complex))
1299
+ {
1300
+ gsl_vector_complex *m, *v;
1301
+ gsl_complex c;
1302
+ size_t i;
1303
+ Data_Get_Struct(obj, gsl_vector_complex, m);
1304
+ v = gsl_vector_complex_alloc(m->size);
1305
+ for (i = 0; i < m->size; i++) {
1306
+ c = gsl_vector_complex_get(m, i);
1307
+ gsl_vector_complex_set(v, i, (*f)(c));
1308
+ }
1309
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
1310
+ }
1311
+
1312
+ /* In-place version of rb_gsl_vector_complex_XXXz */
1313
+ static VALUE rb_gsl_vector_complex_XXXz_bang(VALUE obj, gsl_complex (*f)(gsl_complex))
1314
+ {
1315
+ gsl_vector_complex *v;
1316
+ gsl_complex c;
1317
+ size_t i;
1318
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1319
+ for (i = 0; i < v->size; i++) {
1320
+ c = gsl_vector_complex_get(v, i);
1321
+ gsl_vector_complex_set(v, i, (*f)(c));
1322
+ }
1323
+ return obj;
1324
+ }
1325
+
1326
+ static VALUE rb_gsl_vector_complex_XXXz2(VALUE obj, VALUE a,
1327
+ gsl_complex (*f)(gsl_complex, gsl_complex))
1328
+ {
1329
+ gsl_vector_complex *m, *v;
1330
+ gsl_complex c, *z;
1331
+ size_t i;
1332
+ CHECK_COMPLEX(a);
1333
+ Data_Get_Struct(obj, gsl_vector_complex, m);
1334
+ Data_Get_Struct(a, gsl_complex, z);
1335
+ v = gsl_vector_complex_alloc(m->size);
1336
+ for (i = 0; i < m->size; i++) {
1337
+ c = gsl_vector_complex_get(m, i);
1338
+ gsl_vector_complex_set(v, i, (*f)(c, *z));
1339
+ }
1340
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, v);
1341
+ }
1342
+
1343
+ static VALUE rb_gsl_vector_complex_XXXz2_bang(VALUE obj, VALUE a,
1344
+ gsl_complex (*f)(gsl_complex, gsl_complex))
1345
+ {
1346
+ gsl_vector_complex *v;
1347
+ gsl_complex c, *z;
1348
+ size_t i;
1349
+ CHECK_COMPLEX(a);
1350
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1351
+ Data_Get_Struct(a, gsl_complex, z);
1352
+ for (i = 0; i < v->size; i++) {
1353
+ c = gsl_vector_complex_get(v, i);
1354
+ gsl_vector_complex_set(v, i, (*f)(c, *z));
1355
+ }
1356
+ return obj;
1357
+ }
1358
+
1359
+ static VALUE rb_gsl_vector_complex_abs2(VALUE obj)
1360
+ {
1361
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_abs2);
1362
+ }
1363
+
1364
+ static VALUE rb_gsl_vector_complex_abs(VALUE obj)
1365
+ {
1366
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_abs);
1367
+ }
1368
+
1369
+ static VALUE rb_gsl_vector_complex_logabs(VALUE obj)
1370
+ {
1371
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_logabs);
1372
+ }
1373
+
1374
+ static VALUE rb_gsl_vector_complex_arg(VALUE obj)
1375
+ {
1376
+ return rb_gsl_vector_complex_XXX(obj, gsl_complex_arg);
1377
+ }
1378
+
1379
+ static VALUE rb_gsl_vector_complex_sqrt(VALUE obj)
1380
+ {
1381
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sqrt);
1382
+ }
1383
+
1384
+ static VALUE rb_gsl_vector_complex_sqrt_bang(VALUE obj)
1385
+ {
1386
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_sqrt);
1387
+ }
1388
+
1389
+ static VALUE rb_gsl_vector_complex_exp(VALUE obj)
1390
+ {
1391
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_exp);
1392
+ }
1393
+
1394
+ static VALUE rb_gsl_vector_complex_exp_bang(VALUE obj)
1395
+ {
1396
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_exp);
1397
+ }
1398
+
1399
+ static VALUE rb_gsl_vector_complex_pow(VALUE obj, VALUE a)
1400
+ {
1401
+ return rb_gsl_vector_complex_XXXz2(obj, a, gsl_complex_pow);
1402
+ }
1403
+
1404
+ static VALUE rb_gsl_vector_complex_pow_bang(VALUE obj, VALUE a)
1405
+ {
1406
+ return rb_gsl_vector_complex_XXXz2_bang(obj, a, gsl_complex_pow);
1407
+ }
1408
+
1409
+ static VALUE rb_gsl_vector_complex_log(VALUE obj)
1410
+ {
1411
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_log);
1412
+ }
1413
+
1414
+ static VALUE rb_gsl_vector_complex_log_bang(VALUE obj)
1415
+ {
1416
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_log);
1417
+ }
1418
+
1419
+ static VALUE rb_gsl_vector_complex_log10(VALUE obj)
1420
+ {
1421
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_log10);
1422
+ }
1423
+
1424
+ static VALUE rb_gsl_vector_complex_log10_bang(VALUE obj)
1425
+ {
1426
+ return rb_gsl_vector_complex_XXXz_bang(obj, gsl_complex_log10);
1427
+ }
1428
+
1429
+ static VALUE rb_gsl_vector_complex_log_b(VALUE obj, VALUE a)
1430
+ {
1431
+ return rb_gsl_vector_complex_XXXz2(obj, a, gsl_complex_log_b);
1432
+ }
1433
+
1434
+ static VALUE rb_gsl_vector_complex_log_b_bang(VALUE obj, VALUE a)
1435
+ {
1436
+ return rb_gsl_vector_complex_XXXz2_bang(obj, a, gsl_complex_log_b);
1437
+ }
1438
+
1439
+ /* gsl_vector_complex_sum */
1440
+ static gsl_complex rb_gsl_vector_complex_sum_gsl(gsl_vector_complex * v)
1441
+ {
1442
+ size_t i;
1443
+ gsl_complex z = gsl_complex_rect(0.0,0.0);
1444
+
1445
+ for(i=0; i<v->size; i++) {
1446
+ z = gsl_complex_add(z, gsl_vector_complex_get(v,i));
1447
+ }
1448
+ return z;
1449
+ }
1450
+
1451
+ /* gsl_vector_complex_mean */
1452
+ static gsl_complex rb_gsl_vector_complex_mean_gsl(gsl_vector_complex * v)
1453
+ {
1454
+ gsl_complex z = rb_gsl_vector_complex_sum_gsl(v);
1455
+ return gsl_complex_div_real(z, (double)v->size);
1456
+ }
1457
+
1458
+ /* gsl_vector_complex_tss_m */
1459
+ static double rb_gsl_vector_complex_tss_m_gsl(gsl_vector_complex * v, gsl_complex mean)
1460
+ {
1461
+ size_t i;
1462
+ double tss = 0.0;
1463
+
1464
+ for(i=0; i<v->size; i++) {
1465
+ tss += gsl_complex_abs2(gsl_complex_sub(gsl_vector_complex_get(v,i), mean));
1466
+ }
1467
+ return tss;
1468
+ }
1469
+
1470
+ /* gsl_vector_complex_variance_m */
1471
+ static double rb_gsl_vector_complex_variance_m_gsl(gsl_vector_complex * v, gsl_complex mean)
1472
+ {
1473
+ double tss = rb_gsl_vector_complex_tss_m_gsl(v, mean);
1474
+ return tss / (double)(v->size - 1);
1475
+ }
1476
+
1477
+ /* gsl_vector_complex_variance_with_fixed_mean */
1478
+ static double rb_gsl_vector_complex_variance_fm_gsl(gsl_vector_complex * v, gsl_complex mean)
1479
+ {
1480
+ double tss = rb_gsl_vector_complex_tss_m_gsl(v, mean);
1481
+ return tss / (double)(v->size);
1482
+ }
1483
+
1484
+ /* gsl_vector_complex_sd_m */
1485
+ static double rb_gsl_vector_complex_sd_m_gsl(gsl_vector_complex * v, gsl_complex mean)
1486
+ {
1487
+ double var = rb_gsl_vector_complex_variance_m_gsl(v, mean);
1488
+ return sqrt(var);
1489
+ }
1490
+
1491
+ /* gsl_vector_complex_sd_with_fixed_mean */
1492
+ static double rb_gsl_vector_complex_sd_fm_gsl(gsl_vector_complex * v, gsl_complex mean)
1493
+ {
1494
+ double var = rb_gsl_vector_complex_variance_fm_gsl(v, mean);
1495
+ return sqrt(var);
1496
+ }
1497
+
1498
+ /* gsl_vector_complex_tss */
1499
+ static double rb_gsl_vector_complex_tss_gsl(gsl_vector_complex * v)
1500
+ {
1501
+ gsl_complex mean = rb_gsl_vector_complex_mean_gsl(v);
1502
+ return rb_gsl_vector_complex_tss_m_gsl(v, mean);
1503
+ }
1504
+
1505
+ /* gsl_vector_complex_variance */
1506
+ static double rb_gsl_vector_complex_variance_gsl(gsl_vector_complex * v)
1507
+ {
1508
+ double tss = rb_gsl_vector_complex_tss_gsl(v);
1509
+ return tss / (double)(v->size - 1);
1510
+ }
1511
+
1512
+ /* gsl_vector_complex_sd */
1513
+ static double rb_gsl_vector_complex_sd_gsl(gsl_vector_complex * v)
1514
+ {
1515
+ double var = rb_gsl_vector_complex_variance_gsl(v);
1516
+ return sqrt(var);
1517
+ }
1518
+
1519
+ /* Wrapper around stats funcs with prototype like
1520
+ * "gsl_complex func(gsl_vector_complex *v)"
1521
+ * (e.g. sum and mean)
1522
+ */
1523
+ static VALUE rb_gsl_vector_complex_z_stats_v(VALUE obj,
1524
+ gsl_complex (*func)(gsl_vector_complex*))
1525
+ {
1526
+ gsl_vector_complex * v;
1527
+ gsl_complex * zp;
1528
+ VALUE zv;
1529
+
1530
+ CHECK_VECTOR_COMPLEX(obj);
1531
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1532
+
1533
+ zv = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
1534
+ *zp = func(v);
1535
+
1536
+ return zv;
1537
+ }
1538
+
1539
+ /* Wrapper around stats funcs with prototype like
1540
+ * "double func(gsl_vector_complex *v)"
1541
+ * (e.g. tss, variance, sd)
1542
+ */
1543
+ static VALUE rb_gsl_vector_complex_d_stats_v(VALUE obj,
1544
+ double (*func)(gsl_vector_complex*))
1545
+ {
1546
+ gsl_vector_complex * v;
1547
+ double d;
1548
+
1549
+ CHECK_VECTOR_COMPLEX(obj);
1550
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1551
+
1552
+ d = func(v);
1553
+
1554
+ return rb_float_new(d);
1555
+ }
1556
+
1557
+ /* Wrapper around stats funcs with prototype like
1558
+ * "double func(gsl_vector_complex *v, gsl_complex z)"
1559
+ * (e.g. tss_m, variance_m, sd_m, variance_fm, sd_fm)
1560
+ */
1561
+ static VALUE rb_gsl_vector_complex_d_stats_v_z(VALUE obj, VALUE arg,
1562
+ double (*func)(gsl_vector_complex*, gsl_complex))
1563
+ {
1564
+ gsl_vector_complex * v;
1565
+ gsl_complex z;
1566
+ gsl_complex * zp;
1567
+ double d;
1568
+
1569
+ CHECK_VECTOR_COMPLEX(obj);
1570
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1571
+
1572
+
1573
+ switch (TYPE(arg)) {
1574
+ case T_FLOAT:
1575
+ case T_FIXNUM:
1576
+ case T_BIGNUM:
1577
+ z = gsl_complex_rect(NUM2DBL(arg), 0.0);
1578
+ zp = &z;
1579
+ break;
1580
+ default:
1581
+ CHECK_COMPLEX(arg);
1582
+ Data_Get_Struct(arg, gsl_complex, zp);
1583
+ break;
1584
+ }
1585
+
1586
+ d = func(v,*zp);
1587
+
1588
+ return rb_float_new(d);
1589
+ }
1590
+
1591
+ static VALUE rb_gsl_vector_complex_sum(VALUE obj)
1592
+ {
1593
+ return rb_gsl_vector_complex_z_stats_v(obj, rb_gsl_vector_complex_sum_gsl);
1594
+ }
1595
+
1596
+ static VALUE rb_gsl_vector_complex_mean(VALUE obj)
1597
+ {
1598
+ return rb_gsl_vector_complex_z_stats_v(obj, rb_gsl_vector_complex_mean_gsl);
1599
+ }
1600
+
1601
+ static VALUE rb_gsl_vector_complex_tss_m(VALUE obj, VALUE arg)
1602
+ {
1603
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_tss_m_gsl);
1604
+ }
1605
+
1606
+ static VALUE rb_gsl_vector_complex_variance_m(VALUE obj, VALUE arg)
1607
+ {
1608
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_variance_m_gsl);
1609
+ }
1610
+
1611
+ static VALUE rb_gsl_vector_complex_variance_fm(VALUE obj, VALUE arg)
1612
+ {
1613
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_variance_fm_gsl);
1614
+ }
1615
+
1616
+ static VALUE rb_gsl_vector_complex_sd_m(VALUE obj, VALUE arg)
1617
+ {
1618
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_sd_m_gsl);
1619
+ }
1620
+
1621
+ static VALUE rb_gsl_vector_complex_sd_fm(VALUE obj, VALUE arg)
1622
+ {
1623
+ return rb_gsl_vector_complex_d_stats_v_z(obj, arg, rb_gsl_vector_complex_sd_fm_gsl);
1624
+ }
1625
+
1626
+ static VALUE rb_gsl_vector_complex_tss(VALUE obj)
1627
+ {
1628
+ return rb_gsl_vector_complex_d_stats_v(obj, rb_gsl_vector_complex_tss_gsl);
1629
+ }
1630
+
1631
+ static VALUE rb_gsl_vector_complex_variance(VALUE obj)
1632
+ {
1633
+ return rb_gsl_vector_complex_d_stats_v(obj, rb_gsl_vector_complex_variance_gsl);
1634
+ }
1635
+
1636
+ static VALUE rb_gsl_vector_complex_sd(VALUE obj)
1637
+ {
1638
+ return rb_gsl_vector_complex_d_stats_v(obj, rb_gsl_vector_complex_sd_gsl);
1639
+ }
1640
+
1641
+ /*****/
1642
+
1643
+ static VALUE rb_gsl_vector_complex_sin(VALUE obj)
1644
+ {
1645
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sin);
1646
+ }
1647
+
1648
+ static VALUE rb_gsl_vector_complex_cos(VALUE obj)
1649
+ {
1650
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_cos);
1651
+ }
1652
+
1653
+ static VALUE rb_gsl_vector_complex_tan(VALUE obj)
1654
+ {
1655
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_tan);
1656
+ }
1657
+
1658
+ static VALUE rb_gsl_vector_complex_sec(VALUE obj)
1659
+ {
1660
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sec);
1661
+ }
1662
+
1663
+ static VALUE rb_gsl_vector_complex_csc(VALUE obj)
1664
+ {
1665
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_csc);
1666
+ }
1667
+ static VALUE rb_gsl_vector_complex_cot(VALUE obj)
1668
+ {
1669
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_cot);
1670
+ }
1671
+
1672
+ static VALUE rb_gsl_vector_complex_arcsin(VALUE obj)
1673
+ {
1674
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsin);
1675
+ }
1676
+
1677
+ static VALUE rb_gsl_vector_complex_arccos(VALUE obj)
1678
+ {
1679
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccos);
1680
+ }
1681
+
1682
+ static VALUE rb_gsl_vector_complex_arctan(VALUE obj)
1683
+ {
1684
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arctan);
1685
+ }
1686
+
1687
+ static VALUE rb_gsl_vector_complex_arcsec(VALUE obj)
1688
+ {
1689
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsec);
1690
+ }
1691
+
1692
+ static VALUE rb_gsl_vector_complex_arccsc(VALUE obj)
1693
+ {
1694
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccsc);
1695
+ }
1696
+
1697
+ static VALUE rb_gsl_vector_complex_arccot(VALUE obj)
1698
+ {
1699
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccot);
1700
+ }
1701
+
1702
+ static VALUE rb_gsl_vector_complex_sinh(VALUE obj)
1703
+ {
1704
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sinh);
1705
+ }
1706
+
1707
+ static VALUE rb_gsl_vector_complex_cosh(VALUE obj)
1708
+ {
1709
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_cosh);
1710
+ }
1711
+
1712
+ static VALUE rb_gsl_vector_complex_tanh(VALUE obj)
1713
+ {
1714
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_tanh);
1715
+ }
1716
+
1717
+ static VALUE rb_gsl_vector_complex_sech(VALUE obj)
1718
+ {
1719
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_sech);
1720
+ }
1721
+
1722
+ static VALUE rb_gsl_vector_complex_csch(VALUE obj)
1723
+ {
1724
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_csch);
1725
+ }
1726
+
1727
+ static VALUE rb_gsl_vector_complex_coth(VALUE obj)
1728
+ {
1729
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_coth);
1730
+ }
1731
+
1732
+ static VALUE rb_gsl_vector_complex_arcsinh(VALUE obj)
1733
+ {
1734
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsinh);
1735
+ }
1736
+
1737
+ static VALUE rb_gsl_vector_complex_arccosh(VALUE obj)
1738
+ {
1739
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccosh);
1740
+ }
1741
+
1742
+ static VALUE rb_gsl_vector_complex_arctanh(VALUE obj)
1743
+ {
1744
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arctanh);
1745
+ }
1746
+
1747
+ static VALUE rb_gsl_vector_complex_arcsech(VALUE obj)
1748
+ {
1749
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arcsech);
1750
+ }
1751
+
1752
+ static VALUE rb_gsl_vector_complex_arccsch(VALUE obj)
1753
+ {
1754
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccsch);
1755
+ }
1756
+
1757
+ static VALUE rb_gsl_vector_complex_arccoth(VALUE obj)
1758
+ {
1759
+ return rb_gsl_vector_complex_XXXz(obj, gsl_complex_arccoth);
1760
+ }
1761
+
1762
+ static VALUE rb_gsl_vector_complex_concat(VALUE obj, VALUE other)
1763
+ {
1764
+ gsl_vector_complex *v = NULL, *v2 = NULL, *vnew = NULL;
1765
+ gsl_vector_complex_view vv;
1766
+ gsl_complex tmp;
1767
+ VALUE x;
1768
+ double beg, end;
1769
+ int step;
1770
+ size_t i, size2;
1771
+
1772
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1773
+
1774
+ switch(TYPE(other)) {
1775
+ case T_FIXNUM:
1776
+ case T_BIGNUM:
1777
+ case T_FLOAT:
1778
+ vnew = gsl_vector_complex_alloc(v->size + 1);
1779
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1780
+ gsl_vector_complex_memcpy(&vv.vector, v);
1781
+ gsl_vector_complex_set(vnew, v->size, rb_gsl_obj_to_gsl_complex(other, NULL));
1782
+ break;
1783
+
1784
+ case T_ARRAY:
1785
+ size2 = RARRAY_LEN(other);
1786
+ vnew = gsl_vector_complex_alloc(v->size + size2);
1787
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1788
+ gsl_vector_complex_memcpy(&vv.vector, v);
1789
+ for (i = 0; i < size2; i++) {
1790
+ x = rb_ary_entry(other, i);
1791
+ gsl_vector_complex_set(vnew, v->size + i, rb_gsl_obj_to_gsl_complex(x, NULL));
1792
+ }
1793
+ break;
1794
+
1795
+ default:
1796
+ if(rb_obj_is_kind_of(other, cgsl_complex)) {
1797
+ vnew = gsl_vector_complex_alloc(v->size + 1);
1798
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1799
+ gsl_vector_complex_memcpy(&vv.vector, v);
1800
+ gsl_vector_complex_set(vnew, v->size, rb_gsl_obj_to_gsl_complex(other, NULL));
1801
+ } else if(rb_obj_is_kind_of(other, rb_cRange)) {
1802
+ get_range_beg_en_n(other, &beg, &end, &size2, &step);
1803
+ vnew = gsl_vector_complex_alloc(v->size + size2);
1804
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1805
+ gsl_vector_complex_memcpy(&vv.vector, v);
1806
+ GSL_SET_COMPLEX(&tmp, beg, 0.0);
1807
+ for (i = 0; i < size2; i++) {
1808
+ gsl_vector_complex_set(vnew, v->size + i, tmp);
1809
+ GSL_SET_REAL(&tmp, GSL_REAL(tmp) + step);
1810
+ }
1811
+ } else if (rb_obj_is_kind_of(other, cgsl_vector_complex)) {
1812
+ Data_Get_Struct(other, gsl_vector_complex, v2);
1813
+ size2 = v2->size;
1814
+ vnew = gsl_vector_complex_alloc(v->size + size2);
1815
+ vv = gsl_vector_complex_subvector(vnew, 0, v->size);
1816
+ gsl_vector_complex_memcpy(&vv.vector, v);
1817
+ vv = gsl_vector_complex_subvector(vnew, v->size, size2);
1818
+ gsl_vector_complex_memcpy(&vv.vector, v2);
1819
+ } else {
1820
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array, Numeric, Range, GSL::Complex, or %s expected)",
1821
+ rb_class2name(CLASS_OF(other)), rb_class2name(cgsl_vector_complex));
1822
+ }
1823
+ break;
1824
+ }
1825
+
1826
+ return Data_Wrap_Struct(VECTOR_COMPLEX_ROW_COL(obj), 0, gsl_vector_complex_free, vnew);
1827
+ }
1828
+
1829
+ static VALUE rb_gsl_vector_complex_block(VALUE obj)
1830
+ {
1831
+ gsl_vector_complex *v = NULL;
1832
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1833
+ return Data_Wrap_Struct(cgsl_block_complex, 0, NULL, v->block);
1834
+ }
1835
+
1836
+ static VALUE rb_gsl_vector_complex_indgen_bang(int argc, VALUE *argv[], VALUE obj)
1837
+ {
1838
+ gsl_vector_complex *v = NULL;
1839
+ double start = 0.0, step = 1.0, x;
1840
+ size_t i;
1841
+ switch (argc) {
1842
+ case 0:
1843
+ break;
1844
+ case 1:
1845
+ start = NUM2DBL(argv[0]);
1846
+ break;
1847
+ case 2:
1848
+ start = NUM2DBL(argv[0]);
1849
+ step = NUM2DBL(argv[1]);
1850
+ break;
1851
+ default:
1852
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1853
+ }
1854
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1855
+ for (i = 0, x = start; i < v->size; i++, x += step) {
1856
+ gsl_vector_complex_set(v, i, gsl_complex_rect(x,0));
1857
+ }
1858
+ return obj;
1859
+ }
1860
+
1861
+ static VALUE rb_gsl_vector_complex_indgen(int argc, VALUE *argv, VALUE obj)
1862
+ {
1863
+ gsl_vector_complex *v = NULL, *vnew;
1864
+ double start = 0, step = 1, x;
1865
+ size_t i;
1866
+ switch (argc) {
1867
+ case 0:
1868
+ break;
1869
+ case 1:
1870
+ start = NUM2DBL(argv[0]);
1871
+ break;
1872
+ case 2:
1873
+ start = NUM2DBL(argv[0]);
1874
+ step = NUM2DBL(argv[1]);
1875
+ break;
1876
+ default:
1877
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1878
+ }
1879
+ Data_Get_Struct(obj, gsl_vector_complex, v);
1880
+ vnew = gsl_vector_complex_calloc(v->size);
1881
+ for (i = 0, x = start; i < vnew->size; i++, x += step) {
1882
+ gsl_vector_complex_set(vnew, i, gsl_complex_rect(x,0));
1883
+ }
1884
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
1885
+ }
1886
+
1887
+ static VALUE rb_gsl_vector_complex_indgen_singleton(int argc, VALUE *argv, VALUE obj)
1888
+ {
1889
+ gsl_vector_complex *vnew;
1890
+ double start = 0, step = 1, x;
1891
+ size_t n, i;
1892
+ switch (argc) {
1893
+ case 1:
1894
+ n = (size_t) FIX2INT(argv[0]);
1895
+ break;
1896
+ case 2:
1897
+ n = (size_t) FIX2INT(argv[0]);
1898
+ start = NUM2DBL(argv[1]);
1899
+ break;
1900
+ case 3:
1901
+ n = (size_t) FIX2INT(argv[0]);
1902
+ start = NUM2DBL(argv[1]);
1903
+ step = NUM2DBL(argv[2]);
1904
+ break;
1905
+ default:
1906
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-3)",argc);
1907
+ }
1908
+ vnew = gsl_vector_complex_calloc(n);
1909
+ for (i = 0, x = start; i < vnew->size; i++, x += step) {
1910
+ gsl_vector_complex_set(vnew, i, gsl_complex_rect(x,0));
1911
+ }
1912
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
1913
+ }
1914
+
1915
+ static VALUE rb_gsl_vector_complex_phasor_singleton(int argc, VALUE *argv, VALUE obj)
1916
+ {
1917
+ gsl_vector_complex *vnew;
1918
+ double start, step, theta;
1919
+ size_t n, i;
1920
+ switch (argc) {
1921
+ case 1:
1922
+ n = (size_t) FIX2INT(argv[0]);
1923
+ start = 0;
1924
+ step = 2 * M_PI / n;
1925
+ break;
1926
+ case 2:
1927
+ n = (size_t) FIX2INT(argv[0]);
1928
+ start = NUM2DBL(argv[1]);
1929
+ step = 2 * M_PI / n;
1930
+ break;
1931
+ case 3:
1932
+ n = (size_t) FIX2INT(argv[0]);
1933
+ start = NUM2DBL(argv[1]);
1934
+ step = NUM2DBL(argv[2]);
1935
+ break;
1936
+ default:
1937
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-3)",argc);
1938
+ }
1939
+ vnew = gsl_vector_complex_alloc(n);
1940
+ for (i = 0, theta = start; i < vnew->size; i++, theta += step) {
1941
+ gsl_vector_complex_set(vnew, i, gsl_complex_polar(1.0,theta));
1942
+ }
1943
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew);
1944
+ }
1945
+
1946
+ static VALUE rb_gsl_vector_complex_zip(int argc, VALUE *argv, VALUE obj)
1947
+ {
1948
+ gsl_vector_complex *v0, **vp, *vnew;
1949
+ VALUE ary;
1950
+ size_t i, j;
1951
+ int argc2;
1952
+ VALUE *argv2;
1953
+ gsl_complex zzero = gsl_complex_rect(0, 0);
1954
+ if (VECTOR_COMPLEX_P(obj)) {
1955
+ Data_Get_Struct(obj, gsl_vector_complex, v0);
1956
+ argc2 = argc;
1957
+ argv2 = argv;
1958
+ } else {
1959
+ if (argc < 1) rb_raise(rb_eArgError, "Too few arguments.");
1960
+ Data_Get_Struct(argv[0], gsl_vector_complex, v0);
1961
+ argc2 = argc - 1;
1962
+ argv2 = argv + 1;
1963
+ }
1964
+ for (i = 0; i < argc2; i++) {
1965
+ CHECK_VECTOR_COMPLEX(argv2[i]);
1966
+ }
1967
+ vp = (gsl_vector_complex**) malloc(sizeof(gsl_vector_complex**));
1968
+ for (i = 0; i < argc2; i++) {
1969
+ Data_Get_Struct(argv2[i], gsl_vector_complex, vp[i]);
1970
+ }
1971
+ ary = rb_ary_new2(v0->size);
1972
+ for (i = 0; i < v0->size; i++) {
1973
+ vnew = gsl_vector_complex_alloc(argc2 + 1);
1974
+ gsl_vector_complex_set(vnew, 0, gsl_vector_complex_get(v0, i));
1975
+ for (j = 0; j < argc2; j++) {
1976
+ if (i < vp[j]->size) {
1977
+ gsl_vector_complex_set(vnew, j+1, gsl_vector_complex_get(vp[j], i));
1978
+ } else {
1979
+ gsl_vector_complex_set(vnew, j+1, zzero);
1980
+ }
1981
+ }
1982
+ rb_ary_store(ary, i, Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew));
1983
+ }
1984
+
1985
+ free((gsl_vector_complex**) vp);
1986
+ return ary;
1987
+ }
1988
+
1989
+ // Starting with version 1.15, GSL provides a gsl_vector_complex_equal
1990
+ // function, but it only determines absolute equality (i.e. is has no epsilon
1991
+ // argument).
1992
+ static int gsl_vector_complex_equal_eps(const gsl_vector_complex *v1,
1993
+ const gsl_vector_complex *v2, double eps)
1994
+ {
1995
+ gsl_complex z1, z2;
1996
+ size_t i;
1997
+ if (v1->size != v2->size) return 0;
1998
+ for (i = 0; i < v1->size; i++) {
1999
+ z1 = gsl_vector_complex_get(v1, i);
2000
+ z2 = gsl_vector_complex_get(v2, i);
2001
+ if (!rbgsl_complex_equal(&z1, &z2, eps)) return 0;
2002
+ }
2003
+ return 1;
2004
+
2005
+ }
2006
+
2007
+ static VALUE rb_gsl_vector_complex_equal(int argc, VALUE *argv, VALUE obj)
2008
+ {
2009
+ gsl_vector_complex *v1, *v2;
2010
+ double eps = 1e-8;
2011
+ int ret;
2012
+ switch (argc) {
2013
+ case 1:
2014
+ eps = 1e-8;
2015
+ break;
2016
+ case 2:
2017
+ eps = NUM2DBL(argv[1]);
2018
+ break;
2019
+ default:
2020
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)\n", argc);
2021
+ }
2022
+ Data_Get_Struct(obj, gsl_vector_complex, v1);
2023
+ CHECK_VECTOR_COMPLEX(argv[0]);
2024
+ Data_Get_Struct(argv[0], gsl_vector_complex, v2);
2025
+ ret = gsl_vector_complex_equal_eps(v1, v2, eps);
2026
+ if (ret == 1) return Qtrue;
2027
+ else return Qfalse;
2028
+ }
2029
+
2030
+ static VALUE rb_gsl_vector_complex_not_equal(int argc, VALUE *argv, VALUE obj)
2031
+ {
2032
+ VALUE ret;
2033
+ ret = rb_gsl_vector_complex_equal(argc, argv, obj);
2034
+ if (ret == Qtrue) return Qfalse;
2035
+ else return Qtrue;
2036
+ }
2037
+
2038
+ void Init_gsl_vector_complex(VALUE module)
2039
+ {
2040
+ rb_define_singleton_method(cgsl_vector_complex, "new", rb_gsl_vector_complex_new, -1);
2041
+ rb_define_singleton_method(cgsl_vector_complex, "[]", rb_gsl_vector_complex_new, -1);
2042
+ rb_define_singleton_method(cgsl_vector_complex, "alloc", rb_gsl_vector_complex_new, -1);
2043
+ rb_define_singleton_method(cgsl_vector_complex, "calloc", rb_gsl_vector_complex_calloc, 1);
2044
+
2045
+ rb_define_singleton_method(cgsl_vector_complex_col, "new",
2046
+ rb_gsl_vector_complex_row_new, -1);
2047
+
2048
+ rb_define_method(cgsl_vector_complex, "size", rb_gsl_vector_complex_size, 0);
2049
+ rb_define_alias(cgsl_vector_complex, "len", "size");
2050
+ rb_define_alias(cgsl_vector_complex, "length", "size");
2051
+ rb_define_method(cgsl_vector_complex, "stride", rb_gsl_vector_complex_stride, 0);
2052
+ rb_define_method(cgsl_vector_complex, "owner", rb_gsl_vector_complex_owner, 0);
2053
+ rb_define_method(cgsl_vector_complex, "get", rb_gsl_vector_complex_get, -1);
2054
+ rb_define_alias(cgsl_vector_complex, "[]", "get");
2055
+ rb_define_method(cgsl_vector_complex, "ptr", rb_gsl_vector_complex_ptr, 1);
2056
+
2057
+ rb_define_method(cgsl_vector_complex, "set", rb_gsl_vector_complex_set, -1);
2058
+ rb_define_alias(cgsl_vector_complex, "[]=", "set");
2059
+ rb_define_method(cgsl_vector_complex, "set_all", rb_gsl_vector_complex_set_all, -1);
2060
+
2061
+ rb_define_method(cgsl_vector_complex, "each", rb_gsl_vector_complex_each, 0);
2062
+ rb_define_method(cgsl_vector_complex, "reverse_each", rb_gsl_vector_complex_reverse_each, 0);
2063
+ rb_define_method(cgsl_vector_complex, "each_index", rb_gsl_vector_complex_each_index, 0);
2064
+ rb_define_method(cgsl_vector_complex, "reverse_each_index", rb_gsl_vector_complex_reverse_each_index, 0);
2065
+ rb_define_method(cgsl_vector_complex, "collect", rb_gsl_vector_complex_collect, 0);
2066
+ rb_define_method(cgsl_vector_complex, "collect!", rb_gsl_vector_complex_collect_bang, 0);
2067
+ rb_define_alias(cgsl_vector_complex, "map", "collect");
2068
+ rb_define_alias(cgsl_vector_complex, "map!", "collect!");
2069
+
2070
+ rb_define_method(cgsl_vector_complex, "set_zero", rb_gsl_vector_complex_set_zero, 0);
2071
+ rb_define_method(cgsl_vector_complex, "set_basis", rb_gsl_vector_complex_set_basis, 1);
2072
+
2073
+ rb_define_method(cgsl_vector_complex, "to_s", rb_gsl_vector_complex_to_s, 0);
2074
+ rb_define_method(cgsl_vector_complex, "fprintf", rb_gsl_vector_complex_fprintf, -1);
2075
+ rb_define_method(cgsl_vector_complex, "printf", rb_gsl_vector_complex_printf, -1);
2076
+ rb_define_method(cgsl_vector_complex, "print", rb_gsl_vector_complex_print, 0);
2077
+ rb_define_method(cgsl_vector_complex, "inspect", rb_gsl_vector_complex_inspect, 0);
2078
+ rb_define_method(cgsl_vector_complex, "fwrite", rb_gsl_vector_complex_fwrite, 1);
2079
+ rb_define_method(cgsl_vector_complex, "fread", rb_gsl_vector_complex_fread, 1);
2080
+ rb_define_method(cgsl_vector_complex, "fscanf", rb_gsl_vector_complex_fscanf, 1);
2081
+
2082
+ rb_define_method(cgsl_vector_complex, "real", rb_gsl_vector_complex_real, 0);
2083
+ rb_define_alias(cgsl_vector_complex, "re", "real");
2084
+ rb_define_method(cgsl_vector_complex, "imag", rb_gsl_vector_complex_imag, 0);
2085
+ rb_define_alias(cgsl_vector_complex, "im", "imag");
2086
+
2087
+ rb_define_method(cgsl_vector_complex, "set_real", rb_gsl_vector_complex_set_real, 1);
2088
+ rb_define_alias(cgsl_vector_complex, "real=", "set_real");
2089
+ rb_define_alias(cgsl_vector_complex, "re=", "set_real");
2090
+ rb_define_method(cgsl_vector_complex, "set_imag", rb_gsl_vector_complex_set_imag, 1);
2091
+ rb_define_alias(cgsl_vector_complex, "imag=", "set_imag");
2092
+ rb_define_alias(cgsl_vector_complex, "im=", "set_imag");
2093
+
2094
+ rb_define_method(cgsl_vector_complex, "conj", rb_gsl_vector_complex_conj, 0);
2095
+ rb_define_alias(cgsl_vector_complex, "conjugate", "conj");
2096
+ rb_define_method(cgsl_vector_complex, "conj!", rb_gsl_vector_complex_conj_bang, 0);
2097
+ rb_define_alias(cgsl_vector_complex, "conjugate!", "conj!");
2098
+
2099
+ rb_define_method(cgsl_vector_complex, "to_a", rb_gsl_vector_complex_to_a, 0);
2100
+ rb_define_method(cgsl_vector_complex, "to_a2", rb_gsl_vector_complex_to_a2, 0);
2101
+
2102
+ rb_define_method(cgsl_vector_complex, "subvector", rb_gsl_vector_complex_subvector, -1);
2103
+ rb_define_alias(cgsl_vector_complex, "view", "subvector");
2104
+ rb_define_method(cgsl_vector_complex, "subvector_with_stride", rb_gsl_vector_complex_subvector_with_stride, 3);
2105
+
2106
+ rb_define_singleton_method(cgsl_vector_complex, "memcpy", rb_gsl_vector_complex_memcpy, 2);
2107
+ rb_define_method(cgsl_vector_complex, "clone", rb_gsl_vector_complex_clone, 0);
2108
+ rb_define_alias(cgsl_vector_complex, "duplicate", "clone");
2109
+ rb_define_alias(cgsl_vector_complex, "dup", "clone");
2110
+ rb_define_method(cgsl_vector_complex, "reverse!", rb_gsl_vector_complex_reverse, 0);
2111
+ rb_define_method(cgsl_vector_complex, "reverse", rb_gsl_vector_complex_reverse2, 0);
2112
+ rb_define_method(cgsl_vector_complex, "swap_elements", rb_gsl_vector_complex_swap_elements, 2);
2113
+ rb_define_method(cgsl_vector_complex, "fftshift!", rb_gsl_vector_complex_fftshift_bang, 0);
2114
+ rb_define_method(cgsl_vector_complex, "fftshift", rb_gsl_vector_complex_fftshift, 0);
2115
+ rb_define_method(cgsl_vector_complex, "ifftshift!", rb_gsl_vector_complex_ifftshift_bang, 0);
2116
+ rb_define_method(cgsl_vector_complex, "ifftshift", rb_gsl_vector_complex_ifftshift, 0);
2117
+ rb_define_method(cgsl_vector_complex, "isnull", rb_gsl_vector_complex_isnull, 0);
2118
+
2119
+ rb_define_method(cgsl_vector_complex, "matrix_view", rb_gsl_vector_complex_matrix_view, -1);
2120
+ rb_define_method(cgsl_vector_complex, "matrix_view_with_tda", rb_gsl_vector_complex_matrix_view_with_tda, -1);
2121
+
2122
+ rb_define_method(cgsl_vector_complex, "trans", rb_gsl_vector_complex_trans, 0);
2123
+ rb_define_alias(cgsl_vector_complex, "transpose", "trans");
2124
+ rb_define_method(cgsl_vector_complex, "trans!", rb_gsl_vector_complex_trans2, 0);
2125
+ rb_define_alias(cgsl_vector_complex, "transpose!", "trans!");
2126
+
2127
+ /*****/
2128
+ rb_define_alias(cgsl_vector_complex, "col", "trans");
2129
+ rb_define_alias(cgsl_vector_complex, "col!", "trans!");
2130
+
2131
+ rb_define_alias(cgsl_vector_complex_col, "row", "trans");
2132
+ rb_define_alias(cgsl_vector_complex_col, "row!", "trans!");
2133
+
2134
+ /*****/
2135
+ rb_define_method(cgsl_vector_complex, "to_real", rb_gsl_vector_complex_to_real, 0);
2136
+
2137
+ rb_define_method(cgsl_vector_complex, "add", rb_gsl_vector_complex_add, 1);
2138
+ rb_define_method(cgsl_vector_complex, "sub", rb_gsl_vector_complex_sub, 1);
2139
+ rb_define_method(cgsl_vector_complex, "mul", rb_gsl_vector_complex_mul, 1);
2140
+ rb_define_method(cgsl_vector_complex, "div", rb_gsl_vector_complex_div, 1);
2141
+ rb_define_method(cgsl_vector_complex, "add!", rb_gsl_vector_complex_add_bang, 1);
2142
+ rb_define_method(cgsl_vector_complex, "sub!", rb_gsl_vector_complex_sub_bang, 1);
2143
+ rb_define_method(cgsl_vector_complex, "mul!", rb_gsl_vector_complex_mul_bang, 1);
2144
+ rb_define_method(cgsl_vector_complex, "div!", rb_gsl_vector_complex_div_bang, 1);
2145
+
2146
+ rb_define_alias(cgsl_vector_complex, "+", "add");
2147
+ rb_define_alias(cgsl_vector_complex, "add_constant", "add");
2148
+ rb_define_alias(cgsl_vector_complex, "add_constant!", "add!");
2149
+ rb_define_alias(cgsl_vector_complex, "-", "sub");
2150
+ rb_define_alias(cgsl_vector_complex, "*", "mul");
2151
+ rb_define_alias(cgsl_vector_complex, "scale", "mul");
2152
+ rb_define_alias(cgsl_vector_complex, "scale!", "mul!");
2153
+ rb_define_alias(cgsl_vector_complex, "/", "div");
2154
+
2155
+ rb_define_method(cgsl_vector_complex, "coerce", rb_gsl_vector_complex_coerce, 1);
2156
+
2157
+ /* 2.Aug.2004 */
2158
+ rb_define_singleton_method(cgsl_vector_complex, "inner_product", rb_gsl_vector_complex_inner_product, -1);
2159
+ rb_define_singleton_method(cgsl_vector_complex, "dot", rb_gsl_vector_complex_inner_product, -1);
2160
+ rb_define_method(cgsl_vector_complex, "inner_product", rb_gsl_vector_complex_inner_product, -1);
2161
+ /* rb_define_alias(cgsl_vector_complex, "dot", "inner_product");*/
2162
+
2163
+ /*****/
2164
+ rb_define_method(cgsl_vector_complex, "-@", rb_gsl_vector_complex_uminus, 0);
2165
+ rb_define_method(cgsl_vector_complex, "+@", rb_gsl_vector_complex_uplus, 0);
2166
+
2167
+ rb_define_method(cgsl_vector_complex, "abs2", rb_gsl_vector_complex_abs2, 0);
2168
+ rb_define_alias(cgsl_vector_complex, "square", "abs2");
2169
+ rb_define_method(cgsl_vector_complex, "abs", rb_gsl_vector_complex_abs, 0);
2170
+ rb_define_alias(cgsl_vector_complex, "amp", "abs");
2171
+ rb_define_alias(cgsl_vector_complex, "mag", "abs");
2172
+ rb_define_method(cgsl_vector_complex, "arg", rb_gsl_vector_complex_arg, 0);
2173
+ rb_define_alias(cgsl_vector_complex, "angle", "arg");
2174
+ rb_define_alias(cgsl_vector_complex, "phase", "arg");
2175
+ rb_define_method(cgsl_vector_complex, "logabs", rb_gsl_vector_complex_logabs, 0);
2176
+
2177
+ rb_define_method(cgsl_vector_complex, "sqrt", rb_gsl_vector_complex_sqrt, 0);
2178
+ rb_define_method(cgsl_vector_complex, "sqrt!", rb_gsl_vector_complex_sqrt_bang, 0);
2179
+ rb_define_method(cgsl_vector_complex, "exp", rb_gsl_vector_complex_exp, 0);
2180
+ rb_define_method(cgsl_vector_complex, "exp!", rb_gsl_vector_complex_exp_bang, 0);
2181
+ rb_define_method(cgsl_vector_complex, "pow", rb_gsl_vector_complex_pow, 1);
2182
+ rb_define_method(cgsl_vector_complex, "pow!", rb_gsl_vector_complex_pow_bang, 1);
2183
+ rb_define_method(cgsl_vector_complex, "log", rb_gsl_vector_complex_log, 0);
2184
+ rb_define_method(cgsl_vector_complex, "log!", rb_gsl_vector_complex_log_bang, 0);
2185
+ rb_define_method(cgsl_vector_complex, "log10", rb_gsl_vector_complex_log10, 0);
2186
+ rb_define_method(cgsl_vector_complex, "log10!", rb_gsl_vector_complex_log10_bang, 0);
2187
+ rb_define_method(cgsl_vector_complex, "log_b", rb_gsl_vector_complex_log_b, 1);
2188
+ rb_define_method(cgsl_vector_complex, "log_b!", rb_gsl_vector_complex_log_b_bang, 1);
2189
+
2190
+ rb_define_method(cgsl_vector_complex, "sum", rb_gsl_vector_complex_sum, 0);
2191
+ rb_define_method(cgsl_vector_complex, "mean", rb_gsl_vector_complex_mean, 0);
2192
+ rb_define_method(cgsl_vector_complex, "tss", rb_gsl_vector_complex_tss, 0);
2193
+ rb_define_method(cgsl_vector_complex, "tss_m", rb_gsl_vector_complex_tss_m, 1);
2194
+ rb_define_method(cgsl_vector_complex, "variance", rb_gsl_vector_complex_variance, 0);
2195
+ rb_define_method(cgsl_vector_complex, "variance_m", rb_gsl_vector_complex_variance_m, 1);
2196
+ rb_define_method(cgsl_vector_complex, "variance_fm", rb_gsl_vector_complex_variance_fm, 1);
2197
+ rb_define_method(cgsl_vector_complex, "sd", rb_gsl_vector_complex_sd, 0);
2198
+ rb_define_method(cgsl_vector_complex, "sd_m", rb_gsl_vector_complex_sd_m, 1);
2199
+ rb_define_method(cgsl_vector_complex, "sd_fm", rb_gsl_vector_complex_sd_fm, 1);
2200
+
2201
+ rb_define_method(cgsl_vector_complex, "sin", rb_gsl_vector_complex_sin, 0);
2202
+ rb_define_method(cgsl_vector_complex, "cos", rb_gsl_vector_complex_cos, 0);
2203
+ rb_define_method(cgsl_vector_complex, "tan", rb_gsl_vector_complex_tan, 0);
2204
+ rb_define_method(cgsl_vector_complex, "sec", rb_gsl_vector_complex_sec, 0);
2205
+ rb_define_method(cgsl_vector_complex, "csc", rb_gsl_vector_complex_csc, 0);
2206
+ rb_define_method(cgsl_vector_complex, "cot", rb_gsl_vector_complex_cot, 0);
2207
+
2208
+ rb_define_method(cgsl_vector_complex, "arcsin", rb_gsl_vector_complex_arcsin, 0);
2209
+ rb_define_method(cgsl_vector_complex, "arccos", rb_gsl_vector_complex_arccos, 0);
2210
+ rb_define_method(cgsl_vector_complex, "arctan", rb_gsl_vector_complex_arctan, 0);
2211
+ rb_define_method(cgsl_vector_complex, "arcsec", rb_gsl_vector_complex_arcsec, 0);
2212
+ rb_define_method(cgsl_vector_complex, "arccsc", rb_gsl_vector_complex_arccsc, 0);
2213
+ rb_define_method(cgsl_vector_complex, "arccot", rb_gsl_vector_complex_arccot, 0);
2214
+
2215
+ rb_define_method(cgsl_vector_complex, "sinh", rb_gsl_vector_complex_sinh, 0);
2216
+ rb_define_method(cgsl_vector_complex, "cosh", rb_gsl_vector_complex_cosh, 0);
2217
+ rb_define_method(cgsl_vector_complex, "tanh", rb_gsl_vector_complex_tanh, 0);
2218
+ rb_define_method(cgsl_vector_complex, "sech", rb_gsl_vector_complex_sech, 0);
2219
+ rb_define_method(cgsl_vector_complex, "csch", rb_gsl_vector_complex_csch, 0);
2220
+ rb_define_method(cgsl_vector_complex, "coth", rb_gsl_vector_complex_coth, 0);
2221
+
2222
+ rb_define_method(cgsl_vector_complex, "arcsinh", rb_gsl_vector_complex_arcsinh, 0);
2223
+ rb_define_method(cgsl_vector_complex, "arccosh", rb_gsl_vector_complex_arccosh, 0);
2224
+ rb_define_method(cgsl_vector_complex, "arctanh", rb_gsl_vector_complex_arctanh, 0);
2225
+ rb_define_method(cgsl_vector_complex, "arcsech", rb_gsl_vector_complex_arcsech, 0);
2226
+ rb_define_method(cgsl_vector_complex, "arccsch", rb_gsl_vector_complex_arccsch, 0);
2227
+ rb_define_method(cgsl_vector_complex, "arccoth", rb_gsl_vector_complex_arccoth, 0);
2228
+
2229
+ /*****/
2230
+ rb_define_method(cgsl_vector_complex, "concat", rb_gsl_vector_complex_concat, 1);
2231
+ rb_define_method(cgsl_vector_complex, "block", rb_gsl_vector_complex_block, 0);
2232
+
2233
+ rb_define_method(cgsl_vector_complex, "indgen", rb_gsl_vector_complex_indgen, -1);
2234
+ rb_define_method(cgsl_vector_complex, "indgen!", rb_gsl_vector_complex_indgen_bang, -1);
2235
+ rb_define_singleton_method(cgsl_vector_complex, "indgen", rb_gsl_vector_complex_indgen_singleton, -1);
2236
+ rb_define_singleton_method(cgsl_vector_complex, "phasor", rb_gsl_vector_complex_phasor_singleton, -1);
2237
+
2238
+ rb_define_method(cgsl_vector_complex, "zip", rb_gsl_vector_complex_zip, -1);
2239
+ rb_define_singleton_method(cgsl_vector_complex, "zip", rb_gsl_vector_complex_zip, -1);
2240
+
2241
+ rb_define_method(cgsl_vector_complex, "equal?", rb_gsl_vector_complex_equal, -1);
2242
+ rb_define_alias(cgsl_vector_complex, "==", "equal?");
2243
+ rb_define_method(cgsl_vector_complex, "not_equal?", rb_gsl_vector_complex_not_equal, -1);
2244
+ rb_define_alias(cgsl_vector_complex, "!=", "not_equal?");
2245
+ }
2246
+