numo-narray-alt 0.9.11 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +7 -0
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/numo/types/robj_macro.h +1 -1
- data/ext/numo/narray/src/mh/bincount.h +233 -0
- data/ext/numo/narray/src/mh/bit/and.h +225 -0
- data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/not.h +173 -0
- data/ext/numo/narray/src/mh/bit/or.h +225 -0
- data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/xor.h +225 -0
- data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
- data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
- data/ext/numo/narray/src/mh/comp/eq.h +26 -0
- data/ext/numo/narray/src/mh/comp/ge.h +26 -0
- data/ext/numo/narray/src/mh/comp/gt.h +26 -0
- data/ext/numo/narray/src/mh/comp/le.h +26 -0
- data/ext/numo/narray/src/mh/comp/lt.h +26 -0
- data/ext/numo/narray/src/mh/comp/ne.h +26 -0
- data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
- data/ext/numo/narray/src/mh/divmod.h +142 -0
- data/ext/numo/narray/src/mh/eye.h +1 -1
- data/ext/numo/narray/src/mh/fill.h +94 -0
- data/ext/numo/narray/src/mh/format.h +108 -0
- data/ext/numo/narray/src/mh/format_to_a.h +89 -0
- data/ext/numo/narray/src/mh/inspect.h +33 -0
- data/ext/numo/narray/src/mh/isfinite.h +42 -0
- data/ext/numo/narray/src/mh/isinf.h +42 -0
- data/ext/numo/narray/src/mh/isnan.h +42 -0
- data/ext/numo/narray/src/mh/isneginf.h +42 -0
- data/ext/numo/narray/src/mh/isposinf.h +42 -0
- data/ext/numo/narray/src/mh/math/acos.h +2 -2
- data/ext/numo/narray/src/mh/math/acosh.h +2 -2
- data/ext/numo/narray/src/mh/math/asin.h +2 -2
- data/ext/numo/narray/src/mh/math/asinh.h +2 -2
- data/ext/numo/narray/src/mh/math/atan.h +2 -2
- data/ext/numo/narray/src/mh/math/atan2.h +3 -3
- data/ext/numo/narray/src/mh/math/atanh.h +2 -2
- data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
- data/ext/numo/narray/src/mh/math/cos.h +2 -2
- data/ext/numo/narray/src/mh/math/cosh.h +2 -2
- data/ext/numo/narray/src/mh/math/erf.h +2 -2
- data/ext/numo/narray/src/mh/math/erfc.h +2 -2
- data/ext/numo/narray/src/mh/math/exp.h +2 -2
- data/ext/numo/narray/src/mh/math/exp10.h +2 -2
- data/ext/numo/narray/src/mh/math/exp2.h +2 -2
- data/ext/numo/narray/src/mh/math/expm1.h +2 -2
- data/ext/numo/narray/src/mh/math/frexp.h +3 -3
- data/ext/numo/narray/src/mh/math/hypot.h +3 -3
- data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
- data/ext/numo/narray/src/mh/math/log.h +2 -2
- data/ext/numo/narray/src/mh/math/log10.h +2 -2
- data/ext/numo/narray/src/mh/math/log1p.h +2 -2
- data/ext/numo/narray/src/mh/math/log2.h +2 -2
- data/ext/numo/narray/src/mh/math/sin.h +2 -2
- data/ext/numo/narray/src/mh/math/sinc.h +2 -2
- data/ext/numo/narray/src/mh/math/sinh.h +2 -2
- data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
- data/ext/numo/narray/src/mh/math/tan.h +2 -2
- data/ext/numo/narray/src/mh/math/tanh.h +2 -2
- data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
- data/ext/numo/narray/src/mh/op/add.h +78 -0
- data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
- data/ext/numo/narray/src/mh/op/div.h +118 -0
- data/ext/numo/narray/src/mh/op/mod.h +108 -0
- data/ext/numo/narray/src/mh/op/mul.h +78 -0
- data/ext/numo/narray/src/mh/op/sub.h +78 -0
- data/ext/numo/narray/src/mh/rand.h +2 -2
- data/ext/numo/narray/src/mh/round/ceil.h +11 -0
- data/ext/numo/narray/src/mh/round/floor.h +11 -0
- data/ext/numo/narray/src/mh/round/rint.h +9 -0
- data/ext/numo/narray/src/mh/round/round.h +11 -0
- data/ext/numo/narray/src/mh/round/trunc.h +11 -0
- data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
- data/ext/numo/narray/src/mh/to_a.h +78 -0
- data/ext/numo/narray/src/t_bit.c +45 -234
- data/ext/numo/narray/src/t_dcomplex.c +584 -1809
- data/ext/numo/narray/src/t_dfloat.c +429 -2432
- data/ext/numo/narray/src/t_int16.c +481 -2283
- data/ext/numo/narray/src/t_int32.c +481 -2283
- data/ext/numo/narray/src/t_int64.c +481 -2283
- data/ext/numo/narray/src/t_int8.c +408 -1873
- data/ext/numo/narray/src/t_robject.c +448 -1977
- data/ext/numo/narray/src/t_scomplex.c +584 -1809
- data/ext/numo/narray/src/t_sfloat.c +429 -2434
- data/ext/numo/narray/src/t_uint16.c +480 -2278
- data/ext/numo/narray/src/t_uint32.c +480 -2278
- data/ext/numo/narray/src/t_uint64.c +480 -2278
- data/ext/numo/narray/src/t_uint8.c +407 -1868
- metadata +41 -2
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_BIT_OR_H
|
|
2
|
+
#define NUMO_NARRAY_MH_BIT_OR_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_INT_BIT_OR_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_bit_or(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
char* p3; \
|
|
10
|
+
ssize_t s1; \
|
|
11
|
+
ssize_t s2; \
|
|
12
|
+
ssize_t s3; \
|
|
13
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
15
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
16
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
17
|
+
if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType)) && \
|
|
18
|
+
is_aligned(p3, sizeof(tDType))) { \
|
|
19
|
+
if (s1 == sizeof(tDType) && s2 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
20
|
+
if (p1 == p3) { \
|
|
21
|
+
for (size_t i = 0; i < n; i++) { \
|
|
22
|
+
((tDType*)p1)[i] = m_bit_or(((tDType*)p1)[i], ((tDType*)p2)[i]); \
|
|
23
|
+
} \
|
|
24
|
+
} else { \
|
|
25
|
+
for (size_t i = 0; i < n; i++) { \
|
|
26
|
+
((tDType*)p3)[i] = m_bit_or(((tDType*)p1)[i], ((tDType*)p2)[i]); \
|
|
27
|
+
} \
|
|
28
|
+
} \
|
|
29
|
+
return; \
|
|
30
|
+
} \
|
|
31
|
+
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
|
|
32
|
+
is_aligned_step(s3, sizeof(tDType))) { \
|
|
33
|
+
if (s2 == 0) { \
|
|
34
|
+
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
35
|
+
if (p1 == p3) { \
|
|
36
|
+
for (size_t i = 0; i < n; i++) { \
|
|
37
|
+
((tDType*)p1)[i] = m_bit_or(((tDType*)p1)[i], *(tDType*)p2); \
|
|
38
|
+
} \
|
|
39
|
+
} else { \
|
|
40
|
+
for (size_t i = 0; i < n; i++) { \
|
|
41
|
+
((tDType*)p3)[i] = m_bit_or(((tDType*)p1)[i], *(tDType*)p2); \
|
|
42
|
+
} \
|
|
43
|
+
} \
|
|
44
|
+
} else { \
|
|
45
|
+
for (size_t i = 0; i < n; i++) { \
|
|
46
|
+
*(tDType*)p3 = m_bit_or(*(tDType*)p1, *(tDType*)p2); \
|
|
47
|
+
p1 += s1; \
|
|
48
|
+
p3 += s3; \
|
|
49
|
+
} \
|
|
50
|
+
} \
|
|
51
|
+
} else { \
|
|
52
|
+
if (p1 == p3) { \
|
|
53
|
+
for (size_t i = 0; i < n; i++) { \
|
|
54
|
+
*(tDType*)p1 = m_bit_or(*(tDType*)p1, *(tDType*)p2); \
|
|
55
|
+
p1 += s1; \
|
|
56
|
+
p2 += s2; \
|
|
57
|
+
} \
|
|
58
|
+
} else { \
|
|
59
|
+
for (size_t i = 0; i < n; i++) { \
|
|
60
|
+
*(tDType*)p3 = m_bit_or(*(tDType*)p1, *(tDType*)p2); \
|
|
61
|
+
p1 += s1; \
|
|
62
|
+
p2 += s2; \
|
|
63
|
+
p3 += s3; \
|
|
64
|
+
} \
|
|
65
|
+
} \
|
|
66
|
+
} \
|
|
67
|
+
return; \
|
|
68
|
+
} \
|
|
69
|
+
} \
|
|
70
|
+
for (size_t i = 0; i < n; i++) { \
|
|
71
|
+
tDType x; \
|
|
72
|
+
tDType y; \
|
|
73
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
74
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
75
|
+
const tDType z = m_bit_or(x, y); \
|
|
76
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
77
|
+
} \
|
|
78
|
+
} \
|
|
79
|
+
\
|
|
80
|
+
static VALUE tDType##_bit_or_self(VALUE self, VALUE other) { \
|
|
81
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
82
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
83
|
+
ndfunc_t ndf = { iter_##tDType##_bit_or, STRIDE_LOOP, 2, 1, ain, aout }; \
|
|
84
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
85
|
+
} \
|
|
86
|
+
\
|
|
87
|
+
static VALUE tDType##_bit_or(VALUE self, VALUE other) { \
|
|
88
|
+
VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
|
|
89
|
+
if (klass == tNAryClass) { \
|
|
90
|
+
return tDType##_bit_or_self(self, other); \
|
|
91
|
+
} else { \
|
|
92
|
+
VALUE v = rb_funcall(klass, id_cast, 1, self); \
|
|
93
|
+
return rb_funcall(v, '|', 1, other); \
|
|
94
|
+
} \
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#define DEF_NARRAY_INT8_BIT_OR_METHOD_FUNC(tDType, tNAryClass) \
|
|
98
|
+
static void iter_##tDType##_bit_or(na_loop_t* const lp) { \
|
|
99
|
+
size_t n; \
|
|
100
|
+
char* p1; \
|
|
101
|
+
char* p2; \
|
|
102
|
+
char* p3; \
|
|
103
|
+
ssize_t s1; \
|
|
104
|
+
ssize_t s2; \
|
|
105
|
+
ssize_t s3; \
|
|
106
|
+
INIT_COUNTER(lp, n); \
|
|
107
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
108
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
109
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
110
|
+
if (s2 == 0) { \
|
|
111
|
+
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
112
|
+
if (p1 == p3) { \
|
|
113
|
+
for (size_t i = 0; i < n; i++) { \
|
|
114
|
+
((tDType*)p1)[i] = m_bit_or(((tDType*)p1)[i], *(tDType*)p2); \
|
|
115
|
+
} \
|
|
116
|
+
} else { \
|
|
117
|
+
for (size_t i = 0; i < n; i++) { \
|
|
118
|
+
((tDType*)p3)[i] = m_bit_or(((tDType*)p1)[i], *(tDType*)p2); \
|
|
119
|
+
} \
|
|
120
|
+
} \
|
|
121
|
+
} else { \
|
|
122
|
+
for (size_t i = 0; i < n; i++) { \
|
|
123
|
+
*(tDType*)p3 = m_bit_or(*(tDType*)p1, *(tDType*)p2); \
|
|
124
|
+
p1 += s1; \
|
|
125
|
+
p3 += s3; \
|
|
126
|
+
} \
|
|
127
|
+
} \
|
|
128
|
+
} else { \
|
|
129
|
+
if (p1 == p3) { \
|
|
130
|
+
for (size_t i = 0; i < n; i++) { \
|
|
131
|
+
*(tDType*)p1 = m_bit_or(*(tDType*)p1, *(tDType*)p2); \
|
|
132
|
+
p1 += s1; \
|
|
133
|
+
p2 += s2; \
|
|
134
|
+
} \
|
|
135
|
+
} else { \
|
|
136
|
+
for (size_t i = 0; i < n; i++) { \
|
|
137
|
+
*(tDType*)p3 = m_bit_or(*(tDType*)p1, *(tDType*)p2); \
|
|
138
|
+
p1 += s1; \
|
|
139
|
+
p2 += s2; \
|
|
140
|
+
p3 += s3; \
|
|
141
|
+
} \
|
|
142
|
+
} \
|
|
143
|
+
} \
|
|
144
|
+
return; \
|
|
145
|
+
} \
|
|
146
|
+
\
|
|
147
|
+
static VALUE tDType##_bit_or_self(VALUE self, VALUE other) { \
|
|
148
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
149
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
150
|
+
ndfunc_t ndf = { iter_##tDType##_bit_or, STRIDE_LOOP, 2, 1, ain, aout }; \
|
|
151
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
152
|
+
} \
|
|
153
|
+
\
|
|
154
|
+
static VALUE tDType##_bit_or(VALUE self, VALUE other) { \
|
|
155
|
+
VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
|
|
156
|
+
if (klass == tNAryClass) { \
|
|
157
|
+
return tDType##_bit_or_self(self, other); \
|
|
158
|
+
} else { \
|
|
159
|
+
VALUE v = rb_funcall(klass, id_cast, 1, self); \
|
|
160
|
+
return rb_funcall(v, '|', 1, other); \
|
|
161
|
+
} \
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#define DEF_NARRAY_ROBJ_BIT_OR_METHOD_FUNC() \
|
|
165
|
+
static void iter_robject_bit_or(na_loop_t* const lp) { \
|
|
166
|
+
size_t n; \
|
|
167
|
+
char* p1; \
|
|
168
|
+
char* p2; \
|
|
169
|
+
char* p3; \
|
|
170
|
+
ssize_t s1; \
|
|
171
|
+
ssize_t s2; \
|
|
172
|
+
ssize_t s3; \
|
|
173
|
+
INIT_COUNTER(lp, n); \
|
|
174
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
175
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
176
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
177
|
+
if (s2 == 0) { \
|
|
178
|
+
if (s1 == sizeof(robject) && s3 == sizeof(robject)) { \
|
|
179
|
+
if (p1 == p3) { \
|
|
180
|
+
for (size_t i = 0; i < n; i++) { \
|
|
181
|
+
((robject*)p1)[i] = m_bit_or(((robject*)p1)[i], *(robject*)p2); \
|
|
182
|
+
} \
|
|
183
|
+
} else { \
|
|
184
|
+
for (size_t i = 0; i < n; i++) { \
|
|
185
|
+
((robject*)p3)[i] = m_bit_or(((robject*)p1)[i], *(robject*)p2); \
|
|
186
|
+
} \
|
|
187
|
+
} \
|
|
188
|
+
} else { \
|
|
189
|
+
for (size_t i = 0; i < n; i++) { \
|
|
190
|
+
*(robject*)p3 = m_bit_or(*(robject*)p1, *(robject*)p2); \
|
|
191
|
+
p1 += s1; \
|
|
192
|
+
p3 += s3; \
|
|
193
|
+
} \
|
|
194
|
+
} \
|
|
195
|
+
} else { \
|
|
196
|
+
if (p1 == p3) { \
|
|
197
|
+
for (size_t i = 0; i < n; i++) { \
|
|
198
|
+
*(robject*)p1 = m_bit_or(*(robject*)p1, *(robject*)p2); \
|
|
199
|
+
p1 += s1; \
|
|
200
|
+
p2 += s2; \
|
|
201
|
+
} \
|
|
202
|
+
} else { \
|
|
203
|
+
for (size_t i = 0; i < n; i++) { \
|
|
204
|
+
*(robject*)p3 = m_bit_or(*(robject*)p1, *(robject*)p2); \
|
|
205
|
+
p1 += s1; \
|
|
206
|
+
p2 += s2; \
|
|
207
|
+
p3 += s3; \
|
|
208
|
+
} \
|
|
209
|
+
} \
|
|
210
|
+
} \
|
|
211
|
+
return; \
|
|
212
|
+
} \
|
|
213
|
+
\
|
|
214
|
+
static VALUE robject_bit_or_self(VALUE self, VALUE other) { \
|
|
215
|
+
ndfunc_arg_in_t ain[2] = { { numo_cRObject, 0 }, { numo_cRObject, 0 } }; \
|
|
216
|
+
ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } }; \
|
|
217
|
+
ndfunc_t ndf = { iter_robject_bit_or, STRIDE_LOOP, 2, 1, ain, aout }; \
|
|
218
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
219
|
+
} \
|
|
220
|
+
\
|
|
221
|
+
static VALUE robject_bit_or(VALUE self, VALUE other) { \
|
|
222
|
+
return robject_bit_or_self(self, other); \
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#endif /* NUMO_NARRAY_MH_BIT_OR_H */
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_BIT_RIGHT_SHIFT_H
|
|
2
|
+
#define NUMO_NARRAY_MH_BIT_RIGHT_SHIFT_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_INT_RIGHT_SHIFT_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_right_shift(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
char* p3; \
|
|
10
|
+
ssize_t s1; \
|
|
11
|
+
ssize_t s2; \
|
|
12
|
+
ssize_t s3; \
|
|
13
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
15
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
16
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
17
|
+
if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType)) && \
|
|
18
|
+
is_aligned(p3, sizeof(tDType))) { \
|
|
19
|
+
if (s1 == sizeof(tDType) && s2 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
20
|
+
if (p1 == p3) { \
|
|
21
|
+
for (size_t i = 0; i < n; i++) { \
|
|
22
|
+
((tDType*)p1)[i] = m_right_shift(((tDType*)p1)[i], ((tDType*)p2)[i]); \
|
|
23
|
+
} \
|
|
24
|
+
} else { \
|
|
25
|
+
for (size_t i = 0; i < n; i++) { \
|
|
26
|
+
((tDType*)p3)[i] = m_right_shift(((tDType*)p1)[i], ((tDType*)p2)[i]); \
|
|
27
|
+
} \
|
|
28
|
+
} \
|
|
29
|
+
return; \
|
|
30
|
+
} \
|
|
31
|
+
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
|
|
32
|
+
is_aligned_step(s3, sizeof(tDType))) { \
|
|
33
|
+
if (s2 == 0) { \
|
|
34
|
+
const tDType v2 = *(tDType*)p2; \
|
|
35
|
+
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
36
|
+
if (p1 == p3) { \
|
|
37
|
+
for (size_t i = 0; i < n; i++) { \
|
|
38
|
+
((tDType*)p1)[i] = m_right_shift(((tDType*)p1)[i], v2); \
|
|
39
|
+
} \
|
|
40
|
+
} else { \
|
|
41
|
+
for (size_t i = 0; i < n; i++) { \
|
|
42
|
+
((tDType*)p3)[i] = m_right_shift(((tDType*)p1)[i], v2); \
|
|
43
|
+
} \
|
|
44
|
+
} \
|
|
45
|
+
} else { \
|
|
46
|
+
for (size_t i = 0; i < n; i++) { \
|
|
47
|
+
*(tDType*)p3 = m_right_shift(*(tDType*)p1, v2); \
|
|
48
|
+
p1 += s1; \
|
|
49
|
+
p3 += s3; \
|
|
50
|
+
} \
|
|
51
|
+
} \
|
|
52
|
+
} else { \
|
|
53
|
+
if (p1 == p3) { \
|
|
54
|
+
for (size_t i = 0; i < n; i++) { \
|
|
55
|
+
*(tDType*)p1 = m_right_shift(*(tDType*)p1, *(tDType*)p2); \
|
|
56
|
+
p1 += s1; \
|
|
57
|
+
p2 += s2; \
|
|
58
|
+
} \
|
|
59
|
+
} else { \
|
|
60
|
+
for (size_t i = 0; i < n; i++) { \
|
|
61
|
+
*(tDType*)p3 = m_right_shift(*(tDType*)p1, *(tDType*)p2); \
|
|
62
|
+
p1 += s1; \
|
|
63
|
+
p2 += s2; \
|
|
64
|
+
p3 += s3; \
|
|
65
|
+
} \
|
|
66
|
+
} \
|
|
67
|
+
} \
|
|
68
|
+
return; \
|
|
69
|
+
} \
|
|
70
|
+
} \
|
|
71
|
+
for (size_t i = 0; i < n; i++) { \
|
|
72
|
+
tDType x; \
|
|
73
|
+
tDType y; \
|
|
74
|
+
tDType z; \
|
|
75
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
76
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
77
|
+
z = m_right_shift(x, y); \
|
|
78
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
79
|
+
} \
|
|
80
|
+
} \
|
|
81
|
+
\
|
|
82
|
+
static VALUE tDType##_right_shift_self(VALUE self, VALUE other) { \
|
|
83
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
84
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
85
|
+
ndfunc_t ndf = { iter_##tDType##_right_shift, STRIDE_LOOP, 2, 1, ain, aout }; \
|
|
86
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
87
|
+
} \
|
|
88
|
+
\
|
|
89
|
+
static VALUE tDType##_right_shift(VALUE self, VALUE other) { \
|
|
90
|
+
VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
|
|
91
|
+
if (klass == tNAryClass) { \
|
|
92
|
+
return tDType##_right_shift_self(self, other); \
|
|
93
|
+
} \
|
|
94
|
+
VALUE v = rb_funcall(klass, id_cast, 1, self); \
|
|
95
|
+
return rb_funcall(v, id_right_shift, 1, other); \
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#define DEF_NARRAY_INT8_RIGHT_SHIFT_METHOD_FUNC(tDType, tNAryClass) \
|
|
99
|
+
static void iter_##tDType##_right_shift(na_loop_t* const lp) { \
|
|
100
|
+
size_t n; \
|
|
101
|
+
char* p1; \
|
|
102
|
+
char* p2; \
|
|
103
|
+
char* p3; \
|
|
104
|
+
ssize_t s1; \
|
|
105
|
+
ssize_t s2; \
|
|
106
|
+
ssize_t s3; \
|
|
107
|
+
INIT_COUNTER(lp, n); \
|
|
108
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
109
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
110
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
111
|
+
if (s2 == 0) { \
|
|
112
|
+
const tDType v2 = *(tDType*)p2; \
|
|
113
|
+
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
114
|
+
if (p1 == p3) { \
|
|
115
|
+
for (size_t i = 0; i < n; i++) { \
|
|
116
|
+
((tDType*)p1)[i] = m_right_shift(((tDType*)p1)[i], v2); \
|
|
117
|
+
} \
|
|
118
|
+
} else { \
|
|
119
|
+
for (size_t i = 0; i < n; i++) { \
|
|
120
|
+
((tDType*)p3)[i] = m_right_shift(((tDType*)p1)[i], v2); \
|
|
121
|
+
} \
|
|
122
|
+
} \
|
|
123
|
+
} else { \
|
|
124
|
+
for (size_t i = 0; i < n; i++) { \
|
|
125
|
+
*(tDType*)p3 = m_right_shift(*(tDType*)p1, v2); \
|
|
126
|
+
p1 += s1; \
|
|
127
|
+
p3 += s3; \
|
|
128
|
+
} \
|
|
129
|
+
} \
|
|
130
|
+
} else { \
|
|
131
|
+
if (p1 == p3) { \
|
|
132
|
+
for (size_t i = 0; i < n; i++) { \
|
|
133
|
+
*(tDType*)p1 = m_right_shift(*(tDType*)p1, *(tDType*)p2); \
|
|
134
|
+
p1 += s1; \
|
|
135
|
+
p2 += s2; \
|
|
136
|
+
} \
|
|
137
|
+
} else { \
|
|
138
|
+
for (size_t i = 0; i < n; i++) { \
|
|
139
|
+
*(tDType*)p3 = m_right_shift(*(tDType*)p1, *(tDType*)p2); \
|
|
140
|
+
p1 += s1; \
|
|
141
|
+
p2 += s2; \
|
|
142
|
+
p3 += s3; \
|
|
143
|
+
} \
|
|
144
|
+
} \
|
|
145
|
+
} \
|
|
146
|
+
} \
|
|
147
|
+
\
|
|
148
|
+
static VALUE tDType##_right_shift_self(VALUE self, VALUE other) { \
|
|
149
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
150
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
151
|
+
ndfunc_t ndf = { iter_##tDType##_right_shift, STRIDE_LOOP, 2, 1, ain, aout }; \
|
|
152
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
153
|
+
} \
|
|
154
|
+
\
|
|
155
|
+
static VALUE tDType##_right_shift(VALUE self, VALUE other) { \
|
|
156
|
+
VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
|
|
157
|
+
if (klass == tNAryClass) { \
|
|
158
|
+
return tDType##_right_shift_self(self, other); \
|
|
159
|
+
} \
|
|
160
|
+
VALUE v = rb_funcall(klass, id_cast, 1, self); \
|
|
161
|
+
return rb_funcall(v, id_right_shift, 1, other); \
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#define DEF_NARRAY_ROBJ_RIGHT_SHIFT_METHOD_FUNC() \
|
|
165
|
+
static void iter_robject_right_shift(na_loop_t* const lp) { \
|
|
166
|
+
size_t n; \
|
|
167
|
+
char* p1; \
|
|
168
|
+
char* p2; \
|
|
169
|
+
char* p3; \
|
|
170
|
+
ssize_t s1; \
|
|
171
|
+
ssize_t s2; \
|
|
172
|
+
ssize_t s3; \
|
|
173
|
+
INIT_COUNTER(lp, n); \
|
|
174
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
175
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
176
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
177
|
+
if (s2 == 0) { \
|
|
178
|
+
const robject v2 = *(robject*)p2; \
|
|
179
|
+
if (s1 == sizeof(robject) && s3 == sizeof(robject)) { \
|
|
180
|
+
if (p1 == p3) { \
|
|
181
|
+
for (size_t i = 0; i < n; i++) { \
|
|
182
|
+
((robject*)p1)[i] = m_right_shift(((robject*)p1)[i], v2); \
|
|
183
|
+
} \
|
|
184
|
+
} else { \
|
|
185
|
+
for (size_t i = 0; i < n; i++) { \
|
|
186
|
+
((robject*)p3)[i] = m_right_shift(((robject*)p1)[i], v2); \
|
|
187
|
+
} \
|
|
188
|
+
} \
|
|
189
|
+
} else { \
|
|
190
|
+
for (size_t i = 0; i < n; i++) { \
|
|
191
|
+
*(robject*)p3 = m_right_shift(*(robject*)p1, v2); \
|
|
192
|
+
p1 += s1; \
|
|
193
|
+
p3 += s3; \
|
|
194
|
+
} \
|
|
195
|
+
} \
|
|
196
|
+
} else { \
|
|
197
|
+
if (p1 == p3) { \
|
|
198
|
+
for (size_t i = 0; i < n; i++) { \
|
|
199
|
+
*(robject*)p1 = m_right_shift(*(robject*)p1, *(robject*)p2); \
|
|
200
|
+
p1 += s1; \
|
|
201
|
+
p2 += s2; \
|
|
202
|
+
} \
|
|
203
|
+
} else { \
|
|
204
|
+
for (size_t i = 0; i < n; i++) { \
|
|
205
|
+
*(robject*)p3 = m_right_shift(*(robject*)p1, *(robject*)p2); \
|
|
206
|
+
p1 += s1; \
|
|
207
|
+
p2 += s2; \
|
|
208
|
+
p3 += s3; \
|
|
209
|
+
} \
|
|
210
|
+
} \
|
|
211
|
+
} \
|
|
212
|
+
} \
|
|
213
|
+
\
|
|
214
|
+
static VALUE robject_right_shift_self(VALUE self, VALUE other) { \
|
|
215
|
+
ndfunc_arg_in_t ain[2] = { { numo_cRObject, 0 }, { numo_cRObject, 0 } }; \
|
|
216
|
+
ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } }; \
|
|
217
|
+
ndfunc_t ndf = { iter_robject_right_shift, STRIDE_LOOP, 2, 1, ain, aout }; \
|
|
218
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
219
|
+
} \
|
|
220
|
+
\
|
|
221
|
+
static VALUE robject_right_shift(VALUE self, VALUE other) { \
|
|
222
|
+
return robject_right_shift_self(self, other); \
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#endif /* NUMO_NARRAY_MH_BIT_RIGHT_SHIFT_H */
|