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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90bcb68c4b90224af8196f103f31646f653f9a495ff7b47e24c1f03c3ba8f3d2
|
|
4
|
+
data.tar.gz: f3105f5bd8c5a2ae27a21ac27f05ad7382a2db76a13529639951ecd98459462b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7e81366c927e13e1da39ab2675d9dd11ba75498ee144570728eaf8f9181b471a83d5b7034fdc6e3ce155cbe080f64444c0f17316f64c854d34e950de7b8398b4
|
|
7
|
+
data.tar.gz: a18a12e36781c4a06f02e2e92835778559e5afa3d3fed7c1b71a257bd7ed91e5523c856db685a1b3c3a527c9dc43f54e229df545a6edfafeaf539c136331ae42
|
data/Gemfile
CHANGED
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/)
|
|
@@ -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 */
|