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
@@ -19,17 +19,17 @@ extern double exp10(double);
19
19
 
20
20
  #include "complex.h"
21
21
 
22
- static inline dtype c_from_scomplex(scomplex x) {
22
+ static inline dtype c_from_scomplex(cumo_scomplex x) {
23
23
  dtype z;
24
- REAL(z) = REAL(x);
25
- IMAG(z) = IMAG(x);
24
+ CUMO_REAL(z) = CUMO_REAL(x);
25
+ CUMO_IMAG(z) = CUMO_IMAG(x);
26
26
  return z;
27
27
  }
28
28
 
29
- static inline dtype c_from_dcomplex(dcomplex x) {
29
+ static inline dtype c_from_dcomplex(cumo_dcomplex x) {
30
30
  dtype z;
31
- REAL(z) = REAL(x);
32
- IMAG(z) = IMAG(x);
31
+ CUMO_REAL(z) = CUMO_REAL(x);
32
+ CUMO_IMAG(z) = CUMO_IMAG(x);
33
33
  return z;
34
34
  }
35
35
 
@@ -53,8 +53,8 @@ static inline dtype c_from_dcomplex(dcomplex x) {
53
53
 
54
54
  #define m_extract(x) COMP2NUM(*(dtype*)x)
55
55
 
56
- #define m_real(x) REAL(x)
57
- #define m_imag(x) IMAG(x)
56
+ #define m_real(x) CUMO_REAL(x)
57
+ #define m_imag(x) CUMO_IMAG(x)
58
58
  #define m_set_real(x,y) c_set_real(x,y)
59
59
  #define m_set_imag(x,y) c_set_imag(x,y)
60
60
 
@@ -70,19 +70,19 @@ static inline dtype c_from_dcomplex(dcomplex x) {
70
70
  #define m_minus(x) c_minus(x)
71
71
  #define m_reciprocal(x) c_reciprocal(x)
72
72
  #define m_square(x) c_square(x)
73
- #define m_floor(x) c_new(floor(REAL(x)),floor(IMAG(x)))
74
- #define m_round(x) c_new(round(REAL(x)),round(IMAG(x)))
75
- #define m_ceil(x) c_new(ceil(REAL(x)),ceil(IMAG(x)))
76
- #define m_trunc(x) c_new(trunc(REAL(x)),trunc(IMAG(x)))
77
- #define m_rint(x) c_new(rint(REAL(x)),rint(IMAG(x)))
73
+ #define m_floor(x) c_new(floor(CUMO_REAL(x)),floor(CUMO_IMAG(x)))
74
+ #define m_round(x) c_new(round(CUMO_REAL(x)),round(CUMO_IMAG(x)))
75
+ #define m_ceil(x) c_new(ceil(CUMO_REAL(x)),ceil(CUMO_IMAG(x)))
76
+ #define m_trunc(x) c_new(trunc(CUMO_REAL(x)),trunc(CUMO_IMAG(x)))
77
+ #define m_rint(x) c_new(rint(CUMO_REAL(x)),rint(CUMO_IMAG(x)))
78
78
  #define m_sign(x) c_new( \
79
- ((REAL(x)==0) ? 0.0:((REAL(x)>0) ? 1.0:((REAL(x)<0) ? -1.0:REAL(x)))), \
80
- ((IMAG(x)==0) ? 0.0:((IMAG(x)>0) ? 1.0:((IMAG(x)<0) ? -1.0:IMAG(x)))))
81
- #define m_copysign(x,y) c_new(copysign(REAL(x),REAL(y)),copysign(IMAG(x),IMAG(y)))
79
+ ((CUMO_REAL(x)==0) ? 0.0:((CUMO_REAL(x)>0) ? 1.0:((CUMO_REAL(x)<0) ? -1.0:CUMO_REAL(x)))), \
80
+ ((CUMO_IMAG(x)==0) ? 0.0:((CUMO_IMAG(x)>0) ? 1.0:((CUMO_IMAG(x)<0) ? -1.0:CUMO_IMAG(x)))))
81
+ #define m_copysign(x,y) c_new(copysign(CUMO_REAL(x),CUMO_REAL(y)),copysign(CUMO_IMAG(x),CUMO_IMAG(y)))
82
82
 
83
83
  #define m_im(x) c_im(x)
84
- #define m_conj(x) c_new(REAL(x),-IMAG(x))
85
- #define m_arg(x) atan2(IMAG(x),REAL(x))
84
+ #define m_conj(x) c_new(CUMO_REAL(x),-CUMO_IMAG(x))
85
+ #define m_arg(x) atan2(CUMO_IMAG(x),CUMO_REAL(x))
86
86
 
87
87
  #define m_eq(x,y) c_eq(x,y)
88
88
  #define m_ne(x,y) c_ne(x,y)
@@ -94,7 +94,7 @@ static inline dtype c_from_dcomplex(dcomplex x) {
94
94
  #define m_isneginf(x) c_isneginf(x)
95
95
  #define m_isfinite(x) c_isfinite(x)
96
96
 
97
- #define m_sprintf(s,x) sprintf(s,"%g%+gi",REAL(x),IMAG(x))
97
+ #define m_sprintf(s,x) sprintf(s,"%g%+gi",CUMO_REAL(x),CUMO_IMAG(x))
98
98
 
99
99
  #define m_sqrt(x) c_sqrt(x)
100
100
  #define m_cbrt(x) c_cbrt(x)
@@ -122,7 +122,7 @@ static inline dtype c_from_dcomplex(dcomplex x) {
122
122
  #define m_sum_init INT2FIX(0)
123
123
  #define m_mulsum_init INT2FIX(0)
124
124
 
125
- #define not_nan(x) (REAL(x)==REAL(x) && IMAG(x)==IMAG(x))
125
+ #define not_nan(x) (CUMO_REAL(x)==CUMO_REAL(x) && CUMO_IMAG(x)==CUMO_IMAG(x))
126
126
 
127
127
  #define m_mulsum(x,y,z) {z = m_add(m_mul(x,y),z);}
128
128
  #define m_mulsum_nan(x,y,z) { \
@@ -186,11 +186,11 @@ static inline dtype f_kahan_sum(size_t n, char *p, ssize_t stride)
186
186
  r = c_zero();
187
187
  for (; i--;) {
188
188
  x = *(dtype*)p;
189
- if (fabs(REAL(x)) > fabs(REAL(y))) {
190
- double z=REAL(x); REAL(x)=REAL(y); REAL(y)=z;
189
+ if (fabs(CUMO_REAL(x)) > fabs(CUMO_REAL(y))) {
190
+ double z=CUMO_REAL(x); CUMO_REAL(x)=CUMO_REAL(y); CUMO_REAL(y)=z;
191
191
  }
192
- if (fabs(IMAG(x)) > fabs(IMAG(y))) {
193
- double z=IMAG(x); IMAG(x)=IMAG(y); IMAG(y)=z;
192
+ if (fabs(CUMO_IMAG(x)) > fabs(CUMO_IMAG(y))) {
193
+ double z=CUMO_IMAG(x); CUMO_IMAG(x)=CUMO_IMAG(y); CUMO_IMAG(y)=z;
194
194
  }
195
195
  r = c_add(x, r);
196
196
  t = y;
@@ -213,11 +213,11 @@ static inline dtype f_kahan_sum_nan(size_t n, char *p, ssize_t stride)
213
213
  for (; i--;) {
214
214
  x = *(dtype*)p;
215
215
  if (not_nan(x)) {
216
- if (fabs(REAL(x)) > fabs(REAL(y))) {
217
- double z=REAL(x); REAL(x)=REAL(y); REAL(y)=z;
216
+ if (fabs(CUMO_REAL(x)) > fabs(CUMO_REAL(y))) {
217
+ double z=CUMO_REAL(x); CUMO_REAL(x)=CUMO_REAL(y); CUMO_REAL(y)=z;
218
218
  }
219
- if (fabs(IMAG(x)) > fabs(IMAG(y))) {
220
- double z=IMAG(x); IMAG(x)=IMAG(y); IMAG(y)=z;
219
+ if (fabs(CUMO_IMAG(x)) > fabs(CUMO_IMAG(y))) {
220
+ double z=CUMO_IMAG(x); CUMO_IMAG(x)=CUMO_IMAG(y); CUMO_IMAG(y)=z;
221
221
  }
222
222
  r = c_add(x, r);
223
223
  t = y;
@@ -22,17 +22,17 @@ extern double exp10(double);
22
22
 
23
23
  #include "complex_kernel.h"
24
24
 
25
- __host__ __device__ static inline dtype c_from_scomplex(scomplex x) {
25
+ __host__ __device__ static inline dtype c_from_scomplex(cumo_scomplex x) {
26
26
  dtype z;
27
- REAL(z) = REAL(x);
28
- IMAG(z) = IMAG(x);
27
+ CUMO_REAL(z) = CUMO_REAL(x);
28
+ CUMO_IMAG(z) = CUMO_IMAG(x);
29
29
  return z;
30
30
  }
31
31
 
32
- __host__ __device__ static inline dtype c_from_dcomplex(dcomplex x) {
32
+ __host__ __device__ static inline dtype c_from_dcomplex(cumo_dcomplex x) {
33
33
  dtype z;
34
- REAL(z) = REAL(x);
35
- IMAG(z) = IMAG(x);
34
+ CUMO_REAL(z) = CUMO_REAL(x);
35
+ CUMO_IMAG(z) = CUMO_IMAG(x);
36
36
  return z;
37
37
  }
38
38
 
@@ -56,8 +56,8 @@ __host__ __device__ static inline dtype c_from_dcomplex(dcomplex x) {
56
56
 
57
57
  //#define m_extract(x) COMP2NUM(*(dtype*)x)
58
58
 
59
- #define m_real(x) REAL(x)
60
- #define m_imag(x) IMAG(x)
59
+ #define m_real(x) CUMO_REAL(x)
60
+ #define m_imag(x) CUMO_IMAG(x)
61
61
  #define m_set_real(x,y) c_set_real(x,y)
62
62
  #define m_set_imag(x,y) c_set_imag(x,y)
63
63
 
@@ -73,19 +73,19 @@ __host__ __device__ static inline dtype c_from_dcomplex(dcomplex x) {
73
73
  #define m_minus(x) c_minus(x)
74
74
  #define m_reciprocal(x) c_reciprocal(x)
75
75
  #define m_square(x) c_square(x)
76
- #define m_floor(x) c_new(floor(REAL(x)),floor(IMAG(x)))
77
- #define m_round(x) c_new(round(REAL(x)),round(IMAG(x)))
78
- #define m_ceil(x) c_new(ceil(REAL(x)),ceil(IMAG(x)))
79
- #define m_trunc(x) c_new(trunc(REAL(x)),trunc(IMAG(x)))
80
- #define m_rint(x) c_new(rint(REAL(x)),rint(IMAG(x)))
76
+ #define m_floor(x) c_new(floor(CUMO_REAL(x)),floor(CUMO_IMAG(x)))
77
+ #define m_round(x) c_new(round(CUMO_REAL(x)),round(CUMO_IMAG(x)))
78
+ #define m_ceil(x) c_new(ceil(CUMO_REAL(x)),ceil(CUMO_IMAG(x)))
79
+ #define m_trunc(x) c_new(trunc(CUMO_REAL(x)),trunc(CUMO_IMAG(x)))
80
+ #define m_rint(x) c_new(rint(CUMO_REAL(x)),rint(CUMO_IMAG(x)))
81
81
  #define m_sign(x) c_new( \
82
- ((REAL(x)==0) ? 0.0:((REAL(x)>0) ? 1.0:((REAL(x)<0) ? -1.0:REAL(x)))), \
83
- ((IMAG(x)==0) ? 0.0:((IMAG(x)>0) ? 1.0:((IMAG(x)<0) ? -1.0:IMAG(x)))))
84
- #define m_copysign(x,y) c_new(copysign(REAL(x),REAL(y)),copysign(IMAG(x),IMAG(y)))
82
+ ((CUMO_REAL(x)==0) ? 0.0:((CUMO_REAL(x)>0) ? 1.0:((CUMO_REAL(x)<0) ? -1.0:CUMO_REAL(x)))), \
83
+ ((CUMO_IMAG(x)==0) ? 0.0:((CUMO_IMAG(x)>0) ? 1.0:((CUMO_IMAG(x)<0) ? -1.0:CUMO_IMAG(x)))))
84
+ #define m_copysign(x,y) c_new(copysign(CUMO_REAL(x),CUMO_REAL(y)),copysign(CUMO_IMAG(x),CUMO_IMAG(y)))
85
85
 
86
86
  #define m_im(x) c_im(x)
87
- #define m_conj(x) c_new(REAL(x),-IMAG(x))
88
- #define m_arg(x) atan2(IMAG(x),REAL(x))
87
+ #define m_conj(x) c_new(CUMO_REAL(x),-CUMO_IMAG(x))
88
+ #define m_arg(x) atan2(CUMO_IMAG(x),CUMO_REAL(x))
89
89
 
90
90
  #define m_eq(x,y) c_eq(x,y)
91
91
  #define m_ne(x,y) c_ne(x,y)
@@ -97,7 +97,7 @@ __host__ __device__ static inline dtype c_from_dcomplex(dcomplex x) {
97
97
  #define m_isneginf(x) c_isneginf(x)
98
98
  #define m_isfinite(x) c_isfinite(x)
99
99
 
100
- #define m_sprintf(s,x) sprintf(s,"%g%+gi",REAL(x),IMAG(x))
100
+ #define m_sprintf(s,x) sprintf(s,"%g%+gi",CUMO_REAL(x),CUMO_IMAG(x))
101
101
 
102
102
  #define m_sqrt(x) c_sqrt(x)
103
103
  #define m_cbrt(x) c_cbrt(x)
@@ -125,7 +125,7 @@ __host__ __device__ static inline dtype c_from_dcomplex(dcomplex x) {
125
125
  #define m_sum_init 0
126
126
  #define m_mulsum_init 0
127
127
 
128
- #define not_nan(x) (REAL(x)==REAL(x) && IMAG(x)==IMAG(x))
128
+ #define not_nan(x) (CUMO_REAL(x)==CUMO_REAL(x) && CUMO_IMAG(x)==CUMO_IMAG(x))
129
129
 
130
130
  #define m_mulsum(x,y,z) {z = m_add(m_mul(x,y),z);}
131
131
  #define m_mulsum_nan(x,y,z) { \
@@ -1,4 +1,4 @@
1
- typedef dcomplex dtype;
1
+ typedef cumo_dcomplex dtype;
2
2
  typedef double rtype;
3
3
  #define cT cumo_cDComplex
4
4
  #define cRT cumo_cDFloat
@@ -17,8 +17,8 @@ static inline bool c_nearly_eq(dtype x, dtype y) {
17
17
  inline static dtype m_rand(dtype max)
18
18
  {
19
19
  dtype z;
20
- REAL(z) = genrand_res53_mix() * REAL(max);
21
- IMAG(z) = genrand_res53_mix() * IMAG(max);
20
+ CUMO_REAL(z) = genrand_res53_mix() * CUMO_REAL(max);
21
+ CUMO_IMAG(z) = genrand_res53_mix() * CUMO_IMAG(max);
22
22
  return z;
23
23
  }
24
24
 
@@ -36,8 +36,8 @@ inline static void m_rand_norm(dtype mu, rtype sigma, dtype *a0)
36
36
  w = x1 * x1 + x2 * x2;
37
37
  } while (w>=1);
38
38
  w = sqrt( (-2*log(w)) / w );
39
- REAL(*a0) = x1*w * sigma + REAL(mu);
40
- IMAG(*a0) = x2*w * sigma + IMAG(mu);
39
+ CUMO_REAL(*a0) = x1*w * sigma + CUMO_REAL(mu);
40
+ CUMO_IMAG(*a0) = x2*w * sigma + CUMO_IMAG(mu);
41
41
  }
42
42
  #endif
43
43
 
@@ -1,7 +1,7 @@
1
1
  #ifndef CUMO_DCOMPLEX_KERNEL_H
2
2
  #define CUMO_DCOMPLEX_KERNEL_H
3
3
 
4
- typedef dcomplex dtype;
4
+ typedef cumo_dcomplex dtype;
5
5
  typedef double rtype;
6
6
 
7
7
  #include "complex_macro_kernel.h"
@@ -4,7 +4,7 @@
4
4
 
5
5
  static inline dtype m_abs(dtype x) {
6
6
  if (x==DATA_MIN) {
7
- rb_raise(nary_eValueError, "cannot convert the minimum integer");
7
+ rb_raise(cumo_na_eValueError, "cannot convert the minimum integer");
8
8
  }
9
9
  return (x<0)?-x:x;
10
10
  }
@@ -8,7 +8,7 @@
8
8
  __host__ __device__ static inline dtype m_abs(dtype x) {
9
9
  // TODO(sonots): How to handle in CUDA kernel?
10
10
  // if (x==DATA_MIN) {
11
- // rb_raise(nary_eValueError, "cannot convert the minimum integer");
11
+ // rb_raise(cumo_na_eValueError, "cannot convert the minimum integer");
12
12
  // }
13
13
  return (x<0)?-x:x;
14
14
  }
@@ -18,45 +18,45 @@
18
18
  #define m_div(x,y) rb_funcall(x,'/',1,y)
19
19
  #define m_mod(x,y) rb_funcall(x,'%',1,y)
20
20
  #define m_divmod(x,y,a,b) \
21
- {x = rb_funcall(x,id_divmod,1,y); \
21
+ {x = rb_funcall(x,cumo_id_divmod,1,y); \
22
22
  a = RARRAY_PTR(x)[0]; b = RARRAY_PTR(x)[0];}
23
- #define m_pow(x,y) rb_funcall(x,id_pow,1,y)
24
- #define m_pow_int(x,y) rb_funcall(x,id_pow,1,y)
23
+ #define m_pow(x,y) rb_funcall(x,cumo_id_pow,1,y)
24
+ #define m_pow_int(x,y) rb_funcall(x,cumo_id_pow,1,y)
25
25
 
26
- #define m_abs(x) rb_funcall(x,id_abs,0)
27
- #define m_minus(x) rb_funcall(x,id_minus,0)
28
- #define m_reciprocal(x) rb_funcall(x,id_reciprocal,0)
26
+ #define m_abs(x) rb_funcall(x,cumo_id_abs,0)
27
+ #define m_minus(x) rb_funcall(x,cumo_id_minus,0)
28
+ #define m_reciprocal(x) rb_funcall(x,cumo_id_reciprocal,0)
29
29
  #define m_square(x) rb_funcall(x,'*',1,x)
30
- #define m_floor(x) rb_funcall(x,id_floor,0)
31
- #define m_round(x) rb_funcall(x,id_round,0)
32
- #define m_ceil(x) rb_funcall(x,id_ceil,0)
33
- #define m_trunc(x) rb_funcall(x,id_truncate,0)
34
- #define m_sign(x) rb_funcall(x,id_ufo,1,INT2FIX(0))
30
+ #define m_floor(x) rb_funcall(x,cumo_id_floor,0)
31
+ #define m_round(x) rb_funcall(x,cumo_id_round,0)
32
+ #define m_ceil(x) rb_funcall(x,cumo_id_ceil,0)
33
+ #define m_trunc(x) rb_funcall(x,cumo_id_truncate,0)
34
+ #define m_sign(x) rb_funcall(x,cumo_id_ufo,1,INT2FIX(0))
35
35
 
36
- #define m_eq(x,y) RTEST(rb_funcall(x,id_eq,1,y))
37
- #define m_ne(x,y) RTEST(rb_funcall(x,id_ne,1,y))
38
- #define m_gt(x,y) RTEST(rb_funcall(x,id_gt,1,y))
39
- #define m_ge(x,y) RTEST(rb_funcall(x,id_ge,1,y))
40
- #define m_lt(x,y) RTEST(rb_funcall(x,id_lt,1,y))
41
- #define m_le(x,y) RTEST(rb_funcall(x,id_le,1,y))
36
+ #define m_eq(x,y) RTEST(rb_funcall(x,cumo_id_eq,1,y))
37
+ #define m_ne(x,y) RTEST(rb_funcall(x,cumo_id_ne,1,y))
38
+ #define m_gt(x,y) RTEST(rb_funcall(x,cumo_id_gt,1,y))
39
+ #define m_ge(x,y) RTEST(rb_funcall(x,cumo_id_ge,1,y))
40
+ #define m_lt(x,y) RTEST(rb_funcall(x,cumo_id_lt,1,y))
41
+ #define m_le(x,y) RTEST(rb_funcall(x,cumo_id_le,1,y))
42
42
 
43
- #define m_bit_and(x,y) rb_funcall(x,id_bit_and,1,y)
44
- #define m_bit_or(x,y) rb_funcall(x,id_bit_or, 1,y)
45
- #define m_bit_xor(x,y) rb_funcall(x,id_bit_xor,1,y)
46
- #define m_bit_not(x) rb_funcall(x,id_bit_not,0)
43
+ #define m_bit_and(x,y) rb_funcall(x,cumo_id_bit_and,1,y)
44
+ #define m_bit_or(x,y) rb_funcall(x,cumo_id_bit_or, 1,y)
45
+ #define m_bit_xor(x,y) rb_funcall(x,cumo_id_bit_xor,1,y)
46
+ #define m_bit_not(x) rb_funcall(x,cumo_id_bit_not,0)
47
47
 
48
- #define m_left_shift(x,y) rb_funcall(x,id_left_shift,1,y)
49
- #define m_right_shift(x,y) rb_funcall(x,id_right_shift,1,y)
48
+ #define m_left_shift(x,y) rb_funcall(x,cumo_id_left_shift,1,y)
49
+ #define m_right_shift(x,y) rb_funcall(x,cumo_id_right_shift,1,y)
50
50
 
51
- #define m_isnan(x) ((rb_respond_to(x,id_nan_p)) ? RTEST(rb_funcall(x,id_nan_p,0)) : 0)
52
- #define m_isinf(x) ((rb_respond_to(x,id_infinite_p)) ? RTEST(rb_funcall(x,id_infinite_p,0)) : 0)
53
- #define m_isposinf(x) ((rb_respond_to(x,id_infinite_p)) ? \
54
- ((RTEST(rb_funcall(x,id_infinite_p,0))) ? \
51
+ #define m_isnan(x) ((rb_respond_to(x,cumo_id_nan_p)) ? RTEST(rb_funcall(x,cumo_id_nan_p,0)) : 0)
52
+ #define m_isinf(x) ((rb_respond_to(x,cumo_id_infinite_p)) ? RTEST(rb_funcall(x,cumo_id_infinite_p,0)) : 0)
53
+ #define m_isposinf(x) ((rb_respond_to(x,cumo_id_infinite_p)) ? \
54
+ ((RTEST(rb_funcall(x,cumo_id_infinite_p,0))) ? \
55
55
  m_gt(x,INT2FIX(0)) : 0) : 0)
56
- #define m_isneginf(x) ((rb_respond_to(x,id_infinite_p)) ? \
57
- ((RTEST(rb_funcall(x,id_infinite_p,0))) ? \
56
+ #define m_isneginf(x) ((rb_respond_to(x,cumo_id_infinite_p)) ? \
57
+ ((RTEST(rb_funcall(x,cumo_id_infinite_p,0))) ? \
58
58
  m_lt(x,INT2FIX(0)) : 0) : 0)
59
- #define m_isfinite(x) ((rb_respond_to(x,id_finite_p)) ? RTEST(rb_funcall(x,id_finite_p,0)) : 0)
59
+ #define m_isfinite(x) ((rb_respond_to(x,cumo_id_finite_p)) ? RTEST(rb_funcall(x,cumo_id_finite_p,0)) : 0)
60
60
 
61
61
  #define m_mulsum_init INT2FIX(0)
62
62
 
@@ -1,4 +1,4 @@
1
- typedef scomplex dtype;
1
+ typedef cumo_scomplex dtype;
2
2
  typedef float rtype;
3
3
  #define cT cumo_cSComplex
4
4
  #define cRT cumo_cSFloat
@@ -17,8 +17,8 @@ static inline bool c_nearly_eq(dtype x, dtype y) {
17
17
  inline static dtype m_rand(dtype max)
18
18
  {
19
19
  dtype z;
20
- REAL(z) = to_real2(gen_rand32()) * REAL(max);
21
- IMAG(z) = to_real2(gen_rand32()) * IMAG(max);
20
+ CUMO_REAL(z) = to_real2(gen_rand32()) * CUMO_REAL(max);
21
+ CUMO_IMAG(z) = to_real2(gen_rand32()) * CUMO_IMAG(max);
22
22
  return z;
23
23
  }
24
24
 
@@ -36,8 +36,8 @@ inline static void m_rand_norm(dtype mu, rtype sigma, dtype *a0)
36
36
  w = x1 * x1 + x2 * x2;
37
37
  } while (w>=1);
38
38
  w = sqrt( (-2*log(w)) / w );
39
- REAL(*a0) = x1*w * sigma + REAL(mu);
40
- IMAG(*a0) = x2*w * sigma + IMAG(mu);
39
+ CUMO_REAL(*a0) = x1*w * sigma + CUMO_REAL(mu);
40
+ CUMO_IMAG(*a0) = x2*w * sigma + CUMO_IMAG(mu);
41
41
  }
42
42
  #endif
43
43
 
@@ -1,7 +1,7 @@
1
1
  #ifndef CUMO_SCOMPLEX_KERNEL_H
2
2
  #define CUMO_SCOMPLEX_KERNEL_H
3
3
 
4
- typedef scomplex dtype;
4
+ typedef cumo_scomplex dtype;
5
5
  typedef float rtype;
6
6
 
7
7
  #include "complex_macro_kernel.h"
@@ -5,31 +5,31 @@
5
5
  typedef struct {
6
6
  size_t shape;
7
7
  VALUE val;
8
- } na_mdai_item_t;
8
+ } cumo_na_mdai_item_t;
9
9
 
10
10
  typedef struct {
11
11
  int capa;
12
- na_mdai_item_t *item;
12
+ cumo_na_mdai_item_t *item;
13
13
  int type; // Ruby numeric type - investigated separately
14
14
  VALUE na_type; // NArray type
15
15
  VALUE int_max;
16
- } na_mdai_t;
16
+ } cumo_na_mdai_t;
17
17
 
18
18
  // Order of Ruby object.
19
- enum { NA_NONE, NA_BIT, NA_INT32, NA_INT64, NA_RATIONAL,
20
- NA_DFLOAT, NA_DCOMPLEX, NA_ROBJ, NA_NTYPES };
19
+ enum { CUMO_NA_NONE, CUMO_NA_BIT, CUMO_NA_INT32, CUMO_NA_INT64, CUMO_NA_RATIONAL,
20
+ CUMO_NA_DFLOAT, CUMO_NA_DCOMPLEX, CUMO_NA_ROBJ, CUMO_NA_NTYPES };
21
21
 
22
- static ID id_begin;
23
- static ID id_end;
24
- static ID id_step;
25
- static ID id_abs;
26
- static ID id_cast;
27
- static ID id_le;
28
- static ID id_Complex;
22
+ static ID cumo_id_begin;
23
+ static ID cumo_id_end;
24
+ static ID cumo_id_step;
25
+ static ID cumo_id_abs;
26
+ static ID cumo_id_cast;
27
+ static ID cumo_id_le;
28
+ static ID cumo_id_Complex;
29
29
 
30
30
 
31
31
  static VALUE
32
- na_object_type(int type, VALUE v)
32
+ cumo_na_object_type(int type, VALUE v)
33
33
  {
34
34
  static VALUE int32_max = Qnil;
35
35
  if (NIL_P(int32_max))
@@ -39,124 +39,124 @@ static VALUE
39
39
 
40
40
  case T_TRUE:
41
41
  case T_FALSE:
42
- if (type<NA_BIT)
43
- return NA_BIT;
42
+ if (type<CUMO_NA_BIT)
43
+ return CUMO_NA_BIT;
44
44
  return type;
45
45
 
46
46
  #if SIZEOF_LONG == 4
47
47
  case T_FIXNUM:
48
- if (type<NA_INT32)
49
- return NA_INT32;
48
+ if (type<CUMO_NA_INT32)
49
+ return CUMO_NA_INT32;
50
50
  return type;
51
51
  case T_BIGNUM:
52
- if (type<NA_INT64) {
53
- v = rb_funcall(v,id_abs,0);
54
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
55
- if (type<NA_INT32)
56
- return NA_INT32;
52
+ if (type<CUMO_NA_INT64) {
53
+ v = rb_funcall(v,cumo_id_abs,0);
54
+ if (RTEST(rb_funcall(v,cumo_id_le,1,int32_max))) {
55
+ if (type<CUMO_NA_INT32)
56
+ return CUMO_NA_INT32;
57
57
  } else {
58
- return NA_INT64;
58
+ return CUMO_NA_INT64;
59
59
  }
60
60
  }
61
61
  return type;
62
62
 
63
63
  #elif SIZEOF_LONG == 8
64
64
  case T_FIXNUM:
65
- if (type<NA_INT64) {
65
+ if (type<CUMO_NA_INT64) {
66
66
  long x = NUM2LONG(v);
67
67
  if (x<0) x=-x;
68
68
  if (x<=2147483647) {
69
- if (type<NA_INT32)
70
- return NA_INT32;
69
+ if (type<CUMO_NA_INT32)
70
+ return CUMO_NA_INT32;
71
71
  } else {
72
- return NA_INT64;
72
+ return CUMO_NA_INT64;
73
73
  }
74
74
  }
75
75
  return type;
76
76
  case T_BIGNUM:
77
- if (type<NA_INT64)
78
- return NA_INT64;
77
+ if (type<CUMO_NA_INT64)
78
+ return CUMO_NA_INT64;
79
79
  return type;
80
80
  #else
81
81
  case T_FIXNUM:
82
82
  case T_BIGNUM:
83
- if (type<NA_INT64) {
84
- v = rb_funcall(v,id_abs,0);
85
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
86
- if (type<NA_INT32)
87
- return NA_INT32;
83
+ if (type<CUMO_NA_INT64) {
84
+ v = rb_funcall(v,cumo_id_abs,0);
85
+ if (RTEST(rb_funcall(v,cumo_id_le,1,int32_max))) {
86
+ if (type<CUMO_NA_INT32)
87
+ return CUMO_NA_INT32;
88
88
  } else {
89
- return NA_INT64;
89
+ return CUMO_NA_INT64;
90
90
  }
91
91
  }
92
92
  return type;
93
93
  #endif
94
94
 
95
95
  case T_FLOAT:
96
- if (type<NA_DFLOAT)
97
- return NA_DFLOAT;
96
+ if (type<CUMO_NA_DFLOAT)
97
+ return CUMO_NA_DFLOAT;
98
98
  return type;
99
99
 
100
100
  case T_NIL:
101
101
  return type;
102
102
 
103
103
  default:
104
- if (CLASS_OF(v) == rb_const_get( rb_cObject, id_Complex )) {
105
- return NA_DCOMPLEX;
104
+ if (rb_obj_class(v) == rb_const_get( rb_cObject, cumo_id_Complex )) {
105
+ return CUMO_NA_DCOMPLEX;
106
106
  }
107
107
  }
108
- return NA_ROBJ;
108
+ return CUMO_NA_ROBJ;
109
109
  }
110
110
 
111
111
 
112
112
  #define MDAI_ATTR_TYPE(tp,v,attr) \
113
- {tp = na_object_type(tp,rb_funcall(v,id_##attr,0));}
113
+ {tp = cumo_na_object_type(tp,rb_funcall(v,cumo_id_##attr,0));}
114
114
 
115
- static int na_mdai_object_type(int type, VALUE v)
115
+ static int cumo_na_mdai_object_type(int type, VALUE v)
116
116
  {
117
117
  if (rb_obj_is_kind_of(v, rb_cRange)) {
118
118
  MDAI_ATTR_TYPE(type,v,begin);
119
119
  MDAI_ATTR_TYPE(type,v,end);
120
- } else if (rb_obj_is_kind_of(v, na_cStep)) {
120
+ } else if (rb_obj_is_kind_of(v, cumo_na_cStep)) {
121
121
  MDAI_ATTR_TYPE(type,v,begin);
122
122
  MDAI_ATTR_TYPE(type,v,end);
123
123
  MDAI_ATTR_TYPE(type,v,step);
124
124
  } else {
125
- type = na_object_type(type,v);
125
+ type = cumo_na_object_type(type,v);
126
126
  }
127
127
  return type;
128
128
  }
129
129
 
130
130
 
131
- static na_mdai_t *
132
- na_mdai_alloc(VALUE ary)
131
+ static cumo_na_mdai_t *
132
+ cumo_na_mdai_alloc(VALUE ary)
133
133
  {
134
134
  int i, n=4;
135
- na_mdai_t *mdai;
135
+ cumo_na_mdai_t *mdai;
136
136
 
137
- mdai = ALLOC(na_mdai_t);
137
+ mdai = ALLOC(cumo_na_mdai_t);
138
138
  mdai->capa = n;
139
- mdai->item = ALLOC_N( na_mdai_item_t, n );
139
+ mdai->item = ALLOC_N( cumo_na_mdai_item_t, n );
140
140
  for (i=0; i<n; i++) {
141
141
  mdai->item[i].shape = 0;
142
142
  mdai->item[i].val = Qnil;
143
143
  }
144
144
  mdai->item[0].val = ary;
145
- mdai->type = NA_NONE;
145
+ mdai->type = CUMO_NA_NONE;
146
146
  mdai->na_type = Qnil;
147
147
 
148
148
  return mdai;
149
149
  }
150
150
 
151
151
  static void
152
- na_mdai_realloc(na_mdai_t *mdai, int n_extra)
152
+ cumo_na_mdai_realloc(cumo_na_mdai_t *mdai, int n_extra)
153
153
  {
154
154
  int i, n;
155
155
 
156
156
  i = mdai->capa;
157
157
  mdai->capa += n_extra;
158
158
  n = mdai->capa;
159
- REALLOC_N( mdai->item, na_mdai_item_t, n );
159
+ REALLOC_N( mdai->item, cumo_na_mdai_item_t, n );
160
160
  for (; i<n; i++) {
161
161
  mdai->item[i].shape = 0;
162
162
  mdai->item[i].val = Qnil;
@@ -164,9 +164,9 @@ na_mdai_realloc(na_mdai_t *mdai, int n_extra)
164
164
  }
165
165
 
166
166
  static void
167
- na_mdai_free(void *ptr)
167
+ cumo_na_mdai_free(void *ptr)
168
168
  {
169
- na_mdai_t *mdai = (na_mdai_t*)ptr;
169
+ cumo_na_mdai_t *mdai = (cumo_na_mdai_t*)ptr;
170
170
  xfree(mdai->item);
171
171
  xfree(mdai);
172
172
  }
@@ -174,7 +174,7 @@ na_mdai_free(void *ptr)
174
174
 
175
175
  /* investigate ndim, shape, type of Array */
176
176
  static int
177
- na_mdai_investigate(na_mdai_t *mdai, int ndim)
177
+ cumo_na_mdai_investigate(cumo_na_mdai_t *mdai, int ndim)
178
178
  {
179
179
  ssize_t i;
180
180
  int j;
@@ -197,28 +197,28 @@ na_mdai_investigate(na_mdai_t *mdai, int ndim)
197
197
  "cannot convert from a recursive Array to NArray");
198
198
  }
199
199
  if ( ndim >= mdai->capa ) {
200
- na_mdai_realloc(mdai,4);
200
+ cumo_na_mdai_realloc(mdai,4);
201
201
  }
202
202
  mdai->item[ndim].val = v;
203
- if ( na_mdai_investigate(mdai,ndim+1) ) {
203
+ if ( cumo_na_mdai_investigate(mdai,ndim+1) ) {
204
204
  len--; /* Array is empty */
205
205
  }
206
206
  }
207
207
  else
208
- if (rb_obj_is_kind_of(v, rb_cRange) || rb_obj_is_kind_of(v, na_cStep)) {
209
- nary_step_sequence(v,&length,&dbeg,&dstep);
208
+ if (rb_obj_is_kind_of(v, rb_cRange) || rb_obj_is_kind_of(v, cumo_na_cStep)) {
209
+ cumo_na_step_sequence(v,&length,&dbeg,&dstep);
210
210
  len += length-1;
211
- mdai->type = na_mdai_object_type(mdai->type, v);
211
+ mdai->type = cumo_na_mdai_object_type(mdai->type, v);
212
212
  }
213
- else if (IsNArray(v)) {
213
+ else if (CumoIsNArray(v)) {
214
214
  int r;
215
- narray_t *na;
216
- GetNArray(v,na);
215
+ cumo_narray_t *na;
216
+ CumoGetNArray(v,na);
217
217
  if ( na->ndim == 0 ) {
218
218
  len--; /* NArray is empty */
219
219
  } else {
220
220
  if ( ndim+na->ndim > mdai->capa ) {
221
- na_mdai_realloc(mdai,((na->ndim-1)/4+1)*4);
221
+ cumo_na_mdai_realloc(mdai,((na->ndim-1)/4+1)*4);
222
222
  }
223
223
  for ( j=0,r=ndim; j < na->ndim ; j++,r++ ) {
224
224
  if ( mdai->item[r].shape < na->shape[j] )
@@ -227,12 +227,12 @@ na_mdai_investigate(na_mdai_t *mdai, int ndim)
227
227
  }
228
228
  // type
229
229
  if (NIL_P(mdai->na_type)) {
230
- mdai->na_type = CLASS_OF(v);
230
+ mdai->na_type = rb_obj_class(v);
231
231
  } else {
232
- mdai->na_type = na_upcast(CLASS_OF(v), mdai->na_type);
232
+ mdai->na_type = cumo_na_upcast(rb_obj_class(v), mdai->na_type);
233
233
  }
234
234
  } else {
235
- mdai->type = na_mdai_object_type(mdai->type, v);
235
+ mdai->type = cumo_na_mdai_object_type(mdai->type, v);
236
236
  }
237
237
  }
238
238
 
@@ -245,7 +245,7 @@ na_mdai_investigate(na_mdai_t *mdai, int ndim)
245
245
 
246
246
 
247
247
  static inline int
248
- na_mdai_ndim(na_mdai_t *mdai)
248
+ cumo_na_mdai_ndim(cumo_na_mdai_t *mdai)
249
249
  {
250
250
  int i;
251
251
  // Dimension
@@ -254,7 +254,7 @@ na_mdai_ndim(na_mdai_t *mdai)
254
254
  }
255
255
 
256
256
  static inline void
257
- na_mdai_shape(na_mdai_t *mdai, int ndim, size_t *shape)
257
+ cumo_na_mdai_shape(cumo_na_mdai_t *mdai, int ndim, size_t *shape)
258
258
  {
259
259
  int i;
260
260
  for (i=0; i<ndim; i++) {
@@ -263,27 +263,27 @@ na_mdai_shape(na_mdai_t *mdai, int ndim, size_t *shape)
263
263
  }
264
264
 
265
265
  static VALUE
266
- na_mdai_dtype_numeric(int type)
266
+ cumo_na_mdai_dtype_numeric(int type)
267
267
  {
268
268
  VALUE tp;
269
269
  // DataType
270
270
  switch(type) {
271
- case NA_BIT:
271
+ case CUMO_NA_BIT:
272
272
  tp = cumo_cBit;
273
273
  break;
274
- case NA_INT32:
274
+ case CUMO_NA_INT32:
275
275
  tp = cumo_cInt32;
276
276
  break;
277
- case NA_INT64:
277
+ case CUMO_NA_INT64:
278
278
  tp = cumo_cInt64;
279
279
  break;
280
- case NA_DFLOAT:
280
+ case CUMO_NA_DFLOAT:
281
281
  tp = cumo_cDFloat;
282
282
  break;
283
- case NA_DCOMPLEX:
283
+ case CUMO_NA_DCOMPLEX:
284
284
  tp = cumo_cDComplex;
285
285
  break;
286
- case NA_ROBJ:
286
+ case CUMO_NA_ROBJ:
287
287
  tp = cumo_cRObject;
288
288
  break;
289
289
  default:
@@ -293,17 +293,17 @@ na_mdai_dtype_numeric(int type)
293
293
  }
294
294
 
295
295
  static VALUE
296
- na_mdai_dtype(na_mdai_t *mdai)
296
+ cumo_na_mdai_dtype(cumo_na_mdai_t *mdai)
297
297
  {
298
298
  VALUE tp;
299
299
 
300
- tp = na_mdai_dtype_numeric(mdai->type);
300
+ tp = cumo_na_mdai_dtype_numeric(mdai->type);
301
301
 
302
302
  if (!NIL_P(mdai->na_type)) {
303
303
  if (NIL_P(tp)) {
304
304
  tp = mdai->na_type;
305
305
  } else {
306
- tp = na_upcast(mdai->na_type,tp);
306
+ tp = cumo_na_upcast(mdai->na_type,tp);
307
307
  }
308
308
  }
309
309
  return tp;
@@ -327,41 +327,41 @@ static inline void
327
327
  check_subclass_of_narray(VALUE dtype)
328
328
  {
329
329
  if (RTEST(rb_obj_is_kind_of(dtype, rb_cClass))) {
330
- if (RTEST(rb_funcall(dtype, id_le, 1, cNArray))) {
330
+ if (RTEST(rb_funcall(dtype, cumo_id_le, 1, cNArray))) {
331
331
  return;
332
332
  }
333
333
  }
334
- rb_raise(nary_eCastError, "cannot convert to NArray");
334
+ rb_raise(cumo_na_eCastError, "cannot convert to NArray");
335
335
  }
336
336
 
337
337
 
338
338
  static size_t
339
- na_mdai_memsize(const void *ptr)
339
+ cumo_na_mdai_memsize(const void *ptr)
340
340
  {
341
- const na_mdai_t *mdai = (const na_mdai_t*)ptr;
341
+ const cumo_na_mdai_t *mdai = (const cumo_na_mdai_t*)ptr;
342
342
 
343
- return sizeof(na_mdai_t) + mdai->capa * sizeof(na_mdai_item_t);
343
+ return sizeof(cumo_na_mdai_t) + mdai->capa * sizeof(cumo_na_mdai_item_t);
344
344
  }
345
345
 
346
346
  static const rb_data_type_t mdai_data_type = {
347
347
  "Cumo::NArray/mdai",
348
- {NULL, na_mdai_free, na_mdai_memsize,},
348
+ {NULL, cumo_na_mdai_free, cumo_na_mdai_memsize,},
349
349
  0, 0, RUBY_TYPED_FREE_IMMEDIATELY|RUBY_TYPED_WB_PROTECTED
350
350
  };
351
351
 
352
352
 
353
353
  static void
354
- na_composition3_ary(VALUE ary, VALUE *ptype, VALUE *pshape, VALUE *pnary)
354
+ cumo_na_composition3_ary(VALUE ary, VALUE *ptype, VALUE *pshape, VALUE *pnary)
355
355
  {
356
356
  VALUE vmdai;
357
- na_mdai_t *mdai;
357
+ cumo_na_mdai_t *mdai;
358
358
  int i, ndim;
359
359
  size_t *shape;
360
360
  VALUE dtype, dshape;
361
361
 
362
- mdai = na_mdai_alloc(ary);
362
+ mdai = cumo_na_mdai_alloc(ary);
363
363
  vmdai = TypedData_Wrap_Struct(rb_cData, &mdai_data_type, (void*)mdai);
364
- if ( na_mdai_investigate(mdai, 1) ) {
364
+ if ( cumo_na_mdai_investigate(mdai, 1) ) {
365
365
  // empty
366
366
  dtype = update_type(ptype, cumo_cInt32);
367
367
  if (pshape) {
@@ -371,13 +371,13 @@ na_composition3_ary(VALUE ary, VALUE *ptype, VALUE *pshape, VALUE *pnary)
371
371
  check_subclass_of_narray(dtype);
372
372
  shape = ALLOCA_N(size_t, 1);
373
373
  shape[0] = 0;
374
- *pnary = nary_new(dtype, 1, shape);
374
+ *pnary = cumo_na_new(dtype, 1, shape);
375
375
  }
376
376
  } else {
377
- ndim = na_mdai_ndim(mdai);
377
+ ndim = cumo_na_mdai_ndim(mdai);
378
378
  shape = ALLOCA_N(size_t, ndim);
379
- na_mdai_shape(mdai, ndim, shape);
380
- dtype = update_type(ptype, na_mdai_dtype(mdai));
379
+ cumo_na_mdai_shape(mdai, ndim, shape);
380
+ dtype = update_type(ptype, cumo_na_mdai_dtype(mdai));
381
381
  if (pshape) {
382
382
  dshape = rb_ary_new2(ndim);
383
383
  for (i=0; i<ndim; i++) {
@@ -387,7 +387,7 @@ na_composition3_ary(VALUE ary, VALUE *ptype, VALUE *pshape, VALUE *pnary)
387
387
  }
388
388
  if (pnary) {
389
389
  check_subclass_of_narray(dtype);
390
- *pnary = nary_new(dtype, ndim, shape);
390
+ *pnary = cumo_na_new(dtype, ndim, shape);
391
391
  }
392
392
  }
393
393
  RB_GC_GUARD(vmdai);
@@ -395,30 +395,30 @@ na_composition3_ary(VALUE ary, VALUE *ptype, VALUE *pshape, VALUE *pnary)
395
395
 
396
396
 
397
397
  static void
398
- na_composition3(VALUE obj, VALUE *ptype, VALUE *pshape, VALUE *pnary)
398
+ cumo_na_composition3(VALUE obj, VALUE *ptype, VALUE *pshape, VALUE *pnary)
399
399
  {
400
400
  VALUE dtype, dshape;
401
401
 
402
402
  if (TYPE(obj) == T_ARRAY) {
403
- na_composition3_ary(obj, ptype, pshape, pnary);
403
+ cumo_na_composition3_ary(obj, ptype, pshape, pnary);
404
404
  }
405
405
  else if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
406
- dtype = na_mdai_dtype_numeric(na_mdai_object_type(NA_NONE, obj));
406
+ dtype = cumo_na_mdai_dtype_numeric(cumo_na_mdai_object_type(CUMO_NA_NONE, obj));
407
407
  dtype = update_type(ptype, dtype);
408
408
  if (pshape) {
409
409
  *pshape = rb_ary_new();
410
410
  }
411
411
  if (pnary) {
412
412
  check_subclass_of_narray(dtype);
413
- *pnary = nary_new(dtype, 0, 0);
413
+ *pnary = cumo_na_new(dtype, 0, 0);
414
414
  }
415
415
  }
416
- else if (IsNArray(obj)) {
416
+ else if (CumoIsNArray(obj)) {
417
417
  int i, ndim;
418
- narray_t *na;
419
- GetNArray(obj,na);
418
+ cumo_narray_t *na;
419
+ CumoGetNArray(obj,na);
420
420
  ndim = na->ndim;
421
- dtype = update_type(ptype, CLASS_OF(obj));
421
+ dtype = update_type(ptype, rb_obj_class(obj));
422
422
  if (pshape) {
423
423
  dshape = rb_ary_new2(ndim);
424
424
  for (i=0; i<ndim; i++) {
@@ -427,17 +427,17 @@ na_composition3(VALUE obj, VALUE *ptype, VALUE *pshape, VALUE *pnary)
427
427
  *pshape = dshape;
428
428
  }
429
429
  if (pnary) {
430
- *pnary = nary_new(dtype, ndim, na->shape);
430
+ *pnary = cumo_na_new(dtype, ndim, na->shape);
431
431
  }
432
432
  } else {
433
433
  rb_raise(rb_eTypeError,"invalid type for NArray: %s",
434
- rb_class2name(CLASS_OF(obj)));
434
+ rb_class2name(rb_obj_class(obj)));
435
435
  }
436
436
  }
437
437
 
438
438
 
439
439
  static VALUE
440
- na_s_array_shape(VALUE mod, VALUE ary)
440
+ cumo_na_s_array_shape(VALUE mod, VALUE ary)
441
441
  {
442
442
  VALUE shape;
443
443
 
@@ -445,7 +445,7 @@ na_s_array_shape(VALUE mod, VALUE ary)
445
445
  // 0-dimension
446
446
  return rb_ary_new();
447
447
  }
448
- na_composition3(ary, 0, &shape, 0);
448
+ cumo_na_composition3(ary, 0, &shape, 0);
449
449
  return shape;
450
450
  }
451
451
 
@@ -467,28 +467,28 @@ na_s_array_shape(VALUE mod, VALUE ary)
467
467
  => Cumo::DComplex#shape=[3](empty)
468
468
  */
469
469
  VALUE
470
- na_s_new_like(VALUE type, VALUE obj)
470
+ cumo_na_s_new_like(VALUE type, VALUE obj)
471
471
  {
472
472
  VALUE newary;
473
473
 
474
- na_composition3(obj, &type, 0, &newary);
474
+ cumo_na_composition3(obj, &type, 0, &newary);
475
475
  return newary;
476
476
  }
477
477
 
478
478
 
479
479
  VALUE
480
- na_ary_composition_dtype(VALUE ary)
480
+ cumo_na_ary_composition_dtype(VALUE ary)
481
481
  {
482
482
  VALUE type = Qnil;
483
483
 
484
- na_composition3(ary, &type, 0, 0);
484
+ cumo_na_composition3(ary, &type, 0, 0);
485
485
  return type;
486
486
  }
487
487
 
488
488
  static VALUE
489
- na_s_array_type(VALUE mod, VALUE ary)
489
+ cumo_na_s_array_type(VALUE mod, VALUE ary)
490
490
  {
491
- return na_ary_composition_dtype(ary);
491
+ return cumo_na_ary_composition_dtype(ary);
492
492
  }
493
493
 
494
494
 
@@ -499,16 +499,16 @@ na_s_array_type(VALUE mod, VALUE ary)
499
499
  @return [NArray]
500
500
  */
501
501
  static VALUE
502
- nary_s_bracket(VALUE klass, VALUE ary)
502
+ cumo_na_s_bracket(VALUE klass, VALUE ary)
503
503
  {
504
504
  VALUE dtype=Qnil;
505
505
 
506
506
  if (TYPE(ary)!=T_ARRAY) {
507
507
  rb_bug("Argument is not array");
508
508
  }
509
- dtype = na_ary_composition_dtype(ary);
509
+ dtype = cumo_na_ary_composition_dtype(ary);
510
510
  check_subclass_of_narray(dtype);
511
- return rb_funcall(dtype, id_cast, 1, ary);
511
+ return rb_funcall(dtype, cumo_id_cast, 1, ary);
512
512
  }
513
513
 
514
514
 
@@ -519,14 +519,14 @@ nary_s_bracket(VALUE klass, VALUE ary)
519
519
  /* investigate ndim, shape, type of Array */
520
520
  /*
521
521
  static int
522
- na_mdai_for_struct(na_mdai_t *mdai, int ndim)
522
+ cumo_na_mdai_for_struct(cumo_na_mdai_t *mdai, int ndim)
523
523
  {
524
524
  size_t i;
525
525
  int j, r;
526
526
  size_t len;
527
527
  VALUE v;
528
528
  VALUE val;
529
- narray_t *na;
529
+ cumo_narray_t *na;
530
530
 
531
531
  //fprintf(stderr,"ndim=%d\n",ndim); rb_p(mdai->na_type);
532
532
  if (ndim>4) { abort(); }
@@ -534,11 +534,11 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
534
534
 
535
535
  //fpintf(stderr,"val = "); rb_p(val);
536
536
 
537
- if (CLASS_OF(val) == mdai->na_type) {
538
- GetNArray(val,na);
537
+ if (rb_obj_class(val) == mdai->na_type) {
538
+ CumoGetNArray(val,na);
539
539
  if ( ndim+na->ndim > mdai->capa ) {
540
540
  abort();
541
- na_mdai_realloc(mdai,((na->ndim-1)/4+1)*4);
541
+ cumo_na_mdai_realloc(mdai,((na->ndim-1)/4+1)*4);
542
542
  }
543
543
  for ( j=0,r=ndim; j < na->ndim; j++,r++ ) {
544
544
  if ( mdai->item[r].shape < na->shape[j] )
@@ -563,7 +563,7 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
563
563
  // otherwise, multi-dimention
564
564
  if (ndim >= mdai->capa) {
565
565
  //fprintf(stderr,"exeed capa\n"); abort();
566
- na_mdai_realloc(mdai,4);
566
+ cumo_na_mdai_realloc(mdai,4);
567
567
  }
568
568
  // finally, multidimension-check
569
569
  len = RARRAY_LEN(val);
@@ -578,7 +578,7 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
578
578
  v = RARRAY_AREF(val,i);
579
579
  //fprintf(stderr,"check:"); rb_p(v);
580
580
  mdai->item[ndim+1].val = v;
581
- if ( na_mdai_for_struct( mdai, ndim+1 ) == 0 ) {
581
+ if ( cumo_na_mdai_for_struct( mdai, ndim+1 ) == 0 ) {
582
582
  //fprintf(stderr,"not struct:"); rb_p(v);
583
583
  //abort();
584
584
  return 0;
@@ -598,19 +598,19 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
598
598
 
599
599
  /*
600
600
  VALUE
601
- na_ary_composition_for_struct(VALUE nstruct, VALUE ary)
601
+ cumo_na_ary_composition_for_struct(VALUE nstruct, VALUE ary)
602
602
  {
603
603
  volatile VALUE vmdai, vnc;
604
- na_mdai_t *mdai;
605
- na_compose_t *nc;
604
+ cumo_na_mdai_t *mdai;
605
+ cumo_na_compose_t *nc;
606
606
 
607
- mdai = na_mdai_alloc(ary);
607
+ mdai = cumo_na_mdai_alloc(ary);
608
608
  mdai->na_type = nstruct;
609
609
  vmdai = TypedData_Wrap_Struct(rb_cData, &mdai_data_type, (void*)mdai);
610
- na_mdai_for_struct(mdai, 0);
611
- nc = na_compose_alloc();
610
+ cumo_na_mdai_for_struct(mdai, 0);
611
+ nc = cumo_na_compose_alloc();
612
612
  vnc = WrapCompose(nc);
613
- na_mdai_result(mdai, nc);
613
+ cumo_na_mdai_result(mdai, nc);
614
614
  //fprintf(stderr,"nc->ndim=%d\n",nc->ndim);
615
615
  rb_gc_force_recycle(vmdai);
616
616
  return vnc;
@@ -620,19 +620,19 @@ na_ary_composition_for_struct(VALUE nstruct, VALUE ary)
620
620
 
621
621
 
622
622
  void
623
- Init_cumo_nary_array()
623
+ Init_cumo_na_array()
624
624
  {
625
- rb_define_singleton_method(cNArray, "array_shape", na_s_array_shape, 1);
626
- rb_define_singleton_method(cNArray, "array_type", na_s_array_type, 1);
627
- rb_define_singleton_method(cNArray, "new_like", na_s_new_like, 1);
628
-
629
- rb_define_singleton_method(cNArray, "[]", nary_s_bracket, -2);
630
-
631
- id_begin = rb_intern("begin");
632
- id_end = rb_intern("end");
633
- id_step = rb_intern("step");
634
- id_cast = rb_intern("cast");
635
- id_abs = rb_intern("abs");
636
- id_le = rb_intern("<=");
637
- id_Complex = rb_intern("Complex");
625
+ rb_define_singleton_method(cNArray, "array_shape", cumo_na_s_array_shape, 1);
626
+ rb_define_singleton_method(cNArray, "array_type", cumo_na_s_array_type, 1);
627
+ rb_define_singleton_method(cNArray, "new_like", cumo_na_s_new_like, 1);
628
+
629
+ rb_define_singleton_method(cNArray, "[]", cumo_na_s_bracket, -2);
630
+
631
+ cumo_id_begin = rb_intern("begin");
632
+ cumo_id_end = rb_intern("end");
633
+ cumo_id_step = rb_intern("step");
634
+ cumo_id_cast = rb_intern("cast");
635
+ cumo_id_abs = rb_intern("abs");
636
+ cumo_id_le = rb_intern("<=");
637
+ cumo_id_Complex = rb_intern("Complex");
638
638
  }