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
|
@@ -43,12 +43,19 @@ static ID id_to_a;
|
|
|
43
43
|
VALUE cT;
|
|
44
44
|
extern VALUE cRT;
|
|
45
45
|
|
|
46
|
+
#include "mh/extract.h"
|
|
47
|
+
#include "mh/aref.h"
|
|
46
48
|
#include "mh/coerce_cast.h"
|
|
47
49
|
#include "mh/to_a.h"
|
|
48
50
|
#include "mh/fill.h"
|
|
49
51
|
#include "mh/format.h"
|
|
50
52
|
#include "mh/format_to_a.h"
|
|
51
53
|
#include "mh/inspect.h"
|
|
54
|
+
#include "mh/each.h"
|
|
55
|
+
#include "mh/map.h"
|
|
56
|
+
#include "mh/each_with_index.h"
|
|
57
|
+
#include "mh/map_with_index.h"
|
|
58
|
+
#include "mh/abs.h"
|
|
52
59
|
#include "mh/op/add.h"
|
|
53
60
|
#include "mh/op/sub.h"
|
|
54
61
|
#include "mh/op/mul.h"
|
|
@@ -92,6 +99,7 @@ extern VALUE cRT;
|
|
|
92
99
|
#include "mh/seq.h"
|
|
93
100
|
#include "mh/eye.h"
|
|
94
101
|
#include "mh/rand.h"
|
|
102
|
+
#include "mh/poly.h"
|
|
95
103
|
#include "mh/mean.h"
|
|
96
104
|
#include "mh/var.h"
|
|
97
105
|
#include "mh/stddev.h"
|
|
@@ -99,12 +107,19 @@ extern VALUE cRT;
|
|
|
99
107
|
|
|
100
108
|
typedef u_int8_t uint8; // Type aliases for shorter notation
|
|
101
109
|
// following the codebase naming convention.
|
|
110
|
+
DEF_NARRAY_EXTRACT_METHOD_FUNC(uint8)
|
|
111
|
+
DEF_NARRAY_AREF_METHOD_FUNC(uint8)
|
|
102
112
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(uint8)
|
|
103
113
|
DEF_NARRAY_TO_A_METHOD_FUNC(uint8)
|
|
104
114
|
DEF_NARRAY_FILL_METHOD_FUNC(uint8)
|
|
105
115
|
DEF_NARRAY_FORMAT_METHOD_FUNC(uint8)
|
|
106
116
|
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(uint8)
|
|
107
117
|
DEF_NARRAY_INSPECT_METHOD_FUNC(uint8)
|
|
118
|
+
DEF_NARRAY_EACH_METHOD_FUNC(uint8)
|
|
119
|
+
DEF_NARRAY_MAP_METHOD_FUNC(uint8, numo_cUInt8)
|
|
120
|
+
DEF_NARRAY_EACH_WITH_INDEX_METHOD_FUNC(uint8)
|
|
121
|
+
DEF_NARRAY_MAP_WITH_INDEX_METHOD_FUNC(uint8, numo_cUInt8)
|
|
122
|
+
DEF_NARRAY_ABS_METHOD_FUNC(uint8, numo_cUInt8, uint8, numo_cUInt8)
|
|
108
123
|
DEF_NARRAY_INT8_ADD_METHOD_FUNC(uint8, numo_cUInt8)
|
|
109
124
|
DEF_NARRAY_INT8_SUB_METHOD_FUNC(uint8, numo_cUInt8)
|
|
110
125
|
DEF_NARRAY_INT8_MUL_METHOD_FUNC(uint8, numo_cUInt8)
|
|
@@ -148,6 +163,7 @@ DEF_NARRAY_INT_MULSUM_METHOD_FUNC(uint8, numo_cUInt8)
|
|
|
148
163
|
DEF_NARRAY_INT_SEQ_METHOD_FUNC(uint8)
|
|
149
164
|
DEF_NARRAY_EYE_METHOD_FUNC(uint8)
|
|
150
165
|
DEF_NARRAY_INT_RAND_METHOD_FUNC(uint8)
|
|
166
|
+
DEF_NARRAY_POLY_METHOD_FUNC(uint8, numo_cUInt8)
|
|
151
167
|
DEF_NARRAY_INT_MEAN_METHOD_FUNC(uint8, numo_cUInt8)
|
|
152
168
|
DEF_NARRAY_INT_VAR_METHOD_FUNC(uint8, numo_cUInt8)
|
|
153
169
|
DEF_NARRAY_INT_STDDEV_METHOD_FUNC(uint8, numo_cUInt8)
|
|
@@ -256,28 +272,6 @@ static VALUE uint8_allocate(VALUE self) {
|
|
|
256
272
|
return self;
|
|
257
273
|
}
|
|
258
274
|
|
|
259
|
-
/*
|
|
260
|
-
Extract an element only if self is a dimensionless NArray.
|
|
261
|
-
@overload extract
|
|
262
|
-
@return [Numeric,Numo::NArray]
|
|
263
|
-
--- Extract element value as Ruby Object if self is a dimensionless NArray,
|
|
264
|
-
otherwise returns self.
|
|
265
|
-
*/
|
|
266
|
-
static VALUE uint8_extract(VALUE self) {
|
|
267
|
-
volatile VALUE v;
|
|
268
|
-
char* ptr;
|
|
269
|
-
narray_t* na;
|
|
270
|
-
GetNArray(self, na);
|
|
271
|
-
|
|
272
|
-
if (na->ndim == 0) {
|
|
273
|
-
ptr = na_get_pointer_for_read(self) + na_get_offset(self);
|
|
274
|
-
v = m_extract(ptr);
|
|
275
|
-
na_release_lock(self);
|
|
276
|
-
return v;
|
|
277
|
-
}
|
|
278
|
-
return self;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
275
|
static VALUE uint8_new_dim0(dtype x) {
|
|
282
276
|
VALUE v;
|
|
283
277
|
dtype* ptr;
|
|
@@ -1255,29 +1249,6 @@ static VALUE uint8_s_cast(VALUE type, VALUE obj) {
|
|
|
1255
1249
|
return Qnil;
|
|
1256
1250
|
}
|
|
1257
1251
|
|
|
1258
|
-
/*
|
|
1259
|
-
Multi-dimensional element reference.
|
|
1260
|
-
@overload [](dim0,...,dimL)
|
|
1261
|
-
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
|
1262
|
-
dim0,...,dimL multi-dimensional indices.
|
|
1263
|
-
@return [Numeric,Numo::UInt8] an element or NArray view.
|
|
1264
|
-
@see Numo::NArray#[]
|
|
1265
|
-
@see #[]=
|
|
1266
|
-
*/
|
|
1267
|
-
static VALUE uint8_aref(int argc, VALUE* argv, VALUE self) {
|
|
1268
|
-
int nd;
|
|
1269
|
-
size_t pos;
|
|
1270
|
-
char* ptr;
|
|
1271
|
-
|
|
1272
|
-
nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
|
|
1273
|
-
if (nd) {
|
|
1274
|
-
return na_aref_main(argc, argv, self, 0, nd);
|
|
1275
|
-
} else {
|
|
1276
|
-
ptr = na_get_pointer_for_read(self) + pos;
|
|
1277
|
-
return m_extract(ptr);
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
1252
|
/*
|
|
1282
1253
|
Multi-dimensional element assignment.
|
|
1283
1254
|
@overload []=(dim0,...,dimL,val)
|
|
@@ -1312,361 +1283,6 @@ static VALUE uint8_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1312
1283
|
return argv[argc];
|
|
1313
1284
|
}
|
|
1314
1285
|
|
|
1315
|
-
static void iter_uint8_each(na_loop_t* const lp) {
|
|
1316
|
-
size_t i, s1;
|
|
1317
|
-
char* p1;
|
|
1318
|
-
size_t* idx1;
|
|
1319
|
-
dtype x;
|
|
1320
|
-
VALUE y;
|
|
1321
|
-
|
|
1322
|
-
INIT_COUNTER(lp, i);
|
|
1323
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1324
|
-
if (idx1) {
|
|
1325
|
-
for (; i--;) {
|
|
1326
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1327
|
-
y = m_data_to_num(x);
|
|
1328
|
-
rb_yield(y);
|
|
1329
|
-
}
|
|
1330
|
-
} else {
|
|
1331
|
-
for (; i--;) {
|
|
1332
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1333
|
-
y = m_data_to_num(x);
|
|
1334
|
-
rb_yield(y);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
/*
|
|
1340
|
-
Calls the given block once for each element in self,
|
|
1341
|
-
passing that element as a parameter.
|
|
1342
|
-
@overload each
|
|
1343
|
-
@return [Numo::NArray] self
|
|
1344
|
-
For a block `{|x| ... }`,
|
|
1345
|
-
@yieldparam [Numeric] x an element of NArray.
|
|
1346
|
-
@see #each_with_index
|
|
1347
|
-
@see #map
|
|
1348
|
-
*/
|
|
1349
|
-
static VALUE uint8_each(VALUE self) {
|
|
1350
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1351
|
-
ndfunc_t ndf = { iter_uint8_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1352
|
-
|
|
1353
|
-
na_ndloop(&ndf, 1, self);
|
|
1354
|
-
return self;
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
static void iter_uint8_map(na_loop_t* const lp) {
|
|
1358
|
-
size_t i, n;
|
|
1359
|
-
char *p1, *p2;
|
|
1360
|
-
ssize_t s1, s2;
|
|
1361
|
-
size_t *idx1, *idx2;
|
|
1362
|
-
dtype x;
|
|
1363
|
-
|
|
1364
|
-
INIT_COUNTER(lp, n);
|
|
1365
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1366
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1367
|
-
|
|
1368
|
-
if (idx1) {
|
|
1369
|
-
if (idx2) {
|
|
1370
|
-
for (i = 0; i < n; i++) {
|
|
1371
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1372
|
-
x = m_map(x);
|
|
1373
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1374
|
-
}
|
|
1375
|
-
} else {
|
|
1376
|
-
for (i = 0; i < n; i++) {
|
|
1377
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1378
|
-
x = m_map(x);
|
|
1379
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
} else {
|
|
1383
|
-
if (idx2) {
|
|
1384
|
-
for (i = 0; i < n; i++) {
|
|
1385
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1386
|
-
x = m_map(x);
|
|
1387
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1388
|
-
}
|
|
1389
|
-
} else {
|
|
1390
|
-
//
|
|
1391
|
-
for (i = 0; i < n; i++) {
|
|
1392
|
-
*(dtype*)p2 = m_map(*(dtype*)p1);
|
|
1393
|
-
p1 += s1;
|
|
1394
|
-
p2 += s2;
|
|
1395
|
-
}
|
|
1396
|
-
return;
|
|
1397
|
-
//
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
/*
|
|
1403
|
-
Unary map.
|
|
1404
|
-
@overload map
|
|
1405
|
-
@return [Numo::UInt8] map of self.
|
|
1406
|
-
*/
|
|
1407
|
-
static VALUE uint8_map(VALUE self) {
|
|
1408
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1409
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1410
|
-
ndfunc_t ndf = { iter_uint8_map, FULL_LOOP, 1, 1, ain, aout };
|
|
1411
|
-
|
|
1412
|
-
return na_ndloop(&ndf, 1, self);
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
static inline void yield_each_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1416
|
-
int j;
|
|
1417
|
-
|
|
1418
|
-
a[0] = m_data_to_num(x);
|
|
1419
|
-
for (j = 0; j <= nd; j++) {
|
|
1420
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1421
|
-
}
|
|
1422
|
-
rb_yield(rb_ary_new4(md, a));
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
static void iter_uint8_each_with_index(na_loop_t* const lp) {
|
|
1426
|
-
size_t i, s1;
|
|
1427
|
-
char* p1;
|
|
1428
|
-
size_t* idx1;
|
|
1429
|
-
dtype x;
|
|
1430
|
-
VALUE* a;
|
|
1431
|
-
size_t* c;
|
|
1432
|
-
int nd, md;
|
|
1433
|
-
|
|
1434
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1435
|
-
nd = lp->ndim;
|
|
1436
|
-
if (nd > 0) {
|
|
1437
|
-
nd--;
|
|
1438
|
-
}
|
|
1439
|
-
md = nd + 2;
|
|
1440
|
-
a = ALLOCA_N(VALUE, md);
|
|
1441
|
-
|
|
1442
|
-
INIT_COUNTER(lp, i);
|
|
1443
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1444
|
-
c[nd] = 0;
|
|
1445
|
-
if (idx1) {
|
|
1446
|
-
for (; i--;) {
|
|
1447
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1448
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1449
|
-
c[nd]++;
|
|
1450
|
-
}
|
|
1451
|
-
} else {
|
|
1452
|
-
for (; i--;) {
|
|
1453
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1454
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1455
|
-
c[nd]++;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
/*
|
|
1461
|
-
Invokes the given block once for each element of self,
|
|
1462
|
-
passing that element and indices along each axis as parameters.
|
|
1463
|
-
@overload each_with_index
|
|
1464
|
-
For a block `{|x,i,j,...| ... }`,
|
|
1465
|
-
@yieldparam [Numeric] x an element
|
|
1466
|
-
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1467
|
-
@return [Numo::NArray] self
|
|
1468
|
-
@see #each
|
|
1469
|
-
@see #map_with_index
|
|
1470
|
-
*/
|
|
1471
|
-
static VALUE uint8_each_with_index(VALUE self) {
|
|
1472
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1473
|
-
ndfunc_t ndf = { iter_uint8_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1474
|
-
|
|
1475
|
-
na_ndloop_with_index(&ndf, 1, self);
|
|
1476
|
-
return self;
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
static inline dtype yield_map_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1480
|
-
int j;
|
|
1481
|
-
VALUE y;
|
|
1482
|
-
|
|
1483
|
-
a[0] = m_data_to_num(x);
|
|
1484
|
-
for (j = 0; j <= nd; j++) {
|
|
1485
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1486
|
-
}
|
|
1487
|
-
y = rb_yield(rb_ary_new4(md, a));
|
|
1488
|
-
return m_num_to_data(y);
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
static void iter_uint8_map_with_index(na_loop_t* const lp) {
|
|
1492
|
-
size_t i;
|
|
1493
|
-
char *p1, *p2;
|
|
1494
|
-
ssize_t s1, s2;
|
|
1495
|
-
size_t *idx1, *idx2;
|
|
1496
|
-
dtype x;
|
|
1497
|
-
VALUE* a;
|
|
1498
|
-
size_t* c;
|
|
1499
|
-
int nd, md;
|
|
1500
|
-
|
|
1501
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1502
|
-
nd = lp->ndim;
|
|
1503
|
-
if (nd > 0) {
|
|
1504
|
-
nd--;
|
|
1505
|
-
}
|
|
1506
|
-
md = nd + 2;
|
|
1507
|
-
a = ALLOCA_N(VALUE, md);
|
|
1508
|
-
|
|
1509
|
-
INIT_COUNTER(lp, i);
|
|
1510
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1511
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1512
|
-
|
|
1513
|
-
c[nd] = 0;
|
|
1514
|
-
if (idx1) {
|
|
1515
|
-
if (idx2) {
|
|
1516
|
-
for (; i--;) {
|
|
1517
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1518
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1519
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1520
|
-
c[nd]++;
|
|
1521
|
-
}
|
|
1522
|
-
} else {
|
|
1523
|
-
for (; i--;) {
|
|
1524
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1525
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1526
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1527
|
-
c[nd]++;
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
} else {
|
|
1531
|
-
if (idx2) {
|
|
1532
|
-
for (; i--;) {
|
|
1533
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1534
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1535
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1536
|
-
c[nd]++;
|
|
1537
|
-
}
|
|
1538
|
-
} else {
|
|
1539
|
-
for (; i--;) {
|
|
1540
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1541
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1542
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1543
|
-
c[nd]++;
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
/*
|
|
1550
|
-
Invokes the given block once for each element of self,
|
|
1551
|
-
passing that element and indices along each axis as parameters.
|
|
1552
|
-
Creates a new NArray containing the values returned by the block.
|
|
1553
|
-
Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
|
1554
|
-
@overload map_with_index
|
|
1555
|
-
For a block `{|x,i,j,...| ... }`,
|
|
1556
|
-
@yieldparam [Numeric] x an element
|
|
1557
|
-
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1558
|
-
@return [Numo::NArray] mapped array
|
|
1559
|
-
@see #map
|
|
1560
|
-
@see #each_with_index
|
|
1561
|
-
*/
|
|
1562
|
-
static VALUE uint8_map_with_index(VALUE self) {
|
|
1563
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1564
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1565
|
-
ndfunc_t ndf = { iter_uint8_map_with_index, FULL_LOOP, 1, 1, ain, aout };
|
|
1566
|
-
|
|
1567
|
-
return na_ndloop_with_index(&ndf, 1, self);
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
static void iter_uint8_abs(na_loop_t* const lp) {
|
|
1571
|
-
size_t i;
|
|
1572
|
-
char *p1, *p2;
|
|
1573
|
-
ssize_t s1, s2;
|
|
1574
|
-
size_t *idx1, *idx2;
|
|
1575
|
-
dtype x;
|
|
1576
|
-
rtype y;
|
|
1577
|
-
INIT_COUNTER(lp, i);
|
|
1578
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1579
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1580
|
-
if (idx1) {
|
|
1581
|
-
if (idx2) {
|
|
1582
|
-
for (; i--;) {
|
|
1583
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1584
|
-
y = m_abs(x);
|
|
1585
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1586
|
-
}
|
|
1587
|
-
} else {
|
|
1588
|
-
for (; i--;) {
|
|
1589
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1590
|
-
y = m_abs(x);
|
|
1591
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
} else {
|
|
1595
|
-
if (idx2) {
|
|
1596
|
-
for (; i--;) {
|
|
1597
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1598
|
-
y = m_abs(x);
|
|
1599
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1600
|
-
}
|
|
1601
|
-
} else {
|
|
1602
|
-
for (; i--;) {
|
|
1603
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1604
|
-
y = m_abs(x);
|
|
1605
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
/*
|
|
1612
|
-
abs of self.
|
|
1613
|
-
@overload abs
|
|
1614
|
-
@return [Numo::UInt8] abs of self.
|
|
1615
|
-
*/
|
|
1616
|
-
static VALUE uint8_abs(VALUE self) {
|
|
1617
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1618
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
1619
|
-
ndfunc_t ndf = { iter_uint8_abs, FULL_LOOP, 1, 1, ain, aout };
|
|
1620
|
-
|
|
1621
|
-
return na_ndloop(&ndf, 1, self);
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
static void iter_uint8_poly(na_loop_t* const lp) {
|
|
1625
|
-
size_t i;
|
|
1626
|
-
dtype x, y, a;
|
|
1627
|
-
|
|
1628
|
-
x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
|
|
1629
|
-
i = lp->narg - 2;
|
|
1630
|
-
y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
1631
|
-
for (; --i;) {
|
|
1632
|
-
y = m_mul(x, y);
|
|
1633
|
-
a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
1634
|
-
y = m_add(y, a);
|
|
1635
|
-
}
|
|
1636
|
-
i = lp->narg - 1;
|
|
1637
|
-
*(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
/*
|
|
1641
|
-
Calculate polynomial.
|
|
1642
|
-
`x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
1643
|
-
@overload poly a0, a1, ..., an
|
|
1644
|
-
@param [Numo::NArray,Numeric] a0,a1,...,an
|
|
1645
|
-
@return [Numo::UInt8]
|
|
1646
|
-
*/
|
|
1647
|
-
static VALUE uint8_poly(VALUE self, VALUE args) {
|
|
1648
|
-
int argc, i;
|
|
1649
|
-
VALUE* argv;
|
|
1650
|
-
volatile VALUE v, a;
|
|
1651
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1652
|
-
ndfunc_t ndf = { iter_uint8_poly, NO_LOOP, 0, 1, 0, aout };
|
|
1653
|
-
|
|
1654
|
-
argc = (int)RARRAY_LEN(args);
|
|
1655
|
-
ndf.nin = argc + 1;
|
|
1656
|
-
ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
|
|
1657
|
-
for (i = 0; i < argc + 1; i++) {
|
|
1658
|
-
ndf.ain[i].type = cT;
|
|
1659
|
-
}
|
|
1660
|
-
argv = ALLOCA_N(VALUE, argc + 1);
|
|
1661
|
-
argv[0] = self;
|
|
1662
|
-
for (i = 0; i < argc; i++) {
|
|
1663
|
-
argv[i + 1] = RARRAY_PTR(args)[i];
|
|
1664
|
-
}
|
|
1665
|
-
a = rb_ary_new4(argc + 1, argv);
|
|
1666
|
-
v = na_ndloop2(&ndf, a);
|
|
1667
|
-
return uint8_extract(v);
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
1286
|
/*
|
|
1671
1287
|
qsort.c
|
|
1672
1288
|
Ruby/Numo::NArray - Numerical Array class for Ruby
|
|
@@ -2237,11 +1853,27 @@ void Init_numo_uint8(void) {
|
|
|
2237
1853
|
rb_define_const(cT, "MIN", M_MIN);
|
|
2238
1854
|
rb_define_alloc_func(cT, uint8_s_alloc_func);
|
|
2239
1855
|
rb_define_method(cT, "allocate", uint8_allocate, 0);
|
|
1856
|
+
/**
|
|
1857
|
+
* Extract an element only if self is a dimensionless NArray.
|
|
1858
|
+
* @overload extract
|
|
1859
|
+
* @return [Numeric,Numo::NArray]
|
|
1860
|
+
* --- Extract element value as Ruby Object if self is a dimensionless NArray,
|
|
1861
|
+
* otherwise returns self.
|
|
1862
|
+
*/
|
|
2240
1863
|
rb_define_method(cT, "extract", uint8_extract, 0);
|
|
2241
1864
|
|
|
2242
1865
|
rb_define_method(cT, "store", uint8_store, 1);
|
|
2243
1866
|
|
|
2244
1867
|
rb_define_singleton_method(cT, "cast", uint8_s_cast, 1);
|
|
1868
|
+
/**
|
|
1869
|
+
* Multi-dimensional element reference.
|
|
1870
|
+
* @overload [](dim0,...,dimL)
|
|
1871
|
+
* @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,
|
|
1872
|
+
* Symbol] dim0,...,dimL multi-dimensional indices.
|
|
1873
|
+
* @return [Numeric,Numo::UInt8] an element or NArray view.
|
|
1874
|
+
* @see Numo::NArray#[]
|
|
1875
|
+
* @see #[]=
|
|
1876
|
+
*/
|
|
2245
1877
|
rb_define_method(cT, "[]", uint8_aref, -1);
|
|
2246
1878
|
rb_define_method(cT, "[]=", uint8_aset, -1);
|
|
2247
1879
|
/**
|
|
@@ -2283,10 +1915,54 @@ void Init_numo_uint8(void) {
|
|
|
2283
1915
|
* @return [String]
|
|
2284
1916
|
*/
|
|
2285
1917
|
rb_define_method(cT, "inspect", uint8_inspect, 0);
|
|
1918
|
+
/**
|
|
1919
|
+
* Calls the given block once for each element in self,
|
|
1920
|
+
* passing that element as a parameter.
|
|
1921
|
+
* @overload each
|
|
1922
|
+
* @return [Numo::NArray] self
|
|
1923
|
+
* For a block `{|x| ... }`,
|
|
1924
|
+
* @yieldparam [Numeric] x an element of NArray.
|
|
1925
|
+
* @see #each_with_index
|
|
1926
|
+
* @see #map
|
|
1927
|
+
*/
|
|
2286
1928
|
rb_define_method(cT, "each", uint8_each, 0);
|
|
1929
|
+
/**
|
|
1930
|
+
* Unary map.
|
|
1931
|
+
* @overload map
|
|
1932
|
+
* @return [Numo::UInt8] map of self.
|
|
1933
|
+
*/
|
|
2287
1934
|
rb_define_method(cT, "map", uint8_map, 0);
|
|
1935
|
+
/**
|
|
1936
|
+
* Invokes the given block once for each element of self,
|
|
1937
|
+
* passing that element and indices along each axis as parameters.
|
|
1938
|
+
* @overload each_with_index
|
|
1939
|
+
* For a block `{|x,i,j,...| ... }`,
|
|
1940
|
+
* @yieldparam [Numeric] x an element
|
|
1941
|
+
* @yieldparam [Integer] i,j,... multitimensional indices
|
|
1942
|
+
* @return [Numo::NArray] self
|
|
1943
|
+
* @see #each
|
|
1944
|
+
* @see #map_with_index
|
|
1945
|
+
*/
|
|
2288
1946
|
rb_define_method(cT, "each_with_index", uint8_each_with_index, 0);
|
|
1947
|
+
/**
|
|
1948
|
+
* Invokes the given block once for each element of self,
|
|
1949
|
+
* passing that element and indices along each axis as parameters.
|
|
1950
|
+
* Creates a new NArray containing the values returned by the block.
|
|
1951
|
+
* Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
|
1952
|
+
* @overload map_with_index
|
|
1953
|
+
* For a block `{|x,i,j,...| ... }`,
|
|
1954
|
+
* @yieldparam [Numeric] x an element
|
|
1955
|
+
* @yieldparam [Integer] i,j,... multitimensional indices
|
|
1956
|
+
* @return [Numo::NArray] mapped array
|
|
1957
|
+
* @see #map
|
|
1958
|
+
* @see #each_with_index
|
|
1959
|
+
*/
|
|
2289
1960
|
rb_define_method(cT, "map_with_index", uint8_map_with_index, 0);
|
|
1961
|
+
/**
|
|
1962
|
+
* abs of self.
|
|
1963
|
+
* @overload abs
|
|
1964
|
+
* @return [Numo::UInt8] abs of self.
|
|
1965
|
+
*/
|
|
2290
1966
|
rb_define_method(cT, "abs", uint8_abs, 0);
|
|
2291
1967
|
/**
|
|
2292
1968
|
* Binary add.
|
|
@@ -2747,6 +2423,13 @@ void Init_numo_uint8(void) {
|
|
|
2747
2423
|
* # [4, 3, 3, 2, 4, 2]
|
|
2748
2424
|
*/
|
|
2749
2425
|
rb_define_method(cT, "rand", uint8_rand, -1);
|
|
2426
|
+
/**
|
|
2427
|
+
* Calculate polynomial.
|
|
2428
|
+
* `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
2429
|
+
* @overload poly a0, a1, ..., an
|
|
2430
|
+
* @param [Numo::NArray,Numeric] a0,a1,...,an
|
|
2431
|
+
* @return [Numo::UInt8]
|
|
2432
|
+
*/
|
|
2750
2433
|
rb_define_method(cT, "poly", uint8_poly, -2);
|
|
2751
2434
|
|
|
2752
2435
|
rb_define_method(cT, "sort", uint8_sort, -1);
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: numo-narray-alt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yoshoku
|
|
@@ -66,6 +66,9 @@ files:
|
|
|
66
66
|
- ext/numo/narray/numo/types/uint_macro.h
|
|
67
67
|
- ext/numo/narray/numo/types/xint_macro.h
|
|
68
68
|
- ext/numo/narray/rand.c
|
|
69
|
+
- ext/numo/narray/src/mh/abs.h
|
|
70
|
+
- ext/numo/narray/src/mh/aref.h
|
|
71
|
+
- ext/numo/narray/src/mh/arg.h
|
|
69
72
|
- ext/numo/narray/src/mh/argmax.h
|
|
70
73
|
- ext/numo/narray/src/mh/argmin.h
|
|
71
74
|
- ext/numo/narray/src/mh/bincount.h
|
|
@@ -85,20 +88,30 @@ files:
|
|
|
85
88
|
- ext/numo/narray/src/mh/comp/lt.h
|
|
86
89
|
- ext/numo/narray/src/mh/comp/ne.h
|
|
87
90
|
- ext/numo/narray/src/mh/comp/nearly_eq.h
|
|
91
|
+
- ext/numo/narray/src/mh/conj.h
|
|
92
|
+
- ext/numo/narray/src/mh/copysign.h
|
|
88
93
|
- ext/numo/narray/src/mh/cumprod.h
|
|
89
94
|
- ext/numo/narray/src/mh/cumsum.h
|
|
90
95
|
- ext/numo/narray/src/mh/divmod.h
|
|
96
|
+
- ext/numo/narray/src/mh/each.h
|
|
97
|
+
- ext/numo/narray/src/mh/each_with_index.h
|
|
98
|
+
- ext/numo/narray/src/mh/extract.h
|
|
91
99
|
- ext/numo/narray/src/mh/eye.h
|
|
92
100
|
- ext/numo/narray/src/mh/fill.h
|
|
93
101
|
- ext/numo/narray/src/mh/format.h
|
|
94
102
|
- ext/numo/narray/src/mh/format_to_a.h
|
|
103
|
+
- ext/numo/narray/src/mh/im.h
|
|
104
|
+
- ext/numo/narray/src/mh/imag.h
|
|
95
105
|
- ext/numo/narray/src/mh/inspect.h
|
|
96
106
|
- ext/numo/narray/src/mh/isfinite.h
|
|
97
107
|
- ext/numo/narray/src/mh/isinf.h
|
|
98
108
|
- ext/numo/narray/src/mh/isnan.h
|
|
99
109
|
- ext/numo/narray/src/mh/isneginf.h
|
|
100
110
|
- ext/numo/narray/src/mh/isposinf.h
|
|
111
|
+
- ext/numo/narray/src/mh/kahan_sum.h
|
|
101
112
|
- ext/numo/narray/src/mh/logseq.h
|
|
113
|
+
- ext/numo/narray/src/mh/map.h
|
|
114
|
+
- ext/numo/narray/src/mh/map_with_index.h
|
|
102
115
|
- ext/numo/narray/src/mh/math/acos.h
|
|
103
116
|
- ext/numo/narray/src/mh/math/acosh.h
|
|
104
117
|
- ext/numo/narray/src/mh/math/asin.h
|
|
@@ -138,6 +151,7 @@ files:
|
|
|
138
151
|
- ext/numo/narray/src/mh/minimum.h
|
|
139
152
|
- ext/numo/narray/src/mh/minmax.h
|
|
140
153
|
- ext/numo/narray/src/mh/minus.h
|
|
154
|
+
- ext/numo/narray/src/mh/modf.h
|
|
141
155
|
- ext/numo/narray/src/mh/mulsum.h
|
|
142
156
|
- ext/numo/narray/src/mh/op/add.h
|
|
143
157
|
- ext/numo/narray/src/mh/op/binary_func.h
|
|
@@ -145,11 +159,13 @@ files:
|
|
|
145
159
|
- ext/numo/narray/src/mh/op/mod.h
|
|
146
160
|
- ext/numo/narray/src/mh/op/mul.h
|
|
147
161
|
- ext/numo/narray/src/mh/op/sub.h
|
|
162
|
+
- ext/numo/narray/src/mh/poly.h
|
|
148
163
|
- ext/numo/narray/src/mh/pow.h
|
|
149
164
|
- ext/numo/narray/src/mh/prod.h
|
|
150
165
|
- ext/numo/narray/src/mh/ptp.h
|
|
151
166
|
- ext/numo/narray/src/mh/rand.h
|
|
152
167
|
- ext/numo/narray/src/mh/rand_norm.h
|
|
168
|
+
- ext/numo/narray/src/mh/real.h
|
|
153
169
|
- ext/numo/narray/src/mh/reciprocal.h
|
|
154
170
|
- ext/numo/narray/src/mh/rms.h
|
|
155
171
|
- ext/numo/narray/src/mh/round/ceil.h
|
|
@@ -159,7 +175,10 @@ files:
|
|
|
159
175
|
- ext/numo/narray/src/mh/round/trunc.h
|
|
160
176
|
- ext/numo/narray/src/mh/round/unary_func.h
|
|
161
177
|
- ext/numo/narray/src/mh/seq.h
|
|
178
|
+
- ext/numo/narray/src/mh/set_imag.h
|
|
179
|
+
- ext/numo/narray/src/mh/set_real.h
|
|
162
180
|
- ext/numo/narray/src/mh/sign.h
|
|
181
|
+
- ext/numo/narray/src/mh/signbit.h
|
|
163
182
|
- ext/numo/narray/src/mh/square.h
|
|
164
183
|
- ext/numo/narray/src/mh/stddev.h
|
|
165
184
|
- ext/numo/narray/src/mh/sum.h
|
|
@@ -191,7 +210,7 @@ licenses:
|
|
|
191
210
|
metadata:
|
|
192
211
|
homepage_uri: https://github.com/yoshoku/numo-narray-alt
|
|
193
212
|
changelog_uri: https://github.com/yoshoku/numo-narray-alt/blob/main/CHANGELOG.md
|
|
194
|
-
documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.9.
|
|
213
|
+
documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.9.14/
|
|
195
214
|
rubygems_mfa_required: 'true'
|
|
196
215
|
post_install_message: |
|
|
197
216
|
===
|