cumo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.travis.yml +5 -0
  4. data/3rd_party/mkmf-cu/.gitignore +36 -0
  5. data/3rd_party/mkmf-cu/Gemfile +3 -0
  6. data/3rd_party/mkmf-cu/LICENSE +21 -0
  7. data/3rd_party/mkmf-cu/README.md +36 -0
  8. data/3rd_party/mkmf-cu/Rakefile +11 -0
  9. data/3rd_party/mkmf-cu/bin/mkmf-cu-nvcc +4 -0
  10. data/3rd_party/mkmf-cu/lib/mkmf-cu.rb +32 -0
  11. data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +80 -0
  12. data/3rd_party/mkmf-cu/lib/mkmf-cu/nvcc.rb +157 -0
  13. data/3rd_party/mkmf-cu/mkmf-cu.gemspec +16 -0
  14. data/3rd_party/mkmf-cu/test/test_mkmf-cu.rb +67 -0
  15. data/CODE_OF_CONDUCT.md +46 -0
  16. data/Gemfile +8 -0
  17. data/LICENSE.txt +82 -0
  18. data/README.md +252 -0
  19. data/Rakefile +43 -0
  20. data/bench/broadcast_fp32.rb +138 -0
  21. data/bench/cumo_bench.rb +193 -0
  22. data/bench/numo_bench.rb +138 -0
  23. data/bench/reduction_fp32.rb +117 -0
  24. data/bin/console +14 -0
  25. data/bin/setup +8 -0
  26. data/cumo.gemspec +32 -0
  27. data/ext/cumo/cuda/cublas.c +278 -0
  28. data/ext/cumo/cuda/driver.c +421 -0
  29. data/ext/cumo/cuda/memory_pool.cpp +185 -0
  30. data/ext/cumo/cuda/memory_pool_impl.cpp +308 -0
  31. data/ext/cumo/cuda/memory_pool_impl.hpp +370 -0
  32. data/ext/cumo/cuda/memory_pool_impl_test.cpp +554 -0
  33. data/ext/cumo/cuda/nvrtc.c +207 -0
  34. data/ext/cumo/cuda/runtime.c +167 -0
  35. data/ext/cumo/cumo.c +148 -0
  36. data/ext/cumo/depend.erb +58 -0
  37. data/ext/cumo/extconf.rb +179 -0
  38. data/ext/cumo/include/cumo.h +25 -0
  39. data/ext/cumo/include/cumo/compat.h +23 -0
  40. data/ext/cumo/include/cumo/cuda/cublas.h +153 -0
  41. data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +187 -0
  42. data/ext/cumo/include/cumo/cuda/cumo_thrust_complex.hpp +79 -0
  43. data/ext/cumo/include/cumo/cuda/driver.h +22 -0
  44. data/ext/cumo/include/cumo/cuda/memory_pool.h +28 -0
  45. data/ext/cumo/include/cumo/cuda/nvrtc.h +22 -0
  46. data/ext/cumo/include/cumo/cuda/runtime.h +40 -0
  47. data/ext/cumo/include/cumo/indexer.h +238 -0
  48. data/ext/cumo/include/cumo/intern.h +142 -0
  49. data/ext/cumo/include/cumo/intern_fwd.h +38 -0
  50. data/ext/cumo/include/cumo/intern_kernel.h +6 -0
  51. data/ext/cumo/include/cumo/narray.h +429 -0
  52. data/ext/cumo/include/cumo/narray_kernel.h +149 -0
  53. data/ext/cumo/include/cumo/ndloop.h +95 -0
  54. data/ext/cumo/include/cumo/reduce_kernel.h +126 -0
  55. data/ext/cumo/include/cumo/template.h +158 -0
  56. data/ext/cumo/include/cumo/template_kernel.h +77 -0
  57. data/ext/cumo/include/cumo/types/bit.h +40 -0
  58. data/ext/cumo/include/cumo/types/bit_kernel.h +34 -0
  59. data/ext/cumo/include/cumo/types/complex.h +402 -0
  60. data/ext/cumo/include/cumo/types/complex_kernel.h +414 -0
  61. data/ext/cumo/include/cumo/types/complex_macro.h +382 -0
  62. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +186 -0
  63. data/ext/cumo/include/cumo/types/dcomplex.h +46 -0
  64. data/ext/cumo/include/cumo/types/dcomplex_kernel.h +13 -0
  65. data/ext/cumo/include/cumo/types/dfloat.h +47 -0
  66. data/ext/cumo/include/cumo/types/dfloat_kernel.h +14 -0
  67. data/ext/cumo/include/cumo/types/float_def.h +34 -0
  68. data/ext/cumo/include/cumo/types/float_def_kernel.h +39 -0
  69. data/ext/cumo/include/cumo/types/float_macro.h +191 -0
  70. data/ext/cumo/include/cumo/types/float_macro_kernel.h +158 -0
  71. data/ext/cumo/include/cumo/types/int16.h +24 -0
  72. data/ext/cumo/include/cumo/types/int16_kernel.h +23 -0
  73. data/ext/cumo/include/cumo/types/int32.h +24 -0
  74. data/ext/cumo/include/cumo/types/int32_kernel.h +19 -0
  75. data/ext/cumo/include/cumo/types/int64.h +24 -0
  76. data/ext/cumo/include/cumo/types/int64_kernel.h +19 -0
  77. data/ext/cumo/include/cumo/types/int8.h +24 -0
  78. data/ext/cumo/include/cumo/types/int8_kernel.h +19 -0
  79. data/ext/cumo/include/cumo/types/int_macro.h +67 -0
  80. data/ext/cumo/include/cumo/types/int_macro_kernel.h +48 -0
  81. data/ext/cumo/include/cumo/types/real_accum.h +486 -0
  82. data/ext/cumo/include/cumo/types/real_accum_kernel.h +101 -0
  83. data/ext/cumo/include/cumo/types/robj_macro.h +80 -0
  84. data/ext/cumo/include/cumo/types/robj_macro_kernel.h +0 -0
  85. data/ext/cumo/include/cumo/types/robject.h +27 -0
  86. data/ext/cumo/include/cumo/types/robject_kernel.h +7 -0
  87. data/ext/cumo/include/cumo/types/scomplex.h +46 -0
  88. data/ext/cumo/include/cumo/types/scomplex_kernel.h +13 -0
  89. data/ext/cumo/include/cumo/types/sfloat.h +48 -0
  90. data/ext/cumo/include/cumo/types/sfloat_kernel.h +14 -0
  91. data/ext/cumo/include/cumo/types/uint16.h +25 -0
  92. data/ext/cumo/include/cumo/types/uint16_kernel.h +20 -0
  93. data/ext/cumo/include/cumo/types/uint32.h +25 -0
  94. data/ext/cumo/include/cumo/types/uint32_kernel.h +20 -0
  95. data/ext/cumo/include/cumo/types/uint64.h +25 -0
  96. data/ext/cumo/include/cumo/types/uint64_kernel.h +20 -0
  97. data/ext/cumo/include/cumo/types/uint8.h +25 -0
  98. data/ext/cumo/include/cumo/types/uint8_kernel.h +20 -0
  99. data/ext/cumo/include/cumo/types/uint_macro.h +58 -0
  100. data/ext/cumo/include/cumo/types/uint_macro_kernel.h +38 -0
  101. data/ext/cumo/include/cumo/types/xint_macro.h +169 -0
  102. data/ext/cumo/include/cumo/types/xint_macro_kernel.h +88 -0
  103. data/ext/cumo/narray/SFMT-params.h +97 -0
  104. data/ext/cumo/narray/SFMT-params19937.h +46 -0
  105. data/ext/cumo/narray/SFMT.c +620 -0
  106. data/ext/cumo/narray/SFMT.h +167 -0
  107. data/ext/cumo/narray/array.c +638 -0
  108. data/ext/cumo/narray/data.c +961 -0
  109. data/ext/cumo/narray/gen/cogen.rb +56 -0
  110. data/ext/cumo/narray/gen/cogen_kernel.rb +58 -0
  111. data/ext/cumo/narray/gen/def/bit.rb +37 -0
  112. data/ext/cumo/narray/gen/def/dcomplex.rb +39 -0
  113. data/ext/cumo/narray/gen/def/dfloat.rb +37 -0
  114. data/ext/cumo/narray/gen/def/int16.rb +36 -0
  115. data/ext/cumo/narray/gen/def/int32.rb +36 -0
  116. data/ext/cumo/narray/gen/def/int64.rb +36 -0
  117. data/ext/cumo/narray/gen/def/int8.rb +36 -0
  118. data/ext/cumo/narray/gen/def/robject.rb +37 -0
  119. data/ext/cumo/narray/gen/def/scomplex.rb +39 -0
  120. data/ext/cumo/narray/gen/def/sfloat.rb +37 -0
  121. data/ext/cumo/narray/gen/def/uint16.rb +36 -0
  122. data/ext/cumo/narray/gen/def/uint32.rb +36 -0
  123. data/ext/cumo/narray/gen/def/uint64.rb +36 -0
  124. data/ext/cumo/narray/gen/def/uint8.rb +36 -0
  125. data/ext/cumo/narray/gen/erbpp2.rb +346 -0
  126. data/ext/cumo/narray/gen/narray_def.rb +268 -0
  127. data/ext/cumo/narray/gen/spec.rb +425 -0
  128. data/ext/cumo/narray/gen/tmpl/accum.c +86 -0
  129. data/ext/cumo/narray/gen/tmpl/accum_binary.c +121 -0
  130. data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +61 -0
  131. data/ext/cumo/narray/gen/tmpl/accum_index.c +119 -0
  132. data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +66 -0
  133. data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +12 -0
  134. data/ext/cumo/narray/gen/tmpl/alloc_func.c +107 -0
  135. data/ext/cumo/narray/gen/tmpl/allocate.c +37 -0
  136. data/ext/cumo/narray/gen/tmpl/aref.c +66 -0
  137. data/ext/cumo/narray/gen/tmpl/aref_cpu.c +50 -0
  138. data/ext/cumo/narray/gen/tmpl/aset.c +56 -0
  139. data/ext/cumo/narray/gen/tmpl/binary.c +162 -0
  140. data/ext/cumo/narray/gen/tmpl/binary2.c +70 -0
  141. data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +15 -0
  142. data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +31 -0
  143. data/ext/cumo/narray/gen/tmpl/binary_s.c +45 -0
  144. data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +15 -0
  145. data/ext/cumo/narray/gen/tmpl/bincount.c +181 -0
  146. data/ext/cumo/narray/gen/tmpl/cast.c +44 -0
  147. data/ext/cumo/narray/gen/tmpl/cast_array.c +13 -0
  148. data/ext/cumo/narray/gen/tmpl/class.c +9 -0
  149. data/ext/cumo/narray/gen/tmpl/class_kernel.cu +6 -0
  150. data/ext/cumo/narray/gen/tmpl/clip.c +121 -0
  151. data/ext/cumo/narray/gen/tmpl/coerce_cast.c +10 -0
  152. data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +129 -0
  153. data/ext/cumo/narray/gen/tmpl/cond_binary.c +68 -0
  154. data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +18 -0
  155. data/ext/cumo/narray/gen/tmpl/cond_unary.c +46 -0
  156. data/ext/cumo/narray/gen/tmpl/cum.c +50 -0
  157. data/ext/cumo/narray/gen/tmpl/each.c +47 -0
  158. data/ext/cumo/narray/gen/tmpl/each_with_index.c +70 -0
  159. data/ext/cumo/narray/gen/tmpl/ewcomp.c +79 -0
  160. data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +19 -0
  161. data/ext/cumo/narray/gen/tmpl/extract.c +22 -0
  162. data/ext/cumo/narray/gen/tmpl/extract_cpu.c +26 -0
  163. data/ext/cumo/narray/gen/tmpl/extract_data.c +53 -0
  164. data/ext/cumo/narray/gen/tmpl/eye.c +105 -0
  165. data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +19 -0
  166. data/ext/cumo/narray/gen/tmpl/fill.c +52 -0
  167. data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +29 -0
  168. data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +106 -0
  169. data/ext/cumo/narray/gen/tmpl/format.c +62 -0
  170. data/ext/cumo/narray/gen/tmpl/format_to_a.c +49 -0
  171. data/ext/cumo/narray/gen/tmpl/frexp.c +38 -0
  172. data/ext/cumo/narray/gen/tmpl/gemm.c +203 -0
  173. data/ext/cumo/narray/gen/tmpl/init_class.c +20 -0
  174. data/ext/cumo/narray/gen/tmpl/init_module.c +12 -0
  175. data/ext/cumo/narray/gen/tmpl/inspect.c +21 -0
  176. data/ext/cumo/narray/gen/tmpl/lib.c +50 -0
  177. data/ext/cumo/narray/gen/tmpl/lib_kernel.cu +24 -0
  178. data/ext/cumo/narray/gen/tmpl/logseq.c +102 -0
  179. data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +31 -0
  180. data/ext/cumo/narray/gen/tmpl/map_with_index.c +98 -0
  181. data/ext/cumo/narray/gen/tmpl/median.c +66 -0
  182. data/ext/cumo/narray/gen/tmpl/minmax.c +47 -0
  183. data/ext/cumo/narray/gen/tmpl/module.c +9 -0
  184. data/ext/cumo/narray/gen/tmpl/module_kernel.cu +1 -0
  185. data/ext/cumo/narray/gen/tmpl/new_dim0.c +15 -0
  186. data/ext/cumo/narray/gen/tmpl/new_dim0_kernel.cu +8 -0
  187. data/ext/cumo/narray/gen/tmpl/poly.c +50 -0
  188. data/ext/cumo/narray/gen/tmpl/pow.c +97 -0
  189. data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +29 -0
  190. data/ext/cumo/narray/gen/tmpl/powint.c +17 -0
  191. data/ext/cumo/narray/gen/tmpl/qsort.c +212 -0
  192. data/ext/cumo/narray/gen/tmpl/rand.c +168 -0
  193. data/ext/cumo/narray/gen/tmpl/rand_norm.c +121 -0
  194. data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +75 -0
  195. data/ext/cumo/narray/gen/tmpl/seq.c +112 -0
  196. data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +43 -0
  197. data/ext/cumo/narray/gen/tmpl/set2.c +57 -0
  198. data/ext/cumo/narray/gen/tmpl/sort.c +48 -0
  199. data/ext/cumo/narray/gen/tmpl/sort_index.c +111 -0
  200. data/ext/cumo/narray/gen/tmpl/store.c +41 -0
  201. data/ext/cumo/narray/gen/tmpl/store_array.c +187 -0
  202. data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +58 -0
  203. data/ext/cumo/narray/gen/tmpl/store_bit.c +86 -0
  204. data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +66 -0
  205. data/ext/cumo/narray/gen/tmpl/store_from.c +81 -0
  206. data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +58 -0
  207. data/ext/cumo/narray/gen/tmpl/store_kernel.cu +3 -0
  208. data/ext/cumo/narray/gen/tmpl/store_numeric.c +9 -0
  209. data/ext/cumo/narray/gen/tmpl/to_a.c +43 -0
  210. data/ext/cumo/narray/gen/tmpl/unary.c +132 -0
  211. data/ext/cumo/narray/gen/tmpl/unary2.c +60 -0
  212. data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +72 -0
  213. data/ext/cumo/narray/gen/tmpl/unary_ret2.c +34 -0
  214. data/ext/cumo/narray/gen/tmpl/unary_s.c +86 -0
  215. data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +58 -0
  216. data/ext/cumo/narray/gen/tmpl_bit/allocate.c +24 -0
  217. data/ext/cumo/narray/gen/tmpl_bit/aref.c +54 -0
  218. data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +57 -0
  219. data/ext/cumo/narray/gen/tmpl_bit/aset.c +56 -0
  220. data/ext/cumo/narray/gen/tmpl_bit/binary.c +98 -0
  221. data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +64 -0
  222. data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +88 -0
  223. data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +76 -0
  224. data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +133 -0
  225. data/ext/cumo/narray/gen/tmpl_bit/each.c +48 -0
  226. data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +70 -0
  227. data/ext/cumo/narray/gen/tmpl_bit/extract.c +30 -0
  228. data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +29 -0
  229. data/ext/cumo/narray/gen/tmpl_bit/fill.c +69 -0
  230. data/ext/cumo/narray/gen/tmpl_bit/format.c +64 -0
  231. data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +51 -0
  232. data/ext/cumo/narray/gen/tmpl_bit/inspect.c +21 -0
  233. data/ext/cumo/narray/gen/tmpl_bit/mask.c +136 -0
  234. data/ext/cumo/narray/gen/tmpl_bit/none_p.c +14 -0
  235. data/ext/cumo/narray/gen/tmpl_bit/store_array.c +108 -0
  236. data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +70 -0
  237. data/ext/cumo/narray/gen/tmpl_bit/store_from.c +60 -0
  238. data/ext/cumo/narray/gen/tmpl_bit/to_a.c +47 -0
  239. data/ext/cumo/narray/gen/tmpl_bit/unary.c +81 -0
  240. data/ext/cumo/narray/gen/tmpl_bit/where.c +90 -0
  241. data/ext/cumo/narray/gen/tmpl_bit/where2.c +95 -0
  242. data/ext/cumo/narray/index.c +880 -0
  243. data/ext/cumo/narray/kwargs.c +153 -0
  244. data/ext/cumo/narray/math.c +142 -0
  245. data/ext/cumo/narray/narray.c +1948 -0
  246. data/ext/cumo/narray/ndloop.c +2105 -0
  247. data/ext/cumo/narray/rand.c +45 -0
  248. data/ext/cumo/narray/step.c +474 -0
  249. data/ext/cumo/narray/struct.c +886 -0
  250. data/lib/cumo.rb +3 -0
  251. data/lib/cumo/cuda.rb +11 -0
  252. data/lib/cumo/cuda/compile_error.rb +36 -0
  253. data/lib/cumo/cuda/compiler.rb +161 -0
  254. data/lib/cumo/cuda/device.rb +47 -0
  255. data/lib/cumo/cuda/link_state.rb +31 -0
  256. data/lib/cumo/cuda/module.rb +40 -0
  257. data/lib/cumo/cuda/nvrtc_program.rb +27 -0
  258. data/lib/cumo/linalg.rb +12 -0
  259. data/lib/cumo/narray.rb +2 -0
  260. data/lib/cumo/narray/extra.rb +1278 -0
  261. data/lib/erbpp.rb +294 -0
  262. data/lib/erbpp/line_number.rb +137 -0
  263. data/lib/erbpp/narray_def.rb +381 -0
  264. data/numo-narray-version +1 -0
  265. data/run.gdb +7 -0
  266. metadata +353 -0
@@ -0,0 +1,37 @@
1
+ set name: "sfloat"
2
+ set type_name: "sfloat"
3
+ set full_class_name: "Cumo::SFloat"
4
+ set class_name: "SFloat"
5
+ set class_alias: "Float32"
6
+ set class_var: "cT"
7
+ set ctype: "float"
8
+
9
+ set has_math: true
10
+ set is_bit: false
11
+ set is_int: false
12
+ set is_unsigned: false
13
+ set is_float: true
14
+ set is_complex: false
15
+ set is_object: false
16
+ set is_real: true
17
+ set is_comparable: true
18
+ set is_double_precision: false
19
+ set need_align: true
20
+
21
+ upcast_rb "Integer"
22
+ upcast_rb "Float"
23
+ upcast_rb "Complex", "SComplex"
24
+
25
+ upcast "RObject", "RObject"
26
+ upcast "DComplex", "DComplex"
27
+ upcast "SComplex", "SComplex"
28
+ upcast "DFloat", "DFloat"
29
+ upcast "SFloat", "SFloat"
30
+ upcast "Int64", "SFloat"
31
+ upcast "Int32", "SFloat"
32
+ upcast "Int16", "SFloat"
33
+ upcast "Int8", "SFloat"
34
+ upcast "UInt64", "SFloat"
35
+ upcast "UInt32", "SFloat"
36
+ upcast "UInt16", "SFloat"
37
+ upcast "UInt8", "SFloat"
@@ -0,0 +1,36 @@
1
+ set name: "uint16"
2
+ set type_name: "uint16"
3
+ set full_class_name: "Cumo::UInt16"
4
+ set class_name: "UInt16"
5
+ set class_var: "cT"
6
+ set ctype: "u_int16_t"
7
+
8
+ set has_math: false
9
+ set is_bit: false
10
+ set is_int: true
11
+ set is_unsigned: true
12
+ set is_float: false
13
+ set is_complex: false
14
+ set is_object: false
15
+ set is_real: true
16
+ set is_comparable: true
17
+ set is_double_precision: false
18
+ set need_align: true
19
+
20
+ upcast_rb "Integer"
21
+ upcast_rb "Float", "DFloat"
22
+ upcast_rb "Complex", "DComplex"
23
+
24
+ upcast "RObject", "RObject"
25
+ upcast "DComplex", "DComplex"
26
+ upcast "SComplex", "SComplex"
27
+ upcast "DFloat", "DFloat"
28
+ upcast "SFloat", "SFloat"
29
+ upcast "Int64", "Int64"
30
+ upcast "Int32", "Int32"
31
+ upcast "Int16", "Int16"
32
+ upcast "Int8", "Int16"
33
+ upcast "UInt64", "UInt64"
34
+ upcast "UInt32", "UInt32"
35
+ upcast "UInt16"
36
+ upcast "UInt8"
@@ -0,0 +1,36 @@
1
+ set name: "uint32"
2
+ set type_name: "uint32"
3
+ set full_class_name: "Cumo::UInt32"
4
+ set class_name: "UInt32"
5
+ set class_var: "cT"
6
+ set ctype: "u_int32_t"
7
+
8
+ set has_math: false
9
+ set is_bit: false
10
+ set is_int: true
11
+ set is_unsigned: true
12
+ set is_float: false
13
+ set is_complex: false
14
+ set is_object: false
15
+ set is_real: true
16
+ set is_comparable: true
17
+ set is_double_precision: false
18
+ set need_align: true
19
+
20
+ upcast_rb "Integer"
21
+ upcast_rb "Float", "DFloat"
22
+ upcast_rb "Complex", "DComplex"
23
+
24
+ upcast "RObject", "RObject"
25
+ upcast "DComplex", "DComplex"
26
+ upcast "SComplex", "SComplex"
27
+ upcast "DFloat", "DFloat"
28
+ upcast "SFloat", "SFloat"
29
+ upcast "Int64", "Int64"
30
+ upcast "Int32", "Int32"
31
+ upcast "Int16", "Int32"
32
+ upcast "Int8", "Int32"
33
+ upcast "UInt64", "UInt64"
34
+ upcast "UInt32"
35
+ upcast "UInt16"
36
+ upcast "UInt8"
@@ -0,0 +1,36 @@
1
+ set name: "uint64"
2
+ set type_name: "uint64"
3
+ set full_class_name: "Cumo::UInt64"
4
+ set class_name: "UInt64"
5
+ set class_var: "cT"
6
+ set ctype: "u_int64_t"
7
+
8
+ set has_math: false
9
+ set is_bit: false
10
+ set is_int: true
11
+ set is_unsigned: true
12
+ set is_float: false
13
+ set is_complex: false
14
+ set is_object: false
15
+ set is_real: true
16
+ set is_comparable: true
17
+ set is_double_precision: false
18
+ set need_align: true
19
+
20
+ upcast_rb "Integer"
21
+ upcast_rb "Float", "DFloat"
22
+ upcast_rb "Complex", "DComplex"
23
+
24
+ upcast "RObject", "RObject"
25
+ upcast "DComplex", "DComplex"
26
+ upcast "SComplex", "SComplex"
27
+ upcast "DFloat", "DFloat"
28
+ upcast "SFloat", "SFloat"
29
+ upcast "Int64", "Int64"
30
+ upcast "Int32", "Int64"
31
+ upcast "Int16", "Int64"
32
+ upcast "Int8", "Int64"
33
+ upcast "UInt64"
34
+ upcast "UInt32"
35
+ upcast "UInt16"
36
+ upcast "UInt8"
@@ -0,0 +1,36 @@
1
+ set name: "uint8"
2
+ set type_name: "uint8"
3
+ set full_class_name: "Cumo::UInt8"
4
+ set class_name: "UInt8"
5
+ set class_var: "cT"
6
+ set ctype: "u_int8_t"
7
+
8
+ set has_math: false
9
+ set is_bit: false
10
+ set is_int: true
11
+ set is_unsigned: true
12
+ set is_float: false
13
+ set is_complex: false
14
+ set is_object: false
15
+ set is_real: true
16
+ set is_comparable: true
17
+ set is_double_precision: false
18
+ set need_align: false
19
+
20
+ upcast_rb "Integer"
21
+ upcast_rb "Float", "DFloat"
22
+ upcast_rb "Complex", "DComplex"
23
+
24
+ upcast "RObject", "RObject"
25
+ upcast "DComplex", "DComplex"
26
+ upcast "SComplex", "SComplex"
27
+ upcast "DFloat", "DFloat"
28
+ upcast "SFloat", "SFloat"
29
+ upcast "Int64", "Int64"
30
+ upcast "Int32", "Int32"
31
+ upcast "Int16", "Int16"
32
+ upcast "Int8", "Int8"
33
+ upcast "UInt64", "UInt64"
34
+ upcast "UInt32", "UInt32"
35
+ upcast "UInt16", "UInt16"
36
+ upcast "UInt8"
@@ -0,0 +1,346 @@
1
+ require "erb"
2
+
3
+ class ErbPP
4
+
5
+ def initialize(parent=nil, erb_base=nil, **opts, &block)
6
+ @parent = parent
7
+ @children = []
8
+ @opts = opts
9
+ set erb_base: erb_base if erb_base
10
+ @parent.add_child(self) if @parent
11
+ instance_eval(&block) if block
12
+ end
13
+
14
+ attr_reader :children
15
+ attr_accessor :parent
16
+
17
+ def add_child(child)
18
+ @children.push(child)
19
+ end
20
+
21
+ def set(**opts)
22
+ @opts.merge!(opts)
23
+ end
24
+
25
+ def get(key, *args, &block)
26
+ if respond_to?(key)
27
+ return send(key, *args, &block)
28
+ end
29
+ if args.empty? && block.nil? && @opts.has_key?(key)
30
+ return @opts[key]
31
+ end
32
+ if @parent
33
+ return @parent.get(key, *args, &block)
34
+ end
35
+ nil
36
+ end
37
+
38
+ def description
39
+ if s = @opts[:description] || @opts[:desc]
40
+ s.gsub(/\@\{/,"[").gsub(/\@\}/,"]")
41
+ end
42
+ end
43
+
44
+ alias desc description
45
+
46
+ alias method_missing_alias method_missing
47
+
48
+ def method_missing(_meth_id, *args, &block)
49
+ if args.empty?
50
+ #$stderr.puts _meth_id.inspect
51
+ v = get(_meth_id, *args, &block)
52
+ return v if !v.nil?
53
+ end
54
+ method_missing_alias(_meth_id, *args, &block)
55
+ end
56
+
57
+ # ERB Loader
58
+
59
+ def load_erb(base_name)
60
+ safe_level = nil
61
+ trim_mode = '%<>'
62
+ file = base_name + get(:erb_suffix)
63
+ dirs = get(:erb_dir)
64
+ dirs = [dirs] if !dirs.kind_of?(Array)
65
+ dirs.each do |x|
66
+ Dir.glob(x).each do |dir|
67
+ path = File.join(dir,file)
68
+ if File.exist?(path)
69
+ erb = ERB.new(File.read(path), safe_level, trim_mode)
70
+ erb.filename = path
71
+ return erb
72
+ end
73
+ end
74
+ end
75
+ nil
76
+ # raise "file not found: #{file.inspect} in #{dirs.inspect}"
77
+ end
78
+
79
+ def run
80
+ if base = @opts[:erb_base]
81
+ # load_erb(base).run(binding)
82
+ if l = load_erb(base)
83
+ l.run(binding)
84
+ end
85
+ end
86
+ end
87
+
88
+ def result
89
+ if base = @opts[:erb_base]
90
+ # load_erb(base).result(binding)
91
+ if l = load_erb(base)
92
+ l.result(binding)
93
+ end
94
+ end
95
+ end
96
+
97
+ def write(output)
98
+ File.open(output,"wt") do |f|
99
+ f.print(result)
100
+ end
101
+ end
102
+
103
+ def init_def
104
+ end
105
+
106
+ def find_tmpl(name)
107
+ @parent.children.find{|x| x.name == name }
108
+ end
109
+
110
+ def find(name)
111
+ children.find{|x| x.name == name }
112
+ end
113
+ end
114
+
115
+
116
+ class DefLib < ErbPP
117
+ def initialize(parent=nil, **opts, &block)
118
+ opts[:erb_base] ||= 'lib'
119
+ opts[:include_files] ||= []
120
+ super(parent, **opts, &block)
121
+ end
122
+ def id_assign
123
+ ids = []
124
+ @children.each{|c| a=c.get(:id_list); ids.concat(a) if a}
125
+ ids.sort.uniq.map{|x| "id_#{x[1]} = rb_intern(\"#{x[0]}\");"}
126
+ end
127
+ def id_decl
128
+ ids = []
129
+ @children.each{|c| a=c.get(:id_list); ids.concat(a) if a}
130
+ ids.sort.uniq.map{|x| "static ID id_#{x[1]};\n"}
131
+ end
132
+ def def_class(**opts, &block)
133
+ DefClass.new(self, **opts, &block)
134
+ end
135
+ def def_module(**opts, &block)
136
+ DefModule.new(self, **opts, &block)
137
+ end
138
+ end
139
+
140
+ module DeclMethod
141
+ def def_alloc_func(m, erb_path=nil, **opts, &block)
142
+ DefAllocFunc.new(self, erb_path||m, name:m, singleton:true, **opts, &block)
143
+ end
144
+ def undef_alloc_func
145
+ UndefAllocFunc.new(self)
146
+ end
147
+ def def_method(m, erb_path=nil, **opts, &block)
148
+ DefMethod.new(self, erb_path||m, name:m, **opts, &block)
149
+ end
150
+ def undef_method(m)
151
+ UndefMethod.new(self,name:m)
152
+ end
153
+ def def_singleton_method(m, erb_path=nil, **opts, &block)
154
+ DefMethod.new(self, erb_path||m, name:m, singleton:true, **opts, &block)
155
+ end
156
+ def undef_singleton_method(m)
157
+ UndefSingletonMethod.new(self,name:m)
158
+ end
159
+ def def_module_function(m, erb_path=nil, **opts, &block)
160
+ DefModuleFunction.new(self, erb_path||m, name:m, **opts, &block)
161
+ end
162
+ def def_alias(from, to)
163
+ DefAlias.new(self, from:from, to:to)
164
+ end
165
+ def def_const(m, v, **opts, &block)
166
+ DefConst.new(self, name:m, value:v, **opts, &block)
167
+ end
168
+ end
169
+
170
+ class DefModule < ErbPP
171
+ include DeclMethod
172
+ def initialize(parent, **opts, &block)
173
+ eb = opts[:erb_base] || 'module'
174
+ super(parent, erb_base:eb, **opts, &block)
175
+ end
176
+ def id_list
177
+ @id_list ||= []
178
+ end
179
+ def def_id(name,var=nil)
180
+ var = name.gsub(/\?/,"_p").gsub(/\!/,"_bang") if var.nil?
181
+ id_list << [name,var]
182
+ end
183
+ def init_def
184
+ load_erb(init_erb).result(binding)
185
+ end
186
+ def init_erb
187
+ @opts[:init_erb] || "init_module"
188
+ end
189
+ def method_code
190
+ @children.map{|c| c.result}.join("\n")
191
+ end
192
+ def _mod_var
193
+ @opts[:module_var]
194
+ end
195
+ end
196
+
197
+ class DefClass < DefModule
198
+ def initialize(parent, **opts, &block)
199
+ eb = opts[:erb_base] || 'class'
200
+ super(parent, erb_base:eb, **opts, &block)
201
+ end
202
+ def _mod_var
203
+ @opts[:class_var]
204
+ end
205
+ def init_erb
206
+ @opts[:init_erb] || "init_class"
207
+ end
208
+ def super_class
209
+ @opts[:super_class] || "rb_cObject"
210
+ end
211
+ def free_func
212
+ @opts[:free_func] || "gsl_"+get(:name)+"_free"
213
+ end
214
+ end
215
+
216
+ class DefMethod < ErbPP
217
+ include DeclMethod
218
+
219
+ def initialize(parent, erb_base, **opts, &block)
220
+ super(parent, **opts, &block)
221
+ set erb_base: erb_base
222
+ end
223
+
224
+ def id_op
225
+ if op.size == 1
226
+ "'#{op}'"
227
+ else
228
+ "id_#{c_name}"
229
+ end
230
+ end
231
+
232
+ def c_name
233
+ @opts[:name].gsub(/\?/,"_p").gsub(/\!/,"_bang").gsub(/=/,"_set")
234
+ end
235
+
236
+ def op_map
237
+ @opts[:op] || @opts[:name]
238
+ end
239
+
240
+ def c_func(n_arg=nil)
241
+ set n_arg: n_arg if n_arg
242
+ s = (singleton) ? "_s" : ""
243
+ "#{@parent.name}#{s}_#{c_name}"
244
+ end
245
+
246
+ def c_iter
247
+ "iter_#{c_func}"
248
+ end
249
+
250
+ def define_method_args
251
+ "#{_mod_var}, \"#{op_map}\", #{c_func}, #{n_arg}"
252
+ end
253
+
254
+ def init_def
255
+ return if n_arg == :nodef
256
+ s = (singleton) ? "_singleton" : ""
257
+ "rb_define#{s}_method(#{define_method_args});"
258
+ end
259
+
260
+ def singleton
261
+ @opts[:singleton]
262
+ end
263
+ end
264
+
265
+ class DefModuleFunction < DefMethod
266
+ def initialize(parent, erb_base, **opts, &block)
267
+ super(parent, erb_base, **opts, &block)
268
+ set singleton: true
269
+ end
270
+
271
+ def init_def
272
+ return if n_arg == :nodef
273
+ "rb_define_module_function(#{define_method_args});"
274
+ end
275
+ end
276
+
277
+ class DefAlias < ErbPP
278
+ def init_def
279
+ "rb_define_alias(#{_mod_var}, \"#{from}\", \"#{to}\");"
280
+ end
281
+ end
282
+
283
+ class DefAllocFunc < DefMethod
284
+ def init_def
285
+ "rb_define_alloc_func(#{_mod_var}, #{c_func});"
286
+ end
287
+ end
288
+
289
+ class UndefAllocFunc < ErbPP
290
+ def init_def
291
+ "rb_undef_alloc_func(#{_mod_var});"
292
+ end
293
+ end
294
+
295
+ class UndefMethod < ErbPP
296
+ def init_def
297
+ "rb_undef_method(#{_mod_var},\"#{name}\");"
298
+ end
299
+ end
300
+
301
+ class UndefSingletonMethod < ErbPP
302
+ def init_def
303
+ "rb_undef_method(rb_singleton_class(#{_mod_var}),\"#{name}\");"
304
+ end
305
+ end
306
+
307
+ class DefConst < ErbPP
308
+ def init_def
309
+ "/*#{desc}*/
310
+ rb_define_const(#{_mod_var},\"#{name}\",#{value});"
311
+ end
312
+ end
313
+
314
+ class DefError < ErbPP
315
+ def initialize(parent, name, sup_var, **opts, &block)
316
+ super(parent, error_name:name, error_var:"e"+name, super_var:sup_var,
317
+ **opts, &block)
318
+ end
319
+ def result
320
+ "static VALUE #{error_var};"
321
+ end
322
+ def init_def
323
+ "/*#{description}*/
324
+ #{error_var} = rb_define_class_under(#{ns_var},\"#{error_name}\",#{super_var});"
325
+ end
326
+ end
327
+
328
+ class DefStruct < ErbPP
329
+ def method_code
330
+ "static VALUE #{class_var};"
331
+ end
332
+ def init_def
333
+ items = members.map{|s| "\"#{s}\""}.join(",")
334
+ "/*#{description}*/
335
+ #{class_var} = rb_struct_define(\"#{class_name}\",#{items},NULL);"
336
+ end
337
+ end
338
+
339
+ class DefInclueModule < ErbPP
340
+ def initialize(parent=nil, incl_class, incl_module, **opts, &block)
341
+ super(parent,incl_class:incl_class,incl_module:incl_module,**opts,&block)
342
+ end
343
+ def init_def
344
+ "rb_include_module(#{get(:incl_class)}, #{get(:incl_module)});"
345
+ end
346
+ end