numo-narray-alt 0.9.11 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +7 -0
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/numo/types/robj_macro.h +1 -1
- data/ext/numo/narray/src/mh/bincount.h +233 -0
- data/ext/numo/narray/src/mh/bit/and.h +225 -0
- data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/not.h +173 -0
- data/ext/numo/narray/src/mh/bit/or.h +225 -0
- data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/xor.h +225 -0
- data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
- data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
- data/ext/numo/narray/src/mh/comp/eq.h +26 -0
- data/ext/numo/narray/src/mh/comp/ge.h +26 -0
- data/ext/numo/narray/src/mh/comp/gt.h +26 -0
- data/ext/numo/narray/src/mh/comp/le.h +26 -0
- data/ext/numo/narray/src/mh/comp/lt.h +26 -0
- data/ext/numo/narray/src/mh/comp/ne.h +26 -0
- data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
- data/ext/numo/narray/src/mh/divmod.h +142 -0
- data/ext/numo/narray/src/mh/eye.h +1 -1
- data/ext/numo/narray/src/mh/fill.h +94 -0
- data/ext/numo/narray/src/mh/format.h +108 -0
- data/ext/numo/narray/src/mh/format_to_a.h +89 -0
- data/ext/numo/narray/src/mh/inspect.h +33 -0
- data/ext/numo/narray/src/mh/isfinite.h +42 -0
- data/ext/numo/narray/src/mh/isinf.h +42 -0
- data/ext/numo/narray/src/mh/isnan.h +42 -0
- data/ext/numo/narray/src/mh/isneginf.h +42 -0
- data/ext/numo/narray/src/mh/isposinf.h +42 -0
- data/ext/numo/narray/src/mh/math/acos.h +2 -2
- data/ext/numo/narray/src/mh/math/acosh.h +2 -2
- data/ext/numo/narray/src/mh/math/asin.h +2 -2
- data/ext/numo/narray/src/mh/math/asinh.h +2 -2
- data/ext/numo/narray/src/mh/math/atan.h +2 -2
- data/ext/numo/narray/src/mh/math/atan2.h +3 -3
- data/ext/numo/narray/src/mh/math/atanh.h +2 -2
- data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
- data/ext/numo/narray/src/mh/math/cos.h +2 -2
- data/ext/numo/narray/src/mh/math/cosh.h +2 -2
- data/ext/numo/narray/src/mh/math/erf.h +2 -2
- data/ext/numo/narray/src/mh/math/erfc.h +2 -2
- data/ext/numo/narray/src/mh/math/exp.h +2 -2
- data/ext/numo/narray/src/mh/math/exp10.h +2 -2
- data/ext/numo/narray/src/mh/math/exp2.h +2 -2
- data/ext/numo/narray/src/mh/math/expm1.h +2 -2
- data/ext/numo/narray/src/mh/math/frexp.h +3 -3
- data/ext/numo/narray/src/mh/math/hypot.h +3 -3
- data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
- data/ext/numo/narray/src/mh/math/log.h +2 -2
- data/ext/numo/narray/src/mh/math/log10.h +2 -2
- data/ext/numo/narray/src/mh/math/log1p.h +2 -2
- data/ext/numo/narray/src/mh/math/log2.h +2 -2
- data/ext/numo/narray/src/mh/math/sin.h +2 -2
- data/ext/numo/narray/src/mh/math/sinc.h +2 -2
- data/ext/numo/narray/src/mh/math/sinh.h +2 -2
- data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
- data/ext/numo/narray/src/mh/math/tan.h +2 -2
- data/ext/numo/narray/src/mh/math/tanh.h +2 -2
- data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
- data/ext/numo/narray/src/mh/op/add.h +78 -0
- data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
- data/ext/numo/narray/src/mh/op/div.h +118 -0
- data/ext/numo/narray/src/mh/op/mod.h +108 -0
- data/ext/numo/narray/src/mh/op/mul.h +78 -0
- data/ext/numo/narray/src/mh/op/sub.h +78 -0
- data/ext/numo/narray/src/mh/rand.h +2 -2
- data/ext/numo/narray/src/mh/round/ceil.h +11 -0
- data/ext/numo/narray/src/mh/round/floor.h +11 -0
- data/ext/numo/narray/src/mh/round/rint.h +9 -0
- data/ext/numo/narray/src/mh/round/round.h +11 -0
- data/ext/numo/narray/src/mh/round/trunc.h +11 -0
- data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
- data/ext/numo/narray/src/mh/to_a.h +78 -0
- data/ext/numo/narray/src/t_bit.c +45 -234
- data/ext/numo/narray/src/t_dcomplex.c +584 -1809
- data/ext/numo/narray/src/t_dfloat.c +429 -2432
- data/ext/numo/narray/src/t_int16.c +481 -2283
- data/ext/numo/narray/src/t_int32.c +481 -2283
- data/ext/numo/narray/src/t_int64.c +481 -2283
- data/ext/numo/narray/src/t_int8.c +408 -1873
- data/ext/numo/narray/src/t_robject.c +448 -1977
- data/ext/numo/narray/src/t_scomplex.c +584 -1809
- data/ext/numo/narray/src/t_sfloat.c +429 -2434
- data/ext/numo/narray/src/t_uint16.c +480 -2278
- data/ext/numo/narray/src/t_uint32.c +480 -2278
- data/ext/numo/narray/src/t_uint64.c +480 -2278
- data/ext/numo/narray/src/t_uint8.c +407 -1868
- metadata +41 -2
|
@@ -43,6 +43,30 @@ 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/comp/eq.h"
|
|
59
|
+
#include "mh/comp/ne.h"
|
|
60
|
+
#include "mh/comp/gt.h"
|
|
61
|
+
#include "mh/comp/ge.h"
|
|
62
|
+
#include "mh/comp/lt.h"
|
|
63
|
+
#include "mh/comp/le.h"
|
|
64
|
+
#include "mh/bit/and.h"
|
|
65
|
+
#include "mh/bit/or.h"
|
|
66
|
+
#include "mh/bit/xor.h"
|
|
67
|
+
#include "mh/bit/not.h"
|
|
68
|
+
#include "mh/bit/left_shift.h"
|
|
69
|
+
#include "mh/bit/right_shift.h"
|
|
46
70
|
#include "mh/clip.h"
|
|
47
71
|
#include "mh/sum.h"
|
|
48
72
|
#include "mh/prod.h"
|
|
@@ -56,6 +80,7 @@ extern VALUE cRT;
|
|
|
56
80
|
#include "mh/maximum.h"
|
|
57
81
|
#include "mh/minimum.h"
|
|
58
82
|
#include "mh/minmax.h"
|
|
83
|
+
#include "mh/bincount.h"
|
|
59
84
|
#include "mh/cumsum.h"
|
|
60
85
|
#include "mh/cumprod.h"
|
|
61
86
|
#include "mh/mulsum.h"
|
|
@@ -69,6 +94,30 @@ extern VALUE cRT;
|
|
|
69
94
|
|
|
70
95
|
typedef int64_t int64; // Type aliases for shorter notation
|
|
71
96
|
// following the codebase naming convention.
|
|
97
|
+
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(int64)
|
|
98
|
+
DEF_NARRAY_TO_A_METHOD_FUNC(int64)
|
|
99
|
+
DEF_NARRAY_FILL_METHOD_FUNC(int64)
|
|
100
|
+
DEF_NARRAY_FORMAT_METHOD_FUNC(int64)
|
|
101
|
+
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(int64)
|
|
102
|
+
DEF_NARRAY_INSPECT_METHOD_FUNC(int64)
|
|
103
|
+
DEF_NARRAY_ADD_METHOD_FUNC(int64, numo_cInt64)
|
|
104
|
+
DEF_NARRAY_SUB_METHOD_FUNC(int64, numo_cInt64)
|
|
105
|
+
DEF_NARRAY_MUL_METHOD_FUNC(int64, numo_cInt64)
|
|
106
|
+
DEF_NARRAY_INT_DIV_METHOD_FUNC(int64, numo_cInt64)
|
|
107
|
+
DEF_NARRAY_INT_MOD_METHOD_FUNC(int64, numo_cInt64)
|
|
108
|
+
DEF_NARRAY_INT_DIVMOD_METHOD_FUNC(int64, numo_cInt64)
|
|
109
|
+
DEF_NARRAY_EQ_METHOD_FUNC(int64, numo_cInt64)
|
|
110
|
+
DEF_NARRAY_NE_METHOD_FUNC(int64, numo_cInt64)
|
|
111
|
+
DEF_NARRAY_GT_METHOD_FUNC(int64, numo_cInt64)
|
|
112
|
+
DEF_NARRAY_GE_METHOD_FUNC(int64, numo_cInt64)
|
|
113
|
+
DEF_NARRAY_LT_METHOD_FUNC(int64, numo_cInt64)
|
|
114
|
+
DEF_NARRAY_LE_METHOD_FUNC(int64, numo_cInt64)
|
|
115
|
+
DEF_NARRAY_INT_BIT_AND_METHOD_FUNC(int64, numo_cInt64)
|
|
116
|
+
DEF_NARRAY_INT_BIT_OR_METHOD_FUNC(int64, numo_cInt64)
|
|
117
|
+
DEF_NARRAY_INT_BIT_XOR_METHOD_FUNC(int64, numo_cInt64)
|
|
118
|
+
DEF_NARRAY_INT_BIT_NOT_METHOD_FUNC(int64, numo_cInt64)
|
|
119
|
+
DEF_NARRAY_INT_LEFT_SHIFT_METHOD_FUNC(int64, numo_cInt64)
|
|
120
|
+
DEF_NARRAY_INT_RIGHT_SHIFT_METHOD_FUNC(int64, numo_cInt64)
|
|
72
121
|
DEF_NARRAY_CLIP_METHOD_FUNC(int64, numo_cInt64)
|
|
73
122
|
DEF_NARRAY_INT_SUM_METHOD_FUNC(int64, numo_cInt64, int64_t, numo_cInt64)
|
|
74
123
|
DEF_NARRAY_INT_PROD_METHOD_FUNC(int64, numo_cInt64, int64_t, numo_cInt64)
|
|
@@ -82,6 +131,7 @@ DEF_NARRAY_INT_ARGMIN_METHOD_FUNC(int64)
|
|
|
82
131
|
DEF_NARRAY_INT_MAXIMUM_METHOD_FUNC(int64, numo_cInt64)
|
|
83
132
|
DEF_NARRAY_INT_MINIMUM_METHOD_FUNC(int64, numo_cInt64)
|
|
84
133
|
DEF_NARRAY_INT_MINMAX_METHOD_FUNC(int64, numo_cInt64)
|
|
134
|
+
DEF_NARRAY_INT_BINCOUNT_METHOD_FUNC(int64, numo_cInt64)
|
|
85
135
|
DEF_NARRAY_INT_CUMSUM_METHOD_FUNC(int64, numo_cInt64)
|
|
86
136
|
DEF_NARRAY_INT_CUMPROD_METHOD_FUNC(int64, numo_cInt64)
|
|
87
137
|
DEF_NARRAY_INT_MULSUM_METHOD_FUNC(int64, numo_cInt64)
|
|
@@ -1252,204 +1302,6 @@ static VALUE int64_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1252
1302
|
return argv[argc];
|
|
1253
1303
|
}
|
|
1254
1304
|
|
|
1255
|
-
/*
|
|
1256
|
-
return NArray with cast to the type of self.
|
|
1257
|
-
@overload coerce_cast(type)
|
|
1258
|
-
@return [nil]
|
|
1259
|
-
*/
|
|
1260
|
-
static VALUE int64_coerce_cast(VALUE self, VALUE type) {
|
|
1261
|
-
return Qnil;
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
static void iter_int64_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 int64_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_int64_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_int64_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::Int64] self.
|
|
1328
|
-
*/
|
|
1329
|
-
static VALUE int64_fill(VALUE self, VALUE val) {
|
|
1330
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
|
|
1331
|
-
ndfunc_t ndf = { iter_int64_fill, FULL_LOOP, 2, 0, ain, 0 };
|
|
1332
|
-
|
|
1333
|
-
na_ndloop(&ndf, 2, self, val);
|
|
1334
|
-
return self;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
static VALUE format_int64(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_int64_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_int64(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_int64(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 int64_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_int64_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_int64_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_int64(fmt, x);
|
|
1412
|
-
rb_ary_push(a, y);
|
|
1413
|
-
}
|
|
1414
|
-
} else {
|
|
1415
|
-
for (; i--;) {
|
|
1416
|
-
x = (dtype*)p1;
|
|
1417
|
-
p1 += s1;
|
|
1418
|
-
y = format_int64(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 int64_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_int64_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_int64_inspect(char* ptr, size_t pos, VALUE fmt) {
|
|
1441
|
-
return format_int64(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 int64_inspect(VALUE ary) {
|
|
1450
|
-
return na_ndloop_inspect(ary, iter_int64_inspect, Qnil);
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
1305
|
static void iter_int64_each(na_loop_t* const lp) {
|
|
1454
1306
|
size_t i, s1;
|
|
1455
1307
|
char* p1;
|
|
@@ -1776,2199 +1628,374 @@ static VALUE int64_abs(VALUE self) {
|
|
|
1776
1628
|
return na_ndloop(&ndf, 1, self);
|
|
1777
1629
|
}
|
|
1778
1630
|
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
static void iter_int64_add(na_loop_t* const lp) {
|
|
1783
|
-
size_t i = 0;
|
|
1784
|
-
size_t n;
|
|
1631
|
+
static void iter_int64_pow(na_loop_t* const lp) {
|
|
1632
|
+
size_t i;
|
|
1785
1633
|
char *p1, *p2, *p3;
|
|
1786
1634
|
ssize_t s1, s2, s3;
|
|
1787
|
-
|
|
1788
|
-
INIT_COUNTER(lp,
|
|
1635
|
+
dtype x, y;
|
|
1636
|
+
INIT_COUNTER(lp, i);
|
|
1789
1637
|
INIT_PTR(lp, 0, p1, s1);
|
|
1790
1638
|
INIT_PTR(lp, 1, p2, s2);
|
|
1791
1639
|
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;
|
|
1640
|
+
for (; i--;) {
|
|
1860
1641
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1861
1642
|
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1643
|
+
x = (dtype)m_pow((int)x, (int)y);
|
|
1644
|
+
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
static void iter_int64_pow_int32(na_loop_t* const lp) {
|
|
1649
|
+
size_t i;
|
|
1650
|
+
char *p1, *p2, *p3;
|
|
1651
|
+
ssize_t s1, s2, s3;
|
|
1652
|
+
dtype x;
|
|
1653
|
+
int32_t y;
|
|
1654
|
+
INIT_COUNTER(lp, i);
|
|
1655
|
+
INIT_PTR(lp, 0, p1, s1);
|
|
1656
|
+
INIT_PTR(lp, 1, p2, s2);
|
|
1657
|
+
INIT_PTR(lp, 2, p3, s3);
|
|
1658
|
+
for (; i--;) {
|
|
1659
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1660
|
+
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
1661
|
+
x = m_pow_int(x, y);
|
|
1662
|
+
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
1865
1663
|
}
|
|
1866
|
-
//
|
|
1867
1664
|
}
|
|
1868
|
-
#undef check_intdivzero
|
|
1869
1665
|
|
|
1870
|
-
static VALUE
|
|
1666
|
+
static VALUE int64_pow_self(VALUE self, VALUE other) {
|
|
1871
1667
|
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1668
|
+
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
1872
1669
|
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1873
|
-
ndfunc_t ndf = {
|
|
1670
|
+
ndfunc_t ndf = { iter_int64_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1671
|
+
ndfunc_t ndf_i = { iter_int64_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
1874
1672
|
|
|
1875
|
-
|
|
1673
|
+
// fixme : use na.integer?
|
|
1674
|
+
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
1675
|
+
return na_ndloop(&ndf_i, 2, self, other);
|
|
1676
|
+
} else {
|
|
1677
|
+
return na_ndloop(&ndf, 2, self, other);
|
|
1678
|
+
}
|
|
1876
1679
|
}
|
|
1877
1680
|
|
|
1878
1681
|
/*
|
|
1879
|
-
Binary
|
|
1880
|
-
@overload
|
|
1682
|
+
Binary power.
|
|
1683
|
+
@overload ** other
|
|
1881
1684
|
@param [Numo::NArray,Numeric] other
|
|
1882
|
-
@return [Numo::NArray] self
|
|
1685
|
+
@return [Numo::NArray] self to the other-th power.
|
|
1883
1686
|
*/
|
|
1884
|
-
static VALUE
|
|
1687
|
+
static VALUE int64_pow(VALUE self, VALUE other) {
|
|
1885
1688
|
|
|
1886
1689
|
VALUE klass, v;
|
|
1887
|
-
|
|
1888
1690
|
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
1889
1691
|
if (klass == cT) {
|
|
1890
|
-
return
|
|
1692
|
+
return int64_pow_self(self, other);
|
|
1891
1693
|
} else {
|
|
1892
1694
|
v = rb_funcall(klass, id_cast, 1, self);
|
|
1893
|
-
return rb_funcall(v,
|
|
1695
|
+
return rb_funcall(v, id_pow, 1, other);
|
|
1894
1696
|
}
|
|
1895
1697
|
}
|
|
1896
1698
|
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
size_t
|
|
1902
|
-
|
|
1903
|
-
char *p1, *p2, *p3;
|
|
1904
|
-
ssize_t s1, s2, s3;
|
|
1699
|
+
static void iter_int64_minus(na_loop_t* const lp) {
|
|
1700
|
+
size_t i, n;
|
|
1701
|
+
char *p1, *p2;
|
|
1702
|
+
ssize_t s1, s2;
|
|
1703
|
+
size_t *idx1, *idx2;
|
|
1704
|
+
dtype x;
|
|
1905
1705
|
|
|
1906
1706
|
INIT_COUNTER(lp, n);
|
|
1907
|
-
|
|
1908
|
-
|
|
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))) {
|
|
1707
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1708
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1914
1709
|
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1710
|
+
if (idx1) {
|
|
1711
|
+
if (idx2) {
|
|
1712
|
+
for (i = 0; i < n; i++) {
|
|
1713
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1714
|
+
x = m_minus(x);
|
|
1715
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1716
|
+
}
|
|
1717
|
+
} else {
|
|
1718
|
+
for (i = 0; i < n; i++) {
|
|
1719
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1720
|
+
x = m_minus(x);
|
|
1721
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1926
1722
|
}
|
|
1927
|
-
return;
|
|
1928
1723
|
}
|
|
1929
|
-
|
|
1930
|
-
if (
|
|
1931
|
-
|
|
1724
|
+
} else {
|
|
1725
|
+
if (idx2) {
|
|
1726
|
+
for (i = 0; i < n; i++) {
|
|
1727
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1728
|
+
x = m_minus(x);
|
|
1729
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1730
|
+
}
|
|
1731
|
+
} else {
|
|
1932
1732
|
//
|
|
1933
|
-
|
|
1934
|
-
|
|
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 {
|
|
1733
|
+
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1734
|
+
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1947
1735
|
for (i = 0; i < n; i++) {
|
|
1948
|
-
|
|
1949
|
-
p1 += s1;
|
|
1950
|
-
p3 += s3;
|
|
1736
|
+
((dtype*)p2)[i] = m_minus(((dtype*)p1)[i]);
|
|
1951
1737
|
}
|
|
1738
|
+
return;
|
|
1952
1739
|
}
|
|
1953
|
-
|
|
1954
|
-
|
|
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 {
|
|
1740
|
+
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1741
|
+
//
|
|
1962
1742
|
for (i = 0; i < n; i++) {
|
|
1963
|
-
|
|
1964
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1743
|
+
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
1965
1744
|
p1 += s1;
|
|
1966
1745
|
p2 += s2;
|
|
1967
|
-
p3 += s3;
|
|
1968
1746
|
}
|
|
1747
|
+
return;
|
|
1748
|
+
//
|
|
1969
1749
|
}
|
|
1970
1750
|
}
|
|
1971
|
-
|
|
1972
|
-
|
|
1751
|
+
for (i = 0; i < n; i++) {
|
|
1752
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1753
|
+
x = m_minus(x);
|
|
1754
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1755
|
+
}
|
|
1973
1756
|
//
|
|
1974
1757
|
}
|
|
1975
1758
|
}
|
|
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
1759
|
}
|
|
1986
|
-
#undef check_intdivzero
|
|
1987
1760
|
|
|
1988
|
-
|
|
1989
|
-
|
|
1761
|
+
/*
|
|
1762
|
+
Unary minus.
|
|
1763
|
+
@overload -@
|
|
1764
|
+
@return [Numo::Int64] minus of self.
|
|
1765
|
+
*/
|
|
1766
|
+
static VALUE int64_minus(VALUE self) {
|
|
1767
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1990
1768
|
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1991
|
-
ndfunc_t ndf = {
|
|
1769
|
+
ndfunc_t ndf = { iter_int64_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
1992
1770
|
|
|
1993
|
-
return na_ndloop(&ndf,
|
|
1771
|
+
return na_ndloop(&ndf, 1, self);
|
|
1994
1772
|
}
|
|
1995
1773
|
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
static VALUE int64_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 int64_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_int64_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;
|
|
1774
|
+
static void iter_int64_reciprocal(na_loop_t* const lp) {
|
|
1775
|
+
size_t i, n;
|
|
1776
|
+
char *p1, *p2;
|
|
1777
|
+
ssize_t s1, s2;
|
|
1778
|
+
size_t *idx1, *idx2;
|
|
1779
|
+
dtype x;
|
|
2023
1780
|
|
|
2024
1781
|
INIT_COUNTER(lp, n);
|
|
2025
|
-
|
|
2026
|
-
|
|
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))) {
|
|
1782
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1783
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2032
1784
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
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
|
-
}
|
|
1785
|
+
if (idx1) {
|
|
1786
|
+
if (idx2) {
|
|
1787
|
+
for (i = 0; i < n; i++) {
|
|
1788
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1789
|
+
x = m_reciprocal(x);
|
|
1790
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2044
1791
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
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
|
-
}
|
|
1792
|
+
} else {
|
|
1793
|
+
for (i = 0; i < n; i++) {
|
|
1794
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1795
|
+
x = m_reciprocal(x);
|
|
1796
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2088
1797
|
}
|
|
2089
|
-
|
|
2090
|
-
return;
|
|
2091
|
-
//
|
|
2092
1798
|
}
|
|
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 int64_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_int64_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 int64_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 int64_mul_self(self, other);
|
|
2127
1799
|
} else {
|
|
2128
|
-
|
|
2129
|
-
|
|
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_int64_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
|
-
}
|
|
1800
|
+
if (idx2) {
|
|
1801
|
+
for (i = 0; i < n; i++) {
|
|
1802
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1803
|
+
x = m_reciprocal(x);
|
|
1804
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2165
1805
|
}
|
|
2166
|
-
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2170
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
1806
|
+
} else {
|
|
2171
1807
|
//
|
|
2172
|
-
|
|
2173
|
-
|
|
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 {
|
|
1808
|
+
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1809
|
+
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2186
1810
|
for (i = 0; i < n; i++) {
|
|
2187
|
-
|
|
2188
|
-
p1 += s1;
|
|
2189
|
-
p3 += s3;
|
|
1811
|
+
((dtype*)p2)[i] = m_reciprocal(((dtype*)p1)[i]);
|
|
2190
1812
|
}
|
|
1813
|
+
return;
|
|
2191
1814
|
}
|
|
2192
|
-
|
|
2193
|
-
|
|
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 {
|
|
1815
|
+
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1816
|
+
//
|
|
2201
1817
|
for (i = 0; i < n; i++) {
|
|
2202
|
-
|
|
2203
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
1818
|
+
*(dtype*)p2 = m_reciprocal(*(dtype*)p1);
|
|
2204
1819
|
p1 += s1;
|
|
2205
1820
|
p2 += s2;
|
|
2206
|
-
p3 += s3;
|
|
2207
1821
|
}
|
|
1822
|
+
return;
|
|
1823
|
+
//
|
|
2208
1824
|
}
|
|
2209
1825
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
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 int64_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_int64_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 int64_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 int64_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_int64_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
|
-
}
|
|
1826
|
+
for (i = 0; i < n; i++) {
|
|
1827
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1828
|
+
x = m_reciprocal(x);
|
|
1829
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2330
1830
|
}
|
|
2331
|
-
|
|
2332
|
-
return;
|
|
2333
1831
|
//
|
|
2334
1832
|
}
|
|
2335
1833
|
}
|
|
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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_divmod, STRIDE_LOOP, 2, 2, ain, aout };
|
|
2402
|
-
|
|
2403
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2404
1834
|
}
|
|
2405
1835
|
|
|
2406
1836
|
/*
|
|
2407
|
-
|
|
2408
|
-
@overload
|
|
2409
|
-
@
|
|
2410
|
-
@return [Numo::NArray] divmod of self and other.
|
|
2411
|
-
*/
|
|
2412
|
-
static VALUE int64_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 int64_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_int64_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 = (dtype)m_pow((int)x, (int)y);
|
|
2437
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2438
|
-
}
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
static void iter_int64_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 int64_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_int64_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2464
|
-
ndfunc_t ndf_i = { iter_int64_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 int64_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 int64_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_int64_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::Int64] minus of self.
|
|
2558
|
-
*/
|
|
2559
|
-
static VALUE int64_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_int64_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
2563
|
-
|
|
2564
|
-
return na_ndloop(&ndf, 1, self);
|
|
2565
|
-
}
|
|
2566
|
-
|
|
2567
|
-
static void iter_int64_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::Int64] reciprocal of self.
|
|
1837
|
+
Unary reciprocal.
|
|
1838
|
+
@overload reciprocal
|
|
1839
|
+
@return [Numo::Int64] reciprocal of self.
|
|
2633
1840
|
*/
|
|
2634
1841
|
static VALUE int64_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_int64_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
2638
|
-
|
|
2639
|
-
return na_ndloop(&ndf, 1, self);
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
static void iter_int64_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::Int64] sign of self.
|
|
2708
|
-
*/
|
|
2709
|
-
static VALUE int64_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_int64_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
2713
|
-
|
|
2714
|
-
return na_ndloop(&ndf, 1, self);
|
|
2715
|
-
}
|
|
2716
|
-
|
|
2717
|
-
static void iter_int64_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::Int64] square of self.
|
|
2783
|
-
*/
|
|
2784
|
-
static VALUE int64_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_int64_square, FULL_LOOP, 1, 1, ain, aout };
|
|
2788
|
-
|
|
2789
|
-
return na_ndloop(&ndf, 1, self);
|
|
2790
|
-
}
|
|
2791
|
-
|
|
2792
|
-
static void iter_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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::Int64] bit_not of self.
|
|
3306
|
-
*/
|
|
3307
|
-
static VALUE int64_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_int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_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 int64_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 int64_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_int64_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 int64_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_int64_bincount_32, NO_LOOP | NDF_STRIDE_LOOP | NDF_INDEX_LOOP, 1, 1, ain, aout
|
|
3776
|
-
};
|
|
1842
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1843
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1844
|
+
ndfunc_t ndf = { iter_int64_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
3777
1845
|
|
|
3778
1846
|
return na_ndloop(&ndf, 1, self);
|
|
3779
1847
|
}
|
|
3780
1848
|
|
|
3781
|
-
static void
|
|
3782
|
-
size_t i,
|
|
1849
|
+
static void iter_int64_sign(na_loop_t* const lp) {
|
|
1850
|
+
size_t i, n;
|
|
3783
1851
|
char *p1, *p2;
|
|
3784
1852
|
ssize_t s1, s2;
|
|
3785
|
-
size_t*
|
|
1853
|
+
size_t *idx1, *idx2;
|
|
1854
|
+
dtype x;
|
|
3786
1855
|
|
|
1856
|
+
INIT_COUNTER(lp, n);
|
|
3787
1857
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3788
|
-
|
|
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;
|
|
3795
|
-
}
|
|
1858
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3796
1859
|
|
|
3797
1860
|
if (idx1) {
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
1861
|
+
if (idx2) {
|
|
1862
|
+
for (i = 0; i < n; i++) {
|
|
1863
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1864
|
+
x = m_sign(x);
|
|
1865
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1866
|
+
}
|
|
1867
|
+
} else {
|
|
1868
|
+
for (i = 0; i < n; i++) {
|
|
1869
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1870
|
+
x = m_sign(x);
|
|
1871
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1872
|
+
}
|
|
3801
1873
|
}
|
|
3802
1874
|
} else {
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
1875
|
+
if (idx2) {
|
|
1876
|
+
for (i = 0; i < n; i++) {
|
|
1877
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1878
|
+
x = m_sign(x);
|
|
1879
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1880
|
+
}
|
|
1881
|
+
} else {
|
|
1882
|
+
//
|
|
1883
|
+
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1884
|
+
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1885
|
+
for (i = 0; i < n; i++) {
|
|
1886
|
+
((dtype*)p2)[i] = m_sign(((dtype*)p1)[i]);
|
|
1887
|
+
}
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1891
|
+
//
|
|
1892
|
+
for (i = 0; i < n; i++) {
|
|
1893
|
+
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
1894
|
+
p1 += s1;
|
|
1895
|
+
p2 += s2;
|
|
1896
|
+
}
|
|
1897
|
+
return;
|
|
1898
|
+
//
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
for (i = 0; i < n; i++) {
|
|
1902
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1903
|
+
x = m_sign(x);
|
|
1904
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1905
|
+
}
|
|
1906
|
+
//
|
|
3806
1907
|
}
|
|
3807
1908
|
}
|
|
3808
1909
|
}
|
|
3809
1910
|
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
};
|
|
1911
|
+
/*
|
|
1912
|
+
Unary sign.
|
|
1913
|
+
@overload sign
|
|
1914
|
+
@return [Numo::Int64] sign of self.
|
|
1915
|
+
*/
|
|
1916
|
+
static VALUE int64_sign(VALUE self) {
|
|
1917
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1918
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1919
|
+
ndfunc_t ndf = { iter_int64_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
3817
1920
|
|
|
3818
1921
|
return na_ndloop(&ndf, 1, self);
|
|
3819
1922
|
}
|
|
3820
|
-
// ------- end of Integer count without weights -------
|
|
3821
|
-
|
|
3822
|
-
// ------- Float count with weights -------
|
|
3823
|
-
|
|
3824
|
-
static void iter_int64_bincount_sf(na_loop_t* const lp) {
|
|
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
|
-
}
|
|
3840
|
-
|
|
3841
|
-
// initialize
|
|
3842
|
-
for (x = 0; x < n; x++) {
|
|
3843
|
-
*(float*)(p3 + s3 * x) = 0;
|
|
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;
|
|
3849
|
-
}
|
|
3850
|
-
}
|
|
3851
|
-
|
|
3852
|
-
static VALUE int64_bincount_sf(VALUE self, VALUE weight, size_t length) {
|
|
3853
|
-
size_t shape_out[1] = { length };
|
|
3854
|
-
ndfunc_arg_in_t ain[2] = { { cT, 1 }, { numo_cSFloat, 1 } };
|
|
3855
|
-
ndfunc_arg_out_t aout[1] = { { numo_cSFloat, 1, shape_out } };
|
|
3856
|
-
ndfunc_t ndf = { iter_int64_bincount_sf, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout };
|
|
3857
|
-
|
|
3858
|
-
return na_ndloop(&ndf, 2, self, weight);
|
|
3859
|
-
}
|
|
3860
|
-
|
|
3861
|
-
static void iter_int64_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
|
-
}
|
|
3877
|
-
|
|
3878
|
-
// initialize
|
|
3879
|
-
for (x = 0; x < n; x++) {
|
|
3880
|
-
*(double*)(p3 + s3 * x) = 0;
|
|
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;
|
|
3886
|
-
}
|
|
3887
|
-
}
|
|
3888
|
-
|
|
3889
|
-
static VALUE int64_bincount_df(VALUE self, VALUE weight, size_t length) {
|
|
3890
|
-
size_t shape_out[1] = { length };
|
|
3891
|
-
ndfunc_arg_in_t ain[2] = { { cT, 1 }, { numo_cDFloat, 1 } };
|
|
3892
|
-
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 1, shape_out } };
|
|
3893
|
-
ndfunc_t ndf = { iter_int64_bincount_df, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout };
|
|
3894
|
-
|
|
3895
|
-
return na_ndloop(&ndf, 2, self, weight);
|
|
3896
|
-
}
|
|
3897
|
-
// ------- end of Float count with weights -------
|
|
3898
|
-
|
|
3899
|
-
/*
|
|
3900
|
-
Count the number of occurrences of each non-negative integer value.
|
|
3901
|
-
Only Integer-types has this method.
|
|
3902
|
-
|
|
3903
|
-
@overload bincount([weight], minlength:nil)
|
|
3904
|
-
@param [SFloat or DFloat or Array] weight (optional) Array of
|
|
3905
|
-
float values. Its size along last axis should be same as that of self.
|
|
3906
|
-
@param [Integer] minlength (keyword, optional) Minimum size along
|
|
3907
|
-
last axis for the output array.
|
|
3908
|
-
@return [UInt32 or UInt64 or SFloat or DFloat]
|
|
3909
|
-
Returns Float NArray if weight array is supplied,
|
|
3910
|
-
otherwise returns UInt32 or UInt64 depending on the size along last axis.
|
|
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
1923
|
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
*/
|
|
3931
|
-
static VALUE int64_bincount(int argc, VALUE* argv, VALUE self) {
|
|
3932
|
-
VALUE weight = Qnil, kw = Qnil;
|
|
3933
|
-
VALUE opts[1] = { Qundef };
|
|
3934
|
-
VALUE v, wclass;
|
|
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 = int64_minmax(0, 0, self);
|
|
3942
|
-
if (m_num_to_data(RARRAY_AREF(v, 0)) < 0) {
|
|
3943
|
-
rb_raise(rb_eArgError, "array items must be non-netagive");
|
|
3944
|
-
}
|
|
3945
|
-
v = RARRAY_AREF(v, 1);
|
|
3946
|
-
|
|
3947
|
-
length = NUM2SIZET(v) + 1;
|
|
1924
|
+
static void iter_int64_square(na_loop_t* const lp) {
|
|
1925
|
+
size_t i, n;
|
|
1926
|
+
char *p1, *p2;
|
|
1927
|
+
ssize_t s1, s2;
|
|
1928
|
+
size_t *idx1, *idx2;
|
|
1929
|
+
dtype x;
|
|
3948
1930
|
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
length = minlength;
|
|
3953
|
-
}
|
|
3954
|
-
}
|
|
1931
|
+
INIT_COUNTER(lp, n);
|
|
1932
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1933
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3955
1934
|
|
|
3956
|
-
if (
|
|
3957
|
-
if (
|
|
3958
|
-
|
|
1935
|
+
if (idx1) {
|
|
1936
|
+
if (idx2) {
|
|
1937
|
+
for (i = 0; i < n; i++) {
|
|
1938
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1939
|
+
x = m_square(x);
|
|
1940
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1941
|
+
}
|
|
3959
1942
|
} else {
|
|
3960
|
-
|
|
1943
|
+
for (i = 0; i < n; i++) {
|
|
1944
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1945
|
+
x = m_square(x);
|
|
1946
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1947
|
+
}
|
|
3961
1948
|
}
|
|
3962
1949
|
} else {
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
1950
|
+
if (idx2) {
|
|
1951
|
+
for (i = 0; i < n; i++) {
|
|
1952
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1953
|
+
x = m_square(x);
|
|
1954
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1955
|
+
}
|
|
3966
1956
|
} else {
|
|
3967
|
-
|
|
1957
|
+
//
|
|
1958
|
+
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1959
|
+
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1960
|
+
for (i = 0; i < n; i++) {
|
|
1961
|
+
((dtype*)p2)[i] = m_square(((dtype*)p1)[i]);
|
|
1962
|
+
}
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1966
|
+
//
|
|
1967
|
+
for (i = 0; i < n; i++) {
|
|
1968
|
+
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
1969
|
+
p1 += s1;
|
|
1970
|
+
p2 += s2;
|
|
1971
|
+
}
|
|
1972
|
+
return;
|
|
1973
|
+
//
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
for (i = 0; i < n; i++) {
|
|
1977
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1978
|
+
x = m_square(x);
|
|
1979
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1980
|
+
}
|
|
1981
|
+
//
|
|
3968
1982
|
}
|
|
3969
1983
|
}
|
|
3970
1984
|
}
|
|
3971
1985
|
|
|
1986
|
+
/*
|
|
1987
|
+
Unary square.
|
|
1988
|
+
@overload square
|
|
1989
|
+
@return [Numo::Int64] square of self.
|
|
1990
|
+
*/
|
|
1991
|
+
static VALUE int64_square(VALUE self) {
|
|
1992
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1993
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1994
|
+
ndfunc_t ndf = { iter_int64_square, FULL_LOOP, 1, 1, ain, aout };
|
|
1995
|
+
|
|
1996
|
+
return na_ndloop(&ndf, 1, self);
|
|
1997
|
+
}
|
|
1998
|
+
|
|
3972
1999
|
static void iter_int64_poly(na_loop_t* const lp) {
|
|
3973
2000
|
size_t i;
|
|
3974
2001
|
dtype x, y, a;
|
|
@@ -4592,22 +2619,91 @@ void Init_numo_int64(void) {
|
|
|
4592
2619
|
rb_define_singleton_method(cT, "cast", int64_s_cast, 1);
|
|
4593
2620
|
rb_define_method(cT, "[]", int64_aref, -1);
|
|
4594
2621
|
rb_define_method(cT, "[]=", int64_aset, -1);
|
|
2622
|
+
/**
|
|
2623
|
+
* return NArray with cast to the type of self.
|
|
2624
|
+
* @overload coerce_cast(type)
|
|
2625
|
+
* @return [nil]
|
|
2626
|
+
*/
|
|
4595
2627
|
rb_define_method(cT, "coerce_cast", int64_coerce_cast, 1);
|
|
2628
|
+
/**
|
|
2629
|
+
* Convert self to Array.
|
|
2630
|
+
* @overload to_a
|
|
2631
|
+
* @return [Array]
|
|
2632
|
+
*/
|
|
4596
2633
|
rb_define_method(cT, "to_a", int64_to_a, 0);
|
|
2634
|
+
/**
|
|
2635
|
+
* Fill elements with other.
|
|
2636
|
+
* @overload fill other
|
|
2637
|
+
* @param [Numeric] other
|
|
2638
|
+
* @return [Numo::Int64] self.
|
|
2639
|
+
*/
|
|
4597
2640
|
rb_define_method(cT, "fill", int64_fill, 1);
|
|
2641
|
+
/**
|
|
2642
|
+
* Format elements into strings.
|
|
2643
|
+
* @overload format format
|
|
2644
|
+
* @param [String] format
|
|
2645
|
+
* @return [Numo::RObject] array of formatted strings.
|
|
2646
|
+
*/
|
|
4598
2647
|
rb_define_method(cT, "format", int64_format, -1);
|
|
2648
|
+
/**
|
|
2649
|
+
* Format elements into strings.
|
|
2650
|
+
* @overload format_to_a format
|
|
2651
|
+
* @param [String] format
|
|
2652
|
+
* @return [Array] array of formatted strings.
|
|
2653
|
+
*/
|
|
4599
2654
|
rb_define_method(cT, "format_to_a", int64_format_to_a, -1);
|
|
2655
|
+
/**
|
|
2656
|
+
* Returns a string containing a human-readable representation of NArray.
|
|
2657
|
+
* @overload inspect
|
|
2658
|
+
* @return [String]
|
|
2659
|
+
*/
|
|
4600
2660
|
rb_define_method(cT, "inspect", int64_inspect, 0);
|
|
4601
2661
|
rb_define_method(cT, "each", int64_each, 0);
|
|
4602
2662
|
rb_define_method(cT, "map", int64_map, 0);
|
|
4603
2663
|
rb_define_method(cT, "each_with_index", int64_each_with_index, 0);
|
|
4604
2664
|
rb_define_method(cT, "map_with_index", int64_map_with_index, 0);
|
|
4605
2665
|
rb_define_method(cT, "abs", int64_abs, 0);
|
|
2666
|
+
/**
|
|
2667
|
+
* Binary add.
|
|
2668
|
+
* @overload + other
|
|
2669
|
+
* @param [Numo::NArray,Numeric] other
|
|
2670
|
+
* @return [Numo::NArray] self + other
|
|
2671
|
+
*/
|
|
4606
2672
|
rb_define_method(cT, "+", int64_add, 1);
|
|
2673
|
+
/**
|
|
2674
|
+
* Binary sub.
|
|
2675
|
+
* @overload - other
|
|
2676
|
+
* @param [Numo::NArray,Numeric] other
|
|
2677
|
+
* @return [Numo::NArray] self - other
|
|
2678
|
+
*/
|
|
4607
2679
|
rb_define_method(cT, "-", int64_sub, 1);
|
|
2680
|
+
/**
|
|
2681
|
+
* Binary mul.
|
|
2682
|
+
* @overload * other
|
|
2683
|
+
* @param [Numo::NArray,Numeric] other
|
|
2684
|
+
* @return [Numo::NArray] self * other
|
|
2685
|
+
*/
|
|
4608
2686
|
rb_define_method(cT, "*", int64_mul, 1);
|
|
2687
|
+
/**
|
|
2688
|
+
* Binary div.
|
|
2689
|
+
* @overload / other
|
|
2690
|
+
* @param [Numo::NArray,Numeric] other
|
|
2691
|
+
* @return [Numo::NArray] self / other
|
|
2692
|
+
*/
|
|
4609
2693
|
rb_define_method(cT, "/", int64_div, 1);
|
|
2694
|
+
/**
|
|
2695
|
+
* Binary mod.
|
|
2696
|
+
* @overload % other
|
|
2697
|
+
* @param [Numo::NArray,Numeric] other
|
|
2698
|
+
* @return [Numo::NArray] self % other
|
|
2699
|
+
*/
|
|
4610
2700
|
rb_define_method(cT, "%", int64_mod, 1);
|
|
2701
|
+
/**
|
|
2702
|
+
* Binary divmod.
|
|
2703
|
+
* @overload divmod other
|
|
2704
|
+
* @param [Numo::NArray,Numeric] other
|
|
2705
|
+
* @return [Numo::NArray] divmod of self and other.
|
|
2706
|
+
*/
|
|
4611
2707
|
rb_define_method(cT, "divmod", int64_divmod, 1);
|
|
4612
2708
|
rb_define_method(cT, "**", int64_pow, 1);
|
|
4613
2709
|
rb_define_alias(cT, "pow", "**");
|
|
@@ -4618,24 +2714,95 @@ void Init_numo_int64(void) {
|
|
|
4618
2714
|
rb_define_alias(cT, "conj", "view");
|
|
4619
2715
|
rb_define_alias(cT, "im", "view");
|
|
4620
2716
|
rb_define_alias(cT, "conjugate", "conj");
|
|
2717
|
+
/**
|
|
2718
|
+
* Comparison eq other.
|
|
2719
|
+
* @overload eq other
|
|
2720
|
+
* @param [Numo::NArray,Numeric] other
|
|
2721
|
+
* @return [Numo::Bit] result of self eq other.
|
|
2722
|
+
*/
|
|
4621
2723
|
rb_define_method(cT, "eq", int64_eq, 1);
|
|
2724
|
+
/**
|
|
2725
|
+
* Comparison ne other.
|
|
2726
|
+
* @overload ne other
|
|
2727
|
+
* @param [Numo::NArray,Numeric] other
|
|
2728
|
+
* @return [Numo::Bit] result of self ne other.
|
|
2729
|
+
*/
|
|
4622
2730
|
rb_define_method(cT, "ne", int64_ne, 1);
|
|
4623
2731
|
rb_define_alias(cT, "nearly_eq", "eq");
|
|
4624
2732
|
rb_define_alias(cT, "close_to", "nearly_eq");
|
|
2733
|
+
/**
|
|
2734
|
+
* Binary bit_and.
|
|
2735
|
+
* @overload & other
|
|
2736
|
+
* @param [Numo::NArray,Numeric] other
|
|
2737
|
+
* @return [Numo::NArray] self & other
|
|
2738
|
+
*/
|
|
4625
2739
|
rb_define_method(cT, "&", int64_bit_and, 1);
|
|
2740
|
+
/**
|
|
2741
|
+
* Binary bit_or.
|
|
2742
|
+
* @overload | other
|
|
2743
|
+
* @param [Numo::NArray,Numeric] other
|
|
2744
|
+
* @return [Numo::NArray] self | other
|
|
2745
|
+
*/
|
|
4626
2746
|
rb_define_method(cT, "|", int64_bit_or, 1);
|
|
2747
|
+
/**
|
|
2748
|
+
* Binary bit_xor.
|
|
2749
|
+
* @overload ^ other
|
|
2750
|
+
* @param [Numo::NArray,Numeric] other
|
|
2751
|
+
* @return [Numo::NArray] self ^ other
|
|
2752
|
+
*/
|
|
4627
2753
|
rb_define_method(cT, "^", int64_bit_xor, 1);
|
|
2754
|
+
/**
|
|
2755
|
+
* Unary bit_not.
|
|
2756
|
+
* @overload ~
|
|
2757
|
+
* @return [Numo::Int64] bit_not of self.
|
|
2758
|
+
*/
|
|
4628
2759
|
rb_define_method(cT, "~", int64_bit_not, 0);
|
|
2760
|
+
/**
|
|
2761
|
+
* Binary left_shift.
|
|
2762
|
+
* @overload << other
|
|
2763
|
+
* @param [Numo::NArray,Numeric] other
|
|
2764
|
+
* @return [Numo::NArray] self << other
|
|
2765
|
+
*/
|
|
4629
2766
|
rb_define_method(cT, "<<", int64_left_shift, 1);
|
|
2767
|
+
/**
|
|
2768
|
+
* Binary right_shift.
|
|
2769
|
+
* @overload >> other
|
|
2770
|
+
* @param [Numo::NArray,Numeric] other
|
|
2771
|
+
* @return [Numo::NArray] self >> other
|
|
2772
|
+
*/
|
|
4630
2773
|
rb_define_method(cT, ">>", int64_right_shift, 1);
|
|
4631
2774
|
rb_define_alias(cT, "floor", "view");
|
|
4632
2775
|
rb_define_alias(cT, "round", "view");
|
|
4633
2776
|
rb_define_alias(cT, "ceil", "view");
|
|
4634
2777
|
rb_define_alias(cT, "trunc", "view");
|
|
4635
2778
|
rb_define_alias(cT, "rint", "view");
|
|
2779
|
+
/**
|
|
2780
|
+
* Comparison gt other.
|
|
2781
|
+
* @overload gt other
|
|
2782
|
+
* @param [Numo::NArray,Numeric] other
|
|
2783
|
+
* @return [Numo::Bit] result of self gt other.
|
|
2784
|
+
*/
|
|
4636
2785
|
rb_define_method(cT, "gt", int64_gt, 1);
|
|
2786
|
+
/**
|
|
2787
|
+
* Comparison ge other.
|
|
2788
|
+
* @overload ge other
|
|
2789
|
+
* @param [Numo::NArray,Numeric] other
|
|
2790
|
+
* @return [Numo::Bit] result of self ge other.
|
|
2791
|
+
*/
|
|
4637
2792
|
rb_define_method(cT, "ge", int64_ge, 1);
|
|
2793
|
+
/**
|
|
2794
|
+
* Comparison lt other.
|
|
2795
|
+
* @overload lt other
|
|
2796
|
+
* @param [Numo::NArray,Numeric] other
|
|
2797
|
+
* @return [Numo::Bit] result of self lt other.
|
|
2798
|
+
*/
|
|
4638
2799
|
rb_define_method(cT, "lt", int64_lt, 1);
|
|
2800
|
+
/**
|
|
2801
|
+
* Comparison le other.
|
|
2802
|
+
* @overload le other
|
|
2803
|
+
* @param [Numo::NArray,Numeric] other
|
|
2804
|
+
* @return [Numo::Bit] result of self le other.
|
|
2805
|
+
*/
|
|
4639
2806
|
rb_define_method(cT, "le", int64_le, 1);
|
|
4640
2807
|
rb_define_alias(cT, ">", "gt");
|
|
4641
2808
|
rb_define_alias(cT, ">=", "ge");
|
|
@@ -4820,6 +2987,37 @@ void Init_numo_int64(void) {
|
|
|
4820
2987
|
* @return [Numo::Int64]
|
|
4821
2988
|
*/
|
|
4822
2989
|
rb_define_module_function(cT, "minimum", int64_s_minimum, -1);
|
|
2990
|
+
/**
|
|
2991
|
+
* Count the number of occurrences of each non-negative integer value.
|
|
2992
|
+
* Only Integer-types has this method.
|
|
2993
|
+
*
|
|
2994
|
+
* @overload bincount([weight], minlength:nil)
|
|
2995
|
+
* @param [SFloat or DFloat or Array] weight (optional) Array of
|
|
2996
|
+
* float values. Its size along last axis should be same as that of self.
|
|
2997
|
+
* @param [Integer] minlength (keyword, optional) Minimum size along
|
|
2998
|
+
* last axis for the output array.
|
|
2999
|
+
* @return [UInt32 or UInt64 or SFloat or DFloat]
|
|
3000
|
+
* Returns Float NArray if weight array is supplied,
|
|
3001
|
+
* otherwise returns UInt32 or UInt64 depending on the size along last axis.
|
|
3002
|
+
* @example
|
|
3003
|
+
* Numo::Int32[0..4].bincount
|
|
3004
|
+
* # => Numo::UInt32#shape=[5]
|
|
3005
|
+
* # [1, 1, 1, 1, 1]
|
|
3006
|
+
*
|
|
3007
|
+
* Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
|
|
3008
|
+
* # => Numo::UInt32#shape=[8]
|
|
3009
|
+
* # [1, 3, 1, 1, 0, 0, 0, 1]
|
|
3010
|
+
*
|
|
3011
|
+
* x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
|
|
3012
|
+
* x.bincount.size == x.max+1
|
|
3013
|
+
* # => true
|
|
3014
|
+
*
|
|
3015
|
+
* w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
|
|
3016
|
+
* x = Numo::Int32[0, 1, 1, 2, 2, 2]
|
|
3017
|
+
* x.bincount(w)
|
|
3018
|
+
* # => Numo::DFloat#shape=[3]
|
|
3019
|
+
* # [0.3, 0.7, 1.1]
|
|
3020
|
+
*/
|
|
4823
3021
|
rb_define_method(cT, "bincount", int64_bincount, -1);
|
|
4824
3022
|
/**
|
|
4825
3023
|
* cumsum of self.
|