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