numo-narray 0.9.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +50 -0
  4. data/Rakefile +64 -0
  5. data/ext/numo/narray/SFMT-params.h +97 -0
  6. data/ext/numo/narray/SFMT-params19937.h +46 -0
  7. data/ext/numo/narray/SFMT.c +620 -0
  8. data/ext/numo/narray/SFMT.h +157 -0
  9. data/ext/numo/narray/array.c +525 -0
  10. data/ext/numo/narray/data.c +901 -0
  11. data/ext/numo/narray/depend.erb +33 -0
  12. data/ext/numo/narray/extconf.rb +118 -0
  13. data/ext/numo/narray/gen/bit.erb.c +811 -0
  14. data/ext/numo/narray/gen/cogen.rb +18 -0
  15. data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
  16. data/ext/numo/narray/gen/def/dfloat.rb +30 -0
  17. data/ext/numo/narray/gen/def/int16.rb +29 -0
  18. data/ext/numo/narray/gen/def/int32.rb +29 -0
  19. data/ext/numo/narray/gen/def/int64.rb +29 -0
  20. data/ext/numo/narray/gen/def/int8.rb +29 -0
  21. data/ext/numo/narray/gen/def/robject.rb +30 -0
  22. data/ext/numo/narray/gen/def/scomplex.rb +32 -0
  23. data/ext/numo/narray/gen/def/sfloat.rb +30 -0
  24. data/ext/numo/narray/gen/def/uint16.rb +29 -0
  25. data/ext/numo/narray/gen/def/uint32.rb +29 -0
  26. data/ext/numo/narray/gen/def/uint64.rb +29 -0
  27. data/ext/numo/narray/gen/def/uint8.rb +29 -0
  28. data/ext/numo/narray/gen/dtype.erb.c +328 -0
  29. data/ext/numo/narray/gen/tmpl/accum.c +36 -0
  30. data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
  31. data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
  32. data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
  33. data/ext/numo/narray/gen/tmpl/aref.c +51 -0
  34. data/ext/numo/narray/gen/tmpl/aset.c +61 -0
  35. data/ext/numo/narray/gen/tmpl/binary.c +53 -0
  36. data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
  37. data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
  38. data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
  39. data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
  40. data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
  41. data/ext/numo/narray/gen/tmpl/cast.c +37 -0
  42. data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
  43. data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
  44. data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
  45. data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
  46. data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
  47. data/ext/numo/narray/gen/tmpl/cum.c +42 -0
  48. data/ext/numo/narray/gen/tmpl/each.c +43 -0
  49. data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
  50. data/ext/numo/narray/gen/tmpl/extract.c +23 -0
  51. data/ext/numo/narray/gen/tmpl/eye.c +91 -0
  52. data/ext/numo/narray/gen/tmpl/fill.c +38 -0
  53. data/ext/numo/narray/gen/tmpl/format.c +60 -0
  54. data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
  55. data/ext/numo/narray/gen/tmpl/head.c +25 -0
  56. data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
  57. data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
  58. data/ext/numo/narray/gen/tmpl/median.c +44 -0
  59. data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
  60. data/ext/numo/narray/gen/tmpl/poly.c +49 -0
  61. data/ext/numo/narray/gen/tmpl/pow.c +74 -0
  62. data/ext/numo/narray/gen/tmpl/powint.c +17 -0
  63. data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
  64. data/ext/numo/narray/gen/tmpl/rand.c +33 -0
  65. data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
  66. data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
  67. data/ext/numo/narray/gen/tmpl/seq.c +61 -0
  68. data/ext/numo/narray/gen/tmpl/set2.c +56 -0
  69. data/ext/numo/narray/gen/tmpl/sort.c +36 -0
  70. data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
  71. data/ext/numo/narray/gen/tmpl/store.c +31 -0
  72. data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
  73. data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
  74. data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
  75. data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
  76. data/ext/numo/narray/gen/tmpl/unary.c +58 -0
  77. data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
  78. data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
  79. data/ext/numo/narray/index.c +822 -0
  80. data/ext/numo/narray/kwarg.c +79 -0
  81. data/ext/numo/narray/math.c +142 -0
  82. data/ext/numo/narray/narray.c +1541 -0
  83. data/ext/numo/narray/ndloop.c +1928 -0
  84. data/ext/numo/narray/numo/compat.h +23 -0
  85. data/ext/numo/narray/numo/intern.h +112 -0
  86. data/ext/numo/narray/numo/narray.h +411 -0
  87. data/ext/numo/narray/numo/ndloop.h +99 -0
  88. data/ext/numo/narray/numo/template.h +140 -0
  89. data/ext/numo/narray/numo/types/bit.h +19 -0
  90. data/ext/numo/narray/numo/types/complex.h +410 -0
  91. data/ext/numo/narray/numo/types/complex_macro.h +205 -0
  92. data/ext/numo/narray/numo/types/dcomplex.h +11 -0
  93. data/ext/numo/narray/numo/types/dfloat.h +12 -0
  94. data/ext/numo/narray/numo/types/float_def.h +34 -0
  95. data/ext/numo/narray/numo/types/float_macro.h +277 -0
  96. data/ext/numo/narray/numo/types/int16.h +12 -0
  97. data/ext/numo/narray/numo/types/int32.h +12 -0
  98. data/ext/numo/narray/numo/types/int64.h +12 -0
  99. data/ext/numo/narray/numo/types/int8.h +12 -0
  100. data/ext/numo/narray/numo/types/int_macro.h +34 -0
  101. data/ext/numo/narray/numo/types/robj_macro.h +218 -0
  102. data/ext/numo/narray/numo/types/robject.h +21 -0
  103. data/ext/numo/narray/numo/types/scomplex.h +11 -0
  104. data/ext/numo/narray/numo/types/sfloat.h +13 -0
  105. data/ext/numo/narray/numo/types/uint16.h +12 -0
  106. data/ext/numo/narray/numo/types/uint32.h +12 -0
  107. data/ext/numo/narray/numo/types/uint64.h +12 -0
  108. data/ext/numo/narray/numo/types/uint8.h +12 -0
  109. data/ext/numo/narray/numo/types/uint_macro.h +31 -0
  110. data/ext/numo/narray/numo/types/xint_macro.h +133 -0
  111. data/ext/numo/narray/rand.c +87 -0
  112. data/ext/numo/narray/step.c +506 -0
  113. data/ext/numo/narray/struct.c +871 -0
  114. data/lib/erbpp.rb +286 -0
  115. data/lib/erbpp/line_number.rb +126 -0
  116. data/lib/erbpp/narray_def.rb +342 -0
  117. data/lib/numo/narray.rb +6 -0
  118. data/numo-narray.gemspec +35 -0
  119. data/spec/bit_spec.rb +93 -0
  120. data/spec/narray_spec.rb +249 -0
  121. metadata +238 -0
@@ -0,0 +1,12 @@
1
+ typedef int16_t dtype;
2
+ typedef int16_t rtype;
3
+ #define cT numo_cInt16
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2INT(x))
7
+ #define m_data_to_num(x) INT2NUM((int)(x))
8
+ #define m_extract(x) INT2NUM((int)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%d",(int)(x))
10
+ #define m_rand ((dtype)gen_rand32())
11
+
12
+ #include "int_macro.h"
@@ -0,0 +1,12 @@
1
+ typedef int32_t dtype;
2
+ typedef int32_t rtype;
3
+ #define cT numo_cInt32
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2INT32(x))
7
+ #define m_data_to_num(x) INT322NUM((int32_t)(x))
8
+ #define m_extract(x) INT322NUM((int32_t)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%"PRId32,(int32_t)(x))
10
+ #define m_rand ((dtype)gen_rand32())
11
+
12
+ #include "int_macro.h"
@@ -0,0 +1,12 @@
1
+ typedef int64_t dtype;
2
+ typedef int64_t rtype;
3
+ #define cT numo_cInt64
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2INT64(x))
7
+ #define m_data_to_num(x) INT642NUM((int64_t)(x))
8
+ #define m_extract(x) INT642NUM((int64_t)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%"PRId64,(int64_t)(x))
10
+ #define m_rand ((dtype)gen_rand64())
11
+
12
+ #include "int_macro.h"
@@ -0,0 +1,12 @@
1
+ typedef int8_t dtype;
2
+ typedef int8_t rtype;
3
+ #define cT numo_cInt8
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2INT(x))
7
+ #define m_data_to_num(x) INT2NUM((int)(x))
8
+ #define m_extract(x) INT2NUM((int)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%d",(int)(x))
10
+ #define m_rand ((dtype)gen_rand32())
11
+
12
+ #include "int_macro.h"
@@ -0,0 +1,34 @@
1
+ #include "xint_macro.h"
2
+
3
+ #define m_abs(x) ((x<0)?-x:x)
4
+
5
+ static inline dtype int_inverse(dtype x) {
6
+ switch (x) {
7
+ case 1:
8
+ return 1;
9
+ case -1:
10
+ return -1;
11
+ case 0:
12
+ rb_raise(rb_eZeroDivError, "divided by 0");
13
+ default:
14
+ return 0;
15
+ }
16
+ }
17
+
18
+ static dtype pow_int(dtype x, int p)
19
+ {
20
+ dtype r = m_one;
21
+ switch(p) {
22
+ case 0: return 1;
23
+ case 1: return x;
24
+ case 2: return x*x;
25
+ case 3: return x*x*x;
26
+ }
27
+ if (p<0) return 0;
28
+ while (p) {
29
+ if (p&1) r *= x;
30
+ x *= x;
31
+ p >>= 1;
32
+ }
33
+ return r;
34
+ }
@@ -0,0 +1,218 @@
1
+ #define m_zero INT2FIX(0)
2
+ #define m_one INT2FIX(1)
3
+
4
+ #define m_num_to_data(x) (x)
5
+ #define m_data_to_num(x) (x)
6
+
7
+ #define m_from_double(x) rb_float_new(x)
8
+ #define m_from_real(x) rb_float_new(x)
9
+
10
+ #define m_add(x,y) rb_funcall(x,'+',1,y)
11
+ #define m_sub(x,y) rb_funcall(x,'-',1,y)
12
+ #define m_mul(x,y) rb_funcall(x,'*',1,y)
13
+ #define m_div(x,y) rb_funcall(x,'/',1,y)
14
+ #define m_mod(x,y) rb_funcall(x,'%',1,y)
15
+ #define m_divmod(x,y,a,b) \
16
+ {x = rb_funcall(x,id_divmod,1,y); \
17
+ a = RARRAY_PTR(x)[0]; b = RARRAY_PTR(x)[0];}
18
+ #define m_pow(x,y) rb_funcall(x,id_pow,1,y)
19
+ #define m_pow_int(x,y) rb_funcall(x,id_pow,1,y)
20
+
21
+ #define m_abs(x) rb_funcall(x,id_abs,0)
22
+ #define m_minus(x) rb_funcall(x,id_minus,0)
23
+ #define m_inverse(x) rb_funcall(x,id_inverse,0)
24
+ #define m_square(x) rb_funcall(x,'*',1,x)
25
+ #define m_floor(x) rb_funcall(x,id_floor,0)
26
+ #define m_round(x) rb_funcall(x,id_round,0)
27
+ #define m_ceil(x) rb_funcall(x,id_ceil,0)
28
+
29
+ #define m_eq(x,y) RTEST(rb_funcall(x,id_eq,1,y))
30
+ #define m_ne(x,y) RTEST(rb_funcall(x,id_ne,1,y))
31
+ #define m_gt(x,y) RTEST(rb_funcall(x,id_op_gt,1,y))
32
+ #define m_ge(x,y) RTEST(rb_funcall(x,id_op_ge,1,y))
33
+ #define m_lt(x,y) RTEST(rb_funcall(x,id_op_lt,1,y))
34
+ #define m_le(x,y) RTEST(rb_funcall(x,id_op_le,1,y))
35
+
36
+ #define m_bit_and(x,y) rb_funcall(x,id_bit_and,1,y)
37
+ #define m_bit_or(x,y) rb_funcall(x,id_bit_or, 1,y)
38
+ #define m_bit_xor(x,y) rb_funcall(x,id_bit_xor,1,y)
39
+ #define m_bit_not(x) rb_funcall(x,id_bit_not,0)
40
+
41
+ #define m_isnan(x) ((rb_respond_to(x,id_nan_p)) ? RTEST(rb_funcall(x,id_nan_p,0)) : 0)
42
+ #define m_isinf(x) ((rb_respond_to(x,id_infinite_p)) ? RTEST(rb_funcall(x,id_infinite_p,0)) : 0)
43
+ #define m_isfinite(x) ((rb_respond_to(x,id_finite_p)) ? RTEST(rb_funcall(x,id_finite_p,0)) : 0)
44
+
45
+ #define m_mulsum(x,y,z) {z = m_add(m_mul(x,y),z);}
46
+ #define m_mulsum_init INT2FIX(0)
47
+
48
+ #define m_rand to_res53(gen_rand64())
49
+ #define m_rand_norm(a) rand_norm(a)
50
+
51
+ #define m_sprintf(s,x) robj_sprintf(s,x)
52
+
53
+ static inline int robj_sprintf(char *s, VALUE x) {
54
+ VALUE v = rb_funcall(x,rb_intern("to_s"),0);
55
+ return sprintf(s,"%s",StringValuePtr(v));
56
+ }
57
+
58
+ static inline dtype f_sum(size_t n, char *p, ssize_t stride)
59
+ {
60
+ size_t i=n;
61
+ dtype x,y=INT2FIX(0);
62
+
63
+ for (; i--;) {
64
+ x = *(dtype*)p;
65
+ if (!m_isnan(x)) {
66
+ y = m_add(x,y);
67
+ }
68
+ p += stride;
69
+ }
70
+ return y;
71
+ }
72
+
73
+ static inline dtype f_prod(size_t n, char *p, ssize_t stride)
74
+ {
75
+ size_t i=n;
76
+ dtype x,y=INT2FIX(1);
77
+
78
+ for (; i--;) {
79
+ x = *(dtype*)p;
80
+ if (!m_isnan(x)) {
81
+ y = m_mul(x,y);
82
+ }
83
+ p += stride;
84
+ }
85
+ return y;
86
+ }
87
+
88
+ static inline dtype f_mean(size_t n, char *p, ssize_t stride)
89
+ {
90
+ size_t i=n;
91
+ size_t count=0;
92
+ dtype x,y=INT2FIX(0);
93
+
94
+ for (; i--;) {
95
+ x = *(dtype*)p;
96
+ if (!m_isnan(x)) {
97
+ y = m_add(x,y);
98
+ count++;
99
+ }
100
+ p += stride;
101
+ }
102
+ return m_div(y,DBL2NUM(count));
103
+ }
104
+
105
+ static inline dtype f_var(size_t n, char *p, ssize_t stride)
106
+ {
107
+ size_t i=n;
108
+ size_t count=0;
109
+ dtype x,m;
110
+ dtype y=INT2FIX(0);
111
+
112
+ m = f_mean(n,p,stride);
113
+
114
+ for (; i--;) {
115
+ x = *(dtype*)p;
116
+ if (!m_isnan(x)) {
117
+ y = m_add(y,m_square(m_abs(m_sub(x,m))));
118
+ count++;
119
+ }
120
+ p += stride;
121
+ }
122
+ return m_div(y,DBL2NUM(count-1));
123
+ }
124
+
125
+ static inline dtype f_stddev(size_t n, char *p, ssize_t stride)
126
+ {
127
+ VALUE m = rb_const_get(rb_mKernel,rb_intern("Math"));
128
+ return rb_funcall(m,rb_intern("sqrt"),1,f_var(n,p,stride));
129
+ }
130
+
131
+ static inline dtype f_rms(size_t n, char *p, ssize_t stride)
132
+ {
133
+ size_t i=n;
134
+ size_t count=0;
135
+ dtype x;
136
+ dtype y=INT2FIX(0);
137
+ VALUE m;
138
+
139
+ for (; i--;) {
140
+ x = *(dtype*)p;
141
+ if (!m_isnan(x)) {
142
+ y = m_add(y,m_square(m_abs(x)));
143
+ count++;
144
+ }
145
+ p += stride;
146
+ }
147
+ y = m_div(y,DBL2NUM(count));
148
+ m = rb_const_get(rb_mKernel,rb_intern("Math"));
149
+ return rb_funcall(m,rb_intern("sqrt"),1,y);
150
+ }
151
+
152
+ static inline dtype f_min(size_t n, char *p, ssize_t stride)
153
+ {
154
+ dtype x,y;
155
+ size_t i=n;
156
+
157
+ y = *(dtype*)p;
158
+ p += stride;
159
+ i--;
160
+ for (; i--;) {
161
+ x = *(dtype*)p;
162
+ if (!m_isnan(x) && (m_isnan(y) || m_lt(x,y))) {
163
+ y = x;
164
+ }
165
+ p += stride;
166
+ }
167
+ return y;
168
+ }
169
+
170
+ static inline dtype f_max(size_t n, char *p, ssize_t stride)
171
+ {
172
+ dtype x,y;
173
+ size_t i=n;
174
+
175
+ y = *(dtype*)p;
176
+ p += stride;
177
+ i--;
178
+ for (; i--;) {
179
+ x = *(dtype*)p;
180
+ if (!m_isnan(x) && (m_isnan(y) || m_gt(x,y))) {
181
+ y = x;
182
+ }
183
+ p += stride;
184
+ }
185
+ return y;
186
+ }
187
+
188
+ static inline size_t f_min_index(size_t n, char *p, ssize_t stride)
189
+ {
190
+ dtype x, y;
191
+ size_t i, j=0;
192
+
193
+ y = *(dtype*)p;
194
+ for (i=1; i<n; i++) {
195
+ x = *(dtype*)(p+i*stride);
196
+ if (!m_isnan(x) && (m_isnan(y) || m_lt(x,y))) {
197
+ y = x;
198
+ j = i;
199
+ }
200
+ }
201
+ return j;
202
+ }
203
+
204
+ static inline size_t f_max_index(size_t n, char *p, ssize_t stride)
205
+ {
206
+ dtype x, y;
207
+ size_t i, j=0;
208
+
209
+ y = *(dtype*)p;
210
+ for (i=1; i<n; i++) {
211
+ x = *(dtype*)(p+i*stride);
212
+ if (!m_isnan(x) && (m_isnan(y) || m_gt(x,y))) {
213
+ y = x;
214
+ j = i;
215
+ }
216
+ }
217
+ return j;
218
+ }
@@ -0,0 +1,21 @@
1
+ typedef VALUE dtype;
2
+ typedef VALUE rtype;
3
+ #define cT numo_cRObject
4
+ #define cRT cT
5
+ //#define mTM mRObjectMath
6
+
7
+ #include "float_def.h"
8
+ #include "robj_macro.h"
9
+
10
+ #define m_min_init (0.0/0.0)
11
+ #define m_max_init (0.0/0.0)
12
+ #define m_extract(x) (*(VALUE*)x)
13
+ #define m_nearly_eq(x,y) robj_nearly_eq(x,y)
14
+
15
+ inline static int robj_nearly_eq(VALUE vx, VALUE vy)
16
+ {
17
+ double x, y;
18
+ x = NUM2DBL(vx);
19
+ y = NUM2DBL(vy);
20
+ return (fabs(x-y)<=(fabs(x)+fabs(y))*DBL_EPSILON*2);
21
+ }
@@ -0,0 +1,11 @@
1
+ typedef scomplex dtype;
2
+ typedef float rtype;
3
+ #define cT numo_cSComplex
4
+ #define cRT numo_cSFloat
5
+ #define mTM numo_mSComplexMath
6
+
7
+ #include "complex_macro.h"
8
+
9
+ static inline bool c_nearly_eq(dtype x, dtype y) {
10
+ return c_abs(c_sub(x,y)) <= (c_abs(x)+c_abs(y))*FLT_EPSILON*2;
11
+ }
@@ -0,0 +1,13 @@
1
+ typedef float dtype;
2
+ typedef float rtype;
3
+ #define cT numo_cSFloat
4
+ #define cRT cT
5
+ #define mTM numo_mSFloatMath
6
+
7
+ #include "float_macro.h"
8
+
9
+ #define m_min_init numo_sfloat_new_dim0(0.0/0.0)
10
+ #define m_max_init numo_sfloat_new_dim0(0.0/0.0)
11
+
12
+ #define m_extract(x) rb_float_new(*(float*)x)
13
+ #define m_nearly_eq(x,y) (fabs(x-y)<=(fabs(x)+fabs(y))*FLT_EPSILON*2)
@@ -0,0 +1,12 @@
1
+ typedef u_int16_t dtype;
2
+ typedef u_int16_t rtype;
3
+ #define cT numo_cUInt16
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2UINT(x))
7
+ #define m_data_to_num(x) UINT2NUM((unsigned int)(x))
8
+ #define m_extract(x) UINT2NUM((unsigned int)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%u",(unsigned int)(x))
10
+ #define m_rand ((dtype)gen_rand32())
11
+
12
+ #include "uint_macro.h"
@@ -0,0 +1,12 @@
1
+ typedef u_int32_t dtype;
2
+ typedef u_int32_t rtype;
3
+ #define cT numo_cUInt32
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2UINT32(x))
7
+ #define m_data_to_num(x) UINT322NUM((u_int32_t)(x))
8
+ #define m_extract(x) UINT322NUM((u_int32_t)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%"PRIu32,(u_int32_t)(x))
10
+ #define m_rand ((dtype)gen_rand32())
11
+
12
+ #include "uint_macro.h"
@@ -0,0 +1,12 @@
1
+ typedef u_int64_t dtype;
2
+ typedef u_int64_t rtype;
3
+ #define cT numo_cUInt64
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2UINT64(x))
7
+ #define m_data_to_num(x) UINT642NUM((u_int64_t)(x))
8
+ #define m_extract(x) UINT642NUM((u_int64_t)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%"PRIu64,(u_int64_t)(x))
10
+ #define m_rand ((dtype)gen_rand64())
11
+
12
+ #include "uint_macro.h"
@@ -0,0 +1,12 @@
1
+ typedef u_int8_t dtype;
2
+ typedef u_int8_t rtype;
3
+ #define cT numo_cUInt8
4
+ #define cRT cT
5
+
6
+ #define m_num_to_data(x) ((dtype)NUM2UINT(x))
7
+ #define m_data_to_num(x) UINT2NUM((unsigned int)(x))
8
+ #define m_extract(x) UINT2NUM((unsigned int)*(dtype*)(x))
9
+ #define m_sprintf(s,x) sprintf(s,"%u",(unsigned int)(x))
10
+ #define m_rand ((dtype)gen_rand32())
11
+
12
+ #include "uint_macro.h"
@@ -0,0 +1,31 @@
1
+ #include "xint_macro.h"
2
+
3
+ #define m_abs(x) (x)
4
+
5
+ static inline dtype int_inverse(dtype x) {
6
+ switch (x) {
7
+ case 1:
8
+ return 1;
9
+ case 0:
10
+ rb_raise(rb_eZeroDivError, "divided by 0");
11
+ default:
12
+ return 0;
13
+ }
14
+ }
15
+
16
+ static dtype pow_int(dtype x, int p)
17
+ {
18
+ dtype r = m_one;
19
+ switch(p) {
20
+ case 0: return 1;
21
+ case 1: return x;
22
+ case 2: return x*x;
23
+ case 3: return x*x*x;
24
+ }
25
+ while (p) {
26
+ if (p&1) r *= x;
27
+ x *= x;
28
+ p >>= 1;
29
+ }
30
+ return r;
31
+ }