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
|
@@ -38,12 +38,19 @@ static ID id_to_a;
|
|
|
38
38
|
VALUE cT;
|
|
39
39
|
extern VALUE cRT;
|
|
40
40
|
|
|
41
|
+
#include "mh/extract.h"
|
|
42
|
+
#include "mh/aref.h"
|
|
41
43
|
#include "mh/coerce_cast.h"
|
|
42
44
|
#include "mh/to_a.h"
|
|
43
45
|
#include "mh/fill.h"
|
|
44
46
|
#include "mh/format.h"
|
|
45
47
|
#include "mh/format_to_a.h"
|
|
46
48
|
#include "mh/inspect.h"
|
|
49
|
+
#include "mh/each.h"
|
|
50
|
+
#include "mh/map.h"
|
|
51
|
+
#include "mh/each_with_index.h"
|
|
52
|
+
#include "mh/map_with_index.h"
|
|
53
|
+
#include "mh/abs.h"
|
|
47
54
|
#include "mh/op/add.h"
|
|
48
55
|
#include "mh/op/sub.h"
|
|
49
56
|
#include "mh/op/mul.h"
|
|
@@ -53,6 +60,13 @@ extern VALUE cRT;
|
|
|
53
60
|
#include "mh/reciprocal.h"
|
|
54
61
|
#include "mh/sign.h"
|
|
55
62
|
#include "mh/square.h"
|
|
63
|
+
#include "mh/conj.h"
|
|
64
|
+
#include "mh/im.h"
|
|
65
|
+
#include "mh/real.h"
|
|
66
|
+
#include "mh/imag.h"
|
|
67
|
+
#include "mh/arg.h"
|
|
68
|
+
#include "mh/set_imag.h"
|
|
69
|
+
#include "mh/set_real.h"
|
|
56
70
|
#include "mh/comp/eq.h"
|
|
57
71
|
#include "mh/comp/ne.h"
|
|
58
72
|
#include "mh/comp/nearly_eq.h"
|
|
@@ -61,6 +75,7 @@ extern VALUE cRT;
|
|
|
61
75
|
#include "mh/round/ceil.h"
|
|
62
76
|
#include "mh/round/trunc.h"
|
|
63
77
|
#include "mh/round/rint.h"
|
|
78
|
+
#include "mh/copysign.h"
|
|
64
79
|
#include "mh/isnan.h"
|
|
65
80
|
#include "mh/isinf.h"
|
|
66
81
|
#include "mh/isposinf.h"
|
|
@@ -80,6 +95,7 @@ extern VALUE cRT;
|
|
|
80
95
|
#include "mh/eye.h"
|
|
81
96
|
#include "mh/rand.h"
|
|
82
97
|
#include "mh/rand_norm.h"
|
|
98
|
+
#include "mh/poly.h"
|
|
83
99
|
#include "mh/math/sqrt.h"
|
|
84
100
|
#include "mh/math/cbrt.h"
|
|
85
101
|
#include "mh/math/log.h"
|
|
@@ -102,12 +118,19 @@ extern VALUE cRT;
|
|
|
102
118
|
#include "mh/math/atanh.h"
|
|
103
119
|
#include "mh/math/sinc.h"
|
|
104
120
|
|
|
121
|
+
DEF_NARRAY_EXTRACT_METHOD_FUNC(scomplex)
|
|
122
|
+
DEF_NARRAY_AREF_METHOD_FUNC(scomplex)
|
|
105
123
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(scomplex)
|
|
106
124
|
DEF_NARRAY_TO_A_METHOD_FUNC(scomplex)
|
|
107
125
|
DEF_NARRAY_FILL_METHOD_FUNC(scomplex)
|
|
108
126
|
DEF_NARRAY_FORMAT_METHOD_FUNC(scomplex)
|
|
109
127
|
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(scomplex)
|
|
110
128
|
DEF_NARRAY_INSPECT_METHOD_FUNC(scomplex)
|
|
129
|
+
DEF_NARRAY_EACH_METHOD_FUNC(scomplex)
|
|
130
|
+
DEF_NARRAY_MAP_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
131
|
+
DEF_NARRAY_EACH_WITH_INDEX_METHOD_FUNC(scomplex)
|
|
132
|
+
DEF_NARRAY_MAP_WITH_INDEX_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
133
|
+
DEF_NARRAY_ABS_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
111
134
|
DEF_NARRAY_ADD_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
112
135
|
DEF_NARRAY_SUB_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
113
136
|
DEF_NARRAY_MUL_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
@@ -117,6 +140,13 @@ DEF_NARRAY_MINUS_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
|
117
140
|
DEF_NARRAY_RECIPROCAL_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
118
141
|
DEF_NARRAY_SIGN_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
119
142
|
DEF_NARRAY_SQUARE_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
143
|
+
DEF_NARRAY_CONJ_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
144
|
+
DEF_NARRAY_IM_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
145
|
+
DEF_NARRAY_REAL_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
146
|
+
DEF_NARRAY_IMAG_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
147
|
+
DEF_NARRAY_ARG_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
148
|
+
DEF_NARRAY_SET_IMAG_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
149
|
+
DEF_NARRAY_SET_REAL_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
120
150
|
DEF_NARRAY_EQ_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
121
151
|
DEF_NARRAY_NE_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
122
152
|
DEF_NARRAY_NEARLY_EQ_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
@@ -125,6 +155,7 @@ DEF_NARRAY_FLT_ROUND_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
|
125
155
|
DEF_NARRAY_FLT_CEIL_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
126
156
|
DEF_NARRAY_FLT_TRUNC_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
127
157
|
DEF_NARRAY_FLT_RINT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
158
|
+
DEF_NARRAY_COPYSIGN_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
128
159
|
DEF_NARRAY_FLT_ISNAN_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
129
160
|
DEF_NARRAY_FLT_ISINF_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
130
161
|
DEF_NARRAY_FLT_ISPOSINF_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
@@ -144,6 +175,7 @@ DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(scomplex)
|
|
|
144
175
|
DEF_NARRAY_EYE_METHOD_FUNC(scomplex)
|
|
145
176
|
DEF_NARRAY_CMP_RAND_METHOD_FUNC(scomplex)
|
|
146
177
|
DEF_NARRAY_CMP_RAND_NORM_METHOD_FUNC(scomplex, float)
|
|
178
|
+
DEF_NARRAY_POLY_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
147
179
|
DEF_NARRAY_FLT_SQRT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
148
180
|
DEF_NARRAY_FLT_CBRT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
149
181
|
DEF_NARRAY_FLT_LOG_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
@@ -269,28 +301,6 @@ static VALUE scomplex_allocate(VALUE self) {
|
|
|
269
301
|
return self;
|
|
270
302
|
}
|
|
271
303
|
|
|
272
|
-
/*
|
|
273
|
-
Extract an element only if self is a dimensionless NArray.
|
|
274
|
-
@overload extract
|
|
275
|
-
@return [Numeric,Numo::NArray]
|
|
276
|
-
--- Extract element value as Ruby Object if self is a dimensionless NArray,
|
|
277
|
-
otherwise returns self.
|
|
278
|
-
*/
|
|
279
|
-
static VALUE scomplex_extract(VALUE self) {
|
|
280
|
-
volatile VALUE v;
|
|
281
|
-
char* ptr;
|
|
282
|
-
narray_t* na;
|
|
283
|
-
GetNArray(self, na);
|
|
284
|
-
|
|
285
|
-
if (na->ndim == 0) {
|
|
286
|
-
ptr = na_get_pointer_for_read(self) + na_get_offset(self);
|
|
287
|
-
v = m_extract(ptr);
|
|
288
|
-
na_release_lock(self);
|
|
289
|
-
return v;
|
|
290
|
-
}
|
|
291
|
-
return self;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
304
|
static VALUE scomplex_new_dim0(dtype x) {
|
|
295
305
|
VALUE v;
|
|
296
306
|
dtype* ptr;
|
|
@@ -1392,29 +1402,6 @@ static VALUE scomplex_s_cast(VALUE type, VALUE obj) {
|
|
|
1392
1402
|
return Qnil;
|
|
1393
1403
|
}
|
|
1394
1404
|
|
|
1395
|
-
/*
|
|
1396
|
-
Multi-dimensional element reference.
|
|
1397
|
-
@overload [](dim0,...,dimL)
|
|
1398
|
-
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
|
1399
|
-
dim0,...,dimL multi-dimensional indices.
|
|
1400
|
-
@return [Numeric,Numo::SComplex] an element or NArray view.
|
|
1401
|
-
@see Numo::NArray#[]
|
|
1402
|
-
@see #[]=
|
|
1403
|
-
*/
|
|
1404
|
-
static VALUE scomplex_aref(int argc, VALUE* argv, VALUE self) {
|
|
1405
|
-
int nd;
|
|
1406
|
-
size_t pos;
|
|
1407
|
-
char* ptr;
|
|
1408
|
-
|
|
1409
|
-
nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
|
|
1410
|
-
if (nd) {
|
|
1411
|
-
return na_aref_main(argc, argv, self, 0, nd);
|
|
1412
|
-
} else {
|
|
1413
|
-
ptr = na_get_pointer_for_read(self) + pos;
|
|
1414
|
-
return m_extract(ptr);
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
1405
|
/*
|
|
1419
1406
|
Multi-dimensional element assignment.
|
|
1420
1407
|
@overload []=(dim0,...,dimL,val)
|
|
@@ -1449,914 +1436,6 @@ static VALUE scomplex_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1449
1436
|
return argv[argc];
|
|
1450
1437
|
}
|
|
1451
1438
|
|
|
1452
|
-
static void iter_scomplex_each(na_loop_t* const lp) {
|
|
1453
|
-
size_t i, s1;
|
|
1454
|
-
char* p1;
|
|
1455
|
-
size_t* idx1;
|
|
1456
|
-
dtype x;
|
|
1457
|
-
VALUE y;
|
|
1458
|
-
|
|
1459
|
-
INIT_COUNTER(lp, i);
|
|
1460
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1461
|
-
if (idx1) {
|
|
1462
|
-
for (; i--;) {
|
|
1463
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1464
|
-
y = m_data_to_num(x);
|
|
1465
|
-
rb_yield(y);
|
|
1466
|
-
}
|
|
1467
|
-
} else {
|
|
1468
|
-
for (; i--;) {
|
|
1469
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1470
|
-
y = m_data_to_num(x);
|
|
1471
|
-
rb_yield(y);
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
/*
|
|
1477
|
-
Calls the given block once for each element in self,
|
|
1478
|
-
passing that element as a parameter.
|
|
1479
|
-
@overload each
|
|
1480
|
-
@return [Numo::NArray] self
|
|
1481
|
-
For a block `{|x| ... }`,
|
|
1482
|
-
@yieldparam [Numeric] x an element of NArray.
|
|
1483
|
-
@see #each_with_index
|
|
1484
|
-
@see #map
|
|
1485
|
-
*/
|
|
1486
|
-
static VALUE scomplex_each(VALUE self) {
|
|
1487
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1488
|
-
ndfunc_t ndf = { iter_scomplex_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1489
|
-
|
|
1490
|
-
na_ndloop(&ndf, 1, self);
|
|
1491
|
-
return self;
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
static void iter_scomplex_map(na_loop_t* const lp) {
|
|
1495
|
-
size_t i, n;
|
|
1496
|
-
char *p1, *p2;
|
|
1497
|
-
ssize_t s1, s2;
|
|
1498
|
-
size_t *idx1, *idx2;
|
|
1499
|
-
dtype x;
|
|
1500
|
-
|
|
1501
|
-
INIT_COUNTER(lp, n);
|
|
1502
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1503
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1504
|
-
|
|
1505
|
-
if (idx1) {
|
|
1506
|
-
if (idx2) {
|
|
1507
|
-
for (i = 0; i < n; i++) {
|
|
1508
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1509
|
-
x = m_map(x);
|
|
1510
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1511
|
-
}
|
|
1512
|
-
} else {
|
|
1513
|
-
for (i = 0; i < n; i++) {
|
|
1514
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1515
|
-
x = m_map(x);
|
|
1516
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
} else {
|
|
1520
|
-
if (idx2) {
|
|
1521
|
-
for (i = 0; i < n; i++) {
|
|
1522
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1523
|
-
x = m_map(x);
|
|
1524
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1525
|
-
}
|
|
1526
|
-
} else {
|
|
1527
|
-
//
|
|
1528
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1529
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1530
|
-
for (i = 0; i < n; i++) {
|
|
1531
|
-
((dtype*)p2)[i] = m_map(((dtype*)p1)[i]);
|
|
1532
|
-
}
|
|
1533
|
-
return;
|
|
1534
|
-
}
|
|
1535
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1536
|
-
//
|
|
1537
|
-
for (i = 0; i < n; i++) {
|
|
1538
|
-
*(dtype*)p2 = m_map(*(dtype*)p1);
|
|
1539
|
-
p1 += s1;
|
|
1540
|
-
p2 += s2;
|
|
1541
|
-
}
|
|
1542
|
-
return;
|
|
1543
|
-
//
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
for (i = 0; i < n; i++) {
|
|
1547
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1548
|
-
x = m_map(x);
|
|
1549
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1550
|
-
}
|
|
1551
|
-
//
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
/*
|
|
1557
|
-
Unary map.
|
|
1558
|
-
@overload map
|
|
1559
|
-
@return [Numo::SComplex] map of self.
|
|
1560
|
-
*/
|
|
1561
|
-
static VALUE scomplex_map(VALUE self) {
|
|
1562
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1563
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1564
|
-
ndfunc_t ndf = { iter_scomplex_map, FULL_LOOP, 1, 1, ain, aout };
|
|
1565
|
-
|
|
1566
|
-
return na_ndloop(&ndf, 1, self);
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
static inline void yield_each_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1570
|
-
int j;
|
|
1571
|
-
|
|
1572
|
-
a[0] = m_data_to_num(x);
|
|
1573
|
-
for (j = 0; j <= nd; j++) {
|
|
1574
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1575
|
-
}
|
|
1576
|
-
rb_yield(rb_ary_new4(md, a));
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
static void iter_scomplex_each_with_index(na_loop_t* const lp) {
|
|
1580
|
-
size_t i, s1;
|
|
1581
|
-
char* p1;
|
|
1582
|
-
size_t* idx1;
|
|
1583
|
-
dtype x;
|
|
1584
|
-
VALUE* a;
|
|
1585
|
-
size_t* c;
|
|
1586
|
-
int nd, md;
|
|
1587
|
-
|
|
1588
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1589
|
-
nd = lp->ndim;
|
|
1590
|
-
if (nd > 0) {
|
|
1591
|
-
nd--;
|
|
1592
|
-
}
|
|
1593
|
-
md = nd + 2;
|
|
1594
|
-
a = ALLOCA_N(VALUE, md);
|
|
1595
|
-
|
|
1596
|
-
INIT_COUNTER(lp, i);
|
|
1597
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1598
|
-
c[nd] = 0;
|
|
1599
|
-
if (idx1) {
|
|
1600
|
-
for (; i--;) {
|
|
1601
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1602
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1603
|
-
c[nd]++;
|
|
1604
|
-
}
|
|
1605
|
-
} else {
|
|
1606
|
-
for (; i--;) {
|
|
1607
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1608
|
-
yield_each_with_index(x, c, a, nd, md);
|
|
1609
|
-
c[nd]++;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
/*
|
|
1615
|
-
Invokes the given block once for each element of self,
|
|
1616
|
-
passing that element and indices along each axis as parameters.
|
|
1617
|
-
@overload each_with_index
|
|
1618
|
-
For a block `{|x,i,j,...| ... }`,
|
|
1619
|
-
@yieldparam [Numeric] x an element
|
|
1620
|
-
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1621
|
-
@return [Numo::NArray] self
|
|
1622
|
-
@see #each
|
|
1623
|
-
@see #map_with_index
|
|
1624
|
-
*/
|
|
1625
|
-
static VALUE scomplex_each_with_index(VALUE self) {
|
|
1626
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1627
|
-
ndfunc_t ndf = { iter_scomplex_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1628
|
-
|
|
1629
|
-
na_ndloop_with_index(&ndf, 1, self);
|
|
1630
|
-
return self;
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
static inline dtype yield_map_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
|
|
1634
|
-
int j;
|
|
1635
|
-
VALUE y;
|
|
1636
|
-
|
|
1637
|
-
a[0] = m_data_to_num(x);
|
|
1638
|
-
for (j = 0; j <= nd; j++) {
|
|
1639
|
-
a[j + 1] = SIZET2NUM(c[j]);
|
|
1640
|
-
}
|
|
1641
|
-
y = rb_yield(rb_ary_new4(md, a));
|
|
1642
|
-
return m_num_to_data(y);
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
static void iter_scomplex_map_with_index(na_loop_t* const lp) {
|
|
1646
|
-
size_t i;
|
|
1647
|
-
char *p1, *p2;
|
|
1648
|
-
ssize_t s1, s2;
|
|
1649
|
-
size_t *idx1, *idx2;
|
|
1650
|
-
dtype x;
|
|
1651
|
-
VALUE* a;
|
|
1652
|
-
size_t* c;
|
|
1653
|
-
int nd, md;
|
|
1654
|
-
|
|
1655
|
-
c = (size_t*)(lp->opt_ptr);
|
|
1656
|
-
nd = lp->ndim;
|
|
1657
|
-
if (nd > 0) {
|
|
1658
|
-
nd--;
|
|
1659
|
-
}
|
|
1660
|
-
md = nd + 2;
|
|
1661
|
-
a = ALLOCA_N(VALUE, md);
|
|
1662
|
-
|
|
1663
|
-
INIT_COUNTER(lp, i);
|
|
1664
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1665
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1666
|
-
|
|
1667
|
-
c[nd] = 0;
|
|
1668
|
-
if (idx1) {
|
|
1669
|
-
if (idx2) {
|
|
1670
|
-
for (; i--;) {
|
|
1671
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1672
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1673
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1674
|
-
c[nd]++;
|
|
1675
|
-
}
|
|
1676
|
-
} else {
|
|
1677
|
-
for (; i--;) {
|
|
1678
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1679
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1680
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1681
|
-
c[nd]++;
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
} else {
|
|
1685
|
-
if (idx2) {
|
|
1686
|
-
for (; i--;) {
|
|
1687
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1688
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1689
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1690
|
-
c[nd]++;
|
|
1691
|
-
}
|
|
1692
|
-
} else {
|
|
1693
|
-
for (; i--;) {
|
|
1694
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1695
|
-
x = yield_map_with_index(x, c, a, nd, md);
|
|
1696
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1697
|
-
c[nd]++;
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
/*
|
|
1704
|
-
Invokes the given block once for each element of self,
|
|
1705
|
-
passing that element and indices along each axis as parameters.
|
|
1706
|
-
Creates a new NArray containing the values returned by the block.
|
|
1707
|
-
Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
|
1708
|
-
@overload map_with_index
|
|
1709
|
-
For a block `{|x,i,j,...| ... }`,
|
|
1710
|
-
@yieldparam [Numeric] x an element
|
|
1711
|
-
@yieldparam [Integer] i,j,... multitimensional indices
|
|
1712
|
-
@return [Numo::NArray] mapped array
|
|
1713
|
-
@see #map
|
|
1714
|
-
@see #each_with_index
|
|
1715
|
-
*/
|
|
1716
|
-
static VALUE scomplex_map_with_index(VALUE self) {
|
|
1717
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1718
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1719
|
-
ndfunc_t ndf = { iter_scomplex_map_with_index, FULL_LOOP, 1, 1, ain, aout };
|
|
1720
|
-
|
|
1721
|
-
return na_ndloop_with_index(&ndf, 1, self);
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
static void iter_scomplex_abs(na_loop_t* const lp) {
|
|
1725
|
-
size_t i;
|
|
1726
|
-
char *p1, *p2;
|
|
1727
|
-
ssize_t s1, s2;
|
|
1728
|
-
size_t *idx1, *idx2;
|
|
1729
|
-
dtype x;
|
|
1730
|
-
rtype y;
|
|
1731
|
-
INIT_COUNTER(lp, i);
|
|
1732
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1733
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1734
|
-
if (idx1) {
|
|
1735
|
-
if (idx2) {
|
|
1736
|
-
for (; i--;) {
|
|
1737
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1738
|
-
y = m_abs(x);
|
|
1739
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1740
|
-
}
|
|
1741
|
-
} else {
|
|
1742
|
-
for (; i--;) {
|
|
1743
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1744
|
-
y = m_abs(x);
|
|
1745
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
} else {
|
|
1749
|
-
if (idx2) {
|
|
1750
|
-
for (; i--;) {
|
|
1751
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1752
|
-
y = m_abs(x);
|
|
1753
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1754
|
-
}
|
|
1755
|
-
} else {
|
|
1756
|
-
for (; i--;) {
|
|
1757
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1758
|
-
y = m_abs(x);
|
|
1759
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
/*
|
|
1766
|
-
abs of self.
|
|
1767
|
-
@overload abs
|
|
1768
|
-
@return [Numo::SFloat] abs of self.
|
|
1769
|
-
*/
|
|
1770
|
-
static VALUE scomplex_abs(VALUE self) {
|
|
1771
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1772
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
1773
|
-
ndfunc_t ndf = { iter_scomplex_abs, FULL_LOOP, 1, 1, ain, aout };
|
|
1774
|
-
|
|
1775
|
-
return na_ndloop(&ndf, 1, self);
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
static void iter_scomplex_conj(na_loop_t* const lp) {
|
|
1779
|
-
size_t i, n;
|
|
1780
|
-
char *p1, *p2;
|
|
1781
|
-
ssize_t s1, s2;
|
|
1782
|
-
size_t *idx1, *idx2;
|
|
1783
|
-
dtype x;
|
|
1784
|
-
|
|
1785
|
-
INIT_COUNTER(lp, n);
|
|
1786
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1787
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1788
|
-
|
|
1789
|
-
if (idx1) {
|
|
1790
|
-
if (idx2) {
|
|
1791
|
-
for (i = 0; i < n; i++) {
|
|
1792
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1793
|
-
x = m_conj(x);
|
|
1794
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1795
|
-
}
|
|
1796
|
-
} else {
|
|
1797
|
-
for (i = 0; i < n; i++) {
|
|
1798
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1799
|
-
x = m_conj(x);
|
|
1800
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
} else {
|
|
1804
|
-
if (idx2) {
|
|
1805
|
-
for (i = 0; i < n; i++) {
|
|
1806
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1807
|
-
x = m_conj(x);
|
|
1808
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1809
|
-
}
|
|
1810
|
-
} else {
|
|
1811
|
-
//
|
|
1812
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1813
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1814
|
-
for (i = 0; i < n; i++) {
|
|
1815
|
-
((dtype*)p2)[i] = m_conj(((dtype*)p1)[i]);
|
|
1816
|
-
}
|
|
1817
|
-
return;
|
|
1818
|
-
}
|
|
1819
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1820
|
-
//
|
|
1821
|
-
for (i = 0; i < n; i++) {
|
|
1822
|
-
*(dtype*)p2 = m_conj(*(dtype*)p1);
|
|
1823
|
-
p1 += s1;
|
|
1824
|
-
p2 += s2;
|
|
1825
|
-
}
|
|
1826
|
-
return;
|
|
1827
|
-
//
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
for (i = 0; i < n; i++) {
|
|
1831
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1832
|
-
x = m_conj(x);
|
|
1833
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1834
|
-
}
|
|
1835
|
-
//
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
/*
|
|
1841
|
-
Unary conj.
|
|
1842
|
-
@overload conj
|
|
1843
|
-
@return [Numo::SComplex] conj of self.
|
|
1844
|
-
*/
|
|
1845
|
-
static VALUE scomplex_conj(VALUE self) {
|
|
1846
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1847
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1848
|
-
ndfunc_t ndf = { iter_scomplex_conj, FULL_LOOP, 1, 1, ain, aout };
|
|
1849
|
-
|
|
1850
|
-
return na_ndloop(&ndf, 1, self);
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
static void iter_scomplex_im(na_loop_t* const lp) {
|
|
1854
|
-
size_t i, n;
|
|
1855
|
-
char *p1, *p2;
|
|
1856
|
-
ssize_t s1, s2;
|
|
1857
|
-
size_t *idx1, *idx2;
|
|
1858
|
-
dtype x;
|
|
1859
|
-
|
|
1860
|
-
INIT_COUNTER(lp, n);
|
|
1861
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1862
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1863
|
-
|
|
1864
|
-
if (idx1) {
|
|
1865
|
-
if (idx2) {
|
|
1866
|
-
for (i = 0; i < n; i++) {
|
|
1867
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1868
|
-
x = m_im(x);
|
|
1869
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1870
|
-
}
|
|
1871
|
-
} else {
|
|
1872
|
-
for (i = 0; i < n; i++) {
|
|
1873
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1874
|
-
x = m_im(x);
|
|
1875
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
} else {
|
|
1879
|
-
if (idx2) {
|
|
1880
|
-
for (i = 0; i < n; i++) {
|
|
1881
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1882
|
-
x = m_im(x);
|
|
1883
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
1884
|
-
}
|
|
1885
|
-
} else {
|
|
1886
|
-
//
|
|
1887
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1888
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1889
|
-
for (i = 0; i < n; i++) {
|
|
1890
|
-
((dtype*)p2)[i] = m_im(((dtype*)p1)[i]);
|
|
1891
|
-
}
|
|
1892
|
-
return;
|
|
1893
|
-
}
|
|
1894
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1895
|
-
//
|
|
1896
|
-
for (i = 0; i < n; i++) {
|
|
1897
|
-
*(dtype*)p2 = m_im(*(dtype*)p1);
|
|
1898
|
-
p1 += s1;
|
|
1899
|
-
p2 += s2;
|
|
1900
|
-
}
|
|
1901
|
-
return;
|
|
1902
|
-
//
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
for (i = 0; i < n; i++) {
|
|
1906
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1907
|
-
x = m_im(x);
|
|
1908
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
1909
|
-
}
|
|
1910
|
-
//
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
|
|
1915
|
-
/*
|
|
1916
|
-
Unary im.
|
|
1917
|
-
@overload im
|
|
1918
|
-
@return [Numo::SComplex] im of self.
|
|
1919
|
-
*/
|
|
1920
|
-
static VALUE scomplex_im(VALUE self) {
|
|
1921
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1922
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1923
|
-
ndfunc_t ndf = { iter_scomplex_im, FULL_LOOP, 1, 1, ain, aout };
|
|
1924
|
-
|
|
1925
|
-
return na_ndloop(&ndf, 1, self);
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
|
-
static void iter_scomplex_real(na_loop_t* const lp) {
|
|
1929
|
-
size_t i;
|
|
1930
|
-
char *p1, *p2;
|
|
1931
|
-
ssize_t s1, s2;
|
|
1932
|
-
size_t *idx1, *idx2;
|
|
1933
|
-
dtype x;
|
|
1934
|
-
rtype y;
|
|
1935
|
-
INIT_COUNTER(lp, i);
|
|
1936
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1937
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1938
|
-
if (idx1) {
|
|
1939
|
-
if (idx2) {
|
|
1940
|
-
for (; i--;) {
|
|
1941
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1942
|
-
y = m_real(x);
|
|
1943
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1944
|
-
}
|
|
1945
|
-
} else {
|
|
1946
|
-
for (; i--;) {
|
|
1947
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1948
|
-
y = m_real(x);
|
|
1949
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
} else {
|
|
1953
|
-
if (idx2) {
|
|
1954
|
-
for (; i--;) {
|
|
1955
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1956
|
-
y = m_real(x);
|
|
1957
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1958
|
-
}
|
|
1959
|
-
} else {
|
|
1960
|
-
for (; i--;) {
|
|
1961
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1962
|
-
y = m_real(x);
|
|
1963
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
/*
|
|
1970
|
-
real of self.
|
|
1971
|
-
@overload real
|
|
1972
|
-
@return [Numo::SFloat] real of self.
|
|
1973
|
-
*/
|
|
1974
|
-
static VALUE scomplex_real(VALUE self) {
|
|
1975
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
1976
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
1977
|
-
ndfunc_t ndf = { iter_scomplex_real, FULL_LOOP, 1, 1, ain, aout };
|
|
1978
|
-
|
|
1979
|
-
return na_ndloop(&ndf, 1, self);
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
static void iter_scomplex_imag(na_loop_t* const lp) {
|
|
1983
|
-
size_t i;
|
|
1984
|
-
char *p1, *p2;
|
|
1985
|
-
ssize_t s1, s2;
|
|
1986
|
-
size_t *idx1, *idx2;
|
|
1987
|
-
dtype x;
|
|
1988
|
-
rtype y;
|
|
1989
|
-
INIT_COUNTER(lp, i);
|
|
1990
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1991
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1992
|
-
if (idx1) {
|
|
1993
|
-
if (idx2) {
|
|
1994
|
-
for (; i--;) {
|
|
1995
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1996
|
-
y = m_imag(x);
|
|
1997
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
1998
|
-
}
|
|
1999
|
-
} else {
|
|
2000
|
-
for (; i--;) {
|
|
2001
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2002
|
-
y = m_imag(x);
|
|
2003
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
} else {
|
|
2007
|
-
if (idx2) {
|
|
2008
|
-
for (; i--;) {
|
|
2009
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2010
|
-
y = m_imag(x);
|
|
2011
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2012
|
-
}
|
|
2013
|
-
} else {
|
|
2014
|
-
for (; i--;) {
|
|
2015
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2016
|
-
y = m_imag(x);
|
|
2017
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
/*
|
|
2024
|
-
imag of self.
|
|
2025
|
-
@overload imag
|
|
2026
|
-
@return [Numo::SFloat] imag of self.
|
|
2027
|
-
*/
|
|
2028
|
-
static VALUE scomplex_imag(VALUE self) {
|
|
2029
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2030
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
2031
|
-
ndfunc_t ndf = { iter_scomplex_imag, FULL_LOOP, 1, 1, ain, aout };
|
|
2032
|
-
|
|
2033
|
-
return na_ndloop(&ndf, 1, self);
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
|
-
static void iter_scomplex_arg(na_loop_t* const lp) {
|
|
2037
|
-
size_t i;
|
|
2038
|
-
char *p1, *p2;
|
|
2039
|
-
ssize_t s1, s2;
|
|
2040
|
-
size_t *idx1, *idx2;
|
|
2041
|
-
dtype x;
|
|
2042
|
-
rtype y;
|
|
2043
|
-
INIT_COUNTER(lp, i);
|
|
2044
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2045
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2046
|
-
if (idx1) {
|
|
2047
|
-
if (idx2) {
|
|
2048
|
-
for (; i--;) {
|
|
2049
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2050
|
-
y = m_arg(x);
|
|
2051
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2052
|
-
}
|
|
2053
|
-
} else {
|
|
2054
|
-
for (; i--;) {
|
|
2055
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2056
|
-
y = m_arg(x);
|
|
2057
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
} else {
|
|
2061
|
-
if (idx2) {
|
|
2062
|
-
for (; i--;) {
|
|
2063
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2064
|
-
y = m_arg(x);
|
|
2065
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2066
|
-
}
|
|
2067
|
-
} else {
|
|
2068
|
-
for (; i--;) {
|
|
2069
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2070
|
-
y = m_arg(x);
|
|
2071
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
/*
|
|
2078
|
-
arg of self.
|
|
2079
|
-
@overload arg
|
|
2080
|
-
@return [Numo::SFloat] arg of self.
|
|
2081
|
-
*/
|
|
2082
|
-
static VALUE scomplex_arg(VALUE self) {
|
|
2083
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2084
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
2085
|
-
ndfunc_t ndf = { iter_scomplex_arg, FULL_LOOP, 1, 1, ain, aout };
|
|
2086
|
-
|
|
2087
|
-
return na_ndloop(&ndf, 1, self);
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
static void iter_scomplex_set_imag(na_loop_t* const lp) {
|
|
2091
|
-
size_t i;
|
|
2092
|
-
char *p1, *p2;
|
|
2093
|
-
ssize_t s1, s2;
|
|
2094
|
-
size_t *idx1, *idx2;
|
|
2095
|
-
dtype x;
|
|
2096
|
-
rtype y;
|
|
2097
|
-
INIT_COUNTER(lp, i);
|
|
2098
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2099
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2100
|
-
if (idx1) {
|
|
2101
|
-
if (idx2) {
|
|
2102
|
-
for (; i--;) {
|
|
2103
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
2104
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2105
|
-
x = m_set_imag(x, y);
|
|
2106
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2107
|
-
}
|
|
2108
|
-
} else {
|
|
2109
|
-
for (; i--;) {
|
|
2110
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
2111
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2112
|
-
x = m_set_imag(x, y);
|
|
2113
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
} else {
|
|
2117
|
-
if (idx2) {
|
|
2118
|
-
for (; i--;) {
|
|
2119
|
-
GET_DATA(p1, dtype, x);
|
|
2120
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2121
|
-
x = m_set_imag(x, y);
|
|
2122
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2123
|
-
}
|
|
2124
|
-
} else {
|
|
2125
|
-
for (; i--;) {
|
|
2126
|
-
GET_DATA(p1, dtype, x);
|
|
2127
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2128
|
-
x = m_set_imag(x, y);
|
|
2129
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
static VALUE scomplex_set_imag(VALUE self, VALUE a1) {
|
|
2136
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
|
|
2137
|
-
ndfunc_t ndf = { iter_scomplex_set_imag, FULL_LOOP, 2, 0, ain, 0 };
|
|
2138
|
-
|
|
2139
|
-
na_ndloop(&ndf, 2, self, a1);
|
|
2140
|
-
return a1;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
static void iter_scomplex_set_real(na_loop_t* const lp) {
|
|
2144
|
-
size_t i;
|
|
2145
|
-
char *p1, *p2;
|
|
2146
|
-
ssize_t s1, s2;
|
|
2147
|
-
size_t *idx1, *idx2;
|
|
2148
|
-
dtype x;
|
|
2149
|
-
rtype y;
|
|
2150
|
-
INIT_COUNTER(lp, i);
|
|
2151
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2152
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2153
|
-
if (idx1) {
|
|
2154
|
-
if (idx2) {
|
|
2155
|
-
for (; i--;) {
|
|
2156
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
2157
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2158
|
-
x = m_set_real(x, y);
|
|
2159
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2160
|
-
}
|
|
2161
|
-
} else {
|
|
2162
|
-
for (; i--;) {
|
|
2163
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
2164
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2165
|
-
x = m_set_real(x, y);
|
|
2166
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
} else {
|
|
2170
|
-
if (idx2) {
|
|
2171
|
-
for (; i--;) {
|
|
2172
|
-
GET_DATA(p1, dtype, x);
|
|
2173
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2174
|
-
x = m_set_real(x, y);
|
|
2175
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2176
|
-
}
|
|
2177
|
-
} else {
|
|
2178
|
-
for (; i--;) {
|
|
2179
|
-
GET_DATA(p1, dtype, x);
|
|
2180
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2181
|
-
x = m_set_real(x, y);
|
|
2182
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
static VALUE scomplex_set_real(VALUE self, VALUE a1) {
|
|
2189
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
|
|
2190
|
-
ndfunc_t ndf = { iter_scomplex_set_real, FULL_LOOP, 2, 0, ain, 0 };
|
|
2191
|
-
|
|
2192
|
-
na_ndloop(&ndf, 2, self, a1);
|
|
2193
|
-
return a1;
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
#define check_intdivzero(y) \
|
|
2197
|
-
{}
|
|
2198
|
-
|
|
2199
|
-
static void iter_scomplex_copysign(na_loop_t* const lp) {
|
|
2200
|
-
size_t i = 0;
|
|
2201
|
-
size_t n;
|
|
2202
|
-
char *p1, *p2, *p3;
|
|
2203
|
-
ssize_t s1, s2, s3;
|
|
2204
|
-
|
|
2205
|
-
INIT_COUNTER(lp, n);
|
|
2206
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2207
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2208
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2209
|
-
|
|
2210
|
-
//
|
|
2211
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2212
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
2213
|
-
|
|
2214
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2215
|
-
if (p1 == p3) { // inplace case
|
|
2216
|
-
for (; i < n; i++) {
|
|
2217
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2218
|
-
((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2219
|
-
}
|
|
2220
|
-
} else {
|
|
2221
|
-
for (; i < n; i++) {
|
|
2222
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2223
|
-
((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
return;
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2230
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2231
|
-
//
|
|
2232
|
-
|
|
2233
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2234
|
-
check_intdivzero(*(dtype*)p2);
|
|
2235
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2236
|
-
if (p1 == p3) { // inplace case
|
|
2237
|
-
for (; i < n; i++) {
|
|
2238
|
-
((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
|
|
2239
|
-
}
|
|
2240
|
-
} else {
|
|
2241
|
-
for (; i < n; i++) {
|
|
2242
|
-
((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
} else {
|
|
2246
|
-
for (i = 0; i < n; i++) {
|
|
2247
|
-
*(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
|
|
2248
|
-
p1 += s1;
|
|
2249
|
-
p3 += s3;
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
} else {
|
|
2253
|
-
if (p1 == p3) { // inplace case
|
|
2254
|
-
for (i = 0; i < n; i++) {
|
|
2255
|
-
check_intdivzero(*(dtype*)p2);
|
|
2256
|
-
*(dtype*)p1 = m_copysign(*(dtype*)p1, *(dtype*)p2);
|
|
2257
|
-
p1 += s1;
|
|
2258
|
-
p2 += s2;
|
|
2259
|
-
}
|
|
2260
|
-
} else {
|
|
2261
|
-
for (i = 0; i < n; i++) {
|
|
2262
|
-
check_intdivzero(*(dtype*)p2);
|
|
2263
|
-
*(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
|
|
2264
|
-
p1 += s1;
|
|
2265
|
-
p2 += s2;
|
|
2266
|
-
p3 += s3;
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
|
|
2271
|
-
return;
|
|
2272
|
-
//
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
for (i = 0; i < n; i++) {
|
|
2276
|
-
dtype x, y, z;
|
|
2277
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2278
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2279
|
-
check_intdivzero(y);
|
|
2280
|
-
z = m_copysign(x, y);
|
|
2281
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2282
|
-
}
|
|
2283
|
-
//
|
|
2284
|
-
}
|
|
2285
|
-
#undef check_intdivzero
|
|
2286
|
-
|
|
2287
|
-
static VALUE scomplex_copysign_self(VALUE self, VALUE other) {
|
|
2288
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2289
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2290
|
-
ndfunc_t ndf = { iter_scomplex_copysign, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2291
|
-
|
|
2292
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
|
-
/*
|
|
2296
|
-
Binary copysign.
|
|
2297
|
-
@overload copysign other
|
|
2298
|
-
@param [Numo::NArray,Numeric] other
|
|
2299
|
-
@return [Numo::NArray] self copysign other
|
|
2300
|
-
*/
|
|
2301
|
-
static VALUE scomplex_copysign(VALUE self, VALUE other) {
|
|
2302
|
-
|
|
2303
|
-
VALUE klass, v;
|
|
2304
|
-
|
|
2305
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2306
|
-
if (klass == cT) {
|
|
2307
|
-
return scomplex_copysign_self(self, other);
|
|
2308
|
-
} else {
|
|
2309
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2310
|
-
return rb_funcall(v, id_copysign, 1, other);
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
static void iter_scomplex_poly(na_loop_t* const lp) {
|
|
2315
|
-
size_t i;
|
|
2316
|
-
dtype x, y, a;
|
|
2317
|
-
|
|
2318
|
-
x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
|
|
2319
|
-
i = lp->narg - 2;
|
|
2320
|
-
y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
2321
|
-
for (; --i;) {
|
|
2322
|
-
y = m_mul(x, y);
|
|
2323
|
-
a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
2324
|
-
y = m_add(y, a);
|
|
2325
|
-
}
|
|
2326
|
-
i = lp->narg - 1;
|
|
2327
|
-
*(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
|
|
2328
|
-
}
|
|
2329
|
-
|
|
2330
|
-
/*
|
|
2331
|
-
Calculate polynomial.
|
|
2332
|
-
`x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
2333
|
-
@overload poly a0, a1, ..., an
|
|
2334
|
-
@param [Numo::NArray,Numeric] a0,a1,...,an
|
|
2335
|
-
@return [Numo::SComplex]
|
|
2336
|
-
*/
|
|
2337
|
-
static VALUE scomplex_poly(VALUE self, VALUE args) {
|
|
2338
|
-
int argc, i;
|
|
2339
|
-
VALUE* argv;
|
|
2340
|
-
volatile VALUE v, a;
|
|
2341
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2342
|
-
ndfunc_t ndf = { iter_scomplex_poly, NO_LOOP, 0, 1, 0, aout };
|
|
2343
|
-
|
|
2344
|
-
argc = (int)RARRAY_LEN(args);
|
|
2345
|
-
ndf.nin = argc + 1;
|
|
2346
|
-
ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
|
|
2347
|
-
for (i = 0; i < argc + 1; i++) {
|
|
2348
|
-
ndf.ain[i].type = cT;
|
|
2349
|
-
}
|
|
2350
|
-
argv = ALLOCA_N(VALUE, argc + 1);
|
|
2351
|
-
argv[0] = self;
|
|
2352
|
-
for (i = 0; i < argc; i++) {
|
|
2353
|
-
argv[i + 1] = RARRAY_PTR(args)[i];
|
|
2354
|
-
}
|
|
2355
|
-
a = rb_ary_new4(argc + 1, argv);
|
|
2356
|
-
v = na_ndloop2(&ndf, a);
|
|
2357
|
-
return scomplex_extract(v);
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
1439
|
VALUE mTM;
|
|
2361
1440
|
|
|
2362
1441
|
void Init_numo_scomplex(void) {
|
|
@@ -2427,11 +1506,27 @@ void Init_numo_scomplex(void) {
|
|
|
2427
1506
|
rb_define_const(cT, "MIN", M_MIN);
|
|
2428
1507
|
rb_define_alloc_func(cT, scomplex_s_alloc_func);
|
|
2429
1508
|
rb_define_method(cT, "allocate", scomplex_allocate, 0);
|
|
1509
|
+
/**
|
|
1510
|
+
* Extract an element only if self is a dimensionless NArray.
|
|
1511
|
+
* @overload extract
|
|
1512
|
+
* @return [Numeric,Numo::NArray]
|
|
1513
|
+
* --- Extract element value as Ruby Object if self is a dimensionless NArray,
|
|
1514
|
+
* otherwise returns self.
|
|
1515
|
+
*/
|
|
2430
1516
|
rb_define_method(cT, "extract", scomplex_extract, 0);
|
|
2431
1517
|
|
|
2432
1518
|
rb_define_method(cT, "store", scomplex_store, 1);
|
|
2433
1519
|
|
|
2434
1520
|
rb_define_singleton_method(cT, "cast", scomplex_s_cast, 1);
|
|
1521
|
+
/**
|
|
1522
|
+
* Multi-dimensional element reference.
|
|
1523
|
+
* @overload [](dim0,...,dimL)
|
|
1524
|
+
* @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,
|
|
1525
|
+
* Symbol] dim0,...,dimL multi-dimensional indices.
|
|
1526
|
+
* @return [Numeric,Numo::SComplex] an element or NArray view.
|
|
1527
|
+
* @see Numo::NArray#[]
|
|
1528
|
+
* @see #[]=
|
|
1529
|
+
*/
|
|
2435
1530
|
rb_define_method(cT, "[]", scomplex_aref, -1);
|
|
2436
1531
|
rb_define_method(cT, "[]=", scomplex_aset, -1);
|
|
2437
1532
|
/**
|
|
@@ -2473,10 +1568,54 @@ void Init_numo_scomplex(void) {
|
|
|
2473
1568
|
* @return [String]
|
|
2474
1569
|
*/
|
|
2475
1570
|
rb_define_method(cT, "inspect", scomplex_inspect, 0);
|
|
1571
|
+
/**
|
|
1572
|
+
* Calls the given block once for each element in self,
|
|
1573
|
+
* passing that element as a parameter.
|
|
1574
|
+
* @overload each
|
|
1575
|
+
* @return [Numo::NArray] self
|
|
1576
|
+
* For a block `{|x| ... }`,
|
|
1577
|
+
* @yieldparam [Numeric] x an element of NArray.
|
|
1578
|
+
* @see #each_with_index
|
|
1579
|
+
* @see #map
|
|
1580
|
+
*/
|
|
2476
1581
|
rb_define_method(cT, "each", scomplex_each, 0);
|
|
1582
|
+
/**
|
|
1583
|
+
* Unary map.
|
|
1584
|
+
* @overload map
|
|
1585
|
+
* @return [Numo::SComplex] map of self.
|
|
1586
|
+
*/
|
|
2477
1587
|
rb_define_method(cT, "map", scomplex_map, 0);
|
|
1588
|
+
/**
|
|
1589
|
+
* Invokes the given block once for each element of self,
|
|
1590
|
+
* passing that element and indices along each axis as parameters.
|
|
1591
|
+
* @overload each_with_index
|
|
1592
|
+
* For a block `{|x,i,j,...| ... }`,
|
|
1593
|
+
* @yieldparam [Numeric] x an element
|
|
1594
|
+
* @yieldparam [Integer] i,j,... multitimensional indices
|
|
1595
|
+
* @return [Numo::NArray] self
|
|
1596
|
+
* @see #each
|
|
1597
|
+
* @see #map_with_index
|
|
1598
|
+
*/
|
|
2478
1599
|
rb_define_method(cT, "each_with_index", scomplex_each_with_index, 0);
|
|
1600
|
+
/**
|
|
1601
|
+
* Invokes the given block once for each element of self,
|
|
1602
|
+
* passing that element and indices along each axis as parameters.
|
|
1603
|
+
* Creates a new NArray containing the values returned by the block.
|
|
1604
|
+
* Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
|
1605
|
+
* @overload map_with_index
|
|
1606
|
+
* For a block `{|x,i,j,...| ... }`,
|
|
1607
|
+
* @yieldparam [Numeric] x an element
|
|
1608
|
+
* @yieldparam [Integer] i,j,... multitimensional indices
|
|
1609
|
+
* @return [Numo::NArray] mapped array
|
|
1610
|
+
* @see #map
|
|
1611
|
+
* @see #each_with_index
|
|
1612
|
+
*/
|
|
2479
1613
|
rb_define_method(cT, "map_with_index", scomplex_map_with_index, 0);
|
|
1614
|
+
/**
|
|
1615
|
+
* abs of self.
|
|
1616
|
+
* @overload abs
|
|
1617
|
+
* @return [Numo::SFloat] abs of self.
|
|
1618
|
+
*/
|
|
2480
1619
|
rb_define_method(cT, "abs", scomplex_abs, 0);
|
|
2481
1620
|
/**
|
|
2482
1621
|
* Binary add.
|
|
@@ -2538,10 +1677,35 @@ void Init_numo_scomplex(void) {
|
|
|
2538
1677
|
* @return [Numo::SComplex] square of self.
|
|
2539
1678
|
*/
|
|
2540
1679
|
rb_define_method(cT, "square", scomplex_square, 0);
|
|
1680
|
+
/**
|
|
1681
|
+
* Unary conj.
|
|
1682
|
+
* @overload conj
|
|
1683
|
+
* @return [Numo::SComplex] conj of self.
|
|
1684
|
+
*/
|
|
2541
1685
|
rb_define_method(cT, "conj", scomplex_conj, 0);
|
|
1686
|
+
/**
|
|
1687
|
+
* Unary im.
|
|
1688
|
+
* @overload im
|
|
1689
|
+
* @return [Numo::SComplex] im of self.
|
|
1690
|
+
*/
|
|
2542
1691
|
rb_define_method(cT, "im", scomplex_im, 0);
|
|
1692
|
+
/**
|
|
1693
|
+
* real of self.
|
|
1694
|
+
* @overload real
|
|
1695
|
+
* @return [Numo::SFloat] real of self.
|
|
1696
|
+
*/
|
|
2543
1697
|
rb_define_method(cT, "real", scomplex_real, 0);
|
|
1698
|
+
/**
|
|
1699
|
+
* imag of self.
|
|
1700
|
+
* @overload imag
|
|
1701
|
+
* @return [Numo::SFloat] imag of self.
|
|
1702
|
+
*/
|
|
2544
1703
|
rb_define_method(cT, "imag", scomplex_imag, 0);
|
|
1704
|
+
/**
|
|
1705
|
+
* arg of self.
|
|
1706
|
+
* @overload arg
|
|
1707
|
+
* @return [Numo::SFloat] arg of self.
|
|
1708
|
+
*/
|
|
2545
1709
|
rb_define_method(cT, "arg", scomplex_arg, 0);
|
|
2546
1710
|
rb_define_alias(cT, "angle", "arg");
|
|
2547
1711
|
rb_define_method(cT, "set_imag", scomplex_set_imag, 1);
|
|
@@ -2601,6 +1765,12 @@ void Init_numo_scomplex(void) {
|
|
|
2601
1765
|
* @return [Numo::SComplex] rint of self.
|
|
2602
1766
|
*/
|
|
2603
1767
|
rb_define_method(cT, "rint", scomplex_rint, 0);
|
|
1768
|
+
/**
|
|
1769
|
+
* Binary copysign.
|
|
1770
|
+
* @overload copysign other
|
|
1771
|
+
* @param [Numo::NArray,Numeric] other
|
|
1772
|
+
* @return [Numo::NArray] self copysign other
|
|
1773
|
+
*/
|
|
2604
1774
|
rb_define_method(cT, "copysign", scomplex_copysign, 1);
|
|
2605
1775
|
/**
|
|
2606
1776
|
* Condition of isnan.
|
|
@@ -2809,6 +1979,13 @@ void Init_numo_scomplex(void) {
|
|
|
2809
1979
|
* @return [Numo::SComplex] self.
|
|
2810
1980
|
*/
|
|
2811
1981
|
rb_define_method(cT, "rand_norm", scomplex_rand_norm, -1);
|
|
1982
|
+
/**
|
|
1983
|
+
* Calculate polynomial.
|
|
1984
|
+
* `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
1985
|
+
* @overload poly a0, a1, ..., an
|
|
1986
|
+
* @param [Numo::NArray,Numeric] a0,a1,...,an
|
|
1987
|
+
* @return [Numo::SComplex]
|
|
1988
|
+
*/
|
|
2812
1989
|
rb_define_method(cT, "poly", scomplex_poly, -2);
|
|
2813
1990
|
rb_define_singleton_method(cT, "[]", scomplex_s_cast, -2);
|
|
2814
1991
|
|