numo-narray-alt 0.9.10 → 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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/LICENSE +1 -1
  4. data/README.md +7 -0
  5. data/ext/numo/narray/numo/narray.h +2 -2
  6. data/ext/numo/narray/numo/types/robj_macro.h +1 -1
  7. data/ext/numo/narray/numo/types/robject.h +1 -1
  8. data/ext/numo/narray/src/mh/argmax.h +154 -0
  9. data/ext/numo/narray/src/mh/argmin.h +154 -0
  10. data/ext/numo/narray/src/mh/bincount.h +233 -0
  11. data/ext/numo/narray/src/mh/bit/and.h +225 -0
  12. data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
  13. data/ext/numo/narray/src/mh/bit/not.h +173 -0
  14. data/ext/numo/narray/src/mh/bit/or.h +225 -0
  15. data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
  16. data/ext/numo/narray/src/mh/bit/xor.h +225 -0
  17. data/ext/numo/narray/src/mh/clip.h +115 -0
  18. data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
  19. data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
  20. data/ext/numo/narray/src/mh/comp/eq.h +26 -0
  21. data/ext/numo/narray/src/mh/comp/ge.h +26 -0
  22. data/ext/numo/narray/src/mh/comp/gt.h +26 -0
  23. data/ext/numo/narray/src/mh/comp/le.h +26 -0
  24. data/ext/numo/narray/src/mh/comp/lt.h +26 -0
  25. data/ext/numo/narray/src/mh/comp/ne.h +26 -0
  26. data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
  27. data/ext/numo/narray/src/mh/cumprod.h +98 -0
  28. data/ext/numo/narray/src/mh/cumsum.h +98 -0
  29. data/ext/numo/narray/src/mh/divmod.h +142 -0
  30. data/ext/numo/narray/src/mh/eye.h +82 -0
  31. data/ext/numo/narray/src/mh/fill.h +94 -0
  32. data/ext/numo/narray/src/mh/format.h +108 -0
  33. data/ext/numo/narray/src/mh/format_to_a.h +89 -0
  34. data/ext/numo/narray/src/mh/inspect.h +33 -0
  35. data/ext/numo/narray/src/mh/isfinite.h +42 -0
  36. data/ext/numo/narray/src/mh/isinf.h +42 -0
  37. data/ext/numo/narray/src/mh/isnan.h +42 -0
  38. data/ext/numo/narray/src/mh/isneginf.h +42 -0
  39. data/ext/numo/narray/src/mh/isposinf.h +42 -0
  40. data/ext/numo/narray/src/mh/logseq.h +69 -0
  41. data/ext/numo/narray/src/mh/math/acos.h +2 -2
  42. data/ext/numo/narray/src/mh/math/acosh.h +2 -2
  43. data/ext/numo/narray/src/mh/math/asin.h +2 -2
  44. data/ext/numo/narray/src/mh/math/asinh.h +2 -2
  45. data/ext/numo/narray/src/mh/math/atan.h +2 -2
  46. data/ext/numo/narray/src/mh/math/atan2.h +3 -3
  47. data/ext/numo/narray/src/mh/math/atanh.h +2 -2
  48. data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
  49. data/ext/numo/narray/src/mh/math/cos.h +2 -2
  50. data/ext/numo/narray/src/mh/math/cosh.h +2 -2
  51. data/ext/numo/narray/src/mh/math/erf.h +2 -2
  52. data/ext/numo/narray/src/mh/math/erfc.h +2 -2
  53. data/ext/numo/narray/src/mh/math/exp.h +2 -2
  54. data/ext/numo/narray/src/mh/math/exp10.h +2 -2
  55. data/ext/numo/narray/src/mh/math/exp2.h +2 -2
  56. data/ext/numo/narray/src/mh/math/expm1.h +2 -2
  57. data/ext/numo/narray/src/mh/math/frexp.h +3 -3
  58. data/ext/numo/narray/src/mh/math/hypot.h +3 -3
  59. data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
  60. data/ext/numo/narray/src/mh/math/log.h +2 -2
  61. data/ext/numo/narray/src/mh/math/log10.h +2 -2
  62. data/ext/numo/narray/src/mh/math/log1p.h +2 -2
  63. data/ext/numo/narray/src/mh/math/log2.h +2 -2
  64. data/ext/numo/narray/src/mh/math/sin.h +2 -2
  65. data/ext/numo/narray/src/mh/math/sinc.h +2 -2
  66. data/ext/numo/narray/src/mh/math/sinh.h +2 -2
  67. data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
  68. data/ext/numo/narray/src/mh/math/tan.h +2 -2
  69. data/ext/numo/narray/src/mh/math/tanh.h +2 -2
  70. data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
  71. data/ext/numo/narray/src/mh/max.h +69 -0
  72. data/ext/numo/narray/src/mh/max_index.h +184 -0
  73. data/ext/numo/narray/src/mh/maximum.h +116 -0
  74. data/ext/numo/narray/src/mh/min.h +69 -0
  75. data/ext/numo/narray/src/mh/min_index.h +184 -0
  76. data/ext/numo/narray/src/mh/minimum.h +116 -0
  77. data/ext/numo/narray/src/mh/minmax.h +77 -0
  78. data/ext/numo/narray/src/mh/mulsum.h +185 -0
  79. data/ext/numo/narray/src/mh/op/add.h +78 -0
  80. data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
  81. data/ext/numo/narray/src/mh/op/div.h +118 -0
  82. data/ext/numo/narray/src/mh/op/mod.h +108 -0
  83. data/ext/numo/narray/src/mh/op/mul.h +78 -0
  84. data/ext/numo/narray/src/mh/op/sub.h +78 -0
  85. data/ext/numo/narray/src/mh/prod.h +69 -0
  86. data/ext/numo/narray/src/mh/ptp.h +69 -0
  87. data/ext/numo/narray/src/mh/rand.h +315 -0
  88. data/ext/numo/narray/src/mh/round/ceil.h +11 -0
  89. data/ext/numo/narray/src/mh/round/floor.h +11 -0
  90. data/ext/numo/narray/src/mh/round/rint.h +9 -0
  91. data/ext/numo/narray/src/mh/round/round.h +11 -0
  92. data/ext/numo/narray/src/mh/round/trunc.h +11 -0
  93. data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
  94. data/ext/numo/narray/src/mh/seq.h +130 -0
  95. data/ext/numo/narray/src/mh/sum.h +69 -0
  96. data/ext/numo/narray/src/mh/to_a.h +78 -0
  97. data/ext/numo/narray/src/t_bit.c +45 -234
  98. data/ext/numo/narray/src/t_dcomplex.c +608 -2369
  99. data/ext/numo/narray/src/t_dfloat.c +485 -3736
  100. data/ext/numo/narray/src/t_int16.c +743 -3444
  101. data/ext/numo/narray/src/t_int32.c +745 -3445
  102. data/ext/numo/narray/src/t_int64.c +743 -3446
  103. data/ext/numo/narray/src/t_int8.c +678 -3040
  104. data/ext/numo/narray/src/t_robject.c +771 -3548
  105. data/ext/numo/narray/src/t_scomplex.c +607 -2368
  106. data/ext/numo/narray/src/t_sfloat.c +440 -3693
  107. data/ext/numo/narray/src/t_uint16.c +743 -3440
  108. data/ext/numo/narray/src/t_uint32.c +743 -3440
  109. data/ext/numo/narray/src/t_uint64.c +743 -3442
  110. data/ext/numo/narray/src/t_uint8.c +678 -3038
  111. data/lib/numo/narray.rb +2 -3
  112. metadata +62 -3
@@ -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 */