cumo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/3rd_party/LICENSE.txt +60 -0
  4. data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
  5. data/LICENSE.txt +1 -62
  6. data/README.md +33 -29
  7. data/bench/cumo_bench.rb +47 -25
  8. data/bench/numo_bench.rb +27 -25
  9. data/docs/src-tree.md +16 -0
  10. data/ext/cumo/cuda/cublas.c +69 -219
  11. data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
  12. data/ext/cumo/cuda/runtime.c +2 -14
  13. data/ext/cumo/cumo.c +16 -16
  14. data/ext/cumo/include/cumo.h +2 -2
  15. data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
  16. data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
  17. data/ext/cumo/include/cumo/indexer.h +46 -63
  18. data/ext/cumo/include/cumo/intern.h +58 -112
  19. data/ext/cumo/include/cumo/narray.h +214 -185
  20. data/ext/cumo/include/cumo/narray_kernel.h +66 -37
  21. data/ext/cumo/include/cumo/ndloop.h +42 -42
  22. data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
  23. data/ext/cumo/include/cumo/template.h +56 -51
  24. data/ext/cumo/include/cumo/template_kernel.h +31 -31
  25. data/ext/cumo/include/cumo/types/bit.h +3 -3
  26. data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
  27. data/ext/cumo/include/cumo/types/complex.h +126 -126
  28. data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
  29. data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
  30. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
  31. data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
  32. data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
  33. data/ext/cumo/include/cumo/types/int_macro.h +1 -1
  34. data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
  35. data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
  36. data/ext/cumo/include/cumo/types/scomplex.h +5 -5
  37. data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
  38. data/ext/cumo/narray/array.c +143 -143
  39. data/ext/cumo/narray/data.c +184 -184
  40. data/ext/cumo/narray/gen/cogen.rb +5 -2
  41. data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
  42. data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
  43. data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
  44. data/ext/cumo/narray/gen/erbln.rb +132 -0
  45. data/ext/cumo/narray/gen/erbpp2.rb +18 -13
  46. data/ext/cumo/narray/gen/narray_def.rb +3 -3
  47. data/ext/cumo/narray/gen/spec.rb +2 -2
  48. data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
  49. data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
  50. data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
  51. data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
  52. data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
  53. data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
  54. data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
  55. data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
  56. data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
  57. data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
  58. data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
  59. data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
  60. data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
  61. data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
  62. data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
  63. data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
  64. data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
  65. data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
  66. data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
  67. data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
  68. data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
  69. data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
  70. data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
  71. data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
  72. data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
  73. data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
  74. data/ext/cumo/narray/gen/tmpl/each.c +9 -9
  75. data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
  76. data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
  77. data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
  78. data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
  79. data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
  80. data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
  81. data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
  82. data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
  83. data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
  84. data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
  85. data/ext/cumo/narray/gen/tmpl/format.c +11 -11
  86. data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
  87. data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
  88. data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
  89. data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
  90. data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
  91. data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
  92. data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
  93. data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
  94. data/ext/cumo/narray/gen/tmpl/median.c +10 -10
  95. data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
  96. data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
  97. data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
  98. data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
  99. data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
  100. data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
  101. data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
  102. data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
  103. data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
  104. data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
  105. data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
  106. data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
  107. data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
  108. data/ext/cumo/narray/gen/tmpl/store.c +6 -6
  109. data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
  110. data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
  111. data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
  112. data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
  113. data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
  114. data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
  115. data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
  116. data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
  117. data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
  118. data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
  119. data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
  120. data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
  121. data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
  122. data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
  123. data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
  124. data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
  125. data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
  126. data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
  127. data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
  128. data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
  129. data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
  130. data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
  131. data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
  132. data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
  133. data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
  134. data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
  135. data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
  136. data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
  137. data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
  138. data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
  139. data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
  140. data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
  141. data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
  142. data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
  143. data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
  144. data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
  145. data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
  146. data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
  147. data/ext/cumo/narray/index.c +213 -213
  148. data/ext/cumo/narray/math.c +27 -27
  149. data/ext/cumo/narray/narray.c +484 -484
  150. data/ext/cumo/narray/ndloop.c +259 -258
  151. data/ext/cumo/narray/rand.c +3 -3
  152. data/ext/cumo/narray/step.c +70 -70
  153. data/ext/cumo/narray/struct.c +139 -139
  154. metadata +6 -7
  155. data/ext/cumo/include/cumo/intern_fwd.h +0 -38
  156. data/lib/erbpp.rb +0 -294
  157. data/lib/erbpp/line_number.rb +0 -137
  158. data/lib/erbpp/narray_def.rb +0 -381
@@ -21,7 +21,7 @@ random_seed()
21
21
  }
22
22
 
23
23
  static VALUE
24
- nary_s_srand(int argc, VALUE *argv, VALUE obj)
24
+ cumo_na_s_srand(int argc, VALUE *argv, VALUE obj)
25
25
  {
26
26
  VALUE vseed;
27
27
  u_int64_t seed;
@@ -39,7 +39,7 @@ nary_s_srand(int argc, VALUE *argv, VALUE obj)
39
39
  }
40
40
 
41
41
  void
42
- Init_cumo_nary_rand() {
43
- rb_define_singleton_method(cNArray, "srand", nary_s_srand, -1);
42
+ Init_cumo_na_rand() {
43
+ rb_define_singleton_method(cNArray, "srand", cumo_na_s_srand, -1);
44
44
  init_gen_rand(0);
45
45
  }
@@ -24,12 +24,12 @@
24
24
  #define DBL_EPSILON 2.2204460492503131e-16
25
25
  #endif
26
26
 
27
- static ID id_beg, id_end, id_len, id_step, id_excl;
27
+ static ID cumo_id_beg, cumo_id_end, cumo_id_len, cumo_id_step, cumo_id_excl;
28
28
 
29
- //#define EXCL(r) RTEST(rb_ivar_get((r), id_excl))
29
+ //#define EXCL(r) RTEST(rb_ivar_get((r), cumo_id_excl))
30
30
  #define EXCL(r) RTEST(rb_funcall((r), rb_intern("exclude_end?"), 0))
31
31
 
32
- #define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v) ? Qtrue : Qfalse)
32
+ #define SET_EXCL(r,v) rb_ivar_set((r), cumo_id_excl, (v) ? Qtrue : Qfalse)
33
33
 
34
34
  static void
35
35
  step_init(
@@ -49,27 +49,27 @@ step_init(
49
49
  rb_raise(rb_eRangeError,"length must be non negative");
50
50
  }
51
51
  }
52
- rb_ivar_set(self, id_beg, beg);
53
- rb_ivar_set(self, id_end, end);
54
- rb_ivar_set(self, id_len, len);
55
- rb_ivar_set(self, id_step, step);
52
+ rb_ivar_set(self, cumo_id_beg, beg);
53
+ rb_ivar_set(self, cumo_id_end, end);
54
+ rb_ivar_set(self, cumo_id_len, len);
55
+ rb_ivar_set(self, cumo_id_step, step);
56
56
  SET_EXCL(self, excl);
57
57
  }
58
58
 
59
59
  static VALUE
60
- nary_step_new2(
60
+ cumo_na_step_new2(
61
61
  VALUE range,
62
62
  VALUE step,
63
63
  VALUE len
64
64
  )
65
65
  {
66
66
  VALUE beg, end, excl;
67
- VALUE self = rb_obj_alloc(na_cStep);
67
+ VALUE self = rb_obj_alloc(cumo_na_cStep);
68
68
 
69
- //beg = rb_ivar_get(range, id_beg);
70
- beg = rb_funcall(range, id_beg, 0);
71
- //end = rb_ivar_get(range, id_end);
72
- end = rb_funcall(range, id_end, 0);
69
+ //beg = rb_ivar_get(range, cumo_id_beg);
70
+ beg = rb_funcall(range, cumo_id_beg, 0);
71
+ //end = rb_ivar_get(range, cumo_id_end);
72
+ end = rb_funcall(range, cumo_id_end, 0);
73
73
  excl = rb_funcall(range, rb_intern("exclude_end?"), 0);
74
74
 
75
75
  step_init(self, beg, end, step, len, excl);
@@ -96,7 +96,7 @@ step_initialize( int argc, VALUE *argv, VALUE self )
96
96
 
97
97
  rb_scan_args(argc, argv, "13", &a, &b, &c, &d);
98
98
  /* Selfs are immutable, so that they should be initialized only once. */
99
- if (rb_ivar_defined(self, id_beg)) {
99
+ if (rb_ivar_defined(self, cumo_id_beg)) {
100
100
  rb_name_error(rb_intern("initialize"), "`initialize' called twice");
101
101
  }
102
102
  if (rb_obj_is_kind_of(a,rb_cRange)) {
@@ -106,10 +106,10 @@ step_initialize( int argc, VALUE *argv, VALUE self )
106
106
  d = c;
107
107
  c = b;
108
108
  e = rb_funcall(a, rb_intern("exclude_end?"), 0);
109
- //b = rb_ivar_get(a, id_end);
110
- b = rb_funcall(a, id_end, 0);
111
- //a = rb_ivar_get(a, id_beg);
112
- a = rb_funcall(a, id_beg, 0);
109
+ //b = rb_ivar_get(a, cumo_id_end);
110
+ b = rb_funcall(a, cumo_id_end, 0);
111
+ //a = rb_ivar_get(a, cumo_id_beg);
112
+ a = rb_funcall(a, cumo_id_beg, 0);
113
113
  }
114
114
  step_init(self, a, b, c, d, e);
115
115
  return Qnil;
@@ -126,7 +126,7 @@ step_initialize( int argc, VALUE *argv, VALUE self )
126
126
  static VALUE
127
127
  step_first( VALUE self )
128
128
  {
129
- return rb_ivar_get(self, id_beg);
129
+ return rb_ivar_get(self, cumo_id_beg);
130
130
  }
131
131
 
132
132
  /*
@@ -140,7 +140,7 @@ step_first( VALUE self )
140
140
  static VALUE
141
141
  step_last( VALUE self )
142
142
  {
143
- return rb_ivar_get(self, id_end);
143
+ return rb_ivar_get(self, cumo_id_end);
144
144
  }
145
145
 
146
146
  /*
@@ -154,7 +154,7 @@ step_last( VALUE self )
154
154
  static VALUE
155
155
  step_length( VALUE self )
156
156
  {
157
- return rb_ivar_get(self, id_len);
157
+ return rb_ivar_get(self, cumo_id_len);
158
158
  }
159
159
 
160
160
  /*
@@ -167,7 +167,7 @@ step_length( VALUE self )
167
167
  static VALUE
168
168
  step_step( VALUE self )
169
169
  {
170
- return rb_ivar_get(self, id_step);
170
+ return rb_ivar_get(self, cumo_id_step);
171
171
  }
172
172
 
173
173
  /*
@@ -179,7 +179,7 @@ step_step( VALUE self )
179
179
  static VALUE
180
180
  step_exclude_end_p(VALUE self)
181
181
  {
182
- return RTEST(rb_ivar_get(self, id_excl)) ? Qtrue : Qfalse;
182
+ return RTEST(rb_ivar_get(self, cumo_id_excl)) ? Qtrue : Qfalse;
183
183
  }
184
184
 
185
185
 
@@ -192,7 +192,7 @@ step_exclude_end_p(VALUE self)
192
192
  */
193
193
 
194
194
  void
195
- nary_step_array_index(VALUE self, size_t ary_size,
195
+ cumo_na_step_array_index(VALUE self, size_t ary_size,
196
196
  size_t *plen, ssize_t *pbeg, ssize_t *pstep)
197
197
  {
198
198
  size_t len;
@@ -200,14 +200,14 @@ nary_step_array_index(VALUE self, size_t ary_size,
200
200
  VALUE vbeg, vend, vstep, vlen;
201
201
  ssize_t end=ary_size;
202
202
 
203
- //vbeg = rb_ivar_get(self, id_beg);
204
- //vend = rb_ivar_get(self, id_end);
205
- vlen = rb_ivar_get(self, id_len);
206
- vstep = rb_ivar_get(self, id_step);
207
- vbeg = rb_funcall(self, id_beg, 0);
208
- vend = rb_funcall(self, id_end, 0);
209
- //vlen = rb_funcall(self, id_len, 0);
210
- //vstep = rb_funcall(self, id_step, 0);
203
+ //vbeg = rb_ivar_get(self, cumo_id_beg);
204
+ //vend = rb_ivar_get(self, cumo_id_end);
205
+ vlen = rb_ivar_get(self, cumo_id_len);
206
+ vstep = rb_ivar_get(self, cumo_id_step);
207
+ vbeg = rb_funcall(self, cumo_id_beg, 0);
208
+ vend = rb_funcall(self, cumo_id_end, 0);
209
+ //vlen = rb_funcall(self, cumo_id_len, 0);
210
+ //vstep = rb_funcall(self, cumo_id_step, 0);
211
211
 
212
212
  if (RTEST(vbeg)) {
213
213
  beg = NUM2SSIZET(vbeg);
@@ -329,23 +329,23 @@ nary_step_array_index(VALUE self, size_t ary_size,
329
329
 
330
330
 
331
331
  void
332
- nary_step_sequence( VALUE self, size_t *plen, double *pbeg, double *pstep )
332
+ cumo_na_step_sequence( VALUE self, size_t *plen, double *pbeg, double *pstep )
333
333
  {
334
334
  VALUE vbeg, vend, vstep, vlen;
335
335
  double dbeg, dend, dstep=1, dsize, err;
336
336
  size_t size, n;
337
337
 
338
- //vbeg = rb_ivar_get(self, id_beg);
339
- vbeg = rb_funcall(self, id_beg, 0);
338
+ //vbeg = rb_ivar_get(self, cumo_id_beg);
339
+ vbeg = rb_funcall(self, cumo_id_beg, 0);
340
340
  dbeg = NUM2DBL(vbeg);
341
341
 
342
- //vend = rb_ivar_get(self, id_end);
343
- vend = rb_funcall(self, id_end, 0);
342
+ //vend = rb_ivar_get(self, cumo_id_end);
343
+ vend = rb_funcall(self, cumo_id_end, 0);
344
344
 
345
- vlen = rb_ivar_get(self, id_len);
346
- vstep = rb_ivar_get(self, id_step);
347
- //vlen = rb_funcall(self, id_len ,0);
348
- //vstep = rb_funcall(self, id_step,0);
345
+ vlen = rb_ivar_get(self, cumo_id_len);
346
+ vstep = rb_ivar_get(self, cumo_id_step);
347
+ //vlen = rb_funcall(self, cumo_id_len ,0);
348
+ //vstep = rb_funcall(self, cumo_id_step,0);
349
349
 
350
350
  if (RTEST(vlen)) {
351
351
  size = NUM2SIZET(vlen);
@@ -406,7 +406,7 @@ step_each( VALUE self )
406
406
  double beg, step;
407
407
  size_t i, size;
408
408
 
409
- a = nary_step_parameters( self, Qnil );
409
+ a = cumo_na_step_parameters( self, Qnil );
410
410
  beg = NUM2DBL(RARRAY_PTR(a)[0]);
411
411
  step = NUM2DBL(RARRAY_PTR(a)[1]);
412
412
  size = NUM2SIZET(RARRAY_PTR(a)[2]);
@@ -421,54 +421,54 @@ step_each( VALUE self )
421
421
  static VALUE
422
422
  range_with_step( VALUE range, VALUE step )
423
423
  {
424
- return nary_step_new2( range, step, Qnil );
424
+ return cumo_na_step_new2( range, step, Qnil );
425
425
  }
426
426
 
427
427
  static VALUE
428
428
  range_with_length( VALUE range, VALUE len )
429
429
  {
430
- return nary_step_new2( range, Qnil, len );
430
+ return cumo_na_step_new2( range, Qnil, len );
431
431
  }
432
432
 
433
433
 
434
434
  static VALUE
435
- nary_s_step( int argc, VALUE *argv, VALUE mod )
435
+ cumo_na_s_step( int argc, VALUE *argv, VALUE mod )
436
436
  {
437
- VALUE self = rb_obj_alloc(na_cStep);
437
+ VALUE self = rb_obj_alloc(cumo_na_cStep);
438
438
  step_initialize(argc, argv, self);
439
439
  return self;
440
440
  }
441
441
 
442
442
 
443
443
  void
444
- Init_cumo_nary_step()
444
+ Init_cumo_na_step()
445
445
  {
446
- na_cStep = rb_define_class_under(cNArray, "Step", rb_cObject);
447
- rb_include_module(na_cStep, rb_mEnumerable);
448
- rb_define_method(na_cStep, "initialize", step_initialize, -1);
449
-
450
- //rb_define_method(na_cStep, "each", step_each, 0);
451
-
452
- rb_define_method(na_cStep, "first", step_first, 0);
453
- rb_define_method(na_cStep, "last", step_last, 0);
454
- rb_define_method(na_cStep, "begin", step_first, 0);
455
- rb_define_method(na_cStep, "end", step_last, 0);
456
- rb_define_method(na_cStep, "step", step_step, 0);
457
- rb_define_method(na_cStep, "length", step_length, 0);
458
- rb_define_method(na_cStep, "size", step_length, 0);
459
- rb_define_method(na_cStep, "exclude_end?", step_exclude_end_p, 0);
460
- //rb_define_method(na_cStep, "to_s", step_to_s, 0);
461
- //rb_define_method(na_cStep, "inspect", step_inspect, 0);
462
- //rb_define_method(na_cStep, "parameters", nary_step_parameters, 1);
446
+ cumo_na_cStep = rb_define_class_under(cNArray, "Step", rb_cObject);
447
+ rb_include_module(cumo_na_cStep, rb_mEnumerable);
448
+ rb_define_method(cumo_na_cStep, "initialize", step_initialize, -1);
449
+
450
+ //rb_define_method(cumo_na_cStep, "each", step_each, 0);
451
+
452
+ rb_define_method(cumo_na_cStep, "first", step_first, 0);
453
+ rb_define_method(cumo_na_cStep, "last", step_last, 0);
454
+ rb_define_method(cumo_na_cStep, "begin", step_first, 0);
455
+ rb_define_method(cumo_na_cStep, "end", step_last, 0);
456
+ rb_define_method(cumo_na_cStep, "step", step_step, 0);
457
+ rb_define_method(cumo_na_cStep, "length", step_length, 0);
458
+ rb_define_method(cumo_na_cStep, "size", step_length, 0);
459
+ rb_define_method(cumo_na_cStep, "exclude_end?", step_exclude_end_p, 0);
460
+ //rb_define_method(cumo_na_cStep, "to_s", step_to_s, 0);
461
+ //rb_define_method(cumo_na_cStep, "inspect", step_inspect, 0);
462
+ //rb_define_method(cumo_na_cStep, "parameters", cumo_na_step_parameters, 1);
463
463
 
464
464
  rb_define_method(rb_cRange, "%", range_with_step, 1);
465
465
  rb_define_method(rb_cRange, "*", range_with_length, 1);
466
466
 
467
- rb_define_singleton_method(cNArray, "step", nary_s_step, -1);
467
+ rb_define_singleton_method(cNArray, "step", cumo_na_s_step, -1);
468
468
 
469
- id_beg = rb_intern("begin");
470
- id_end = rb_intern("end");
471
- id_len = rb_intern("length");
472
- id_step = rb_intern("step");
473
- id_excl = rb_intern("excl");
469
+ cumo_id_beg = rb_intern("begin");
470
+ cumo_id_end = rb_intern("end");
471
+ cumo_id_len = rb_intern("length");
472
+ cumo_id_step = rb_intern("step");
473
+ cumo_id_excl = rb_intern("excl");
474
474
  }
@@ -10,29 +10,29 @@ VALUE cT;
10
10
  static VALUE
11
11
  nst_allocate(VALUE self)
12
12
  {
13
- narray_t *na;
13
+ cumo_narray_t *na;
14
14
  void *ptr;
15
15
  VALUE velmsz;
16
16
 
17
- GetNArray(self,na);
17
+ CumoGetNArray(self,na);
18
18
 
19
- switch(NA_TYPE(na)) {
20
- case NARRAY_DATA_T:
21
- ptr = NA_DATA_PTR(na);
19
+ switch(CUMO_NA_TYPE(na)) {
20
+ case CUMO_NARRAY_DATA_T:
21
+ ptr = CUMO_NA_DATA_PTR(na);
22
22
  if (na->size > 0 && ptr == NULL) {
23
- velmsz = rb_const_get(CLASS_OF(self), rb_intern("element_byte_size"));
23
+ velmsz = rb_const_get(rb_obj_class(self), rb_intern("element_byte_size"));
24
24
  ptr = cumo_cuda_runtime_malloc(NUM2SIZET(velmsz) * na->size);
25
- NA_DATA_PTR(na) = ptr;
25
+ CUMO_NA_DATA_PTR(na) = ptr;
26
26
  }
27
27
  break;
28
- case NARRAY_VIEW_T:
29
- rb_funcall(NA_VIEW_DATA(na), rb_intern("allocate"), 0);
28
+ case CUMO_NARRAY_VIEW_T:
29
+ rb_funcall(CUMO_NA_VIEW_DATA(na), rb_intern("allocate"), 0);
30
30
  break;
31
- case NARRAY_FILEMAP_T:
32
- //ptr = ((narray_filemap_t*)na)->ptr;
31
+ case CUMO_NARRAY_FILEMAP_T:
32
+ //ptr = ((cumo_narray_filemap_t*)na)->ptr;
33
33
  // to be implemented
34
34
  default:
35
- rb_bug("invalid narray type : %d",NA_TYPE(na));
35
+ rb_bug("invalid narray type : %d",CUMO_NA_TYPE(na));
36
36
  }
37
37
  return self;
38
38
  }
@@ -48,7 +48,7 @@ static VALUE
48
48
  nst_definition(VALUE nst, VALUE idx)
49
49
  {
50
50
  long i;
51
- VALUE def = nst_definitions(CLASS_OF(nst));
51
+ VALUE def = nst_definitions(rb_obj_class(nst));
52
52
  long len = RARRAY_LEN(def);
53
53
 
54
54
  if (TYPE(idx) == T_STRING || TYPE(idx) == T_SYMBOL) {
@@ -71,27 +71,27 @@ nst_definition(VALUE nst, VALUE idx)
71
71
 
72
72
 
73
73
 
74
- void na_copy_array_structure(VALUE self, VALUE view);
74
+ void cumo_na_copy_array_structure(VALUE self, VALUE view);
75
75
 
76
76
  static VALUE
77
- na_make_view_struct(VALUE self, VALUE dtype, VALUE offset)
77
+ cumo_na_make_view_struct(VALUE self, VALUE dtype, VALUE offset)
78
78
  {
79
79
  size_t i, n;
80
80
  int j, k, ndim;
81
81
  size_t *shape;
82
82
  size_t *idx1, *idx2;
83
83
  ssize_t stride;
84
- stridx_t *stridx;
85
- narray_t *na, *nt;
86
- narray_view_t *na1, *na2;
84
+ cumo_stridx_t *stridx;
85
+ cumo_narray_t *na, *nt;
86
+ cumo_narray_view_t *na1, *na2;
87
87
  VALUE klass;
88
88
  volatile VALUE view;
89
89
 
90
- GetNArray(self,na);
90
+ CumoGetNArray(self,na);
91
91
 
92
92
  // build from Cumo::Struct
93
93
  if (rb_obj_is_kind_of(dtype,cNArray)) {
94
- GetNArray(dtype,nt);
94
+ CumoGetNArray(dtype,nt);
95
95
  ndim = na->ndim + nt->ndim;
96
96
  shape = ALLOCA_N(size_t,ndim);
97
97
  // struct dimensions
@@ -102,11 +102,11 @@ na_make_view_struct(VALUE self, VALUE dtype, VALUE offset)
102
102
  for (j=na->ndim,k=0; j<ndim; j++,k++) {
103
103
  shape[j] = nt->shape[k];
104
104
  }
105
- klass = CLASS_OF(dtype);
106
- stridx = ALLOC_N(stridx_t, ndim);
107
- stride = na_dtype_elmsz(klass);
105
+ klass = rb_obj_class(dtype);
106
+ stridx = ALLOC_N(cumo_stridx_t, ndim);
107
+ stride = cumo_na_dtype_element_stride(klass);
108
108
  for (j=ndim,k=nt->ndim; k; ) {
109
- SDX_SET_STRIDE(stridx[--j],stride);
109
+ CUMO_SDX_SET_STRIDE(stridx[--j],stride);
110
110
  stride *= nt->shape[--k];
111
111
  }
112
112
  } else {
@@ -115,43 +115,43 @@ na_make_view_struct(VALUE self, VALUE dtype, VALUE offset)
115
115
  for (j=0; j<ndim; j++) {
116
116
  shape[j] = na->shape[j];
117
117
  }
118
- klass = CLASS_OF(self);
118
+ klass = rb_obj_class(self);
119
119
  if (TYPE(dtype)==T_CLASS) {
120
120
  if (RTEST(rb_class_inherited_p(dtype,cNArray))) {
121
121
  klass = dtype;
122
122
  }
123
123
  }
124
- stridx = ALLOC_N(stridx_t, ndim);
124
+ stridx = ALLOC_N(cumo_stridx_t, ndim);
125
125
  }
126
126
 
127
- view = na_s_allocate_view(klass);
128
- na_copy_flags(self, view);
129
- GetNArrayView(view, na2);
130
- na_setup_shape((narray_t*)na2, ndim, shape);
127
+ view = cumo_na_s_allocate_view(klass);
128
+ cumo_na_copy_flags(self, view);
129
+ CumoGetNArrayView(view, na2);
130
+ cumo_na_setup_shape((cumo_narray_t*)na2, ndim, shape);
131
131
  na2->stridx = stridx;
132
132
 
133
133
  switch(na->type) {
134
- case NARRAY_DATA_T:
135
- case NARRAY_FILEMAP_T:
136
- stride = nary_element_stride(self);
134
+ case CUMO_NARRAY_DATA_T:
135
+ case CUMO_NARRAY_FILEMAP_T:
136
+ stride = cumo_na_element_stride(self);
137
137
  for (j=na->ndim; j--;) {
138
- SDX_SET_STRIDE(na2->stridx[j], stride);
138
+ CUMO_SDX_SET_STRIDE(na2->stridx[j], stride);
139
139
  stride *= na->shape[j];
140
140
  }
141
141
  na2->offset = 0;
142
142
  na2->data = self;
143
143
  break;
144
- case NARRAY_VIEW_T:
145
- GetNArrayView(self, na1);
144
+ case CUMO_NARRAY_VIEW_T:
145
+ CumoGetNArrayView(self, na1);
146
146
  for (j=na1->base.ndim; j--; ) {
147
- if (SDX_IS_INDEX(na1->stridx[j])) {
147
+ if (CUMO_SDX_IS_INDEX(na1->stridx[j])) {
148
148
  n = na1->base.shape[j];
149
- idx1 = SDX_GET_INDEX(na1->stridx[j]);
149
+ idx1 = CUMO_SDX_GET_INDEX(na1->stridx[j]);
150
150
  idx2 = ALLOC_N(size_t, na1->base.shape[j]);
151
151
  for (i=0; i<n; i++) {
152
152
  idx2[i] = idx1[i];
153
153
  }
154
- SDX_SET_INDEX(na2->stridx[j],idx2);
154
+ CUMO_SDX_SET_INDEX(na2->stridx[j],idx2);
155
155
  } else {
156
156
  na2->stridx[j] = na1->stridx[j];
157
157
  }
@@ -178,21 +178,21 @@ nst_field_view(VALUE self, VALUE idx)
178
178
  if (!RTEST(def)) {
179
179
  idx = rb_funcall(idx, rb_intern("to_s"), 0);
180
180
  rb_raise(rb_eTypeError, "Invalid field: '%s' for struct %s",
181
- StringValuePtr(idx), rb_class2name(CLASS_OF(self)));
181
+ StringValuePtr(idx), rb_class2name(rb_obj_class(self)));
182
182
  }
183
183
  type = RARRAY_AREF(def,1);
184
184
  ofs = RARRAY_AREF(def,2);
185
- return na_make_view_struct(self, type, ofs);
185
+ return cumo_na_make_view_struct(self, type, ofs);
186
186
  }
187
187
 
188
188
  static VALUE
189
189
  nst_field(VALUE self, VALUE idx)
190
190
  {
191
191
  VALUE obj;
192
- narray_view_t *nv;
192
+ cumo_narray_view_t *nv;
193
193
 
194
194
  obj = nst_field_view(self,idx);
195
- GetNArrayView(obj,nv);
195
+ CumoGetNArrayView(obj,nv);
196
196
  if (nv->base.ndim==0) {
197
197
  obj = rb_funcall(obj,rb_intern("extract_cpu"),0);
198
198
  }
@@ -291,9 +291,9 @@ nst_s_new(int argc, VALUE *argv, VALUE klass)
291
291
  size = rb_iv_get(st, "__offset__");
292
292
  members = rb_iv_get(st, "__members__");
293
293
  //printf("size=%d\n",NUM2INT(size));
294
- rb_define_const(st, CONTIGUOUS_STRIDE, size);
295
- rb_define_const(st, ELEMENT_BYTE_SIZE, size);
296
- rb_define_const(st, ELEMENT_BIT_SIZE, rb_funcall(size,'*',1,INT2FIX(8)));
294
+ rb_define_const(st, "CONTIGUOUS_STRIDE", size);
295
+ rb_define_const(st, "ELEMENT_BYTE_SIZE", size);
296
+ rb_define_const(st, "ELEMENT_BIT_SIZE", rb_funcall(size,'*',1,INT2FIX(8)));
297
297
 
298
298
  OBJ_FREEZE(members);
299
299
  rb_define_const(st, "DEFINITIONS", members);
@@ -316,7 +316,7 @@ nstruct_add_type(VALUE type, int argc, VALUE *argv, VALUE nst)
316
316
  size_t *shape=NULL;
317
317
  int ndim=0;
318
318
  ssize_t stride;
319
- narray_view_t *nt;
319
+ cumo_narray_view_t *nt;
320
320
  int j;
321
321
 
322
322
  for (i=0; i<argc; i++) {
@@ -333,14 +333,14 @@ nstruct_add_type(VALUE type, int argc, VALUE *argv, VALUE nst)
333
333
  rb_raise(rb_eArgError,"multiple shape in struct definition");
334
334
  }
335
335
  ndim = RARRAY_LEN(argv[i]);
336
- if (ndim > NA_MAX_DIMENSION) {
336
+ if (ndim > CUMO_NA_MAX_DIMENSION) {
337
337
  rb_raise(rb_eArgError,"too large number of dimensions");
338
338
  }
339
339
  if (ndim == 0) {
340
340
  rb_raise(rb_eArgError,"array is empty");
341
341
  }
342
342
  shape = ALLOCA_N(size_t, ndim);
343
- na_array_to_internal_shape(Qnil, argv[i], shape);
343
+ cumo_na_array_to_internal_shape(Qnil, argv[i], shape);
344
344
  break;
345
345
  }
346
346
  }
@@ -348,19 +348,19 @@ nstruct_add_type(VALUE type, int argc, VALUE *argv, VALUE nst)
348
348
  id = rb_to_id(name);
349
349
  name = ID2SYM(id);
350
350
  if (rb_obj_is_kind_of(type,cNArray)) {
351
- narray_t *na;
352
- GetNArray(type,na);
353
- type = CLASS_OF(type);
351
+ cumo_narray_t *na;
352
+ CumoGetNArray(type,na);
353
+ type = rb_obj_class(type);
354
354
  ndim = na->ndim;
355
355
  shape = na->shape;
356
356
  }
357
- type = nary_view_new(type,ndim,shape);
358
- GetNArrayView(type,nt);
357
+ type = cumo_na_view_new(type,ndim,shape);
358
+ CumoGetNArrayView(type,nt);
359
359
 
360
- nt->stridx = ALLOC_N(stridx_t,ndim);
361
- stride = na_dtype_elmsz(CLASS_OF(type));
360
+ nt->stridx = ALLOC_N(cumo_stridx_t,ndim);
361
+ stride = cumo_na_dtype_element_stride(rb_obj_class(type));
362
362
  for (j=ndim; j--; ) {
363
- SDX_SET_STRIDE(nt->stridx[j], stride);
363
+ CUMO_SDX_SET_STRIDE(nt->stridx[j], stride);
364
364
  stride *= shape[j];
365
365
  }
366
366
 
@@ -383,13 +383,13 @@ nst_extract(VALUE self)
383
383
 
384
384
 
385
385
  static void
386
- iter_nstruct_to_a(na_loop_t *const lp)
386
+ iter_nstruct_to_a(cumo_na_loop_t *const lp)
387
387
  {
388
388
  long i, len;
389
389
  VALUE opt, types, defs, def;
390
390
  VALUE elmt, velm, vary;
391
391
  size_t ofs, pos;
392
- narray_view_t *ne;
392
+ cumo_narray_view_t *ne;
393
393
 
394
394
  opt = lp->option;
395
395
  types = RARRAY_AREF(opt,0);
@@ -404,7 +404,7 @@ iter_nstruct_to_a(na_loop_t *const lp)
404
404
  ofs = NUM2SIZET(RARRAY_AREF(def,2));
405
405
  //ofs = NUM2SIZET(RARRAY_AREF(ofsts,i));
406
406
  elmt = RARRAY_AREF(types,i);
407
- GetNArrayView(elmt,ne);
407
+ CumoGetNArrayView(elmt,ne);
408
408
  ne->offset = pos + ofs;
409
409
  if (ne->base.ndim==0) {
410
410
  velm = rb_funcall(elmt,rb_intern("extract_cpu"),0);
@@ -417,15 +417,15 @@ iter_nstruct_to_a(na_loop_t *const lp)
417
417
  }
418
418
 
419
419
  static VALUE
420
- na_original_data(VALUE self)
420
+ cumo_na_original_data(VALUE self)
421
421
  {
422
- narray_t *na;
423
- narray_view_t *nv;
422
+ cumo_narray_t *na;
423
+ cumo_narray_view_t *nv;
424
424
 
425
- GetNArray(self,na);
425
+ CumoGetNArray(self,na);
426
426
  switch(na->type) {
427
- case NARRAY_VIEW_T:
428
- GetNArrayView(self, nv);
427
+ case CUMO_NARRAY_VIEW_T:
428
+ CumoGetNArrayView(self, nv);
429
429
  return nv->data;
430
430
  }
431
431
  return self;
@@ -436,9 +436,9 @@ nst_create_member_views(VALUE self)
436
436
  {
437
437
  VALUE defs, def, types, type, elmt;
438
438
  long i, len;
439
- narray_view_t *ne;
439
+ cumo_narray_view_t *ne;
440
440
 
441
- defs = nst_definitions(CLASS_OF(self));
441
+ defs = nst_definitions(rb_obj_class(self));
442
442
  len = RARRAY_LEN(defs);
443
443
  types = rb_ary_new2(len);
444
444
  //ofsts = rb_ary_new2(len);
@@ -446,25 +446,25 @@ nst_create_member_views(VALUE self)
446
446
  def = RARRAY_AREF(defs,i);
447
447
  type = RARRAY_AREF(def,1);
448
448
  //ofst = RARRAY_AREF(def,2);
449
- elmt = na_make_view(type);
449
+ elmt = cumo_na_make_view(type);
450
450
  rb_ary_push(types, elmt);
451
451
  //rb_ary_push(ofsts, ofst);
452
- GetNArrayView(elmt,ne);
453
- ne->data = na_original_data(self);
452
+ CumoGetNArrayView(elmt,ne);
453
+ ne->data = cumo_na_original_data(self);
454
454
  }
455
455
  return rb_assoc_new(types,defs);
456
456
  }
457
457
 
458
458
  static VALUE
459
- nary_struct_to_a(VALUE self)
459
+ cumo_na_struct_to_a(VALUE self)
460
460
  {
461
461
  volatile VALUE opt;
462
- ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
463
- ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
464
- ndfunc_t ndf = {iter_nstruct_to_a, NO_LOOP, 3, 1, ain, aout};
462
+ cumo_ndfunc_arg_in_t ain[3] = {{Qnil,0},{cumo_sym_loop_opt},{cumo_sym_option}};
463
+ cumo_ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
464
+ cumo_ndfunc_t ndf = {iter_nstruct_to_a, CUMO_NO_LOOP, 3, 1, ain, aout};
465
465
 
466
466
  opt = nst_create_member_views(self);
467
- return na_ndloop_cast_narray_to_rarray(&ndf, self, opt);
467
+ return cumo_na_ndloop_cast_narray_to_rarray(&ndf, self, opt);
468
468
  }
469
469
 
470
470
 
@@ -472,13 +472,13 @@ nary_struct_to_a(VALUE self)
472
472
  /*
473
473
  static size_t
474
474
  check_array(VALUE item) {
475
- narray_t *na;
475
+ cumo_narray_t *na;
476
476
 
477
477
  if (TYPE(item) == T_ARRAY) {
478
478
  return 1;
479
479
  }
480
480
  if (RTEST(rb_obj_is_kind_of(item, cNArray))) {
481
- GetNArray(item,na);
481
+ CumoGetNArray(item,na);
482
482
  if (na->ndim == 1) {
483
483
  return 1;
484
484
  } else {
@@ -492,7 +492,7 @@ check_array(VALUE item) {
492
492
  /*
493
493
  static size_t
494
494
  check_array_1d(VALUE item, size_t size) {
495
- narray_t *na;
495
+ cumo_narray_t *na;
496
496
  size_t i, len;
497
497
 
498
498
  if (TYPE(item) == T_ARRAY) {
@@ -508,7 +508,7 @@ check_array_1d(VALUE item, size_t size) {
508
508
  return 1;
509
509
  }
510
510
  if (RTEST(rb_obj_is_kind_of(item, cNArray))) {
511
- GetNArray(item,na);
511
+ CumoGetNArray(item,na);
512
512
  if (na->ndim == 1 && na->size == size) {
513
513
  return 1;
514
514
  } else {
@@ -525,10 +525,10 @@ nst_check_compatibility(VALUE nst, VALUE ary)
525
525
  {
526
526
  VALUE defs, def, type, item;
527
527
  long len, i;
528
- narray_t *nt;
528
+ cumo_narray_t *nt;
529
529
 
530
530
  if (TYPE(ary) != T_ARRAY) {
531
- if (nst==CLASS_OF(ary)) { // same Struct
531
+ if (nst==rb_obj_class(ary)) { // same Struct
532
532
  return Qtrue;
533
533
  }
534
534
  return Qfalse;
@@ -543,7 +543,7 @@ nst_check_compatibility(VALUE nst, VALUE ary)
543
543
  for (i=0; i<len; i++) {
544
544
  def = RARRAY_AREF(defs,i);
545
545
  type = RARRAY_AREF(def,1);
546
- GetNArray(type,nt);
546
+ CumoGetNArray(type,nt);
547
547
  item = RARRAY_AREF(ary,i);
548
548
  if (nt->ndim == 0) {
549
549
  if (check_array(item)) {
@@ -558,15 +558,15 @@ nst_check_compatibility(VALUE nst, VALUE ary)
558
558
  } else {
559
559
  // multi-dimension member
560
560
  //volatile VALUE vnc;
561
- //na_compose_t *nc;
561
+ //cumo_na_compose_t *nc;
562
562
  VALUE vnc;
563
- narray_t *nc;
563
+ cumo_narray_t *nc;
564
564
  int j;
565
565
 
566
- //vnc = na_ary_composition(item);
567
- //Data_Get_Struct(vnc, na_compose_t, nc);
568
- vnc = na_s_new_like(cNArray, item);
569
- GetNArray(vnc,nc);
566
+ //vnc = cumo_na_ary_composition(item);
567
+ //Data_Get_Struct(vnc, cumo_na_compose_t, nc);
568
+ vnc = cumo_na_s_new_like(cNArray, item);
569
+ CumoGetNArray(vnc,nc);
570
570
  if (nt->ndim != nc->ndim) {
571
571
  return Qfalse;
572
572
  }
@@ -583,31 +583,31 @@ nst_check_compatibility(VALUE nst, VALUE ary)
583
583
  */
584
584
 
585
585
 
586
- VALUE na_ary_composition_for_struct(VALUE nstruct, VALUE ary);
586
+ VALUE cumo_na_ary_composition_for_struct(VALUE nstruct, VALUE ary);
587
587
 
588
588
  // ------
589
589
  static void
590
- iter_nstruct_from_a(na_loop_t *const lp)
590
+ iter_nstruct_from_a(cumo_na_loop_t *const lp)
591
591
  {
592
592
  long i, len;
593
593
  VALUE ary;
594
594
  VALUE types, defs, def;
595
595
  VALUE elmt, item;
596
596
  size_t ofs;
597
- narray_view_t *ne;
597
+ cumo_narray_view_t *ne;
598
598
 
599
599
  types = RARRAY_AREF(lp->option,0);
600
600
  defs = RARRAY_AREF(lp->option,1);
601
601
 
602
602
  len = RARRAY_LEN(types);
603
603
  ary = lp->args[1].value;
604
- //rb_p(CLASS_OF(ary));rb_p(ary);
604
+ //rb_p(rb_obj_class(ary));rb_p(ary);
605
605
 
606
606
  for (i=0; i<len; i++) {
607
607
  def = RARRAY_AREF(defs,i);
608
608
  ofs = NUM2SIZET(RARRAY_AREF(def,2));
609
609
  elmt = RARRAY_AREF(types,i);
610
- GetNArrayView(elmt,ne);
610
+ CumoGetNArrayView(elmt,ne);
611
611
  ne->offset = lp->args[0].iter[0].pos + ofs;
612
612
  item = RARRAY_AREF(ary,i);
613
613
  //rb_p(ary);
@@ -619,44 +619,44 @@ iter_nstruct_from_a(na_loop_t *const lp)
619
619
  }
620
620
 
621
621
  static VALUE
622
- nary_struct_cast_array(VALUE klass, VALUE rary)
622
+ cumo_na_struct_cast_array(VALUE klass, VALUE rary)
623
623
  {
624
624
  //volatile VALUE vnc, nary;
625
625
  VALUE nary;
626
- narray_t *na;
627
- //na_compose_t *nc;
626
+ cumo_narray_t *na;
627
+ //cumo_na_compose_t *nc;
628
628
  VALUE opt;
629
- ndfunc_arg_in_t ain[3] = {{OVERWRITE,0},{rb_cArray,0},{sym_option}};
630
- ndfunc_t ndf = {iter_nstruct_from_a, NO_LOOP, 3, 0, ain, 0};
629
+ cumo_ndfunc_arg_in_t ain[3] = {{CUMO_OVERWRITE,0},{rb_cArray,0},{cumo_sym_option}};
630
+ cumo_ndfunc_t ndf = {iter_nstruct_from_a, CUMO_NO_LOOP, 3, 0, ain, 0};
631
631
 
632
632
  //fprintf(stderr,"rary:");rb_p(rary);
633
- //fprintf(stderr,"class_of(rary):");rb_p(CLASS_OF(rary));
633
+ //fprintf(stderr,"class_of(rary):");rb_p(rb_obj_class(rary));
634
634
 
635
- //vnc = na_ary_composition_for_struct(klass, rary);
636
- //Data_Get_Struct(vnc, na_compose_t, nc);
637
- //nary = nary_new(klass, nc->ndim, nc->shape);
638
- nary = na_s_new_like(klass, rary);
639
- GetNArray(nary,na);
635
+ //vnc = cumo_na_ary_composition_for_struct(klass, rary);
636
+ //Data_Get_Struct(vnc, cumo_na_compose_t, nc);
637
+ //nary = cumo_na_new(klass, nc->ndim, nc->shape);
638
+ nary = cumo_na_s_new_like(klass, rary);
639
+ CumoGetNArray(nary,na);
640
640
  //fprintf(stderr,"na->size=%lu\n",na->size);
641
641
  //fprintf(stderr,"na->ndim=%d\n",na->ndim);
642
642
  if (na->size>0) {
643
643
  opt = nst_create_member_views(nary);
644
644
  rb_funcall(nary, rb_intern("allocate"), 0);
645
- na_ndloop_store_rarray2(&ndf, nary, rary, opt);
645
+ cumo_na_ndloop_store_rarray2(&ndf, nary, rary, opt);
646
646
  }
647
647
  return nary;
648
648
  }
649
649
 
650
650
  static inline VALUE
651
- nary_struct_s_cast(VALUE klass, VALUE rary)
651
+ cumo_na_struct_s_cast(VALUE klass, VALUE rary)
652
652
  {
653
- return nary_struct_cast_array(klass, rary);
653
+ return cumo_na_struct_cast_array(klass, rary);
654
654
  }
655
655
 
656
656
 
657
657
 
658
658
  static void
659
- iter_struct_store_struct(na_loop_t *const lp)
659
+ iter_struct_store_struct(cumo_na_loop_t *const lp)
660
660
  {
661
661
  size_t i, s1, s2;
662
662
  char *p1, *p2;
@@ -664,10 +664,10 @@ iter_struct_store_struct(na_loop_t *const lp)
664
664
  size_t elmsz;
665
665
  char *x, *y;
666
666
 
667
- INIT_COUNTER(lp, i);
668
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
669
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
670
- INIT_ELMSIZE(lp, 0, elmsz);
667
+ CUMO_INIT_COUNTER(lp, i);
668
+ CUMO_INIT_PTR_IDX(lp, 0, p1, s1, idx1);
669
+ CUMO_INIT_PTR_IDX(lp, 1, p2, s2, idx2);
670
+ CUMO_INIT_ELMSIZE(lp, 0, elmsz);
671
671
  if (idx2) {
672
672
  if (idx1) {
673
673
  for (; i--;) {
@@ -701,12 +701,12 @@ iter_struct_store_struct(na_loop_t *const lp)
701
701
 
702
702
 
703
703
  static VALUE
704
- nary_struct_store_struct(VALUE self, VALUE obj)
704
+ cumo_na_struct_store_struct(VALUE self, VALUE obj)
705
705
  {
706
- ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{Qnil,0}};
707
- ndfunc_t ndf = {iter_struct_store_struct, FULL_LOOP, 2, 0, ain, 0};
706
+ cumo_ndfunc_arg_in_t ain[2] = {{CUMO_OVERWRITE,0},{Qnil,0}};
707
+ cumo_ndfunc_t ndf = {iter_struct_store_struct, CUMO_FULL_LOOP, 2, 0, ain, 0};
708
708
 
709
- na_ndloop(&ndf, 2, self, obj);
709
+ cumo_na_ndloop(&ndf, 2, self, obj);
710
710
  return self;
711
711
  }
712
712
 
@@ -714,9 +714,9 @@ nary_struct_store_struct(VALUE self, VALUE obj)
714
714
 
715
715
 
716
716
  static inline VALUE
717
- nary_struct_store_array(VALUE self, VALUE obj)
717
+ cumo_na_struct_store_array(VALUE self, VALUE obj)
718
718
  {
719
- return nary_struct_store_struct(self, nary_struct_cast_array(CLASS_OF(self),obj));
719
+ return cumo_na_struct_store_struct(self, cumo_na_struct_cast_array(rb_obj_class(self),obj));
720
720
  }
721
721
 
722
722
  /*
@@ -726,32 +726,32 @@ nary_struct_store_array(VALUE self, VALUE obj)
726
726
  @return [Cumo::Struct] self
727
727
  */
728
728
  static VALUE
729
- nary_struct_store(VALUE self, VALUE obj)
729
+ cumo_na_struct_store(VALUE self, VALUE obj)
730
730
  {
731
731
  if (TYPE(obj)==T_ARRAY) {
732
- nary_struct_store_array(self,obj);
732
+ cumo_na_struct_store_array(self,obj);
733
733
  return self;
734
734
  }
735
- if (CLASS_OF(self) == CLASS_OF(obj)) {
736
- nary_struct_store_struct(self,obj);
735
+ if (rb_obj_class(self) == rb_obj_class(obj)) {
736
+ cumo_na_struct_store_struct(self,obj);
737
737
  return self;
738
738
  }
739
- rb_raise(nary_eCastError, "unknown conversion from %s to %s",
740
- rb_class2name(CLASS_OF(obj)),
741
- rb_class2name(CLASS_OF(self)));
739
+ rb_raise(cumo_na_eCastError, "unknown conversion from %s to %s",
740
+ rb_class2name(rb_obj_class(obj)),
741
+ rb_class2name(rb_obj_class(self)));
742
742
  return self;
743
743
  }
744
744
 
745
745
 
746
746
 
747
747
  static VALUE
748
- //iter_struct_inspect(na_loop_t *const lp)
748
+ //iter_struct_inspect(cumo_na_loop_t *const lp)
749
749
  iter_struct_inspect(char *ptr, size_t pos, VALUE opt)
750
750
  {
751
751
  VALUE types, defs, def, name, elmt, vary, v, x;
752
752
  size_t ofs;
753
753
  long i, len;
754
- narray_view_t *ne;
754
+ cumo_narray_view_t *ne;
755
755
 
756
756
  types = RARRAY_AREF(opt,0);
757
757
  defs = RARRAY_AREF(opt,1);
@@ -764,7 +764,7 @@ iter_struct_inspect(char *ptr, size_t pos, VALUE opt)
764
764
  name = RARRAY_AREF(def,0);
765
765
  ofs = NUM2SIZET(RARRAY_AREF(def,2));
766
766
  elmt = RARRAY_AREF(types,i);
767
- GetNArrayView(elmt,ne);
767
+ CumoGetNArrayView(elmt,ne);
768
768
  ne->offset = pos + ofs;
769
769
  v = rb_str_concat(rb_sym_to_s(name), rb_str_new2(": "));
770
770
  x = rb_funcall(elmt, rb_intern("format_to_a"), 0); // <-- fix me
@@ -787,11 +787,11 @@ iter_struct_inspect(char *ptr, size_t pos, VALUE opt)
787
787
  @return [String]
788
788
  */
789
789
  static VALUE
790
- nary_struct_inspect(VALUE ary)
790
+ cumo_na_struct_inspect(VALUE ary)
791
791
  {
792
792
  VALUE opt;
793
793
  opt = nst_create_member_views(ary);
794
- return na_ndloop_inspect(ary, iter_struct_inspect, opt);
794
+ return cumo_na_ndloop_inspect(ary, iter_struct_inspect, opt);
795
795
  }
796
796
 
797
797
 
@@ -833,7 +833,7 @@ NST_TYPEDEF(scomplex,cumo_cSComplex)
833
833
  rb_define_alias(rb_singleton_class(klass),name1,name2)
834
834
 
835
835
  void
836
- Init_cumo_nary_struct()
836
+ Init_cumo_na_struct()
837
837
  {
838
838
  cT = rb_define_class_under(mCumo, "Struct", cumo_cNArray);
839
839
  //cNStMember = rb_define_class_under(cT, "Member", rb_cObject);
@@ -868,18 +868,18 @@ Init_cumo_nary_struct()
868
868
  rb_define_method(cT, "extract", nst_extract, 0);
869
869
  rb_define_method(cT, "method_missing", nst_method_missing, -1);
870
870
 
871
- //rb_define_method(cT, "fill", nary_nstruct_fill, 1);
871
+ //rb_define_method(cT, "fill", cumo_na_nstruct_fill, 1);
872
872
 
873
- //rb_define_method(cT, "debug_print", nary_nstruct_debug_print, 0);
873
+ //rb_define_method(cT, "debug_print", cumo_na_nstruct_debug_print, 0);
874
874
 
875
- rb_define_method(cT, "to_a", nary_struct_to_a, 0);
875
+ rb_define_method(cT, "to_a", cumo_na_struct_to_a, 0);
876
876
 
877
- rb_define_method(cT, "store", nary_struct_store, 1);
877
+ rb_define_method(cT, "store", cumo_na_struct_store, 1);
878
878
 
879
- rb_define_method(cT, "inspect", nary_struct_inspect, 0);
879
+ rb_define_method(cT, "inspect", cumo_na_struct_inspect, 0);
880
880
 
881
- rb_define_singleton_method(cT, "cast", nary_struct_s_cast, 1);
882
- rb_define_singleton_method(cT, "[]", nary_struct_s_cast, -2);
881
+ rb_define_singleton_method(cT, "cast", cumo_na_struct_s_cast, 1);
882
+ rb_define_singleton_method(cT, "[]", cumo_na_struct_s_cast, -2);
883
883
 
884
884
  //rb_define_method(cT, "initialize", rb_struct_initialize, -2);
885
885
  //rb_define_method(cT, "initialize_copy", rb_struct_init_copy, 1);