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
|
@@ -42,12 +42,19 @@ static ID id_to_a;
|
|
|
42
42
|
VALUE cT;
|
|
43
43
|
extern VALUE cRT;
|
|
44
44
|
|
|
45
|
+
#include "mh/extract.h"
|
|
46
|
+
#include "mh/aref.h"
|
|
45
47
|
#include "mh/coerce_cast.h"
|
|
46
48
|
#include "mh/to_a.h"
|
|
47
49
|
#include "mh/fill.h"
|
|
48
50
|
#include "mh/format.h"
|
|
49
51
|
#include "mh/format_to_a.h"
|
|
50
52
|
#include "mh/inspect.h"
|
|
53
|
+
#include "mh/each.h"
|
|
54
|
+
#include "mh/map.h"
|
|
55
|
+
#include "mh/each_with_index.h"
|
|
56
|
+
#include "mh/map_with_index.h"
|
|
57
|
+
#include "mh/abs.h"
|
|
51
58
|
#include "mh/op/add.h"
|
|
52
59
|
#include "mh/op/sub.h"
|
|
53
60
|
#include "mh/op/mul.h"
|
|
@@ -64,6 +71,9 @@ extern VALUE cRT;
|
|
|
64
71
|
#include "mh/round/ceil.h"
|
|
65
72
|
#include "mh/round/trunc.h"
|
|
66
73
|
#include "mh/round/rint.h"
|
|
74
|
+
#include "mh/copysign.h"
|
|
75
|
+
#include "mh/signbit.h"
|
|
76
|
+
#include "mh/modf.h"
|
|
67
77
|
#include "mh/comp/eq.h"
|
|
68
78
|
#include "mh/comp/ne.h"
|
|
69
79
|
#include "mh/comp/nearly_eq.h"
|
|
@@ -101,6 +111,7 @@ extern VALUE cRT;
|
|
|
101
111
|
#include "mh/eye.h"
|
|
102
112
|
#include "mh/rand.h"
|
|
103
113
|
#include "mh/rand_norm.h"
|
|
114
|
+
#include "mh/poly.h"
|
|
104
115
|
#include "mh/math/sqrt.h"
|
|
105
116
|
#include "mh/math/cbrt.h"
|
|
106
117
|
#include "mh/math/log.h"
|
|
@@ -133,12 +144,19 @@ extern VALUE cRT;
|
|
|
133
144
|
|
|
134
145
|
typedef float sfloat; // Type aliases for shorter notation
|
|
135
146
|
// following the codebase naming convention.
|
|
147
|
+
DEF_NARRAY_EXTRACT_METHOD_FUNC(sfloat)
|
|
148
|
+
DEF_NARRAY_AREF_METHOD_FUNC(sfloat)
|
|
136
149
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(sfloat)
|
|
137
150
|
DEF_NARRAY_TO_A_METHOD_FUNC(sfloat)
|
|
138
151
|
DEF_NARRAY_FILL_METHOD_FUNC(sfloat)
|
|
139
152
|
DEF_NARRAY_FORMAT_METHOD_FUNC(sfloat)
|
|
140
153
|
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(sfloat)
|
|
141
154
|
DEF_NARRAY_INSPECT_METHOD_FUNC(sfloat)
|
|
155
|
+
DEF_NARRAY_EACH_METHOD_FUNC(sfloat)
|
|
156
|
+
DEF_NARRAY_MAP_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
157
|
+
DEF_NARRAY_EACH_WITH_INDEX_METHOD_FUNC(sfloat)
|
|
158
|
+
DEF_NARRAY_MAP_WITH_INDEX_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
159
|
+
DEF_NARRAY_ABS_METHOD_FUNC(sfloat, numo_cSFloat, sfloat, numo_cSFloat)
|
|
142
160
|
#ifdef __SSE2__
|
|
143
161
|
DEF_NARRAY_SFLT_ADD_SSE2_METHOD_FUNC()
|
|
144
162
|
DEF_NARRAY_SFLT_SUB_SSE2_METHOD_FUNC()
|
|
@@ -162,6 +180,9 @@ DEF_NARRAY_FLT_ROUND_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
|
162
180
|
DEF_NARRAY_FLT_CEIL_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
163
181
|
DEF_NARRAY_FLT_TRUNC_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
164
182
|
DEF_NARRAY_FLT_RINT_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
183
|
+
DEF_NARRAY_COPYSIGN_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
184
|
+
DEF_NARRAY_SIGNBIT_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
185
|
+
DEF_NARRAY_MODF_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
165
186
|
DEF_NARRAY_EQ_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
166
187
|
DEF_NARRAY_NE_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
167
188
|
DEF_NARRAY_NEARLY_EQ_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
@@ -199,6 +220,7 @@ DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(sfloat)
|
|
|
199
220
|
DEF_NARRAY_EYE_METHOD_FUNC(sfloat)
|
|
200
221
|
DEF_NARRAY_FLT_RAND_METHOD_FUNC(sfloat)
|
|
201
222
|
DEF_NARRAY_FLT_RAND_NORM_METHOD_FUNC(sfloat)
|
|
223
|
+
DEF_NARRAY_POLY_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
202
224
|
#ifdef __SSE2__
|
|
203
225
|
DEF_NARRAY_FLT_SQRT_SSE2_SGL_METHOD_FUNC(sfloat, numo_cSFloat)
|
|
204
226
|
#else
|
|
@@ -336,21 +358,6 @@ static VALUE sfloat_allocate(VALUE self) {
|
|
|
336
358
|
return self;
|
|
337
359
|
}
|
|
338
360
|
|
|
339
|
-
static VALUE sfloat_extract(VALUE self) {
|
|
340
|
-
volatile VALUE v;
|
|
341
|
-
char* ptr;
|
|
342
|
-
narray_t* na;
|
|
343
|
-
GetNArray(self, na);
|
|
344
|
-
|
|
345
|
-
if (na->ndim == 0) {
|
|
346
|
-
ptr = na_get_pointer_for_read(self) + na_get_offset(self);
|
|
347
|
-
v = m_extract(ptr);
|
|
348
|
-
na_release_lock(self);
|
|
349
|
-
return v;
|
|
350
|
-
}
|
|
351
|
-
return self;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
361
|
static VALUE sfloat_new_dim0(dtype x) {
|
|
355
362
|
VALUE v;
|
|
356
363
|
dtype* ptr;
|
|
@@ -1314,20 +1321,6 @@ static VALUE sfloat_s_cast(VALUE type, VALUE obj) {
|
|
|
1314
1321
|
return Qnil;
|
|
1315
1322
|
}
|
|
1316
1323
|
|
|
1317
|
-
static VALUE sfloat_aref(int argc, VALUE* argv, VALUE self) {
|
|
1318
|
-
int nd;
|
|
1319
|
-
size_t pos;
|
|
1320
|
-
char* ptr;
|
|
1321
|
-
|
|
1322
|
-
nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
|
|
1323
|
-
if (nd) {
|
|
1324
|
-
return na_aref_main(argc, argv, self, 0, nd);
|
|
1325
|
-
} else {
|
|
1326
|
-
ptr = na_get_pointer_for_read(self) + pos;
|
|
1327
|
-
return m_extract(ptr);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
1324
|
static VALUE sfloat_aset(int argc, VALUE* argv, VALUE self) {
|
|
1332
1325
|
int nd;
|
|
1333
1326
|
size_t pos;
|
|
@@ -1352,501 +1345,6 @@ static VALUE sfloat_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1352
1345
|
return argv[argc];
|
|
1353
1346
|
}
|
|
1354
1347
|
|
|
1355
|
-
static void iter_sfloat_each(na_loop_t* const lp) {
|
|
1356
|
-
size_t i, s1;
|
|
1357
|
-
char* p1;
|
|
1358
|
-
size_t* idx1;
|
|
1359
|
-
dtype x;
|
|
1360
|
-
VALUE y;
|
|
1361
|
-
|
|
1362
|
-
INIT_COUNTER(lp, i);
|
|
1363
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1364
|
-
if (idx1) {
|
|
1365
|
-
for (; i--;) {
|
|
1366
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1367
|
-
y = m_data_to_num(x);
|
|
1368
|
-
rb_yield(y);
|
|
1369
|
-
}
|
|
1370
|
-
} else {
|
|
1371
|
-
for (; i--;) {
|
|
1372
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1373
|
-
y = m_data_to_num(x);
|
|
1374
|
-
rb_yield(y);
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
static VALUE sfloat_each(VALUE self) {
|
|
1380
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1381
|
-
ndfunc_t ndf = { iter_sfloat_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1382
|
-
|
|
1383
|
-
na_ndloop(&ndf, 1, self);
|
|
1384
|
-
return self;
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
static void iter_sfloat_map(na_loop_t* const lp) {
|
|
1388
|
-
size_t i, n;
|
|
1389
|
-
char *p1, *p2;
|
|
1390
|
-
ssize_t s1, s2;
|
|
1391
|
-
size_t *idx1, *idx2;
|
|
1392
|
-
dtype x;
|
|
1393
|
-
|
|
1394
|
-
INIT_COUNTER(lp, n);
|
|
1395
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1396
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1397
|
-
|
|
1398
|
-
if (idx1) {
|
|
1399
|
-
if (idx2) {
|
|
1400
|
-
for (i = 0; i < n; i++) {
|
|
1401
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1402
|
-
x = m_map(x);
|
|
1403
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1404
|
-
}
|
|
1405
|
-
} else {
|
|
1406
|
-
for (i = 0; i < n; i++) {
|
|
1407
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1408
|
-
x = m_map(x);
|
|
1409
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
} else {
|
|
1413
|
-
if (idx2) {
|
|
1414
|
-
for (i = 0; i < n; i++) {
|
|
1415
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1416
|
-
x = m_map(x);
|
|
1417
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1418
|
-
}
|
|
1419
|
-
} else {
|
|
1420
|
-
//
|
|
1421
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1422
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1423
|
-
for (i = 0; i < n; i++) {
|
|
1424
|
-
((dtype*)p2)[i] = m_map(((dtype*)p1)[i]);
|
|
1425
|
-
}
|
|
1426
|
-
return;
|
|
1427
|
-
}
|
|
1428
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1429
|
-
//
|
|
1430
|
-
for (i = 0; i < n; i++) {
|
|
1431
|
-
*(dtype*)p2 = m_map(*(dtype*)p1);
|
|
1432
|
-
p1 += s1;
|
|
1433
|
-
p2 += s2;
|
|
1434
|
-
}
|
|
1435
|
-
return;
|
|
1436
|
-
//
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
for (i = 0; i < n; i++) {
|
|
1440
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1441
|
-
x = m_map(x);
|
|
1442
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1443
|
-
}
|
|
1444
|
-
//
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
static VALUE sfloat_map(VALUE self) {
|
|
1450
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1451
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1452
|
-
ndfunc_t ndf = { iter_sfloat_map, FULL_LOOP, 1, 1, ain, aout };
|
|
1453
|
-
|
|
1454
|
-
return na_ndloop(&ndf, 1, self);
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
static inline void yield_each_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1458
|
-
int j;
|
|
1459
|
-
|
|
1460
|
-
a[0] = m_data_to_num(x);
|
|
1461
|
-
for (j = 0; j <= nd; j++) {
|
|
1462
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1463
|
-
}
|
|
1464
|
-
rb_yield(rb_ary_new4(md, a));
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
static void iter_sfloat_each_with_index(na_loop_t* const lp) {
|
|
1468
|
-
size_t i, s1;
|
|
1469
|
-
char* p1;
|
|
1470
|
-
size_t* idx1;
|
|
1471
|
-
dtype x;
|
|
1472
|
-
VALUE* a;
|
|
1473
|
-
size_t* c;
|
|
1474
|
-
int nd, md;
|
|
1475
|
-
|
|
1476
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1477
|
-
nd = lp->ndim;
|
|
1478
|
-
if (nd > 0) {
|
|
1479
|
-
nd--;
|
|
1480
|
-
}
|
|
1481
|
-
md = nd + 2;
|
|
1482
|
-
a = ALLOCA_N(VALUE, md);
|
|
1483
|
-
|
|
1484
|
-
INIT_COUNTER(lp, i);
|
|
1485
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1486
|
-
c[nd] = 0;
|
|
1487
|
-
if (idx1) {
|
|
1488
|
-
for (; i--;) {
|
|
1489
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1490
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1491
|
-
c[nd]++;
|
|
1492
|
-
}
|
|
1493
|
-
} else {
|
|
1494
|
-
for (; i--;) {
|
|
1495
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1496
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1497
|
-
c[nd]++;
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
static VALUE sfloat_each_with_index(VALUE self) {
|
|
1503
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1504
|
-
ndfunc_t ndf = { iter_sfloat_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1505
|
-
|
|
1506
|
-
na_ndloop_with_index(&ndf, 1, self);
|
|
1507
|
-
return self;
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
static inline dtype yield_map_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1511
|
-
int j;
|
|
1512
|
-
VALUE y;
|
|
1513
|
-
|
|
1514
|
-
a[0] = m_data_to_num(x);
|
|
1515
|
-
for (j = 0; j <= nd; j++) {
|
|
1516
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1517
|
-
}
|
|
1518
|
-
y = rb_yield(rb_ary_new4(md, a));
|
|
1519
|
-
return m_num_to_data(y);
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
static void iter_sfloat_map_with_index(na_loop_t* const lp) {
|
|
1523
|
-
size_t i;
|
|
1524
|
-
char *p1, *p2;
|
|
1525
|
-
ssize_t s1, s2;
|
|
1526
|
-
size_t *idx1, *idx2;
|
|
1527
|
-
dtype x;
|
|
1528
|
-
VALUE* a;
|
|
1529
|
-
size_t* c;
|
|
1530
|
-
int nd, md;
|
|
1531
|
-
|
|
1532
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1533
|
-
nd = lp->ndim;
|
|
1534
|
-
if (nd > 0) {
|
|
1535
|
-
nd--;
|
|
1536
|
-
}
|
|
1537
|
-
md = nd + 2;
|
|
1538
|
-
a = ALLOCA_N(VALUE, md);
|
|
1539
|
-
|
|
1540
|
-
INIT_COUNTER(lp, i);
|
|
1541
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1542
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1543
|
-
|
|
1544
|
-
c[nd] = 0;
|
|
1545
|
-
if (idx1) {
|
|
1546
|
-
if (idx2) {
|
|
1547
|
-
for (; i--;) {
|
|
1548
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1549
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1550
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1551
|
-
c[nd]++;
|
|
1552
|
-
}
|
|
1553
|
-
} else {
|
|
1554
|
-
for (; i--;) {
|
|
1555
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1556
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1557
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1558
|
-
c[nd]++;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
} else {
|
|
1562
|
-
if (idx2) {
|
|
1563
|
-
for (; i--;) {
|
|
1564
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1565
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1566
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1567
|
-
c[nd]++;
|
|
1568
|
-
}
|
|
1569
|
-
} else {
|
|
1570
|
-
for (; i--;) {
|
|
1571
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1572
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1573
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1574
|
-
c[nd]++;
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
|
-
static VALUE sfloat_map_with_index(VALUE self) {
|
|
1581
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1582
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1583
|
-
ndfunc_t ndf = { iter_sfloat_map_with_index, FULL_LOOP, 1, 1, ain, aout };
|
|
1584
|
-
|
|
1585
|
-
return na_ndloop_with_index(&ndf, 1, self);
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
static void iter_sfloat_abs(na_loop_t* const lp) {
|
|
1589
|
-
size_t i;
|
|
1590
|
-
char *p1, *p2;
|
|
1591
|
-
ssize_t s1, s2;
|
|
1592
|
-
size_t *idx1, *idx2;
|
|
1593
|
-
dtype x;
|
|
1594
|
-
rtype y;
|
|
1595
|
-
INIT_COUNTER(lp, i);
|
|
1596
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1597
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1598
|
-
if (idx1) {
|
|
1599
|
-
if (idx2) {
|
|
1600
|
-
for (; i--;) {
|
|
1601
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1602
|
-
y = m_abs(x);
|
|
1603
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1604
|
-
}
|
|
1605
|
-
} else {
|
|
1606
|
-
for (; i--;) {
|
|
1607
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1608
|
-
y = m_abs(x);
|
|
1609
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
} else {
|
|
1613
|
-
if (idx2) {
|
|
1614
|
-
for (; i--;) {
|
|
1615
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1616
|
-
y = m_abs(x);
|
|
1617
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1618
|
-
}
|
|
1619
|
-
} else {
|
|
1620
|
-
for (; i--;) {
|
|
1621
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1622
|
-
y = m_abs(x);
|
|
1623
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
static VALUE sfloat_abs(VALUE self) {
|
|
1630
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1631
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
1632
|
-
ndfunc_t ndf = { iter_sfloat_abs, FULL_LOOP, 1, 1, ain, aout };
|
|
1633
|
-
|
|
1634
|
-
return na_ndloop(&ndf, 1, self);
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
#define check_intdivzero(y) \
|
|
1638
|
-
{}
|
|
1639
|
-
|
|
1640
|
-
static void iter_sfloat_copysign(na_loop_t* const lp) {
|
|
1641
|
-
size_t i = 0;
|
|
1642
|
-
size_t n;
|
|
1643
|
-
char *p1, *p2, *p3;
|
|
1644
|
-
ssize_t s1, s2, s3;
|
|
1645
|
-
|
|
1646
|
-
INIT_COUNTER(lp, n);
|
|
1647
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
1648
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1649
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1650
|
-
|
|
1651
|
-
//
|
|
1652
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
1653
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
1654
|
-
|
|
1655
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1656
|
-
if (p1 == p3) { // inplace case
|
|
1657
|
-
for (; i < n; i++) {
|
|
1658
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
1659
|
-
((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
1660
|
-
}
|
|
1661
|
-
} else {
|
|
1662
|
-
for (; i < n; i++) {
|
|
1663
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
1664
|
-
((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
return;
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
1671
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
1672
|
-
//
|
|
1673
|
-
|
|
1674
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
1675
|
-
check_intdivzero(*(dtype*)p2);
|
|
1676
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1677
|
-
if (p1 == p3) { // inplace case
|
|
1678
|
-
for (; i < n; i++) {
|
|
1679
|
-
((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
|
|
1680
|
-
}
|
|
1681
|
-
} else {
|
|
1682
|
-
for (; i < n; i++) {
|
|
1683
|
-
((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
} else {
|
|
1687
|
-
for (i = 0; i < n; i++) {
|
|
1688
|
-
*(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
|
|
1689
|
-
p1 += s1;
|
|
1690
|
-
p3 += s3;
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
} else {
|
|
1694
|
-
if (p1 == p3) { // inplace case
|
|
1695
|
-
for (i = 0; i < n; i++) {
|
|
1696
|
-
check_intdivzero(*(dtype*)p2);
|
|
1697
|
-
*(dtype*)p1 = m_copysign(*(dtype*)p1, *(dtype*)p2);
|
|
1698
|
-
p1 += s1;
|
|
1699
|
-
p2 += s2;
|
|
1700
|
-
}
|
|
1701
|
-
} else {
|
|
1702
|
-
for (i = 0; i < n; i++) {
|
|
1703
|
-
check_intdivzero(*(dtype*)p2);
|
|
1704
|
-
*(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
|
|
1705
|
-
p1 += s1;
|
|
1706
|
-
p2 += s2;
|
|
1707
|
-
p3 += s3;
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
return;
|
|
1713
|
-
//
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
for (i = 0; i < n; i++) {
|
|
1717
|
-
dtype x, y, z;
|
|
1718
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1719
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
1720
|
-
check_intdivzero(y);
|
|
1721
|
-
z = m_copysign(x, y);
|
|
1722
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
1723
|
-
}
|
|
1724
|
-
//
|
|
1725
|
-
}
|
|
1726
|
-
#undef check_intdivzero
|
|
1727
|
-
|
|
1728
|
-
static VALUE sfloat_copysign_self(VALUE self, VALUE other) {
|
|
1729
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
1730
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1731
|
-
ndfunc_t ndf = { iter_sfloat_copysign, STRIDE_LOOP, 2, 1, ain, aout };
|
|
1732
|
-
|
|
1733
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
static VALUE sfloat_copysign(VALUE self, VALUE other) {
|
|
1737
|
-
|
|
1738
|
-
VALUE klass, v;
|
|
1739
|
-
|
|
1740
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
1741
|
-
if (klass == cT) {
|
|
1742
|
-
return sfloat_copysign_self(self, other);
|
|
1743
|
-
} else {
|
|
1744
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
1745
|
-
return rb_funcall(v, id_copysign, 1, other);
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
static void iter_sfloat_signbit(na_loop_t* const lp) {
|
|
1750
|
-
size_t i;
|
|
1751
|
-
char* p1;
|
|
1752
|
-
BIT_DIGIT* a2;
|
|
1753
|
-
size_t p2;
|
|
1754
|
-
ssize_t s1, s2;
|
|
1755
|
-
size_t* idx1;
|
|
1756
|
-
dtype x;
|
|
1757
|
-
BIT_DIGIT b;
|
|
1758
|
-
INIT_COUNTER(lp, i);
|
|
1759
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1760
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
1761
|
-
if (idx1) {
|
|
1762
|
-
for (; i--;) {
|
|
1763
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1764
|
-
b = (m_signbit(x)) ? 1 : 0;
|
|
1765
|
-
STORE_BIT(a2, p2, b);
|
|
1766
|
-
p2 += s2;
|
|
1767
|
-
}
|
|
1768
|
-
} else {
|
|
1769
|
-
for (; i--;) {
|
|
1770
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1771
|
-
b = (m_signbit(x)) ? 1 : 0;
|
|
1772
|
-
STORE_BIT(a2, p2, b);
|
|
1773
|
-
p2 += s2;
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
static VALUE sfloat_signbit(VALUE self) {
|
|
1779
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1780
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
1781
|
-
ndfunc_t ndf = { iter_sfloat_signbit, FULL_LOOP, 1, 1, ain, aout };
|
|
1782
|
-
|
|
1783
|
-
return na_ndloop(&ndf, 1, self);
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
static void iter_sfloat_modf(na_loop_t* const lp) {
|
|
1787
|
-
size_t i;
|
|
1788
|
-
char *p1, *p2, *p3;
|
|
1789
|
-
ssize_t s1, s2, s3;
|
|
1790
|
-
dtype x, y, z;
|
|
1791
|
-
INIT_COUNTER(lp, i);
|
|
1792
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
1793
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1794
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1795
|
-
for (; i--;) {
|
|
1796
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1797
|
-
m_modf(x, y, z);
|
|
1798
|
-
SET_DATA_STRIDE(p2, s2, dtype, y);
|
|
1799
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
static VALUE sfloat_modf(VALUE self) {
|
|
1804
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1805
|
-
ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
|
|
1806
|
-
ndfunc_t ndf = { iter_sfloat_modf, STRIDE_LOOP, 1, 2, ain, aout };
|
|
1807
|
-
|
|
1808
|
-
return na_ndloop(&ndf, 1, self);
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
static void iter_sfloat_poly(na_loop_t* const lp) {
|
|
1812
|
-
size_t i;
|
|
1813
|
-
dtype x, y, a;
|
|
1814
|
-
|
|
1815
|
-
x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
|
|
1816
|
-
i = lp->narg - 2;
|
|
1817
|
-
y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
1818
|
-
for (; --i;) {
|
|
1819
|
-
y = m_mul(x, y);
|
|
1820
|
-
a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
1821
|
-
y = m_add(y, a);
|
|
1822
|
-
}
|
|
1823
|
-
i = lp->narg - 1;
|
|
1824
|
-
*(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
|
-
static VALUE sfloat_poly(VALUE self, VALUE args) {
|
|
1828
|
-
int argc, i;
|
|
1829
|
-
VALUE* argv;
|
|
1830
|
-
volatile VALUE v, a;
|
|
1831
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1832
|
-
ndfunc_t ndf = { iter_sfloat_poly, NO_LOOP, 0, 1, 0, aout };
|
|
1833
|
-
|
|
1834
|
-
argc = (int)RARRAY_LEN(args);
|
|
1835
|
-
ndf.nin = argc + 1;
|
|
1836
|
-
ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
|
|
1837
|
-
for (i = 0; i < argc + 1; i++) {
|
|
1838
|
-
ndf.ain[i].type = cT;
|
|
1839
|
-
}
|
|
1840
|
-
argv = ALLOCA_N(VALUE, argc + 1);
|
|
1841
|
-
argv[0] = self;
|
|
1842
|
-
for (i = 0; i < argc; i++) {
|
|
1843
|
-
argv[i + 1] = RARRAY_PTR(args)[i];
|
|
1844
|
-
}
|
|
1845
|
-
a = rb_ary_new4(argc + 1, argv);
|
|
1846
|
-
v = na_ndloop2(&ndf, a);
|
|
1847
|
-
return sfloat_extract(v);
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
1348
|
/*
|
|
1851
1349
|
qsort.c
|
|
1852
1350
|
Ruby/Numo::NArray - Numerical Array class for Ruby
|