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,39 @@
1
+ /*
2
+ matrix.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
+ int gsl_linalg_matmult_int(const gsl_matrix_int *A,
27
+ const gsl_matrix_int *B, gsl_matrix_int *C);
28
+
29
+ #define BASE_DOUBLE
30
+ #include "templates_on.h"
31
+ #include "matrix_source.c"
32
+ #include "templates_off.h"
33
+ #undef BASE_DOUBLE
34
+
35
+ #define BASE_INT
36
+ #include "templates_on.h"
37
+ #include "matrix_source.c"
38
+ #include "templates_off.h"
39
+ #undef BASE_INT
@@ -0,0 +1,1737 @@
1
+ /*
2
+ matrix_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
+
12
+ #include "rb_gsl_config.h"
13
+ #include "rb_gsl_array.h"
14
+ #include "rb_gsl_complex.h"
15
+
16
+ enum {
17
+ GSL_MATRIX_COMPLEX_ADD,
18
+ GSL_MATRIX_COMPLEX_SUB,
19
+ GSL_MATRIX_COMPLEX_MUL,
20
+ GSL_MATRIX_COMPLEX_DIV,
21
+ };
22
+
23
+ // From complex.c
24
+ gsl_complex rb_gsl_obj_to_gsl_complex(VALUE obj, gsl_complex *z);
25
+
26
+ // From ext/vector_source.c
27
+ void get_range_beg_en_n(VALUE range, double *beg, double *en, size_t *n, int *step);
28
+
29
+ // From ext/matrix_source.c
30
+ void parse_submatrix_args(int argc, VALUE *argv, size_t size1, size_t size2,
31
+ size_t *i, size_t *j, size_t *n1, size_t *n2);
32
+
33
+ static VALUE rb_gsl_matrix_complex_arithmetics(int flag, VALUE obj, VALUE bb)
34
+ {
35
+ gsl_matrix *m = NULL;
36
+ gsl_matrix_complex *cm = NULL, *cmb = NULL, *cmnew = NULL;
37
+ gsl_complex *c = NULL, z;
38
+ gsl_vector *v = NULL;
39
+ gsl_vector_complex *cv = NULL, *cvnew = NULL, *cvb = NULL;
40
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
41
+ switch (TYPE(bb)) {
42
+ case T_FLOAT:
43
+ case T_FIXNUM:
44
+ case T_BIGNUM:
45
+ z = gsl_complex_rect(NUM2DBL(bb), 0.0);
46
+ switch (flag) {
47
+ case GSL_MATRIX_COMPLEX_ADD:
48
+ cmnew = make_matrix_complex_clone(cm);
49
+ gsl_matrix_complex_add_constant(cmnew, z);
50
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
51
+ break;
52
+ case GSL_MATRIX_COMPLEX_SUB:
53
+ cmnew = make_matrix_complex_clone(cm);
54
+ gsl_matrix_complex_add_constant(cmnew, gsl_complex_negative(z));
55
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
56
+ break;
57
+ case GSL_MATRIX_COMPLEX_MUL:
58
+ cmnew = make_matrix_complex_clone(cm);
59
+ gsl_matrix_complex_scale(cmnew, z);
60
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
61
+ break;
62
+ case GSL_MATRIX_COMPLEX_DIV:
63
+ cmnew = make_matrix_complex_clone(cm);
64
+ gsl_matrix_complex_scale(cmnew, gsl_complex_inverse(z));
65
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
66
+ break;
67
+ default:
68
+ rb_raise(rb_eRuntimeError, "operation not defined");
69
+ break;
70
+ }
71
+ break;
72
+ default:
73
+ if (rb_obj_is_kind_of(bb, cgsl_matrix_complex)) {
74
+ Data_Get_Struct(bb, gsl_matrix_complex, cmb);
75
+ switch (flag) {
76
+ case GSL_MATRIX_COMPLEX_ADD:
77
+ cmnew = make_matrix_complex_clone(cm);
78
+ gsl_matrix_complex_add(cmnew, cmb);
79
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
80
+ break;
81
+ case GSL_MATRIX_COMPLEX_SUB:
82
+ cmnew = make_matrix_complex_clone(cm);
83
+ gsl_matrix_complex_sub(cmnew,cmb);
84
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
85
+ break;
86
+ case GSL_MATRIX_COMPLEX_MUL:
87
+ cmnew = make_matrix_complex_clone(cm);
88
+ gsl_matrix_complex_mul_elements(cmnew, cmb);
89
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
90
+ break;
91
+ case GSL_MATRIX_COMPLEX_DIV:
92
+ cmnew = make_matrix_complex_clone(cm);
93
+ gsl_matrix_complex_div_elements(cmnew, cmb);
94
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
95
+ break;
96
+ default:
97
+ rb_raise(rb_eRuntimeError, "operation not defined");
98
+ break;
99
+ }
100
+ } else if (rb_obj_is_kind_of(bb, cgsl_matrix)) {
101
+ Data_Get_Struct(bb, gsl_matrix, m);
102
+ cmb = matrix_to_complex(m);
103
+ cmnew = make_matrix_complex_clone(cm);
104
+ switch (flag) {
105
+ case GSL_MATRIX_COMPLEX_ADD:
106
+ gsl_matrix_complex_add(cmnew, cmb);
107
+ break;
108
+ case GSL_MATRIX_COMPLEX_SUB:
109
+ gsl_matrix_complex_sub(cmnew,cmb);
110
+ break;
111
+ case GSL_MATRIX_COMPLEX_MUL:
112
+ gsl_matrix_complex_mul_elements(cmnew, cmb);
113
+ break;
114
+ case GSL_MATRIX_COMPLEX_DIV:
115
+ gsl_matrix_complex_div_elements(cmnew, cmb);
116
+ break;
117
+ default:
118
+ rb_raise(rb_eRuntimeError, "operation not defined");
119
+ break;
120
+ }
121
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
122
+ } else if (rb_obj_is_kind_of(bb, cgsl_complex)) {
123
+ Data_Get_Struct(bb, gsl_complex, c);
124
+ switch (flag) {
125
+ case GSL_MATRIX_COMPLEX_ADD:
126
+ cmnew = make_matrix_complex_clone(cm);
127
+ gsl_matrix_complex_add_constant(cmnew, *c);
128
+ break;
129
+ case GSL_MATRIX_COMPLEX_SUB:
130
+ cmnew = make_matrix_complex_clone(cm);
131
+ gsl_matrix_complex_add_constant(cmnew, gsl_complex_negative(*c));
132
+ break;
133
+ case GSL_MATRIX_COMPLEX_MUL:
134
+ cmnew = make_matrix_complex_clone(cm);
135
+ gsl_matrix_complex_scale(cmnew, *c);
136
+ break;
137
+ case GSL_MATRIX_COMPLEX_DIV:
138
+ cmnew = make_matrix_complex_clone(cm);
139
+ gsl_matrix_complex_scale(cmnew, gsl_complex_inverse(*c));
140
+ break;
141
+ default:
142
+ rb_raise(rb_eRuntimeError, "operation not defined");
143
+ break;
144
+ }
145
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
146
+ } else if (rb_obj_is_kind_of(bb, cgsl_vector)) {
147
+ Data_Get_Struct(bb, gsl_vector, v);
148
+ switch (flag) {
149
+ case GSL_MATRIX_COMPLEX_MUL:
150
+ cvb = vector_to_complex(v);
151
+ cvnew = gsl_vector_complex_alloc(v->size);
152
+ if (cvnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
153
+ gsl_matrix_complex_mul_vector(cvnew, cm, cvb);
154
+ gsl_vector_complex_free(cvb);
155
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, cvnew);
156
+ break;
157
+ default:
158
+ rb_raise(rb_eRuntimeError,
159
+ "operation is not defined %s and Matrix_Complex",
160
+ rb_class2name(CLASS_OF(bb)));
161
+ break;
162
+ }
163
+ } else if (rb_obj_is_kind_of(bb, cgsl_vector_complex)) {
164
+ if (!VECTOR_COMPLEX_COL_P(bb))
165
+ rb_raise(rb_eTypeError,
166
+ "Operation is not defined with %s (Vector::Complex::Col expected)",
167
+ rb_class2name(CLASS_OF(bb)));
168
+ Data_Get_Struct(bb, gsl_vector_complex, cv);
169
+ switch (flag) {
170
+ case GSL_MATRIX_COMPLEX_MUL:
171
+ cvnew = gsl_vector_complex_alloc(cv->size);
172
+ if (cvnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
173
+ gsl_matrix_complex_mul_vector(cvnew, cm, cv);
174
+ return Data_Wrap_Struct(cgsl_vector_complex_col, 0, gsl_vector_complex_free, cvnew);;
175
+ default:
176
+ rb_raise(rb_eRuntimeError,
177
+ "operation is not defined %s and Matrix_Complex",
178
+ rb_class2name(CLASS_OF(bb)));
179
+ break;
180
+ }
181
+ } else {
182
+ rb_raise(rb_eTypeError, "wrong argument type %s", rb_class2name(CLASS_OF(bb)));
183
+ }
184
+ }
185
+ /* never reach here */
186
+ return Qnil;
187
+ }
188
+
189
+ static VALUE rb_gsl_matrix_complex_new(VALUE klass, VALUE s1, VALUE s2)
190
+ {
191
+ gsl_matrix_complex *m = NULL;
192
+ CHECK_FIXNUM(s1); CHECK_FIXNUM(s2);
193
+ m = gsl_matrix_complex_calloc(FIX2INT(s1), FIX2INT(s2));
194
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
195
+ return Data_Wrap_Struct(klass, 0, gsl_matrix_complex_free, m);
196
+ }
197
+
198
+ static VALUE rb_gsl_matrix_complex_eye(int argc, VALUE *argv, VALUE klass)
199
+ {
200
+ size_t n, i;
201
+ gsl_matrix_complex *m = NULL;
202
+ gsl_complex z, *pz = &z;
203
+ switch (argc) {
204
+ case 1:
205
+ CHECK_FIXNUM(argv[0]);
206
+ n = FIX2INT(argv[0]);
207
+ z = gsl_complex_rect(1.0, 0.0);
208
+ break;
209
+ case 2:
210
+ CHECK_FIXNUM(argv[0]);
211
+ n = FIX2INT(argv[0]);
212
+ switch (TYPE(argv[1])) {
213
+ case T_FIXNUM:
214
+ case T_BIGNUM:
215
+ case T_FLOAT:
216
+ z = gsl_complex_rect(NUM2DBL(argv[1]), 0.0);
217
+ break;
218
+ case T_ARRAY:
219
+ // if (RARRAY(argv[1])->len < 2) rb_raise(rb_eArgError, "wrong argument");
220
+ if (RARRAY_LEN(argv[1]) < 2) rb_raise(rb_eArgError, "wrong argument");
221
+ z = gsl_complex_rect(NUM2DBL(rb_ary_entry(argv[1], 0)),
222
+ NUM2DBL(rb_ary_entry(argv[1], 1)));
223
+ break;
224
+ default:
225
+ if (rb_obj_is_kind_of(argv[1], cgsl_complex)) {
226
+ Data_Get_Struct(argv[1], gsl_complex, pz);
227
+ z = *pz;
228
+ } else {
229
+ rb_raise(rb_eTypeError,
230
+ "wrong argument type %s", rb_class2name(CLASS_OF(argv[1])));
231
+ }
232
+ break;
233
+ }
234
+ break;
235
+ case 3:
236
+ CHECK_FIXNUM(argv[0]);
237
+ n = FIX2INT(argv[0]);
238
+ Need_Float(argv[1]); Need_Float(argv[2]);
239
+ z = gsl_complex_rect(NUM2DBL(argv[1]), NUM2DBL(argv[2]));
240
+ break;
241
+ default:
242
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1, 2, or 3)", argc);
243
+ break;
244
+ }
245
+ m = gsl_matrix_complex_calloc(n, n);
246
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
247
+ for (i = 0; i < n; i++) gsl_matrix_complex_set(m, i, i, z);
248
+ return Data_Wrap_Struct(klass, 0, gsl_matrix_complex_free, m);
249
+ }
250
+
251
+ static VALUE rb_gsl_matrix_complex_identity(VALUE klass, VALUE nn)
252
+ {
253
+ size_t n, i;
254
+ gsl_matrix_complex *m = NULL;
255
+ gsl_complex z;
256
+ CHECK_FIXNUM(nn);
257
+ n = FIX2INT(nn);
258
+ m = gsl_matrix_complex_calloc(n, n);
259
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_calloc failed");
260
+ z = gsl_complex_rect(1.0, 0.0);
261
+ for (i = 0; i < n; i++) gsl_matrix_complex_set(m, i, i, z);
262
+ return Data_Wrap_Struct(klass, 0, gsl_matrix_complex_free, m);
263
+ }
264
+
265
+ static VALUE rb_gsl_matrix_complex_set_zero(VALUE obj)
266
+ {
267
+ gsl_matrix_complex *m = NULL;
268
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
269
+ gsl_matrix_complex_set_zero(m);
270
+ return obj;
271
+ }
272
+
273
+ static VALUE rb_gsl_matrix_complex_set_identity(VALUE obj)
274
+ {
275
+ gsl_matrix_complex *m = NULL;
276
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
277
+ gsl_matrix_complex_set_identity(m);
278
+ return obj;
279
+ }
280
+
281
+ static VALUE rb_gsl_matrix_complex_set_all(VALUE obj, VALUE s)
282
+ {
283
+ gsl_matrix_complex *m = NULL;
284
+ gsl_complex c, *z = NULL;
285
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
286
+ switch (TYPE(s)) {
287
+ case T_FLOAT:
288
+ case T_BIGNUM:
289
+ case T_FIXNUM:
290
+ c.dat[0] = NUM2DBL(s);
291
+ c.dat[1] = 0.0;
292
+ gsl_matrix_complex_set_all(m, c);
293
+ break;
294
+ case T_ARRAY:
295
+ c.dat[0] = NUM2DBL(rb_ary_entry(s, 0));
296
+ c.dat[1] = NUM2DBL(rb_ary_entry(s, 1));
297
+ gsl_matrix_complex_set_all(m, c);
298
+ break;
299
+ default:
300
+ if (rb_obj_is_kind_of(s, cgsl_complex)) {
301
+ Data_Get_Struct(s, gsl_complex, z);
302
+ gsl_matrix_complex_set_all(m, *z);
303
+ } else {
304
+ rb_raise(rb_eTypeError,
305
+ "wrong argument type %s", rb_class2name(CLASS_OF(s)));
306
+ }
307
+ break;
308
+ }
309
+ return obj;
310
+ }
311
+
312
+ void rb_gsl_vector_complex_set_subvector(int argc, VALUE *argv, gsl_vector_complex *v, VALUE other);
313
+ static VALUE rb_gsl_matrix_complex_set(int argc, VALUE *argv, VALUE obj)
314
+ {
315
+ gsl_matrix_complex *m = NULL, *mother;
316
+ gsl_matrix_complex_view mv;
317
+ gsl_vector_complex_view vv;
318
+ gsl_complex tmp;
319
+ VALUE other, row, row_set_argv[2];
320
+ int ii, ij, step;
321
+ size_t i, j, k, n1, n2, nother;
322
+ double beg, end;
323
+
324
+ if(argc < 1 || argc > 5) {
325
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-5)", argc);
326
+ }
327
+
328
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
329
+ other = argv[argc-1];
330
+
331
+ if(argc == 1) {
332
+ // m[] = x
333
+ gsl_matrix_complex_set_all(m, rb_gsl_obj_to_gsl_complex(other, NULL));
334
+ } else if(argc == 3 && TYPE(argv[0]) == T_FIXNUM && TYPE(argv[1]) == T_FIXNUM) {
335
+ // m[i,j] = x
336
+ ii = FIX2INT(argv[0]);
337
+ ij = FIX2INT(argv[1]);
338
+ if(ii < 0) ii += m->size1;
339
+ if(ij < 0) ij += m->size2;
340
+ gsl_matrix_complex_set(m, (size_t)ii, (size_t)ij, rb_gsl_obj_to_gsl_complex(other, NULL));
341
+ } else if(TYPE(argv[0]) == T_ARRAY) {
342
+ // m.set(row0...)
343
+ row_set_argv[0] = INT2FIX(0);
344
+ row_set_argv[1] = INT2FIX(m->size2);
345
+
346
+ for(k = 0; k < argc && k < m->size1; k++) {
347
+ vv = gsl_matrix_complex_row(m, k);
348
+ rb_gsl_vector_complex_set_subvector(2, row_set_argv, &vv.vector, argv[k]);
349
+ }
350
+ } else {
351
+ // x -> assignment to m.submatrix(i...)
352
+ parse_submatrix_args(argc-1, argv, m->size1, m->size2, &i, &j, &n1, &n2);
353
+ if(n1 == 0) n1 = 1;
354
+ if(n2 == 0) n2 = 1;
355
+ mv = gsl_matrix_complex_submatrix(m, i, j, n1, n2);
356
+ if(rb_obj_is_kind_of(other, cgsl_matrix_complex)) {
357
+ // m[...] = m_other
358
+ Data_Get_Struct(other, gsl_matrix_complex, mother);
359
+ if(n1 * n2 != mother->size1 * mother->size2) {
360
+ rb_raise(rb_eRangeError, "sizes do not match (%d x %d != %d x %d)",
361
+ (int) n1, (int) n2, (int) mother->size1, (int) mother->size2);
362
+ }
363
+ // TODO Change to gsl_matrix_memmove if/when GSL has such a function
364
+ // because gsl_matrix_memcpy does not handle overlapping regions (e.g.
365
+ // Views) well.
366
+ gsl_matrix_complex_memcpy(&mv.matrix, mother);
367
+ } else if(rb_obj_is_kind_of(other, rb_cArray)) {
368
+ row_set_argv[0] = INT2FIX(0);
369
+ row_set_argv[1] = INT2FIX(n2);
370
+
371
+ if(n1 == 1) {
372
+ // m[...] = [col0, ...] # single row
373
+ vv = gsl_matrix_complex_row(&mv.matrix, 0);
374
+ rb_gsl_vector_complex_set_subvector(2, row_set_argv, &vv.vector, other);
375
+ } else {
376
+ // m[...] = [[row0], [row1], ...] # multiple rows
377
+ if(n1 != RARRAY_LEN(other)) {
378
+ rb_raise(rb_eRangeError, "row counts do not match (%d != %d)",
379
+ (int) n1, (int) RARRAY_LEN(other));
380
+ }
381
+ for(k = 0; k < n1; k++) {
382
+ vv = gsl_matrix_complex_row(&mv.matrix, k);
383
+ row = rb_ary_entry(other, k);
384
+ rb_gsl_vector_complex_set_subvector(2, row_set_argv, &vv.vector, row);
385
+ }
386
+ }
387
+ } else if(rb_obj_is_kind_of(other, rb_cRange)) {
388
+ // m[...] = beg..end
389
+ get_range_beg_en_n(other, &beg, &end, &nother, &step);
390
+ if(n1 * n2 != nother) {
391
+ rb_raise(rb_eRangeError, "sizes do not match (%d x %d != %d)", (int) n1, (int) n2, (int) nother);
392
+ }
393
+ tmp = gsl_complex_rect(beg, 0.0);
394
+ for(k = 0; k < nother; k++) {
395
+ gsl_matrix_complex_set(&mv.matrix, k / n2, k % n2, tmp);
396
+ GSL_SET_REAL(&tmp, GSL_REAL(tmp) + step);
397
+ }
398
+ } else {
399
+ // m[...] = x
400
+ gsl_matrix_complex_set_all(&mv.matrix, rb_gsl_obj_to_gsl_complex(other, NULL));
401
+ }
402
+ }
403
+
404
+ return obj;
405
+ }
406
+
407
+ static VALUE rb_gsl_matrix_complex_set_row(int argc, VALUE *argv, VALUE obj)
408
+ {
409
+ gsl_matrix_complex *A = NULL;
410
+ size_t i, k;
411
+ gsl_complex z, *pz = &z;
412
+ if (argc < 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for >= 2)",
413
+ argc);
414
+ CHECK_FIXNUM(argv[0]);
415
+ Data_Get_Struct(obj, gsl_matrix_complex, A);
416
+ i = FIX2INT(argv[0]);
417
+ for (k = 1; k < argc; k++) {
418
+ if (k-1 >= A->size1) break;
419
+ switch (TYPE(argv[k])) {
420
+ case T_ARRAY:
421
+ z = ary2complex(argv[k]);
422
+ break;
423
+ default:
424
+ CHECK_COMPLEX(argv[k]);
425
+ Data_Get_Struct(argv[k], gsl_complex, pz);
426
+ z = *pz;
427
+ break;
428
+ }
429
+ gsl_matrix_complex_set(A, i, k-1, z);
430
+ }
431
+ return obj;
432
+ }
433
+
434
+ static VALUE rb_gsl_matrix_complex_set_col(int argc, VALUE *argv, VALUE obj)
435
+ {
436
+ gsl_matrix_complex *A = NULL;
437
+ int j, k;
438
+ gsl_complex z, *pz = &z;
439
+ if (argc < 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for >= 2)",
440
+ argc);
441
+ CHECK_FIXNUM(argv[0]);
442
+ Data_Get_Struct(obj, gsl_matrix_complex, A);
443
+ j = FIX2INT(argv[0]);
444
+ for (k = 1; k < argc; k++) {
445
+ if (k-1 >= A->size2) break;
446
+ switch (TYPE(argv[k])) {
447
+ case T_ARRAY:
448
+ z = ary2complex(argv[k]);
449
+ break;
450
+ default:
451
+ CHECK_COMPLEX(argv[k]);
452
+ Data_Get_Struct(argv[k], gsl_complex, pz);
453
+ z = *pz;
454
+ break;
455
+ }
456
+ gsl_matrix_complex_set(A, k-1, j, z);
457
+ }
458
+ return obj;
459
+ }
460
+
461
+ static VALUE rb_gsl_matrix_complex_submatrix(int argc, VALUE *argv, VALUE obj);
462
+ static VALUE rb_gsl_matrix_complex_get(int argc, VALUE *argv, VALUE obj)
463
+ {
464
+ gsl_matrix_complex *m = NULL;
465
+ gsl_complex *c = NULL;
466
+ VALUE retval;
467
+ int ii, ij;
468
+
469
+ if(argc == 2 && TYPE(argv[0]) == T_FIXNUM && TYPE(argv[1]) == T_FIXNUM) {
470
+ // m[i,j]
471
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
472
+ ii = FIX2INT(argv[0]);
473
+ ij = FIX2INT(argv[1]);
474
+ if(ii < 0) ii += m->size1;
475
+ if(ij < 0) ij += m->size2;
476
+ c = ALLOC(gsl_complex);
477
+ *c = gsl_matrix_complex_get(m, (size_t)ii, (size_t)ij);
478
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
479
+ } else if(argc == 1 && TYPE(argv[0]) == T_FIXNUM) {
480
+ // m[i]
481
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
482
+ ii = FIX2INT(argv[0]);
483
+ if(ii < 0) ii += m->size1 * m->size2;
484
+ c = ALLOC(gsl_complex);
485
+ *c = gsl_matrix_complex_get(m, (size_t)(ii / m->size2), (size_t)(ii % m->size2));
486
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
487
+ } else if(argc == 1 && TYPE(argv[0]) == T_ARRAY) {
488
+ // m[[i,j]], to have parity with Real Matrix types
489
+ if(RARRAY_LEN(argv[0]) == 2) {
490
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
491
+ ii = FIX2INT(RARRAY_PTR(argv[0])[0]);
492
+ ij = FIX2INT(RARRAY_PTR(argv[0])[1]);
493
+ if(ii < 0) ii += m->size1;
494
+ if(ij < 0) ij += m->size2;
495
+ c = ALLOC(gsl_complex);
496
+ *c = gsl_matrix_complex_get(m, (size_t)ii, (size_t)ij);
497
+ retval = Data_Wrap_Struct(cgsl_complex, 0, free, c);
498
+ } else {
499
+ rb_raise(rb_eArgError, "Array index must have length 2, not %d", (int) RARRAY_LEN(argv[0]));
500
+ }
501
+ } else {
502
+ retval = rb_gsl_matrix_complex_submatrix(argc, argv, obj);
503
+ }
504
+
505
+ return retval;
506
+ }
507
+
508
+ static void rb_gsl_matrix_complex_collect_native(gsl_matrix_complex *src, gsl_matrix_complex *dst)
509
+ {
510
+ VALUE vz;
511
+ gsl_complex * zp;
512
+ size_t i, j;
513
+ for (i = 0; i < src->size1; i++) {
514
+ for (j = 0; j < src->size2; j++) {
515
+ vz = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, zp);
516
+ *zp = gsl_matrix_complex_get(src, i, j);
517
+ vz = rb_yield(vz);
518
+ CHECK_COMPLEX(vz);
519
+ Data_Get_Struct(vz, gsl_complex, zp);
520
+ gsl_matrix_complex_set(dst, i, j, *zp);
521
+ }
522
+ }
523
+ }
524
+
525
+ static VALUE rb_gsl_matrix_complex_collect(VALUE obj)
526
+ {
527
+ gsl_matrix_complex *m = NULL, *mnew;
528
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
529
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
530
+ rb_gsl_matrix_complex_collect_native(m, mnew);
531
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
532
+ }
533
+
534
+ static VALUE rb_gsl_matrix_complex_collect_bang(VALUE obj)
535
+ {
536
+ gsl_matrix_complex *m = NULL;
537
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
538
+ rb_gsl_matrix_complex_collect_native(m, m);
539
+ return obj;
540
+ }
541
+
542
+ static VALUE rb_gsl_matrix_complex_to_a(VALUE obj)
543
+ {
544
+ gsl_matrix_complex *m;
545
+ gsl_complex *c;
546
+ VALUE ma, ra;
547
+ size_t i, j;
548
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
549
+ ma = rb_ary_new2(m->size1);
550
+ for(i=0; i < m->size1; i++) {
551
+ ra = rb_ary_new2(m->size2);
552
+ rb_ary_store(ma, i, ra);
553
+ for(j=0; j < m->size2; j++) {
554
+ c = ALLOC(gsl_complex);
555
+ *c = gsl_matrix_complex_get(m, i, j);
556
+ rb_ary_store(ra, j, Data_Wrap_Struct(cgsl_complex, 0, free, c));
557
+ }
558
+ }
559
+ return ma;
560
+ }
561
+
562
+ static VALUE rb_gsl_matrix_complex_ptr(VALUE obj, VALUE i, VALUE j)
563
+ {
564
+ gsl_matrix_complex *m = NULL;
565
+ gsl_complex *c = NULL;
566
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
567
+ c = gsl_matrix_complex_ptr(m, FIX2INT(i), FIX2INT(j));
568
+ return Data_Wrap_Struct(cgsl_complex, 0, NULL, c);
569
+ }
570
+
571
+ static VALUE rb_gsl_matrix_complex_printf(int argc, VALUE *argv, VALUE obj)
572
+ {
573
+ gsl_matrix_complex *h = NULL;
574
+ int status;
575
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
576
+ if (argc == 1) {
577
+ Check_Type(argv[0], T_STRING);
578
+ status = gsl_matrix_complex_fprintf(stdout, h, STR2CSTR(argv[0]));
579
+ } else {
580
+ status = gsl_matrix_complex_fprintf(stdout, h, "%g");
581
+ }
582
+ return INT2FIX(status);
583
+ }
584
+
585
+ static VALUE rb_gsl_matrix_complex_print(VALUE obj)
586
+ {
587
+ gsl_matrix_complex *h = NULL;
588
+ gsl_complex *z = NULL;
589
+ size_t i, j;
590
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
591
+ printf("[ ");
592
+ for (i = 0; i < h->size1; i++) {
593
+ if (i != 0) printf(" ");
594
+ for (j = 0; j < h->size2; j++) {
595
+ z = gsl_matrix_complex_ptr(h, i, j);
596
+ printf("[%4.3e %4.3e] ", GSL_REAL(*z), GSL_IMAG(*z));
597
+ }
598
+ if (i != h->size1 -1) printf("\n");
599
+ else printf("]\n");
600
+ }
601
+ return obj;
602
+ }
603
+
604
+ static VALUE rb_gsl_matrix_complex_to_s(int argc, VALUE *argv, VALUE obj)
605
+ {
606
+ gsl_matrix_complex *m = NULL;
607
+ char buf[64];
608
+ size_t i, j;
609
+ VALUE str;
610
+ gsl_complex z;
611
+ int max_rows = 4;
612
+ int max_cols = 4;
613
+
614
+ switch(argc){
615
+ case 2: max_cols = NUM2INT(argv[1]);
616
+ case 1: max_rows = NUM2INT(argv[0]);
617
+ case 0: break;
618
+ default:
619
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0, 1, or 2)", argc);
620
+ }
621
+
622
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
623
+ if (m->size1 == 0 && m->size2 == 0) return rb_str_new2("[ ]");
624
+ str = rb_str_new2("[ ");
625
+ for (i = 0; i < m->size1; i++) {
626
+ if (i != 0) {
627
+ rb_str_cat(str, "\n ", 3);
628
+ }
629
+ for (j = 0; j < m->size2; j++) {
630
+ z = gsl_matrix_complex_get(m, i, j);
631
+ sprintf(buf,
632
+ "%s[ %4.3e %4.3e ]", (j==0) ? "" : " ", GSL_REAL(z), GSL_IMAG(z));
633
+ rb_str_cat(str, buf, strlen(buf));
634
+ // if too many cols
635
+ if (j >= max_cols-1 && j != m->size2-1) {
636
+ rb_str_cat(str, " ...", 4);
637
+ break;
638
+ }
639
+ }
640
+ // if too many rows
641
+ if (i >= max_rows-1 && i != m->size1-1) {
642
+ rb_str_cat(str, "\n ...", 6);
643
+ break;
644
+ }
645
+ }
646
+ rb_str_cat(str, " ]", 2);
647
+ return str;
648
+ }
649
+
650
+ static VALUE rb_gsl_matrix_complex_inspect(int argc, VALUE *argv, VALUE obj)
651
+ {
652
+ VALUE str;
653
+ char buf[128];
654
+ gsl_matrix_complex *m;
655
+
656
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
657
+ sprintf(buf, "#<%s[%lu,%lu]:%#lx>\n", rb_class2name(CLASS_OF(obj)), m->size1, m->size2, NUM2ULONG(rb_obj_id(obj)));
658
+ str = rb_str_new2(buf);
659
+ return rb_str_concat(str, rb_gsl_matrix_complex_to_s(argc, argv, obj));
660
+ }
661
+
662
+ static VALUE rb_gsl_matrix_complex_fwrite(VALUE obj, VALUE io)
663
+ {
664
+ gsl_matrix_complex *h = NULL;
665
+ FILE *fp = NULL;
666
+ int status, flag = 0;
667
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
668
+ fp = rb_gsl_open_writefile(io, &flag);
669
+ status = gsl_matrix_complex_fwrite(fp, h);
670
+ if (flag == 1) fclose(fp);
671
+ return INT2FIX(status);
672
+ }
673
+
674
+ static VALUE rb_gsl_matrix_complex_fread(VALUE obj, VALUE io)
675
+ {
676
+ gsl_matrix_complex *h = NULL;
677
+ FILE *f = NULL;
678
+ int status, flag = 0;
679
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
680
+ f = rb_gsl_open_readfile(io, &flag);
681
+ status = gsl_matrix_complex_fread(f, h);
682
+ if (flag == 1) fclose(f);
683
+ return INT2FIX(status);
684
+ }
685
+
686
+ static VALUE rb_gsl_matrix_complex_fprintf(int argc, VALUE *argv, VALUE obj)
687
+ {
688
+ gsl_matrix_complex *h = NULL;
689
+ FILE *fp = NULL;
690
+ int status, flag = 0;
691
+ if (argc != 1 && argc != 2) {
692
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
693
+ }
694
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
695
+ fp = rb_gsl_open_writefile(argv[0], &flag);
696
+ if (argc == 2) {
697
+ Check_Type(argv[1], T_STRING);
698
+ status = gsl_matrix_complex_fprintf(fp, h, STR2CSTR(argv[1]));
699
+ } else {
700
+ status = gsl_matrix_complex_fprintf(fp, h, "%g");
701
+ }
702
+ if (flag == 1) fclose(fp);
703
+ return INT2FIX(status);
704
+ }
705
+
706
+ static VALUE rb_gsl_matrix_complex_fscanf(VALUE obj, VALUE io)
707
+ {
708
+ gsl_matrix_complex *h = NULL;
709
+ FILE *f = NULL;
710
+ int status, flag = 0;
711
+ Data_Get_Struct(obj, gsl_matrix_complex, h);
712
+ f = rb_gsl_open_readfile(io, &flag);
713
+ status = gsl_matrix_complex_fscanf(f, h);
714
+ if (flag == 1) fclose(f);
715
+ return INT2FIX(status);
716
+ }
717
+
718
+ gsl_matrix_complex_view* gsl_matrix_complex_view_alloc()
719
+ {
720
+ gsl_matrix_complex_view *vv = NULL;
721
+ vv = ALLOC(gsl_matrix_complex_view);
722
+ if (vv == NULL) rb_raise(rb_eRuntimeError, "malloc failed");
723
+ return vv;
724
+ }
725
+
726
+ void gsl_matrix_complex_view_free(gsl_matrix_view * vv)
727
+ {
728
+ free((gsl_matrix_complex_view *) vv);
729
+ }
730
+
731
+ /* singleton */
732
+ static VALUE rb_gsl_matrix_complex_memcpy(VALUE obj, VALUE dst, VALUE src)
733
+ {
734
+ gsl_matrix_complex *m, *dest;
735
+ CHECK_MATRIX_COMPLEX(dst);
736
+ CHECK_MATRIX_COMPLEX(src);
737
+ Data_Get_Struct(dst, gsl_matrix_complex, dest);
738
+ Data_Get_Struct(src, gsl_matrix_complex, m);
739
+ gsl_matrix_complex_memcpy(dest, m);
740
+ return dst;
741
+ }
742
+
743
+ static VALUE rb_gsl_matrix_complex_clone(VALUE obj)
744
+ {
745
+ gsl_matrix_complex *m, *mnew = NULL;
746
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
747
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
748
+ if (mnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
749
+ gsl_matrix_complex_memcpy(mnew, m);
750
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
751
+ }
752
+
753
+ static VALUE rb_gsl_matrix_complex_swap_rows(VALUE obj, VALUE i, VALUE j)
754
+ {
755
+ gsl_matrix_complex *m = NULL;
756
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
757
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
758
+ gsl_matrix_complex_swap_rows(m, FIX2INT(i), FIX2INT(j));
759
+ return obj;
760
+ }
761
+
762
+ static VALUE rb_gsl_matrix_complex_swap_columns(VALUE obj, VALUE i, VALUE j)
763
+ {
764
+ gsl_matrix_complex *m = NULL;
765
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
766
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
767
+ gsl_matrix_complex_swap_columns(m, FIX2INT(i), FIX2INT(j));
768
+ return obj;
769
+ }
770
+
771
+ static VALUE rb_gsl_matrix_complex_swap_rowcol(VALUE obj, VALUE i, VALUE j)
772
+ {
773
+ gsl_matrix_complex *m = NULL;
774
+ CHECK_FIXNUM(i); CHECK_FIXNUM(j);
775
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
776
+ gsl_matrix_complex_swap_rowcol(m, FIX2INT(i), FIX2INT(j));
777
+ return obj;
778
+ }
779
+
780
+ static VALUE rb_gsl_matrix_complex_transpose(VALUE obj)
781
+ {
782
+ gsl_matrix_complex *m = NULL;
783
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
784
+ gsl_matrix_complex_transpose(m);
785
+ return obj;
786
+ }
787
+
788
+ static VALUE rb_gsl_matrix_complex_isnull(VALUE obj)
789
+ {
790
+ gsl_matrix_complex *m = NULL;
791
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
792
+ if (gsl_matrix_complex_isnull(m)) return Qtrue;
793
+ else return Qfalse;
794
+ }
795
+
796
+ static VALUE rb_gsl_matrix_complex_add(VALUE obj, VALUE mmb)
797
+ {
798
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_ADD, obj, mmb);
799
+ }
800
+
801
+ static VALUE rb_gsl_matrix_complex_sub(VALUE obj, VALUE mmb)
802
+ {
803
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_SUB, obj, mmb);
804
+ }
805
+
806
+ static VALUE rb_gsl_matrix_complex_mul_elements(VALUE obj, VALUE mmb)
807
+ {
808
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_MUL, obj, mmb);
809
+ }
810
+
811
+ static VALUE rb_gsl_matrix_complex_div_elements(VALUE obj, VALUE mmb)
812
+ {
813
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_DIV, obj, mmb);
814
+ }
815
+
816
+ static VALUE rb_gsl_matrix_complex_scale(VALUE obj, VALUE s)
817
+ {
818
+ return rb_gsl_matrix_complex_arithmetics(GSL_MATRIX_COMPLEX_MUL, obj, s);
819
+ }
820
+
821
+ static VALUE rb_gsl_matrix_complex_scale_bang(VALUE obj, VALUE s)
822
+ {
823
+ gsl_matrix_complex *m;
824
+ gsl_complex c, *z = &c;
825
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
826
+ switch (TYPE(s)) {
827
+ case T_FIXNUM:
828
+ case T_FLOAT:
829
+ GSL_SET_REAL(z, NUM2DBL(s));
830
+ GSL_SET_IMAG(z, 0.0);
831
+ break;
832
+ default:
833
+ CHECK_COMPLEX(s);
834
+ Data_Get_Struct(s, gsl_complex, z);
835
+ break;
836
+ }
837
+ gsl_matrix_complex_scale(m, *z);
838
+ return obj;
839
+ }
840
+
841
+ static VALUE rb_gsl_matrix_complex_mul(VALUE obj, VALUE mb)
842
+ {
843
+ gsl_matrix_complex *cm = NULL, *cmb = NULL, *cmnew = NULL;
844
+ gsl_matrix *m = NULL;
845
+ gsl_vector *v = NULL;
846
+ gsl_vector_complex *vc = NULL, *vcnew = NULL;
847
+ gsl_complex a, b;
848
+ int flag = 0;
849
+ if (COMPLEX_P(mb) || TYPE(mb) == T_FIXNUM || TYPE(mb) == T_FLOAT)
850
+ return rb_gsl_matrix_complex_mul_elements(obj, mb);
851
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
852
+ if (VECTOR_P(mb)) {
853
+ Data_Get_Struct(mb, gsl_vector, v);
854
+ vc = vector_to_complex(v);
855
+ vcnew = gsl_vector_complex_calloc(vc->size);
856
+ a.dat[0] = 1.0; a.dat[1] = 0.0;
857
+ b.dat[0] = 0.0; b.dat[1] = 0.0;
858
+ gsl_blas_zgemv(CblasNoTrans, a, cm, vc, b, vcnew);
859
+ gsl_vector_complex_free(vc);
860
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vcnew);
861
+ }
862
+ if (VECTOR_COMPLEX_P(mb)) {
863
+ Data_Get_Struct(mb, gsl_vector_complex, vc);
864
+ vcnew = gsl_vector_complex_calloc(vc->size);
865
+ a.dat[0] = 1.0; a.dat[1] = 0.0;
866
+ b.dat[0] = 0.0; b.dat[1] = 0.0;
867
+ gsl_blas_zgemv(CblasNoTrans, a, cm, vc, b, vcnew);
868
+ return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vcnew);
869
+ }
870
+ if (MATRIX_P(mb)) {
871
+ Data_Get_Struct(mb, gsl_matrix, m);
872
+ cmb = matrix_to_complex(m);
873
+ flag = 1;
874
+ } else {
875
+ CHECK_MATRIX_COMPLEX(mb);
876
+ Data_Get_Struct(mb, gsl_matrix_complex, cmb);
877
+ }
878
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
879
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
880
+ gsl_matrix_complex_mul(cmnew, cm, cmb);
881
+ if (flag == 1) gsl_matrix_complex_free(cmb);
882
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
883
+ }
884
+
885
+ static VALUE rb_gsl_matrix_complex_mul2(VALUE obj, VALUE mb)
886
+ {
887
+ gsl_matrix_complex *cm = NULL, *cmb = NULL, *cmnew = NULL;
888
+ gsl_matrix *m = NULL;
889
+ int flag = 0;
890
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
891
+ if (MATRIX_P(mb)) {
892
+ Data_Get_Struct(mb, gsl_matrix, m);
893
+ cmb = matrix_to_complex(m);
894
+ flag = 1;
895
+ } else {
896
+ CHECK_MATRIX_COMPLEX(mb);
897
+ Data_Get_Struct(mb, gsl_matrix_complex, cmb);
898
+ }
899
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
900
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
901
+ gsl_matrix_complex_mul(cmnew, cm, cmb);
902
+ gsl_matrix_complex_memcpy(cm, cmnew);
903
+ if (flag == 1) gsl_matrix_complex_free(cmb);
904
+ return obj;
905
+ }
906
+
907
+ static VALUE rb_gsl_matrix_complex_add_diagonal(VALUE obj, VALUE s)
908
+ {
909
+ gsl_matrix_complex *m = NULL;
910
+ gsl_complex c, *z = NULL;
911
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
912
+ switch (TYPE(s)) {
913
+ case T_FLOAT:
914
+ case T_BIGNUM:
915
+ case T_FIXNUM:
916
+ c.dat[0] = NUM2DBL(s);
917
+ c.dat[1] = 0.0;
918
+ gsl_matrix_complex_add_diagonal(m, c);
919
+ break;
920
+ case T_ARRAY:
921
+ c.dat[0] = NUM2DBL(rb_ary_entry(s, 0));
922
+ c.dat[1] = NUM2DBL(rb_ary_entry(s, 1));
923
+ gsl_matrix_complex_add_diagonal(m, c);
924
+ break;
925
+ default:
926
+ if (rb_obj_is_kind_of(s, cgsl_complex)) {
927
+ Data_Get_Struct(s, gsl_complex, z);
928
+ gsl_matrix_complex_add_diagonal(m, *z);
929
+ } else {
930
+ rb_raise(rb_eTypeError,
931
+ "wrong argument type %s", rb_class2name(CLASS_OF(s)));
932
+ }
933
+ break;
934
+ }
935
+ return obj;
936
+ }
937
+
938
+ static VALUE rb_gsl_matrix_complex_submatrix(int argc, VALUE *argv, VALUE obj)
939
+ {
940
+ gsl_matrix_complex *m = NULL;
941
+ gsl_matrix_complex_view *mv = NULL;
942
+ gsl_vector_complex_view *vv = NULL;
943
+ size_t i, j, n1, n2;
944
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
945
+ parse_submatrix_args(argc, argv, m->size1, m->size2, &i, &j, &n1, &n2);
946
+ if(n1 == 0) {
947
+ vv = ALLOC(gsl_vector_complex_view);
948
+ *vv = gsl_matrix_complex_subrow(m, i, j, n2);
949
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, free, vv);
950
+ }
951
+ else if(n2 == 0) {
952
+ vv = ALLOC(gsl_vector_complex_view);
953
+ *vv = gsl_matrix_complex_subcolumn(m, j, i, n1);
954
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, free, vv);
955
+ } else {
956
+ mv = ALLOC(gsl_matrix_complex_view);
957
+ *mv = gsl_matrix_complex_submatrix(m, i, j, n1, n2);
958
+ return Data_Wrap_Struct(cgsl_matrix_complex_view, 0, free, mv);
959
+ }
960
+ }
961
+
962
+ static VALUE rb_gsl_matrix_complex_row(VALUE obj, VALUE i)
963
+ {
964
+ gsl_matrix_complex *m = NULL;
965
+ gsl_vector_complex_view *vv = NULL;
966
+ CHECK_FIXNUM(i);
967
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
968
+ vv = gsl_vector_complex_view_alloc();
969
+ *vv = gsl_matrix_complex_row(m, FIX2INT(i));
970
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
971
+ }
972
+
973
+ static VALUE rb_gsl_matrix_complex_column(VALUE obj, VALUE i)
974
+ {
975
+ gsl_matrix_complex *m = NULL;
976
+ gsl_vector_complex_view *vv = NULL;
977
+ CHECK_FIXNUM(i);
978
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
979
+ vv = gsl_vector_complex_view_alloc();
980
+ *vv = gsl_matrix_complex_column(m, FIX2INT(i));
981
+ return Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, gsl_vector_complex_view_free, vv);
982
+ }
983
+
984
+ static VALUE rb_gsl_matrix_complex_diagonal(VALUE obj)
985
+ {
986
+ gsl_matrix_complex *m = NULL;
987
+ gsl_vector_complex_view *vv = NULL;
988
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
989
+ vv = gsl_vector_complex_view_alloc();
990
+ *vv = gsl_matrix_complex_diagonal(m);
991
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
992
+ }
993
+
994
+ static VALUE rb_gsl_matrix_complex_set_diagonal(VALUE obj, VALUE diag)
995
+ {
996
+ gsl_matrix_complex *m = NULL;
997
+ gsl_vector_complex *v;
998
+ size_t i;
999
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1000
+ if (VECTOR_COMPLEX_P(diag)) {
1001
+ Data_Get_Struct(diag, gsl_vector_complex, v);
1002
+ for (i = 0; i < m->size1; i++) gsl_matrix_complex_set(m, i, i, gsl_vector_complex_get(v, i));
1003
+ } else {
1004
+ rb_raise(rb_eTypeError, "wrong argument type %s (GSL::Vector_Complex or Array expected)",
1005
+ rb_class2name(CLASS_OF(diag)));
1006
+ }
1007
+ return obj;
1008
+ }
1009
+
1010
+ static VALUE rb_gsl_matrix_complex_subdiagonal(VALUE obj, VALUE i)
1011
+ {
1012
+ gsl_matrix_complex *m = NULL;
1013
+ gsl_vector_complex_view *vv = NULL;
1014
+ CHECK_FIXNUM(i);
1015
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1016
+ vv = gsl_vector_complex_view_alloc();
1017
+ *vv = gsl_matrix_complex_subdiagonal(m, FIX2INT(i));
1018
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
1019
+ }
1020
+
1021
+ static VALUE rb_gsl_matrix_complex_superdiagonal(VALUE obj, VALUE i)
1022
+ {
1023
+ gsl_matrix_complex *m = NULL;
1024
+ gsl_vector_complex_view *vv = NULL;
1025
+ CHECK_FIXNUM(i);
1026
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1027
+ vv = gsl_vector_complex_view_alloc();
1028
+ *vv = gsl_matrix_complex_superdiagonal(m, FIX2INT(i));
1029
+ return Data_Wrap_Struct(cgsl_vector_complex_view, 0, gsl_vector_complex_view_free, vv);
1030
+ }
1031
+
1032
+ static VALUE rb_gsl_matrix_complex_coerce(VALUE obj, VALUE other)
1033
+ {
1034
+ gsl_matrix_complex *cm = NULL, *cmnew = NULL;
1035
+ gsl_matrix *m = NULL;
1036
+ gsl_complex z;
1037
+ VALUE vcm;
1038
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1039
+ switch (TYPE(other)) {
1040
+ case T_FLOAT:
1041
+ case T_FIXNUM:
1042
+ case T_BIGNUM:
1043
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
1044
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
1045
+ GSL_SET_REAL(&z, NUM2DBL(other));
1046
+ GSL_SET_IMAG(&z, 0.0);
1047
+ gsl_matrix_complex_set_all(cmnew, z);
1048
+ vcm = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1049
+ return rb_ary_new3(2, vcm, obj);
1050
+ break;
1051
+ default:
1052
+ if (rb_obj_is_kind_of(other, cgsl_matrix)) {
1053
+ Data_Get_Struct(other, gsl_matrix, m);
1054
+ cmnew = matrix_to_complex(m);
1055
+ vcm = Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1056
+ return rb_ary_new3(2, vcm, obj);
1057
+ } else {
1058
+ rb_raise(rb_eTypeError, "cannot coerce %s to GSL::Matrix::Complex",
1059
+ rb_class2name(CLASS_OF(other)));
1060
+ }
1061
+ break;
1062
+ }
1063
+ }
1064
+
1065
+ static VALUE rb_gsl_matrix_complex_real(VALUE obj)
1066
+ {
1067
+ gsl_matrix_complex *cm = NULL;
1068
+ gsl_matrix *m = NULL;
1069
+ gsl_complex z;
1070
+ size_t i, j;
1071
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1072
+ m = gsl_matrix_alloc(cm->size1, cm->size2);
1073
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_alloc failed");
1074
+ for (i = 0; i < cm->size1; i++) {
1075
+ for (j = 0; j < cm->size2; j++) {
1076
+ z = gsl_matrix_complex_get(cm, i, j);
1077
+ gsl_matrix_set(m, i, j, GSL_REAL(z));
1078
+ }
1079
+ }
1080
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, m);
1081
+ }
1082
+
1083
+ static VALUE rb_gsl_matrix_complex_imag(VALUE obj)
1084
+ {
1085
+ gsl_matrix_complex *cm = NULL;
1086
+ gsl_matrix *m = NULL;
1087
+ gsl_complex z;
1088
+ size_t i, j;
1089
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1090
+ m = gsl_matrix_alloc(cm->size1, cm->size2);
1091
+ if (m == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_alloc failed");
1092
+ for (i = 0; i < cm->size1; i++) {
1093
+ for (j = 0; j < cm->size2; j++) {
1094
+ z = gsl_matrix_complex_get(cm, i, j);
1095
+ gsl_matrix_set(m, i, j, GSL_IMAG(z));
1096
+ }
1097
+ }
1098
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, m);
1099
+ }
1100
+
1101
+ static void gsl_matrix_complex_conjugate(gsl_matrix_complex *cm)
1102
+ {
1103
+ gsl_complex z;
1104
+ size_t i, j;
1105
+ for (i = 0; i < cm->size1; i++) {
1106
+ for (j = 0; j < cm->size2; j++) {
1107
+ z = gsl_matrix_complex_get(cm, i, j);
1108
+ gsl_matrix_complex_set(cm, i, j, gsl_complex_conjugate(z));
1109
+ }
1110
+ }
1111
+ }
1112
+
1113
+ static void gsl_matrix_complex_conjugate2(gsl_matrix_complex *cmnew, gsl_matrix_complex *cm)
1114
+ {
1115
+ gsl_complex z;
1116
+ size_t i, j;
1117
+ for (i = 0; i < cm->size1; i++) {
1118
+ for (j = 0; j < cm->size2; j++) {
1119
+ z = gsl_matrix_complex_get(cm, i, j);
1120
+ gsl_matrix_complex_set(cmnew, i, j, gsl_complex_conjugate(z));
1121
+ }
1122
+ }
1123
+ }
1124
+
1125
+ static VALUE rb_gsl_matrix_complex_conjugate(VALUE obj)
1126
+ {
1127
+ gsl_matrix_complex *cm = NULL;
1128
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1129
+ gsl_matrix_complex_conjugate(cm);
1130
+ return obj;
1131
+ }
1132
+
1133
+ static VALUE rb_gsl_matrix_complex_conjugate2(VALUE obj)
1134
+ {
1135
+ gsl_matrix_complex *cm = NULL, *cmnew = NULL;
1136
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1137
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
1138
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
1139
+ gsl_matrix_complex_conjugate2(cmnew, cm);
1140
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1141
+ }
1142
+
1143
+ static VALUE rb_gsl_matrix_complex_dagger(VALUE obj)
1144
+ {
1145
+ gsl_matrix_complex *cm = NULL;
1146
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1147
+ gsl_matrix_complex_conjugate(cm);
1148
+ gsl_matrix_complex_transpose(cm);
1149
+ return obj;
1150
+ }
1151
+
1152
+ static VALUE rb_gsl_matrix_complex_dagger2(VALUE obj)
1153
+ {
1154
+ gsl_matrix_complex *cm = NULL, *cmnew = NULL;
1155
+ Data_Get_Struct(obj, gsl_matrix_complex, cm);
1156
+ cmnew = gsl_matrix_complex_alloc(cm->size1, cm->size2);
1157
+ if (cmnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
1158
+ gsl_matrix_complex_conjugate2(cmnew, cm);
1159
+ gsl_matrix_complex_transpose(cmnew);
1160
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, cmnew);
1161
+ }
1162
+
1163
+ static VALUE rb_gsl_matrix_complex_trace(VALUE obj)
1164
+ {
1165
+ gsl_matrix_complex *m = NULL;
1166
+ gsl_complex *trace = NULL;
1167
+ VALUE vtrace;
1168
+ size_t i;
1169
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1170
+ vtrace = Data_Make_Struct(cgsl_complex, gsl_complex, 0, free, trace);
1171
+ trace->dat[0] = 0.0; trace->dat[1] = 0.0;
1172
+ for (i = 0; i < m->size1; i++) *trace = gsl_complex_add(*trace, gsl_matrix_complex_get(m, i, i));
1173
+ return vtrace;
1174
+ }
1175
+
1176
+ static VALUE rb_gsl_matrix_complex_each_row(VALUE obj)
1177
+ {
1178
+ gsl_matrix_complex *m = NULL;
1179
+ gsl_vector_complex_view *vv;
1180
+ size_t i;
1181
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1182
+ for (i = 0; i < m->size1; i++) {
1183
+ vv = ALLOC(gsl_vector_complex_view);
1184
+ *vv = gsl_matrix_complex_row(m, i);
1185
+ rb_yield(Data_Wrap_Struct(cgsl_vector_complex_view, 0, free, vv));
1186
+ }
1187
+ return obj;
1188
+ }
1189
+
1190
+ static VALUE rb_gsl_matrix_complex_each_col(VALUE obj)
1191
+ {
1192
+ gsl_matrix_complex *m = NULL;
1193
+ gsl_vector_complex_view *vv;
1194
+ size_t i;
1195
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1196
+ for (i = 0; i < m->size2; i++) {
1197
+ vv = ALLOC(gsl_vector_complex_view);
1198
+ *vv = gsl_matrix_complex_column(m, i);
1199
+ rb_yield(Data_Wrap_Struct(cgsl_vector_complex_col_view, 0, free, vv));
1200
+ }
1201
+ return obj;
1202
+ }
1203
+
1204
+ static VALUE rb_gsl_matrix_complex_size1(VALUE obj)
1205
+ {
1206
+ gsl_matrix_complex *m = NULL;
1207
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1208
+ return INT2FIX(m->size1);
1209
+ }
1210
+ static VALUE rb_gsl_matrix_complex_size2(VALUE obj)
1211
+ {
1212
+ gsl_matrix_complex *m = NULL;
1213
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1214
+ return INT2FIX(m->size2);
1215
+ }
1216
+ static VALUE rb_gsl_matrix_complex_shape(VALUE obj)
1217
+ {
1218
+ gsl_matrix_complex *m = NULL;
1219
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1220
+ return rb_ary_new3(2, INT2FIX(m->size1), INT2FIX(m->size2));
1221
+ }
1222
+
1223
+ static VALUE rb_gsl_matrix_complex_uplus(VALUE obj)
1224
+ {
1225
+ return obj;
1226
+ }
1227
+
1228
+ static VALUE rb_gsl_matrix_complex_uminus(VALUE obj)
1229
+ {
1230
+ gsl_matrix_complex *m = NULL, *mnew;
1231
+ size_t i, j;
1232
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1233
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
1234
+ for (i = 0; i < m->size1; i++) {
1235
+ for (j = 0; j < m->size2; j++) {
1236
+ gsl_matrix_complex_set(mnew, i, j, gsl_complex_negative(gsl_matrix_complex_get(m, i, j)));
1237
+ }
1238
+ }
1239
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1240
+ }
1241
+
1242
+ static VALUE rb_gsl_matrix_complex_XXX(VALUE obj, double (*f)(gsl_complex))
1243
+ {
1244
+ gsl_matrix_complex *m;
1245
+ gsl_matrix *mnew;
1246
+ size_t i, j;
1247
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1248
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
1249
+ for (i = 0; i < m->size1; i++) {
1250
+ for (j = 0; j < m->size2; j++) {
1251
+ gsl_matrix_set(mnew, i, j, (*f)(gsl_matrix_complex_get(m, i, j)));
1252
+ }
1253
+ }
1254
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
1255
+ }
1256
+
1257
+ static VALUE rb_gsl_matrix_complex_arg(VALUE obj)
1258
+ {
1259
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_arg);
1260
+ }
1261
+
1262
+ static VALUE rb_gsl_matrix_complex_abs(VALUE obj)
1263
+ {
1264
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_abs);
1265
+ }
1266
+
1267
+ static VALUE rb_gsl_matrix_complex_abs2(VALUE obj)
1268
+ {
1269
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_abs2);
1270
+ }
1271
+
1272
+ static VALUE rb_gsl_matrix_complex_logabs(VALUE obj)
1273
+ {
1274
+ return rb_gsl_matrix_complex_XXX(obj, gsl_complex_logabs);
1275
+ }
1276
+
1277
+ static VALUE rb_gsl_matrix_complex_XXX_complex(VALUE obj,
1278
+ gsl_complex (*f)(gsl_complex))
1279
+ {
1280
+ gsl_matrix_complex *m, *mnew;
1281
+ size_t i, j;
1282
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1283
+ mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
1284
+ for (i = 0; i < m->size1; i++) {
1285
+ for (j = 0; j < m->size2; j++) {
1286
+ gsl_matrix_complex_set(mnew, i, j, (*f)(gsl_matrix_complex_get(m, i, j)));
1287
+ }
1288
+ }
1289
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1290
+ }
1291
+
1292
+ static VALUE rb_gsl_matrix_complex_sqrt(VALUE obj)
1293
+ {
1294
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sqrt);
1295
+ }
1296
+
1297
+ static VALUE rb_gsl_matrix_complex_exp(VALUE obj)
1298
+ {
1299
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_exp);
1300
+ }
1301
+
1302
+ static VALUE rb_gsl_matrix_complex_log(VALUE obj)
1303
+ {
1304
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_log);
1305
+ }
1306
+
1307
+ static VALUE rb_gsl_matrix_complex_log10(VALUE obj)
1308
+ {
1309
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_log10);
1310
+ }
1311
+
1312
+ static VALUE rb_gsl_matrix_complex_sin(VALUE obj)
1313
+ {
1314
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sin);
1315
+ }
1316
+
1317
+ static VALUE rb_gsl_matrix_complex_cos(VALUE obj)
1318
+ {
1319
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_cos);
1320
+ }
1321
+
1322
+ static VALUE rb_gsl_matrix_complex_tan(VALUE obj)
1323
+ {
1324
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_tan);
1325
+ }
1326
+
1327
+ static VALUE rb_gsl_matrix_complex_sec(VALUE obj)
1328
+ {
1329
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sec);
1330
+ }
1331
+
1332
+ static VALUE rb_gsl_matrix_complex_csc(VALUE obj)
1333
+ {
1334
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_csc);
1335
+ }
1336
+
1337
+ static VALUE rb_gsl_matrix_complex_cot(VALUE obj)
1338
+ {
1339
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_cot);
1340
+ }
1341
+
1342
+ static VALUE rb_gsl_matrix_complex_arcsin(VALUE obj)
1343
+ {
1344
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsin);
1345
+ }
1346
+
1347
+ static VALUE rb_gsl_matrix_complex_arccos(VALUE obj)
1348
+ {
1349
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccos);
1350
+ }
1351
+
1352
+ static VALUE rb_gsl_matrix_complex_arctan(VALUE obj)
1353
+ {
1354
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arctan);
1355
+ }
1356
+
1357
+ static VALUE rb_gsl_matrix_complex_arcsec(VALUE obj)
1358
+ {
1359
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsec);
1360
+ }
1361
+
1362
+ static VALUE rb_gsl_matrix_complex_arccsc(VALUE obj)
1363
+ {
1364
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccsc);
1365
+ }
1366
+
1367
+ static VALUE rb_gsl_matrix_complex_arccot(VALUE obj)
1368
+ {
1369
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccot);
1370
+ }
1371
+
1372
+ static VALUE rb_gsl_matrix_complex_sinh(VALUE obj)
1373
+ {
1374
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sinh);
1375
+ }
1376
+
1377
+ static VALUE rb_gsl_matrix_complex_cosh(VALUE obj)
1378
+ {
1379
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_cosh);
1380
+ }
1381
+
1382
+ static VALUE rb_gsl_matrix_complex_tanh(VALUE obj)
1383
+ {
1384
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_tanh);
1385
+ }
1386
+
1387
+ static VALUE rb_gsl_matrix_complex_sech(VALUE obj)
1388
+ {
1389
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_sech);
1390
+ }
1391
+
1392
+ static VALUE rb_gsl_matrix_complex_csch(VALUE obj)
1393
+ {
1394
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_csch);
1395
+ }
1396
+ static VALUE rb_gsl_matrix_complex_coth(VALUE obj)
1397
+ {
1398
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_coth);
1399
+ }
1400
+
1401
+ static VALUE rb_gsl_matrix_complex_arcsinh(VALUE obj)
1402
+ {
1403
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsinh);
1404
+ }
1405
+
1406
+ static VALUE rb_gsl_matrix_complex_arccosh(VALUE obj)
1407
+ {
1408
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccosh);
1409
+ }
1410
+
1411
+ static VALUE rb_gsl_matrix_complex_arctanh(VALUE obj)
1412
+ {
1413
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arctanh);
1414
+ }
1415
+
1416
+ static VALUE rb_gsl_matrix_complex_arcsech(VALUE obj)
1417
+ {
1418
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arcsech);
1419
+ }
1420
+
1421
+ static VALUE rb_gsl_matrix_complex_arccsch(VALUE obj)
1422
+ {
1423
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccsch);
1424
+ }
1425
+
1426
+ static VALUE rb_gsl_matrix_complex_arccoth(VALUE obj)
1427
+ {
1428
+ return rb_gsl_matrix_complex_XXX_complex(obj, gsl_complex_arccoth);
1429
+ }
1430
+
1431
+ static VALUE rb_gsl_matrix_complex_indgen_bang(int argc, VALUE *argv[], VALUE obj)
1432
+ {
1433
+ gsl_matrix_complex *m = NULL;
1434
+ double start = 0, step = 1, x;
1435
+ size_t i, j;
1436
+ switch (argc) {
1437
+ case 0:
1438
+ break;
1439
+ case 1:
1440
+ start = NUM2DBL(argv[0]);
1441
+ break;
1442
+ case 2:
1443
+ start = NUM2DBL(argv[0]);
1444
+ step = NUM2DBL(argv[1]);
1445
+ break;
1446
+ default:
1447
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1448
+ }
1449
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1450
+ x = start;
1451
+ for (i = 0; i < m->size1; i++) {
1452
+ for (j = 0; j < m->size2; j++) {
1453
+ gsl_matrix_complex_set(m, i, j, gsl_complex_rect(x, 0));
1454
+ x += step;
1455
+ }
1456
+ }
1457
+ return obj;
1458
+ }
1459
+
1460
+ static VALUE rb_gsl_matrix_complex_indgen(int argc, VALUE *argv, VALUE obj)
1461
+ {
1462
+ gsl_matrix_complex *m = NULL, *mnew;
1463
+ double start = 0, step = 1, x;
1464
+ size_t i, j;
1465
+ switch (argc) {
1466
+ case 0:
1467
+ break;
1468
+ case 1:
1469
+ start = NUM2DBL(argv[0]);
1470
+ break;
1471
+ case 2:
1472
+ start = NUM2DBL(argv[0]);
1473
+ step = NUM2DBL(argv[1]);
1474
+ break;
1475
+ default:
1476
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-2)", argc);
1477
+ }
1478
+ Data_Get_Struct(obj, gsl_matrix_complex, m);
1479
+ mnew = gsl_matrix_complex_calloc(m->size1, m->size2);
1480
+ x = start;
1481
+ for (i = 0; i < mnew->size1; i++) {
1482
+ for (j = 0; j < mnew->size2; j++) {
1483
+ gsl_matrix_complex_set(mnew, i, j, gsl_complex_rect(x, 0));
1484
+ x += step;
1485
+ }
1486
+ }
1487
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1488
+ }
1489
+
1490
+ static VALUE rb_gsl_matrix_complex_indgen_singleton(int argc, VALUE *argv, VALUE obj)
1491
+ {
1492
+ gsl_matrix_complex *mnew;
1493
+ double start = 0, step = 1, x;
1494
+ size_t n1, n2, i, j;
1495
+ switch (argc) {
1496
+ case 2:
1497
+ n1 = (size_t) NUM2INT(argv[0]);
1498
+ n2 = (size_t) NUM2INT(argv[1]);
1499
+ break;
1500
+ case 3:
1501
+ n1 = (size_t) NUM2INT(argv[0]);
1502
+ n2 = (size_t) NUM2INT(argv[1]);
1503
+ start = NUM2DBL(argv[2]);
1504
+ break;
1505
+ case 4:
1506
+ n1 = (size_t) NUM2INT(argv[0]);
1507
+ n2 = (size_t) NUM2INT(argv[1]);
1508
+ start = NUM2DBL(argv[2]);
1509
+ step = NUM2DBL(argv[3]);
1510
+ break;
1511
+ default:
1512
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0-4)", argc);
1513
+ }
1514
+ mnew = gsl_matrix_complex_calloc(n1, n2);
1515
+ x = start;
1516
+ for (i = 0; i < mnew->size1; i++) {
1517
+ for (j = 0; j < mnew->size2; j++) {
1518
+ gsl_matrix_complex_set(mnew, i, j, gsl_complex_rect(x, 0));
1519
+ x += step;
1520
+ }
1521
+ }
1522
+ return Data_Wrap_Struct(cgsl_matrix_complex, 0, gsl_matrix_complex_free, mnew);
1523
+ }
1524
+
1525
+ // Starting with version 1.15, GSL provides a gsl_matrix_complex_equal
1526
+ // function, but it only determines absolute equality (i.e. is has no epsilon
1527
+ // argument).
1528
+ static int gsl_matrix_complex_equal_eps(const gsl_matrix_complex *m1,
1529
+ const gsl_matrix_complex *m2, double eps)
1530
+ {
1531
+ gsl_complex z1, z2;
1532
+ size_t i, j;
1533
+ if (m1->size1 != m2->size1) return 0;
1534
+ if (m1->size2 != m2->size2) return 0;
1535
+ for (i = 0; i < m1->size1; i++) {
1536
+ for (j = 0; j < m1->size2; j++) {
1537
+ z1 = gsl_matrix_complex_get(m1, i, j);
1538
+ z2 = gsl_matrix_complex_get(m2, i, j);
1539
+ if (!rbgsl_complex_equal(&z1, &z2, eps)) return 0;
1540
+ }
1541
+ }
1542
+ return 1;
1543
+ }
1544
+
1545
+ static VALUE rb_gsl_matrix_complex_equal(int argc, VALUE *argv, VALUE obj)
1546
+ {
1547
+ gsl_matrix_complex *m1, *m2;
1548
+ double eps = 1e-8;
1549
+ int ret;
1550
+ switch (argc) {
1551
+ case 1:
1552
+ eps = 1e-8;
1553
+ break;
1554
+ case 2:
1555
+ eps = NUM2DBL(argv[1]);
1556
+ break;
1557
+ default:
1558
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)\n", argc);
1559
+ }
1560
+ Data_Get_Struct(obj, gsl_matrix_complex, m1);
1561
+ CHECK_MATRIX_COMPLEX(argv[0]);
1562
+ Data_Get_Struct(argv[0], gsl_matrix_complex, m2);
1563
+ ret = gsl_matrix_complex_equal_eps(m1, m2, eps);
1564
+ if (ret == 1) return Qtrue;
1565
+ else return Qfalse;
1566
+ }
1567
+
1568
+ static VALUE rb_gsl_matrix_complex_not_equal(int argc, VALUE *argv, VALUE obj)
1569
+ {
1570
+ VALUE ret;
1571
+ ret = rb_gsl_matrix_complex_equal(argc, argv, obj);
1572
+ if (ret == Qtrue) return Qfalse;
1573
+ else return Qtrue;
1574
+ }
1575
+
1576
+ void Init_gsl_matrix_complex(VALUE module)
1577
+ {
1578
+ // rb_define_singleton_method(cgsl_matrix_complex, "new", rb_gsl_matrix_complex_new, 2);
1579
+ rb_define_singleton_method(cgsl_matrix_complex, "alloc", rb_gsl_matrix_complex_new, 2);
1580
+ rb_define_singleton_method(cgsl_matrix_complex, "[]", rb_gsl_matrix_complex_new, 2);
1581
+ rb_define_singleton_method(cgsl_matrix_complex, "calloc", rb_gsl_matrix_complex_new, 2);
1582
+ rb_define_singleton_method(cgsl_matrix_complex, "eye", rb_gsl_matrix_complex_eye, -1);
1583
+ rb_define_singleton_method(cgsl_matrix_complex, "diagonal", rb_gsl_matrix_complex_eye, -1);
1584
+ rb_define_singleton_method(cgsl_matrix_complex, "identity", rb_gsl_matrix_complex_identity, 1);
1585
+ rb_define_singleton_method(cgsl_matrix_complex, "unit", rb_gsl_matrix_complex_identity, 1);
1586
+ rb_define_singleton_method(cgsl_matrix_complex, "I", rb_gsl_matrix_complex_identity, 1);
1587
+
1588
+ rb_define_method(cgsl_matrix_complex, "set", rb_gsl_matrix_complex_set, -1);
1589
+ rb_define_alias(cgsl_matrix_complex, "[]=", "set");
1590
+
1591
+ rb_define_method(cgsl_matrix_complex, "set_row", rb_gsl_matrix_complex_set_row, -1);
1592
+ rb_define_method(cgsl_matrix_complex, "set_col", rb_gsl_matrix_complex_set_col, -1);
1593
+
1594
+ rb_define_method(cgsl_matrix_complex, "get", rb_gsl_matrix_complex_get, -1);
1595
+ rb_define_alias(cgsl_matrix_complex, "[]", "get");
1596
+ rb_define_method(cgsl_matrix_complex, "ptr", rb_gsl_matrix_complex_ptr, 2);
1597
+
1598
+ rb_define_method(cgsl_matrix_complex, "to_s", rb_gsl_matrix_complex_to_s, -1);
1599
+ rb_define_method(cgsl_matrix_complex, "fprintf", rb_gsl_matrix_complex_fprintf, -1);
1600
+ rb_define_method(cgsl_matrix_complex, "printf", rb_gsl_matrix_complex_printf, -1);
1601
+ rb_define_method(cgsl_matrix_complex, "print", rb_gsl_matrix_complex_print, 0);
1602
+ rb_define_method(cgsl_matrix_complex, "inspect", rb_gsl_matrix_complex_inspect, -1);
1603
+ rb_define_method(cgsl_matrix_complex, "fwrite", rb_gsl_matrix_complex_fwrite, 1);
1604
+ rb_define_method(cgsl_matrix_complex, "fread", rb_gsl_matrix_complex_fread, 1);
1605
+ rb_define_method(cgsl_matrix_complex, "fscanf", rb_gsl_matrix_complex_fscanf, 1);
1606
+
1607
+ rb_define_singleton_method(cgsl_matrix_complex, "memcpy", rb_gsl_matrix_complex_memcpy, 2);
1608
+ rb_define_method(cgsl_matrix_complex, "clone", rb_gsl_matrix_complex_clone, 0);
1609
+ rb_define_alias(cgsl_matrix_complex, "duplicate", "clone");
1610
+ rb_define_alias(cgsl_matrix_complex, "dup", "clone");
1611
+ rb_define_method(cgsl_matrix_complex, "swap_rows", rb_gsl_matrix_complex_swap_rows, 2);
1612
+ rb_define_method(cgsl_matrix_complex, "swap_columns", rb_gsl_matrix_complex_swap_columns, 2);
1613
+ rb_define_method(cgsl_matrix_complex, "swap_rowcol", rb_gsl_matrix_complex_swap_rowcol, 2);
1614
+
1615
+ rb_define_method(cgsl_matrix_complex, "transpose", rb_gsl_matrix_complex_transpose, 0);
1616
+ rb_define_method(cgsl_matrix_complex, "isnull", rb_gsl_matrix_complex_isnull, 0);
1617
+
1618
+ rb_define_method(cgsl_matrix_complex, "add", rb_gsl_matrix_complex_add, 1);
1619
+ rb_define_alias(cgsl_matrix_complex, "add_constant", "add");
1620
+ rb_define_alias(cgsl_matrix_complex, "+", "add");
1621
+ rb_define_method(cgsl_matrix_complex, "sub", rb_gsl_matrix_complex_sub, 1);
1622
+ rb_define_alias(cgsl_matrix_complex, "-", "sub");
1623
+ rb_define_method(cgsl_matrix_complex, "mul_elements", rb_gsl_matrix_complex_mul_elements, 1);
1624
+ rb_define_method(cgsl_matrix_complex, "div_elements", rb_gsl_matrix_complex_div_elements, 1);
1625
+ rb_define_alias(cgsl_matrix_complex, "/", "div_elements");
1626
+ rb_define_method(cgsl_matrix_complex, "scale", rb_gsl_matrix_complex_scale, 1);
1627
+ rb_define_method(cgsl_matrix_complex, "scale!", rb_gsl_matrix_complex_scale_bang, 1);
1628
+
1629
+ rb_define_method(cgsl_matrix_complex, "add_diagonal", rb_gsl_matrix_complex_add_diagonal, 1);
1630
+
1631
+ rb_define_method(cgsl_matrix_complex, "set_zero", rb_gsl_matrix_complex_set_zero, 0);
1632
+ rb_define_method(cgsl_matrix_complex, "set_identity", rb_gsl_matrix_complex_set_identity, 0);
1633
+ rb_define_method(cgsl_matrix_complex, "set_all", rb_gsl_matrix_complex_set_all, 1);
1634
+
1635
+ rb_define_method(cgsl_matrix_complex, "submatrix", rb_gsl_matrix_complex_submatrix, -1);
1636
+ rb_define_alias(cgsl_matrix_complex, "view", "submatrix");
1637
+ rb_define_method(cgsl_matrix_complex, "row", rb_gsl_matrix_complex_row, 1);
1638
+ /* rb_define_alias(cgsl_matrix_complex, "[]", "row");*/
1639
+ rb_define_method(cgsl_matrix_complex, "column", rb_gsl_matrix_complex_column, 1);
1640
+ rb_define_alias(cgsl_matrix_complex, "col", "column");
1641
+ rb_define_method(cgsl_matrix_complex, "diagonal", rb_gsl_matrix_complex_diagonal, 0);
1642
+ rb_define_alias(cgsl_matrix_complex, "diag", "diagonal");
1643
+ rb_define_method(cgsl_matrix_complex, "set_diagonal", rb_gsl_matrix_complex_set_diagonal, 1);
1644
+ rb_define_method(cgsl_matrix_complex, "subdiagonal", rb_gsl_matrix_complex_subdiagonal, 1);
1645
+ rb_define_method(cgsl_matrix_complex, "superdiagonal", rb_gsl_matrix_complex_superdiagonal, 1);
1646
+
1647
+ rb_define_method(cgsl_matrix_complex, "coerce", rb_gsl_matrix_complex_coerce, 1);
1648
+
1649
+ rb_define_method(cgsl_matrix_complex, "mul", rb_gsl_matrix_complex_mul, 1);
1650
+ rb_define_alias(cgsl_matrix_complex, "*", "mul");
1651
+ rb_define_method(cgsl_matrix_complex, "mul!", rb_gsl_matrix_complex_mul2, 1);
1652
+
1653
+ rb_define_method(cgsl_matrix_complex, "real", rb_gsl_matrix_complex_real, 0);
1654
+ rb_define_alias(cgsl_matrix_complex, "to_real", "real");
1655
+ rb_define_alias(cgsl_matrix_complex, "re", "real");
1656
+ rb_define_method(cgsl_matrix_complex, "imag", rb_gsl_matrix_complex_imag, 0);
1657
+ rb_define_alias(cgsl_matrix_complex, "im", "imag");
1658
+
1659
+ /* 25.June.2004 */
1660
+ rb_define_method(cgsl_matrix_complex, "conjugate!", rb_gsl_matrix_complex_conjugate, 0);
1661
+ rb_define_alias(cgsl_matrix_complex, "conj!", "conjugate!");
1662
+ rb_define_method(cgsl_matrix_complex, "conjugate", rb_gsl_matrix_complex_conjugate2, 0);
1663
+ rb_define_alias(cgsl_matrix_complex, "conj", "conjugate");
1664
+ rb_define_method(cgsl_matrix_complex, "dagger!", rb_gsl_matrix_complex_dagger, 0);
1665
+ rb_define_method(cgsl_matrix_complex, "dagger", rb_gsl_matrix_complex_dagger2, 0);
1666
+
1667
+ rb_define_method(cgsl_matrix_complex, "trace", rb_gsl_matrix_complex_trace, 0);
1668
+ rb_define_method(cgsl_matrix_complex, "each_row", rb_gsl_matrix_complex_each_row, 0);
1669
+ rb_define_method(cgsl_matrix_complex, "each_col", rb_gsl_matrix_complex_each_col, 0);
1670
+ rb_define_alias(cgsl_matrix_complex, "each_column", "each_col");
1671
+ rb_define_method(cgsl_matrix_complex, "collect", rb_gsl_matrix_complex_collect, 0);
1672
+ rb_define_method(cgsl_matrix_complex, "collect!", rb_gsl_matrix_complex_collect_bang, 0);
1673
+ rb_define_alias(cgsl_matrix_complex, "map", "collect");
1674
+ rb_define_alias(cgsl_matrix_complex, "map!", "collect!");
1675
+
1676
+ rb_define_method(cgsl_matrix_complex, "to_a", rb_gsl_matrix_complex_to_a, 0);
1677
+
1678
+ rb_define_method(cgsl_matrix_complex, "size1", rb_gsl_matrix_complex_size1, 0);
1679
+ rb_define_method(cgsl_matrix_complex, "size2", rb_gsl_matrix_complex_size2, 0);
1680
+ rb_define_method(cgsl_matrix_complex, "shape", rb_gsl_matrix_complex_shape, 0);
1681
+ rb_define_alias(cgsl_matrix_complex, "size", "shape");
1682
+
1683
+ /*****/
1684
+ rb_define_method(cgsl_matrix_complex, "-@", rb_gsl_matrix_complex_uminus, 0);
1685
+ rb_define_method(cgsl_matrix_complex, "+@", rb_gsl_matrix_complex_uplus, 0);
1686
+
1687
+ /****/
1688
+ rb_define_method(cgsl_matrix_complex, "arg", rb_gsl_matrix_complex_arg, 0);
1689
+ rb_define_alias(cgsl_matrix_complex, "angle", "arg");
1690
+ rb_define_alias(cgsl_matrix_complex, "phase", "arg");
1691
+ rb_define_method(cgsl_matrix_complex, "abs", rb_gsl_matrix_complex_abs, 0);
1692
+ rb_define_alias(cgsl_matrix_complex, "amp", "abs");
1693
+ rb_define_method(cgsl_matrix_complex, "abs2", rb_gsl_matrix_complex_abs2, 0);
1694
+ rb_define_method(cgsl_matrix_complex, "logabs", rb_gsl_matrix_complex_logabs, 0);
1695
+
1696
+ rb_define_method(cgsl_matrix_complex, "sqrt", rb_gsl_matrix_complex_sqrt, 0);
1697
+ rb_define_method(cgsl_matrix_complex, "exp", rb_gsl_matrix_complex_exp, 0);
1698
+ rb_define_method(cgsl_matrix_complex, "log", rb_gsl_matrix_complex_log, 0);
1699
+ rb_define_method(cgsl_matrix_complex, "log10", rb_gsl_matrix_complex_log10, 0);
1700
+
1701
+ rb_define_method(cgsl_matrix_complex, "sin", rb_gsl_matrix_complex_sin, 0);
1702
+ rb_define_method(cgsl_matrix_complex, "cos", rb_gsl_matrix_complex_cos, 0);
1703
+ rb_define_method(cgsl_matrix_complex, "tan", rb_gsl_matrix_complex_tan, 0);
1704
+ rb_define_method(cgsl_matrix_complex, "sec", rb_gsl_matrix_complex_sec, 0);
1705
+ rb_define_method(cgsl_matrix_complex, "csc", rb_gsl_matrix_complex_csc, 0);
1706
+ rb_define_method(cgsl_matrix_complex, "cot", rb_gsl_matrix_complex_cot, 0);
1707
+
1708
+ rb_define_method(cgsl_matrix_complex, "arcsin", rb_gsl_matrix_complex_arcsin, 0);
1709
+ rb_define_method(cgsl_matrix_complex, "arccos", rb_gsl_matrix_complex_arccos, 0);
1710
+ rb_define_method(cgsl_matrix_complex, "arctan", rb_gsl_matrix_complex_arctan, 0);
1711
+ rb_define_method(cgsl_matrix_complex, "arcsec", rb_gsl_matrix_complex_arcsec, 0);
1712
+ rb_define_method(cgsl_matrix_complex, "arccsc", rb_gsl_matrix_complex_arccsc, 0);
1713
+ rb_define_method(cgsl_matrix_complex, "arccot", rb_gsl_matrix_complex_arccot, 0);
1714
+
1715
+ rb_define_method(cgsl_matrix_complex, "sinh", rb_gsl_matrix_complex_sinh, 0);
1716
+ rb_define_method(cgsl_matrix_complex, "cosh", rb_gsl_matrix_complex_cosh, 0);
1717
+ rb_define_method(cgsl_matrix_complex, "tanh", rb_gsl_matrix_complex_tanh, 0);
1718
+ rb_define_method(cgsl_matrix_complex, "sech", rb_gsl_matrix_complex_sech, 0);
1719
+ rb_define_method(cgsl_matrix_complex, "csch", rb_gsl_matrix_complex_csch, 0);
1720
+ rb_define_method(cgsl_matrix_complex, "coth", rb_gsl_matrix_complex_coth, 0);
1721
+
1722
+ rb_define_method(cgsl_matrix_complex, "arcsinh", rb_gsl_matrix_complex_arcsinh, 0);
1723
+ rb_define_method(cgsl_matrix_complex, "arccosh", rb_gsl_matrix_complex_arccosh, 0);
1724
+ rb_define_method(cgsl_matrix_complex, "arctanh", rb_gsl_matrix_complex_arctanh, 0);
1725
+ rb_define_method(cgsl_matrix_complex, "arcsech", rb_gsl_matrix_complex_arcsech, 0);
1726
+ rb_define_method(cgsl_matrix_complex, "arccsch", rb_gsl_matrix_complex_arccsch, 0);
1727
+ rb_define_method(cgsl_matrix_complex, "arccoth", rb_gsl_matrix_complex_arccoth, 0);
1728
+
1729
+ rb_define_method(cgsl_matrix_complex, "indgen", rb_gsl_matrix_complex_indgen, -1);
1730
+ rb_define_method(cgsl_matrix_complex, "indgen!", rb_gsl_matrix_complex_indgen_bang, -1);
1731
+ rb_define_singleton_method(cgsl_matrix_complex, "indgen", rb_gsl_matrix_complex_indgen_singleton, -1);
1732
+
1733
+ rb_define_method(cgsl_matrix_complex, "equal?", rb_gsl_matrix_complex_equal, -1);
1734
+ rb_define_alias(cgsl_matrix_complex, "==", "equal?");
1735
+ rb_define_method(cgsl_matrix_complex, "not_equal?", rb_gsl_matrix_complex_not_equal, -1);
1736
+ rb_define_alias(cgsl_matrix_complex, "!=", "not_equal?");
1737
+ }