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
@@ -1,7 +1,5 @@
1
1
  #include "include/rb_gsl.h"
2
2
 
3
- #ifdef GSL_1_14_LATER
4
-
5
3
  VALUE cMultiset;
6
4
 
7
5
  VALUE rb_gsl_multiset_alloc(VALUE klass, VALUE nn, VALUE kk)
@@ -18,7 +16,7 @@ VALUE rb_gsl_multiset_calloc(VALUE klass, VALUE nn, VALUE kk)
18
16
  m = gsl_multiset_alloc(FIX2INT(nn), FIX2INT(kk));
19
17
  return Data_Wrap_Struct(klass, 0, gsl_multiset_free, m);
20
18
  }
21
-
19
+
22
20
  VALUE rb_gsl_multiset_init_first(VALUE mm)
23
21
  {
24
22
  gsl_multiset *m;
@@ -180,14 +178,14 @@ VALUE rb_gsl_multiset_data2(VALUE mm, VALUE i)
180
178
  p = gsl_multiset_data(m);
181
179
  return INT2FIX(p[i]);
182
180
  }
183
-
181
+
184
182
  void Init_multiset(VALUE module)
185
183
  {
186
184
  cMultiset = rb_define_class_under(module, "Multiset", cGSL_Object);
187
185
  rb_define_singleton_method(cMultiset, "alloc", rb_gsl_multiset_alloc, 2);
188
186
  rb_define_singleton_method(cMultiset, "calloc", rb_gsl_multiset_calloc, 2);
189
187
  rb_define_singleton_method(cMultiset, "memcpy", rb_gsl_multiset_memcpy, 2);
190
-
188
+
191
189
  rb_define_method(cMultiset, "init_first", rb_gsl_multiset_init_first, 0);
192
190
  rb_define_method(cMultiset, "init_last", rb_gsl_multiset_init_last, 0);
193
191
 
@@ -210,5 +208,3 @@ void Init_multiset(VALUE module)
210
208
  rb_define_method(cMultiset, "fscanf", rb_gsl_multiset_fscanf, 1);
211
209
  }
212
210
 
213
- #endif
214
-
@@ -1,321 +1,320 @@
1
- #include "include/rb_gsl.h"
2
-
3
- #ifdef HAVE_NDLINEAR_GSL_MULTIFIT_NDLINEAR_H
4
- #include <gsl/gsl_math.h>
5
- #include <gsl/gsl_matrix.h>
6
- #include <gsl/gsl_vector.h>
7
- #include <gsl/gsl_multifit.h>
8
- #include <ndlinear/gsl_multifit_ndlinear.h>
9
-
10
- static VALUE cWorkspace;
11
-
12
- enum Index_Ndlinear {
13
- INDEX_NDIM = 0,
14
- INDEX_N = 1,
15
- INDEX_PROCS = 2,
16
- INDEX_PARAMS = 3,
17
- INDEX_FUNCS = 4,
18
- INDEX_NDIM_I = 5,
19
-
20
- NDLINEAR_ARY_SIZE = 6,
21
- };
22
-
23
- static void multifit_ndlinear_mark(gsl_multifit_ndlinear_workspace *w)
24
- {
25
- rb_gc_mark((VALUE) w->params);
26
- }
27
-
28
- typedef int (*UFUNC)(double, double[], void*);
29
- typedef struct ufunc_struct
30
- {
31
- UFUNC *fptr;
32
- } ufunc_struct;
33
-
34
- static VALUE cUFunc;
35
- static ufunc_struct* ufunc_struct_alloc(size_t n_dim) {
36
- ufunc_struct *p;
37
- p = (ufunc_struct*) malloc(sizeof(ufunc_struct));
38
- p->fptr = malloc(sizeof(UFUNC)*n_dim);
39
- return p;
40
- }
41
- static void ufunc_struct_free(ufunc_struct *p)
42
- {
43
- free(p->fptr);
44
- free(p);
45
- }
46
-
47
- static int func_u(double x, double y[], void *data);
48
- static VALUE rb_gsl_multifit_ndlinear_alloc(int argc, VALUE *argv, VALUE klass)
49
- {
50
- gsl_multifit_ndlinear_workspace *w;
51
- int istart = 0;
52
- size_t n_dim = 0, *N, i;
53
- struct ufunc_struct *p;
54
- VALUE params, wspace, pp;
55
- switch (argc) {
56
- case 4:
57
- istart = 1;
58
- CHECK_FIXNUM(argv[0]);
59
- n_dim = FIX2INT(argv[0]);
60
- /* no break */
61
- case 3:
62
- if (TYPE(argv[istart]) != T_ARRAY) {
63
- rb_raise(rb_eTypeError, "Wrong argument type %s (Array expected)",
64
- rb_class2name(CLASS_OF(argv[istart])));
65
- }
66
- if (TYPE(argv[istart+1]) != T_ARRAY) {
67
- rb_raise(rb_eTypeError, "Wrong argument type %s (Array expected)",
68
- rb_class2name(CLASS_OF(argv[istart+1])));
69
- }
70
- // n_dim = RARRAY(argv[istart])->len;
71
- n_dim = RARRAY_LEN(argv[istart]);
72
- N = (size_t*) malloc(sizeof(size_t)*n_dim);
73
- break;
74
- default:
75
- rb_raise(rb_eArgError, "Wrong number of arguments (%d for 3 or 4)", argc);
76
- }
77
- for (i = 0; i < n_dim; i++) {
78
- N[i] = FIX2INT(rb_ary_entry(argv[istart], i));
79
- }
80
-
81
- params = rb_ary_new2(NDLINEAR_ARY_SIZE);
82
- rb_ary_store(params, INDEX_NDIM, INT2FIX((int) n_dim));
83
- rb_ary_store(params, INDEX_N, argv[istart]); /* N */
84
- rb_ary_store(params, INDEX_PROCS, argv[istart+1]); /* procs */
85
- rb_ary_store(params, INDEX_PARAMS, argv[istart+2]); /* params */
86
- rb_ary_store(params, INDEX_NDIM_I, INT2FIX(0)); /* for the first parameter */
87
-
88
- p = ufunc_struct_alloc(n_dim);
89
- for (i = 0; i < n_dim; i++) p->fptr[i] = func_u;
90
- pp = Data_Wrap_Struct(cUFunc, 0, ufunc_struct_free, p);
91
- rb_ary_store(params, INDEX_FUNCS, pp);
92
-
93
- w = gsl_multifit_ndlinear_alloc(n_dim, N, p->fptr, (void*) params);
94
-
95
- free((size_t*) N);
96
-
97
- wspace = Data_Wrap_Struct(cWorkspace, multifit_ndlinear_mark, gsl_multifit_ndlinear_free, w);
98
-
99
- return wspace;
100
- }
101
-
102
- static int func_u(double x, double y[], void *data)
103
- {
104
- VALUE ary, vN, procs, proc, vy, params;
105
- gsl_vector_view ytmp;
106
- size_t i, n_dim;
107
- int rslt;
108
- ary = (VALUE) data;
109
- n_dim = FIX2INT(rb_ary_entry(ary, INDEX_NDIM));
110
- vN = rb_ary_entry(ary, INDEX_N);
111
- procs = rb_ary_entry(ary, INDEX_PROCS);
112
- params = rb_ary_entry(ary, INDEX_PARAMS);
113
- i = FIX2INT(rb_ary_entry(ary, INDEX_NDIM_I));
114
- proc = rb_ary_entry(procs, i);
115
-
116
- ytmp.vector.data = (double*) y;
117
- ytmp.vector.stride = 1;
118
- ytmp.vector.size = FIX2INT(rb_ary_entry(vN, i));
119
- vy = Data_Wrap_Struct(cgsl_vector_view, 0, NULL, &ytmp);
120
-
121
- rslt = rb_funcall((VALUE) proc, RBGSL_ID_call, 3, rb_float_new(x), vy, params);
122
-
123
- /* for the next parameter */
124
- i += 1;
125
- if (i == n_dim) i = 0;
126
- rb_ary_store(ary, INDEX_NDIM_I, INT2FIX(i));
127
-
128
- return GSL_SUCCESS;
129
- }
130
-
131
- static VALUE rb_gsl_multifit_ndlinear_design(int argc, VALUE *argv, VALUE obj)
132
- {
133
- gsl_multifit_ndlinear_workspace *w;
134
- gsl_matrix *vars = NULL, *X = NULL;
135
- int argc2, flag = 0, ret;
136
- switch (TYPE(obj)) {
137
- case T_MODULE:
138
- case T_CLASS:
139
- case T_OBJECT:
140
- if (!rb_obj_is_kind_of(argv[argc-1], cWorkspace)) {
141
- rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::MultiFit::Ndlinear::Workspace expected)",
142
- rb_class2name(CLASS_OF(argv[argc-1])));
143
- }
144
- Data_Get_Struct(argv[argc-1], gsl_multifit_ndlinear_workspace, w);
145
- argc2 = argc-1;
146
- break;
147
- default:
148
- Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
149
- argc2 = argc;
150
- }
151
- switch (argc2) {
152
- case 1:
153
- CHECK_MATRIX(argv[0]);
154
- Data_Get_Struct(argv[0], gsl_matrix, vars);
155
- X = gsl_matrix_alloc(vars->size1, w->n_coeffs);
156
- flag = 1;
157
- break;
158
- case 2:
159
- CHECK_MATRIX(argv[0]);
160
- CHECK_MATRIX(argv[1]);
161
- Data_Get_Struct(argv[0], gsl_matrix, vars);
162
- Data_Get_Struct(argv[1], gsl_matrix, X);
163
- break;
164
- default:
165
- rb_raise(rb_eArgError, "Wrong number of arguments.");
166
- }
167
- ret = gsl_multifit_ndlinear_design(vars, X, w);
168
-
169
- if (flag == 1) {
170
- return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, X);
171
- } else {
172
- return INT2FIX(ret);
173
- }
174
- }
175
-
176
- static VALUE rb_gsl_multifit_ndlinear_est(int argc, VALUE *argv, VALUE obj)
177
- {
178
- gsl_multifit_ndlinear_workspace *w;
179
- gsl_vector *x = NULL, *c = NULL;
180
- gsl_matrix *cov = NULL;
181
- double y, yerr;
182
- int argc2;
183
- switch (TYPE(obj)) {
184
- case T_MODULE:
185
- case T_CLASS:
186
- case T_OBJECT:
187
- if (!rb_obj_is_kind_of(argv[argc-1], cWorkspace)) {
188
- rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::MultiFit::Ndlinear::Workspace expected)",
189
- rb_class2name(CLASS_OF(argv[argc-1])));
190
- }
191
- Data_Get_Struct(argv[argc-1], gsl_multifit_ndlinear_workspace, w);
192
- argc2 = argc-1;
193
- break;
194
- default:
195
- Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
196
- argc2 = argc;
197
- }
198
- switch (argc2) {
199
- case 3:
200
- CHECK_VECTOR(argv[0]);
201
- CHECK_VECTOR(argv[1]);
202
- CHECK_MATRIX(argv[2]);
203
- Data_Get_Struct(argv[0], gsl_vector, x);
204
- Data_Get_Struct(argv[1], gsl_vector, c);
205
- Data_Get_Struct(argv[2], gsl_matrix, cov);
206
- break;
207
- default:
208
- rb_raise(rb_eArgError, "Wrong number of arguments.");
209
- }
210
- gsl_multifit_ndlinear_est(x, c, cov, &y, &yerr, w);
211
- return rb_ary_new3(2, rb_float_new(y), rb_float_new(yerr));
212
- }
213
-
214
- static VALUE rb_gsl_multifit_ndlinear_calc(int argc, VALUE *argv, VALUE obj)
215
- {
216
- gsl_multifit_ndlinear_workspace *w;
217
- gsl_vector *x = NULL, *c = NULL;
218
- double val;
219
- int argc2;
220
- switch (TYPE(obj)) {
221
- case T_MODULE:
222
- case T_CLASS:
223
- case T_OBJECT:
224
- if (!rb_obj_is_kind_of(argv[argc-1], cWorkspace)) {
225
- rb_raise(rb_eTypeError,
226
- "Wrong argument type %s (GSL::MultiFit::Ndlinear::Workspace expected)",
227
- rb_class2name(CLASS_OF(argv[argc-1])));
228
- }
229
- Data_Get_Struct(argv[argc-1], gsl_multifit_ndlinear_workspace, w);
230
- argc2 = argc-1;
231
- break;
232
- default:
233
- Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
234
- argc2 = argc;
235
- }
236
- switch (argc2) {
237
- case 2:
238
- CHECK_VECTOR(argv[0]);
239
- CHECK_VECTOR(argv[1]);
240
- Data_Get_Struct(argv[0], gsl_vector, x);
241
- Data_Get_Struct(argv[1], gsl_vector, c);
242
- break;
243
- default:
244
- rb_raise(rb_eArgError, "Wrong number of arguments.");
245
- }
246
- val = gsl_multifit_ndlinear_calc(x, c, w);
247
- return rb_float_new(val);
248
- }
249
-
250
- static VALUE rb_gsl_multifit_ndlinear_n_coeffs(VALUE obj)
251
- {
252
- gsl_multifit_ndlinear_workspace *w;
253
- Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
254
- return INT2FIX(w->n_coeffs);
255
- }
256
-
257
- static VALUE rb_gsl_multifit_ndlinear_n_dim(VALUE obj)
258
- {
259
- gsl_multifit_ndlinear_workspace *w;
260
- Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
261
- return INT2FIX(w->n_dim);
262
- }
263
-
264
- static VALUE rb_gsl_multifit_ndlinear_N(VALUE obj)
265
- {
266
- gsl_multifit_ndlinear_workspace *w;
267
- VALUE ary;
268
- Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
269
- ary = (VALUE) w->params;
270
- return rb_ary_entry(ary, INDEX_N);
271
- }
272
- /*
273
- static VALUE rb_gsl_multifit_linear_Rsq(VALUE module, VALUE vy, VALUE vchisq)
274
- {
275
- gsl_vector *y;
276
- double chisq, Rsq;
277
- CHECK_VECTOR(vy);
278
- Data_Get_Struct(vy, gsl_vector, y);
279
- chisq = NUM2DBL(vchisq);
280
- gsl_multifit_linear_Rsq(y, chisq, &Rsq);
281
- return rb_float_new(Rsq);
282
- }
283
- */
284
- void Init_ndlinear(VALUE module)
285
- {
286
- VALUE mNdlinear;
287
- mNdlinear = rb_define_module_under(module, "Ndlinear");
288
- cUFunc = rb_define_class_under(mNdlinear, "UFunc", rb_cObject);
289
- cWorkspace = rb_define_class_under(mNdlinear, "Workspace", cGSL_Object);
290
-
291
- rb_define_singleton_method(mNdlinear, "alloc",
292
- rb_gsl_multifit_ndlinear_alloc, -1);
293
- rb_define_singleton_method(cWorkspace, "alloc",
294
- rb_gsl_multifit_ndlinear_alloc, -1);
295
-
296
- rb_define_singleton_method(mNdlinear, "design",
297
- rb_gsl_multifit_ndlinear_design, -1);
298
- rb_define_singleton_method(cWorkspace, "design",
299
- rb_gsl_multifit_ndlinear_design, -1);
300
- rb_define_method(cWorkspace, "design",rb_gsl_multifit_ndlinear_est, -1);
301
- rb_define_singleton_method(mNdlinear, "est",
302
- rb_gsl_multifit_ndlinear_est, -1);
303
- rb_define_singleton_method(cWorkspace, "est",
304
- rb_gsl_multifit_ndlinear_est, -1);
305
- rb_define_method(cWorkspace, "est",rb_gsl_multifit_ndlinear_est, -1);
306
-
307
- rb_define_singleton_method(mNdlinear, "calc",
308
- rb_gsl_multifit_ndlinear_calc, -1);
309
- rb_define_singleton_method(cWorkspace, "calc",
310
- rb_gsl_multifit_ndlinear_calc, -1);
311
- rb_define_method(cWorkspace, "calc",rb_gsl_multifit_ndlinear_calc, -1);
312
-
313
- rb_define_method(cWorkspace, "n_coeffs",rb_gsl_multifit_ndlinear_n_coeffs, 0);
314
- rb_define_method(cWorkspace, "n_dim",rb_gsl_multifit_ndlinear_n_dim, 0);
315
- rb_define_method(cWorkspace, "N",rb_gsl_multifit_ndlinear_N, 0);
316
-
317
- // rb_define_module_function(module, "linear_Rsq", rb_gsl_multifit_linear_Rsq, 2);
318
- }
319
-
320
- #endif
321
-
1
+ #include "include/rb_gsl.h"
2
+
3
+ #ifdef HAVE_NDLINEAR_GSL_MULTIFIT_NDLINEAR_H
4
+ #include <gsl/gsl_math.h>
5
+ #include <gsl/gsl_matrix.h>
6
+ #include <gsl/gsl_vector.h>
7
+ #include <gsl/gsl_multifit.h>
8
+ #include <ndlinear/gsl_multifit_ndlinear.h>
9
+
10
+ static VALUE cWorkspace;
11
+
12
+ enum Index_Ndlinear {
13
+ INDEX_NDIM = 0,
14
+ INDEX_N = 1,
15
+ INDEX_PROCS = 2,
16
+ INDEX_PARAMS = 3,
17
+ INDEX_FUNCS = 4,
18
+ INDEX_NDIM_I = 5,
19
+
20
+ NDLINEAR_ARY_SIZE = 6,
21
+ };
22
+
23
+ static void multifit_ndlinear_mark(gsl_multifit_ndlinear_workspace *w)
24
+ {
25
+ rb_gc_mark((VALUE) w->params);
26
+ }
27
+
28
+ typedef int (*UFUNC)(double, double[], void*);
29
+ typedef struct ufunc_struct
30
+ {
31
+ UFUNC *fptr;
32
+ } ufunc_struct;
33
+
34
+ static VALUE cUFunc;
35
+ static ufunc_struct* ufunc_struct_alloc(size_t n_dim) {
36
+ ufunc_struct *p;
37
+ p = (ufunc_struct*) malloc(sizeof(ufunc_struct));
38
+ p->fptr = malloc(sizeof(UFUNC)*n_dim);
39
+ return p;
40
+ }
41
+ static void ufunc_struct_free(ufunc_struct *p)
42
+ {
43
+ free(p->fptr);
44
+ free(p);
45
+ }
46
+
47
+ static int func_u(double x, double y[], void *data);
48
+ static VALUE rb_gsl_multifit_ndlinear_alloc(int argc, VALUE *argv, VALUE klass)
49
+ {
50
+ gsl_multifit_ndlinear_workspace *w;
51
+ int istart = 0;
52
+ size_t n_dim = 0, *N, i;
53
+ struct ufunc_struct *p;
54
+ VALUE params, wspace, pp;
55
+ switch (argc) {
56
+ case 4:
57
+ istart = 1;
58
+ CHECK_FIXNUM(argv[0]);
59
+ n_dim = FIX2INT(argv[0]);
60
+ /* no break */
61
+ case 3:
62
+ if (TYPE(argv[istart]) != T_ARRAY) {
63
+ rb_raise(rb_eTypeError, "Wrong argument type %s (Array expected)",
64
+ rb_class2name(CLASS_OF(argv[istart])));
65
+ }
66
+ if (TYPE(argv[istart+1]) != T_ARRAY) {
67
+ rb_raise(rb_eTypeError, "Wrong argument type %s (Array expected)",
68
+ rb_class2name(CLASS_OF(argv[istart+1])));
69
+ }
70
+ // n_dim = RARRAY(argv[istart])->len;
71
+ n_dim = RARRAY_LEN(argv[istart]);
72
+ N = (size_t*) malloc(sizeof(size_t)*n_dim);
73
+ break;
74
+ default:
75
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for 3 or 4)", argc);
76
+ }
77
+ for (i = 0; i < n_dim; i++) {
78
+ N[i] = FIX2INT(rb_ary_entry(argv[istart], i));
79
+ }
80
+ params = rb_ary_new2(NDLINEAR_ARY_SIZE);
81
+ rb_ary_store(params, INDEX_NDIM, INT2FIX((int) n_dim));
82
+ rb_ary_store(params, INDEX_N, argv[istart]); /* N */
83
+ rb_ary_store(params, INDEX_PROCS, argv[istart+1]); /* procs */
84
+ rb_ary_store(params, INDEX_PARAMS, argv[istart+2]); /* params */
85
+ rb_ary_store(params, INDEX_NDIM_I, INT2FIX(0)); /* for the first parameter */
86
+
87
+ p = ufunc_struct_alloc(n_dim);
88
+ for (i = 0; i < n_dim; i++) p->fptr[i] = func_u;
89
+ pp = Data_Wrap_Struct(cUFunc, 0, ufunc_struct_free, p);
90
+ rb_ary_store(params, INDEX_FUNCS, pp);
91
+
92
+ w = gsl_multifit_ndlinear_alloc(n_dim, N, p->fptr, (void*) params);
93
+
94
+ free((size_t*) N);
95
+
96
+ wspace = Data_Wrap_Struct(cWorkspace, multifit_ndlinear_mark, gsl_multifit_ndlinear_free, w);
97
+
98
+ return wspace;
99
+ }
100
+
101
+ static int func_u(double x, double y[], void *data)
102
+ {
103
+ VALUE ary, vN, procs, proc, vy, params;
104
+ gsl_vector_view ytmp;
105
+ size_t i, n_dim;
106
+ int rslt;
107
+ ary = (VALUE) data;
108
+ n_dim = FIX2INT(rb_ary_entry(ary, INDEX_NDIM));
109
+ vN = rb_ary_entry(ary, INDEX_N);
110
+ procs = rb_ary_entry(ary, INDEX_PROCS);
111
+ params = rb_ary_entry(ary, INDEX_PARAMS);
112
+ i = FIX2INT(rb_ary_entry(ary, INDEX_NDIM_I));
113
+ proc = rb_ary_entry(procs, i);
114
+
115
+ ytmp.vector.data = (double*) y;
116
+ ytmp.vector.stride = 1;
117
+ ytmp.vector.size = FIX2INT(rb_ary_entry(vN, i));
118
+ vy = Data_Wrap_Struct(cgsl_vector_view, 0, NULL, &ytmp);
119
+
120
+ rslt = rb_funcall((VALUE) proc, RBGSL_ID_call, 3, rb_float_new(x), vy, params);
121
+
122
+ /* for the next parameter */
123
+ i += 1;
124
+ if (i == n_dim) i = 0;
125
+ rb_ary_store(ary, INDEX_NDIM_I, INT2FIX(i));
126
+
127
+ return GSL_SUCCESS;
128
+ }
129
+
130
+ static VALUE rb_gsl_multifit_ndlinear_design(int argc, VALUE *argv, VALUE obj)
131
+ {
132
+ gsl_multifit_ndlinear_workspace *w;
133
+ gsl_matrix *vars = NULL, *X = NULL;
134
+ int argc2, flag = 0, ret;
135
+ switch (TYPE(obj)) {
136
+ case T_MODULE:
137
+ case T_CLASS:
138
+ case T_OBJECT:
139
+ if (!rb_obj_is_kind_of(argv[argc-1], cWorkspace)) {
140
+ rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::MultiFit::Ndlinear::Workspace expected)",
141
+ rb_class2name(CLASS_OF(argv[argc-1])));
142
+ }
143
+ Data_Get_Struct(argv[argc-1], gsl_multifit_ndlinear_workspace, w);
144
+ argc2 = argc-1;
145
+ break;
146
+ default:
147
+ Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
148
+ argc2 = argc;
149
+ }
150
+ switch (argc2) {
151
+ case 1:
152
+ CHECK_MATRIX(argv[0]);
153
+ Data_Get_Struct(argv[0], gsl_matrix, vars);
154
+ X = gsl_matrix_alloc(vars->size1, w->n_coeffs);
155
+ flag = 1;
156
+ break;
157
+ case 2:
158
+ CHECK_MATRIX(argv[0]);
159
+ CHECK_MATRIX(argv[1]);
160
+ Data_Get_Struct(argv[0], gsl_matrix, vars);
161
+ Data_Get_Struct(argv[1], gsl_matrix, X);
162
+ break;
163
+ default:
164
+ rb_raise(rb_eArgError, "Wrong number of arguments.");
165
+ }
166
+ ret = gsl_multifit_ndlinear_design(vars, X, w);
167
+
168
+ if (flag == 1) {
169
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, X);
170
+ } else {
171
+ return INT2FIX(ret);
172
+ }
173
+ }
174
+
175
+ static VALUE rb_gsl_multifit_ndlinear_est(int argc, VALUE *argv, VALUE obj)
176
+ {
177
+ gsl_multifit_ndlinear_workspace *w;
178
+ gsl_vector *x = NULL, *c = NULL;
179
+ gsl_matrix *cov = NULL;
180
+ double y, yerr;
181
+ int argc2;
182
+ switch (TYPE(obj)) {
183
+ case T_MODULE:
184
+ case T_CLASS:
185
+ case T_OBJECT:
186
+ if (!rb_obj_is_kind_of(argv[argc-1], cWorkspace)) {
187
+ rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::MultiFit::Ndlinear::Workspace expected)",
188
+ rb_class2name(CLASS_OF(argv[argc-1])));
189
+ }
190
+ Data_Get_Struct(argv[argc-1], gsl_multifit_ndlinear_workspace, w);
191
+ argc2 = argc-1;
192
+ break;
193
+ default:
194
+ Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
195
+ argc2 = argc;
196
+ }
197
+ switch (argc2) {
198
+ case 3:
199
+ CHECK_VECTOR(argv[0]);
200
+ CHECK_VECTOR(argv[1]);
201
+ CHECK_MATRIX(argv[2]);
202
+ Data_Get_Struct(argv[0], gsl_vector, x);
203
+ Data_Get_Struct(argv[1], gsl_vector, c);
204
+ Data_Get_Struct(argv[2], gsl_matrix, cov);
205
+ break;
206
+ default:
207
+ rb_raise(rb_eArgError, "Wrong number of arguments.");
208
+ }
209
+ gsl_multifit_ndlinear_est(x, c, cov, &y, &yerr, w);
210
+ return rb_ary_new3(2, rb_float_new(y), rb_float_new(yerr));
211
+ }
212
+
213
+ static VALUE rb_gsl_multifit_ndlinear_calc(int argc, VALUE *argv, VALUE obj)
214
+ {
215
+ gsl_multifit_ndlinear_workspace *w;
216
+ gsl_vector *x = NULL, *c = NULL;
217
+ double val;
218
+ int argc2;
219
+ switch (TYPE(obj)) {
220
+ case T_MODULE:
221
+ case T_CLASS:
222
+ case T_OBJECT:
223
+ if (!rb_obj_is_kind_of(argv[argc-1], cWorkspace)) {
224
+ rb_raise(rb_eTypeError,
225
+ "Wrong argument type %s (GSL::MultiFit::Ndlinear::Workspace expected)",
226
+ rb_class2name(CLASS_OF(argv[argc-1])));
227
+ }
228
+ Data_Get_Struct(argv[argc-1], gsl_multifit_ndlinear_workspace, w);
229
+ argc2 = argc-1;
230
+ break;
231
+ default:
232
+ Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
233
+ argc2 = argc;
234
+ }
235
+ switch (argc2) {
236
+ case 2:
237
+ CHECK_VECTOR(argv[0]);
238
+ CHECK_VECTOR(argv[1]);
239
+ Data_Get_Struct(argv[0], gsl_vector, x);
240
+ Data_Get_Struct(argv[1], gsl_vector, c);
241
+ break;
242
+ default:
243
+ rb_raise(rb_eArgError, "Wrong number of arguments.");
244
+ }
245
+ val = gsl_multifit_ndlinear_calc(x, c, w);
246
+ return rb_float_new(val);
247
+ }
248
+
249
+ static VALUE rb_gsl_multifit_ndlinear_n_coeffs(VALUE obj)
250
+ {
251
+ gsl_multifit_ndlinear_workspace *w;
252
+ Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
253
+ return INT2FIX(w->n_coeffs);
254
+ }
255
+
256
+ static VALUE rb_gsl_multifit_ndlinear_n_dim(VALUE obj)
257
+ {
258
+ gsl_multifit_ndlinear_workspace *w;
259
+ Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
260
+ return INT2FIX(w->n_dim);
261
+ }
262
+
263
+ static VALUE rb_gsl_multifit_ndlinear_N(VALUE obj)
264
+ {
265
+ gsl_multifit_ndlinear_workspace *w;
266
+ VALUE ary;
267
+ Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w);
268
+ ary = (VALUE) w->params;
269
+ return rb_ary_entry(ary, INDEX_N);
270
+ }
271
+ /*
272
+ static VALUE rb_gsl_multifit_linear_Rsq(VALUE module, VALUE vy, VALUE vchisq)
273
+ {
274
+ gsl_vector *y;
275
+ double chisq, Rsq;
276
+ CHECK_VECTOR(vy);
277
+ Data_Get_Struct(vy, gsl_vector, y);
278
+ chisq = NUM2DBL(vchisq);
279
+ gsl_multifit_linear_Rsq(y, chisq, &Rsq);
280
+ return rb_float_new(Rsq);
281
+ }
282
+ */
283
+ void Init_ndlinear(VALUE module)
284
+ {
285
+ VALUE mNdlinear;
286
+ mNdlinear = rb_define_module_under(module, "Ndlinear");
287
+ cUFunc = rb_define_class_under(mNdlinear, "UFunc", rb_cObject);
288
+ cWorkspace = rb_define_class_under(mNdlinear, "Workspace", cGSL_Object);
289
+
290
+ rb_define_singleton_method(mNdlinear, "alloc",
291
+ rb_gsl_multifit_ndlinear_alloc, -1);
292
+ rb_define_singleton_method(cWorkspace, "alloc",
293
+ rb_gsl_multifit_ndlinear_alloc, -1);
294
+
295
+ rb_define_singleton_method(mNdlinear, "design",
296
+ rb_gsl_multifit_ndlinear_design, -1);
297
+ rb_define_singleton_method(cWorkspace, "design",
298
+ rb_gsl_multifit_ndlinear_design, -1);
299
+ rb_define_method(cWorkspace, "design",rb_gsl_multifit_ndlinear_est, -1);
300
+ rb_define_singleton_method(mNdlinear, "est",
301
+ rb_gsl_multifit_ndlinear_est, -1);
302
+ rb_define_singleton_method(cWorkspace, "est",
303
+ rb_gsl_multifit_ndlinear_est, -1);
304
+ rb_define_method(cWorkspace, "est",rb_gsl_multifit_ndlinear_est, -1);
305
+
306
+ rb_define_singleton_method(mNdlinear, "calc",
307
+ rb_gsl_multifit_ndlinear_calc, -1);
308
+ rb_define_singleton_method(cWorkspace, "calc",
309
+ rb_gsl_multifit_ndlinear_calc, -1);
310
+ rb_define_method(cWorkspace, "calc",rb_gsl_multifit_ndlinear_calc, -1);
311
+
312
+ rb_define_method(cWorkspace, "n_coeffs",rb_gsl_multifit_ndlinear_n_coeffs, 0);
313
+ rb_define_method(cWorkspace, "n_dim",rb_gsl_multifit_ndlinear_n_dim, 0);
314
+ rb_define_method(cWorkspace, "N",rb_gsl_multifit_ndlinear_N, 0);
315
+
316
+ // rb_define_module_function(module, "linear_Rsq", rb_gsl_multifit_linear_Rsq, 2);
317
+ }
318
+
319
+ #endif
320
+