rb-gsl 1.16.0.4 → 1.16.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (307) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -0
  3. data/.travis.yml +24 -0
  4. data/AUTHORS +6 -0
  5. data/COPYING +341 -339
  6. data/ChangeLog +608 -587
  7. data/Gemfile +4 -0
  8. data/README.md +77 -0
  9. data/Rakefile +14 -33
  10. data/THANKS +1 -1
  11. data/examples/blas/blas.rb +1 -1
  12. data/examples/bspline.rb +3 -3
  13. data/examples/complex/functions.rb +4 -4
  14. data/examples/complex/mul.rb +1 -1
  15. data/examples/const/physconst.rb +4 -4
  16. data/examples/const/travel.rb +4 -4
  17. data/examples/eigen/nonsymmv.rb +1 -1
  18. data/examples/eigen/qhoscillator.rb +3 -3
  19. data/examples/fft/radix2.rb +1 -1
  20. data/examples/fft/real-halfcomplex.rb +3 -3
  21. data/examples/fft/real-halfcomplex2.rb +3 -3
  22. data/examples/fit/expfit.rb +1 -1
  23. data/examples/fit/multifit.rb +1 -1
  24. data/examples/fit/ndlinear.rb +44 -44
  25. data/examples/fit/nonlinearfit.rb +1 -1
  26. data/examples/fit/wlinear.rb +3 -3
  27. data/examples/function/function.rb +1 -1
  28. data/examples/function/min.rb +1 -1
  29. data/examples/function/synchrotron.rb +2 -2
  30. data/examples/gallery/koch.rb +1 -1
  31. data/examples/histogram/cauchy.rb +2 -2
  32. data/examples/histogram/exponential.rb +1 -1
  33. data/examples/histogram/histo3d.rb +1 -1
  34. data/examples/histogram/histogram-pdf.rb +2 -2
  35. data/examples/histogram/xexp.rb +1 -1
  36. data/examples/integration/ahmed.rb +2 -2
  37. data/examples/integration/cosmology.rb +7 -7
  38. data/examples/integration/friedmann.rb +4 -4
  39. data/examples/integration/qng.rb +1 -1
  40. data/examples/interp/demo.rb +2 -2
  41. data/examples/linalg/LQ_solve.rb +1 -1
  42. data/examples/linalg/LU.rb +1 -1
  43. data/examples/linalg/LU2.rb +1 -1
  44. data/examples/linalg/LU_narray.rb +1 -1
  45. data/examples/linalg/PTLQ.rb +1 -1
  46. data/examples/linalg/QRPT.rb +1 -1
  47. data/examples/linalg/chol.rb +1 -1
  48. data/examples/linalg/chol_narray.rb +1 -1
  49. data/examples/linalg/complex.rb +1 -1
  50. data/examples/math/elementary.rb +1 -1
  51. data/examples/math/functions.rb +1 -1
  52. data/examples/math/inf_nan.rb +1 -1
  53. data/examples/math/minmax.rb +1 -1
  54. data/examples/math/power.rb +1 -1
  55. data/examples/math/test.rb +1 -1
  56. data/examples/min.rb +1 -1
  57. data/examples/multimin/bundle.rb +1 -1
  58. data/examples/multimin/cqp.rb +17 -17
  59. data/examples/multiroot/fsolver3.rb +1 -1
  60. data/examples/odeiv/binarysystem.rb +12 -12
  61. data/examples/odeiv/demo.rb +3 -3
  62. data/examples/odeiv/frei1.rb +7 -7
  63. data/examples/odeiv/frei2.rb +4 -4
  64. data/examples/odeiv/oscillator.rb +1 -1
  65. data/examples/odeiv/sedov.rb +3 -3
  66. data/examples/odeiv/whitedwarf.rb +11 -11
  67. data/examples/permutation/ex1.rb +2 -2
  68. data/examples/permutation/permutation.rb +1 -1
  69. data/examples/poly/demo.rb +1 -1
  70. data/examples/random/diffusion.rb +1 -1
  71. data/examples/random/generator.rb +2 -2
  72. data/examples/random/randomwalk.rb +3 -3
  73. data/examples/random/rng.rb +1 -1
  74. data/examples/roots/bisection.rb +1 -1
  75. data/examples/roots/brent.rb +1 -1
  76. data/examples/roots/demo.rb +1 -1
  77. data/examples/roots/newton.rb +2 -2
  78. data/examples/roots/recombination.gp +0 -1
  79. data/examples/sf/hyperg.rb +1 -1
  80. data/examples/sf/sphbessel.rb +1 -1
  81. data/examples/sort/sort.rb +1 -1
  82. data/examples/tamu_anova.rb +4 -4
  83. data/examples/vector/add.rb +1 -1
  84. data/examples/vector/decimate.rb +1 -1
  85. data/examples/vector/gnuplot.rb +8 -8
  86. data/examples/vector/vector.rb +2 -2
  87. data/examples/wavelet/wavelet1.rb +1 -1
  88. data/ext/{gsl → gsl_native}/alf.c +9 -9
  89. data/ext/{gsl → gsl_native}/array.c +64 -151
  90. data/ext/{gsl → gsl_native}/array_complex.c +61 -63
  91. data/ext/{gsl → gsl_native}/blas.c +0 -0
  92. data/ext/{gsl → gsl_native}/blas1.c +32 -32
  93. data/ext/{gsl → gsl_native}/blas2.c +54 -58
  94. data/ext/{gsl → gsl_native}/blas3.c +54 -54
  95. data/ext/{gsl → gsl_native}/block.c +3 -6
  96. data/ext/{gsl/block_source.c → gsl_native/block_source.h} +109 -111
  97. data/ext/gsl_native/bspline.c +122 -0
  98. data/ext/{gsl → gsl_native}/bundle.c +0 -0
  99. data/ext/{gsl → gsl_native}/cdf.c +76 -88
  100. data/ext/{gsl → gsl_native}/cheb.c +74 -85
  101. data/ext/{gsl → gsl_native}/combination.c +9 -16
  102. data/ext/{gsl → gsl_native}/common.c +7 -37
  103. data/ext/{gsl → gsl_native}/complex.c +113 -115
  104. data/ext/gsl_native/const.c +331 -0
  105. data/ext/{gsl → gsl_native}/const_additional.c +12 -33
  106. data/ext/gsl_native/cqp.c +283 -0
  107. data/ext/{gsl → gsl_native}/deriv.c +22 -30
  108. data/ext/{gsl → gsl_native}/dht.c +20 -28
  109. data/ext/{gsl → gsl_native}/diff.c +23 -25
  110. data/ext/{gsl → gsl_native}/dirac.c +44 -45
  111. data/ext/{gsl → gsl_native}/eigen.c +1031 -1082
  112. data/ext/{gsl → gsl_native}/error.c +13 -13
  113. data/ext/{gsl → gsl_native}/extconf.rb +5 -13
  114. data/ext/{gsl → gsl_native}/fft.c +192 -198
  115. data/ext/{gsl → gsl_native}/fit.c +16 -16
  116. data/ext/gsl_native/fresnel.c +312 -0
  117. data/ext/{gsl → gsl_native}/function.c +29 -35
  118. data/ext/{gsl → gsl_native}/geometry.c +15 -15
  119. data/ext/{gsl → gsl_native}/graph.c +37 -87
  120. data/ext/{gsl → gsl_native}/gsl.c +10 -23
  121. data/ext/{gsl → gsl_native}/gsl_narray.c +15 -24
  122. data/ext/{gsl → gsl_native}/histogram.c +123 -150
  123. data/ext/{gsl → gsl_native}/histogram2d.c +71 -96
  124. data/ext/{gsl → gsl_native}/histogram3d.c +72 -72
  125. data/ext/{gsl → gsl_native}/histogram3d_source.c +195 -196
  126. data/ext/{gsl → gsl_native}/histogram_find.c +31 -33
  127. data/ext/{gsl → gsl_native}/histogram_oper.c +43 -52
  128. data/ext/{gsl → gsl_native}/ieee.c +7 -15
  129. data/ext/{gsl → gsl_native}/include/rb_gsl.h +0 -7
  130. data/ext/{gsl → gsl_native}/include/rb_gsl_array.h +15 -25
  131. data/ext/{gsl → gsl_native}/include/rb_gsl_cheb.h +0 -0
  132. data/ext/{gsl → gsl_native}/include/rb_gsl_common.h +44 -52
  133. data/ext/{gsl → gsl_native}/include/rb_gsl_complex.h +0 -0
  134. data/ext/{gsl → gsl_native}/include/rb_gsl_const.h +0 -5
  135. data/ext/{gsl → gsl_native}/include/rb_gsl_dirac.h +0 -0
  136. data/ext/{gsl → gsl_native}/include/rb_gsl_eigen.h +0 -0
  137. data/ext/{gsl → gsl_native}/include/rb_gsl_fft.h +0 -3
  138. data/ext/{gsl → gsl_native}/include/rb_gsl_fit.h +0 -0
  139. data/ext/{gsl → gsl_native}/include/rb_gsl_function.h +0 -0
  140. data/ext/{gsl → gsl_native}/include/rb_gsl_graph.h +2 -2
  141. data/ext/{gsl → gsl_native}/include/rb_gsl_histogram.h +8 -8
  142. data/ext/{gsl → gsl_native}/include/rb_gsl_histogram3d.h +50 -50
  143. data/ext/{gsl → gsl_native}/include/rb_gsl_integration.h +0 -0
  144. data/ext/{gsl → gsl_native}/include/rb_gsl_interp.h +0 -0
  145. data/ext/{gsl → gsl_native}/include/rb_gsl_linalg.h +0 -1
  146. data/ext/{gsl → gsl_native}/include/rb_gsl_math.h +0 -4
  147. data/ext/{gsl → gsl_native}/include/rb_gsl_odeiv.h +0 -0
  148. data/ext/{gsl → gsl_native}/include/rb_gsl_poly.h +3 -3
  149. data/ext/{gsl → gsl_native}/include/rb_gsl_rational.h +1 -1
  150. data/ext/{gsl → gsl_native}/include/rb_gsl_rng.h +0 -0
  151. data/ext/{gsl → gsl_native}/include/rb_gsl_root.h +0 -0
  152. data/ext/{gsl → gsl_native}/include/rb_gsl_sf.h +39 -43
  153. data/ext/{gsl → gsl_native}/include/rb_gsl_statistics.h +0 -0
  154. data/ext/{gsl → gsl_native}/include/rb_gsl_tensor.h +0 -0
  155. data/ext/{gsl → gsl_native}/include/rb_gsl_with_narray.h +0 -0
  156. data/ext/{gsl → gsl_native}/include/templates_off.h +0 -0
  157. data/ext/{gsl → gsl_native}/include/templates_on.h +1 -1
  158. data/ext/{gsl → gsl_native}/integration.c +160 -183
  159. data/ext/{gsl → gsl_native}/interp.c +23 -31
  160. data/ext/gsl_native/jacobi.c +733 -0
  161. data/ext/{gsl → gsl_native}/linalg.c +448 -576
  162. data/ext/{gsl → gsl_native}/linalg_complex.c +84 -98
  163. data/ext/{gsl → gsl_native}/math.c +45 -63
  164. data/ext/{gsl → gsl_native}/matrix.c +4 -6
  165. data/ext/{gsl → gsl_native}/matrix_complex.c +111 -114
  166. data/ext/{gsl → gsl_native}/matrix_double.c +74 -77
  167. data/ext/{gsl → gsl_native}/matrix_int.c +49 -50
  168. data/ext/{gsl/matrix_source.c → gsl_native/matrix_source.h} +280 -302
  169. data/ext/{gsl → gsl_native}/min.c +43 -74
  170. data/ext/{gsl → gsl_native}/monte.c +45 -59
  171. data/ext/{gsl → gsl_native}/multifit.c +138 -147
  172. data/ext/{gsl → gsl_native}/multimin.c +55 -83
  173. data/ext/{gsl → gsl_native}/multimin_fsdf.c +15 -15
  174. data/ext/{gsl → gsl_native}/multiroots.c +61 -64
  175. data/ext/{gsl → gsl_native}/multiset.c +3 -7
  176. data/ext/{gsl → gsl_native}/ndlinear.c +320 -321
  177. data/ext/{gsl → gsl_native}/nmf.c +11 -11
  178. data/ext/{gsl → gsl_native}/nmf_wrap.c +1 -1
  179. data/ext/{gsl → gsl_native}/ntuple.c +13 -13
  180. data/ext/{gsl → gsl_native}/odeiv.c +95 -106
  181. data/ext/gsl_native/ool.c +879 -0
  182. data/ext/{gsl → gsl_native}/permutation.c +36 -34
  183. data/ext/{gsl → gsl_native}/poly.c +2 -5
  184. data/ext/{gsl → gsl_native}/poly2.c +6 -6
  185. data/ext/{gsl/poly_source.c → gsl_native/poly_source.h} +232 -275
  186. data/ext/{gsl → gsl_native}/qrng.c +6 -17
  187. data/ext/{gsl → gsl_native}/randist.c +218 -243
  188. data/ext/{gsl → gsl_native}/rational.c +9 -9
  189. data/ext/{gsl → gsl_native}/rng.c +29 -45
  190. data/ext/{gsl → gsl_native}/root.c +43 -43
  191. data/ext/{gsl → gsl_native}/sf.c +163 -197
  192. data/ext/{gsl → gsl_native}/sf_airy.c +0 -0
  193. data/ext/{gsl → gsl_native}/sf_bessel.c +6 -6
  194. data/ext/{gsl → gsl_native}/sf_clausen.c +0 -0
  195. data/ext/{gsl → gsl_native}/sf_coulomb.c +39 -39
  196. data/ext/{gsl → gsl_native}/sf_coupling.c +29 -29
  197. data/ext/{gsl → gsl_native}/sf_dawson.c +0 -0
  198. data/ext/{gsl → gsl_native}/sf_debye.c +0 -9
  199. data/ext/{gsl → gsl_native}/sf_dilog.c +0 -0
  200. data/ext/{gsl → gsl_native}/sf_elementary.c +2 -2
  201. data/ext/{gsl → gsl_native}/sf_ellint.c +42 -42
  202. data/ext/{gsl → gsl_native}/sf_elljac.c +2 -2
  203. data/ext/{gsl → gsl_native}/sf_erfc.c +0 -4
  204. data/ext/{gsl → gsl_native}/sf_exp.c +2 -2
  205. data/ext/{gsl → gsl_native}/sf_expint.c +1 -11
  206. data/ext/{gsl → gsl_native}/sf_fermi_dirac.c +0 -0
  207. data/ext/{gsl → gsl_native}/sf_gamma.c +1 -5
  208. data/ext/{gsl → gsl_native}/sf_gegenbauer.c +0 -0
  209. data/ext/{gsl → gsl_native}/sf_hyperg.c +0 -0
  210. data/ext/{gsl → gsl_native}/sf_laguerre.c +3 -3
  211. data/ext/{gsl → gsl_native}/sf_lambert.c +0 -0
  212. data/ext/{gsl → gsl_native}/sf_legendre.c +0 -0
  213. data/ext/{gsl → gsl_native}/sf_log.c +3 -3
  214. data/ext/gsl_native/sf_mathieu.c +235 -0
  215. data/ext/{gsl → gsl_native}/sf_power.c +0 -0
  216. data/ext/{gsl → gsl_native}/sf_psi.c +2 -11
  217. data/ext/{gsl → gsl_native}/sf_synchrotron.c +0 -0
  218. data/ext/{gsl → gsl_native}/sf_transport.c +0 -0
  219. data/ext/{gsl → gsl_native}/sf_trigonometric.c +3 -3
  220. data/ext/{gsl → gsl_native}/sf_zeta.c +0 -4
  221. data/ext/{gsl → gsl_native}/signal.c +60 -64
  222. data/ext/{gsl → gsl_native}/siman.c +36 -40
  223. data/ext/{gsl → gsl_native}/sort.c +3 -4
  224. data/ext/{gsl → gsl_native}/spline.c +25 -43
  225. data/ext/{gsl → gsl_native}/stats.c +102 -115
  226. data/ext/{gsl → gsl_native}/sum.c +32 -32
  227. data/ext/{gsl → gsl_native}/tamu_anova.c +0 -0
  228. data/ext/{gsl → gsl_native}/tensor.c +2 -4
  229. data/ext/{gsl/tensor_source.c → gsl_native/tensor_source.h} +144 -144
  230. data/ext/{gsl → gsl_native}/vector.c +2 -4
  231. data/ext/{gsl → gsl_native}/vector_complex.c +165 -171
  232. data/ext/{gsl → gsl_native}/vector_double.c +167 -174
  233. data/ext/{gsl → gsl_native}/vector_int.c +23 -25
  234. data/ext/{gsl/vector_source.c → gsl_native/vector_source.h} +400 -414
  235. data/ext/{gsl → gsl_native}/wavelet.c +215 -236
  236. data/lib/gsl.rb +1 -7
  237. data/lib/gsl/gnuplot.rb +2 -2
  238. data/lib/gsl/version.rb +1 -3
  239. data/rb-gsl.gemspec +29 -0
  240. data/rdoc/blas.rdoc +3 -3
  241. data/rdoc/bspline.rdoc +7 -7
  242. data/rdoc/cheb.rdoc +8 -8
  243. data/rdoc/cholesky_complex.rdoc +1 -1
  244. data/rdoc/combi.rdoc +9 -9
  245. data/rdoc/complex.rdoc +11 -11
  246. data/rdoc/const.rdoc +20 -20
  247. data/rdoc/dht.rdoc +6 -6
  248. data/rdoc/diff.rdoc +6 -6
  249. data/rdoc/ehandling.rdoc +3 -3
  250. data/rdoc/eigen.rdoc +11 -11
  251. data/rdoc/fft.rdoc +26 -26
  252. data/rdoc/fit.rdoc +18 -18
  253. data/rdoc/graph.rdoc +2 -2
  254. data/rdoc/hist.rdoc +16 -16
  255. data/rdoc/hist2d.rdoc +4 -4
  256. data/rdoc/hist3d.rdoc +3 -3
  257. data/rdoc/integration.rdoc +16 -16
  258. data/rdoc/interp.rdoc +11 -11
  259. data/rdoc/intro.rdoc +3 -3
  260. data/rdoc/linalg.rdoc +20 -20
  261. data/rdoc/linalg_complex.rdoc +1 -1
  262. data/rdoc/math.rdoc +13 -13
  263. data/rdoc/matrix.rdoc +22 -22
  264. data/rdoc/min.rdoc +9 -9
  265. data/rdoc/monte.rdoc +3 -3
  266. data/rdoc/multimin.rdoc +12 -12
  267. data/rdoc/multiroot.rdoc +12 -12
  268. data/rdoc/narray.rdoc +9 -9
  269. data/rdoc/ndlinear.rdoc +4 -4
  270. data/rdoc/nonlinearfit.rdoc +17 -17
  271. data/rdoc/ntuple.rdoc +5 -5
  272. data/rdoc/odeiv.rdoc +12 -12
  273. data/rdoc/perm.rdoc +11 -11
  274. data/rdoc/poly.rdoc +17 -17
  275. data/rdoc/qrng.rdoc +9 -9
  276. data/rdoc/randist.rdoc +10 -10
  277. data/rdoc/ref.rdoc +49 -49
  278. data/rdoc/rng.rdoc +9 -9
  279. data/rdoc/roots.rdoc +12 -12
  280. data/rdoc/sf.rdoc +35 -35
  281. data/rdoc/siman.rdoc +3 -3
  282. data/rdoc/sort.rdoc +6 -6
  283. data/rdoc/start.rdoc +2 -2
  284. data/rdoc/stats.rdoc +13 -13
  285. data/rdoc/sum.rdoc +4 -4
  286. data/rdoc/tensor.rdoc +3 -3
  287. data/rdoc/tut.rdoc +1 -1
  288. data/rdoc/use.rdoc +3 -3
  289. data/rdoc/vector.rdoc +28 -28
  290. data/rdoc/vector_complex.rdoc +6 -6
  291. data/rdoc/wavelet.rdoc +8 -8
  292. data/test/gsl/blas_test.rb +1 -1
  293. data/test/gsl/index_test.rb +61 -0
  294. data/test/gsl/matrix_test.rb +21 -0
  295. data/uncrustify.cfg +1693 -0
  296. metadata +212 -243
  297. data/README +0 -28
  298. data/ext/gsl/bspline.c +0 -130
  299. data/ext/gsl/const.c +0 -672
  300. data/ext/gsl/cqp.c +0 -283
  301. data/ext/gsl/fcmp.c +0 -64
  302. data/ext/gsl/fresnel.c +0 -312
  303. data/ext/gsl/jacobi.c +0 -739
  304. data/ext/gsl/ool.c +0 -879
  305. data/ext/gsl/oper_complex_source.c +0 -251
  306. data/ext/gsl/sf_mathieu.c +0 -238
  307. data/rdoc/index.rdoc +0 -50
@@ -34,10 +34,10 @@ static VALUE rb_gsl_interp_new(int argc, VALUE *argv, VALUE klass)
34
34
  break;
35
35
  default:
36
36
  if (ptrx == NULL) {
37
- ptrx = get_vector_ptr(argv[i], &stride, &sizex);
37
+ ptrx = get_vector_ptr(argv[i], &stride, &sizex);
38
38
  } else {
39
- ptry = get_vector_ptr(argv[i], &stride, &sizey);
40
- size = GSL_MIN_INT(sizex, sizey);
39
+ ptry = get_vector_ptr(argv[i], &stride, &sizey);
40
+ size = GSL_MIN_INT(sizex, sizey);
41
41
  }
42
42
  break;
43
43
  }
@@ -132,7 +132,7 @@ static VALUE rb_gsl_interp_bsearch(int argc, VALUE *argv, VALUE obj)
132
132
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 3)", argc);
133
133
  break;
134
134
  }
135
- break;
135
+ break;
136
136
  }
137
137
  return INT2FIX(gsl_interp_bsearch(v->data, x, indexl, indexh));
138
138
  }
@@ -170,9 +170,9 @@ static VALUE rb_gsl_interp_accel_find(VALUE obj, VALUE vv, VALUE xx)
170
170
  }
171
171
 
172
172
  static VALUE rb_gsl_interp_evaluate(VALUE obj, VALUE xxa, VALUE yya, VALUE xx,
173
- double (*eval)(const gsl_interp *, const double [],
174
- const double [], double,
175
- gsl_interp_accel *))
173
+ double (*eval)(const gsl_interp *, const double [],
174
+ const double [], double,
175
+ gsl_interp_accel *))
176
176
  {
177
177
  rb_gsl_interp *rgi = NULL;
178
178
  double *ptrx = NULL, *ptry = NULL;
@@ -181,17 +181,13 @@ static VALUE rb_gsl_interp_evaluate(VALUE obj, VALUE xxa, VALUE yya, VALUE xx,
181
181
  VALUE ary, x;
182
182
  double val;
183
183
  size_t n, i, j, size, stridex, stridey;
184
- #ifdef HAVE_NARRAY_H
185
- struct NARRAY *na = NULL;
186
- double *ptrz = NULL, *ptr = NULL;
187
- #endif
188
184
  Data_Get_Struct(obj, rb_gsl_interp, rgi);
189
185
  ptrx = get_vector_ptr(xxa, &stridex, &size);
190
- if (size != rgi->p->size ){
186
+ if (size != rgi->p->size ) {
191
187
  rb_raise(rb_eTypeError, "size mismatch (xa:%d != %d)", (int) size, (int) rgi->p->size);
192
188
  }
193
189
  ptry = get_vector_ptr(yya, &stridey, &size);
194
- if (size != rgi->p->size ){
190
+ if (size != rgi->p->size ) {
195
191
  rb_raise(rb_eTypeError, "size mismatch (ya:%d != %d)", (int) size, (int) rgi->p->size);
196
192
  }
197
193
  if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
@@ -215,12 +211,14 @@ static VALUE rb_gsl_interp_evaluate(VALUE obj, VALUE xxa, VALUE yya, VALUE xx,
215
211
  default:
216
212
  #ifdef HAVE_NARRAY_H
217
213
  if (NA_IsNArray(xx)) {
214
+ struct NARRAY *na = NULL;
215
+ double *ptrz = NULL, *ptr = NULL;
218
216
  GetNArray(xx, na);
219
217
  ptrz = (double*) na->ptr;
220
218
  ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
221
219
  ptr = NA_PTR_TYPE(ary, double*);
222
220
  for (i = 0; (int) i < na->total; i++)
223
- ptr[i] = (*eval)(rgi->p, ptrx, ptry, ptrz[i], rgi->a);
221
+ ptr[i] = (*eval)(rgi->p, ptrx, ptry, ptrz[i], rgi->a);
224
222
  return ary;
225
223
  }
226
224
  #endif
@@ -228,18 +226,18 @@ static VALUE rb_gsl_interp_evaluate(VALUE obj, VALUE xxa, VALUE yya, VALUE xx,
228
226
  Data_Get_Struct(xx, gsl_vector, v);
229
227
  vnew = gsl_vector_alloc(v->size);
230
228
  for (i = 0; i < v->size; i++) {
231
- val = (*eval)(rgi->p, ptrx, ptry, gsl_vector_get(v, i), rgi->a);
232
- gsl_vector_set(vnew, i, val);
229
+ val = (*eval)(rgi->p, ptrx, ptry, gsl_vector_get(v, i), rgi->a);
230
+ gsl_vector_set(vnew, i, val);
233
231
  }
234
232
  return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
235
233
  } else if (MATRIX_P(xx)) {
236
234
  Data_Get_Struct(xx, gsl_matrix, m);
237
235
  mnew = gsl_matrix_alloc(m->size1, m->size2);
238
236
  for (i = 0; i < m->size1; i++) {
239
- for (j = 0; j < m->size2; j++) {
240
- val = (*eval)(rgi->p, ptrx, ptry, gsl_matrix_get(m, i, j), rgi->a);
241
- gsl_matrix_set(mnew, i, j, val);
242
- }
237
+ for (j = 0; j < m->size2; j++) {
238
+ val = (*eval)(rgi->p, ptrx, ptry, gsl_matrix_get(m, i, j), rgi->a);
239
+ gsl_matrix_set(mnew, i, j, val);
240
+ }
243
241
  }
244
242
  return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
245
243
  } else {
@@ -306,7 +304,7 @@ static VALUE rb_gsl_interp_eval_deriv_e(VALUE obj, VALUE xxa, VALUE yya, VALUE x
306
304
  default:
307
305
  return rb_float_new(y);
308
306
  break;
309
- }
307
+ }
310
308
  return Qnil;
311
309
  }
312
310
 
@@ -338,8 +336,8 @@ static VALUE rb_gsl_interp_eval_deriv2_e(VALUE obj, VALUE xxa, VALUE yya, VALUE
338
336
  return Qnil;
339
337
  }
340
338
 
341
- static VALUE rb_gsl_interp_eval_integ(VALUE obj, VALUE xxa, VALUE yya,
342
- VALUE aa, VALUE bb)
339
+ static VALUE rb_gsl_interp_eval_integ(VALUE obj, VALUE xxa, VALUE yya,
340
+ VALUE aa, VALUE bb)
343
341
  {
344
342
  rb_gsl_interp *rgi = NULL;
345
343
  double *ptr1 = NULL, *ptr2 = NULL;
@@ -354,8 +352,8 @@ static VALUE rb_gsl_interp_eval_integ(VALUE obj, VALUE xxa, VALUE yya,
354
352
  return rb_float_new(gsl_interp_eval_integ(rgi->p, ptr1, ptr2, a, b, rgi->a));
355
353
  }
356
354
 
357
- static VALUE rb_gsl_interp_eval_integ_e(VALUE obj, VALUE xxa, VALUE yya,
358
- VALUE aa, VALUE bb)
355
+ static VALUE rb_gsl_interp_eval_integ_e(VALUE obj, VALUE xxa, VALUE yya,
356
+ VALUE aa, VALUE bb)
359
357
  {
360
358
  rb_gsl_interp *rgi = NULL;
361
359
  double *ptr1 = NULL, *ptr2 = NULL;
@@ -392,9 +390,7 @@ const gsl_interp_type* get_interp_type(VALUE t)
392
390
  type = FIX2INT(t);
393
391
  switch (type) {
394
392
  case GSL_INTERP_LINEAR: return gsl_interp_linear; break;
395
- #ifdef GSL_1_1_LATER
396
393
  case GSL_INTERP_POLYNOMIAL: return gsl_interp_polynomial; break;
397
- #endif
398
394
  case GSL_INTERP_CSPLINE: return gsl_interp_cspline; break;
399
395
  case GSL_INTERP_CSPLINE_PERIODIC: return gsl_interp_cspline_periodic; break;
400
396
  case GSL_INTERP_AKIMA: return gsl_interp_akima; break;
@@ -408,10 +404,8 @@ const gsl_interp_type* get_interp_type(VALUE t)
408
404
  strcpy(name, STR2CSTR(t));
409
405
  if (str_tail_grep(name, "linear") == 0) {
410
406
  return gsl_interp_linear;
411
- #ifdef GSL_1_1_LATER
412
407
  } else if (str_tail_grep(name, "polynomial") == 0) {
413
408
  return gsl_interp_polynomial;
414
- #endif
415
409
  } else if (str_tail_grep(name, "cspline") == 0) {
416
410
  return gsl_interp_cspline;
417
411
  } else if (str_tail_grep(name, "cspline_periodic") == 0) {
@@ -453,10 +447,8 @@ static void rb_gsl_interp_define_const(VALUE klass)
453
447
  rb_define_const(klass, "AKIMA_PERIODIC", INT2FIX(GSL_INTERP_AKIMA_PERIODIC));
454
448
 
455
449
  rb_define_const(klass, "Linear", INT2FIX(GSL_INTERP_LINEAR));
456
- #ifdef GSL_1_1_LATER
457
450
  rb_define_const(klass, "POLYNOMIAL", INT2FIX(GSL_INTERP_POLYNOMIAL));
458
451
  rb_define_const(klass, "Polynomial", INT2FIX(GSL_INTERP_POLYNOMIAL));
459
- #endif
460
452
  rb_define_const(klass, "CSpline", INT2FIX(GSL_INTERP_CSPLINE));
461
453
  rb_define_const(klass, "CSpline_Periodic", INT2FIX(GSL_INTERP_CSPLINE_PERIODIC));
462
454
  rb_define_const(klass, "Akima", INT2FIX(GSL_INTERP_AKIMA));
@@ -0,0 +1,733 @@
1
+ #ifdef HAVE_JACOBI_H
2
+ #include "include/rb_gsl.h"
3
+ #include "jacobi.h"
4
+
5
+ static VALUE jac_eval3_e(VALUE x, VALUE a, VALUE b,
6
+ int (*f)(double, double, double, gsl_sf_result*))
7
+ {
8
+ gsl_sf_result *result;
9
+ VALUE obj;
10
+ obj = Data_Make_Struct(cgsl_sf_result, gsl_sf_result, 0, free, result);
11
+ (*f)(NUM2DBL(x), NUM2DBL(a), NUM2DBL(b), result);
12
+ return obj;
13
+ }
14
+
15
+ static VALUE jac_eval3(VALUE xx, VALUE aa, VALUE bb, double (*f)(double, double, double))
16
+ {
17
+ gsl_vector *x, *y;
18
+ double a, b;
19
+ size_t i, len;
20
+ VALUE ary;
21
+ a = NUM2DBL(aa);
22
+ b = NUM2DBL(bb);
23
+ if (VECTOR_P(xx)) {
24
+ Data_Get_Struct(xx, gsl_vector, x);
25
+ y = gsl_vector_alloc(x->size);
26
+ for (i = 0; i < x->size; i++) {
27
+ gsl_vector_set(y, i, (*f)(gsl_vector_get(x, i), a, b));
28
+ }
29
+ return Data_Wrap_Struct(VECTOR_ROW_COL(CLASS_OF(xx)), 0, gsl_vector_free, y);
30
+ } else if (TYPE(xx) == T_ARRAY) {
31
+ // len = RARRAY(xx)->len;
32
+ len = RARRAY_LEN(xx);
33
+ ary = rb_ary_new2(len);
34
+ for (i = 0; i < len; i++) {
35
+ rb_ary_store(ary, i, rb_float_new((*f)(NUM2DBL(rb_ary_entry(xx, i)), a, b)));
36
+ }
37
+ return ary;
38
+ #ifdef HAVE_NARRAY_H
39
+ } else if (NA_IsNArray(xx)) {
40
+ double *ptr1, *ptr2;
41
+ struct NARRAY *na;
42
+ GetNArray(xx, na);
43
+ len = na->total;
44
+ ptr1 = (double*) na->ptr;
45
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
46
+ ptr2 = NA_PTR_TYPE(ary, double*);
47
+ for (i = 0; i < len; i++) {
48
+ ptr2[i] = (*f)(ptr1[i], a, b);
49
+ }
50
+ return ary;
51
+ #endif
52
+ } else {
53
+ return rb_float_new((*f)(NUM2DBL(xx), a, b));
54
+ }
55
+ }
56
+
57
+ static VALUE rb_jac_jacobi_eval(int argc, VALUE *argv,
58
+ double (*f)(double, int, double, double),
59
+ int (*f2)(int, const double*, int, double*, double, double, double*))
60
+ {
61
+ gsl_vector *x, *ws, *y;
62
+ double a, b;
63
+ VALUE ary;
64
+ size_t len, i;
65
+ int n, flag = 0;
66
+ if (argc < 4) rb_raise(rb_eArgError, "Too few arguments (%d for >= 4)", argc);
67
+ if (VECTOR_P(argv[0])) {
68
+ Data_Get_Struct(argv[0], gsl_vector, x);
69
+ y = gsl_vector_alloc(x->size);
70
+ ary = Data_Wrap_Struct(VECTOR_ROW_COL(CLASS_OF(x)), 0, gsl_vector_free, y);
71
+ switch (argc) {
72
+ case 4:
73
+ ws = gsl_vector_alloc(2*x->size);
74
+ flag = 1;
75
+ break;
76
+ case 5:
77
+ CHECK_VECTOR(argv[4]);
78
+ Data_Get_Struct(argv[4], gsl_vector, ws);
79
+ break;
80
+ default:
81
+ rb_raise(rb_eArgError, "Too many arguments (%d for 4 or 5)", argc);
82
+ }
83
+ (*f2)(x->size, x->data, FIX2INT(argv[1]), y->data, NUM2DBL(argv[2]), NUM2DBL(argv[3]),
84
+ ws->data);
85
+ if (flag == 1) gsl_vector_free(ws);
86
+ return ary;
87
+ } else if (TYPE(argv[0]) == T_ARRAY) {
88
+ n = FIX2INT(argv[1]);
89
+ a = NUM2DBL(argv[2]);
90
+ b = NUM2DBL(argv[3]);
91
+ // len = RARRAY(argv[0])->len;
92
+ len = RARRAY_LEN(argv[0]);
93
+ ary = rb_ary_new2(len);
94
+ for (i = 0; i < len; i++) {
95
+ rb_ary_store(ary, i, rb_float_new((*f)(NUM2DBL(rb_ary_entry(argv[0], i)), n, a, b)));
96
+ }
97
+ return ary;
98
+ #ifdef HAVE_NARRAY_H
99
+ } else if (NA_IsNArray(argv[0])) {
100
+ double *ptr1, *ptr2;
101
+ struct NARRAY *na;
102
+ GetNArray(argv[0], na);
103
+ len = na->total;
104
+ ptr1 = (double*) na->ptr;
105
+ ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(argv[0]));
106
+ ptr2 = NA_PTR_TYPE(ary, double*);
107
+ n = FIX2INT(argv[1]);
108
+ a = NUM2DBL(argv[2]);
109
+ b = NUM2DBL(argv[3]);
110
+ ws = gsl_vector_alloc(len);
111
+ (*f2)(len, ptr1, n, ptr2, a, b, ws->data);
112
+ gsl_vector_free(ws);
113
+ return ary;
114
+ #endif
115
+ } else {
116
+ return rb_float_new((*f)(NUM2DBL(argv[0]), FIX2INT(argv[1]), NUM2DBL(argv[2]), NUM2DBL(argv[3])));
117
+ }
118
+ }
119
+ static VALUE rb_jac_jacobi_P0_e(VALUE module, VALUE x, VALUE a, VALUE b)
120
+ {
121
+ return jac_eval3_e(x, a, b, jac_jacobi_P0_e);
122
+ }
123
+
124
+ static VALUE rb_jac_jacobi_P0(VALUE module, VALUE x, VALUE a, VALUE b)
125
+ {
126
+ return jac_eval3(x, a, b, jac_jacobi_P0);
127
+ }
128
+
129
+ static VALUE rb_jac_jacobi_P1_e(VALUE module, VALUE x, VALUE a, VALUE b)
130
+ {
131
+ return jac_eval3_e(x, a, b, jac_jacobi_P1_e);
132
+ }
133
+
134
+ static VALUE rb_jac_jacobi_P1(VALUE module, VALUE x, VALUE a, VALUE b)
135
+ {
136
+ return jac_eval3(x, a, b, jac_jacobi_P1);
137
+ }
138
+
139
+
140
+ static VALUE rb_jac_jacobi(int argc, VALUE *argv, VALUE module)
141
+ {
142
+ return rb_jac_jacobi_eval(argc, argv, jac_jacobi, jac_jacobi_array);
143
+ }
144
+
145
+ static VALUE rb_jac_djacobi_P0_e(VALUE module, VALUE x, VALUE a, VALUE b)
146
+ {
147
+ return jac_eval3_e(x, a, b, jac_djacobi_P0_e);
148
+ }
149
+
150
+ static VALUE rb_jac_djacobi_P0(VALUE module, VALUE x, VALUE a, VALUE b)
151
+ {
152
+ return jac_eval3(x, a, b, jac_djacobi_P0);
153
+ }
154
+
155
+ static VALUE rb_jac_djacobi_P1_e(VALUE module, VALUE x, VALUE a, VALUE b)
156
+ {
157
+ return jac_eval3_e(x, a, b, jac_djacobi_P1_e);
158
+ }
159
+
160
+ static VALUE rb_jac_djacobi_P1(VALUE module, VALUE x, VALUE a, VALUE b)
161
+ {
162
+ return jac_eval3(x, a, b, jac_djacobi_P1);
163
+ }
164
+
165
+ static VALUE rb_jac_djacobi(int argc, VALUE *argv, VALUE module)
166
+ {
167
+ return rb_jac_jacobi_eval(argc, argv, jac_djacobi, jac_djacobi_array);
168
+ }
169
+
170
+ static VALUE rb_jac_zeros_eval(int argc, VALUE *argv, VALUE module,
171
+ int (*f)(double*, int, double, double))
172
+ {
173
+ gsl_vector *x;
174
+ int m, status;
175
+ double a, b;
176
+ VALUE xx;
177
+ switch (argc) {
178
+ case 3:
179
+ if (FIXNUM_P(argv[0])) {
180
+ m = FIX2INT(argv[0]);
181
+ a = NUM2DBL(argv[1]);
182
+ b = NUM2DBL(argv[2]);
183
+ x = gsl_vector_alloc(m);
184
+ xx = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, x);
185
+ } else if (VECTOR_P(argv[0])) {
186
+ Data_Get_Struct(argv[0], gsl_vector, x);
187
+ m = x->size;
188
+ a = NUM2DBL(argv[1]);
189
+ b = NUM2DBL(argv[2]);
190
+ xx = argv[0];
191
+ } else {
192
+ rb_raise(rb_eTypeError, "Wrong argument type %s (Fixnum or GSL::Vector expected)",
193
+ rb_class2name(CLASS_OF(argv[0])));
194
+ }
195
+ break;
196
+ case 4:
197
+ CHECK_VECTOR(argv[0]);
198
+ Data_Get_Struct(argv[0], gsl_vector, x);
199
+ m = FIX2INT(argv[1]);
200
+ a = NUM2DBL(argv[2]);
201
+ b = NUM2DBL(argv[3]);
202
+ break;
203
+ default:
204
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 3 or 4)", argc);
205
+ }
206
+ status = (*f)(x->data, m, a, b);
207
+ if (status != GSL_SUCCESS)
208
+ rb_raise(rb_eRuntimeError, "Something wrong. (error code %d)", status);
209
+ return xx;
210
+ }
211
+
212
+ static VALUE rb_jac_jacobi_zeros(int argc, VALUE *argv, VALUE module)
213
+ {
214
+ return rb_jac_zeros_eval(argc, argv, module, jac_jacobi_zeros);
215
+ }
216
+
217
+ static void jac_define_const(VALUE module)
218
+ {
219
+ rb_define_const(module, "GJ", INT2FIX(JAC_GJ));
220
+ rb_define_const(module, "GLJ", INT2FIX(JAC_GLJ));
221
+ rb_define_const(module, "GRJM", INT2FIX(JAC_GRJM));
222
+ rb_define_const(module, "GRJP", INT2FIX(JAC_GRJP));
223
+ }
224
+
225
+ static VALUE rb_jac_quadrature_alloc(VALUE klass, VALUE vQ)
226
+ {
227
+ jac_quadrature *q;
228
+
229
+ q = jac_quadrature_alloc(FIX2INT(vQ));
230
+
231
+ return Data_Wrap_Struct(klass, 0, jac_quadrature_free, q);
232
+ }
233
+
234
+ static VALUE rb_jac_quadrature_Q(VALUE obj)
235
+ {
236
+ jac_quadrature *q;
237
+ Data_Get_Struct(obj, jac_quadrature, q);
238
+ return INT2FIX(q->Q);
239
+ }
240
+
241
+ static VALUE rb_jac_quadrature_type(VALUE obj)
242
+ {
243
+ jac_quadrature *q;
244
+ Data_Get_Struct(obj, jac_quadrature, q);
245
+ return INT2FIX((int) q->type);
246
+ }
247
+
248
+ static VALUE rb_jac_quadrature_alpha(VALUE obj)
249
+ {
250
+ jac_quadrature *q;
251
+ Data_Get_Struct(obj, jac_quadrature, q);
252
+ return NUM2DBL(q->alpha);
253
+ }
254
+
255
+ static VALUE rb_jac_quadrature_beta(VALUE obj)
256
+ {
257
+ jac_quadrature *q;
258
+ Data_Get_Struct(obj, jac_quadrature, q);
259
+ return NUM2DBL(q->beta);
260
+ }
261
+
262
+ static VALUE rb_jac_quadrature_x(VALUE obj)
263
+ {
264
+ jac_quadrature *q;
265
+ gsl_vector_view *v;
266
+ Data_Get_Struct(obj, jac_quadrature, q);
267
+ v = gsl_vector_view_alloc();
268
+ v->vector.data = q->x;
269
+ v->vector.size = q->Q;
270
+ v->vector.stride = 1;
271
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, v);
272
+ }
273
+
274
+ static VALUE rb_jac_quadrature_w(VALUE obj)
275
+ {
276
+ jac_quadrature *q;
277
+ gsl_vector_view *v;
278
+ Data_Get_Struct(obj, jac_quadrature, q);
279
+ v = gsl_vector_view_alloc();
280
+ v->vector.data = q->w;
281
+ v->vector.size = q->Q;
282
+ v->vector.stride = 1;
283
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, v);
284
+ }
285
+
286
+ static VALUE rb_jac_quadrature_D(VALUE obj)
287
+ {
288
+ jac_quadrature *q;
289
+ gsl_vector_view *v;
290
+ Data_Get_Struct(obj, jac_quadrature, q);
291
+ v = gsl_vector_view_alloc();
292
+ v->vector.data = q->D;
293
+ v->vector.size = q->Q;
294
+ v->vector.stride = 1;
295
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, v);
296
+ }
297
+
298
+ static VALUE rb_jac_quadrature_xp(VALUE obj)
299
+ {
300
+ jac_quadrature *q;
301
+ gsl_vector_view *v;
302
+ Data_Get_Struct(obj, jac_quadrature, q);
303
+ v = gsl_vector_view_alloc();
304
+ v->vector.data = q->w;
305
+ v->vector.size = q->np;
306
+ v->vector.stride = 1;
307
+ return Data_Wrap_Struct(cgsl_vector_view, 0, gsl_vector_view_free, v);
308
+ }
309
+
310
+ static VALUE rb_jac_interpmat_alloc(int argc, VALUE *argv, VALUE obj)
311
+ {
312
+ int err;
313
+ jac_quadrature *q;
314
+ gsl_vector *xp;
315
+ int np;
316
+ Data_Get_Struct(obj, jac_quadrature, q);
317
+ switch (argc) {
318
+ case 1:
319
+ CHECK_VECTOR(argv[0]);
320
+ Data_Get_Struct(argv[0], gsl_vector, xp);
321
+ np = xp->size;
322
+ break;
323
+ case 2:
324
+ CHECK_VECTOR(argv[1]);
325
+ Data_Get_Struct(argv[1], gsl_vector, xp);
326
+ np = FIX2INT(argv[0]);
327
+ break;
328
+ default:
329
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)", argc);
330
+ }
331
+ err = jac_interpmat_alloc(q, np, xp->data);
332
+ return FIX2INT(err);
333
+ }
334
+
335
+ static VALUE rb_jac_interpmat_free(VALUE obj)
336
+ {
337
+ jac_quadrature *q;
338
+ Data_Get_Struct(obj, jac_quadrature, q);
339
+ jac_interpmat_free(q);
340
+ return Qtrue;
341
+ }
342
+
343
+ static VALUE rb_jac_quadrature_zwd(int argc, VALUE *argv, VALUE obj)
344
+ {
345
+ jac_quadrature *q;
346
+ gsl_vector *ws;
347
+ int flag = 0, type, status;
348
+ double a, b;
349
+ Data_Get_Struct(obj, jac_quadrature, q);
350
+ switch (argc) {
351
+ case 3:
352
+ type = FIX2INT(argv[0]);
353
+ a = NUM2DBL(argv[1]);
354
+ b = NUM2DBL(argv[2]);
355
+ ws = gsl_vector_alloc(q->Q);
356
+ flag = 1;
357
+ break;
358
+ case 4:
359
+ type = FIX2INT(argv[0]);
360
+ a = NUM2DBL(argv[1]);
361
+ b = NUM2DBL(argv[2]);
362
+ Data_Get_Struct(argv[3], gsl_vector, ws);
363
+ break;
364
+ default:
365
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 3 or 4)", argc);
366
+ }
367
+ status = jac_quadrature_zwd(q, type, a, b, ws->data);
368
+ if (flag == 1) gsl_vector_free(ws);
369
+ return INT2FIX(status);
370
+ }
371
+
372
+ static VALUE rb_jac_integrate(VALUE obj, VALUE ff)
373
+ {
374
+ jac_quadrature *q;
375
+ gsl_vector *f;
376
+ CHECK_VECTOR(ff);
377
+ Data_Get_Struct(obj, jac_quadrature, q);
378
+ Data_Get_Struct(ff, gsl_vector, f);
379
+ return rb_float_new(jac_integrate(q, f->data));
380
+ }
381
+
382
+ static VALUE rb_jac_interpolate(int argc, VALUE *argv, VALUE obj)
383
+ {
384
+ jac_quadrature *q;
385
+ gsl_vector *f, *fout;
386
+ VALUE vfout;
387
+ switch (argc) {
388
+ case 1:
389
+ CHECK_VECTOR(argv[0]);
390
+ Data_Get_Struct(argv[0], gsl_vector, f);
391
+ fout = gsl_vector_alloc(f->size);
392
+ vfout = Data_Wrap_Struct(VECTOR_ROW_COL(CLASS_OF(argv[0])), 0, gsl_vector_free, fout);
393
+ break;
394
+ case 2:
395
+ CHECK_VECTOR(argv[0]);
396
+ Data_Get_Struct(argv[0], gsl_vector, f);
397
+ CHECK_VECTOR(argv[1]);
398
+ Data_Get_Struct(argv[1], gsl_vector, fout);
399
+ vfout = argv[1];
400
+ break;
401
+ default:
402
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)", argc);
403
+ }
404
+ Data_Get_Struct(obj, jac_quadrature, q);
405
+ jac_interpolate(q, f->data, fout->data);
406
+ return vfout;
407
+ }
408
+
409
+ static VALUE rb_jac_differentiate(int argc, VALUE *argv, VALUE obj)
410
+ {
411
+ jac_quadrature *q;
412
+ gsl_vector *f, *fout;
413
+ VALUE vfout;
414
+ switch (argc) {
415
+ case 1:
416
+ CHECK_VECTOR(argv[0]);
417
+ Data_Get_Struct(argv[0], gsl_vector, f);
418
+ fout = gsl_vector_alloc(f->size);
419
+ vfout = Data_Wrap_Struct(VECTOR_ROW_COL(CLASS_OF(argv[0])), 0, gsl_vector_free, fout);
420
+ break;
421
+ case 2:
422
+ CHECK_VECTOR(argv[0]);
423
+ Data_Get_Struct(argv[0], gsl_vector, f);
424
+ CHECK_VECTOR(argv[1]);
425
+ Data_Get_Struct(argv[1], gsl_vector, fout);
426
+ vfout = argv[1];
427
+ break;
428
+ default:
429
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 1 or 2)", argc);
430
+ }
431
+ Data_Get_Struct(obj, jac_quadrature, q);
432
+ jac_differentiate(q, f->data, fout->data);
433
+ return vfout;
434
+ }
435
+
436
+ /*****/
437
+ static VALUE rb_jac_qeval(int argc, VALUE *argv,
438
+ int (*f)(double*, double*, const int, double, double, double*))
439
+ {
440
+ gsl_vector *z, *D, *ws;
441
+ int Q;
442
+ int flag = 0, status;
443
+ double alpha, beta;
444
+ VALUE vD;
445
+ if (argc < 3) rb_raise(rb_eArgError, "Too few arguments (%d for >= 3)", argc);
446
+ CHECK_VECTOR(argv[0]);
447
+ Data_Get_Struct(argv[0], gsl_vector, z);
448
+ argc -= 1;
449
+ argv += 1;
450
+ if (VECTOR_P(argv[argc-1])) {
451
+ Data_Get_Struct(argv[argc-1], gsl_vector, ws);
452
+ argc -= 1;
453
+ } else {
454
+ ws = gsl_vector_alloc(z->size);
455
+ flag = 1;
456
+ }
457
+ switch (argc) {
458
+ case 2:
459
+ Q = z->size;
460
+ D = gsl_vector_alloc(Q*Q);
461
+ alpha = NUM2DBL(argv[0]);
462
+ beta = NUM2DBL(argv[1]);
463
+ vD = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, D);
464
+ break;
465
+ case 4:
466
+ Data_Get_Struct(argv[0], gsl_vector, D);
467
+ vD = argv[0];
468
+ Q = FIX2INT(argv[1]);
469
+ alpha = NUM2DBL(argv[2]);
470
+ beta = NUM2DBL(argv[3]);
471
+ break;
472
+ case 3:
473
+ if (VECTOR_P(argv[0])) {
474
+ Q = z->size;
475
+ Data_Get_Struct(argv[0], gsl_vector, D);
476
+ vD = argv[0];
477
+ } else {
478
+ Q = FIX2INT(argv[0]);
479
+ D = gsl_vector_alloc(Q*Q);
480
+ vD = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, D);
481
+ }
482
+ alpha = NUM2DBL(argv[1]);
483
+ beta = NUM2DBL(argv[2]);
484
+ break;
485
+ default:
486
+ rb_raise(rb_eArgError, "Wrong number of arguments.");
487
+ }
488
+ status = (*f)(z->data, D->data, Q, alpha, beta, ws->data);
489
+ if (flag == 1) gsl_vector_free(ws);
490
+ if (status != GSL_SUCCESS) rb_raise(rb_eRuntimeError, "Something wrong.");
491
+ return vD;
492
+ }
493
+
494
+ static VALUE rb_jac_diffmat_gj(int argc, VALUE *argv, VALUE module)
495
+ {
496
+ return rb_jac_qeval(argc, argv, jac_diffmat_gj);
497
+ }
498
+
499
+ static VALUE rb_jac_diffmat_glj(int argc, VALUE *argv, VALUE module)
500
+ {
501
+ return rb_jac_qeval(argc, argv, jac_diffmat_glj);
502
+ }
503
+
504
+ static VALUE rb_jac_diffmat_grjm(int argc, VALUE *argv, VALUE module)
505
+ {
506
+ return rb_jac_qeval(argc, argv, jac_diffmat_grjm);
507
+ }
508
+
509
+ static VALUE rb_jac_diffmat_grjp(int argc, VALUE *argv, VALUE module)
510
+ {
511
+ return rb_jac_qeval(argc, argv, jac_diffmat_grjp);
512
+ }
513
+
514
+ static VALUE rb_jac_weights_gj(int argc, VALUE *argv, VALUE module)
515
+ {
516
+ return rb_jac_qeval(argc, argv, jac_weights_gj);
517
+ }
518
+
519
+ static VALUE rb_jac_weights_glj(int argc, VALUE *argv, VALUE module)
520
+ {
521
+ return rb_jac_qeval(argc, argv, jac_weights_glj);
522
+ }
523
+
524
+ static VALUE rb_jac_weights_grjm(int argc, VALUE *argv, VALUE module)
525
+ {
526
+ return rb_jac_qeval(argc, argv, jac_weights_grjm);
527
+ }
528
+
529
+ static VALUE rb_jac_weights_grjp(int argc, VALUE *argv, VALUE module)
530
+ {
531
+ return rb_jac_qeval(argc, argv, jac_weights_grjp);
532
+ }
533
+
534
+ static VALUE rb_jac_zeros_gj(int argc, VALUE *argv, VALUE module)
535
+ {
536
+ return rb_jac_zeros_eval(argc, argv, module, jac_zeros_gj);
537
+ }
538
+ static VALUE rb_jac_zeros_glj(int argc, VALUE *argv, VALUE module)
539
+ {
540
+ return rb_jac_zeros_eval(argc, argv, module, jac_zeros_glj);
541
+ }
542
+ static VALUE rb_jac_zeros_grjm(int argc, VALUE *argv, VALUE module)
543
+ {
544
+ return rb_jac_zeros_eval(argc, argv, module, jac_zeros_grjm);
545
+ }
546
+ static VALUE rb_jac_zeros_grjp(int argc, VALUE *argv, VALUE module)
547
+ {
548
+ return rb_jac_zeros_eval(argc, argv, module, jac_zeros_grjp);
549
+ }
550
+
551
+ static VALUE rb_jac_lagrange_eval(int argc, VALUE *argv,
552
+ double (*f)(int, double, int, double*, double, double))
553
+ {
554
+ gsl_vector *z;
555
+ int i, Q;
556
+ double alpha, beta, zz;
557
+
558
+ switch (argc) {
559
+ case 5:
560
+ i = FIX2INT(argv[0]);
561
+ zz = NUM2DBL(argv[1]);
562
+ CHECK_VECTOR(argv[2]);
563
+ Data_Get_Struct(argv[2], gsl_vector, z);
564
+ Q = z->size;
565
+ alpha = NUM2DBL(argv[3]);
566
+ beta = NUM2DBL(argv[4]);
567
+ break;
568
+ case 6:
569
+ i = FIX2INT(argv[0]);
570
+ zz = NUM2DBL(argv[1]);
571
+ Q = FIX2INT(argv[2]);
572
+ CHECK_VECTOR(argv[3]);
573
+ Data_Get_Struct(argv[3], gsl_vector, z);
574
+ alpha = NUM2DBL(argv[4]);
575
+ beta = NUM2DBL(argv[5]);
576
+ break;
577
+ default:
578
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 5 or 6)", argc);
579
+ }
580
+ return rb_float_new((*f)(i, zz, Q, z->data, alpha, beta));
581
+ }
582
+
583
+ static VALUE rb_jac_lagrange_gj(int argc, VALUE *argv, VALUE module)
584
+ {
585
+ return rb_jac_lagrange_eval(argc, argv, jac_lagrange_gj);
586
+ }
587
+ static VALUE rb_jac_lagrange_glj(int argc, VALUE *argv, VALUE module)
588
+ {
589
+ return rb_jac_lagrange_eval(argc, argv, jac_lagrange_glj);
590
+ }
591
+ static VALUE rb_jac_lagrange_grjm(int argc, VALUE *argv, VALUE module)
592
+ {
593
+ return rb_jac_lagrange_eval(argc, argv, jac_lagrange_grjm);
594
+ }
595
+
596
+ static VALUE rb_jac_lagrange_grjp(int argc, VALUE *argv, VALUE module)
597
+ {
598
+ return rb_jac_lagrange_eval(argc, argv, jac_lagrange_grjp);
599
+ }
600
+
601
+ static VALUE rb_jac_interpmat_eval(int argc, VALUE *argv,
602
+ int (*f)(double*, double*, int, double*, int, double, double))
603
+ {
604
+ gsl_vector *imat, *zp, *z;
605
+ double alpha, beta;
606
+ int np, Q, status;
607
+ VALUE vimat;
608
+
609
+ if (argc < 3) rb_raise(rb_eArgError, "Too few arguments (%d for >= 3)", argc);
610
+ CHECK_VECTOR(argv[0]);
611
+ if (VECTOR_P(argv[1])) {
612
+ Data_Get_Struct(argv[0], gsl_vector, imat);
613
+ Data_Get_Struct(argv[1], gsl_vector, zp);
614
+ vimat = argv[0];
615
+ if (FIXNUM_P(argv[2])) np = FIX2INT(argv[2]);
616
+ argc -= 3;
617
+ argv += 3;
618
+ } else {
619
+ Data_Get_Struct(argv[0], gsl_vector, zp);
620
+ if (FIXNUM_P(argv[1])) np = FIX2INT(argv[1]);
621
+ else np = zp->size;
622
+ imat = gsl_vector_alloc(np);
623
+ vimat = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, imat);
624
+ argc -= 2;
625
+ argv += 2;
626
+ }
627
+ CHECK_VECTOR(argv[0]);
628
+ Data_Get_Struct(argv[0], gsl_vector, z);
629
+ argc -= 1;
630
+ argv += 1;
631
+ switch (argc) {
632
+ case 3:
633
+ Q = FIX2INT(argv[0]);
634
+ alpha = NUM2DBL(argv[1]);
635
+ beta = NUM2DBL(argv[2]);
636
+ break;
637
+ case 2:
638
+ Q = z->size;
639
+ alpha = NUM2DBL(argv[0]);
640
+ beta = NUM2DBL(argv[1]);
641
+ break;
642
+ default:
643
+ rb_raise(rb_eArgError, "Wrong number of arguments.");
644
+ }
645
+ (*f)(imat->data, zp->data, np, z->data, Q, alpha, beta);
646
+ if (status != GSL_SUCCESS) rb_raise(rb_eRuntimeError, "Some error.");
647
+ return vimat;
648
+ }
649
+
650
+ static VALUE rb_jac_interpmat_gj(int argc, VALUE *argv, VALUE module)
651
+ {
652
+ return rb_jac_interpmat_eval(argc, argv, jac_interpmat_gj);
653
+ }
654
+
655
+ static VALUE rb_jac_interpmat_glj(int argc, VALUE *argv, VALUE module)
656
+ {
657
+ return rb_jac_interpmat_eval(argc, argv, jac_interpmat_glj);
658
+ }
659
+ static VALUE rb_jac_interpmat_grjm(int argc, VALUE *argv, VALUE module)
660
+ {
661
+ return rb_jac_interpmat_eval(argc, argv, jac_interpmat_grjm);
662
+ }
663
+ static VALUE rb_jac_interpmat_grjp(int argc, VALUE *argv, VALUE module)
664
+ {
665
+ return rb_jac_interpmat_eval(argc, argv, jac_interpmat_grjp);
666
+ }
667
+ void Init_jacobi(VALUE module)
668
+ {
669
+ VALUE mjac, cjacq;
670
+
671
+ mjac = rb_define_module("Jac");
672
+ jac_define_const(mjac);
673
+ cjacq = rb_define_class_under(mjac, "Quadrature", cGSL_Object);
674
+
675
+ rb_define_module_function(mjac, "jacobi_P0_e", rb_jac_jacobi_P0_e, 3);
676
+ rb_define_module_function(mjac, "jacobi_P0", rb_jac_jacobi_P0, 3);
677
+ rb_define_module_function(mjac, "jacobi_P1_e", rb_jac_jacobi_P1_e, 3);
678
+ rb_define_module_function(mjac, "jacobi_P1", rb_jac_jacobi_P1, 3);
679
+ rb_define_module_function(mjac, "jacobi", rb_jac_jacobi, -1);
680
+ rb_define_module_function(mjac, "djacobi_P0_e", rb_jac_djacobi_P0_e, 3);
681
+ rb_define_module_function(mjac, "djacobi_P0", rb_jac_djacobi_P0, 3);
682
+ rb_define_module_function(mjac, "djacobi_P1_e", rb_jac_djacobi_P1_e, 3);
683
+ rb_define_module_function(mjac, "djacobi_P1", rb_jac_djacobi_P1, 3);
684
+ rb_define_module_function(mjac, "djacobi", rb_jac_djacobi, 4);
685
+
686
+ rb_define_module_function(mjac, "jacobi_zeros", rb_jac_jacobi_zeros, -1);
687
+
688
+ /*****/
689
+ rb_define_singleton_method(cjacq, "alloc", rb_jac_quadrature_alloc, 1);
690
+ rb_define_method(cjacq, "Q", rb_jac_quadrature_Q, 0);
691
+ rb_define_method(cjacq, "type", rb_jac_quadrature_type, 0);
692
+ rb_define_method(cjacq, "alpha", rb_jac_quadrature_alpha, 0);
693
+ rb_define_method(cjacq, "beta", rb_jac_quadrature_beta, 0);
694
+ rb_define_method(cjacq, "x", rb_jac_quadrature_x, 0);
695
+ rb_define_method(cjacq, "w", rb_jac_quadrature_w, 0);
696
+ rb_define_method(cjacq, "D", rb_jac_quadrature_D, 0);
697
+ rb_define_method(cjacq, "xp", rb_jac_quadrature_xp, 0);
698
+ rb_define_method(cjacq, "interpmat_alloc", rb_jac_interpmat_alloc, -1);
699
+ rb_define_method(cjacq, "interpmat_free", rb_jac_interpmat_free, 0);
700
+ rb_define_method(cjacq, "zwd", rb_jac_quadrature_zwd, -1);
701
+ rb_define_method(cjacq, "integrate", rb_jac_integrate, 1);
702
+ rb_define_method(cjacq, "interpolate", rb_jac_interpolate, -1);
703
+ rb_define_method(cjacq, "differentiate", rb_jac_differentiate, -1);
704
+ /*****/
705
+ rb_define_module_function(mjac, "diffmat_gj", rb_jac_diffmat_gj, -1);
706
+ rb_define_module_function(mjac, "diffmat_glj", rb_jac_diffmat_glj, -1);
707
+ rb_define_module_function(mjac, "diffmat_grjm", rb_jac_diffmat_grjm, -1);
708
+ rb_define_module_function(mjac, "diffmat_grjp", rb_jac_diffmat_grjp, -1);
709
+
710
+ rb_define_module_function(mjac, "weights_gj", rb_jac_weights_gj, -1);
711
+ rb_define_module_function(mjac, "weights_glj", rb_jac_weights_glj, -1);
712
+ rb_define_module_function(mjac, "weights_grjm", rb_jac_weights_grjm, -1);
713
+ rb_define_module_function(mjac, "weights_grjp", rb_jac_weights_grjp, -1);
714
+
715
+ rb_define_module_function(mjac, "zeros_gj", rb_jac_zeros_gj, -1);
716
+ rb_define_module_function(mjac, "zeros_glj", rb_jac_zeros_glj, -1);
717
+ rb_define_module_function(mjac, "zeros_grjm", rb_jac_zeros_grjm, -1);
718
+ rb_define_module_function(mjac, "zeros_grjp", rb_jac_zeros_grjp, -1);
719
+
720
+ rb_define_module_function(mjac, "lagrange_gj", rb_jac_lagrange_gj, -1);
721
+ rb_define_module_function(mjac, "lagrange_glj", rb_jac_lagrange_glj, -1);
722
+ rb_define_module_function(mjac, "lagrange_grjm", rb_jac_lagrange_grjm, -1);
723
+ rb_define_module_function(mjac, "lagrange_grjp", rb_jac_lagrange_grjp, -1);
724
+
725
+ rb_define_module_function(mjac, "interpmat_gj", rb_jac_interpmat_gj, -1);
726
+ rb_define_module_function(mjac, "interpmat_glj", rb_jac_interpmat_glj, -1);
727
+ rb_define_module_function(mjac, "interpmat_grjm", rb_jac_interpmat_grjm, -1);
728
+ rb_define_module_function(mjac, "interpmat_grjp", rb_jac_interpmat_grjp, -1);
729
+
730
+ }
731
+
732
+ #endif
733
+