numo-narray-alt 0.9.11 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +7 -0
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/numo/types/robj_macro.h +1 -1
- data/ext/numo/narray/src/mh/bincount.h +233 -0
- data/ext/numo/narray/src/mh/bit/and.h +225 -0
- data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/not.h +173 -0
- data/ext/numo/narray/src/mh/bit/or.h +225 -0
- data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/xor.h +225 -0
- data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
- data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
- data/ext/numo/narray/src/mh/comp/eq.h +26 -0
- data/ext/numo/narray/src/mh/comp/ge.h +26 -0
- data/ext/numo/narray/src/mh/comp/gt.h +26 -0
- data/ext/numo/narray/src/mh/comp/le.h +26 -0
- data/ext/numo/narray/src/mh/comp/lt.h +26 -0
- data/ext/numo/narray/src/mh/comp/ne.h +26 -0
- data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
- data/ext/numo/narray/src/mh/divmod.h +142 -0
- data/ext/numo/narray/src/mh/eye.h +1 -1
- data/ext/numo/narray/src/mh/fill.h +94 -0
- data/ext/numo/narray/src/mh/format.h +108 -0
- data/ext/numo/narray/src/mh/format_to_a.h +89 -0
- data/ext/numo/narray/src/mh/inspect.h +33 -0
- data/ext/numo/narray/src/mh/isfinite.h +42 -0
- data/ext/numo/narray/src/mh/isinf.h +42 -0
- data/ext/numo/narray/src/mh/isnan.h +42 -0
- data/ext/numo/narray/src/mh/isneginf.h +42 -0
- data/ext/numo/narray/src/mh/isposinf.h +42 -0
- data/ext/numo/narray/src/mh/math/acos.h +2 -2
- data/ext/numo/narray/src/mh/math/acosh.h +2 -2
- data/ext/numo/narray/src/mh/math/asin.h +2 -2
- data/ext/numo/narray/src/mh/math/asinh.h +2 -2
- data/ext/numo/narray/src/mh/math/atan.h +2 -2
- data/ext/numo/narray/src/mh/math/atan2.h +3 -3
- data/ext/numo/narray/src/mh/math/atanh.h +2 -2
- data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
- data/ext/numo/narray/src/mh/math/cos.h +2 -2
- data/ext/numo/narray/src/mh/math/cosh.h +2 -2
- data/ext/numo/narray/src/mh/math/erf.h +2 -2
- data/ext/numo/narray/src/mh/math/erfc.h +2 -2
- data/ext/numo/narray/src/mh/math/exp.h +2 -2
- data/ext/numo/narray/src/mh/math/exp10.h +2 -2
- data/ext/numo/narray/src/mh/math/exp2.h +2 -2
- data/ext/numo/narray/src/mh/math/expm1.h +2 -2
- data/ext/numo/narray/src/mh/math/frexp.h +3 -3
- data/ext/numo/narray/src/mh/math/hypot.h +3 -3
- data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
- data/ext/numo/narray/src/mh/math/log.h +2 -2
- data/ext/numo/narray/src/mh/math/log10.h +2 -2
- data/ext/numo/narray/src/mh/math/log1p.h +2 -2
- data/ext/numo/narray/src/mh/math/log2.h +2 -2
- data/ext/numo/narray/src/mh/math/sin.h +2 -2
- data/ext/numo/narray/src/mh/math/sinc.h +2 -2
- data/ext/numo/narray/src/mh/math/sinh.h +2 -2
- data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
- data/ext/numo/narray/src/mh/math/tan.h +2 -2
- data/ext/numo/narray/src/mh/math/tanh.h +2 -2
- data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
- data/ext/numo/narray/src/mh/minus.h +125 -0
- data/ext/numo/narray/src/mh/op/add.h +78 -0
- data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
- data/ext/numo/narray/src/mh/op/div.h +118 -0
- data/ext/numo/narray/src/mh/op/mod.h +108 -0
- data/ext/numo/narray/src/mh/op/mul.h +78 -0
- data/ext/numo/narray/src/mh/op/sub.h +78 -0
- data/ext/numo/narray/src/mh/pow.h +197 -0
- data/ext/numo/narray/src/mh/rand.h +2 -2
- data/ext/numo/narray/src/mh/rand_norm.h +125 -0
- data/ext/numo/narray/src/mh/reciprocal.h +125 -0
- data/ext/numo/narray/src/mh/round/ceil.h +11 -0
- data/ext/numo/narray/src/mh/round/floor.h +11 -0
- data/ext/numo/narray/src/mh/round/rint.h +9 -0
- data/ext/numo/narray/src/mh/round/round.h +11 -0
- data/ext/numo/narray/src/mh/round/trunc.h +11 -0
- data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
- data/ext/numo/narray/src/mh/sign.h +125 -0
- data/ext/numo/narray/src/mh/square.h +125 -0
- data/ext/numo/narray/src/mh/to_a.h +78 -0
- data/ext/numo/narray/src/t_bit.c +45 -234
- data/ext/numo/narray/src/t_dcomplex.c +457 -2075
- data/ext/numo/narray/src/t_dfloat.c +154 -2560
- data/ext/numo/narray/src/t_int16.c +408 -2542
- data/ext/numo/narray/src/t_int32.c +408 -2542
- data/ext/numo/narray/src/t_int64.c +408 -2542
- data/ext/numo/narray/src/t_int8.c +409 -2138
- data/ext/numo/narray/src/t_robject.c +376 -2161
- data/ext/numo/narray/src/t_scomplex.c +435 -2053
- data/ext/numo/narray/src/t_sfloat.c +149 -2557
- data/ext/numo/narray/src/t_uint16.c +407 -2537
- data/ext/numo/narray/src/t_uint32.c +407 -2537
- data/ext/numo/narray/src/t_uint64.c +407 -2537
- data/ext/numo/narray/src/t_uint8.c +407 -2132
- metadata +47 -2
|
@@ -60,7 +60,46 @@ static ID id_truncate;
|
|
|
60
60
|
VALUE cT;
|
|
61
61
|
extern VALUE cRT;
|
|
62
62
|
|
|
63
|
+
#include "mh/coerce_cast.h"
|
|
64
|
+
#include "mh/to_a.h"
|
|
65
|
+
#include "mh/fill.h"
|
|
66
|
+
#include "mh/format.h"
|
|
67
|
+
#include "mh/format_to_a.h"
|
|
68
|
+
#include "mh/inspect.h"
|
|
69
|
+
#include "mh/op/add.h"
|
|
70
|
+
#include "mh/op/sub.h"
|
|
71
|
+
#include "mh/op/mul.h"
|
|
72
|
+
#include "mh/op/div.h"
|
|
73
|
+
#include "mh/op/mod.h"
|
|
74
|
+
#include "mh/divmod.h"
|
|
75
|
+
#include "mh/pow.h"
|
|
76
|
+
#include "mh/minus.h"
|
|
77
|
+
#include "mh/reciprocal.h"
|
|
78
|
+
#include "mh/sign.h"
|
|
79
|
+
#include "mh/square.h"
|
|
80
|
+
#include "mh/round/floor.h"
|
|
81
|
+
#include "mh/round/round.h"
|
|
82
|
+
#include "mh/round/ceil.h"
|
|
83
|
+
#include "mh/round/trunc.h"
|
|
84
|
+
#include "mh/comp/eq.h"
|
|
85
|
+
#include "mh/comp/ne.h"
|
|
86
|
+
#include "mh/comp/nearly_eq.h"
|
|
87
|
+
#include "mh/comp/gt.h"
|
|
88
|
+
#include "mh/comp/ge.h"
|
|
89
|
+
#include "mh/comp/lt.h"
|
|
90
|
+
#include "mh/comp/le.h"
|
|
91
|
+
#include "mh/bit/and.h"
|
|
92
|
+
#include "mh/bit/or.h"
|
|
93
|
+
#include "mh/bit/xor.h"
|
|
94
|
+
#include "mh/bit/not.h"
|
|
95
|
+
#include "mh/bit/left_shift.h"
|
|
96
|
+
#include "mh/bit/right_shift.h"
|
|
63
97
|
#include "mh/clip.h"
|
|
98
|
+
#include "mh/isnan.h"
|
|
99
|
+
#include "mh/isinf.h"
|
|
100
|
+
#include "mh/isposinf.h"
|
|
101
|
+
#include "mh/isneginf.h"
|
|
102
|
+
#include "mh/isfinite.h"
|
|
64
103
|
#include "mh/sum.h"
|
|
65
104
|
#include "mh/prod.h"
|
|
66
105
|
#include "mh/mean.h"
|
|
@@ -87,7 +126,46 @@ extern VALUE cRT;
|
|
|
87
126
|
|
|
88
127
|
typedef VALUE robject; // Type aliases for shorter notation
|
|
89
128
|
// following the codebase naming convention.
|
|
129
|
+
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(robject)
|
|
130
|
+
DEF_NARRAY_TO_A_METHOD_FUNC(robject)
|
|
131
|
+
DEF_NARRAY_FILL_METHOD_FUNC(robject)
|
|
132
|
+
DEF_NARRAY_FORMAT_METHOD_FUNC(robject)
|
|
133
|
+
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(robject)
|
|
134
|
+
DEF_NARRAY_ROBJ_INSPECT_METHOD_FUNC()
|
|
135
|
+
DEF_NARRAY_ROBJ_ADD_METHOD_FUNC()
|
|
136
|
+
DEF_NARRAY_ROBJ_SUB_METHOD_FUNC()
|
|
137
|
+
DEF_NARRAY_ROBJ_MUL_METHOD_FUNC()
|
|
138
|
+
DEF_NARRAY_ROBJ_DIV_METHOD_FUNC()
|
|
139
|
+
DEF_NARRAY_ROBJ_MOD_METHOD_FUNC()
|
|
140
|
+
DEF_NARRAY_ROBJ_DIVMOD_METHOD_FUNC()
|
|
141
|
+
DEF_NARRAY_ROBJ_POW_METHOD_FUNC()
|
|
142
|
+
DEF_NARRAY_ROBJ_MINUS_METHOD_FUNC()
|
|
143
|
+
DEF_NARRAY_ROBJ_RECIPROCAL_METHOD_FUNC()
|
|
144
|
+
DEF_NARRAY_ROBJ_SIGN_METHOD_FUNC()
|
|
145
|
+
DEF_NARRAY_ROBJ_SQUARE_METHOD_FUNC()
|
|
146
|
+
DEF_NARRAY_ROBJ_FLOOR_METHOD_FUNC()
|
|
147
|
+
DEF_NARRAY_ROBJ_ROUND_METHOD_FUNC()
|
|
148
|
+
DEF_NARRAY_ROBJ_CEIL_METHOD_FUNC()
|
|
149
|
+
DEF_NARRAY_ROBJ_TRUNC_METHOD_FUNC()
|
|
150
|
+
DEF_NARRAY_ROBJ_EQ_METHOD_FUNC()
|
|
151
|
+
DEF_NARRAY_ROBJ_NE_METHOD_FUNC()
|
|
152
|
+
DEF_NARRAY_ROBJ_NEARLY_EQ_METHOD_FUNC()
|
|
153
|
+
DEF_NARRAY_ROBJ_GT_METHOD_FUNC()
|
|
154
|
+
DEF_NARRAY_ROBJ_GE_METHOD_FUNC()
|
|
155
|
+
DEF_NARRAY_ROBJ_LT_METHOD_FUNC()
|
|
156
|
+
DEF_NARRAY_ROBJ_LE_METHOD_FUNC()
|
|
157
|
+
DEF_NARRAY_ROBJ_BIT_AND_METHOD_FUNC()
|
|
158
|
+
DEF_NARRAY_ROBJ_BIT_OR_METHOD_FUNC()
|
|
159
|
+
DEF_NARRAY_ROBJ_BIT_XOR_METHOD_FUNC()
|
|
160
|
+
DEF_NARRAY_ROBJ_BIT_NOT_METHOD_FUNC()
|
|
161
|
+
DEF_NARRAY_ROBJ_LEFT_SHIFT_METHOD_FUNC()
|
|
162
|
+
DEF_NARRAY_ROBJ_RIGHT_SHIFT_METHOD_FUNC()
|
|
90
163
|
DEF_NARRAY_CLIP_METHOD_FUNC(robject, numo_cRObject)
|
|
164
|
+
DEF_NARRAY_FLT_ISNAN_METHOD_FUNC(robject, numo_cRObject)
|
|
165
|
+
DEF_NARRAY_FLT_ISINF_METHOD_FUNC(robject, numo_cRObject)
|
|
166
|
+
DEF_NARRAY_FLT_ISPOSINF_METHOD_FUNC(robject, numo_cRObject)
|
|
167
|
+
DEF_NARRAY_FLT_ISNEGINF_METHOD_FUNC(robject, numo_cRObject)
|
|
168
|
+
DEF_NARRAY_FLT_ISFINITE_METHOD_FUNC(robject, numo_cRObject)
|
|
91
169
|
DEF_NARRAY_FLT_SUM_METHOD_FUNC(robject, numo_cRObject)
|
|
92
170
|
DEF_NARRAY_FLT_PROD_METHOD_FUNC(robject, numo_cRObject)
|
|
93
171
|
DEF_NARRAY_FLT_MEAN_METHOD_FUNC(robject, numo_cRObject, VALUE, numo_cRObject)
|
|
@@ -1286,204 +1364,6 @@ static VALUE robject_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1286
1364
|
return argv[argc];
|
|
1287
1365
|
}
|
|
1288
1366
|
|
|
1289
|
-
/*
|
|
1290
|
-
return NArray with cast to the type of self.
|
|
1291
|
-
@overload coerce_cast(type)
|
|
1292
|
-
@return [nil]
|
|
1293
|
-
*/
|
|
1294
|
-
static VALUE robject_coerce_cast(VALUE self, VALUE type) {
|
|
1295
|
-
return Qnil;
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
static void iter_robject_to_a(na_loop_t* const lp) {
|
|
1299
|
-
size_t i, s1;
|
|
1300
|
-
char* p1;
|
|
1301
|
-
size_t* idx1;
|
|
1302
|
-
dtype x;
|
|
1303
|
-
volatile VALUE a, y;
|
|
1304
|
-
|
|
1305
|
-
INIT_COUNTER(lp, i);
|
|
1306
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1307
|
-
a = rb_ary_new2(i);
|
|
1308
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1309
|
-
if (idx1) {
|
|
1310
|
-
for (; i--;) {
|
|
1311
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1312
|
-
y = m_data_to_num(x);
|
|
1313
|
-
rb_ary_push(a, y);
|
|
1314
|
-
}
|
|
1315
|
-
} else {
|
|
1316
|
-
for (; i--;) {
|
|
1317
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1318
|
-
y = m_data_to_num(x);
|
|
1319
|
-
rb_ary_push(a, y);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
/*
|
|
1325
|
-
Convert self to Array.
|
|
1326
|
-
@overload to_a
|
|
1327
|
-
@return [Array]
|
|
1328
|
-
*/
|
|
1329
|
-
static VALUE robject_to_a(VALUE self) {
|
|
1330
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1331
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1332
|
-
ndfunc_t ndf = { iter_robject_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1333
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
static void iter_robject_fill(na_loop_t* const lp) {
|
|
1337
|
-
size_t i;
|
|
1338
|
-
char* p1;
|
|
1339
|
-
ssize_t s1;
|
|
1340
|
-
size_t* idx1;
|
|
1341
|
-
VALUE x = lp->option;
|
|
1342
|
-
dtype y;
|
|
1343
|
-
INIT_COUNTER(lp, i);
|
|
1344
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1345
|
-
y = m_num_to_data(x);
|
|
1346
|
-
if (idx1) {
|
|
1347
|
-
for (; i--;) {
|
|
1348
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
1349
|
-
}
|
|
1350
|
-
} else {
|
|
1351
|
-
for (; i--;) {
|
|
1352
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
/*
|
|
1358
|
-
Fill elements with other.
|
|
1359
|
-
@overload fill other
|
|
1360
|
-
@param [Numeric] other
|
|
1361
|
-
@return [Numo::RObject] self.
|
|
1362
|
-
*/
|
|
1363
|
-
static VALUE robject_fill(VALUE self, VALUE val) {
|
|
1364
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
|
|
1365
|
-
ndfunc_t ndf = { iter_robject_fill, FULL_LOOP, 2, 0, ain, 0 };
|
|
1366
|
-
|
|
1367
|
-
na_ndloop(&ndf, 2, self, val);
|
|
1368
|
-
return self;
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
static VALUE format_robject(VALUE fmt, dtype* x) {
|
|
1372
|
-
// fix-me
|
|
1373
|
-
char s[48];
|
|
1374
|
-
int n;
|
|
1375
|
-
|
|
1376
|
-
if (NIL_P(fmt)) {
|
|
1377
|
-
n = m_sprintf(s, *x);
|
|
1378
|
-
return rb_str_new(s, n);
|
|
1379
|
-
}
|
|
1380
|
-
return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
static void iter_robject_format(na_loop_t* const lp) {
|
|
1384
|
-
size_t i;
|
|
1385
|
-
char *p1, *p2;
|
|
1386
|
-
ssize_t s1, s2;
|
|
1387
|
-
size_t* idx1;
|
|
1388
|
-
dtype* x;
|
|
1389
|
-
VALUE y;
|
|
1390
|
-
VALUE fmt = lp->option;
|
|
1391
|
-
INIT_COUNTER(lp, i);
|
|
1392
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1393
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1394
|
-
if (idx1) {
|
|
1395
|
-
for (; i--;) {
|
|
1396
|
-
x = (dtype*)(p1 + *idx1);
|
|
1397
|
-
idx1++;
|
|
1398
|
-
y = format_robject(fmt, x);
|
|
1399
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1400
|
-
}
|
|
1401
|
-
} else {
|
|
1402
|
-
for (; i--;) {
|
|
1403
|
-
x = (dtype*)p1;
|
|
1404
|
-
p1 += s1;
|
|
1405
|
-
y = format_robject(fmt, x);
|
|
1406
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
/*
|
|
1412
|
-
Format elements into strings.
|
|
1413
|
-
@overload format format
|
|
1414
|
-
@param [String] format
|
|
1415
|
-
@return [Numo::RObject] array of formatted strings.
|
|
1416
|
-
*/
|
|
1417
|
-
static VALUE robject_format(int argc, VALUE* argv, VALUE self) {
|
|
1418
|
-
VALUE fmt = Qnil;
|
|
1419
|
-
|
|
1420
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
|
|
1421
|
-
ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
|
|
1422
|
-
ndfunc_t ndf = { iter_robject_format, FULL_LOOP_NIP, 2, 1, ain, aout };
|
|
1423
|
-
|
|
1424
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1425
|
-
return na_ndloop(&ndf, 2, self, fmt);
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
static void iter_robject_format_to_a(na_loop_t* const lp) {
|
|
1429
|
-
size_t i;
|
|
1430
|
-
char* p1;
|
|
1431
|
-
ssize_t s1;
|
|
1432
|
-
size_t* idx1;
|
|
1433
|
-
dtype* x;
|
|
1434
|
-
VALUE y;
|
|
1435
|
-
volatile VALUE a;
|
|
1436
|
-
VALUE fmt = lp->option;
|
|
1437
|
-
INIT_COUNTER(lp, i);
|
|
1438
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1439
|
-
a = rb_ary_new2(i);
|
|
1440
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1441
|
-
if (idx1) {
|
|
1442
|
-
for (; i--;) {
|
|
1443
|
-
x = (dtype*)(p1 + *idx1);
|
|
1444
|
-
idx1++;
|
|
1445
|
-
y = format_robject(fmt, x);
|
|
1446
|
-
rb_ary_push(a, y);
|
|
1447
|
-
}
|
|
1448
|
-
} else {
|
|
1449
|
-
for (; i--;) {
|
|
1450
|
-
x = (dtype*)p1;
|
|
1451
|
-
p1 += s1;
|
|
1452
|
-
y = format_robject(fmt, x);
|
|
1453
|
-
rb_ary_push(a, y);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
/*
|
|
1459
|
-
Format elements into strings.
|
|
1460
|
-
@overload format_to_a format
|
|
1461
|
-
@param [String] format
|
|
1462
|
-
@return [Array] array of formatted strings.
|
|
1463
|
-
*/
|
|
1464
|
-
static VALUE robject_format_to_a(int argc, VALUE* argv, VALUE self) {
|
|
1465
|
-
VALUE fmt = Qnil;
|
|
1466
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1467
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1468
|
-
ndfunc_t ndf = { iter_robject_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1469
|
-
|
|
1470
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1471
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
static VALUE iter_robject_inspect(char* ptr, size_t pos, VALUE fmt) {
|
|
1475
|
-
return rb_inspect(*(VALUE*)(ptr + pos));
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
/*
|
|
1479
|
-
Returns a string containing a human-readable representation of NArray.
|
|
1480
|
-
@overload inspect
|
|
1481
|
-
@return [String]
|
|
1482
|
-
*/
|
|
1483
|
-
static VALUE robject_inspect(VALUE ary) {
|
|
1484
|
-
return na_ndloop_inspect(ary, iter_robject_inspect, Qnil);
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
1367
|
static void iter_robject_each(na_loop_t* const lp) {
|
|
1488
1368
|
size_t i, s1;
|
|
1489
1369
|
char* p1;
|
|
@@ -1793,1983 +1673,101 @@ static VALUE robject_abs(VALUE self) {
|
|
|
1793
1673
|
return na_ndloop(&ndf, 1, self);
|
|
1794
1674
|
}
|
|
1795
1675
|
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
static void iter_robject_add(na_loop_t* const lp) {
|
|
1800
|
-
size_t i = 0;
|
|
1801
|
-
size_t n;
|
|
1802
|
-
char *p1, *p2, *p3;
|
|
1803
|
-
ssize_t s1, s2, s3;
|
|
1676
|
+
static void iter_robject_poly(na_loop_t* const lp) {
|
|
1677
|
+
size_t i;
|
|
1678
|
+
dtype x, y, a;
|
|
1804
1679
|
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
1813
|
-
check_intdivzero(*(dtype*)p2);
|
|
1814
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1815
|
-
if (p1 == p3) { // inplace case
|
|
1816
|
-
for (; i < n; i++) {
|
|
1817
|
-
((dtype*)p1)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1818
|
-
}
|
|
1819
|
-
} else {
|
|
1820
|
-
for (; i < n; i++) {
|
|
1821
|
-
((dtype*)p3)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
} else {
|
|
1825
|
-
for (i = 0; i < n; i++) {
|
|
1826
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1827
|
-
p1 += s1;
|
|
1828
|
-
p3 += s3;
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
} else {
|
|
1832
|
-
if (p1 == p3) { // inplace case
|
|
1833
|
-
for (i = 0; i < n; i++) {
|
|
1834
|
-
check_intdivzero(*(dtype*)p2);
|
|
1835
|
-
*(dtype*)p1 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1836
|
-
p1 += s1;
|
|
1837
|
-
p2 += s2;
|
|
1838
|
-
}
|
|
1839
|
-
} else {
|
|
1840
|
-
for (i = 0; i < n; i++) {
|
|
1841
|
-
check_intdivzero(*(dtype*)p2);
|
|
1842
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1843
|
-
p1 += s1;
|
|
1844
|
-
p2 += s2;
|
|
1845
|
-
p3 += s3;
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1680
|
+
x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
|
|
1681
|
+
i = lp->narg - 2;
|
|
1682
|
+
y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
1683
|
+
for (; --i;) {
|
|
1684
|
+
y = m_mul(x, y);
|
|
1685
|
+
a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
1686
|
+
y = m_add(y, a);
|
|
1848
1687
|
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
//
|
|
1852
|
-
}
|
|
1853
|
-
#undef check_intdivzero
|
|
1854
|
-
|
|
1855
|
-
static VALUE robject_add_self(VALUE self, VALUE other) {
|
|
1856
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1857
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1858
|
-
ndfunc_t ndf = { iter_robject_add, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1859
|
-
|
|
1860
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1688
|
+
i = lp->narg - 1;
|
|
1689
|
+
*(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
|
|
1861
1690
|
}
|
|
1862
1691
|
|
|
1863
1692
|
/*
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
@
|
|
1693
|
+
Calculate polynomial.
|
|
1694
|
+
`x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
1695
|
+
@overload poly a0, a1, ..., an
|
|
1696
|
+
@param [Numo::NArray,Numeric] a0,a1,...,an
|
|
1697
|
+
@return [Numo::RObject]
|
|
1868
1698
|
*/
|
|
1869
|
-
static VALUE
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
{}
|
|
1875
|
-
|
|
1876
|
-
static void iter_robject_sub(na_loop_t* const lp) {
|
|
1877
|
-
size_t i = 0;
|
|
1878
|
-
size_t n;
|
|
1879
|
-
char *p1, *p2, *p3;
|
|
1880
|
-
ssize_t s1, s2, s3;
|
|
1699
|
+
static VALUE robject_poly(VALUE self, VALUE args) {
|
|
1700
|
+
int argc, i;
|
|
1701
|
+
VALUE* argv;
|
|
1702
|
+
volatile VALUE v, a;
|
|
1703
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1704
|
+
ndfunc_t ndf = { iter_robject_poly, NO_LOOP, 0, 1, 0, aout };
|
|
1881
1705
|
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
//
|
|
1888
|
-
|
|
1889
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
1890
|
-
check_intdivzero(*(dtype*)p2);
|
|
1891
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1892
|
-
if (p1 == p3) { // inplace case
|
|
1893
|
-
for (; i < n; i++) {
|
|
1894
|
-
((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
1895
|
-
}
|
|
1896
|
-
} else {
|
|
1897
|
-
for (; i < n; i++) {
|
|
1898
|
-
((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
} else {
|
|
1902
|
-
for (i = 0; i < n; i++) {
|
|
1903
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1904
|
-
p1 += s1;
|
|
1905
|
-
p3 += s3;
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
} else {
|
|
1909
|
-
if (p1 == p3) { // inplace case
|
|
1910
|
-
for (i = 0; i < n; i++) {
|
|
1911
|
-
check_intdivzero(*(dtype*)p2);
|
|
1912
|
-
*(dtype*)p1 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1913
|
-
p1 += s1;
|
|
1914
|
-
p2 += s2;
|
|
1915
|
-
}
|
|
1916
|
-
} else {
|
|
1917
|
-
for (i = 0; i < n; i++) {
|
|
1918
|
-
check_intdivzero(*(dtype*)p2);
|
|
1919
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1920
|
-
p1 += s1;
|
|
1921
|
-
p2 += s2;
|
|
1922
|
-
p3 += s3;
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1706
|
+
argc = (int)RARRAY_LEN(args);
|
|
1707
|
+
ndf.nin = argc + 1;
|
|
1708
|
+
ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
|
|
1709
|
+
for (i = 0; i < argc + 1; i++) {
|
|
1710
|
+
ndf.ain[i].type = cT;
|
|
1925
1711
|
}
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1712
|
+
argv = ALLOCA_N(VALUE, argc + 1);
|
|
1713
|
+
argv[0] = self;
|
|
1714
|
+
for (i = 0; i < argc; i++) {
|
|
1715
|
+
argv[i + 1] = RARRAY_PTR(args)[i];
|
|
1716
|
+
}
|
|
1717
|
+
a = rb_ary_new4(argc + 1, argv);
|
|
1718
|
+
v = na_ndloop2(&ndf, a);
|
|
1719
|
+
return robject_extract(v);
|
|
1929
1720
|
}
|
|
1930
|
-
#undef check_intdivzero
|
|
1931
1721
|
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1935
|
-
ndfunc_t ndf = { iter_robject_sub, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1722
|
+
void Init_numo_robject(void) {
|
|
1723
|
+
VALUE hCast, mNumo;
|
|
1936
1724
|
|
|
1937
|
-
|
|
1938
|
-
}
|
|
1725
|
+
mNumo = rb_define_module("Numo");
|
|
1939
1726
|
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1727
|
+
id_ne = rb_intern("!=");
|
|
1728
|
+
id_pow = rb_intern("**");
|
|
1729
|
+
id_minus = rb_intern("-@");
|
|
1730
|
+
id_lt = rb_intern("<");
|
|
1731
|
+
id_left_shift = rb_intern("<<");
|
|
1732
|
+
id_le = rb_intern("<=");
|
|
1733
|
+
id_ufo = rb_intern("<=>");
|
|
1734
|
+
id_eq = rb_intern("==");
|
|
1735
|
+
id_gt = rb_intern(">");
|
|
1736
|
+
id_ge = rb_intern(">=");
|
|
1737
|
+
id_right_shift = rb_intern(">>");
|
|
1738
|
+
id_abs = rb_intern("abs");
|
|
1739
|
+
id_bit_and = rb_intern("bit_and");
|
|
1740
|
+
id_bit_not = rb_intern("bit_not");
|
|
1741
|
+
id_bit_or = rb_intern("bit_or");
|
|
1742
|
+
id_bit_xor = rb_intern("bit_xor");
|
|
1743
|
+
id_cast = rb_intern("cast");
|
|
1744
|
+
id_ceil = rb_intern("ceil");
|
|
1745
|
+
id_copysign = rb_intern("copysign");
|
|
1746
|
+
id_divmod = rb_intern("divmod");
|
|
1747
|
+
id_finite_p = rb_intern("finite?");
|
|
1748
|
+
id_floor = rb_intern("floor");
|
|
1749
|
+
id_infinite_p = rb_intern("infinite?");
|
|
1750
|
+
id_mulsum = rb_intern("mulsum");
|
|
1751
|
+
id_nan = rb_intern("nan");
|
|
1752
|
+
id_nan_p = rb_intern("nan?");
|
|
1753
|
+
id_nearly_eq = rb_intern("nearly_eq");
|
|
1754
|
+
id_reciprocal = rb_intern("reciprocal");
|
|
1755
|
+
id_round = rb_intern("round");
|
|
1756
|
+
id_square = rb_intern("square");
|
|
1757
|
+
id_to_a = rb_intern("to_a");
|
|
1758
|
+
id_truncate = rb_intern("truncate");
|
|
1949
1759
|
|
|
1950
|
-
|
|
1951
|
-
|
|
1760
|
+
/**
|
|
1761
|
+
* Document-class: Numo::RObject
|
|
1762
|
+
*
|
|
1763
|
+
* Ruby object N-dimensional array class.
|
|
1764
|
+
*/
|
|
1765
|
+
cT = rb_define_class_under(mNumo, "RObject", cNArray);
|
|
1952
1766
|
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
ssize_t s1, s2, s3;
|
|
1958
|
-
|
|
1959
|
-
INIT_COUNTER(lp, n);
|
|
1960
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
1961
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1962
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1963
|
-
|
|
1964
|
-
//
|
|
1965
|
-
|
|
1966
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
1967
|
-
check_intdivzero(*(dtype*)p2);
|
|
1968
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1969
|
-
if (p1 == p3) { // inplace case
|
|
1970
|
-
for (; i < n; i++) {
|
|
1971
|
-
((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
1972
|
-
}
|
|
1973
|
-
} else {
|
|
1974
|
-
for (; i < n; i++) {
|
|
1975
|
-
((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
} else {
|
|
1979
|
-
for (i = 0; i < n; i++) {
|
|
1980
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1981
|
-
p1 += s1;
|
|
1982
|
-
p3 += s3;
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
} else {
|
|
1986
|
-
if (p1 == p3) { // inplace case
|
|
1987
|
-
for (i = 0; i < n; i++) {
|
|
1988
|
-
check_intdivzero(*(dtype*)p2);
|
|
1989
|
-
*(dtype*)p1 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1990
|
-
p1 += s1;
|
|
1991
|
-
p2 += s2;
|
|
1992
|
-
}
|
|
1993
|
-
} else {
|
|
1994
|
-
for (i = 0; i < n; i++) {
|
|
1995
|
-
check_intdivzero(*(dtype*)p2);
|
|
1996
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1997
|
-
p1 += s1;
|
|
1998
|
-
p2 += s2;
|
|
1999
|
-
p3 += s3;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
|
|
2004
|
-
return;
|
|
2005
|
-
//
|
|
2006
|
-
}
|
|
2007
|
-
#undef check_intdivzero
|
|
2008
|
-
|
|
2009
|
-
static VALUE robject_mul_self(VALUE self, VALUE other) {
|
|
2010
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2011
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2012
|
-
ndfunc_t ndf = { iter_robject_mul, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2013
|
-
|
|
2014
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
|
-
/*
|
|
2018
|
-
Binary mul.
|
|
2019
|
-
@overload * other
|
|
2020
|
-
@param [Numo::NArray,Numeric] other
|
|
2021
|
-
@return [Numo::NArray] self * other
|
|
2022
|
-
*/
|
|
2023
|
-
static VALUE robject_mul(VALUE self, VALUE other) {
|
|
2024
|
-
return robject_mul_self(self, other);
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
#define check_intdivzero(y) \
|
|
2028
|
-
if ((y) == 0) { \
|
|
2029
|
-
lp->err_type = rb_eZeroDivError; \
|
|
2030
|
-
return; \
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
static void iter_robject_div(na_loop_t* const lp) {
|
|
2034
|
-
size_t i = 0;
|
|
2035
|
-
size_t n;
|
|
2036
|
-
char *p1, *p2, *p3;
|
|
2037
|
-
ssize_t s1, s2, s3;
|
|
2038
|
-
|
|
2039
|
-
INIT_COUNTER(lp, n);
|
|
2040
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2041
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2042
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2043
|
-
|
|
2044
|
-
//
|
|
2045
|
-
|
|
2046
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2047
|
-
check_intdivzero(*(dtype*)p2);
|
|
2048
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2049
|
-
if (p1 == p3) { // inplace case
|
|
2050
|
-
for (; i < n; i++) {
|
|
2051
|
-
((dtype*)p1)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2052
|
-
}
|
|
2053
|
-
} else {
|
|
2054
|
-
for (; i < n; i++) {
|
|
2055
|
-
((dtype*)p3)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
} else {
|
|
2059
|
-
for (i = 0; i < n; i++) {
|
|
2060
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2061
|
-
p1 += s1;
|
|
2062
|
-
p3 += s3;
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
} else {
|
|
2066
|
-
if (p1 == p3) { // inplace case
|
|
2067
|
-
for (i = 0; i < n; i++) {
|
|
2068
|
-
check_intdivzero(*(dtype*)p2);
|
|
2069
|
-
*(dtype*)p1 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2070
|
-
p1 += s1;
|
|
2071
|
-
p2 += s2;
|
|
2072
|
-
}
|
|
2073
|
-
} else {
|
|
2074
|
-
for (i = 0; i < n; i++) {
|
|
2075
|
-
check_intdivzero(*(dtype*)p2);
|
|
2076
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2077
|
-
p1 += s1;
|
|
2078
|
-
p2 += s2;
|
|
2079
|
-
p3 += s3;
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
return;
|
|
2085
|
-
//
|
|
2086
|
-
}
|
|
2087
|
-
#undef check_intdivzero
|
|
2088
|
-
|
|
2089
|
-
static VALUE robject_div_self(VALUE self, VALUE other) {
|
|
2090
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2091
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2092
|
-
ndfunc_t ndf = { iter_robject_div, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2093
|
-
|
|
2094
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2095
|
-
}
|
|
2096
|
-
|
|
2097
|
-
/*
|
|
2098
|
-
Binary div.
|
|
2099
|
-
@overload / other
|
|
2100
|
-
@param [Numo::NArray,Numeric] other
|
|
2101
|
-
@return [Numo::NArray] self / other
|
|
2102
|
-
*/
|
|
2103
|
-
static VALUE robject_div(VALUE self, VALUE other) {
|
|
2104
|
-
return robject_div_self(self, other);
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
|
-
#define check_intdivzero(y) \
|
|
2108
|
-
if ((y) == 0) { \
|
|
2109
|
-
lp->err_type = rb_eZeroDivError; \
|
|
2110
|
-
return; \
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
static void iter_robject_mod(na_loop_t* const lp) {
|
|
2114
|
-
size_t i = 0;
|
|
2115
|
-
size_t n;
|
|
2116
|
-
char *p1, *p2, *p3;
|
|
2117
|
-
ssize_t s1, s2, s3;
|
|
2118
|
-
|
|
2119
|
-
INIT_COUNTER(lp, n);
|
|
2120
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2121
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2122
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2123
|
-
|
|
2124
|
-
//
|
|
2125
|
-
|
|
2126
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2127
|
-
check_intdivzero(*(dtype*)p2);
|
|
2128
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2129
|
-
if (p1 == p3) { // inplace case
|
|
2130
|
-
for (; i < n; i++) {
|
|
2131
|
-
((dtype*)p1)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2132
|
-
}
|
|
2133
|
-
} else {
|
|
2134
|
-
for (; i < n; i++) {
|
|
2135
|
-
((dtype*)p3)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2136
|
-
}
|
|
2137
|
-
}
|
|
2138
|
-
} else {
|
|
2139
|
-
for (i = 0; i < n; i++) {
|
|
2140
|
-
*(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2141
|
-
p1 += s1;
|
|
2142
|
-
p3 += s3;
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
|
-
} else {
|
|
2146
|
-
if (p1 == p3) { // inplace case
|
|
2147
|
-
for (i = 0; i < n; i++) {
|
|
2148
|
-
check_intdivzero(*(dtype*)p2);
|
|
2149
|
-
*(dtype*)p1 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2150
|
-
p1 += s1;
|
|
2151
|
-
p2 += s2;
|
|
2152
|
-
}
|
|
2153
|
-
} else {
|
|
2154
|
-
for (i = 0; i < n; i++) {
|
|
2155
|
-
check_intdivzero(*(dtype*)p2);
|
|
2156
|
-
*(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2157
|
-
p1 += s1;
|
|
2158
|
-
p2 += s2;
|
|
2159
|
-
p3 += s3;
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
|
|
2164
|
-
return;
|
|
2165
|
-
//
|
|
2166
|
-
}
|
|
2167
|
-
#undef check_intdivzero
|
|
2168
|
-
|
|
2169
|
-
static VALUE robject_mod_self(VALUE self, VALUE other) {
|
|
2170
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2171
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2172
|
-
ndfunc_t ndf = { iter_robject_mod, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2173
|
-
|
|
2174
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
/*
|
|
2178
|
-
Binary mod.
|
|
2179
|
-
@overload % other
|
|
2180
|
-
@param [Numo::NArray,Numeric] other
|
|
2181
|
-
@return [Numo::NArray] self % other
|
|
2182
|
-
*/
|
|
2183
|
-
static VALUE robject_mod(VALUE self, VALUE other) {
|
|
2184
|
-
return robject_mod_self(self, other);
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
static void iter_robject_divmod(na_loop_t* const lp) {
|
|
2188
|
-
size_t i, n;
|
|
2189
|
-
char *p1, *p2, *p3, *p4;
|
|
2190
|
-
ssize_t s1, s2, s3, s4;
|
|
2191
|
-
dtype x, y, a, b;
|
|
2192
|
-
INIT_COUNTER(lp, n);
|
|
2193
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2194
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2195
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2196
|
-
INIT_PTR(lp, 3, p4, s4);
|
|
2197
|
-
for (i = n; i--;) {
|
|
2198
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2199
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2200
|
-
if (y == 0) {
|
|
2201
|
-
lp->err_type = rb_eZeroDivError;
|
|
2202
|
-
return;
|
|
2203
|
-
}
|
|
2204
|
-
m_divmod(x, y, a, b);
|
|
2205
|
-
SET_DATA_STRIDE(p3, s3, dtype, a);
|
|
2206
|
-
SET_DATA_STRIDE(p4, s4, dtype, b);
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
static VALUE robject_divmod_self(VALUE self, VALUE other) {
|
|
2211
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2212
|
-
ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
|
|
2213
|
-
ndfunc_t ndf = { iter_robject_divmod, STRIDE_LOOP, 2, 2, ain, aout };
|
|
2214
|
-
|
|
2215
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2216
|
-
}
|
|
2217
|
-
|
|
2218
|
-
/*
|
|
2219
|
-
Binary divmod.
|
|
2220
|
-
@overload divmod other
|
|
2221
|
-
@param [Numo::NArray,Numeric] other
|
|
2222
|
-
@return [Numo::NArray] divmod of self and other.
|
|
2223
|
-
*/
|
|
2224
|
-
static VALUE robject_divmod(VALUE self, VALUE other) {
|
|
2225
|
-
return robject_divmod_self(self, other);
|
|
2226
|
-
}
|
|
2227
|
-
|
|
2228
|
-
static void iter_robject_pow(na_loop_t* const lp) {
|
|
2229
|
-
size_t i;
|
|
2230
|
-
char *p1, *p2, *p3;
|
|
2231
|
-
ssize_t s1, s2, s3;
|
|
2232
|
-
dtype x, y;
|
|
2233
|
-
INIT_COUNTER(lp, i);
|
|
2234
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2235
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2236
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2237
|
-
for (; i--;) {
|
|
2238
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2239
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2240
|
-
x = m_pow(x, y);
|
|
2241
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2242
|
-
}
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2245
|
-
static void iter_robject_pow_int32(na_loop_t* const lp) {
|
|
2246
|
-
size_t i;
|
|
2247
|
-
char *p1, *p2, *p3;
|
|
2248
|
-
ssize_t s1, s2, s3;
|
|
2249
|
-
dtype x;
|
|
2250
|
-
int32_t y;
|
|
2251
|
-
INIT_COUNTER(lp, i);
|
|
2252
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2253
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2254
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2255
|
-
for (; i--;) {
|
|
2256
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2257
|
-
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
2258
|
-
x = m_pow_int(x, y);
|
|
2259
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
|
|
2263
|
-
static VALUE robject_pow_self(VALUE self, VALUE other) {
|
|
2264
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2265
|
-
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
2266
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2267
|
-
ndfunc_t ndf = { iter_robject_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2268
|
-
ndfunc_t ndf_i = { iter_robject_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
2269
|
-
|
|
2270
|
-
// fixme : use na.integer?
|
|
2271
|
-
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
2272
|
-
return na_ndloop(&ndf_i, 2, self, other);
|
|
2273
|
-
} else {
|
|
2274
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
/*
|
|
2279
|
-
Binary power.
|
|
2280
|
-
@overload ** other
|
|
2281
|
-
@param [Numo::NArray,Numeric] other
|
|
2282
|
-
@return [Numo::NArray] self to the other-th power.
|
|
2283
|
-
*/
|
|
2284
|
-
static VALUE robject_pow(VALUE self, VALUE other) {
|
|
2285
|
-
return robject_pow_self(self, other);
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2288
|
-
static void iter_robject_minus(na_loop_t* const lp) {
|
|
2289
|
-
size_t i, n;
|
|
2290
|
-
char *p1, *p2;
|
|
2291
|
-
ssize_t s1, s2;
|
|
2292
|
-
size_t *idx1, *idx2;
|
|
2293
|
-
dtype x;
|
|
2294
|
-
|
|
2295
|
-
INIT_COUNTER(lp, n);
|
|
2296
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2297
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2298
|
-
|
|
2299
|
-
if (idx1) {
|
|
2300
|
-
if (idx2) {
|
|
2301
|
-
for (i = 0; i < n; i++) {
|
|
2302
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2303
|
-
x = m_minus(x);
|
|
2304
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2305
|
-
}
|
|
2306
|
-
} else {
|
|
2307
|
-
for (i = 0; i < n; i++) {
|
|
2308
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2309
|
-
x = m_minus(x);
|
|
2310
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
} else {
|
|
2314
|
-
if (idx2) {
|
|
2315
|
-
for (i = 0; i < n; i++) {
|
|
2316
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2317
|
-
x = m_minus(x);
|
|
2318
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2319
|
-
}
|
|
2320
|
-
} else {
|
|
2321
|
-
//
|
|
2322
|
-
for (i = 0; i < n; i++) {
|
|
2323
|
-
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
2324
|
-
p1 += s1;
|
|
2325
|
-
p2 += s2;
|
|
2326
|
-
}
|
|
2327
|
-
return;
|
|
2328
|
-
//
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
|
|
2333
|
-
/*
|
|
2334
|
-
Unary minus.
|
|
2335
|
-
@overload -@
|
|
2336
|
-
@return [Numo::RObject] minus of self.
|
|
2337
|
-
*/
|
|
2338
|
-
static VALUE robject_minus(VALUE self) {
|
|
2339
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2340
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2341
|
-
ndfunc_t ndf = { iter_robject_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
2342
|
-
|
|
2343
|
-
return na_ndloop(&ndf, 1, self);
|
|
2344
|
-
}
|
|
2345
|
-
|
|
2346
|
-
static void iter_robject_reciprocal(na_loop_t* const lp) {
|
|
2347
|
-
size_t i, n;
|
|
2348
|
-
char *p1, *p2;
|
|
2349
|
-
ssize_t s1, s2;
|
|
2350
|
-
size_t *idx1, *idx2;
|
|
2351
|
-
dtype x;
|
|
2352
|
-
|
|
2353
|
-
INIT_COUNTER(lp, n);
|
|
2354
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2355
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2356
|
-
|
|
2357
|
-
if (idx1) {
|
|
2358
|
-
if (idx2) {
|
|
2359
|
-
for (i = 0; i < n; i++) {
|
|
2360
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2361
|
-
x = m_reciprocal(x);
|
|
2362
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2363
|
-
}
|
|
2364
|
-
} else {
|
|
2365
|
-
for (i = 0; i < n; i++) {
|
|
2366
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2367
|
-
x = m_reciprocal(x);
|
|
2368
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
} else {
|
|
2372
|
-
if (idx2) {
|
|
2373
|
-
for (i = 0; i < n; i++) {
|
|
2374
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2375
|
-
x = m_reciprocal(x);
|
|
2376
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2377
|
-
}
|
|
2378
|
-
} else {
|
|
2379
|
-
//
|
|
2380
|
-
for (i = 0; i < n; i++) {
|
|
2381
|
-
*(dtype*)p2 = m_reciprocal(*(dtype*)p1);
|
|
2382
|
-
p1 += s1;
|
|
2383
|
-
p2 += s2;
|
|
2384
|
-
}
|
|
2385
|
-
return;
|
|
2386
|
-
//
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
}
|
|
2390
|
-
|
|
2391
|
-
/*
|
|
2392
|
-
Unary reciprocal.
|
|
2393
|
-
@overload reciprocal
|
|
2394
|
-
@return [Numo::RObject] reciprocal of self.
|
|
2395
|
-
*/
|
|
2396
|
-
static VALUE robject_reciprocal(VALUE self) {
|
|
2397
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2398
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2399
|
-
ndfunc_t ndf = { iter_robject_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
2400
|
-
|
|
2401
|
-
return na_ndloop(&ndf, 1, self);
|
|
2402
|
-
}
|
|
2403
|
-
|
|
2404
|
-
static void iter_robject_sign(na_loop_t* const lp) {
|
|
2405
|
-
size_t i, n;
|
|
2406
|
-
char *p1, *p2;
|
|
2407
|
-
ssize_t s1, s2;
|
|
2408
|
-
size_t *idx1, *idx2;
|
|
2409
|
-
dtype x;
|
|
2410
|
-
|
|
2411
|
-
INIT_COUNTER(lp, n);
|
|
2412
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2413
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2414
|
-
|
|
2415
|
-
if (idx1) {
|
|
2416
|
-
if (idx2) {
|
|
2417
|
-
for (i = 0; i < n; i++) {
|
|
2418
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2419
|
-
x = m_sign(x);
|
|
2420
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2421
|
-
}
|
|
2422
|
-
} else {
|
|
2423
|
-
for (i = 0; i < n; i++) {
|
|
2424
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2425
|
-
x = m_sign(x);
|
|
2426
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
} else {
|
|
2430
|
-
if (idx2) {
|
|
2431
|
-
for (i = 0; i < n; i++) {
|
|
2432
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2433
|
-
x = m_sign(x);
|
|
2434
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2435
|
-
}
|
|
2436
|
-
} else {
|
|
2437
|
-
//
|
|
2438
|
-
for (i = 0; i < n; i++) {
|
|
2439
|
-
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
2440
|
-
p1 += s1;
|
|
2441
|
-
p2 += s2;
|
|
2442
|
-
}
|
|
2443
|
-
return;
|
|
2444
|
-
//
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
}
|
|
2448
|
-
|
|
2449
|
-
/*
|
|
2450
|
-
Unary sign.
|
|
2451
|
-
@overload sign
|
|
2452
|
-
@return [Numo::RObject] sign of self.
|
|
2453
|
-
*/
|
|
2454
|
-
static VALUE robject_sign(VALUE self) {
|
|
2455
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2456
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2457
|
-
ndfunc_t ndf = { iter_robject_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
2458
|
-
|
|
2459
|
-
return na_ndloop(&ndf, 1, self);
|
|
2460
|
-
}
|
|
2461
|
-
|
|
2462
|
-
static void iter_robject_square(na_loop_t* const lp) {
|
|
2463
|
-
size_t i, n;
|
|
2464
|
-
char *p1, *p2;
|
|
2465
|
-
ssize_t s1, s2;
|
|
2466
|
-
size_t *idx1, *idx2;
|
|
2467
|
-
dtype x;
|
|
2468
|
-
|
|
2469
|
-
INIT_COUNTER(lp, n);
|
|
2470
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2471
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2472
|
-
|
|
2473
|
-
if (idx1) {
|
|
2474
|
-
if (idx2) {
|
|
2475
|
-
for (i = 0; i < n; i++) {
|
|
2476
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2477
|
-
x = m_square(x);
|
|
2478
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2479
|
-
}
|
|
2480
|
-
} else {
|
|
2481
|
-
for (i = 0; i < n; i++) {
|
|
2482
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2483
|
-
x = m_square(x);
|
|
2484
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
} else {
|
|
2488
|
-
if (idx2) {
|
|
2489
|
-
for (i = 0; i < n; i++) {
|
|
2490
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2491
|
-
x = m_square(x);
|
|
2492
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2493
|
-
}
|
|
2494
|
-
} else {
|
|
2495
|
-
//
|
|
2496
|
-
for (i = 0; i < n; i++) {
|
|
2497
|
-
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
2498
|
-
p1 += s1;
|
|
2499
|
-
p2 += s2;
|
|
2500
|
-
}
|
|
2501
|
-
return;
|
|
2502
|
-
//
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
|
-
/*
|
|
2508
|
-
Unary square.
|
|
2509
|
-
@overload square
|
|
2510
|
-
@return [Numo::RObject] square of self.
|
|
2511
|
-
*/
|
|
2512
|
-
static VALUE robject_square(VALUE self) {
|
|
2513
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2514
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2515
|
-
ndfunc_t ndf = { iter_robject_square, FULL_LOOP, 1, 1, ain, aout };
|
|
2516
|
-
|
|
2517
|
-
return na_ndloop(&ndf, 1, self);
|
|
2518
|
-
}
|
|
2519
|
-
|
|
2520
|
-
static void iter_robject_eq(na_loop_t* const lp) {
|
|
2521
|
-
size_t i;
|
|
2522
|
-
char *p1, *p2;
|
|
2523
|
-
BIT_DIGIT* a3;
|
|
2524
|
-
size_t p3;
|
|
2525
|
-
ssize_t s1, s2, s3;
|
|
2526
|
-
dtype x, y;
|
|
2527
|
-
BIT_DIGIT b;
|
|
2528
|
-
INIT_COUNTER(lp, i);
|
|
2529
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2530
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2531
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2532
|
-
for (; i--;) {
|
|
2533
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2534
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2535
|
-
b = (m_eq(x, y)) ? 1 : 0;
|
|
2536
|
-
STORE_BIT(a3, p3, b);
|
|
2537
|
-
p3 += s3;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
|
|
2541
|
-
static VALUE robject_eq_self(VALUE self, VALUE other) {
|
|
2542
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2543
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2544
|
-
ndfunc_t ndf = { iter_robject_eq, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2545
|
-
|
|
2546
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
/*
|
|
2550
|
-
Comparison eq other.
|
|
2551
|
-
@overload eq other
|
|
2552
|
-
@param [Numo::NArray,Numeric] other
|
|
2553
|
-
@return [Numo::Bit] result of self eq other.
|
|
2554
|
-
*/
|
|
2555
|
-
static VALUE robject_eq(VALUE self, VALUE other) {
|
|
2556
|
-
return robject_eq_self(self, other);
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
static void iter_robject_ne(na_loop_t* const lp) {
|
|
2560
|
-
size_t i;
|
|
2561
|
-
char *p1, *p2;
|
|
2562
|
-
BIT_DIGIT* a3;
|
|
2563
|
-
size_t p3;
|
|
2564
|
-
ssize_t s1, s2, s3;
|
|
2565
|
-
dtype x, y;
|
|
2566
|
-
BIT_DIGIT b;
|
|
2567
|
-
INIT_COUNTER(lp, i);
|
|
2568
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2569
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2570
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2571
|
-
for (; i--;) {
|
|
2572
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2573
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2574
|
-
b = (m_ne(x, y)) ? 1 : 0;
|
|
2575
|
-
STORE_BIT(a3, p3, b);
|
|
2576
|
-
p3 += s3;
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
|
|
2580
|
-
static VALUE robject_ne_self(VALUE self, VALUE other) {
|
|
2581
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2582
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2583
|
-
ndfunc_t ndf = { iter_robject_ne, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2584
|
-
|
|
2585
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2586
|
-
}
|
|
2587
|
-
|
|
2588
|
-
/*
|
|
2589
|
-
Comparison ne other.
|
|
2590
|
-
@overload ne other
|
|
2591
|
-
@param [Numo::NArray,Numeric] other
|
|
2592
|
-
@return [Numo::Bit] result of self ne other.
|
|
2593
|
-
*/
|
|
2594
|
-
static VALUE robject_ne(VALUE self, VALUE other) {
|
|
2595
|
-
return robject_ne_self(self, other);
|
|
2596
|
-
}
|
|
2597
|
-
|
|
2598
|
-
static void iter_robject_nearly_eq(na_loop_t* const lp) {
|
|
2599
|
-
size_t i;
|
|
2600
|
-
char *p1, *p2;
|
|
2601
|
-
BIT_DIGIT* a3;
|
|
2602
|
-
size_t p3;
|
|
2603
|
-
ssize_t s1, s2, s3;
|
|
2604
|
-
dtype x, y;
|
|
2605
|
-
BIT_DIGIT b;
|
|
2606
|
-
INIT_COUNTER(lp, i);
|
|
2607
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2608
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2609
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2610
|
-
for (; i--;) {
|
|
2611
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2612
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2613
|
-
b = (m_nearly_eq(x, y)) ? 1 : 0;
|
|
2614
|
-
STORE_BIT(a3, p3, b);
|
|
2615
|
-
p3 += s3;
|
|
2616
|
-
}
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
|
-
static VALUE robject_nearly_eq_self(VALUE self, VALUE other) {
|
|
2620
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2621
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2622
|
-
ndfunc_t ndf = { iter_robject_nearly_eq, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2623
|
-
|
|
2624
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2625
|
-
}
|
|
2626
|
-
|
|
2627
|
-
/*
|
|
2628
|
-
Comparison nearly_eq other.
|
|
2629
|
-
@overload nearly_eq other
|
|
2630
|
-
@param [Numo::NArray,Numeric] other
|
|
2631
|
-
@return [Numo::Bit] result of self nearly_eq other.
|
|
2632
|
-
*/
|
|
2633
|
-
static VALUE robject_nearly_eq(VALUE self, VALUE other) {
|
|
2634
|
-
return robject_nearly_eq_self(self, other);
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
|
-
#define check_intdivzero(y) \
|
|
2638
|
-
{}
|
|
2639
|
-
|
|
2640
|
-
static void iter_robject_bit_and(na_loop_t* const lp) {
|
|
2641
|
-
size_t i = 0;
|
|
2642
|
-
size_t n;
|
|
2643
|
-
char *p1, *p2, *p3;
|
|
2644
|
-
ssize_t s1, s2, s3;
|
|
2645
|
-
|
|
2646
|
-
INIT_COUNTER(lp, n);
|
|
2647
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2648
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2649
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2650
|
-
|
|
2651
|
-
//
|
|
2652
|
-
|
|
2653
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2654
|
-
check_intdivzero(*(dtype*)p2);
|
|
2655
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2656
|
-
if (p1 == p3) { // inplace case
|
|
2657
|
-
for (; i < n; i++) {
|
|
2658
|
-
((dtype*)p1)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2659
|
-
}
|
|
2660
|
-
} else {
|
|
2661
|
-
for (; i < n; i++) {
|
|
2662
|
-
((dtype*)p3)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
} else {
|
|
2666
|
-
for (i = 0; i < n; i++) {
|
|
2667
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2668
|
-
p1 += s1;
|
|
2669
|
-
p3 += s3;
|
|
2670
|
-
}
|
|
2671
|
-
}
|
|
2672
|
-
} else {
|
|
2673
|
-
if (p1 == p3) { // inplace case
|
|
2674
|
-
for (i = 0; i < n; i++) {
|
|
2675
|
-
check_intdivzero(*(dtype*)p2);
|
|
2676
|
-
*(dtype*)p1 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2677
|
-
p1 += s1;
|
|
2678
|
-
p2 += s2;
|
|
2679
|
-
}
|
|
2680
|
-
} else {
|
|
2681
|
-
for (i = 0; i < n; i++) {
|
|
2682
|
-
check_intdivzero(*(dtype*)p2);
|
|
2683
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2684
|
-
p1 += s1;
|
|
2685
|
-
p2 += s2;
|
|
2686
|
-
p3 += s3;
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
|
-
return;
|
|
2692
|
-
//
|
|
2693
|
-
}
|
|
2694
|
-
#undef check_intdivzero
|
|
2695
|
-
|
|
2696
|
-
static VALUE robject_bit_and_self(VALUE self, VALUE other) {
|
|
2697
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2698
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2699
|
-
ndfunc_t ndf = { iter_robject_bit_and, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2700
|
-
|
|
2701
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2702
|
-
}
|
|
2703
|
-
|
|
2704
|
-
/*
|
|
2705
|
-
Binary bit_and.
|
|
2706
|
-
@overload & other
|
|
2707
|
-
@param [Numo::NArray,Numeric] other
|
|
2708
|
-
@return [Numo::NArray] self & other
|
|
2709
|
-
*/
|
|
2710
|
-
static VALUE robject_bit_and(VALUE self, VALUE other) {
|
|
2711
|
-
return robject_bit_and_self(self, other);
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
#define check_intdivzero(y) \
|
|
2715
|
-
{}
|
|
2716
|
-
|
|
2717
|
-
static void iter_robject_bit_or(na_loop_t* const lp) {
|
|
2718
|
-
size_t i = 0;
|
|
2719
|
-
size_t n;
|
|
2720
|
-
char *p1, *p2, *p3;
|
|
2721
|
-
ssize_t s1, s2, s3;
|
|
2722
|
-
|
|
2723
|
-
INIT_COUNTER(lp, n);
|
|
2724
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2725
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2726
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2727
|
-
|
|
2728
|
-
//
|
|
2729
|
-
|
|
2730
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2731
|
-
check_intdivzero(*(dtype*)p2);
|
|
2732
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2733
|
-
if (p1 == p3) { // inplace case
|
|
2734
|
-
for (; i < n; i++) {
|
|
2735
|
-
((dtype*)p1)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
2736
|
-
}
|
|
2737
|
-
} else {
|
|
2738
|
-
for (; i < n; i++) {
|
|
2739
|
-
((dtype*)p3)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
} else {
|
|
2743
|
-
for (i = 0; i < n; i++) {
|
|
2744
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2745
|
-
p1 += s1;
|
|
2746
|
-
p3 += s3;
|
|
2747
|
-
}
|
|
2748
|
-
}
|
|
2749
|
-
} else {
|
|
2750
|
-
if (p1 == p3) { // inplace case
|
|
2751
|
-
for (i = 0; i < n; i++) {
|
|
2752
|
-
check_intdivzero(*(dtype*)p2);
|
|
2753
|
-
*(dtype*)p1 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2754
|
-
p1 += s1;
|
|
2755
|
-
p2 += s2;
|
|
2756
|
-
}
|
|
2757
|
-
} else {
|
|
2758
|
-
for (i = 0; i < n; i++) {
|
|
2759
|
-
check_intdivzero(*(dtype*)p2);
|
|
2760
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2761
|
-
p1 += s1;
|
|
2762
|
-
p2 += s2;
|
|
2763
|
-
p3 += s3;
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
}
|
|
2767
|
-
|
|
2768
|
-
return;
|
|
2769
|
-
//
|
|
2770
|
-
}
|
|
2771
|
-
#undef check_intdivzero
|
|
2772
|
-
|
|
2773
|
-
static VALUE robject_bit_or_self(VALUE self, VALUE other) {
|
|
2774
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2775
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2776
|
-
ndfunc_t ndf = { iter_robject_bit_or, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2777
|
-
|
|
2778
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
/*
|
|
2782
|
-
Binary bit_or.
|
|
2783
|
-
@overload | other
|
|
2784
|
-
@param [Numo::NArray,Numeric] other
|
|
2785
|
-
@return [Numo::NArray] self | other
|
|
2786
|
-
*/
|
|
2787
|
-
static VALUE robject_bit_or(VALUE self, VALUE other) {
|
|
2788
|
-
return robject_bit_or_self(self, other);
|
|
2789
|
-
}
|
|
2790
|
-
|
|
2791
|
-
#define check_intdivzero(y) \
|
|
2792
|
-
{}
|
|
2793
|
-
|
|
2794
|
-
static void iter_robject_bit_xor(na_loop_t* const lp) {
|
|
2795
|
-
size_t i = 0;
|
|
2796
|
-
size_t n;
|
|
2797
|
-
char *p1, *p2, *p3;
|
|
2798
|
-
ssize_t s1, s2, s3;
|
|
2799
|
-
|
|
2800
|
-
INIT_COUNTER(lp, n);
|
|
2801
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2802
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2803
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2804
|
-
|
|
2805
|
-
//
|
|
2806
|
-
|
|
2807
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2808
|
-
check_intdivzero(*(dtype*)p2);
|
|
2809
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2810
|
-
if (p1 == p3) { // inplace case
|
|
2811
|
-
for (; i < n; i++) {
|
|
2812
|
-
((dtype*)p1)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
2813
|
-
}
|
|
2814
|
-
} else {
|
|
2815
|
-
for (; i < n; i++) {
|
|
2816
|
-
((dtype*)p3)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
} else {
|
|
2820
|
-
for (i = 0; i < n; i++) {
|
|
2821
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2822
|
-
p1 += s1;
|
|
2823
|
-
p3 += s3;
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
} else {
|
|
2827
|
-
if (p1 == p3) { // inplace case
|
|
2828
|
-
for (i = 0; i < n; i++) {
|
|
2829
|
-
check_intdivzero(*(dtype*)p2);
|
|
2830
|
-
*(dtype*)p1 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2831
|
-
p1 += s1;
|
|
2832
|
-
p2 += s2;
|
|
2833
|
-
}
|
|
2834
|
-
} else {
|
|
2835
|
-
for (i = 0; i < n; i++) {
|
|
2836
|
-
check_intdivzero(*(dtype*)p2);
|
|
2837
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2838
|
-
p1 += s1;
|
|
2839
|
-
p2 += s2;
|
|
2840
|
-
p3 += s3;
|
|
2841
|
-
}
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
|
|
2845
|
-
return;
|
|
2846
|
-
//
|
|
2847
|
-
}
|
|
2848
|
-
#undef check_intdivzero
|
|
2849
|
-
|
|
2850
|
-
static VALUE robject_bit_xor_self(VALUE self, VALUE other) {
|
|
2851
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2852
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2853
|
-
ndfunc_t ndf = { iter_robject_bit_xor, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2854
|
-
|
|
2855
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2856
|
-
}
|
|
2857
|
-
|
|
2858
|
-
/*
|
|
2859
|
-
Binary bit_xor.
|
|
2860
|
-
@overload ^ other
|
|
2861
|
-
@param [Numo::NArray,Numeric] other
|
|
2862
|
-
@return [Numo::NArray] self ^ other
|
|
2863
|
-
*/
|
|
2864
|
-
static VALUE robject_bit_xor(VALUE self, VALUE other) {
|
|
2865
|
-
return robject_bit_xor_self(self, other);
|
|
2866
|
-
}
|
|
2867
|
-
|
|
2868
|
-
static void iter_robject_bit_not(na_loop_t* const lp) {
|
|
2869
|
-
size_t i, n;
|
|
2870
|
-
char *p1, *p2;
|
|
2871
|
-
ssize_t s1, s2;
|
|
2872
|
-
size_t *idx1, *idx2;
|
|
2873
|
-
dtype x;
|
|
2874
|
-
|
|
2875
|
-
INIT_COUNTER(lp, n);
|
|
2876
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2877
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2878
|
-
|
|
2879
|
-
if (idx1) {
|
|
2880
|
-
if (idx2) {
|
|
2881
|
-
for (i = 0; i < n; i++) {
|
|
2882
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2883
|
-
x = m_bit_not(x);
|
|
2884
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2885
|
-
}
|
|
2886
|
-
} else {
|
|
2887
|
-
for (i = 0; i < n; i++) {
|
|
2888
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2889
|
-
x = m_bit_not(x);
|
|
2890
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
} else {
|
|
2894
|
-
if (idx2) {
|
|
2895
|
-
for (i = 0; i < n; i++) {
|
|
2896
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2897
|
-
x = m_bit_not(x);
|
|
2898
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2899
|
-
}
|
|
2900
|
-
} else {
|
|
2901
|
-
//
|
|
2902
|
-
for (i = 0; i < n; i++) {
|
|
2903
|
-
*(dtype*)p2 = m_bit_not(*(dtype*)p1);
|
|
2904
|
-
p1 += s1;
|
|
2905
|
-
p2 += s2;
|
|
2906
|
-
}
|
|
2907
|
-
return;
|
|
2908
|
-
//
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
|
|
2913
|
-
/*
|
|
2914
|
-
Unary bit_not.
|
|
2915
|
-
@overload ~
|
|
2916
|
-
@return [Numo::RObject] bit_not of self.
|
|
2917
|
-
*/
|
|
2918
|
-
static VALUE robject_bit_not(VALUE self) {
|
|
2919
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2920
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2921
|
-
ndfunc_t ndf = { iter_robject_bit_not, FULL_LOOP, 1, 1, ain, aout };
|
|
2922
|
-
|
|
2923
|
-
return na_ndloop(&ndf, 1, self);
|
|
2924
|
-
}
|
|
2925
|
-
|
|
2926
|
-
#define check_intdivzero(y) \
|
|
2927
|
-
{}
|
|
2928
|
-
|
|
2929
|
-
static void iter_robject_left_shift(na_loop_t* const lp) {
|
|
2930
|
-
size_t i = 0;
|
|
2931
|
-
size_t n;
|
|
2932
|
-
char *p1, *p2, *p3;
|
|
2933
|
-
ssize_t s1, s2, s3;
|
|
2934
|
-
|
|
2935
|
-
INIT_COUNTER(lp, n);
|
|
2936
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2937
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2938
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2939
|
-
|
|
2940
|
-
//
|
|
2941
|
-
|
|
2942
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2943
|
-
check_intdivzero(*(dtype*)p2);
|
|
2944
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2945
|
-
if (p1 == p3) { // inplace case
|
|
2946
|
-
for (; i < n; i++) {
|
|
2947
|
-
((dtype*)p1)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
2948
|
-
}
|
|
2949
|
-
} else {
|
|
2950
|
-
for (; i < n; i++) {
|
|
2951
|
-
((dtype*)p3)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
2952
|
-
}
|
|
2953
|
-
}
|
|
2954
|
-
} else {
|
|
2955
|
-
for (i = 0; i < n; i++) {
|
|
2956
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2957
|
-
p1 += s1;
|
|
2958
|
-
p3 += s3;
|
|
2959
|
-
}
|
|
2960
|
-
}
|
|
2961
|
-
} else {
|
|
2962
|
-
if (p1 == p3) { // inplace case
|
|
2963
|
-
for (i = 0; i < n; i++) {
|
|
2964
|
-
check_intdivzero(*(dtype*)p2);
|
|
2965
|
-
*(dtype*)p1 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2966
|
-
p1 += s1;
|
|
2967
|
-
p2 += s2;
|
|
2968
|
-
}
|
|
2969
|
-
} else {
|
|
2970
|
-
for (i = 0; i < n; i++) {
|
|
2971
|
-
check_intdivzero(*(dtype*)p2);
|
|
2972
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2973
|
-
p1 += s1;
|
|
2974
|
-
p2 += s2;
|
|
2975
|
-
p3 += s3;
|
|
2976
|
-
}
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
|
|
2980
|
-
return;
|
|
2981
|
-
//
|
|
2982
|
-
}
|
|
2983
|
-
#undef check_intdivzero
|
|
2984
|
-
|
|
2985
|
-
static VALUE robject_left_shift_self(VALUE self, VALUE other) {
|
|
2986
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2987
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2988
|
-
ndfunc_t ndf = { iter_robject_left_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2989
|
-
|
|
2990
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2991
|
-
}
|
|
2992
|
-
|
|
2993
|
-
/*
|
|
2994
|
-
Binary left_shift.
|
|
2995
|
-
@overload << other
|
|
2996
|
-
@param [Numo::NArray,Numeric] other
|
|
2997
|
-
@return [Numo::NArray] self << other
|
|
2998
|
-
*/
|
|
2999
|
-
static VALUE robject_left_shift(VALUE self, VALUE other) {
|
|
3000
|
-
return robject_left_shift_self(self, other);
|
|
3001
|
-
}
|
|
3002
|
-
|
|
3003
|
-
#define check_intdivzero(y) \
|
|
3004
|
-
{}
|
|
3005
|
-
|
|
3006
|
-
static void iter_robject_right_shift(na_loop_t* const lp) {
|
|
3007
|
-
size_t i = 0;
|
|
3008
|
-
size_t n;
|
|
3009
|
-
char *p1, *p2, *p3;
|
|
3010
|
-
ssize_t s1, s2, s3;
|
|
3011
|
-
|
|
3012
|
-
INIT_COUNTER(lp, n);
|
|
3013
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3014
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3015
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3016
|
-
|
|
3017
|
-
//
|
|
3018
|
-
|
|
3019
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
3020
|
-
check_intdivzero(*(dtype*)p2);
|
|
3021
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3022
|
-
if (p1 == p3) { // inplace case
|
|
3023
|
-
for (; i < n; i++) {
|
|
3024
|
-
((dtype*)p1)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3025
|
-
}
|
|
3026
|
-
} else {
|
|
3027
|
-
for (; i < n; i++) {
|
|
3028
|
-
((dtype*)p3)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
} else {
|
|
3032
|
-
for (i = 0; i < n; i++) {
|
|
3033
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3034
|
-
p1 += s1;
|
|
3035
|
-
p3 += s3;
|
|
3036
|
-
}
|
|
3037
|
-
}
|
|
3038
|
-
} else {
|
|
3039
|
-
if (p1 == p3) { // inplace case
|
|
3040
|
-
for (i = 0; i < n; i++) {
|
|
3041
|
-
check_intdivzero(*(dtype*)p2);
|
|
3042
|
-
*(dtype*)p1 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3043
|
-
p1 += s1;
|
|
3044
|
-
p2 += s2;
|
|
3045
|
-
}
|
|
3046
|
-
} else {
|
|
3047
|
-
for (i = 0; i < n; i++) {
|
|
3048
|
-
check_intdivzero(*(dtype*)p2);
|
|
3049
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3050
|
-
p1 += s1;
|
|
3051
|
-
p2 += s2;
|
|
3052
|
-
p3 += s3;
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
|
|
3057
|
-
return;
|
|
3058
|
-
//
|
|
3059
|
-
}
|
|
3060
|
-
#undef check_intdivzero
|
|
3061
|
-
|
|
3062
|
-
static VALUE robject_right_shift_self(VALUE self, VALUE other) {
|
|
3063
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3064
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3065
|
-
ndfunc_t ndf = { iter_robject_right_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3066
|
-
|
|
3067
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3068
|
-
}
|
|
3069
|
-
|
|
3070
|
-
/*
|
|
3071
|
-
Binary right_shift.
|
|
3072
|
-
@overload >> other
|
|
3073
|
-
@param [Numo::NArray,Numeric] other
|
|
3074
|
-
@return [Numo::NArray] self >> other
|
|
3075
|
-
*/
|
|
3076
|
-
static VALUE robject_right_shift(VALUE self, VALUE other) {
|
|
3077
|
-
return robject_right_shift_self(self, other);
|
|
3078
|
-
}
|
|
3079
|
-
|
|
3080
|
-
static void iter_robject_floor(na_loop_t* const lp) {
|
|
3081
|
-
size_t i, n;
|
|
3082
|
-
char *p1, *p2;
|
|
3083
|
-
ssize_t s1, s2;
|
|
3084
|
-
size_t *idx1, *idx2;
|
|
3085
|
-
dtype x;
|
|
3086
|
-
|
|
3087
|
-
INIT_COUNTER(lp, n);
|
|
3088
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3089
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3090
|
-
|
|
3091
|
-
if (idx1) {
|
|
3092
|
-
if (idx2) {
|
|
3093
|
-
for (i = 0; i < n; i++) {
|
|
3094
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3095
|
-
x = m_floor(x);
|
|
3096
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3097
|
-
}
|
|
3098
|
-
} else {
|
|
3099
|
-
for (i = 0; i < n; i++) {
|
|
3100
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3101
|
-
x = m_floor(x);
|
|
3102
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
} else {
|
|
3106
|
-
if (idx2) {
|
|
3107
|
-
for (i = 0; i < n; i++) {
|
|
3108
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3109
|
-
x = m_floor(x);
|
|
3110
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3111
|
-
}
|
|
3112
|
-
} else {
|
|
3113
|
-
//
|
|
3114
|
-
for (i = 0; i < n; i++) {
|
|
3115
|
-
*(dtype*)p2 = m_floor(*(dtype*)p1);
|
|
3116
|
-
p1 += s1;
|
|
3117
|
-
p2 += s2;
|
|
3118
|
-
}
|
|
3119
|
-
return;
|
|
3120
|
-
//
|
|
3121
|
-
}
|
|
3122
|
-
}
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
|
-
/*
|
|
3126
|
-
Unary floor.
|
|
3127
|
-
@overload floor
|
|
3128
|
-
@return [Numo::RObject] floor of self.
|
|
3129
|
-
*/
|
|
3130
|
-
static VALUE robject_floor(VALUE self) {
|
|
3131
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3132
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3133
|
-
ndfunc_t ndf = { iter_robject_floor, FULL_LOOP, 1, 1, ain, aout };
|
|
3134
|
-
|
|
3135
|
-
return na_ndloop(&ndf, 1, self);
|
|
3136
|
-
}
|
|
3137
|
-
|
|
3138
|
-
static void iter_robject_round(na_loop_t* const lp) {
|
|
3139
|
-
size_t i, n;
|
|
3140
|
-
char *p1, *p2;
|
|
3141
|
-
ssize_t s1, s2;
|
|
3142
|
-
size_t *idx1, *idx2;
|
|
3143
|
-
dtype x;
|
|
3144
|
-
|
|
3145
|
-
INIT_COUNTER(lp, n);
|
|
3146
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3147
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3148
|
-
|
|
3149
|
-
if (idx1) {
|
|
3150
|
-
if (idx2) {
|
|
3151
|
-
for (i = 0; i < n; i++) {
|
|
3152
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3153
|
-
x = m_round(x);
|
|
3154
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3155
|
-
}
|
|
3156
|
-
} else {
|
|
3157
|
-
for (i = 0; i < n; i++) {
|
|
3158
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3159
|
-
x = m_round(x);
|
|
3160
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3161
|
-
}
|
|
3162
|
-
}
|
|
3163
|
-
} else {
|
|
3164
|
-
if (idx2) {
|
|
3165
|
-
for (i = 0; i < n; i++) {
|
|
3166
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3167
|
-
x = m_round(x);
|
|
3168
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3169
|
-
}
|
|
3170
|
-
} else {
|
|
3171
|
-
//
|
|
3172
|
-
for (i = 0; i < n; i++) {
|
|
3173
|
-
*(dtype*)p2 = m_round(*(dtype*)p1);
|
|
3174
|
-
p1 += s1;
|
|
3175
|
-
p2 += s2;
|
|
3176
|
-
}
|
|
3177
|
-
return;
|
|
3178
|
-
//
|
|
3179
|
-
}
|
|
3180
|
-
}
|
|
3181
|
-
}
|
|
3182
|
-
|
|
3183
|
-
/*
|
|
3184
|
-
Unary round.
|
|
3185
|
-
@overload round
|
|
3186
|
-
@return [Numo::RObject] round of self.
|
|
3187
|
-
*/
|
|
3188
|
-
static VALUE robject_round(VALUE self) {
|
|
3189
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3190
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3191
|
-
ndfunc_t ndf = { iter_robject_round, FULL_LOOP, 1, 1, ain, aout };
|
|
3192
|
-
|
|
3193
|
-
return na_ndloop(&ndf, 1, self);
|
|
3194
|
-
}
|
|
3195
|
-
|
|
3196
|
-
static void iter_robject_ceil(na_loop_t* const lp) {
|
|
3197
|
-
size_t i, n;
|
|
3198
|
-
char *p1, *p2;
|
|
3199
|
-
ssize_t s1, s2;
|
|
3200
|
-
size_t *idx1, *idx2;
|
|
3201
|
-
dtype x;
|
|
3202
|
-
|
|
3203
|
-
INIT_COUNTER(lp, n);
|
|
3204
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3205
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3206
|
-
|
|
3207
|
-
if (idx1) {
|
|
3208
|
-
if (idx2) {
|
|
3209
|
-
for (i = 0; i < n; i++) {
|
|
3210
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3211
|
-
x = m_ceil(x);
|
|
3212
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3213
|
-
}
|
|
3214
|
-
} else {
|
|
3215
|
-
for (i = 0; i < n; i++) {
|
|
3216
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3217
|
-
x = m_ceil(x);
|
|
3218
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
} else {
|
|
3222
|
-
if (idx2) {
|
|
3223
|
-
for (i = 0; i < n; i++) {
|
|
3224
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3225
|
-
x = m_ceil(x);
|
|
3226
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3227
|
-
}
|
|
3228
|
-
} else {
|
|
3229
|
-
//
|
|
3230
|
-
for (i = 0; i < n; i++) {
|
|
3231
|
-
*(dtype*)p2 = m_ceil(*(dtype*)p1);
|
|
3232
|
-
p1 += s1;
|
|
3233
|
-
p2 += s2;
|
|
3234
|
-
}
|
|
3235
|
-
return;
|
|
3236
|
-
//
|
|
3237
|
-
}
|
|
3238
|
-
}
|
|
3239
|
-
}
|
|
3240
|
-
|
|
3241
|
-
/*
|
|
3242
|
-
Unary ceil.
|
|
3243
|
-
@overload ceil
|
|
3244
|
-
@return [Numo::RObject] ceil of self.
|
|
3245
|
-
*/
|
|
3246
|
-
static VALUE robject_ceil(VALUE self) {
|
|
3247
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3248
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3249
|
-
ndfunc_t ndf = { iter_robject_ceil, FULL_LOOP, 1, 1, ain, aout };
|
|
3250
|
-
|
|
3251
|
-
return na_ndloop(&ndf, 1, self);
|
|
3252
|
-
}
|
|
3253
|
-
|
|
3254
|
-
static void iter_robject_trunc(na_loop_t* const lp) {
|
|
3255
|
-
size_t i, n;
|
|
3256
|
-
char *p1, *p2;
|
|
3257
|
-
ssize_t s1, s2;
|
|
3258
|
-
size_t *idx1, *idx2;
|
|
3259
|
-
dtype x;
|
|
3260
|
-
|
|
3261
|
-
INIT_COUNTER(lp, n);
|
|
3262
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3263
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3264
|
-
|
|
3265
|
-
if (idx1) {
|
|
3266
|
-
if (idx2) {
|
|
3267
|
-
for (i = 0; i < n; i++) {
|
|
3268
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3269
|
-
x = m_trunc(x);
|
|
3270
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3271
|
-
}
|
|
3272
|
-
} else {
|
|
3273
|
-
for (i = 0; i < n; i++) {
|
|
3274
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3275
|
-
x = m_trunc(x);
|
|
3276
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3277
|
-
}
|
|
3278
|
-
}
|
|
3279
|
-
} else {
|
|
3280
|
-
if (idx2) {
|
|
3281
|
-
for (i = 0; i < n; i++) {
|
|
3282
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3283
|
-
x = m_trunc(x);
|
|
3284
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3285
|
-
}
|
|
3286
|
-
} else {
|
|
3287
|
-
//
|
|
3288
|
-
for (i = 0; i < n; i++) {
|
|
3289
|
-
*(dtype*)p2 = m_trunc(*(dtype*)p1);
|
|
3290
|
-
p1 += s1;
|
|
3291
|
-
p2 += s2;
|
|
3292
|
-
}
|
|
3293
|
-
return;
|
|
3294
|
-
//
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
|
-
/*
|
|
3300
|
-
Unary trunc.
|
|
3301
|
-
@overload trunc
|
|
3302
|
-
@return [Numo::RObject] trunc of self.
|
|
3303
|
-
*/
|
|
3304
|
-
static VALUE robject_trunc(VALUE self) {
|
|
3305
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3306
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3307
|
-
ndfunc_t ndf = { iter_robject_trunc, FULL_LOOP, 1, 1, ain, aout };
|
|
3308
|
-
|
|
3309
|
-
return na_ndloop(&ndf, 1, self);
|
|
3310
|
-
}
|
|
3311
|
-
|
|
3312
|
-
static void iter_robject_gt(na_loop_t* const lp) {
|
|
3313
|
-
size_t i;
|
|
3314
|
-
char *p1, *p2;
|
|
3315
|
-
BIT_DIGIT* a3;
|
|
3316
|
-
size_t p3;
|
|
3317
|
-
ssize_t s1, s2, s3;
|
|
3318
|
-
dtype x, y;
|
|
3319
|
-
BIT_DIGIT b;
|
|
3320
|
-
INIT_COUNTER(lp, i);
|
|
3321
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3322
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3323
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3324
|
-
for (; i--;) {
|
|
3325
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3326
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3327
|
-
b = (m_gt(x, y)) ? 1 : 0;
|
|
3328
|
-
STORE_BIT(a3, p3, b);
|
|
3329
|
-
p3 += s3;
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
|
-
|
|
3333
|
-
static VALUE robject_gt_self(VALUE self, VALUE other) {
|
|
3334
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3335
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3336
|
-
ndfunc_t ndf = { iter_robject_gt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3337
|
-
|
|
3338
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3339
|
-
}
|
|
3340
|
-
|
|
3341
|
-
/*
|
|
3342
|
-
Comparison gt other.
|
|
3343
|
-
@overload gt other
|
|
3344
|
-
@param [Numo::NArray,Numeric] other
|
|
3345
|
-
@return [Numo::Bit] result of self gt other.
|
|
3346
|
-
*/
|
|
3347
|
-
static VALUE robject_gt(VALUE self, VALUE other) {
|
|
3348
|
-
return robject_gt_self(self, other);
|
|
3349
|
-
}
|
|
3350
|
-
|
|
3351
|
-
static void iter_robject_ge(na_loop_t* const lp) {
|
|
3352
|
-
size_t i;
|
|
3353
|
-
char *p1, *p2;
|
|
3354
|
-
BIT_DIGIT* a3;
|
|
3355
|
-
size_t p3;
|
|
3356
|
-
ssize_t s1, s2, s3;
|
|
3357
|
-
dtype x, y;
|
|
3358
|
-
BIT_DIGIT b;
|
|
3359
|
-
INIT_COUNTER(lp, i);
|
|
3360
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3361
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3362
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3363
|
-
for (; i--;) {
|
|
3364
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3365
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3366
|
-
b = (m_ge(x, y)) ? 1 : 0;
|
|
3367
|
-
STORE_BIT(a3, p3, b);
|
|
3368
|
-
p3 += s3;
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
|
|
3372
|
-
static VALUE robject_ge_self(VALUE self, VALUE other) {
|
|
3373
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3374
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3375
|
-
ndfunc_t ndf = { iter_robject_ge, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3376
|
-
|
|
3377
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3378
|
-
}
|
|
3379
|
-
|
|
3380
|
-
/*
|
|
3381
|
-
Comparison ge other.
|
|
3382
|
-
@overload ge other
|
|
3383
|
-
@param [Numo::NArray,Numeric] other
|
|
3384
|
-
@return [Numo::Bit] result of self ge other.
|
|
3385
|
-
*/
|
|
3386
|
-
static VALUE robject_ge(VALUE self, VALUE other) {
|
|
3387
|
-
return robject_ge_self(self, other);
|
|
3388
|
-
}
|
|
3389
|
-
|
|
3390
|
-
static void iter_robject_lt(na_loop_t* const lp) {
|
|
3391
|
-
size_t i;
|
|
3392
|
-
char *p1, *p2;
|
|
3393
|
-
BIT_DIGIT* a3;
|
|
3394
|
-
size_t p3;
|
|
3395
|
-
ssize_t s1, s2, s3;
|
|
3396
|
-
dtype x, y;
|
|
3397
|
-
BIT_DIGIT b;
|
|
3398
|
-
INIT_COUNTER(lp, i);
|
|
3399
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3400
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3401
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3402
|
-
for (; i--;) {
|
|
3403
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3404
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3405
|
-
b = (m_lt(x, y)) ? 1 : 0;
|
|
3406
|
-
STORE_BIT(a3, p3, b);
|
|
3407
|
-
p3 += s3;
|
|
3408
|
-
}
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
static VALUE robject_lt_self(VALUE self, VALUE other) {
|
|
3412
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3413
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3414
|
-
ndfunc_t ndf = { iter_robject_lt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3415
|
-
|
|
3416
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3417
|
-
}
|
|
3418
|
-
|
|
3419
|
-
/*
|
|
3420
|
-
Comparison lt other.
|
|
3421
|
-
@overload lt other
|
|
3422
|
-
@param [Numo::NArray,Numeric] other
|
|
3423
|
-
@return [Numo::Bit] result of self lt other.
|
|
3424
|
-
*/
|
|
3425
|
-
static VALUE robject_lt(VALUE self, VALUE other) {
|
|
3426
|
-
return robject_lt_self(self, other);
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
|
-
static void iter_robject_le(na_loop_t* const lp) {
|
|
3430
|
-
size_t i;
|
|
3431
|
-
char *p1, *p2;
|
|
3432
|
-
BIT_DIGIT* a3;
|
|
3433
|
-
size_t p3;
|
|
3434
|
-
ssize_t s1, s2, s3;
|
|
3435
|
-
dtype x, y;
|
|
3436
|
-
BIT_DIGIT b;
|
|
3437
|
-
INIT_COUNTER(lp, i);
|
|
3438
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3439
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3440
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3441
|
-
for (; i--;) {
|
|
3442
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3443
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3444
|
-
b = (m_le(x, y)) ? 1 : 0;
|
|
3445
|
-
STORE_BIT(a3, p3, b);
|
|
3446
|
-
p3 += s3;
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
|
|
3450
|
-
static VALUE robject_le_self(VALUE self, VALUE other) {
|
|
3451
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3452
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3453
|
-
ndfunc_t ndf = { iter_robject_le, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3454
|
-
|
|
3455
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3456
|
-
}
|
|
3457
|
-
|
|
3458
|
-
/*
|
|
3459
|
-
Comparison le other.
|
|
3460
|
-
@overload le other
|
|
3461
|
-
@param [Numo::NArray,Numeric] other
|
|
3462
|
-
@return [Numo::Bit] result of self le other.
|
|
3463
|
-
*/
|
|
3464
|
-
static VALUE robject_le(VALUE self, VALUE other) {
|
|
3465
|
-
return robject_le_self(self, other);
|
|
3466
|
-
}
|
|
3467
|
-
|
|
3468
|
-
static void iter_robject_isnan(na_loop_t* const lp) {
|
|
3469
|
-
size_t i;
|
|
3470
|
-
char* p1;
|
|
3471
|
-
BIT_DIGIT* a2;
|
|
3472
|
-
size_t p2;
|
|
3473
|
-
ssize_t s1, s2;
|
|
3474
|
-
size_t* idx1;
|
|
3475
|
-
dtype x;
|
|
3476
|
-
BIT_DIGIT b;
|
|
3477
|
-
INIT_COUNTER(lp, i);
|
|
3478
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3479
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3480
|
-
if (idx1) {
|
|
3481
|
-
for (; i--;) {
|
|
3482
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3483
|
-
b = (m_isnan(x)) ? 1 : 0;
|
|
3484
|
-
STORE_BIT(a2, p2, b);
|
|
3485
|
-
p2 += s2;
|
|
3486
|
-
}
|
|
3487
|
-
} else {
|
|
3488
|
-
for (; i--;) {
|
|
3489
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3490
|
-
b = (m_isnan(x)) ? 1 : 0;
|
|
3491
|
-
STORE_BIT(a2, p2, b);
|
|
3492
|
-
p2 += s2;
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
|
-
}
|
|
3496
|
-
|
|
3497
|
-
/*
|
|
3498
|
-
Condition of isnan.
|
|
3499
|
-
@overload isnan
|
|
3500
|
-
@return [Numo::Bit] Condition of isnan.
|
|
3501
|
-
*/
|
|
3502
|
-
static VALUE robject_isnan(VALUE self) {
|
|
3503
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3504
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3505
|
-
ndfunc_t ndf = { iter_robject_isnan, FULL_LOOP, 1, 1, ain, aout };
|
|
3506
|
-
|
|
3507
|
-
return na_ndloop(&ndf, 1, self);
|
|
3508
|
-
}
|
|
3509
|
-
|
|
3510
|
-
static void iter_robject_isinf(na_loop_t* const lp) {
|
|
3511
|
-
size_t i;
|
|
3512
|
-
char* p1;
|
|
3513
|
-
BIT_DIGIT* a2;
|
|
3514
|
-
size_t p2;
|
|
3515
|
-
ssize_t s1, s2;
|
|
3516
|
-
size_t* idx1;
|
|
3517
|
-
dtype x;
|
|
3518
|
-
BIT_DIGIT b;
|
|
3519
|
-
INIT_COUNTER(lp, i);
|
|
3520
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3521
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3522
|
-
if (idx1) {
|
|
3523
|
-
for (; i--;) {
|
|
3524
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3525
|
-
b = (m_isinf(x)) ? 1 : 0;
|
|
3526
|
-
STORE_BIT(a2, p2, b);
|
|
3527
|
-
p2 += s2;
|
|
3528
|
-
}
|
|
3529
|
-
} else {
|
|
3530
|
-
for (; i--;) {
|
|
3531
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3532
|
-
b = (m_isinf(x)) ? 1 : 0;
|
|
3533
|
-
STORE_BIT(a2, p2, b);
|
|
3534
|
-
p2 += s2;
|
|
3535
|
-
}
|
|
3536
|
-
}
|
|
3537
|
-
}
|
|
3538
|
-
|
|
3539
|
-
/*
|
|
3540
|
-
Condition of isinf.
|
|
3541
|
-
@overload isinf
|
|
3542
|
-
@return [Numo::Bit] Condition of isinf.
|
|
3543
|
-
*/
|
|
3544
|
-
static VALUE robject_isinf(VALUE self) {
|
|
3545
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3546
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3547
|
-
ndfunc_t ndf = { iter_robject_isinf, FULL_LOOP, 1, 1, ain, aout };
|
|
3548
|
-
|
|
3549
|
-
return na_ndloop(&ndf, 1, self);
|
|
3550
|
-
}
|
|
3551
|
-
|
|
3552
|
-
static void iter_robject_isposinf(na_loop_t* const lp) {
|
|
3553
|
-
size_t i;
|
|
3554
|
-
char* p1;
|
|
3555
|
-
BIT_DIGIT* a2;
|
|
3556
|
-
size_t p2;
|
|
3557
|
-
ssize_t s1, s2;
|
|
3558
|
-
size_t* idx1;
|
|
3559
|
-
dtype x;
|
|
3560
|
-
BIT_DIGIT b;
|
|
3561
|
-
INIT_COUNTER(lp, i);
|
|
3562
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3563
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3564
|
-
if (idx1) {
|
|
3565
|
-
for (; i--;) {
|
|
3566
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3567
|
-
b = (m_isposinf(x)) ? 1 : 0;
|
|
3568
|
-
STORE_BIT(a2, p2, b);
|
|
3569
|
-
p2 += s2;
|
|
3570
|
-
}
|
|
3571
|
-
} else {
|
|
3572
|
-
for (; i--;) {
|
|
3573
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3574
|
-
b = (m_isposinf(x)) ? 1 : 0;
|
|
3575
|
-
STORE_BIT(a2, p2, b);
|
|
3576
|
-
p2 += s2;
|
|
3577
|
-
}
|
|
3578
|
-
}
|
|
3579
|
-
}
|
|
3580
|
-
|
|
3581
|
-
/*
|
|
3582
|
-
Condition of isposinf.
|
|
3583
|
-
@overload isposinf
|
|
3584
|
-
@return [Numo::Bit] Condition of isposinf.
|
|
3585
|
-
*/
|
|
3586
|
-
static VALUE robject_isposinf(VALUE self) {
|
|
3587
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3588
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3589
|
-
ndfunc_t ndf = { iter_robject_isposinf, FULL_LOOP, 1, 1, ain, aout };
|
|
3590
|
-
|
|
3591
|
-
return na_ndloop(&ndf, 1, self);
|
|
3592
|
-
}
|
|
3593
|
-
|
|
3594
|
-
static void iter_robject_isneginf(na_loop_t* const lp) {
|
|
3595
|
-
size_t i;
|
|
3596
|
-
char* p1;
|
|
3597
|
-
BIT_DIGIT* a2;
|
|
3598
|
-
size_t p2;
|
|
3599
|
-
ssize_t s1, s2;
|
|
3600
|
-
size_t* idx1;
|
|
3601
|
-
dtype x;
|
|
3602
|
-
BIT_DIGIT b;
|
|
3603
|
-
INIT_COUNTER(lp, i);
|
|
3604
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3605
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3606
|
-
if (idx1) {
|
|
3607
|
-
for (; i--;) {
|
|
3608
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3609
|
-
b = (m_isneginf(x)) ? 1 : 0;
|
|
3610
|
-
STORE_BIT(a2, p2, b);
|
|
3611
|
-
p2 += s2;
|
|
3612
|
-
}
|
|
3613
|
-
} else {
|
|
3614
|
-
for (; i--;) {
|
|
3615
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3616
|
-
b = (m_isneginf(x)) ? 1 : 0;
|
|
3617
|
-
STORE_BIT(a2, p2, b);
|
|
3618
|
-
p2 += s2;
|
|
3619
|
-
}
|
|
3620
|
-
}
|
|
3621
|
-
}
|
|
3622
|
-
|
|
3623
|
-
/*
|
|
3624
|
-
Condition of isneginf.
|
|
3625
|
-
@overload isneginf
|
|
3626
|
-
@return [Numo::Bit] Condition of isneginf.
|
|
3627
|
-
*/
|
|
3628
|
-
static VALUE robject_isneginf(VALUE self) {
|
|
3629
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3630
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3631
|
-
ndfunc_t ndf = { iter_robject_isneginf, FULL_LOOP, 1, 1, ain, aout };
|
|
3632
|
-
|
|
3633
|
-
return na_ndloop(&ndf, 1, self);
|
|
3634
|
-
}
|
|
3635
|
-
|
|
3636
|
-
static void iter_robject_isfinite(na_loop_t* const lp) {
|
|
3637
|
-
size_t i;
|
|
3638
|
-
char* p1;
|
|
3639
|
-
BIT_DIGIT* a2;
|
|
3640
|
-
size_t p2;
|
|
3641
|
-
ssize_t s1, s2;
|
|
3642
|
-
size_t* idx1;
|
|
3643
|
-
dtype x;
|
|
3644
|
-
BIT_DIGIT b;
|
|
3645
|
-
INIT_COUNTER(lp, i);
|
|
3646
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3647
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3648
|
-
if (idx1) {
|
|
3649
|
-
for (; i--;) {
|
|
3650
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3651
|
-
b = (m_isfinite(x)) ? 1 : 0;
|
|
3652
|
-
STORE_BIT(a2, p2, b);
|
|
3653
|
-
p2 += s2;
|
|
3654
|
-
}
|
|
3655
|
-
} else {
|
|
3656
|
-
for (; i--;) {
|
|
3657
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3658
|
-
b = (m_isfinite(x)) ? 1 : 0;
|
|
3659
|
-
STORE_BIT(a2, p2, b);
|
|
3660
|
-
p2 += s2;
|
|
3661
|
-
}
|
|
3662
|
-
}
|
|
3663
|
-
}
|
|
3664
|
-
|
|
3665
|
-
/*
|
|
3666
|
-
Condition of isfinite.
|
|
3667
|
-
@overload isfinite
|
|
3668
|
-
@return [Numo::Bit] Condition of isfinite.
|
|
3669
|
-
*/
|
|
3670
|
-
static VALUE robject_isfinite(VALUE self) {
|
|
3671
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3672
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3673
|
-
ndfunc_t ndf = { iter_robject_isfinite, FULL_LOOP, 1, 1, ain, aout };
|
|
3674
|
-
|
|
3675
|
-
return na_ndloop(&ndf, 1, self);
|
|
3676
|
-
}
|
|
3677
|
-
|
|
3678
|
-
static void iter_robject_poly(na_loop_t* const lp) {
|
|
3679
|
-
size_t i;
|
|
3680
|
-
dtype x, y, a;
|
|
3681
|
-
|
|
3682
|
-
x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
|
|
3683
|
-
i = lp->narg - 2;
|
|
3684
|
-
y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
3685
|
-
for (; --i;) {
|
|
3686
|
-
y = m_mul(x, y);
|
|
3687
|
-
a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
3688
|
-
y = m_add(y, a);
|
|
3689
|
-
}
|
|
3690
|
-
i = lp->narg - 1;
|
|
3691
|
-
*(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
|
|
3692
|
-
}
|
|
3693
|
-
|
|
3694
|
-
/*
|
|
3695
|
-
Calculate polynomial.
|
|
3696
|
-
`x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
3697
|
-
@overload poly a0, a1, ..., an
|
|
3698
|
-
@param [Numo::NArray,Numeric] a0,a1,...,an
|
|
3699
|
-
@return [Numo::RObject]
|
|
3700
|
-
*/
|
|
3701
|
-
static VALUE robject_poly(VALUE self, VALUE args) {
|
|
3702
|
-
int argc, i;
|
|
3703
|
-
VALUE* argv;
|
|
3704
|
-
volatile VALUE v, a;
|
|
3705
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3706
|
-
ndfunc_t ndf = { iter_robject_poly, NO_LOOP, 0, 1, 0, aout };
|
|
3707
|
-
|
|
3708
|
-
argc = (int)RARRAY_LEN(args);
|
|
3709
|
-
ndf.nin = argc + 1;
|
|
3710
|
-
ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
|
|
3711
|
-
for (i = 0; i < argc + 1; i++) {
|
|
3712
|
-
ndf.ain[i].type = cT;
|
|
3713
|
-
}
|
|
3714
|
-
argv = ALLOCA_N(VALUE, argc + 1);
|
|
3715
|
-
argv[0] = self;
|
|
3716
|
-
for (i = 0; i < argc; i++) {
|
|
3717
|
-
argv[i + 1] = RARRAY_PTR(args)[i];
|
|
3718
|
-
}
|
|
3719
|
-
a = rb_ary_new4(argc + 1, argv);
|
|
3720
|
-
v = na_ndloop2(&ndf, a);
|
|
3721
|
-
return robject_extract(v);
|
|
3722
|
-
}
|
|
3723
|
-
|
|
3724
|
-
void Init_numo_robject(void) {
|
|
3725
|
-
VALUE hCast, mNumo;
|
|
3726
|
-
|
|
3727
|
-
mNumo = rb_define_module("Numo");
|
|
3728
|
-
|
|
3729
|
-
id_ne = rb_intern("!=");
|
|
3730
|
-
id_pow = rb_intern("**");
|
|
3731
|
-
id_minus = rb_intern("-@");
|
|
3732
|
-
id_lt = rb_intern("<");
|
|
3733
|
-
id_left_shift = rb_intern("<<");
|
|
3734
|
-
id_le = rb_intern("<=");
|
|
3735
|
-
id_ufo = rb_intern("<=>");
|
|
3736
|
-
id_eq = rb_intern("==");
|
|
3737
|
-
id_gt = rb_intern(">");
|
|
3738
|
-
id_ge = rb_intern(">=");
|
|
3739
|
-
id_right_shift = rb_intern(">>");
|
|
3740
|
-
id_abs = rb_intern("abs");
|
|
3741
|
-
id_bit_and = rb_intern("bit_and");
|
|
3742
|
-
id_bit_not = rb_intern("bit_not");
|
|
3743
|
-
id_bit_or = rb_intern("bit_or");
|
|
3744
|
-
id_bit_xor = rb_intern("bit_xor");
|
|
3745
|
-
id_cast = rb_intern("cast");
|
|
3746
|
-
id_ceil = rb_intern("ceil");
|
|
3747
|
-
id_copysign = rb_intern("copysign");
|
|
3748
|
-
id_divmod = rb_intern("divmod");
|
|
3749
|
-
id_finite_p = rb_intern("finite?");
|
|
3750
|
-
id_floor = rb_intern("floor");
|
|
3751
|
-
id_infinite_p = rb_intern("infinite?");
|
|
3752
|
-
id_mulsum = rb_intern("mulsum");
|
|
3753
|
-
id_nan = rb_intern("nan");
|
|
3754
|
-
id_nan_p = rb_intern("nan?");
|
|
3755
|
-
id_nearly_eq = rb_intern("nearly_eq");
|
|
3756
|
-
id_reciprocal = rb_intern("reciprocal");
|
|
3757
|
-
id_round = rb_intern("round");
|
|
3758
|
-
id_square = rb_intern("square");
|
|
3759
|
-
id_to_a = rb_intern("to_a");
|
|
3760
|
-
id_truncate = rb_intern("truncate");
|
|
3761
|
-
|
|
3762
|
-
/**
|
|
3763
|
-
* Document-class: Numo::RObject
|
|
3764
|
-
*
|
|
3765
|
-
* Ruby object N-dimensional array class.
|
|
3766
|
-
*/
|
|
3767
|
-
cT = rb_define_class_under(mNumo, "RObject", cNArray);
|
|
3768
|
-
|
|
3769
|
-
hCast = rb_hash_new();
|
|
3770
|
-
/* Upcasting rules of RObject. */
|
|
3771
|
-
rb_define_const(cT, "UPCAST", hCast);
|
|
3772
|
-
rb_hash_aset(hCast, rb_cArray, cT);
|
|
1767
|
+
hCast = rb_hash_new();
|
|
1768
|
+
/* Upcasting rules of RObject. */
|
|
1769
|
+
rb_define_const(cT, "UPCAST", hCast);
|
|
1770
|
+
rb_hash_aset(hCast, rb_cArray, cT);
|
|
3773
1771
|
|
|
3774
1772
|
#ifdef RUBY_INTEGER_UNIFICATION
|
|
3775
1773
|
rb_hash_aset(hCast, rb_cInteger, cT);
|
|
@@ -3815,49 +1813,241 @@ void Init_numo_robject(void) {
|
|
|
3815
1813
|
rb_define_singleton_method(cT, "cast", robject_s_cast, 1);
|
|
3816
1814
|
rb_define_method(cT, "[]", robject_aref, -1);
|
|
3817
1815
|
rb_define_method(cT, "[]=", robject_aset, -1);
|
|
1816
|
+
/**
|
|
1817
|
+
* return NArray with cast to the type of self.
|
|
1818
|
+
* @overload coerce_cast(type)
|
|
1819
|
+
* @return [nil]
|
|
1820
|
+
*/
|
|
3818
1821
|
rb_define_method(cT, "coerce_cast", robject_coerce_cast, 1);
|
|
1822
|
+
/**
|
|
1823
|
+
* Convert self to Array.
|
|
1824
|
+
* @overload to_a
|
|
1825
|
+
* @return [Array]
|
|
1826
|
+
*/
|
|
3819
1827
|
rb_define_method(cT, "to_a", robject_to_a, 0);
|
|
1828
|
+
/**
|
|
1829
|
+
* Fill elements with other.
|
|
1830
|
+
* @overload fill other
|
|
1831
|
+
* @param [Numeric] other
|
|
1832
|
+
* @return [Numo::RObject] self.
|
|
1833
|
+
*/
|
|
3820
1834
|
rb_define_method(cT, "fill", robject_fill, 1);
|
|
1835
|
+
/**
|
|
1836
|
+
* Format elements into strings.
|
|
1837
|
+
* @overload format format
|
|
1838
|
+
* @param [String] format
|
|
1839
|
+
* @return [Numo::RObject] array of formatted strings.
|
|
1840
|
+
*/
|
|
3821
1841
|
rb_define_method(cT, "format", robject_format, -1);
|
|
1842
|
+
/**
|
|
1843
|
+
* Format elements into strings.
|
|
1844
|
+
* @overload format_to_a format
|
|
1845
|
+
* @param [String] format
|
|
1846
|
+
* @return [Array] array of formatted strings.
|
|
1847
|
+
*/
|
|
3822
1848
|
rb_define_method(cT, "format_to_a", robject_format_to_a, -1);
|
|
1849
|
+
/**
|
|
1850
|
+
* Returns a string containing a human-readable representation of NArray.
|
|
1851
|
+
* @overload inspect
|
|
1852
|
+
* @return [String]
|
|
1853
|
+
*/
|
|
3823
1854
|
rb_define_method(cT, "inspect", robject_inspect, 0);
|
|
3824
1855
|
rb_define_method(cT, "each", robject_each, 0);
|
|
3825
1856
|
rb_define_method(cT, "map", robject_map, 0);
|
|
3826
1857
|
rb_define_method(cT, "each_with_index", robject_each_with_index, 0);
|
|
3827
1858
|
rb_define_method(cT, "map_with_index", robject_map_with_index, 0);
|
|
3828
1859
|
rb_define_method(cT, "abs", robject_abs, 0);
|
|
1860
|
+
/**
|
|
1861
|
+
* Binary add.
|
|
1862
|
+
* @overload + other
|
|
1863
|
+
* @param [Numo::NArray,Numeric] other
|
|
1864
|
+
* @return [Numo::NArray] self + other
|
|
1865
|
+
*/
|
|
3829
1866
|
rb_define_method(cT, "+", robject_add, 1);
|
|
1867
|
+
/**
|
|
1868
|
+
* Binary sub.
|
|
1869
|
+
* @overload - other
|
|
1870
|
+
* @param [Numo::NArray,Numeric] other
|
|
1871
|
+
* @return [Numo::NArray] self - other
|
|
1872
|
+
*/
|
|
3830
1873
|
rb_define_method(cT, "-", robject_sub, 1);
|
|
1874
|
+
/**
|
|
1875
|
+
* Binary mul.
|
|
1876
|
+
* @overload * other
|
|
1877
|
+
* @param [Numo::NArray,Numeric] other
|
|
1878
|
+
* @return [Numo::NArray] self * other
|
|
1879
|
+
*/
|
|
3831
1880
|
rb_define_method(cT, "*", robject_mul, 1);
|
|
1881
|
+
/**
|
|
1882
|
+
* Binary div.
|
|
1883
|
+
* @overload / other
|
|
1884
|
+
* @param [Numo::NArray,Numeric] other
|
|
1885
|
+
* @return [Numo::NArray] self / other
|
|
1886
|
+
*/
|
|
3832
1887
|
rb_define_method(cT, "/", robject_div, 1);
|
|
1888
|
+
/**
|
|
1889
|
+
* Binary mod.
|
|
1890
|
+
* @overload % other
|
|
1891
|
+
* @param [Numo::NArray,Numeric] other
|
|
1892
|
+
* @return [Numo::NArray] self % other
|
|
1893
|
+
*/
|
|
3833
1894
|
rb_define_method(cT, "%", robject_mod, 1);
|
|
1895
|
+
/**
|
|
1896
|
+
* Binary divmod.
|
|
1897
|
+
* @overload divmod other
|
|
1898
|
+
* @param [Numo::NArray,Numeric] other
|
|
1899
|
+
* @return [Numo::NArray] divmod of self and other.
|
|
1900
|
+
*/
|
|
3834
1901
|
rb_define_method(cT, "divmod", robject_divmod, 1);
|
|
1902
|
+
/**
|
|
1903
|
+
* Binary power.
|
|
1904
|
+
* @overload ** other
|
|
1905
|
+
* @param [Numo::NArray,Numeric] other
|
|
1906
|
+
* @return [Numo::NArray] self to the other-th power.
|
|
1907
|
+
*/
|
|
3835
1908
|
rb_define_method(cT, "**", robject_pow, 1);
|
|
3836
1909
|
rb_define_alias(cT, "pow", "**");
|
|
1910
|
+
/**
|
|
1911
|
+
* Unary minus.
|
|
1912
|
+
* @overload -@
|
|
1913
|
+
* @return [Numo::RObject] minus of self.
|
|
1914
|
+
*/
|
|
3837
1915
|
rb_define_method(cT, "-@", robject_minus, 0);
|
|
1916
|
+
/**
|
|
1917
|
+
* Unary reciprocal.
|
|
1918
|
+
* @overload reciprocal
|
|
1919
|
+
* @return [Numo::RObject] reciprocal of self.
|
|
1920
|
+
*/
|
|
3838
1921
|
rb_define_method(cT, "reciprocal", robject_reciprocal, 0);
|
|
1922
|
+
/**
|
|
1923
|
+
* Unary sign.
|
|
1924
|
+
* @overload sign
|
|
1925
|
+
* @return [Numo::RObject] sign of self.
|
|
1926
|
+
*/
|
|
3839
1927
|
rb_define_method(cT, "sign", robject_sign, 0);
|
|
1928
|
+
/**
|
|
1929
|
+
* Unary square.
|
|
1930
|
+
* @overload square
|
|
1931
|
+
* @return [Numo::RObject] square of self.
|
|
1932
|
+
*/
|
|
3840
1933
|
rb_define_method(cT, "square", robject_square, 0);
|
|
3841
1934
|
rb_define_alias(cT, "conj", "view");
|
|
3842
1935
|
rb_define_alias(cT, "im", "view");
|
|
3843
1936
|
rb_define_alias(cT, "conjugate", "conj");
|
|
1937
|
+
/**
|
|
1938
|
+
* Comparison eq other.
|
|
1939
|
+
* @overload eq other
|
|
1940
|
+
* @param [Numo::NArray,Numeric] other
|
|
1941
|
+
* @return [Numo::Bit] result of self eq other.
|
|
1942
|
+
*/
|
|
3844
1943
|
rb_define_method(cT, "eq", robject_eq, 1);
|
|
1944
|
+
/**
|
|
1945
|
+
* Comparison ne other.
|
|
1946
|
+
* @overload ne other
|
|
1947
|
+
* @param [Numo::NArray,Numeric] other
|
|
1948
|
+
* @return [Numo::Bit] result of self ne other.
|
|
1949
|
+
*/
|
|
3845
1950
|
rb_define_method(cT, "ne", robject_ne, 1);
|
|
1951
|
+
/**
|
|
1952
|
+
* Comparison nearly_eq other.
|
|
1953
|
+
* @overload nearly_eq other
|
|
1954
|
+
* @param [Numo::NArray,Numeric] other
|
|
1955
|
+
* @return [Numo::Bit] result of self nearly_eq other.
|
|
1956
|
+
*/
|
|
3846
1957
|
rb_define_method(cT, "nearly_eq", robject_nearly_eq, 1);
|
|
3847
1958
|
rb_define_alias(cT, "close_to", "nearly_eq");
|
|
1959
|
+
/**
|
|
1960
|
+
* Binary bit_and.
|
|
1961
|
+
* @overload & other
|
|
1962
|
+
* @param [Numo::NArray,Numeric] other
|
|
1963
|
+
* @return [Numo::NArray] self & other
|
|
1964
|
+
*/
|
|
3848
1965
|
rb_define_method(cT, "&", robject_bit_and, 1);
|
|
1966
|
+
/**
|
|
1967
|
+
* Binary bit_or.
|
|
1968
|
+
* @overload | other
|
|
1969
|
+
* @param [Numo::NArray,Numeric] other
|
|
1970
|
+
* @return [Numo::NArray] self | other
|
|
1971
|
+
*/
|
|
3849
1972
|
rb_define_method(cT, "|", robject_bit_or, 1);
|
|
1973
|
+
/**
|
|
1974
|
+
* Binary bit_xor.
|
|
1975
|
+
* @overload ^ other
|
|
1976
|
+
* @param [Numo::NArray,Numeric] other
|
|
1977
|
+
* @return [Numo::NArray] self ^ other
|
|
1978
|
+
*/
|
|
3850
1979
|
rb_define_method(cT, "^", robject_bit_xor, 1);
|
|
1980
|
+
/**
|
|
1981
|
+
* Unary bit_not.
|
|
1982
|
+
* @overload ~
|
|
1983
|
+
* @return [Numo::RObject] bit_not of self.
|
|
1984
|
+
*/
|
|
3851
1985
|
rb_define_method(cT, "~", robject_bit_not, 0);
|
|
1986
|
+
/**
|
|
1987
|
+
* Binary left_shift.
|
|
1988
|
+
* @overload << other
|
|
1989
|
+
* @param [Numo::NArray,Numeric] other
|
|
1990
|
+
* @return [Numo::NArray] self << other
|
|
1991
|
+
*/
|
|
3852
1992
|
rb_define_method(cT, "<<", robject_left_shift, 1);
|
|
1993
|
+
/**
|
|
1994
|
+
* Binary right_shift.
|
|
1995
|
+
* @overload >> other
|
|
1996
|
+
* @param [Numo::NArray,Numeric] other
|
|
1997
|
+
* @return [Numo::NArray] self >> other
|
|
1998
|
+
*/
|
|
3853
1999
|
rb_define_method(cT, ">>", robject_right_shift, 1);
|
|
2000
|
+
/**
|
|
2001
|
+
* Unary floor.
|
|
2002
|
+
* @overload floor
|
|
2003
|
+
* @return [Numo::RObject] floor of self.
|
|
2004
|
+
*/
|
|
3854
2005
|
rb_define_method(cT, "floor", robject_floor, 0);
|
|
2006
|
+
/**
|
|
2007
|
+
* Unary round.
|
|
2008
|
+
* @overload round
|
|
2009
|
+
* @return [Numo::RObject] round of self.
|
|
2010
|
+
*/
|
|
3855
2011
|
rb_define_method(cT, "round", robject_round, 0);
|
|
2012
|
+
/**
|
|
2013
|
+
* Unary ceil.
|
|
2014
|
+
* @overload ceil
|
|
2015
|
+
* @return [Numo::RObject] ceil of self.
|
|
2016
|
+
*/
|
|
3856
2017
|
rb_define_method(cT, "ceil", robject_ceil, 0);
|
|
2018
|
+
/**
|
|
2019
|
+
* Unary trunc.
|
|
2020
|
+
* @overload trunc
|
|
2021
|
+
* @return [Numo::RObject] trunc of self.
|
|
2022
|
+
*/
|
|
3857
2023
|
rb_define_method(cT, "trunc", robject_trunc, 0);
|
|
2024
|
+
/**
|
|
2025
|
+
* Comparison gt other.
|
|
2026
|
+
* @overload gt other
|
|
2027
|
+
* @param [Numo::NArray,Numeric] other
|
|
2028
|
+
* @return [Numo::Bit] result of self gt other.
|
|
2029
|
+
*/
|
|
3858
2030
|
rb_define_method(cT, "gt", robject_gt, 1);
|
|
2031
|
+
/**
|
|
2032
|
+
* Comparison ge other.
|
|
2033
|
+
* @overload ge other
|
|
2034
|
+
* @param [Numo::NArray,Numeric] other
|
|
2035
|
+
* @return [Numo::Bit] result of self ge other.
|
|
2036
|
+
*/
|
|
3859
2037
|
rb_define_method(cT, "ge", robject_ge, 1);
|
|
2038
|
+
/**
|
|
2039
|
+
* Comparison lt other.
|
|
2040
|
+
* @overload lt other
|
|
2041
|
+
* @param [Numo::NArray,Numeric] other
|
|
2042
|
+
* @return [Numo::Bit] result of self lt other.
|
|
2043
|
+
*/
|
|
3860
2044
|
rb_define_method(cT, "lt", robject_lt, 1);
|
|
2045
|
+
/**
|
|
2046
|
+
* Comparison le other.
|
|
2047
|
+
* @overload le other
|
|
2048
|
+
* @param [Numo::NArray,Numeric] other
|
|
2049
|
+
* @return [Numo::Bit] result of self le other.
|
|
2050
|
+
*/
|
|
3861
2051
|
rb_define_method(cT, "le", robject_le, 1);
|
|
3862
2052
|
rb_define_alias(cT, ">", "gt");
|
|
3863
2053
|
rb_define_alias(cT, ">=", "ge");
|
|
@@ -3894,10 +2084,35 @@ void Init_numo_robject(void) {
|
|
|
3894
2084
|
* # [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
3895
2085
|
*/
|
|
3896
2086
|
rb_define_method(cT, "clip", robject_clip, 2);
|
|
2087
|
+
/**
|
|
2088
|
+
* Condition of isnan.
|
|
2089
|
+
* @overload isnan
|
|
2090
|
+
* @return [Numo::Bit] Condition of isnan.
|
|
2091
|
+
*/
|
|
3897
2092
|
rb_define_method(cT, "isnan", robject_isnan, 0);
|
|
2093
|
+
/**
|
|
2094
|
+
* Condition of isinf.
|
|
2095
|
+
* @overload isinf
|
|
2096
|
+
* @return [Numo::Bit] Condition of isinf.
|
|
2097
|
+
*/
|
|
3898
2098
|
rb_define_method(cT, "isinf", robject_isinf, 0);
|
|
2099
|
+
/**
|
|
2100
|
+
* Condition of isposinf.
|
|
2101
|
+
* @overload isposinf
|
|
2102
|
+
* @return [Numo::Bit] Condition of isposinf.
|
|
2103
|
+
*/
|
|
3899
2104
|
rb_define_method(cT, "isposinf", robject_isposinf, 0);
|
|
2105
|
+
/**
|
|
2106
|
+
* Condition of isneginf.
|
|
2107
|
+
* @overload isneginf
|
|
2108
|
+
* @return [Numo::Bit] Condition of isneginf.
|
|
2109
|
+
*/
|
|
3900
2110
|
rb_define_method(cT, "isneginf", robject_isneginf, 0);
|
|
2111
|
+
/**
|
|
2112
|
+
* Condition of isfinite.
|
|
2113
|
+
* @overload isfinite
|
|
2114
|
+
* @return [Numo::Bit] Condition of isfinite.
|
|
2115
|
+
*/
|
|
3901
2116
|
rb_define_method(cT, "isfinite", robject_isfinite, 0);
|
|
3902
2117
|
/**
|
|
3903
2118
|
* sum of self.
|