numo-narray-alt 0.9.11 → 0.9.13
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/Gemfile +0 -1
- data/README.md +7 -0
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/numo/types/robj_macro.h +1 -1
- data/ext/numo/narray/src/mh/bincount.h +233 -0
- data/ext/numo/narray/src/mh/bit/and.h +225 -0
- data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/not.h +173 -0
- data/ext/numo/narray/src/mh/bit/or.h +225 -0
- data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/xor.h +225 -0
- data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
- data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
- data/ext/numo/narray/src/mh/comp/eq.h +26 -0
- data/ext/numo/narray/src/mh/comp/ge.h +26 -0
- data/ext/numo/narray/src/mh/comp/gt.h +26 -0
- data/ext/numo/narray/src/mh/comp/le.h +26 -0
- data/ext/numo/narray/src/mh/comp/lt.h +26 -0
- data/ext/numo/narray/src/mh/comp/ne.h +26 -0
- data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
- data/ext/numo/narray/src/mh/divmod.h +142 -0
- data/ext/numo/narray/src/mh/eye.h +1 -1
- data/ext/numo/narray/src/mh/fill.h +94 -0
- data/ext/numo/narray/src/mh/format.h +108 -0
- data/ext/numo/narray/src/mh/format_to_a.h +89 -0
- data/ext/numo/narray/src/mh/inspect.h +33 -0
- data/ext/numo/narray/src/mh/isfinite.h +42 -0
- data/ext/numo/narray/src/mh/isinf.h +42 -0
- data/ext/numo/narray/src/mh/isnan.h +42 -0
- data/ext/numo/narray/src/mh/isneginf.h +42 -0
- data/ext/numo/narray/src/mh/isposinf.h +42 -0
- data/ext/numo/narray/src/mh/math/acos.h +2 -2
- data/ext/numo/narray/src/mh/math/acosh.h +2 -2
- data/ext/numo/narray/src/mh/math/asin.h +2 -2
- data/ext/numo/narray/src/mh/math/asinh.h +2 -2
- data/ext/numo/narray/src/mh/math/atan.h +2 -2
- data/ext/numo/narray/src/mh/math/atan2.h +3 -3
- data/ext/numo/narray/src/mh/math/atanh.h +2 -2
- data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
- data/ext/numo/narray/src/mh/math/cos.h +2 -2
- data/ext/numo/narray/src/mh/math/cosh.h +2 -2
- data/ext/numo/narray/src/mh/math/erf.h +2 -2
- data/ext/numo/narray/src/mh/math/erfc.h +2 -2
- data/ext/numo/narray/src/mh/math/exp.h +2 -2
- data/ext/numo/narray/src/mh/math/exp10.h +2 -2
- data/ext/numo/narray/src/mh/math/exp2.h +2 -2
- data/ext/numo/narray/src/mh/math/expm1.h +2 -2
- data/ext/numo/narray/src/mh/math/frexp.h +3 -3
- data/ext/numo/narray/src/mh/math/hypot.h +3 -3
- data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
- data/ext/numo/narray/src/mh/math/log.h +2 -2
- data/ext/numo/narray/src/mh/math/log10.h +2 -2
- data/ext/numo/narray/src/mh/math/log1p.h +2 -2
- data/ext/numo/narray/src/mh/math/log2.h +2 -2
- data/ext/numo/narray/src/mh/math/sin.h +2 -2
- data/ext/numo/narray/src/mh/math/sinc.h +2 -2
- data/ext/numo/narray/src/mh/math/sinh.h +2 -2
- data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
- data/ext/numo/narray/src/mh/math/tan.h +2 -2
- data/ext/numo/narray/src/mh/math/tanh.h +2 -2
- data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
- data/ext/numo/narray/src/mh/minus.h +125 -0
- data/ext/numo/narray/src/mh/op/add.h +78 -0
- data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
- data/ext/numo/narray/src/mh/op/div.h +118 -0
- data/ext/numo/narray/src/mh/op/mod.h +108 -0
- data/ext/numo/narray/src/mh/op/mul.h +78 -0
- data/ext/numo/narray/src/mh/op/sub.h +78 -0
- data/ext/numo/narray/src/mh/pow.h +197 -0
- data/ext/numo/narray/src/mh/rand.h +2 -2
- data/ext/numo/narray/src/mh/rand_norm.h +125 -0
- data/ext/numo/narray/src/mh/reciprocal.h +125 -0
- data/ext/numo/narray/src/mh/round/ceil.h +11 -0
- data/ext/numo/narray/src/mh/round/floor.h +11 -0
- data/ext/numo/narray/src/mh/round/rint.h +9 -0
- data/ext/numo/narray/src/mh/round/round.h +11 -0
- data/ext/numo/narray/src/mh/round/trunc.h +11 -0
- data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
- data/ext/numo/narray/src/mh/sign.h +125 -0
- data/ext/numo/narray/src/mh/square.h +125 -0
- data/ext/numo/narray/src/mh/to_a.h +78 -0
- data/ext/numo/narray/src/t_bit.c +45 -234
- data/ext/numo/narray/src/t_dcomplex.c +457 -2075
- data/ext/numo/narray/src/t_dfloat.c +154 -2560
- data/ext/numo/narray/src/t_int16.c +408 -2542
- data/ext/numo/narray/src/t_int32.c +408 -2542
- data/ext/numo/narray/src/t_int64.c +408 -2542
- data/ext/numo/narray/src/t_int8.c +409 -2138
- data/ext/numo/narray/src/t_robject.c +376 -2161
- data/ext/numo/narray/src/t_scomplex.c +435 -2053
- data/ext/numo/narray/src/t_sfloat.c +149 -2557
- data/ext/numo/narray/src/t_uint16.c +407 -2537
- data/ext/numo/narray/src/t_uint32.c +407 -2537
- data/ext/numo/narray/src/t_uint64.c +407 -2537
- data/ext/numo/narray/src/t_uint8.c +407 -2132
- metadata +47 -2
|
@@ -38,6 +38,34 @@ static ID id_to_a;
|
|
|
38
38
|
VALUE cT;
|
|
39
39
|
extern VALUE cRT;
|
|
40
40
|
|
|
41
|
+
#include "mh/coerce_cast.h"
|
|
42
|
+
#include "mh/to_a.h"
|
|
43
|
+
#include "mh/fill.h"
|
|
44
|
+
#include "mh/format.h"
|
|
45
|
+
#include "mh/format_to_a.h"
|
|
46
|
+
#include "mh/inspect.h"
|
|
47
|
+
#include "mh/op/add.h"
|
|
48
|
+
#include "mh/op/sub.h"
|
|
49
|
+
#include "mh/op/mul.h"
|
|
50
|
+
#include "mh/op/div.h"
|
|
51
|
+
#include "mh/pow.h"
|
|
52
|
+
#include "mh/minus.h"
|
|
53
|
+
#include "mh/reciprocal.h"
|
|
54
|
+
#include "mh/sign.h"
|
|
55
|
+
#include "mh/square.h"
|
|
56
|
+
#include "mh/comp/eq.h"
|
|
57
|
+
#include "mh/comp/ne.h"
|
|
58
|
+
#include "mh/comp/nearly_eq.h"
|
|
59
|
+
#include "mh/round/floor.h"
|
|
60
|
+
#include "mh/round/round.h"
|
|
61
|
+
#include "mh/round/ceil.h"
|
|
62
|
+
#include "mh/round/trunc.h"
|
|
63
|
+
#include "mh/round/rint.h"
|
|
64
|
+
#include "mh/isnan.h"
|
|
65
|
+
#include "mh/isinf.h"
|
|
66
|
+
#include "mh/isposinf.h"
|
|
67
|
+
#include "mh/isneginf.h"
|
|
68
|
+
#include "mh/isfinite.h"
|
|
41
69
|
#include "mh/sum.h"
|
|
42
70
|
#include "mh/prod.h"
|
|
43
71
|
#include "mh/mean.h"
|
|
@@ -51,6 +79,7 @@ extern VALUE cRT;
|
|
|
51
79
|
#include "mh/logseq.h"
|
|
52
80
|
#include "mh/eye.h"
|
|
53
81
|
#include "mh/rand.h"
|
|
82
|
+
#include "mh/rand_norm.h"
|
|
54
83
|
#include "mh/math/sqrt.h"
|
|
55
84
|
#include "mh/math/cbrt.h"
|
|
56
85
|
#include "mh/math/log.h"
|
|
@@ -73,6 +102,34 @@ extern VALUE cRT;
|
|
|
73
102
|
#include "mh/math/atanh.h"
|
|
74
103
|
#include "mh/math/sinc.h"
|
|
75
104
|
|
|
105
|
+
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(scomplex)
|
|
106
|
+
DEF_NARRAY_TO_A_METHOD_FUNC(scomplex)
|
|
107
|
+
DEF_NARRAY_FILL_METHOD_FUNC(scomplex)
|
|
108
|
+
DEF_NARRAY_FORMAT_METHOD_FUNC(scomplex)
|
|
109
|
+
DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(scomplex)
|
|
110
|
+
DEF_NARRAY_INSPECT_METHOD_FUNC(scomplex)
|
|
111
|
+
DEF_NARRAY_ADD_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
112
|
+
DEF_NARRAY_SUB_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
113
|
+
DEF_NARRAY_MUL_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
114
|
+
DEF_NARRAY_FLT_DIV_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
115
|
+
DEF_NARRAY_POW_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
116
|
+
DEF_NARRAY_MINUS_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
117
|
+
DEF_NARRAY_RECIPROCAL_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
118
|
+
DEF_NARRAY_SIGN_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
119
|
+
DEF_NARRAY_SQUARE_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
120
|
+
DEF_NARRAY_EQ_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
121
|
+
DEF_NARRAY_NE_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
122
|
+
DEF_NARRAY_NEARLY_EQ_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
123
|
+
DEF_NARRAY_FLT_FLOOR_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
124
|
+
DEF_NARRAY_FLT_ROUND_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
125
|
+
DEF_NARRAY_FLT_CEIL_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
126
|
+
DEF_NARRAY_FLT_TRUNC_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
127
|
+
DEF_NARRAY_FLT_RINT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
128
|
+
DEF_NARRAY_FLT_ISNAN_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
129
|
+
DEF_NARRAY_FLT_ISINF_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
130
|
+
DEF_NARRAY_FLT_ISPOSINF_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
131
|
+
DEF_NARRAY_FLT_ISNEGINF_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
132
|
+
DEF_NARRAY_FLT_ISFINITE_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
76
133
|
DEF_NARRAY_FLT_SUM_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
77
134
|
DEF_NARRAY_FLT_PROD_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
78
135
|
DEF_NARRAY_FLT_MEAN_METHOD_FUNC(scomplex, numo_cSComplex, scomplex, numo_cSComplex)
|
|
@@ -86,6 +143,7 @@ DEF_NARRAY_FLT_SEQ_METHOD_FUNC(scomplex)
|
|
|
86
143
|
DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(scomplex)
|
|
87
144
|
DEF_NARRAY_EYE_METHOD_FUNC(scomplex)
|
|
88
145
|
DEF_NARRAY_CMP_RAND_METHOD_FUNC(scomplex)
|
|
146
|
+
DEF_NARRAY_CMP_RAND_NORM_METHOD_FUNC(scomplex, float)
|
|
89
147
|
DEF_NARRAY_FLT_SQRT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
90
148
|
DEF_NARRAY_FLT_CBRT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
91
149
|
DEF_NARRAY_FLT_LOG_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
@@ -1391,204 +1449,6 @@ static VALUE scomplex_aset(int argc, VALUE* argv, VALUE self) {
|
|
|
1391
1449
|
return argv[argc];
|
|
1392
1450
|
}
|
|
1393
1451
|
|
|
1394
|
-
/*
|
|
1395
|
-
return NArray with cast to the type of self.
|
|
1396
|
-
@overload coerce_cast(type)
|
|
1397
|
-
@return [nil]
|
|
1398
|
-
*/
|
|
1399
|
-
static VALUE scomplex_coerce_cast(VALUE self, VALUE type) {
|
|
1400
|
-
return Qnil;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
static void iter_scomplex_to_a(na_loop_t* const lp) {
|
|
1404
|
-
size_t i, s1;
|
|
1405
|
-
char* p1;
|
|
1406
|
-
size_t* idx1;
|
|
1407
|
-
dtype x;
|
|
1408
|
-
volatile VALUE a, y;
|
|
1409
|
-
|
|
1410
|
-
INIT_COUNTER(lp, i);
|
|
1411
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1412
|
-
a = rb_ary_new2(i);
|
|
1413
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1414
|
-
if (idx1) {
|
|
1415
|
-
for (; i--;) {
|
|
1416
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
1417
|
-
y = m_data_to_num(x);
|
|
1418
|
-
rb_ary_push(a, y);
|
|
1419
|
-
}
|
|
1420
|
-
} else {
|
|
1421
|
-
for (; i--;) {
|
|
1422
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
1423
|
-
y = m_data_to_num(x);
|
|
1424
|
-
rb_ary_push(a, y);
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
/*
|
|
1430
|
-
Convert self to Array.
|
|
1431
|
-
@overload to_a
|
|
1432
|
-
@return [Array]
|
|
1433
|
-
*/
|
|
1434
|
-
static VALUE scomplex_to_a(VALUE self) {
|
|
1435
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1436
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1437
|
-
ndfunc_t ndf = { iter_scomplex_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1438
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
static void iter_scomplex_fill(na_loop_t* const lp) {
|
|
1442
|
-
size_t i;
|
|
1443
|
-
char* p1;
|
|
1444
|
-
ssize_t s1;
|
|
1445
|
-
size_t* idx1;
|
|
1446
|
-
VALUE x = lp->option;
|
|
1447
|
-
dtype y;
|
|
1448
|
-
INIT_COUNTER(lp, i);
|
|
1449
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1450
|
-
y = m_num_to_data(x);
|
|
1451
|
-
if (idx1) {
|
|
1452
|
-
for (; i--;) {
|
|
1453
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
1454
|
-
}
|
|
1455
|
-
} else {
|
|
1456
|
-
for (; i--;) {
|
|
1457
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
/*
|
|
1463
|
-
Fill elements with other.
|
|
1464
|
-
@overload fill other
|
|
1465
|
-
@param [Numeric] other
|
|
1466
|
-
@return [Numo::SComplex] self.
|
|
1467
|
-
*/
|
|
1468
|
-
static VALUE scomplex_fill(VALUE self, VALUE val) {
|
|
1469
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
|
|
1470
|
-
ndfunc_t ndf = { iter_scomplex_fill, FULL_LOOP, 2, 0, ain, 0 };
|
|
1471
|
-
|
|
1472
|
-
na_ndloop(&ndf, 2, self, val);
|
|
1473
|
-
return self;
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
static VALUE format_scomplex(VALUE fmt, dtype* x) {
|
|
1477
|
-
// fix-me
|
|
1478
|
-
char s[48];
|
|
1479
|
-
int n;
|
|
1480
|
-
|
|
1481
|
-
if (NIL_P(fmt)) {
|
|
1482
|
-
n = m_sprintf(s, *x);
|
|
1483
|
-
return rb_str_new(s, n);
|
|
1484
|
-
}
|
|
1485
|
-
return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
static void iter_scomplex_format(na_loop_t* const lp) {
|
|
1489
|
-
size_t i;
|
|
1490
|
-
char *p1, *p2;
|
|
1491
|
-
ssize_t s1, s2;
|
|
1492
|
-
size_t* idx1;
|
|
1493
|
-
dtype* x;
|
|
1494
|
-
VALUE y;
|
|
1495
|
-
VALUE fmt = lp->option;
|
|
1496
|
-
INIT_COUNTER(lp, i);
|
|
1497
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1498
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
1499
|
-
if (idx1) {
|
|
1500
|
-
for (; i--;) {
|
|
1501
|
-
x = (dtype*)(p1 + *idx1);
|
|
1502
|
-
idx1++;
|
|
1503
|
-
y = format_scomplex(fmt, x);
|
|
1504
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1505
|
-
}
|
|
1506
|
-
} else {
|
|
1507
|
-
for (; i--;) {
|
|
1508
|
-
x = (dtype*)p1;
|
|
1509
|
-
p1 += s1;
|
|
1510
|
-
y = format_scomplex(fmt, x);
|
|
1511
|
-
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
/*
|
|
1517
|
-
Format elements into strings.
|
|
1518
|
-
@overload format format
|
|
1519
|
-
@param [String] format
|
|
1520
|
-
@return [Numo::RObject] array of formatted strings.
|
|
1521
|
-
*/
|
|
1522
|
-
static VALUE scomplex_format(int argc, VALUE* argv, VALUE self) {
|
|
1523
|
-
VALUE fmt = Qnil;
|
|
1524
|
-
|
|
1525
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
|
|
1526
|
-
ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
|
|
1527
|
-
ndfunc_t ndf = { iter_scomplex_format, FULL_LOOP_NIP, 2, 1, ain, aout };
|
|
1528
|
-
|
|
1529
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1530
|
-
return na_ndloop(&ndf, 2, self, fmt);
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
static void iter_scomplex_format_to_a(na_loop_t* const lp) {
|
|
1534
|
-
size_t i;
|
|
1535
|
-
char* p1;
|
|
1536
|
-
ssize_t s1;
|
|
1537
|
-
size_t* idx1;
|
|
1538
|
-
dtype* x;
|
|
1539
|
-
VALUE y;
|
|
1540
|
-
volatile VALUE a;
|
|
1541
|
-
VALUE fmt = lp->option;
|
|
1542
|
-
INIT_COUNTER(lp, i);
|
|
1543
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1544
|
-
a = rb_ary_new2(i);
|
|
1545
|
-
rb_ary_push(lp->args[1].value, a);
|
|
1546
|
-
if (idx1) {
|
|
1547
|
-
for (; i--;) {
|
|
1548
|
-
x = (dtype*)(p1 + *idx1);
|
|
1549
|
-
idx1++;
|
|
1550
|
-
y = format_scomplex(fmt, x);
|
|
1551
|
-
rb_ary_push(a, y);
|
|
1552
|
-
}
|
|
1553
|
-
} else {
|
|
1554
|
-
for (; i--;) {
|
|
1555
|
-
x = (dtype*)p1;
|
|
1556
|
-
p1 += s1;
|
|
1557
|
-
y = format_scomplex(fmt, x);
|
|
1558
|
-
rb_ary_push(a, y);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
/*
|
|
1564
|
-
Format elements into strings.
|
|
1565
|
-
@overload format_to_a format
|
|
1566
|
-
@param [String] format
|
|
1567
|
-
@return [Array] array of formatted strings.
|
|
1568
|
-
*/
|
|
1569
|
-
static VALUE scomplex_format_to_a(int argc, VALUE* argv, VALUE self) {
|
|
1570
|
-
VALUE fmt = Qnil;
|
|
1571
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
|
1572
|
-
ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
|
|
1573
|
-
ndfunc_t ndf = { iter_scomplex_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
|
|
1574
|
-
|
|
1575
|
-
rb_scan_args(argc, argv, "01", &fmt);
|
|
1576
|
-
return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
static VALUE iter_scomplex_inspect(char* ptr, size_t pos, VALUE fmt) {
|
|
1580
|
-
return format_scomplex(fmt, (dtype*)(ptr + pos));
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
/*
|
|
1584
|
-
Returns a string containing a human-readable representation of NArray.
|
|
1585
|
-
@overload inspect
|
|
1586
|
-
@return [String]
|
|
1587
|
-
*/
|
|
1588
|
-
static VALUE scomplex_inspect(VALUE ary) {
|
|
1589
|
-
return na_ndloop_inspect(ary, iter_scomplex_inspect, Qnil);
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
1452
|
static void iter_scomplex_each(na_loop_t* const lp) {
|
|
1593
1453
|
size_t i, s1;
|
|
1594
1454
|
char* p1;
|
|
@@ -1915,1212 +1775,157 @@ static VALUE scomplex_abs(VALUE self) {
|
|
|
1915
1775
|
return na_ndloop(&ndf, 1, self);
|
|
1916
1776
|
}
|
|
1917
1777
|
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
size_t
|
|
1923
|
-
|
|
1924
|
-
char *p1, *p2, *p3;
|
|
1925
|
-
ssize_t s1, s2, s3;
|
|
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;
|
|
1926
1784
|
|
|
1927
1785
|
INIT_COUNTER(lp, n);
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
1931
|
-
|
|
1932
|
-
//
|
|
1933
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
1934
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
1786
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1787
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
1935
1788
|
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
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);
|
|
1947
1801
|
}
|
|
1948
|
-
return;
|
|
1949
1802
|
}
|
|
1950
|
-
|
|
1951
|
-
if (
|
|
1952
|
-
|
|
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 {
|
|
1953
1811
|
//
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
check_intdivzero(*(dtype*)p2);
|
|
1957
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
1958
|
-
if (p1 == p3) { // inplace case
|
|
1959
|
-
for (; i < n; i++) {
|
|
1960
|
-
((dtype*)p1)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1961
|
-
}
|
|
1962
|
-
} else {
|
|
1963
|
-
for (; i < n; i++) {
|
|
1964
|
-
((dtype*)p3)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
} else {
|
|
1812
|
+
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
1813
|
+
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
1968
1814
|
for (i = 0; i < n; i++) {
|
|
1969
|
-
|
|
1970
|
-
p1 += s1;
|
|
1971
|
-
p3 += s3;
|
|
1815
|
+
((dtype*)p2)[i] = m_conj(((dtype*)p1)[i]);
|
|
1972
1816
|
}
|
|
1817
|
+
return;
|
|
1973
1818
|
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
for (i = 0; i < n; i++) {
|
|
1977
|
-
check_intdivzero(*(dtype*)p2);
|
|
1978
|
-
*(dtype*)p1 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1979
|
-
p1 += s1;
|
|
1980
|
-
p2 += s2;
|
|
1981
|
-
}
|
|
1982
|
-
} else {
|
|
1819
|
+
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
1820
|
+
//
|
|
1983
1821
|
for (i = 0; i < n; i++) {
|
|
1984
|
-
|
|
1985
|
-
*(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
|
|
1822
|
+
*(dtype*)p2 = m_conj(*(dtype*)p1);
|
|
1986
1823
|
p1 += s1;
|
|
1987
1824
|
p2 += s2;
|
|
1988
|
-
p3 += s3;
|
|
1989
1825
|
}
|
|
1826
|
+
return;
|
|
1827
|
+
//
|
|
1990
1828
|
}
|
|
1991
1829
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
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
|
+
}
|
|
1994
1835
|
//
|
|
1995
1836
|
}
|
|
1996
1837
|
}
|
|
1997
|
-
for (i = 0; i < n; i++) {
|
|
1998
|
-
dtype x, y, z;
|
|
1999
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2000
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2001
|
-
check_intdivzero(y);
|
|
2002
|
-
z = m_add(x, y);
|
|
2003
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2004
|
-
}
|
|
2005
|
-
//
|
|
2006
|
-
}
|
|
2007
|
-
#undef check_intdivzero
|
|
2008
|
-
|
|
2009
|
-
static VALUE scomplex_add_self(VALUE self, VALUE other) {
|
|
2010
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2011
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2012
|
-
ndfunc_t ndf = { iter_scomplex_add, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2013
|
-
|
|
2014
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2015
1838
|
}
|
|
2016
1839
|
|
|
2017
1840
|
/*
|
|
2018
|
-
|
|
2019
|
-
@overload
|
|
2020
|
-
@
|
|
2021
|
-
@return [Numo::NArray] self + other
|
|
1841
|
+
Unary conj.
|
|
1842
|
+
@overload conj
|
|
1843
|
+
@return [Numo::SComplex] conj of self.
|
|
2022
1844
|
*/
|
|
2023
|
-
static VALUE
|
|
2024
|
-
|
|
2025
|
-
|
|
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 };
|
|
2026
1849
|
|
|
2027
|
-
|
|
2028
|
-
if (klass == cT) {
|
|
2029
|
-
return scomplex_add_self(self, other);
|
|
2030
|
-
} else {
|
|
2031
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2032
|
-
return rb_funcall(v, '+', 1, other);
|
|
2033
|
-
}
|
|
1850
|
+
return na_ndloop(&ndf, 1, self);
|
|
2034
1851
|
}
|
|
2035
1852
|
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
size_t
|
|
2041
|
-
|
|
2042
|
-
char *p1, *p2, *p3;
|
|
2043
|
-
ssize_t s1, s2, s3;
|
|
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;
|
|
2044
1859
|
|
|
2045
1860
|
INIT_COUNTER(lp, n);
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2049
|
-
|
|
2050
|
-
//
|
|
2051
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2052
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
1861
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1862
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2053
1863
|
|
|
2054
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2055
|
-
if (p1 == p3) { // inplace case
|
|
2056
|
-
for (; i < n; i++) {
|
|
2057
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2058
|
-
((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2059
|
-
}
|
|
2060
|
-
} else {
|
|
2061
|
-
for (; i < n; i++) {
|
|
2062
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2063
|
-
((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2070
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2071
|
-
//
|
|
2072
|
-
|
|
2073
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2074
|
-
check_intdivzero(*(dtype*)p2);
|
|
2075
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2076
|
-
if (p1 == p3) { // inplace case
|
|
2077
|
-
for (; i < n; i++) {
|
|
2078
|
-
((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
2079
|
-
}
|
|
2080
|
-
} else {
|
|
2081
|
-
for (; i < n; i++) {
|
|
2082
|
-
((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
} else {
|
|
2086
|
-
for (i = 0; i < n; i++) {
|
|
2087
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
2088
|
-
p1 += s1;
|
|
2089
|
-
p3 += s3;
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
} else {
|
|
2093
|
-
if (p1 == p3) { // inplace case
|
|
2094
|
-
for (i = 0; i < n; i++) {
|
|
2095
|
-
check_intdivzero(*(dtype*)p2);
|
|
2096
|
-
*(dtype*)p1 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
2097
|
-
p1 += s1;
|
|
2098
|
-
p2 += s2;
|
|
2099
|
-
}
|
|
2100
|
-
} else {
|
|
2101
|
-
for (i = 0; i < n; i++) {
|
|
2102
|
-
check_intdivzero(*(dtype*)p2);
|
|
2103
|
-
*(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
|
|
2104
|
-
p1 += s1;
|
|
2105
|
-
p2 += s2;
|
|
2106
|
-
p3 += s3;
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
return;
|
|
2112
|
-
//
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
for (i = 0; i < n; i++) {
|
|
2116
|
-
dtype x, y, z;
|
|
2117
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2118
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2119
|
-
check_intdivzero(y);
|
|
2120
|
-
z = m_sub(x, y);
|
|
2121
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2122
|
-
}
|
|
2123
|
-
//
|
|
2124
|
-
}
|
|
2125
|
-
#undef check_intdivzero
|
|
2126
|
-
|
|
2127
|
-
static VALUE scomplex_sub_self(VALUE self, VALUE other) {
|
|
2128
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2129
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2130
|
-
ndfunc_t ndf = { iter_scomplex_sub, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2131
|
-
|
|
2132
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
/*
|
|
2136
|
-
Binary sub.
|
|
2137
|
-
@overload - other
|
|
2138
|
-
@param [Numo::NArray,Numeric] other
|
|
2139
|
-
@return [Numo::NArray] self - other
|
|
2140
|
-
*/
|
|
2141
|
-
static VALUE scomplex_sub(VALUE self, VALUE other) {
|
|
2142
|
-
|
|
2143
|
-
VALUE klass, v;
|
|
2144
|
-
|
|
2145
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2146
|
-
if (klass == cT) {
|
|
2147
|
-
return scomplex_sub_self(self, other);
|
|
2148
|
-
} else {
|
|
2149
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2150
|
-
return rb_funcall(v, '-', 1, other);
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
#define check_intdivzero(y) \
|
|
2155
|
-
{}
|
|
2156
|
-
|
|
2157
|
-
static void iter_scomplex_mul(na_loop_t* const lp) {
|
|
2158
|
-
size_t i = 0;
|
|
2159
|
-
size_t n;
|
|
2160
|
-
char *p1, *p2, *p3;
|
|
2161
|
-
ssize_t s1, s2, s3;
|
|
2162
|
-
|
|
2163
|
-
INIT_COUNTER(lp, n);
|
|
2164
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2165
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2166
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2167
|
-
|
|
2168
|
-
//
|
|
2169
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2170
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
2171
|
-
|
|
2172
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2173
|
-
if (p1 == p3) { // inplace case
|
|
2174
|
-
for (; i < n; i++) {
|
|
2175
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2176
|
-
((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2177
|
-
}
|
|
2178
|
-
} else {
|
|
2179
|
-
for (; i < n; i++) {
|
|
2180
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2181
|
-
((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
return;
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2188
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2189
|
-
//
|
|
2190
|
-
|
|
2191
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2192
|
-
check_intdivzero(*(dtype*)p2);
|
|
2193
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2194
|
-
if (p1 == p3) { // inplace case
|
|
2195
|
-
for (; i < n; i++) {
|
|
2196
|
-
((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
2197
|
-
}
|
|
2198
|
-
} else {
|
|
2199
|
-
for (; i < n; i++) {
|
|
2200
|
-
((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
} else {
|
|
2204
|
-
for (i = 0; i < n; i++) {
|
|
2205
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
2206
|
-
p1 += s1;
|
|
2207
|
-
p3 += s3;
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
} else {
|
|
2211
|
-
if (p1 == p3) { // inplace case
|
|
2212
|
-
for (i = 0; i < n; i++) {
|
|
2213
|
-
check_intdivzero(*(dtype*)p2);
|
|
2214
|
-
*(dtype*)p1 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
2215
|
-
p1 += s1;
|
|
2216
|
-
p2 += s2;
|
|
2217
|
-
}
|
|
2218
|
-
} else {
|
|
2219
|
-
for (i = 0; i < n; i++) {
|
|
2220
|
-
check_intdivzero(*(dtype*)p2);
|
|
2221
|
-
*(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
|
|
2222
|
-
p1 += s1;
|
|
2223
|
-
p2 += s2;
|
|
2224
|
-
p3 += s3;
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
return;
|
|
2230
|
-
//
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
for (i = 0; i < n; i++) {
|
|
2234
|
-
dtype x, y, z;
|
|
2235
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2236
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2237
|
-
check_intdivzero(y);
|
|
2238
|
-
z = m_mul(x, y);
|
|
2239
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2240
|
-
}
|
|
2241
|
-
//
|
|
2242
|
-
}
|
|
2243
|
-
#undef check_intdivzero
|
|
2244
|
-
|
|
2245
|
-
static VALUE scomplex_mul_self(VALUE self, VALUE other) {
|
|
2246
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2247
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2248
|
-
ndfunc_t ndf = { iter_scomplex_mul, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2249
|
-
|
|
2250
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2251
|
-
}
|
|
2252
|
-
|
|
2253
|
-
/*
|
|
2254
|
-
Binary mul.
|
|
2255
|
-
@overload * other
|
|
2256
|
-
@param [Numo::NArray,Numeric] other
|
|
2257
|
-
@return [Numo::NArray] self * other
|
|
2258
|
-
*/
|
|
2259
|
-
static VALUE scomplex_mul(VALUE self, VALUE other) {
|
|
2260
|
-
|
|
2261
|
-
VALUE klass, v;
|
|
2262
|
-
|
|
2263
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2264
|
-
if (klass == cT) {
|
|
2265
|
-
return scomplex_mul_self(self, other);
|
|
2266
|
-
} else {
|
|
2267
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2268
|
-
return rb_funcall(v, '*', 1, other);
|
|
2269
|
-
}
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
|
-
#define check_intdivzero(y) \
|
|
2273
|
-
{}
|
|
2274
|
-
|
|
2275
|
-
static void iter_scomplex_div(na_loop_t* const lp) {
|
|
2276
|
-
size_t i = 0;
|
|
2277
|
-
size_t n;
|
|
2278
|
-
char *p1, *p2, *p3;
|
|
2279
|
-
ssize_t s1, s2, s3;
|
|
2280
|
-
|
|
2281
|
-
INIT_COUNTER(lp, n);
|
|
2282
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2283
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2284
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2285
|
-
|
|
2286
|
-
//
|
|
2287
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
|
|
2288
|
-
is_aligned(p3, sizeof(dtype))) {
|
|
2289
|
-
|
|
2290
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2291
|
-
if (p1 == p3) { // inplace case
|
|
2292
|
-
for (; i < n; i++) {
|
|
2293
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2294
|
-
((dtype*)p1)[i] = m_div(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2295
|
-
}
|
|
2296
|
-
} else {
|
|
2297
|
-
for (; i < n; i++) {
|
|
2298
|
-
check_intdivzero(((dtype*)p2)[i]);
|
|
2299
|
-
((dtype*)p3)[i] = m_div(((dtype*)p1)[i], ((dtype*)p2)[i]);
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
return;
|
|
2303
|
-
}
|
|
2304
|
-
|
|
2305
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
|
|
2306
|
-
is_aligned_step(s3, sizeof(dtype))) {
|
|
2307
|
-
//
|
|
2308
|
-
|
|
2309
|
-
if (s2 == 0) { // Broadcasting from scalar value.
|
|
2310
|
-
check_intdivzero(*(dtype*)p2);
|
|
2311
|
-
if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
|
|
2312
|
-
if (p1 == p3) { // inplace case
|
|
2313
|
-
for (; i < n; i++) {
|
|
2314
|
-
((dtype*)p1)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2315
|
-
}
|
|
2316
|
-
} else {
|
|
2317
|
-
for (; i < n; i++) {
|
|
2318
|
-
((dtype*)p3)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
|
|
2319
|
-
}
|
|
2320
|
-
}
|
|
2321
|
-
} else {
|
|
2322
|
-
for (i = 0; i < n; i++) {
|
|
2323
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2324
|
-
p1 += s1;
|
|
2325
|
-
p3 += s3;
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
} else {
|
|
2329
|
-
if (p1 == p3) { // inplace case
|
|
2330
|
-
for (i = 0; i < n; i++) {
|
|
2331
|
-
check_intdivzero(*(dtype*)p2);
|
|
2332
|
-
*(dtype*)p1 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2333
|
-
p1 += s1;
|
|
2334
|
-
p2 += s2;
|
|
2335
|
-
}
|
|
2336
|
-
} else {
|
|
2337
|
-
for (i = 0; i < n; i++) {
|
|
2338
|
-
check_intdivzero(*(dtype*)p2);
|
|
2339
|
-
*(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
|
|
2340
|
-
p1 += s1;
|
|
2341
|
-
p2 += s2;
|
|
2342
|
-
p3 += s3;
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
return;
|
|
2348
|
-
//
|
|
2349
|
-
}
|
|
2350
|
-
}
|
|
2351
|
-
for (i = 0; i < n; i++) {
|
|
2352
|
-
dtype x, y, z;
|
|
2353
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2354
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2355
|
-
check_intdivzero(y);
|
|
2356
|
-
z = m_div(x, y);
|
|
2357
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
2358
|
-
}
|
|
2359
|
-
//
|
|
2360
|
-
}
|
|
2361
|
-
#undef check_intdivzero
|
|
2362
|
-
|
|
2363
|
-
static VALUE scomplex_div_self(VALUE self, VALUE other) {
|
|
2364
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2365
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2366
|
-
ndfunc_t ndf = { iter_scomplex_div, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2367
|
-
|
|
2368
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
/*
|
|
2372
|
-
Binary div.
|
|
2373
|
-
@overload / other
|
|
2374
|
-
@param [Numo::NArray,Numeric] other
|
|
2375
|
-
@return [Numo::NArray] self / other
|
|
2376
|
-
*/
|
|
2377
|
-
static VALUE scomplex_div(VALUE self, VALUE other) {
|
|
2378
|
-
|
|
2379
|
-
VALUE klass, v;
|
|
2380
|
-
|
|
2381
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2382
|
-
if (klass == cT) {
|
|
2383
|
-
return scomplex_div_self(self, other);
|
|
2384
|
-
} else {
|
|
2385
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2386
|
-
return rb_funcall(v, '/', 1, other);
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
|
|
2390
|
-
static void iter_scomplex_pow(na_loop_t* const lp) {
|
|
2391
|
-
size_t i;
|
|
2392
|
-
char *p1, *p2, *p3;
|
|
2393
|
-
ssize_t s1, s2, s3;
|
|
2394
|
-
dtype x, y;
|
|
2395
|
-
INIT_COUNTER(lp, i);
|
|
2396
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2397
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2398
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2399
|
-
for (; i--;) {
|
|
2400
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2401
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
2402
|
-
x = m_pow(x, y);
|
|
2403
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
|
-
static void iter_scomplex_pow_int32(na_loop_t* const lp) {
|
|
2408
|
-
size_t i;
|
|
2409
|
-
char *p1, *p2, *p3;
|
|
2410
|
-
ssize_t s1, s2, s3;
|
|
2411
|
-
dtype x;
|
|
2412
|
-
int32_t y;
|
|
2413
|
-
INIT_COUNTER(lp, i);
|
|
2414
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
2415
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
2416
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
2417
|
-
for (; i--;) {
|
|
2418
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2419
|
-
GET_DATA_STRIDE(p2, s2, int32_t, y);
|
|
2420
|
-
x = m_pow_int(x, y);
|
|
2421
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
|
|
2425
|
-
static VALUE scomplex_pow_self(VALUE self, VALUE other) {
|
|
2426
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
2427
|
-
ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
|
|
2428
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2429
|
-
ndfunc_t ndf = { iter_scomplex_pow, STRIDE_LOOP, 2, 1, ain, aout };
|
|
2430
|
-
ndfunc_t ndf_i = { iter_scomplex_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
|
|
2431
|
-
|
|
2432
|
-
// fixme : use na.integer?
|
|
2433
|
-
if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
|
|
2434
|
-
return na_ndloop(&ndf_i, 2, self, other);
|
|
2435
|
-
} else {
|
|
2436
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
|
|
2440
|
-
/*
|
|
2441
|
-
Binary power.
|
|
2442
|
-
@overload ** other
|
|
2443
|
-
@param [Numo::NArray,Numeric] other
|
|
2444
|
-
@return [Numo::NArray] self to the other-th power.
|
|
2445
|
-
*/
|
|
2446
|
-
static VALUE scomplex_pow(VALUE self, VALUE other) {
|
|
2447
|
-
|
|
2448
|
-
VALUE klass, v;
|
|
2449
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
2450
|
-
if (klass == cT) {
|
|
2451
|
-
return scomplex_pow_self(self, other);
|
|
2452
|
-
} else {
|
|
2453
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
2454
|
-
return rb_funcall(v, id_pow, 1, other);
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2458
|
-
static void iter_scomplex_minus(na_loop_t* const lp) {
|
|
2459
|
-
size_t i, n;
|
|
2460
|
-
char *p1, *p2;
|
|
2461
|
-
ssize_t s1, s2;
|
|
2462
|
-
size_t *idx1, *idx2;
|
|
2463
|
-
dtype x;
|
|
2464
|
-
|
|
2465
|
-
INIT_COUNTER(lp, n);
|
|
2466
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2467
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2468
|
-
|
|
2469
|
-
if (idx1) {
|
|
2470
|
-
if (idx2) {
|
|
2471
|
-
for (i = 0; i < n; i++) {
|
|
2472
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2473
|
-
x = m_minus(x);
|
|
2474
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2475
|
-
}
|
|
2476
|
-
} else {
|
|
2477
|
-
for (i = 0; i < n; i++) {
|
|
2478
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2479
|
-
x = m_minus(x);
|
|
2480
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
} else {
|
|
2484
|
-
if (idx2) {
|
|
2485
|
-
for (i = 0; i < n; i++) {
|
|
2486
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2487
|
-
x = m_minus(x);
|
|
2488
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2489
|
-
}
|
|
2490
|
-
} else {
|
|
2491
|
-
//
|
|
2492
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2493
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2494
|
-
for (i = 0; i < n; i++) {
|
|
2495
|
-
((dtype*)p2)[i] = m_minus(((dtype*)p1)[i]);
|
|
2496
|
-
}
|
|
2497
|
-
return;
|
|
2498
|
-
}
|
|
2499
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2500
|
-
//
|
|
2501
|
-
for (i = 0; i < n; i++) {
|
|
2502
|
-
*(dtype*)p2 = m_minus(*(dtype*)p1);
|
|
2503
|
-
p1 += s1;
|
|
2504
|
-
p2 += s2;
|
|
2505
|
-
}
|
|
2506
|
-
return;
|
|
2507
|
-
//
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
for (i = 0; i < n; i++) {
|
|
2511
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2512
|
-
x = m_minus(x);
|
|
2513
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2514
|
-
}
|
|
2515
|
-
//
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
|
|
2520
|
-
/*
|
|
2521
|
-
Unary minus.
|
|
2522
|
-
@overload -@
|
|
2523
|
-
@return [Numo::SComplex] minus of self.
|
|
2524
|
-
*/
|
|
2525
|
-
static VALUE scomplex_minus(VALUE self) {
|
|
2526
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2527
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2528
|
-
ndfunc_t ndf = { iter_scomplex_minus, FULL_LOOP, 1, 1, ain, aout };
|
|
2529
|
-
|
|
2530
|
-
return na_ndloop(&ndf, 1, self);
|
|
2531
|
-
}
|
|
2532
|
-
|
|
2533
|
-
static void iter_scomplex_reciprocal(na_loop_t* const lp) {
|
|
2534
|
-
size_t i, n;
|
|
2535
|
-
char *p1, *p2;
|
|
2536
|
-
ssize_t s1, s2;
|
|
2537
|
-
size_t *idx1, *idx2;
|
|
2538
|
-
dtype x;
|
|
2539
|
-
|
|
2540
|
-
INIT_COUNTER(lp, n);
|
|
2541
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2542
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2543
|
-
|
|
2544
|
-
if (idx1) {
|
|
2545
|
-
if (idx2) {
|
|
2546
|
-
for (i = 0; i < n; i++) {
|
|
2547
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2548
|
-
x = m_reciprocal(x);
|
|
2549
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2550
|
-
}
|
|
2551
|
-
} else {
|
|
2552
|
-
for (i = 0; i < n; i++) {
|
|
2553
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2554
|
-
x = m_reciprocal(x);
|
|
2555
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
} else {
|
|
2559
|
-
if (idx2) {
|
|
2560
|
-
for (i = 0; i < n; i++) {
|
|
2561
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2562
|
-
x = m_reciprocal(x);
|
|
2563
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2564
|
-
}
|
|
2565
|
-
} else {
|
|
2566
|
-
//
|
|
2567
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2568
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2569
|
-
for (i = 0; i < n; i++) {
|
|
2570
|
-
((dtype*)p2)[i] = m_reciprocal(((dtype*)p1)[i]);
|
|
2571
|
-
}
|
|
2572
|
-
return;
|
|
2573
|
-
}
|
|
2574
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2575
|
-
//
|
|
2576
|
-
for (i = 0; i < n; i++) {
|
|
2577
|
-
*(dtype*)p2 = m_reciprocal(*(dtype*)p1);
|
|
2578
|
-
p1 += s1;
|
|
2579
|
-
p2 += s2;
|
|
2580
|
-
}
|
|
2581
|
-
return;
|
|
2582
|
-
//
|
|
2583
|
-
}
|
|
2584
|
-
}
|
|
2585
|
-
for (i = 0; i < n; i++) {
|
|
2586
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2587
|
-
x = m_reciprocal(x);
|
|
2588
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2589
|
-
}
|
|
2590
|
-
//
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
|
|
2595
|
-
/*
|
|
2596
|
-
Unary reciprocal.
|
|
2597
|
-
@overload reciprocal
|
|
2598
|
-
@return [Numo::SComplex] reciprocal of self.
|
|
2599
|
-
*/
|
|
2600
|
-
static VALUE scomplex_reciprocal(VALUE self) {
|
|
2601
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2602
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2603
|
-
ndfunc_t ndf = { iter_scomplex_reciprocal, FULL_LOOP, 1, 1, ain, aout };
|
|
2604
|
-
|
|
2605
|
-
return na_ndloop(&ndf, 1, self);
|
|
2606
|
-
}
|
|
2607
|
-
|
|
2608
|
-
static void iter_scomplex_sign(na_loop_t* const lp) {
|
|
2609
|
-
size_t i, n;
|
|
2610
|
-
char *p1, *p2;
|
|
2611
|
-
ssize_t s1, s2;
|
|
2612
|
-
size_t *idx1, *idx2;
|
|
2613
|
-
dtype x;
|
|
2614
|
-
|
|
2615
|
-
INIT_COUNTER(lp, n);
|
|
2616
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2617
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2618
|
-
|
|
2619
|
-
if (idx1) {
|
|
2620
|
-
if (idx2) {
|
|
2621
|
-
for (i = 0; i < n; i++) {
|
|
2622
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2623
|
-
x = m_sign(x);
|
|
2624
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2625
|
-
}
|
|
2626
|
-
} else {
|
|
2627
|
-
for (i = 0; i < n; i++) {
|
|
2628
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2629
|
-
x = m_sign(x);
|
|
2630
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
} else {
|
|
2634
|
-
if (idx2) {
|
|
2635
|
-
for (i = 0; i < n; i++) {
|
|
2636
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2637
|
-
x = m_sign(x);
|
|
2638
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2639
|
-
}
|
|
2640
|
-
} else {
|
|
2641
|
-
//
|
|
2642
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2643
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2644
|
-
for (i = 0; i < n; i++) {
|
|
2645
|
-
((dtype*)p2)[i] = m_sign(((dtype*)p1)[i]);
|
|
2646
|
-
}
|
|
2647
|
-
return;
|
|
2648
|
-
}
|
|
2649
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2650
|
-
//
|
|
2651
|
-
for (i = 0; i < n; i++) {
|
|
2652
|
-
*(dtype*)p2 = m_sign(*(dtype*)p1);
|
|
2653
|
-
p1 += s1;
|
|
2654
|
-
p2 += s2;
|
|
2655
|
-
}
|
|
2656
|
-
return;
|
|
2657
|
-
//
|
|
2658
|
-
}
|
|
2659
|
-
}
|
|
2660
|
-
for (i = 0; i < n; i++) {
|
|
2661
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2662
|
-
x = m_sign(x);
|
|
2663
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2664
|
-
}
|
|
2665
|
-
//
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
/*
|
|
2671
|
-
Unary sign.
|
|
2672
|
-
@overload sign
|
|
2673
|
-
@return [Numo::SComplex] sign of self.
|
|
2674
|
-
*/
|
|
2675
|
-
static VALUE scomplex_sign(VALUE self) {
|
|
2676
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2677
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2678
|
-
ndfunc_t ndf = { iter_scomplex_sign, FULL_LOOP, 1, 1, ain, aout };
|
|
2679
|
-
|
|
2680
|
-
return na_ndloop(&ndf, 1, self);
|
|
2681
|
-
}
|
|
2682
|
-
|
|
2683
|
-
static void iter_scomplex_square(na_loop_t* const lp) {
|
|
2684
|
-
size_t i, n;
|
|
2685
|
-
char *p1, *p2;
|
|
2686
|
-
ssize_t s1, s2;
|
|
2687
|
-
size_t *idx1, *idx2;
|
|
2688
|
-
dtype x;
|
|
2689
|
-
|
|
2690
|
-
INIT_COUNTER(lp, n);
|
|
2691
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2692
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2693
|
-
|
|
2694
|
-
if (idx1) {
|
|
2695
|
-
if (idx2) {
|
|
2696
|
-
for (i = 0; i < n; i++) {
|
|
2697
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2698
|
-
x = m_square(x);
|
|
2699
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2700
|
-
}
|
|
2701
|
-
} else {
|
|
2702
|
-
for (i = 0; i < n; i++) {
|
|
2703
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2704
|
-
x = m_square(x);
|
|
2705
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2708
|
-
} else {
|
|
2709
|
-
if (idx2) {
|
|
2710
|
-
for (i = 0; i < n; i++) {
|
|
2711
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2712
|
-
x = m_square(x);
|
|
2713
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2714
|
-
}
|
|
2715
|
-
} else {
|
|
2716
|
-
//
|
|
2717
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2718
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2719
|
-
for (i = 0; i < n; i++) {
|
|
2720
|
-
((dtype*)p2)[i] = m_square(((dtype*)p1)[i]);
|
|
2721
|
-
}
|
|
2722
|
-
return;
|
|
2723
|
-
}
|
|
2724
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2725
|
-
//
|
|
2726
|
-
for (i = 0; i < n; i++) {
|
|
2727
|
-
*(dtype*)p2 = m_square(*(dtype*)p1);
|
|
2728
|
-
p1 += s1;
|
|
2729
|
-
p2 += s2;
|
|
2730
|
-
}
|
|
2731
|
-
return;
|
|
2732
|
-
//
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
for (i = 0; i < n; i++) {
|
|
2736
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2737
|
-
x = m_square(x);
|
|
2738
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2739
|
-
}
|
|
2740
|
-
//
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
|
|
2745
|
-
/*
|
|
2746
|
-
Unary square.
|
|
2747
|
-
@overload square
|
|
2748
|
-
@return [Numo::SComplex] square of self.
|
|
2749
|
-
*/
|
|
2750
|
-
static VALUE scomplex_square(VALUE self) {
|
|
2751
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2752
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2753
|
-
ndfunc_t ndf = { iter_scomplex_square, FULL_LOOP, 1, 1, ain, aout };
|
|
2754
|
-
|
|
2755
|
-
return na_ndloop(&ndf, 1, self);
|
|
2756
|
-
}
|
|
2757
|
-
|
|
2758
|
-
static void iter_scomplex_conj(na_loop_t* const lp) {
|
|
2759
|
-
size_t i, n;
|
|
2760
|
-
char *p1, *p2;
|
|
2761
|
-
ssize_t s1, s2;
|
|
2762
|
-
size_t *idx1, *idx2;
|
|
2763
|
-
dtype x;
|
|
2764
|
-
|
|
2765
|
-
INIT_COUNTER(lp, n);
|
|
2766
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2767
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2768
|
-
|
|
2769
|
-
if (idx1) {
|
|
2770
|
-
if (idx2) {
|
|
2771
|
-
for (i = 0; i < n; i++) {
|
|
2772
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2773
|
-
x = m_conj(x);
|
|
2774
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2775
|
-
}
|
|
2776
|
-
} else {
|
|
2777
|
-
for (i = 0; i < n; i++) {
|
|
2778
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2779
|
-
x = m_conj(x);
|
|
2780
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
} else {
|
|
2784
|
-
if (idx2) {
|
|
2785
|
-
for (i = 0; i < n; i++) {
|
|
2786
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2787
|
-
x = m_conj(x);
|
|
2788
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2789
|
-
}
|
|
2790
|
-
} else {
|
|
2791
|
-
//
|
|
2792
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2793
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2794
|
-
for (i = 0; i < n; i++) {
|
|
2795
|
-
((dtype*)p2)[i] = m_conj(((dtype*)p1)[i]);
|
|
2796
|
-
}
|
|
2797
|
-
return;
|
|
2798
|
-
}
|
|
2799
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2800
|
-
//
|
|
2801
|
-
for (i = 0; i < n; i++) {
|
|
2802
|
-
*(dtype*)p2 = m_conj(*(dtype*)p1);
|
|
2803
|
-
p1 += s1;
|
|
2804
|
-
p2 += s2;
|
|
2805
|
-
}
|
|
2806
|
-
return;
|
|
2807
|
-
//
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2810
|
-
for (i = 0; i < n; i++) {
|
|
2811
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2812
|
-
x = m_conj(x);
|
|
2813
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2814
|
-
}
|
|
2815
|
-
//
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
|
|
2820
|
-
/*
|
|
2821
|
-
Unary conj.
|
|
2822
|
-
@overload conj
|
|
2823
|
-
@return [Numo::SComplex] conj of self.
|
|
2824
|
-
*/
|
|
2825
|
-
static VALUE scomplex_conj(VALUE self) {
|
|
2826
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2827
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2828
|
-
ndfunc_t ndf = { iter_scomplex_conj, FULL_LOOP, 1, 1, ain, aout };
|
|
2829
|
-
|
|
2830
|
-
return na_ndloop(&ndf, 1, self);
|
|
2831
|
-
}
|
|
2832
|
-
|
|
2833
|
-
static void iter_scomplex_im(na_loop_t* const lp) {
|
|
2834
|
-
size_t i, n;
|
|
2835
|
-
char *p1, *p2;
|
|
2836
|
-
ssize_t s1, s2;
|
|
2837
|
-
size_t *idx1, *idx2;
|
|
2838
|
-
dtype x;
|
|
2839
|
-
|
|
2840
|
-
INIT_COUNTER(lp, n);
|
|
2841
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2842
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2843
|
-
|
|
2844
|
-
if (idx1) {
|
|
2845
|
-
if (idx2) {
|
|
2846
|
-
for (i = 0; i < n; i++) {
|
|
2847
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2848
|
-
x = m_im(x);
|
|
2849
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2850
|
-
}
|
|
2851
|
-
} else {
|
|
2852
|
-
for (i = 0; i < n; i++) {
|
|
2853
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2854
|
-
x = m_im(x);
|
|
2855
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2856
|
-
}
|
|
2857
|
-
}
|
|
2858
|
-
} else {
|
|
2859
|
-
if (idx2) {
|
|
2860
|
-
for (i = 0; i < n; i++) {
|
|
2861
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2862
|
-
x = m_im(x);
|
|
2863
|
-
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
2864
|
-
}
|
|
2865
|
-
} else {
|
|
2866
|
-
//
|
|
2867
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
2868
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
2869
|
-
for (i = 0; i < n; i++) {
|
|
2870
|
-
((dtype*)p2)[i] = m_im(((dtype*)p1)[i]);
|
|
2871
|
-
}
|
|
2872
|
-
return;
|
|
2873
|
-
}
|
|
2874
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
2875
|
-
//
|
|
2876
|
-
for (i = 0; i < n; i++) {
|
|
2877
|
-
*(dtype*)p2 = m_im(*(dtype*)p1);
|
|
2878
|
-
p1 += s1;
|
|
2879
|
-
p2 += s2;
|
|
2880
|
-
}
|
|
2881
|
-
return;
|
|
2882
|
-
//
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
for (i = 0; i < n; i++) {
|
|
2886
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2887
|
-
x = m_im(x);
|
|
2888
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
2889
|
-
}
|
|
2890
|
-
//
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
}
|
|
2894
|
-
|
|
2895
|
-
/*
|
|
2896
|
-
Unary im.
|
|
2897
|
-
@overload im
|
|
2898
|
-
@return [Numo::SComplex] im of self.
|
|
2899
|
-
*/
|
|
2900
|
-
static VALUE scomplex_im(VALUE self) {
|
|
2901
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2902
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
2903
|
-
ndfunc_t ndf = { iter_scomplex_im, FULL_LOOP, 1, 1, ain, aout };
|
|
2904
|
-
|
|
2905
|
-
return na_ndloop(&ndf, 1, self);
|
|
2906
|
-
}
|
|
2907
|
-
|
|
2908
|
-
static void iter_scomplex_real(na_loop_t* const lp) {
|
|
2909
|
-
size_t i;
|
|
2910
|
-
char *p1, *p2;
|
|
2911
|
-
ssize_t s1, s2;
|
|
2912
|
-
size_t *idx1, *idx2;
|
|
2913
|
-
dtype x;
|
|
2914
|
-
rtype y;
|
|
2915
|
-
INIT_COUNTER(lp, i);
|
|
2916
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2917
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2918
|
-
if (idx1) {
|
|
2919
|
-
if (idx2) {
|
|
2920
|
-
for (; i--;) {
|
|
2921
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2922
|
-
y = m_real(x);
|
|
2923
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2924
|
-
}
|
|
2925
|
-
} else {
|
|
2926
|
-
for (; i--;) {
|
|
2927
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2928
|
-
y = m_real(x);
|
|
2929
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
} else {
|
|
2933
|
-
if (idx2) {
|
|
2934
|
-
for (; i--;) {
|
|
2935
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2936
|
-
y = m_real(x);
|
|
2937
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2938
|
-
}
|
|
2939
|
-
} else {
|
|
2940
|
-
for (; i--;) {
|
|
2941
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2942
|
-
y = m_real(x);
|
|
2943
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2944
|
-
}
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
}
|
|
2948
|
-
|
|
2949
|
-
/*
|
|
2950
|
-
real of self.
|
|
2951
|
-
@overload real
|
|
2952
|
-
@return [Numo::SFloat] real of self.
|
|
2953
|
-
*/
|
|
2954
|
-
static VALUE scomplex_real(VALUE self) {
|
|
2955
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
2956
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
2957
|
-
ndfunc_t ndf = { iter_scomplex_real, FULL_LOOP, 1, 1, ain, aout };
|
|
2958
|
-
|
|
2959
|
-
return na_ndloop(&ndf, 1, self);
|
|
2960
|
-
}
|
|
2961
|
-
|
|
2962
|
-
static void iter_scomplex_imag(na_loop_t* const lp) {
|
|
2963
|
-
size_t i;
|
|
2964
|
-
char *p1, *p2;
|
|
2965
|
-
ssize_t s1, s2;
|
|
2966
|
-
size_t *idx1, *idx2;
|
|
2967
|
-
dtype x;
|
|
2968
|
-
rtype y;
|
|
2969
|
-
INIT_COUNTER(lp, i);
|
|
2970
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
2971
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
2972
|
-
if (idx1) {
|
|
2973
|
-
if (idx2) {
|
|
2974
|
-
for (; i--;) {
|
|
2975
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2976
|
-
y = m_imag(x);
|
|
2977
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2978
|
-
}
|
|
2979
|
-
} else {
|
|
2980
|
-
for (; i--;) {
|
|
2981
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
2982
|
-
y = m_imag(x);
|
|
2983
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2984
|
-
}
|
|
2985
|
-
}
|
|
2986
|
-
} else {
|
|
2987
|
-
if (idx2) {
|
|
2988
|
-
for (; i--;) {
|
|
2989
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2990
|
-
y = m_imag(x);
|
|
2991
|
-
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
2992
|
-
}
|
|
2993
|
-
} else {
|
|
2994
|
-
for (; i--;) {
|
|
2995
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
2996
|
-
y = m_imag(x);
|
|
2997
|
-
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
2998
|
-
}
|
|
2999
|
-
}
|
|
3000
|
-
}
|
|
3001
|
-
}
|
|
3002
|
-
|
|
3003
|
-
/*
|
|
3004
|
-
imag of self.
|
|
3005
|
-
@overload imag
|
|
3006
|
-
@return [Numo::SFloat] imag of self.
|
|
3007
|
-
*/
|
|
3008
|
-
static VALUE scomplex_imag(VALUE self) {
|
|
3009
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3010
|
-
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
3011
|
-
ndfunc_t ndf = { iter_scomplex_imag, FULL_LOOP, 1, 1, ain, aout };
|
|
3012
|
-
|
|
3013
|
-
return na_ndloop(&ndf, 1, self);
|
|
3014
|
-
}
|
|
3015
|
-
|
|
3016
|
-
static void iter_scomplex_arg(na_loop_t* const lp) {
|
|
3017
|
-
size_t i;
|
|
3018
|
-
char *p1, *p2;
|
|
3019
|
-
ssize_t s1, s2;
|
|
3020
|
-
size_t *idx1, *idx2;
|
|
3021
|
-
dtype x;
|
|
3022
|
-
rtype y;
|
|
3023
|
-
INIT_COUNTER(lp, i);
|
|
3024
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3025
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3026
1864
|
if (idx1) {
|
|
3027
1865
|
if (idx2) {
|
|
3028
|
-
for (; i
|
|
1866
|
+
for (i = 0; i < n; i++) {
|
|
3029
1867
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3030
|
-
|
|
3031
|
-
SET_DATA_INDEX(p2, idx2,
|
|
1868
|
+
x = m_im(x);
|
|
1869
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3032
1870
|
}
|
|
3033
1871
|
} else {
|
|
3034
|
-
for (; i
|
|
1872
|
+
for (i = 0; i < n; i++) {
|
|
3035
1873
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3036
|
-
|
|
3037
|
-
SET_DATA_STRIDE(p2, s2,
|
|
1874
|
+
x = m_im(x);
|
|
1875
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3038
1876
|
}
|
|
3039
1877
|
}
|
|
3040
1878
|
} else {
|
|
3041
1879
|
if (idx2) {
|
|
3042
|
-
for (; i
|
|
1880
|
+
for (i = 0; i < n; i++) {
|
|
3043
1881
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3044
|
-
|
|
3045
|
-
SET_DATA_INDEX(p2, idx2,
|
|
1882
|
+
x = m_im(x);
|
|
1883
|
+
SET_DATA_INDEX(p2, idx2, dtype, x);
|
|
3046
1884
|
}
|
|
3047
1885
|
} else {
|
|
3048
|
-
|
|
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++) {
|
|
3049
1906
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3050
|
-
|
|
3051
|
-
SET_DATA_STRIDE(p2, s2,
|
|
1907
|
+
x = m_im(x);
|
|
1908
|
+
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
3052
1909
|
}
|
|
1910
|
+
//
|
|
3053
1911
|
}
|
|
3054
1912
|
}
|
|
3055
1913
|
}
|
|
3056
1914
|
|
|
3057
1915
|
/*
|
|
3058
|
-
|
|
3059
|
-
@overload
|
|
3060
|
-
@return [Numo::
|
|
1916
|
+
Unary im.
|
|
1917
|
+
@overload im
|
|
1918
|
+
@return [Numo::SComplex] im of self.
|
|
3061
1919
|
*/
|
|
3062
|
-
static VALUE
|
|
1920
|
+
static VALUE scomplex_im(VALUE self) {
|
|
3063
1921
|
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3064
|
-
ndfunc_arg_out_t aout[1] = { {
|
|
3065
|
-
ndfunc_t ndf = {
|
|
1922
|
+
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
1923
|
+
ndfunc_t ndf = { iter_scomplex_im, FULL_LOOP, 1, 1, ain, aout };
|
|
3066
1924
|
|
|
3067
1925
|
return na_ndloop(&ndf, 1, self);
|
|
3068
1926
|
}
|
|
3069
1927
|
|
|
3070
|
-
static void
|
|
3071
|
-
size_t i;
|
|
3072
|
-
char *p1, *p2;
|
|
3073
|
-
ssize_t s1, s2;
|
|
3074
|
-
size_t *idx1, *idx2;
|
|
3075
|
-
dtype x;
|
|
3076
|
-
rtype y;
|
|
3077
|
-
INIT_COUNTER(lp, i);
|
|
3078
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3079
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3080
|
-
if (idx1) {
|
|
3081
|
-
if (idx2) {
|
|
3082
|
-
for (; i--;) {
|
|
3083
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
3084
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3085
|
-
x = m_set_imag(x, y);
|
|
3086
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3087
|
-
}
|
|
3088
|
-
} else {
|
|
3089
|
-
for (; i--;) {
|
|
3090
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
3091
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3092
|
-
x = m_set_imag(x, y);
|
|
3093
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
} else {
|
|
3097
|
-
if (idx2) {
|
|
3098
|
-
for (; i--;) {
|
|
3099
|
-
GET_DATA(p1, dtype, x);
|
|
3100
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3101
|
-
x = m_set_imag(x, y);
|
|
3102
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3103
|
-
}
|
|
3104
|
-
} else {
|
|
3105
|
-
for (; i--;) {
|
|
3106
|
-
GET_DATA(p1, dtype, x);
|
|
3107
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3108
|
-
x = m_set_imag(x, y);
|
|
3109
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3110
|
-
}
|
|
3111
|
-
}
|
|
3112
|
-
}
|
|
3113
|
-
}
|
|
3114
|
-
|
|
3115
|
-
static VALUE scomplex_set_imag(VALUE self, VALUE a1) {
|
|
3116
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
|
|
3117
|
-
ndfunc_t ndf = { iter_scomplex_set_imag, FULL_LOOP, 2, 0, ain, 0 };
|
|
3118
|
-
|
|
3119
|
-
na_ndloop(&ndf, 2, self, a1);
|
|
3120
|
-
return a1;
|
|
3121
|
-
}
|
|
3122
|
-
|
|
3123
|
-
static void iter_scomplex_set_real(na_loop_t* const lp) {
|
|
1928
|
+
static void iter_scomplex_real(na_loop_t* const lp) {
|
|
3124
1929
|
size_t i;
|
|
3125
1930
|
char *p1, *p2;
|
|
3126
1931
|
ssize_t s1, s2;
|
|
@@ -3133,560 +1938,259 @@ static void iter_scomplex_set_real(na_loop_t* const lp) {
|
|
|
3133
1938
|
if (idx1) {
|
|
3134
1939
|
if (idx2) {
|
|
3135
1940
|
for (; i--;) {
|
|
3136
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
3137
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3138
|
-
x = m_set_real(x, y);
|
|
3139
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3140
|
-
}
|
|
3141
|
-
} else {
|
|
3142
|
-
for (; i--;) {
|
|
3143
|
-
GET_DATA(p1 + *idx1, dtype, x);
|
|
3144
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3145
|
-
x = m_set_real(x, y);
|
|
3146
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3147
|
-
}
|
|
3148
|
-
}
|
|
3149
|
-
} else {
|
|
3150
|
-
if (idx2) {
|
|
3151
|
-
for (; i--;) {
|
|
3152
|
-
GET_DATA(p1, dtype, x);
|
|
3153
|
-
GET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3154
|
-
x = m_set_real(x, y);
|
|
3155
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3156
|
-
}
|
|
3157
|
-
} else {
|
|
3158
|
-
for (; i--;) {
|
|
3159
|
-
GET_DATA(p1, dtype, x);
|
|
3160
|
-
GET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3161
|
-
x = m_set_real(x, y);
|
|
3162
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3163
|
-
}
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3168
|
-
static VALUE scomplex_set_real(VALUE self, VALUE a1) {
|
|
3169
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
|
|
3170
|
-
ndfunc_t ndf = { iter_scomplex_set_real, FULL_LOOP, 2, 0, ain, 0 };
|
|
3171
|
-
|
|
3172
|
-
na_ndloop(&ndf, 2, self, a1);
|
|
3173
|
-
return a1;
|
|
3174
|
-
}
|
|
3175
|
-
|
|
3176
|
-
static void iter_scomplex_eq(na_loop_t* const lp) {
|
|
3177
|
-
size_t i;
|
|
3178
|
-
char *p1, *p2;
|
|
3179
|
-
BIT_DIGIT* a3;
|
|
3180
|
-
size_t p3;
|
|
3181
|
-
ssize_t s1, s2, s3;
|
|
3182
|
-
dtype x, y;
|
|
3183
|
-
BIT_DIGIT b;
|
|
3184
|
-
INIT_COUNTER(lp, i);
|
|
3185
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3186
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3187
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3188
|
-
for (; i--;) {
|
|
3189
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3190
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3191
|
-
b = (m_eq(x, y)) ? 1 : 0;
|
|
3192
|
-
STORE_BIT(a3, p3, b);
|
|
3193
|
-
p3 += s3;
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
|
-
static VALUE scomplex_eq_self(VALUE self, VALUE other) {
|
|
3198
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3199
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3200
|
-
ndfunc_t ndf = { iter_scomplex_eq, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3201
|
-
|
|
3202
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3203
|
-
}
|
|
3204
|
-
|
|
3205
|
-
/*
|
|
3206
|
-
Comparison eq other.
|
|
3207
|
-
@overload eq other
|
|
3208
|
-
@param [Numo::NArray,Numeric] other
|
|
3209
|
-
@return [Numo::Bit] result of self eq other.
|
|
3210
|
-
*/
|
|
3211
|
-
static VALUE scomplex_eq(VALUE self, VALUE other) {
|
|
3212
|
-
|
|
3213
|
-
VALUE klass, v;
|
|
3214
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3215
|
-
if (klass == cT) {
|
|
3216
|
-
return scomplex_eq_self(self, other);
|
|
3217
|
-
} else {
|
|
3218
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3219
|
-
return rb_funcall(v, id_eq, 1, other);
|
|
3220
|
-
}
|
|
3221
|
-
}
|
|
3222
|
-
|
|
3223
|
-
static void iter_scomplex_ne(na_loop_t* const lp) {
|
|
3224
|
-
size_t i;
|
|
3225
|
-
char *p1, *p2;
|
|
3226
|
-
BIT_DIGIT* a3;
|
|
3227
|
-
size_t p3;
|
|
3228
|
-
ssize_t s1, s2, s3;
|
|
3229
|
-
dtype x, y;
|
|
3230
|
-
BIT_DIGIT b;
|
|
3231
|
-
INIT_COUNTER(lp, i);
|
|
3232
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3233
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3234
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3235
|
-
for (; i--;) {
|
|
3236
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3237
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3238
|
-
b = (m_ne(x, y)) ? 1 : 0;
|
|
3239
|
-
STORE_BIT(a3, p3, b);
|
|
3240
|
-
p3 += s3;
|
|
3241
|
-
}
|
|
3242
|
-
}
|
|
3243
|
-
|
|
3244
|
-
static VALUE scomplex_ne_self(VALUE self, VALUE other) {
|
|
3245
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3246
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3247
|
-
ndfunc_t ndf = { iter_scomplex_ne, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3248
|
-
|
|
3249
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3250
|
-
}
|
|
3251
|
-
|
|
3252
|
-
/*
|
|
3253
|
-
Comparison ne other.
|
|
3254
|
-
@overload ne other
|
|
3255
|
-
@param [Numo::NArray,Numeric] other
|
|
3256
|
-
@return [Numo::Bit] result of self ne other.
|
|
3257
|
-
*/
|
|
3258
|
-
static VALUE scomplex_ne(VALUE self, VALUE other) {
|
|
3259
|
-
|
|
3260
|
-
VALUE klass, v;
|
|
3261
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3262
|
-
if (klass == cT) {
|
|
3263
|
-
return scomplex_ne_self(self, other);
|
|
3264
|
-
} else {
|
|
3265
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3266
|
-
return rb_funcall(v, id_ne, 1, other);
|
|
3267
|
-
}
|
|
3268
|
-
}
|
|
3269
|
-
|
|
3270
|
-
static void iter_scomplex_nearly_eq(na_loop_t* const lp) {
|
|
3271
|
-
size_t i;
|
|
3272
|
-
char *p1, *p2;
|
|
3273
|
-
BIT_DIGIT* a3;
|
|
3274
|
-
size_t p3;
|
|
3275
|
-
ssize_t s1, s2, s3;
|
|
3276
|
-
dtype x, y;
|
|
3277
|
-
BIT_DIGIT b;
|
|
3278
|
-
INIT_COUNTER(lp, i);
|
|
3279
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3280
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3281
|
-
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
|
3282
|
-
for (; i--;) {
|
|
3283
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3284
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
3285
|
-
b = (m_nearly_eq(x, y)) ? 1 : 0;
|
|
3286
|
-
STORE_BIT(a3, p3, b);
|
|
3287
|
-
p3 += s3;
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3290
|
-
|
|
3291
|
-
static VALUE scomplex_nearly_eq_self(VALUE self, VALUE other) {
|
|
3292
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
3293
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3294
|
-
ndfunc_t ndf = { iter_scomplex_nearly_eq, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3295
|
-
|
|
3296
|
-
return na_ndloop(&ndf, 2, self, other);
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
|
-
/*
|
|
3300
|
-
Comparison nearly_eq other.
|
|
3301
|
-
@overload nearly_eq other
|
|
3302
|
-
@param [Numo::NArray,Numeric] other
|
|
3303
|
-
@return [Numo::Bit] result of self nearly_eq other.
|
|
3304
|
-
*/
|
|
3305
|
-
static VALUE scomplex_nearly_eq(VALUE self, VALUE other) {
|
|
3306
|
-
|
|
3307
|
-
VALUE klass, v;
|
|
3308
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
|
|
3309
|
-
if (klass == cT) {
|
|
3310
|
-
return scomplex_nearly_eq_self(self, other);
|
|
3311
|
-
} else {
|
|
3312
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
3313
|
-
return rb_funcall(v, id_nearly_eq, 1, other);
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
|
|
3317
|
-
static void iter_scomplex_floor(na_loop_t* const lp) {
|
|
3318
|
-
size_t i, n;
|
|
3319
|
-
char *p1, *p2;
|
|
3320
|
-
ssize_t s1, s2;
|
|
3321
|
-
size_t *idx1, *idx2;
|
|
3322
|
-
dtype x;
|
|
3323
|
-
|
|
3324
|
-
INIT_COUNTER(lp, n);
|
|
3325
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3326
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3327
|
-
|
|
3328
|
-
if (idx1) {
|
|
3329
|
-
if (idx2) {
|
|
3330
|
-
for (i = 0; i < n; i++) {
|
|
3331
1941
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3332
|
-
|
|
3333
|
-
SET_DATA_INDEX(p2, idx2,
|
|
1942
|
+
y = m_real(x);
|
|
1943
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3334
1944
|
}
|
|
3335
1945
|
} else {
|
|
3336
|
-
for (
|
|
1946
|
+
for (; i--;) {
|
|
3337
1947
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3338
|
-
|
|
3339
|
-
SET_DATA_STRIDE(p2, s2,
|
|
1948
|
+
y = m_real(x);
|
|
1949
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3340
1950
|
}
|
|
3341
1951
|
}
|
|
3342
1952
|
} else {
|
|
3343
1953
|
if (idx2) {
|
|
3344
|
-
for (
|
|
1954
|
+
for (; i--;) {
|
|
3345
1955
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3346
|
-
|
|
3347
|
-
SET_DATA_INDEX(p2, idx2,
|
|
1956
|
+
y = m_real(x);
|
|
1957
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3348
1958
|
}
|
|
3349
1959
|
} else {
|
|
3350
|
-
|
|
3351
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
3352
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
3353
|
-
for (i = 0; i < n; i++) {
|
|
3354
|
-
((dtype*)p2)[i] = m_floor(((dtype*)p1)[i]);
|
|
3355
|
-
}
|
|
3356
|
-
return;
|
|
3357
|
-
}
|
|
3358
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
3359
|
-
//
|
|
3360
|
-
for (i = 0; i < n; i++) {
|
|
3361
|
-
*(dtype*)p2 = m_floor(*(dtype*)p1);
|
|
3362
|
-
p1 += s1;
|
|
3363
|
-
p2 += s2;
|
|
3364
|
-
}
|
|
3365
|
-
return;
|
|
3366
|
-
//
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
for (i = 0; i < n; i++) {
|
|
1960
|
+
for (; i--;) {
|
|
3370
1961
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3371
|
-
|
|
3372
|
-
SET_DATA_STRIDE(p2, s2,
|
|
1962
|
+
y = m_real(x);
|
|
1963
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3373
1964
|
}
|
|
3374
|
-
//
|
|
3375
1965
|
}
|
|
3376
1966
|
}
|
|
3377
1967
|
}
|
|
3378
1968
|
|
|
3379
1969
|
/*
|
|
3380
|
-
|
|
3381
|
-
@overload
|
|
3382
|
-
@return [Numo::
|
|
1970
|
+
real of self.
|
|
1971
|
+
@overload real
|
|
1972
|
+
@return [Numo::SFloat] real of self.
|
|
3383
1973
|
*/
|
|
3384
|
-
static VALUE
|
|
1974
|
+
static VALUE scomplex_real(VALUE self) {
|
|
3385
1975
|
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3386
|
-
ndfunc_arg_out_t aout[1] = { {
|
|
3387
|
-
ndfunc_t ndf = {
|
|
1976
|
+
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
1977
|
+
ndfunc_t ndf = { iter_scomplex_real, FULL_LOOP, 1, 1, ain, aout };
|
|
3388
1978
|
|
|
3389
1979
|
return na_ndloop(&ndf, 1, self);
|
|
3390
1980
|
}
|
|
3391
1981
|
|
|
3392
|
-
static void
|
|
3393
|
-
size_t i
|
|
1982
|
+
static void iter_scomplex_imag(na_loop_t* const lp) {
|
|
1983
|
+
size_t i;
|
|
3394
1984
|
char *p1, *p2;
|
|
3395
1985
|
ssize_t s1, s2;
|
|
3396
1986
|
size_t *idx1, *idx2;
|
|
3397
1987
|
dtype x;
|
|
3398
|
-
|
|
3399
|
-
INIT_COUNTER(lp,
|
|
1988
|
+
rtype y;
|
|
1989
|
+
INIT_COUNTER(lp, i);
|
|
3400
1990
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3401
1991
|
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3402
|
-
|
|
3403
1992
|
if (idx1) {
|
|
3404
1993
|
if (idx2) {
|
|
3405
|
-
for (
|
|
1994
|
+
for (; i--;) {
|
|
3406
1995
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3407
|
-
|
|
3408
|
-
SET_DATA_INDEX(p2, idx2,
|
|
1996
|
+
y = m_imag(x);
|
|
1997
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3409
1998
|
}
|
|
3410
1999
|
} else {
|
|
3411
|
-
for (
|
|
2000
|
+
for (; i--;) {
|
|
3412
2001
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3413
|
-
|
|
3414
|
-
SET_DATA_STRIDE(p2, s2,
|
|
2002
|
+
y = m_imag(x);
|
|
2003
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3415
2004
|
}
|
|
3416
2005
|
}
|
|
3417
2006
|
} else {
|
|
3418
2007
|
if (idx2) {
|
|
3419
|
-
for (
|
|
2008
|
+
for (; i--;) {
|
|
3420
2009
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3421
|
-
|
|
3422
|
-
SET_DATA_INDEX(p2, idx2,
|
|
2010
|
+
y = m_imag(x);
|
|
2011
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3423
2012
|
}
|
|
3424
2013
|
} else {
|
|
3425
|
-
|
|
3426
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
3427
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
3428
|
-
for (i = 0; i < n; i++) {
|
|
3429
|
-
((dtype*)p2)[i] = m_round(((dtype*)p1)[i]);
|
|
3430
|
-
}
|
|
3431
|
-
return;
|
|
3432
|
-
}
|
|
3433
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
3434
|
-
//
|
|
3435
|
-
for (i = 0; i < n; i++) {
|
|
3436
|
-
*(dtype*)p2 = m_round(*(dtype*)p1);
|
|
3437
|
-
p1 += s1;
|
|
3438
|
-
p2 += s2;
|
|
3439
|
-
}
|
|
3440
|
-
return;
|
|
3441
|
-
//
|
|
3442
|
-
}
|
|
3443
|
-
}
|
|
3444
|
-
for (i = 0; i < n; i++) {
|
|
2014
|
+
for (; i--;) {
|
|
3445
2015
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3446
|
-
|
|
3447
|
-
SET_DATA_STRIDE(p2, s2,
|
|
2016
|
+
y = m_imag(x);
|
|
2017
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3448
2018
|
}
|
|
3449
|
-
//
|
|
3450
2019
|
}
|
|
3451
2020
|
}
|
|
3452
2021
|
}
|
|
3453
2022
|
|
|
3454
2023
|
/*
|
|
3455
|
-
|
|
3456
|
-
@overload
|
|
3457
|
-
@return [Numo::
|
|
2024
|
+
imag of self.
|
|
2025
|
+
@overload imag
|
|
2026
|
+
@return [Numo::SFloat] imag of self.
|
|
3458
2027
|
*/
|
|
3459
|
-
static VALUE
|
|
2028
|
+
static VALUE scomplex_imag(VALUE self) {
|
|
3460
2029
|
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3461
|
-
ndfunc_arg_out_t aout[1] = { {
|
|
3462
|
-
ndfunc_t ndf = {
|
|
2030
|
+
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
2031
|
+
ndfunc_t ndf = { iter_scomplex_imag, FULL_LOOP, 1, 1, ain, aout };
|
|
3463
2032
|
|
|
3464
2033
|
return na_ndloop(&ndf, 1, self);
|
|
3465
2034
|
}
|
|
3466
2035
|
|
|
3467
|
-
static void
|
|
3468
|
-
size_t i
|
|
2036
|
+
static void iter_scomplex_arg(na_loop_t* const lp) {
|
|
2037
|
+
size_t i;
|
|
3469
2038
|
char *p1, *p2;
|
|
3470
2039
|
ssize_t s1, s2;
|
|
3471
2040
|
size_t *idx1, *idx2;
|
|
3472
2041
|
dtype x;
|
|
3473
|
-
|
|
3474
|
-
INIT_COUNTER(lp,
|
|
2042
|
+
rtype y;
|
|
2043
|
+
INIT_COUNTER(lp, i);
|
|
3475
2044
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3476
2045
|
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3477
|
-
|
|
3478
2046
|
if (idx1) {
|
|
3479
2047
|
if (idx2) {
|
|
3480
|
-
for (
|
|
2048
|
+
for (; i--;) {
|
|
3481
2049
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3482
|
-
|
|
3483
|
-
SET_DATA_INDEX(p2, idx2,
|
|
2050
|
+
y = m_arg(x);
|
|
2051
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3484
2052
|
}
|
|
3485
2053
|
} else {
|
|
3486
|
-
for (
|
|
2054
|
+
for (; i--;) {
|
|
3487
2055
|
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3488
|
-
|
|
3489
|
-
SET_DATA_STRIDE(p2, s2,
|
|
2056
|
+
y = m_arg(x);
|
|
2057
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3490
2058
|
}
|
|
3491
2059
|
}
|
|
3492
2060
|
} else {
|
|
3493
2061
|
if (idx2) {
|
|
3494
|
-
for (
|
|
2062
|
+
for (; i--;) {
|
|
3495
2063
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3496
|
-
|
|
3497
|
-
SET_DATA_INDEX(p2, idx2,
|
|
2064
|
+
y = m_arg(x);
|
|
2065
|
+
SET_DATA_INDEX(p2, idx2, rtype, y);
|
|
3498
2066
|
}
|
|
3499
2067
|
} else {
|
|
3500
|
-
|
|
3501
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
3502
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
3503
|
-
for (i = 0; i < n; i++) {
|
|
3504
|
-
((dtype*)p2)[i] = m_ceil(((dtype*)p1)[i]);
|
|
3505
|
-
}
|
|
3506
|
-
return;
|
|
3507
|
-
}
|
|
3508
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
3509
|
-
//
|
|
3510
|
-
for (i = 0; i < n; i++) {
|
|
3511
|
-
*(dtype*)p2 = m_ceil(*(dtype*)p1);
|
|
3512
|
-
p1 += s1;
|
|
3513
|
-
p2 += s2;
|
|
3514
|
-
}
|
|
3515
|
-
return;
|
|
3516
|
-
//
|
|
3517
|
-
}
|
|
3518
|
-
}
|
|
3519
|
-
for (i = 0; i < n; i++) {
|
|
2068
|
+
for (; i--;) {
|
|
3520
2069
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3521
|
-
|
|
3522
|
-
SET_DATA_STRIDE(p2, s2,
|
|
2070
|
+
y = m_arg(x);
|
|
2071
|
+
SET_DATA_STRIDE(p2, s2, rtype, y);
|
|
3523
2072
|
}
|
|
3524
|
-
//
|
|
3525
2073
|
}
|
|
3526
2074
|
}
|
|
3527
2075
|
}
|
|
3528
2076
|
|
|
3529
2077
|
/*
|
|
3530
|
-
|
|
3531
|
-
@overload
|
|
3532
|
-
@return [Numo::
|
|
2078
|
+
arg of self.
|
|
2079
|
+
@overload arg
|
|
2080
|
+
@return [Numo::SFloat] arg of self.
|
|
3533
2081
|
*/
|
|
3534
|
-
static VALUE
|
|
2082
|
+
static VALUE scomplex_arg(VALUE self) {
|
|
3535
2083
|
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3536
|
-
ndfunc_arg_out_t aout[1] = { {
|
|
3537
|
-
ndfunc_t ndf = {
|
|
2084
|
+
ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
|
|
2085
|
+
ndfunc_t ndf = { iter_scomplex_arg, FULL_LOOP, 1, 1, ain, aout };
|
|
3538
2086
|
|
|
3539
2087
|
return na_ndloop(&ndf, 1, self);
|
|
3540
2088
|
}
|
|
3541
2089
|
|
|
3542
|
-
static void
|
|
3543
|
-
size_t i
|
|
2090
|
+
static void iter_scomplex_set_imag(na_loop_t* const lp) {
|
|
2091
|
+
size_t i;
|
|
3544
2092
|
char *p1, *p2;
|
|
3545
2093
|
ssize_t s1, s2;
|
|
3546
2094
|
size_t *idx1, *idx2;
|
|
3547
2095
|
dtype x;
|
|
3548
|
-
|
|
3549
|
-
INIT_COUNTER(lp,
|
|
2096
|
+
rtype y;
|
|
2097
|
+
INIT_COUNTER(lp, i);
|
|
3550
2098
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3551
2099
|
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3552
|
-
|
|
3553
2100
|
if (idx1) {
|
|
3554
2101
|
if (idx2) {
|
|
3555
|
-
for (
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
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);
|
|
3559
2107
|
}
|
|
3560
2108
|
} else {
|
|
3561
|
-
for (
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
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);
|
|
3565
2114
|
}
|
|
3566
2115
|
}
|
|
3567
2116
|
} else {
|
|
3568
2117
|
if (idx2) {
|
|
3569
|
-
for (
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
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);
|
|
3573
2123
|
}
|
|
3574
2124
|
} else {
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
}
|
|
3581
|
-
return;
|
|
3582
|
-
}
|
|
3583
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
3584
|
-
//
|
|
3585
|
-
for (i = 0; i < n; i++) {
|
|
3586
|
-
*(dtype*)p2 = m_trunc(*(dtype*)p1);
|
|
3587
|
-
p1 += s1;
|
|
3588
|
-
p2 += s2;
|
|
3589
|
-
}
|
|
3590
|
-
return;
|
|
3591
|
-
//
|
|
3592
|
-
}
|
|
3593
|
-
}
|
|
3594
|
-
for (i = 0; i < n; i++) {
|
|
3595
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3596
|
-
x = m_trunc(x);
|
|
3597
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
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);
|
|
3598
2130
|
}
|
|
3599
|
-
//
|
|
3600
2131
|
}
|
|
3601
2132
|
}
|
|
3602
2133
|
}
|
|
3603
2134
|
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
@return [Numo::SComplex] trunc of self.
|
|
3608
|
-
*/
|
|
3609
|
-
static VALUE scomplex_trunc(VALUE self) {
|
|
3610
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3611
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3612
|
-
ndfunc_t ndf = { iter_scomplex_trunc, FULL_LOOP, 1, 1, ain, aout };
|
|
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 };
|
|
3613
2138
|
|
|
3614
|
-
|
|
2139
|
+
na_ndloop(&ndf, 2, self, a1);
|
|
2140
|
+
return a1;
|
|
3615
2141
|
}
|
|
3616
2142
|
|
|
3617
|
-
static void
|
|
3618
|
-
size_t i
|
|
2143
|
+
static void iter_scomplex_set_real(na_loop_t* const lp) {
|
|
2144
|
+
size_t i;
|
|
3619
2145
|
char *p1, *p2;
|
|
3620
2146
|
ssize_t s1, s2;
|
|
3621
2147
|
size_t *idx1, *idx2;
|
|
3622
2148
|
dtype x;
|
|
3623
|
-
|
|
3624
|
-
INIT_COUNTER(lp,
|
|
2149
|
+
rtype y;
|
|
2150
|
+
INIT_COUNTER(lp, i);
|
|
3625
2151
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3626
2152
|
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
3627
|
-
|
|
3628
2153
|
if (idx1) {
|
|
3629
2154
|
if (idx2) {
|
|
3630
|
-
for (
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
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);
|
|
3634
2160
|
}
|
|
3635
2161
|
} else {
|
|
3636
|
-
for (
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
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);
|
|
3640
2167
|
}
|
|
3641
2168
|
}
|
|
3642
2169
|
} else {
|
|
3643
2170
|
if (idx2) {
|
|
3644
|
-
for (
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
} else {
|
|
3650
|
-
//
|
|
3651
|
-
if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
|
|
3652
|
-
if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
|
|
3653
|
-
for (i = 0; i < n; i++) {
|
|
3654
|
-
((dtype*)p2)[i] = m_rint(((dtype*)p1)[i]);
|
|
3655
|
-
}
|
|
3656
|
-
return;
|
|
3657
|
-
}
|
|
3658
|
-
if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
|
|
3659
|
-
//
|
|
3660
|
-
for (i = 0; i < n; i++) {
|
|
3661
|
-
*(dtype*)p2 = m_rint(*(dtype*)p1);
|
|
3662
|
-
p1 += s1;
|
|
3663
|
-
p2 += s2;
|
|
3664
|
-
}
|
|
3665
|
-
return;
|
|
3666
|
-
//
|
|
3667
|
-
}
|
|
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);
|
|
3668
2176
|
}
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
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);
|
|
3673
2183
|
}
|
|
3674
|
-
//
|
|
3675
2184
|
}
|
|
3676
2185
|
}
|
|
3677
2186
|
}
|
|
3678
2187
|
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
@return [Numo::SComplex] rint of self.
|
|
3683
|
-
*/
|
|
3684
|
-
static VALUE scomplex_rint(VALUE self) {
|
|
3685
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3686
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3687
|
-
ndfunc_t ndf = { iter_scomplex_rint, FULL_LOOP, 1, 1, ain, aout };
|
|
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 };
|
|
3688
2191
|
|
|
3689
|
-
|
|
2192
|
+
na_ndloop(&ndf, 2, self, a1);
|
|
2193
|
+
return a1;
|
|
3690
2194
|
}
|
|
3691
2195
|
|
|
3692
2196
|
#define check_intdivzero(y) \
|
|
@@ -3807,288 +2311,6 @@ static VALUE scomplex_copysign(VALUE self, VALUE other) {
|
|
|
3807
2311
|
}
|
|
3808
2312
|
}
|
|
3809
2313
|
|
|
3810
|
-
static void iter_scomplex_isnan(na_loop_t* const lp) {
|
|
3811
|
-
size_t i;
|
|
3812
|
-
char* p1;
|
|
3813
|
-
BIT_DIGIT* a2;
|
|
3814
|
-
size_t p2;
|
|
3815
|
-
ssize_t s1, s2;
|
|
3816
|
-
size_t* idx1;
|
|
3817
|
-
dtype x;
|
|
3818
|
-
BIT_DIGIT b;
|
|
3819
|
-
INIT_COUNTER(lp, i);
|
|
3820
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3821
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3822
|
-
if (idx1) {
|
|
3823
|
-
for (; i--;) {
|
|
3824
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3825
|
-
b = (m_isnan(x)) ? 1 : 0;
|
|
3826
|
-
STORE_BIT(a2, p2, b);
|
|
3827
|
-
p2 += s2;
|
|
3828
|
-
}
|
|
3829
|
-
} else {
|
|
3830
|
-
for (; i--;) {
|
|
3831
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3832
|
-
b = (m_isnan(x)) ? 1 : 0;
|
|
3833
|
-
STORE_BIT(a2, p2, b);
|
|
3834
|
-
p2 += s2;
|
|
3835
|
-
}
|
|
3836
|
-
}
|
|
3837
|
-
}
|
|
3838
|
-
|
|
3839
|
-
/*
|
|
3840
|
-
Condition of isnan.
|
|
3841
|
-
@overload isnan
|
|
3842
|
-
@return [Numo::Bit] Condition of isnan.
|
|
3843
|
-
*/
|
|
3844
|
-
static VALUE scomplex_isnan(VALUE self) {
|
|
3845
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3846
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3847
|
-
ndfunc_t ndf = { iter_scomplex_isnan, FULL_LOOP, 1, 1, ain, aout };
|
|
3848
|
-
|
|
3849
|
-
return na_ndloop(&ndf, 1, self);
|
|
3850
|
-
}
|
|
3851
|
-
|
|
3852
|
-
static void iter_scomplex_isinf(na_loop_t* const lp) {
|
|
3853
|
-
size_t i;
|
|
3854
|
-
char* p1;
|
|
3855
|
-
BIT_DIGIT* a2;
|
|
3856
|
-
size_t p2;
|
|
3857
|
-
ssize_t s1, s2;
|
|
3858
|
-
size_t* idx1;
|
|
3859
|
-
dtype x;
|
|
3860
|
-
BIT_DIGIT b;
|
|
3861
|
-
INIT_COUNTER(lp, i);
|
|
3862
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3863
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3864
|
-
if (idx1) {
|
|
3865
|
-
for (; i--;) {
|
|
3866
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3867
|
-
b = (m_isinf(x)) ? 1 : 0;
|
|
3868
|
-
STORE_BIT(a2, p2, b);
|
|
3869
|
-
p2 += s2;
|
|
3870
|
-
}
|
|
3871
|
-
} else {
|
|
3872
|
-
for (; i--;) {
|
|
3873
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3874
|
-
b = (m_isinf(x)) ? 1 : 0;
|
|
3875
|
-
STORE_BIT(a2, p2, b);
|
|
3876
|
-
p2 += s2;
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3879
|
-
}
|
|
3880
|
-
|
|
3881
|
-
/*
|
|
3882
|
-
Condition of isinf.
|
|
3883
|
-
@overload isinf
|
|
3884
|
-
@return [Numo::Bit] Condition of isinf.
|
|
3885
|
-
*/
|
|
3886
|
-
static VALUE scomplex_isinf(VALUE self) {
|
|
3887
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3888
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3889
|
-
ndfunc_t ndf = { iter_scomplex_isinf, FULL_LOOP, 1, 1, ain, aout };
|
|
3890
|
-
|
|
3891
|
-
return na_ndloop(&ndf, 1, self);
|
|
3892
|
-
}
|
|
3893
|
-
|
|
3894
|
-
static void iter_scomplex_isposinf(na_loop_t* const lp) {
|
|
3895
|
-
size_t i;
|
|
3896
|
-
char* p1;
|
|
3897
|
-
BIT_DIGIT* a2;
|
|
3898
|
-
size_t p2;
|
|
3899
|
-
ssize_t s1, s2;
|
|
3900
|
-
size_t* idx1;
|
|
3901
|
-
dtype x;
|
|
3902
|
-
BIT_DIGIT b;
|
|
3903
|
-
INIT_COUNTER(lp, i);
|
|
3904
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3905
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3906
|
-
if (idx1) {
|
|
3907
|
-
for (; i--;) {
|
|
3908
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3909
|
-
b = (m_isposinf(x)) ? 1 : 0;
|
|
3910
|
-
STORE_BIT(a2, p2, b);
|
|
3911
|
-
p2 += s2;
|
|
3912
|
-
}
|
|
3913
|
-
} else {
|
|
3914
|
-
for (; i--;) {
|
|
3915
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3916
|
-
b = (m_isposinf(x)) ? 1 : 0;
|
|
3917
|
-
STORE_BIT(a2, p2, b);
|
|
3918
|
-
p2 += s2;
|
|
3919
|
-
}
|
|
3920
|
-
}
|
|
3921
|
-
}
|
|
3922
|
-
|
|
3923
|
-
/*
|
|
3924
|
-
Condition of isposinf.
|
|
3925
|
-
@overload isposinf
|
|
3926
|
-
@return [Numo::Bit] Condition of isposinf.
|
|
3927
|
-
*/
|
|
3928
|
-
static VALUE scomplex_isposinf(VALUE self) {
|
|
3929
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3930
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3931
|
-
ndfunc_t ndf = { iter_scomplex_isposinf, FULL_LOOP, 1, 1, ain, aout };
|
|
3932
|
-
|
|
3933
|
-
return na_ndloop(&ndf, 1, self);
|
|
3934
|
-
}
|
|
3935
|
-
|
|
3936
|
-
static void iter_scomplex_isneginf(na_loop_t* const lp) {
|
|
3937
|
-
size_t i;
|
|
3938
|
-
char* p1;
|
|
3939
|
-
BIT_DIGIT* a2;
|
|
3940
|
-
size_t p2;
|
|
3941
|
-
ssize_t s1, s2;
|
|
3942
|
-
size_t* idx1;
|
|
3943
|
-
dtype x;
|
|
3944
|
-
BIT_DIGIT b;
|
|
3945
|
-
INIT_COUNTER(lp, i);
|
|
3946
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3947
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3948
|
-
if (idx1) {
|
|
3949
|
-
for (; i--;) {
|
|
3950
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3951
|
-
b = (m_isneginf(x)) ? 1 : 0;
|
|
3952
|
-
STORE_BIT(a2, p2, b);
|
|
3953
|
-
p2 += s2;
|
|
3954
|
-
}
|
|
3955
|
-
} else {
|
|
3956
|
-
for (; i--;) {
|
|
3957
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3958
|
-
b = (m_isneginf(x)) ? 1 : 0;
|
|
3959
|
-
STORE_BIT(a2, p2, b);
|
|
3960
|
-
p2 += s2;
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3963
|
-
}
|
|
3964
|
-
|
|
3965
|
-
/*
|
|
3966
|
-
Condition of isneginf.
|
|
3967
|
-
@overload isneginf
|
|
3968
|
-
@return [Numo::Bit] Condition of isneginf.
|
|
3969
|
-
*/
|
|
3970
|
-
static VALUE scomplex_isneginf(VALUE self) {
|
|
3971
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3972
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3973
|
-
ndfunc_t ndf = { iter_scomplex_isneginf, FULL_LOOP, 1, 1, ain, aout };
|
|
3974
|
-
|
|
3975
|
-
return na_ndloop(&ndf, 1, self);
|
|
3976
|
-
}
|
|
3977
|
-
|
|
3978
|
-
static void iter_scomplex_isfinite(na_loop_t* const lp) {
|
|
3979
|
-
size_t i;
|
|
3980
|
-
char* p1;
|
|
3981
|
-
BIT_DIGIT* a2;
|
|
3982
|
-
size_t p2;
|
|
3983
|
-
ssize_t s1, s2;
|
|
3984
|
-
size_t* idx1;
|
|
3985
|
-
dtype x;
|
|
3986
|
-
BIT_DIGIT b;
|
|
3987
|
-
INIT_COUNTER(lp, i);
|
|
3988
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3989
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3990
|
-
if (idx1) {
|
|
3991
|
-
for (; i--;) {
|
|
3992
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3993
|
-
b = (m_isfinite(x)) ? 1 : 0;
|
|
3994
|
-
STORE_BIT(a2, p2, b);
|
|
3995
|
-
p2 += s2;
|
|
3996
|
-
}
|
|
3997
|
-
} else {
|
|
3998
|
-
for (; i--;) {
|
|
3999
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4000
|
-
b = (m_isfinite(x)) ? 1 : 0;
|
|
4001
|
-
STORE_BIT(a2, p2, b);
|
|
4002
|
-
p2 += s2;
|
|
4003
|
-
}
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
|
|
4007
|
-
/*
|
|
4008
|
-
Condition of isfinite.
|
|
4009
|
-
@overload isfinite
|
|
4010
|
-
@return [Numo::Bit] Condition of isfinite.
|
|
4011
|
-
*/
|
|
4012
|
-
static VALUE scomplex_isfinite(VALUE self) {
|
|
4013
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
4014
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
4015
|
-
ndfunc_t ndf = { iter_scomplex_isfinite, FULL_LOOP, 1, 1, ain, aout };
|
|
4016
|
-
|
|
4017
|
-
return na_ndloop(&ndf, 1, self);
|
|
4018
|
-
}
|
|
4019
|
-
|
|
4020
|
-
typedef struct {
|
|
4021
|
-
dtype mu;
|
|
4022
|
-
rtype sigma;
|
|
4023
|
-
} randn_opt_t;
|
|
4024
|
-
|
|
4025
|
-
static void iter_scomplex_rand_norm(na_loop_t* const lp) {
|
|
4026
|
-
size_t i;
|
|
4027
|
-
char* p1;
|
|
4028
|
-
ssize_t s1;
|
|
4029
|
-
size_t* idx1;
|
|
4030
|
-
|
|
4031
|
-
dtype* a0;
|
|
4032
|
-
|
|
4033
|
-
dtype mu;
|
|
4034
|
-
rtype sigma;
|
|
4035
|
-
randn_opt_t* g;
|
|
4036
|
-
|
|
4037
|
-
INIT_COUNTER(lp, i);
|
|
4038
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4039
|
-
g = (randn_opt_t*)(lp->opt_ptr);
|
|
4040
|
-
mu = g->mu;
|
|
4041
|
-
sigma = g->sigma;
|
|
4042
|
-
|
|
4043
|
-
if (idx1) {
|
|
4044
|
-
|
|
4045
|
-
for (; i--;) {
|
|
4046
|
-
a0 = (dtype*)(p1 + *idx1);
|
|
4047
|
-
m_rand_norm(mu, sigma, a0);
|
|
4048
|
-
idx1 += 1;
|
|
4049
|
-
}
|
|
4050
|
-
|
|
4051
|
-
} else {
|
|
4052
|
-
|
|
4053
|
-
for (; i--;) {
|
|
4054
|
-
a0 = (dtype*)(p1);
|
|
4055
|
-
m_rand_norm(mu, sigma, a0);
|
|
4056
|
-
p1 += s1;
|
|
4057
|
-
}
|
|
4058
|
-
}
|
|
4059
|
-
}
|
|
4060
|
-
|
|
4061
|
-
/*
|
|
4062
|
-
Generates random numbers from the normal distribution on self narray
|
|
4063
|
-
using Box-Muller Transformation.
|
|
4064
|
-
|
|
4065
|
-
@overload rand_norm([mu,[sigma]])
|
|
4066
|
-
@param [Numeric] mu mean of normal distribution. (default=0)
|
|
4067
|
-
@param [Numeric] sigma standard deviation of normal distribution. (default=1)
|
|
4068
|
-
@return [Numo::SComplex] self.
|
|
4069
|
-
*/
|
|
4070
|
-
static VALUE scomplex_rand_norm(int argc, VALUE* argv, VALUE self) {
|
|
4071
|
-
int n;
|
|
4072
|
-
randn_opt_t g;
|
|
4073
|
-
VALUE v1 = Qnil, v2 = Qnil;
|
|
4074
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4075
|
-
ndfunc_t ndf = { iter_scomplex_rand_norm, FULL_LOOP, 1, 0, ain, 0 };
|
|
4076
|
-
|
|
4077
|
-
n = rb_scan_args(argc, argv, "02", &v1, &v2);
|
|
4078
|
-
if (n == 0) {
|
|
4079
|
-
g.mu = m_zero;
|
|
4080
|
-
} else {
|
|
4081
|
-
g.mu = m_num_to_data(v1);
|
|
4082
|
-
}
|
|
4083
|
-
if (n == 2) {
|
|
4084
|
-
g.sigma = NUM2DBL(v2);
|
|
4085
|
-
} else {
|
|
4086
|
-
g.sigma = 1;
|
|
4087
|
-
}
|
|
4088
|
-
na_ndloop3(&ndf, &g, 1, self);
|
|
4089
|
-
return self;
|
|
4090
|
-
}
|
|
4091
|
-
|
|
4092
2314
|
static void iter_scomplex_poly(na_loop_t* const lp) {
|
|
4093
2315
|
size_t i;
|
|
4094
2316
|
dtype x, y, a;
|
|
@@ -4212,26 +2434,109 @@ void Init_numo_scomplex(void) {
|
|
|
4212
2434
|
rb_define_singleton_method(cT, "cast", scomplex_s_cast, 1);
|
|
4213
2435
|
rb_define_method(cT, "[]", scomplex_aref, -1);
|
|
4214
2436
|
rb_define_method(cT, "[]=", scomplex_aset, -1);
|
|
2437
|
+
/**
|
|
2438
|
+
* return NArray with cast to the type of self.
|
|
2439
|
+
* @overload coerce_cast(type)
|
|
2440
|
+
* @return [nil]
|
|
2441
|
+
*/
|
|
4215
2442
|
rb_define_method(cT, "coerce_cast", scomplex_coerce_cast, 1);
|
|
2443
|
+
/**
|
|
2444
|
+
* Convert self to Array.
|
|
2445
|
+
* @overload to_a
|
|
2446
|
+
* @return [Array]
|
|
2447
|
+
*/
|
|
4216
2448
|
rb_define_method(cT, "to_a", scomplex_to_a, 0);
|
|
2449
|
+
/**
|
|
2450
|
+
* Fill elements with other.
|
|
2451
|
+
* @overload fill other
|
|
2452
|
+
* @param [Numeric] other
|
|
2453
|
+
* @return [Numo::SComplex] self.
|
|
2454
|
+
*/
|
|
4217
2455
|
rb_define_method(cT, "fill", scomplex_fill, 1);
|
|
2456
|
+
/**
|
|
2457
|
+
* Format elements into strings.
|
|
2458
|
+
* @overload format format
|
|
2459
|
+
* @param [String] format
|
|
2460
|
+
* @return [Numo::RObject] array of formatted strings.
|
|
2461
|
+
*/
|
|
4218
2462
|
rb_define_method(cT, "format", scomplex_format, -1);
|
|
2463
|
+
/**
|
|
2464
|
+
* Format elements into strings.
|
|
2465
|
+
* @overload format_to_a format
|
|
2466
|
+
* @param [String] format
|
|
2467
|
+
* @return [Array] array of formatted strings.
|
|
2468
|
+
*/
|
|
4219
2469
|
rb_define_method(cT, "format_to_a", scomplex_format_to_a, -1);
|
|
2470
|
+
/**
|
|
2471
|
+
* Returns a string containing a human-readable representation of NArray.
|
|
2472
|
+
* @overload inspect
|
|
2473
|
+
* @return [String]
|
|
2474
|
+
*/
|
|
4220
2475
|
rb_define_method(cT, "inspect", scomplex_inspect, 0);
|
|
4221
2476
|
rb_define_method(cT, "each", scomplex_each, 0);
|
|
4222
2477
|
rb_define_method(cT, "map", scomplex_map, 0);
|
|
4223
2478
|
rb_define_method(cT, "each_with_index", scomplex_each_with_index, 0);
|
|
4224
2479
|
rb_define_method(cT, "map_with_index", scomplex_map_with_index, 0);
|
|
4225
2480
|
rb_define_method(cT, "abs", scomplex_abs, 0);
|
|
2481
|
+
/**
|
|
2482
|
+
* Binary add.
|
|
2483
|
+
* @overload + other
|
|
2484
|
+
* @param [Numo::NArray,Numeric] other
|
|
2485
|
+
* @return [Numo::NArray] self + other
|
|
2486
|
+
*/
|
|
4226
2487
|
rb_define_method(cT, "+", scomplex_add, 1);
|
|
2488
|
+
/**
|
|
2489
|
+
* Binary sub.
|
|
2490
|
+
* @overload - other
|
|
2491
|
+
* @param [Numo::NArray,Numeric] other
|
|
2492
|
+
* @return [Numo::NArray] self - other
|
|
2493
|
+
*/
|
|
4227
2494
|
rb_define_method(cT, "-", scomplex_sub, 1);
|
|
2495
|
+
/**
|
|
2496
|
+
* Binary mul.
|
|
2497
|
+
* @overload * other
|
|
2498
|
+
* @param [Numo::NArray,Numeric] other
|
|
2499
|
+
* @return [Numo::NArray] self * other
|
|
2500
|
+
*/
|
|
4228
2501
|
rb_define_method(cT, "*", scomplex_mul, 1);
|
|
2502
|
+
/**
|
|
2503
|
+
* Binary div.
|
|
2504
|
+
* @overload / other
|
|
2505
|
+
* @param [Numo::NArray,Numeric] other
|
|
2506
|
+
* @return [Numo::NArray] self / other
|
|
2507
|
+
*/
|
|
4229
2508
|
rb_define_method(cT, "/", scomplex_div, 1);
|
|
2509
|
+
/**
|
|
2510
|
+
* Binary power.
|
|
2511
|
+
* @overload ** other
|
|
2512
|
+
* @param [Numo::NArray,Numeric] other
|
|
2513
|
+
* @return [Numo::NArray] self to the other-th power.
|
|
2514
|
+
*/
|
|
4230
2515
|
rb_define_method(cT, "**", scomplex_pow, 1);
|
|
4231
2516
|
rb_define_alias(cT, "pow", "**");
|
|
2517
|
+
/**
|
|
2518
|
+
* Unary minus.
|
|
2519
|
+
* @overload -@
|
|
2520
|
+
* @return [Numo::SComplex] minus of self.
|
|
2521
|
+
*/
|
|
4232
2522
|
rb_define_method(cT, "-@", scomplex_minus, 0);
|
|
2523
|
+
/**
|
|
2524
|
+
* Unary reciprocal.
|
|
2525
|
+
* @overload reciprocal
|
|
2526
|
+
* @return [Numo::SComplex] reciprocal of self.
|
|
2527
|
+
*/
|
|
4233
2528
|
rb_define_method(cT, "reciprocal", scomplex_reciprocal, 0);
|
|
2529
|
+
/**
|
|
2530
|
+
* Unary sign.
|
|
2531
|
+
* @overload sign
|
|
2532
|
+
* @return [Numo::SComplex] sign of self.
|
|
2533
|
+
*/
|
|
4234
2534
|
rb_define_method(cT, "sign", scomplex_sign, 0);
|
|
2535
|
+
/**
|
|
2536
|
+
* Unary square.
|
|
2537
|
+
* @overload square
|
|
2538
|
+
* @return [Numo::SComplex] square of self.
|
|
2539
|
+
*/
|
|
4235
2540
|
rb_define_method(cT, "square", scomplex_square, 0);
|
|
4236
2541
|
rb_define_method(cT, "conj", scomplex_conj, 0);
|
|
4237
2542
|
rb_define_method(cT, "im", scomplex_im, 0);
|
|
@@ -4244,20 +2549,88 @@ void Init_numo_scomplex(void) {
|
|
|
4244
2549
|
rb_define_alias(cT, "imag=", "set_imag");
|
|
4245
2550
|
rb_define_alias(cT, "real=", "set_real");
|
|
4246
2551
|
rb_define_alias(cT, "conjugate", "conj");
|
|
2552
|
+
/**
|
|
2553
|
+
* Comparison eq other.
|
|
2554
|
+
* @overload eq other
|
|
2555
|
+
* @param [Numo::NArray,Numeric] other
|
|
2556
|
+
* @return [Numo::Bit] result of self eq other.
|
|
2557
|
+
*/
|
|
4247
2558
|
rb_define_method(cT, "eq", scomplex_eq, 1);
|
|
2559
|
+
/**
|
|
2560
|
+
* Comparison ne other.
|
|
2561
|
+
* @overload ne other
|
|
2562
|
+
* @param [Numo::NArray,Numeric] other
|
|
2563
|
+
* @return [Numo::Bit] result of self ne other.
|
|
2564
|
+
*/
|
|
4248
2565
|
rb_define_method(cT, "ne", scomplex_ne, 1);
|
|
2566
|
+
/**
|
|
2567
|
+
* Comparison nearly_eq other.
|
|
2568
|
+
* @overload nearly_eq other
|
|
2569
|
+
* @param [Numo::NArray,Numeric] other
|
|
2570
|
+
* @return [Numo::Bit] result of self nearly_eq other.
|
|
2571
|
+
*/
|
|
4249
2572
|
rb_define_method(cT, "nearly_eq", scomplex_nearly_eq, 1);
|
|
4250
2573
|
rb_define_alias(cT, "close_to", "nearly_eq");
|
|
2574
|
+
/**
|
|
2575
|
+
* Unary floor.
|
|
2576
|
+
* @overload floor
|
|
2577
|
+
* @return [Numo::SComplex] floor of self.
|
|
2578
|
+
*/
|
|
4251
2579
|
rb_define_method(cT, "floor", scomplex_floor, 0);
|
|
2580
|
+
/**
|
|
2581
|
+
* Unary round.
|
|
2582
|
+
* @overload round
|
|
2583
|
+
* @return [Numo::SComplex] round of self.
|
|
2584
|
+
*/
|
|
4252
2585
|
rb_define_method(cT, "round", scomplex_round, 0);
|
|
2586
|
+
/**
|
|
2587
|
+
* Unary ceil.
|
|
2588
|
+
* @overload ceil
|
|
2589
|
+
* @return [Numo::SComplex] ceil of self.
|
|
2590
|
+
*/
|
|
4253
2591
|
rb_define_method(cT, "ceil", scomplex_ceil, 0);
|
|
2592
|
+
/**
|
|
2593
|
+
* Unary trunc.
|
|
2594
|
+
* @overload trunc
|
|
2595
|
+
* @return [Numo::SComplex] trunc of self.
|
|
2596
|
+
*/
|
|
4254
2597
|
rb_define_method(cT, "trunc", scomplex_trunc, 0);
|
|
2598
|
+
/**
|
|
2599
|
+
* Unary rint.
|
|
2600
|
+
* @overload rint
|
|
2601
|
+
* @return [Numo::SComplex] rint of self.
|
|
2602
|
+
*/
|
|
4255
2603
|
rb_define_method(cT, "rint", scomplex_rint, 0);
|
|
4256
2604
|
rb_define_method(cT, "copysign", scomplex_copysign, 1);
|
|
2605
|
+
/**
|
|
2606
|
+
* Condition of isnan.
|
|
2607
|
+
* @overload isnan
|
|
2608
|
+
* @return [Numo::Bit] Condition of isnan.
|
|
2609
|
+
*/
|
|
4257
2610
|
rb_define_method(cT, "isnan", scomplex_isnan, 0);
|
|
2611
|
+
/**
|
|
2612
|
+
* Condition of isinf.
|
|
2613
|
+
* @overload isinf
|
|
2614
|
+
* @return [Numo::Bit] Condition of isinf.
|
|
2615
|
+
*/
|
|
4258
2616
|
rb_define_method(cT, "isinf", scomplex_isinf, 0);
|
|
2617
|
+
/**
|
|
2618
|
+
* Condition of isposinf.
|
|
2619
|
+
* @overload isposinf
|
|
2620
|
+
* @return [Numo::Bit] Condition of isposinf.
|
|
2621
|
+
*/
|
|
4259
2622
|
rb_define_method(cT, "isposinf", scomplex_isposinf, 0);
|
|
2623
|
+
/**
|
|
2624
|
+
* Condition of isneginf.
|
|
2625
|
+
* @overload isneginf
|
|
2626
|
+
* @return [Numo::Bit] Condition of isneginf.
|
|
2627
|
+
*/
|
|
4260
2628
|
rb_define_method(cT, "isneginf", scomplex_isneginf, 0);
|
|
2629
|
+
/**
|
|
2630
|
+
* Condition of isfinite.
|
|
2631
|
+
* @overload isfinite
|
|
2632
|
+
* @return [Numo::Bit] Condition of isfinite.
|
|
2633
|
+
*/
|
|
4261
2634
|
rb_define_method(cT, "isfinite", scomplex_isfinite, 0);
|
|
4262
2635
|
/**
|
|
4263
2636
|
* sum of self.
|
|
@@ -4426,6 +2799,15 @@ void Init_numo_scomplex(void) {
|
|
|
4426
2799
|
* # [4, 3, 3, 2, 4, 2]
|
|
4427
2800
|
*/
|
|
4428
2801
|
rb_define_method(cT, "rand", scomplex_rand, -1);
|
|
2802
|
+
/**
|
|
2803
|
+
* Generates random numbers from the normal distribution on self narray
|
|
2804
|
+
* using Box-Muller Transformation.
|
|
2805
|
+
*
|
|
2806
|
+
* @overload rand_norm([mu,[sigma]])
|
|
2807
|
+
* @param [Numeric] mu mean of normal distribution. (default=0)
|
|
2808
|
+
* @param [Numeric] sigma standard deviation of normal distribution. (default=1)
|
|
2809
|
+
* @return [Numo::SComplex] self.
|
|
2810
|
+
*/
|
|
4429
2811
|
rb_define_method(cT, "rand_norm", scomplex_rand_norm, -1);
|
|
4430
2812
|
rb_define_method(cT, "poly", scomplex_poly, -2);
|
|
4431
2813
|
rb_define_singleton_method(cT, "[]", scomplex_s_cast, -2);
|