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"
|
|
@@ -68,6 +83,7 @@ extern VALUE cRT;
|
|
|
68
83
|
#include "mh/isfinite.h"
|
|
69
84
|
#include "mh/sum.h"
|
|
70
85
|
#include "mh/prod.h"
|
|
86
|
+
#include "mh/kahan_sum.h"
|
|
71
87
|
#include "mh/mean.h"
|
|
72
88
|
#include "mh/var.h"
|
|
73
89
|
#include "mh/stddev.h"
|
|
@@ -80,6 +96,7 @@ extern VALUE cRT;
|
|
|
80
96
|
#include "mh/eye.h"
|
|
81
97
|
#include "mh/rand.h"
|
|
82
98
|
#include "mh/rand_norm.h"
|
|
99
|
+
#include "mh/poly.h"
|
|
83
100
|
#include "mh/math/sqrt.h"
|
|
84
101
|
#include "mh/math/cbrt.h"
|
|
85
102
|
#include "mh/math/log.h"
|
|
@@ -102,12 +119,19 @@ extern VALUE cRT;
|
|
|
102
119
|
#include "mh/math/atanh.h"
|
|
103
120
|
#include "mh/math/sinc.h"
|
|
104
121
|
|
|
122
|
+
DEF_NARRAY_EXTRACT_METHOD_FUNC(dcomplex)
|
|
123
|
+
DEF_NARRAY_AREF_METHOD_FUNC(dcomplex)
|
|
105
124
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(dcomplex)
|
|
106
125
|
DEF_NARRAY_TO_A_METHOD_FUNC(dcomplex)
|
|
107
126
|
DEF_NARRAY_FILL_METHOD_FUNC(dcomplex)
|
|
108
127
|
DEF_NARRAY_FORMAT_METHOD_FUNC(dcomplex)
|
|
109
128
|
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(dcomplex)
|
|
110
129
|
DEF_NARRAY_INSPECT_METHOD_FUNC(dcomplex)
|
|
130
|
+
DEF_NARRAY_EACH_METHOD_FUNC(dcomplex)
|
|
131
|
+
DEF_NARRAY_MAP_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
132
|
+
DEF_NARRAY_EACH_WITH_INDEX_METHOD_FUNC(dcomplex)
|
|
133
|
+
DEF_NARRAY_MAP_WITH_INDEX_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
134
|
+
DEF_NARRAY_ABS_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
111
135
|
DEF_NARRAY_ADD_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
112
136
|
DEF_NARRAY_SUB_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
113
137
|
DEF_NARRAY_MUL_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
@@ -117,6 +141,13 @@ DEF_NARRAY_MINUS_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
|
117
141
|
DEF_NARRAY_RECIPROCAL_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
118
142
|
DEF_NARRAY_SIGN_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
119
143
|
DEF_NARRAY_SQUARE_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
144
|
+
DEF_NARRAY_CONJ_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
145
|
+
DEF_NARRAY_IM_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
146
|
+
DEF_NARRAY_REAL_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
147
|
+
DEF_NARRAY_IMAG_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
148
|
+
DEF_NARRAY_ARG_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
149
|
+
DEF_NARRAY_SET_IMAG_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
150
|
+
DEF_NARRAY_SET_REAL_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
120
151
|
DEF_NARRAY_EQ_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
121
152
|
DEF_NARRAY_NE_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
122
153
|
DEF_NARRAY_NEARLY_EQ_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
@@ -125,6 +156,7 @@ DEF_NARRAY_FLT_ROUND_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
|
125
156
|
DEF_NARRAY_FLT_CEIL_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
126
157
|
DEF_NARRAY_FLT_TRUNC_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
127
158
|
DEF_NARRAY_FLT_RINT_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
159
|
+
DEF_NARRAY_COPYSIGN_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
128
160
|
DEF_NARRAY_FLT_ISNAN_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
129
161
|
DEF_NARRAY_FLT_ISINF_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
130
162
|
DEF_NARRAY_FLT_ISPOSINF_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
@@ -132,6 +164,7 @@ DEF_NARRAY_FLT_ISNEGINF_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
|
132
164
|
DEF_NARRAY_FLT_ISFINITE_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
133
165
|
DEF_NARRAY_FLT_SUM_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
134
166
|
DEF_NARRAY_FLT_PROD_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
167
|
+
DEF_NARRAY_KAHAN_SUM_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
135
168
|
DEF_NARRAY_FLT_MEAN_METHOD_FUNC(dcomplex, numo_cDComplex, dcomplex, numo_cDComplex)
|
|
136
169
|
DEF_NARRAY_FLT_VAR_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
137
170
|
DEF_NARRAY_FLT_STDDEV_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
@@ -144,6 +177,7 @@ DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(dcomplex)
|
|
|
144
177
|
DEF_NARRAY_EYE_METHOD_FUNC(dcomplex)
|
|
145
178
|
DEF_NARRAY_CMP_RAND_METHOD_FUNC(dcomplex)
|
|
146
179
|
DEF_NARRAY_CMP_RAND_NORM_METHOD_FUNC(dcomplex, double)
|
|
180
|
+
DEF_NARRAY_POLY_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
147
181
|
DEF_NARRAY_FLT_SQRT_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
148
182
|
DEF_NARRAY_FLT_CBRT_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
149
183
|
DEF_NARRAY_FLT_LOG_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
@@ -269,28 +303,6 @@ static VALUE dcomplex_allocate(VALUE self) {
|
|
|
269
303
|
return self;
|
|
270
304
|
}
|
|
271
305
|
|
|
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 dcomplex_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
306
|
static VALUE dcomplex_new_dim0(dtype x) {
|
|
295
307
|
VALUE v;
|
|
296
308
|
dtype* ptr;
|
|
@@ -1392,29 +1404,6 @@ static VALUE dcomplex_s_cast(VALUE type, VALUE obj) {
|
|
|
1392
1404
|
return Qnil;
|
|
1393
1405
|
}
|
|
1394
1406
|
|
|
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::DComplex] an element or NArray view.
|
|
1401
|
-
@see Numo::NArray#[]
|
|
1402
|
-
@see #[]=
|
|
1403
|
-
*/
|
|
1404
|
-
static VALUE dcomplex_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
1407
|
/*
|
|
1419
1408
|
Multi-dimensional element assignment.
|
|
1420
1409
|
@overload []=(dim0,...,dimL,val)
|
|
@@ -1449,962 +1438,6 @@ static VALUE dcomplex_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1449
1438
|
return argv[argc];
|
|
1450
1439
|
}
|
|
1451
1440
|
|
|
1452
|
-
static void iter_dcomplex_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 dcomplex_each(VALUE self) {
|
|
1487
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1488
|
-
ndfunc_t ndf = { iter_dcomplex_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
|
|
1489
|
-
|
|
1490
|
-
na_ndloop(&ndf, 1, self);
|
|
1491
|
-
return self;
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
static void iter_dcomplex_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::DComplex] map of self.
|
|
1560
|
-
*/
|
|
1561
|
-
static VALUE dcomplex_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_dcomplex_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_dcomplex_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 dcomplex_each_with_index(VALUE self) {
|
|
1626
|
-
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
|
1627
|
-
ndfunc_t ndf = { iter_dcomplex_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_dcomplex_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 dcomplex_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_dcomplex_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_dcomplex_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::DFloat] abs of self.
|
|
1769
|
-
*/
|
|
1770
|
-
static VALUE dcomplex_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_dcomplex_abs, FULL_LOOP, 1, 1, ain, aout };
|
|
1774
|
-
|
|
1775
|
-
return na_ndloop(&ndf, 1, self);
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
static void iter_dcomplex_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::DComplex] conj of self.
|
|
1844
|
-
*/
|
|
1845
|
-
static VALUE dcomplex_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_dcomplex_conj, FULL_LOOP, 1, 1, ain, aout };
|
|
1849
|
-
|
|
1850
|
-
return na_ndloop(&ndf, 1, self);
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
static void iter_dcomplex_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::DComplex] im of self.
|
|
1919
|
-
*/
|
|
1920
|
-
static VALUE dcomplex_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_dcomplex_im, FULL_LOOP, 1, 1, ain, aout };
|
|
1924
|
-
|
|
1925
|
-
return na_ndloop(&ndf, 1, self);
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
|
-
static void iter_dcomplex_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::DFloat] real of self.
|
|
1973
|
-
*/
|
|
1974
|
-
static VALUE dcomplex_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_dcomplex_real, FULL_LOOP, 1, 1, ain, aout };
|
|
1978
|
-
|
|
1979
|
-
return na_ndloop(&ndf, 1, self);
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
static void iter_dcomplex_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::DFloat] imag of self.
|
|
2027
|
-
*/
|
|
2028
|
-
static VALUE dcomplex_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_dcomplex_imag, FULL_LOOP, 1, 1, ain, aout };
|
|
2032
|
-
|
|
2033
|
-
return na_ndloop(&ndf, 1, self);
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
|
-
static void iter_dcomplex_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::DFloat] arg of self.
|
|
2081
|
-
*/
|
|
2082
|
-
static VALUE dcomplex_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_dcomplex_arg, FULL_LOOP, 1, 1, ain, aout };
|
|
2086
|
-
|
|
2087
|
-
return na_ndloop(&ndf, 1, self);
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
static void iter_dcomplex_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 dcomplex_set_imag(VALUE self, VALUE a1) {
|
|
2136
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
|
|
2137
|
-
ndfunc_t ndf = { iter_dcomplex_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_dcomplex_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 dcomplex_set_real(VALUE self, VALUE a1) {
|
|
2189
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
|
|
2190
|
-
ndfunc_t ndf = { iter_dcomplex_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_dcomplex_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 dcomplex_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_dcomplex_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 dcomplex_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 dcomplex_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_dcomplex_kahan_sum(na_loop_t* const lp) {
|
|
2315
|
-
size_t n;
|
|
2316
|
-
char *p1, *p2;
|
|
2317
|
-
ssize_t s1;
|
|
2318
|
-
|
|
2319
|
-
INIT_COUNTER(lp, n);
|
|
2320
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2321
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
2322
|
-
|
|
2323
|
-
*(dtype*)p2 = f_kahan_sum(n, p1, s1);
|
|
2324
|
-
}
|
|
2325
|
-
static void iter_dcomplex_kahan_sum_nan(na_loop_t* const lp) {
|
|
2326
|
-
size_t n;
|
|
2327
|
-
char *p1, *p2;
|
|
2328
|
-
ssize_t s1;
|
|
2329
|
-
|
|
2330
|
-
INIT_COUNTER(lp, n);
|
|
2331
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2332
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
2333
|
-
|
|
2334
|
-
*(dtype*)p2 = f_kahan_sum_nan(n, p1, s1);
|
|
2335
|
-
}
|
|
2336
|
-
|
|
2337
|
-
/*
|
|
2338
|
-
kahan_sum of self.
|
|
2339
|
-
@overload kahan_sum(axis:nil, keepdims:false, nan:false)
|
|
2340
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
2341
|
-
return NaN for min/max etc).
|
|
2342
|
-
@param [Numeric,Array,Range] axis Performs kahan_sum along the axis.
|
|
2343
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
2344
|
-
dimensions with size one.
|
|
2345
|
-
@return [Numo::DComplex] returns result of kahan_sum.
|
|
2346
|
-
*/
|
|
2347
|
-
static VALUE dcomplex_kahan_sum(int argc, VALUE* argv, VALUE self) {
|
|
2348
|
-
VALUE v, reduce;
|
|
2349
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
2350
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2351
|
-
ndfunc_t ndf = {
|
|
2352
|
-
iter_dcomplex_kahan_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout
|
|
2353
|
-
};
|
|
2354
|
-
|
|
2355
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_dcomplex_kahan_sum_nan);
|
|
2356
|
-
|
|
2357
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
2358
|
-
|
|
2359
|
-
return dcomplex_extract(v);
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
static void iter_dcomplex_poly(na_loop_t* const lp) {
|
|
2363
|
-
size_t i;
|
|
2364
|
-
dtype x, y, a;
|
|
2365
|
-
|
|
2366
|
-
x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
|
|
2367
|
-
i = lp->narg - 2;
|
|
2368
|
-
y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
2369
|
-
for (; --i;) {
|
|
2370
|
-
y = m_mul(x, y);
|
|
2371
|
-
a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
|
|
2372
|
-
y = m_add(y, a);
|
|
2373
|
-
}
|
|
2374
|
-
i = lp->narg - 1;
|
|
2375
|
-
*(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
|
|
2376
|
-
}
|
|
2377
|
-
|
|
2378
|
-
/*
|
|
2379
|
-
Calculate polynomial.
|
|
2380
|
-
`x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
2381
|
-
@overload poly a0, a1, ..., an
|
|
2382
|
-
@param [Numo::NArray,Numeric] a0,a1,...,an
|
|
2383
|
-
@return [Numo::DComplex]
|
|
2384
|
-
*/
|
|
2385
|
-
static VALUE dcomplex_poly(VALUE self, VALUE args) {
|
|
2386
|
-
int argc, i;
|
|
2387
|
-
VALUE* argv;
|
|
2388
|
-
volatile VALUE v, a;
|
|
2389
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2390
|
-
ndfunc_t ndf = { iter_dcomplex_poly, NO_LOOP, 0, 1, 0, aout };
|
|
2391
|
-
|
|
2392
|
-
argc = (int)RARRAY_LEN(args);
|
|
2393
|
-
ndf.nin = argc + 1;
|
|
2394
|
-
ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
|
|
2395
|
-
for (i = 0; i < argc + 1; i++) {
|
|
2396
|
-
ndf.ain[i].type = cT;
|
|
2397
|
-
}
|
|
2398
|
-
argv = ALLOCA_N(VALUE, argc + 1);
|
|
2399
|
-
argv[0] = self;
|
|
2400
|
-
for (i = 0; i < argc; i++) {
|
|
2401
|
-
argv[i + 1] = RARRAY_PTR(args)[i];
|
|
2402
|
-
}
|
|
2403
|
-
a = rb_ary_new4(argc + 1, argv);
|
|
2404
|
-
v = na_ndloop2(&ndf, a);
|
|
2405
|
-
return dcomplex_extract(v);
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
1441
|
VALUE mTM;
|
|
2409
1442
|
|
|
2410
1443
|
void Init_numo_dcomplex(void) {
|
|
@@ -2475,11 +1508,27 @@ void Init_numo_dcomplex(void) {
|
|
|
2475
1508
|
rb_define_const(cT, "MIN", M_MIN);
|
|
2476
1509
|
rb_define_alloc_func(cT, dcomplex_s_alloc_func);
|
|
2477
1510
|
rb_define_method(cT, "allocate", dcomplex_allocate, 0);
|
|
1511
|
+
/**
|
|
1512
|
+
* Extract an element only if self is a dimensionless NArray.
|
|
1513
|
+
* @overload extract
|
|
1514
|
+
* @return [Numeric,Numo::NArray]
|
|
1515
|
+
* --- Extract element value as Ruby Object if self is a dimensionless NArray,
|
|
1516
|
+
* otherwise returns self.
|
|
1517
|
+
*/
|
|
2478
1518
|
rb_define_method(cT, "extract", dcomplex_extract, 0);
|
|
2479
1519
|
|
|
2480
1520
|
rb_define_method(cT, "store", dcomplex_store, 1);
|
|
2481
1521
|
|
|
2482
1522
|
rb_define_singleton_method(cT, "cast", dcomplex_s_cast, 1);
|
|
1523
|
+
/**
|
|
1524
|
+
* Multi-dimensional element reference.
|
|
1525
|
+
* @overload [](dim0,...,dimL)
|
|
1526
|
+
* @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,
|
|
1527
|
+
* Symbol] dim0,...,dimL multi-dimensional indices.
|
|
1528
|
+
* @return [Numeric,Numo::DComplex] an element or NArray view.
|
|
1529
|
+
* @see Numo::NArray#[]
|
|
1530
|
+
* @see #[]=
|
|
1531
|
+
*/
|
|
2483
1532
|
rb_define_method(cT, "[]", dcomplex_aref, -1);
|
|
2484
1533
|
rb_define_method(cT, "[]=", dcomplex_aset, -1);
|
|
2485
1534
|
/**
|
|
@@ -2521,10 +1570,54 @@ void Init_numo_dcomplex(void) {
|
|
|
2521
1570
|
* @return [String]
|
|
2522
1571
|
*/
|
|
2523
1572
|
rb_define_method(cT, "inspect", dcomplex_inspect, 0);
|
|
1573
|
+
/**
|
|
1574
|
+
* Calls the given block once for each element in self,
|
|
1575
|
+
* passing that element as a parameter.
|
|
1576
|
+
* @overload each
|
|
1577
|
+
* @return [Numo::NArray] self
|
|
1578
|
+
* For a block `{|x| ... }`,
|
|
1579
|
+
* @yieldparam [Numeric] x an element of NArray.
|
|
1580
|
+
* @see #each_with_index
|
|
1581
|
+
* @see #map
|
|
1582
|
+
*/
|
|
2524
1583
|
rb_define_method(cT, "each", dcomplex_each, 0);
|
|
1584
|
+
/**
|
|
1585
|
+
* Unary map.
|
|
1586
|
+
* @overload map
|
|
1587
|
+
* @return [Numo::DComplex] map of self.
|
|
1588
|
+
*/
|
|
2525
1589
|
rb_define_method(cT, "map", dcomplex_map, 0);
|
|
1590
|
+
/**
|
|
1591
|
+
* Invokes the given block once for each element of self,
|
|
1592
|
+
* passing that element and indices along each axis as parameters.
|
|
1593
|
+
* @overload each_with_index
|
|
1594
|
+
* For a block `{|x,i,j,...| ... }`,
|
|
1595
|
+
* @yieldparam [Numeric] x an element
|
|
1596
|
+
* @yieldparam [Integer] i,j,... multitimensional indices
|
|
1597
|
+
* @return [Numo::NArray] self
|
|
1598
|
+
* @see #each
|
|
1599
|
+
* @see #map_with_index
|
|
1600
|
+
*/
|
|
2526
1601
|
rb_define_method(cT, "each_with_index", dcomplex_each_with_index, 0);
|
|
1602
|
+
/**
|
|
1603
|
+
* Invokes the given block once for each element of self,
|
|
1604
|
+
* passing that element and indices along each axis as parameters.
|
|
1605
|
+
* Creates a new NArray containing the values returned by the block.
|
|
1606
|
+
* Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
|
1607
|
+
* @overload map_with_index
|
|
1608
|
+
* For a block `{|x,i,j,...| ... }`,
|
|
1609
|
+
* @yieldparam [Numeric] x an element
|
|
1610
|
+
* @yieldparam [Integer] i,j,... multitimensional indices
|
|
1611
|
+
* @return [Numo::NArray] mapped array
|
|
1612
|
+
* @see #map
|
|
1613
|
+
* @see #each_with_index
|
|
1614
|
+
*/
|
|
2527
1615
|
rb_define_method(cT, "map_with_index", dcomplex_map_with_index, 0);
|
|
1616
|
+
/**
|
|
1617
|
+
* abs of self.
|
|
1618
|
+
* @overload abs
|
|
1619
|
+
* @return [Numo::DFloat] abs of self.
|
|
1620
|
+
*/
|
|
2528
1621
|
rb_define_method(cT, "abs", dcomplex_abs, 0);
|
|
2529
1622
|
/**
|
|
2530
1623
|
* Binary add.
|
|
@@ -2586,10 +1679,35 @@ void Init_numo_dcomplex(void) {
|
|
|
2586
1679
|
* @return [Numo::DComplex] square of self.
|
|
2587
1680
|
*/
|
|
2588
1681
|
rb_define_method(cT, "square", dcomplex_square, 0);
|
|
1682
|
+
/**
|
|
1683
|
+
* Unary conj.
|
|
1684
|
+
* @overload conj
|
|
1685
|
+
* @return [Numo::DComplex] conj of self.
|
|
1686
|
+
*/
|
|
2589
1687
|
rb_define_method(cT, "conj", dcomplex_conj, 0);
|
|
1688
|
+
/**
|
|
1689
|
+
* Unary im.
|
|
1690
|
+
* @overload im
|
|
1691
|
+
* @return [Numo::DComplex] im of self.
|
|
1692
|
+
*/
|
|
2590
1693
|
rb_define_method(cT, "im", dcomplex_im, 0);
|
|
1694
|
+
/**
|
|
1695
|
+
* real of self.
|
|
1696
|
+
* @overload real
|
|
1697
|
+
* @return [Numo::DFloat] real of self.
|
|
1698
|
+
*/
|
|
2591
1699
|
rb_define_method(cT, "real", dcomplex_real, 0);
|
|
1700
|
+
/**
|
|
1701
|
+
* imag of self.
|
|
1702
|
+
* @overload imag
|
|
1703
|
+
* @return [Numo::DFloat] imag of self.
|
|
1704
|
+
*/
|
|
2592
1705
|
rb_define_method(cT, "imag", dcomplex_imag, 0);
|
|
1706
|
+
/**
|
|
1707
|
+
* arg of self.
|
|
1708
|
+
* @overload arg
|
|
1709
|
+
* @return [Numo::DFloat] arg of self.
|
|
1710
|
+
*/
|
|
2593
1711
|
rb_define_method(cT, "arg", dcomplex_arg, 0);
|
|
2594
1712
|
rb_define_alias(cT, "angle", "arg");
|
|
2595
1713
|
rb_define_method(cT, "set_imag", dcomplex_set_imag, 1);
|
|
@@ -2649,6 +1767,12 @@ void Init_numo_dcomplex(void) {
|
|
|
2649
1767
|
* @return [Numo::DComplex] rint of self.
|
|
2650
1768
|
*/
|
|
2651
1769
|
rb_define_method(cT, "rint", dcomplex_rint, 0);
|
|
1770
|
+
/**
|
|
1771
|
+
* Binary copysign.
|
|
1772
|
+
* @overload copysign other
|
|
1773
|
+
* @param [Numo::NArray,Numeric] other
|
|
1774
|
+
* @return [Numo::NArray] self copysign other
|
|
1775
|
+
*/
|
|
2652
1776
|
rb_define_method(cT, "copysign", dcomplex_copysign, 1);
|
|
2653
1777
|
/**
|
|
2654
1778
|
* Condition of isnan.
|
|
@@ -2702,6 +1826,16 @@ void Init_numo_dcomplex(void) {
|
|
|
2702
1826
|
* @return [Numo::DComplex] returns result of prod.
|
|
2703
1827
|
*/
|
|
2704
1828
|
rb_define_method(cT, "prod", dcomplex_prod, -1);
|
|
1829
|
+
/**
|
|
1830
|
+
* kahan_sum of self.
|
|
1831
|
+
* @overload kahan_sum(axis:nil, keepdims:false, nan:false)
|
|
1832
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc,
|
|
1833
|
+
* or, return NaN for min/max etc).
|
|
1834
|
+
* @param [Numeric,Array,Range] axis Performs kahan_sum along the axis.
|
|
1835
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
1836
|
+
* dimensions with size one.
|
|
1837
|
+
* @return [Numo::DComplex] returns result of kahan_sum.
|
|
1838
|
+
*/
|
|
2705
1839
|
rb_define_method(cT, "kahan_sum", dcomplex_kahan_sum, -1);
|
|
2706
1840
|
/**
|
|
2707
1841
|
* mean of self.
|
|
@@ -2879,6 +2013,13 @@ void Init_numo_dcomplex(void) {
|
|
|
2879
2013
|
* # [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]
|
|
2880
2014
|
*/
|
|
2881
2015
|
rb_define_method(cT, "rand_norm", dcomplex_rand_norm, -1);
|
|
2016
|
+
/**
|
|
2017
|
+
* Calculate polynomial.
|
|
2018
|
+
* `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
|
|
2019
|
+
* @overload poly a0, a1, ..., an
|
|
2020
|
+
* @param [Numo::NArray,Numeric] a0,a1,...,an
|
|
2021
|
+
* @return [Numo::DComplex]
|
|
2022
|
+
*/
|
|
2882
2023
|
rb_define_method(cT, "poly", dcomplex_poly, -2);
|
|
2883
2024
|
rb_define_singleton_method(cT, "[]", dcomplex_s_cast, -2);
|
|
2884
2025
|
|