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 int8_t int8; // Type aliases for shorter notation
|
|
71
96
|
// following the codebase naming convention.
|
|
97
|
+
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(int8)
|
|
98
|
+
DEF_NARRAY_TO_A_METHOD_FUNC(int8)
|
|
99
|
+
DEF_NARRAY_FILL_METHOD_FUNC(int8)
|
|
100
|
+
DEF_NARRAY_FORMAT_METHOD_FUNC(int8)
|
|
101
|
+
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(int8)
|
|
102
|
+
DEF_NARRAY_INSPECT_METHOD_FUNC(int8)
|
|
103
|
+
DEF_NARRAY_INT8_ADD_METHOD_FUNC(int8, numo_cInt8)
|
|
104
|
+
DEF_NARRAY_INT8_SUB_METHOD_FUNC(int8, numo_cInt8)
|
|
105
|
+
DEF_NARRAY_INT8_MUL_METHOD_FUNC(int8, numo_cInt8)
|
|
106
|
+
DEF_NARRAY_INT8_DIV_METHOD_FUNC(int8, numo_cInt8)
|
|
107
|
+
DEF_NARRAY_INT8_MOD_METHOD_FUNC(int8, numo_cInt8)
|
|
108
|
+
DEF_NARRAY_INT_DIVMOD_METHOD_FUNC(int8, numo_cInt8)
|
|
109
|
+
DEF_NARRAY_EQ_METHOD_FUNC(int8, numo_cInt8)
|
|
110
|
+
DEF_NARRAY_NE_METHOD_FUNC(int8, numo_cInt8)
|
|
111
|
+
DEF_NARRAY_GT_METHOD_FUNC(int8, numo_cInt8)
|
|
112
|
+
DEF_NARRAY_GE_METHOD_FUNC(int8, numo_cInt8)
|
|
113
|
+
DEF_NARRAY_LT_METHOD_FUNC(int8, numo_cInt8)
|
|
114
|
+
DEF_NARRAY_LE_METHOD_FUNC(int8, numo_cInt8)
|
|
115
|
+
DEF_NARRAY_INT8_BIT_AND_METHOD_FUNC(int8, numo_cInt8)
|
|
116
|
+
DEF_NARRAY_INT8_BIT_OR_METHOD_FUNC(int8, numo_cInt8)
|
|
117
|
+
DEF_NARRAY_INT8_BIT_XOR_METHOD_FUNC(int8, numo_cInt8)
|
|
118
|
+
DEF_NARRAY_INT8_BIT_NOT_METHOD_FUNC(int8, numo_cInt8)
|
|
119
|
+
DEF_NARRAY_INT8_LEFT_SHIFT_METHOD_FUNC(int8, numo_cInt8)
|
|
120
|
+
DEF_NARRAY_INT8_RIGHT_SHIFT_METHOD_FUNC(int8, numo_cInt8)
|
|
72
121
|
DEF_NARRAY_CLIP_METHOD_FUNC(int8, numo_cInt8)
|
|
73
122
|
DEF_NARRAY_INT_SUM_METHOD_FUNC(int8, numo_cInt8, int64_t, numo_cInt64)
|
|
74
123
|
DEF_NARRAY_INT_PROD_METHOD_FUNC(int8, numo_cInt8, int64_t, numo_cInt64)
|
|
@@ -82,6 +131,7 @@ DEF_NARRAY_INT_ARGMIN_METHOD_FUNC(int8)
|
|
|
82
131
|
DEF_NARRAY_INT_MAXIMUM_METHOD_FUNC(int8, numo_cInt8)
|
|
83
132
|
DEF_NARRAY_INT_MINIMUM_METHOD_FUNC(int8, numo_cInt8)
|
|
84
133
|
DEF_NARRAY_INT_MINMAX_METHOD_FUNC(int8, numo_cInt8)
|
|
134
|
+
DEF_NARRAY_INT_BINCOUNT_METHOD_FUNC(int8, numo_cInt8)
|
|
85
135
|
DEF_NARRAY_INT_CUMSUM_METHOD_FUNC(int8, numo_cInt8)
|
|
86
136
|
DEF_NARRAY_INT_CUMPROD_METHOD_FUNC(int8, numo_cInt8)
|
|
87
137
|
DEF_NARRAY_INT_MULSUM_METHOD_FUNC(int8, numo_cInt8)
|
|
@@ -1252,204 +1302,6 @@ static VALUE int8_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 int8_coerce_cast(VALUE self, VALUE type) {
|
|
1261
|
-
return Qnil;
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
static void iter_int8_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 int8_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_int8_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_int8_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::Int8] self.
|
|
1328
|
-
*/
|
|
1329
|
-
static VALUE int8_fill(VALUE self, VALUE val) {
|
|
1330
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
|
|
1331
|
-
ndfunc_t ndf = { iter_int8_fill, FULL_LOOP, 2, 0, ain, 0 };
|
|
1332
|
-
|
|
1333
|
-
na_ndloop(&ndf, 2, self, val);
|
|
1334
|
-
return self;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
static VALUE format_int8(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_int8_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_int8(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_int8(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 int8_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_int8_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_int8_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_int8(fmt, x);
|
|
1412
|
-
rb_ary_push(a, y);
|
|
1413
|
-
}
|
|
1414
|
-
} else {
|
|
1415
|
-
for (; i--;) {
|
|
1416
|
-
x = (dtype*)p1;
|
|
1417
|
-
p1 += s1;
|
|
1418
|
-
y = format_int8(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 int8_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_int8_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_int8_inspect(char* ptr, size_t pos, VALUE fmt) {
|
|
1441
|
-
return format_int8(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 int8_inspect(VALUE ary) {
|
|
1450
|
-
return na_ndloop_inspect(ary, iter_int8_inspect, Qnil);
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
1305
|
static void iter_int8_each(na_loop_t* const lp) {
|
|
1454
1306
|
size_t i, s1;
|
|
1455
1307
|
char* p1;
|
|
@@ -1759,1165 +1611,154 @@ static VALUE int8_abs(VALUE self) {
|
|
|
1759
1611
|
return na_ndloop(&ndf, 1, self);
|
|
1760
1612
|
}
|
|
1761
1613
|
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
static void iter_int8_add(na_loop_t* const lp) {
|
|
1766
|
-
size_t i = 0;
|
|
1767
|
-
size_t n;
|
|
1614
|
+
static void iter_int8_pow(na_loop_t* const lp) {
|
|
1615
|
+
size_t i;
|
|
1768
1616
|
char *p1, *p2, *p3;
|
|
1769
1617
|
ssize_t s1, s2, s3;
|
|
1770
|
-
|
|
1771
|
-
INIT_COUNTER(lp,
|
|
1618
|
+
dtype x, y;
|
|
1619
|
+
INIT_COUNTER(lp, i);
|
|
1772
1620
|
INIT_PTR(lp, 0, p1, s1);
|
|
1773
1621
|
INIT_PTR(lp, 1, p2, s2);
|
|
1774
1622
|
INIT_PTR(lp, 2, p3, s3);
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1781
|
-
if (p1 == p3) { // inplace case
|
|
1782
|
-
for (; i < n; i++) {
|
|
1783
|
-
((dtype*)p1)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1784
|
-
}
|
|
1785
|
-
} else {
|
|
1786
|
-
for (; i < n; i++) {
|
|
1787
|
-
((dtype*)p3)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
} else {
|
|
1791
|
-
for (i = 0; i < n; i++) {
|
|
1792
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1793
|
-
p1 += s1;
|
|
1794
|
-
p3 += s3;
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
} else {
|
|
1798
|
-
if (p1 == p3) { // inplace case
|
|
1799
|
-
for (i = 0; i < n; i++) {
|
|
1800
|
-
check_intdivzero(*(dtype*)p2);
|
|
1801
|
-
*(dtype*)p1 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1802
|
-
p1 += s1;
|
|
1803
|
-
p2 += s2;
|
|
1804
|
-
}
|
|
1805
|
-
} else {
|
|
1806
|
-
for (i = 0; i < n; i++) {
|
|
1807
|
-
check_intdivzero(*(dtype*)p2);
|
|
1808
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1809
|
-
p1 += s1;
|
|
1810
|
-
p2 += s2;
|
|
1811
|
-
p3 += s3;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1623
|
+
for (; i--;) {
|
|
1624
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1625
|
+
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
1626
|
+
x = m_pow(x, y);
|
|
1627
|
+
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
1814
1628
|
}
|
|
1629
|
+
}
|
|
1815
1630
|
|
|
1816
|
-
|
|
1817
|
-
|
|
1631
|
+
static void iter_int8_pow_int32(na_loop_t* const lp) {
|
|
1632
|
+
size_t i;
|
|
1633
|
+
char *p1, *p2, *p3;
|
|
1634
|
+
ssize_t s1, s2, s3;
|
|
1635
|
+
dtype x;
|
|
1636
|
+
int32_t y;
|
|
1637
|
+
INIT_COUNTER(lp, i);
|
|
1638
|
+
INIT_PTR(lp, 0, p1, s1);
|
|
1639
|
+
INIT_PTR(lp, 1, p2, s2);
|
|
1640
|
+
INIT_PTR(lp, 2, p3, s3);
|
|
1641
|
+
for (; i--;) {
|
|
1642
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1643
|
+
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
1644
|
+
x = m_pow_int(x, y);
|
|
1645
|
+
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
1646
|
+
}
|
|
1818
1647
|
}
|
|
1819
|
-
#undef check_intdivzero
|
|
1820
1648
|
|
|
1821
|
-
static VALUE
|
|
1649
|
+
static VALUE int8_pow_self(VALUE self, VALUE other) {
|
|
1822
1650
|
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1651
|
+
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
1823
1652
|
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1824
|
-
ndfunc_t ndf = {
|
|
1653
|
+
ndfunc_t ndf = { iter_int8_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1654
|
+
ndfunc_t ndf_i = { iter_int8_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
1825
1655
|
|
|
1826
|
-
|
|
1656
|
+
// fixme : use na.integer?
|
|
1657
|
+
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
1658
|
+
return na_ndloop(&ndf_i, 2, self, other);
|
|
1659
|
+
} else {
|
|
1660
|
+
return na_ndloop(&ndf, 2, self, other);
|
|
1661
|
+
}
|
|
1827
1662
|
}
|
|
1828
1663
|
|
|
1829
1664
|
/*
|
|
1830
|
-
Binary
|
|
1831
|
-
@overload
|
|
1665
|
+
Binary power.
|
|
1666
|
+
@overload ** other
|
|
1832
1667
|
@param [Numo::NArray,Numeric] other
|
|
1833
|
-
@return [Numo::NArray] self
|
|
1668
|
+
@return [Numo::NArray] self to the other-th power.
|
|
1834
1669
|
*/
|
|
1835
|
-
static VALUE
|
|
1670
|
+
static VALUE int8_pow(VALUE self, VALUE other) {
|
|
1836
1671
|
|
|
1837
1672
|
VALUE klass, v;
|
|
1838
|
-
|
|
1839
1673
|
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
1840
1674
|
if (klass == cT) {
|
|
1841
|
-
return
|
|
1675
|
+
return int8_pow_self(self, other);
|
|
1842
1676
|
} else {
|
|
1843
1677
|
v = rb_funcall(klass, id_cast, 1, self);
|
|
1844
|
-
return rb_funcall(v,
|
|
1678
|
+
return rb_funcall(v, id_pow, 1, other);
|
|
1845
1679
|
}
|
|
1846
1680
|
}
|
|
1847
1681
|
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
size_t
|
|
1853
|
-
|
|
1854
|
-
char *p1, *p2, *p3;
|
|
1855
|
-
ssize_t s1, s2, s3;
|
|
1682
|
+
static void iter_int8_minus(na_loop_t* const lp) {
|
|
1683
|
+
size_t i, n;
|
|
1684
|
+
char *p1, *p2;
|
|
1685
|
+
ssize_t s1, s2;
|
|
1686
|
+
size_t *idx1, *idx2;
|
|
1687
|
+
dtype x;
|
|
1856
1688
|
|
|
1857
1689
|
INIT_COUNTER(lp, n);
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1861
|
-
|
|
1862
|
-
//
|
|
1690
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1691
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1863
1692
|
|
|
1864
|
-
if (
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
}
|
|
1871
|
-
} else {
|
|
1872
|
-
for (; i < n; i++) {
|
|
1873
|
-
((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
1874
|
-
}
|
|
1693
|
+
if (idx1) {
|
|
1694
|
+
if (idx2) {
|
|
1695
|
+
for (i = 0; i < n; i++) {
|
|
1696
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1697
|
+
x = m_minus(x);
|
|
1698
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1875
1699
|
}
|
|
1876
1700
|
} else {
|
|
1877
1701
|
for (i = 0; i < n; i++) {
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1702
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1703
|
+
x = m_minus(x);
|
|
1704
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1881
1705
|
}
|
|
1882
1706
|
}
|
|
1883
1707
|
} else {
|
|
1884
|
-
if (
|
|
1708
|
+
if (idx2) {
|
|
1885
1709
|
for (i = 0; i < n; i++) {
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
p2 += s2;
|
|
1710
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1711
|
+
x = m_minus(x);
|
|
1712
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1890
1713
|
}
|
|
1891
1714
|
} else {
|
|
1715
|
+
//
|
|
1892
1716
|
for (i = 0; i < n; i++) {
|
|
1893
|
-
|
|
1894
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1717
|
+
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
1895
1718
|
p1 += s1;
|
|
1896
1719
|
p2 += s2;
|
|
1897
|
-
p3 += s3;
|
|
1898
1720
|
}
|
|
1721
|
+
return;
|
|
1722
|
+
//
|
|
1899
1723
|
}
|
|
1900
1724
|
}
|
|
1901
|
-
|
|
1902
|
-
return;
|
|
1903
|
-
//
|
|
1904
|
-
}
|
|
1905
|
-
#undef check_intdivzero
|
|
1906
|
-
|
|
1907
|
-
static VALUE int8_sub_self(VALUE self, VALUE other) {
|
|
1908
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1909
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1910
|
-
ndfunc_t ndf = { iter_int8_sub, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1911
|
-
|
|
1912
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1913
1725
|
}
|
|
1914
1726
|
|
|
1915
1727
|
/*
|
|
1916
|
-
|
|
1917
|
-
@overload
|
|
1918
|
-
@
|
|
1919
|
-
@return [Numo::NArray] self - other
|
|
1728
|
+
Unary minus.
|
|
1729
|
+
@overload -@
|
|
1730
|
+
@return [Numo::Int8] minus of self.
|
|
1920
1731
|
*/
|
|
1921
|
-
static VALUE
|
|
1922
|
-
|
|
1923
|
-
|
|
1732
|
+
static VALUE int8_minus(VALUE self) {
|
|
1733
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1734
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1735
|
+
ndfunc_t ndf = { iter_int8_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
1924
1736
|
|
|
1925
|
-
|
|
1926
|
-
if (klass == cT) {
|
|
1927
|
-
return int8_sub_self(self, other);
|
|
1928
|
-
} else {
|
|
1929
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
1930
|
-
return rb_funcall(v, '-', 1, other);
|
|
1931
|
-
}
|
|
1737
|
+
return na_ndloop(&ndf, 1, self);
|
|
1932
1738
|
}
|
|
1933
1739
|
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
size_t
|
|
1939
|
-
|
|
1940
|
-
char *p1, *p2, *p3;
|
|
1941
|
-
ssize_t s1, s2, s3;
|
|
1740
|
+
static void iter_int8_reciprocal(na_loop_t* const lp) {
|
|
1741
|
+
size_t i, n;
|
|
1742
|
+
char *p1, *p2;
|
|
1743
|
+
ssize_t s1, s2;
|
|
1744
|
+
size_t *idx1, *idx2;
|
|
1745
|
+
dtype x;
|
|
1942
1746
|
|
|
1943
1747
|
INIT_COUNTER(lp, n);
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1947
|
-
|
|
1948
|
-
//
|
|
1748
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1749
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1949
1750
|
|
|
1950
|
-
if (
|
|
1951
|
-
|
|
1952
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1953
|
-
if (p1 == p3) { // inplace case
|
|
1954
|
-
for (; i < n; i++) {
|
|
1955
|
-
((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
1956
|
-
}
|
|
1957
|
-
} else {
|
|
1958
|
-
for (; i < n; i++) {
|
|
1959
|
-
((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
} else {
|
|
1963
|
-
for (i = 0; i < n; i++) {
|
|
1964
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1965
|
-
p1 += s1;
|
|
1966
|
-
p3 += s3;
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
} else {
|
|
1970
|
-
if (p1 == p3) { // inplace case
|
|
1971
|
-
for (i = 0; i < n; i++) {
|
|
1972
|
-
check_intdivzero(*(dtype*)p2);
|
|
1973
|
-
*(dtype*)p1 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1974
|
-
p1 += s1;
|
|
1975
|
-
p2 += s2;
|
|
1976
|
-
}
|
|
1977
|
-
} else {
|
|
1978
|
-
for (i = 0; i < n; i++) {
|
|
1979
|
-
check_intdivzero(*(dtype*)p2);
|
|
1980
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1981
|
-
p1 += s1;
|
|
1982
|
-
p2 += s2;
|
|
1983
|
-
p3 += s3;
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
return;
|
|
1989
|
-
//
|
|
1990
|
-
}
|
|
1991
|
-
#undef check_intdivzero
|
|
1992
|
-
|
|
1993
|
-
static VALUE int8_mul_self(VALUE self, VALUE other) {
|
|
1994
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1995
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1996
|
-
ndfunc_t ndf = { iter_int8_mul, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1997
|
-
|
|
1998
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
/*
|
|
2002
|
-
Binary mul.
|
|
2003
|
-
@overload * other
|
|
2004
|
-
@param [Numo::NArray,Numeric] other
|
|
2005
|
-
@return [Numo::NArray] self * other
|
|
2006
|
-
*/
|
|
2007
|
-
static VALUE int8_mul(VALUE self, VALUE other) {
|
|
2008
|
-
|
|
2009
|
-
VALUE klass, v;
|
|
2010
|
-
|
|
2011
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2012
|
-
if (klass == cT) {
|
|
2013
|
-
return int8_mul_self(self, other);
|
|
2014
|
-
} else {
|
|
2015
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2016
|
-
return rb_funcall(v, '*', 1, other);
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
#define check_intdivzero(y) \
|
|
2021
|
-
if ((y) == 0) { \
|
|
2022
|
-
lp->err_type = rb_eZeroDivError; \
|
|
2023
|
-
return; \
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
static void iter_int8_div(na_loop_t* const lp) {
|
|
2027
|
-
size_t i = 0;
|
|
2028
|
-
size_t n;
|
|
2029
|
-
char *p1, *p2, *p3;
|
|
2030
|
-
ssize_t s1, s2, s3;
|
|
2031
|
-
|
|
2032
|
-
INIT_COUNTER(lp, n);
|
|
2033
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2034
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2035
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2036
|
-
|
|
2037
|
-
//
|
|
2038
|
-
|
|
2039
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2040
|
-
check_intdivzero(*(dtype*)p2);
|
|
2041
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2042
|
-
if (p1 == p3) { // inplace case
|
|
2043
|
-
for (; i < n; i++) {
|
|
2044
|
-
((dtype*)p1)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2045
|
-
}
|
|
2046
|
-
} else {
|
|
2047
|
-
for (; i < n; i++) {
|
|
2048
|
-
((dtype*)p3)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
} else {
|
|
2052
|
-
for (i = 0; i < n; i++) {
|
|
2053
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2054
|
-
p1 += s1;
|
|
2055
|
-
p3 += s3;
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
} else {
|
|
2059
|
-
if (p1 == p3) { // inplace case
|
|
2060
|
-
for (i = 0; i < n; i++) {
|
|
2061
|
-
check_intdivzero(*(dtype*)p2);
|
|
2062
|
-
*(dtype*)p1 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2063
|
-
p1 += s1;
|
|
2064
|
-
p2 += s2;
|
|
2065
|
-
}
|
|
2066
|
-
} else {
|
|
2067
|
-
for (i = 0; i < n; i++) {
|
|
2068
|
-
check_intdivzero(*(dtype*)p2);
|
|
2069
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2070
|
-
p1 += s1;
|
|
2071
|
-
p2 += s2;
|
|
2072
|
-
p3 += s3;
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
return;
|
|
2078
|
-
//
|
|
2079
|
-
}
|
|
2080
|
-
#undef check_intdivzero
|
|
2081
|
-
|
|
2082
|
-
static VALUE int8_div_self(VALUE self, VALUE other) {
|
|
2083
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2084
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2085
|
-
ndfunc_t ndf = { iter_int8_div, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2086
|
-
|
|
2087
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
/*
|
|
2091
|
-
Binary div.
|
|
2092
|
-
@overload / other
|
|
2093
|
-
@param [Numo::NArray,Numeric] other
|
|
2094
|
-
@return [Numo::NArray] self / other
|
|
2095
|
-
*/
|
|
2096
|
-
static VALUE int8_div(VALUE self, VALUE other) {
|
|
2097
|
-
|
|
2098
|
-
VALUE klass, v;
|
|
2099
|
-
|
|
2100
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2101
|
-
if (klass == cT) {
|
|
2102
|
-
return int8_div_self(self, other);
|
|
2103
|
-
} else {
|
|
2104
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2105
|
-
return rb_funcall(v, '/', 1, other);
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
#define check_intdivzero(y) \
|
|
2110
|
-
if ((y) == 0) { \
|
|
2111
|
-
lp->err_type = rb_eZeroDivError; \
|
|
2112
|
-
return; \
|
|
2113
|
-
}
|
|
2114
|
-
|
|
2115
|
-
static void iter_int8_mod(na_loop_t* const lp) {
|
|
2116
|
-
size_t i = 0;
|
|
2117
|
-
size_t n;
|
|
2118
|
-
char *p1, *p2, *p3;
|
|
2119
|
-
ssize_t s1, s2, s3;
|
|
2120
|
-
|
|
2121
|
-
INIT_COUNTER(lp, n);
|
|
2122
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2123
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2124
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2125
|
-
|
|
2126
|
-
//
|
|
2127
|
-
|
|
2128
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2129
|
-
check_intdivzero(*(dtype*)p2);
|
|
2130
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2131
|
-
if (p1 == p3) { // inplace case
|
|
2132
|
-
for (; i < n; i++) {
|
|
2133
|
-
((dtype*)p1)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2134
|
-
}
|
|
2135
|
-
} else {
|
|
2136
|
-
for (; i < n; i++) {
|
|
2137
|
-
((dtype*)p3)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
} else {
|
|
2141
|
-
for (i = 0; i < n; i++) {
|
|
2142
|
-
*(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2143
|
-
p1 += s1;
|
|
2144
|
-
p3 += s3;
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
} else {
|
|
2148
|
-
if (p1 == p3) { // inplace case
|
|
2149
|
-
for (i = 0; i < n; i++) {
|
|
2150
|
-
check_intdivzero(*(dtype*)p2);
|
|
2151
|
-
*(dtype*)p1 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2152
|
-
p1 += s1;
|
|
2153
|
-
p2 += s2;
|
|
2154
|
-
}
|
|
2155
|
-
} else {
|
|
2156
|
-
for (i = 0; i < n; i++) {
|
|
2157
|
-
check_intdivzero(*(dtype*)p2);
|
|
2158
|
-
*(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2159
|
-
p1 += s1;
|
|
2160
|
-
p2 += s2;
|
|
2161
|
-
p3 += s3;
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
return;
|
|
2167
|
-
//
|
|
2168
|
-
}
|
|
2169
|
-
#undef check_intdivzero
|
|
2170
|
-
|
|
2171
|
-
static VALUE int8_mod_self(VALUE self, VALUE other) {
|
|
2172
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2173
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2174
|
-
ndfunc_t ndf = { iter_int8_mod, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2175
|
-
|
|
2176
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2177
|
-
}
|
|
2178
|
-
|
|
2179
|
-
/*
|
|
2180
|
-
Binary mod.
|
|
2181
|
-
@overload % other
|
|
2182
|
-
@param [Numo::NArray,Numeric] other
|
|
2183
|
-
@return [Numo::NArray] self % other
|
|
2184
|
-
*/
|
|
2185
|
-
static VALUE int8_mod(VALUE self, VALUE other) {
|
|
2186
|
-
|
|
2187
|
-
VALUE klass, v;
|
|
2188
|
-
|
|
2189
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2190
|
-
if (klass == cT) {
|
|
2191
|
-
return int8_mod_self(self, other);
|
|
2192
|
-
} else {
|
|
2193
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2194
|
-
return rb_funcall(v, '%', 1, other);
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
|
|
2198
|
-
static void iter_int8_divmod(na_loop_t* const lp) {
|
|
2199
|
-
size_t i, n;
|
|
2200
|
-
char *p1, *p2, *p3, *p4;
|
|
2201
|
-
ssize_t s1, s2, s3, s4;
|
|
2202
|
-
dtype x, y, a, b;
|
|
2203
|
-
INIT_COUNTER(lp, n);
|
|
2204
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2205
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2206
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2207
|
-
INIT_PTR(lp, 3, p4, s4);
|
|
2208
|
-
for (i = n; i--;) {
|
|
2209
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2210
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2211
|
-
if (y == 0) {
|
|
2212
|
-
lp->err_type = rb_eZeroDivError;
|
|
2213
|
-
return;
|
|
2214
|
-
}
|
|
2215
|
-
m_divmod(x, y, a, b);
|
|
2216
|
-
SET_DATA_STRIDE(p3, s3, dtype, a);
|
|
2217
|
-
SET_DATA_STRIDE(p4, s4, dtype, b);
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
|
|
2221
|
-
static VALUE int8_divmod_self(VALUE self, VALUE other) {
|
|
2222
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2223
|
-
ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
|
|
2224
|
-
ndfunc_t ndf = { iter_int8_divmod, STRIDE_LOOP, 2, 2, ain, aout };
|
|
2225
|
-
|
|
2226
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
/*
|
|
2230
|
-
Binary divmod.
|
|
2231
|
-
@overload divmod other
|
|
2232
|
-
@param [Numo::NArray,Numeric] other
|
|
2233
|
-
@return [Numo::NArray] divmod of self and other.
|
|
2234
|
-
*/
|
|
2235
|
-
static VALUE int8_divmod(VALUE self, VALUE other) {
|
|
2236
|
-
|
|
2237
|
-
VALUE klass, v;
|
|
2238
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2239
|
-
if (klass == cT) {
|
|
2240
|
-
return int8_divmod_self(self, other);
|
|
2241
|
-
} else {
|
|
2242
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2243
|
-
return rb_funcall(v, id_divmod, 1, other);
|
|
2244
|
-
}
|
|
2245
|
-
}
|
|
2246
|
-
|
|
2247
|
-
static void iter_int8_pow(na_loop_t* const lp) {
|
|
2248
|
-
size_t i;
|
|
2249
|
-
char *p1, *p2, *p3;
|
|
2250
|
-
ssize_t s1, s2, s3;
|
|
2251
|
-
dtype x, y;
|
|
2252
|
-
INIT_COUNTER(lp, i);
|
|
2253
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2254
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2255
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2256
|
-
for (; i--;) {
|
|
2257
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2258
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2259
|
-
x = m_pow(x, y);
|
|
2260
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2264
|
-
static void iter_int8_pow_int32(na_loop_t* const lp) {
|
|
2265
|
-
size_t i;
|
|
2266
|
-
char *p1, *p2, *p3;
|
|
2267
|
-
ssize_t s1, s2, s3;
|
|
2268
|
-
dtype x;
|
|
2269
|
-
int32_t y;
|
|
2270
|
-
INIT_COUNTER(lp, i);
|
|
2271
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2272
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2273
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2274
|
-
for (; i--;) {
|
|
2275
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2276
|
-
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
2277
|
-
x = m_pow_int(x, y);
|
|
2278
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
static VALUE int8_pow_self(VALUE self, VALUE other) {
|
|
2283
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2284
|
-
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
2285
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2286
|
-
ndfunc_t ndf = { iter_int8_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2287
|
-
ndfunc_t ndf_i = { iter_int8_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
2288
|
-
|
|
2289
|
-
// fixme : use na.integer?
|
|
2290
|
-
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
2291
|
-
return na_ndloop(&ndf_i, 2, self, other);
|
|
2292
|
-
} else {
|
|
2293
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2294
|
-
}
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
/*
|
|
2298
|
-
Binary power.
|
|
2299
|
-
@overload ** other
|
|
2300
|
-
@param [Numo::NArray,Numeric] other
|
|
2301
|
-
@return [Numo::NArray] self to the other-th power.
|
|
2302
|
-
*/
|
|
2303
|
-
static VALUE int8_pow(VALUE self, VALUE other) {
|
|
2304
|
-
|
|
2305
|
-
VALUE klass, v;
|
|
2306
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2307
|
-
if (klass == cT) {
|
|
2308
|
-
return int8_pow_self(self, other);
|
|
2309
|
-
} else {
|
|
2310
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2311
|
-
return rb_funcall(v, id_pow, 1, other);
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
static void iter_int8_minus(na_loop_t* const lp) {
|
|
2316
|
-
size_t i, n;
|
|
2317
|
-
char *p1, *p2;
|
|
2318
|
-
ssize_t s1, s2;
|
|
2319
|
-
size_t *idx1, *idx2;
|
|
2320
|
-
dtype x;
|
|
2321
|
-
|
|
2322
|
-
INIT_COUNTER(lp, n);
|
|
2323
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2324
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2325
|
-
|
|
2326
|
-
if (idx1) {
|
|
2327
|
-
if (idx2) {
|
|
2328
|
-
for (i = 0; i < n; i++) {
|
|
2329
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2330
|
-
x = m_minus(x);
|
|
2331
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2332
|
-
}
|
|
2333
|
-
} else {
|
|
2334
|
-
for (i = 0; i < n; i++) {
|
|
2335
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2336
|
-
x = m_minus(x);
|
|
2337
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
} else {
|
|
2341
|
-
if (idx2) {
|
|
2342
|
-
for (i = 0; i < n; i++) {
|
|
2343
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2344
|
-
x = m_minus(x);
|
|
2345
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2346
|
-
}
|
|
2347
|
-
} else {
|
|
2348
|
-
//
|
|
2349
|
-
for (i = 0; i < n; i++) {
|
|
2350
|
-
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
2351
|
-
p1 += s1;
|
|
2352
|
-
p2 += s2;
|
|
2353
|
-
}
|
|
2354
|
-
return;
|
|
2355
|
-
//
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
/*
|
|
2361
|
-
Unary minus.
|
|
2362
|
-
@overload -@
|
|
2363
|
-
@return [Numo::Int8] minus of self.
|
|
2364
|
-
*/
|
|
2365
|
-
static VALUE int8_minus(VALUE self) {
|
|
2366
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2367
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2368
|
-
ndfunc_t ndf = { iter_int8_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
2369
|
-
|
|
2370
|
-
return na_ndloop(&ndf, 1, self);
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
static void iter_int8_reciprocal(na_loop_t* const lp) {
|
|
2374
|
-
size_t i, n;
|
|
2375
|
-
char *p1, *p2;
|
|
2376
|
-
ssize_t s1, s2;
|
|
2377
|
-
size_t *idx1, *idx2;
|
|
2378
|
-
dtype x;
|
|
2379
|
-
|
|
2380
|
-
INIT_COUNTER(lp, n);
|
|
2381
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2382
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2383
|
-
|
|
2384
|
-
if (idx1) {
|
|
2385
|
-
if (idx2) {
|
|
2386
|
-
for (i = 0; i < n; i++) {
|
|
2387
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2388
|
-
x = m_reciprocal(x);
|
|
2389
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2390
|
-
}
|
|
2391
|
-
} else {
|
|
2392
|
-
for (i = 0; i < n; i++) {
|
|
2393
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2394
|
-
x = m_reciprocal(x);
|
|
2395
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
} else {
|
|
2399
|
-
if (idx2) {
|
|
2400
|
-
for (i = 0; i < n; i++) {
|
|
2401
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2402
|
-
x = m_reciprocal(x);
|
|
2403
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2404
|
-
}
|
|
2405
|
-
} else {
|
|
2406
|
-
//
|
|
2407
|
-
for (i = 0; i < n; i++) {
|
|
2408
|
-
*(dtype*)p2 = m_reciprocal(*(dtype*)p1);
|
|
2409
|
-
p1 += s1;
|
|
2410
|
-
p2 += s2;
|
|
2411
|
-
}
|
|
2412
|
-
return;
|
|
2413
|
-
//
|
|
2414
|
-
}
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
/*
|
|
2419
|
-
Unary reciprocal.
|
|
2420
|
-
@overload reciprocal
|
|
2421
|
-
@return [Numo::Int8] reciprocal of self.
|
|
2422
|
-
*/
|
|
2423
|
-
static VALUE int8_reciprocal(VALUE self) {
|
|
2424
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2425
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2426
|
-
ndfunc_t ndf = { iter_int8_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
2427
|
-
|
|
2428
|
-
return na_ndloop(&ndf, 1, self);
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
static void iter_int8_sign(na_loop_t* const lp) {
|
|
2432
|
-
size_t i, n;
|
|
2433
|
-
char *p1, *p2;
|
|
2434
|
-
ssize_t s1, s2;
|
|
2435
|
-
size_t *idx1, *idx2;
|
|
2436
|
-
dtype x;
|
|
2437
|
-
|
|
2438
|
-
INIT_COUNTER(lp, n);
|
|
2439
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2440
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2441
|
-
|
|
2442
|
-
if (idx1) {
|
|
2443
|
-
if (idx2) {
|
|
2444
|
-
for (i = 0; i < n; i++) {
|
|
2445
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2446
|
-
x = m_sign(x);
|
|
2447
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2448
|
-
}
|
|
2449
|
-
} else {
|
|
2450
|
-
for (i = 0; i < n; i++) {
|
|
2451
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2452
|
-
x = m_sign(x);
|
|
2453
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
} else {
|
|
2457
|
-
if (idx2) {
|
|
2458
|
-
for (i = 0; i < n; i++) {
|
|
2459
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2460
|
-
x = m_sign(x);
|
|
2461
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2462
|
-
}
|
|
2463
|
-
} else {
|
|
2464
|
-
//
|
|
2465
|
-
for (i = 0; i < n; i++) {
|
|
2466
|
-
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
2467
|
-
p1 += s1;
|
|
2468
|
-
p2 += s2;
|
|
2469
|
-
}
|
|
2470
|
-
return;
|
|
2471
|
-
//
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
|
-
/*
|
|
2477
|
-
Unary sign.
|
|
2478
|
-
@overload sign
|
|
2479
|
-
@return [Numo::Int8] sign of self.
|
|
2480
|
-
*/
|
|
2481
|
-
static VALUE int8_sign(VALUE self) {
|
|
2482
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2483
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2484
|
-
ndfunc_t ndf = { iter_int8_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
2485
|
-
|
|
2486
|
-
return na_ndloop(&ndf, 1, self);
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
static void iter_int8_square(na_loop_t* const lp) {
|
|
2490
|
-
size_t i, n;
|
|
2491
|
-
char *p1, *p2;
|
|
2492
|
-
ssize_t s1, s2;
|
|
2493
|
-
size_t *idx1, *idx2;
|
|
2494
|
-
dtype x;
|
|
2495
|
-
|
|
2496
|
-
INIT_COUNTER(lp, n);
|
|
2497
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2498
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2499
|
-
|
|
2500
|
-
if (idx1) {
|
|
2501
|
-
if (idx2) {
|
|
2502
|
-
for (i = 0; i < n; i++) {
|
|
2503
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2504
|
-
x = m_square(x);
|
|
2505
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2506
|
-
}
|
|
2507
|
-
} else {
|
|
2508
|
-
for (i = 0; i < n; i++) {
|
|
2509
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2510
|
-
x = m_square(x);
|
|
2511
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
} else {
|
|
2515
|
-
if (idx2) {
|
|
2516
|
-
for (i = 0; i < n; i++) {
|
|
2517
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2518
|
-
x = m_square(x);
|
|
2519
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2520
|
-
}
|
|
2521
|
-
} else {
|
|
2522
|
-
//
|
|
2523
|
-
for (i = 0; i < n; i++) {
|
|
2524
|
-
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
2525
|
-
p1 += s1;
|
|
2526
|
-
p2 += s2;
|
|
2527
|
-
}
|
|
2528
|
-
return;
|
|
2529
|
-
//
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
|
|
2534
|
-
/*
|
|
2535
|
-
Unary square.
|
|
2536
|
-
@overload square
|
|
2537
|
-
@return [Numo::Int8] square of self.
|
|
2538
|
-
*/
|
|
2539
|
-
static VALUE int8_square(VALUE self) {
|
|
2540
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2541
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2542
|
-
ndfunc_t ndf = { iter_int8_square, FULL_LOOP, 1, 1, ain, aout };
|
|
2543
|
-
|
|
2544
|
-
return na_ndloop(&ndf, 1, self);
|
|
2545
|
-
}
|
|
2546
|
-
|
|
2547
|
-
static void iter_int8_eq(na_loop_t* const lp) {
|
|
2548
|
-
size_t i;
|
|
2549
|
-
char *p1, *p2;
|
|
2550
|
-
BIT_DIGIT* a3;
|
|
2551
|
-
size_t p3;
|
|
2552
|
-
ssize_t s1, s2, s3;
|
|
2553
|
-
dtype x, y;
|
|
2554
|
-
BIT_DIGIT b;
|
|
2555
|
-
INIT_COUNTER(lp, i);
|
|
2556
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2557
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2558
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2559
|
-
for (; i--;) {
|
|
2560
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2561
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2562
|
-
b = (m_eq(x, y)) ? 1 : 0;
|
|
2563
|
-
STORE_BIT(a3, p3, b);
|
|
2564
|
-
p3 += s3;
|
|
2565
|
-
}
|
|
2566
|
-
}
|
|
2567
|
-
|
|
2568
|
-
static VALUE int8_eq_self(VALUE self, VALUE other) {
|
|
2569
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2570
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2571
|
-
ndfunc_t ndf = { iter_int8_eq, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2572
|
-
|
|
2573
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2574
|
-
}
|
|
2575
|
-
|
|
2576
|
-
/*
|
|
2577
|
-
Comparison eq other.
|
|
2578
|
-
@overload eq other
|
|
2579
|
-
@param [Numo::NArray,Numeric] other
|
|
2580
|
-
@return [Numo::Bit] result of self eq other.
|
|
2581
|
-
*/
|
|
2582
|
-
static VALUE int8_eq(VALUE self, VALUE other) {
|
|
2583
|
-
|
|
2584
|
-
VALUE klass, v;
|
|
2585
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2586
|
-
if (klass == cT) {
|
|
2587
|
-
return int8_eq_self(self, other);
|
|
2588
|
-
} else {
|
|
2589
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2590
|
-
return rb_funcall(v, id_eq, 1, other);
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
|
|
2594
|
-
static void iter_int8_ne(na_loop_t* const lp) {
|
|
2595
|
-
size_t i;
|
|
2596
|
-
char *p1, *p2;
|
|
2597
|
-
BIT_DIGIT* a3;
|
|
2598
|
-
size_t p3;
|
|
2599
|
-
ssize_t s1, s2, s3;
|
|
2600
|
-
dtype x, y;
|
|
2601
|
-
BIT_DIGIT b;
|
|
2602
|
-
INIT_COUNTER(lp, i);
|
|
2603
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2604
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2605
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2606
|
-
for (; i--;) {
|
|
2607
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2608
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2609
|
-
b = (m_ne(x, y)) ? 1 : 0;
|
|
2610
|
-
STORE_BIT(a3, p3, b);
|
|
2611
|
-
p3 += s3;
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
|
|
2615
|
-
static VALUE int8_ne_self(VALUE self, VALUE other) {
|
|
2616
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2617
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2618
|
-
ndfunc_t ndf = { iter_int8_ne, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2619
|
-
|
|
2620
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2621
|
-
}
|
|
2622
|
-
|
|
2623
|
-
/*
|
|
2624
|
-
Comparison ne other.
|
|
2625
|
-
@overload ne other
|
|
2626
|
-
@param [Numo::NArray,Numeric] other
|
|
2627
|
-
@return [Numo::Bit] result of self ne other.
|
|
2628
|
-
*/
|
|
2629
|
-
static VALUE int8_ne(VALUE self, VALUE other) {
|
|
2630
|
-
|
|
2631
|
-
VALUE klass, v;
|
|
2632
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2633
|
-
if (klass == cT) {
|
|
2634
|
-
return int8_ne_self(self, other);
|
|
2635
|
-
} else {
|
|
2636
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2637
|
-
return rb_funcall(v, id_ne, 1, other);
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
|
|
2641
|
-
#define check_intdivzero(y) \
|
|
2642
|
-
{}
|
|
2643
|
-
|
|
2644
|
-
static void iter_int8_bit_and(na_loop_t* const lp) {
|
|
2645
|
-
size_t i = 0;
|
|
2646
|
-
size_t n;
|
|
2647
|
-
char *p1, *p2, *p3;
|
|
2648
|
-
ssize_t s1, s2, s3;
|
|
2649
|
-
|
|
2650
|
-
INIT_COUNTER(lp, n);
|
|
2651
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2652
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2653
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2654
|
-
|
|
2655
|
-
//
|
|
2656
|
-
|
|
2657
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2658
|
-
check_intdivzero(*(dtype*)p2);
|
|
2659
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2660
|
-
if (p1 == p3) { // inplace case
|
|
2661
|
-
for (; i < n; i++) {
|
|
2662
|
-
((dtype*)p1)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2663
|
-
}
|
|
2664
|
-
} else {
|
|
2665
|
-
for (; i < n; i++) {
|
|
2666
|
-
((dtype*)p3)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
} else {
|
|
2670
|
-
for (i = 0; i < n; i++) {
|
|
2671
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2672
|
-
p1 += s1;
|
|
2673
|
-
p3 += s3;
|
|
2674
|
-
}
|
|
2675
|
-
}
|
|
2676
|
-
} else {
|
|
2677
|
-
if (p1 == p3) { // inplace case
|
|
2678
|
-
for (i = 0; i < n; i++) {
|
|
2679
|
-
check_intdivzero(*(dtype*)p2);
|
|
2680
|
-
*(dtype*)p1 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2681
|
-
p1 += s1;
|
|
2682
|
-
p2 += s2;
|
|
2683
|
-
}
|
|
2684
|
-
} else {
|
|
2685
|
-
for (i = 0; i < n; i++) {
|
|
2686
|
-
check_intdivzero(*(dtype*)p2);
|
|
2687
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2688
|
-
p1 += s1;
|
|
2689
|
-
p2 += s2;
|
|
2690
|
-
p3 += s3;
|
|
2691
|
-
}
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
|
|
2695
|
-
return;
|
|
2696
|
-
//
|
|
2697
|
-
}
|
|
2698
|
-
#undef check_intdivzero
|
|
2699
|
-
|
|
2700
|
-
static VALUE int8_bit_and_self(VALUE self, VALUE other) {
|
|
2701
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2702
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2703
|
-
ndfunc_t ndf = { iter_int8_bit_and, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2704
|
-
|
|
2705
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2708
|
-
/*
|
|
2709
|
-
Binary bit_and.
|
|
2710
|
-
@overload & other
|
|
2711
|
-
@param [Numo::NArray,Numeric] other
|
|
2712
|
-
@return [Numo::NArray] self & other
|
|
2713
|
-
*/
|
|
2714
|
-
static VALUE int8_bit_and(VALUE self, VALUE other) {
|
|
2715
|
-
|
|
2716
|
-
VALUE klass, v;
|
|
2717
|
-
|
|
2718
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2719
|
-
if (klass == cT) {
|
|
2720
|
-
return int8_bit_and_self(self, other);
|
|
2721
|
-
} else {
|
|
2722
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2723
|
-
return rb_funcall(v, '&', 1, other);
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
|
|
2727
|
-
#define check_intdivzero(y) \
|
|
2728
|
-
{}
|
|
2729
|
-
|
|
2730
|
-
static void iter_int8_bit_or(na_loop_t* const lp) {
|
|
2731
|
-
size_t i = 0;
|
|
2732
|
-
size_t n;
|
|
2733
|
-
char *p1, *p2, *p3;
|
|
2734
|
-
ssize_t s1, s2, s3;
|
|
2735
|
-
|
|
2736
|
-
INIT_COUNTER(lp, n);
|
|
2737
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2738
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2739
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2740
|
-
|
|
2741
|
-
//
|
|
2742
|
-
|
|
2743
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2744
|
-
check_intdivzero(*(dtype*)p2);
|
|
2745
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2746
|
-
if (p1 == p3) { // inplace case
|
|
2747
|
-
for (; i < n; i++) {
|
|
2748
|
-
((dtype*)p1)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
2749
|
-
}
|
|
2750
|
-
} else {
|
|
2751
|
-
for (; i < n; i++) {
|
|
2752
|
-
((dtype*)p3)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
} else {
|
|
2756
|
-
for (i = 0; i < n; i++) {
|
|
2757
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2758
|
-
p1 += s1;
|
|
2759
|
-
p3 += s3;
|
|
2760
|
-
}
|
|
2761
|
-
}
|
|
2762
|
-
} else {
|
|
2763
|
-
if (p1 == p3) { // inplace case
|
|
2764
|
-
for (i = 0; i < n; i++) {
|
|
2765
|
-
check_intdivzero(*(dtype*)p2);
|
|
2766
|
-
*(dtype*)p1 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2767
|
-
p1 += s1;
|
|
2768
|
-
p2 += s2;
|
|
2769
|
-
}
|
|
2770
|
-
} else {
|
|
2771
|
-
for (i = 0; i < n; i++) {
|
|
2772
|
-
check_intdivzero(*(dtype*)p2);
|
|
2773
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2774
|
-
p1 += s1;
|
|
2775
|
-
p2 += s2;
|
|
2776
|
-
p3 += s3;
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
return;
|
|
2782
|
-
//
|
|
2783
|
-
}
|
|
2784
|
-
#undef check_intdivzero
|
|
2785
|
-
|
|
2786
|
-
static VALUE int8_bit_or_self(VALUE self, VALUE other) {
|
|
2787
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2788
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2789
|
-
ndfunc_t ndf = { iter_int8_bit_or, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2790
|
-
|
|
2791
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
|
-
/*
|
|
2795
|
-
Binary bit_or.
|
|
2796
|
-
@overload | other
|
|
2797
|
-
@param [Numo::NArray,Numeric] other
|
|
2798
|
-
@return [Numo::NArray] self | other
|
|
2799
|
-
*/
|
|
2800
|
-
static VALUE int8_bit_or(VALUE self, VALUE other) {
|
|
2801
|
-
|
|
2802
|
-
VALUE klass, v;
|
|
2803
|
-
|
|
2804
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2805
|
-
if (klass == cT) {
|
|
2806
|
-
return int8_bit_or_self(self, other);
|
|
2807
|
-
} else {
|
|
2808
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2809
|
-
return rb_funcall(v, '|', 1, other);
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
|
|
2813
|
-
#define check_intdivzero(y) \
|
|
2814
|
-
{}
|
|
2815
|
-
|
|
2816
|
-
static void iter_int8_bit_xor(na_loop_t* const lp) {
|
|
2817
|
-
size_t i = 0;
|
|
2818
|
-
size_t n;
|
|
2819
|
-
char *p1, *p2, *p3;
|
|
2820
|
-
ssize_t s1, s2, s3;
|
|
2821
|
-
|
|
2822
|
-
INIT_COUNTER(lp, n);
|
|
2823
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2824
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2825
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2826
|
-
|
|
2827
|
-
//
|
|
2828
|
-
|
|
2829
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2830
|
-
check_intdivzero(*(dtype*)p2);
|
|
2831
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2832
|
-
if (p1 == p3) { // inplace case
|
|
2833
|
-
for (; i < n; i++) {
|
|
2834
|
-
((dtype*)p1)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
2835
|
-
}
|
|
2836
|
-
} else {
|
|
2837
|
-
for (; i < n; i++) {
|
|
2838
|
-
((dtype*)p3)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
} else {
|
|
2842
|
-
for (i = 0; i < n; i++) {
|
|
2843
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2844
|
-
p1 += s1;
|
|
2845
|
-
p3 += s3;
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
} else {
|
|
2849
|
-
if (p1 == p3) { // inplace case
|
|
2850
|
-
for (i = 0; i < n; i++) {
|
|
2851
|
-
check_intdivzero(*(dtype*)p2);
|
|
2852
|
-
*(dtype*)p1 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2853
|
-
p1 += s1;
|
|
2854
|
-
p2 += s2;
|
|
2855
|
-
}
|
|
2856
|
-
} else {
|
|
2857
|
-
for (i = 0; i < n; i++) {
|
|
2858
|
-
check_intdivzero(*(dtype*)p2);
|
|
2859
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2860
|
-
p1 += s1;
|
|
2861
|
-
p2 += s2;
|
|
2862
|
-
p3 += s3;
|
|
2863
|
-
}
|
|
2864
|
-
}
|
|
2865
|
-
}
|
|
2866
|
-
|
|
2867
|
-
return;
|
|
2868
|
-
//
|
|
2869
|
-
}
|
|
2870
|
-
#undef check_intdivzero
|
|
2871
|
-
|
|
2872
|
-
static VALUE int8_bit_xor_self(VALUE self, VALUE other) {
|
|
2873
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2874
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2875
|
-
ndfunc_t ndf = { iter_int8_bit_xor, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2876
|
-
|
|
2877
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2878
|
-
}
|
|
2879
|
-
|
|
2880
|
-
/*
|
|
2881
|
-
Binary bit_xor.
|
|
2882
|
-
@overload ^ other
|
|
2883
|
-
@param [Numo::NArray,Numeric] other
|
|
2884
|
-
@return [Numo::NArray] self ^ other
|
|
2885
|
-
*/
|
|
2886
|
-
static VALUE int8_bit_xor(VALUE self, VALUE other) {
|
|
2887
|
-
|
|
2888
|
-
VALUE klass, v;
|
|
2889
|
-
|
|
2890
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2891
|
-
if (klass == cT) {
|
|
2892
|
-
return int8_bit_xor_self(self, other);
|
|
2893
|
-
} else {
|
|
2894
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2895
|
-
return rb_funcall(v, '^', 1, other);
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
|
|
2899
|
-
static void iter_int8_bit_not(na_loop_t* const lp) {
|
|
2900
|
-
size_t i, n;
|
|
2901
|
-
char *p1, *p2;
|
|
2902
|
-
ssize_t s1, s2;
|
|
2903
|
-
size_t *idx1, *idx2;
|
|
2904
|
-
dtype x;
|
|
2905
|
-
|
|
2906
|
-
INIT_COUNTER(lp, n);
|
|
2907
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2908
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2909
|
-
|
|
2910
|
-
if (idx1) {
|
|
2911
|
-
if (idx2) {
|
|
1751
|
+
if (idx1) {
|
|
1752
|
+
if (idx2) {
|
|
2912
1753
|
for (i = 0; i < n; i++) {
|
|
2913
1754
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2914
|
-
x =
|
|
1755
|
+
x = m_reciprocal(x);
|
|
2915
1756
|
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2916
1757
|
}
|
|
2917
1758
|
} else {
|
|
2918
1759
|
for (i = 0; i < n; i++) {
|
|
2919
1760
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2920
|
-
x =
|
|
1761
|
+
x = m_reciprocal(x);
|
|
2921
1762
|
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2922
1763
|
}
|
|
2923
1764
|
}
|
|
@@ -2925,626 +1766,149 @@ static void iter_int8_bit_not(na_loop_t* const lp) {
|
|
|
2925
1766
|
if (idx2) {
|
|
2926
1767
|
for (i = 0; i < n; i++) {
|
|
2927
1768
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2928
|
-
x =
|
|
1769
|
+
x = m_reciprocal(x);
|
|
2929
1770
|
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2930
1771
|
}
|
|
2931
1772
|
} else {
|
|
2932
1773
|
//
|
|
2933
|
-
for (i = 0; i < n; i++) {
|
|
2934
|
-
*(dtype*)p2 =
|
|
2935
|
-
p1 += s1;
|
|
2936
|
-
p2 += s2;
|
|
2937
|
-
}
|
|
2938
|
-
return;
|
|
2939
|
-
//
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
|
|
2944
|
-
/*
|
|
2945
|
-
Unary bit_not.
|
|
2946
|
-
@overload ~
|
|
2947
|
-
@return [Numo::Int8] bit_not of self.
|
|
2948
|
-
*/
|
|
2949
|
-
static VALUE int8_bit_not(VALUE self) {
|
|
2950
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2951
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2952
|
-
ndfunc_t ndf = { iter_int8_bit_not, FULL_LOOP, 1, 1, ain, aout };
|
|
2953
|
-
|
|
2954
|
-
return na_ndloop(&ndf, 1, self);
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
#define check_intdivzero(y) \
|
|
2958
|
-
{}
|
|
2959
|
-
|
|
2960
|
-
static void iter_int8_left_shift(na_loop_t* const lp) {
|
|
2961
|
-
size_t i = 0;
|
|
2962
|
-
size_t n;
|
|
2963
|
-
char *p1, *p2, *p3;
|
|
2964
|
-
ssize_t s1, s2, s3;
|
|
2965
|
-
|
|
2966
|
-
INIT_COUNTER(lp, n);
|
|
2967
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2968
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2969
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2970
|
-
|
|
2971
|
-
//
|
|
2972
|
-
|
|
2973
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2974
|
-
check_intdivzero(*(dtype*)p2);
|
|
2975
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2976
|
-
if (p1 == p3) { // inplace case
|
|
2977
|
-
for (; i < n; i++) {
|
|
2978
|
-
((dtype*)p1)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
2979
|
-
}
|
|
2980
|
-
} else {
|
|
2981
|
-
for (; i < n; i++) {
|
|
2982
|
-
((dtype*)p3)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
2983
|
-
}
|
|
2984
|
-
}
|
|
2985
|
-
} else {
|
|
2986
|
-
for (i = 0; i < n; i++) {
|
|
2987
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2988
|
-
p1 += s1;
|
|
2989
|
-
p3 += s3;
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
} else {
|
|
2993
|
-
if (p1 == p3) { // inplace case
|
|
2994
|
-
for (i = 0; i < n; i++) {
|
|
2995
|
-
check_intdivzero(*(dtype*)p2);
|
|
2996
|
-
*(dtype*)p1 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2997
|
-
p1 += s1;
|
|
2998
|
-
p2 += s2;
|
|
2999
|
-
}
|
|
3000
|
-
} else {
|
|
3001
|
-
for (i = 0; i < n; i++) {
|
|
3002
|
-
check_intdivzero(*(dtype*)p2);
|
|
3003
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3004
|
-
p1 += s1;
|
|
3005
|
-
p2 += s2;
|
|
3006
|
-
p3 += s3;
|
|
3007
|
-
}
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
|
|
3011
|
-
return;
|
|
3012
|
-
//
|
|
3013
|
-
}
|
|
3014
|
-
#undef check_intdivzero
|
|
3015
|
-
|
|
3016
|
-
static VALUE int8_left_shift_self(VALUE self, VALUE other) {
|
|
3017
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3018
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3019
|
-
ndfunc_t ndf = { iter_int8_left_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3020
|
-
|
|
3021
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
/*
|
|
3025
|
-
Binary left_shift.
|
|
3026
|
-
@overload << other
|
|
3027
|
-
@param [Numo::NArray,Numeric] other
|
|
3028
|
-
@return [Numo::NArray] self << other
|
|
3029
|
-
*/
|
|
3030
|
-
static VALUE int8_left_shift(VALUE self, VALUE other) {
|
|
3031
|
-
|
|
3032
|
-
VALUE klass, v;
|
|
3033
|
-
|
|
3034
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3035
|
-
if (klass == cT) {
|
|
3036
|
-
return int8_left_shift_self(self, other);
|
|
3037
|
-
} else {
|
|
3038
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3039
|
-
return rb_funcall(v, id_left_shift, 1, other);
|
|
3040
|
-
}
|
|
3041
|
-
}
|
|
3042
|
-
|
|
3043
|
-
#define check_intdivzero(y) \
|
|
3044
|
-
{}
|
|
3045
|
-
|
|
3046
|
-
static void iter_int8_right_shift(na_loop_t* const lp) {
|
|
3047
|
-
size_t i = 0;
|
|
3048
|
-
size_t n;
|
|
3049
|
-
char *p1, *p2, *p3;
|
|
3050
|
-
ssize_t s1, s2, s3;
|
|
3051
|
-
|
|
3052
|
-
INIT_COUNTER(lp, n);
|
|
3053
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3054
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3055
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3056
|
-
|
|
3057
|
-
//
|
|
3058
|
-
|
|
3059
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
3060
|
-
check_intdivzero(*(dtype*)p2);
|
|
3061
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3062
|
-
if (p1 == p3) { // inplace case
|
|
3063
|
-
for (; i < n; i++) {
|
|
3064
|
-
((dtype*)p1)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3065
|
-
}
|
|
3066
|
-
} else {
|
|
3067
|
-
for (; i < n; i++) {
|
|
3068
|
-
((dtype*)p3)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
} else {
|
|
3072
|
-
for (i = 0; i < n; i++) {
|
|
3073
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3074
|
-
p1 += s1;
|
|
3075
|
-
p3 += s3;
|
|
3076
|
-
}
|
|
3077
|
-
}
|
|
3078
|
-
} else {
|
|
3079
|
-
if (p1 == p3) { // inplace case
|
|
3080
|
-
for (i = 0; i < n; i++) {
|
|
3081
|
-
check_intdivzero(*(dtype*)p2);
|
|
3082
|
-
*(dtype*)p1 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3083
|
-
p1 += s1;
|
|
3084
|
-
p2 += s2;
|
|
3085
|
-
}
|
|
3086
|
-
} else {
|
|
3087
|
-
for (i = 0; i < n; i++) {
|
|
3088
|
-
check_intdivzero(*(dtype*)p2);
|
|
3089
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3090
|
-
p1 += s1;
|
|
3091
|
-
p2 += s2;
|
|
3092
|
-
p3 += s3;
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
|
|
3097
|
-
return;
|
|
3098
|
-
//
|
|
3099
|
-
}
|
|
3100
|
-
#undef check_intdivzero
|
|
3101
|
-
|
|
3102
|
-
static VALUE int8_right_shift_self(VALUE self, VALUE other) {
|
|
3103
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3104
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3105
|
-
ndfunc_t ndf = { iter_int8_right_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3106
|
-
|
|
3107
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3108
|
-
}
|
|
3109
|
-
|
|
3110
|
-
/*
|
|
3111
|
-
Binary right_shift.
|
|
3112
|
-
@overload >> other
|
|
3113
|
-
@param [Numo::NArray,Numeric] other
|
|
3114
|
-
@return [Numo::NArray] self >> other
|
|
3115
|
-
*/
|
|
3116
|
-
static VALUE int8_right_shift(VALUE self, VALUE other) {
|
|
3117
|
-
|
|
3118
|
-
VALUE klass, v;
|
|
3119
|
-
|
|
3120
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3121
|
-
if (klass == cT) {
|
|
3122
|
-
return int8_right_shift_self(self, other);
|
|
3123
|
-
} else {
|
|
3124
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3125
|
-
return rb_funcall(v, id_right_shift, 1, other);
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
|
|
3129
|
-
static void iter_int8_gt(na_loop_t* const lp) {
|
|
3130
|
-
size_t i;
|
|
3131
|
-
char *p1, *p2;
|
|
3132
|
-
BIT_DIGIT* a3;
|
|
3133
|
-
size_t p3;
|
|
3134
|
-
ssize_t s1, s2, s3;
|
|
3135
|
-
dtype x, y;
|
|
3136
|
-
BIT_DIGIT b;
|
|
3137
|
-
INIT_COUNTER(lp, i);
|
|
3138
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3139
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3140
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3141
|
-
for (; i--;) {
|
|
3142
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3143
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3144
|
-
b = (m_gt(x, y)) ? 1 : 0;
|
|
3145
|
-
STORE_BIT(a3, p3, b);
|
|
3146
|
-
p3 += s3;
|
|
3147
|
-
}
|
|
3148
|
-
}
|
|
3149
|
-
|
|
3150
|
-
static VALUE int8_gt_self(VALUE self, VALUE other) {
|
|
3151
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3152
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3153
|
-
ndfunc_t ndf = { iter_int8_gt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3154
|
-
|
|
3155
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3156
|
-
}
|
|
3157
|
-
|
|
3158
|
-
/*
|
|
3159
|
-
Comparison gt other.
|
|
3160
|
-
@overload gt other
|
|
3161
|
-
@param [Numo::NArray,Numeric] other
|
|
3162
|
-
@return [Numo::Bit] result of self gt other.
|
|
3163
|
-
*/
|
|
3164
|
-
static VALUE int8_gt(VALUE self, VALUE other) {
|
|
3165
|
-
|
|
3166
|
-
VALUE klass, v;
|
|
3167
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3168
|
-
if (klass == cT) {
|
|
3169
|
-
return int8_gt_self(self, other);
|
|
3170
|
-
} else {
|
|
3171
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3172
|
-
return rb_funcall(v, id_gt, 1, other);
|
|
3173
|
-
}
|
|
3174
|
-
}
|
|
3175
|
-
|
|
3176
|
-
static void iter_int8_ge(na_loop_t* const lp) {
|
|
3177
|
-
size_t i;
|
|
3178
|
-
char *p1, *p2;
|
|
3179
|
-
BIT_DIGIT* a3;
|
|
3180
|
-
size_t p3;
|
|
3181
|
-
ssize_t s1, s2, s3;
|
|
3182
|
-
dtype x, y;
|
|
3183
|
-
BIT_DIGIT b;
|
|
3184
|
-
INIT_COUNTER(lp, i);
|
|
3185
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3186
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3187
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3188
|
-
for (; i--;) {
|
|
3189
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3190
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3191
|
-
b = (m_ge(x, y)) ? 1 : 0;
|
|
3192
|
-
STORE_BIT(a3, p3, b);
|
|
3193
|
-
p3 += s3;
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
|
-
static VALUE int8_ge_self(VALUE self, VALUE other) {
|
|
3198
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3199
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3200
|
-
ndfunc_t ndf = { iter_int8_ge, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3201
|
-
|
|
3202
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3203
|
-
}
|
|
3204
|
-
|
|
3205
|
-
/*
|
|
3206
|
-
Comparison ge other.
|
|
3207
|
-
@overload ge other
|
|
3208
|
-
@param [Numo::NArray,Numeric] other
|
|
3209
|
-
@return [Numo::Bit] result of self ge other.
|
|
3210
|
-
*/
|
|
3211
|
-
static VALUE int8_ge(VALUE self, VALUE other) {
|
|
3212
|
-
|
|
3213
|
-
VALUE klass, v;
|
|
3214
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3215
|
-
if (klass == cT) {
|
|
3216
|
-
return int8_ge_self(self, other);
|
|
3217
|
-
} else {
|
|
3218
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3219
|
-
return rb_funcall(v, id_ge, 1, other);
|
|
3220
|
-
}
|
|
3221
|
-
}
|
|
3222
|
-
|
|
3223
|
-
static void iter_int8_lt(na_loop_t* const lp) {
|
|
3224
|
-
size_t i;
|
|
3225
|
-
char *p1, *p2;
|
|
3226
|
-
BIT_DIGIT* a3;
|
|
3227
|
-
size_t p3;
|
|
3228
|
-
ssize_t s1, s2, s3;
|
|
3229
|
-
dtype x, y;
|
|
3230
|
-
BIT_DIGIT b;
|
|
3231
|
-
INIT_COUNTER(lp, i);
|
|
3232
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3233
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3234
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3235
|
-
for (; i--;) {
|
|
3236
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3237
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3238
|
-
b = (m_lt(x, y)) ? 1 : 0;
|
|
3239
|
-
STORE_BIT(a3, p3, b);
|
|
3240
|
-
p3 += s3;
|
|
3241
|
-
}
|
|
3242
|
-
}
|
|
3243
|
-
|
|
3244
|
-
static VALUE int8_lt_self(VALUE self, VALUE other) {
|
|
3245
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3246
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3247
|
-
ndfunc_t ndf = { iter_int8_lt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3248
|
-
|
|
3249
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3250
|
-
}
|
|
3251
|
-
|
|
3252
|
-
/*
|
|
3253
|
-
Comparison lt other.
|
|
3254
|
-
@overload lt other
|
|
3255
|
-
@param [Numo::NArray,Numeric] other
|
|
3256
|
-
@return [Numo::Bit] result of self lt other.
|
|
3257
|
-
*/
|
|
3258
|
-
static VALUE int8_lt(VALUE self, VALUE other) {
|
|
3259
|
-
|
|
3260
|
-
VALUE klass, v;
|
|
3261
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3262
|
-
if (klass == cT) {
|
|
3263
|
-
return int8_lt_self(self, other);
|
|
3264
|
-
} else {
|
|
3265
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3266
|
-
return rb_funcall(v, id_lt, 1, other);
|
|
3267
|
-
}
|
|
3268
|
-
}
|
|
3269
|
-
|
|
3270
|
-
static void iter_int8_le(na_loop_t* const lp) {
|
|
3271
|
-
size_t i;
|
|
3272
|
-
char *p1, *p2;
|
|
3273
|
-
BIT_DIGIT* a3;
|
|
3274
|
-
size_t p3;
|
|
3275
|
-
ssize_t s1, s2, s3;
|
|
3276
|
-
dtype x, y;
|
|
3277
|
-
BIT_DIGIT b;
|
|
3278
|
-
INIT_COUNTER(lp, i);
|
|
3279
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3280
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3281
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3282
|
-
for (; i--;) {
|
|
3283
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3284
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3285
|
-
b = (m_le(x, y)) ? 1 : 0;
|
|
3286
|
-
STORE_BIT(a3, p3, b);
|
|
3287
|
-
p3 += s3;
|
|
1774
|
+
for (i = 0; i < n; i++) {
|
|
1775
|
+
*(dtype*)p2 = m_reciprocal(*(dtype*)p1);
|
|
1776
|
+
p1 += s1;
|
|
1777
|
+
p2 += s2;
|
|
1778
|
+
}
|
|
1779
|
+
return;
|
|
1780
|
+
//
|
|
1781
|
+
}
|
|
3288
1782
|
}
|
|
3289
1783
|
}
|
|
3290
1784
|
|
|
3291
|
-
static VALUE int8_le_self(VALUE self, VALUE other) {
|
|
3292
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3293
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3294
|
-
ndfunc_t ndf = { iter_int8_le, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3295
|
-
|
|
3296
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
1785
|
/*
|
|
3300
|
-
|
|
3301
|
-
@overload
|
|
3302
|
-
@
|
|
3303
|
-
@return [Numo::Bit] result of self le other.
|
|
1786
|
+
Unary reciprocal.
|
|
1787
|
+
@overload reciprocal
|
|
1788
|
+
@return [Numo::Int8] reciprocal of self.
|
|
3304
1789
|
*/
|
|
3305
|
-
static VALUE
|
|
1790
|
+
static VALUE int8_reciprocal(VALUE self) {
|
|
1791
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1792
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1793
|
+
ndfunc_t ndf = { iter_int8_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
3306
1794
|
|
|
3307
|
-
|
|
3308
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3309
|
-
if (klass == cT) {
|
|
3310
|
-
return int8_le_self(self, other);
|
|
3311
|
-
} else {
|
|
3312
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3313
|
-
return rb_funcall(v, id_le, 1, other);
|
|
3314
|
-
}
|
|
1795
|
+
return na_ndloop(&ndf, 1, self);
|
|
3315
1796
|
}
|
|
3316
1797
|
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
static void iter_int8_bincount_32(na_loop_t* const lp) {
|
|
3320
|
-
size_t i, x, n;
|
|
1798
|
+
static void iter_int8_sign(na_loop_t* const lp) {
|
|
1799
|
+
size_t i, n;
|
|
3321
1800
|
char *p1, *p2;
|
|
3322
1801
|
ssize_t s1, s2;
|
|
3323
|
-
size_t*
|
|
1802
|
+
size_t *idx1, *idx2;
|
|
1803
|
+
dtype x;
|
|
3324
1804
|
|
|
1805
|
+
INIT_COUNTER(lp, n);
|
|
3325
1806
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3326
|
-
|
|
3327
|
-
i = lp->args[0].shape[0];
|
|
3328
|
-
n = lp->args[1].shape[0];
|
|
3329
|
-
|
|
3330
|
-
// initialize
|
|
3331
|
-
for (x = 0; x < n; x++) {
|
|
3332
|
-
*(u_int32_t*)(p2 + s2 * x) = 0;
|
|
3333
|
-
}
|
|
1807
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3334
1808
|
|
|
3335
1809
|
if (idx1) {
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
1810
|
+
if (idx2) {
|
|
1811
|
+
for (i = 0; i < n; i++) {
|
|
1812
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1813
|
+
x = m_sign(x);
|
|
1814
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1815
|
+
}
|
|
1816
|
+
} else {
|
|
1817
|
+
for (i = 0; i < n; i++) {
|
|
1818
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1819
|
+
x = m_sign(x);
|
|
1820
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1821
|
+
}
|
|
3339
1822
|
}
|
|
3340
1823
|
} else {
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
1824
|
+
if (idx2) {
|
|
1825
|
+
for (i = 0; i < n; i++) {
|
|
1826
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1827
|
+
x = m_sign(x);
|
|
1828
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1829
|
+
}
|
|
1830
|
+
} else {
|
|
1831
|
+
//
|
|
1832
|
+
for (i = 0; i < n; i++) {
|
|
1833
|
+
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
1834
|
+
p1 += s1;
|
|
1835
|
+
p2 += s2;
|
|
1836
|
+
}
|
|
1837
|
+
return;
|
|
1838
|
+
//
|
|
3344
1839
|
}
|
|
3345
1840
|
}
|
|
3346
1841
|
}
|
|
3347
1842
|
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
};
|
|
1843
|
+
/*
|
|
1844
|
+
Unary sign.
|
|
1845
|
+
@overload sign
|
|
1846
|
+
@return [Numo::Int8] sign of self.
|
|
1847
|
+
*/
|
|
1848
|
+
static VALUE int8_sign(VALUE self) {
|
|
1849
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1850
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1851
|
+
ndfunc_t ndf = { iter_int8_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
3355
1852
|
|
|
3356
1853
|
return na_ndloop(&ndf, 1, self);
|
|
3357
1854
|
}
|
|
3358
1855
|
|
|
3359
|
-
static void
|
|
3360
|
-
size_t i,
|
|
1856
|
+
static void iter_int8_square(na_loop_t* const lp) {
|
|
1857
|
+
size_t i, n;
|
|
3361
1858
|
char *p1, *p2;
|
|
3362
1859
|
ssize_t s1, s2;
|
|
3363
|
-
size_t*
|
|
1860
|
+
size_t *idx1, *idx2;
|
|
1861
|
+
dtype x;
|
|
3364
1862
|
|
|
1863
|
+
INIT_COUNTER(lp, n);
|
|
3365
1864
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3366
|
-
|
|
3367
|
-
i = lp->args[0].shape[0];
|
|
3368
|
-
n = lp->args[1].shape[0];
|
|
3369
|
-
|
|
3370
|
-
// initialize
|
|
3371
|
-
for (x = 0; x < n; x++) {
|
|
3372
|
-
*(u_int64_t*)(p2 + s2 * x) = 0;
|
|
3373
|
-
}
|
|
1865
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3374
1866
|
|
|
3375
1867
|
if (idx1) {
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
1868
|
+
if (idx2) {
|
|
1869
|
+
for (i = 0; i < n; i++) {
|
|
1870
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1871
|
+
x = m_square(x);
|
|
1872
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1873
|
+
}
|
|
1874
|
+
} else {
|
|
1875
|
+
for (i = 0; i < n; i++) {
|
|
1876
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1877
|
+
x = m_square(x);
|
|
1878
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1879
|
+
}
|
|
3379
1880
|
}
|
|
3380
1881
|
} else {
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
1882
|
+
if (idx2) {
|
|
1883
|
+
for (i = 0; i < n; i++) {
|
|
1884
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1885
|
+
x = m_square(x);
|
|
1886
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1887
|
+
}
|
|
1888
|
+
} else {
|
|
1889
|
+
//
|
|
1890
|
+
for (i = 0; i < n; i++) {
|
|
1891
|
+
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
1892
|
+
p1 += s1;
|
|
1893
|
+
p2 += s2;
|
|
1894
|
+
}
|
|
1895
|
+
return;
|
|
1896
|
+
//
|
|
3384
1897
|
}
|
|
3385
1898
|
}
|
|
3386
1899
|
}
|
|
3387
1900
|
|
|
3388
|
-
static VALUE int8_bincount_64(VALUE self, size_t length) {
|
|
3389
|
-
size_t shape_out[1] = { length };
|
|
3390
|
-
ndfunc_arg_in_t ain[1] = { { cT, 1 } };
|
|
3391
|
-
ndfunc_arg_out_t aout[1] = { { numo_cUInt64, 1, shape_out } };
|
|
3392
|
-
ndfunc_t ndf = {
|
|
3393
|
-
iter_int8_bincount_64, NO_LOOP | NDF_STRIDE_LOOP | NDF_INDEX_LOOP, 1, 1, ain, aout
|
|
3394
|
-
};
|
|
3395
|
-
|
|
3396
|
-
return na_ndloop(&ndf, 1, self);
|
|
3397
|
-
}
|
|
3398
|
-
// ------- end of Integer count without weights -------
|
|
3399
|
-
|
|
3400
|
-
// ------- Float count with weights -------
|
|
3401
|
-
|
|
3402
|
-
static void iter_int8_bincount_sf(na_loop_t* const lp) {
|
|
3403
|
-
float w;
|
|
3404
|
-
size_t i, x, n, m;
|
|
3405
|
-
char *p1, *p2, *p3;
|
|
3406
|
-
ssize_t s1, s2, s3;
|
|
3407
|
-
|
|
3408
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3409
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3410
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3411
|
-
i = lp->args[0].shape[0];
|
|
3412
|
-
m = lp->args[1].shape[0];
|
|
3413
|
-
n = lp->args[2].shape[0];
|
|
3414
|
-
|
|
3415
|
-
if (i != m) {
|
|
3416
|
-
rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight");
|
|
3417
|
-
}
|
|
3418
|
-
|
|
3419
|
-
// initialize
|
|
3420
|
-
for (x = 0; x < n; x++) {
|
|
3421
|
-
*(float*)(p3 + s3 * x) = 0;
|
|
3422
|
-
}
|
|
3423
|
-
for (; i--;) {
|
|
3424
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3425
|
-
GET_DATA_STRIDE(p2, s2, float, w);
|
|
3426
|
-
(*(float*)(p3 + s3 * x)) += w;
|
|
3427
|
-
}
|
|
3428
|
-
}
|
|
3429
|
-
|
|
3430
|
-
static VALUE int8_bincount_sf(VALUE self, VALUE weight, size_t length) {
|
|
3431
|
-
size_t shape_out[1] = { length };
|
|
3432
|
-
ndfunc_arg_in_t ain[2] = { { cT, 1 }, { numo_cSFloat, 1 } };
|
|
3433
|
-
ndfunc_arg_out_t aout[1] = { { numo_cSFloat, 1, shape_out } };
|
|
3434
|
-
ndfunc_t ndf = { iter_int8_bincount_sf, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout };
|
|
3435
|
-
|
|
3436
|
-
return na_ndloop(&ndf, 2, self, weight);
|
|
3437
|
-
}
|
|
3438
|
-
|
|
3439
|
-
static void iter_int8_bincount_df(na_loop_t* const lp) {
|
|
3440
|
-
double w;
|
|
3441
|
-
size_t i, x, n, m;
|
|
3442
|
-
char *p1, *p2, *p3;
|
|
3443
|
-
ssize_t s1, s2, s3;
|
|
3444
|
-
|
|
3445
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3446
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3447
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3448
|
-
i = lp->args[0].shape[0];
|
|
3449
|
-
m = lp->args[1].shape[0];
|
|
3450
|
-
n = lp->args[2].shape[0];
|
|
3451
|
-
|
|
3452
|
-
if (i != m) {
|
|
3453
|
-
rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight");
|
|
3454
|
-
}
|
|
3455
|
-
|
|
3456
|
-
// initialize
|
|
3457
|
-
for (x = 0; x < n; x++) {
|
|
3458
|
-
*(double*)(p3 + s3 * x) = 0;
|
|
3459
|
-
}
|
|
3460
|
-
for (; i--;) {
|
|
3461
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3462
|
-
GET_DATA_STRIDE(p2, s2, double, w);
|
|
3463
|
-
(*(double*)(p3 + s3 * x)) += w;
|
|
3464
|
-
}
|
|
3465
|
-
}
|
|
3466
|
-
|
|
3467
|
-
static VALUE int8_bincount_df(VALUE self, VALUE weight, size_t length) {
|
|
3468
|
-
size_t shape_out[1] = { length };
|
|
3469
|
-
ndfunc_arg_in_t ain[2] = { { cT, 1 }, { numo_cDFloat, 1 } };
|
|
3470
|
-
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 1, shape_out } };
|
|
3471
|
-
ndfunc_t ndf = { iter_int8_bincount_df, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout };
|
|
3472
|
-
|
|
3473
|
-
return na_ndloop(&ndf, 2, self, weight);
|
|
3474
|
-
}
|
|
3475
|
-
// ------- end of Float count with weights -------
|
|
3476
|
-
|
|
3477
1901
|
/*
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
@overload bincount([weight], minlength:nil)
|
|
3482
|
-
@param [SFloat or DFloat or Array] weight (optional) Array of
|
|
3483
|
-
float values. Its size along last axis should be same as that of self.
|
|
3484
|
-
@param [Integer] minlength (keyword, optional) Minimum size along
|
|
3485
|
-
last axis for the output array.
|
|
3486
|
-
@return [UInt32 or UInt64 or SFloat or DFloat]
|
|
3487
|
-
Returns Float NArray if weight array is supplied,
|
|
3488
|
-
otherwise returns UInt32 or UInt64 depending on the size along last axis.
|
|
3489
|
-
@example
|
|
3490
|
-
Numo::Int32[0..4].bincount
|
|
3491
|
-
# => Numo::UInt32#shape=[5]
|
|
3492
|
-
# [1, 1, 1, 1, 1]
|
|
3493
|
-
|
|
3494
|
-
Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
|
|
3495
|
-
# => Numo::UInt32#shape=[8]
|
|
3496
|
-
# [1, 3, 1, 1, 0, 0, 0, 1]
|
|
3497
|
-
|
|
3498
|
-
x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
|
|
3499
|
-
x.bincount.size == x.max+1
|
|
3500
|
-
# => true
|
|
3501
|
-
|
|
3502
|
-
w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
|
|
3503
|
-
x = Numo::Int32[0, 1, 1, 2, 2, 2]
|
|
3504
|
-
x.bincount(w)
|
|
3505
|
-
# => Numo::DFloat#shape=[3]
|
|
3506
|
-
# [0.3, 0.7, 1.1]
|
|
3507
|
-
|
|
1902
|
+
Unary square.
|
|
1903
|
+
@overload square
|
|
1904
|
+
@return [Numo::Int8] square of self.
|
|
3508
1905
|
*/
|
|
3509
|
-
static VALUE
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
ID table[1] = { id_minlength };
|
|
3514
|
-
size_t length, minlength;
|
|
3515
|
-
|
|
3516
|
-
rb_scan_args(argc, argv, "01:", &weight, &kw);
|
|
3517
|
-
rb_get_kwargs(kw, table, 0, 1, opts);
|
|
3518
|
-
|
|
3519
|
-
v = int8_minmax(0, 0, self);
|
|
3520
|
-
if (m_num_to_data(RARRAY_AREF(v, 0)) < 0) {
|
|
3521
|
-
rb_raise(rb_eArgError, "array items must be non-netagive");
|
|
3522
|
-
}
|
|
3523
|
-
v = RARRAY_AREF(v, 1);
|
|
3524
|
-
|
|
3525
|
-
length = NUM2SIZET(v) + 1;
|
|
3526
|
-
|
|
3527
|
-
if (opts[0] != Qundef) {
|
|
3528
|
-
minlength = NUM2SIZET(opts[0]);
|
|
3529
|
-
if (minlength > length) {
|
|
3530
|
-
length = minlength;
|
|
3531
|
-
}
|
|
3532
|
-
}
|
|
1906
|
+
static VALUE int8_square(VALUE self) {
|
|
1907
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1908
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1909
|
+
ndfunc_t ndf = { iter_int8_square, FULL_LOOP, 1, 1, ain, aout };
|
|
3533
1910
|
|
|
3534
|
-
|
|
3535
|
-
if (length > 4294967295ul) {
|
|
3536
|
-
return int8_bincount_64(self, length);
|
|
3537
|
-
} else {
|
|
3538
|
-
return int8_bincount_32(self, length);
|
|
3539
|
-
}
|
|
3540
|
-
} else {
|
|
3541
|
-
wclass = rb_obj_class(weight);
|
|
3542
|
-
if (wclass == numo_cSFloat) {
|
|
3543
|
-
return int8_bincount_sf(self, weight, length);
|
|
3544
|
-
} else {
|
|
3545
|
-
return int8_bincount_df(self, weight, length);
|
|
3546
|
-
}
|
|
3547
|
-
}
|
|
1911
|
+
return na_ndloop(&ndf, 1, self);
|
|
3548
1912
|
}
|
|
3549
1913
|
|
|
3550
1914
|
static void iter_int8_poly(na_loop_t* const lp) {
|
|
@@ -4170,22 +2534,91 @@ void Init_numo_int8(void) {
|
|
|
4170
2534
|
rb_define_singleton_method(cT, "cast", int8_s_cast, 1);
|
|
4171
2535
|
rb_define_method(cT, "[]", int8_aref, -1);
|
|
4172
2536
|
rb_define_method(cT, "[]=", int8_aset, -1);
|
|
2537
|
+
/**
|
|
2538
|
+
* return NArray with cast to the type of self.
|
|
2539
|
+
* @overload coerce_cast(type)
|
|
2540
|
+
* @return [nil]
|
|
2541
|
+
*/
|
|
4173
2542
|
rb_define_method(cT, "coerce_cast", int8_coerce_cast, 1);
|
|
2543
|
+
/**
|
|
2544
|
+
* Convert self to Array.
|
|
2545
|
+
* @overload to_a
|
|
2546
|
+
* @return [Array]
|
|
2547
|
+
*/
|
|
4174
2548
|
rb_define_method(cT, "to_a", int8_to_a, 0);
|
|
2549
|
+
/**
|
|
2550
|
+
* Fill elements with other.
|
|
2551
|
+
* @overload fill other
|
|
2552
|
+
* @param [Numeric] other
|
|
2553
|
+
* @return [Numo::Int8] self.
|
|
2554
|
+
*/
|
|
4175
2555
|
rb_define_method(cT, "fill", int8_fill, 1);
|
|
2556
|
+
/**
|
|
2557
|
+
* Format elements into strings.
|
|
2558
|
+
* @overload format format
|
|
2559
|
+
* @param [String] format
|
|
2560
|
+
* @return [Numo::RObject] array of formatted strings.
|
|
2561
|
+
*/
|
|
4176
2562
|
rb_define_method(cT, "format", int8_format, -1);
|
|
2563
|
+
/**
|
|
2564
|
+
* Format elements into strings.
|
|
2565
|
+
* @overload format_to_a format
|
|
2566
|
+
* @param [String] format
|
|
2567
|
+
* @return [Array] array of formatted strings.
|
|
2568
|
+
*/
|
|
4177
2569
|
rb_define_method(cT, "format_to_a", int8_format_to_a, -1);
|
|
2570
|
+
/**
|
|
2571
|
+
* Returns a string containing a human-readable representation of NArray.
|
|
2572
|
+
* @overload inspect
|
|
2573
|
+
* @return [String]
|
|
2574
|
+
*/
|
|
4178
2575
|
rb_define_method(cT, "inspect", int8_inspect, 0);
|
|
4179
2576
|
rb_define_method(cT, "each", int8_each, 0);
|
|
4180
2577
|
rb_define_method(cT, "map", int8_map, 0);
|
|
4181
2578
|
rb_define_method(cT, "each_with_index", int8_each_with_index, 0);
|
|
4182
2579
|
rb_define_method(cT, "map_with_index", int8_map_with_index, 0);
|
|
4183
2580
|
rb_define_method(cT, "abs", int8_abs, 0);
|
|
2581
|
+
/**
|
|
2582
|
+
* Binary add.
|
|
2583
|
+
* @overload + other
|
|
2584
|
+
* @param [Numo::NArray,Numeric] other
|
|
2585
|
+
* @return [Numo::NArray] self + other
|
|
2586
|
+
*/
|
|
4184
2587
|
rb_define_method(cT, "+", int8_add, 1);
|
|
2588
|
+
/**
|
|
2589
|
+
* Binary sub.
|
|
2590
|
+
* @overload - other
|
|
2591
|
+
* @param [Numo::NArray,Numeric] other
|
|
2592
|
+
* @return [Numo::NArray] self - other
|
|
2593
|
+
*/
|
|
4185
2594
|
rb_define_method(cT, "-", int8_sub, 1);
|
|
2595
|
+
/**
|
|
2596
|
+
* Binary mul.
|
|
2597
|
+
* @overload * other
|
|
2598
|
+
* @param [Numo::NArray,Numeric] other
|
|
2599
|
+
* @return [Numo::NArray] self * other
|
|
2600
|
+
*/
|
|
4186
2601
|
rb_define_method(cT, "*", int8_mul, 1);
|
|
2602
|
+
/**
|
|
2603
|
+
* Binary div.
|
|
2604
|
+
* @overload / other
|
|
2605
|
+
* @param [Numo::NArray,Numeric] other
|
|
2606
|
+
* @return [Numo::NArray] self / other
|
|
2607
|
+
*/
|
|
4187
2608
|
rb_define_method(cT, "/", int8_div, 1);
|
|
2609
|
+
/**
|
|
2610
|
+
* Binary mod.
|
|
2611
|
+
* @overload % other
|
|
2612
|
+
* @param [Numo::NArray,Numeric] other
|
|
2613
|
+
* @return [Numo::NArray] self % other
|
|
2614
|
+
*/
|
|
4188
2615
|
rb_define_method(cT, "%", int8_mod, 1);
|
|
2616
|
+
/**
|
|
2617
|
+
* Binary divmod.
|
|
2618
|
+
* @overload divmod other
|
|
2619
|
+
* @param [Numo::NArray,Numeric] other
|
|
2620
|
+
* @return [Numo::NArray] divmod of self and other.
|
|
2621
|
+
*/
|
|
4189
2622
|
rb_define_method(cT, "divmod", int8_divmod, 1);
|
|
4190
2623
|
rb_define_method(cT, "**", int8_pow, 1);
|
|
4191
2624
|
rb_define_alias(cT, "pow", "**");
|
|
@@ -4196,24 +2629,95 @@ void Init_numo_int8(void) {
|
|
|
4196
2629
|
rb_define_alias(cT, "conj", "view");
|
|
4197
2630
|
rb_define_alias(cT, "im", "view");
|
|
4198
2631
|
rb_define_alias(cT, "conjugate", "conj");
|
|
2632
|
+
/**
|
|
2633
|
+
* Comparison eq other.
|
|
2634
|
+
* @overload eq other
|
|
2635
|
+
* @param [Numo::NArray,Numeric] other
|
|
2636
|
+
* @return [Numo::Bit] result of self eq other.
|
|
2637
|
+
*/
|
|
4199
2638
|
rb_define_method(cT, "eq", int8_eq, 1);
|
|
2639
|
+
/**
|
|
2640
|
+
* Comparison ne other.
|
|
2641
|
+
* @overload ne other
|
|
2642
|
+
* @param [Numo::NArray,Numeric] other
|
|
2643
|
+
* @return [Numo::Bit] result of self ne other.
|
|
2644
|
+
*/
|
|
4200
2645
|
rb_define_method(cT, "ne", int8_ne, 1);
|
|
4201
2646
|
rb_define_alias(cT, "nearly_eq", "eq");
|
|
4202
2647
|
rb_define_alias(cT, "close_to", "nearly_eq");
|
|
2648
|
+
/**
|
|
2649
|
+
* Binary bit_and.
|
|
2650
|
+
* @overload & other
|
|
2651
|
+
* @param [Numo::NArray,Numeric] other
|
|
2652
|
+
* @return [Numo::NArray] self & other
|
|
2653
|
+
*/
|
|
4203
2654
|
rb_define_method(cT, "&", int8_bit_and, 1);
|
|
2655
|
+
/**
|
|
2656
|
+
* Binary bit_or.
|
|
2657
|
+
* @overload | other
|
|
2658
|
+
* @param [Numo::NArray,Numeric] other
|
|
2659
|
+
* @return [Numo::NArray] self | other
|
|
2660
|
+
*/
|
|
4204
2661
|
rb_define_method(cT, "|", int8_bit_or, 1);
|
|
2662
|
+
/**
|
|
2663
|
+
* binary bit_xor.
|
|
2664
|
+
* @overload ^ other
|
|
2665
|
+
* @param [numo::narray,numeric] other
|
|
2666
|
+
* @return [numo::narray] self ^ other
|
|
2667
|
+
*/
|
|
4205
2668
|
rb_define_method(cT, "^", int8_bit_xor, 1);
|
|
2669
|
+
/**
|
|
2670
|
+
* Unary bit_not.
|
|
2671
|
+
* @overload ~
|
|
2672
|
+
* @return [Numo::Int8] bit_not of self.
|
|
2673
|
+
*/
|
|
4206
2674
|
rb_define_method(cT, "~", int8_bit_not, 0);
|
|
2675
|
+
/**
|
|
2676
|
+
* Binary left_shift.
|
|
2677
|
+
* @overload << other
|
|
2678
|
+
* @param [Numo::NArray,Numeric] other
|
|
2679
|
+
* @return [Numo::NArray] self << other
|
|
2680
|
+
*/
|
|
4207
2681
|
rb_define_method(cT, "<<", int8_left_shift, 1);
|
|
2682
|
+
/**
|
|
2683
|
+
* Binary right_shift.
|
|
2684
|
+
* @overload >> other
|
|
2685
|
+
* @param [Numo::NArray,Numeric] other
|
|
2686
|
+
* @return [Numo::NArray] self >> other
|
|
2687
|
+
*/
|
|
4208
2688
|
rb_define_method(cT, ">>", int8_right_shift, 1);
|
|
4209
2689
|
rb_define_alias(cT, "floor", "view");
|
|
4210
2690
|
rb_define_alias(cT, "round", "view");
|
|
4211
2691
|
rb_define_alias(cT, "ceil", "view");
|
|
4212
2692
|
rb_define_alias(cT, "trunc", "view");
|
|
4213
2693
|
rb_define_alias(cT, "rint", "view");
|
|
2694
|
+
/**
|
|
2695
|
+
* Comparison gt other.
|
|
2696
|
+
* @overload gt other
|
|
2697
|
+
* @param [Numo::NArray,Numeric] other
|
|
2698
|
+
* @return [Numo::Bit] result of self gt other.
|
|
2699
|
+
*/
|
|
4214
2700
|
rb_define_method(cT, "gt", int8_gt, 1);
|
|
2701
|
+
/**
|
|
2702
|
+
* Comparison ge other.
|
|
2703
|
+
* @overload ge other
|
|
2704
|
+
* @param [Numo::NArray,Numeric] other
|
|
2705
|
+
* @return [Numo::Bit] result of self ge other.
|
|
2706
|
+
*/
|
|
4215
2707
|
rb_define_method(cT, "ge", int8_ge, 1);
|
|
2708
|
+
/**
|
|
2709
|
+
* Comparison lt other.
|
|
2710
|
+
* @overload lt other
|
|
2711
|
+
* @param [Numo::NArray,Numeric] other
|
|
2712
|
+
* @return [Numo::Bit] result of self lt other.
|
|
2713
|
+
*/
|
|
4216
2714
|
rb_define_method(cT, "lt", int8_lt, 1);
|
|
2715
|
+
/**
|
|
2716
|
+
* Comparison le other.
|
|
2717
|
+
* @overload le other
|
|
2718
|
+
* @param [Numo::NArray,Numeric] other
|
|
2719
|
+
* @return [Numo::Bit] result of self le other.
|
|
2720
|
+
*/
|
|
4217
2721
|
rb_define_method(cT, "le", int8_le, 1);
|
|
4218
2722
|
rb_define_alias(cT, ">", "gt");
|
|
4219
2723
|
rb_define_alias(cT, ">=", "ge");
|
|
@@ -4398,6 +2902,37 @@ void Init_numo_int8(void) {
|
|
|
4398
2902
|
* @return [Numo::Int8]
|
|
4399
2903
|
*/
|
|
4400
2904
|
rb_define_module_function(cT, "minimum", int8_s_minimum, -1);
|
|
2905
|
+
/**
|
|
2906
|
+
* Count the number of occurrences of each non-negative integer value.
|
|
2907
|
+
* Only Integer-types has this method.
|
|
2908
|
+
*
|
|
2909
|
+
* @overload bincount([weight], minlength:nil)
|
|
2910
|
+
* @param [SFloat or DFloat or Array] weight (optional) Array of
|
|
2911
|
+
* float values. Its size along last axis should be same as that of self.
|
|
2912
|
+
* @param [Integer] minlength (keyword, optional) Minimum size along
|
|
2913
|
+
* last axis for the output array.
|
|
2914
|
+
* @return [UInt32 or UInt64 or SFloat or DFloat]
|
|
2915
|
+
* Returns Float NArray if weight array is supplied,
|
|
2916
|
+
* otherwise returns UInt32 or UInt64 depending on the size along last axis.
|
|
2917
|
+
* @example
|
|
2918
|
+
* Numo::Int32[0..4].bincount
|
|
2919
|
+
* # => Numo::UInt32#shape=[5]
|
|
2920
|
+
* # [1, 1, 1, 1, 1]
|
|
2921
|
+
*
|
|
2922
|
+
* Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
|
|
2923
|
+
* # => Numo::UInt32#shape=[8]
|
|
2924
|
+
* # [1, 3, 1, 1, 0, 0, 0, 1]
|
|
2925
|
+
*
|
|
2926
|
+
* x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
|
|
2927
|
+
* x.bincount.size == x.max+1
|
|
2928
|
+
* # => true
|
|
2929
|
+
*
|
|
2930
|
+
* w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
|
|
2931
|
+
* x = Numo::Int32[0, 1, 1, 2, 2, 2]
|
|
2932
|
+
* x.bincount(w)
|
|
2933
|
+
* # => Numo::DFloat#shape=[3]
|
|
2934
|
+
* # [0.3, 0.7, 1.1]
|
|
2935
|
+
*/
|
|
4401
2936
|
rb_define_method(cT, "bincount", int8_bincount, -1);
|
|
4402
2937
|
/**
|
|
4403
2938
|
* cumsum of self.
|