numo-narray-alt 0.9.12 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,6 +55,11 @@ extern VALUE cRT;
55
55
  #include "mh/op/div.h"
56
56
  #include "mh/op/mod.h"
57
57
  #include "mh/divmod.h"
58
+ #include "mh/pow.h"
59
+ #include "mh/minus.h"
60
+ #include "mh/reciprocal.h"
61
+ #include "mh/sign.h"
62
+ #include "mh/square.h"
58
63
  #include "mh/comp/eq.h"
59
64
  #include "mh/comp/ne.h"
60
65
  #include "mh/comp/gt.h"
@@ -106,6 +111,11 @@ DEF_NARRAY_INT8_MUL_METHOD_FUNC(int8, numo_cInt8)
106
111
  DEF_NARRAY_INT8_DIV_METHOD_FUNC(int8, numo_cInt8)
107
112
  DEF_NARRAY_INT8_MOD_METHOD_FUNC(int8, numo_cInt8)
108
113
  DEF_NARRAY_INT_DIVMOD_METHOD_FUNC(int8, numo_cInt8)
114
+ DEF_NARRAY_POW_METHOD_FUNC(int8, numo_cInt8)
115
+ DEF_NARRAY_INT8_MINUS_METHOD_FUNC(int8, numo_cInt8)
116
+ DEF_NARRAY_INT8_RECIPROCAL_METHOD_FUNC(int8, numo_cInt8)
117
+ DEF_NARRAY_INT8_SIGN_METHOD_FUNC(int8, numo_cInt8)
118
+ DEF_NARRAY_INT8_SQUARE_METHOD_FUNC(int8, numo_cInt8)
109
119
  DEF_NARRAY_EQ_METHOD_FUNC(int8, numo_cInt8)
110
120
  DEF_NARRAY_NE_METHOD_FUNC(int8, numo_cInt8)
111
121
  DEF_NARRAY_GT_METHOD_FUNC(int8, numo_cInt8)
@@ -1611,306 +1621,6 @@ static VALUE int8_abs(VALUE self) {
1611
1621
  return na_ndloop(&ndf, 1, self);
1612
1622
  }
1613
1623
 
1614
- static void iter_int8_pow(na_loop_t* const lp) {
1615
- size_t i;
1616
- char *p1, *p2, *p3;
1617
- ssize_t s1, s2, s3;
1618
- dtype x, y;
1619
- INIT_COUNTER(lp, i);
1620
- INIT_PTR(lp, 0, p1, s1);
1621
- INIT_PTR(lp, 1, p2, s2);
1622
- INIT_PTR(lp, 2, p3, s3);
1623
- for (; i--;) {
1624
- GET_DATA_STRIDE(p1, s1, dtype, x);
1625
- GET_DATA_STRIDE(p2, s2, dtype, y);
1626
- x = m_pow(x, y);
1627
- SET_DATA_STRIDE(p3, s3, dtype, x);
1628
- }
1629
- }
1630
-
1631
- static void iter_int8_pow_int32(na_loop_t* const lp) {
1632
- size_t i;
1633
- char *p1, *p2, *p3;
1634
- ssize_t s1, s2, s3;
1635
- dtype x;
1636
- int32_t y;
1637
- INIT_COUNTER(lp, i);
1638
- INIT_PTR(lp, 0, p1, s1);
1639
- INIT_PTR(lp, 1, p2, s2);
1640
- INIT_PTR(lp, 2, p3, s3);
1641
- for (; i--;) {
1642
- GET_DATA_STRIDE(p1, s1, dtype, x);
1643
- GET_DATA_STRIDE(p2, s2, int32_t, y);
1644
- x = m_pow_int(x, y);
1645
- SET_DATA_STRIDE(p3, s3, dtype, x);
1646
- }
1647
- }
1648
-
1649
- static VALUE int8_pow_self(VALUE self, VALUE other) {
1650
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
1651
- ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
1652
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1653
- ndfunc_t ndf = { iter_int8_pow, STRIDE_LOOP, 2, 1, ain, aout };
1654
- ndfunc_t ndf_i = { iter_int8_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
1655
-
1656
- // fixme : use na.integer?
1657
- if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
1658
- return na_ndloop(&ndf_i, 2, self, other);
1659
- } else {
1660
- return na_ndloop(&ndf, 2, self, other);
1661
- }
1662
- }
1663
-
1664
- /*
1665
- Binary power.
1666
- @overload ** other
1667
- @param [Numo::NArray,Numeric] other
1668
- @return [Numo::NArray] self to the other-th power.
1669
- */
1670
- static VALUE int8_pow(VALUE self, VALUE other) {
1671
-
1672
- VALUE klass, v;
1673
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
1674
- if (klass == cT) {
1675
- return int8_pow_self(self, other);
1676
- } else {
1677
- v = rb_funcall(klass, id_cast, 1, self);
1678
- return rb_funcall(v, id_pow, 1, other);
1679
- }
1680
- }
1681
-
1682
- static void iter_int8_minus(na_loop_t* const lp) {
1683
- size_t i, n;
1684
- char *p1, *p2;
1685
- ssize_t s1, s2;
1686
- size_t *idx1, *idx2;
1687
- dtype x;
1688
-
1689
- INIT_COUNTER(lp, n);
1690
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1691
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1692
-
1693
- if (idx1) {
1694
- if (idx2) {
1695
- for (i = 0; i < n; i++) {
1696
- GET_DATA_INDEX(p1, idx1, dtype, x);
1697
- x = m_minus(x);
1698
- SET_DATA_INDEX(p2, idx2, dtype, x);
1699
- }
1700
- } else {
1701
- for (i = 0; i < n; i++) {
1702
- GET_DATA_INDEX(p1, idx1, dtype, x);
1703
- x = m_minus(x);
1704
- SET_DATA_STRIDE(p2, s2, dtype, x);
1705
- }
1706
- }
1707
- } else {
1708
- if (idx2) {
1709
- for (i = 0; i < n; i++) {
1710
- GET_DATA_STRIDE(p1, s1, dtype, x);
1711
- x = m_minus(x);
1712
- SET_DATA_INDEX(p2, idx2, dtype, x);
1713
- }
1714
- } else {
1715
- //
1716
- for (i = 0; i < n; i++) {
1717
- *(dtype*)p2 = m_minus(*(dtype*)p1);
1718
- p1 += s1;
1719
- p2 += s2;
1720
- }
1721
- return;
1722
- //
1723
- }
1724
- }
1725
- }
1726
-
1727
- /*
1728
- Unary minus.
1729
- @overload -@
1730
- @return [Numo::Int8] minus of self.
1731
- */
1732
- static VALUE int8_minus(VALUE self) {
1733
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1734
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1735
- ndfunc_t ndf = { iter_int8_minus, FULL_LOOP, 1, 1, ain, aout };
1736
-
1737
- return na_ndloop(&ndf, 1, self);
1738
- }
1739
-
1740
- static void iter_int8_reciprocal(na_loop_t* const lp) {
1741
- size_t i, n;
1742
- char *p1, *p2;
1743
- ssize_t s1, s2;
1744
- size_t *idx1, *idx2;
1745
- dtype x;
1746
-
1747
- INIT_COUNTER(lp, n);
1748
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1749
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1750
-
1751
- if (idx1) {
1752
- if (idx2) {
1753
- for (i = 0; i < n; i++) {
1754
- GET_DATA_INDEX(p1, idx1, dtype, x);
1755
- x = m_reciprocal(x);
1756
- SET_DATA_INDEX(p2, idx2, dtype, x);
1757
- }
1758
- } else {
1759
- for (i = 0; i < n; i++) {
1760
- GET_DATA_INDEX(p1, idx1, dtype, x);
1761
- x = m_reciprocal(x);
1762
- SET_DATA_STRIDE(p2, s2, dtype, x);
1763
- }
1764
- }
1765
- } else {
1766
- if (idx2) {
1767
- for (i = 0; i < n; i++) {
1768
- GET_DATA_STRIDE(p1, s1, dtype, x);
1769
- x = m_reciprocal(x);
1770
- SET_DATA_INDEX(p2, idx2, dtype, x);
1771
- }
1772
- } else {
1773
- //
1774
- for (i = 0; i < n; i++) {
1775
- *(dtype*)p2 = m_reciprocal(*(dtype*)p1);
1776
- p1 += s1;
1777
- p2 += s2;
1778
- }
1779
- return;
1780
- //
1781
- }
1782
- }
1783
- }
1784
-
1785
- /*
1786
- Unary reciprocal.
1787
- @overload reciprocal
1788
- @return [Numo::Int8] reciprocal of self.
1789
- */
1790
- static VALUE int8_reciprocal(VALUE self) {
1791
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1792
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1793
- ndfunc_t ndf = { iter_int8_reciprocal, FULL_LOOP, 1, 1, ain, aout };
1794
-
1795
- return na_ndloop(&ndf, 1, self);
1796
- }
1797
-
1798
- static void iter_int8_sign(na_loop_t* const lp) {
1799
- size_t i, n;
1800
- char *p1, *p2;
1801
- ssize_t s1, s2;
1802
- size_t *idx1, *idx2;
1803
- dtype x;
1804
-
1805
- INIT_COUNTER(lp, n);
1806
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1807
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1808
-
1809
- if (idx1) {
1810
- if (idx2) {
1811
- for (i = 0; i < n; i++) {
1812
- GET_DATA_INDEX(p1, idx1, dtype, x);
1813
- x = m_sign(x);
1814
- SET_DATA_INDEX(p2, idx2, dtype, x);
1815
- }
1816
- } else {
1817
- for (i = 0; i < n; i++) {
1818
- GET_DATA_INDEX(p1, idx1, dtype, x);
1819
- x = m_sign(x);
1820
- SET_DATA_STRIDE(p2, s2, dtype, x);
1821
- }
1822
- }
1823
- } else {
1824
- if (idx2) {
1825
- for (i = 0; i < n; i++) {
1826
- GET_DATA_STRIDE(p1, s1, dtype, x);
1827
- x = m_sign(x);
1828
- SET_DATA_INDEX(p2, idx2, dtype, x);
1829
- }
1830
- } else {
1831
- //
1832
- for (i = 0; i < n; i++) {
1833
- *(dtype*)p2 = m_sign(*(dtype*)p1);
1834
- p1 += s1;
1835
- p2 += s2;
1836
- }
1837
- return;
1838
- //
1839
- }
1840
- }
1841
- }
1842
-
1843
- /*
1844
- Unary sign.
1845
- @overload sign
1846
- @return [Numo::Int8] sign of self.
1847
- */
1848
- static VALUE int8_sign(VALUE self) {
1849
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1850
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1851
- ndfunc_t ndf = { iter_int8_sign, FULL_LOOP, 1, 1, ain, aout };
1852
-
1853
- return na_ndloop(&ndf, 1, self);
1854
- }
1855
-
1856
- static void iter_int8_square(na_loop_t* const lp) {
1857
- size_t i, n;
1858
- char *p1, *p2;
1859
- ssize_t s1, s2;
1860
- size_t *idx1, *idx2;
1861
- dtype x;
1862
-
1863
- INIT_COUNTER(lp, n);
1864
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1865
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1866
-
1867
- if (idx1) {
1868
- if (idx2) {
1869
- for (i = 0; i < n; i++) {
1870
- GET_DATA_INDEX(p1, idx1, dtype, x);
1871
- x = m_square(x);
1872
- SET_DATA_INDEX(p2, idx2, dtype, x);
1873
- }
1874
- } else {
1875
- for (i = 0; i < n; i++) {
1876
- GET_DATA_INDEX(p1, idx1, dtype, x);
1877
- x = m_square(x);
1878
- SET_DATA_STRIDE(p2, s2, dtype, x);
1879
- }
1880
- }
1881
- } else {
1882
- if (idx2) {
1883
- for (i = 0; i < n; i++) {
1884
- GET_DATA_STRIDE(p1, s1, dtype, x);
1885
- x = m_square(x);
1886
- SET_DATA_INDEX(p2, idx2, dtype, x);
1887
- }
1888
- } else {
1889
- //
1890
- for (i = 0; i < n; i++) {
1891
- *(dtype*)p2 = m_square(*(dtype*)p1);
1892
- p1 += s1;
1893
- p2 += s2;
1894
- }
1895
- return;
1896
- //
1897
- }
1898
- }
1899
- }
1900
-
1901
- /*
1902
- Unary square.
1903
- @overload square
1904
- @return [Numo::Int8] square of self.
1905
- */
1906
- static VALUE int8_square(VALUE self) {
1907
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1908
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1909
- ndfunc_t ndf = { iter_int8_square, FULL_LOOP, 1, 1, ain, aout };
1910
-
1911
- return na_ndloop(&ndf, 1, self);
1912
- }
1913
-
1914
1624
  static void iter_int8_poly(na_loop_t* const lp) {
1915
1625
  size_t i;
1916
1626
  dtype x, y, a;
@@ -2620,11 +2330,37 @@ void Init_numo_int8(void) {
2620
2330
  * @return [Numo::NArray] divmod of self and other.
2621
2331
  */
2622
2332
  rb_define_method(cT, "divmod", int8_divmod, 1);
2333
+ /**
2334
+ * Binary power.
2335
+ * @overload ** other
2336
+ * @param [Numo::NArray,Numeric] other
2337
+ * @return [Numo::NArray] self to the other-th power.
2338
+ */
2623
2339
  rb_define_method(cT, "**", int8_pow, 1);
2624
2340
  rb_define_alias(cT, "pow", "**");
2341
+ /**
2342
+ * Unary minus.
2343
+ * @overload -@
2344
+ * @return [Numo::Int8] minus of self.
2345
+ */
2625
2346
  rb_define_method(cT, "-@", int8_minus, 0);
2347
+ /**
2348
+ * Unary reciprocal.
2349
+ * @overload reciprocal
2350
+ * @return [Numo::Int8] reciprocal of self.
2351
+ */
2626
2352
  rb_define_method(cT, "reciprocal", int8_reciprocal, 0);
2353
+ /**
2354
+ * Unary sign.
2355
+ * @overload sign
2356
+ * @return [Numo::Int8] sign of self.
2357
+ */
2627
2358
  rb_define_method(cT, "sign", int8_sign, 0);
2359
+ /**
2360
+ * Unary square.
2361
+ * @overload square
2362
+ * @return [Numo::Int8] square of self.
2363
+ */
2628
2364
  rb_define_method(cT, "square", int8_square, 0);
2629
2365
  rb_define_alias(cT, "conj", "view");
2630
2366
  rb_define_alias(cT, "im", "view");
@@ -72,6 +72,11 @@ extern VALUE cRT;
72
72
  #include "mh/op/div.h"
73
73
  #include "mh/op/mod.h"
74
74
  #include "mh/divmod.h"
75
+ #include "mh/pow.h"
76
+ #include "mh/minus.h"
77
+ #include "mh/reciprocal.h"
78
+ #include "mh/sign.h"
79
+ #include "mh/square.h"
75
80
  #include "mh/round/floor.h"
76
81
  #include "mh/round/round.h"
77
82
  #include "mh/round/ceil.h"
@@ -133,6 +138,11 @@ DEF_NARRAY_ROBJ_MUL_METHOD_FUNC()
133
138
  DEF_NARRAY_ROBJ_DIV_METHOD_FUNC()
134
139
  DEF_NARRAY_ROBJ_MOD_METHOD_FUNC()
135
140
  DEF_NARRAY_ROBJ_DIVMOD_METHOD_FUNC()
141
+ DEF_NARRAY_ROBJ_POW_METHOD_FUNC()
142
+ DEF_NARRAY_ROBJ_MINUS_METHOD_FUNC()
143
+ DEF_NARRAY_ROBJ_RECIPROCAL_METHOD_FUNC()
144
+ DEF_NARRAY_ROBJ_SIGN_METHOD_FUNC()
145
+ DEF_NARRAY_ROBJ_SQUARE_METHOD_FUNC()
136
146
  DEF_NARRAY_ROBJ_FLOOR_METHOD_FUNC()
137
147
  DEF_NARRAY_ROBJ_ROUND_METHOD_FUNC()
138
148
  DEF_NARRAY_ROBJ_CEIL_METHOD_FUNC()
@@ -1663,298 +1673,6 @@ static VALUE robject_abs(VALUE self) {
1663
1673
  return na_ndloop(&ndf, 1, self);
1664
1674
  }
1665
1675
 
1666
- static void iter_robject_pow(na_loop_t* const lp) {
1667
- size_t i;
1668
- char *p1, *p2, *p3;
1669
- ssize_t s1, s2, s3;
1670
- dtype x, y;
1671
- INIT_COUNTER(lp, i);
1672
- INIT_PTR(lp, 0, p1, s1);
1673
- INIT_PTR(lp, 1, p2, s2);
1674
- INIT_PTR(lp, 2, p3, s3);
1675
- for (; i--;) {
1676
- GET_DATA_STRIDE(p1, s1, dtype, x);
1677
- GET_DATA_STRIDE(p2, s2, dtype, y);
1678
- x = m_pow(x, y);
1679
- SET_DATA_STRIDE(p3, s3, dtype, x);
1680
- }
1681
- }
1682
-
1683
- static void iter_robject_pow_int32(na_loop_t* const lp) {
1684
- size_t i;
1685
- char *p1, *p2, *p3;
1686
- ssize_t s1, s2, s3;
1687
- dtype x;
1688
- int32_t y;
1689
- INIT_COUNTER(lp, i);
1690
- INIT_PTR(lp, 0, p1, s1);
1691
- INIT_PTR(lp, 1, p2, s2);
1692
- INIT_PTR(lp, 2, p3, s3);
1693
- for (; i--;) {
1694
- GET_DATA_STRIDE(p1, s1, dtype, x);
1695
- GET_DATA_STRIDE(p2, s2, int32_t, y);
1696
- x = m_pow_int(x, y);
1697
- SET_DATA_STRIDE(p3, s3, dtype, x);
1698
- }
1699
- }
1700
-
1701
- static VALUE robject_pow_self(VALUE self, VALUE other) {
1702
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
1703
- ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
1704
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1705
- ndfunc_t ndf = { iter_robject_pow, STRIDE_LOOP, 2, 1, ain, aout };
1706
- ndfunc_t ndf_i = { iter_robject_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
1707
-
1708
- // fixme : use na.integer?
1709
- if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
1710
- return na_ndloop(&ndf_i, 2, self, other);
1711
- } else {
1712
- return na_ndloop(&ndf, 2, self, other);
1713
- }
1714
- }
1715
-
1716
- /*
1717
- Binary power.
1718
- @overload ** other
1719
- @param [Numo::NArray,Numeric] other
1720
- @return [Numo::NArray] self to the other-th power.
1721
- */
1722
- static VALUE robject_pow(VALUE self, VALUE other) {
1723
- return robject_pow_self(self, other);
1724
- }
1725
-
1726
- static void iter_robject_minus(na_loop_t* const lp) {
1727
- size_t i, n;
1728
- char *p1, *p2;
1729
- ssize_t s1, s2;
1730
- size_t *idx1, *idx2;
1731
- dtype x;
1732
-
1733
- INIT_COUNTER(lp, n);
1734
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1735
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1736
-
1737
- if (idx1) {
1738
- if (idx2) {
1739
- for (i = 0; i < n; i++) {
1740
- GET_DATA_INDEX(p1, idx1, dtype, x);
1741
- x = m_minus(x);
1742
- SET_DATA_INDEX(p2, idx2, dtype, x);
1743
- }
1744
- } else {
1745
- for (i = 0; i < n; i++) {
1746
- GET_DATA_INDEX(p1, idx1, dtype, x);
1747
- x = m_minus(x);
1748
- SET_DATA_STRIDE(p2, s2, dtype, x);
1749
- }
1750
- }
1751
- } else {
1752
- if (idx2) {
1753
- for (i = 0; i < n; i++) {
1754
- GET_DATA_STRIDE(p1, s1, dtype, x);
1755
- x = m_minus(x);
1756
- SET_DATA_INDEX(p2, idx2, dtype, x);
1757
- }
1758
- } else {
1759
- //
1760
- for (i = 0; i < n; i++) {
1761
- *(dtype*)p2 = m_minus(*(dtype*)p1);
1762
- p1 += s1;
1763
- p2 += s2;
1764
- }
1765
- return;
1766
- //
1767
- }
1768
- }
1769
- }
1770
-
1771
- /*
1772
- Unary minus.
1773
- @overload -@
1774
- @return [Numo::RObject] minus of self.
1775
- */
1776
- static VALUE robject_minus(VALUE self) {
1777
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1778
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1779
- ndfunc_t ndf = { iter_robject_minus, FULL_LOOP, 1, 1, ain, aout };
1780
-
1781
- return na_ndloop(&ndf, 1, self);
1782
- }
1783
-
1784
- static void iter_robject_reciprocal(na_loop_t* const lp) {
1785
- size_t i, n;
1786
- char *p1, *p2;
1787
- ssize_t s1, s2;
1788
- size_t *idx1, *idx2;
1789
- dtype x;
1790
-
1791
- INIT_COUNTER(lp, n);
1792
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1793
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1794
-
1795
- if (idx1) {
1796
- if (idx2) {
1797
- for (i = 0; i < n; i++) {
1798
- GET_DATA_INDEX(p1, idx1, dtype, x);
1799
- x = m_reciprocal(x);
1800
- SET_DATA_INDEX(p2, idx2, dtype, x);
1801
- }
1802
- } else {
1803
- for (i = 0; i < n; i++) {
1804
- GET_DATA_INDEX(p1, idx1, dtype, x);
1805
- x = m_reciprocal(x);
1806
- SET_DATA_STRIDE(p2, s2, dtype, x);
1807
- }
1808
- }
1809
- } else {
1810
- if (idx2) {
1811
- for (i = 0; i < n; i++) {
1812
- GET_DATA_STRIDE(p1, s1, dtype, x);
1813
- x = m_reciprocal(x);
1814
- SET_DATA_INDEX(p2, idx2, dtype, x);
1815
- }
1816
- } else {
1817
- //
1818
- for (i = 0; i < n; i++) {
1819
- *(dtype*)p2 = m_reciprocal(*(dtype*)p1);
1820
- p1 += s1;
1821
- p2 += s2;
1822
- }
1823
- return;
1824
- //
1825
- }
1826
- }
1827
- }
1828
-
1829
- /*
1830
- Unary reciprocal.
1831
- @overload reciprocal
1832
- @return [Numo::RObject] reciprocal of self.
1833
- */
1834
- static VALUE robject_reciprocal(VALUE self) {
1835
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1836
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1837
- ndfunc_t ndf = { iter_robject_reciprocal, FULL_LOOP, 1, 1, ain, aout };
1838
-
1839
- return na_ndloop(&ndf, 1, self);
1840
- }
1841
-
1842
- static void iter_robject_sign(na_loop_t* const lp) {
1843
- size_t i, n;
1844
- char *p1, *p2;
1845
- ssize_t s1, s2;
1846
- size_t *idx1, *idx2;
1847
- dtype x;
1848
-
1849
- INIT_COUNTER(lp, n);
1850
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1851
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1852
-
1853
- if (idx1) {
1854
- if (idx2) {
1855
- for (i = 0; i < n; i++) {
1856
- GET_DATA_INDEX(p1, idx1, dtype, x);
1857
- x = m_sign(x);
1858
- SET_DATA_INDEX(p2, idx2, dtype, x);
1859
- }
1860
- } else {
1861
- for (i = 0; i < n; i++) {
1862
- GET_DATA_INDEX(p1, idx1, dtype, x);
1863
- x = m_sign(x);
1864
- SET_DATA_STRIDE(p2, s2, dtype, x);
1865
- }
1866
- }
1867
- } else {
1868
- if (idx2) {
1869
- for (i = 0; i < n; i++) {
1870
- GET_DATA_STRIDE(p1, s1, dtype, x);
1871
- x = m_sign(x);
1872
- SET_DATA_INDEX(p2, idx2, dtype, x);
1873
- }
1874
- } else {
1875
- //
1876
- for (i = 0; i < n; i++) {
1877
- *(dtype*)p2 = m_sign(*(dtype*)p1);
1878
- p1 += s1;
1879
- p2 += s2;
1880
- }
1881
- return;
1882
- //
1883
- }
1884
- }
1885
- }
1886
-
1887
- /*
1888
- Unary sign.
1889
- @overload sign
1890
- @return [Numo::RObject] sign of self.
1891
- */
1892
- static VALUE robject_sign(VALUE self) {
1893
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1894
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1895
- ndfunc_t ndf = { iter_robject_sign, FULL_LOOP, 1, 1, ain, aout };
1896
-
1897
- return na_ndloop(&ndf, 1, self);
1898
- }
1899
-
1900
- static void iter_robject_square(na_loop_t* const lp) {
1901
- size_t i, n;
1902
- char *p1, *p2;
1903
- ssize_t s1, s2;
1904
- size_t *idx1, *idx2;
1905
- dtype x;
1906
-
1907
- INIT_COUNTER(lp, n);
1908
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1909
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1910
-
1911
- if (idx1) {
1912
- if (idx2) {
1913
- for (i = 0; i < n; i++) {
1914
- GET_DATA_INDEX(p1, idx1, dtype, x);
1915
- x = m_square(x);
1916
- SET_DATA_INDEX(p2, idx2, dtype, x);
1917
- }
1918
- } else {
1919
- for (i = 0; i < n; i++) {
1920
- GET_DATA_INDEX(p1, idx1, dtype, x);
1921
- x = m_square(x);
1922
- SET_DATA_STRIDE(p2, s2, dtype, x);
1923
- }
1924
- }
1925
- } else {
1926
- if (idx2) {
1927
- for (i = 0; i < n; i++) {
1928
- GET_DATA_STRIDE(p1, s1, dtype, x);
1929
- x = m_square(x);
1930
- SET_DATA_INDEX(p2, idx2, dtype, x);
1931
- }
1932
- } else {
1933
- //
1934
- for (i = 0; i < n; i++) {
1935
- *(dtype*)p2 = m_square(*(dtype*)p1);
1936
- p1 += s1;
1937
- p2 += s2;
1938
- }
1939
- return;
1940
- //
1941
- }
1942
- }
1943
- }
1944
-
1945
- /*
1946
- Unary square.
1947
- @overload square
1948
- @return [Numo::RObject] square of self.
1949
- */
1950
- static VALUE robject_square(VALUE self) {
1951
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1952
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1953
- ndfunc_t ndf = { iter_robject_square, FULL_LOOP, 1, 1, ain, aout };
1954
-
1955
- return na_ndloop(&ndf, 1, self);
1956
- }
1957
-
1958
1676
  static void iter_robject_poly(na_loop_t* const lp) {
1959
1677
  size_t i;
1960
1678
  dtype x, y, a;
@@ -2181,11 +1899,37 @@ void Init_numo_robject(void) {
2181
1899
  * @return [Numo::NArray] divmod of self and other.
2182
1900
  */
2183
1901
  rb_define_method(cT, "divmod", robject_divmod, 1);
1902
+ /**
1903
+ * Binary power.
1904
+ * @overload ** other
1905
+ * @param [Numo::NArray,Numeric] other
1906
+ * @return [Numo::NArray] self to the other-th power.
1907
+ */
2184
1908
  rb_define_method(cT, "**", robject_pow, 1);
2185
1909
  rb_define_alias(cT, "pow", "**");
1910
+ /**
1911
+ * Unary minus.
1912
+ * @overload -@
1913
+ * @return [Numo::RObject] minus of self.
1914
+ */
2186
1915
  rb_define_method(cT, "-@", robject_minus, 0);
1916
+ /**
1917
+ * Unary reciprocal.
1918
+ * @overload reciprocal
1919
+ * @return [Numo::RObject] reciprocal of self.
1920
+ */
2187
1921
  rb_define_method(cT, "reciprocal", robject_reciprocal, 0);
1922
+ /**
1923
+ * Unary sign.
1924
+ * @overload sign
1925
+ * @return [Numo::RObject] sign of self.
1926
+ */
2188
1927
  rb_define_method(cT, "sign", robject_sign, 0);
1928
+ /**
1929
+ * Unary square.
1930
+ * @overload square
1931
+ * @return [Numo::RObject] square of self.
1932
+ */
2189
1933
  rb_define_method(cT, "square", robject_square, 0);
2190
1934
  rb_define_alias(cT, "conj", "view");
2191
1935
  rb_define_alias(cT, "im", "view");