numo-gsl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +84 -0
  4. data/Rakefile +16 -0
  5. data/ext/numo/gsl/cdf/depend +17 -0
  6. data/ext/numo/gsl/cdf/erbpp_cdf.rb +44 -0
  7. data/ext/numo/gsl/cdf/extconf.rb +9 -0
  8. data/ext/numo/gsl/cdf/func_def.rb +610 -0
  9. data/ext/numo/gsl/const/const_def.rb +419 -0
  10. data/ext/numo/gsl/const/depend +17 -0
  11. data/ext/numo/gsl/const/erbpp_const.rb +30 -0
  12. data/ext/numo/gsl/const/extconf.rb +9 -0
  13. data/ext/numo/gsl/err/depend +1 -0
  14. data/ext/numo/gsl/err/err.c +22 -0
  15. data/ext/numo/gsl/err/extconf.rb +9 -0
  16. data/ext/numo/gsl/extconf_gsl.rb +44 -0
  17. data/ext/numo/gsl/fit/depend +17 -0
  18. data/ext/numo/gsl/fit/erbpp_fit.rb +74 -0
  19. data/ext/numo/gsl/fit/extconf.rb +9 -0
  20. data/ext/numo/gsl/fit/func_def.rb +129 -0
  21. data/ext/numo/gsl/fit/tmpl/check_1d.c +9 -0
  22. data/ext/numo/gsl/fit/tmpl/fit_linear.c +53 -0
  23. data/ext/numo/gsl/fit/tmpl/fit_linear_est.c +56 -0
  24. data/ext/numo/gsl/fit/tmpl/fit_mul.c +50 -0
  25. data/ext/numo/gsl/fit/tmpl/fit_mul_est.c +47 -0
  26. data/ext/numo/gsl/fit/tmpl/fit_wlinear.c +59 -0
  27. data/ext/numo/gsl/fit/tmpl/fit_wmul.c +56 -0
  28. data/ext/numo/gsl/gen/erbpp2.rb +306 -0
  29. data/ext/numo/gsl/gen/erbpp_gsl.rb +166 -0
  30. data/ext/numo/gsl/gen/func_parser.rb +520 -0
  31. data/ext/numo/gsl/gen/tmpl/c_DFloat_f_DFloat.c +40 -0
  32. data/ext/numo/gsl/gen/tmpl/c_DFloat_f_SZ.c +41 -0
  33. data/ext/numo/gsl/gen/tmpl/c_DFloat_f_SZ_x2.c +44 -0
  34. data/ext/numo/gsl/gen/tmpl/c_DFloat_x2_f_DFloat_x2.c +45 -0
  35. data/ext/numo/gsl/gen/tmpl/c_double_f_double.c +16 -0
  36. data/ext/numo/gsl/gen/tmpl/c_double_f_sizet.c +16 -0
  37. data/ext/numo/gsl/gen/tmpl/c_double_f_sizet_x2.c +17 -0
  38. data/ext/numo/gsl/gen/tmpl/c_double_f_void.c +15 -0
  39. data/ext/numo/gsl/gen/tmpl/c_double_x2_f_void.c +17 -0
  40. data/ext/numo/gsl/gen/tmpl/c_new_DFloat.c +29 -0
  41. data/ext/numo/gsl/gen/tmpl/c_new_double.c +22 -0
  42. data/ext/numo/gsl/gen/tmpl/c_new_f_other.c +25 -0
  43. data/ext/numo/gsl/gen/tmpl/c_new_sizet.c +22 -0
  44. data/ext/numo/gsl/gen/tmpl/c_new_sizet_double.c +23 -0
  45. data/ext/numo/gsl/gen/tmpl/c_new_sizet_x2.c +23 -0
  46. data/ext/numo/gsl/gen/tmpl/c_new_void.c +21 -0
  47. data/ext/numo/gsl/gen/tmpl/c_other_f_void.c +19 -0
  48. data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat.c +46 -0
  49. data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat_x2.c +41 -0
  50. data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat_x3.c +44 -0
  51. data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat_x4.c +47 -0
  52. data/ext/numo/gsl/gen/tmpl/c_self_f_SZ_x2_DFloat.c +45 -0
  53. data/ext/numo/gsl/gen/tmpl/c_self_f_double.c +17 -0
  54. data/ext/numo/gsl/gen/tmpl/c_self_f_other.c +17 -0
  55. data/ext/numo/gsl/gen/tmpl/c_self_f_sizet.c +21 -0
  56. data/ext/numo/gsl/gen/tmpl/c_self_f_void.c +14 -0
  57. data/ext/numo/gsl/gen/tmpl/c_sizet_f_void.c +15 -0
  58. data/ext/numo/gsl/gen/tmpl/c_sizet_x2_f_void.c +17 -0
  59. data/ext/numo/gsl/gen/tmpl/c_str_f_void.c +15 -0
  60. data/ext/numo/gsl/gen/tmpl/c_super_new_void.c +18 -0
  61. data/ext/numo/gsl/gen/tmpl/c_uint_f_void.c +15 -0
  62. data/ext/numo/gsl/gen/tmpl/c_ulong_f_void.c +15 -0
  63. data/ext/numo/gsl/gen/tmpl/c_void_f_double.c +17 -0
  64. data/ext/numo/gsl/gen/tmpl/c_void_f_double_x2.c +18 -0
  65. data/ext/numo/gsl/gen/tmpl/c_void_f_double_x4.c +20 -0
  66. data/ext/numo/gsl/gen/tmpl/c_void_f_ulong.c +17 -0
  67. data/ext/numo/gsl/gen/tmpl/c_void_f_void.c +14 -0
  68. data/ext/numo/gsl/gen/tmpl/cast_1d_contiguous.c +15 -0
  69. data/ext/numo/gsl/gen/tmpl/cast_2d_contiguous.c +15 -0
  70. data/ext/numo/gsl/gen/tmpl/class.c +26 -0
  71. data/ext/numo/gsl/gen/tmpl/create_new_narray.c +26 -0
  72. data/ext/numo/gsl/gen/tmpl/init_class.c +10 -0
  73. data/ext/numo/gsl/gen/tmpl/init_module.c +12 -0
  74. data/ext/numo/gsl/gen/tmpl/lib.c +41 -0
  75. data/ext/numo/gsl/gen/tmpl/m_DFloat_Int_f_DFloat.c +38 -0
  76. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat.c +35 -0
  77. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_Int.c +39 -0
  78. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_UInt.c +39 -0
  79. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_double.c +42 -0
  80. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_double_x2.c +47 -0
  81. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_int.c +42 -0
  82. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_x2.c +38 -0
  83. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_x3.c +41 -0
  84. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_Int.c +36 -0
  85. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt.c +36 -0
  86. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32.c +36 -0
  87. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_double.c +43 -0
  88. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_double_uint.c +49 -0
  89. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_double_x2.c +48 -0
  90. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_uint_x3.c +51 -0
  91. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_double.c +43 -0
  92. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_double_uint.c +50 -0
  93. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_double_x2.c +48 -0
  94. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_uint_x3.c +51 -0
  95. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_int_DFloat.c +41 -0
  96. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_int_DFloat_x2.c +44 -0
  97. data/ext/numo/gsl/gen/tmpl/m_DFloat_f_int_x2_DFloat_x2.c +46 -0
  98. data/ext/numo/gsl/gen/tmpl/m_Int_f_DFloat.c +36 -0
  99. data/ext/numo/gsl/gen/tmpl/m_Int_f_DFloat_x3.c +42 -0
  100. data/ext/numo/gsl/gen/tmpl/m_Int_f_int_DFloat.c +42 -0
  101. data/ext/numo/gsl/gen/tmpl/m_Int_f_int_DFloat_x2.c +45 -0
  102. data/ext/numo/gsl/gen/tmpl/mod_func_noloop.c +54 -0
  103. data/ext/numo/gsl/gen/tmpl/mod_func_scalar.c +27 -0
  104. data/ext/numo/gsl/gen/tmpl/module.c +9 -0
  105. data/ext/numo/gsl/histogram/depend +17 -0
  106. data/ext/numo/gsl/histogram/erbpp_histogram.rb +109 -0
  107. data/ext/numo/gsl/histogram/extconf.rb +9 -0
  108. data/ext/numo/gsl/histogram/func_def.rb +763 -0
  109. data/ext/numo/gsl/histogram/tmpl/c_DFloat_f_2d_get.c +54 -0
  110. data/ext/numo/gsl/histogram/tmpl/c_DFloat_f_field.c +35 -0
  111. data/ext/numo/gsl/histogram/tmpl/c_DFloat_f_get.c +47 -0
  112. data/ext/numo/gsl/histogram/tmpl/c_DFloat_x2_f_get_range.c +56 -0
  113. data/ext/numo/gsl/histogram/tmpl/c_bool_f_other.c +19 -0
  114. data/ext/numo/gsl/histogram/tmpl/c_bool_f_pdf_init.c +24 -0
  115. data/ext/numo/gsl/histogram/tmpl/c_self_f_2d_set_ranges.c +26 -0
  116. data/ext/numo/gsl/histogram/tmpl/c_self_f_set_ranges.c +21 -0
  117. data/ext/numo/gsl/histogram/tmpl/c_sizet_f_field.c +15 -0
  118. data/ext/numo/gsl/interp/depend +17 -0
  119. data/ext/numo/gsl/interp/erbpp_interp.rb +59 -0
  120. data/ext/numo/gsl/interp/extconf.rb +9 -0
  121. data/ext/numo/gsl/interp/func_def.rb +816 -0
  122. data/ext/numo/gsl/interp/parse_interp.rb +67 -0
  123. data/ext/numo/gsl/interp/tmpl/interp2d_new.c +36 -0
  124. data/ext/numo/gsl/interp/tmpl/interp2d_type_new.c +17 -0
  125. data/ext/numo/gsl/interp/tmpl/interp_bsearch.c +57 -0
  126. data/ext/numo/gsl/interp/tmpl/interp_new.c +29 -0
  127. data/ext/numo/gsl/interp/tmpl/interp_type_new.c +16 -0
  128. data/ext/numo/gsl/interp/tmpl/spline2d_eval.c +61 -0
  129. data/ext/numo/gsl/interp/tmpl/spline_eval.c +55 -0
  130. data/ext/numo/gsl/interp/tmpl/spline_integ.c +56 -0
  131. data/ext/numo/gsl/interp/type_def.rb +9 -0
  132. data/ext/numo/gsl/multifit/depend +17 -0
  133. data/ext/numo/gsl/multifit/erbpp_multifit.rb +99 -0
  134. data/ext/numo/gsl/multifit/extconf.rb +9 -0
  135. data/ext/numo/gsl/multifit/func_2.1.rb +1035 -0
  136. data/ext/numo/gsl/multifit/func_2.2.1.rb +736 -0
  137. data/ext/numo/gsl/multifit/func_2.2.rb +736 -0
  138. data/ext/numo/gsl/multifit/func_2.3.rb +872 -0
  139. data/ext/numo/gsl/multifit/func_def.rb +1012 -0
  140. data/ext/numo/gsl/multifit/tmpl/multifit_linear.c +66 -0
  141. data/ext/numo/gsl/multifit/tmpl/multifit_linear_est.c +48 -0
  142. data/ext/numo/gsl/multifit/tmpl/multifit_linear_residuals.c +47 -0
  143. data/ext/numo/gsl/multifit/tmpl/multifit_wlinear.c +70 -0
  144. data/ext/numo/gsl/multifit/type_def.rb +1 -0
  145. data/ext/numo/gsl/numo_gsl.h +117 -0
  146. data/ext/numo/gsl/pdf/depend +17 -0
  147. data/ext/numo/gsl/pdf/erbpp_pdf.rb +26 -0
  148. data/ext/numo/gsl/pdf/extconf.rb +9 -0
  149. data/ext/numo/gsl/pdf/func_2.2.1.rb +306 -0
  150. data/ext/numo/gsl/pdf/func_2.2.rb +306 -0
  151. data/ext/numo/gsl/pdf/func_2.3.rb +306 -0
  152. data/ext/numo/gsl/pdf/func_def.rb +282 -0
  153. data/ext/numo/gsl/pdf/parse_pdf.rb +42 -0
  154. data/ext/numo/gsl/pdf/tmpl/dirichlet.c +39 -0
  155. data/ext/numo/gsl/pdf/tmpl/multinomial.c +39 -0
  156. data/ext/numo/gsl/poly/depend +17 -0
  157. data/ext/numo/gsl/poly/erbpp_poly.rb +70 -0
  158. data/ext/numo/gsl/poly/extconf.rb +9 -0
  159. data/ext/numo/gsl/poly/func_def.rb +234 -0
  160. data/ext/numo/gsl/poly/tmpl/poly_complex_solve.c +59 -0
  161. data/ext/numo/gsl/poly/tmpl/poly_eval.c +70 -0
  162. data/ext/numo/gsl/poly/tmpl/poly_eval_derivs.c +40 -0
  163. data/ext/numo/gsl/ran/depend +17 -0
  164. data/ext/numo/gsl/ran/erbpp_ran.rb +42 -0
  165. data/ext/numo/gsl/ran/extconf.rb +9 -0
  166. data/ext/numo/gsl/ran/func_2.2.1.rb +1658 -0
  167. data/ext/numo/gsl/ran/func_2.2.rb +1658 -0
  168. data/ext/numo/gsl/ran/func_2.3.rb +1658 -0
  169. data/ext/numo/gsl/ran/func_def.rb +1594 -0
  170. data/ext/numo/gsl/ran/parse_ran.rb +10 -0
  171. data/ext/numo/gsl/rng/depend +17 -0
  172. data/ext/numo/gsl/rng/erbpp_rng.rb +58 -0
  173. data/ext/numo/gsl/rng/extconf.rb +9 -0
  174. data/ext/numo/gsl/rng/func_def.rb +230 -0
  175. data/ext/numo/gsl/rng/parse_rng.rb +125 -0
  176. data/ext/numo/gsl/rng/tmpl/ran.c +40 -0
  177. data/ext/numo/gsl/rng/tmpl/ran_DFloat_f_DFloat.c +28 -0
  178. data/ext/numo/gsl/rng/tmpl/ran_DFloat_x2.c +45 -0
  179. data/ext/numo/gsl/rng/tmpl/ran_DFloat_x3.c +51 -0
  180. data/ext/numo/gsl/rng/tmpl/ran_multinomial.c +32 -0
  181. data/ext/numo/gsl/rng/tmpl/rng_DFloat.c +29 -0
  182. data/ext/numo/gsl/rng/tmpl/rng_UInt.c +44 -0
  183. data/ext/numo/gsl/rng/tmpl/rng_alloc.c +24 -0
  184. data/ext/numo/gsl/rng/tmpl/rng_type_new.c +14 -0
  185. data/ext/numo/gsl/rng/type_def.rb +63 -0
  186. data/ext/numo/gsl/rstat/depend +17 -0
  187. data/ext/numo/gsl/rstat/erbpp_rstat.rb +64 -0
  188. data/ext/numo/gsl/rstat/extconf.rb +9 -0
  189. data/ext/numo/gsl/rstat/func_2.2.1.rb +116 -0
  190. data/ext/numo/gsl/rstat/func_2.2.rb +116 -0
  191. data/ext/numo/gsl/rstat/func_2.3.rb +123 -0
  192. data/ext/numo/gsl/rstat/func_def.rb +102 -0
  193. data/ext/numo/gsl/sf/depend +17 -0
  194. data/ext/numo/gsl/sf/erbpp_sf.rb +51 -0
  195. data/ext/numo/gsl/sf/extconf.rb +9 -0
  196. data/ext/numo/gsl/sf/func_def.rb +4703 -0
  197. data/ext/numo/gsl/sf/parse_sf.rb +277 -0
  198. data/ext/numo/gsl/sf/tmpl/c_DFloat_f_int_x2_DFloat.c +50 -0
  199. data/ext/numo/gsl/sf/tmpl/c_DFloat_f_int_x2_DFloat_x2.c +52 -0
  200. data/ext/numo/gsl/sf/tmpl/c_DFloat_f_int_x3_DFloat_x2.c +55 -0
  201. data/ext/numo/gsl/sf/tmpl/m_DFloat_f_DFloat_mode.c +47 -0
  202. data/ext/numo/gsl/sf/tmpl/m_DFloat_f_lmax_array.c +41 -0
  203. data/ext/numo/gsl/sf/tmpl/m_DFloat_f_nmin_nmax_array.c +49 -0
  204. data/ext/numo/gsl/spmatrix/const_2.2.1.rb +3 -0
  205. data/ext/numo/gsl/spmatrix/const_2.2.rb +3 -0
  206. data/ext/numo/gsl/spmatrix/const_2.3.rb +3 -0
  207. data/ext/numo/gsl/spmatrix/const_def.rb +2 -0
  208. data/ext/numo/gsl/spmatrix/depend +17 -0
  209. data/ext/numo/gsl/spmatrix/erbpp_spmatrix.rb +100 -0
  210. data/ext/numo/gsl/spmatrix/extconf.rb +9 -0
  211. data/ext/numo/gsl/spmatrix/func_2.2.1.rb +297 -0
  212. data/ext/numo/gsl/spmatrix/func_2.2.rb +297 -0
  213. data/ext/numo/gsl/spmatrix/func_2.3.rb +297 -0
  214. data/ext/numo/gsl/spmatrix/func_def.rb +218 -0
  215. data/ext/numo/gsl/spmatrix/parse_spmatrix.rb +70 -0
  216. data/ext/numo/gsl/spmatrix/tmpl/itersolve_iterate.c +47 -0
  217. data/ext/numo/gsl/spmatrix/tmpl/itersolve_new.c +22 -0
  218. data/ext/numo/gsl/spmatrix/tmpl/itersolve_type_new.c +16 -0
  219. data/ext/numo/gsl/spmatrix/tmpl/spblas_dgemm.c +35 -0
  220. data/ext/numo/gsl/spmatrix/tmpl/spblas_dgemv.c +43 -0
  221. data/ext/numo/gsl/spmatrix/tmpl/spmatrix_add.c +22 -0
  222. data/ext/numo/gsl/spmatrix/tmpl/spmatrix_d2sp.c +28 -0
  223. data/ext/numo/gsl/spmatrix/tmpl/spmatrix_new.c +40 -0
  224. data/ext/numo/gsl/spmatrix/tmpl/spmatrix_sp2d.c +25 -0
  225. data/ext/numo/gsl/spmatrix/type_def.rb +1 -0
  226. data/ext/numo/gsl/stats/depend +17 -0
  227. data/ext/numo/gsl/stats/erbpp_stats.rb +29 -0
  228. data/ext/numo/gsl/stats/extconf.rb +9 -0
  229. data/ext/numo/gsl/stats/func_2.2.1.rb +608 -0
  230. data/ext/numo/gsl/stats/func_2.2.rb +608 -0
  231. data/ext/numo/gsl/stats/func_2.3.rb +608 -0
  232. data/ext/numo/gsl/stats/func_def.rb +608 -0
  233. data/ext/numo/gsl/stats/parse_stats.rb +63 -0
  234. data/ext/numo/gsl/stats/tmpl/stats_1a0p.c +37 -0
  235. data/ext/numo/gsl/stats/tmpl/stats_1a0p_index.c +60 -0
  236. data/ext/numo/gsl/stats/tmpl/stats_1a1p.c +41 -0
  237. data/ext/numo/gsl/stats/tmpl/stats_1a2p.c +42 -0
  238. data/ext/numo/gsl/stats/tmpl/stats_2a0p.c +39 -0
  239. data/ext/numo/gsl/stats/tmpl/stats_2a1p.c +43 -0
  240. data/ext/numo/gsl/stats/tmpl/stats_2a2p.c +44 -0
  241. data/ext/numo/gsl/stats/tmpl/stats_minmax.c +37 -0
  242. data/ext/numo/gsl/stats/tmpl/stats_minmax_index.c +67 -0
  243. data/ext/numo/gsl/stats/tmpl/stats_spearman.c +46 -0
  244. data/ext/numo/gsl/sys/const_def.rb +21 -0
  245. data/ext/numo/gsl/sys/depend +17 -0
  246. data/ext/numo/gsl/sys/enum_def.rb +75 -0
  247. data/ext/numo/gsl/sys/erbpp_sys.rb +60 -0
  248. data/ext/numo/gsl/sys/extconf.rb +9 -0
  249. data/ext/numo/gsl/sys/func_def.rb +249 -0
  250. data/ext/numo/gsl/version.h +1 -0
  251. data/ext/numo/gsl/wavelet/depend +17 -0
  252. data/ext/numo/gsl/wavelet/erbpp_wavelet.rb +48 -0
  253. data/ext/numo/gsl/wavelet/extconf.rb +9 -0
  254. data/ext/numo/gsl/wavelet/func_def.rb +337 -0
  255. data/ext/numo/gsl/wavelet/parse_wavelet.rb +47 -0
  256. data/ext/numo/gsl/wavelet/tmpl/wavelet2d_transform.c +56 -0
  257. data/ext/numo/gsl/wavelet/tmpl/wavelet_array_check.c +56 -0
  258. data/ext/numo/gsl/wavelet/tmpl/wavelet_macro.c +1 -0
  259. data/ext/numo/gsl/wavelet/tmpl/wavelet_new.c +20 -0
  260. data/ext/numo/gsl/wavelet/tmpl/wavelet_transform.c +55 -0
  261. data/ext/numo/gsl/wavelet/tmpl/wavelet_transform2.c +22 -0
  262. data/ext/numo/gsl/wavelet/tmpl/wavelet_type_new.c +15 -0
  263. data/ext/numo/gsl/wavelet/type_def.rb +6 -0
  264. data/lib/numo/gsl.rb +17 -0
  265. data/numo-gsl.gemspec +33 -0
  266. metadata +367 -0
@@ -0,0 +1,166 @@
1
+ require_relative "func_parser"
2
+
3
+ module ErbppGsl
4
+
5
+ module_function
6
+
7
+ def FM(*args,**opts)
8
+ FuncMatch.new(*args,**opts)
9
+ end
10
+
11
+ def dbl; "double" end
12
+ def dblp; "double *" end
13
+ def str; "char *" end
14
+ def szt; "size_t" end
15
+ def sztp; "size_t *" end
16
+ def int; "int" end
17
+ def intp; "int *" end
18
+ def long; "long" end
19
+ def uint; "unsigned int" end
20
+ def ulong; /^unsigned long/ end
21
+ def void; "void" end
22
+ def tp; get(:struct)+" *" end
23
+
24
+ def read_eval(prefix)
25
+ fmt = prefix + "_%s.rb"
26
+ fn = fmt % `gsl-config --version`.chomp
27
+ if !File.exist?(fn)
28
+ fn = fmt % "def"
29
+ end
30
+ File.exist?(fn) ? eval(open(fn).read) : []
31
+ end
32
+
33
+ def read_func(prefix="func")
34
+ read_eval(prefix).each do |h|
35
+ h[:desc].gsub!(/\/\*/,"//")
36
+ h[:desc].gsub!(/\*\//,"")
37
+ end
38
+ end
39
+
40
+ def read_const
41
+ read_eval("const")
42
+ end
43
+
44
+ def read_enum
45
+ read_eval("enum")
46
+ end
47
+
48
+ def read_type
49
+ read_eval("type")
50
+ end
51
+
52
+ def read_func_pattern(*a)
53
+ read_func.each do |h|
54
+ no_match = true
55
+ a.each do |re,list|
56
+ if re === h[:func_name]
57
+ list << h
58
+ no_match = false
59
+ break
60
+ end
61
+ end
62
+ if no_match
63
+ $stderr.puts "skip "+h[:func_name]
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ class DefSubclassNew < DefMethod
71
+ def initialize(parent,tmpl,var,subtp=nil,**h)
72
+ super(parent, tmpl, name:"new", **h)
73
+ if !subtp
74
+ subtp = var.sub(/gsl_#{parent.name}_/,"")
75
+ end
76
+ set subtype_var: var
77
+ set subtype_name: subtp
78
+ set subtype_class: subtp.split('_').map{|x| x.capitalize}.join("")
79
+ set c_superclass_new: "#{parent.name}_s_new"
80
+ end
81
+
82
+ def c_func(narg=nil)
83
+ super(narg)
84
+ "#{@parent.name}_#{get(:subtype_name)}_s_new"
85
+ end
86
+
87
+ def init_def
88
+ if n_arg != :nodef
89
+ "{ VALUE c#{subtype_class} = rb_define_class_under(#{_mod_var}, \"#{subtype_class}\", #{_mod_var});
90
+ rb_define_singleton_method(c#{subtype_class}, \"new\", #{c_func}, #{n_arg}); }"
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ class DefGslClass < DefClass
97
+ include ErbppGsl
98
+
99
+ def lookup(h)
100
+ # implement in Subclass
101
+ raise NotImplementedError
102
+ end
103
+
104
+ def check_func(h)
105
+ fn = h[:func_name]
106
+ if t = lookup(h)
107
+ m = to_method_name(fn)
108
+ define_method(t, name:m, **h)
109
+ elsif /_free$/ =~ fn
110
+ set free_func: fn
111
+ else
112
+ $stderr.puts "skip #{fn}"
113
+ end
114
+ end
115
+
116
+ def to_method_name(s)
117
+ s.sub(/^gsl_#{name}_/,"")
118
+ end
119
+
120
+ def define_method(t,**h)
121
+ DefGslMethod.new(self, t, **h)
122
+ end
123
+ end
124
+
125
+ class DefGslModule < DefModule
126
+ include ErbppGsl
127
+
128
+ def lookup(h)
129
+ # implement in Subclass
130
+ end
131
+
132
+ def check_func(h)
133
+ if t = lookup(h)
134
+ m = to_method_name(h[:func_name])
135
+ define_method(t, name:m, **h)
136
+ else
137
+ $stderr.puts "skip #{h[:func_name]}"
138
+ end
139
+ end
140
+
141
+ def to_method_name(s)
142
+ s.sub(/^gsl_#{name}_/,"")
143
+ end
144
+
145
+ def define_method(t,**h)
146
+ DefGslModuleFunction.new(self, t, **h)
147
+ end
148
+ end
149
+
150
+ class DefGslModuleFunction < DefModuleFunction
151
+ include FuncParser
152
+
153
+ def initialize(parent,tmpl,**h)
154
+ super(parent,tmpl,**h)
155
+ parse_args(h)
156
+ end
157
+ end
158
+
159
+ class DefGslMethod < DefMethod
160
+ include FuncParser
161
+
162
+ def initialize(parent,tmpl,**h)
163
+ super(parent,tmpl,**h)
164
+ parse_args(h)
165
+ end
166
+ end
@@ -0,0 +1,520 @@
1
+ require_relative "erbpp2"
2
+
3
+ class Argument
4
+
5
+ def description
6
+ @func.param_desc[@name] ||
7
+ if @prop[:param]
8
+ "@param [#{rb_class}] #{@name}"
9
+ elsif @prop[:narray]
10
+ "@param [#{na_class}] #{@name}"
11
+ end
12
+ end
13
+
14
+ NUM2DATA =
15
+ {
16
+ "double"=>"%2 = NUM2DBL(%1)",
17
+ "int"=>"%2 = NUM2INT(%1)",
18
+ "unsigned int"=>"%2 = NUM2UINT(%1)",
19
+ "size_t"=>"%2 = NUM2SIZET(%1)",
20
+ "gsl_mode_t"=>"%2 = NUM2INT(%1)",
21
+ "gsl_sf_legendre_t"=>"%2 = NUM2INT(%1)",
22
+ "gsl_sf_mathieu_workspace *"=>'
23
+ if (rb_obj_is_kind_of(%1,cWorkspace)!=Qtrue) {
24
+ rb_raise(rb_eTypeError,"last argument must be "
25
+ "Numo::GSL::Sf::MathieuWorkspace class");
26
+ }
27
+ TypedData_Get_Struct(%1, gsl_sf_mathieu_workspace, &mathieuws_type, %2)'
28
+ }
29
+
30
+ DATA2NUM =
31
+ {
32
+ "double"=>"DBL2NUM(%1)",
33
+ "int"=>"INT2NUM(%1)",
34
+ "unsigned int"=>"UINT2NUM(%1)",
35
+ "size_t"=>"SIZET2NUM(%1)",
36
+ "gsl_sf_result *"=>["DBL2NUM(%1.val)","DBL2NUM(%1.err)"]
37
+ }
38
+
39
+ TYPEMAP =
40
+ {
41
+ "double"=>"cDF",
42
+ "gsl_complex"=>"cDC",
43
+ "unsigned int"=>"cUI",
44
+ "int"=>"cI",
45
+ "size_t"=>"cSZ",
46
+ }
47
+
48
+ NACLASSMAP =
49
+ {
50
+ "double"=>"Numo::DFloat",
51
+ "gsl_complex"=>"Numo::DComplex",
52
+ "unsigned int"=>"Numo::UInt",
53
+ "int"=>"Numo::Int",
54
+ "size_t"=>"Numo::UInt64",
55
+ "gsl_sf_result *"=>["Numo::DFloat"]*2,
56
+ "gsl_sf_result_e10 *"=>["Numo::DFloat"]*2+["Numo::Int"],
57
+ "gsl_sf_mathieu_workspace *"=>"Numo::GSL::Sf::MathieuWorkspace"
58
+ }
59
+
60
+ RBCLASSMAP =
61
+ {
62
+ "double"=>"Float",
63
+ "gsl_complex"=>"Complex",
64
+ "unsigned int"=>"Integer",
65
+ "int"=>"Integer",
66
+ "size_t"=>"Integer",
67
+ "gsl_mode_t"=>"Integer",
68
+ "gsl_sf_result *"=>["Float"]*2
69
+ }
70
+
71
+ CTYPEMAP =
72
+ {
73
+ "double"=>"double",
74
+ #"unsigned int"=>"uint32_t",
75
+ #"int"=>"int32_t",
76
+ "unsigned int"=>"unsigned int",
77
+ "int"=>"int",
78
+ "size_t"=>"uint64_t",
79
+ "gsl_complex"=>"gsl_complex",
80
+ }
81
+
82
+ RETNAMEMAP =
83
+ {
84
+ "double"=>"Numo::DFloat",
85
+ "gsl_complex"=>"Numo::DComplex",
86
+ #"unsigned int"=>"Numo::UInt32",
87
+ #"int"=>"Numo::Int32",
88
+ "unsigned int"=>"Numo::UInt",
89
+ "int"=>"Numo::Int",
90
+ "size_t"=>"Numo::UInt64",
91
+ "gsl_sf_result *"=>["Numo::DFloat"]*2,
92
+ "gsl_sf_result_e10 *"=>["Numo::DFloat"]*2+["Numo::Int"]
93
+ }
94
+
95
+ def initialize(func,idx,type,name,prop)
96
+ @func = func
97
+ @idx = idx
98
+ @type = type
99
+ @name = name
100
+ @prop = prop
101
+ @pass = @prop[:pass]
102
+
103
+ if /(.+)\*$/ =~ @type
104
+ @type2 = $1.strip
105
+ end
106
+
107
+ if @prop[:output]
108
+ @n_out =
109
+ case @type
110
+ when "gsl_sf_result_e10 *"; 3
111
+ when "gsl_sf_result *"; 2
112
+ else 1
113
+ end
114
+ end
115
+
116
+ @ctype = CTYPEMAP[@type] || CTYPEMAP[@type2]
117
+ end
118
+
119
+ attr_reader :type, :name
120
+ attr_reader :pass, :n_out
121
+
122
+ [:input,:output,:param,:narray].each do |sym|
123
+ define_method(sym){@prop[sym]}
124
+ end
125
+
126
+ def c_var
127
+ "c#{@idx}"
128
+ end
129
+
130
+ def c_arg
131
+ (@pass == :pointer) ? "&"+c_var : c_var
132
+ end
133
+
134
+ def v_var
135
+ if @func.n_arg < 0
136
+ "v[#{@idx}]"
137
+ else
138
+ "v#{@idx}"
139
+ end
140
+ end
141
+
142
+ def ain_def
143
+ "{#{na_type},0}"
144
+ end
145
+
146
+ def aout_def
147
+ case @type
148
+ when "gsl_sf_result_e10 *"
149
+ return "{cDF,0},{cDF,0},{cI,0}"
150
+ when "gsl_sf_result *"
151
+ return "{cDF,0},{cDF,0}"
152
+ end
153
+ case @pass
154
+ when :array
155
+ "{#{na_type},1,shape}"
156
+ when :pointer,:return
157
+ "{#{na_type},0}"
158
+ else
159
+ raise "no aout_def for #{self.inspect}"
160
+ end
161
+ end
162
+
163
+ def na_type
164
+ TYPEMAP[@type] || TYPEMAP[@type2]
165
+ end
166
+
167
+ def na_class
168
+ NACLASSMAP[@type] || NACLASSMAP[@type2]
169
+ end
170
+
171
+ def rb_class
172
+ RBCLASSMAP[@type] || RBCLASSMAP[@type2]
173
+ end
174
+
175
+ def ret_val
176
+ case @type
177
+ when "gsl_sf_result *"
178
+ [@name+".val",@name+".err"]
179
+ when "gsl_sf_result_e10 *"
180
+ [@name+".val",@name+".err",@name+".e10"]
181
+ else
182
+ @name
183
+ end
184
+ end
185
+
186
+ def def_var
187
+ if @prop[:param]
188
+ "#{@type} #{c_var};"
189
+ elsif @prop[:input]
190
+ "#{@type} #{c_var};"
191
+ elsif @pass == :array
192
+ "#{@type} *#{c_var};"
193
+ elsif @pass == :pointer
194
+ "#{@type2} #{c_var};"
195
+ elsif @pass == :return
196
+ "#{@type} #{c_var};"
197
+ else
198
+ raise "no variable definition"
199
+ end
200
+ end
201
+
202
+ def def_value
203
+ "VALUE #{v_var};"
204
+ end
205
+
206
+ def set_value
207
+ NUM2DATA[@type].gsub(/%1/,v_var).sub(/%2/,c_var)+";"
208
+ end
209
+
210
+ def get_value
211
+ case a = DATA2NUM[@type]
212
+ when String
213
+ a.gsub(/%1/,c_var)
214
+ when Array
215
+ a.map{|s| s.gsub(/%1/,c_var)}
216
+ end
217
+ end
218
+
219
+ def store_to_array(va)
220
+ a = get_value
221
+ a = [a] unless Array === a
222
+ a.map{|x|"rb_ary_push(#{va},#{x});"}.join("\n"+" "*8)
223
+ end
224
+
225
+ def set_param(opt)
226
+ n = @func.n_input
227
+ if @type == "gsl_mode_t" && n == @idx+1
228
+ return <<EOL
229
+ if (argc==#{@idx}) {
230
+ #{c_var} = GSL_MODE_DEFAULT;
231
+ } else if (argc==#{@idx+1}) {
232
+ #{set_value}
233
+ } else {
234
+ rb_raise(rb_eArgError,"invalid number of argument: %d for #{n-1} or #{n}",argc);
235
+ }
236
+ #{opt} = &#{c_var}; //#{@name}
237
+ EOL
238
+ else
239
+ return "#{set_value} #{opt} = &#{c_var}; //#{@name}"
240
+ end
241
+ end
242
+
243
+ def get_param(opt)
244
+ "#{c_var} = *(#{@type}*)(#{opt}); //#{@name}"
245
+ end
246
+
247
+ def get_data(lp)
248
+ "#{c_var} = *(#{@ctype}*)GET_PTR(#{lp},#{cnt}); //#{@name}"
249
+ end
250
+
251
+ def get_ptr(lp)
252
+ if @pass == :array
253
+ "#{c_var} = (#{@ctype}*)GET_PTR(#{lp},#{cnt}); //#{@name}"
254
+ end
255
+ end
256
+
257
+ def set_data(lp)
258
+ if @pass != :array
259
+ if "gsl_sf_result_e10 *" == @type
260
+ "*(double*)GET_PTR(#{lp},#{cnt}) = #{c_var}.val; "+
261
+ "*(double*)GET_PTR(#{lp},#{cnt}) = #{c_var}.err; "+
262
+ "*(int*)GET_PTR(#{lp},#{cnt}) = #{c_var}.e10; //#{@name}"
263
+ elsif "gsl_sf_result *" == @type
264
+ "*(double*)GET_PTR(#{lp},#{cnt}) = #{c_var}.val; "+
265
+ "*(double*)GET_PTR(#{lp},#{cnt}) = #{c_var}.err; //#{@name}"
266
+ else
267
+ "*(#{@ctype}*)GET_PTR(#{lp},#{cnt}) = #{c_var}; //#{@name}"
268
+ end
269
+ end
270
+ end
271
+
272
+ def cnt
273
+ @func.counter.inc
274
+ end
275
+ end
276
+
277
+ #----------------------------------------------------------
278
+
279
+ class FuncMatch
280
+
281
+ def initialize(*args,type:nil,name:nil)
282
+ @func_type = type
283
+ @func_name = name
284
+ @args = args
285
+ end
286
+
287
+ def ===(h)
288
+ if /These functions are now deprecated/m =~ h[:desc]
289
+ $stderr.puts "depricated: #{h[:func_name]}"
290
+ return false
291
+ end
292
+ if /This function is now deprecated/m =~ h[:desc]
293
+ $stderr.puts "depricated: #{h[:func_name]}"
294
+ return false
295
+ end
296
+ if @func_type
297
+ return false unless t = h[:func_type]
298
+ t.sub!(/^const\s+/,"")
299
+ #$stderr.puts [t,@func_type].inspect
300
+ return false unless @func_type === t
301
+ end
302
+ if @func_name
303
+ return false unless @func_name === h[:func_name]
304
+ end
305
+ if @args
306
+ return false unless h_args = h[:args]
307
+ #$stderr.puts [@args,h_args].inspect
308
+ return false unless @args.size == 0 || @args.size == h_args.size
309
+ @args.each_with_index do |a,i|
310
+ #$stderr.puts [a,h_args[i]].inspect
311
+ return false unless h_a = h_args[i]
312
+ case a
313
+ when Array
314
+ if a[0] # C type
315
+ return false unless t = h_a[0]
316
+ t.sub!(/^const\s+/,"")
317
+ return false unless a[0] === t
318
+ end
319
+ if a[1] # var name
320
+ return false unless a[1] === h_a[1]
321
+ end
322
+ else # String or Regexp
323
+ #$stderr.puts [a,h_a[0]].inspect
324
+ return false unless t = h_a[0]
325
+ t.sub!(/^const\s+/,"")
326
+ #$stderr.puts [a,t].inspect
327
+ return false unless a === t
328
+ end
329
+ end
330
+ end
331
+ #$stderr.puts self.inspect
332
+ true
333
+ end
334
+
335
+ end
336
+
337
+ class Counter
338
+ def initialize
339
+ @i = 0
340
+ end
341
+ def inc
342
+ i = @i
343
+ @i += 1
344
+ i
345
+ end
346
+ end
347
+
348
+ #----------------------------------------------------------
349
+
350
+ module FuncParser
351
+
352
+ def self.lookup(h)
353
+ false
354
+ end
355
+
356
+ PARAM_DESC = {}
357
+ PARAM_NAMES = {}
358
+
359
+ def param_desc
360
+ self.class::PARAM_DESC
361
+ end
362
+
363
+ def param_names
364
+ self.class::PARAM_NAMES
365
+ end
366
+
367
+ def parse_args(h)
368
+ i = 0
369
+ @parsed_args = []
370
+ h[:args].each do |type,name|
371
+ type = type.sub(/^const\s+/,"").strip
372
+ if /_array$/ =~ name && /(.+)\*$/ =~ type
373
+ type = $1.strip
374
+ name = name+"[]"
375
+ end
376
+ prop = argument_property(type,name)
377
+ @parsed_args << Argument.new(self,i,type,name,prop)
378
+ i += 1
379
+ end
380
+ t = h[:func_type]
381
+ if t != "void"
382
+ prop = argument_property(t,"return")
383
+ @parsed_args << Argument.new(self,i,t,"return",prop)
384
+ end
385
+ #
386
+ @args_param = @parsed_args.select{|a|a.param}
387
+ @args_input = @parsed_args.select{|a|a.input}
388
+ @args_in = @parsed_args.select{|a|a.narray && a.input}
389
+ @args_out = @parsed_args.select{|a|a.narray && a.output}
390
+ @parsed_args.each do |a|
391
+ if a.pass == :array
392
+ @generate_array = true
393
+ break
394
+ end
395
+ end
396
+ @counter = Counter.new
397
+ if @args_param.any?{|a| a.type=="gsl_mode_t"}
398
+ set n_arg: -1
399
+ else
400
+ set n_arg: @args_param.size+@args_in.size
401
+ end
402
+ end
403
+
404
+ #attr_reader :name
405
+ attr_reader :args_out, :args_in, :args_param
406
+ attr_reader :generate_array
407
+ attr_reader :counter
408
+
409
+ def argument_property(type,name)
410
+ if name == "return"
411
+ {output:true, narray:true, pass: :return}
412
+ elsif /\[\]$/ =~ name
413
+ {output:true, narray:true, pass: :array}
414
+ elsif is_param(type,name)
415
+ {input:true, param:true}
416
+ elsif /\*$/ =~ type
417
+ {output:true, narray:true, pass: :pointer}
418
+ else
419
+ {input:true, narray:true}
420
+ end
421
+ end
422
+
423
+ def is_param(tp,nm)
424
+ #$stderr.puts "type='#{tp}' name='#{nm}'"
425
+ a = self.class::PARAM_NAMES[tp]
426
+ case a
427
+ when Array
428
+ a.include?(nm)
429
+ else
430
+ a
431
+ end
432
+ end
433
+
434
+ def n_param
435
+ @args_param.size
436
+ end
437
+
438
+ def n_in
439
+ @args_in.size
440
+ end
441
+
442
+ def n_input
443
+ @args_input.size
444
+ end
445
+
446
+ def n_out
447
+ n = 0
448
+ @args_out.each{|a| n+=a.n_out}
449
+ n
450
+ end
451
+
452
+ def def_ain
453
+ @args_in.map{|a| a.ain_def}.join(",")
454
+ end
455
+
456
+ def def_aout
457
+ @args_out.map{|a| a.aout_def}.join(",")
458
+ end
459
+
460
+ def find_name(name)
461
+ @parsed_args.find{|a| a.name==name}
462
+ end
463
+
464
+ def c_args
465
+ @parsed_args.select{|a| a.pass != :return}.
466
+ map{|a| a.c_arg}.join(",")
467
+ end
468
+
469
+ def recv
470
+ a = args_out.last
471
+ if a && a.pass == :return
472
+ a.c_var + " = "
473
+ else
474
+ ""
475
+ end
476
+ end
477
+
478
+ def method_args
479
+ s = @args_input.map{|a| a.name}.join(",")
480
+ s.sub(/,mode$/,",[mode]")
481
+ end
482
+
483
+ def cdef_args
484
+ if n_arg == -1
485
+ "int argc, VALUE *v, VALUE mod"
486
+ else
487
+ "VALUE mod," +
488
+ @args_input.map{|a|"VALUE #{a.v_var}"}.join(",")
489
+ end
490
+ end
491
+
492
+ def ndl_args
493
+ @args_in.map{|a| a.v_var}.join(",")
494
+ end
495
+
496
+ def desc_param
497
+ #t = (["Numo::DFloat"]*n_out).join(",")
498
+ t = @args_out.map{|a| a.na_class}.flatten.join(", ")
499
+ v = @args_out.map{|a| a.ret_val}.flatten.join(", ")
500
+ if n_out > 1
501
+ r = "@return [[#{t}]] array of [#{v}]"
502
+ else
503
+ r = "@return [#{t}] #{v}"
504
+ end
505
+ @args_input.map{|a| a.description}+[r]
506
+ end
507
+
508
+ def desc_param_scalar
509
+ #t = (["Numo::DFloat"]*n_out).join(",")
510
+ t = @args_out.map{|a| a.rb_class}.flatten.join(", ")
511
+ v = @args_out.map{|a| a.ret_val}.flatten.join(", ")
512
+ if n_out > 1
513
+ r = "@return [[#{t}]] array of [#{v}]"
514
+ else
515
+ r = "@return [#{t}] #{v}"
516
+ end
517
+ @args_input.map{|a| a.description}+[r]
518
+ end
519
+
520
+ end