numo-narray-alt 0.9.10 → 0.9.12

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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/LICENSE +1 -1
  4. data/README.md +7 -0
  5. data/ext/numo/narray/numo/narray.h +2 -2
  6. data/ext/numo/narray/numo/types/robj_macro.h +1 -1
  7. data/ext/numo/narray/numo/types/robject.h +1 -1
  8. data/ext/numo/narray/src/mh/argmax.h +154 -0
  9. data/ext/numo/narray/src/mh/argmin.h +154 -0
  10. data/ext/numo/narray/src/mh/bincount.h +233 -0
  11. data/ext/numo/narray/src/mh/bit/and.h +225 -0
  12. data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
  13. data/ext/numo/narray/src/mh/bit/not.h +173 -0
  14. data/ext/numo/narray/src/mh/bit/or.h +225 -0
  15. data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
  16. data/ext/numo/narray/src/mh/bit/xor.h +225 -0
  17. data/ext/numo/narray/src/mh/clip.h +115 -0
  18. data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
  19. data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
  20. data/ext/numo/narray/src/mh/comp/eq.h +26 -0
  21. data/ext/numo/narray/src/mh/comp/ge.h +26 -0
  22. data/ext/numo/narray/src/mh/comp/gt.h +26 -0
  23. data/ext/numo/narray/src/mh/comp/le.h +26 -0
  24. data/ext/numo/narray/src/mh/comp/lt.h +26 -0
  25. data/ext/numo/narray/src/mh/comp/ne.h +26 -0
  26. data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
  27. data/ext/numo/narray/src/mh/cumprod.h +98 -0
  28. data/ext/numo/narray/src/mh/cumsum.h +98 -0
  29. data/ext/numo/narray/src/mh/divmod.h +142 -0
  30. data/ext/numo/narray/src/mh/eye.h +82 -0
  31. data/ext/numo/narray/src/mh/fill.h +94 -0
  32. data/ext/numo/narray/src/mh/format.h +108 -0
  33. data/ext/numo/narray/src/mh/format_to_a.h +89 -0
  34. data/ext/numo/narray/src/mh/inspect.h +33 -0
  35. data/ext/numo/narray/src/mh/isfinite.h +42 -0
  36. data/ext/numo/narray/src/mh/isinf.h +42 -0
  37. data/ext/numo/narray/src/mh/isnan.h +42 -0
  38. data/ext/numo/narray/src/mh/isneginf.h +42 -0
  39. data/ext/numo/narray/src/mh/isposinf.h +42 -0
  40. data/ext/numo/narray/src/mh/logseq.h +69 -0
  41. data/ext/numo/narray/src/mh/math/acos.h +2 -2
  42. data/ext/numo/narray/src/mh/math/acosh.h +2 -2
  43. data/ext/numo/narray/src/mh/math/asin.h +2 -2
  44. data/ext/numo/narray/src/mh/math/asinh.h +2 -2
  45. data/ext/numo/narray/src/mh/math/atan.h +2 -2
  46. data/ext/numo/narray/src/mh/math/atan2.h +3 -3
  47. data/ext/numo/narray/src/mh/math/atanh.h +2 -2
  48. data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
  49. data/ext/numo/narray/src/mh/math/cos.h +2 -2
  50. data/ext/numo/narray/src/mh/math/cosh.h +2 -2
  51. data/ext/numo/narray/src/mh/math/erf.h +2 -2
  52. data/ext/numo/narray/src/mh/math/erfc.h +2 -2
  53. data/ext/numo/narray/src/mh/math/exp.h +2 -2
  54. data/ext/numo/narray/src/mh/math/exp10.h +2 -2
  55. data/ext/numo/narray/src/mh/math/exp2.h +2 -2
  56. data/ext/numo/narray/src/mh/math/expm1.h +2 -2
  57. data/ext/numo/narray/src/mh/math/frexp.h +3 -3
  58. data/ext/numo/narray/src/mh/math/hypot.h +3 -3
  59. data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
  60. data/ext/numo/narray/src/mh/math/log.h +2 -2
  61. data/ext/numo/narray/src/mh/math/log10.h +2 -2
  62. data/ext/numo/narray/src/mh/math/log1p.h +2 -2
  63. data/ext/numo/narray/src/mh/math/log2.h +2 -2
  64. data/ext/numo/narray/src/mh/math/sin.h +2 -2
  65. data/ext/numo/narray/src/mh/math/sinc.h +2 -2
  66. data/ext/numo/narray/src/mh/math/sinh.h +2 -2
  67. data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
  68. data/ext/numo/narray/src/mh/math/tan.h +2 -2
  69. data/ext/numo/narray/src/mh/math/tanh.h +2 -2
  70. data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
  71. data/ext/numo/narray/src/mh/max.h +69 -0
  72. data/ext/numo/narray/src/mh/max_index.h +184 -0
  73. data/ext/numo/narray/src/mh/maximum.h +116 -0
  74. data/ext/numo/narray/src/mh/min.h +69 -0
  75. data/ext/numo/narray/src/mh/min_index.h +184 -0
  76. data/ext/numo/narray/src/mh/minimum.h +116 -0
  77. data/ext/numo/narray/src/mh/minmax.h +77 -0
  78. data/ext/numo/narray/src/mh/mulsum.h +185 -0
  79. data/ext/numo/narray/src/mh/op/add.h +78 -0
  80. data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
  81. data/ext/numo/narray/src/mh/op/div.h +118 -0
  82. data/ext/numo/narray/src/mh/op/mod.h +108 -0
  83. data/ext/numo/narray/src/mh/op/mul.h +78 -0
  84. data/ext/numo/narray/src/mh/op/sub.h +78 -0
  85. data/ext/numo/narray/src/mh/prod.h +69 -0
  86. data/ext/numo/narray/src/mh/ptp.h +69 -0
  87. data/ext/numo/narray/src/mh/rand.h +315 -0
  88. data/ext/numo/narray/src/mh/round/ceil.h +11 -0
  89. data/ext/numo/narray/src/mh/round/floor.h +11 -0
  90. data/ext/numo/narray/src/mh/round/rint.h +9 -0
  91. data/ext/numo/narray/src/mh/round/round.h +11 -0
  92. data/ext/numo/narray/src/mh/round/trunc.h +11 -0
  93. data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
  94. data/ext/numo/narray/src/mh/seq.h +130 -0
  95. data/ext/numo/narray/src/mh/sum.h +69 -0
  96. data/ext/numo/narray/src/mh/to_a.h +78 -0
  97. data/ext/numo/narray/src/t_bit.c +45 -234
  98. data/ext/numo/narray/src/t_dcomplex.c +608 -2369
  99. data/ext/numo/narray/src/t_dfloat.c +485 -3736
  100. data/ext/numo/narray/src/t_int16.c +743 -3444
  101. data/ext/numo/narray/src/t_int32.c +745 -3445
  102. data/ext/numo/narray/src/t_int64.c +743 -3446
  103. data/ext/numo/narray/src/t_int8.c +678 -3040
  104. data/ext/numo/narray/src/t_robject.c +771 -3548
  105. data/ext/numo/narray/src/t_scomplex.c +607 -2368
  106. data/ext/numo/narray/src/t_sfloat.c +440 -3693
  107. data/ext/numo/narray/src/t_uint16.c +743 -3440
  108. data/ext/numo/narray/src/t_uint32.c +743 -3440
  109. data/ext/numo/narray/src/t_uint64.c +743 -3442
  110. data/ext/numo/narray/src/t_uint8.c +678 -3038
  111. data/lib/numo/narray.rb +2 -3
  112. metadata +62 -3
@@ -38,10 +38,42 @@ 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/comp/eq.h"
52
+ #include "mh/comp/ne.h"
53
+ #include "mh/comp/nearly_eq.h"
54
+ #include "mh/round/floor.h"
55
+ #include "mh/round/round.h"
56
+ #include "mh/round/ceil.h"
57
+ #include "mh/round/trunc.h"
58
+ #include "mh/round/rint.h"
59
+ #include "mh/isnan.h"
60
+ #include "mh/isinf.h"
61
+ #include "mh/isposinf.h"
62
+ #include "mh/isneginf.h"
63
+ #include "mh/isfinite.h"
64
+ #include "mh/sum.h"
65
+ #include "mh/prod.h"
41
66
  #include "mh/mean.h"
42
67
  #include "mh/var.h"
43
68
  #include "mh/stddev.h"
44
69
  #include "mh/rms.h"
70
+ #include "mh/cumsum.h"
71
+ #include "mh/cumprod.h"
72
+ #include "mh/mulsum.h"
73
+ #include "mh/seq.h"
74
+ #include "mh/logseq.h"
75
+ #include "mh/eye.h"
76
+ #include "mh/rand.h"
45
77
  #include "mh/math/sqrt.h"
46
78
  #include "mh/math/cbrt.h"
47
79
  #include "mh/math/log.h"
@@ -64,10 +96,42 @@ extern VALUE cRT;
64
96
  #include "mh/math/atanh.h"
65
97
  #include "mh/math/sinc.h"
66
98
 
99
+ DEF_NARRAY_COERCE_CAST_METHOD_FUNC(scomplex)
100
+ DEF_NARRAY_TO_A_METHOD_FUNC(scomplex)
101
+ DEF_NARRAY_FILL_METHOD_FUNC(scomplex)
102
+ DEF_NARRAY_FORMAT_METHOD_FUNC(scomplex)
103
+ DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(scomplex)
104
+ DEF_NARRAY_INSPECT_METHOD_FUNC(scomplex)
105
+ DEF_NARRAY_ADD_METHOD_FUNC(scomplex, numo_cSComplex)
106
+ DEF_NARRAY_SUB_METHOD_FUNC(scomplex, numo_cSComplex)
107
+ DEF_NARRAY_MUL_METHOD_FUNC(scomplex, numo_cSComplex)
108
+ DEF_NARRAY_FLT_DIV_METHOD_FUNC(scomplex, numo_cSComplex)
109
+ DEF_NARRAY_EQ_METHOD_FUNC(scomplex, numo_cSComplex)
110
+ DEF_NARRAY_NE_METHOD_FUNC(scomplex, numo_cSComplex)
111
+ DEF_NARRAY_NEARLY_EQ_METHOD_FUNC(scomplex, numo_cSComplex)
112
+ DEF_NARRAY_FLT_FLOOR_METHOD_FUNC(scomplex, numo_cSComplex)
113
+ DEF_NARRAY_FLT_ROUND_METHOD_FUNC(scomplex, numo_cSComplex)
114
+ DEF_NARRAY_FLT_CEIL_METHOD_FUNC(scomplex, numo_cSComplex)
115
+ DEF_NARRAY_FLT_TRUNC_METHOD_FUNC(scomplex, numo_cSComplex)
116
+ DEF_NARRAY_FLT_RINT_METHOD_FUNC(scomplex, numo_cSComplex)
117
+ DEF_NARRAY_FLT_ISNAN_METHOD_FUNC(scomplex, numo_cSComplex)
118
+ DEF_NARRAY_FLT_ISINF_METHOD_FUNC(scomplex, numo_cSComplex)
119
+ DEF_NARRAY_FLT_ISPOSINF_METHOD_FUNC(scomplex, numo_cSComplex)
120
+ DEF_NARRAY_FLT_ISNEGINF_METHOD_FUNC(scomplex, numo_cSComplex)
121
+ DEF_NARRAY_FLT_ISFINITE_METHOD_FUNC(scomplex, numo_cSComplex)
122
+ DEF_NARRAY_FLT_SUM_METHOD_FUNC(scomplex, numo_cSComplex)
123
+ DEF_NARRAY_FLT_PROD_METHOD_FUNC(scomplex, numo_cSComplex)
67
124
  DEF_NARRAY_FLT_MEAN_METHOD_FUNC(scomplex, numo_cSComplex, scomplex, numo_cSComplex)
68
125
  DEF_NARRAY_FLT_VAR_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
69
126
  DEF_NARRAY_FLT_STDDEV_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
70
127
  DEF_NARRAY_FLT_RMS_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
128
+ DEF_NARRAY_FLT_CUMSUM_METHOD_FUNC(scomplex, numo_cSComplex)
129
+ DEF_NARRAY_FLT_CUMPROD_METHOD_FUNC(scomplex, numo_cSComplex)
130
+ DEF_NARRAY_FLT_MULSUM_METHOD_FUNC(scomplex, numo_cSComplex)
131
+ DEF_NARRAY_FLT_SEQ_METHOD_FUNC(scomplex)
132
+ DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(scomplex)
133
+ DEF_NARRAY_EYE_METHOD_FUNC(scomplex)
134
+ DEF_NARRAY_CMP_RAND_METHOD_FUNC(scomplex)
71
135
  DEF_NARRAY_FLT_SQRT_METHOD_FUNC(scomplex, numo_cSComplex)
72
136
  DEF_NARRAY_FLT_CBRT_METHOD_FUNC(scomplex, numo_cSComplex)
73
137
  DEF_NARRAY_FLT_LOG_METHOD_FUNC(scomplex, numo_cSComplex)
@@ -1373,204 +1437,6 @@ static VALUE scomplex_aset(int argc, VALUE* argv, VALUE self) {
1373
1437
  return argv[argc];
1374
1438
  }
1375
1439
 
1376
- /*
1377
- return NArray with cast to the type of self.
1378
- @overload coerce_cast(type)
1379
- @return [nil]
1380
- */
1381
- static VALUE scomplex_coerce_cast(VALUE self, VALUE type) {
1382
- return Qnil;
1383
- }
1384
-
1385
- static void iter_scomplex_to_a(na_loop_t* const lp) {
1386
- size_t i, s1;
1387
- char* p1;
1388
- size_t* idx1;
1389
- dtype x;
1390
- volatile VALUE a, y;
1391
-
1392
- INIT_COUNTER(lp, i);
1393
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1394
- a = rb_ary_new2(i);
1395
- rb_ary_push(lp->args[1].value, a);
1396
- if (idx1) {
1397
- for (; i--;) {
1398
- GET_DATA_INDEX(p1, idx1, dtype, x);
1399
- y = m_data_to_num(x);
1400
- rb_ary_push(a, y);
1401
- }
1402
- } else {
1403
- for (; i--;) {
1404
- GET_DATA_STRIDE(p1, s1, dtype, x);
1405
- y = m_data_to_num(x);
1406
- rb_ary_push(a, y);
1407
- }
1408
- }
1409
- }
1410
-
1411
- /*
1412
- Convert self to Array.
1413
- @overload to_a
1414
- @return [Array]
1415
- */
1416
- static VALUE scomplex_to_a(VALUE self) {
1417
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1418
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1419
- ndfunc_t ndf = { iter_scomplex_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1420
- return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
1421
- }
1422
-
1423
- static void iter_scomplex_fill(na_loop_t* const lp) {
1424
- size_t i;
1425
- char* p1;
1426
- ssize_t s1;
1427
- size_t* idx1;
1428
- VALUE x = lp->option;
1429
- dtype y;
1430
- INIT_COUNTER(lp, i);
1431
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1432
- y = m_num_to_data(x);
1433
- if (idx1) {
1434
- for (; i--;) {
1435
- SET_DATA_INDEX(p1, idx1, dtype, y);
1436
- }
1437
- } else {
1438
- for (; i--;) {
1439
- SET_DATA_STRIDE(p1, s1, dtype, y);
1440
- }
1441
- }
1442
- }
1443
-
1444
- /*
1445
- Fill elements with other.
1446
- @overload fill other
1447
- @param [Numeric] other
1448
- @return [Numo::SComplex] self.
1449
- */
1450
- static VALUE scomplex_fill(VALUE self, VALUE val) {
1451
- ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
1452
- ndfunc_t ndf = { iter_scomplex_fill, FULL_LOOP, 2, 0, ain, 0 };
1453
-
1454
- na_ndloop(&ndf, 2, self, val);
1455
- return self;
1456
- }
1457
-
1458
- static VALUE format_scomplex(VALUE fmt, dtype* x) {
1459
- // fix-me
1460
- char s[48];
1461
- int n;
1462
-
1463
- if (NIL_P(fmt)) {
1464
- n = m_sprintf(s, *x);
1465
- return rb_str_new(s, n);
1466
- }
1467
- return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
1468
- }
1469
-
1470
- static void iter_scomplex_format(na_loop_t* const lp) {
1471
- size_t i;
1472
- char *p1, *p2;
1473
- ssize_t s1, s2;
1474
- size_t* idx1;
1475
- dtype* x;
1476
- VALUE y;
1477
- VALUE fmt = lp->option;
1478
- INIT_COUNTER(lp, i);
1479
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1480
- INIT_PTR(lp, 1, p2, s2);
1481
- if (idx1) {
1482
- for (; i--;) {
1483
- x = (dtype*)(p1 + *idx1);
1484
- idx1++;
1485
- y = format_scomplex(fmt, x);
1486
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1487
- }
1488
- } else {
1489
- for (; i--;) {
1490
- x = (dtype*)p1;
1491
- p1 += s1;
1492
- y = format_scomplex(fmt, x);
1493
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1494
- }
1495
- }
1496
- }
1497
-
1498
- /*
1499
- Format elements into strings.
1500
- @overload format format
1501
- @param [String] format
1502
- @return [Numo::RObject] array of formatted strings.
1503
- */
1504
- static VALUE scomplex_format(int argc, VALUE* argv, VALUE self) {
1505
- VALUE fmt = Qnil;
1506
-
1507
- ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
1508
- ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
1509
- ndfunc_t ndf = { iter_scomplex_format, FULL_LOOP_NIP, 2, 1, ain, aout };
1510
-
1511
- rb_scan_args(argc, argv, "01", &fmt);
1512
- return na_ndloop(&ndf, 2, self, fmt);
1513
- }
1514
-
1515
- static void iter_scomplex_format_to_a(na_loop_t* const lp) {
1516
- size_t i;
1517
- char* p1;
1518
- ssize_t s1;
1519
- size_t* idx1;
1520
- dtype* x;
1521
- VALUE y;
1522
- volatile VALUE a;
1523
- VALUE fmt = lp->option;
1524
- INIT_COUNTER(lp, i);
1525
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1526
- a = rb_ary_new2(i);
1527
- rb_ary_push(lp->args[1].value, a);
1528
- if (idx1) {
1529
- for (; i--;) {
1530
- x = (dtype*)(p1 + *idx1);
1531
- idx1++;
1532
- y = format_scomplex(fmt, x);
1533
- rb_ary_push(a, y);
1534
- }
1535
- } else {
1536
- for (; i--;) {
1537
- x = (dtype*)p1;
1538
- p1 += s1;
1539
- y = format_scomplex(fmt, x);
1540
- rb_ary_push(a, y);
1541
- }
1542
- }
1543
- }
1544
-
1545
- /*
1546
- Format elements into strings.
1547
- @overload format_to_a format
1548
- @param [String] format
1549
- @return [Array] array of formatted strings.
1550
- */
1551
- static VALUE scomplex_format_to_a(int argc, VALUE* argv, VALUE self) {
1552
- VALUE fmt = Qnil;
1553
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1554
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1555
- ndfunc_t ndf = { iter_scomplex_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1556
-
1557
- rb_scan_args(argc, argv, "01", &fmt);
1558
- return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
1559
- }
1560
-
1561
- static VALUE iter_scomplex_inspect(char* ptr, size_t pos, VALUE fmt) {
1562
- return format_scomplex(fmt, (dtype*)(ptr + pos));
1563
- }
1564
-
1565
- /*
1566
- Returns a string containing a human-readable representation of NArray.
1567
- @overload inspect
1568
- @return [String]
1569
- */
1570
- static VALUE scomplex_inspect(VALUE ary) {
1571
- return na_ndloop_inspect(ary, iter_scomplex_inspect, Qnil);
1572
- }
1573
-
1574
1440
  static void iter_scomplex_each(na_loop_t* const lp) {
1575
1441
  size_t i, s1;
1576
1442
  char* p1;
@@ -1897,568 +1763,246 @@ static VALUE scomplex_abs(VALUE self) {
1897
1763
  return na_ndloop(&ndf, 1, self);
1898
1764
  }
1899
1765
 
1900
- #define check_intdivzero(y) \
1901
- {}
1902
-
1903
- static void iter_scomplex_add(na_loop_t* const lp) {
1904
- size_t i = 0;
1905
- size_t n;
1766
+ static void iter_scomplex_pow(na_loop_t* const lp) {
1767
+ size_t i;
1906
1768
  char *p1, *p2, *p3;
1907
1769
  ssize_t s1, s2, s3;
1908
-
1909
- INIT_COUNTER(lp, n);
1770
+ dtype x, y;
1771
+ INIT_COUNTER(lp, i);
1910
1772
  INIT_PTR(lp, 0, p1, s1);
1911
1773
  INIT_PTR(lp, 1, p2, s2);
1912
1774
  INIT_PTR(lp, 2, p3, s3);
1913
-
1914
- //
1915
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
1916
- is_aligned(p3, sizeof(dtype))) {
1917
-
1918
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
1919
- if (p1 == p3) { // inplace case
1920
- for (; i < n; i++) {
1921
- check_intdivzero(((dtype*)p2)[i]);
1922
- ((dtype*)p1)[i] = m_add(((dtype*)p1)[i], ((dtype*)p2)[i]);
1923
- }
1924
- } else {
1925
- for (; i < n; i++) {
1926
- check_intdivzero(((dtype*)p2)[i]);
1927
- ((dtype*)p3)[i] = m_add(((dtype*)p1)[i], ((dtype*)p2)[i]);
1928
- }
1929
- }
1930
- return;
1931
- }
1932
-
1933
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
1934
- is_aligned_step(s3, sizeof(dtype))) {
1935
- //
1936
-
1937
- if (s2 == 0) { // Broadcasting from scalar value.
1938
- check_intdivzero(*(dtype*)p2);
1939
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
1940
- if (p1 == p3) { // inplace case
1941
- for (; i < n; i++) {
1942
- ((dtype*)p1)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
1943
- }
1944
- } else {
1945
- for (; i < n; i++) {
1946
- ((dtype*)p3)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
1947
- }
1948
- }
1949
- } else {
1950
- for (i = 0; i < n; i++) {
1951
- *(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
1952
- p1 += s1;
1953
- p3 += s3;
1954
- }
1955
- }
1956
- } else {
1957
- if (p1 == p3) { // inplace case
1958
- for (i = 0; i < n; i++) {
1959
- check_intdivzero(*(dtype*)p2);
1960
- *(dtype*)p1 = m_add(*(dtype*)p1, *(dtype*)p2);
1961
- p1 += s1;
1962
- p2 += s2;
1963
- }
1964
- } else {
1965
- for (i = 0; i < n; i++) {
1966
- check_intdivzero(*(dtype*)p2);
1967
- *(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
1968
- p1 += s1;
1969
- p2 += s2;
1970
- p3 += s3;
1971
- }
1972
- }
1973
- }
1974
-
1975
- return;
1976
- //
1977
- }
1978
- }
1979
- for (i = 0; i < n; i++) {
1980
- dtype x, y, z;
1775
+ for (; i--;) {
1981
1776
  GET_DATA_STRIDE(p1, s1, dtype, x);
1982
1777
  GET_DATA_STRIDE(p2, s2, dtype, y);
1983
- check_intdivzero(y);
1984
- z = m_add(x, y);
1985
- SET_DATA_STRIDE(p3, s3, dtype, z);
1778
+ x = m_pow(x, y);
1779
+ SET_DATA_STRIDE(p3, s3, dtype, x);
1780
+ }
1781
+ }
1782
+
1783
+ static void iter_scomplex_pow_int32(na_loop_t* const lp) {
1784
+ size_t i;
1785
+ char *p1, *p2, *p3;
1786
+ ssize_t s1, s2, s3;
1787
+ dtype x;
1788
+ int32_t y;
1789
+ INIT_COUNTER(lp, i);
1790
+ INIT_PTR(lp, 0, p1, s1);
1791
+ INIT_PTR(lp, 1, p2, s2);
1792
+ INIT_PTR(lp, 2, p3, s3);
1793
+ for (; i--;) {
1794
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1795
+ GET_DATA_STRIDE(p2, s2, int32_t, y);
1796
+ x = m_pow_int(x, y);
1797
+ SET_DATA_STRIDE(p3, s3, dtype, x);
1986
1798
  }
1987
- //
1988
1799
  }
1989
- #undef check_intdivzero
1990
1800
 
1991
- static VALUE scomplex_add_self(VALUE self, VALUE other) {
1801
+ static VALUE scomplex_pow_self(VALUE self, VALUE other) {
1992
1802
  ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
1803
+ ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
1993
1804
  ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1994
- ndfunc_t ndf = { iter_scomplex_add, STRIDE_LOOP, 2, 1, ain, aout };
1805
+ ndfunc_t ndf = { iter_scomplex_pow, STRIDE_LOOP, 2, 1, ain, aout };
1806
+ ndfunc_t ndf_i = { iter_scomplex_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
1995
1807
 
1996
- return na_ndloop(&ndf, 2, self, other);
1808
+ // fixme : use na.integer?
1809
+ if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
1810
+ return na_ndloop(&ndf_i, 2, self, other);
1811
+ } else {
1812
+ return na_ndloop(&ndf, 2, self, other);
1813
+ }
1997
1814
  }
1998
1815
 
1999
1816
  /*
2000
- Binary add.
2001
- @overload + other
1817
+ Binary power.
1818
+ @overload ** other
2002
1819
  @param [Numo::NArray,Numeric] other
2003
- @return [Numo::NArray] self + other
1820
+ @return [Numo::NArray] self to the other-th power.
2004
1821
  */
2005
- static VALUE scomplex_add(VALUE self, VALUE other) {
1822
+ static VALUE scomplex_pow(VALUE self, VALUE other) {
2006
1823
 
2007
1824
  VALUE klass, v;
2008
-
2009
1825
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
2010
1826
  if (klass == cT) {
2011
- return scomplex_add_self(self, other);
1827
+ return scomplex_pow_self(self, other);
2012
1828
  } else {
2013
1829
  v = rb_funcall(klass, id_cast, 1, self);
2014
- return rb_funcall(v, '+', 1, other);
1830
+ return rb_funcall(v, id_pow, 1, other);
2015
1831
  }
2016
1832
  }
2017
1833
 
2018
- #define check_intdivzero(y) \
2019
- {}
2020
-
2021
- static void iter_scomplex_sub(na_loop_t* const lp) {
2022
- size_t i = 0;
2023
- size_t n;
2024
- char *p1, *p2, *p3;
2025
- ssize_t s1, s2, s3;
1834
+ static void iter_scomplex_minus(na_loop_t* const lp) {
1835
+ size_t i, n;
1836
+ char *p1, *p2;
1837
+ ssize_t s1, s2;
1838
+ size_t *idx1, *idx2;
1839
+ dtype x;
2026
1840
 
2027
1841
  INIT_COUNTER(lp, n);
2028
- INIT_PTR(lp, 0, p1, s1);
2029
- INIT_PTR(lp, 1, p2, s2);
2030
- INIT_PTR(lp, 2, p3, s3);
2031
-
2032
- //
2033
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
2034
- is_aligned(p3, sizeof(dtype))) {
1842
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1843
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2035
1844
 
2036
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
2037
- if (p1 == p3) { // inplace case
2038
- for (; i < n; i++) {
2039
- check_intdivzero(((dtype*)p2)[i]);
2040
- ((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], ((dtype*)p2)[i]);
2041
- }
2042
- } else {
2043
- for (; i < n; i++) {
2044
- check_intdivzero(((dtype*)p2)[i]);
2045
- ((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], ((dtype*)p2)[i]);
2046
- }
2047
- }
2048
- return;
1845
+ if (idx1) {
1846
+ if (idx2) {
1847
+ for (i = 0; i < n; i++) {
1848
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1849
+ x = m_minus(x);
1850
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1851
+ }
1852
+ } else {
1853
+ for (i = 0; i < n; i++) {
1854
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1855
+ x = m_minus(x);
1856
+ SET_DATA_STRIDE(p2, s2, dtype, x);
1857
+ }
2049
1858
  }
2050
-
2051
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
2052
- is_aligned_step(s3, sizeof(dtype))) {
1859
+ } else {
1860
+ if (idx2) {
1861
+ for (i = 0; i < n; i++) {
1862
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1863
+ x = m_minus(x);
1864
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1865
+ }
1866
+ } else {
2053
1867
  //
2054
-
2055
- if (s2 == 0) { // Broadcasting from scalar value.
2056
- check_intdivzero(*(dtype*)p2);
2057
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2058
- if (p1 == p3) { // inplace case
2059
- for (; i < n; i++) {
2060
- ((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
2061
- }
2062
- } else {
2063
- for (; i < n; i++) {
2064
- ((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
2065
- }
2066
- }
2067
- } else {
1868
+ if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
1869
+ if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2068
1870
  for (i = 0; i < n; i++) {
2069
- *(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
2070
- p1 += s1;
2071
- p3 += s3;
1871
+ ((dtype*)p2)[i] = m_minus(((dtype*)p1)[i]);
2072
1872
  }
1873
+ return;
2073
1874
  }
2074
- } else {
2075
- if (p1 == p3) { // inplace case
2076
- for (i = 0; i < n; i++) {
2077
- check_intdivzero(*(dtype*)p2);
2078
- *(dtype*)p1 = m_sub(*(dtype*)p1, *(dtype*)p2);
2079
- p1 += s1;
2080
- p2 += s2;
2081
- }
2082
- } else {
1875
+ if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
1876
+ //
2083
1877
  for (i = 0; i < n; i++) {
2084
- check_intdivzero(*(dtype*)p2);
2085
- *(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
1878
+ *(dtype*)p2 = m_minus(*(dtype*)p1);
2086
1879
  p1 += s1;
2087
1880
  p2 += s2;
2088
- p3 += s3;
2089
1881
  }
1882
+ return;
1883
+ //
2090
1884
  }
2091
1885
  }
2092
-
2093
- return;
1886
+ for (i = 0; i < n; i++) {
1887
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1888
+ x = m_minus(x);
1889
+ SET_DATA_STRIDE(p2, s2, dtype, x);
1890
+ }
2094
1891
  //
2095
1892
  }
2096
1893
  }
2097
- for (i = 0; i < n; i++) {
2098
- dtype x, y, z;
2099
- GET_DATA_STRIDE(p1, s1, dtype, x);
2100
- GET_DATA_STRIDE(p2, s2, dtype, y);
2101
- check_intdivzero(y);
2102
- z = m_sub(x, y);
2103
- SET_DATA_STRIDE(p3, s3, dtype, z);
2104
- }
2105
- //
2106
- }
2107
- #undef check_intdivzero
2108
-
2109
- static VALUE scomplex_sub_self(VALUE self, VALUE other) {
2110
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2111
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2112
- ndfunc_t ndf = { iter_scomplex_sub, STRIDE_LOOP, 2, 1, ain, aout };
2113
-
2114
- return na_ndloop(&ndf, 2, self, other);
2115
1894
  }
2116
1895
 
2117
1896
  /*
2118
- Binary sub.
2119
- @overload - other
2120
- @param [Numo::NArray,Numeric] other
2121
- @return [Numo::NArray] self - other
1897
+ Unary minus.
1898
+ @overload -@
1899
+ @return [Numo::SComplex] minus of self.
2122
1900
  */
2123
- static VALUE scomplex_sub(VALUE self, VALUE other) {
2124
-
2125
- VALUE klass, v;
1901
+ static VALUE scomplex_minus(VALUE self) {
1902
+ ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1903
+ ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1904
+ ndfunc_t ndf = { iter_scomplex_minus, FULL_LOOP, 1, 1, ain, aout };
2126
1905
 
2127
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
2128
- if (klass == cT) {
2129
- return scomplex_sub_self(self, other);
2130
- } else {
2131
- v = rb_funcall(klass, id_cast, 1, self);
2132
- return rb_funcall(v, '-', 1, other);
2133
- }
1906
+ return na_ndloop(&ndf, 1, self);
2134
1907
  }
2135
1908
 
2136
- #define check_intdivzero(y) \
2137
- {}
2138
-
2139
- static void iter_scomplex_mul(na_loop_t* const lp) {
2140
- size_t i = 0;
2141
- size_t n;
2142
- char *p1, *p2, *p3;
2143
- ssize_t s1, s2, s3;
1909
+ static void iter_scomplex_reciprocal(na_loop_t* const lp) {
1910
+ size_t i, n;
1911
+ char *p1, *p2;
1912
+ ssize_t s1, s2;
1913
+ size_t *idx1, *idx2;
1914
+ dtype x;
2144
1915
 
2145
1916
  INIT_COUNTER(lp, n);
2146
- INIT_PTR(lp, 0, p1, s1);
2147
- INIT_PTR(lp, 1, p2, s2);
2148
- INIT_PTR(lp, 2, p3, s3);
2149
-
2150
- //
2151
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
2152
- is_aligned(p3, sizeof(dtype))) {
1917
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1918
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2153
1919
 
2154
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
2155
- if (p1 == p3) { // inplace case
2156
- for (; i < n; i++) {
2157
- check_intdivzero(((dtype*)p2)[i]);
2158
- ((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], ((dtype*)p2)[i]);
2159
- }
2160
- } else {
2161
- for (; i < n; i++) {
2162
- check_intdivzero(((dtype*)p2)[i]);
2163
- ((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], ((dtype*)p2)[i]);
2164
- }
1920
+ if (idx1) {
1921
+ if (idx2) {
1922
+ for (i = 0; i < n; i++) {
1923
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1924
+ x = m_reciprocal(x);
1925
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1926
+ }
1927
+ } else {
1928
+ for (i = 0; i < n; i++) {
1929
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1930
+ x = m_reciprocal(x);
1931
+ SET_DATA_STRIDE(p2, s2, dtype, x);
2165
1932
  }
2166
- return;
2167
1933
  }
2168
-
2169
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
2170
- is_aligned_step(s3, sizeof(dtype))) {
1934
+ } else {
1935
+ if (idx2) {
1936
+ for (i = 0; i < n; i++) {
1937
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1938
+ x = m_reciprocal(x);
1939
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1940
+ }
1941
+ } else {
2171
1942
  //
2172
-
2173
- if (s2 == 0) { // Broadcasting from scalar value.
2174
- check_intdivzero(*(dtype*)p2);
2175
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2176
- if (p1 == p3) { // inplace case
2177
- for (; i < n; i++) {
2178
- ((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
2179
- }
2180
- } else {
2181
- for (; i < n; i++) {
2182
- ((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
2183
- }
2184
- }
2185
- } else {
1943
+ if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
1944
+ if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2186
1945
  for (i = 0; i < n; i++) {
2187
- *(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
2188
- p1 += s1;
2189
- p3 += s3;
1946
+ ((dtype*)p2)[i] = m_reciprocal(((dtype*)p1)[i]);
2190
1947
  }
1948
+ return;
2191
1949
  }
2192
- } else {
2193
- if (p1 == p3) { // inplace case
2194
- for (i = 0; i < n; i++) {
2195
- check_intdivzero(*(dtype*)p2);
2196
- *(dtype*)p1 = m_mul(*(dtype*)p1, *(dtype*)p2);
2197
- p1 += s1;
2198
- p2 += s2;
2199
- }
2200
- } else {
1950
+ if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
1951
+ //
2201
1952
  for (i = 0; i < n; i++) {
2202
- check_intdivzero(*(dtype*)p2);
2203
- *(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
1953
+ *(dtype*)p2 = m_reciprocal(*(dtype*)p1);
2204
1954
  p1 += s1;
2205
1955
  p2 += s2;
2206
- p3 += s3;
2207
1956
  }
1957
+ return;
1958
+ //
2208
1959
  }
2209
1960
  }
2210
-
2211
- return;
1961
+ for (i = 0; i < n; i++) {
1962
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1963
+ x = m_reciprocal(x);
1964
+ SET_DATA_STRIDE(p2, s2, dtype, x);
1965
+ }
2212
1966
  //
2213
1967
  }
2214
1968
  }
2215
- for (i = 0; i < n; i++) {
2216
- dtype x, y, z;
2217
- GET_DATA_STRIDE(p1, s1, dtype, x);
2218
- GET_DATA_STRIDE(p2, s2, dtype, y);
2219
- check_intdivzero(y);
2220
- z = m_mul(x, y);
2221
- SET_DATA_STRIDE(p3, s3, dtype, z);
2222
- }
2223
- //
2224
- }
2225
- #undef check_intdivzero
2226
-
2227
- static VALUE scomplex_mul_self(VALUE self, VALUE other) {
2228
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2229
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2230
- ndfunc_t ndf = { iter_scomplex_mul, STRIDE_LOOP, 2, 1, ain, aout };
2231
-
2232
- return na_ndloop(&ndf, 2, self, other);
2233
1969
  }
2234
1970
 
2235
1971
  /*
2236
- Binary mul.
2237
- @overload * other
2238
- @param [Numo::NArray,Numeric] other
2239
- @return [Numo::NArray] self * other
1972
+ Unary reciprocal.
1973
+ @overload reciprocal
1974
+ @return [Numo::SComplex] reciprocal of self.
2240
1975
  */
2241
- static VALUE scomplex_mul(VALUE self, VALUE other) {
2242
-
2243
- VALUE klass, v;
1976
+ static VALUE scomplex_reciprocal(VALUE self) {
1977
+ ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1978
+ ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1979
+ ndfunc_t ndf = { iter_scomplex_reciprocal, FULL_LOOP, 1, 1, ain, aout };
2244
1980
 
2245
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
2246
- if (klass == cT) {
2247
- return scomplex_mul_self(self, other);
2248
- } else {
2249
- v = rb_funcall(klass, id_cast, 1, self);
2250
- return rb_funcall(v, '*', 1, other);
2251
- }
1981
+ return na_ndloop(&ndf, 1, self);
2252
1982
  }
2253
1983
 
2254
- #define check_intdivzero(y) \
2255
- {}
2256
-
2257
- static void iter_scomplex_div(na_loop_t* const lp) {
2258
- size_t i = 0;
2259
- size_t n;
2260
- char *p1, *p2, *p3;
2261
- ssize_t s1, s2, s3;
1984
+ static void iter_scomplex_sign(na_loop_t* const lp) {
1985
+ size_t i, n;
1986
+ char *p1, *p2;
1987
+ ssize_t s1, s2;
1988
+ size_t *idx1, *idx2;
1989
+ dtype x;
2262
1990
 
2263
1991
  INIT_COUNTER(lp, n);
2264
- INIT_PTR(lp, 0, p1, s1);
2265
- INIT_PTR(lp, 1, p2, s2);
2266
- INIT_PTR(lp, 2, p3, s3);
2267
-
2268
- //
2269
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
2270
- is_aligned(p3, sizeof(dtype))) {
2271
-
2272
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
2273
- if (p1 == p3) { // inplace case
2274
- for (; i < n; i++) {
2275
- check_intdivzero(((dtype*)p2)[i]);
2276
- ((dtype*)p1)[i] = m_div(((dtype*)p1)[i], ((dtype*)p2)[i]);
2277
- }
2278
- } else {
2279
- for (; i < n; i++) {
2280
- check_intdivzero(((dtype*)p2)[i]);
2281
- ((dtype*)p3)[i] = m_div(((dtype*)p1)[i], ((dtype*)p2)[i]);
2282
- }
2283
- }
2284
- return;
2285
- }
2286
-
2287
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
2288
- is_aligned_step(s3, sizeof(dtype))) {
2289
- //
2290
-
2291
- if (s2 == 0) { // Broadcasting from scalar value.
2292
- check_intdivzero(*(dtype*)p2);
2293
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2294
- if (p1 == p3) { // inplace case
2295
- for (; i < n; i++) {
2296
- ((dtype*)p1)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
2297
- }
2298
- } else {
2299
- for (; i < n; i++) {
2300
- ((dtype*)p3)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
2301
- }
2302
- }
2303
- } else {
2304
- for (i = 0; i < n; i++) {
2305
- *(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
2306
- p1 += s1;
2307
- p3 += s3;
2308
- }
2309
- }
2310
- } else {
2311
- if (p1 == p3) { // inplace case
2312
- for (i = 0; i < n; i++) {
2313
- check_intdivzero(*(dtype*)p2);
2314
- *(dtype*)p1 = m_div(*(dtype*)p1, *(dtype*)p2);
2315
- p1 += s1;
2316
- p2 += s2;
2317
- }
2318
- } else {
2319
- for (i = 0; i < n; i++) {
2320
- check_intdivzero(*(dtype*)p2);
2321
- *(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
2322
- p1 += s1;
2323
- p2 += s2;
2324
- p3 += s3;
2325
- }
2326
- }
2327
- }
2328
-
2329
- return;
2330
- //
2331
- }
2332
- }
2333
- for (i = 0; i < n; i++) {
2334
- dtype x, y, z;
2335
- GET_DATA_STRIDE(p1, s1, dtype, x);
2336
- GET_DATA_STRIDE(p2, s2, dtype, y);
2337
- check_intdivzero(y);
2338
- z = m_div(x, y);
2339
- SET_DATA_STRIDE(p3, s3, dtype, z);
2340
- }
2341
- //
2342
- }
2343
- #undef check_intdivzero
2344
-
2345
- static VALUE scomplex_div_self(VALUE self, VALUE other) {
2346
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2347
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2348
- ndfunc_t ndf = { iter_scomplex_div, STRIDE_LOOP, 2, 1, ain, aout };
2349
-
2350
- return na_ndloop(&ndf, 2, self, other);
2351
- }
2352
-
2353
- /*
2354
- Binary div.
2355
- @overload / other
2356
- @param [Numo::NArray,Numeric] other
2357
- @return [Numo::NArray] self / other
2358
- */
2359
- static VALUE scomplex_div(VALUE self, VALUE other) {
2360
-
2361
- VALUE klass, v;
2362
-
2363
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
2364
- if (klass == cT) {
2365
- return scomplex_div_self(self, other);
2366
- } else {
2367
- v = rb_funcall(klass, id_cast, 1, self);
2368
- return rb_funcall(v, '/', 1, other);
2369
- }
2370
- }
2371
-
2372
- static void iter_scomplex_pow(na_loop_t* const lp) {
2373
- size_t i;
2374
- char *p1, *p2, *p3;
2375
- ssize_t s1, s2, s3;
2376
- dtype x, y;
2377
- INIT_COUNTER(lp, i);
2378
- INIT_PTR(lp, 0, p1, s1);
2379
- INIT_PTR(lp, 1, p2, s2);
2380
- INIT_PTR(lp, 2, p3, s3);
2381
- for (; i--;) {
2382
- GET_DATA_STRIDE(p1, s1, dtype, x);
2383
- GET_DATA_STRIDE(p2, s2, dtype, y);
2384
- x = m_pow(x, y);
2385
- SET_DATA_STRIDE(p3, s3, dtype, x);
2386
- }
2387
- }
2388
-
2389
- static void iter_scomplex_pow_int32(na_loop_t* const lp) {
2390
- size_t i;
2391
- char *p1, *p2, *p3;
2392
- ssize_t s1, s2, s3;
2393
- dtype x;
2394
- int32_t 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, int32_t, y);
2402
- x = m_pow_int(x, y);
2403
- SET_DATA_STRIDE(p3, s3, dtype, x);
2404
- }
2405
- }
2406
-
2407
- static VALUE scomplex_pow_self(VALUE self, VALUE other) {
2408
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2409
- ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
2410
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2411
- ndfunc_t ndf = { iter_scomplex_pow, STRIDE_LOOP, 2, 1, ain, aout };
2412
- ndfunc_t ndf_i = { iter_scomplex_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
2413
-
2414
- // fixme : use na.integer?
2415
- if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
2416
- return na_ndloop(&ndf_i, 2, self, other);
2417
- } else {
2418
- return na_ndloop(&ndf, 2, self, other);
2419
- }
2420
- }
2421
-
2422
- /*
2423
- Binary power.
2424
- @overload ** other
2425
- @param [Numo::NArray,Numeric] other
2426
- @return [Numo::NArray] self to the other-th power.
2427
- */
2428
- static VALUE scomplex_pow(VALUE self, VALUE other) {
2429
-
2430
- VALUE klass, v;
2431
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
2432
- if (klass == cT) {
2433
- return scomplex_pow_self(self, other);
2434
- } else {
2435
- v = rb_funcall(klass, id_cast, 1, self);
2436
- return rb_funcall(v, id_pow, 1, other);
2437
- }
2438
- }
2439
-
2440
- static void iter_scomplex_minus(na_loop_t* const lp) {
2441
- size_t i, n;
2442
- char *p1, *p2;
2443
- ssize_t s1, s2;
2444
- size_t *idx1, *idx2;
2445
- dtype x;
2446
-
2447
- INIT_COUNTER(lp, n);
2448
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2449
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1992
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1993
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2450
1994
 
2451
1995
  if (idx1) {
2452
1996
  if (idx2) {
2453
1997
  for (i = 0; i < n; i++) {
2454
1998
  GET_DATA_INDEX(p1, idx1, dtype, x);
2455
- x = m_minus(x);
1999
+ x = m_sign(x);
2456
2000
  SET_DATA_INDEX(p2, idx2, dtype, x);
2457
2001
  }
2458
2002
  } else {
2459
2003
  for (i = 0; i < n; i++) {
2460
2004
  GET_DATA_INDEX(p1, idx1, dtype, x);
2461
- x = m_minus(x);
2005
+ x = m_sign(x);
2462
2006
  SET_DATA_STRIDE(p2, s2, dtype, x);
2463
2007
  }
2464
2008
  }
@@ -2466,7 +2010,7 @@ static void iter_scomplex_minus(na_loop_t* const lp) {
2466
2010
  if (idx2) {
2467
2011
  for (i = 0; i < n; i++) {
2468
2012
  GET_DATA_STRIDE(p1, s1, dtype, x);
2469
- x = m_minus(x);
2013
+ x = m_sign(x);
2470
2014
  SET_DATA_INDEX(p2, idx2, dtype, x);
2471
2015
  }
2472
2016
  } else {
@@ -2474,14 +2018,14 @@ static void iter_scomplex_minus(na_loop_t* const lp) {
2474
2018
  if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
2475
2019
  if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2476
2020
  for (i = 0; i < n; i++) {
2477
- ((dtype*)p2)[i] = m_minus(((dtype*)p1)[i]);
2021
+ ((dtype*)p2)[i] = m_sign(((dtype*)p1)[i]);
2478
2022
  }
2479
2023
  return;
2480
2024
  }
2481
2025
  if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
2482
2026
  //
2483
2027
  for (i = 0; i < n; i++) {
2484
- *(dtype*)p2 = m_minus(*(dtype*)p1);
2028
+ *(dtype*)p2 = m_sign(*(dtype*)p1);
2485
2029
  p1 += s1;
2486
2030
  p2 += s2;
2487
2031
  }
@@ -2491,7 +2035,7 @@ static void iter_scomplex_minus(na_loop_t* const lp) {
2491
2035
  }
2492
2036
  for (i = 0; i < n; i++) {
2493
2037
  GET_DATA_STRIDE(p1, s1, dtype, x);
2494
- x = m_minus(x);
2038
+ x = m_sign(x);
2495
2039
  SET_DATA_STRIDE(p2, s2, dtype, x);
2496
2040
  }
2497
2041
  //
@@ -2500,19 +2044,19 @@ static void iter_scomplex_minus(na_loop_t* const lp) {
2500
2044
  }
2501
2045
 
2502
2046
  /*
2503
- Unary minus.
2504
- @overload -@
2505
- @return [Numo::SComplex] minus of self.
2047
+ Unary sign.
2048
+ @overload sign
2049
+ @return [Numo::SComplex] sign of self.
2506
2050
  */
2507
- static VALUE scomplex_minus(VALUE self) {
2051
+ static VALUE scomplex_sign(VALUE self) {
2508
2052
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2509
2053
  ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2510
- ndfunc_t ndf = { iter_scomplex_minus, FULL_LOOP, 1, 1, ain, aout };
2054
+ ndfunc_t ndf = { iter_scomplex_sign, FULL_LOOP, 1, 1, ain, aout };
2511
2055
 
2512
2056
  return na_ndloop(&ndf, 1, self);
2513
2057
  }
2514
2058
 
2515
- static void iter_scomplex_reciprocal(na_loop_t* const lp) {
2059
+ static void iter_scomplex_square(na_loop_t* const lp) {
2516
2060
  size_t i, n;
2517
2061
  char *p1, *p2;
2518
2062
  ssize_t s1, s2;
@@ -2527,13 +2071,13 @@ static void iter_scomplex_reciprocal(na_loop_t* const lp) {
2527
2071
  if (idx2) {
2528
2072
  for (i = 0; i < n; i++) {
2529
2073
  GET_DATA_INDEX(p1, idx1, dtype, x);
2530
- x = m_reciprocal(x);
2074
+ x = m_square(x);
2531
2075
  SET_DATA_INDEX(p2, idx2, dtype, x);
2532
2076
  }
2533
2077
  } else {
2534
2078
  for (i = 0; i < n; i++) {
2535
2079
  GET_DATA_INDEX(p1, idx1, dtype, x);
2536
- x = m_reciprocal(x);
2080
+ x = m_square(x);
2537
2081
  SET_DATA_STRIDE(p2, s2, dtype, x);
2538
2082
  }
2539
2083
  }
@@ -2541,7 +2085,7 @@ static void iter_scomplex_reciprocal(na_loop_t* const lp) {
2541
2085
  if (idx2) {
2542
2086
  for (i = 0; i < n; i++) {
2543
2087
  GET_DATA_STRIDE(p1, s1, dtype, x);
2544
- x = m_reciprocal(x);
2088
+ x = m_square(x);
2545
2089
  SET_DATA_INDEX(p2, idx2, dtype, x);
2546
2090
  }
2547
2091
  } else {
@@ -2549,14 +2093,14 @@ static void iter_scomplex_reciprocal(na_loop_t* const lp) {
2549
2093
  if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
2550
2094
  if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2551
2095
  for (i = 0; i < n; i++) {
2552
- ((dtype*)p2)[i] = m_reciprocal(((dtype*)p1)[i]);
2096
+ ((dtype*)p2)[i] = m_square(((dtype*)p1)[i]);
2553
2097
  }
2554
2098
  return;
2555
2099
  }
2556
2100
  if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
2557
2101
  //
2558
2102
  for (i = 0; i < n; i++) {
2559
- *(dtype*)p2 = m_reciprocal(*(dtype*)p1);
2103
+ *(dtype*)p2 = m_square(*(dtype*)p1);
2560
2104
  p1 += s1;
2561
2105
  p2 += s2;
2562
2106
  }
@@ -2566,7 +2110,7 @@ static void iter_scomplex_reciprocal(na_loop_t* const lp) {
2566
2110
  }
2567
2111
  for (i = 0; i < n; i++) {
2568
2112
  GET_DATA_STRIDE(p1, s1, dtype, x);
2569
- x = m_reciprocal(x);
2113
+ x = m_square(x);
2570
2114
  SET_DATA_STRIDE(p2, s2, dtype, x);
2571
2115
  }
2572
2116
  //
@@ -2575,19 +2119,19 @@ static void iter_scomplex_reciprocal(na_loop_t* const lp) {
2575
2119
  }
2576
2120
 
2577
2121
  /*
2578
- Unary reciprocal.
2579
- @overload reciprocal
2580
- @return [Numo::SComplex] reciprocal of self.
2122
+ Unary square.
2123
+ @overload square
2124
+ @return [Numo::SComplex] square of self.
2581
2125
  */
2582
- static VALUE scomplex_reciprocal(VALUE self) {
2126
+ static VALUE scomplex_square(VALUE self) {
2583
2127
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2584
2128
  ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2585
- ndfunc_t ndf = { iter_scomplex_reciprocal, FULL_LOOP, 1, 1, ain, aout };
2129
+ ndfunc_t ndf = { iter_scomplex_square, FULL_LOOP, 1, 1, ain, aout };
2586
2130
 
2587
2131
  return na_ndloop(&ndf, 1, self);
2588
2132
  }
2589
2133
 
2590
- static void iter_scomplex_sign(na_loop_t* const lp) {
2134
+ static void iter_scomplex_conj(na_loop_t* const lp) {
2591
2135
  size_t i, n;
2592
2136
  char *p1, *p2;
2593
2137
  ssize_t s1, s2;
@@ -2602,13 +2146,13 @@ static void iter_scomplex_sign(na_loop_t* const lp) {
2602
2146
  if (idx2) {
2603
2147
  for (i = 0; i < n; i++) {
2604
2148
  GET_DATA_INDEX(p1, idx1, dtype, x);
2605
- x = m_sign(x);
2149
+ x = m_conj(x);
2606
2150
  SET_DATA_INDEX(p2, idx2, dtype, x);
2607
2151
  }
2608
2152
  } else {
2609
2153
  for (i = 0; i < n; i++) {
2610
2154
  GET_DATA_INDEX(p1, idx1, dtype, x);
2611
- x = m_sign(x);
2155
+ x = m_conj(x);
2612
2156
  SET_DATA_STRIDE(p2, s2, dtype, x);
2613
2157
  }
2614
2158
  }
@@ -2616,7 +2160,7 @@ static void iter_scomplex_sign(na_loop_t* const lp) {
2616
2160
  if (idx2) {
2617
2161
  for (i = 0; i < n; i++) {
2618
2162
  GET_DATA_STRIDE(p1, s1, dtype, x);
2619
- x = m_sign(x);
2163
+ x = m_conj(x);
2620
2164
  SET_DATA_INDEX(p2, idx2, dtype, x);
2621
2165
  }
2622
2166
  } else {
@@ -2624,14 +2168,14 @@ static void iter_scomplex_sign(na_loop_t* const lp) {
2624
2168
  if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
2625
2169
  if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2626
2170
  for (i = 0; i < n; i++) {
2627
- ((dtype*)p2)[i] = m_sign(((dtype*)p1)[i]);
2171
+ ((dtype*)p2)[i] = m_conj(((dtype*)p1)[i]);
2628
2172
  }
2629
2173
  return;
2630
2174
  }
2631
2175
  if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
2632
2176
  //
2633
2177
  for (i = 0; i < n; i++) {
2634
- *(dtype*)p2 = m_sign(*(dtype*)p1);
2178
+ *(dtype*)p2 = m_conj(*(dtype*)p1);
2635
2179
  p1 += s1;
2636
2180
  p2 += s2;
2637
2181
  }
@@ -2641,7 +2185,7 @@ static void iter_scomplex_sign(na_loop_t* const lp) {
2641
2185
  }
2642
2186
  for (i = 0; i < n; i++) {
2643
2187
  GET_DATA_STRIDE(p1, s1, dtype, x);
2644
- x = m_sign(x);
2188
+ x = m_conj(x);
2645
2189
  SET_DATA_STRIDE(p2, s2, dtype, x);
2646
2190
  }
2647
2191
  //
@@ -2650,19 +2194,19 @@ static void iter_scomplex_sign(na_loop_t* const lp) {
2650
2194
  }
2651
2195
 
2652
2196
  /*
2653
- Unary sign.
2654
- @overload sign
2655
- @return [Numo::SComplex] sign of self.
2197
+ Unary conj.
2198
+ @overload conj
2199
+ @return [Numo::SComplex] conj of self.
2656
2200
  */
2657
- static VALUE scomplex_sign(VALUE self) {
2201
+ static VALUE scomplex_conj(VALUE self) {
2658
2202
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2659
2203
  ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2660
- ndfunc_t ndf = { iter_scomplex_sign, FULL_LOOP, 1, 1, ain, aout };
2204
+ ndfunc_t ndf = { iter_scomplex_conj, FULL_LOOP, 1, 1, ain, aout };
2661
2205
 
2662
2206
  return na_ndloop(&ndf, 1, self);
2663
2207
  }
2664
2208
 
2665
- static void iter_scomplex_square(na_loop_t* const lp) {
2209
+ static void iter_scomplex_im(na_loop_t* const lp) {
2666
2210
  size_t i, n;
2667
2211
  char *p1, *p2;
2668
2212
  ssize_t s1, s2;
@@ -2677,13 +2221,13 @@ static void iter_scomplex_square(na_loop_t* const lp) {
2677
2221
  if (idx2) {
2678
2222
  for (i = 0; i < n; i++) {
2679
2223
  GET_DATA_INDEX(p1, idx1, dtype, x);
2680
- x = m_square(x);
2224
+ x = m_im(x);
2681
2225
  SET_DATA_INDEX(p2, idx2, dtype, x);
2682
2226
  }
2683
2227
  } else {
2684
2228
  for (i = 0; i < n; i++) {
2685
2229
  GET_DATA_INDEX(p1, idx1, dtype, x);
2686
- x = m_square(x);
2230
+ x = m_im(x);
2687
2231
  SET_DATA_STRIDE(p2, s2, dtype, x);
2688
2232
  }
2689
2233
  }
@@ -2691,7 +2235,7 @@ static void iter_scomplex_square(na_loop_t* const lp) {
2691
2235
  if (idx2) {
2692
2236
  for (i = 0; i < n; i++) {
2693
2237
  GET_DATA_STRIDE(p1, s1, dtype, x);
2694
- x = m_square(x);
2238
+ x = m_im(x);
2695
2239
  SET_DATA_INDEX(p2, idx2, dtype, x);
2696
2240
  }
2697
2241
  } else {
@@ -2699,14 +2243,14 @@ static void iter_scomplex_square(na_loop_t* const lp) {
2699
2243
  if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
2700
2244
  if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2701
2245
  for (i = 0; i < n; i++) {
2702
- ((dtype*)p2)[i] = m_square(((dtype*)p1)[i]);
2246
+ ((dtype*)p2)[i] = m_im(((dtype*)p1)[i]);
2703
2247
  }
2704
2248
  return;
2705
2249
  }
2706
2250
  if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
2707
2251
  //
2708
2252
  for (i = 0; i < n; i++) {
2709
- *(dtype*)p2 = m_square(*(dtype*)p1);
2253
+ *(dtype*)p2 = m_im(*(dtype*)p1);
2710
2254
  p1 += s1;
2711
2255
  p2 += s2;
2712
2256
  }
@@ -2716,7 +2260,7 @@ static void iter_scomplex_square(na_loop_t* const lp) {
2716
2260
  }
2717
2261
  for (i = 0; i < n; i++) {
2718
2262
  GET_DATA_STRIDE(p1, s1, dtype, x);
2719
- x = m_square(x);
2263
+ x = m_im(x);
2720
2264
  SET_DATA_STRIDE(p2, s2, dtype, x);
2721
2265
  }
2722
2266
  //
@@ -2725,181 +2269,31 @@ static void iter_scomplex_square(na_loop_t* const lp) {
2725
2269
  }
2726
2270
 
2727
2271
  /*
2728
- Unary square.
2729
- @overload square
2730
- @return [Numo::SComplex] square of self.
2272
+ Unary im.
2273
+ @overload im
2274
+ @return [Numo::SComplex] im of self.
2731
2275
  */
2732
- static VALUE scomplex_square(VALUE self) {
2276
+ static VALUE scomplex_im(VALUE self) {
2733
2277
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2734
2278
  ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2735
- ndfunc_t ndf = { iter_scomplex_square, FULL_LOOP, 1, 1, ain, aout };
2279
+ ndfunc_t ndf = { iter_scomplex_im, FULL_LOOP, 1, 1, ain, aout };
2736
2280
 
2737
2281
  return na_ndloop(&ndf, 1, self);
2738
2282
  }
2739
2283
 
2740
- static void iter_scomplex_conj(na_loop_t* const lp) {
2741
- size_t i, n;
2284
+ static void iter_scomplex_real(na_loop_t* const lp) {
2285
+ size_t i;
2742
2286
  char *p1, *p2;
2743
2287
  ssize_t s1, s2;
2744
2288
  size_t *idx1, *idx2;
2745
2289
  dtype x;
2746
-
2747
- INIT_COUNTER(lp, n);
2290
+ rtype y;
2291
+ INIT_COUNTER(lp, i);
2748
2292
  INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2749
2293
  INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2750
-
2751
2294
  if (idx1) {
2752
2295
  if (idx2) {
2753
- for (i = 0; i < n; i++) {
2754
- GET_DATA_INDEX(p1, idx1, dtype, x);
2755
- x = m_conj(x);
2756
- SET_DATA_INDEX(p2, idx2, dtype, x);
2757
- }
2758
- } else {
2759
- for (i = 0; i < n; i++) {
2760
- GET_DATA_INDEX(p1, idx1, dtype, x);
2761
- x = m_conj(x);
2762
- SET_DATA_STRIDE(p2, s2, dtype, x);
2763
- }
2764
- }
2765
- } else {
2766
- if (idx2) {
2767
- for (i = 0; i < n; i++) {
2768
- GET_DATA_STRIDE(p1, s1, dtype, x);
2769
- x = m_conj(x);
2770
- SET_DATA_INDEX(p2, idx2, dtype, x);
2771
- }
2772
- } else {
2773
- //
2774
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
2775
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2776
- for (i = 0; i < n; i++) {
2777
- ((dtype*)p2)[i] = m_conj(((dtype*)p1)[i]);
2778
- }
2779
- return;
2780
- }
2781
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
2782
- //
2783
- for (i = 0; i < n; i++) {
2784
- *(dtype*)p2 = m_conj(*(dtype*)p1);
2785
- p1 += s1;
2786
- p2 += s2;
2787
- }
2788
- return;
2789
- //
2790
- }
2791
- }
2792
- for (i = 0; i < n; i++) {
2793
- GET_DATA_STRIDE(p1, s1, dtype, x);
2794
- x = m_conj(x);
2795
- SET_DATA_STRIDE(p2, s2, dtype, x);
2796
- }
2797
- //
2798
- }
2799
- }
2800
- }
2801
-
2802
- /*
2803
- Unary conj.
2804
- @overload conj
2805
- @return [Numo::SComplex] conj of self.
2806
- */
2807
- static VALUE scomplex_conj(VALUE self) {
2808
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2809
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2810
- ndfunc_t ndf = { iter_scomplex_conj, FULL_LOOP, 1, 1, ain, aout };
2811
-
2812
- return na_ndloop(&ndf, 1, self);
2813
- }
2814
-
2815
- static void iter_scomplex_im(na_loop_t* const lp) {
2816
- size_t i, n;
2817
- char *p1, *p2;
2818
- ssize_t s1, s2;
2819
- size_t *idx1, *idx2;
2820
- dtype x;
2821
-
2822
- INIT_COUNTER(lp, n);
2823
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2824
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2825
-
2826
- if (idx1) {
2827
- if (idx2) {
2828
- for (i = 0; i < n; i++) {
2829
- GET_DATA_INDEX(p1, idx1, dtype, x);
2830
- x = m_im(x);
2831
- SET_DATA_INDEX(p2, idx2, dtype, x);
2832
- }
2833
- } else {
2834
- for (i = 0; i < n; i++) {
2835
- GET_DATA_INDEX(p1, idx1, dtype, x);
2836
- x = m_im(x);
2837
- SET_DATA_STRIDE(p2, s2, dtype, x);
2838
- }
2839
- }
2840
- } else {
2841
- if (idx2) {
2842
- for (i = 0; i < n; i++) {
2843
- GET_DATA_STRIDE(p1, s1, dtype, x);
2844
- x = m_im(x);
2845
- SET_DATA_INDEX(p2, idx2, dtype, x);
2846
- }
2847
- } else {
2848
- //
2849
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
2850
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2851
- for (i = 0; i < n; i++) {
2852
- ((dtype*)p2)[i] = m_im(((dtype*)p1)[i]);
2853
- }
2854
- return;
2855
- }
2856
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
2857
- //
2858
- for (i = 0; i < n; i++) {
2859
- *(dtype*)p2 = m_im(*(dtype*)p1);
2860
- p1 += s1;
2861
- p2 += s2;
2862
- }
2863
- return;
2864
- //
2865
- }
2866
- }
2867
- for (i = 0; i < n; i++) {
2868
- GET_DATA_STRIDE(p1, s1, dtype, x);
2869
- x = m_im(x);
2870
- SET_DATA_STRIDE(p2, s2, dtype, x);
2871
- }
2872
- //
2873
- }
2874
- }
2875
- }
2876
-
2877
- /*
2878
- Unary im.
2879
- @overload im
2880
- @return [Numo::SComplex] im of self.
2881
- */
2882
- static VALUE scomplex_im(VALUE self) {
2883
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2884
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2885
- ndfunc_t ndf = { iter_scomplex_im, FULL_LOOP, 1, 1, ain, aout };
2886
-
2887
- return na_ndloop(&ndf, 1, self);
2888
- }
2889
-
2890
- static void iter_scomplex_real(na_loop_t* const lp) {
2891
- size_t i;
2892
- char *p1, *p2;
2893
- ssize_t s1, s2;
2894
- size_t *idx1, *idx2;
2895
- dtype x;
2896
- rtype y;
2897
- INIT_COUNTER(lp, i);
2898
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2899
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2900
- if (idx1) {
2901
- if (idx2) {
2902
- for (; i--;) {
2296
+ for (; i--;) {
2903
2297
  GET_DATA_INDEX(p1, idx1, dtype, x);
2904
2298
  y = m_real(x);
2905
2299
  SET_DATA_INDEX(p2, idx2, rtype, y);
@@ -3140,1530 +2534,137 @@ static void iter_scomplex_set_real(na_loop_t* const lp) {
3140
2534
  for (; i--;) {
3141
2535
  GET_DATA(p1, dtype, x);
3142
2536
  GET_DATA_STRIDE(p2, s2, rtype, y);
3143
- x = m_set_real(x, y);
3144
- SET_DATA_STRIDE(p1, s1, dtype, x);
3145
- }
3146
- }
3147
- }
3148
- }
3149
-
3150
- static VALUE scomplex_set_real(VALUE self, VALUE a1) {
3151
- ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
3152
- ndfunc_t ndf = { iter_scomplex_set_real, FULL_LOOP, 2, 0, ain, 0 };
3153
-
3154
- na_ndloop(&ndf, 2, self, a1);
3155
- return a1;
3156
- }
3157
-
3158
- static void iter_scomplex_eq(na_loop_t* const lp) {
3159
- size_t i;
3160
- char *p1, *p2;
3161
- BIT_DIGIT* a3;
3162
- size_t p3;
3163
- ssize_t s1, s2, s3;
3164
- dtype x, y;
3165
- BIT_DIGIT b;
3166
- INIT_COUNTER(lp, i);
3167
- INIT_PTR(lp, 0, p1, s1);
3168
- INIT_PTR(lp, 1, p2, s2);
3169
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
3170
- for (; i--;) {
3171
- GET_DATA_STRIDE(p1, s1, dtype, x);
3172
- GET_DATA_STRIDE(p2, s2, dtype, y);
3173
- b = (m_eq(x, y)) ? 1 : 0;
3174
- STORE_BIT(a3, p3, b);
3175
- p3 += s3;
3176
- }
3177
- }
3178
-
3179
- static VALUE scomplex_eq_self(VALUE self, VALUE other) {
3180
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3181
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3182
- ndfunc_t ndf = { iter_scomplex_eq, STRIDE_LOOP, 2, 1, ain, aout };
3183
-
3184
- return na_ndloop(&ndf, 2, self, other);
3185
- }
3186
-
3187
- /*
3188
- Comparison eq other.
3189
- @overload eq other
3190
- @param [Numo::NArray,Numeric] other
3191
- @return [Numo::Bit] result of self eq other.
3192
- */
3193
- static VALUE scomplex_eq(VALUE self, VALUE other) {
3194
-
3195
- VALUE klass, v;
3196
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
3197
- if (klass == cT) {
3198
- return scomplex_eq_self(self, other);
3199
- } else {
3200
- v = rb_funcall(klass, id_cast, 1, self);
3201
- return rb_funcall(v, id_eq, 1, other);
3202
- }
3203
- }
3204
-
3205
- static void iter_scomplex_ne(na_loop_t* const lp) {
3206
- size_t i;
3207
- char *p1, *p2;
3208
- BIT_DIGIT* a3;
3209
- size_t p3;
3210
- ssize_t s1, s2, s3;
3211
- dtype x, y;
3212
- BIT_DIGIT b;
3213
- INIT_COUNTER(lp, i);
3214
- INIT_PTR(lp, 0, p1, s1);
3215
- INIT_PTR(lp, 1, p2, s2);
3216
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
3217
- for (; i--;) {
3218
- GET_DATA_STRIDE(p1, s1, dtype, x);
3219
- GET_DATA_STRIDE(p2, s2, dtype, y);
3220
- b = (m_ne(x, y)) ? 1 : 0;
3221
- STORE_BIT(a3, p3, b);
3222
- p3 += s3;
3223
- }
3224
- }
3225
-
3226
- static VALUE scomplex_ne_self(VALUE self, VALUE other) {
3227
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3228
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3229
- ndfunc_t ndf = { iter_scomplex_ne, STRIDE_LOOP, 2, 1, ain, aout };
3230
-
3231
- return na_ndloop(&ndf, 2, self, other);
3232
- }
3233
-
3234
- /*
3235
- Comparison ne other.
3236
- @overload ne other
3237
- @param [Numo::NArray,Numeric] other
3238
- @return [Numo::Bit] result of self ne other.
3239
- */
3240
- static VALUE scomplex_ne(VALUE self, VALUE other) {
3241
-
3242
- VALUE klass, v;
3243
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
3244
- if (klass == cT) {
3245
- return scomplex_ne_self(self, other);
3246
- } else {
3247
- v = rb_funcall(klass, id_cast, 1, self);
3248
- return rb_funcall(v, id_ne, 1, other);
3249
- }
3250
- }
3251
-
3252
- static void iter_scomplex_nearly_eq(na_loop_t* const lp) {
3253
- size_t i;
3254
- char *p1, *p2;
3255
- BIT_DIGIT* a3;
3256
- size_t p3;
3257
- ssize_t s1, s2, s3;
3258
- dtype x, y;
3259
- BIT_DIGIT b;
3260
- INIT_COUNTER(lp, i);
3261
- INIT_PTR(lp, 0, p1, s1);
3262
- INIT_PTR(lp, 1, p2, s2);
3263
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
3264
- for (; i--;) {
3265
- GET_DATA_STRIDE(p1, s1, dtype, x);
3266
- GET_DATA_STRIDE(p2, s2, dtype, y);
3267
- b = (m_nearly_eq(x, y)) ? 1 : 0;
3268
- STORE_BIT(a3, p3, b);
3269
- p3 += s3;
3270
- }
3271
- }
3272
-
3273
- static VALUE scomplex_nearly_eq_self(VALUE self, VALUE other) {
3274
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3275
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3276
- ndfunc_t ndf = { iter_scomplex_nearly_eq, STRIDE_LOOP, 2, 1, ain, aout };
3277
-
3278
- return na_ndloop(&ndf, 2, self, other);
3279
- }
3280
-
3281
- /*
3282
- Comparison nearly_eq other.
3283
- @overload nearly_eq other
3284
- @param [Numo::NArray,Numeric] other
3285
- @return [Numo::Bit] result of self nearly_eq other.
3286
- */
3287
- static VALUE scomplex_nearly_eq(VALUE self, VALUE other) {
3288
-
3289
- VALUE klass, v;
3290
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
3291
- if (klass == cT) {
3292
- return scomplex_nearly_eq_self(self, other);
3293
- } else {
3294
- v = rb_funcall(klass, id_cast, 1, self);
3295
- return rb_funcall(v, id_nearly_eq, 1, other);
3296
- }
3297
- }
3298
-
3299
- static void iter_scomplex_floor(na_loop_t* const lp) {
3300
- size_t i, n;
3301
- char *p1, *p2;
3302
- ssize_t s1, s2;
3303
- size_t *idx1, *idx2;
3304
- dtype x;
3305
-
3306
- INIT_COUNTER(lp, n);
3307
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3308
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3309
-
3310
- if (idx1) {
3311
- if (idx2) {
3312
- for (i = 0; i < n; i++) {
3313
- GET_DATA_INDEX(p1, idx1, dtype, x);
3314
- x = m_floor(x);
3315
- SET_DATA_INDEX(p2, idx2, dtype, x);
3316
- }
3317
- } else {
3318
- for (i = 0; i < n; i++) {
3319
- GET_DATA_INDEX(p1, idx1, dtype, x);
3320
- x = m_floor(x);
3321
- SET_DATA_STRIDE(p2, s2, dtype, x);
3322
- }
3323
- }
3324
- } else {
3325
- if (idx2) {
3326
- for (i = 0; i < n; i++) {
3327
- GET_DATA_STRIDE(p1, s1, dtype, x);
3328
- x = m_floor(x);
3329
- SET_DATA_INDEX(p2, idx2, dtype, x);
3330
- }
3331
- } else {
3332
- //
3333
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
3334
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
3335
- for (i = 0; i < n; i++) {
3336
- ((dtype*)p2)[i] = m_floor(((dtype*)p1)[i]);
3337
- }
3338
- return;
3339
- }
3340
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
3341
- //
3342
- for (i = 0; i < n; i++) {
3343
- *(dtype*)p2 = m_floor(*(dtype*)p1);
3344
- p1 += s1;
3345
- p2 += s2;
3346
- }
3347
- return;
3348
- //
3349
- }
3350
- }
3351
- for (i = 0; i < n; i++) {
3352
- GET_DATA_STRIDE(p1, s1, dtype, x);
3353
- x = m_floor(x);
3354
- SET_DATA_STRIDE(p2, s2, dtype, x);
3355
- }
3356
- //
3357
- }
3358
- }
3359
- }
3360
-
3361
- /*
3362
- Unary floor.
3363
- @overload floor
3364
- @return [Numo::SComplex] floor of self.
3365
- */
3366
- static VALUE scomplex_floor(VALUE self) {
3367
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3368
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3369
- ndfunc_t ndf = { iter_scomplex_floor, FULL_LOOP, 1, 1, ain, aout };
3370
-
3371
- return na_ndloop(&ndf, 1, self);
3372
- }
3373
-
3374
- static void iter_scomplex_round(na_loop_t* const lp) {
3375
- size_t i, n;
3376
- char *p1, *p2;
3377
- ssize_t s1, s2;
3378
- size_t *idx1, *idx2;
3379
- dtype x;
3380
-
3381
- INIT_COUNTER(lp, n);
3382
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3383
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3384
-
3385
- if (idx1) {
3386
- if (idx2) {
3387
- for (i = 0; i < n; i++) {
3388
- GET_DATA_INDEX(p1, idx1, dtype, x);
3389
- x = m_round(x);
3390
- SET_DATA_INDEX(p2, idx2, dtype, x);
3391
- }
3392
- } else {
3393
- for (i = 0; i < n; i++) {
3394
- GET_DATA_INDEX(p1, idx1, dtype, x);
3395
- x = m_round(x);
3396
- SET_DATA_STRIDE(p2, s2, dtype, x);
3397
- }
3398
- }
3399
- } else {
3400
- if (idx2) {
3401
- for (i = 0; i < n; i++) {
3402
- GET_DATA_STRIDE(p1, s1, dtype, x);
3403
- x = m_round(x);
3404
- SET_DATA_INDEX(p2, idx2, dtype, x);
3405
- }
3406
- } else {
3407
- //
3408
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
3409
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
3410
- for (i = 0; i < n; i++) {
3411
- ((dtype*)p2)[i] = m_round(((dtype*)p1)[i]);
3412
- }
3413
- return;
3414
- }
3415
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
3416
- //
3417
- for (i = 0; i < n; i++) {
3418
- *(dtype*)p2 = m_round(*(dtype*)p1);
3419
- p1 += s1;
3420
- p2 += s2;
3421
- }
3422
- return;
3423
- //
3424
- }
3425
- }
3426
- for (i = 0; i < n; i++) {
3427
- GET_DATA_STRIDE(p1, s1, dtype, x);
3428
- x = m_round(x);
3429
- SET_DATA_STRIDE(p2, s2, dtype, x);
3430
- }
3431
- //
3432
- }
3433
- }
3434
- }
3435
-
3436
- /*
3437
- Unary round.
3438
- @overload round
3439
- @return [Numo::SComplex] round of self.
3440
- */
3441
- static VALUE scomplex_round(VALUE self) {
3442
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3443
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3444
- ndfunc_t ndf = { iter_scomplex_round, FULL_LOOP, 1, 1, ain, aout };
3445
-
3446
- return na_ndloop(&ndf, 1, self);
3447
- }
3448
-
3449
- static void iter_scomplex_ceil(na_loop_t* const lp) {
3450
- size_t i, n;
3451
- char *p1, *p2;
3452
- ssize_t s1, s2;
3453
- size_t *idx1, *idx2;
3454
- dtype x;
3455
-
3456
- INIT_COUNTER(lp, n);
3457
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3458
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3459
-
3460
- if (idx1) {
3461
- if (idx2) {
3462
- for (i = 0; i < n; i++) {
3463
- GET_DATA_INDEX(p1, idx1, dtype, x);
3464
- x = m_ceil(x);
3465
- SET_DATA_INDEX(p2, idx2, dtype, x);
3466
- }
3467
- } else {
3468
- for (i = 0; i < n; i++) {
3469
- GET_DATA_INDEX(p1, idx1, dtype, x);
3470
- x = m_ceil(x);
3471
- SET_DATA_STRIDE(p2, s2, dtype, x);
3472
- }
3473
- }
3474
- } else {
3475
- if (idx2) {
3476
- for (i = 0; i < n; i++) {
3477
- GET_DATA_STRIDE(p1, s1, dtype, x);
3478
- x = m_ceil(x);
3479
- SET_DATA_INDEX(p2, idx2, dtype, x);
3480
- }
3481
- } else {
3482
- //
3483
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
3484
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
3485
- for (i = 0; i < n; i++) {
3486
- ((dtype*)p2)[i] = m_ceil(((dtype*)p1)[i]);
3487
- }
3488
- return;
3489
- }
3490
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
3491
- //
3492
- for (i = 0; i < n; i++) {
3493
- *(dtype*)p2 = m_ceil(*(dtype*)p1);
3494
- p1 += s1;
3495
- p2 += s2;
3496
- }
3497
- return;
3498
- //
3499
- }
3500
- }
3501
- for (i = 0; i < n; i++) {
3502
- GET_DATA_STRIDE(p1, s1, dtype, x);
3503
- x = m_ceil(x);
3504
- SET_DATA_STRIDE(p2, s2, dtype, x);
3505
- }
3506
- //
3507
- }
3508
- }
3509
- }
3510
-
3511
- /*
3512
- Unary ceil.
3513
- @overload ceil
3514
- @return [Numo::SComplex] ceil of self.
3515
- */
3516
- static VALUE scomplex_ceil(VALUE self) {
3517
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3518
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3519
- ndfunc_t ndf = { iter_scomplex_ceil, FULL_LOOP, 1, 1, ain, aout };
3520
-
3521
- return na_ndloop(&ndf, 1, self);
3522
- }
3523
-
3524
- static void iter_scomplex_trunc(na_loop_t* const lp) {
3525
- size_t i, n;
3526
- char *p1, *p2;
3527
- ssize_t s1, s2;
3528
- size_t *idx1, *idx2;
3529
- dtype x;
3530
-
3531
- INIT_COUNTER(lp, n);
3532
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3533
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3534
-
3535
- if (idx1) {
3536
- if (idx2) {
3537
- for (i = 0; i < n; i++) {
3538
- GET_DATA_INDEX(p1, idx1, dtype, x);
3539
- x = m_trunc(x);
3540
- SET_DATA_INDEX(p2, idx2, dtype, x);
3541
- }
3542
- } else {
3543
- for (i = 0; i < n; i++) {
3544
- GET_DATA_INDEX(p1, idx1, dtype, x);
3545
- x = m_trunc(x);
3546
- SET_DATA_STRIDE(p2, s2, dtype, x);
3547
- }
3548
- }
3549
- } else {
3550
- if (idx2) {
3551
- for (i = 0; i < n; i++) {
3552
- GET_DATA_STRIDE(p1, s1, dtype, x);
3553
- x = m_trunc(x);
3554
- SET_DATA_INDEX(p2, idx2, dtype, x);
3555
- }
3556
- } else {
3557
- //
3558
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
3559
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
3560
- for (i = 0; i < n; i++) {
3561
- ((dtype*)p2)[i] = m_trunc(((dtype*)p1)[i]);
3562
- }
3563
- return;
3564
- }
3565
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
3566
- //
3567
- for (i = 0; i < n; i++) {
3568
- *(dtype*)p2 = m_trunc(*(dtype*)p1);
3569
- p1 += s1;
3570
- p2 += s2;
3571
- }
3572
- return;
3573
- //
3574
- }
3575
- }
3576
- for (i = 0; i < n; i++) {
3577
- GET_DATA_STRIDE(p1, s1, dtype, x);
3578
- x = m_trunc(x);
3579
- SET_DATA_STRIDE(p2, s2, dtype, x);
3580
- }
3581
- //
3582
- }
3583
- }
3584
- }
3585
-
3586
- /*
3587
- Unary trunc.
3588
- @overload trunc
3589
- @return [Numo::SComplex] trunc of self.
3590
- */
3591
- static VALUE scomplex_trunc(VALUE self) {
3592
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3593
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3594
- ndfunc_t ndf = { iter_scomplex_trunc, FULL_LOOP, 1, 1, ain, aout };
3595
-
3596
- return na_ndloop(&ndf, 1, self);
3597
- }
3598
-
3599
- static void iter_scomplex_rint(na_loop_t* const lp) {
3600
- size_t i, n;
3601
- char *p1, *p2;
3602
- ssize_t s1, s2;
3603
- size_t *idx1, *idx2;
3604
- dtype x;
3605
-
3606
- INIT_COUNTER(lp, n);
3607
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3608
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3609
-
3610
- if (idx1) {
3611
- if (idx2) {
3612
- for (i = 0; i < n; i++) {
3613
- GET_DATA_INDEX(p1, idx1, dtype, x);
3614
- x = m_rint(x);
3615
- SET_DATA_INDEX(p2, idx2, dtype, x);
3616
- }
3617
- } else {
3618
- for (i = 0; i < n; i++) {
3619
- GET_DATA_INDEX(p1, idx1, dtype, x);
3620
- x = m_rint(x);
3621
- SET_DATA_STRIDE(p2, s2, dtype, x);
3622
- }
3623
- }
3624
- } else {
3625
- if (idx2) {
3626
- for (i = 0; i < n; i++) {
3627
- GET_DATA_STRIDE(p1, s1, dtype, x);
3628
- x = m_rint(x);
3629
- SET_DATA_INDEX(p2, idx2, dtype, x);
3630
- }
3631
- } else {
3632
- //
3633
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
3634
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
3635
- for (i = 0; i < n; i++) {
3636
- ((dtype*)p2)[i] = m_rint(((dtype*)p1)[i]);
3637
- }
3638
- return;
3639
- }
3640
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
3641
- //
3642
- for (i = 0; i < n; i++) {
3643
- *(dtype*)p2 = m_rint(*(dtype*)p1);
3644
- p1 += s1;
3645
- p2 += s2;
3646
- }
3647
- return;
3648
- //
3649
- }
3650
- }
3651
- for (i = 0; i < n; i++) {
3652
- GET_DATA_STRIDE(p1, s1, dtype, x);
3653
- x = m_rint(x);
3654
- SET_DATA_STRIDE(p2, s2, dtype, x);
3655
- }
3656
- //
3657
- }
3658
- }
3659
- }
3660
-
3661
- /*
3662
- Unary rint.
3663
- @overload rint
3664
- @return [Numo::SComplex] rint of self.
3665
- */
3666
- static VALUE scomplex_rint(VALUE self) {
3667
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3668
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3669
- ndfunc_t ndf = { iter_scomplex_rint, FULL_LOOP, 1, 1, ain, aout };
3670
-
3671
- return na_ndloop(&ndf, 1, self);
3672
- }
3673
-
3674
- #define check_intdivzero(y) \
3675
- {}
3676
-
3677
- static void iter_scomplex_copysign(na_loop_t* const lp) {
3678
- size_t i = 0;
3679
- size_t n;
3680
- char *p1, *p2, *p3;
3681
- ssize_t s1, s2, s3;
3682
-
3683
- INIT_COUNTER(lp, n);
3684
- INIT_PTR(lp, 0, p1, s1);
3685
- INIT_PTR(lp, 1, p2, s2);
3686
- INIT_PTR(lp, 2, p3, s3);
3687
-
3688
- //
3689
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
3690
- is_aligned(p3, sizeof(dtype))) {
3691
-
3692
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
3693
- if (p1 == p3) { // inplace case
3694
- for (; i < n; i++) {
3695
- check_intdivzero(((dtype*)p2)[i]);
3696
- ((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
3697
- }
3698
- } else {
3699
- for (; i < n; i++) {
3700
- check_intdivzero(((dtype*)p2)[i]);
3701
- ((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
3702
- }
3703
- }
3704
- return;
3705
- }
3706
-
3707
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
3708
- is_aligned_step(s3, sizeof(dtype))) {
3709
- //
3710
-
3711
- if (s2 == 0) { // Broadcasting from scalar value.
3712
- check_intdivzero(*(dtype*)p2);
3713
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
3714
- if (p1 == p3) { // inplace case
3715
- for (; i < n; i++) {
3716
- ((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
3717
- }
3718
- } else {
3719
- for (; i < n; i++) {
3720
- ((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
3721
- }
3722
- }
3723
- } else {
3724
- for (i = 0; i < n; i++) {
3725
- *(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
3726
- p1 += s1;
3727
- p3 += s3;
3728
- }
3729
- }
3730
- } else {
3731
- if (p1 == p3) { // inplace case
3732
- for (i = 0; i < n; i++) {
3733
- check_intdivzero(*(dtype*)p2);
3734
- *(dtype*)p1 = m_copysign(*(dtype*)p1, *(dtype*)p2);
3735
- p1 += s1;
3736
- p2 += s2;
3737
- }
3738
- } else {
3739
- for (i = 0; i < n; i++) {
3740
- check_intdivzero(*(dtype*)p2);
3741
- *(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
3742
- p1 += s1;
3743
- p2 += s2;
3744
- p3 += s3;
3745
- }
3746
- }
3747
- }
3748
-
3749
- return;
3750
- //
3751
- }
3752
- }
3753
- for (i = 0; i < n; i++) {
3754
- dtype x, y, z;
3755
- GET_DATA_STRIDE(p1, s1, dtype, x);
3756
- GET_DATA_STRIDE(p2, s2, dtype, y);
3757
- check_intdivzero(y);
3758
- z = m_copysign(x, y);
3759
- SET_DATA_STRIDE(p3, s3, dtype, z);
3760
- }
3761
- //
3762
- }
3763
- #undef check_intdivzero
3764
-
3765
- static VALUE scomplex_copysign_self(VALUE self, VALUE other) {
3766
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3767
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3768
- ndfunc_t ndf = { iter_scomplex_copysign, STRIDE_LOOP, 2, 1, ain, aout };
3769
-
3770
- return na_ndloop(&ndf, 2, self, other);
3771
- }
3772
-
3773
- /*
3774
- Binary copysign.
3775
- @overload copysign other
3776
- @param [Numo::NArray,Numeric] other
3777
- @return [Numo::NArray] self copysign other
3778
- */
3779
- static VALUE scomplex_copysign(VALUE self, VALUE other) {
3780
-
3781
- VALUE klass, v;
3782
-
3783
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
3784
- if (klass == cT) {
3785
- return scomplex_copysign_self(self, other);
3786
- } else {
3787
- v = rb_funcall(klass, id_cast, 1, self);
3788
- return rb_funcall(v, id_copysign, 1, other);
3789
- }
3790
- }
3791
-
3792
- static void iter_scomplex_isnan(na_loop_t* const lp) {
3793
- size_t i;
3794
- char* p1;
3795
- BIT_DIGIT* a2;
3796
- size_t p2;
3797
- ssize_t s1, s2;
3798
- size_t* idx1;
3799
- dtype x;
3800
- BIT_DIGIT b;
3801
- INIT_COUNTER(lp, i);
3802
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3803
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3804
- if (idx1) {
3805
- for (; i--;) {
3806
- GET_DATA_INDEX(p1, idx1, dtype, x);
3807
- b = (m_isnan(x)) ? 1 : 0;
3808
- STORE_BIT(a2, p2, b);
3809
- p2 += s2;
3810
- }
3811
- } else {
3812
- for (; i--;) {
3813
- GET_DATA_STRIDE(p1, s1, dtype, x);
3814
- b = (m_isnan(x)) ? 1 : 0;
3815
- STORE_BIT(a2, p2, b);
3816
- p2 += s2;
3817
- }
3818
- }
3819
- }
3820
-
3821
- /*
3822
- Condition of isnan.
3823
- @overload isnan
3824
- @return [Numo::Bit] Condition of isnan.
3825
- */
3826
- static VALUE scomplex_isnan(VALUE self) {
3827
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3828
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3829
- ndfunc_t ndf = { iter_scomplex_isnan, FULL_LOOP, 1, 1, ain, aout };
3830
-
3831
- return na_ndloop(&ndf, 1, self);
3832
- }
3833
-
3834
- static void iter_scomplex_isinf(na_loop_t* const lp) {
3835
- size_t i;
3836
- char* p1;
3837
- BIT_DIGIT* a2;
3838
- size_t p2;
3839
- ssize_t s1, s2;
3840
- size_t* idx1;
3841
- dtype x;
3842
- BIT_DIGIT b;
3843
- INIT_COUNTER(lp, i);
3844
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3845
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3846
- if (idx1) {
3847
- for (; i--;) {
3848
- GET_DATA_INDEX(p1, idx1, dtype, x);
3849
- b = (m_isinf(x)) ? 1 : 0;
3850
- STORE_BIT(a2, p2, b);
3851
- p2 += s2;
3852
- }
3853
- } else {
3854
- for (; i--;) {
3855
- GET_DATA_STRIDE(p1, s1, dtype, x);
3856
- b = (m_isinf(x)) ? 1 : 0;
3857
- STORE_BIT(a2, p2, b);
3858
- p2 += s2;
3859
- }
3860
- }
3861
- }
3862
-
3863
- /*
3864
- Condition of isinf.
3865
- @overload isinf
3866
- @return [Numo::Bit] Condition of isinf.
3867
- */
3868
- static VALUE scomplex_isinf(VALUE self) {
3869
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3870
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3871
- ndfunc_t ndf = { iter_scomplex_isinf, FULL_LOOP, 1, 1, ain, aout };
3872
-
3873
- return na_ndloop(&ndf, 1, self);
3874
- }
3875
-
3876
- static void iter_scomplex_isposinf(na_loop_t* const lp) {
3877
- size_t i;
3878
- char* p1;
3879
- BIT_DIGIT* a2;
3880
- size_t p2;
3881
- ssize_t s1, s2;
3882
- size_t* idx1;
3883
- dtype x;
3884
- BIT_DIGIT b;
3885
- INIT_COUNTER(lp, i);
3886
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3887
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3888
- if (idx1) {
3889
- for (; i--;) {
3890
- GET_DATA_INDEX(p1, idx1, dtype, x);
3891
- b = (m_isposinf(x)) ? 1 : 0;
3892
- STORE_BIT(a2, p2, b);
3893
- p2 += s2;
3894
- }
3895
- } else {
3896
- for (; i--;) {
3897
- GET_DATA_STRIDE(p1, s1, dtype, x);
3898
- b = (m_isposinf(x)) ? 1 : 0;
3899
- STORE_BIT(a2, p2, b);
3900
- p2 += s2;
3901
- }
3902
- }
3903
- }
3904
-
3905
- /*
3906
- Condition of isposinf.
3907
- @overload isposinf
3908
- @return [Numo::Bit] Condition of isposinf.
3909
- */
3910
- static VALUE scomplex_isposinf(VALUE self) {
3911
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3912
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3913
- ndfunc_t ndf = { iter_scomplex_isposinf, FULL_LOOP, 1, 1, ain, aout };
3914
-
3915
- return na_ndloop(&ndf, 1, self);
3916
- }
3917
-
3918
- static void iter_scomplex_isneginf(na_loop_t* const lp) {
3919
- size_t i;
3920
- char* p1;
3921
- BIT_DIGIT* a2;
3922
- size_t p2;
3923
- ssize_t s1, s2;
3924
- size_t* idx1;
3925
- dtype x;
3926
- BIT_DIGIT b;
3927
- INIT_COUNTER(lp, i);
3928
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3929
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3930
- if (idx1) {
3931
- for (; i--;) {
3932
- GET_DATA_INDEX(p1, idx1, dtype, x);
3933
- b = (m_isneginf(x)) ? 1 : 0;
3934
- STORE_BIT(a2, p2, b);
3935
- p2 += s2;
3936
- }
3937
- } else {
3938
- for (; i--;) {
3939
- GET_DATA_STRIDE(p1, s1, dtype, x);
3940
- b = (m_isneginf(x)) ? 1 : 0;
3941
- STORE_BIT(a2, p2, b);
3942
- p2 += s2;
3943
- }
3944
- }
3945
- }
3946
-
3947
- /*
3948
- Condition of isneginf.
3949
- @overload isneginf
3950
- @return [Numo::Bit] Condition of isneginf.
3951
- */
3952
- static VALUE scomplex_isneginf(VALUE self) {
3953
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3954
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3955
- ndfunc_t ndf = { iter_scomplex_isneginf, FULL_LOOP, 1, 1, ain, aout };
3956
-
3957
- return na_ndloop(&ndf, 1, self);
3958
- }
3959
-
3960
- static void iter_scomplex_isfinite(na_loop_t* const lp) {
3961
- size_t i;
3962
- char* p1;
3963
- BIT_DIGIT* a2;
3964
- size_t p2;
3965
- ssize_t s1, s2;
3966
- size_t* idx1;
3967
- dtype x;
3968
- BIT_DIGIT b;
3969
- INIT_COUNTER(lp, i);
3970
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3971
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3972
- if (idx1) {
3973
- for (; i--;) {
3974
- GET_DATA_INDEX(p1, idx1, dtype, x);
3975
- b = (m_isfinite(x)) ? 1 : 0;
3976
- STORE_BIT(a2, p2, b);
3977
- p2 += s2;
3978
- }
3979
- } else {
3980
- for (; i--;) {
3981
- GET_DATA_STRIDE(p1, s1, dtype, x);
3982
- b = (m_isfinite(x)) ? 1 : 0;
3983
- STORE_BIT(a2, p2, b);
3984
- p2 += s2;
3985
- }
3986
- }
3987
- }
3988
-
3989
- /*
3990
- Condition of isfinite.
3991
- @overload isfinite
3992
- @return [Numo::Bit] Condition of isfinite.
3993
- */
3994
- static VALUE scomplex_isfinite(VALUE self) {
3995
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3996
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3997
- ndfunc_t ndf = { iter_scomplex_isfinite, FULL_LOOP, 1, 1, ain, aout };
3998
-
3999
- return na_ndloop(&ndf, 1, self);
4000
- }
4001
-
4002
- static void iter_scomplex_sum(na_loop_t* const lp) {
4003
- size_t n;
4004
- char *p1, *p2;
4005
- ssize_t s1;
4006
-
4007
- INIT_COUNTER(lp, n);
4008
- INIT_PTR(lp, 0, p1, s1);
4009
- p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
4010
-
4011
- *(dtype*)p2 = f_sum(n, p1, s1);
4012
- }
4013
- static void iter_scomplex_sum_nan(na_loop_t* const lp) {
4014
- size_t n;
4015
- char *p1, *p2;
4016
- ssize_t s1;
4017
-
4018
- INIT_COUNTER(lp, n);
4019
- INIT_PTR(lp, 0, p1, s1);
4020
- p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
4021
-
4022
- *(dtype*)p2 = f_sum_nan(n, p1, s1);
4023
- }
4024
-
4025
- /*
4026
- sum of self.
4027
- @overload sum(axis:nil, keepdims:false, nan:false)
4028
- @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
4029
- return NaN for min/max etc).
4030
- @param [Numeric,Array,Range] axis Performs sum along the axis.
4031
- @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
4032
- dimensions with size one.
4033
- @return [Numo::SComplex] returns result of sum.
4034
- */
4035
- static VALUE scomplex_sum(int argc, VALUE* argv, VALUE self) {
4036
- VALUE v, reduce;
4037
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
4038
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
4039
- ndfunc_t ndf = { iter_scomplex_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
4040
-
4041
- reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_sum_nan);
4042
-
4043
- v = na_ndloop(&ndf, 2, self, reduce);
4044
-
4045
- return scomplex_extract(v);
4046
- }
4047
-
4048
- static void iter_scomplex_prod(na_loop_t* const lp) {
4049
- size_t n;
4050
- char *p1, *p2;
4051
- ssize_t s1;
4052
-
4053
- INIT_COUNTER(lp, n);
4054
- INIT_PTR(lp, 0, p1, s1);
4055
- p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
4056
-
4057
- *(dtype*)p2 = f_prod(n, p1, s1);
4058
- }
4059
- static void iter_scomplex_prod_nan(na_loop_t* const lp) {
4060
- size_t n;
4061
- char *p1, *p2;
4062
- ssize_t s1;
4063
-
4064
- INIT_COUNTER(lp, n);
4065
- INIT_PTR(lp, 0, p1, s1);
4066
- p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
4067
-
4068
- *(dtype*)p2 = f_prod_nan(n, p1, s1);
4069
- }
4070
-
4071
- /*
4072
- prod of self.
4073
- @overload prod(axis:nil, keepdims:false, nan:false)
4074
- @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
4075
- return NaN for min/max etc).
4076
- @param [Numeric,Array,Range] axis Performs prod along the axis.
4077
- @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
4078
- dimensions with size one.
4079
- @return [Numo::SComplex] returns result of prod.
4080
- */
4081
- static VALUE scomplex_prod(int argc, VALUE* argv, VALUE self) {
4082
- VALUE v, reduce;
4083
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
4084
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
4085
- ndfunc_t ndf = { iter_scomplex_prod, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
4086
-
4087
- reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_prod_nan);
4088
-
4089
- v = na_ndloop(&ndf, 2, self, reduce);
4090
-
4091
- return scomplex_extract(v);
4092
- }
4093
-
4094
- static void iter_scomplex_cumsum(na_loop_t* const lp) {
4095
- size_t i;
4096
- char *p1, *p2;
4097
- ssize_t s1, s2;
4098
- dtype x, y;
4099
-
4100
- INIT_COUNTER(lp, i);
4101
- INIT_PTR(lp, 0, p1, s1);
4102
- INIT_PTR(lp, 1, p2, s2);
4103
-
4104
- GET_DATA_STRIDE(p1, s1, dtype, x);
4105
- SET_DATA_STRIDE(p2, s2, dtype, x);
4106
- for (i--; i--;) {
4107
- GET_DATA_STRIDE(p1, s1, dtype, y);
4108
- m_cumsum(x, y);
4109
- SET_DATA_STRIDE(p2, s2, dtype, x);
4110
- }
4111
- }
4112
- static void iter_scomplex_cumsum_nan(na_loop_t* const lp) {
4113
- size_t i;
4114
- char *p1, *p2;
4115
- ssize_t s1, s2;
4116
- dtype x, y;
4117
-
4118
- INIT_COUNTER(lp, i);
4119
- INIT_PTR(lp, 0, p1, s1);
4120
- INIT_PTR(lp, 1, p2, s2);
4121
-
4122
- GET_DATA_STRIDE(p1, s1, dtype, x);
4123
- SET_DATA_STRIDE(p2, s2, dtype, x);
4124
- for (i--; i--;) {
4125
- GET_DATA_STRIDE(p1, s1, dtype, y);
4126
- m_cumsum_nan(x, y);
4127
- SET_DATA_STRIDE(p2, s2, dtype, x);
4128
- }
4129
- }
4130
-
4131
- /*
4132
- cumsum of self.
4133
- @overload cumsum(axis:nil, nan:false)
4134
- @param [Numeric,Array,Range] axis Performs cumsum along the axis.
4135
- @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
4136
- @return [Numo::SComplex] cumsum of self.
4137
- */
4138
- static VALUE scomplex_cumsum(int argc, VALUE* argv, VALUE self) {
4139
- VALUE reduce;
4140
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
4141
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
4142
- ndfunc_t ndf = {
4143
- iter_scomplex_cumsum, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
4144
- };
4145
-
4146
- reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_cumsum_nan);
4147
-
4148
- return na_ndloop(&ndf, 2, self, reduce);
4149
- }
4150
-
4151
- static void iter_scomplex_cumprod(na_loop_t* const lp) {
4152
- size_t i;
4153
- char *p1, *p2;
4154
- ssize_t s1, s2;
4155
- dtype x, y;
4156
-
4157
- INIT_COUNTER(lp, i);
4158
- INIT_PTR(lp, 0, p1, s1);
4159
- INIT_PTR(lp, 1, p2, s2);
4160
-
4161
- GET_DATA_STRIDE(p1, s1, dtype, x);
4162
- SET_DATA_STRIDE(p2, s2, dtype, x);
4163
- for (i--; i--;) {
4164
- GET_DATA_STRIDE(p1, s1, dtype, y);
4165
- m_cumprod(x, y);
4166
- SET_DATA_STRIDE(p2, s2, dtype, x);
4167
- }
4168
- }
4169
- static void iter_scomplex_cumprod_nan(na_loop_t* const lp) {
4170
- size_t i;
4171
- char *p1, *p2;
4172
- ssize_t s1, s2;
4173
- dtype x, y;
4174
-
4175
- INIT_COUNTER(lp, i);
4176
- INIT_PTR(lp, 0, p1, s1);
4177
- INIT_PTR(lp, 1, p2, s2);
4178
-
4179
- GET_DATA_STRIDE(p1, s1, dtype, x);
4180
- SET_DATA_STRIDE(p2, s2, dtype, x);
4181
- for (i--; i--;) {
4182
- GET_DATA_STRIDE(p1, s1, dtype, y);
4183
- m_cumprod_nan(x, y);
4184
- SET_DATA_STRIDE(p2, s2, dtype, x);
4185
- }
4186
- }
4187
-
4188
- /*
4189
- cumprod of self.
4190
- @overload cumprod(axis:nil, nan:false)
4191
- @param [Numeric,Array,Range] axis Performs cumprod along the axis.
4192
- @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
4193
- @return [Numo::SComplex] cumprod of self.
4194
- */
4195
- static VALUE scomplex_cumprod(int argc, VALUE* argv, VALUE self) {
4196
- VALUE reduce;
4197
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
4198
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
4199
- ndfunc_t ndf = {
4200
- iter_scomplex_cumprod, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
4201
- };
4202
-
4203
- reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_cumprod_nan);
4204
-
4205
- return na_ndloop(&ndf, 2, self, reduce);
4206
- }
4207
-
4208
- //
4209
- static void iter_scomplex_mulsum(na_loop_t* const lp) {
4210
- size_t i, n;
4211
- char *p1, *p2, *p3;
4212
- ssize_t s1, s2, s3;
4213
-
4214
- INIT_COUNTER(lp, n);
4215
- INIT_PTR(lp, 0, p1, s1);
4216
- INIT_PTR(lp, 1, p2, s2);
4217
- INIT_PTR(lp, 2, p3, s3);
4218
-
4219
- if (s3 == 0) {
4220
- dtype z;
4221
- // Reduce loop
4222
- GET_DATA(p3, dtype, z);
4223
- for (i = 0; i < n; i++) {
4224
- dtype x, y;
4225
- GET_DATA_STRIDE(p1, s1, dtype, x);
4226
- GET_DATA_STRIDE(p2, s2, dtype, y);
4227
- m_mulsum(x, y, z);
4228
- }
4229
- SET_DATA(p3, dtype, z);
4230
- return;
4231
- } else {
4232
- for (i = 0; i < n; i++) {
4233
- dtype x, y, z;
4234
- GET_DATA_STRIDE(p1, s1, dtype, x);
4235
- GET_DATA_STRIDE(p2, s2, dtype, y);
4236
- GET_DATA(p3, dtype, z);
4237
- m_mulsum(x, y, z);
4238
- SET_DATA_STRIDE(p3, s3, dtype, z);
4239
- }
4240
- }
4241
- }
4242
- //
4243
- static void iter_scomplex_mulsum_nan(na_loop_t* const lp) {
4244
- size_t i, n;
4245
- char *p1, *p2, *p3;
4246
- ssize_t s1, s2, s3;
4247
-
4248
- INIT_COUNTER(lp, n);
4249
- INIT_PTR(lp, 0, p1, s1);
4250
- INIT_PTR(lp, 1, p2, s2);
4251
- INIT_PTR(lp, 2, p3, s3);
4252
-
4253
- if (s3 == 0) {
4254
- dtype z;
4255
- // Reduce loop
4256
- GET_DATA(p3, dtype, z);
4257
- for (i = 0; i < n; i++) {
4258
- dtype x, y;
4259
- GET_DATA_STRIDE(p1, s1, dtype, x);
4260
- GET_DATA_STRIDE(p2, s2, dtype, y);
4261
- m_mulsum_nan(x, y, z);
4262
- }
4263
- SET_DATA(p3, dtype, z);
4264
- return;
4265
- } else {
4266
- for (i = 0; i < n; i++) {
4267
- dtype x, y, z;
4268
- GET_DATA_STRIDE(p1, s1, dtype, x);
4269
- GET_DATA_STRIDE(p2, s2, dtype, y);
4270
- GET_DATA(p3, dtype, z);
4271
- m_mulsum_nan(x, y, z);
4272
- SET_DATA_STRIDE(p3, s3, dtype, z);
4273
- }
4274
- }
4275
- }
4276
- //
4277
-
4278
- static VALUE scomplex_mulsum_self(int argc, VALUE* argv, VALUE self) {
4279
- VALUE v, reduce;
4280
- VALUE naryv[2];
4281
- ndfunc_arg_in_t ain[4] = { { cT, 0 }, { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
4282
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
4283
- ndfunc_t ndf = { iter_scomplex_mulsum, STRIDE_LOOP_NIP, 4, 1, ain, aout };
4284
-
4285
- if (argc < 1) {
4286
- rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
4287
- }
4288
- // should fix below: [self.ndim,other.ndim].max or?
4289
- naryv[0] = self;
4290
- naryv[1] = argv[0];
4291
- //
4292
- reduce = na_reduce_dimension(argc - 1, argv + 1, 2, naryv, &ndf, iter_scomplex_mulsum_nan);
4293
- //
4294
-
4295
- v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_mulsum_init);
4296
- return scomplex_extract(v);
4297
- }
4298
-
4299
- /*
4300
- Binary mulsum.
4301
-
4302
- @overload mulsum(other, axis:nil, keepdims:false, nan:false)
4303
- @param [Numo::NArray,Numeric] other
4304
- @param [Numeric,Array,Range] axis Performs mulsum along the axis.
4305
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
4306
- as dimensions with size one.
4307
- @param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm (avoid NaN if exists).
4308
- @return [Numo::NArray] mulsum of self and other.
4309
- */
4310
- static VALUE scomplex_mulsum(int argc, VALUE* argv, VALUE self) {
4311
- //
4312
- VALUE klass, v;
4313
- //
4314
- if (argc < 1) {
4315
- rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
4316
- }
4317
- //
4318
- klass = na_upcast(rb_obj_class(self), rb_obj_class(argv[0]));
4319
- if (klass == cT) {
4320
- return scomplex_mulsum_self(argc, argv, self);
4321
- } else {
4322
- v = rb_funcall(klass, id_cast, 1, self);
4323
- //
4324
- return rb_funcallv_kw(v, rb_intern("mulsum"), argc, argv, RB_PASS_CALLED_KEYWORDS);
4325
- //
4326
- }
4327
- //
4328
- }
4329
-
4330
- typedef dtype seq_data_t;
4331
-
4332
- typedef double seq_count_t;
4333
-
4334
- typedef struct {
4335
- seq_data_t beg;
4336
- seq_data_t step;
4337
- seq_count_t count;
4338
- } seq_opt_t;
4339
-
4340
- static void iter_scomplex_seq(na_loop_t* const lp) {
4341
- size_t i;
4342
- char* p1;
4343
- ssize_t s1;
4344
- size_t* idx1;
4345
- dtype x;
4346
- seq_data_t beg, step;
4347
- seq_count_t c;
4348
- seq_opt_t* g;
4349
-
4350
- INIT_COUNTER(lp, i);
4351
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
4352
- g = (seq_opt_t*)(lp->opt_ptr);
4353
- beg = g->beg;
4354
- step = g->step;
4355
- c = g->count;
4356
- if (idx1) {
4357
- for (; i--;) {
4358
- x = f_seq(beg, step, c++);
4359
- *(dtype*)(p1 + *idx1) = x;
4360
- idx1++;
4361
- }
4362
- } else {
4363
- for (; i--;) {
4364
- x = f_seq(beg, step, c++);
4365
- *(dtype*)(p1) = x;
4366
- p1 += s1;
2537
+ x = m_set_real(x, y);
2538
+ SET_DATA_STRIDE(p1, s1, dtype, x);
2539
+ }
4367
2540
  }
4368
2541
  }
4369
- g->count = c;
4370
2542
  }
4371
2543
 
4372
- /*
4373
- Set linear sequence of numbers to self. The sequence is obtained from
4374
- beg+i*step
4375
- where i is 1-dimensional index.
4376
- @overload seq([beg,[step]])
4377
- @param [Numeric] beg beginning of sequence. (default=0)
4378
- @param [Numeric] step step of sequence. (default=1)
4379
- @return [Numo::SComplex] self.
4380
- @example
4381
- Numo::DFloat.new(6).seq(1,-0.2)
4382
- # => Numo::DFloat#shape=[6]
4383
- # [1, 0.8, 0.6, 0.4, 0.2, 0]
4384
-
4385
- Numo::DComplex.new(6).seq(1,-0.2+0.2i)
4386
- # => Numo::DComplex#shape=[6]
4387
- # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
4388
- */
4389
- static VALUE scomplex_seq(int argc, VALUE* argv, VALUE self) {
4390
- seq_opt_t* g;
4391
- VALUE vbeg = Qnil, vstep = Qnil;
4392
- ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
4393
- ndfunc_t ndf = { iter_scomplex_seq, FULL_LOOP, 1, 0, ain, 0 };
4394
-
4395
- g = ALLOCA_N(seq_opt_t, 1);
4396
- g->beg = m_zero;
4397
- g->step = m_one;
4398
- g->count = 0;
4399
- rb_scan_args(argc, argv, "02", &vbeg, &vstep);
4400
- if (vbeg != Qnil) {
4401
- g->beg = m_num_to_data(vbeg);
4402
- }
4403
- if (vstep != Qnil) {
4404
- g->step = m_num_to_data(vstep);
4405
- }
2544
+ static VALUE scomplex_set_real(VALUE self, VALUE a1) {
2545
+ ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { cRT, 0 } };
2546
+ ndfunc_t ndf = { iter_scomplex_set_real, FULL_LOOP, 2, 0, ain, 0 };
4406
2547
 
4407
- na_ndloop3(&ndf, g, 1, self);
4408
- return self;
2548
+ na_ndloop(&ndf, 2, self, a1);
2549
+ return a1;
4409
2550
  }
4410
2551
 
4411
- typedef struct {
4412
- seq_data_t beg;
4413
- seq_data_t step;
4414
- seq_data_t base;
4415
- seq_count_t count;
4416
- } logseq_opt_t;
4417
-
4418
- static void iter_scomplex_logseq(na_loop_t* const lp) {
4419
- size_t i;
4420
- char* p1;
4421
- ssize_t s1;
4422
- size_t* idx1;
4423
- dtype x;
4424
- seq_data_t beg, step, base;
4425
- seq_count_t c;
4426
- logseq_opt_t* g;
4427
-
4428
- INIT_COUNTER(lp, i);
4429
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
4430
- g = (logseq_opt_t*)(lp->opt_ptr);
4431
- beg = g->beg;
4432
- step = g->step;
4433
- base = g->base;
4434
- c = g->count;
4435
- if (idx1) {
4436
- for (; i--;) {
4437
- x = f_seq(beg, step, c++);
4438
- *(dtype*)(p1 + *idx1) = m_pow(base, x);
4439
- idx1++;
4440
- }
4441
- } else {
4442
- for (; i--;) {
4443
- x = f_seq(beg, step, c++);
4444
- *(dtype*)(p1) = m_pow(base, x);
4445
- p1 += s1;
4446
- }
4447
- }
4448
- g->count = c;
4449
- }
2552
+ #define check_intdivzero(y) \
2553
+ {}
4450
2554
 
4451
- /*
4452
- Set logarithmic sequence of numbers to self. The sequence is obtained from
4453
- `base**(beg+i*step)`
4454
- where i is 1-dimensional index.
4455
- Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
4456
-
4457
- @overload logseq(beg,step,[base])
4458
- @param [Numeric] beg The beginning of sequence.
4459
- @param [Numeric] step The step of sequence.
4460
- @param [Numeric] base The base of log space. (default=10)
4461
- @return [Numo::SComplex] self.
2555
+ static void iter_scomplex_copysign(na_loop_t* const lp) {
2556
+ size_t i = 0;
2557
+ size_t n;
2558
+ char *p1, *p2, *p3;
2559
+ ssize_t s1, s2, s3;
4462
2560
 
4463
- @example
4464
- Numo::DFloat.new(5).logseq(4,-1,2)
4465
- # => Numo::DFloat#shape=[5]
4466
- # [16, 8, 4, 2, 1]
2561
+ INIT_COUNTER(lp, n);
2562
+ INIT_PTR(lp, 0, p1, s1);
2563
+ INIT_PTR(lp, 1, p2, s2);
2564
+ INIT_PTR(lp, 2, p3, s3);
4467
2565
 
4468
- Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
4469
- # => Numo::DComplex#shape=[5]
4470
- # [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
4471
- */
4472
- static VALUE scomplex_logseq(int argc, VALUE* argv, VALUE self) {
4473
- logseq_opt_t* g;
4474
- VALUE vbeg, vstep, vbase;
4475
- ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
4476
- ndfunc_t ndf = { iter_scomplex_logseq, FULL_LOOP, 1, 0, ain, 0 };
4477
-
4478
- g = ALLOCA_N(logseq_opt_t, 1);
4479
- rb_scan_args(argc, argv, "21", &vbeg, &vstep, &vbase);
4480
- g->beg = m_num_to_data(vbeg);
4481
- g->step = m_num_to_data(vstep);
4482
- if (vbase == Qnil) {
4483
- g->base = m_from_real(10);
4484
- } else {
4485
- g->base = m_num_to_data(vbase);
4486
- }
4487
- na_ndloop3(&ndf, g, 1, self);
4488
- return self;
4489
- }
2566
+ //
2567
+ if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype)) &&
2568
+ is_aligned(p3, sizeof(dtype))) {
4490
2569
 
4491
- static void iter_scomplex_eye(na_loop_t* const lp) {
4492
- size_t n0, n1;
4493
- size_t i0, i1;
4494
- ssize_t s0, s1;
4495
- char *p0, *p1;
4496
- char* g;
4497
- ssize_t kofs;
4498
- dtype data;
4499
-
4500
- g = (char*)(lp->opt_ptr);
4501
- kofs = *(ssize_t*)g;
4502
- data = *(dtype*)(g + sizeof(ssize_t));
4503
-
4504
- n0 = lp->args[0].shape[0];
4505
- n1 = lp->args[0].shape[1];
4506
- s0 = lp->args[0].iter[0].step;
4507
- s1 = lp->args[0].iter[1].step;
4508
- p0 = NDL_PTR(lp, 0);
4509
-
4510
- for (i0 = 0; i0 < n0; i0++) {
4511
- p1 = p0;
4512
- for (i1 = 0; i1 < n1; i1++) {
4513
- *(dtype*)p1 = (i0 + kofs == i1) ? data : m_zero;
4514
- p1 += s1;
2570
+ if (s1 == sizeof(dtype) && s2 == sizeof(dtype) && s3 == sizeof(dtype)) {
2571
+ if (p1 == p3) { // inplace case
2572
+ for (; i < n; i++) {
2573
+ check_intdivzero(((dtype*)p2)[i]);
2574
+ ((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
2575
+ }
2576
+ } else {
2577
+ for (; i < n; i++) {
2578
+ check_intdivzero(((dtype*)p2)[i]);
2579
+ ((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], ((dtype*)p2)[i]);
2580
+ }
2581
+ }
2582
+ return;
4515
2583
  }
4516
- p0 += s0;
4517
- }
4518
- }
4519
2584
 
4520
- /*
4521
- Eye: Set a value to diagonal components, set 0 to non-diagonal components.
4522
- @overload eye([element,offset])
4523
- @param [Numeric] element Diagonal element to be stored. Default is 1.
4524
- @param [Integer] offset Diagonal offset from the main diagonal. The
4525
- default is 0. k>0 for diagonals above the main diagonal, and k<0
4526
- for diagonals below the main diagonal.
4527
- @return [Numo::SComplex] eye of self.
4528
- */
4529
- static VALUE scomplex_eye(int argc, VALUE* argv, VALUE self) {
4530
- ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } };
4531
- ndfunc_t ndf = { iter_scomplex_eye, NO_LOOP, 1, 0, ain, 0 };
4532
- ssize_t kofs;
4533
- dtype data;
4534
- char* g;
4535
- int nd;
4536
- narray_t* na;
4537
-
4538
- // check arguments
4539
- if (argc > 2) {
4540
- rb_raise(rb_eArgError, "too many arguments (%d for 0..2)", argc);
4541
- } else if (argc == 2) {
4542
- data = m_num_to_data(argv[0]);
4543
- kofs = NUM2SSIZET(argv[1]);
4544
- } else if (argc == 1) {
4545
- data = m_num_to_data(argv[0]);
4546
- kofs = 0;
4547
- } else {
4548
- data = m_one;
4549
- kofs = 0;
4550
- }
2585
+ if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype)) &&
2586
+ is_aligned_step(s3, sizeof(dtype))) {
2587
+ //
4551
2588
 
4552
- GetNArray(self, na);
4553
- nd = na->ndim;
4554
- if (nd < 2) {
4555
- rb_raise(nary_eDimensionError, "less than 2-d array");
4556
- }
2589
+ if (s2 == 0) { // Broadcasting from scalar value.
2590
+ check_intdivzero(*(dtype*)p2);
2591
+ if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2592
+ if (p1 == p3) { // inplace case
2593
+ for (; i < n; i++) {
2594
+ ((dtype*)p1)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
2595
+ }
2596
+ } else {
2597
+ for (; i < n; i++) {
2598
+ ((dtype*)p3)[i] = m_copysign(((dtype*)p1)[i], *(dtype*)p2);
2599
+ }
2600
+ }
2601
+ } else {
2602
+ for (i = 0; i < n; i++) {
2603
+ *(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
2604
+ p1 += s1;
2605
+ p3 += s3;
2606
+ }
2607
+ }
2608
+ } else {
2609
+ if (p1 == p3) { // inplace case
2610
+ for (i = 0; i < n; i++) {
2611
+ check_intdivzero(*(dtype*)p2);
2612
+ *(dtype*)p1 = m_copysign(*(dtype*)p1, *(dtype*)p2);
2613
+ p1 += s1;
2614
+ p2 += s2;
2615
+ }
2616
+ } else {
2617
+ for (i = 0; i < n; i++) {
2618
+ check_intdivzero(*(dtype*)p2);
2619
+ *(dtype*)p3 = m_copysign(*(dtype*)p1, *(dtype*)p2);
2620
+ p1 += s1;
2621
+ p2 += s2;
2622
+ p3 += s3;
2623
+ }
2624
+ }
2625
+ }
4557
2626
 
4558
- // Diagonal offset from the main diagonal.
4559
- if (kofs >= 0) {
4560
- if ((size_t)(kofs) >= na->shape[nd - 1]) {
4561
- rb_raise(
4562
- rb_eArgError,
4563
- "invalid diagonal offset(%" SZF "d) for "
4564
- "last dimension size(%" SZF "d)",
4565
- kofs, na->shape[nd - 1]
4566
- );
4567
- }
4568
- } else {
4569
- if ((size_t)(-kofs) >= na->shape[nd - 2]) {
4570
- rb_raise(
4571
- rb_eArgError,
4572
- "invalid diagonal offset(%" SZF "d) for "
4573
- "last-1 dimension size(%" SZF "d)",
4574
- kofs, na->shape[nd - 2]
4575
- );
2627
+ return;
2628
+ //
4576
2629
  }
4577
2630
  }
4578
-
4579
- g = ALLOCA_N(char, sizeof(ssize_t) + sizeof(dtype));
4580
- *(ssize_t*)g = kofs;
4581
- *(dtype*)(g + sizeof(ssize_t)) = data;
4582
-
4583
- na_ndloop3(&ndf, g, 1, self);
4584
- return self;
2631
+ for (i = 0; i < n; i++) {
2632
+ dtype x, y, z;
2633
+ GET_DATA_STRIDE(p1, s1, dtype, x);
2634
+ GET_DATA_STRIDE(p2, s2, dtype, y);
2635
+ check_intdivzero(y);
2636
+ z = m_copysign(x, y);
2637
+ SET_DATA_STRIDE(p3, s3, dtype, z);
2638
+ }
2639
+ //
4585
2640
  }
2641
+ #undef check_intdivzero
4586
2642
 
4587
- typedef struct {
4588
- dtype low;
4589
- dtype max;
4590
- } rand_opt_t;
4591
-
4592
- static void iter_scomplex_rand(na_loop_t* const lp) {
4593
- size_t i;
4594
- char* p1;
4595
- ssize_t s1;
4596
- size_t* idx1;
4597
- dtype x;
4598
- rand_opt_t* g;
4599
- dtype low;
4600
- dtype max;
4601
-
4602
- INIT_COUNTER(lp, i);
4603
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
4604
- g = (rand_opt_t*)(lp->opt_ptr);
4605
- low = g->low;
4606
- max = g->max;
2643
+ static VALUE scomplex_copysign_self(VALUE self, VALUE other) {
2644
+ ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2645
+ ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2646
+ ndfunc_t ndf = { iter_scomplex_copysign, STRIDE_LOOP, 2, 1, ain, aout };
4607
2647
 
4608
- if (idx1) {
4609
- for (; i--;) {
4610
- x = m_add(m_rand(max), low);
4611
- SET_DATA_INDEX(p1, idx1, dtype, x);
4612
- }
4613
- } else {
4614
- for (; i--;) {
4615
- x = m_add(m_rand(max), low);
4616
- SET_DATA_STRIDE(p1, s1, dtype, x);
4617
- }
4618
- }
2648
+ return na_ndloop(&ndf, 2, self, other);
4619
2649
  }
4620
2650
 
4621
2651
  /*
4622
- Generate uniformly distributed random numbers on self narray.
4623
- @overload rand([[low],high])
4624
- @param [Numeric] low lower inclusive boundary of random numbers. (default=0)
4625
- @param [Numeric] high upper exclusive boundary of random numbers. (default=1 or 1+1i for
4626
- complex types)
4627
- @return [Numo::SComplex] self.
4628
- @example
4629
- Numo::DFloat.new(6).rand
4630
- # => Numo::DFloat#shape=[6]
4631
- # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
4632
-
4633
- Numo::DComplex.new(6).rand(5+5i)
4634
- # => Numo::DComplex#shape=[6]
4635
- # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
4636
-
4637
- Numo::Int32.new(6).rand(2,5)
4638
- # => Numo::Int32#shape=[6]
4639
- # [4, 3, 3, 2, 4, 2]
2652
+ Binary copysign.
2653
+ @overload copysign other
2654
+ @param [Numo::NArray,Numeric] other
2655
+ @return [Numo::NArray] self copysign other
4640
2656
  */
4641
- static VALUE scomplex_rand(int argc, VALUE* argv, VALUE self) {
4642
- rand_opt_t g;
4643
- VALUE v1 = Qnil, v2 = Qnil;
4644
- dtype high;
4645
- ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
4646
- ndfunc_t ndf = { iter_scomplex_rand, FULL_LOOP, 1, 0, ain, 0 };
4647
-
4648
- rb_scan_args(argc, argv, "02", &v1, &v2);
4649
- if (v2 == Qnil) {
4650
- g.low = m_zero;
4651
- if (v1 == Qnil) {
4652
-
4653
- g.max = high = c_new(1, 1);
2657
+ static VALUE scomplex_copysign(VALUE self, VALUE other) {
4654
2658
 
4655
- } else {
4656
- g.max = high = m_num_to_data(v1);
4657
- }
2659
+ VALUE klass, v;
4658
2660
 
2661
+ klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
2662
+ if (klass == cT) {
2663
+ return scomplex_copysign_self(self, other);
4659
2664
  } else {
4660
- g.low = m_num_to_data(v1);
4661
- high = m_num_to_data(v2);
4662
- g.max = m_sub(high, g.low);
2665
+ v = rb_funcall(klass, id_cast, 1, self);
2666
+ return rb_funcall(v, id_copysign, 1, other);
4663
2667
  }
4664
-
4665
- na_ndloop3(&ndf, &g, 1, self);
4666
- return self;
4667
2668
  }
4668
2669
 
4669
2670
  typedef struct {
@@ -4861,20 +2862,77 @@ void Init_numo_scomplex(void) {
4861
2862
  rb_define_singleton_method(cT, "cast", scomplex_s_cast, 1);
4862
2863
  rb_define_method(cT, "[]", scomplex_aref, -1);
4863
2864
  rb_define_method(cT, "[]=", scomplex_aset, -1);
2865
+ /**
2866
+ * return NArray with cast to the type of self.
2867
+ * @overload coerce_cast(type)
2868
+ * @return [nil]
2869
+ */
4864
2870
  rb_define_method(cT, "coerce_cast", scomplex_coerce_cast, 1);
2871
+ /**
2872
+ * Convert self to Array.
2873
+ * @overload to_a
2874
+ * @return [Array]
2875
+ */
4865
2876
  rb_define_method(cT, "to_a", scomplex_to_a, 0);
2877
+ /**
2878
+ * Fill elements with other.
2879
+ * @overload fill other
2880
+ * @param [Numeric] other
2881
+ * @return [Numo::SComplex] self.
2882
+ */
4866
2883
  rb_define_method(cT, "fill", scomplex_fill, 1);
2884
+ /**
2885
+ * Format elements into strings.
2886
+ * @overload format format
2887
+ * @param [String] format
2888
+ * @return [Numo::RObject] array of formatted strings.
2889
+ */
4867
2890
  rb_define_method(cT, "format", scomplex_format, -1);
2891
+ /**
2892
+ * Format elements into strings.
2893
+ * @overload format_to_a format
2894
+ * @param [String] format
2895
+ * @return [Array] array of formatted strings.
2896
+ */
4868
2897
  rb_define_method(cT, "format_to_a", scomplex_format_to_a, -1);
2898
+ /**
2899
+ * Returns a string containing a human-readable representation of NArray.
2900
+ * @overload inspect
2901
+ * @return [String]
2902
+ */
4869
2903
  rb_define_method(cT, "inspect", scomplex_inspect, 0);
4870
2904
  rb_define_method(cT, "each", scomplex_each, 0);
4871
2905
  rb_define_method(cT, "map", scomplex_map, 0);
4872
2906
  rb_define_method(cT, "each_with_index", scomplex_each_with_index, 0);
4873
2907
  rb_define_method(cT, "map_with_index", scomplex_map_with_index, 0);
4874
2908
  rb_define_method(cT, "abs", scomplex_abs, 0);
2909
+ /**
2910
+ * Binary add.
2911
+ * @overload + other
2912
+ * @param [Numo::NArray,Numeric] other
2913
+ * @return [Numo::NArray] self + other
2914
+ */
4875
2915
  rb_define_method(cT, "+", scomplex_add, 1);
2916
+ /**
2917
+ * Binary sub.
2918
+ * @overload - other
2919
+ * @param [Numo::NArray,Numeric] other
2920
+ * @return [Numo::NArray] self - other
2921
+ */
4876
2922
  rb_define_method(cT, "-", scomplex_sub, 1);
2923
+ /**
2924
+ * Binary mul.
2925
+ * @overload * other
2926
+ * @param [Numo::NArray,Numeric] other
2927
+ * @return [Numo::NArray] self * other
2928
+ */
4877
2929
  rb_define_method(cT, "*", scomplex_mul, 1);
2930
+ /**
2931
+ * Binary div.
2932
+ * @overload / other
2933
+ * @param [Numo::NArray,Numeric] other
2934
+ * @return [Numo::NArray] self / other
2935
+ */
4878
2936
  rb_define_method(cT, "/", scomplex_div, 1);
4879
2937
  rb_define_method(cT, "**", scomplex_pow, 1);
4880
2938
  rb_define_alias(cT, "pow", "**");
@@ -4893,22 +2951,110 @@ void Init_numo_scomplex(void) {
4893
2951
  rb_define_alias(cT, "imag=", "set_imag");
4894
2952
  rb_define_alias(cT, "real=", "set_real");
4895
2953
  rb_define_alias(cT, "conjugate", "conj");
2954
+ /**
2955
+ * Comparison eq other.
2956
+ * @overload eq other
2957
+ * @param [Numo::NArray,Numeric] other
2958
+ * @return [Numo::Bit] result of self eq other.
2959
+ */
4896
2960
  rb_define_method(cT, "eq", scomplex_eq, 1);
2961
+ /**
2962
+ * Comparison ne other.
2963
+ * @overload ne other
2964
+ * @param [Numo::NArray,Numeric] other
2965
+ * @return [Numo::Bit] result of self ne other.
2966
+ */
4897
2967
  rb_define_method(cT, "ne", scomplex_ne, 1);
2968
+ /**
2969
+ * Comparison nearly_eq other.
2970
+ * @overload nearly_eq other
2971
+ * @param [Numo::NArray,Numeric] other
2972
+ * @return [Numo::Bit] result of self nearly_eq other.
2973
+ */
4898
2974
  rb_define_method(cT, "nearly_eq", scomplex_nearly_eq, 1);
4899
2975
  rb_define_alias(cT, "close_to", "nearly_eq");
2976
+ /**
2977
+ * Unary floor.
2978
+ * @overload floor
2979
+ * @return [Numo::SComplex] floor of self.
2980
+ */
4900
2981
  rb_define_method(cT, "floor", scomplex_floor, 0);
2982
+ /**
2983
+ * Unary round.
2984
+ * @overload round
2985
+ * @return [Numo::SComplex] round of self.
2986
+ */
4901
2987
  rb_define_method(cT, "round", scomplex_round, 0);
2988
+ /**
2989
+ * Unary ceil.
2990
+ * @overload ceil
2991
+ * @return [Numo::SComplex] ceil of self.
2992
+ */
4902
2993
  rb_define_method(cT, "ceil", scomplex_ceil, 0);
2994
+ /**
2995
+ * Unary trunc.
2996
+ * @overload trunc
2997
+ * @return [Numo::SComplex] trunc of self.
2998
+ */
4903
2999
  rb_define_method(cT, "trunc", scomplex_trunc, 0);
3000
+ /**
3001
+ * Unary rint.
3002
+ * @overload rint
3003
+ * @return [Numo::SComplex] rint of self.
3004
+ */
4904
3005
  rb_define_method(cT, "rint", scomplex_rint, 0);
4905
3006
  rb_define_method(cT, "copysign", scomplex_copysign, 1);
3007
+ /**
3008
+ * Condition of isnan.
3009
+ * @overload isnan
3010
+ * @return [Numo::Bit] Condition of isnan.
3011
+ */
4906
3012
  rb_define_method(cT, "isnan", scomplex_isnan, 0);
3013
+ /**
3014
+ * Condition of isinf.
3015
+ * @overload isinf
3016
+ * @return [Numo::Bit] Condition of isinf.
3017
+ */
4907
3018
  rb_define_method(cT, "isinf", scomplex_isinf, 0);
3019
+ /**
3020
+ * Condition of isposinf.
3021
+ * @overload isposinf
3022
+ * @return [Numo::Bit] Condition of isposinf.
3023
+ */
4908
3024
  rb_define_method(cT, "isposinf", scomplex_isposinf, 0);
3025
+ /**
3026
+ * Condition of isneginf.
3027
+ * @overload isneginf
3028
+ * @return [Numo::Bit] Condition of isneginf.
3029
+ */
4909
3030
  rb_define_method(cT, "isneginf", scomplex_isneginf, 0);
3031
+ /**
3032
+ * Condition of isfinite.
3033
+ * @overload isfinite
3034
+ * @return [Numo::Bit] Condition of isfinite.
3035
+ */
4910
3036
  rb_define_method(cT, "isfinite", scomplex_isfinite, 0);
3037
+ /**
3038
+ * sum of self.
3039
+ * @overload sum(axis:nil, keepdims:false, nan:false)
3040
+ * @param [TrueClass] nan If true, apply NaN-aware algorithm
3041
+ * (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
3042
+ * @param [Numeric,Array,Range] axis Performs sum along the axis.
3043
+ * @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
3044
+ * dimensions with size one.
3045
+ * @return [Numo::SComplex] returns result of sum.
3046
+ */
4911
3047
  rb_define_method(cT, "sum", scomplex_sum, -1);
3048
+ /**
3049
+ * prod of self.
3050
+ * @overload prod(axis:nil, keepdims:false, nan:false)
3051
+ * @param [TrueClass] nan If true, apply NaN-aware algorithm
3052
+ * (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
3053
+ * @param [Numeric,Array,Range] axis Performs prod along the axis.
3054
+ * @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
3055
+ * dimensions with size one.
3056
+ * @return [Numo::SComplex] returns result of prod.
3057
+ */
4912
3058
  rb_define_method(cT, "prod", scomplex_prod, -1);
4913
3059
  /**
4914
3060
  * mean of self.
@@ -4954,13 +3100,106 @@ void Init_numo_scomplex(void) {
4954
3100
  * @return [Numo::SFloat] returns result of rms.
4955
3101
  */
4956
3102
  rb_define_method(cT, "rms", scomplex_rms, -1);
3103
+ /**
3104
+ * cumsum of self.
3105
+ * @overload cumsum(axis:nil, nan:false)
3106
+ * @param [Numeric,Array,Range] axis Performs cumsum along the axis.
3107
+ * @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
3108
+ * @return [Numo::SComplex] cumsum of self.
3109
+ */
4957
3110
  rb_define_method(cT, "cumsum", scomplex_cumsum, -1);
3111
+ /**
3112
+ * cumprod of self.
3113
+ * @overload cumprod(axis:nil, nan:false)
3114
+ * @param [Numeric,Array,Range] axis Performs cumprod along the axis.
3115
+ * @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
3116
+ * @return [Numo::SComplex] cumprod of self.
3117
+ */
4958
3118
  rb_define_method(cT, "cumprod", scomplex_cumprod, -1);
3119
+ /**
3120
+ * Binary mulsum.
3121
+ *
3122
+ * @overload mulsum(other, axis:nil, keepdims:false, nan:false)
3123
+ * @param [Numo::NArray,Numeric] other
3124
+ * @param [Numeric,Array,Range] axis Performs mulsum along the axis.
3125
+ * @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in
3126
+ * the result array as dimensions with size one.
3127
+ * @param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm
3128
+ * (avoid NaN if exists).
3129
+ * @return [Numo::NArray] mulsum of self and other.
3130
+ */
4959
3131
  rb_define_method(cT, "mulsum", scomplex_mulsum, -1);
3132
+ /**
3133
+ * Set linear sequence of numbers to self. The sequence is obtained from
3134
+ * beg+i*step
3135
+ * where i is 1-dimensional index.
3136
+ * @overload seq([beg,[step]])
3137
+ * @param [Numeric] beg beginning of sequence. (default=0)
3138
+ * @param [Numeric] step step of sequence. (default=1)
3139
+ * @return [Numo::SComplex] self.
3140
+ * @example
3141
+ * Numo::DFloat.new(6).seq(1,-0.2)
3142
+ * # => Numo::DFloat#shape=[6]
3143
+ * # [1, 0.8, 0.6, 0.4, 0.2, 0]
3144
+ *
3145
+ * Numo::DComplex.new(6).seq(1,-0.2+0.2i)
3146
+ * # => Numo::DComplex#shape=[6]
3147
+ * # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
3148
+ */
4960
3149
  rb_define_method(cT, "seq", scomplex_seq, -1);
3150
+ /**
3151
+ * Set logarithmic sequence of numbers to self. The sequence is obtained from
3152
+ * `base**(beg+i*step)`
3153
+ * where i is 1-dimensional index.
3154
+ * Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
3155
+ *
3156
+ * @overload logseq(beg,step,[base])
3157
+ * @param [Numeric] beg The beginning of sequence.
3158
+ * @param [Numeric] step The step of sequence.
3159
+ * @param [Numeric] base The base of log space. (default=10)
3160
+ * @return [Numo::SComplex] self.
3161
+ *
3162
+ * @example
3163
+ * Numo::DFloat.new(5).logseq(4,-1,2)
3164
+ * # => Numo::DFloat#shape=[5]
3165
+ * # [16, 8, 4, 2, 1]
3166
+ *
3167
+ * Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
3168
+ * # => Numo::DComplex#shape=[5]
3169
+ * # [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
3170
+ */
4961
3171
  rb_define_method(cT, "logseq", scomplex_logseq, -1);
3172
+ /**
3173
+ * Eye: Set a value to diagonal components, set 0 to non-diagonal components.
3174
+ * @overload eye([element,offset])
3175
+ * @param [Numeric] element Diagonal element to be stored. Default is 1.
3176
+ * @param [Integer] offset Diagonal offset from the main diagonal. The
3177
+ * default is 0. k>0 for diagonals above the main diagonal, and k<0
3178
+ * for diagonals below the main diagonal.
3179
+ * @return [Numo::SComplex] eye of self.
3180
+ */
4962
3181
  rb_define_method(cT, "eye", scomplex_eye, -1);
4963
3182
  rb_define_alias(cT, "indgen", "seq");
3183
+ /**
3184
+ * Generate uniformly distributed random numbers on self narray.
3185
+ * @overload rand([[low],high])
3186
+ * @param [Numeric] low lower inclusive boundary of random numbers. (default=0)
3187
+ * @param [Numeric] high upper exclusive boundary of random numbers.
3188
+ * (default=1 or 1+1i for complex types)
3189
+ * @return [Numo::SComplex] self.
3190
+ * @example
3191
+ * Numo::DFloat.new(6).rand
3192
+ * # => Numo::DFloat#shape=[6]
3193
+ * # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
3194
+ *
3195
+ * Numo::DComplex.new(6).rand(5+5i)
3196
+ * # => Numo::DComplex#shape=[6]
3197
+ * # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
3198
+ *
3199
+ * Numo::Int32.new(6).rand(2,5)
3200
+ * # => Numo::Int32#shape=[6]
3201
+ * # [4, 3, 3, 2, 4, 2]
3202
+ */
4964
3203
  rb_define_method(cT, "rand", scomplex_rand, -1);
4965
3204
  rb_define_method(cT, "rand_norm", scomplex_rand_norm, -1);
4966
3205
  rb_define_method(cT, "poly", scomplex_poly, -2);