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.
- 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/minus.h +125 -0
- 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/pow.h +197 -0
- data/ext/numo/narray/src/mh/rand.h +2 -2
- data/ext/numo/narray/src/mh/rand_norm.h +125 -0
- data/ext/numo/narray/src/mh/reciprocal.h +125 -0
- 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/sign.h +125 -0
- data/ext/numo/narray/src/mh/square.h +125 -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 +457 -2075
- data/ext/numo/narray/src/t_dfloat.c +154 -2560
- data/ext/numo/narray/src/t_int16.c +408 -2542
- data/ext/numo/narray/src/t_int32.c +408 -2542
- data/ext/numo/narray/src/t_int64.c +408 -2542
- data/ext/numo/narray/src/t_int8.c +409 -2138
- data/ext/numo/narray/src/t_robject.c +376 -2161
- data/ext/numo/narray/src/t_scomplex.c +435 -2053
- data/ext/numo/narray/src/t_sfloat.c +149 -2557
- data/ext/numo/narray/src/t_uint16.c +407 -2537
- data/ext/numo/narray/src/t_uint32.c +407 -2537
- data/ext/numo/narray/src/t_uint64.c +407 -2537
- data/ext/numo/narray/src/t_uint8.c +407 -2132
- metadata +47 -2
|
@@ -43,6 +43,35 @@ static ID id_to_a;
|
|
|
43
43
|
VALUE cT;
|
|
44
44
|
extern VALUE cRT;
|
|
45
45
|
|
|
46
|
+
#include "mh/coerce_cast.h"
|
|
47
|
+
#include "mh/to_a.h"
|
|
48
|
+
#include "mh/fill.h"
|
|
49
|
+
#include "mh/format.h"
|
|
50
|
+
#include "mh/format_to_a.h"
|
|
51
|
+
#include "mh/inspect.h"
|
|
52
|
+
#include "mh/op/add.h"
|
|
53
|
+
#include "mh/op/sub.h"
|
|
54
|
+
#include "mh/op/mul.h"
|
|
55
|
+
#include "mh/op/div.h"
|
|
56
|
+
#include "mh/op/mod.h"
|
|
57
|
+
#include "mh/divmod.h"
|
|
58
|
+
#include "mh/pow.h"
|
|
59
|
+
#include "mh/minus.h"
|
|
60
|
+
#include "mh/reciprocal.h"
|
|
61
|
+
#include "mh/sign.h"
|
|
62
|
+
#include "mh/square.h"
|
|
63
|
+
#include "mh/comp/eq.h"
|
|
64
|
+
#include "mh/comp/ne.h"
|
|
65
|
+
#include "mh/comp/gt.h"
|
|
66
|
+
#include "mh/comp/ge.h"
|
|
67
|
+
#include "mh/comp/lt.h"
|
|
68
|
+
#include "mh/comp/le.h"
|
|
69
|
+
#include "mh/bit/and.h"
|
|
70
|
+
#include "mh/bit/or.h"
|
|
71
|
+
#include "mh/bit/xor.h"
|
|
72
|
+
#include "mh/bit/not.h"
|
|
73
|
+
#include "mh/bit/left_shift.h"
|
|
74
|
+
#include "mh/bit/right_shift.h"
|
|
46
75
|
#include "mh/clip.h"
|
|
47
76
|
#include "mh/sum.h"
|
|
48
77
|
#include "mh/prod.h"
|
|
@@ -56,6 +85,7 @@ extern VALUE cRT;
|
|
|
56
85
|
#include "mh/maximum.h"
|
|
57
86
|
#include "mh/minimum.h"
|
|
58
87
|
#include "mh/minmax.h"
|
|
88
|
+
#include "mh/bincount.h"
|
|
59
89
|
#include "mh/cumsum.h"
|
|
60
90
|
#include "mh/cumprod.h"
|
|
61
91
|
#include "mh/mulsum.h"
|
|
@@ -69,6 +99,35 @@ extern VALUE cRT;
|
|
|
69
99
|
|
|
70
100
|
typedef u_int32_t uint32; // Type aliases for shorter notation
|
|
71
101
|
// following the codebase naming convention.
|
|
102
|
+
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(uint32)
|
|
103
|
+
DEF_NARRAY_TO_A_METHOD_FUNC(uint32)
|
|
104
|
+
DEF_NARRAY_FILL_METHOD_FUNC(uint32)
|
|
105
|
+
DEF_NARRAY_FORMAT_METHOD_FUNC(uint32)
|
|
106
|
+
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(uint32)
|
|
107
|
+
DEF_NARRAY_INSPECT_METHOD_FUNC(uint32)
|
|
108
|
+
DEF_NARRAY_ADD_METHOD_FUNC(uint32, numo_cUInt32)
|
|
109
|
+
DEF_NARRAY_SUB_METHOD_FUNC(uint32, numo_cUInt32)
|
|
110
|
+
DEF_NARRAY_MUL_METHOD_FUNC(uint32, numo_cUInt32)
|
|
111
|
+
DEF_NARRAY_INT_DIV_METHOD_FUNC(uint32, numo_cUInt32)
|
|
112
|
+
DEF_NARRAY_INT_MOD_METHOD_FUNC(uint32, numo_cUInt32)
|
|
113
|
+
DEF_NARRAY_INT_DIVMOD_METHOD_FUNC(uint32, numo_cUInt32)
|
|
114
|
+
DEF_NARRAY_POW_METHOD_FUNC(uint32, numo_cUInt32)
|
|
115
|
+
DEF_NARRAY_MINUS_METHOD_FUNC(uint32, numo_cUInt32)
|
|
116
|
+
DEF_NARRAY_RECIPROCAL_METHOD_FUNC(uint32, numo_cUInt32)
|
|
117
|
+
DEF_NARRAY_SIGN_METHOD_FUNC(uint32, numo_cUInt32)
|
|
118
|
+
DEF_NARRAY_SQUARE_METHOD_FUNC(uint32, numo_cUInt32)
|
|
119
|
+
DEF_NARRAY_EQ_METHOD_FUNC(uint32, numo_cUInt32)
|
|
120
|
+
DEF_NARRAY_NE_METHOD_FUNC(uint32, numo_cUInt32)
|
|
121
|
+
DEF_NARRAY_GT_METHOD_FUNC(uint32, numo_cUInt32)
|
|
122
|
+
DEF_NARRAY_GE_METHOD_FUNC(uint32, numo_cUInt32)
|
|
123
|
+
DEF_NARRAY_LT_METHOD_FUNC(uint32, numo_cUInt32)
|
|
124
|
+
DEF_NARRAY_LE_METHOD_FUNC(uint32, numo_cUInt32)
|
|
125
|
+
DEF_NARRAY_INT_BIT_AND_METHOD_FUNC(uint32, numo_cUInt32)
|
|
126
|
+
DEF_NARRAY_INT_BIT_OR_METHOD_FUNC(uint32, numo_cUInt32)
|
|
127
|
+
DEF_NARRAY_INT_BIT_XOR_METHOD_FUNC(uint32, numo_cUInt32)
|
|
128
|
+
DEF_NARRAY_INT_BIT_NOT_METHOD_FUNC(uint32, numo_cUInt32)
|
|
129
|
+
DEF_NARRAY_INT_LEFT_SHIFT_METHOD_FUNC(uint32, numo_cUInt32)
|
|
130
|
+
DEF_NARRAY_INT_RIGHT_SHIFT_METHOD_FUNC(uint32, numo_cUInt32)
|
|
72
131
|
DEF_NARRAY_CLIP_METHOD_FUNC(uint32, numo_cUInt32)
|
|
73
132
|
DEF_NARRAY_INT_SUM_METHOD_FUNC(uint32, numo_cUInt32, u_int64_t, numo_cUInt64)
|
|
74
133
|
DEF_NARRAY_INT_PROD_METHOD_FUNC(uint32, numo_cUInt32, u_int64_t, numo_cUInt64)
|
|
@@ -82,6 +141,7 @@ DEF_NARRAY_INT_ARGMIN_METHOD_FUNC(uint32)
|
|
|
82
141
|
DEF_NARRAY_INT_MAXIMUM_METHOD_FUNC(uint32, numo_cUInt32)
|
|
83
142
|
DEF_NARRAY_INT_MINIMUM_METHOD_FUNC(uint32, numo_cUInt32)
|
|
84
143
|
DEF_NARRAY_INT_MINMAX_METHOD_FUNC(uint32, numo_cUInt32)
|
|
144
|
+
DEF_NARRAY_UINT_BINCOUNT_METHOD_FUNC(uint32, numo_cUInt32)
|
|
85
145
|
DEF_NARRAY_INT_CUMSUM_METHOD_FUNC(uint32, numo_cUInt32)
|
|
86
146
|
DEF_NARRAY_INT_CUMPROD_METHOD_FUNC(uint32, numo_cUInt32)
|
|
87
147
|
DEF_NARRAY_INT_MULSUM_METHOD_FUNC(uint32, numo_cUInt32)
|
|
@@ -1252,204 +1312,6 @@ static VALUE uint32_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1252
1312
|
return argv[argc];
|
|
1253
1313
|
}
|
|
1254
1314
|
|
|
1255
|
-
/*
|
|
1256
|
-
return NArray with cast to the type of self.
|
|
1257
|
-
@overload coerce_cast(type)
|
|
1258
|
-
@return [nil]
|
|
1259
|
-
*/
|
|
1260
|
-
static VALUE uint32_coerce_cast(VALUE self, VALUE type) {
|
|
1261
|
-
return Qnil;
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
static void iter_uint32_to_a(na_loop_t* const lp) {
|
|
1265
|
-
size_t i, s1;
|
|
1266
|
-
char* p1;
|
|
1267
|
-
size_t* idx1;
|
|
1268
|
-
dtype x;
|
|
1269
|
-
volatile VALUE a, y;
|
|
1270
|
-
|
|
1271
|
-
INIT_COUNTER(lp, i);
|
|
1272
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1273
|
-
a = rb_ary_new2(i);
|
|
1274
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1275
|
-
if (idx1) {
|
|
1276
|
-
for (; i--;) {
|
|
1277
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1278
|
-
y = m_data_to_num(x);
|
|
1279
|
-
rb_ary_push(a, y);
|
|
1280
|
-
}
|
|
1281
|
-
} else {
|
|
1282
|
-
for (; i--;) {
|
|
1283
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1284
|
-
y = m_data_to_num(x);
|
|
1285
|
-
rb_ary_push(a, y);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
/*
|
|
1291
|
-
Convert self to Array.
|
|
1292
|
-
@overload to_a
|
|
1293
|
-
@return [Array]
|
|
1294
|
-
*/
|
|
1295
|
-
static VALUE uint32_to_a(VALUE self) {
|
|
1296
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1297
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1298
|
-
ndfunc_t ndf = { iter_uint32_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1299
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
static void iter_uint32_fill(na_loop_t* const lp) {
|
|
1303
|
-
size_t i;
|
|
1304
|
-
char* p1;
|
|
1305
|
-
ssize_t s1;
|
|
1306
|
-
size_t* idx1;
|
|
1307
|
-
VALUE x = lp->option;
|
|
1308
|
-
dtype y;
|
|
1309
|
-
INIT_COUNTER(lp, i);
|
|
1310
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1311
|
-
y = m_num_to_data(x);
|
|
1312
|
-
if (idx1) {
|
|
1313
|
-
for (; i--;) {
|
|
1314
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
1315
|
-
}
|
|
1316
|
-
} else {
|
|
1317
|
-
for (; i--;) {
|
|
1318
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
/*
|
|
1324
|
-
Fill elements with other.
|
|
1325
|
-
@overload fill other
|
|
1326
|
-
@param [Numeric] other
|
|
1327
|
-
@return [Numo::UInt32] self.
|
|
1328
|
-
*/
|
|
1329
|
-
static VALUE uint32_fill(VALUE self, VALUE val) {
|
|
1330
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
|
|
1331
|
-
ndfunc_t ndf = { iter_uint32_fill, FULL_LOOP, 2, 0, ain, 0 };
|
|
1332
|
-
|
|
1333
|
-
na_ndloop(&ndf, 2, self, val);
|
|
1334
|
-
return self;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
static VALUE format_uint32(VALUE fmt, dtype* x) {
|
|
1338
|
-
// fix-me
|
|
1339
|
-
char s[48];
|
|
1340
|
-
int n;
|
|
1341
|
-
|
|
1342
|
-
if (NIL_P(fmt)) {
|
|
1343
|
-
n = m_sprintf(s, *x);
|
|
1344
|
-
return rb_str_new(s, n);
|
|
1345
|
-
}
|
|
1346
|
-
return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
static void iter_uint32_format(na_loop_t* const lp) {
|
|
1350
|
-
size_t i;
|
|
1351
|
-
char *p1, *p2;
|
|
1352
|
-
ssize_t s1, s2;
|
|
1353
|
-
size_t* idx1;
|
|
1354
|
-
dtype* x;
|
|
1355
|
-
VALUE y;
|
|
1356
|
-
VALUE fmt = lp->option;
|
|
1357
|
-
INIT_COUNTER(lp, i);
|
|
1358
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1359
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1360
|
-
if (idx1) {
|
|
1361
|
-
for (; i--;) {
|
|
1362
|
-
x = (dtype*)(p1 + *idx1);
|
|
1363
|
-
idx1++;
|
|
1364
|
-
y = format_uint32(fmt, x);
|
|
1365
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1366
|
-
}
|
|
1367
|
-
} else {
|
|
1368
|
-
for (; i--;) {
|
|
1369
|
-
x = (dtype*)p1;
|
|
1370
|
-
p1 += s1;
|
|
1371
|
-
y = format_uint32(fmt, x);
|
|
1372
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
/*
|
|
1378
|
-
Format elements into strings.
|
|
1379
|
-
@overload format format
|
|
1380
|
-
@param [String] format
|
|
1381
|
-
@return [Numo::RObject] array of formatted strings.
|
|
1382
|
-
*/
|
|
1383
|
-
static VALUE uint32_format(int argc, VALUE* argv, VALUE self) {
|
|
1384
|
-
VALUE fmt = Qnil;
|
|
1385
|
-
|
|
1386
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
|
|
1387
|
-
ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
|
|
1388
|
-
ndfunc_t ndf = { iter_uint32_format, FULL_LOOP_NIP, 2, 1, ain, aout };
|
|
1389
|
-
|
|
1390
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1391
|
-
return na_ndloop(&ndf, 2, self, fmt);
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
static void iter_uint32_format_to_a(na_loop_t* const lp) {
|
|
1395
|
-
size_t i;
|
|
1396
|
-
char* p1;
|
|
1397
|
-
ssize_t s1;
|
|
1398
|
-
size_t* idx1;
|
|
1399
|
-
dtype* x;
|
|
1400
|
-
VALUE y;
|
|
1401
|
-
volatile VALUE a;
|
|
1402
|
-
VALUE fmt = lp->option;
|
|
1403
|
-
INIT_COUNTER(lp, i);
|
|
1404
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1405
|
-
a = rb_ary_new2(i);
|
|
1406
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1407
|
-
if (idx1) {
|
|
1408
|
-
for (; i--;) {
|
|
1409
|
-
x = (dtype*)(p1 + *idx1);
|
|
1410
|
-
idx1++;
|
|
1411
|
-
y = format_uint32(fmt, x);
|
|
1412
|
-
rb_ary_push(a, y);
|
|
1413
|
-
}
|
|
1414
|
-
} else {
|
|
1415
|
-
for (; i--;) {
|
|
1416
|
-
x = (dtype*)p1;
|
|
1417
|
-
p1 += s1;
|
|
1418
|
-
y = format_uint32(fmt, x);
|
|
1419
|
-
rb_ary_push(a, y);
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
/*
|
|
1425
|
-
Format elements into strings.
|
|
1426
|
-
@overload format_to_a format
|
|
1427
|
-
@param [String] format
|
|
1428
|
-
@return [Array] array of formatted strings.
|
|
1429
|
-
*/
|
|
1430
|
-
static VALUE uint32_format_to_a(int argc, VALUE* argv, VALUE self) {
|
|
1431
|
-
VALUE fmt = Qnil;
|
|
1432
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1433
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1434
|
-
ndfunc_t ndf = { iter_uint32_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1435
|
-
|
|
1436
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1437
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
static VALUE iter_uint32_inspect(char* ptr, size_t pos, VALUE fmt) {
|
|
1441
|
-
return format_uint32(fmt, (dtype*)(ptr + pos));
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
/*
|
|
1445
|
-
Returns a string containing a human-readable representation of NArray.
|
|
1446
|
-
@overload inspect
|
|
1447
|
-
@return [String]
|
|
1448
|
-
*/
|
|
1449
|
-
static VALUE uint32_inspect(VALUE ary) {
|
|
1450
|
-
return na_ndloop_inspect(ary, iter_uint32_inspect, Qnil);
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
1315
|
static void iter_uint32_each(na_loop_t* const lp) {
|
|
1454
1316
|
size_t i, s1;
|
|
1455
1317
|
char* p1;
|
|
@@ -1588,2383 +1450,194 @@ static void iter_uint32_each_with_index(na_loop_t* const lp) {
|
|
|
1588
1450
|
|
|
1589
1451
|
c = (size_t*)(lp->opt_ptr);
|
|
1590
1452
|
nd = lp->ndim;
|
|
1591
|
-
if (nd > 0) {
|
|
1592
|
-
nd--;
|
|
1593
|
-
}
|
|
1594
|
-
md = nd + 2;
|
|
1595
|
-
a = ALLOCA_N(VALUE, md);
|
|
1596
|
-
|
|
1597
|
-
INIT_COUNTER(lp, i);
|
|
1598
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1599
|
-
c[nd] = 0;
|
|
1600
|
-
if (idx1) {
|
|
1601
|
-
for (; i--;) {
|
|
1602
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1603
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1604
|
-
c[nd]++;
|
|
1605
|
-
}
|
|
1606
|
-
} else {
|
|
1607
|
-
for (; i--;) {
|
|
1608
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1609
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1610
|
-
c[nd]++;
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
/*
|
|
1616
|
-
Invokes the given block once for each element of self,
|
|
1617
|
-
passing that element and indices along each axis as parameters.
|
|
1618
|
-
@overload each_with_index
|
|
1619
|
-
For a block `{|x,i,j,...| ... }`,
|
|
1620
|
-
@yieldparam [Numeric] x an element
|
|
1621
|
-
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1622
|
-
@return [Numo::NArray] self
|
|
1623
|
-
@see #each
|
|
1624
|
-
@see #map_with_index
|
|
1625
|
-
*/
|
|
1626
|
-
static VALUE uint32_each_with_index(VALUE self) {
|
|
1627
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1628
|
-
ndfunc_t ndf = { iter_uint32_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1629
|
-
|
|
1630
|
-
na_ndloop_with_index(&ndf, 1, self);
|
|
1631
|
-
return self;
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
static inline dtype yield_map_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1635
|
-
int j;
|
|
1636
|
-
VALUE y;
|
|
1637
|
-
|
|
1638
|
-
a[0] = m_data_to_num(x);
|
|
1639
|
-
for (j = 0; j <= nd; j++) {
|
|
1640
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1641
|
-
}
|
|
1642
|
-
y = rb_yield(rb_ary_new4(md, a));
|
|
1643
|
-
return m_num_to_data(y);
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
static void iter_uint32_map_with_index(na_loop_t* const lp) {
|
|
1647
|
-
size_t i;
|
|
1648
|
-
char *p1, *p2;
|
|
1649
|
-
ssize_t s1, s2;
|
|
1650
|
-
size_t *idx1, *idx2;
|
|
1651
|
-
dtype x;
|
|
1652
|
-
VALUE* a;
|
|
1653
|
-
size_t* c;
|
|
1654
|
-
int nd, md;
|
|
1655
|
-
|
|
1656
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1657
|
-
nd = lp->ndim;
|
|
1658
|
-
if (nd > 0) {
|
|
1659
|
-
nd--;
|
|
1660
|
-
}
|
|
1661
|
-
md = nd + 2;
|
|
1662
|
-
a = ALLOCA_N(VALUE, md);
|
|
1663
|
-
|
|
1664
|
-
INIT_COUNTER(lp, i);
|
|
1665
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1666
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1667
|
-
|
|
1668
|
-
c[nd] = 0;
|
|
1669
|
-
if (idx1) {
|
|
1670
|
-
if (idx2) {
|
|
1671
|
-
for (; i--;) {
|
|
1672
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1673
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1674
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1675
|
-
c[nd]++;
|
|
1676
|
-
}
|
|
1677
|
-
} else {
|
|
1678
|
-
for (; i--;) {
|
|
1679
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1680
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1681
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1682
|
-
c[nd]++;
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
} else {
|
|
1686
|
-
if (idx2) {
|
|
1687
|
-
for (; i--;) {
|
|
1688
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1689
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1690
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1691
|
-
c[nd]++;
|
|
1692
|
-
}
|
|
1693
|
-
} else {
|
|
1694
|
-
for (; i--;) {
|
|
1695
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1696
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1697
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1698
|
-
c[nd]++;
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
/*
|
|
1705
|
-
Invokes the given block once for each element of self,
|
|
1706
|
-
passing that element and indices along each axis as parameters.
|
|
1707
|
-
Creates a new NArray containing the values returned by the block.
|
|
1708
|
-
Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
|
1709
|
-
@overload map_with_index
|
|
1710
|
-
For a block `{|x,i,j,...| ... }`,
|
|
1711
|
-
@yieldparam [Numeric] x an element
|
|
1712
|
-
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1713
|
-
@return [Numo::NArray] mapped array
|
|
1714
|
-
@see #map
|
|
1715
|
-
@see #each_with_index
|
|
1716
|
-
*/
|
|
1717
|
-
static VALUE uint32_map_with_index(VALUE self) {
|
|
1718
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1719
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1720
|
-
ndfunc_t ndf = { iter_uint32_map_with_index, FULL_LOOP, 1, 1, ain, aout };
|
|
1721
|
-
|
|
1722
|
-
return na_ndloop_with_index(&ndf, 1, self);
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
static void iter_uint32_abs(na_loop_t* const lp) {
|
|
1726
|
-
size_t i;
|
|
1727
|
-
char *p1, *p2;
|
|
1728
|
-
ssize_t s1, s2;
|
|
1729
|
-
size_t *idx1, *idx2;
|
|
1730
|
-
dtype x;
|
|
1731
|
-
rtype y;
|
|
1732
|
-
INIT_COUNTER(lp, i);
|
|
1733
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1734
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1735
|
-
if (idx1) {
|
|
1736
|
-
if (idx2) {
|
|
1737
|
-
for (; i--;) {
|
|
1738
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1739
|
-
y = m_abs(x);
|
|
1740
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1741
|
-
}
|
|
1742
|
-
} else {
|
|
1743
|
-
for (; i--;) {
|
|
1744
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1745
|
-
y = m_abs(x);
|
|
1746
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
} else {
|
|
1750
|
-
if (idx2) {
|
|
1751
|
-
for (; i--;) {
|
|
1752
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1753
|
-
y = m_abs(x);
|
|
1754
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1755
|
-
}
|
|
1756
|
-
} else {
|
|
1757
|
-
for (; i--;) {
|
|
1758
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1759
|
-
y = m_abs(x);
|
|
1760
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
/*
|
|
1767
|
-
abs of self.
|
|
1768
|
-
@overload abs
|
|
1769
|
-
@return [Numo::UInt32] abs of self.
|
|
1770
|
-
*/
|
|
1771
|
-
static VALUE uint32_abs(VALUE self) {
|
|
1772
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1773
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
1774
|
-
ndfunc_t ndf = { iter_uint32_abs, FULL_LOOP, 1, 1, ain, aout };
|
|
1775
|
-
|
|
1776
|
-
return na_ndloop(&ndf, 1, self);
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
#define check_intdivzero(y) \
|
|
1780
|
-
{}
|
|
1781
|
-
|
|
1782
|
-
static void iter_uint32_add(na_loop_t* const lp) {
|
|
1783
|
-
size_t i = 0;
|
|
1784
|
-
size_t n;
|
|
1785
|
-
char *p1, *p2, *p3;
|
|
1786
|
-
ssize_t s1, s2, s3;
|
|
1787
|
-
|
|
1788
|
-
INIT_COUNTER(lp, n);
|
|
1789
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
1790
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1791
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1792
|
-
|
|
1793
|
-
//
|
|
1794
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
1795
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
1796
|
-
|
|
1797
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1798
|
-
if (p1 == p3) { // inplace case
|
|
1799
|
-
for (; i < n; i++) {
|
|
1800
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
1801
|
-
((dtype*)p1)[i] = m_add(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
1802
|
-
}
|
|
1803
|
-
} else {
|
|
1804
|
-
for (; i < n; i++) {
|
|
1805
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
1806
|
-
((dtype*)p3)[i] = m_add(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
return;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
1813
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
1814
|
-
//
|
|
1815
|
-
|
|
1816
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
1817
|
-
check_intdivzero(*(dtype*)p2);
|
|
1818
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1819
|
-
if (p1 == p3) { // inplace case
|
|
1820
|
-
for (; i < n; i++) {
|
|
1821
|
-
((dtype*)p1)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1822
|
-
}
|
|
1823
|
-
} else {
|
|
1824
|
-
for (; i < n; i++) {
|
|
1825
|
-
((dtype*)p3)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
} else {
|
|
1829
|
-
for (i = 0; i < n; i++) {
|
|
1830
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1831
|
-
p1 += s1;
|
|
1832
|
-
p3 += s3;
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
} else {
|
|
1836
|
-
if (p1 == p3) { // inplace case
|
|
1837
|
-
for (i = 0; i < n; i++) {
|
|
1838
|
-
check_intdivzero(*(dtype*)p2);
|
|
1839
|
-
*(dtype*)p1 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1840
|
-
p1 += s1;
|
|
1841
|
-
p2 += s2;
|
|
1842
|
-
}
|
|
1843
|
-
} else {
|
|
1844
|
-
for (i = 0; i < n; i++) {
|
|
1845
|
-
check_intdivzero(*(dtype*)p2);
|
|
1846
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1847
|
-
p1 += s1;
|
|
1848
|
-
p2 += s2;
|
|
1849
|
-
p3 += s3;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
return;
|
|
1855
|
-
//
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
for (i = 0; i < n; i++) {
|
|
1859
|
-
dtype x, y, z;
|
|
1860
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1861
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
1862
|
-
check_intdivzero(y);
|
|
1863
|
-
z = m_add(x, y);
|
|
1864
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
1865
|
-
}
|
|
1866
|
-
//
|
|
1867
|
-
}
|
|
1868
|
-
#undef check_intdivzero
|
|
1869
|
-
|
|
1870
|
-
static VALUE uint32_add_self(VALUE self, VALUE other) {
|
|
1871
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1872
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1873
|
-
ndfunc_t ndf = { iter_uint32_add, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1874
|
-
|
|
1875
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
/*
|
|
1879
|
-
Binary add.
|
|
1880
|
-
@overload + other
|
|
1881
|
-
@param [Numo::NArray,Numeric] other
|
|
1882
|
-
@return [Numo::NArray] self + other
|
|
1883
|
-
*/
|
|
1884
|
-
static VALUE uint32_add(VALUE self, VALUE other) {
|
|
1885
|
-
|
|
1886
|
-
VALUE klass, v;
|
|
1887
|
-
|
|
1888
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
1889
|
-
if (klass == cT) {
|
|
1890
|
-
return uint32_add_self(self, other);
|
|
1891
|
-
} else {
|
|
1892
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
1893
|
-
return rb_funcall(v, '+', 1, other);
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
#define check_intdivzero(y) \
|
|
1898
|
-
{}
|
|
1899
|
-
|
|
1900
|
-
static void iter_uint32_sub(na_loop_t* const lp) {
|
|
1901
|
-
size_t i = 0;
|
|
1902
|
-
size_t n;
|
|
1903
|
-
char *p1, *p2, *p3;
|
|
1904
|
-
ssize_t s1, s2, s3;
|
|
1905
|
-
|
|
1906
|
-
INIT_COUNTER(lp, n);
|
|
1907
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
1908
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1909
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1910
|
-
|
|
1911
|
-
//
|
|
1912
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
1913
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
1914
|
-
|
|
1915
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1916
|
-
if (p1 == p3) { // inplace case
|
|
1917
|
-
for (; i < n; i++) {
|
|
1918
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
1919
|
-
((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
1920
|
-
}
|
|
1921
|
-
} else {
|
|
1922
|
-
for (; i < n; i++) {
|
|
1923
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
1924
|
-
((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
return;
|
|
1928
|
-
}
|
|
1929
|
-
|
|
1930
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
1931
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
1932
|
-
//
|
|
1933
|
-
|
|
1934
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
1935
|
-
check_intdivzero(*(dtype*)p2);
|
|
1936
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1937
|
-
if (p1 == p3) { // inplace case
|
|
1938
|
-
for (; i < n; i++) {
|
|
1939
|
-
((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
1940
|
-
}
|
|
1941
|
-
} else {
|
|
1942
|
-
for (; i < n; i++) {
|
|
1943
|
-
((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
} else {
|
|
1947
|
-
for (i = 0; i < n; i++) {
|
|
1948
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1949
|
-
p1 += s1;
|
|
1950
|
-
p3 += s3;
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
} else {
|
|
1954
|
-
if (p1 == p3) { // inplace case
|
|
1955
|
-
for (i = 0; i < n; i++) {
|
|
1956
|
-
check_intdivzero(*(dtype*)p2);
|
|
1957
|
-
*(dtype*)p1 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1958
|
-
p1 += s1;
|
|
1959
|
-
p2 += s2;
|
|
1960
|
-
}
|
|
1961
|
-
} else {
|
|
1962
|
-
for (i = 0; i < n; i++) {
|
|
1963
|
-
check_intdivzero(*(dtype*)p2);
|
|
1964
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1965
|
-
p1 += s1;
|
|
1966
|
-
p2 += s2;
|
|
1967
|
-
p3 += s3;
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
return;
|
|
1973
|
-
//
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
for (i = 0; i < n; i++) {
|
|
1977
|
-
dtype x, y, z;
|
|
1978
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1979
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
1980
|
-
check_intdivzero(y);
|
|
1981
|
-
z = m_sub(x, y);
|
|
1982
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
1983
|
-
}
|
|
1984
|
-
//
|
|
1985
|
-
}
|
|
1986
|
-
#undef check_intdivzero
|
|
1987
|
-
|
|
1988
|
-
static VALUE uint32_sub_self(VALUE self, VALUE other) {
|
|
1989
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1990
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1991
|
-
ndfunc_t ndf = { iter_uint32_sub, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1992
|
-
|
|
1993
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
|
-
/*
|
|
1997
|
-
Binary sub.
|
|
1998
|
-
@overload - other
|
|
1999
|
-
@param [Numo::NArray,Numeric] other
|
|
2000
|
-
@return [Numo::NArray] self - other
|
|
2001
|
-
*/
|
|
2002
|
-
static VALUE uint32_sub(VALUE self, VALUE other) {
|
|
2003
|
-
|
|
2004
|
-
VALUE klass, v;
|
|
2005
|
-
|
|
2006
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2007
|
-
if (klass == cT) {
|
|
2008
|
-
return uint32_sub_self(self, other);
|
|
2009
|
-
} else {
|
|
2010
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2011
|
-
return rb_funcall(v, '-', 1, other);
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
#define check_intdivzero(y) \
|
|
2016
|
-
{}
|
|
2017
|
-
|
|
2018
|
-
static void iter_uint32_mul(na_loop_t* const lp) {
|
|
2019
|
-
size_t i = 0;
|
|
2020
|
-
size_t n;
|
|
2021
|
-
char *p1, *p2, *p3;
|
|
2022
|
-
ssize_t s1, s2, s3;
|
|
2023
|
-
|
|
2024
|
-
INIT_COUNTER(lp, n);
|
|
2025
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2026
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2027
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2028
|
-
|
|
2029
|
-
//
|
|
2030
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2031
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
2032
|
-
|
|
2033
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2034
|
-
if (p1 == p3) { // inplace case
|
|
2035
|
-
for (; i < n; i++) {
|
|
2036
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2037
|
-
((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2038
|
-
}
|
|
2039
|
-
} else {
|
|
2040
|
-
for (; i < n; i++) {
|
|
2041
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2042
|
-
((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
return;
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2049
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2050
|
-
//
|
|
2051
|
-
|
|
2052
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2053
|
-
check_intdivzero(*(dtype*)p2);
|
|
2054
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2055
|
-
if (p1 == p3) { // inplace case
|
|
2056
|
-
for (; i < n; i++) {
|
|
2057
|
-
((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
2058
|
-
}
|
|
2059
|
-
} else {
|
|
2060
|
-
for (; i < n; i++) {
|
|
2061
|
-
((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
} else {
|
|
2065
|
-
for (i = 0; i < n; i++) {
|
|
2066
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
2067
|
-
p1 += s1;
|
|
2068
|
-
p3 += s3;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
} else {
|
|
2072
|
-
if (p1 == p3) { // inplace case
|
|
2073
|
-
for (i = 0; i < n; i++) {
|
|
2074
|
-
check_intdivzero(*(dtype*)p2);
|
|
2075
|
-
*(dtype*)p1 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
2076
|
-
p1 += s1;
|
|
2077
|
-
p2 += s2;
|
|
2078
|
-
}
|
|
2079
|
-
} else {
|
|
2080
|
-
for (i = 0; i < n; i++) {
|
|
2081
|
-
check_intdivzero(*(dtype*)p2);
|
|
2082
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
2083
|
-
p1 += s1;
|
|
2084
|
-
p2 += s2;
|
|
2085
|
-
p3 += s3;
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
return;
|
|
2091
|
-
//
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
for (i = 0; i < n; i++) {
|
|
2095
|
-
dtype x, y, z;
|
|
2096
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2097
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2098
|
-
check_intdivzero(y);
|
|
2099
|
-
z = m_mul(x, y);
|
|
2100
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2101
|
-
}
|
|
2102
|
-
//
|
|
2103
|
-
}
|
|
2104
|
-
#undef check_intdivzero
|
|
2105
|
-
|
|
2106
|
-
static VALUE uint32_mul_self(VALUE self, VALUE other) {
|
|
2107
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2108
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2109
|
-
ndfunc_t ndf = { iter_uint32_mul, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2110
|
-
|
|
2111
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
/*
|
|
2115
|
-
Binary mul.
|
|
2116
|
-
@overload * other
|
|
2117
|
-
@param [Numo::NArray,Numeric] other
|
|
2118
|
-
@return [Numo::NArray] self * other
|
|
2119
|
-
*/
|
|
2120
|
-
static VALUE uint32_mul(VALUE self, VALUE other) {
|
|
2121
|
-
|
|
2122
|
-
VALUE klass, v;
|
|
2123
|
-
|
|
2124
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2125
|
-
if (klass == cT) {
|
|
2126
|
-
return uint32_mul_self(self, other);
|
|
2127
|
-
} else {
|
|
2128
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2129
|
-
return rb_funcall(v, '*', 1, other);
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
#define check_intdivzero(y) \
|
|
2134
|
-
if ((y) == 0) { \
|
|
2135
|
-
lp->err_type = rb_eZeroDivError; \
|
|
2136
|
-
return; \
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
static void iter_uint32_div(na_loop_t* const lp) {
|
|
2140
|
-
size_t i = 0;
|
|
2141
|
-
size_t n;
|
|
2142
|
-
char *p1, *p2, *p3;
|
|
2143
|
-
ssize_t s1, s2, s3;
|
|
2144
|
-
|
|
2145
|
-
INIT_COUNTER(lp, n);
|
|
2146
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2147
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2148
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2149
|
-
|
|
2150
|
-
//
|
|
2151
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2152
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
2153
|
-
|
|
2154
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2155
|
-
if (p1 == p3) { // inplace case
|
|
2156
|
-
for (; i < n; i++) {
|
|
2157
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2158
|
-
((dtype*)p1)[i] = m_div(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2159
|
-
}
|
|
2160
|
-
} else {
|
|
2161
|
-
for (; i < n; i++) {
|
|
2162
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2163
|
-
((dtype*)p3)[i] = m_div(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
return;
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2170
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2171
|
-
//
|
|
2172
|
-
|
|
2173
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2174
|
-
check_intdivzero(*(dtype*)p2);
|
|
2175
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2176
|
-
if (p1 == p3) { // inplace case
|
|
2177
|
-
for (; i < n; i++) {
|
|
2178
|
-
((dtype*)p1)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2179
|
-
}
|
|
2180
|
-
} else {
|
|
2181
|
-
for (; i < n; i++) {
|
|
2182
|
-
((dtype*)p3)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
} else {
|
|
2186
|
-
for (i = 0; i < n; i++) {
|
|
2187
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2188
|
-
p1 += s1;
|
|
2189
|
-
p3 += s3;
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
} else {
|
|
2193
|
-
if (p1 == p3) { // inplace case
|
|
2194
|
-
for (i = 0; i < n; i++) {
|
|
2195
|
-
check_intdivzero(*(dtype*)p2);
|
|
2196
|
-
*(dtype*)p1 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2197
|
-
p1 += s1;
|
|
2198
|
-
p2 += s2;
|
|
2199
|
-
}
|
|
2200
|
-
} else {
|
|
2201
|
-
for (i = 0; i < n; i++) {
|
|
2202
|
-
check_intdivzero(*(dtype*)p2);
|
|
2203
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2204
|
-
p1 += s1;
|
|
2205
|
-
p2 += s2;
|
|
2206
|
-
p3 += s3;
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
return;
|
|
2212
|
-
//
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
for (i = 0; i < n; i++) {
|
|
2216
|
-
dtype x, y, z;
|
|
2217
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2218
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2219
|
-
check_intdivzero(y);
|
|
2220
|
-
z = m_div(x, y);
|
|
2221
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2222
|
-
}
|
|
2223
|
-
//
|
|
2224
|
-
}
|
|
2225
|
-
#undef check_intdivzero
|
|
2226
|
-
|
|
2227
|
-
static VALUE uint32_div_self(VALUE self, VALUE other) {
|
|
2228
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2229
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2230
|
-
ndfunc_t ndf = { iter_uint32_div, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2231
|
-
|
|
2232
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2233
|
-
}
|
|
2234
|
-
|
|
2235
|
-
/*
|
|
2236
|
-
Binary div.
|
|
2237
|
-
@overload / other
|
|
2238
|
-
@param [Numo::NArray,Numeric] other
|
|
2239
|
-
@return [Numo::NArray] self / other
|
|
2240
|
-
*/
|
|
2241
|
-
static VALUE uint32_div(VALUE self, VALUE other) {
|
|
2242
|
-
|
|
2243
|
-
VALUE klass, v;
|
|
2244
|
-
|
|
2245
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2246
|
-
if (klass == cT) {
|
|
2247
|
-
return uint32_div_self(self, other);
|
|
2248
|
-
} else {
|
|
2249
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2250
|
-
return rb_funcall(v, '/', 1, other);
|
|
2251
|
-
}
|
|
2252
|
-
}
|
|
2253
|
-
|
|
2254
|
-
#define check_intdivzero(y) \
|
|
2255
|
-
if ((y) == 0) { \
|
|
2256
|
-
lp->err_type = rb_eZeroDivError; \
|
|
2257
|
-
return; \
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
static void iter_uint32_mod(na_loop_t* const lp) {
|
|
2261
|
-
size_t i = 0;
|
|
2262
|
-
size_t n;
|
|
2263
|
-
char *p1, *p2, *p3;
|
|
2264
|
-
ssize_t s1, s2, s3;
|
|
2265
|
-
|
|
2266
|
-
INIT_COUNTER(lp, n);
|
|
2267
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2268
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2269
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2270
|
-
|
|
2271
|
-
//
|
|
2272
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2273
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
2274
|
-
|
|
2275
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2276
|
-
if (p1 == p3) { // inplace case
|
|
2277
|
-
for (; i < n; i++) {
|
|
2278
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2279
|
-
((dtype*)p1)[i] = m_mod(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2280
|
-
}
|
|
2281
|
-
} else {
|
|
2282
|
-
for (; i < n; i++) {
|
|
2283
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2284
|
-
((dtype*)p3)[i] = m_mod(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2287
|
-
return;
|
|
2288
|
-
}
|
|
2289
|
-
|
|
2290
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2291
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2292
|
-
//
|
|
2293
|
-
|
|
2294
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2295
|
-
check_intdivzero(*(dtype*)p2);
|
|
2296
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2297
|
-
if (p1 == p3) { // inplace case
|
|
2298
|
-
for (; i < n; i++) {
|
|
2299
|
-
((dtype*)p1)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2300
|
-
}
|
|
2301
|
-
} else {
|
|
2302
|
-
for (; i < n; i++) {
|
|
2303
|
-
((dtype*)p3)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
} else {
|
|
2307
|
-
for (i = 0; i < n; i++) {
|
|
2308
|
-
*(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2309
|
-
p1 += s1;
|
|
2310
|
-
p3 += s3;
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
} else {
|
|
2314
|
-
if (p1 == p3) { // inplace case
|
|
2315
|
-
for (i = 0; i < n; i++) {
|
|
2316
|
-
check_intdivzero(*(dtype*)p2);
|
|
2317
|
-
*(dtype*)p1 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2318
|
-
p1 += s1;
|
|
2319
|
-
p2 += s2;
|
|
2320
|
-
}
|
|
2321
|
-
} else {
|
|
2322
|
-
for (i = 0; i < n; i++) {
|
|
2323
|
-
check_intdivzero(*(dtype*)p2);
|
|
2324
|
-
*(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2325
|
-
p1 += s1;
|
|
2326
|
-
p2 += s2;
|
|
2327
|
-
p3 += s3;
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
return;
|
|
2333
|
-
//
|
|
2334
|
-
}
|
|
2335
|
-
}
|
|
2336
|
-
for (i = 0; i < n; i++) {
|
|
2337
|
-
dtype x, y, z;
|
|
2338
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2339
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2340
|
-
check_intdivzero(y);
|
|
2341
|
-
z = m_mod(x, y);
|
|
2342
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2343
|
-
}
|
|
2344
|
-
//
|
|
2345
|
-
}
|
|
2346
|
-
#undef check_intdivzero
|
|
2347
|
-
|
|
2348
|
-
static VALUE uint32_mod_self(VALUE self, VALUE other) {
|
|
2349
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2350
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2351
|
-
ndfunc_t ndf = { iter_uint32_mod, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2352
|
-
|
|
2353
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2354
|
-
}
|
|
2355
|
-
|
|
2356
|
-
/*
|
|
2357
|
-
Binary mod.
|
|
2358
|
-
@overload % other
|
|
2359
|
-
@param [Numo::NArray,Numeric] other
|
|
2360
|
-
@return [Numo::NArray] self % other
|
|
2361
|
-
*/
|
|
2362
|
-
static VALUE uint32_mod(VALUE self, VALUE other) {
|
|
2363
|
-
|
|
2364
|
-
VALUE klass, v;
|
|
2365
|
-
|
|
2366
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2367
|
-
if (klass == cT) {
|
|
2368
|
-
return uint32_mod_self(self, other);
|
|
2369
|
-
} else {
|
|
2370
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2371
|
-
return rb_funcall(v, '%', 1, other);
|
|
2372
|
-
}
|
|
2373
|
-
}
|
|
2374
|
-
|
|
2375
|
-
static void iter_uint32_divmod(na_loop_t* const lp) {
|
|
2376
|
-
size_t i, n;
|
|
2377
|
-
char *p1, *p2, *p3, *p4;
|
|
2378
|
-
ssize_t s1, s2, s3, s4;
|
|
2379
|
-
dtype x, y, a, b;
|
|
2380
|
-
INIT_COUNTER(lp, n);
|
|
2381
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2382
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2383
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2384
|
-
INIT_PTR(lp, 3, p4, s4);
|
|
2385
|
-
for (i = n; i--;) {
|
|
2386
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2387
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2388
|
-
if (y == 0) {
|
|
2389
|
-
lp->err_type = rb_eZeroDivError;
|
|
2390
|
-
return;
|
|
2391
|
-
}
|
|
2392
|
-
m_divmod(x, y, a, b);
|
|
2393
|
-
SET_DATA_STRIDE(p3, s3, dtype, a);
|
|
2394
|
-
SET_DATA_STRIDE(p4, s4, dtype, b);
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2398
|
-
static VALUE uint32_divmod_self(VALUE self, VALUE other) {
|
|
2399
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2400
|
-
ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
|
|
2401
|
-
ndfunc_t ndf = { iter_uint32_divmod, STRIDE_LOOP, 2, 2, ain, aout };
|
|
2402
|
-
|
|
2403
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2404
|
-
}
|
|
2405
|
-
|
|
2406
|
-
/*
|
|
2407
|
-
Binary divmod.
|
|
2408
|
-
@overload divmod other
|
|
2409
|
-
@param [Numo::NArray,Numeric] other
|
|
2410
|
-
@return [Numo::NArray] divmod of self and other.
|
|
2411
|
-
*/
|
|
2412
|
-
static VALUE uint32_divmod(VALUE self, VALUE other) {
|
|
2413
|
-
|
|
2414
|
-
VALUE klass, v;
|
|
2415
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2416
|
-
if (klass == cT) {
|
|
2417
|
-
return uint32_divmod_self(self, other);
|
|
2418
|
-
} else {
|
|
2419
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2420
|
-
return rb_funcall(v, id_divmod, 1, other);
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
|
|
2424
|
-
static void iter_uint32_pow(na_loop_t* const lp) {
|
|
2425
|
-
size_t i;
|
|
2426
|
-
char *p1, *p2, *p3;
|
|
2427
|
-
ssize_t s1, s2, s3;
|
|
2428
|
-
dtype x, y;
|
|
2429
|
-
INIT_COUNTER(lp, i);
|
|
2430
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2431
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2432
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2433
|
-
for (; i--;) {
|
|
2434
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2435
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2436
|
-
x = m_pow(x, y);
|
|
2437
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2438
|
-
}
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
static void iter_uint32_pow_int32(na_loop_t* const lp) {
|
|
2442
|
-
size_t i;
|
|
2443
|
-
char *p1, *p2, *p3;
|
|
2444
|
-
ssize_t s1, s2, s3;
|
|
2445
|
-
dtype x;
|
|
2446
|
-
int32_t y;
|
|
2447
|
-
INIT_COUNTER(lp, i);
|
|
2448
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2449
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2450
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2451
|
-
for (; i--;) {
|
|
2452
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2453
|
-
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
2454
|
-
x = m_pow_int(x, y);
|
|
2455
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
|
|
2459
|
-
static VALUE uint32_pow_self(VALUE self, VALUE other) {
|
|
2460
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2461
|
-
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
2462
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2463
|
-
ndfunc_t ndf = { iter_uint32_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2464
|
-
ndfunc_t ndf_i = { iter_uint32_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
2465
|
-
|
|
2466
|
-
// fixme : use na.integer?
|
|
2467
|
-
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
2468
|
-
return na_ndloop(&ndf_i, 2, self, other);
|
|
2469
|
-
} else {
|
|
2470
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
|
-
/*
|
|
2475
|
-
Binary power.
|
|
2476
|
-
@overload ** other
|
|
2477
|
-
@param [Numo::NArray,Numeric] other
|
|
2478
|
-
@return [Numo::NArray] self to the other-th power.
|
|
2479
|
-
*/
|
|
2480
|
-
static VALUE uint32_pow(VALUE self, VALUE other) {
|
|
2481
|
-
|
|
2482
|
-
VALUE klass, v;
|
|
2483
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2484
|
-
if (klass == cT) {
|
|
2485
|
-
return uint32_pow_self(self, other);
|
|
2486
|
-
} else {
|
|
2487
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2488
|
-
return rb_funcall(v, id_pow, 1, other);
|
|
2489
|
-
}
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
static void iter_uint32_minus(na_loop_t* const lp) {
|
|
2493
|
-
size_t i, n;
|
|
2494
|
-
char *p1, *p2;
|
|
2495
|
-
ssize_t s1, s2;
|
|
2496
|
-
size_t *idx1, *idx2;
|
|
2497
|
-
dtype x;
|
|
2498
|
-
|
|
2499
|
-
INIT_COUNTER(lp, n);
|
|
2500
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2501
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2502
|
-
|
|
2503
|
-
if (idx1) {
|
|
2504
|
-
if (idx2) {
|
|
2505
|
-
for (i = 0; i < n; i++) {
|
|
2506
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2507
|
-
x = m_minus(x);
|
|
2508
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2509
|
-
}
|
|
2510
|
-
} else {
|
|
2511
|
-
for (i = 0; i < n; i++) {
|
|
2512
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2513
|
-
x = m_minus(x);
|
|
2514
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
} else {
|
|
2518
|
-
if (idx2) {
|
|
2519
|
-
for (i = 0; i < n; i++) {
|
|
2520
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2521
|
-
x = m_minus(x);
|
|
2522
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2523
|
-
}
|
|
2524
|
-
} else {
|
|
2525
|
-
//
|
|
2526
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2527
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2528
|
-
for (i = 0; i < n; i++) {
|
|
2529
|
-
((dtype*)p2)[i] = m_minus(((dtype*)p1)[i]);
|
|
2530
|
-
}
|
|
2531
|
-
return;
|
|
2532
|
-
}
|
|
2533
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2534
|
-
//
|
|
2535
|
-
for (i = 0; i < n; i++) {
|
|
2536
|
-
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
2537
|
-
p1 += s1;
|
|
2538
|
-
p2 += s2;
|
|
2539
|
-
}
|
|
2540
|
-
return;
|
|
2541
|
-
//
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
for (i = 0; i < n; i++) {
|
|
2545
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2546
|
-
x = m_minus(x);
|
|
2547
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2548
|
-
}
|
|
2549
|
-
//
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
|
-
/*
|
|
2555
|
-
Unary minus.
|
|
2556
|
-
@overload -@
|
|
2557
|
-
@return [Numo::UInt32] minus of self.
|
|
2558
|
-
*/
|
|
2559
|
-
static VALUE uint32_minus(VALUE self) {
|
|
2560
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2561
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2562
|
-
ndfunc_t ndf = { iter_uint32_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
2563
|
-
|
|
2564
|
-
return na_ndloop(&ndf, 1, self);
|
|
2565
|
-
}
|
|
2566
|
-
|
|
2567
|
-
static void iter_uint32_reciprocal(na_loop_t* const lp) {
|
|
2568
|
-
size_t i, n;
|
|
2569
|
-
char *p1, *p2;
|
|
2570
|
-
ssize_t s1, s2;
|
|
2571
|
-
size_t *idx1, *idx2;
|
|
2572
|
-
dtype x;
|
|
2573
|
-
|
|
2574
|
-
INIT_COUNTER(lp, n);
|
|
2575
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2576
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2577
|
-
|
|
2578
|
-
if (idx1) {
|
|
2579
|
-
if (idx2) {
|
|
2580
|
-
for (i = 0; i < n; i++) {
|
|
2581
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2582
|
-
x = m_reciprocal(x);
|
|
2583
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2584
|
-
}
|
|
2585
|
-
} else {
|
|
2586
|
-
for (i = 0; i < n; i++) {
|
|
2587
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2588
|
-
x = m_reciprocal(x);
|
|
2589
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
} else {
|
|
2593
|
-
if (idx2) {
|
|
2594
|
-
for (i = 0; i < n; i++) {
|
|
2595
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2596
|
-
x = m_reciprocal(x);
|
|
2597
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2598
|
-
}
|
|
2599
|
-
} else {
|
|
2600
|
-
//
|
|
2601
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2602
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2603
|
-
for (i = 0; i < n; i++) {
|
|
2604
|
-
((dtype*)p2)[i] = m_reciprocal(((dtype*)p1)[i]);
|
|
2605
|
-
}
|
|
2606
|
-
return;
|
|
2607
|
-
}
|
|
2608
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2609
|
-
//
|
|
2610
|
-
for (i = 0; i < n; i++) {
|
|
2611
|
-
*(dtype*)p2 = m_reciprocal(*(dtype*)p1);
|
|
2612
|
-
p1 += s1;
|
|
2613
|
-
p2 += s2;
|
|
2614
|
-
}
|
|
2615
|
-
return;
|
|
2616
|
-
//
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
for (i = 0; i < n; i++) {
|
|
2620
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2621
|
-
x = m_reciprocal(x);
|
|
2622
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2623
|
-
}
|
|
2624
|
-
//
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
|
|
2629
|
-
/*
|
|
2630
|
-
Unary reciprocal.
|
|
2631
|
-
@overload reciprocal
|
|
2632
|
-
@return [Numo::UInt32] reciprocal of self.
|
|
2633
|
-
*/
|
|
2634
|
-
static VALUE uint32_reciprocal(VALUE self) {
|
|
2635
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2636
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2637
|
-
ndfunc_t ndf = { iter_uint32_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
2638
|
-
|
|
2639
|
-
return na_ndloop(&ndf, 1, self);
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
static void iter_uint32_sign(na_loop_t* const lp) {
|
|
2643
|
-
size_t i, n;
|
|
2644
|
-
char *p1, *p2;
|
|
2645
|
-
ssize_t s1, s2;
|
|
2646
|
-
size_t *idx1, *idx2;
|
|
2647
|
-
dtype x;
|
|
2648
|
-
|
|
2649
|
-
INIT_COUNTER(lp, n);
|
|
2650
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2651
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2652
|
-
|
|
2653
|
-
if (idx1) {
|
|
2654
|
-
if (idx2) {
|
|
2655
|
-
for (i = 0; i < n; i++) {
|
|
2656
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2657
|
-
x = m_sign(x);
|
|
2658
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2659
|
-
}
|
|
2660
|
-
} else {
|
|
2661
|
-
for (i = 0; i < n; i++) {
|
|
2662
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2663
|
-
x = m_sign(x);
|
|
2664
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2665
|
-
}
|
|
2666
|
-
}
|
|
2667
|
-
} else {
|
|
2668
|
-
if (idx2) {
|
|
2669
|
-
for (i = 0; i < n; i++) {
|
|
2670
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2671
|
-
x = m_sign(x);
|
|
2672
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2673
|
-
}
|
|
2674
|
-
} else {
|
|
2675
|
-
//
|
|
2676
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2677
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2678
|
-
for (i = 0; i < n; i++) {
|
|
2679
|
-
((dtype*)p2)[i] = m_sign(((dtype*)p1)[i]);
|
|
2680
|
-
}
|
|
2681
|
-
return;
|
|
2682
|
-
}
|
|
2683
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2684
|
-
//
|
|
2685
|
-
for (i = 0; i < n; i++) {
|
|
2686
|
-
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
2687
|
-
p1 += s1;
|
|
2688
|
-
p2 += s2;
|
|
2689
|
-
}
|
|
2690
|
-
return;
|
|
2691
|
-
//
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
for (i = 0; i < n; i++) {
|
|
2695
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2696
|
-
x = m_sign(x);
|
|
2697
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2698
|
-
}
|
|
2699
|
-
//
|
|
2700
|
-
}
|
|
2701
|
-
}
|
|
2702
|
-
}
|
|
2703
|
-
|
|
2704
|
-
/*
|
|
2705
|
-
Unary sign.
|
|
2706
|
-
@overload sign
|
|
2707
|
-
@return [Numo::UInt32] sign of self.
|
|
2708
|
-
*/
|
|
2709
|
-
static VALUE uint32_sign(VALUE self) {
|
|
2710
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2711
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2712
|
-
ndfunc_t ndf = { iter_uint32_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
2713
|
-
|
|
2714
|
-
return na_ndloop(&ndf, 1, self);
|
|
2715
|
-
}
|
|
2716
|
-
|
|
2717
|
-
static void iter_uint32_square(na_loop_t* const lp) {
|
|
2718
|
-
size_t i, n;
|
|
2719
|
-
char *p1, *p2;
|
|
2720
|
-
ssize_t s1, s2;
|
|
2721
|
-
size_t *idx1, *idx2;
|
|
2722
|
-
dtype x;
|
|
2723
|
-
|
|
2724
|
-
INIT_COUNTER(lp, n);
|
|
2725
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2726
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2727
|
-
|
|
2728
|
-
if (idx1) {
|
|
2729
|
-
if (idx2) {
|
|
2730
|
-
for (i = 0; i < n; i++) {
|
|
2731
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2732
|
-
x = m_square(x);
|
|
2733
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2734
|
-
}
|
|
2735
|
-
} else {
|
|
2736
|
-
for (i = 0; i < n; i++) {
|
|
2737
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2738
|
-
x = m_square(x);
|
|
2739
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
} else {
|
|
2743
|
-
if (idx2) {
|
|
2744
|
-
for (i = 0; i < n; i++) {
|
|
2745
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2746
|
-
x = m_square(x);
|
|
2747
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2748
|
-
}
|
|
2749
|
-
} else {
|
|
2750
|
-
//
|
|
2751
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2752
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2753
|
-
for (i = 0; i < n; i++) {
|
|
2754
|
-
((dtype*)p2)[i] = m_square(((dtype*)p1)[i]);
|
|
2755
|
-
}
|
|
2756
|
-
return;
|
|
2757
|
-
}
|
|
2758
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2759
|
-
//
|
|
2760
|
-
for (i = 0; i < n; i++) {
|
|
2761
|
-
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
2762
|
-
p1 += s1;
|
|
2763
|
-
p2 += s2;
|
|
2764
|
-
}
|
|
2765
|
-
return;
|
|
2766
|
-
//
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
for (i = 0; i < n; i++) {
|
|
2770
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2771
|
-
x = m_square(x);
|
|
2772
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2773
|
-
}
|
|
2774
|
-
//
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
|
-
/*
|
|
2780
|
-
Unary square.
|
|
2781
|
-
@overload square
|
|
2782
|
-
@return [Numo::UInt32] square of self.
|
|
2783
|
-
*/
|
|
2784
|
-
static VALUE uint32_square(VALUE self) {
|
|
2785
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2786
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2787
|
-
ndfunc_t ndf = { iter_uint32_square, FULL_LOOP, 1, 1, ain, aout };
|
|
2788
|
-
|
|
2789
|
-
return na_ndloop(&ndf, 1, self);
|
|
2790
|
-
}
|
|
2791
|
-
|
|
2792
|
-
static void iter_uint32_eq(na_loop_t* const lp) {
|
|
2793
|
-
size_t i;
|
|
2794
|
-
char *p1, *p2;
|
|
2795
|
-
BIT_DIGIT* a3;
|
|
2796
|
-
size_t p3;
|
|
2797
|
-
ssize_t s1, s2, s3;
|
|
2798
|
-
dtype x, y;
|
|
2799
|
-
BIT_DIGIT b;
|
|
2800
|
-
INIT_COUNTER(lp, i);
|
|
2801
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2802
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2803
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2804
|
-
for (; i--;) {
|
|
2805
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2806
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2807
|
-
b = (m_eq(x, y)) ? 1 : 0;
|
|
2808
|
-
STORE_BIT(a3, p3, b);
|
|
2809
|
-
p3 += s3;
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
static VALUE uint32_eq_self(VALUE self, VALUE other) {
|
|
2814
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2815
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2816
|
-
ndfunc_t ndf = { iter_uint32_eq, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2817
|
-
|
|
2818
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2819
|
-
}
|
|
2820
|
-
|
|
2821
|
-
/*
|
|
2822
|
-
Comparison eq other.
|
|
2823
|
-
@overload eq other
|
|
2824
|
-
@param [Numo::NArray,Numeric] other
|
|
2825
|
-
@return [Numo::Bit] result of self eq other.
|
|
2826
|
-
*/
|
|
2827
|
-
static VALUE uint32_eq(VALUE self, VALUE other) {
|
|
2828
|
-
|
|
2829
|
-
VALUE klass, v;
|
|
2830
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2831
|
-
if (klass == cT) {
|
|
2832
|
-
return uint32_eq_self(self, other);
|
|
2833
|
-
} else {
|
|
2834
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2835
|
-
return rb_funcall(v, id_eq, 1, other);
|
|
2836
|
-
}
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
static void iter_uint32_ne(na_loop_t* const lp) {
|
|
2840
|
-
size_t i;
|
|
2841
|
-
char *p1, *p2;
|
|
2842
|
-
BIT_DIGIT* a3;
|
|
2843
|
-
size_t p3;
|
|
2844
|
-
ssize_t s1, s2, s3;
|
|
2845
|
-
dtype x, y;
|
|
2846
|
-
BIT_DIGIT b;
|
|
2847
|
-
INIT_COUNTER(lp, i);
|
|
2848
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2849
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2850
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2851
|
-
for (; i--;) {
|
|
2852
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2853
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2854
|
-
b = (m_ne(x, y)) ? 1 : 0;
|
|
2855
|
-
STORE_BIT(a3, p3, b);
|
|
2856
|
-
p3 += s3;
|
|
2857
|
-
}
|
|
2858
|
-
}
|
|
2859
|
-
|
|
2860
|
-
static VALUE uint32_ne_self(VALUE self, VALUE other) {
|
|
2861
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2862
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2863
|
-
ndfunc_t ndf = { iter_uint32_ne, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2864
|
-
|
|
2865
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2866
|
-
}
|
|
2867
|
-
|
|
2868
|
-
/*
|
|
2869
|
-
Comparison ne other.
|
|
2870
|
-
@overload ne other
|
|
2871
|
-
@param [Numo::NArray,Numeric] other
|
|
2872
|
-
@return [Numo::Bit] result of self ne other.
|
|
2873
|
-
*/
|
|
2874
|
-
static VALUE uint32_ne(VALUE self, VALUE other) {
|
|
2875
|
-
|
|
2876
|
-
VALUE klass, v;
|
|
2877
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2878
|
-
if (klass == cT) {
|
|
2879
|
-
return uint32_ne_self(self, other);
|
|
2880
|
-
} else {
|
|
2881
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2882
|
-
return rb_funcall(v, id_ne, 1, other);
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
|
|
2886
|
-
#define check_intdivzero(y) \
|
|
2887
|
-
{}
|
|
2888
|
-
|
|
2889
|
-
static void iter_uint32_bit_and(na_loop_t* const lp) {
|
|
2890
|
-
size_t i = 0;
|
|
2891
|
-
size_t n;
|
|
2892
|
-
char *p1, *p2, *p3;
|
|
2893
|
-
ssize_t s1, s2, s3;
|
|
2894
|
-
|
|
2895
|
-
INIT_COUNTER(lp, n);
|
|
2896
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2897
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2898
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2899
|
-
|
|
2900
|
-
//
|
|
2901
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2902
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
2903
|
-
|
|
2904
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2905
|
-
if (p1 == p3) { // inplace case
|
|
2906
|
-
for (; i < n; i++) {
|
|
2907
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2908
|
-
((dtype*)p1)[i] = m_bit_and(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2909
|
-
}
|
|
2910
|
-
} else {
|
|
2911
|
-
for (; i < n; i++) {
|
|
2912
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2913
|
-
((dtype*)p3)[i] = m_bit_and(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
return;
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2920
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2921
|
-
//
|
|
2922
|
-
|
|
2923
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2924
|
-
check_intdivzero(*(dtype*)p2);
|
|
2925
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2926
|
-
if (p1 == p3) { // inplace case
|
|
2927
|
-
for (; i < n; i++) {
|
|
2928
|
-
((dtype*)p1)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2929
|
-
}
|
|
2930
|
-
} else {
|
|
2931
|
-
for (; i < n; i++) {
|
|
2932
|
-
((dtype*)p3)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2933
|
-
}
|
|
2934
|
-
}
|
|
2935
|
-
} else {
|
|
2936
|
-
for (i = 0; i < n; i++) {
|
|
2937
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2938
|
-
p1 += s1;
|
|
2939
|
-
p3 += s3;
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
2942
|
-
} else {
|
|
2943
|
-
if (p1 == p3) { // inplace case
|
|
2944
|
-
for (i = 0; i < n; i++) {
|
|
2945
|
-
check_intdivzero(*(dtype*)p2);
|
|
2946
|
-
*(dtype*)p1 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2947
|
-
p1 += s1;
|
|
2948
|
-
p2 += s2;
|
|
2949
|
-
}
|
|
2950
|
-
} else {
|
|
2951
|
-
for (i = 0; i < n; i++) {
|
|
2952
|
-
check_intdivzero(*(dtype*)p2);
|
|
2953
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2954
|
-
p1 += s1;
|
|
2955
|
-
p2 += s2;
|
|
2956
|
-
p3 += s3;
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
|
|
2961
|
-
return;
|
|
2962
|
-
//
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
for (i = 0; i < n; i++) {
|
|
2966
|
-
dtype x, y, z;
|
|
2967
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2968
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2969
|
-
check_intdivzero(y);
|
|
2970
|
-
z = m_bit_and(x, y);
|
|
2971
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2972
|
-
}
|
|
2973
|
-
//
|
|
2974
|
-
}
|
|
2975
|
-
#undef check_intdivzero
|
|
2976
|
-
|
|
2977
|
-
static VALUE uint32_bit_and_self(VALUE self, VALUE other) {
|
|
2978
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2979
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2980
|
-
ndfunc_t ndf = { iter_uint32_bit_and, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2981
|
-
|
|
2982
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2983
|
-
}
|
|
2984
|
-
|
|
2985
|
-
/*
|
|
2986
|
-
Binary bit_and.
|
|
2987
|
-
@overload & other
|
|
2988
|
-
@param [Numo::NArray,Numeric] other
|
|
2989
|
-
@return [Numo::NArray] self & other
|
|
2990
|
-
*/
|
|
2991
|
-
static VALUE uint32_bit_and(VALUE self, VALUE other) {
|
|
2992
|
-
|
|
2993
|
-
VALUE klass, v;
|
|
2994
|
-
|
|
2995
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2996
|
-
if (klass == cT) {
|
|
2997
|
-
return uint32_bit_and_self(self, other);
|
|
2998
|
-
} else {
|
|
2999
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3000
|
-
return rb_funcall(v, '&', 1, other);
|
|
3001
|
-
}
|
|
3002
|
-
}
|
|
3003
|
-
|
|
3004
|
-
#define check_intdivzero(y) \
|
|
3005
|
-
{}
|
|
3006
|
-
|
|
3007
|
-
static void iter_uint32_bit_or(na_loop_t* const lp) {
|
|
3008
|
-
size_t i = 0;
|
|
3009
|
-
size_t n;
|
|
3010
|
-
char *p1, *p2, *p3;
|
|
3011
|
-
ssize_t s1, s2, s3;
|
|
3012
|
-
|
|
3013
|
-
INIT_COUNTER(lp, n);
|
|
3014
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3015
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3016
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3017
|
-
|
|
3018
|
-
//
|
|
3019
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
3020
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
3021
|
-
|
|
3022
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3023
|
-
if (p1 == p3) { // inplace case
|
|
3024
|
-
for (; i < n; i++) {
|
|
3025
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3026
|
-
((dtype*)p1)[i] = m_bit_or(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3027
|
-
}
|
|
3028
|
-
} else {
|
|
3029
|
-
for (; i < n; i++) {
|
|
3030
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3031
|
-
((dtype*)p3)[i] = m_bit_or(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3032
|
-
}
|
|
3033
|
-
}
|
|
3034
|
-
return;
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
3038
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
3039
|
-
//
|
|
3040
|
-
|
|
3041
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
3042
|
-
check_intdivzero(*(dtype*)p2);
|
|
3043
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3044
|
-
if (p1 == p3) { // inplace case
|
|
3045
|
-
for (; i < n; i++) {
|
|
3046
|
-
((dtype*)p1)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
3047
|
-
}
|
|
3048
|
-
} else {
|
|
3049
|
-
for (; i < n; i++) {
|
|
3050
|
-
((dtype*)p3)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
3051
|
-
}
|
|
3052
|
-
}
|
|
3053
|
-
} else {
|
|
3054
|
-
for (i = 0; i < n; i++) {
|
|
3055
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
3056
|
-
p1 += s1;
|
|
3057
|
-
p3 += s3;
|
|
3058
|
-
}
|
|
3059
|
-
}
|
|
3060
|
-
} else {
|
|
3061
|
-
if (p1 == p3) { // inplace case
|
|
3062
|
-
for (i = 0; i < n; i++) {
|
|
3063
|
-
check_intdivzero(*(dtype*)p2);
|
|
3064
|
-
*(dtype*)p1 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
3065
|
-
p1 += s1;
|
|
3066
|
-
p2 += s2;
|
|
3067
|
-
}
|
|
3068
|
-
} else {
|
|
3069
|
-
for (i = 0; i < n; i++) {
|
|
3070
|
-
check_intdivzero(*(dtype*)p2);
|
|
3071
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
3072
|
-
p1 += s1;
|
|
3073
|
-
p2 += s2;
|
|
3074
|
-
p3 += s3;
|
|
3075
|
-
}
|
|
3076
|
-
}
|
|
3077
|
-
}
|
|
3078
|
-
|
|
3079
|
-
return;
|
|
3080
|
-
//
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
for (i = 0; i < n; i++) {
|
|
3084
|
-
dtype x, y, z;
|
|
3085
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3086
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3087
|
-
check_intdivzero(y);
|
|
3088
|
-
z = m_bit_or(x, y);
|
|
3089
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
3090
|
-
}
|
|
3091
|
-
//
|
|
3092
|
-
}
|
|
3093
|
-
#undef check_intdivzero
|
|
3094
|
-
|
|
3095
|
-
static VALUE uint32_bit_or_self(VALUE self, VALUE other) {
|
|
3096
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3097
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3098
|
-
ndfunc_t ndf = { iter_uint32_bit_or, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3099
|
-
|
|
3100
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3101
|
-
}
|
|
3102
|
-
|
|
3103
|
-
/*
|
|
3104
|
-
Binary bit_or.
|
|
3105
|
-
@overload | other
|
|
3106
|
-
@param [Numo::NArray,Numeric] other
|
|
3107
|
-
@return [Numo::NArray] self | other
|
|
3108
|
-
*/
|
|
3109
|
-
static VALUE uint32_bit_or(VALUE self, VALUE other) {
|
|
3110
|
-
|
|
3111
|
-
VALUE klass, v;
|
|
3112
|
-
|
|
3113
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3114
|
-
if (klass == cT) {
|
|
3115
|
-
return uint32_bit_or_self(self, other);
|
|
3116
|
-
} else {
|
|
3117
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3118
|
-
return rb_funcall(v, '|', 1, other);
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
|
-
|
|
3122
|
-
#define check_intdivzero(y) \
|
|
3123
|
-
{}
|
|
3124
|
-
|
|
3125
|
-
static void iter_uint32_bit_xor(na_loop_t* const lp) {
|
|
3126
|
-
size_t i = 0;
|
|
3127
|
-
size_t n;
|
|
3128
|
-
char *p1, *p2, *p3;
|
|
3129
|
-
ssize_t s1, s2, s3;
|
|
3130
|
-
|
|
3131
|
-
INIT_COUNTER(lp, n);
|
|
3132
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3133
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3134
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3135
|
-
|
|
3136
|
-
//
|
|
3137
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
3138
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
3139
|
-
|
|
3140
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3141
|
-
if (p1 == p3) { // inplace case
|
|
3142
|
-
for (; i < n; i++) {
|
|
3143
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3144
|
-
((dtype*)p1)[i] = m_bit_xor(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3145
|
-
}
|
|
3146
|
-
} else {
|
|
3147
|
-
for (; i < n; i++) {
|
|
3148
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3149
|
-
((dtype*)p3)[i] = m_bit_xor(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
return;
|
|
3153
|
-
}
|
|
3154
|
-
|
|
3155
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
3156
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
3157
|
-
//
|
|
3158
|
-
|
|
3159
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
3160
|
-
check_intdivzero(*(dtype*)p2);
|
|
3161
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3162
|
-
if (p1 == p3) { // inplace case
|
|
3163
|
-
for (; i < n; i++) {
|
|
3164
|
-
((dtype*)p1)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
3165
|
-
}
|
|
3166
|
-
} else {
|
|
3167
|
-
for (; i < n; i++) {
|
|
3168
|
-
((dtype*)p3)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
3169
|
-
}
|
|
3170
|
-
}
|
|
3171
|
-
} else {
|
|
3172
|
-
for (i = 0; i < n; i++) {
|
|
3173
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
3174
|
-
p1 += s1;
|
|
3175
|
-
p3 += s3;
|
|
3176
|
-
}
|
|
3177
|
-
}
|
|
3178
|
-
} else {
|
|
3179
|
-
if (p1 == p3) { // inplace case
|
|
3180
|
-
for (i = 0; i < n; i++) {
|
|
3181
|
-
check_intdivzero(*(dtype*)p2);
|
|
3182
|
-
*(dtype*)p1 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
3183
|
-
p1 += s1;
|
|
3184
|
-
p2 += s2;
|
|
3185
|
-
}
|
|
3186
|
-
} else {
|
|
3187
|
-
for (i = 0; i < n; i++) {
|
|
3188
|
-
check_intdivzero(*(dtype*)p2);
|
|
3189
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
3190
|
-
p1 += s1;
|
|
3191
|
-
p2 += s2;
|
|
3192
|
-
p3 += s3;
|
|
3193
|
-
}
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
|
-
return;
|
|
3198
|
-
//
|
|
3199
|
-
}
|
|
3200
|
-
}
|
|
3201
|
-
for (i = 0; i < n; i++) {
|
|
3202
|
-
dtype x, y, z;
|
|
3203
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3204
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3205
|
-
check_intdivzero(y);
|
|
3206
|
-
z = m_bit_xor(x, y);
|
|
3207
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
3208
|
-
}
|
|
3209
|
-
//
|
|
3210
|
-
}
|
|
3211
|
-
#undef check_intdivzero
|
|
3212
|
-
|
|
3213
|
-
static VALUE uint32_bit_xor_self(VALUE self, VALUE other) {
|
|
3214
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3215
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3216
|
-
ndfunc_t ndf = { iter_uint32_bit_xor, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3217
|
-
|
|
3218
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3219
|
-
}
|
|
3220
|
-
|
|
3221
|
-
/*
|
|
3222
|
-
Binary bit_xor.
|
|
3223
|
-
@overload ^ other
|
|
3224
|
-
@param [Numo::NArray,Numeric] other
|
|
3225
|
-
@return [Numo::NArray] self ^ other
|
|
3226
|
-
*/
|
|
3227
|
-
static VALUE uint32_bit_xor(VALUE self, VALUE other) {
|
|
3228
|
-
|
|
3229
|
-
VALUE klass, v;
|
|
3230
|
-
|
|
3231
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3232
|
-
if (klass == cT) {
|
|
3233
|
-
return uint32_bit_xor_self(self, other);
|
|
3234
|
-
} else {
|
|
3235
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3236
|
-
return rb_funcall(v, '^', 1, other);
|
|
3237
|
-
}
|
|
3238
|
-
}
|
|
3239
|
-
|
|
3240
|
-
static void iter_uint32_bit_not(na_loop_t* const lp) {
|
|
3241
|
-
size_t i, n;
|
|
3242
|
-
char *p1, *p2;
|
|
3243
|
-
ssize_t s1, s2;
|
|
3244
|
-
size_t *idx1, *idx2;
|
|
3245
|
-
dtype x;
|
|
3246
|
-
|
|
3247
|
-
INIT_COUNTER(lp, n);
|
|
3248
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3249
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3250
|
-
|
|
3251
|
-
if (idx1) {
|
|
3252
|
-
if (idx2) {
|
|
3253
|
-
for (i = 0; i < n; i++) {
|
|
3254
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3255
|
-
x = m_bit_not(x);
|
|
3256
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3257
|
-
}
|
|
3258
|
-
} else {
|
|
3259
|
-
for (i = 0; i < n; i++) {
|
|
3260
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3261
|
-
x = m_bit_not(x);
|
|
3262
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3263
|
-
}
|
|
3264
|
-
}
|
|
3265
|
-
} else {
|
|
3266
|
-
if (idx2) {
|
|
3267
|
-
for (i = 0; i < n; i++) {
|
|
3268
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3269
|
-
x = m_bit_not(x);
|
|
3270
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3271
|
-
}
|
|
3272
|
-
} else {
|
|
3273
|
-
//
|
|
3274
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
3275
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
3276
|
-
for (i = 0; i < n; i++) {
|
|
3277
|
-
((dtype*)p2)[i] = m_bit_not(((dtype*)p1)[i]);
|
|
3278
|
-
}
|
|
3279
|
-
return;
|
|
3280
|
-
}
|
|
3281
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
3282
|
-
//
|
|
3283
|
-
for (i = 0; i < n; i++) {
|
|
3284
|
-
*(dtype*)p2 = m_bit_not(*(dtype*)p1);
|
|
3285
|
-
p1 += s1;
|
|
3286
|
-
p2 += s2;
|
|
3287
|
-
}
|
|
3288
|
-
return;
|
|
3289
|
-
//
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
for (i = 0; i < n; i++) {
|
|
3293
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3294
|
-
x = m_bit_not(x);
|
|
3295
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3296
|
-
}
|
|
3297
|
-
//
|
|
3298
|
-
}
|
|
3299
|
-
}
|
|
3300
|
-
}
|
|
3301
|
-
|
|
3302
|
-
/*
|
|
3303
|
-
Unary bit_not.
|
|
3304
|
-
@overload ~
|
|
3305
|
-
@return [Numo::UInt32] bit_not of self.
|
|
3306
|
-
*/
|
|
3307
|
-
static VALUE uint32_bit_not(VALUE self) {
|
|
3308
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3309
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3310
|
-
ndfunc_t ndf = { iter_uint32_bit_not, FULL_LOOP, 1, 1, ain, aout };
|
|
3311
|
-
|
|
3312
|
-
return na_ndloop(&ndf, 1, self);
|
|
3313
|
-
}
|
|
3314
|
-
|
|
3315
|
-
#define check_intdivzero(y) \
|
|
3316
|
-
{}
|
|
3317
|
-
|
|
3318
|
-
static void iter_uint32_left_shift(na_loop_t* const lp) {
|
|
3319
|
-
size_t i = 0;
|
|
3320
|
-
size_t n;
|
|
3321
|
-
char *p1, *p2, *p3;
|
|
3322
|
-
ssize_t s1, s2, s3;
|
|
3323
|
-
|
|
3324
|
-
INIT_COUNTER(lp, n);
|
|
3325
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3326
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3327
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3328
|
-
|
|
3329
|
-
//
|
|
3330
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
3331
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
3332
|
-
|
|
3333
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3334
|
-
if (p1 == p3) { // inplace case
|
|
3335
|
-
for (; i < n; i++) {
|
|
3336
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3337
|
-
((dtype*)p1)[i] = m_left_shift(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3338
|
-
}
|
|
3339
|
-
} else {
|
|
3340
|
-
for (; i < n; i++) {
|
|
3341
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3342
|
-
((dtype*)p3)[i] = m_left_shift(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3343
|
-
}
|
|
3344
|
-
}
|
|
3345
|
-
return;
|
|
3346
|
-
}
|
|
3347
|
-
|
|
3348
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
3349
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
3350
|
-
//
|
|
3351
|
-
|
|
3352
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
3353
|
-
check_intdivzero(*(dtype*)p2);
|
|
3354
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3355
|
-
if (p1 == p3) { // inplace case
|
|
3356
|
-
for (; i < n; i++) {
|
|
3357
|
-
((dtype*)p1)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3358
|
-
}
|
|
3359
|
-
} else {
|
|
3360
|
-
for (; i < n; i++) {
|
|
3361
|
-
((dtype*)p3)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3362
|
-
}
|
|
3363
|
-
}
|
|
3364
|
-
} else {
|
|
3365
|
-
for (i = 0; i < n; i++) {
|
|
3366
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3367
|
-
p1 += s1;
|
|
3368
|
-
p3 += s3;
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
} else {
|
|
3372
|
-
if (p1 == p3) { // inplace case
|
|
3373
|
-
for (i = 0; i < n; i++) {
|
|
3374
|
-
check_intdivzero(*(dtype*)p2);
|
|
3375
|
-
*(dtype*)p1 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3376
|
-
p1 += s1;
|
|
3377
|
-
p2 += s2;
|
|
3378
|
-
}
|
|
3379
|
-
} else {
|
|
3380
|
-
for (i = 0; i < n; i++) {
|
|
3381
|
-
check_intdivzero(*(dtype*)p2);
|
|
3382
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3383
|
-
p1 += s1;
|
|
3384
|
-
p2 += s2;
|
|
3385
|
-
p3 += s3;
|
|
3386
|
-
}
|
|
3387
|
-
}
|
|
3388
|
-
}
|
|
3389
|
-
|
|
3390
|
-
return;
|
|
3391
|
-
//
|
|
3392
|
-
}
|
|
3393
|
-
}
|
|
3394
|
-
for (i = 0; i < n; i++) {
|
|
3395
|
-
dtype x, y, z;
|
|
3396
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3397
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3398
|
-
check_intdivzero(y);
|
|
3399
|
-
z = m_left_shift(x, y);
|
|
3400
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
3401
|
-
}
|
|
3402
|
-
//
|
|
3403
|
-
}
|
|
3404
|
-
#undef check_intdivzero
|
|
3405
|
-
|
|
3406
|
-
static VALUE uint32_left_shift_self(VALUE self, VALUE other) {
|
|
3407
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3408
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3409
|
-
ndfunc_t ndf = { iter_uint32_left_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3410
|
-
|
|
3411
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3412
|
-
}
|
|
3413
|
-
|
|
3414
|
-
/*
|
|
3415
|
-
Binary left_shift.
|
|
3416
|
-
@overload << other
|
|
3417
|
-
@param [Numo::NArray,Numeric] other
|
|
3418
|
-
@return [Numo::NArray] self << other
|
|
3419
|
-
*/
|
|
3420
|
-
static VALUE uint32_left_shift(VALUE self, VALUE other) {
|
|
3421
|
-
|
|
3422
|
-
VALUE klass, v;
|
|
3423
|
-
|
|
3424
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3425
|
-
if (klass == cT) {
|
|
3426
|
-
return uint32_left_shift_self(self, other);
|
|
3427
|
-
} else {
|
|
3428
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3429
|
-
return rb_funcall(v, id_left_shift, 1, other);
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
|
|
3433
|
-
#define check_intdivzero(y) \
|
|
3434
|
-
{}
|
|
3435
|
-
|
|
3436
|
-
static void iter_uint32_right_shift(na_loop_t* const lp) {
|
|
3437
|
-
size_t i = 0;
|
|
3438
|
-
size_t n;
|
|
3439
|
-
char *p1, *p2, *p3;
|
|
3440
|
-
ssize_t s1, s2, s3;
|
|
3441
|
-
|
|
3442
|
-
INIT_COUNTER(lp, n);
|
|
3443
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3444
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3445
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3446
|
-
|
|
3447
|
-
//
|
|
3448
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
3449
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
3450
|
-
|
|
3451
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3452
|
-
if (p1 == p3) { // inplace case
|
|
3453
|
-
for (; i < n; i++) {
|
|
3454
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3455
|
-
((dtype*)p1)[i] = m_right_shift(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3456
|
-
}
|
|
3457
|
-
} else {
|
|
3458
|
-
for (; i < n; i++) {
|
|
3459
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
3460
|
-
((dtype*)p3)[i] = m_right_shift(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
3461
|
-
}
|
|
3462
|
-
}
|
|
3463
|
-
return;
|
|
3464
|
-
}
|
|
3465
|
-
|
|
3466
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
3467
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
3468
|
-
//
|
|
3469
|
-
|
|
3470
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
3471
|
-
check_intdivzero(*(dtype*)p2);
|
|
3472
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3473
|
-
if (p1 == p3) { // inplace case
|
|
3474
|
-
for (; i < n; i++) {
|
|
3475
|
-
((dtype*)p1)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3476
|
-
}
|
|
3477
|
-
} else {
|
|
3478
|
-
for (; i < n; i++) {
|
|
3479
|
-
((dtype*)p3)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3480
|
-
}
|
|
3481
|
-
}
|
|
3482
|
-
} else {
|
|
3483
|
-
for (i = 0; i < n; i++) {
|
|
3484
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3485
|
-
p1 += s1;
|
|
3486
|
-
p3 += s3;
|
|
3487
|
-
}
|
|
3488
|
-
}
|
|
3489
|
-
} else {
|
|
3490
|
-
if (p1 == p3) { // inplace case
|
|
3491
|
-
for (i = 0; i < n; i++) {
|
|
3492
|
-
check_intdivzero(*(dtype*)p2);
|
|
3493
|
-
*(dtype*)p1 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3494
|
-
p1 += s1;
|
|
3495
|
-
p2 += s2;
|
|
3496
|
-
}
|
|
3497
|
-
} else {
|
|
3498
|
-
for (i = 0; i < n; i++) {
|
|
3499
|
-
check_intdivzero(*(dtype*)p2);
|
|
3500
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3501
|
-
p1 += s1;
|
|
3502
|
-
p2 += s2;
|
|
3503
|
-
p3 += s3;
|
|
3504
|
-
}
|
|
3505
|
-
}
|
|
3506
|
-
}
|
|
3507
|
-
|
|
3508
|
-
return;
|
|
3509
|
-
//
|
|
3510
|
-
}
|
|
3511
|
-
}
|
|
3512
|
-
for (i = 0; i < n; i++) {
|
|
3513
|
-
dtype x, y, z;
|
|
3514
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3515
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3516
|
-
check_intdivzero(y);
|
|
3517
|
-
z = m_right_shift(x, y);
|
|
3518
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
3519
|
-
}
|
|
3520
|
-
//
|
|
3521
|
-
}
|
|
3522
|
-
#undef check_intdivzero
|
|
3523
|
-
|
|
3524
|
-
static VALUE uint32_right_shift_self(VALUE self, VALUE other) {
|
|
3525
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3526
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3527
|
-
ndfunc_t ndf = { iter_uint32_right_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3528
|
-
|
|
3529
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3530
|
-
}
|
|
3531
|
-
|
|
3532
|
-
/*
|
|
3533
|
-
Binary right_shift.
|
|
3534
|
-
@overload >> other
|
|
3535
|
-
@param [Numo::NArray,Numeric] other
|
|
3536
|
-
@return [Numo::NArray] self >> other
|
|
3537
|
-
*/
|
|
3538
|
-
static VALUE uint32_right_shift(VALUE self, VALUE other) {
|
|
3539
|
-
|
|
3540
|
-
VALUE klass, v;
|
|
3541
|
-
|
|
3542
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3543
|
-
if (klass == cT) {
|
|
3544
|
-
return uint32_right_shift_self(self, other);
|
|
3545
|
-
} else {
|
|
3546
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3547
|
-
return rb_funcall(v, id_right_shift, 1, other);
|
|
3548
|
-
}
|
|
3549
|
-
}
|
|
3550
|
-
|
|
3551
|
-
static void iter_uint32_gt(na_loop_t* const lp) {
|
|
3552
|
-
size_t i;
|
|
3553
|
-
char *p1, *p2;
|
|
3554
|
-
BIT_DIGIT* a3;
|
|
3555
|
-
size_t p3;
|
|
3556
|
-
ssize_t s1, s2, s3;
|
|
3557
|
-
dtype x, y;
|
|
3558
|
-
BIT_DIGIT b;
|
|
3559
|
-
INIT_COUNTER(lp, i);
|
|
3560
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3561
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3562
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3563
|
-
for (; i--;) {
|
|
3564
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3565
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3566
|
-
b = (m_gt(x, y)) ? 1 : 0;
|
|
3567
|
-
STORE_BIT(a3, p3, b);
|
|
3568
|
-
p3 += s3;
|
|
3569
|
-
}
|
|
3570
|
-
}
|
|
3571
|
-
|
|
3572
|
-
static VALUE uint32_gt_self(VALUE self, VALUE other) {
|
|
3573
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3574
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3575
|
-
ndfunc_t ndf = { iter_uint32_gt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3576
|
-
|
|
3577
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3578
|
-
}
|
|
3579
|
-
|
|
3580
|
-
/*
|
|
3581
|
-
Comparison gt other.
|
|
3582
|
-
@overload gt other
|
|
3583
|
-
@param [Numo::NArray,Numeric] other
|
|
3584
|
-
@return [Numo::Bit] result of self gt other.
|
|
3585
|
-
*/
|
|
3586
|
-
static VALUE uint32_gt(VALUE self, VALUE other) {
|
|
3587
|
-
|
|
3588
|
-
VALUE klass, v;
|
|
3589
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3590
|
-
if (klass == cT) {
|
|
3591
|
-
return uint32_gt_self(self, other);
|
|
3592
|
-
} else {
|
|
3593
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3594
|
-
return rb_funcall(v, id_gt, 1, other);
|
|
3595
|
-
}
|
|
3596
|
-
}
|
|
3597
|
-
|
|
3598
|
-
static void iter_uint32_ge(na_loop_t* const lp) {
|
|
3599
|
-
size_t i;
|
|
3600
|
-
char *p1, *p2;
|
|
3601
|
-
BIT_DIGIT* a3;
|
|
3602
|
-
size_t p3;
|
|
3603
|
-
ssize_t s1, s2, s3;
|
|
3604
|
-
dtype x, y;
|
|
3605
|
-
BIT_DIGIT b;
|
|
3606
|
-
INIT_COUNTER(lp, i);
|
|
3607
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3608
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3609
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3610
|
-
for (; i--;) {
|
|
3611
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3612
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3613
|
-
b = (m_ge(x, y)) ? 1 : 0;
|
|
3614
|
-
STORE_BIT(a3, p3, b);
|
|
3615
|
-
p3 += s3;
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
|
-
|
|
3619
|
-
static VALUE uint32_ge_self(VALUE self, VALUE other) {
|
|
3620
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3621
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3622
|
-
ndfunc_t ndf = { iter_uint32_ge, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3623
|
-
|
|
3624
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3625
|
-
}
|
|
3626
|
-
|
|
3627
|
-
/*
|
|
3628
|
-
Comparison ge other.
|
|
3629
|
-
@overload ge other
|
|
3630
|
-
@param [Numo::NArray,Numeric] other
|
|
3631
|
-
@return [Numo::Bit] result of self ge other.
|
|
3632
|
-
*/
|
|
3633
|
-
static VALUE uint32_ge(VALUE self, VALUE other) {
|
|
3634
|
-
|
|
3635
|
-
VALUE klass, v;
|
|
3636
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3637
|
-
if (klass == cT) {
|
|
3638
|
-
return uint32_ge_self(self, other);
|
|
3639
|
-
} else {
|
|
3640
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3641
|
-
return rb_funcall(v, id_ge, 1, other);
|
|
3642
|
-
}
|
|
3643
|
-
}
|
|
3644
|
-
|
|
3645
|
-
static void iter_uint32_lt(na_loop_t* const lp) {
|
|
3646
|
-
size_t i;
|
|
3647
|
-
char *p1, *p2;
|
|
3648
|
-
BIT_DIGIT* a3;
|
|
3649
|
-
size_t p3;
|
|
3650
|
-
ssize_t s1, s2, s3;
|
|
3651
|
-
dtype x, y;
|
|
3652
|
-
BIT_DIGIT b;
|
|
3653
|
-
INIT_COUNTER(lp, i);
|
|
3654
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3655
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3656
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3657
|
-
for (; i--;) {
|
|
3658
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3659
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3660
|
-
b = (m_lt(x, y)) ? 1 : 0;
|
|
3661
|
-
STORE_BIT(a3, p3, b);
|
|
3662
|
-
p3 += s3;
|
|
3663
|
-
}
|
|
3664
|
-
}
|
|
3665
|
-
|
|
3666
|
-
static VALUE uint32_lt_self(VALUE self, VALUE other) {
|
|
3667
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3668
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3669
|
-
ndfunc_t ndf = { iter_uint32_lt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3670
|
-
|
|
3671
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3672
|
-
}
|
|
3673
|
-
|
|
3674
|
-
/*
|
|
3675
|
-
Comparison lt other.
|
|
3676
|
-
@overload lt other
|
|
3677
|
-
@param [Numo::NArray,Numeric] other
|
|
3678
|
-
@return [Numo::Bit] result of self lt other.
|
|
3679
|
-
*/
|
|
3680
|
-
static VALUE uint32_lt(VALUE self, VALUE other) {
|
|
3681
|
-
|
|
3682
|
-
VALUE klass, v;
|
|
3683
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3684
|
-
if (klass == cT) {
|
|
3685
|
-
return uint32_lt_self(self, other);
|
|
3686
|
-
} else {
|
|
3687
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3688
|
-
return rb_funcall(v, id_lt, 1, other);
|
|
3689
|
-
}
|
|
3690
|
-
}
|
|
3691
|
-
|
|
3692
|
-
static void iter_uint32_le(na_loop_t* const lp) {
|
|
3693
|
-
size_t i;
|
|
3694
|
-
char *p1, *p2;
|
|
3695
|
-
BIT_DIGIT* a3;
|
|
3696
|
-
size_t p3;
|
|
3697
|
-
ssize_t s1, s2, s3;
|
|
3698
|
-
dtype x, y;
|
|
3699
|
-
BIT_DIGIT b;
|
|
3700
|
-
INIT_COUNTER(lp, i);
|
|
3701
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3702
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3703
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3704
|
-
for (; i--;) {
|
|
3705
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3706
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3707
|
-
b = (m_le(x, y)) ? 1 : 0;
|
|
3708
|
-
STORE_BIT(a3, p3, b);
|
|
3709
|
-
p3 += s3;
|
|
3710
|
-
}
|
|
3711
|
-
}
|
|
3712
|
-
|
|
3713
|
-
static VALUE uint32_le_self(VALUE self, VALUE other) {
|
|
3714
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3715
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3716
|
-
ndfunc_t ndf = { iter_uint32_le, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3717
|
-
|
|
3718
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3719
|
-
}
|
|
3720
|
-
|
|
3721
|
-
/*
|
|
3722
|
-
Comparison le other.
|
|
3723
|
-
@overload le other
|
|
3724
|
-
@param [Numo::NArray,Numeric] other
|
|
3725
|
-
@return [Numo::Bit] result of self le other.
|
|
3726
|
-
*/
|
|
3727
|
-
static VALUE uint32_le(VALUE self, VALUE other) {
|
|
3728
|
-
|
|
3729
|
-
VALUE klass, v;
|
|
3730
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3731
|
-
if (klass == cT) {
|
|
3732
|
-
return uint32_le_self(self, other);
|
|
3733
|
-
} else {
|
|
3734
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3735
|
-
return rb_funcall(v, id_le, 1, other);
|
|
3736
|
-
}
|
|
3737
|
-
}
|
|
3738
|
-
|
|
3739
|
-
// ------- Integer count without weights -------
|
|
3740
|
-
|
|
3741
|
-
static void iter_uint32_bincount_32(na_loop_t* const lp) {
|
|
3742
|
-
size_t i, x, n;
|
|
3743
|
-
char *p1, *p2;
|
|
3744
|
-
ssize_t s1, s2;
|
|
3745
|
-
size_t* idx1;
|
|
3746
|
-
|
|
3747
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3748
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3749
|
-
i = lp->args[0].shape[0];
|
|
3750
|
-
n = lp->args[1].shape[0];
|
|
3751
|
-
|
|
3752
|
-
// initialize
|
|
3753
|
-
for (x = 0; x < n; x++) {
|
|
3754
|
-
*(u_int32_t*)(p2 + s2 * x) = 0;
|
|
3755
|
-
}
|
|
3756
|
-
|
|
3757
|
-
if (idx1) {
|
|
3758
|
-
for (; i--;) {
|
|
3759
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3760
|
-
(*(u_int32_t*)(p2 + s2 * x))++;
|
|
3761
|
-
}
|
|
3762
|
-
} else {
|
|
3763
|
-
for (; i--;) {
|
|
3764
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3765
|
-
(*(u_int32_t*)(p2 + s2 * x))++;
|
|
3766
|
-
}
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3770
|
-
static VALUE uint32_bincount_32(VALUE self, size_t length) {
|
|
3771
|
-
size_t shape_out[1] = { length };
|
|
3772
|
-
ndfunc_arg_in_t ain[1] = { { cT, 1 } };
|
|
3773
|
-
ndfunc_arg_out_t aout[1] = { { numo_cUInt32, 1, shape_out } };
|
|
3774
|
-
ndfunc_t ndf = {
|
|
3775
|
-
iter_uint32_bincount_32, NO_LOOP | NDF_STRIDE_LOOP | NDF_INDEX_LOOP, 1, 1, ain, aout
|
|
3776
|
-
};
|
|
3777
|
-
|
|
3778
|
-
return na_ndloop(&ndf, 1, self);
|
|
3779
|
-
}
|
|
3780
|
-
|
|
3781
|
-
static void iter_uint32_bincount_64(na_loop_t* const lp) {
|
|
3782
|
-
size_t i, x, n;
|
|
3783
|
-
char *p1, *p2;
|
|
3784
|
-
ssize_t s1, s2;
|
|
3785
|
-
size_t* idx1;
|
|
3786
|
-
|
|
3787
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3788
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3789
|
-
i = lp->args[0].shape[0];
|
|
3790
|
-
n = lp->args[1].shape[0];
|
|
3791
|
-
|
|
3792
|
-
// initialize
|
|
3793
|
-
for (x = 0; x < n; x++) {
|
|
3794
|
-
*(u_int64_t*)(p2 + s2 * x) = 0;
|
|
1453
|
+
if (nd > 0) {
|
|
1454
|
+
nd--;
|
|
3795
1455
|
}
|
|
1456
|
+
md = nd + 2;
|
|
1457
|
+
a = ALLOCA_N(VALUE, md);
|
|
3796
1458
|
|
|
1459
|
+
INIT_COUNTER(lp, i);
|
|
1460
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1461
|
+
c[nd] = 0;
|
|
3797
1462
|
if (idx1) {
|
|
3798
1463
|
for (; i--;) {
|
|
3799
1464
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3800
|
-
(
|
|
1465
|
+
yield_each_with_index(x, c, a, nd, md);
|
|
1466
|
+
c[nd]++;
|
|
3801
1467
|
}
|
|
3802
1468
|
} else {
|
|
3803
1469
|
for (; i--;) {
|
|
3804
1470
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3805
|
-
(
|
|
1471
|
+
yield_each_with_index(x, c, a, nd, md);
|
|
1472
|
+
c[nd]++;
|
|
3806
1473
|
}
|
|
3807
1474
|
}
|
|
3808
1475
|
}
|
|
3809
1476
|
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
1477
|
+
/*
|
|
1478
|
+
Invokes the given block once for each element of self,
|
|
1479
|
+
passing that element and indices along each axis as parameters.
|
|
1480
|
+
@overload each_with_index
|
|
1481
|
+
For a block `{|x,i,j,...| ... }`,
|
|
1482
|
+
@yieldparam [Numeric] x an element
|
|
1483
|
+
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1484
|
+
@return [Numo::NArray] self
|
|
1485
|
+
@see #each
|
|
1486
|
+
@see #map_with_index
|
|
1487
|
+
*/
|
|
1488
|
+
static VALUE uint32_each_with_index(VALUE self) {
|
|
1489
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1490
|
+
ndfunc_t ndf = { iter_uint32_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
3817
1491
|
|
|
3818
|
-
|
|
1492
|
+
na_ndloop_with_index(&ndf, 1, self);
|
|
1493
|
+
return self;
|
|
3819
1494
|
}
|
|
3820
|
-
// ------- end of Integer count without weights -------
|
|
3821
1495
|
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
float w;
|
|
3826
|
-
size_t i, x, n, m;
|
|
3827
|
-
char *p1, *p2, *p3;
|
|
3828
|
-
ssize_t s1, s2, s3;
|
|
3829
|
-
|
|
3830
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3831
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3832
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3833
|
-
i = lp->args[0].shape[0];
|
|
3834
|
-
m = lp->args[1].shape[0];
|
|
3835
|
-
n = lp->args[2].shape[0];
|
|
3836
|
-
|
|
3837
|
-
if (i != m) {
|
|
3838
|
-
rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight");
|
|
3839
|
-
}
|
|
1496
|
+
static inline dtype yield_map_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1497
|
+
int j;
|
|
1498
|
+
VALUE y;
|
|
3840
1499
|
|
|
3841
|
-
|
|
3842
|
-
for (
|
|
3843
|
-
|
|
3844
|
-
}
|
|
3845
|
-
for (; i--;) {
|
|
3846
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3847
|
-
GET_DATA_STRIDE(p2, s2, float, w);
|
|
3848
|
-
(*(float*)(p3 + s3 * x)) += w;
|
|
1500
|
+
a[0] = m_data_to_num(x);
|
|
1501
|
+
for (j = 0; j <= nd; j++) {
|
|
1502
|
+
a[j + 1] = SIZET2NUM(c[j]);
|
|
3849
1503
|
}
|
|
1504
|
+
y = rb_yield(rb_ary_new4(md, a));
|
|
1505
|
+
return m_num_to_data(y);
|
|
3850
1506
|
}
|
|
3851
1507
|
|
|
3852
|
-
static
|
|
3853
|
-
size_t
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
static void iter_uint32_bincount_df(na_loop_t* const lp) {
|
|
3862
|
-
double w;
|
|
3863
|
-
size_t i, x, n, m;
|
|
3864
|
-
char *p1, *p2, *p3;
|
|
3865
|
-
ssize_t s1, s2, s3;
|
|
3866
|
-
|
|
3867
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3868
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3869
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3870
|
-
i = lp->args[0].shape[0];
|
|
3871
|
-
m = lp->args[1].shape[0];
|
|
3872
|
-
n = lp->args[2].shape[0];
|
|
3873
|
-
|
|
3874
|
-
if (i != m) {
|
|
3875
|
-
rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight");
|
|
3876
|
-
}
|
|
1508
|
+
static void iter_uint32_map_with_index(na_loop_t* const lp) {
|
|
1509
|
+
size_t i;
|
|
1510
|
+
char *p1, *p2;
|
|
1511
|
+
ssize_t s1, s2;
|
|
1512
|
+
size_t *idx1, *idx2;
|
|
1513
|
+
dtype x;
|
|
1514
|
+
VALUE* a;
|
|
1515
|
+
size_t* c;
|
|
1516
|
+
int nd, md;
|
|
3877
1517
|
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
for (; i--;) {
|
|
3883
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3884
|
-
GET_DATA_STRIDE(p2, s2, double, w);
|
|
3885
|
-
(*(double*)(p3 + s3 * x)) += w;
|
|
1518
|
+
c = (size_t*)(lp->opt_ptr);
|
|
1519
|
+
nd = lp->ndim;
|
|
1520
|
+
if (nd > 0) {
|
|
1521
|
+
nd--;
|
|
3886
1522
|
}
|
|
3887
|
-
|
|
1523
|
+
md = nd + 2;
|
|
1524
|
+
a = ALLOCA_N(VALUE, md);
|
|
3888
1525
|
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 1, shape_out } };
|
|
3893
|
-
ndfunc_t ndf = { iter_uint32_bincount_df, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout };
|
|
1526
|
+
INIT_COUNTER(lp, i);
|
|
1527
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1528
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3894
1529
|
|
|
3895
|
-
|
|
1530
|
+
c[nd] = 0;
|
|
1531
|
+
if (idx1) {
|
|
1532
|
+
if (idx2) {
|
|
1533
|
+
for (; i--;) {
|
|
1534
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1535
|
+
x = yield_map_with_index(x, c, a, nd, md);
|
|
1536
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1537
|
+
c[nd]++;
|
|
1538
|
+
}
|
|
1539
|
+
} else {
|
|
1540
|
+
for (; i--;) {
|
|
1541
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1542
|
+
x = yield_map_with_index(x, c, a, nd, md);
|
|
1543
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1544
|
+
c[nd]++;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
} else {
|
|
1548
|
+
if (idx2) {
|
|
1549
|
+
for (; i--;) {
|
|
1550
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1551
|
+
x = yield_map_with_index(x, c, a, nd, md);
|
|
1552
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1553
|
+
c[nd]++;
|
|
1554
|
+
}
|
|
1555
|
+
} else {
|
|
1556
|
+
for (; i--;) {
|
|
1557
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1558
|
+
x = yield_map_with_index(x, c, a, nd, md);
|
|
1559
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1560
|
+
c[nd]++;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
3896
1564
|
}
|
|
3897
|
-
// ------- end of Float count with weights -------
|
|
3898
1565
|
|
|
3899
1566
|
/*
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
@
|
|
3907
|
-
|
|
3908
|
-
@return [
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
@example
|
|
3912
|
-
Numo::Int32[0..4].bincount
|
|
3913
|
-
# => Numo::UInt32#shape=[5]
|
|
3914
|
-
# [1, 1, 1, 1, 1]
|
|
3915
|
-
|
|
3916
|
-
Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
|
|
3917
|
-
# => Numo::UInt32#shape=[8]
|
|
3918
|
-
# [1, 3, 1, 1, 0, 0, 0, 1]
|
|
3919
|
-
|
|
3920
|
-
x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
|
|
3921
|
-
x.bincount.size == x.max+1
|
|
3922
|
-
# => true
|
|
3923
|
-
|
|
3924
|
-
w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
|
|
3925
|
-
x = Numo::Int32[0, 1, 1, 2, 2, 2]
|
|
3926
|
-
x.bincount(w)
|
|
3927
|
-
# => Numo::DFloat#shape=[3]
|
|
3928
|
-
# [0.3, 0.7, 1.1]
|
|
3929
|
-
|
|
1567
|
+
Invokes the given block once for each element of self,
|
|
1568
|
+
passing that element and indices along each axis as parameters.
|
|
1569
|
+
Creates a new NArray containing the values returned by the block.
|
|
1570
|
+
Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
|
1571
|
+
@overload map_with_index
|
|
1572
|
+
For a block `{|x,i,j,...| ... }`,
|
|
1573
|
+
@yieldparam [Numeric] x an element
|
|
1574
|
+
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1575
|
+
@return [Numo::NArray] mapped array
|
|
1576
|
+
@see #map
|
|
1577
|
+
@see #each_with_index
|
|
3930
1578
|
*/
|
|
3931
|
-
static VALUE
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
ID table[1] = { id_minlength };
|
|
3936
|
-
size_t length, minlength;
|
|
3937
|
-
|
|
3938
|
-
rb_scan_args(argc, argv, "01:", &weight, &kw);
|
|
3939
|
-
rb_get_kwargs(kw, table, 0, 1, opts);
|
|
3940
|
-
|
|
3941
|
-
v = uint32_max(0, 0, self);
|
|
3942
|
-
|
|
3943
|
-
length = NUM2SIZET(v) + 1;
|
|
1579
|
+
static VALUE uint32_map_with_index(VALUE self) {
|
|
1580
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1581
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1582
|
+
ndfunc_t ndf = { iter_uint32_map_with_index, FULL_LOOP, 1, 1, ain, aout };
|
|
3944
1583
|
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
if (minlength > length) {
|
|
3948
|
-
length = minlength;
|
|
3949
|
-
}
|
|
3950
|
-
}
|
|
1584
|
+
return na_ndloop_with_index(&ndf, 1, self);
|
|
1585
|
+
}
|
|
3951
1586
|
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
1587
|
+
static void iter_uint32_abs(na_loop_t* const lp) {
|
|
1588
|
+
size_t i;
|
|
1589
|
+
char *p1, *p2;
|
|
1590
|
+
ssize_t s1, s2;
|
|
1591
|
+
size_t *idx1, *idx2;
|
|
1592
|
+
dtype x;
|
|
1593
|
+
rtype y;
|
|
1594
|
+
INIT_COUNTER(lp, i);
|
|
1595
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1596
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1597
|
+
if (idx1) {
|
|
1598
|
+
if (idx2) {
|
|
1599
|
+
for (; i--;) {
|
|
1600
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1601
|
+
y = m_abs(x);
|
|
1602
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1603
|
+
}
|
|
3955
1604
|
} else {
|
|
3956
|
-
|
|
1605
|
+
for (; i--;) {
|
|
1606
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1607
|
+
y = m_abs(x);
|
|
1608
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1609
|
+
}
|
|
3957
1610
|
}
|
|
3958
1611
|
} else {
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
1612
|
+
if (idx2) {
|
|
1613
|
+
for (; i--;) {
|
|
1614
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1615
|
+
y = m_abs(x);
|
|
1616
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1617
|
+
}
|
|
3962
1618
|
} else {
|
|
3963
|
-
|
|
1619
|
+
for (; i--;) {
|
|
1620
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1621
|
+
y = m_abs(x);
|
|
1622
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1623
|
+
}
|
|
3964
1624
|
}
|
|
3965
1625
|
}
|
|
3966
1626
|
}
|
|
3967
1627
|
|
|
1628
|
+
/*
|
|
1629
|
+
abs of self.
|
|
1630
|
+
@overload abs
|
|
1631
|
+
@return [Numo::UInt32] abs of self.
|
|
1632
|
+
*/
|
|
1633
|
+
static VALUE uint32_abs(VALUE self) {
|
|
1634
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1635
|
+
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
1636
|
+
ndfunc_t ndf = { iter_uint32_abs, FULL_LOOP, 1, 1, ain, aout };
|
|
1637
|
+
|
|
1638
|
+
return na_ndloop(&ndf, 1, self);
|
|
1639
|
+
}
|
|
1640
|
+
|
|
3968
1641
|
static void iter_uint32_poly(na_loop_t* const lp) {
|
|
3969
1642
|
size_t i;
|
|
3970
1643
|
dtype x, y, a;
|
|
@@ -4588,50 +2261,216 @@ void Init_numo_uint32(void) {
|
|
|
4588
2261
|
rb_define_singleton_method(cT, "cast", uint32_s_cast, 1);
|
|
4589
2262
|
rb_define_method(cT, "[]", uint32_aref, -1);
|
|
4590
2263
|
rb_define_method(cT, "[]=", uint32_aset, -1);
|
|
2264
|
+
/**
|
|
2265
|
+
* return NArray with cast to the type of self.
|
|
2266
|
+
* @overload coerce_cast(type)
|
|
2267
|
+
* @return [nil]
|
|
2268
|
+
*/
|
|
4591
2269
|
rb_define_method(cT, "coerce_cast", uint32_coerce_cast, 1);
|
|
2270
|
+
/**
|
|
2271
|
+
* Convert self to Array.
|
|
2272
|
+
* @overload to_a
|
|
2273
|
+
* @return [Array]
|
|
2274
|
+
*/
|
|
4592
2275
|
rb_define_method(cT, "to_a", uint32_to_a, 0);
|
|
2276
|
+
/**
|
|
2277
|
+
* Fill elements with other.
|
|
2278
|
+
* @overload fill other
|
|
2279
|
+
* @param [Numeric] other
|
|
2280
|
+
* @return [Numo::UInt32] self.
|
|
2281
|
+
*/
|
|
4593
2282
|
rb_define_method(cT, "fill", uint32_fill, 1);
|
|
2283
|
+
/**
|
|
2284
|
+
* Format elements into strings.
|
|
2285
|
+
* @overload format format
|
|
2286
|
+
* @param [String] format
|
|
2287
|
+
* @return [Numo::RObject] array of formatted strings.
|
|
2288
|
+
*/
|
|
4594
2289
|
rb_define_method(cT, "format", uint32_format, -1);
|
|
2290
|
+
/**
|
|
2291
|
+
* Format elements into strings.
|
|
2292
|
+
* @overload format_to_a format
|
|
2293
|
+
* @param [String] format
|
|
2294
|
+
* @return [Array] array of formatted strings.
|
|
2295
|
+
*/
|
|
4595
2296
|
rb_define_method(cT, "format_to_a", uint32_format_to_a, -1);
|
|
2297
|
+
/**
|
|
2298
|
+
* Returns a string containing a human-readable representation of NArray.
|
|
2299
|
+
* @overload inspect
|
|
2300
|
+
* @return [String]
|
|
2301
|
+
*/
|
|
4596
2302
|
rb_define_method(cT, "inspect", uint32_inspect, 0);
|
|
4597
2303
|
rb_define_method(cT, "each", uint32_each, 0);
|
|
4598
2304
|
rb_define_method(cT, "map", uint32_map, 0);
|
|
4599
2305
|
rb_define_method(cT, "each_with_index", uint32_each_with_index, 0);
|
|
4600
2306
|
rb_define_method(cT, "map_with_index", uint32_map_with_index, 0);
|
|
4601
2307
|
rb_define_method(cT, "abs", uint32_abs, 0);
|
|
2308
|
+
/**
|
|
2309
|
+
* Binary add.
|
|
2310
|
+
* @overload + other
|
|
2311
|
+
* @param [Numo::NArray,Numeric] other
|
|
2312
|
+
* @return [Numo::NArray] self + other
|
|
2313
|
+
*/
|
|
4602
2314
|
rb_define_method(cT, "+", uint32_add, 1);
|
|
2315
|
+
/**
|
|
2316
|
+
* Binary sub.
|
|
2317
|
+
* @overload - other
|
|
2318
|
+
* @param [Numo::NArray,Numeric] other
|
|
2319
|
+
* @return [Numo::NArray] self - other
|
|
2320
|
+
*/
|
|
4603
2321
|
rb_define_method(cT, "-", uint32_sub, 1);
|
|
2322
|
+
/**
|
|
2323
|
+
* Binary mul.
|
|
2324
|
+
* @overload * other
|
|
2325
|
+
* @param [Numo::NArray,Numeric] other
|
|
2326
|
+
* @return [Numo::NArray] self * other
|
|
2327
|
+
*/
|
|
4604
2328
|
rb_define_method(cT, "*", uint32_mul, 1);
|
|
2329
|
+
/**
|
|
2330
|
+
* Binary div.
|
|
2331
|
+
* @overload / other
|
|
2332
|
+
* @param [Numo::NArray,Numeric] other
|
|
2333
|
+
* @return [Numo::NArray] self / other
|
|
2334
|
+
*/
|
|
4605
2335
|
rb_define_method(cT, "/", uint32_div, 1);
|
|
2336
|
+
/**
|
|
2337
|
+
* Binary mod.
|
|
2338
|
+
* @overload % other
|
|
2339
|
+
* @param [Numo::NArray,Numeric] other
|
|
2340
|
+
* @return [Numo::NArray] self % other
|
|
2341
|
+
*/
|
|
4606
2342
|
rb_define_method(cT, "%", uint32_mod, 1);
|
|
2343
|
+
/**
|
|
2344
|
+
* Binary divmod.
|
|
2345
|
+
* @overload divmod other
|
|
2346
|
+
* @param [Numo::NArray,Numeric] other
|
|
2347
|
+
* @return [Numo::NArray] divmod of self and other.
|
|
2348
|
+
*/
|
|
4607
2349
|
rb_define_method(cT, "divmod", uint32_divmod, 1);
|
|
2350
|
+
/**
|
|
2351
|
+
* Binary power.
|
|
2352
|
+
* @overload ** other
|
|
2353
|
+
* @param [Numo::NArray,Numeric] other
|
|
2354
|
+
* @return [Numo::NArray] self to the other-th power.
|
|
2355
|
+
*/
|
|
4608
2356
|
rb_define_method(cT, "**", uint32_pow, 1);
|
|
4609
2357
|
rb_define_alias(cT, "pow", "**");
|
|
2358
|
+
/**
|
|
2359
|
+
* Unary minus.
|
|
2360
|
+
* @overload -@
|
|
2361
|
+
* @return [Numo::UInt32] minus of self.
|
|
2362
|
+
*/
|
|
4610
2363
|
rb_define_method(cT, "-@", uint32_minus, 0);
|
|
2364
|
+
/**
|
|
2365
|
+
* Unary reciprocal.
|
|
2366
|
+
* @overload reciprocal
|
|
2367
|
+
* @return [Numo::UInt32] reciprocal of self.
|
|
2368
|
+
*/
|
|
4611
2369
|
rb_define_method(cT, "reciprocal", uint32_reciprocal, 0);
|
|
2370
|
+
/**
|
|
2371
|
+
* Unary sign.
|
|
2372
|
+
* @overload sign
|
|
2373
|
+
* @return [Numo::UInt32] sign of self.
|
|
2374
|
+
*/
|
|
4612
2375
|
rb_define_method(cT, "sign", uint32_sign, 0);
|
|
2376
|
+
/**
|
|
2377
|
+
* Unary square.
|
|
2378
|
+
* @overload square
|
|
2379
|
+
* @return [Numo::UInt32] square of self.
|
|
2380
|
+
*/
|
|
4613
2381
|
rb_define_method(cT, "square", uint32_square, 0);
|
|
4614
2382
|
rb_define_alias(cT, "conj", "view");
|
|
4615
2383
|
rb_define_alias(cT, "im", "view");
|
|
4616
2384
|
rb_define_alias(cT, "conjugate", "conj");
|
|
2385
|
+
/**
|
|
2386
|
+
* Comparison eq other.
|
|
2387
|
+
* @overload eq other
|
|
2388
|
+
* @param [Numo::NArray,Numeric] other
|
|
2389
|
+
* @return [Numo::Bit] result of self eq other.
|
|
2390
|
+
*/
|
|
4617
2391
|
rb_define_method(cT, "eq", uint32_eq, 1);
|
|
2392
|
+
/**
|
|
2393
|
+
* Comparison ne other.
|
|
2394
|
+
* @overload ne other
|
|
2395
|
+
* @param [Numo::NArray,Numeric] other
|
|
2396
|
+
* @return [Numo::Bit] result of self ne other.
|
|
2397
|
+
*/
|
|
4618
2398
|
rb_define_method(cT, "ne", uint32_ne, 1);
|
|
4619
2399
|
rb_define_alias(cT, "nearly_eq", "eq");
|
|
4620
2400
|
rb_define_alias(cT, "close_to", "nearly_eq");
|
|
2401
|
+
/**
|
|
2402
|
+
* Binary bit_and.
|
|
2403
|
+
* @overload & other
|
|
2404
|
+
* @param [Numo::NArray,Numeric] other
|
|
2405
|
+
* @return [Numo::NArray] self & other
|
|
2406
|
+
*/
|
|
4621
2407
|
rb_define_method(cT, "&", uint32_bit_and, 1);
|
|
2408
|
+
/**
|
|
2409
|
+
* Binary bit_or.
|
|
2410
|
+
* @overload | other
|
|
2411
|
+
* @param [Numo::NArray,Numeric] other
|
|
2412
|
+
* @return [Numo::NArray] self | other
|
|
2413
|
+
*/
|
|
4622
2414
|
rb_define_method(cT, "|", uint32_bit_or, 1);
|
|
2415
|
+
/**
|
|
2416
|
+
* Binary bit_xor.
|
|
2417
|
+
* @overload ^ other
|
|
2418
|
+
* @param [Numo::NArray,Numeric] other
|
|
2419
|
+
* @return [Numo::NArray] self ^ other
|
|
2420
|
+
*/
|
|
4623
2421
|
rb_define_method(cT, "^", uint32_bit_xor, 1);
|
|
2422
|
+
/**
|
|
2423
|
+
* Unary bit_not.
|
|
2424
|
+
* @overload ~
|
|
2425
|
+
* @return [Numo::UInt32] bit_not of self.
|
|
2426
|
+
*/
|
|
4624
2427
|
rb_define_method(cT, "~", uint32_bit_not, 0);
|
|
2428
|
+
/**
|
|
2429
|
+
* Binary left_shift.
|
|
2430
|
+
* @overload << other
|
|
2431
|
+
* @param [Numo::NArray,Numeric] other
|
|
2432
|
+
* @return [Numo::NArray] self << other
|
|
2433
|
+
*/
|
|
4625
2434
|
rb_define_method(cT, "<<", uint32_left_shift, 1);
|
|
2435
|
+
/**
|
|
2436
|
+
* Binary right_shift.
|
|
2437
|
+
* @overload >> other
|
|
2438
|
+
* @param [Numo::NArray,Numeric] other
|
|
2439
|
+
* @return [Numo::NArray] self >> other
|
|
2440
|
+
*/
|
|
4626
2441
|
rb_define_method(cT, ">>", uint32_right_shift, 1);
|
|
4627
2442
|
rb_define_alias(cT, "floor", "view");
|
|
4628
2443
|
rb_define_alias(cT, "round", "view");
|
|
4629
2444
|
rb_define_alias(cT, "ceil", "view");
|
|
4630
2445
|
rb_define_alias(cT, "trunc", "view");
|
|
4631
2446
|
rb_define_alias(cT, "rint", "view");
|
|
2447
|
+
/**
|
|
2448
|
+
* Comparison gt other.
|
|
2449
|
+
* @overload gt other
|
|
2450
|
+
* @param [Numo::NArray,Numeric] other
|
|
2451
|
+
* @return [Numo::Bit] result of self gt other.
|
|
2452
|
+
*/
|
|
4632
2453
|
rb_define_method(cT, "gt", uint32_gt, 1);
|
|
2454
|
+
/**
|
|
2455
|
+
* Comparison ge other.
|
|
2456
|
+
* @overload ge other
|
|
2457
|
+
* @param [Numo::NArray,Numeric] other
|
|
2458
|
+
* @return [Numo::Bit] result of self ge other.
|
|
2459
|
+
*/
|
|
4633
2460
|
rb_define_method(cT, "ge", uint32_ge, 1);
|
|
2461
|
+
/**
|
|
2462
|
+
* Comparison lt other.
|
|
2463
|
+
* @overload lt other
|
|
2464
|
+
* @param [Numo::NArray,Numeric] other
|
|
2465
|
+
* @return [Numo::Bit] result of self lt other.
|
|
2466
|
+
*/
|
|
4634
2467
|
rb_define_method(cT, "lt", uint32_lt, 1);
|
|
2468
|
+
/**
|
|
2469
|
+
* Comparison le other.
|
|
2470
|
+
* @overload le other
|
|
2471
|
+
* @param [Numo::NArray,Numeric] other
|
|
2472
|
+
* @return [Numo::Bit] result of self le other.
|
|
2473
|
+
*/
|
|
4635
2474
|
rb_define_method(cT, "le", uint32_le, 1);
|
|
4636
2475
|
rb_define_alias(cT, ">", "gt");
|
|
4637
2476
|
rb_define_alias(cT, ">=", "ge");
|
|
@@ -4816,6 +2655,37 @@ void Init_numo_uint32(void) {
|
|
|
4816
2655
|
* @return [Numo::UInt32]
|
|
4817
2656
|
*/
|
|
4818
2657
|
rb_define_module_function(cT, "minimum", uint32_s_minimum, -1);
|
|
2658
|
+
/**
|
|
2659
|
+
* Count the number of occurrences of each non-negative integer value.
|
|
2660
|
+
* Only Integer-types has this method.
|
|
2661
|
+
*
|
|
2662
|
+
* @overload bincount([weight], minlength:nil)
|
|
2663
|
+
* @param [SFloat or DFloat or Array] weight (optional) Array of
|
|
2664
|
+
* float values. Its size along last axis should be same as that of self.
|
|
2665
|
+
* @param [Integer] minlength (keyword, optional) Minimum size along
|
|
2666
|
+
* last axis for the output array.
|
|
2667
|
+
* @return [UInt32 or UInt64 or SFloat or DFloat]
|
|
2668
|
+
* Returns Float NArray if weight array is supplied,
|
|
2669
|
+
* otherwise returns UInt32 or UInt64 depending on the size along last axis.
|
|
2670
|
+
* @example
|
|
2671
|
+
* Numo::Int32[0..4].bincount
|
|
2672
|
+
* # => Numo::UInt32#shape=[5]
|
|
2673
|
+
* # [1, 1, 1, 1, 1]
|
|
2674
|
+
*
|
|
2675
|
+
* Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
|
|
2676
|
+
* # => Numo::UInt32#shape=[8]
|
|
2677
|
+
* # [1, 3, 1, 1, 0, 0, 0, 1]
|
|
2678
|
+
*
|
|
2679
|
+
* x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
|
|
2680
|
+
* x.bincount.size == x.max+1
|
|
2681
|
+
* # => true
|
|
2682
|
+
*
|
|
2683
|
+
* w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
|
|
2684
|
+
* x = Numo::Int32[0, 1, 1, 2, 2, 2]
|
|
2685
|
+
* x.bincount(w)
|
|
2686
|
+
* # => Numo::DFloat#shape=[3]
|
|
2687
|
+
* # [0.3, 0.7, 1.1]
|
|
2688
|
+
*/
|
|
4819
2689
|
rb_define_method(cT, "bincount", uint32_bincount, -1);
|
|
4820
2690
|
/**
|
|
4821
2691
|
* cumsum of self.
|