numo-narray-alt 0.9.11 → 0.9.13

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/README.md +7 -0
  4. data/ext/numo/narray/numo/narray.h +2 -2
  5. data/ext/numo/narray/numo/types/robj_macro.h +1 -1
  6. data/ext/numo/narray/src/mh/bincount.h +233 -0
  7. data/ext/numo/narray/src/mh/bit/and.h +225 -0
  8. data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
  9. data/ext/numo/narray/src/mh/bit/not.h +173 -0
  10. data/ext/numo/narray/src/mh/bit/or.h +225 -0
  11. data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
  12. data/ext/numo/narray/src/mh/bit/xor.h +225 -0
  13. data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
  14. data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
  15. data/ext/numo/narray/src/mh/comp/eq.h +26 -0
  16. data/ext/numo/narray/src/mh/comp/ge.h +26 -0
  17. data/ext/numo/narray/src/mh/comp/gt.h +26 -0
  18. data/ext/numo/narray/src/mh/comp/le.h +26 -0
  19. data/ext/numo/narray/src/mh/comp/lt.h +26 -0
  20. data/ext/numo/narray/src/mh/comp/ne.h +26 -0
  21. data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
  22. data/ext/numo/narray/src/mh/divmod.h +142 -0
  23. data/ext/numo/narray/src/mh/eye.h +1 -1
  24. data/ext/numo/narray/src/mh/fill.h +94 -0
  25. data/ext/numo/narray/src/mh/format.h +108 -0
  26. data/ext/numo/narray/src/mh/format_to_a.h +89 -0
  27. data/ext/numo/narray/src/mh/inspect.h +33 -0
  28. data/ext/numo/narray/src/mh/isfinite.h +42 -0
  29. data/ext/numo/narray/src/mh/isinf.h +42 -0
  30. data/ext/numo/narray/src/mh/isnan.h +42 -0
  31. data/ext/numo/narray/src/mh/isneginf.h +42 -0
  32. data/ext/numo/narray/src/mh/isposinf.h +42 -0
  33. data/ext/numo/narray/src/mh/math/acos.h +2 -2
  34. data/ext/numo/narray/src/mh/math/acosh.h +2 -2
  35. data/ext/numo/narray/src/mh/math/asin.h +2 -2
  36. data/ext/numo/narray/src/mh/math/asinh.h +2 -2
  37. data/ext/numo/narray/src/mh/math/atan.h +2 -2
  38. data/ext/numo/narray/src/mh/math/atan2.h +3 -3
  39. data/ext/numo/narray/src/mh/math/atanh.h +2 -2
  40. data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
  41. data/ext/numo/narray/src/mh/math/cos.h +2 -2
  42. data/ext/numo/narray/src/mh/math/cosh.h +2 -2
  43. data/ext/numo/narray/src/mh/math/erf.h +2 -2
  44. data/ext/numo/narray/src/mh/math/erfc.h +2 -2
  45. data/ext/numo/narray/src/mh/math/exp.h +2 -2
  46. data/ext/numo/narray/src/mh/math/exp10.h +2 -2
  47. data/ext/numo/narray/src/mh/math/exp2.h +2 -2
  48. data/ext/numo/narray/src/mh/math/expm1.h +2 -2
  49. data/ext/numo/narray/src/mh/math/frexp.h +3 -3
  50. data/ext/numo/narray/src/mh/math/hypot.h +3 -3
  51. data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
  52. data/ext/numo/narray/src/mh/math/log.h +2 -2
  53. data/ext/numo/narray/src/mh/math/log10.h +2 -2
  54. data/ext/numo/narray/src/mh/math/log1p.h +2 -2
  55. data/ext/numo/narray/src/mh/math/log2.h +2 -2
  56. data/ext/numo/narray/src/mh/math/sin.h +2 -2
  57. data/ext/numo/narray/src/mh/math/sinc.h +2 -2
  58. data/ext/numo/narray/src/mh/math/sinh.h +2 -2
  59. data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
  60. data/ext/numo/narray/src/mh/math/tan.h +2 -2
  61. data/ext/numo/narray/src/mh/math/tanh.h +2 -2
  62. data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
  63. data/ext/numo/narray/src/mh/minus.h +125 -0
  64. data/ext/numo/narray/src/mh/op/add.h +78 -0
  65. data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
  66. data/ext/numo/narray/src/mh/op/div.h +118 -0
  67. data/ext/numo/narray/src/mh/op/mod.h +108 -0
  68. data/ext/numo/narray/src/mh/op/mul.h +78 -0
  69. data/ext/numo/narray/src/mh/op/sub.h +78 -0
  70. data/ext/numo/narray/src/mh/pow.h +197 -0
  71. data/ext/numo/narray/src/mh/rand.h +2 -2
  72. data/ext/numo/narray/src/mh/rand_norm.h +125 -0
  73. data/ext/numo/narray/src/mh/reciprocal.h +125 -0
  74. data/ext/numo/narray/src/mh/round/ceil.h +11 -0
  75. data/ext/numo/narray/src/mh/round/floor.h +11 -0
  76. data/ext/numo/narray/src/mh/round/rint.h +9 -0
  77. data/ext/numo/narray/src/mh/round/round.h +11 -0
  78. data/ext/numo/narray/src/mh/round/trunc.h +11 -0
  79. data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
  80. data/ext/numo/narray/src/mh/sign.h +125 -0
  81. data/ext/numo/narray/src/mh/square.h +125 -0
  82. data/ext/numo/narray/src/mh/to_a.h +78 -0
  83. data/ext/numo/narray/src/t_bit.c +45 -234
  84. data/ext/numo/narray/src/t_dcomplex.c +457 -2075
  85. data/ext/numo/narray/src/t_dfloat.c +154 -2560
  86. data/ext/numo/narray/src/t_int16.c +408 -2542
  87. data/ext/numo/narray/src/t_int32.c +408 -2542
  88. data/ext/numo/narray/src/t_int64.c +408 -2542
  89. data/ext/numo/narray/src/t_int8.c +409 -2138
  90. data/ext/numo/narray/src/t_robject.c +376 -2161
  91. data/ext/numo/narray/src/t_scomplex.c +435 -2053
  92. data/ext/numo/narray/src/t_sfloat.c +149 -2557
  93. data/ext/numo/narray/src/t_uint16.c +407 -2537
  94. data/ext/numo/narray/src/t_uint32.c +407 -2537
  95. data/ext/numo/narray/src/t_uint64.c +407 -2537
  96. data/ext/numo/narray/src/t_uint8.c +407 -2132
  97. metadata +47 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f5745729ac9808d98856b30963b19d93cfec3ca0502b4b9db35023094ceb009
4
- data.tar.gz: 38252691a0d86e3f7d3e5280bec28081effce8f40596e56b21d3e23205198350
3
+ metadata.gz: 51d818d5b1d990bb12a358f15adae53ef1b5d488d172dd275abd2d96d4c74ab4
4
+ data.tar.gz: 8f521c4247a54185936fa6f06ebcd322cc90babde98c093ac7287ccc93f443fd
5
5
  SHA512:
6
- metadata.gz: 94c876a77295498c07aea51465e193eb054d0b9936df76ff709ae6e6c677d908a705d9692595af6e60faaddd517b91cdb42356828bee6b40e8b3bcff1c9e114e
7
- data.tar.gz: cf8005eff8efc53fc55641869cc18824dd11ae4be4f93618ba586e632f6aa94643b500fcdf4239b47eaec9b6870dcf080900e35484309101bb34557d9f289bec
6
+ metadata.gz: d01294b516c33ac3173da16947700e8ae5e0db4e5d99bcb9f4c279c98a4880fb6c23a6559426aaae197b6b066400964b77aa2689b797907b52f16f78af4aff56
7
+ data.tar.gz: 6ca130060197c3a3a1a9c2191e820dd7fb0c1d9c514058356bf0b4851a20eb1ac3db5fb0b7e65d161ac606948147b555090a94436febee83a89261829a312bba
data/Gemfile CHANGED
@@ -15,7 +15,6 @@ gem 'rubocop-minitest', '~> 0.38.2'
15
15
  gem 'rubocop-performance', '~> 1.26'
16
16
  gem 'rubocop-rake', '~> 0.7.1'
17
17
  gem 'simplecov', '~> 0.22.0'
18
- gem 'test-unit', '~> 3.7'
19
18
  gem 'yard', '~> 0.9.37'
20
19
 
21
20
  group :memcheck, optional: true do
data/README.md CHANGED
@@ -43,6 +43,13 @@ Numo::DFloat#shape=[2,2]
43
43
  irb(main):004>
44
44
  ```
45
45
 
46
+ If you want to explicitly load numo-narray-alt, write the require method as follows:
47
+
48
+ ```ruby
49
+ irb(main):001> require 'numo/narray/alt'
50
+ => true
51
+ ```
52
+
46
53
  ## Documentation
47
54
 
48
55
  - [API Documentation on Gemdocs](https://gemdocs.org/gems/numo-narray-alt/)
@@ -13,8 +13,8 @@ extern "C" {
13
13
  #endif
14
14
  #endif
15
15
 
16
- #define NARRAY_VERSION "0.9.11"
17
- #define NARRAY_VERSION_CODE 9110
16
+ #define NARRAY_VERSION "0.9.13"
17
+ #define NARRAY_VERSION_CODE 9130
18
18
 
19
19
  #include <math.h>
20
20
  #include "numo/compat.h"
@@ -22,7 +22,7 @@
22
22
  { \
23
23
  x = rb_funcall(x, id_divmod, 1, y); \
24
24
  a = RARRAY_PTR(x)[0]; \
25
- b = RARRAY_PTR(x)[0]; \
25
+ b = RARRAY_PTR(x)[1]; \
26
26
  }
27
27
  #define m_pow(x, y) rb_funcall(x, id_pow, 1, y)
28
28
  #define m_pow_int(x, y) rb_funcall(x, id_pow, 1, y)
@@ -0,0 +1,233 @@
1
+ #ifndef NUMO_NARRAY_MH_BINCOUNT_H
2
+ #define NUMO_NARRAY_MH_BINCOUNT_H 1
3
+
4
+ #define DEF_BINCOUNT_FUNCS(tDType, tNAryClass) \
5
+ static void iter_##tDType##_bincount_32(na_loop_t* const lp) { \
6
+ char* p1; \
7
+ char* p2; \
8
+ ssize_t s1; \
9
+ ssize_t s2; \
10
+ size_t* idx1; \
11
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
12
+ INIT_PTR(lp, 1, p2, s2); \
13
+ const size_t m = lp->args[0].shape[0]; \
14
+ const size_t n = lp->args[1].shape[0]; \
15
+ \
16
+ for (size_t i = 0; i < n; i++) { \
17
+ *(u_int32_t*)(p2 + s2 * i) = 0; \
18
+ } \
19
+ \
20
+ size_t x; \
21
+ if (idx1) { \
22
+ for (size_t i = 0; i < m; i++) { \
23
+ GET_DATA_INDEX(p1, idx1, tDType, x); \
24
+ (*(u_int32_t*)(p2 + s2 * x))++; \
25
+ } \
26
+ } else { \
27
+ for (size_t i = 0; i < m; i++) { \
28
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
29
+ (*(u_int32_t*)(p2 + s2 * x))++; \
30
+ } \
31
+ } \
32
+ } \
33
+ \
34
+ static VALUE tDType##_bincount_32(VALUE self, size_t length) { \
35
+ size_t shape_out[1] = { length }; \
36
+ ndfunc_arg_in_t ain[1] = { { tNAryClass, 1 } }; \
37
+ ndfunc_arg_out_t aout[1] = { { numo_cUInt32, 1, shape_out } }; \
38
+ ndfunc_t ndf = { \
39
+ iter_##tDType##_bincount_32, NO_LOOP | NDF_STRIDE_LOOP | NDF_INDEX_LOOP, 1, 1, ain, aout \
40
+ }; \
41
+ return na_ndloop(&ndf, 1, self); \
42
+ } \
43
+ \
44
+ static void iter_##tDType##_bincount_64(na_loop_t* const lp) { \
45
+ char* p1; \
46
+ char* p2; \
47
+ ssize_t s1; \
48
+ ssize_t s2; \
49
+ size_t* idx1; \
50
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
51
+ INIT_PTR(lp, 1, p2, s2); \
52
+ const size_t m = lp->args[0].shape[0]; \
53
+ const size_t n = lp->args[1].shape[0]; \
54
+ \
55
+ for (size_t i = 0; i < n; i++) { \
56
+ *(u_int64_t*)(p2 + s2 * i) = 0; \
57
+ } \
58
+ \
59
+ size_t x; \
60
+ if (idx1) { \
61
+ for (size_t i = 0; i < m; i++) { \
62
+ GET_DATA_INDEX(p1, idx1, tDType, x); \
63
+ (*(u_int64_t*)(p2 + s2 * x))++; \
64
+ } \
65
+ } else { \
66
+ for (size_t i = 0; i < m; i++) { \
67
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
68
+ (*(u_int64_t*)(p2 + s2 * x))++; \
69
+ } \
70
+ } \
71
+ } \
72
+ \
73
+ static VALUE tDType##_bincount_64(VALUE self, size_t length) { \
74
+ size_t shape_out[1] = { length }; \
75
+ ndfunc_arg_in_t ain[1] = { { tNAryClass, 1 } }; \
76
+ ndfunc_arg_out_t aout[1] = { { numo_cUInt64, 1, shape_out } }; \
77
+ ndfunc_t ndf = { \
78
+ iter_##tDType##_bincount_64, NO_LOOP | NDF_STRIDE_LOOP | NDF_INDEX_LOOP, 1, 1, ain, aout \
79
+ }; \
80
+ return na_ndloop(&ndf, 1, self); \
81
+ } \
82
+ \
83
+ static void iter_##tDType##_bincount_sf(na_loop_t* const lp) { \
84
+ char* p1; \
85
+ char* p2; \
86
+ char* p3; \
87
+ ssize_t s1; \
88
+ ssize_t s2; \
89
+ ssize_t s3; \
90
+ INIT_PTR(lp, 0, p1, s1); \
91
+ INIT_PTR(lp, 1, p2, s2); \
92
+ INIT_PTR(lp, 2, p3, s3); \
93
+ const size_t l = lp->args[0].shape[0]; \
94
+ const size_t m = lp->args[1].shape[0]; \
95
+ const size_t n = lp->args[2].shape[0]; \
96
+ \
97
+ if (l != m) { \
98
+ rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight"); \
99
+ } \
100
+ \
101
+ for (size_t i = 0; i < n; i++) { \
102
+ *(float*)(p3 + s3 * i) = 0; \
103
+ } \
104
+ size_t x; \
105
+ float w; \
106
+ for (size_t i = 0; i < l; i++) { \
107
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
108
+ GET_DATA_STRIDE(p2, s2, float, w); \
109
+ (*(float*)(p3 + s3 * x)) += w; \
110
+ } \
111
+ } \
112
+ \
113
+ static VALUE tDType##_bincount_sf(VALUE self, VALUE weight, size_t length) { \
114
+ size_t shape_out[1] = { length }; \
115
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 1 }, { numo_cSFloat, 1 } }; \
116
+ ndfunc_arg_out_t aout[1] = { { numo_cSFloat, 1, shape_out } }; \
117
+ ndfunc_t ndf = { \
118
+ iter_##tDType##_bincount_sf, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout \
119
+ }; \
120
+ return na_ndloop(&ndf, 2, self, weight); \
121
+ } \
122
+ \
123
+ static void iter_##tDType##_bincount_df(na_loop_t* const lp) { \
124
+ char* p1; \
125
+ char* p2; \
126
+ char* p3; \
127
+ ssize_t s1; \
128
+ ssize_t s2; \
129
+ ssize_t s3; \
130
+ INIT_PTR(lp, 0, p1, s1); \
131
+ INIT_PTR(lp, 1, p2, s2); \
132
+ INIT_PTR(lp, 2, p3, s3); \
133
+ const size_t l = lp->args[0].shape[0]; \
134
+ const size_t m = lp->args[1].shape[0]; \
135
+ const size_t n = lp->args[2].shape[0]; \
136
+ \
137
+ if (l != m) { \
138
+ rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight"); \
139
+ } \
140
+ \
141
+ for (size_t i = 0; i < n; i++) { \
142
+ *(double*)(p3 + s3 * i) = 0; \
143
+ } \
144
+ size_t x; \
145
+ double w; \
146
+ for (size_t i = 0; i < l; i++) { \
147
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
148
+ GET_DATA_STRIDE(p2, s2, double, w); \
149
+ (*(double*)(p3 + s3 * x)) += w; \
150
+ } \
151
+ } \
152
+ \
153
+ static VALUE tDType##_bincount_df(VALUE self, VALUE weight, size_t length) { \
154
+ size_t shape_out[1] = { length }; \
155
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 1 }, { numo_cDFloat, 1 } }; \
156
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 1, shape_out } }; \
157
+ ndfunc_t ndf = { \
158
+ iter_##tDType##_bincount_df, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout \
159
+ }; \
160
+ return na_ndloop(&ndf, 2, self, weight); \
161
+ }
162
+
163
+ #define DEF_NARRAY_INT_BINCOUNT_METHOD_FUNC(tDType, tNAryClass) \
164
+ DEF_BINCOUNT_FUNCS(tDType, tNAryClass) \
165
+ static VALUE tDType##_bincount(int argc, VALUE* argv, VALUE self) { \
166
+ VALUE weight = Qnil; \
167
+ VALUE kw = Qnil; \
168
+ VALUE opts[1] = { Qundef }; \
169
+ ID table[1] = { id_minlength }; \
170
+ rb_scan_args(argc, argv, "01:", &weight, &kw); \
171
+ rb_get_kwargs(kw, table, 0, 1, opts); \
172
+ \
173
+ VALUE v = tDType##_minmax(0, 0, self); \
174
+ if (m_num_to_data(RARRAY_AREF(v, 0)) < 0) { \
175
+ rb_raise(rb_eArgError, "array items must be non-netagive"); \
176
+ } \
177
+ v = RARRAY_AREF(v, 1); \
178
+ \
179
+ size_t length = NUM2SIZET(v) + 1; \
180
+ if (opts[0] != Qundef) { \
181
+ const size_t minlength = NUM2SIZET(opts[0]); \
182
+ if (minlength > length) { \
183
+ length = minlength; \
184
+ } \
185
+ } \
186
+ \
187
+ if (NIL_P(weight)) { \
188
+ if (length > 4294967295ul) { \
189
+ return tDType##_bincount_64(self, length); \
190
+ } \
191
+ return tDType##_bincount_32(self, length); \
192
+ } else { \
193
+ if (rb_obj_class(weight) == numo_cSFloat) { \
194
+ return tDType##_bincount_sf(self, weight, length); \
195
+ } \
196
+ return tDType##_bincount_df(self, weight, length); \
197
+ } \
198
+ }
199
+
200
+ #define DEF_NARRAY_UINT_BINCOUNT_METHOD_FUNC(tDType, tNAryClass) \
201
+ DEF_BINCOUNT_FUNCS(tDType, tNAryClass) \
202
+ static VALUE tDType##_bincount(int argc, VALUE* argv, VALUE self) { \
203
+ VALUE weight = Qnil; \
204
+ VALUE kw = Qnil; \
205
+ VALUE opts[1] = { Qundef }; \
206
+ ID table[1] = { id_minlength }; \
207
+ rb_scan_args(argc, argv, "01:", &weight, &kw); \
208
+ rb_get_kwargs(kw, table, 0, 1, opts); \
209
+ \
210
+ VALUE v = tDType##_max(0, 0, self); \
211
+ \
212
+ size_t length = NUM2SIZET(v) + 1; \
213
+ if (opts[0] != Qundef) { \
214
+ const size_t minlength = NUM2SIZET(opts[0]); \
215
+ if (minlength > length) { \
216
+ length = minlength; \
217
+ } \
218
+ } \
219
+ \
220
+ if (NIL_P(weight)) { \
221
+ if (length > 4294967295ul) { \
222
+ return tDType##_bincount_64(self, length); \
223
+ } \
224
+ return tDType##_bincount_32(self, length); \
225
+ } else { \
226
+ if (rb_obj_class(weight) == numo_cSFloat) { \
227
+ return tDType##_bincount_sf(self, weight, length); \
228
+ } \
229
+ return tDType##_bincount_df(self, weight, length); \
230
+ } \
231
+ }
232
+
233
+ #endif /* NUMO_NARRAY_MH_BINCOUNT_H */
@@ -0,0 +1,225 @@
1
+ #ifndef NUMO_NARRAY_MH_BIT_AND_H
2
+ #define NUMO_NARRAY_MH_BIT_AND_H 1
3
+
4
+ #define DEF_NARRAY_INT_BIT_AND_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_bit_and(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_and(((tDType*)p1)[i], ((tDType*)p2)[i]); \
23
+ } \
24
+ } else { \
25
+ for (size_t i = 0; i < n; i++) { \
26
+ ((tDType*)p3)[i] = m_bit_and(((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_and(((tDType*)p1)[i], *(tDType*)p2); \
38
+ } \
39
+ } else { \
40
+ for (size_t i = 0; i < n; i++) { \
41
+ ((tDType*)p3)[i] = m_bit_and(((tDType*)p1)[i], *(tDType*)p2); \
42
+ } \
43
+ } \
44
+ } else { \
45
+ for (size_t i = 0; i < n; i++) { \
46
+ *(tDType*)p3 = m_bit_and(*(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_and(*(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_and(*(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_and(x, y); \
76
+ SET_DATA_STRIDE(p3, s3, tDType, z); \
77
+ } \
78
+ } \
79
+ \
80
+ static VALUE tDType##_bit_and_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_and, STRIDE_LOOP, 2, 1, ain, aout }; \
84
+ return na_ndloop(&ndf, 2, self, other); \
85
+ } \
86
+ \
87
+ static VALUE tDType##_bit_and(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_and_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_AND_METHOD_FUNC(tDType, tNAryClass) \
98
+ static void iter_##tDType##_bit_and(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_and(((tDType*)p1)[i], *(tDType*)p2); \
115
+ } \
116
+ } else { \
117
+ for (size_t i = 0; i < n; i++) { \
118
+ ((tDType*)p3)[i] = m_bit_and(((tDType*)p1)[i], *(tDType*)p2); \
119
+ } \
120
+ } \
121
+ } else { \
122
+ for (size_t i = 0; i < n; i++) { \
123
+ *(tDType*)p3 = m_bit_and(*(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_and(*(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_and(*(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_and_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_and, STRIDE_LOOP, 2, 1, ain, aout }; \
151
+ return na_ndloop(&ndf, 2, self, other); \
152
+ } \
153
+ \
154
+ static VALUE tDType##_bit_and(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_and_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_AND_METHOD_FUNC() \
165
+ static void iter_robject_bit_and(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_and(((robject*)p1)[i], *(robject*)p2); \
182
+ } \
183
+ } else { \
184
+ for (size_t i = 0; i < n; i++) { \
185
+ ((robject*)p3)[i] = m_bit_and(((robject*)p1)[i], *(robject*)p2); \
186
+ } \
187
+ } \
188
+ } else { \
189
+ for (size_t i = 0; i < n; i++) { \
190
+ *(robject*)p3 = m_bit_and(*(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_and(*(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_and(*(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_and_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_and, STRIDE_LOOP, 2, 1, ain, aout }; \
218
+ return na_ndloop(&ndf, 2, self, other); \
219
+ } \
220
+ \
221
+ static VALUE robject_bit_and(VALUE self, VALUE other) { \
222
+ return robject_bit_and_self(self, other); \
223
+ }
224
+
225
+ #endif /* NUMO_NARRAY_MH_BIT_AND_H */