numo-narray-alt 0.9.13 → 0.9.14
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/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/src/mh/abs.h +56 -0
- data/ext/numo/narray/src/mh/aref.h +28 -0
- data/ext/numo/narray/src/mh/arg.h +56 -0
- data/ext/numo/narray/src/mh/conj.h +71 -0
- data/ext/numo/narray/src/mh/copysign.h +97 -0
- data/ext/numo/narray/src/mh/each.h +71 -0
- data/ext/numo/narray/src/mh/each_with_index.h +98 -0
- data/ext/numo/narray/src/mh/extract.h +36 -0
- data/ext/numo/narray/src/mh/im.h +71 -0
- data/ext/numo/narray/src/mh/imag.h +56 -0
- data/ext/numo/narray/src/mh/kahan_sum.h +39 -0
- data/ext/numo/narray/src/mh/map.h +126 -0
- data/ext/numo/narray/src/mh/map_with_index.h +76 -0
- data/ext/numo/narray/src/mh/modf.h +35 -0
- data/ext/numo/narray/src/mh/poly.h +42 -0
- data/ext/numo/narray/src/mh/real.h +56 -0
- data/ext/numo/narray/src/mh/set_imag.h +60 -0
- data/ext/numo/narray/src/mh/set_real.h +60 -0
- data/ext/numo/narray/src/mh/signbit.h +42 -0
- data/ext/numo/narray/src/t_bit.c +63 -176
- data/ext/numo/narray/src/t_dcomplex.c +142 -1001
- data/ext/numo/narray/src/t_dfloat.c +24 -560
- data/ext/numo/narray/src/t_int16.c +83 -417
- data/ext/numo/narray/src/t_int32.c +83 -417
- data/ext/numo/narray/src/t_int64.c +83 -417
- data/ext/numo/narray/src/t_int8.c +83 -400
- data/ext/numo/narray/src/t_robject.c +83 -400
- data/ext/numo/narray/src/t_scomplex.c +130 -953
- data/ext/numo/narray/src/t_sfloat.c +22 -524
- data/ext/numo/narray/src/t_uint16.c +83 -417
- data/ext/numo/narray/src/t_uint32.c +83 -417
- data/ext/numo/narray/src/t_uint64.c +83 -417
- data/ext/numo/narray/src/t_uint8.c +83 -400
- metadata +21 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_SET_REAL_H
|
|
2
|
+
#define NUMO_NARRAY_MH_SET_REAL_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_SET_REAL_METHOD_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass) \
|
|
5
|
+
static void iter_##tDType##_set_real(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
ssize_t s1; \
|
|
10
|
+
ssize_t s2; \
|
|
11
|
+
size_t* idx1; \
|
|
12
|
+
size_t* idx2; \
|
|
13
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
16
|
+
tDType x; \
|
|
17
|
+
tRtDType y; \
|
|
18
|
+
if (idx1) { \
|
|
19
|
+
if (idx2) { \
|
|
20
|
+
for (size_t i = 0; i < n; i++) { \
|
|
21
|
+
GET_DATA(p1 + *idx1, tDType, x); \
|
|
22
|
+
GET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
23
|
+
x = m_set_real(x, y); \
|
|
24
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
25
|
+
} \
|
|
26
|
+
} else { \
|
|
27
|
+
for (size_t i = 0; i < n; i++) { \
|
|
28
|
+
GET_DATA(p1 + *idx1, tDType, x); \
|
|
29
|
+
GET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
30
|
+
x = m_set_real(x, y); \
|
|
31
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
32
|
+
} \
|
|
33
|
+
} \
|
|
34
|
+
} else { \
|
|
35
|
+
if (idx2) { \
|
|
36
|
+
for (size_t i = 0; i < n; i++) { \
|
|
37
|
+
GET_DATA(p1, tDType, x); \
|
|
38
|
+
GET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
39
|
+
x = m_set_real(x, y); \
|
|
40
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
41
|
+
} \
|
|
42
|
+
} else { \
|
|
43
|
+
for (size_t i = 0; i < n; i++) { \
|
|
44
|
+
GET_DATA(p1, tDType, x); \
|
|
45
|
+
GET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
46
|
+
x = m_set_real(x, y); \
|
|
47
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
48
|
+
} \
|
|
49
|
+
} \
|
|
50
|
+
} \
|
|
51
|
+
} \
|
|
52
|
+
\
|
|
53
|
+
static VALUE tDType##_set_real(VALUE self, VALUE a1) { \
|
|
54
|
+
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { tRtNAryClass, 0 } }; \
|
|
55
|
+
ndfunc_t ndf = { iter_##tDType##_set_real, FULL_LOOP, 2, 0, ain, 0 }; \
|
|
56
|
+
na_ndloop(&ndf, 2, self, a1); \
|
|
57
|
+
return a1; \
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#endif /* NUMO_NARRAY_MH_SET_REAL_H */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_SIGNBIT_H
|
|
2
|
+
#define NUMO_NARRAY_MH_SIGNBIT_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_SIGNBIT_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_signbit(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
ssize_t s1; \
|
|
9
|
+
size_t* idx1; \
|
|
10
|
+
BIT_DIGIT* a2; \
|
|
11
|
+
size_t p2; \
|
|
12
|
+
ssize_t s2; \
|
|
13
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
INIT_PTR_BIT(lp, 1, a2, p2, s2); \
|
|
16
|
+
BIT_DIGIT b; \
|
|
17
|
+
tDType x; \
|
|
18
|
+
if (idx1) { \
|
|
19
|
+
for (size_t i = 0; i < n; i++) { \
|
|
20
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
21
|
+
b = (m_signbit(x)) ? 1 : 0; \
|
|
22
|
+
STORE_BIT(a2, p2, b); \
|
|
23
|
+
p2 += s2; \
|
|
24
|
+
} \
|
|
25
|
+
} else { \
|
|
26
|
+
for (size_t i = 0; i < n; i++) { \
|
|
27
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
28
|
+
b = (m_signbit(x)) ? 1 : 0; \
|
|
29
|
+
STORE_BIT(a2, p2, b); \
|
|
30
|
+
p2 += s2; \
|
|
31
|
+
} \
|
|
32
|
+
} \
|
|
33
|
+
} \
|
|
34
|
+
\
|
|
35
|
+
static VALUE tDType##_signbit(VALUE self) { \
|
|
36
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
37
|
+
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } }; \
|
|
38
|
+
ndfunc_t ndf = { iter_##tDType##_signbit, FULL_LOOP, 1, 1, ain, aout }; \
|
|
39
|
+
return na_ndloop(&ndf, 1, self); \
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#endif /* NUMO_NARRAY_MH_SIGNBIT_H */
|
data/ext/numo/narray/src/t_bit.c
CHANGED
|
@@ -31,23 +31,31 @@ static ID id_to_a;
|
|
|
31
31
|
VALUE cT;
|
|
32
32
|
extern VALUE cRT;
|
|
33
33
|
|
|
34
|
+
#include "mh/extract.h"
|
|
35
|
+
#include "mh/aref.h"
|
|
34
36
|
#include "mh/coerce_cast.h"
|
|
35
37
|
#include "mh/to_a.h"
|
|
36
38
|
#include "mh/fill.h"
|
|
37
39
|
#include "mh/format.h"
|
|
38
40
|
#include "mh/format_to_a.h"
|
|
39
41
|
#include "mh/inspect.h"
|
|
42
|
+
#include "mh/each.h"
|
|
43
|
+
#include "mh/each_with_index.h"
|
|
40
44
|
#include "mh/mean.h"
|
|
41
45
|
#include "mh/var.h"
|
|
42
46
|
#include "mh/stddev.h"
|
|
43
47
|
#include "mh/rms.h"
|
|
44
48
|
|
|
49
|
+
DEF_NARRAY_BIT_EXTRACT_METHOD_FUNC()
|
|
50
|
+
DEF_NARRAY_BIT_AREF_METHOD_FUNC()
|
|
45
51
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(bit)
|
|
46
52
|
DEF_NARRAY_BIT_TO_A_METHOD_FUNC()
|
|
47
53
|
DEF_NARRAY_BIT_FILL_METHOD_FUNC()
|
|
48
54
|
DEF_NARRAY_BIT_FORMAT_METHOD_FUNC()
|
|
49
55
|
DEF_NARRAY_BIT_FORMAT_TO_A_METHOD_FUNC()
|
|
50
56
|
DEF_NARRAY_BIT_INSPECT_METHOD_FUNC()
|
|
57
|
+
DEF_NARRAY_BIT_EACH_METHOD_FUNC()
|
|
58
|
+
DEF_NARRAY_BIT_EACH_WITH_INDEX_METHOD_FUNC()
|
|
51
59
|
DEF_NARRAY_BIT_MEAN_METHOD_FUNC()
|
|
52
60
|
DEF_NARRAY_BIT_VAR_METHOD_FUNC()
|
|
53
61
|
DEF_NARRAY_BIT_STDDEV_METHOD_FUNC()
|
|
@@ -152,30 +160,6 @@ static VALUE bit_allocate(VALUE self) {
|
|
|
152
160
|
return self;
|
|
153
161
|
}
|
|
154
162
|
|
|
155
|
-
/*
|
|
156
|
-
Extract an element only if self is a dimensionless NArray.
|
|
157
|
-
@overload extract
|
|
158
|
-
@return [Numeric,Numo::NArray]
|
|
159
|
-
--- Extract element value as Ruby Object if self is a dimensionless NArray,
|
|
160
|
-
otherwise returns self.
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
static VALUE bit_extract(VALUE self) {
|
|
164
|
-
BIT_DIGIT *ptr, val;
|
|
165
|
-
size_t pos;
|
|
166
|
-
narray_t* na;
|
|
167
|
-
GetNArray(self, na);
|
|
168
|
-
|
|
169
|
-
if (na->ndim == 0) {
|
|
170
|
-
pos = na_get_offset(self);
|
|
171
|
-
ptr = (BIT_DIGIT*)na_get_pointer_for_read(self);
|
|
172
|
-
val = ((*((ptr) + (pos) / NB)) >> ((pos) % NB)) & 1u;
|
|
173
|
-
na_release_lock(self);
|
|
174
|
-
return INT2FIX(val);
|
|
175
|
-
}
|
|
176
|
-
return self;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
163
|
static VALUE bit_new_dim0(dtype x) {
|
|
180
164
|
VALUE v;
|
|
181
165
|
dtype* ptr;
|
|
@@ -1268,53 +1252,6 @@ static VALUE bit_s_cast(VALUE type, VALUE obj) {
|
|
|
1268
1252
|
return Qnil;
|
|
1269
1253
|
}
|
|
1270
1254
|
|
|
1271
|
-
/*
|
|
1272
|
-
Multi-dimensional element reference.
|
|
1273
|
-
@overload [](dim0,...,dimL)
|
|
1274
|
-
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
|
1275
|
-
dim0,...,dimL multi-dimensional indices.
|
|
1276
|
-
@return [Numeric,Numo::Bit] an element or NArray view.
|
|
1277
|
-
@see Numo::NArray#[]
|
|
1278
|
-
@see #[]=
|
|
1279
|
-
|
|
1280
|
-
@example
|
|
1281
|
-
a = Numo::Int32.new(3,4).seq
|
|
1282
|
-
# => Numo::Int32#shape=[3,4]
|
|
1283
|
-
# [[0, 1, 2, 3],
|
|
1284
|
-
# [4, 5, 6, 7],
|
|
1285
|
-
# [8, 9, 10, 11]]
|
|
1286
|
-
|
|
1287
|
-
b = (a%2).eq(0)
|
|
1288
|
-
# => Numo::Bit#shape=[3,4]
|
|
1289
|
-
# [[1, 0, 1, 0],
|
|
1290
|
-
# [1, 0, 1, 0],
|
|
1291
|
-
# [1, 0, 1, 0]]
|
|
1292
|
-
|
|
1293
|
-
b[true,(0..-1)%2]
|
|
1294
|
-
# => Numo::Bit(view)#shape=[3,2]
|
|
1295
|
-
# [[1, 1],
|
|
1296
|
-
# [1, 1],
|
|
1297
|
-
# [1, 1]]
|
|
1298
|
-
|
|
1299
|
-
b[1,1]
|
|
1300
|
-
# => 0
|
|
1301
|
-
*/
|
|
1302
|
-
static VALUE bit_aref(int argc, VALUE* argv, VALUE self) {
|
|
1303
|
-
int nd;
|
|
1304
|
-
size_t pos;
|
|
1305
|
-
char* ptr;
|
|
1306
|
-
dtype x;
|
|
1307
|
-
|
|
1308
|
-
nd = na_get_result_dimension(self, argc, argv, 1, &pos);
|
|
1309
|
-
if (nd) {
|
|
1310
|
-
return na_aref_main(argc, argv, self, 0, nd);
|
|
1311
|
-
} else {
|
|
1312
|
-
ptr = na_get_pointer_for_read(self);
|
|
1313
|
-
LOAD_BIT(ptr, pos, x);
|
|
1314
|
-
return m_data_to_num(x);
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
1255
|
/*
|
|
1319
1256
|
Multi-dimensional element assignment.
|
|
1320
1257
|
@overload []=(dim0,...,dimL,val)
|
|
@@ -1365,111 +1302,6 @@ static VALUE bit_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1365
1302
|
return argv[argc];
|
|
1366
1303
|
}
|
|
1367
1304
|
|
|
1368
|
-
static void iter_bit_each(na_loop_t* const lp) {
|
|
1369
|
-
size_t i;
|
|
1370
|
-
BIT_DIGIT *a1, x = 0;
|
|
1371
|
-
size_t p1;
|
|
1372
|
-
ssize_t s1;
|
|
1373
|
-
size_t* idx1;
|
|
1374
|
-
VALUE y;
|
|
1375
|
-
|
|
1376
|
-
INIT_COUNTER(lp, i);
|
|
1377
|
-
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
|
1378
|
-
if (idx1) {
|
|
1379
|
-
for (; i--;) {
|
|
1380
|
-
LOAD_BIT(a1, p1 + *idx1, x);
|
|
1381
|
-
idx1++;
|
|
1382
|
-
y = m_data_to_num(x);
|
|
1383
|
-
rb_yield(y);
|
|
1384
|
-
}
|
|
1385
|
-
} else {
|
|
1386
|
-
for (; i--;) {
|
|
1387
|
-
LOAD_BIT(a1, p1, x);
|
|
1388
|
-
p1 += s1;
|
|
1389
|
-
y = m_data_to_num(x);
|
|
1390
|
-
rb_yield(y);
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
/*
|
|
1396
|
-
Calls the given block once for each element in self,
|
|
1397
|
-
passing that element as a parameter.
|
|
1398
|
-
@overload each
|
|
1399
|
-
@return [Numo::NArray] self
|
|
1400
|
-
For a block {|x| ... }
|
|
1401
|
-
@yield [x] x is element of NArray.
|
|
1402
|
-
*/
|
|
1403
|
-
static VALUE bit_each(VALUE self) {
|
|
1404
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1405
|
-
ndfunc_t ndf = { iter_bit_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1406
|
-
|
|
1407
|
-
na_ndloop(&ndf, 1, self);
|
|
1408
|
-
return self;
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
static inline void yield_each_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1412
|
-
int j;
|
|
1413
|
-
|
|
1414
|
-
a[0] = m_data_to_num(x);
|
|
1415
|
-
for (j = 0; j <= nd; j++) {
|
|
1416
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1417
|
-
}
|
|
1418
|
-
rb_yield(rb_ary_new4(md, a));
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
static void iter_bit_each_with_index(na_loop_t* const lp) {
|
|
1422
|
-
size_t i;
|
|
1423
|
-
BIT_DIGIT *a1, x = 0;
|
|
1424
|
-
size_t p1;
|
|
1425
|
-
ssize_t s1;
|
|
1426
|
-
size_t* idx1;
|
|
1427
|
-
|
|
1428
|
-
VALUE* a;
|
|
1429
|
-
size_t* c;
|
|
1430
|
-
int nd, md;
|
|
1431
|
-
|
|
1432
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1433
|
-
nd = lp->ndim - 1;
|
|
1434
|
-
md = lp->ndim + 1;
|
|
1435
|
-
a = ALLOCA_N(VALUE, md);
|
|
1436
|
-
|
|
1437
|
-
INIT_COUNTER(lp, i);
|
|
1438
|
-
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
|
1439
|
-
c[nd] = 0;
|
|
1440
|
-
if (idx1) {
|
|
1441
|
-
for (; i--;) {
|
|
1442
|
-
LOAD_BIT(a1, p1 + *idx1, x);
|
|
1443
|
-
idx1++;
|
|
1444
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1445
|
-
c[nd]++;
|
|
1446
|
-
}
|
|
1447
|
-
} else {
|
|
1448
|
-
for (; i--;) {
|
|
1449
|
-
LOAD_BIT(a1, p1, x);
|
|
1450
|
-
p1 += s1;
|
|
1451
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1452
|
-
c[nd]++;
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
/*
|
|
1458
|
-
Invokes the given block once for each element of self,
|
|
1459
|
-
passing that element and indices along each axis as parameters.
|
|
1460
|
-
@overload each_with_index
|
|
1461
|
-
@return [Numo::NArray] self
|
|
1462
|
-
For a block {|x,i,j,...| ... }
|
|
1463
|
-
@yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
|
|
1464
|
-
*/
|
|
1465
|
-
static VALUE bit_each_with_index(VALUE self) {
|
|
1466
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1467
|
-
ndfunc_t ndf = { iter_bit_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1468
|
-
|
|
1469
|
-
na_ndloop_with_index(&ndf, 1, self);
|
|
1470
|
-
return self;
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
1305
|
static void iter_bit_copy(na_loop_t* const lp) {
|
|
1474
1306
|
size_t n;
|
|
1475
1307
|
size_t p1, p3;
|
|
@@ -2993,11 +2825,50 @@ void Init_numo_bit(void) {
|
|
|
2993
2825
|
rb_define_const(cT, "CONTIGUOUS_STRIDE", INT2FIX(1));
|
|
2994
2826
|
rb_define_alloc_func(cT, bit_s_alloc_func);
|
|
2995
2827
|
rb_define_method(cT, "allocate", bit_allocate, 0);
|
|
2828
|
+
/**
|
|
2829
|
+
* Extract an element only if self is a dimensionless NArray.
|
|
2830
|
+
* @overload extract
|
|
2831
|
+
* @return [Numeric,Numo::NArray]
|
|
2832
|
+
* --- Extract element value as Ruby Object if self is a dimensionless NArray,
|
|
2833
|
+
* otherwise returns self.
|
|
2834
|
+
*/
|
|
2996
2835
|
rb_define_method(cT, "extract", bit_extract, 0);
|
|
2997
2836
|
|
|
2998
2837
|
rb_define_method(cT, "store", bit_store, 1);
|
|
2999
2838
|
|
|
3000
2839
|
rb_define_singleton_method(cT, "cast", bit_s_cast, 1);
|
|
2840
|
+
/**
|
|
2841
|
+
* Multi-dimensional element reference.
|
|
2842
|
+
* @overload [](dim0,...,dimL)
|
|
2843
|
+
* @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,
|
|
2844
|
+
* Symbol]
|
|
2845
|
+
* dim0,...,dimL multi-dimensional indices.
|
|
2846
|
+
* @return [Numeric,Numo::Bit] an element or NArray view.
|
|
2847
|
+
* @see Numo::NArray#[]
|
|
2848
|
+
* @see #[]=
|
|
2849
|
+
*
|
|
2850
|
+
* @example
|
|
2851
|
+
* a = Numo::Int32.new(3,4).seq
|
|
2852
|
+
* # => Numo::Int32#shape=[3,4]
|
|
2853
|
+
* # [[0, 1, 2, 3],
|
|
2854
|
+
* # [4, 5, 6, 7],
|
|
2855
|
+
* # [8, 9, 10, 11]]
|
|
2856
|
+
*
|
|
2857
|
+
* b = (a%2).eq(0)
|
|
2858
|
+
* # => Numo::Bit#shape=[3,4]
|
|
2859
|
+
* # [[1, 0, 1, 0],
|
|
2860
|
+
* # [1, 0, 1, 0],
|
|
2861
|
+
* # [1, 0, 1, 0]]
|
|
2862
|
+
*
|
|
2863
|
+
* b[true,(0..-1)%2]
|
|
2864
|
+
* # => Numo::Bit(view)#shape=[3,2]
|
|
2865
|
+
* # [[1, 1],
|
|
2866
|
+
* # [1, 1],
|
|
2867
|
+
* # [1, 1]]
|
|
2868
|
+
*
|
|
2869
|
+
* b[1,1]
|
|
2870
|
+
* # => 0
|
|
2871
|
+
*/
|
|
3001
2872
|
rb_define_method(cT, "[]", bit_aref, -1);
|
|
3002
2873
|
rb_define_method(cT, "[]=", bit_aset, -1);
|
|
3003
2874
|
/**
|
|
@@ -3039,7 +2910,23 @@ void Init_numo_bit(void) {
|
|
|
3039
2910
|
* @return [String]
|
|
3040
2911
|
*/
|
|
3041
2912
|
rb_define_method(cT, "inspect", bit_inspect, 0);
|
|
2913
|
+
/**
|
|
2914
|
+
* Calls the given block once for each element in self,
|
|
2915
|
+
* passing that element as a parameter.
|
|
2916
|
+
* @overload each
|
|
2917
|
+
* @return [Numo::NArray] self
|
|
2918
|
+
* For a block {|x| ... }
|
|
2919
|
+
* @yield [x] x is element of NArray.
|
|
2920
|
+
*/
|
|
3042
2921
|
rb_define_method(cT, "each", bit_each, 0);
|
|
2922
|
+
/**
|
|
2923
|
+
* Invokes the given block once for each element of self,
|
|
2924
|
+
* passing that element and indices along each axis as parameters.
|
|
2925
|
+
* @overload each_with_index
|
|
2926
|
+
* @return [Numo::NArray] self
|
|
2927
|
+
* For a block {|x,i,j,...| ... }
|
|
2928
|
+
* @yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
|
|
2929
|
+
*/
|
|
3043
2930
|
rb_define_method(cT, "each_with_index", bit_each_with_index, 0);
|
|
3044
2931
|
rb_define_method(cT, "copy", bit_copy, 0);
|
|
3045
2932
|
rb_define_method(cT, "~", bit_not, 0);
|