numo-narray-alt 0.9.10 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/LICENSE +1 -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/numo/types/robject.h +1 -1
- data/ext/numo/narray/src/mh/argmax.h +154 -0
- data/ext/numo/narray/src/mh/argmin.h +154 -0
- 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/clip.h +115 -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/cumprod.h +98 -0
- data/ext/numo/narray/src/mh/cumsum.h +98 -0
- data/ext/numo/narray/src/mh/divmod.h +142 -0
- data/ext/numo/narray/src/mh/eye.h +82 -0
- 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/logseq.h +69 -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/max.h +69 -0
- data/ext/numo/narray/src/mh/max_index.h +184 -0
- data/ext/numo/narray/src/mh/maximum.h +116 -0
- data/ext/numo/narray/src/mh/min.h +69 -0
- data/ext/numo/narray/src/mh/min_index.h +184 -0
- data/ext/numo/narray/src/mh/minimum.h +116 -0
- data/ext/numo/narray/src/mh/minmax.h +77 -0
- data/ext/numo/narray/src/mh/mulsum.h +185 -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/prod.h +69 -0
- data/ext/numo/narray/src/mh/ptp.h +69 -0
- data/ext/numo/narray/src/mh/rand.h +315 -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/seq.h +130 -0
- data/ext/numo/narray/src/mh/sum.h +69 -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 +608 -2369
- data/ext/numo/narray/src/t_dfloat.c +485 -3736
- data/ext/numo/narray/src/t_int16.c +743 -3444
- data/ext/numo/narray/src/t_int32.c +745 -3445
- data/ext/numo/narray/src/t_int64.c +743 -3446
- data/ext/numo/narray/src/t_int8.c +678 -3040
- data/ext/numo/narray/src/t_robject.c +771 -3548
- data/ext/numo/narray/src/t_scomplex.c +607 -2368
- data/ext/numo/narray/src/t_sfloat.c +440 -3693
- data/ext/numo/narray/src/t_uint16.c +743 -3440
- data/ext/numo/narray/src/t_uint32.c +743 -3440
- data/ext/numo/narray/src/t_uint64.c +743 -3442
- data/ext/numo/narray/src/t_uint8.c +678 -3038
- data/lib/numo/narray.rb +2 -3
- metadata +62 -3
|
@@ -43,6 +43,50 @@ static ID id_to_a;
|
|
|
43
43
|
VALUE cT;
|
|
44
44
|
extern VALUE cRT;
|
|
45
45
|
|
|
46
|
+
#include "mh/coerce_cast.h"
|
|
47
|
+
#include "mh/to_a.h"
|
|
48
|
+
#include "mh/fill.h"
|
|
49
|
+
#include "mh/format.h"
|
|
50
|
+
#include "mh/format_to_a.h"
|
|
51
|
+
#include "mh/inspect.h"
|
|
52
|
+
#include "mh/op/add.h"
|
|
53
|
+
#include "mh/op/sub.h"
|
|
54
|
+
#include "mh/op/mul.h"
|
|
55
|
+
#include "mh/op/div.h"
|
|
56
|
+
#include "mh/op/mod.h"
|
|
57
|
+
#include "mh/divmod.h"
|
|
58
|
+
#include "mh/comp/eq.h"
|
|
59
|
+
#include "mh/comp/ne.h"
|
|
60
|
+
#include "mh/comp/gt.h"
|
|
61
|
+
#include "mh/comp/ge.h"
|
|
62
|
+
#include "mh/comp/lt.h"
|
|
63
|
+
#include "mh/comp/le.h"
|
|
64
|
+
#include "mh/bit/and.h"
|
|
65
|
+
#include "mh/bit/or.h"
|
|
66
|
+
#include "mh/bit/xor.h"
|
|
67
|
+
#include "mh/bit/not.h"
|
|
68
|
+
#include "mh/bit/left_shift.h"
|
|
69
|
+
#include "mh/bit/right_shift.h"
|
|
70
|
+
#include "mh/clip.h"
|
|
71
|
+
#include "mh/sum.h"
|
|
72
|
+
#include "mh/prod.h"
|
|
73
|
+
#include "mh/min.h"
|
|
74
|
+
#include "mh/max.h"
|
|
75
|
+
#include "mh/ptp.h"
|
|
76
|
+
#include "mh/max_index.h"
|
|
77
|
+
#include "mh/min_index.h"
|
|
78
|
+
#include "mh/argmax.h"
|
|
79
|
+
#include "mh/argmin.h"
|
|
80
|
+
#include "mh/maximum.h"
|
|
81
|
+
#include "mh/minimum.h"
|
|
82
|
+
#include "mh/minmax.h"
|
|
83
|
+
#include "mh/bincount.h"
|
|
84
|
+
#include "mh/cumsum.h"
|
|
85
|
+
#include "mh/cumprod.h"
|
|
86
|
+
#include "mh/mulsum.h"
|
|
87
|
+
#include "mh/seq.h"
|
|
88
|
+
#include "mh/eye.h"
|
|
89
|
+
#include "mh/rand.h"
|
|
46
90
|
#include "mh/mean.h"
|
|
47
91
|
#include "mh/var.h"
|
|
48
92
|
#include "mh/stddev.h"
|
|
@@ -50,6 +94,50 @@ extern VALUE cRT;
|
|
|
50
94
|
|
|
51
95
|
typedef int8_t int8; // Type aliases for shorter notation
|
|
52
96
|
// following the codebase naming convention.
|
|
97
|
+
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(int8)
|
|
98
|
+
DEF_NARRAY_TO_A_METHOD_FUNC(int8)
|
|
99
|
+
DEF_NARRAY_FILL_METHOD_FUNC(int8)
|
|
100
|
+
DEF_NARRAY_FORMAT_METHOD_FUNC(int8)
|
|
101
|
+
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(int8)
|
|
102
|
+
DEF_NARRAY_INSPECT_METHOD_FUNC(int8)
|
|
103
|
+
DEF_NARRAY_INT8_ADD_METHOD_FUNC(int8, numo_cInt8)
|
|
104
|
+
DEF_NARRAY_INT8_SUB_METHOD_FUNC(int8, numo_cInt8)
|
|
105
|
+
DEF_NARRAY_INT8_MUL_METHOD_FUNC(int8, numo_cInt8)
|
|
106
|
+
DEF_NARRAY_INT8_DIV_METHOD_FUNC(int8, numo_cInt8)
|
|
107
|
+
DEF_NARRAY_INT8_MOD_METHOD_FUNC(int8, numo_cInt8)
|
|
108
|
+
DEF_NARRAY_INT_DIVMOD_METHOD_FUNC(int8, numo_cInt8)
|
|
109
|
+
DEF_NARRAY_EQ_METHOD_FUNC(int8, numo_cInt8)
|
|
110
|
+
DEF_NARRAY_NE_METHOD_FUNC(int8, numo_cInt8)
|
|
111
|
+
DEF_NARRAY_GT_METHOD_FUNC(int8, numo_cInt8)
|
|
112
|
+
DEF_NARRAY_GE_METHOD_FUNC(int8, numo_cInt8)
|
|
113
|
+
DEF_NARRAY_LT_METHOD_FUNC(int8, numo_cInt8)
|
|
114
|
+
DEF_NARRAY_LE_METHOD_FUNC(int8, numo_cInt8)
|
|
115
|
+
DEF_NARRAY_INT8_BIT_AND_METHOD_FUNC(int8, numo_cInt8)
|
|
116
|
+
DEF_NARRAY_INT8_BIT_OR_METHOD_FUNC(int8, numo_cInt8)
|
|
117
|
+
DEF_NARRAY_INT8_BIT_XOR_METHOD_FUNC(int8, numo_cInt8)
|
|
118
|
+
DEF_NARRAY_INT8_BIT_NOT_METHOD_FUNC(int8, numo_cInt8)
|
|
119
|
+
DEF_NARRAY_INT8_LEFT_SHIFT_METHOD_FUNC(int8, numo_cInt8)
|
|
120
|
+
DEF_NARRAY_INT8_RIGHT_SHIFT_METHOD_FUNC(int8, numo_cInt8)
|
|
121
|
+
DEF_NARRAY_CLIP_METHOD_FUNC(int8, numo_cInt8)
|
|
122
|
+
DEF_NARRAY_INT_SUM_METHOD_FUNC(int8, numo_cInt8, int64_t, numo_cInt64)
|
|
123
|
+
DEF_NARRAY_INT_PROD_METHOD_FUNC(int8, numo_cInt8, int64_t, numo_cInt64)
|
|
124
|
+
DEF_NARRAY_INT_MAX_METHOD_FUNC(int8, numo_cInt8)
|
|
125
|
+
DEF_NARRAY_INT_MIN_METHOD_FUNC(int8, numo_cInt8)
|
|
126
|
+
DEF_NARRAY_INT_PTP_METHOD_FUNC(int8, numo_cInt8)
|
|
127
|
+
DEF_NARRAY_INT_MAX_INDEX_METHOD_FUNC(int8)
|
|
128
|
+
DEF_NARRAY_INT_MIN_INDEX_METHOD_FUNC(int8)
|
|
129
|
+
DEF_NARRAY_INT_ARGMAX_METHOD_FUNC(int8)
|
|
130
|
+
DEF_NARRAY_INT_ARGMIN_METHOD_FUNC(int8)
|
|
131
|
+
DEF_NARRAY_INT_MAXIMUM_METHOD_FUNC(int8, numo_cInt8)
|
|
132
|
+
DEF_NARRAY_INT_MINIMUM_METHOD_FUNC(int8, numo_cInt8)
|
|
133
|
+
DEF_NARRAY_INT_MINMAX_METHOD_FUNC(int8, numo_cInt8)
|
|
134
|
+
DEF_NARRAY_INT_BINCOUNT_METHOD_FUNC(int8, numo_cInt8)
|
|
135
|
+
DEF_NARRAY_INT_CUMSUM_METHOD_FUNC(int8, numo_cInt8)
|
|
136
|
+
DEF_NARRAY_INT_CUMPROD_METHOD_FUNC(int8, numo_cInt8)
|
|
137
|
+
DEF_NARRAY_INT_MULSUM_METHOD_FUNC(int8, numo_cInt8)
|
|
138
|
+
DEF_NARRAY_INT_SEQ_METHOD_FUNC(int8)
|
|
139
|
+
DEF_NARRAY_EYE_METHOD_FUNC(int8)
|
|
140
|
+
DEF_NARRAY_INT_RAND_METHOD_FUNC(int8)
|
|
53
141
|
DEF_NARRAY_INT_MEAN_METHOD_FUNC(int8, numo_cInt8)
|
|
54
142
|
DEF_NARRAY_INT_VAR_METHOD_FUNC(int8, numo_cInt8)
|
|
55
143
|
DEF_NARRAY_INT_STDDEV_METHOD_FUNC(int8, numo_cInt8)
|
|
@@ -1214,204 +1302,6 @@ static VALUE int8_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1214
1302
|
return argv[argc];
|
|
1215
1303
|
}
|
|
1216
1304
|
|
|
1217
|
-
/*
|
|
1218
|
-
return NArray with cast to the type of self.
|
|
1219
|
-
@overload coerce_cast(type)
|
|
1220
|
-
@return [nil]
|
|
1221
|
-
*/
|
|
1222
|
-
static VALUE int8_coerce_cast(VALUE self, VALUE type) {
|
|
1223
|
-
return Qnil;
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
static void iter_int8_to_a(na_loop_t* const lp) {
|
|
1227
|
-
size_t i, s1;
|
|
1228
|
-
char* p1;
|
|
1229
|
-
size_t* idx1;
|
|
1230
|
-
dtype x;
|
|
1231
|
-
volatile VALUE a, y;
|
|
1232
|
-
|
|
1233
|
-
INIT_COUNTER(lp, i);
|
|
1234
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1235
|
-
a = rb_ary_new2(i);
|
|
1236
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1237
|
-
if (idx1) {
|
|
1238
|
-
for (; i--;) {
|
|
1239
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1240
|
-
y = m_data_to_num(x);
|
|
1241
|
-
rb_ary_push(a, y);
|
|
1242
|
-
}
|
|
1243
|
-
} else {
|
|
1244
|
-
for (; i--;) {
|
|
1245
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1246
|
-
y = m_data_to_num(x);
|
|
1247
|
-
rb_ary_push(a, y);
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
/*
|
|
1253
|
-
Convert self to Array.
|
|
1254
|
-
@overload to_a
|
|
1255
|
-
@return [Array]
|
|
1256
|
-
*/
|
|
1257
|
-
static VALUE int8_to_a(VALUE self) {
|
|
1258
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1259
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1260
|
-
ndfunc_t ndf = { iter_int8_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1261
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
static void iter_int8_fill(na_loop_t* const lp) {
|
|
1265
|
-
size_t i;
|
|
1266
|
-
char* p1;
|
|
1267
|
-
ssize_t s1;
|
|
1268
|
-
size_t* idx1;
|
|
1269
|
-
VALUE x = lp->option;
|
|
1270
|
-
dtype y;
|
|
1271
|
-
INIT_COUNTER(lp, i);
|
|
1272
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1273
|
-
y = m_num_to_data(x);
|
|
1274
|
-
if (idx1) {
|
|
1275
|
-
for (; i--;) {
|
|
1276
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
1277
|
-
}
|
|
1278
|
-
} else {
|
|
1279
|
-
for (; i--;) {
|
|
1280
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
/*
|
|
1286
|
-
Fill elements with other.
|
|
1287
|
-
@overload fill other
|
|
1288
|
-
@param [Numeric] other
|
|
1289
|
-
@return [Numo::Int8] self.
|
|
1290
|
-
*/
|
|
1291
|
-
static VALUE int8_fill(VALUE self, VALUE val) {
|
|
1292
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
|
|
1293
|
-
ndfunc_t ndf = { iter_int8_fill, FULL_LOOP, 2, 0, ain, 0 };
|
|
1294
|
-
|
|
1295
|
-
na_ndloop(&ndf, 2, self, val);
|
|
1296
|
-
return self;
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
static VALUE format_int8(VALUE fmt, dtype* x) {
|
|
1300
|
-
// fix-me
|
|
1301
|
-
char s[48];
|
|
1302
|
-
int n;
|
|
1303
|
-
|
|
1304
|
-
if (NIL_P(fmt)) {
|
|
1305
|
-
n = m_sprintf(s, *x);
|
|
1306
|
-
return rb_str_new(s, n);
|
|
1307
|
-
}
|
|
1308
|
-
return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
static void iter_int8_format(na_loop_t* const lp) {
|
|
1312
|
-
size_t i;
|
|
1313
|
-
char *p1, *p2;
|
|
1314
|
-
ssize_t s1, s2;
|
|
1315
|
-
size_t* idx1;
|
|
1316
|
-
dtype* x;
|
|
1317
|
-
VALUE y;
|
|
1318
|
-
VALUE fmt = lp->option;
|
|
1319
|
-
INIT_COUNTER(lp, i);
|
|
1320
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1321
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1322
|
-
if (idx1) {
|
|
1323
|
-
for (; i--;) {
|
|
1324
|
-
x = (dtype*)(p1 + *idx1);
|
|
1325
|
-
idx1++;
|
|
1326
|
-
y = format_int8(fmt, x);
|
|
1327
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1328
|
-
}
|
|
1329
|
-
} else {
|
|
1330
|
-
for (; i--;) {
|
|
1331
|
-
x = (dtype*)p1;
|
|
1332
|
-
p1 += s1;
|
|
1333
|
-
y = format_int8(fmt, x);
|
|
1334
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
/*
|
|
1340
|
-
Format elements into strings.
|
|
1341
|
-
@overload format format
|
|
1342
|
-
@param [String] format
|
|
1343
|
-
@return [Numo::RObject] array of formatted strings.
|
|
1344
|
-
*/
|
|
1345
|
-
static VALUE int8_format(int argc, VALUE* argv, VALUE self) {
|
|
1346
|
-
VALUE fmt = Qnil;
|
|
1347
|
-
|
|
1348
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
|
|
1349
|
-
ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
|
|
1350
|
-
ndfunc_t ndf = { iter_int8_format, FULL_LOOP_NIP, 2, 1, ain, aout };
|
|
1351
|
-
|
|
1352
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1353
|
-
return na_ndloop(&ndf, 2, self, fmt);
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
static void iter_int8_format_to_a(na_loop_t* const lp) {
|
|
1357
|
-
size_t i;
|
|
1358
|
-
char* p1;
|
|
1359
|
-
ssize_t s1;
|
|
1360
|
-
size_t* idx1;
|
|
1361
|
-
dtype* x;
|
|
1362
|
-
VALUE y;
|
|
1363
|
-
volatile VALUE a;
|
|
1364
|
-
VALUE fmt = lp->option;
|
|
1365
|
-
INIT_COUNTER(lp, i);
|
|
1366
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1367
|
-
a = rb_ary_new2(i);
|
|
1368
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1369
|
-
if (idx1) {
|
|
1370
|
-
for (; i--;) {
|
|
1371
|
-
x = (dtype*)(p1 + *idx1);
|
|
1372
|
-
idx1++;
|
|
1373
|
-
y = format_int8(fmt, x);
|
|
1374
|
-
rb_ary_push(a, y);
|
|
1375
|
-
}
|
|
1376
|
-
} else {
|
|
1377
|
-
for (; i--;) {
|
|
1378
|
-
x = (dtype*)p1;
|
|
1379
|
-
p1 += s1;
|
|
1380
|
-
y = format_int8(fmt, x);
|
|
1381
|
-
rb_ary_push(a, y);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
/*
|
|
1387
|
-
Format elements into strings.
|
|
1388
|
-
@overload format_to_a format
|
|
1389
|
-
@param [String] format
|
|
1390
|
-
@return [Array] array of formatted strings.
|
|
1391
|
-
*/
|
|
1392
|
-
static VALUE int8_format_to_a(int argc, VALUE* argv, VALUE self) {
|
|
1393
|
-
VALUE fmt = Qnil;
|
|
1394
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1395
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1396
|
-
ndfunc_t ndf = { iter_int8_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1397
|
-
|
|
1398
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1399
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
static VALUE iter_int8_inspect(char* ptr, size_t pos, VALUE fmt) {
|
|
1403
|
-
return format_int8(fmt, (dtype*)(ptr + pos));
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
/*
|
|
1407
|
-
Returns a string containing a human-readable representation of NArray.
|
|
1408
|
-
@overload inspect
|
|
1409
|
-
@return [String]
|
|
1410
|
-
*/
|
|
1411
|
-
static VALUE int8_inspect(VALUE ary) {
|
|
1412
|
-
return na_ndloop_inspect(ary, iter_int8_inspect, Qnil);
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
1305
|
static void iter_int8_each(na_loop_t* const lp) {
|
|
1416
1306
|
size_t i, s1;
|
|
1417
1307
|
char* p1;
|
|
@@ -1721,2951 +1611,304 @@ static VALUE int8_abs(VALUE self) {
|
|
|
1721
1611
|
return na_ndloop(&ndf, 1, self);
|
|
1722
1612
|
}
|
|
1723
1613
|
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
static void iter_int8_add(na_loop_t* const lp) {
|
|
1728
|
-
size_t i = 0;
|
|
1729
|
-
size_t n;
|
|
1614
|
+
static void iter_int8_pow(na_loop_t* const lp) {
|
|
1615
|
+
size_t i;
|
|
1730
1616
|
char *p1, *p2, *p3;
|
|
1731
1617
|
ssize_t s1, s2, s3;
|
|
1732
|
-
|
|
1733
|
-
INIT_COUNTER(lp,
|
|
1618
|
+
dtype x, y;
|
|
1619
|
+
INIT_COUNTER(lp, i);
|
|
1734
1620
|
INIT_PTR(lp, 0, p1, s1);
|
|
1735
1621
|
INIT_PTR(lp, 1, p2, s2);
|
|
1736
1622
|
INIT_PTR(lp, 2, p3, s3);
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1743
|
-
if (p1 == p3) { // inplace case
|
|
1744
|
-
for (; i < n; i++) {
|
|
1745
|
-
((dtype*)p1)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1746
|
-
}
|
|
1747
|
-
} else {
|
|
1748
|
-
for (; i < n; i++) {
|
|
1749
|
-
((dtype*)p3)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
} else {
|
|
1753
|
-
for (i = 0; i < n; i++) {
|
|
1754
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1755
|
-
p1 += s1;
|
|
1756
|
-
p3 += s3;
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
} else {
|
|
1760
|
-
if (p1 == p3) { // inplace case
|
|
1761
|
-
for (i = 0; i < n; i++) {
|
|
1762
|
-
check_intdivzero(*(dtype*)p2);
|
|
1763
|
-
*(dtype*)p1 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1764
|
-
p1 += s1;
|
|
1765
|
-
p2 += s2;
|
|
1766
|
-
}
|
|
1767
|
-
} else {
|
|
1768
|
-
for (i = 0; i < n; i++) {
|
|
1769
|
-
check_intdivzero(*(dtype*)p2);
|
|
1770
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1771
|
-
p1 += s1;
|
|
1772
|
-
p2 += s2;
|
|
1773
|
-
p3 += s3;
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1623
|
+
for (; i--;) {
|
|
1624
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1625
|
+
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
1626
|
+
x = m_pow(x, y);
|
|
1627
|
+
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
1776
1628
|
}
|
|
1629
|
+
}
|
|
1777
1630
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1631
|
+
static void iter_int8_pow_int32(na_loop_t* const lp) {
|
|
1632
|
+
size_t i;
|
|
1633
|
+
char *p1, *p2, *p3;
|
|
1634
|
+
ssize_t s1, s2, s3;
|
|
1635
|
+
dtype x;
|
|
1636
|
+
int32_t y;
|
|
1637
|
+
INIT_COUNTER(lp, i);
|
|
1638
|
+
INIT_PTR(lp, 0, p1, s1);
|
|
1639
|
+
INIT_PTR(lp, 1, p2, s2);
|
|
1640
|
+
INIT_PTR(lp, 2, p3, s3);
|
|
1641
|
+
for (; i--;) {
|
|
1642
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1643
|
+
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
1644
|
+
x = m_pow_int(x, y);
|
|
1645
|
+
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
1646
|
+
}
|
|
1780
1647
|
}
|
|
1781
|
-
#undef check_intdivzero
|
|
1782
1648
|
|
|
1783
|
-
static VALUE
|
|
1649
|
+
static VALUE int8_pow_self(VALUE self, VALUE other) {
|
|
1784
1650
|
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1651
|
+
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
1785
1652
|
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1786
|
-
ndfunc_t ndf = {
|
|
1653
|
+
ndfunc_t ndf = { iter_int8_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1654
|
+
ndfunc_t ndf_i = { iter_int8_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
1787
1655
|
|
|
1788
|
-
|
|
1656
|
+
// fixme : use na.integer?
|
|
1657
|
+
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
1658
|
+
return na_ndloop(&ndf_i, 2, self, other);
|
|
1659
|
+
} else {
|
|
1660
|
+
return na_ndloop(&ndf, 2, self, other);
|
|
1661
|
+
}
|
|
1789
1662
|
}
|
|
1790
1663
|
|
|
1791
1664
|
/*
|
|
1792
|
-
Binary
|
|
1793
|
-
@overload
|
|
1665
|
+
Binary power.
|
|
1666
|
+
@overload ** other
|
|
1794
1667
|
@param [Numo::NArray,Numeric] other
|
|
1795
|
-
@return [Numo::NArray] self
|
|
1668
|
+
@return [Numo::NArray] self to the other-th power.
|
|
1796
1669
|
*/
|
|
1797
|
-
static VALUE
|
|
1670
|
+
static VALUE int8_pow(VALUE self, VALUE other) {
|
|
1798
1671
|
|
|
1799
1672
|
VALUE klass, v;
|
|
1800
|
-
|
|
1801
1673
|
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
1802
1674
|
if (klass == cT) {
|
|
1803
|
-
return
|
|
1675
|
+
return int8_pow_self(self, other);
|
|
1804
1676
|
} else {
|
|
1805
1677
|
v = rb_funcall(klass, id_cast, 1, self);
|
|
1806
|
-
return rb_funcall(v,
|
|
1678
|
+
return rb_funcall(v, id_pow, 1, other);
|
|
1807
1679
|
}
|
|
1808
1680
|
}
|
|
1809
1681
|
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
size_t
|
|
1815
|
-
|
|
1816
|
-
char *p1, *p2, *p3;
|
|
1817
|
-
ssize_t s1, s2, s3;
|
|
1682
|
+
static void iter_int8_minus(na_loop_t* const lp) {
|
|
1683
|
+
size_t i, n;
|
|
1684
|
+
char *p1, *p2;
|
|
1685
|
+
ssize_t s1, s2;
|
|
1686
|
+
size_t *idx1, *idx2;
|
|
1687
|
+
dtype x;
|
|
1818
1688
|
|
|
1819
1689
|
INIT_COUNTER(lp, n);
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1823
|
-
|
|
1824
|
-
//
|
|
1690
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1691
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1825
1692
|
|
|
1826
|
-
if (
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
}
|
|
1833
|
-
} else {
|
|
1834
|
-
for (; i < n; i++) {
|
|
1835
|
-
((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
1836
|
-
}
|
|
1693
|
+
if (idx1) {
|
|
1694
|
+
if (idx2) {
|
|
1695
|
+
for (i = 0; i < n; i++) {
|
|
1696
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1697
|
+
x = m_minus(x);
|
|
1698
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1837
1699
|
}
|
|
1838
1700
|
} else {
|
|
1839
1701
|
for (i = 0; i < n; i++) {
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1702
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1703
|
+
x = m_minus(x);
|
|
1704
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1843
1705
|
}
|
|
1844
1706
|
}
|
|
1845
1707
|
} else {
|
|
1846
|
-
if (
|
|
1708
|
+
if (idx2) {
|
|
1847
1709
|
for (i = 0; i < n; i++) {
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
p2 += s2;
|
|
1710
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1711
|
+
x = m_minus(x);
|
|
1712
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1852
1713
|
}
|
|
1853
1714
|
} else {
|
|
1715
|
+
//
|
|
1854
1716
|
for (i = 0; i < n; i++) {
|
|
1855
|
-
|
|
1856
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
1717
|
+
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
1857
1718
|
p1 += s1;
|
|
1858
1719
|
p2 += s2;
|
|
1859
|
-
p3 += s3;
|
|
1860
1720
|
}
|
|
1721
|
+
return;
|
|
1722
|
+
//
|
|
1861
1723
|
}
|
|
1862
1724
|
}
|
|
1863
|
-
|
|
1864
|
-
return;
|
|
1865
|
-
//
|
|
1866
|
-
}
|
|
1867
|
-
#undef check_intdivzero
|
|
1868
|
-
|
|
1869
|
-
static VALUE int8_sub_self(VALUE self, VALUE other) {
|
|
1870
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1871
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1872
|
-
ndfunc_t ndf = { iter_int8_sub, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1873
|
-
|
|
1874
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1875
1725
|
}
|
|
1876
1726
|
|
|
1877
1727
|
/*
|
|
1878
|
-
|
|
1879
|
-
@overload
|
|
1880
|
-
@
|
|
1881
|
-
@return [Numo::NArray] self - other
|
|
1728
|
+
Unary minus.
|
|
1729
|
+
@overload -@
|
|
1730
|
+
@return [Numo::Int8] minus of self.
|
|
1882
1731
|
*/
|
|
1883
|
-
static VALUE
|
|
1884
|
-
|
|
1885
|
-
|
|
1732
|
+
static VALUE int8_minus(VALUE self) {
|
|
1733
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1734
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1735
|
+
ndfunc_t ndf = { iter_int8_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
1886
1736
|
|
|
1887
|
-
|
|
1888
|
-
if (klass == cT) {
|
|
1889
|
-
return int8_sub_self(self, other);
|
|
1890
|
-
} else {
|
|
1891
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
1892
|
-
return rb_funcall(v, '-', 1, other);
|
|
1893
|
-
}
|
|
1737
|
+
return na_ndloop(&ndf, 1, self);
|
|
1894
1738
|
}
|
|
1895
1739
|
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
size_t
|
|
1901
|
-
|
|
1902
|
-
char *p1, *p2, *p3;
|
|
1903
|
-
ssize_t s1, s2, s3;
|
|
1740
|
+
static void iter_int8_reciprocal(na_loop_t* const lp) {
|
|
1741
|
+
size_t i, n;
|
|
1742
|
+
char *p1, *p2;
|
|
1743
|
+
ssize_t s1, s2;
|
|
1744
|
+
size_t *idx1, *idx2;
|
|
1745
|
+
dtype x;
|
|
1904
1746
|
|
|
1905
1747
|
INIT_COUNTER(lp, n);
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1909
|
-
|
|
1910
|
-
//
|
|
1748
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1749
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1911
1750
|
|
|
1912
|
-
if (
|
|
1913
|
-
|
|
1914
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1915
|
-
if (p1 == p3) { // inplace case
|
|
1916
|
-
for (; i < n; i++) {
|
|
1917
|
-
((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
1918
|
-
}
|
|
1919
|
-
} else {
|
|
1920
|
-
for (; i < n; i++) {
|
|
1921
|
-
((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
} else {
|
|
1751
|
+
if (idx1) {
|
|
1752
|
+
if (idx2) {
|
|
1925
1753
|
for (i = 0; i < n; i++) {
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
} else {
|
|
1932
|
-
if (p1 == p3) { // inplace case
|
|
1933
|
-
for (i = 0; i < n; i++) {
|
|
1934
|
-
check_intdivzero(*(dtype*)p2);
|
|
1935
|
-
*(dtype*)p1 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1936
|
-
p1 += s1;
|
|
1937
|
-
p2 += s2;
|
|
1938
|
-
}
|
|
1939
|
-
} else {
|
|
1940
|
-
for (i = 0; i < n; i++) {
|
|
1941
|
-
check_intdivzero(*(dtype*)p2);
|
|
1942
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
1943
|
-
p1 += s1;
|
|
1944
|
-
p2 += s2;
|
|
1945
|
-
p3 += s3;
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
|
-
return;
|
|
1951
|
-
//
|
|
1952
|
-
}
|
|
1953
|
-
#undef check_intdivzero
|
|
1954
|
-
|
|
1955
|
-
static VALUE int8_mul_self(VALUE self, VALUE other) {
|
|
1956
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1957
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1958
|
-
ndfunc_t ndf = { iter_int8_mul, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1959
|
-
|
|
1960
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1961
|
-
}
|
|
1962
|
-
|
|
1963
|
-
/*
|
|
1964
|
-
Binary mul.
|
|
1965
|
-
@overload * other
|
|
1966
|
-
@param [Numo::NArray,Numeric] other
|
|
1967
|
-
@return [Numo::NArray] self * other
|
|
1968
|
-
*/
|
|
1969
|
-
static VALUE int8_mul(VALUE self, VALUE other) {
|
|
1970
|
-
|
|
1971
|
-
VALUE klass, v;
|
|
1972
|
-
|
|
1973
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
1974
|
-
if (klass == cT) {
|
|
1975
|
-
return int8_mul_self(self, other);
|
|
1976
|
-
} else {
|
|
1977
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
1978
|
-
return rb_funcall(v, '*', 1, other);
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
#define check_intdivzero(y) \
|
|
1983
|
-
if ((y) == 0) { \
|
|
1984
|
-
lp->err_type = rb_eZeroDivError; \
|
|
1985
|
-
return; \
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
static void iter_int8_div(na_loop_t* const lp) {
|
|
1989
|
-
size_t i = 0;
|
|
1990
|
-
size_t n;
|
|
1991
|
-
char *p1, *p2, *p3;
|
|
1992
|
-
ssize_t s1, s2, s3;
|
|
1993
|
-
|
|
1994
|
-
INIT_COUNTER(lp, n);
|
|
1995
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
1996
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1997
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1998
|
-
|
|
1999
|
-
//
|
|
2000
|
-
|
|
2001
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2002
|
-
check_intdivzero(*(dtype*)p2);
|
|
2003
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2004
|
-
if (p1 == p3) { // inplace case
|
|
2005
|
-
for (; i < n; i++) {
|
|
2006
|
-
((dtype*)p1)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2007
|
-
}
|
|
2008
|
-
} else {
|
|
2009
|
-
for (; i < n; i++) {
|
|
2010
|
-
((dtype*)p3)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
} else {
|
|
2014
|
-
for (i = 0; i < n; i++) {
|
|
2015
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2016
|
-
p1 += s1;
|
|
2017
|
-
p3 += s3;
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
} else {
|
|
2021
|
-
if (p1 == p3) { // inplace case
|
|
2022
|
-
for (i = 0; i < n; i++) {
|
|
2023
|
-
check_intdivzero(*(dtype*)p2);
|
|
2024
|
-
*(dtype*)p1 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2025
|
-
p1 += s1;
|
|
2026
|
-
p2 += s2;
|
|
2027
|
-
}
|
|
2028
|
-
} else {
|
|
2029
|
-
for (i = 0; i < n; i++) {
|
|
2030
|
-
check_intdivzero(*(dtype*)p2);
|
|
2031
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2032
|
-
p1 += s1;
|
|
2033
|
-
p2 += s2;
|
|
2034
|
-
p3 += s3;
|
|
2035
|
-
}
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
return;
|
|
2040
|
-
//
|
|
2041
|
-
}
|
|
2042
|
-
#undef check_intdivzero
|
|
2043
|
-
|
|
2044
|
-
static VALUE int8_div_self(VALUE self, VALUE other) {
|
|
2045
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2046
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2047
|
-
ndfunc_t ndf = { iter_int8_div, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2048
|
-
|
|
2049
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
/*
|
|
2053
|
-
Binary div.
|
|
2054
|
-
@overload / other
|
|
2055
|
-
@param [Numo::NArray,Numeric] other
|
|
2056
|
-
@return [Numo::NArray] self / other
|
|
2057
|
-
*/
|
|
2058
|
-
static VALUE int8_div(VALUE self, VALUE other) {
|
|
2059
|
-
|
|
2060
|
-
VALUE klass, v;
|
|
2061
|
-
|
|
2062
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2063
|
-
if (klass == cT) {
|
|
2064
|
-
return int8_div_self(self, other);
|
|
2065
|
-
} else {
|
|
2066
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2067
|
-
return rb_funcall(v, '/', 1, other);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
|
|
2071
|
-
#define check_intdivzero(y) \
|
|
2072
|
-
if ((y) == 0) { \
|
|
2073
|
-
lp->err_type = rb_eZeroDivError; \
|
|
2074
|
-
return; \
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
static void iter_int8_mod(na_loop_t* const lp) {
|
|
2078
|
-
size_t i = 0;
|
|
2079
|
-
size_t n;
|
|
2080
|
-
char *p1, *p2, *p3;
|
|
2081
|
-
ssize_t s1, s2, s3;
|
|
2082
|
-
|
|
2083
|
-
INIT_COUNTER(lp, n);
|
|
2084
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2085
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2086
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2087
|
-
|
|
2088
|
-
//
|
|
2089
|
-
|
|
2090
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2091
|
-
check_intdivzero(*(dtype*)p2);
|
|
2092
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2093
|
-
if (p1 == p3) { // inplace case
|
|
2094
|
-
for (; i < n; i++) {
|
|
2095
|
-
((dtype*)p1)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2096
|
-
}
|
|
2097
|
-
} else {
|
|
2098
|
-
for (; i < n; i++) {
|
|
2099
|
-
((dtype*)p3)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
} else {
|
|
2103
|
-
for (i = 0; i < n; i++) {
|
|
2104
|
-
*(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2105
|
-
p1 += s1;
|
|
2106
|
-
p3 += s3;
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
} else {
|
|
2110
|
-
if (p1 == p3) { // inplace case
|
|
2111
|
-
for (i = 0; i < n; i++) {
|
|
2112
|
-
check_intdivzero(*(dtype*)p2);
|
|
2113
|
-
*(dtype*)p1 = m_mod(*(dtype*)p1, *(dtype*)p2);
|
|
2114
|
-
p1 += s1;
|
|
2115
|
-
p2 += s2;
|
|
1754
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1755
|
+
x = m_reciprocal(x);
|
|
1756
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2116
1757
|
}
|
|
2117
1758
|
} else {
|
|
2118
1759
|
for (i = 0; i < n; i++) {
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
p2 += s2;
|
|
2123
|
-
p3 += s3;
|
|
1760
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1761
|
+
x = m_reciprocal(x);
|
|
1762
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2124
1763
|
}
|
|
2125
1764
|
}
|
|
2126
|
-
}
|
|
2127
|
-
|
|
2128
|
-
return;
|
|
2129
|
-
//
|
|
2130
|
-
}
|
|
2131
|
-
#undef check_intdivzero
|
|
2132
|
-
|
|
2133
|
-
static VALUE int8_mod_self(VALUE self, VALUE other) {
|
|
2134
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2135
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2136
|
-
ndfunc_t ndf = { iter_int8_mod, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2137
|
-
|
|
2138
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
|
-
/*
|
|
2142
|
-
Binary mod.
|
|
2143
|
-
@overload % other
|
|
2144
|
-
@param [Numo::NArray,Numeric] other
|
|
2145
|
-
@return [Numo::NArray] self % other
|
|
2146
|
-
*/
|
|
2147
|
-
static VALUE int8_mod(VALUE self, VALUE other) {
|
|
2148
|
-
|
|
2149
|
-
VALUE klass, v;
|
|
2150
|
-
|
|
2151
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2152
|
-
if (klass == cT) {
|
|
2153
|
-
return int8_mod_self(self, other);
|
|
2154
|
-
} else {
|
|
2155
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2156
|
-
return rb_funcall(v, '%', 1, other);
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
static void iter_int8_divmod(na_loop_t* const lp) {
|
|
2161
|
-
size_t i, n;
|
|
2162
|
-
char *p1, *p2, *p3, *p4;
|
|
2163
|
-
ssize_t s1, s2, s3, s4;
|
|
2164
|
-
dtype x, y, a, b;
|
|
2165
|
-
INIT_COUNTER(lp, n);
|
|
2166
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2167
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2168
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2169
|
-
INIT_PTR(lp, 3, p4, s4);
|
|
2170
|
-
for (i = n; i--;) {
|
|
2171
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2172
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2173
|
-
if (y == 0) {
|
|
2174
|
-
lp->err_type = rb_eZeroDivError;
|
|
2175
|
-
return;
|
|
2176
|
-
}
|
|
2177
|
-
m_divmod(x, y, a, b);
|
|
2178
|
-
SET_DATA_STRIDE(p3, s3, dtype, a);
|
|
2179
|
-
SET_DATA_STRIDE(p4, s4, dtype, b);
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2183
|
-
static VALUE int8_divmod_self(VALUE self, VALUE other) {
|
|
2184
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2185
|
-
ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
|
|
2186
|
-
ndfunc_t ndf = { iter_int8_divmod, STRIDE_LOOP, 2, 2, ain, aout };
|
|
2187
|
-
|
|
2188
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2189
|
-
}
|
|
2190
|
-
|
|
2191
|
-
/*
|
|
2192
|
-
Binary divmod.
|
|
2193
|
-
@overload divmod other
|
|
2194
|
-
@param [Numo::NArray,Numeric] other
|
|
2195
|
-
@return [Numo::NArray] divmod of self and other.
|
|
2196
|
-
*/
|
|
2197
|
-
static VALUE int8_divmod(VALUE self, VALUE other) {
|
|
2198
|
-
|
|
2199
|
-
VALUE klass, v;
|
|
2200
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2201
|
-
if (klass == cT) {
|
|
2202
|
-
return int8_divmod_self(self, other);
|
|
2203
|
-
} else {
|
|
2204
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2205
|
-
return rb_funcall(v, id_divmod, 1, other);
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
|
|
2209
|
-
static void iter_int8_pow(na_loop_t* const lp) {
|
|
2210
|
-
size_t i;
|
|
2211
|
-
char *p1, *p2, *p3;
|
|
2212
|
-
ssize_t s1, s2, s3;
|
|
2213
|
-
dtype x, y;
|
|
2214
|
-
INIT_COUNTER(lp, i);
|
|
2215
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2216
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2217
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2218
|
-
for (; i--;) {
|
|
2219
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2220
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2221
|
-
x = m_pow(x, y);
|
|
2222
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
static void iter_int8_pow_int32(na_loop_t* const lp) {
|
|
2227
|
-
size_t i;
|
|
2228
|
-
char *p1, *p2, *p3;
|
|
2229
|
-
ssize_t s1, s2, s3;
|
|
2230
|
-
dtype x;
|
|
2231
|
-
int32_t y;
|
|
2232
|
-
INIT_COUNTER(lp, i);
|
|
2233
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2234
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2235
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2236
|
-
for (; i--;) {
|
|
2237
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2238
|
-
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
2239
|
-
x = m_pow_int(x, y);
|
|
2240
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
|
|
2244
|
-
static VALUE int8_pow_self(VALUE self, VALUE other) {
|
|
2245
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2246
|
-
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
2247
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2248
|
-
ndfunc_t ndf = { iter_int8_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2249
|
-
ndfunc_t ndf_i = { iter_int8_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
2250
|
-
|
|
2251
|
-
// fixme : use na.integer?
|
|
2252
|
-
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
2253
|
-
return na_ndloop(&ndf_i, 2, self, other);
|
|
2254
|
-
} else {
|
|
2255
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
|
|
2259
|
-
/*
|
|
2260
|
-
Binary power.
|
|
2261
|
-
@overload ** other
|
|
2262
|
-
@param [Numo::NArray,Numeric] other
|
|
2263
|
-
@return [Numo::NArray] self to the other-th power.
|
|
2264
|
-
*/
|
|
2265
|
-
static VALUE int8_pow(VALUE self, VALUE other) {
|
|
2266
|
-
|
|
2267
|
-
VALUE klass, v;
|
|
2268
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2269
|
-
if (klass == cT) {
|
|
2270
|
-
return int8_pow_self(self, other);
|
|
2271
1765
|
} else {
|
|
2272
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2273
|
-
return rb_funcall(v, id_pow, 1, other);
|
|
2274
|
-
}
|
|
2275
|
-
}
|
|
2276
|
-
|
|
2277
|
-
static void iter_int8_minus(na_loop_t* const lp) {
|
|
2278
|
-
size_t i, n;
|
|
2279
|
-
char *p1, *p2;
|
|
2280
|
-
ssize_t s1, s2;
|
|
2281
|
-
size_t *idx1, *idx2;
|
|
2282
|
-
dtype x;
|
|
2283
|
-
|
|
2284
|
-
INIT_COUNTER(lp, n);
|
|
2285
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2286
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2287
|
-
|
|
2288
|
-
if (idx1) {
|
|
2289
1766
|
if (idx2) {
|
|
2290
1767
|
for (i = 0; i < n; i++) {
|
|
2291
|
-
|
|
2292
|
-
x =
|
|
1768
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1769
|
+
x = m_reciprocal(x);
|
|
2293
1770
|
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2294
1771
|
}
|
|
2295
1772
|
} else {
|
|
2296
|
-
|
|
2297
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2298
|
-
x = m_minus(x);
|
|
2299
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
} else {
|
|
2303
|
-
if (idx2) {
|
|
2304
|
-
for (i = 0; i < n; i++) {
|
|
2305
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2306
|
-
x = m_minus(x);
|
|
2307
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2308
|
-
}
|
|
2309
|
-
} else {
|
|
2310
|
-
//
|
|
2311
|
-
for (i = 0; i < n; i++) {
|
|
2312
|
-
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
2313
|
-
p1 += s1;
|
|
2314
|
-
p2 += s2;
|
|
2315
|
-
}
|
|
2316
|
-
return;
|
|
2317
|
-
//
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
/*
|
|
2323
|
-
Unary minus.
|
|
2324
|
-
@overload -@
|
|
2325
|
-
@return [Numo::Int8] minus of self.
|
|
2326
|
-
*/
|
|
2327
|
-
static VALUE int8_minus(VALUE self) {
|
|
2328
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2329
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2330
|
-
ndfunc_t ndf = { iter_int8_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
2331
|
-
|
|
2332
|
-
return na_ndloop(&ndf, 1, self);
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
static void iter_int8_reciprocal(na_loop_t* const lp) {
|
|
2336
|
-
size_t i, n;
|
|
2337
|
-
char *p1, *p2;
|
|
2338
|
-
ssize_t s1, s2;
|
|
2339
|
-
size_t *idx1, *idx2;
|
|
2340
|
-
dtype x;
|
|
2341
|
-
|
|
2342
|
-
INIT_COUNTER(lp, n);
|
|
2343
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2344
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2345
|
-
|
|
2346
|
-
if (idx1) {
|
|
2347
|
-
if (idx2) {
|
|
2348
|
-
for (i = 0; i < n; i++) {
|
|
2349
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2350
|
-
x = m_reciprocal(x);
|
|
2351
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2352
|
-
}
|
|
2353
|
-
} else {
|
|
2354
|
-
for (i = 0; i < n; i++) {
|
|
2355
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2356
|
-
x = m_reciprocal(x);
|
|
2357
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
} else {
|
|
2361
|
-
if (idx2) {
|
|
2362
|
-
for (i = 0; i < n; i++) {
|
|
2363
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2364
|
-
x = m_reciprocal(x);
|
|
2365
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2366
|
-
}
|
|
2367
|
-
} else {
|
|
2368
|
-
//
|
|
1773
|
+
//
|
|
2369
1774
|
for (i = 0; i < n; i++) {
|
|
2370
1775
|
*(dtype*)p2 = m_reciprocal(*(dtype*)p1);
|
|
2371
1776
|
p1 += s1;
|
|
2372
|
-
p2 += s2;
|
|
2373
|
-
}
|
|
2374
|
-
return;
|
|
2375
|
-
//
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
/*
|
|
2381
|
-
Unary reciprocal.
|
|
2382
|
-
@overload reciprocal
|
|
2383
|
-
@return [Numo::Int8] reciprocal of self.
|
|
2384
|
-
*/
|
|
2385
|
-
static VALUE int8_reciprocal(VALUE self) {
|
|
2386
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2387
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2388
|
-
ndfunc_t ndf = { iter_int8_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
2389
|
-
|
|
2390
|
-
return na_ndloop(&ndf, 1, self);
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
static void iter_int8_sign(na_loop_t* const lp) {
|
|
2394
|
-
size_t i, n;
|
|
2395
|
-
char *p1, *p2;
|
|
2396
|
-
ssize_t s1, s2;
|
|
2397
|
-
size_t *idx1, *idx2;
|
|
2398
|
-
dtype x;
|
|
2399
|
-
|
|
2400
|
-
INIT_COUNTER(lp, n);
|
|
2401
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2402
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2403
|
-
|
|
2404
|
-
if (idx1) {
|
|
2405
|
-
if (idx2) {
|
|
2406
|
-
for (i = 0; i < n; i++) {
|
|
2407
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2408
|
-
x = m_sign(x);
|
|
2409
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2410
|
-
}
|
|
2411
|
-
} else {
|
|
2412
|
-
for (i = 0; i < n; i++) {
|
|
2413
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2414
|
-
x = m_sign(x);
|
|
2415
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
} else {
|
|
2419
|
-
if (idx2) {
|
|
2420
|
-
for (i = 0; i < n; i++) {
|
|
2421
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2422
|
-
x = m_sign(x);
|
|
2423
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2424
|
-
}
|
|
2425
|
-
} else {
|
|
2426
|
-
//
|
|
2427
|
-
for (i = 0; i < n; i++) {
|
|
2428
|
-
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
2429
|
-
p1 += s1;
|
|
2430
|
-
p2 += s2;
|
|
2431
|
-
}
|
|
2432
|
-
return;
|
|
2433
|
-
//
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
|
|
2438
|
-
/*
|
|
2439
|
-
Unary sign.
|
|
2440
|
-
@overload sign
|
|
2441
|
-
@return [Numo::Int8] sign of self.
|
|
2442
|
-
*/
|
|
2443
|
-
static VALUE int8_sign(VALUE self) {
|
|
2444
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2445
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2446
|
-
ndfunc_t ndf = { iter_int8_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
2447
|
-
|
|
2448
|
-
return na_ndloop(&ndf, 1, self);
|
|
2449
|
-
}
|
|
2450
|
-
|
|
2451
|
-
static void iter_int8_square(na_loop_t* const lp) {
|
|
2452
|
-
size_t i, n;
|
|
2453
|
-
char *p1, *p2;
|
|
2454
|
-
ssize_t s1, s2;
|
|
2455
|
-
size_t *idx1, *idx2;
|
|
2456
|
-
dtype x;
|
|
2457
|
-
|
|
2458
|
-
INIT_COUNTER(lp, n);
|
|
2459
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2460
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2461
|
-
|
|
2462
|
-
if (idx1) {
|
|
2463
|
-
if (idx2) {
|
|
2464
|
-
for (i = 0; i < n; i++) {
|
|
2465
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2466
|
-
x = m_square(x);
|
|
2467
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2468
|
-
}
|
|
2469
|
-
} else {
|
|
2470
|
-
for (i = 0; i < n; i++) {
|
|
2471
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2472
|
-
x = m_square(x);
|
|
2473
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
} else {
|
|
2477
|
-
if (idx2) {
|
|
2478
|
-
for (i = 0; i < n; i++) {
|
|
2479
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2480
|
-
x = m_square(x);
|
|
2481
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2482
|
-
}
|
|
2483
|
-
} else {
|
|
2484
|
-
//
|
|
2485
|
-
for (i = 0; i < n; i++) {
|
|
2486
|
-
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
2487
|
-
p1 += s1;
|
|
2488
|
-
p2 += s2;
|
|
2489
|
-
}
|
|
2490
|
-
return;
|
|
2491
|
-
//
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
|
|
2496
|
-
/*
|
|
2497
|
-
Unary square.
|
|
2498
|
-
@overload square
|
|
2499
|
-
@return [Numo::Int8] square of self.
|
|
2500
|
-
*/
|
|
2501
|
-
static VALUE int8_square(VALUE self) {
|
|
2502
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2503
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2504
|
-
ndfunc_t ndf = { iter_int8_square, FULL_LOOP, 1, 1, ain, aout };
|
|
2505
|
-
|
|
2506
|
-
return na_ndloop(&ndf, 1, self);
|
|
2507
|
-
}
|
|
2508
|
-
|
|
2509
|
-
static void iter_int8_eq(na_loop_t* const lp) {
|
|
2510
|
-
size_t i;
|
|
2511
|
-
char *p1, *p2;
|
|
2512
|
-
BIT_DIGIT* a3;
|
|
2513
|
-
size_t p3;
|
|
2514
|
-
ssize_t s1, s2, s3;
|
|
2515
|
-
dtype x, y;
|
|
2516
|
-
BIT_DIGIT b;
|
|
2517
|
-
INIT_COUNTER(lp, i);
|
|
2518
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2519
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2520
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2521
|
-
for (; i--;) {
|
|
2522
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2523
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2524
|
-
b = (m_eq(x, y)) ? 1 : 0;
|
|
2525
|
-
STORE_BIT(a3, p3, b);
|
|
2526
|
-
p3 += s3;
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2529
|
-
|
|
2530
|
-
static VALUE int8_eq_self(VALUE self, VALUE other) {
|
|
2531
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2532
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2533
|
-
ndfunc_t ndf = { iter_int8_eq, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2534
|
-
|
|
2535
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2536
|
-
}
|
|
2537
|
-
|
|
2538
|
-
/*
|
|
2539
|
-
Comparison eq other.
|
|
2540
|
-
@overload eq other
|
|
2541
|
-
@param [Numo::NArray,Numeric] other
|
|
2542
|
-
@return [Numo::Bit] result of self eq other.
|
|
2543
|
-
*/
|
|
2544
|
-
static VALUE int8_eq(VALUE self, VALUE other) {
|
|
2545
|
-
|
|
2546
|
-
VALUE klass, v;
|
|
2547
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2548
|
-
if (klass == cT) {
|
|
2549
|
-
return int8_eq_self(self, other);
|
|
2550
|
-
} else {
|
|
2551
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2552
|
-
return rb_funcall(v, id_eq, 1, other);
|
|
2553
|
-
}
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
static void iter_int8_ne(na_loop_t* const lp) {
|
|
2557
|
-
size_t i;
|
|
2558
|
-
char *p1, *p2;
|
|
2559
|
-
BIT_DIGIT* a3;
|
|
2560
|
-
size_t p3;
|
|
2561
|
-
ssize_t s1, s2, s3;
|
|
2562
|
-
dtype x, y;
|
|
2563
|
-
BIT_DIGIT b;
|
|
2564
|
-
INIT_COUNTER(lp, i);
|
|
2565
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2566
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2567
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
2568
|
-
for (; i--;) {
|
|
2569
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2570
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2571
|
-
b = (m_ne(x, y)) ? 1 : 0;
|
|
2572
|
-
STORE_BIT(a3, p3, b);
|
|
2573
|
-
p3 += s3;
|
|
2574
|
-
}
|
|
2575
|
-
}
|
|
2576
|
-
|
|
2577
|
-
static VALUE int8_ne_self(VALUE self, VALUE other) {
|
|
2578
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2579
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
2580
|
-
ndfunc_t ndf = { iter_int8_ne, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2581
|
-
|
|
2582
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2583
|
-
}
|
|
2584
|
-
|
|
2585
|
-
/*
|
|
2586
|
-
Comparison ne other.
|
|
2587
|
-
@overload ne other
|
|
2588
|
-
@param [Numo::NArray,Numeric] other
|
|
2589
|
-
@return [Numo::Bit] result of self ne other.
|
|
2590
|
-
*/
|
|
2591
|
-
static VALUE int8_ne(VALUE self, VALUE other) {
|
|
2592
|
-
|
|
2593
|
-
VALUE klass, v;
|
|
2594
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2595
|
-
if (klass == cT) {
|
|
2596
|
-
return int8_ne_self(self, other);
|
|
2597
|
-
} else {
|
|
2598
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2599
|
-
return rb_funcall(v, id_ne, 1, other);
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
|
|
2603
|
-
#define check_intdivzero(y) \
|
|
2604
|
-
{}
|
|
2605
|
-
|
|
2606
|
-
static void iter_int8_bit_and(na_loop_t* const lp) {
|
|
2607
|
-
size_t i = 0;
|
|
2608
|
-
size_t n;
|
|
2609
|
-
char *p1, *p2, *p3;
|
|
2610
|
-
ssize_t s1, s2, s3;
|
|
2611
|
-
|
|
2612
|
-
INIT_COUNTER(lp, n);
|
|
2613
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2614
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2615
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2616
|
-
|
|
2617
|
-
//
|
|
2618
|
-
|
|
2619
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2620
|
-
check_intdivzero(*(dtype*)p2);
|
|
2621
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2622
|
-
if (p1 == p3) { // inplace case
|
|
2623
|
-
for (; i < n; i++) {
|
|
2624
|
-
((dtype*)p1)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2625
|
-
}
|
|
2626
|
-
} else {
|
|
2627
|
-
for (; i < n; i++) {
|
|
2628
|
-
((dtype*)p3)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
|
|
2629
|
-
}
|
|
2630
|
-
}
|
|
2631
|
-
} else {
|
|
2632
|
-
for (i = 0; i < n; i++) {
|
|
2633
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2634
|
-
p1 += s1;
|
|
2635
|
-
p3 += s3;
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
} else {
|
|
2639
|
-
if (p1 == p3) { // inplace case
|
|
2640
|
-
for (i = 0; i < n; i++) {
|
|
2641
|
-
check_intdivzero(*(dtype*)p2);
|
|
2642
|
-
*(dtype*)p1 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2643
|
-
p1 += s1;
|
|
2644
|
-
p2 += s2;
|
|
2645
|
-
}
|
|
2646
|
-
} else {
|
|
2647
|
-
for (i = 0; i < n; i++) {
|
|
2648
|
-
check_intdivzero(*(dtype*)p2);
|
|
2649
|
-
*(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
|
|
2650
|
-
p1 += s1;
|
|
2651
|
-
p2 += s2;
|
|
2652
|
-
p3 += s3;
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
return;
|
|
2658
|
-
//
|
|
2659
|
-
}
|
|
2660
|
-
#undef check_intdivzero
|
|
2661
|
-
|
|
2662
|
-
static VALUE int8_bit_and_self(VALUE self, VALUE other) {
|
|
2663
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2664
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2665
|
-
ndfunc_t ndf = { iter_int8_bit_and, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2666
|
-
|
|
2667
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
/*
|
|
2671
|
-
Binary bit_and.
|
|
2672
|
-
@overload & other
|
|
2673
|
-
@param [Numo::NArray,Numeric] other
|
|
2674
|
-
@return [Numo::NArray] self & other
|
|
2675
|
-
*/
|
|
2676
|
-
static VALUE int8_bit_and(VALUE self, VALUE other) {
|
|
2677
|
-
|
|
2678
|
-
VALUE klass, v;
|
|
2679
|
-
|
|
2680
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2681
|
-
if (klass == cT) {
|
|
2682
|
-
return int8_bit_and_self(self, other);
|
|
2683
|
-
} else {
|
|
2684
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2685
|
-
return rb_funcall(v, '&', 1, other);
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
|
|
2689
|
-
#define check_intdivzero(y) \
|
|
2690
|
-
{}
|
|
2691
|
-
|
|
2692
|
-
static void iter_int8_bit_or(na_loop_t* const lp) {
|
|
2693
|
-
size_t i = 0;
|
|
2694
|
-
size_t n;
|
|
2695
|
-
char *p1, *p2, *p3;
|
|
2696
|
-
ssize_t s1, s2, s3;
|
|
2697
|
-
|
|
2698
|
-
INIT_COUNTER(lp, n);
|
|
2699
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2700
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2701
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2702
|
-
|
|
2703
|
-
//
|
|
2704
|
-
|
|
2705
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2706
|
-
check_intdivzero(*(dtype*)p2);
|
|
2707
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2708
|
-
if (p1 == p3) { // inplace case
|
|
2709
|
-
for (; i < n; i++) {
|
|
2710
|
-
((dtype*)p1)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
2711
|
-
}
|
|
2712
|
-
} else {
|
|
2713
|
-
for (; i < n; i++) {
|
|
2714
|
-
((dtype*)p3)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
|
|
2715
|
-
}
|
|
2716
|
-
}
|
|
2717
|
-
} else {
|
|
2718
|
-
for (i = 0; i < n; i++) {
|
|
2719
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2720
|
-
p1 += s1;
|
|
2721
|
-
p3 += s3;
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
} else {
|
|
2725
|
-
if (p1 == p3) { // inplace case
|
|
2726
|
-
for (i = 0; i < n; i++) {
|
|
2727
|
-
check_intdivzero(*(dtype*)p2);
|
|
2728
|
-
*(dtype*)p1 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2729
|
-
p1 += s1;
|
|
2730
|
-
p2 += s2;
|
|
2731
|
-
}
|
|
2732
|
-
} else {
|
|
2733
|
-
for (i = 0; i < n; i++) {
|
|
2734
|
-
check_intdivzero(*(dtype*)p2);
|
|
2735
|
-
*(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
|
|
2736
|
-
p1 += s1;
|
|
2737
|
-
p2 += s2;
|
|
2738
|
-
p3 += s3;
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
|
|
2743
|
-
return;
|
|
2744
|
-
//
|
|
2745
|
-
}
|
|
2746
|
-
#undef check_intdivzero
|
|
2747
|
-
|
|
2748
|
-
static VALUE int8_bit_or_self(VALUE self, VALUE other) {
|
|
2749
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2750
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2751
|
-
ndfunc_t ndf = { iter_int8_bit_or, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2752
|
-
|
|
2753
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2754
|
-
}
|
|
2755
|
-
|
|
2756
|
-
/*
|
|
2757
|
-
Binary bit_or.
|
|
2758
|
-
@overload | other
|
|
2759
|
-
@param [Numo::NArray,Numeric] other
|
|
2760
|
-
@return [Numo::NArray] self | other
|
|
2761
|
-
*/
|
|
2762
|
-
static VALUE int8_bit_or(VALUE self, VALUE other) {
|
|
2763
|
-
|
|
2764
|
-
VALUE klass, v;
|
|
2765
|
-
|
|
2766
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2767
|
-
if (klass == cT) {
|
|
2768
|
-
return int8_bit_or_self(self, other);
|
|
2769
|
-
} else {
|
|
2770
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2771
|
-
return rb_funcall(v, '|', 1, other);
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
|
|
2775
|
-
#define check_intdivzero(y) \
|
|
2776
|
-
{}
|
|
2777
|
-
|
|
2778
|
-
static void iter_int8_bit_xor(na_loop_t* const lp) {
|
|
2779
|
-
size_t i = 0;
|
|
2780
|
-
size_t n;
|
|
2781
|
-
char *p1, *p2, *p3;
|
|
2782
|
-
ssize_t s1, s2, s3;
|
|
2783
|
-
|
|
2784
|
-
INIT_COUNTER(lp, n);
|
|
2785
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2786
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2787
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2788
|
-
|
|
2789
|
-
//
|
|
2790
|
-
|
|
2791
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2792
|
-
check_intdivzero(*(dtype*)p2);
|
|
2793
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2794
|
-
if (p1 == p3) { // inplace case
|
|
2795
|
-
for (; i < n; i++) {
|
|
2796
|
-
((dtype*)p1)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
2797
|
-
}
|
|
2798
|
-
} else {
|
|
2799
|
-
for (; i < n; i++) {
|
|
2800
|
-
((dtype*)p3)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
|
|
2801
|
-
}
|
|
2802
|
-
}
|
|
2803
|
-
} else {
|
|
2804
|
-
for (i = 0; i < n; i++) {
|
|
2805
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2806
|
-
p1 += s1;
|
|
2807
|
-
p3 += s3;
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2810
|
-
} else {
|
|
2811
|
-
if (p1 == p3) { // inplace case
|
|
2812
|
-
for (i = 0; i < n; i++) {
|
|
2813
|
-
check_intdivzero(*(dtype*)p2);
|
|
2814
|
-
*(dtype*)p1 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2815
|
-
p1 += s1;
|
|
2816
|
-
p2 += s2;
|
|
2817
|
-
}
|
|
2818
|
-
} else {
|
|
2819
|
-
for (i = 0; i < n; i++) {
|
|
2820
|
-
check_intdivzero(*(dtype*)p2);
|
|
2821
|
-
*(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
|
|
2822
|
-
p1 += s1;
|
|
2823
|
-
p2 += s2;
|
|
2824
|
-
p3 += s3;
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
}
|
|
2828
|
-
|
|
2829
|
-
return;
|
|
2830
|
-
//
|
|
2831
|
-
}
|
|
2832
|
-
#undef check_intdivzero
|
|
2833
|
-
|
|
2834
|
-
static VALUE int8_bit_xor_self(VALUE self, VALUE other) {
|
|
2835
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2836
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2837
|
-
ndfunc_t ndf = { iter_int8_bit_xor, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2838
|
-
|
|
2839
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2840
|
-
}
|
|
2841
|
-
|
|
2842
|
-
/*
|
|
2843
|
-
Binary bit_xor.
|
|
2844
|
-
@overload ^ other
|
|
2845
|
-
@param [Numo::NArray,Numeric] other
|
|
2846
|
-
@return [Numo::NArray] self ^ other
|
|
2847
|
-
*/
|
|
2848
|
-
static VALUE int8_bit_xor(VALUE self, VALUE other) {
|
|
2849
|
-
|
|
2850
|
-
VALUE klass, v;
|
|
2851
|
-
|
|
2852
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2853
|
-
if (klass == cT) {
|
|
2854
|
-
return int8_bit_xor_self(self, other);
|
|
2855
|
-
} else {
|
|
2856
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2857
|
-
return rb_funcall(v, '^', 1, other);
|
|
2858
|
-
}
|
|
2859
|
-
}
|
|
2860
|
-
|
|
2861
|
-
static void iter_int8_bit_not(na_loop_t* const lp) {
|
|
2862
|
-
size_t i, n;
|
|
2863
|
-
char *p1, *p2;
|
|
2864
|
-
ssize_t s1, s2;
|
|
2865
|
-
size_t *idx1, *idx2;
|
|
2866
|
-
dtype x;
|
|
2867
|
-
|
|
2868
|
-
INIT_COUNTER(lp, n);
|
|
2869
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2870
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2871
|
-
|
|
2872
|
-
if (idx1) {
|
|
2873
|
-
if (idx2) {
|
|
2874
|
-
for (i = 0; i < n; i++) {
|
|
2875
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2876
|
-
x = m_bit_not(x);
|
|
2877
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2878
|
-
}
|
|
2879
|
-
} else {
|
|
2880
|
-
for (i = 0; i < n; i++) {
|
|
2881
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2882
|
-
x = m_bit_not(x);
|
|
2883
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
2886
|
-
} else {
|
|
2887
|
-
if (idx2) {
|
|
2888
|
-
for (i = 0; i < n; i++) {
|
|
2889
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2890
|
-
x = m_bit_not(x);
|
|
2891
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2892
|
-
}
|
|
2893
|
-
} else {
|
|
2894
|
-
//
|
|
2895
|
-
for (i = 0; i < n; i++) {
|
|
2896
|
-
*(dtype*)p2 = m_bit_not(*(dtype*)p1);
|
|
2897
|
-
p1 += s1;
|
|
2898
|
-
p2 += s2;
|
|
2899
|
-
}
|
|
2900
|
-
return;
|
|
2901
|
-
//
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
|
|
2906
|
-
/*
|
|
2907
|
-
Unary bit_not.
|
|
2908
|
-
@overload ~
|
|
2909
|
-
@return [Numo::Int8] bit_not of self.
|
|
2910
|
-
*/
|
|
2911
|
-
static VALUE int8_bit_not(VALUE self) {
|
|
2912
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2913
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2914
|
-
ndfunc_t ndf = { iter_int8_bit_not, FULL_LOOP, 1, 1, ain, aout };
|
|
2915
|
-
|
|
2916
|
-
return na_ndloop(&ndf, 1, self);
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
|
-
#define check_intdivzero(y) \
|
|
2920
|
-
{}
|
|
2921
|
-
|
|
2922
|
-
static void iter_int8_left_shift(na_loop_t* const lp) {
|
|
2923
|
-
size_t i = 0;
|
|
2924
|
-
size_t n;
|
|
2925
|
-
char *p1, *p2, *p3;
|
|
2926
|
-
ssize_t s1, s2, s3;
|
|
2927
|
-
|
|
2928
|
-
INIT_COUNTER(lp, n);
|
|
2929
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2930
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2931
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2932
|
-
|
|
2933
|
-
//
|
|
2934
|
-
|
|
2935
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2936
|
-
check_intdivzero(*(dtype*)p2);
|
|
2937
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2938
|
-
if (p1 == p3) { // inplace case
|
|
2939
|
-
for (; i < n; i++) {
|
|
2940
|
-
((dtype*)p1)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
2941
|
-
}
|
|
2942
|
-
} else {
|
|
2943
|
-
for (; i < n; i++) {
|
|
2944
|
-
((dtype*)p3)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
} else {
|
|
2948
|
-
for (i = 0; i < n; i++) {
|
|
2949
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2950
|
-
p1 += s1;
|
|
2951
|
-
p3 += s3;
|
|
2952
|
-
}
|
|
2953
|
-
}
|
|
2954
|
-
} else {
|
|
2955
|
-
if (p1 == p3) { // inplace case
|
|
2956
|
-
for (i = 0; i < n; i++) {
|
|
2957
|
-
check_intdivzero(*(dtype*)p2);
|
|
2958
|
-
*(dtype*)p1 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2959
|
-
p1 += s1;
|
|
2960
|
-
p2 += s2;
|
|
2961
|
-
}
|
|
2962
|
-
} else {
|
|
2963
|
-
for (i = 0; i < n; i++) {
|
|
2964
|
-
check_intdivzero(*(dtype*)p2);
|
|
2965
|
-
*(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
|
|
2966
|
-
p1 += s1;
|
|
2967
|
-
p2 += s2;
|
|
2968
|
-
p3 += s3;
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
|
|
2973
|
-
return;
|
|
2974
|
-
//
|
|
2975
|
-
}
|
|
2976
|
-
#undef check_intdivzero
|
|
2977
|
-
|
|
2978
|
-
static VALUE int8_left_shift_self(VALUE self, VALUE other) {
|
|
2979
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2980
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2981
|
-
ndfunc_t ndf = { iter_int8_left_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2982
|
-
|
|
2983
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2984
|
-
}
|
|
2985
|
-
|
|
2986
|
-
/*
|
|
2987
|
-
Binary left_shift.
|
|
2988
|
-
@overload << other
|
|
2989
|
-
@param [Numo::NArray,Numeric] other
|
|
2990
|
-
@return [Numo::NArray] self << other
|
|
2991
|
-
*/
|
|
2992
|
-
static VALUE int8_left_shift(VALUE self, VALUE other) {
|
|
2993
|
-
|
|
2994
|
-
VALUE klass, v;
|
|
2995
|
-
|
|
2996
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2997
|
-
if (klass == cT) {
|
|
2998
|
-
return int8_left_shift_self(self, other);
|
|
2999
|
-
} else {
|
|
3000
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3001
|
-
return rb_funcall(v, id_left_shift, 1, other);
|
|
3002
|
-
}
|
|
3003
|
-
}
|
|
3004
|
-
|
|
3005
|
-
#define check_intdivzero(y) \
|
|
3006
|
-
{}
|
|
3007
|
-
|
|
3008
|
-
static void iter_int8_right_shift(na_loop_t* const lp) {
|
|
3009
|
-
size_t i = 0;
|
|
3010
|
-
size_t n;
|
|
3011
|
-
char *p1, *p2, *p3;
|
|
3012
|
-
ssize_t s1, s2, s3;
|
|
3013
|
-
|
|
3014
|
-
INIT_COUNTER(lp, n);
|
|
3015
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3016
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3017
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3018
|
-
|
|
3019
|
-
//
|
|
3020
|
-
|
|
3021
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
3022
|
-
check_intdivzero(*(dtype*)p2);
|
|
3023
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
3024
|
-
if (p1 == p3) { // inplace case
|
|
3025
|
-
for (; i < n; i++) {
|
|
3026
|
-
((dtype*)p1)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3027
|
-
}
|
|
3028
|
-
} else {
|
|
3029
|
-
for (; i < n; i++) {
|
|
3030
|
-
((dtype*)p3)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
|
|
3031
|
-
}
|
|
3032
|
-
}
|
|
3033
|
-
} else {
|
|
3034
|
-
for (i = 0; i < n; i++) {
|
|
3035
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3036
|
-
p1 += s1;
|
|
3037
|
-
p3 += s3;
|
|
3038
|
-
}
|
|
3039
|
-
}
|
|
3040
|
-
} else {
|
|
3041
|
-
if (p1 == p3) { // inplace case
|
|
3042
|
-
for (i = 0; i < n; i++) {
|
|
3043
|
-
check_intdivzero(*(dtype*)p2);
|
|
3044
|
-
*(dtype*)p1 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3045
|
-
p1 += s1;
|
|
3046
|
-
p2 += s2;
|
|
3047
|
-
}
|
|
3048
|
-
} else {
|
|
3049
|
-
for (i = 0; i < n; i++) {
|
|
3050
|
-
check_intdivzero(*(dtype*)p2);
|
|
3051
|
-
*(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
|
|
3052
|
-
p1 += s1;
|
|
3053
|
-
p2 += s2;
|
|
3054
|
-
p3 += s3;
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
|
|
3059
|
-
return;
|
|
3060
|
-
//
|
|
3061
|
-
}
|
|
3062
|
-
#undef check_intdivzero
|
|
3063
|
-
|
|
3064
|
-
static VALUE int8_right_shift_self(VALUE self, VALUE other) {
|
|
3065
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3066
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3067
|
-
ndfunc_t ndf = { iter_int8_right_shift, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3068
|
-
|
|
3069
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3070
|
-
}
|
|
3071
|
-
|
|
3072
|
-
/*
|
|
3073
|
-
Binary right_shift.
|
|
3074
|
-
@overload >> other
|
|
3075
|
-
@param [Numo::NArray,Numeric] other
|
|
3076
|
-
@return [Numo::NArray] self >> other
|
|
3077
|
-
*/
|
|
3078
|
-
static VALUE int8_right_shift(VALUE self, VALUE other) {
|
|
3079
|
-
|
|
3080
|
-
VALUE klass, v;
|
|
3081
|
-
|
|
3082
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3083
|
-
if (klass == cT) {
|
|
3084
|
-
return int8_right_shift_self(self, other);
|
|
3085
|
-
} else {
|
|
3086
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3087
|
-
return rb_funcall(v, id_right_shift, 1, other);
|
|
3088
|
-
}
|
|
3089
|
-
}
|
|
3090
|
-
|
|
3091
|
-
static void iter_int8_gt(na_loop_t* const lp) {
|
|
3092
|
-
size_t i;
|
|
3093
|
-
char *p1, *p2;
|
|
3094
|
-
BIT_DIGIT* a3;
|
|
3095
|
-
size_t p3;
|
|
3096
|
-
ssize_t s1, s2, s3;
|
|
3097
|
-
dtype x, y;
|
|
3098
|
-
BIT_DIGIT b;
|
|
3099
|
-
INIT_COUNTER(lp, i);
|
|
3100
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3101
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3102
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3103
|
-
for (; i--;) {
|
|
3104
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3105
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3106
|
-
b = (m_gt(x, y)) ? 1 : 0;
|
|
3107
|
-
STORE_BIT(a3, p3, b);
|
|
3108
|
-
p3 += s3;
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
|
|
3112
|
-
static VALUE int8_gt_self(VALUE self, VALUE other) {
|
|
3113
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3114
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3115
|
-
ndfunc_t ndf = { iter_int8_gt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3116
|
-
|
|
3117
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3118
|
-
}
|
|
3119
|
-
|
|
3120
|
-
/*
|
|
3121
|
-
Comparison gt other.
|
|
3122
|
-
@overload gt other
|
|
3123
|
-
@param [Numo::NArray,Numeric] other
|
|
3124
|
-
@return [Numo::Bit] result of self gt other.
|
|
3125
|
-
*/
|
|
3126
|
-
static VALUE int8_gt(VALUE self, VALUE other) {
|
|
3127
|
-
|
|
3128
|
-
VALUE klass, v;
|
|
3129
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3130
|
-
if (klass == cT) {
|
|
3131
|
-
return int8_gt_self(self, other);
|
|
3132
|
-
} else {
|
|
3133
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3134
|
-
return rb_funcall(v, id_gt, 1, other);
|
|
3135
|
-
}
|
|
3136
|
-
}
|
|
3137
|
-
|
|
3138
|
-
static void iter_int8_ge(na_loop_t* const lp) {
|
|
3139
|
-
size_t i;
|
|
3140
|
-
char *p1, *p2;
|
|
3141
|
-
BIT_DIGIT* a3;
|
|
3142
|
-
size_t p3;
|
|
3143
|
-
ssize_t s1, s2, s3;
|
|
3144
|
-
dtype x, y;
|
|
3145
|
-
BIT_DIGIT b;
|
|
3146
|
-
INIT_COUNTER(lp, i);
|
|
3147
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3148
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3149
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3150
|
-
for (; i--;) {
|
|
3151
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3152
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3153
|
-
b = (m_ge(x, y)) ? 1 : 0;
|
|
3154
|
-
STORE_BIT(a3, p3, b);
|
|
3155
|
-
p3 += s3;
|
|
3156
|
-
}
|
|
3157
|
-
}
|
|
3158
|
-
|
|
3159
|
-
static VALUE int8_ge_self(VALUE self, VALUE other) {
|
|
3160
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3161
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3162
|
-
ndfunc_t ndf = { iter_int8_ge, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3163
|
-
|
|
3164
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3165
|
-
}
|
|
3166
|
-
|
|
3167
|
-
/*
|
|
3168
|
-
Comparison ge other.
|
|
3169
|
-
@overload ge other
|
|
3170
|
-
@param [Numo::NArray,Numeric] other
|
|
3171
|
-
@return [Numo::Bit] result of self ge other.
|
|
3172
|
-
*/
|
|
3173
|
-
static VALUE int8_ge(VALUE self, VALUE other) {
|
|
3174
|
-
|
|
3175
|
-
VALUE klass, v;
|
|
3176
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3177
|
-
if (klass == cT) {
|
|
3178
|
-
return int8_ge_self(self, other);
|
|
3179
|
-
} else {
|
|
3180
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3181
|
-
return rb_funcall(v, id_ge, 1, other);
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
|
|
3185
|
-
static void iter_int8_lt(na_loop_t* const lp) {
|
|
3186
|
-
size_t i;
|
|
3187
|
-
char *p1, *p2;
|
|
3188
|
-
BIT_DIGIT* a3;
|
|
3189
|
-
size_t p3;
|
|
3190
|
-
ssize_t s1, s2, s3;
|
|
3191
|
-
dtype x, y;
|
|
3192
|
-
BIT_DIGIT b;
|
|
3193
|
-
INIT_COUNTER(lp, i);
|
|
3194
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3195
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3196
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3197
|
-
for (; i--;) {
|
|
3198
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3199
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3200
|
-
b = (m_lt(x, y)) ? 1 : 0;
|
|
3201
|
-
STORE_BIT(a3, p3, b);
|
|
3202
|
-
p3 += s3;
|
|
3203
|
-
}
|
|
3204
|
-
}
|
|
3205
|
-
|
|
3206
|
-
static VALUE int8_lt_self(VALUE self, VALUE other) {
|
|
3207
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3208
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3209
|
-
ndfunc_t ndf = { iter_int8_lt, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3210
|
-
|
|
3211
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3212
|
-
}
|
|
3213
|
-
|
|
3214
|
-
/*
|
|
3215
|
-
Comparison lt other.
|
|
3216
|
-
@overload lt other
|
|
3217
|
-
@param [Numo::NArray,Numeric] other
|
|
3218
|
-
@return [Numo::Bit] result of self lt other.
|
|
3219
|
-
*/
|
|
3220
|
-
static VALUE int8_lt(VALUE self, VALUE other) {
|
|
3221
|
-
|
|
3222
|
-
VALUE klass, v;
|
|
3223
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3224
|
-
if (klass == cT) {
|
|
3225
|
-
return int8_lt_self(self, other);
|
|
3226
|
-
} else {
|
|
3227
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3228
|
-
return rb_funcall(v, id_lt, 1, other);
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
|
-
|
|
3232
|
-
static void iter_int8_le(na_loop_t* const lp) {
|
|
3233
|
-
size_t i;
|
|
3234
|
-
char *p1, *p2;
|
|
3235
|
-
BIT_DIGIT* a3;
|
|
3236
|
-
size_t p3;
|
|
3237
|
-
ssize_t s1, s2, s3;
|
|
3238
|
-
dtype x, y;
|
|
3239
|
-
BIT_DIGIT b;
|
|
3240
|
-
INIT_COUNTER(lp, i);
|
|
3241
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3242
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3243
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3244
|
-
for (; i--;) {
|
|
3245
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3246
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3247
|
-
b = (m_le(x, y)) ? 1 : 0;
|
|
3248
|
-
STORE_BIT(a3, p3, b);
|
|
3249
|
-
p3 += s3;
|
|
3250
|
-
}
|
|
3251
|
-
}
|
|
3252
|
-
|
|
3253
|
-
static VALUE int8_le_self(VALUE self, VALUE other) {
|
|
3254
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3255
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3256
|
-
ndfunc_t ndf = { iter_int8_le, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3257
|
-
|
|
3258
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3259
|
-
}
|
|
3260
|
-
|
|
3261
|
-
/*
|
|
3262
|
-
Comparison le other.
|
|
3263
|
-
@overload le other
|
|
3264
|
-
@param [Numo::NArray,Numeric] other
|
|
3265
|
-
@return [Numo::Bit] result of self le other.
|
|
3266
|
-
*/
|
|
3267
|
-
static VALUE int8_le(VALUE self, VALUE other) {
|
|
3268
|
-
|
|
3269
|
-
VALUE klass, v;
|
|
3270
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3271
|
-
if (klass == cT) {
|
|
3272
|
-
return int8_le_self(self, other);
|
|
3273
|
-
} else {
|
|
3274
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3275
|
-
return rb_funcall(v, id_le, 1, other);
|
|
3276
|
-
}
|
|
3277
|
-
}
|
|
3278
|
-
|
|
3279
|
-
static void iter_int8_clip(na_loop_t* const lp) {
|
|
3280
|
-
size_t i;
|
|
3281
|
-
char *p1, *p2, *p3, *p4;
|
|
3282
|
-
ssize_t s1, s2, s3, s4;
|
|
3283
|
-
dtype x, min, max;
|
|
3284
|
-
INIT_COUNTER(lp, i);
|
|
3285
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3286
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3287
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3288
|
-
INIT_PTR(lp, 3, p4, s4);
|
|
3289
|
-
for (; i--;) {
|
|
3290
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3291
|
-
GET_DATA_STRIDE(p2, s2, dtype, min);
|
|
3292
|
-
GET_DATA_STRIDE(p3, s3, dtype, max);
|
|
3293
|
-
if (m_gt(min, max)) {
|
|
3294
|
-
rb_raise(nary_eOperationError, "min is greater than max");
|
|
3295
|
-
}
|
|
3296
|
-
if (m_lt(x, min)) {
|
|
3297
|
-
x = min;
|
|
3298
|
-
}
|
|
3299
|
-
if (m_gt(x, max)) {
|
|
3300
|
-
x = max;
|
|
3301
|
-
}
|
|
3302
|
-
SET_DATA_STRIDE(p4, s4, dtype, x);
|
|
3303
|
-
}
|
|
3304
|
-
}
|
|
3305
|
-
|
|
3306
|
-
static void iter_int8_clip_min(na_loop_t* const lp) {
|
|
3307
|
-
size_t i;
|
|
3308
|
-
char *p1, *p2, *p3;
|
|
3309
|
-
ssize_t s1, s2, s3;
|
|
3310
|
-
dtype x, min;
|
|
3311
|
-
INIT_COUNTER(lp, i);
|
|
3312
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3313
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3314
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3315
|
-
for (; i--;) {
|
|
3316
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3317
|
-
GET_DATA_STRIDE(p2, s2, dtype, min);
|
|
3318
|
-
if (m_lt(x, min)) {
|
|
3319
|
-
x = min;
|
|
3320
|
-
}
|
|
3321
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
3322
|
-
}
|
|
3323
|
-
}
|
|
3324
|
-
|
|
3325
|
-
static void iter_int8_clip_max(na_loop_t* const lp) {
|
|
3326
|
-
size_t i;
|
|
3327
|
-
char *p1, *p2, *p3;
|
|
3328
|
-
ssize_t s1, s2, s3;
|
|
3329
|
-
dtype x, max;
|
|
3330
|
-
INIT_COUNTER(lp, i);
|
|
3331
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3332
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3333
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3334
|
-
for (; i--;) {
|
|
3335
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3336
|
-
GET_DATA_STRIDE(p2, s2, dtype, max);
|
|
3337
|
-
if (m_gt(x, max)) {
|
|
3338
|
-
x = max;
|
|
3339
|
-
}
|
|
3340
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
|
|
3344
|
-
/*
|
|
3345
|
-
Clip array elements by [min,max].
|
|
3346
|
-
If either of min or max is nil, one side is clipped.
|
|
3347
|
-
@overload clip(min,max)
|
|
3348
|
-
@param [Numo::NArray,Numeric] min
|
|
3349
|
-
@param [Numo::NArray,Numeric] max
|
|
3350
|
-
@return [Numo::NArray] result of clip.
|
|
3351
|
-
|
|
3352
|
-
@example
|
|
3353
|
-
a = Numo::Int32.new(10).seq
|
|
3354
|
-
# => Numo::Int32#shape=[10]
|
|
3355
|
-
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
3356
|
-
|
|
3357
|
-
a.clip(1,8)
|
|
3358
|
-
# => Numo::Int32#shape=[10]
|
|
3359
|
-
# [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
3360
|
-
|
|
3361
|
-
a.inplace.clip(3,6)
|
|
3362
|
-
a
|
|
3363
|
-
# => Numo::Int32#shape=[10]
|
|
3364
|
-
# [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
|
|
3365
|
-
|
|
3366
|
-
b = Numo::Int32.new(10).seq
|
|
3367
|
-
# => Numo::Int32#shape=[10]
|
|
3368
|
-
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
3369
|
-
|
|
3370
|
-
b.clip([3,4,1,1,1,4,4,4,4,4], 8)
|
|
3371
|
-
# => Numo::Int32#shape=[10]
|
|
3372
|
-
# [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
3373
|
-
*/
|
|
3374
|
-
static VALUE int8_clip(VALUE self, VALUE min, VALUE max) {
|
|
3375
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { cT, 0 }, { cT, 0 } };
|
|
3376
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3377
|
-
ndfunc_t ndf_min = { iter_int8_clip_min, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3378
|
-
ndfunc_t ndf_max = { iter_int8_clip_max, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3379
|
-
ndfunc_t ndf_both = { iter_int8_clip, STRIDE_LOOP, 3, 1, ain, aout };
|
|
3380
|
-
|
|
3381
|
-
if (RTEST(min)) {
|
|
3382
|
-
if (RTEST(max)) {
|
|
3383
|
-
return na_ndloop(&ndf_both, 3, self, min, max);
|
|
3384
|
-
} else {
|
|
3385
|
-
return na_ndloop(&ndf_min, 2, self, min);
|
|
3386
|
-
}
|
|
3387
|
-
} else {
|
|
3388
|
-
if (RTEST(max)) {
|
|
3389
|
-
return na_ndloop(&ndf_max, 2, self, max);
|
|
3390
|
-
}
|
|
3391
|
-
}
|
|
3392
|
-
rb_raise(rb_eArgError, "min and max are not given");
|
|
3393
|
-
return Qnil;
|
|
3394
|
-
}
|
|
3395
|
-
|
|
3396
|
-
static void iter_int8_sum(na_loop_t* const lp) {
|
|
3397
|
-
size_t n;
|
|
3398
|
-
char *p1, *p2;
|
|
3399
|
-
ssize_t s1;
|
|
3400
|
-
|
|
3401
|
-
INIT_COUNTER(lp, n);
|
|
3402
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3403
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3404
|
-
|
|
3405
|
-
*(int64_t*)p2 = f_sum(n, p1, s1);
|
|
3406
|
-
}
|
|
3407
|
-
|
|
3408
|
-
/*
|
|
3409
|
-
sum of self.
|
|
3410
|
-
@overload sum(axis:nil, keepdims:false)
|
|
3411
|
-
@param [Numeric,Array,Range] axis Performs sum along the axis.
|
|
3412
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3413
|
-
dimensions with size one.
|
|
3414
|
-
@return [Numo::Int8] returns result of sum.
|
|
3415
|
-
*/
|
|
3416
|
-
static VALUE int8_sum(int argc, VALUE* argv, VALUE self) {
|
|
3417
|
-
VALUE v, reduce;
|
|
3418
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3419
|
-
ndfunc_arg_out_t aout[1] = { { numo_cInt64, 0 } };
|
|
3420
|
-
ndfunc_t ndf = { iter_int8_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3421
|
-
|
|
3422
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3423
|
-
|
|
3424
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3425
|
-
|
|
3426
|
-
return rb_funcall(v, rb_intern("extract"), 0);
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
|
-
static void iter_int8_prod(na_loop_t* const lp) {
|
|
3430
|
-
size_t n;
|
|
3431
|
-
char *p1, *p2;
|
|
3432
|
-
ssize_t s1;
|
|
3433
|
-
|
|
3434
|
-
INIT_COUNTER(lp, n);
|
|
3435
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3436
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3437
|
-
|
|
3438
|
-
*(int64_t*)p2 = f_prod(n, p1, s1);
|
|
3439
|
-
}
|
|
3440
|
-
|
|
3441
|
-
/*
|
|
3442
|
-
prod of self.
|
|
3443
|
-
@overload prod(axis:nil, keepdims:false)
|
|
3444
|
-
@param [Numeric,Array,Range] axis Performs prod along the axis.
|
|
3445
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3446
|
-
dimensions with size one.
|
|
3447
|
-
@return [Numo::Int8] returns result of prod.
|
|
3448
|
-
*/
|
|
3449
|
-
static VALUE int8_prod(int argc, VALUE* argv, VALUE self) {
|
|
3450
|
-
VALUE v, reduce;
|
|
3451
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3452
|
-
ndfunc_arg_out_t aout[1] = { { numo_cInt64, 0 } };
|
|
3453
|
-
ndfunc_t ndf = { iter_int8_prod, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3454
|
-
|
|
3455
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3456
|
-
|
|
3457
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3458
|
-
|
|
3459
|
-
return rb_funcall(v, rb_intern("extract"), 0);
|
|
3460
|
-
}
|
|
3461
|
-
|
|
3462
|
-
static void iter_int8_min(na_loop_t* const lp) {
|
|
3463
|
-
size_t n;
|
|
3464
|
-
char *p1, *p2;
|
|
3465
|
-
ssize_t s1;
|
|
3466
|
-
|
|
3467
|
-
INIT_COUNTER(lp, n);
|
|
3468
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3469
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3470
|
-
|
|
3471
|
-
*(dtype*)p2 = f_min(n, p1, s1);
|
|
3472
|
-
}
|
|
3473
|
-
|
|
3474
|
-
/*
|
|
3475
|
-
min of self.
|
|
3476
|
-
@overload min(axis:nil, keepdims:false)
|
|
3477
|
-
@param [Numeric,Array,Range] axis Performs min along the axis.
|
|
3478
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3479
|
-
dimensions with size one.
|
|
3480
|
-
@return [Numo::Int8] returns result of min.
|
|
3481
|
-
*/
|
|
3482
|
-
static VALUE int8_min(int argc, VALUE* argv, VALUE self) {
|
|
3483
|
-
VALUE v, reduce;
|
|
3484
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3485
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3486
|
-
ndfunc_t ndf = { iter_int8_min, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3487
|
-
|
|
3488
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3489
|
-
|
|
3490
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3491
|
-
|
|
3492
|
-
return int8_extract(v);
|
|
3493
|
-
}
|
|
3494
|
-
|
|
3495
|
-
static void iter_int8_max(na_loop_t* const lp) {
|
|
3496
|
-
size_t n;
|
|
3497
|
-
char *p1, *p2;
|
|
3498
|
-
ssize_t s1;
|
|
3499
|
-
|
|
3500
|
-
INIT_COUNTER(lp, n);
|
|
3501
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3502
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3503
|
-
|
|
3504
|
-
*(dtype*)p2 = f_max(n, p1, s1);
|
|
3505
|
-
}
|
|
3506
|
-
|
|
3507
|
-
/*
|
|
3508
|
-
max of self.
|
|
3509
|
-
@overload max(axis:nil, keepdims:false)
|
|
3510
|
-
@param [Numeric,Array,Range] axis Performs max along the axis.
|
|
3511
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3512
|
-
dimensions with size one.
|
|
3513
|
-
@return [Numo::Int8] returns result of max.
|
|
3514
|
-
*/
|
|
3515
|
-
static VALUE int8_max(int argc, VALUE* argv, VALUE self) {
|
|
3516
|
-
VALUE v, reduce;
|
|
3517
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3518
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3519
|
-
ndfunc_t ndf = { iter_int8_max, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3520
|
-
|
|
3521
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3522
|
-
|
|
3523
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3524
|
-
|
|
3525
|
-
return int8_extract(v);
|
|
3526
|
-
}
|
|
3527
|
-
|
|
3528
|
-
static void iter_int8_ptp(na_loop_t* const lp) {
|
|
3529
|
-
size_t n;
|
|
3530
|
-
char *p1, *p2;
|
|
3531
|
-
ssize_t s1;
|
|
3532
|
-
|
|
3533
|
-
INIT_COUNTER(lp, n);
|
|
3534
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3535
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3536
|
-
|
|
3537
|
-
*(dtype*)p2 = f_ptp(n, p1, s1);
|
|
3538
|
-
}
|
|
3539
|
-
|
|
3540
|
-
/*
|
|
3541
|
-
ptp of self.
|
|
3542
|
-
@overload ptp(axis:nil, keepdims:false)
|
|
3543
|
-
@param [Numeric,Array,Range] axis Performs ptp along the axis.
|
|
3544
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3545
|
-
dimensions with size one.
|
|
3546
|
-
@return [Numo::Int8] returns result of ptp.
|
|
3547
|
-
*/
|
|
3548
|
-
static VALUE int8_ptp(int argc, VALUE* argv, VALUE self) {
|
|
3549
|
-
VALUE v, reduce;
|
|
3550
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3551
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3552
|
-
ndfunc_t ndf = { iter_int8_ptp, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3553
|
-
|
|
3554
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3555
|
-
|
|
3556
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3557
|
-
|
|
3558
|
-
return int8_extract(v);
|
|
3559
|
-
}
|
|
3560
|
-
|
|
3561
|
-
#define idx_t int64_t
|
|
3562
|
-
static void iter_int8_max_index_index64(na_loop_t* const lp) {
|
|
3563
|
-
size_t n, idx;
|
|
3564
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
3565
|
-
ssize_t d_step, i_step;
|
|
3566
|
-
|
|
3567
|
-
INIT_COUNTER(lp, n);
|
|
3568
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3569
|
-
|
|
3570
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
3571
|
-
|
|
3572
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
3573
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
3574
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
3575
|
-
}
|
|
3576
|
-
#undef idx_t
|
|
3577
|
-
|
|
3578
|
-
#define idx_t int32_t
|
|
3579
|
-
static void iter_int8_max_index_index32(na_loop_t* const lp) {
|
|
3580
|
-
size_t n, idx;
|
|
3581
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
3582
|
-
ssize_t d_step, i_step;
|
|
3583
|
-
|
|
3584
|
-
INIT_COUNTER(lp, n);
|
|
3585
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3586
|
-
|
|
3587
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
3588
|
-
|
|
3589
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
3590
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
3591
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
3592
|
-
}
|
|
3593
|
-
#undef idx_t
|
|
3594
|
-
|
|
3595
|
-
/*
|
|
3596
|
-
Index of the maximum value.
|
|
3597
|
-
@overload max_index(axis:nil)
|
|
3598
|
-
@param [Numeric,Array,Range] axis Finds maximum values along the axis and returns **flat
|
|
3599
|
-
1-d indices**.
|
|
3600
|
-
@return [Integer,Numo::Int] returns result indices.
|
|
3601
|
-
@see #argmax
|
|
3602
|
-
@see #max
|
|
3603
|
-
|
|
3604
|
-
@example
|
|
3605
|
-
a = Numo::NArray[3,4,1,2]
|
|
3606
|
-
a.max_index #=> 1
|
|
3607
|
-
|
|
3608
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
3609
|
-
b.max_index #=> 5
|
|
3610
|
-
b.max_index(axis:1) #=> [1, 5]
|
|
3611
|
-
b.max_index(axis:0) #=> [0, 1, 5]
|
|
3612
|
-
b[b.max_index(axis:0)] #=> [3, 4, 5]
|
|
3613
|
-
*/
|
|
3614
|
-
static VALUE int8_max_index(int argc, VALUE* argv, VALUE self) {
|
|
3615
|
-
narray_t* na;
|
|
3616
|
-
VALUE idx, reduce;
|
|
3617
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { Qnil, 0 }, { sym_reduce, 0 } };
|
|
3618
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
3619
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 3, 1, ain, aout };
|
|
3620
|
-
|
|
3621
|
-
GetNArray(self, na);
|
|
3622
|
-
if (na->ndim == 0) {
|
|
3623
|
-
return INT2FIX(0);
|
|
3624
|
-
}
|
|
3625
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
3626
|
-
aout[0].type = numo_cInt64;
|
|
3627
|
-
idx = nary_new(numo_cInt64, na->ndim, na->shape);
|
|
3628
|
-
ndf.func = iter_int8_max_index_index64;
|
|
3629
|
-
|
|
3630
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3631
|
-
|
|
3632
|
-
} else {
|
|
3633
|
-
aout[0].type = numo_cInt32;
|
|
3634
|
-
idx = nary_new(numo_cInt32, na->ndim, na->shape);
|
|
3635
|
-
ndf.func = iter_int8_max_index_index32;
|
|
3636
|
-
|
|
3637
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3638
|
-
}
|
|
3639
|
-
rb_funcall(idx, rb_intern("seq"), 0);
|
|
3640
|
-
|
|
3641
|
-
return na_ndloop(&ndf, 3, self, idx, reduce);
|
|
3642
|
-
}
|
|
3643
|
-
|
|
3644
|
-
#define idx_t int64_t
|
|
3645
|
-
static void iter_int8_min_index_index64(na_loop_t* const lp) {
|
|
3646
|
-
size_t n, idx;
|
|
3647
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
3648
|
-
ssize_t d_step, i_step;
|
|
3649
|
-
|
|
3650
|
-
INIT_COUNTER(lp, n);
|
|
3651
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3652
|
-
|
|
3653
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
3654
|
-
|
|
3655
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
3656
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
3657
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
3658
|
-
}
|
|
3659
|
-
#undef idx_t
|
|
3660
|
-
|
|
3661
|
-
#define idx_t int32_t
|
|
3662
|
-
static void iter_int8_min_index_index32(na_loop_t* const lp) {
|
|
3663
|
-
size_t n, idx;
|
|
3664
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
3665
|
-
ssize_t d_step, i_step;
|
|
3666
|
-
|
|
3667
|
-
INIT_COUNTER(lp, n);
|
|
3668
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3669
|
-
|
|
3670
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
3671
|
-
|
|
3672
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
3673
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
3674
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
3675
|
-
}
|
|
3676
|
-
#undef idx_t
|
|
3677
|
-
|
|
3678
|
-
/*
|
|
3679
|
-
Index of the minimum value.
|
|
3680
|
-
@overload min_index(axis:nil)
|
|
3681
|
-
@param [Numeric,Array,Range] axis Finds minimum values along the axis and returns **flat
|
|
3682
|
-
1-d indices**.
|
|
3683
|
-
@return [Integer,Numo::Int] returns result indices.
|
|
3684
|
-
@see #argmin
|
|
3685
|
-
@see #min
|
|
3686
|
-
|
|
3687
|
-
@example
|
|
3688
|
-
a = Numo::NArray[3,4,1,2]
|
|
3689
|
-
a.min_index #=> 2
|
|
3690
|
-
|
|
3691
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
3692
|
-
b.min_index #=> 4
|
|
3693
|
-
b.min_index(axis:1) #=> [2, 4]
|
|
3694
|
-
b.min_index(axis:0) #=> [3, 4, 2]
|
|
3695
|
-
b[b.min_index(axis:0)] #=> [2, 0, 1]
|
|
3696
|
-
*/
|
|
3697
|
-
static VALUE int8_min_index(int argc, VALUE* argv, VALUE self) {
|
|
3698
|
-
narray_t* na;
|
|
3699
|
-
VALUE idx, reduce;
|
|
3700
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { Qnil, 0 }, { sym_reduce, 0 } };
|
|
3701
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
3702
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 3, 1, ain, aout };
|
|
3703
|
-
|
|
3704
|
-
GetNArray(self, na);
|
|
3705
|
-
if (na->ndim == 0) {
|
|
3706
|
-
return INT2FIX(0);
|
|
3707
|
-
}
|
|
3708
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
3709
|
-
aout[0].type = numo_cInt64;
|
|
3710
|
-
idx = nary_new(numo_cInt64, na->ndim, na->shape);
|
|
3711
|
-
ndf.func = iter_int8_min_index_index64;
|
|
3712
|
-
|
|
3713
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3714
|
-
|
|
3715
|
-
} else {
|
|
3716
|
-
aout[0].type = numo_cInt32;
|
|
3717
|
-
idx = nary_new(numo_cInt32, na->ndim, na->shape);
|
|
3718
|
-
ndf.func = iter_int8_min_index_index32;
|
|
3719
|
-
|
|
3720
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3721
|
-
}
|
|
3722
|
-
rb_funcall(idx, rb_intern("seq"), 0);
|
|
3723
|
-
|
|
3724
|
-
return na_ndloop(&ndf, 3, self, idx, reduce);
|
|
3725
|
-
}
|
|
3726
|
-
|
|
3727
|
-
#define idx_t int64_t
|
|
3728
|
-
static void iter_int8_argmax_arg64(na_loop_t* const lp) {
|
|
3729
|
-
size_t n, idx;
|
|
3730
|
-
char *d_ptr, *o_ptr;
|
|
3731
|
-
ssize_t d_step;
|
|
3732
|
-
|
|
3733
|
-
INIT_COUNTER(lp, n);
|
|
3734
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3735
|
-
|
|
3736
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
3737
|
-
|
|
3738
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
3739
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
3740
|
-
}
|
|
3741
|
-
#undef idx_t
|
|
3742
|
-
|
|
3743
|
-
#define idx_t int32_t
|
|
3744
|
-
static void iter_int8_argmax_arg32(na_loop_t* const lp) {
|
|
3745
|
-
size_t n, idx;
|
|
3746
|
-
char *d_ptr, *o_ptr;
|
|
3747
|
-
ssize_t d_step;
|
|
3748
|
-
|
|
3749
|
-
INIT_COUNTER(lp, n);
|
|
3750
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3751
|
-
|
|
3752
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
3753
|
-
|
|
3754
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
3755
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
3756
|
-
}
|
|
3757
|
-
#undef idx_t
|
|
3758
|
-
|
|
3759
|
-
/*
|
|
3760
|
-
Index of the maximum value.
|
|
3761
|
-
@overload argmax(axis:nil)
|
|
3762
|
-
@param [Numeric,Array,Range] axis Finds maximum values along the axis and returns **indices
|
|
3763
|
-
along the axis**.
|
|
3764
|
-
@return [Integer,Numo::Int] returns the result indices.
|
|
3765
|
-
@see #max_index
|
|
3766
|
-
@see #max
|
|
3767
|
-
|
|
3768
|
-
@example
|
|
3769
|
-
a = Numo::NArray[3,4,1,2]
|
|
3770
|
-
a.argmax #=> 1
|
|
3771
|
-
|
|
3772
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
3773
|
-
b.argmax #=> 5
|
|
3774
|
-
b.argmax(axis:1) #=> [1, 2]
|
|
3775
|
-
b.argmax(axis:0) #=> [0, 0, 1]
|
|
3776
|
-
b.at(b.argmax(axis:0), 0..-1) #=> [3, 4, 5]
|
|
3777
|
-
*/
|
|
3778
|
-
static VALUE int8_argmax(int argc, VALUE* argv, VALUE self) {
|
|
3779
|
-
narray_t* na;
|
|
3780
|
-
VALUE reduce;
|
|
3781
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } };
|
|
3782
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
3783
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout };
|
|
3784
|
-
|
|
3785
|
-
GetNArray(self, na);
|
|
3786
|
-
if (na->ndim == 0) {
|
|
3787
|
-
return INT2FIX(0);
|
|
3788
|
-
}
|
|
3789
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
3790
|
-
aout[0].type = numo_cInt64;
|
|
3791
|
-
ndf.func = iter_int8_argmax_arg64;
|
|
3792
|
-
|
|
3793
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3794
|
-
|
|
3795
|
-
} else {
|
|
3796
|
-
aout[0].type = numo_cInt32;
|
|
3797
|
-
ndf.func = iter_int8_argmax_arg32;
|
|
3798
|
-
|
|
3799
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
3803
|
-
}
|
|
3804
|
-
|
|
3805
|
-
#define idx_t int64_t
|
|
3806
|
-
static void iter_int8_argmin_arg64(na_loop_t* const lp) {
|
|
3807
|
-
size_t n, idx;
|
|
3808
|
-
char *d_ptr, *o_ptr;
|
|
3809
|
-
ssize_t d_step;
|
|
3810
|
-
|
|
3811
|
-
INIT_COUNTER(lp, n);
|
|
3812
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3813
|
-
|
|
3814
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
3815
|
-
|
|
3816
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
3817
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
3818
|
-
}
|
|
3819
|
-
#undef idx_t
|
|
3820
|
-
|
|
3821
|
-
#define idx_t int32_t
|
|
3822
|
-
static void iter_int8_argmin_arg32(na_loop_t* const lp) {
|
|
3823
|
-
size_t n, idx;
|
|
3824
|
-
char *d_ptr, *o_ptr;
|
|
3825
|
-
ssize_t d_step;
|
|
3826
|
-
|
|
3827
|
-
INIT_COUNTER(lp, n);
|
|
3828
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3829
|
-
|
|
3830
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
3831
|
-
|
|
3832
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
3833
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
3834
|
-
}
|
|
3835
|
-
#undef idx_t
|
|
3836
|
-
|
|
3837
|
-
/*
|
|
3838
|
-
Index of the minimum value.
|
|
3839
|
-
@overload argmin(axis:nil)
|
|
3840
|
-
@param [Numeric,Array,Range] axis Finds minimum values along the axis and returns **indices
|
|
3841
|
-
along the axis**.
|
|
3842
|
-
@return [Integer,Numo::Int] returns the result indices.
|
|
3843
|
-
@see #min_index
|
|
3844
|
-
@see #min
|
|
3845
|
-
|
|
3846
|
-
@example
|
|
3847
|
-
a = Numo::NArray[3,4,1,2]
|
|
3848
|
-
a.argmin #=> 2
|
|
3849
|
-
|
|
3850
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
3851
|
-
b.argmin #=> 4
|
|
3852
|
-
b.argmin(axis:1) #=> [2, 1]
|
|
3853
|
-
b.argmin(axis:0) #=> [1, 1, 0]
|
|
3854
|
-
b.at(b.argmin(axis:0), 0..-1) #=> [2, 0, 1]
|
|
3855
|
-
*/
|
|
3856
|
-
static VALUE int8_argmin(int argc, VALUE* argv, VALUE self) {
|
|
3857
|
-
narray_t* na;
|
|
3858
|
-
VALUE reduce;
|
|
3859
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } };
|
|
3860
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
3861
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout };
|
|
3862
|
-
|
|
3863
|
-
GetNArray(self, na);
|
|
3864
|
-
if (na->ndim == 0) {
|
|
3865
|
-
return INT2FIX(0);
|
|
3866
|
-
}
|
|
3867
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
3868
|
-
aout[0].type = numo_cInt64;
|
|
3869
|
-
ndf.func = iter_int8_argmin_arg64;
|
|
3870
|
-
|
|
3871
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3872
|
-
|
|
3873
|
-
} else {
|
|
3874
|
-
aout[0].type = numo_cInt32;
|
|
3875
|
-
ndf.func = iter_int8_argmin_arg32;
|
|
3876
|
-
|
|
3877
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3878
|
-
}
|
|
3879
|
-
|
|
3880
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
3881
|
-
}
|
|
3882
|
-
|
|
3883
|
-
static void iter_int8_minmax(na_loop_t* const lp) {
|
|
3884
|
-
size_t n;
|
|
3885
|
-
char* p1;
|
|
3886
|
-
ssize_t s1;
|
|
3887
|
-
dtype xmin, xmax;
|
|
3888
|
-
|
|
3889
|
-
INIT_COUNTER(lp, n);
|
|
3890
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3891
|
-
|
|
3892
|
-
f_minmax(n, p1, s1, &xmin, &xmax);
|
|
3893
|
-
|
|
3894
|
-
*(dtype*)(lp->args[1].ptr + lp->args[1].iter[0].pos) = xmin;
|
|
3895
|
-
*(dtype*)(lp->args[2].ptr + lp->args[2].iter[0].pos) = xmax;
|
|
3896
|
-
}
|
|
3897
|
-
|
|
3898
|
-
/*
|
|
3899
|
-
minmax of self.
|
|
3900
|
-
@overload minmax(axis:nil, keepdims:false)
|
|
3901
|
-
@param [Numeric,Array,Range] axis Finds min-max along the axis.
|
|
3902
|
-
@param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
|
|
3903
|
-
as dimensions with size one.
|
|
3904
|
-
@return [Numo::Int8,Numo::Int8] min and max of self.
|
|
3905
|
-
*/
|
|
3906
|
-
static VALUE int8_minmax(int argc, VALUE* argv, VALUE self) {
|
|
3907
|
-
VALUE reduce;
|
|
3908
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3909
|
-
ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
|
|
3910
|
-
ndfunc_t ndf = {
|
|
3911
|
-
iter_int8_minmax, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 2, ain, aout
|
|
3912
|
-
};
|
|
3913
|
-
|
|
3914
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
3915
|
-
|
|
3916
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
3917
|
-
}
|
|
3918
|
-
|
|
3919
|
-
static void iter_int8_s_maximum(na_loop_t* const lp) {
|
|
3920
|
-
size_t i, n;
|
|
3921
|
-
char *p1, *p2, *p3;
|
|
3922
|
-
ssize_t s1, s2, s3;
|
|
3923
|
-
|
|
3924
|
-
INIT_COUNTER(lp, n);
|
|
3925
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3926
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3927
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3928
|
-
|
|
3929
|
-
for (i = 0; i < n; i++) {
|
|
3930
|
-
dtype x, y, z;
|
|
3931
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3932
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3933
|
-
GET_DATA(p3, dtype, z);
|
|
3934
|
-
z = f_maximum(x, y);
|
|
3935
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
3936
|
-
}
|
|
3937
|
-
}
|
|
3938
|
-
|
|
3939
|
-
static VALUE int8_s_maximum(int argc, VALUE* argv, VALUE mod) {
|
|
3940
|
-
VALUE a1 = Qnil;
|
|
3941
|
-
VALUE a2 = Qnil;
|
|
3942
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3943
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3944
|
-
ndfunc_t ndf = { iter_int8_s_maximum, STRIDE_LOOP_NIP, 2, 1, ain, aout };
|
|
3945
|
-
|
|
3946
|
-
rb_scan_args(argc, argv, "20", &a1, &a2);
|
|
3947
|
-
|
|
3948
|
-
return na_ndloop(&ndf, 2, a1, a2);
|
|
3949
|
-
}
|
|
3950
|
-
|
|
3951
|
-
static void iter_int8_s_minimum(na_loop_t* const lp) {
|
|
3952
|
-
size_t i, n;
|
|
3953
|
-
char *p1, *p2, *p3;
|
|
3954
|
-
ssize_t s1, s2, s3;
|
|
3955
|
-
|
|
3956
|
-
INIT_COUNTER(lp, n);
|
|
3957
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3958
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3959
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3960
|
-
|
|
3961
|
-
for (i = 0; i < n; i++) {
|
|
3962
|
-
dtype x, y, z;
|
|
3963
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3964
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3965
|
-
GET_DATA(p3, dtype, z);
|
|
3966
|
-
z = f_minimum(x, y);
|
|
3967
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
3968
|
-
}
|
|
3969
|
-
}
|
|
3970
|
-
|
|
3971
|
-
static VALUE int8_s_minimum(int argc, VALUE* argv, VALUE mod) {
|
|
3972
|
-
VALUE a1 = Qnil;
|
|
3973
|
-
VALUE a2 = Qnil;
|
|
3974
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3975
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3976
|
-
ndfunc_t ndf = { iter_int8_s_minimum, STRIDE_LOOP_NIP, 2, 1, ain, aout };
|
|
3977
|
-
|
|
3978
|
-
rb_scan_args(argc, argv, "20", &a1, &a2);
|
|
3979
|
-
|
|
3980
|
-
return na_ndloop(&ndf, 2, a1, a2);
|
|
3981
|
-
}
|
|
3982
|
-
|
|
3983
|
-
// ------- Integer count without weights -------
|
|
3984
|
-
|
|
3985
|
-
static void iter_int8_bincount_32(na_loop_t* const lp) {
|
|
3986
|
-
size_t i, x, n;
|
|
3987
|
-
char *p1, *p2;
|
|
3988
|
-
ssize_t s1, s2;
|
|
3989
|
-
size_t* idx1;
|
|
3990
|
-
|
|
3991
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3992
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3993
|
-
i = lp->args[0].shape[0];
|
|
3994
|
-
n = lp->args[1].shape[0];
|
|
3995
|
-
|
|
3996
|
-
// initialize
|
|
3997
|
-
for (x = 0; x < n; x++) {
|
|
3998
|
-
*(u_int32_t*)(p2 + s2 * x) = 0;
|
|
3999
|
-
}
|
|
4000
|
-
|
|
4001
|
-
if (idx1) {
|
|
4002
|
-
for (; i--;) {
|
|
4003
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
4004
|
-
(*(u_int32_t*)(p2 + s2 * x))++;
|
|
4005
|
-
}
|
|
4006
|
-
} else {
|
|
4007
|
-
for (; i--;) {
|
|
4008
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4009
|
-
(*(u_int32_t*)(p2 + s2 * x))++;
|
|
4010
|
-
}
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
|
-
|
|
4014
|
-
static VALUE int8_bincount_32(VALUE self, size_t length) {
|
|
4015
|
-
size_t shape_out[1] = { length };
|
|
4016
|
-
ndfunc_arg_in_t ain[1] = { { cT, 1 } };
|
|
4017
|
-
ndfunc_arg_out_t aout[1] = { { numo_cUInt32, 1, shape_out } };
|
|
4018
|
-
ndfunc_t ndf = {
|
|
4019
|
-
iter_int8_bincount_32, NO_LOOP | NDF_STRIDE_LOOP | NDF_INDEX_LOOP, 1, 1, ain, aout
|
|
4020
|
-
};
|
|
4021
|
-
|
|
4022
|
-
return na_ndloop(&ndf, 1, self);
|
|
4023
|
-
}
|
|
4024
|
-
|
|
4025
|
-
static void iter_int8_bincount_64(na_loop_t* const lp) {
|
|
4026
|
-
size_t i, x, n;
|
|
4027
|
-
char *p1, *p2;
|
|
4028
|
-
ssize_t s1, s2;
|
|
4029
|
-
size_t* idx1;
|
|
4030
|
-
|
|
4031
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4032
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4033
|
-
i = lp->args[0].shape[0];
|
|
4034
|
-
n = lp->args[1].shape[0];
|
|
4035
|
-
|
|
4036
|
-
// initialize
|
|
4037
|
-
for (x = 0; x < n; x++) {
|
|
4038
|
-
*(u_int64_t*)(p2 + s2 * x) = 0;
|
|
4039
|
-
}
|
|
4040
|
-
|
|
4041
|
-
if (idx1) {
|
|
4042
|
-
for (; i--;) {
|
|
4043
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
4044
|
-
(*(u_int64_t*)(p2 + s2 * x))++;
|
|
4045
|
-
}
|
|
4046
|
-
} else {
|
|
4047
|
-
for (; i--;) {
|
|
4048
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4049
|
-
(*(u_int64_t*)(p2 + s2 * x))++;
|
|
4050
|
-
}
|
|
4051
|
-
}
|
|
4052
|
-
}
|
|
4053
|
-
|
|
4054
|
-
static VALUE int8_bincount_64(VALUE self, size_t length) {
|
|
4055
|
-
size_t shape_out[1] = { length };
|
|
4056
|
-
ndfunc_arg_in_t ain[1] = { { cT, 1 } };
|
|
4057
|
-
ndfunc_arg_out_t aout[1] = { { numo_cUInt64, 1, shape_out } };
|
|
4058
|
-
ndfunc_t ndf = {
|
|
4059
|
-
iter_int8_bincount_64, NO_LOOP | NDF_STRIDE_LOOP | NDF_INDEX_LOOP, 1, 1, ain, aout
|
|
4060
|
-
};
|
|
4061
|
-
|
|
4062
|
-
return na_ndloop(&ndf, 1, self);
|
|
4063
|
-
}
|
|
4064
|
-
// ------- end of Integer count without weights -------
|
|
4065
|
-
|
|
4066
|
-
// ------- Float count with weights -------
|
|
4067
|
-
|
|
4068
|
-
static void iter_int8_bincount_sf(na_loop_t* const lp) {
|
|
4069
|
-
float w;
|
|
4070
|
-
size_t i, x, n, m;
|
|
4071
|
-
char *p1, *p2, *p3;
|
|
4072
|
-
ssize_t s1, s2, s3;
|
|
4073
|
-
|
|
4074
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4075
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4076
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4077
|
-
i = lp->args[0].shape[0];
|
|
4078
|
-
m = lp->args[1].shape[0];
|
|
4079
|
-
n = lp->args[2].shape[0];
|
|
4080
|
-
|
|
4081
|
-
if (i != m) {
|
|
4082
|
-
rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight");
|
|
4083
|
-
}
|
|
4084
|
-
|
|
4085
|
-
// initialize
|
|
4086
|
-
for (x = 0; x < n; x++) {
|
|
4087
|
-
*(float*)(p3 + s3 * x) = 0;
|
|
4088
|
-
}
|
|
4089
|
-
for (; i--;) {
|
|
4090
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4091
|
-
GET_DATA_STRIDE(p2, s2, float, w);
|
|
4092
|
-
(*(float*)(p3 + s3 * x)) += w;
|
|
4093
|
-
}
|
|
4094
|
-
}
|
|
4095
|
-
|
|
4096
|
-
static VALUE int8_bincount_sf(VALUE self, VALUE weight, size_t length) {
|
|
4097
|
-
size_t shape_out[1] = { length };
|
|
4098
|
-
ndfunc_arg_in_t ain[2] = { { cT, 1 }, { numo_cSFloat, 1 } };
|
|
4099
|
-
ndfunc_arg_out_t aout[1] = { { numo_cSFloat, 1, shape_out } };
|
|
4100
|
-
ndfunc_t ndf = { iter_int8_bincount_sf, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout };
|
|
4101
|
-
|
|
4102
|
-
return na_ndloop(&ndf, 2, self, weight);
|
|
4103
|
-
}
|
|
4104
|
-
|
|
4105
|
-
static void iter_int8_bincount_df(na_loop_t* const lp) {
|
|
4106
|
-
double w;
|
|
4107
|
-
size_t i, x, n, m;
|
|
4108
|
-
char *p1, *p2, *p3;
|
|
4109
|
-
ssize_t s1, s2, s3;
|
|
4110
|
-
|
|
4111
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4112
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4113
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4114
|
-
i = lp->args[0].shape[0];
|
|
4115
|
-
m = lp->args[1].shape[0];
|
|
4116
|
-
n = lp->args[2].shape[0];
|
|
4117
|
-
|
|
4118
|
-
if (i != m) {
|
|
4119
|
-
rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight");
|
|
4120
|
-
}
|
|
4121
|
-
|
|
4122
|
-
// initialize
|
|
4123
|
-
for (x = 0; x < n; x++) {
|
|
4124
|
-
*(double*)(p3 + s3 * x) = 0;
|
|
4125
|
-
}
|
|
4126
|
-
for (; i--;) {
|
|
4127
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4128
|
-
GET_DATA_STRIDE(p2, s2, double, w);
|
|
4129
|
-
(*(double*)(p3 + s3 * x)) += w;
|
|
4130
|
-
}
|
|
4131
|
-
}
|
|
4132
|
-
|
|
4133
|
-
static VALUE int8_bincount_df(VALUE self, VALUE weight, size_t length) {
|
|
4134
|
-
size_t shape_out[1] = { length };
|
|
4135
|
-
ndfunc_arg_in_t ain[2] = { { cT, 1 }, { numo_cDFloat, 1 } };
|
|
4136
|
-
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 1, shape_out } };
|
|
4137
|
-
ndfunc_t ndf = { iter_int8_bincount_df, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout };
|
|
4138
|
-
|
|
4139
|
-
return na_ndloop(&ndf, 2, self, weight);
|
|
4140
|
-
}
|
|
4141
|
-
// ------- end of Float count with weights -------
|
|
4142
|
-
|
|
4143
|
-
/*
|
|
4144
|
-
Count the number of occurrences of each non-negative integer value.
|
|
4145
|
-
Only Integer-types has this method.
|
|
4146
|
-
|
|
4147
|
-
@overload bincount([weight], minlength:nil)
|
|
4148
|
-
@param [SFloat or DFloat or Array] weight (optional) Array of
|
|
4149
|
-
float values. Its size along last axis should be same as that of self.
|
|
4150
|
-
@param [Integer] minlength (keyword, optional) Minimum size along
|
|
4151
|
-
last axis for the output array.
|
|
4152
|
-
@return [UInt32 or UInt64 or SFloat or DFloat]
|
|
4153
|
-
Returns Float NArray if weight array is supplied,
|
|
4154
|
-
otherwise returns UInt32 or UInt64 depending on the size along last axis.
|
|
4155
|
-
@example
|
|
4156
|
-
Numo::Int32[0..4].bincount
|
|
4157
|
-
# => Numo::UInt32#shape=[5]
|
|
4158
|
-
# [1, 1, 1, 1, 1]
|
|
4159
|
-
|
|
4160
|
-
Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
|
|
4161
|
-
# => Numo::UInt32#shape=[8]
|
|
4162
|
-
# [1, 3, 1, 1, 0, 0, 0, 1]
|
|
4163
|
-
|
|
4164
|
-
x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
|
|
4165
|
-
x.bincount.size == x.max+1
|
|
4166
|
-
# => true
|
|
4167
|
-
|
|
4168
|
-
w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
|
|
4169
|
-
x = Numo::Int32[0, 1, 1, 2, 2, 2]
|
|
4170
|
-
x.bincount(w)
|
|
4171
|
-
# => Numo::DFloat#shape=[3]
|
|
4172
|
-
# [0.3, 0.7, 1.1]
|
|
4173
|
-
|
|
4174
|
-
*/
|
|
4175
|
-
static VALUE int8_bincount(int argc, VALUE* argv, VALUE self) {
|
|
4176
|
-
VALUE weight = Qnil, kw = Qnil;
|
|
4177
|
-
VALUE opts[1] = { Qundef };
|
|
4178
|
-
VALUE v, wclass;
|
|
4179
|
-
ID table[1] = { id_minlength };
|
|
4180
|
-
size_t length, minlength;
|
|
4181
|
-
|
|
4182
|
-
rb_scan_args(argc, argv, "01:", &weight, &kw);
|
|
4183
|
-
rb_get_kwargs(kw, table, 0, 1, opts);
|
|
4184
|
-
|
|
4185
|
-
v = int8_minmax(0, 0, self);
|
|
4186
|
-
if (m_num_to_data(RARRAY_AREF(v, 0)) < 0) {
|
|
4187
|
-
rb_raise(rb_eArgError, "array items must be non-netagive");
|
|
4188
|
-
}
|
|
4189
|
-
v = RARRAY_AREF(v, 1);
|
|
4190
|
-
|
|
4191
|
-
length = NUM2SIZET(v) + 1;
|
|
4192
|
-
|
|
4193
|
-
if (opts[0] != Qundef) {
|
|
4194
|
-
minlength = NUM2SIZET(opts[0]);
|
|
4195
|
-
if (minlength > length) {
|
|
4196
|
-
length = minlength;
|
|
4197
|
-
}
|
|
4198
|
-
}
|
|
4199
|
-
|
|
4200
|
-
if (NIL_P(weight)) {
|
|
4201
|
-
if (length > 4294967295ul) {
|
|
4202
|
-
return int8_bincount_64(self, length);
|
|
4203
|
-
} else {
|
|
4204
|
-
return int8_bincount_32(self, length);
|
|
4205
|
-
}
|
|
4206
|
-
} else {
|
|
4207
|
-
wclass = rb_obj_class(weight);
|
|
4208
|
-
if (wclass == numo_cSFloat) {
|
|
4209
|
-
return int8_bincount_sf(self, weight, length);
|
|
4210
|
-
} else {
|
|
4211
|
-
return int8_bincount_df(self, weight, length);
|
|
4212
|
-
}
|
|
4213
|
-
}
|
|
4214
|
-
}
|
|
4215
|
-
|
|
4216
|
-
static void iter_int8_cumsum(na_loop_t* const lp) {
|
|
4217
|
-
size_t i;
|
|
4218
|
-
char *p1, *p2;
|
|
4219
|
-
ssize_t s1, s2;
|
|
4220
|
-
dtype x, y;
|
|
4221
|
-
|
|
4222
|
-
INIT_COUNTER(lp, i);
|
|
4223
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4224
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4225
|
-
|
|
4226
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4227
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4228
|
-
for (i--; i--;) {
|
|
4229
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4230
|
-
m_cumsum(x, y);
|
|
4231
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4232
|
-
}
|
|
4233
|
-
}
|
|
4234
|
-
|
|
4235
|
-
/*
|
|
4236
|
-
cumsum of self.
|
|
4237
|
-
@overload cumsum(axis:nil, nan:false)
|
|
4238
|
-
@param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
4239
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4240
|
-
@return [Numo::Int8] cumsum of self.
|
|
4241
|
-
*/
|
|
4242
|
-
static VALUE int8_cumsum(int argc, VALUE* argv, VALUE self) {
|
|
4243
|
-
VALUE reduce;
|
|
4244
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4245
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4246
|
-
ndfunc_t ndf = { iter_int8_cumsum, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout };
|
|
4247
|
-
|
|
4248
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
4249
|
-
|
|
4250
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4251
|
-
}
|
|
4252
|
-
|
|
4253
|
-
static void iter_int8_cumprod(na_loop_t* const lp) {
|
|
4254
|
-
size_t i;
|
|
4255
|
-
char *p1, *p2;
|
|
4256
|
-
ssize_t s1, s2;
|
|
4257
|
-
dtype x, y;
|
|
4258
|
-
|
|
4259
|
-
INIT_COUNTER(lp, i);
|
|
4260
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4261
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4262
|
-
|
|
4263
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4264
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4265
|
-
for (i--; i--;) {
|
|
4266
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4267
|
-
m_cumprod(x, y);
|
|
4268
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4269
|
-
}
|
|
4270
|
-
}
|
|
4271
|
-
|
|
4272
|
-
/*
|
|
4273
|
-
cumprod of self.
|
|
4274
|
-
@overload cumprod(axis:nil, nan:false)
|
|
4275
|
-
@param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
4276
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4277
|
-
@return [Numo::Int8] cumprod of self.
|
|
4278
|
-
*/
|
|
4279
|
-
static VALUE int8_cumprod(int argc, VALUE* argv, VALUE self) {
|
|
4280
|
-
VALUE reduce;
|
|
4281
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4282
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4283
|
-
ndfunc_t ndf = {
|
|
4284
|
-
iter_int8_cumprod, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
|
|
4285
|
-
};
|
|
4286
|
-
|
|
4287
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
|
4288
|
-
|
|
4289
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4290
|
-
}
|
|
4291
|
-
|
|
4292
|
-
//
|
|
4293
|
-
static void iter_int8_mulsum(na_loop_t* const lp) {
|
|
4294
|
-
size_t i, n;
|
|
4295
|
-
char *p1, *p2, *p3;
|
|
4296
|
-
ssize_t s1, s2, s3;
|
|
4297
|
-
|
|
4298
|
-
INIT_COUNTER(lp, n);
|
|
4299
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4300
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4301
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4302
|
-
|
|
4303
|
-
if (s3 == 0) {
|
|
4304
|
-
dtype z;
|
|
4305
|
-
// Reduce loop
|
|
4306
|
-
GET_DATA(p3, dtype, z);
|
|
4307
|
-
for (i = 0; i < n; i++) {
|
|
4308
|
-
dtype x, y;
|
|
4309
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4310
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4311
|
-
m_mulsum(x, y, z);
|
|
4312
|
-
}
|
|
4313
|
-
SET_DATA(p3, dtype, z);
|
|
4314
|
-
return;
|
|
4315
|
-
} else {
|
|
4316
|
-
for (i = 0; i < n; i++) {
|
|
4317
|
-
dtype x, y, z;
|
|
4318
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4319
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4320
|
-
GET_DATA(p3, dtype, z);
|
|
4321
|
-
m_mulsum(x, y, z);
|
|
4322
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4323
|
-
}
|
|
4324
|
-
}
|
|
4325
|
-
}
|
|
4326
|
-
//
|
|
4327
|
-
|
|
4328
|
-
static VALUE int8_mulsum_self(int argc, VALUE* argv, VALUE self) {
|
|
4329
|
-
VALUE v, reduce;
|
|
4330
|
-
VALUE naryv[2];
|
|
4331
|
-
ndfunc_arg_in_t ain[4] = { { cT, 0 }, { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
|
|
4332
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4333
|
-
ndfunc_t ndf = { iter_int8_mulsum, STRIDE_LOOP_NIP, 4, 1, ain, aout };
|
|
4334
|
-
|
|
4335
|
-
if (argc < 1) {
|
|
4336
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
|
|
4337
|
-
}
|
|
4338
|
-
// should fix below: [self.ndim,other.ndim].max or?
|
|
4339
|
-
naryv[0] = self;
|
|
4340
|
-
naryv[1] = argv[0];
|
|
4341
|
-
//
|
|
4342
|
-
reduce = na_reduce_dimension(argc - 1, argv + 1, 2, naryv, &ndf, 0);
|
|
4343
|
-
//
|
|
4344
|
-
|
|
4345
|
-
v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_mulsum_init);
|
|
4346
|
-
return int8_extract(v);
|
|
4347
|
-
}
|
|
4348
|
-
|
|
4349
|
-
/*
|
|
4350
|
-
Binary mulsum.
|
|
4351
|
-
|
|
4352
|
-
@overload mulsum(other, axis:nil, keepdims:false)
|
|
4353
|
-
@param [Numo::NArray,Numeric] other
|
|
4354
|
-
@param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
4355
|
-
@param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
|
|
4356
|
-
as dimensions with size one.
|
|
4357
|
-
@return [Numo::NArray] mulsum of self and other.
|
|
4358
|
-
*/
|
|
4359
|
-
static VALUE int8_mulsum(int argc, VALUE* argv, VALUE self) {
|
|
4360
|
-
//
|
|
4361
|
-
VALUE klass, v;
|
|
4362
|
-
//
|
|
4363
|
-
if (argc < 1) {
|
|
4364
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
|
|
4365
|
-
}
|
|
4366
|
-
//
|
|
4367
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(argv[0]));
|
|
4368
|
-
if (klass == cT) {
|
|
4369
|
-
return int8_mulsum_self(argc, argv, self);
|
|
4370
|
-
} else {
|
|
4371
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
4372
|
-
//
|
|
4373
|
-
return rb_funcallv_kw(v, rb_intern("mulsum"), argc, argv, RB_PASS_CALLED_KEYWORDS);
|
|
4374
|
-
//
|
|
4375
|
-
}
|
|
4376
|
-
//
|
|
4377
|
-
}
|
|
4378
|
-
|
|
4379
|
-
typedef double seq_data_t;
|
|
4380
|
-
|
|
4381
|
-
typedef double seq_count_t;
|
|
4382
|
-
|
|
4383
|
-
typedef struct {
|
|
4384
|
-
seq_data_t beg;
|
|
4385
|
-
seq_data_t step;
|
|
4386
|
-
seq_count_t count;
|
|
4387
|
-
} seq_opt_t;
|
|
4388
|
-
|
|
4389
|
-
static void iter_int8_seq(na_loop_t* const lp) {
|
|
4390
|
-
size_t i;
|
|
4391
|
-
char* p1;
|
|
4392
|
-
ssize_t s1;
|
|
4393
|
-
size_t* idx1;
|
|
4394
|
-
dtype x;
|
|
4395
|
-
seq_data_t beg, step;
|
|
4396
|
-
seq_count_t c;
|
|
4397
|
-
seq_opt_t* g;
|
|
4398
|
-
|
|
4399
|
-
INIT_COUNTER(lp, i);
|
|
4400
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4401
|
-
g = (seq_opt_t*)(lp->opt_ptr);
|
|
4402
|
-
beg = g->beg;
|
|
4403
|
-
step = g->step;
|
|
4404
|
-
c = g->count;
|
|
4405
|
-
if (idx1) {
|
|
4406
|
-
for (; i--;) {
|
|
4407
|
-
x = f_seq(beg, step, c++);
|
|
4408
|
-
*(dtype*)(p1 + *idx1) = x;
|
|
4409
|
-
idx1++;
|
|
4410
|
-
}
|
|
4411
|
-
} else {
|
|
4412
|
-
for (; i--;) {
|
|
4413
|
-
x = f_seq(beg, step, c++);
|
|
4414
|
-
*(dtype*)(p1) = x;
|
|
4415
|
-
p1 += s1;
|
|
1777
|
+
p2 += s2;
|
|
1778
|
+
}
|
|
1779
|
+
return;
|
|
1780
|
+
//
|
|
4416
1781
|
}
|
|
4417
1782
|
}
|
|
4418
|
-
g->count = c;
|
|
4419
1783
|
}
|
|
4420
1784
|
|
|
4421
1785
|
/*
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
@overload seq([beg,[step]])
|
|
4426
|
-
@param [Numeric] beg beginning of sequence. (default=0)
|
|
4427
|
-
@param [Numeric] step step of sequence. (default=1)
|
|
4428
|
-
@return [Numo::Int8] self.
|
|
4429
|
-
@example
|
|
4430
|
-
Numo::DFloat.new(6).seq(1,-0.2)
|
|
4431
|
-
# => Numo::DFloat#shape=[6]
|
|
4432
|
-
# [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
4433
|
-
|
|
4434
|
-
Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
4435
|
-
# => Numo::DComplex#shape=[6]
|
|
4436
|
-
# [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
1786
|
+
Unary reciprocal.
|
|
1787
|
+
@overload reciprocal
|
|
1788
|
+
@return [Numo::Int8] reciprocal of self.
|
|
4437
1789
|
*/
|
|
4438
|
-
static VALUE
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
ndfunc_t ndf = { iter_int8_seq, FULL_LOOP, 1, 0, ain, 0 };
|
|
4443
|
-
|
|
4444
|
-
g = ALLOCA_N(seq_opt_t, 1);
|
|
4445
|
-
g->beg = m_zero;
|
|
4446
|
-
g->step = m_one;
|
|
4447
|
-
g->count = 0;
|
|
4448
|
-
rb_scan_args(argc, argv, "02", &vbeg, &vstep);
|
|
4449
|
-
if (vbeg != Qnil) {
|
|
4450
|
-
g->beg = NUM2DBL(vbeg);
|
|
4451
|
-
}
|
|
4452
|
-
if (vstep != Qnil) {
|
|
4453
|
-
g->step = NUM2DBL(vstep);
|
|
4454
|
-
}
|
|
4455
|
-
|
|
4456
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4457
|
-
return self;
|
|
4458
|
-
}
|
|
1790
|
+
static VALUE int8_reciprocal(VALUE self) {
|
|
1791
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1792
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1793
|
+
ndfunc_t ndf = { iter_int8_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
4459
1794
|
|
|
4460
|
-
|
|
4461
|
-
size_t n0, n1;
|
|
4462
|
-
size_t i0, i1;
|
|
4463
|
-
ssize_t s0, s1;
|
|
4464
|
-
char *p0, *p1;
|
|
4465
|
-
char* g;
|
|
4466
|
-
ssize_t kofs;
|
|
4467
|
-
dtype data;
|
|
4468
|
-
|
|
4469
|
-
g = (char*)(lp->opt_ptr);
|
|
4470
|
-
kofs = *(ssize_t*)g;
|
|
4471
|
-
data = *(dtype*)(g + sizeof(ssize_t));
|
|
4472
|
-
|
|
4473
|
-
n0 = lp->args[0].shape[0];
|
|
4474
|
-
n1 = lp->args[0].shape[1];
|
|
4475
|
-
s0 = lp->args[0].iter[0].step;
|
|
4476
|
-
s1 = lp->args[0].iter[1].step;
|
|
4477
|
-
p0 = NDL_PTR(lp, 0);
|
|
4478
|
-
|
|
4479
|
-
for (i0 = 0; i0 < n0; i0++) {
|
|
4480
|
-
p1 = p0;
|
|
4481
|
-
for (i1 = 0; i1 < n1; i1++) {
|
|
4482
|
-
*(dtype*)p1 = (i0 + kofs == i1) ? data : m_zero;
|
|
4483
|
-
p1 += s1;
|
|
4484
|
-
}
|
|
4485
|
-
p0 += s0;
|
|
4486
|
-
}
|
|
1795
|
+
return na_ndloop(&ndf, 1, self);
|
|
4487
1796
|
}
|
|
4488
1797
|
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
for diagonals below the main diagonal.
|
|
4496
|
-
@return [Numo::Int8] eye of self.
|
|
4497
|
-
*/
|
|
4498
|
-
static VALUE int8_eye(int argc, VALUE* argv, VALUE self) {
|
|
4499
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } };
|
|
4500
|
-
ndfunc_t ndf = { iter_int8_eye, NO_LOOP, 1, 0, ain, 0 };
|
|
4501
|
-
ssize_t kofs;
|
|
4502
|
-
dtype data;
|
|
4503
|
-
char* g;
|
|
4504
|
-
int nd;
|
|
4505
|
-
narray_t* na;
|
|
4506
|
-
|
|
4507
|
-
// check arguments
|
|
4508
|
-
if (argc > 2) {
|
|
4509
|
-
rb_raise(rb_eArgError, "too many arguments (%d for 0..2)", argc);
|
|
4510
|
-
} else if (argc == 2) {
|
|
4511
|
-
data = m_num_to_data(argv[0]);
|
|
4512
|
-
kofs = NUM2SSIZET(argv[1]);
|
|
4513
|
-
} else if (argc == 1) {
|
|
4514
|
-
data = m_num_to_data(argv[0]);
|
|
4515
|
-
kofs = 0;
|
|
4516
|
-
} else {
|
|
4517
|
-
data = m_one;
|
|
4518
|
-
kofs = 0;
|
|
4519
|
-
}
|
|
1798
|
+
static void iter_int8_sign(na_loop_t* const lp) {
|
|
1799
|
+
size_t i, n;
|
|
1800
|
+
char *p1, *p2;
|
|
1801
|
+
ssize_t s1, s2;
|
|
1802
|
+
size_t *idx1, *idx2;
|
|
1803
|
+
dtype x;
|
|
4520
1804
|
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
rb_raise(nary_eDimensionError, "less than 2-d array");
|
|
4525
|
-
}
|
|
1805
|
+
INIT_COUNTER(lp, n);
|
|
1806
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1807
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
4526
1808
|
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
)
|
|
1809
|
+
if (idx1) {
|
|
1810
|
+
if (idx2) {
|
|
1811
|
+
for (i = 0; i < n; i++) {
|
|
1812
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1813
|
+
x = m_sign(x);
|
|
1814
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1815
|
+
}
|
|
1816
|
+
} else {
|
|
1817
|
+
for (i = 0; i < n; i++) {
|
|
1818
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1819
|
+
x = m_sign(x);
|
|
1820
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1821
|
+
}
|
|
4536
1822
|
}
|
|
4537
1823
|
} else {
|
|
4538
|
-
if (
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
);
|
|
4545
|
-
}
|
|
4546
|
-
}
|
|
4547
|
-
|
|
4548
|
-
g = ALLOCA_N(char, sizeof(ssize_t) + sizeof(dtype));
|
|
4549
|
-
*(ssize_t*)g = kofs;
|
|
4550
|
-
*(dtype*)(g + sizeof(ssize_t)) = data;
|
|
4551
|
-
|
|
4552
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4553
|
-
return self;
|
|
4554
|
-
}
|
|
4555
|
-
|
|
4556
|
-
#define HWID (sizeof(dtype) * 4)
|
|
4557
|
-
|
|
4558
|
-
static int msb_pos(uint32_t a) {
|
|
4559
|
-
int width = HWID;
|
|
4560
|
-
int pos = 0;
|
|
4561
|
-
uint32_t mask = (((dtype)1 << HWID) - 1) << HWID;
|
|
4562
|
-
|
|
4563
|
-
if (a == 0) {
|
|
4564
|
-
return -1;
|
|
4565
|
-
}
|
|
4566
|
-
|
|
4567
|
-
while (width) {
|
|
4568
|
-
if (a & mask) {
|
|
4569
|
-
pos += width;
|
|
1824
|
+
if (idx2) {
|
|
1825
|
+
for (i = 0; i < n; i++) {
|
|
1826
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1827
|
+
x = m_sign(x);
|
|
1828
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1829
|
+
}
|
|
4570
1830
|
} else {
|
|
4571
|
-
|
|
1831
|
+
//
|
|
1832
|
+
for (i = 0; i < n; i++) {
|
|
1833
|
+
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
1834
|
+
p1 += s1;
|
|
1835
|
+
p2 += s2;
|
|
1836
|
+
}
|
|
1837
|
+
return;
|
|
1838
|
+
//
|
|
4572
1839
|
}
|
|
4573
|
-
width >>= 1;
|
|
4574
|
-
mask &= mask << width;
|
|
4575
1840
|
}
|
|
4576
|
-
return pos;
|
|
4577
1841
|
}
|
|
4578
1842
|
|
|
4579
|
-
/*
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
}
|
|
1843
|
+
/*
|
|
1844
|
+
Unary sign.
|
|
1845
|
+
@overload sign
|
|
1846
|
+
@return [Numo::Int8] sign of self.
|
|
1847
|
+
*/
|
|
1848
|
+
static VALUE int8_sign(VALUE self) {
|
|
1849
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1850
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1851
|
+
ndfunc_t ndf = { iter_int8_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
4588
1852
|
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
uint32_t max;
|
|
4592
|
-
} rand_opt_t;
|
|
1853
|
+
return na_ndloop(&ndf, 1, self);
|
|
1854
|
+
}
|
|
4593
1855
|
|
|
4594
|
-
static void
|
|
4595
|
-
size_t i;
|
|
4596
|
-
char*
|
|
4597
|
-
ssize_t s1;
|
|
4598
|
-
size_t*
|
|
1856
|
+
static void iter_int8_square(na_loop_t* const lp) {
|
|
1857
|
+
size_t i, n;
|
|
1858
|
+
char *p1, *p2;
|
|
1859
|
+
ssize_t s1, s2;
|
|
1860
|
+
size_t *idx1, *idx2;
|
|
4599
1861
|
dtype x;
|
|
4600
|
-
rand_opt_t* g;
|
|
4601
|
-
dtype low;
|
|
4602
|
-
uint32_t max;
|
|
4603
|
-
int shift;
|
|
4604
1862
|
|
|
4605
|
-
INIT_COUNTER(lp,
|
|
1863
|
+
INIT_COUNTER(lp, n);
|
|
4606
1864
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4607
|
-
|
|
4608
|
-
low = g->low;
|
|
4609
|
-
max = g->max;
|
|
4610
|
-
shift = 31 - msb_pos(max);
|
|
1865
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
4611
1866
|
|
|
4612
1867
|
if (idx1) {
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
1868
|
+
if (idx2) {
|
|
1869
|
+
for (i = 0; i < n; i++) {
|
|
1870
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1871
|
+
x = m_square(x);
|
|
1872
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1873
|
+
}
|
|
1874
|
+
} else {
|
|
1875
|
+
for (i = 0; i < n; i++) {
|
|
1876
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1877
|
+
x = m_square(x);
|
|
1878
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1879
|
+
}
|
|
4616
1880
|
}
|
|
4617
1881
|
} else {
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
1882
|
+
if (idx2) {
|
|
1883
|
+
for (i = 0; i < n; i++) {
|
|
1884
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1885
|
+
x = m_square(x);
|
|
1886
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1887
|
+
}
|
|
1888
|
+
} else {
|
|
1889
|
+
//
|
|
1890
|
+
for (i = 0; i < n; i++) {
|
|
1891
|
+
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
1892
|
+
p1 += s1;
|
|
1893
|
+
p2 += s2;
|
|
1894
|
+
}
|
|
1895
|
+
return;
|
|
1896
|
+
//
|
|
4621
1897
|
}
|
|
4622
1898
|
}
|
|
4623
1899
|
}
|
|
4624
1900
|
|
|
4625
1901
|
/*
|
|
4626
|
-
|
|
4627
|
-
@overload
|
|
4628
|
-
@
|
|
4629
|
-
@param [Numeric] high upper exclusive boundary of random numbers. (default=1 or 1+1i for
|
|
4630
|
-
complex types)
|
|
4631
|
-
@return [Numo::Int8] self.
|
|
4632
|
-
@example
|
|
4633
|
-
Numo::DFloat.new(6).rand
|
|
4634
|
-
# => Numo::DFloat#shape=[6]
|
|
4635
|
-
# [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
4636
|
-
|
|
4637
|
-
Numo::DComplex.new(6).rand(5+5i)
|
|
4638
|
-
# => Numo::DComplex#shape=[6]
|
|
4639
|
-
# [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
4640
|
-
|
|
4641
|
-
Numo::Int32.new(6).rand(2,5)
|
|
4642
|
-
# => Numo::Int32#shape=[6]
|
|
4643
|
-
# [4, 3, 3, 2, 4, 2]
|
|
1902
|
+
Unary square.
|
|
1903
|
+
@overload square
|
|
1904
|
+
@return [Numo::Int8] square of self.
|
|
4644
1905
|
*/
|
|
4645
|
-
static VALUE
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4650
|
-
ndfunc_t ndf = { iter_int8_rand, FULL_LOOP, 1, 0, ain, 0 };
|
|
4651
|
-
|
|
4652
|
-
rb_scan_args(argc, argv, "11", &v1, &v2);
|
|
4653
|
-
if (v2 == Qnil) {
|
|
4654
|
-
g.low = m_zero;
|
|
4655
|
-
g.max = high = m_num_to_data(v1);
|
|
4656
|
-
|
|
4657
|
-
} else {
|
|
4658
|
-
g.low = m_num_to_data(v1);
|
|
4659
|
-
high = m_num_to_data(v2);
|
|
4660
|
-
g.max = m_sub(high, g.low);
|
|
4661
|
-
}
|
|
4662
|
-
|
|
4663
|
-
if (high <= g.low) {
|
|
4664
|
-
rb_raise(rb_eArgError, "high must be larger than low");
|
|
4665
|
-
}
|
|
1906
|
+
static VALUE int8_square(VALUE self) {
|
|
1907
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1908
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1909
|
+
ndfunc_t ndf = { iter_int8_square, FULL_LOOP, 1, 1, ain, aout };
|
|
4666
1910
|
|
|
4667
|
-
|
|
4668
|
-
return self;
|
|
1911
|
+
return na_ndloop(&ndf, 1, self);
|
|
4669
1912
|
}
|
|
4670
1913
|
|
|
4671
1914
|
static void iter_int8_poly(na_loop_t* const lp) {
|
|
@@ -5291,22 +2534,91 @@ void Init_numo_int8(void) {
|
|
|
5291
2534
|
rb_define_singleton_method(cT, "cast", int8_s_cast, 1);
|
|
5292
2535
|
rb_define_method(cT, "[]", int8_aref, -1);
|
|
5293
2536
|
rb_define_method(cT, "[]=", int8_aset, -1);
|
|
2537
|
+
/**
|
|
2538
|
+
* return NArray with cast to the type of self.
|
|
2539
|
+
* @overload coerce_cast(type)
|
|
2540
|
+
* @return [nil]
|
|
2541
|
+
*/
|
|
5294
2542
|
rb_define_method(cT, "coerce_cast", int8_coerce_cast, 1);
|
|
2543
|
+
/**
|
|
2544
|
+
* Convert self to Array.
|
|
2545
|
+
* @overload to_a
|
|
2546
|
+
* @return [Array]
|
|
2547
|
+
*/
|
|
5295
2548
|
rb_define_method(cT, "to_a", int8_to_a, 0);
|
|
2549
|
+
/**
|
|
2550
|
+
* Fill elements with other.
|
|
2551
|
+
* @overload fill other
|
|
2552
|
+
* @param [Numeric] other
|
|
2553
|
+
* @return [Numo::Int8] self.
|
|
2554
|
+
*/
|
|
5296
2555
|
rb_define_method(cT, "fill", int8_fill, 1);
|
|
2556
|
+
/**
|
|
2557
|
+
* Format elements into strings.
|
|
2558
|
+
* @overload format format
|
|
2559
|
+
* @param [String] format
|
|
2560
|
+
* @return [Numo::RObject] array of formatted strings.
|
|
2561
|
+
*/
|
|
5297
2562
|
rb_define_method(cT, "format", int8_format, -1);
|
|
2563
|
+
/**
|
|
2564
|
+
* Format elements into strings.
|
|
2565
|
+
* @overload format_to_a format
|
|
2566
|
+
* @param [String] format
|
|
2567
|
+
* @return [Array] array of formatted strings.
|
|
2568
|
+
*/
|
|
5298
2569
|
rb_define_method(cT, "format_to_a", int8_format_to_a, -1);
|
|
2570
|
+
/**
|
|
2571
|
+
* Returns a string containing a human-readable representation of NArray.
|
|
2572
|
+
* @overload inspect
|
|
2573
|
+
* @return [String]
|
|
2574
|
+
*/
|
|
5299
2575
|
rb_define_method(cT, "inspect", int8_inspect, 0);
|
|
5300
2576
|
rb_define_method(cT, "each", int8_each, 0);
|
|
5301
2577
|
rb_define_method(cT, "map", int8_map, 0);
|
|
5302
2578
|
rb_define_method(cT, "each_with_index", int8_each_with_index, 0);
|
|
5303
2579
|
rb_define_method(cT, "map_with_index", int8_map_with_index, 0);
|
|
5304
2580
|
rb_define_method(cT, "abs", int8_abs, 0);
|
|
2581
|
+
/**
|
|
2582
|
+
* Binary add.
|
|
2583
|
+
* @overload + other
|
|
2584
|
+
* @param [Numo::NArray,Numeric] other
|
|
2585
|
+
* @return [Numo::NArray] self + other
|
|
2586
|
+
*/
|
|
5305
2587
|
rb_define_method(cT, "+", int8_add, 1);
|
|
2588
|
+
/**
|
|
2589
|
+
* Binary sub.
|
|
2590
|
+
* @overload - other
|
|
2591
|
+
* @param [Numo::NArray,Numeric] other
|
|
2592
|
+
* @return [Numo::NArray] self - other
|
|
2593
|
+
*/
|
|
5306
2594
|
rb_define_method(cT, "-", int8_sub, 1);
|
|
2595
|
+
/**
|
|
2596
|
+
* Binary mul.
|
|
2597
|
+
* @overload * other
|
|
2598
|
+
* @param [Numo::NArray,Numeric] other
|
|
2599
|
+
* @return [Numo::NArray] self * other
|
|
2600
|
+
*/
|
|
5307
2601
|
rb_define_method(cT, "*", int8_mul, 1);
|
|
2602
|
+
/**
|
|
2603
|
+
* Binary div.
|
|
2604
|
+
* @overload / other
|
|
2605
|
+
* @param [Numo::NArray,Numeric] other
|
|
2606
|
+
* @return [Numo::NArray] self / other
|
|
2607
|
+
*/
|
|
5308
2608
|
rb_define_method(cT, "/", int8_div, 1);
|
|
2609
|
+
/**
|
|
2610
|
+
* Binary mod.
|
|
2611
|
+
* @overload % other
|
|
2612
|
+
* @param [Numo::NArray,Numeric] other
|
|
2613
|
+
* @return [Numo::NArray] self % other
|
|
2614
|
+
*/
|
|
5309
2615
|
rb_define_method(cT, "%", int8_mod, 1);
|
|
2616
|
+
/**
|
|
2617
|
+
* Binary divmod.
|
|
2618
|
+
* @overload divmod other
|
|
2619
|
+
* @param [Numo::NArray,Numeric] other
|
|
2620
|
+
* @return [Numo::NArray] divmod of self and other.
|
|
2621
|
+
*/
|
|
5310
2622
|
rb_define_method(cT, "divmod", int8_divmod, 1);
|
|
5311
2623
|
rb_define_method(cT, "**", int8_pow, 1);
|
|
5312
2624
|
rb_define_alias(cT, "pow", "**");
|
|
@@ -5317,39 +2629,264 @@ void Init_numo_int8(void) {
|
|
|
5317
2629
|
rb_define_alias(cT, "conj", "view");
|
|
5318
2630
|
rb_define_alias(cT, "im", "view");
|
|
5319
2631
|
rb_define_alias(cT, "conjugate", "conj");
|
|
2632
|
+
/**
|
|
2633
|
+
* Comparison eq other.
|
|
2634
|
+
* @overload eq other
|
|
2635
|
+
* @param [Numo::NArray,Numeric] other
|
|
2636
|
+
* @return [Numo::Bit] result of self eq other.
|
|
2637
|
+
*/
|
|
5320
2638
|
rb_define_method(cT, "eq", int8_eq, 1);
|
|
2639
|
+
/**
|
|
2640
|
+
* Comparison ne other.
|
|
2641
|
+
* @overload ne other
|
|
2642
|
+
* @param [Numo::NArray,Numeric] other
|
|
2643
|
+
* @return [Numo::Bit] result of self ne other.
|
|
2644
|
+
*/
|
|
5321
2645
|
rb_define_method(cT, "ne", int8_ne, 1);
|
|
5322
2646
|
rb_define_alias(cT, "nearly_eq", "eq");
|
|
5323
2647
|
rb_define_alias(cT, "close_to", "nearly_eq");
|
|
2648
|
+
/**
|
|
2649
|
+
* Binary bit_and.
|
|
2650
|
+
* @overload & other
|
|
2651
|
+
* @param [Numo::NArray,Numeric] other
|
|
2652
|
+
* @return [Numo::NArray] self & other
|
|
2653
|
+
*/
|
|
5324
2654
|
rb_define_method(cT, "&", int8_bit_and, 1);
|
|
2655
|
+
/**
|
|
2656
|
+
* Binary bit_or.
|
|
2657
|
+
* @overload | other
|
|
2658
|
+
* @param [Numo::NArray,Numeric] other
|
|
2659
|
+
* @return [Numo::NArray] self | other
|
|
2660
|
+
*/
|
|
5325
2661
|
rb_define_method(cT, "|", int8_bit_or, 1);
|
|
2662
|
+
/**
|
|
2663
|
+
* binary bit_xor.
|
|
2664
|
+
* @overload ^ other
|
|
2665
|
+
* @param [numo::narray,numeric] other
|
|
2666
|
+
* @return [numo::narray] self ^ other
|
|
2667
|
+
*/
|
|
5326
2668
|
rb_define_method(cT, "^", int8_bit_xor, 1);
|
|
2669
|
+
/**
|
|
2670
|
+
* Unary bit_not.
|
|
2671
|
+
* @overload ~
|
|
2672
|
+
* @return [Numo::Int8] bit_not of self.
|
|
2673
|
+
*/
|
|
5327
2674
|
rb_define_method(cT, "~", int8_bit_not, 0);
|
|
2675
|
+
/**
|
|
2676
|
+
* Binary left_shift.
|
|
2677
|
+
* @overload << other
|
|
2678
|
+
* @param [Numo::NArray,Numeric] other
|
|
2679
|
+
* @return [Numo::NArray] self << other
|
|
2680
|
+
*/
|
|
5328
2681
|
rb_define_method(cT, "<<", int8_left_shift, 1);
|
|
2682
|
+
/**
|
|
2683
|
+
* Binary right_shift.
|
|
2684
|
+
* @overload >> other
|
|
2685
|
+
* @param [Numo::NArray,Numeric] other
|
|
2686
|
+
* @return [Numo::NArray] self >> other
|
|
2687
|
+
*/
|
|
5329
2688
|
rb_define_method(cT, ">>", int8_right_shift, 1);
|
|
5330
2689
|
rb_define_alias(cT, "floor", "view");
|
|
5331
2690
|
rb_define_alias(cT, "round", "view");
|
|
5332
2691
|
rb_define_alias(cT, "ceil", "view");
|
|
5333
2692
|
rb_define_alias(cT, "trunc", "view");
|
|
5334
2693
|
rb_define_alias(cT, "rint", "view");
|
|
2694
|
+
/**
|
|
2695
|
+
* Comparison gt other.
|
|
2696
|
+
* @overload gt other
|
|
2697
|
+
* @param [Numo::NArray,Numeric] other
|
|
2698
|
+
* @return [Numo::Bit] result of self gt other.
|
|
2699
|
+
*/
|
|
5335
2700
|
rb_define_method(cT, "gt", int8_gt, 1);
|
|
2701
|
+
/**
|
|
2702
|
+
* Comparison ge other.
|
|
2703
|
+
* @overload ge other
|
|
2704
|
+
* @param [Numo::NArray,Numeric] other
|
|
2705
|
+
* @return [Numo::Bit] result of self ge other.
|
|
2706
|
+
*/
|
|
5336
2707
|
rb_define_method(cT, "ge", int8_ge, 1);
|
|
2708
|
+
/**
|
|
2709
|
+
* Comparison lt other.
|
|
2710
|
+
* @overload lt other
|
|
2711
|
+
* @param [Numo::NArray,Numeric] other
|
|
2712
|
+
* @return [Numo::Bit] result of self lt other.
|
|
2713
|
+
*/
|
|
5337
2714
|
rb_define_method(cT, "lt", int8_lt, 1);
|
|
2715
|
+
/**
|
|
2716
|
+
* Comparison le other.
|
|
2717
|
+
* @overload le other
|
|
2718
|
+
* @param [Numo::NArray,Numeric] other
|
|
2719
|
+
* @return [Numo::Bit] result of self le other.
|
|
2720
|
+
*/
|
|
5338
2721
|
rb_define_method(cT, "le", int8_le, 1);
|
|
5339
2722
|
rb_define_alias(cT, ">", "gt");
|
|
5340
2723
|
rb_define_alias(cT, ">=", "ge");
|
|
5341
2724
|
rb_define_alias(cT, "<", "lt");
|
|
5342
2725
|
rb_define_alias(cT, "<=", "le");
|
|
2726
|
+
/**
|
|
2727
|
+
* Clip array elements by [min,max].
|
|
2728
|
+
* If either of min or max is nil, one side is clipped.
|
|
2729
|
+
* @overload clip(min,max)
|
|
2730
|
+
* @param [Numo::NArray,Numeric] min
|
|
2731
|
+
* @param [Numo::NArray,Numeric] max
|
|
2732
|
+
* @return [Numo::NArray] result of clip.
|
|
2733
|
+
*
|
|
2734
|
+
* @example
|
|
2735
|
+
* a = Numo::Int32.new(10).seq
|
|
2736
|
+
* # => Numo::Int32#shape=[10]
|
|
2737
|
+
* # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
2738
|
+
*
|
|
2739
|
+
* a.clip(1,8)
|
|
2740
|
+
* # => Numo::Int32#shape=[10]
|
|
2741
|
+
* # [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
2742
|
+
*
|
|
2743
|
+
* a.inplace.clip(3,6)
|
|
2744
|
+
* a
|
|
2745
|
+
* # => Numo::Int32#shape=[10]
|
|
2746
|
+
* # [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
|
|
2747
|
+
*
|
|
2748
|
+
* b = Numo::Int32.new(10).seq
|
|
2749
|
+
* # => Numo::Int32#shape=[10]
|
|
2750
|
+
* # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
2751
|
+
*
|
|
2752
|
+
* b.clip([3,4,1,1,1,4,4,4,4,4], 8)
|
|
2753
|
+
* # => Numo::Int32#shape=[10]
|
|
2754
|
+
* # [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
2755
|
+
*/
|
|
5343
2756
|
rb_define_method(cT, "clip", int8_clip, 2);
|
|
2757
|
+
/**
|
|
2758
|
+
* sum of self.
|
|
2759
|
+
* @overload sum(axis:nil, keepdims:false)
|
|
2760
|
+
* @param [Numeric,Array,Range] axis Performs sum along the axis.
|
|
2761
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
2762
|
+
* dimensions with size one.
|
|
2763
|
+
* @return [Numo::Int8] returns result of sum.
|
|
2764
|
+
*/
|
|
5344
2765
|
rb_define_method(cT, "sum", int8_sum, -1);
|
|
2766
|
+
/**
|
|
2767
|
+
* prod of self.
|
|
2768
|
+
* @overload prod(axis:nil, keepdims:false)
|
|
2769
|
+
* @param [Numeric,Array,Range] axis Performs prod along the axis.
|
|
2770
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
2771
|
+
* dimensions with size one.
|
|
2772
|
+
* @return [Numo::Int64] returns result of prod.
|
|
2773
|
+
*/
|
|
5345
2774
|
rb_define_method(cT, "prod", int8_prod, -1);
|
|
2775
|
+
/**
|
|
2776
|
+
* min of self.
|
|
2777
|
+
* @overload min(axis:nil, keepdims:false)
|
|
2778
|
+
* @param [Numeric,Array,Range] axis Performs min along the axis.
|
|
2779
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
2780
|
+
* dimensions with size one.
|
|
2781
|
+
* @return [Numo::Int8] returns result of min.
|
|
2782
|
+
*/
|
|
5346
2783
|
rb_define_method(cT, "min", int8_min, -1);
|
|
2784
|
+
/**
|
|
2785
|
+
* max of self.
|
|
2786
|
+
* @overload max(axis:nil, keepdims:false)
|
|
2787
|
+
* @param [Numeric,Array,Range] axis Performs max along the axis.
|
|
2788
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
2789
|
+
* dimensions with size one.
|
|
2790
|
+
* @return [Numo::Int8] returns result of max.
|
|
2791
|
+
*/
|
|
5347
2792
|
rb_define_method(cT, "max", int8_max, -1);
|
|
2793
|
+
/**
|
|
2794
|
+
* ptp of self.
|
|
2795
|
+
* @overload ptp(axis:nil, keepdims:false)
|
|
2796
|
+
* @param [Numeric,Array,Range] axis Performs ptp along the axis.
|
|
2797
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
2798
|
+
* dimensions with size one.
|
|
2799
|
+
* @return [Numo::Int8] returns result of ptp.
|
|
2800
|
+
*/
|
|
5348
2801
|
rb_define_method(cT, "ptp", int8_ptp, -1);
|
|
2802
|
+
/**
|
|
2803
|
+
* Index of the maximum value.
|
|
2804
|
+
* @overload max_index(axis:nil)
|
|
2805
|
+
* @param [Numeric,Array,Range] axis Finds maximum values along the axis and
|
|
2806
|
+
* returns **flat 1-d indices**.
|
|
2807
|
+
* @return [Integer,Numo::Int] returns result indices.
|
|
2808
|
+
* @see #argmax
|
|
2809
|
+
* @see #max
|
|
2810
|
+
*
|
|
2811
|
+
* @example
|
|
2812
|
+
* a = Numo::NArray[3,4,1,2]
|
|
2813
|
+
* a.max_index #=> 1
|
|
2814
|
+
*
|
|
2815
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
2816
|
+
* b.max_index #=> 5
|
|
2817
|
+
* b.max_index(axis:1) #=> [1, 5]
|
|
2818
|
+
* b.max_index(axis:0) #=> [0, 1, 5]
|
|
2819
|
+
* b[b.max_index(axis:0)] #=> [3, 4, 5]
|
|
2820
|
+
*/
|
|
5349
2821
|
rb_define_method(cT, "max_index", int8_max_index, -1);
|
|
2822
|
+
/**
|
|
2823
|
+
* Index of the minimum value.
|
|
2824
|
+
* @overload min_index(axis:nil)
|
|
2825
|
+
* @param [Numeric,Array,Range] axis Finds minimum values along the axis and
|
|
2826
|
+
* returns **flat 1-d indices**.
|
|
2827
|
+
* @return [Integer,Numo::Int] returns result indices.
|
|
2828
|
+
* @see #argmin
|
|
2829
|
+
* @see #min
|
|
2830
|
+
*
|
|
2831
|
+
* @example
|
|
2832
|
+
* a = Numo::NArray[3,4,1,2]
|
|
2833
|
+
* a.min_index #=> 2
|
|
2834
|
+
*
|
|
2835
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
2836
|
+
* b.min_index #=> 4
|
|
2837
|
+
* b.min_index(axis:1) #=> [2, 4]
|
|
2838
|
+
* b.min_index(axis:0) #=> [3, 4, 2]
|
|
2839
|
+
* b[b.min_index(axis:0)] #=> [2, 0, 1]
|
|
2840
|
+
*/
|
|
5350
2841
|
rb_define_method(cT, "min_index", int8_min_index, -1);
|
|
2842
|
+
/**
|
|
2843
|
+
* Index of the maximum value.
|
|
2844
|
+
* @overload argmax(axis:nil)
|
|
2845
|
+
* @param [Numeric,Array,Range] axis Finds maximum values along the axis and
|
|
2846
|
+
* returns **indices along the axis**.
|
|
2847
|
+
* @return [Integer,Numo::Int] returns the result indices.
|
|
2848
|
+
* @see #max_index
|
|
2849
|
+
* @see #max
|
|
2850
|
+
*
|
|
2851
|
+
* @example
|
|
2852
|
+
* a = Numo::NArray[3,4,1,2]
|
|
2853
|
+
* a.argmax #=> 1
|
|
2854
|
+
*
|
|
2855
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
2856
|
+
* b.argmax #=> 5
|
|
2857
|
+
* b.argmax(axis:1) #=> [1, 2]
|
|
2858
|
+
* b.argmax(axis:0) #=> [0, 0, 1]
|
|
2859
|
+
* b.at(b.argmax(axis:0), 0..-1) #=> [3, 4, 5]
|
|
2860
|
+
*/
|
|
5351
2861
|
rb_define_method(cT, "argmax", int8_argmax, -1);
|
|
2862
|
+
/**
|
|
2863
|
+
* Index of the minimum value.
|
|
2864
|
+
* @overload argmin(axis:nil)
|
|
2865
|
+
* @param [Numeric,Array,Range] axis Finds minimum values along the axis and
|
|
2866
|
+
* returns **indices along the axis**.
|
|
2867
|
+
* @return [Integer,Numo::Int] returns the result indices.
|
|
2868
|
+
* @see #min_index
|
|
2869
|
+
* @see #min
|
|
2870
|
+
*
|
|
2871
|
+
* @example
|
|
2872
|
+
* a = Numo::NArray[3,4,1,2]
|
|
2873
|
+
* a.argmin #=> 2
|
|
2874
|
+
*
|
|
2875
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
2876
|
+
* b.argmin #=> 4
|
|
2877
|
+
* b.argmin(axis:1) #=> [2, 1]
|
|
2878
|
+
* b.argmin(axis:0) #=> [1, 1, 0]
|
|
2879
|
+
* b.at(b.argmin(axis:0), 0..-1) #=> [2, 0, 1]
|
|
2880
|
+
*/
|
|
5352
2881
|
rb_define_method(cT, "argmin", int8_argmin, -1);
|
|
2882
|
+
/**
|
|
2883
|
+
* minmax of self.
|
|
2884
|
+
* @overload minmax(axis:nil, keepdims:false)
|
|
2885
|
+
* @param [Numeric,Array,Range] axis Finds min-max along the axis.
|
|
2886
|
+
* @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in
|
|
2887
|
+
* the result array as dimensions with size one.
|
|
2888
|
+
* @return [Numo::Int8,Numo::Int8] min and max of self.
|
|
2889
|
+
*/
|
|
5353
2890
|
rb_define_method(cT, "minmax", int8_minmax, -1);
|
|
5354
2891
|
/**
|
|
5355
2892
|
* Element-wise maximum of two arrays.
|
|
@@ -5365,13 +2902,114 @@ void Init_numo_int8(void) {
|
|
|
5365
2902
|
* @return [Numo::Int8]
|
|
5366
2903
|
*/
|
|
5367
2904
|
rb_define_module_function(cT, "minimum", int8_s_minimum, -1);
|
|
2905
|
+
/**
|
|
2906
|
+
* Count the number of occurrences of each non-negative integer value.
|
|
2907
|
+
* Only Integer-types has this method.
|
|
2908
|
+
*
|
|
2909
|
+
* @overload bincount([weight], minlength:nil)
|
|
2910
|
+
* @param [SFloat or DFloat or Array] weight (optional) Array of
|
|
2911
|
+
* float values. Its size along last axis should be same as that of self.
|
|
2912
|
+
* @param [Integer] minlength (keyword, optional) Minimum size along
|
|
2913
|
+
* last axis for the output array.
|
|
2914
|
+
* @return [UInt32 or UInt64 or SFloat or DFloat]
|
|
2915
|
+
* Returns Float NArray if weight array is supplied,
|
|
2916
|
+
* otherwise returns UInt32 or UInt64 depending on the size along last axis.
|
|
2917
|
+
* @example
|
|
2918
|
+
* Numo::Int32[0..4].bincount
|
|
2919
|
+
* # => Numo::UInt32#shape=[5]
|
|
2920
|
+
* # [1, 1, 1, 1, 1]
|
|
2921
|
+
*
|
|
2922
|
+
* Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
|
|
2923
|
+
* # => Numo::UInt32#shape=[8]
|
|
2924
|
+
* # [1, 3, 1, 1, 0, 0, 0, 1]
|
|
2925
|
+
*
|
|
2926
|
+
* x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
|
|
2927
|
+
* x.bincount.size == x.max+1
|
|
2928
|
+
* # => true
|
|
2929
|
+
*
|
|
2930
|
+
* w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
|
|
2931
|
+
* x = Numo::Int32[0, 1, 1, 2, 2, 2]
|
|
2932
|
+
* x.bincount(w)
|
|
2933
|
+
* # => Numo::DFloat#shape=[3]
|
|
2934
|
+
* # [0.3, 0.7, 1.1]
|
|
2935
|
+
*/
|
|
5368
2936
|
rb_define_method(cT, "bincount", int8_bincount, -1);
|
|
2937
|
+
/**
|
|
2938
|
+
* cumsum of self.
|
|
2939
|
+
* @overload cumsum(axis:nil, nan:false)
|
|
2940
|
+
* @param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
2941
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
2942
|
+
* @return [Numo::Int8] cumsum of self.
|
|
2943
|
+
*/
|
|
5369
2944
|
rb_define_method(cT, "cumsum", int8_cumsum, -1);
|
|
2945
|
+
/**
|
|
2946
|
+
* cumprod of self.
|
|
2947
|
+
* @overload cumprod(axis:nil, nan:false)
|
|
2948
|
+
* @param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
2949
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
2950
|
+
* @return [Numo::Int8] cumprod of self.
|
|
2951
|
+
*/
|
|
5370
2952
|
rb_define_method(cT, "cumprod", int8_cumprod, -1);
|
|
2953
|
+
/**
|
|
2954
|
+
* Binary mulsum.
|
|
2955
|
+
*
|
|
2956
|
+
* @overload mulsum(other, axis:nil, keepdims:false)
|
|
2957
|
+
* @param [Numo::NArray,Numeric] other
|
|
2958
|
+
* @param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
2959
|
+
* @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in
|
|
2960
|
+
* the result array as dimensions with size one.
|
|
2961
|
+
* @return [Numo::NArray] mulsum of self and other.
|
|
2962
|
+
*/
|
|
5371
2963
|
rb_define_method(cT, "mulsum", int8_mulsum, -1);
|
|
2964
|
+
/**
|
|
2965
|
+
* Set linear sequence of numbers to self. The sequence is obtained from
|
|
2966
|
+
* beg+i*step
|
|
2967
|
+
* where i is 1-dimensional index.
|
|
2968
|
+
* @overload seq([beg,[step]])
|
|
2969
|
+
* @param [Numeric] beg beginning of sequence. (default=0)
|
|
2970
|
+
* @param [Numeric] step step of sequence. (default=1)
|
|
2971
|
+
* @return [Numo::Int8] self.
|
|
2972
|
+
* @example
|
|
2973
|
+
* Numo::DFloat.new(6).seq(1,-0.2)
|
|
2974
|
+
* # => Numo::DFloat#shape=[6]
|
|
2975
|
+
* # [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
2976
|
+
*
|
|
2977
|
+
* Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
2978
|
+
* # => Numo::DComplex#shape=[6]
|
|
2979
|
+
* # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
2980
|
+
*/
|
|
5372
2981
|
rb_define_method(cT, "seq", int8_seq, -1);
|
|
2982
|
+
/**
|
|
2983
|
+
* Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
|
2984
|
+
* @overload eye([element,offset])
|
|
2985
|
+
* @param [Numeric] element Diagonal element to be stored. Default is 1.
|
|
2986
|
+
* @param [Integer] offset Diagonal offset from the main diagonal. The
|
|
2987
|
+
* default is 0. k>0 for diagonals above the main diagonal, and k<0
|
|
2988
|
+
* for diagonals below the main diagonal.
|
|
2989
|
+
* @return [Numo::Int8] eye of self.
|
|
2990
|
+
*/
|
|
5373
2991
|
rb_define_method(cT, "eye", int8_eye, -1);
|
|
5374
2992
|
rb_define_alias(cT, "indgen", "seq");
|
|
2993
|
+
/**
|
|
2994
|
+
* Generate uniformly distributed random numbers on self narray.
|
|
2995
|
+
* @overload rand([[low],high])
|
|
2996
|
+
* @param [Numeric] low lower inclusive boundary of random numbers. (default=0)
|
|
2997
|
+
* @param [Numeric] high upper exclusive boundary of random numbers.
|
|
2998
|
+
* (default=1 or 1+1i for complex types)
|
|
2999
|
+
* @return [Numo::Int8] self.
|
|
3000
|
+
* @example
|
|
3001
|
+
* Numo::DFloat.new(6).rand
|
|
3002
|
+
* # => Numo::DFloat#shape=[6]
|
|
3003
|
+
* # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
3004
|
+
*
|
|
3005
|
+
* Numo::DComplex.new(6).rand(5+5i)
|
|
3006
|
+
* # => Numo::DComplex#shape=[6]
|
|
3007
|
+
* # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
3008
|
+
*
|
|
3009
|
+
* Numo::Int32.new(6).rand(2,5)
|
|
3010
|
+
* # => Numo::Int32#shape=[6]
|
|
3011
|
+
* # [4, 3, 3, 2, 4, 2]
|
|
3012
|
+
*/
|
|
5375
3013
|
rb_define_method(cT, "rand", int8_rand, -1);
|
|
5376
3014
|
rb_define_method(cT, "poly", int8_poly, -2);
|
|
5377
3015
|
|