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(uint8, numo_cUInt8)
106
111
  DEF_NARRAY_INT8_DIV_METHOD_FUNC(uint8, numo_cUInt8)
107
112
  DEF_NARRAY_INT8_MOD_METHOD_FUNC(uint8, numo_cUInt8)
108
113
  DEF_NARRAY_INT_DIVMOD_METHOD_FUNC(uint8, numo_cUInt8)
114
+ DEF_NARRAY_POW_METHOD_FUNC(uint8, numo_cUInt8)
115
+ DEF_NARRAY_INT8_MINUS_METHOD_FUNC(uint8, numo_cUInt8)
116
+ DEF_NARRAY_INT8_RECIPROCAL_METHOD_FUNC(uint8, numo_cUInt8)
117
+ DEF_NARRAY_INT8_SIGN_METHOD_FUNC(uint8, numo_cUInt8)
118
+ DEF_NARRAY_INT8_SQUARE_METHOD_FUNC(uint8, numo_cUInt8)
109
119
  DEF_NARRAY_EQ_METHOD_FUNC(uint8, numo_cUInt8)
110
120
  DEF_NARRAY_NE_METHOD_FUNC(uint8, numo_cUInt8)
111
121
  DEF_NARRAY_GT_METHOD_FUNC(uint8, numo_cUInt8)
@@ -1611,306 +1621,6 @@ static VALUE uint8_abs(VALUE self) {
1611
1621
  return na_ndloop(&ndf, 1, self);
1612
1622
  }
1613
1623
 
1614
- static void iter_uint8_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_uint8_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 uint8_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_uint8_pow, STRIDE_LOOP, 2, 1, ain, aout };
1654
- ndfunc_t ndf_i = { iter_uint8_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 uint8_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 uint8_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_uint8_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::UInt8] minus of self.
1731
- */
1732
- static VALUE uint8_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_uint8_minus, FULL_LOOP, 1, 1, ain, aout };
1736
-
1737
- return na_ndloop(&ndf, 1, self);
1738
- }
1739
-
1740
- static void iter_uint8_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::UInt8] reciprocal of self.
1789
- */
1790
- static VALUE uint8_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_uint8_reciprocal, FULL_LOOP, 1, 1, ain, aout };
1794
-
1795
- return na_ndloop(&ndf, 1, self);
1796
- }
1797
-
1798
- static void iter_uint8_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::UInt8] sign of self.
1847
- */
1848
- static VALUE uint8_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_uint8_sign, FULL_LOOP, 1, 1, ain, aout };
1852
-
1853
- return na_ndloop(&ndf, 1, self);
1854
- }
1855
-
1856
- static void iter_uint8_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::UInt8] square of self.
1905
- */
1906
- static VALUE uint8_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_uint8_square, FULL_LOOP, 1, 1, ain, aout };
1910
-
1911
- return na_ndloop(&ndf, 1, self);
1912
- }
1913
-
1914
1624
  static void iter_uint8_poly(na_loop_t* const lp) {
1915
1625
  size_t i;
1916
1626
  dtype x, y, a;
@@ -2620,11 +2330,37 @@ void Init_numo_uint8(void) {
2620
2330
  * @return [Numo::NArray] divmod of self and other.
2621
2331
  */
2622
2332
  rb_define_method(cT, "divmod", uint8_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, "**", uint8_pow, 1);
2624
2340
  rb_define_alias(cT, "pow", "**");
2341
+ /**
2342
+ * Unary minus.
2343
+ * @overload -@
2344
+ * @return [Numo::UInt8] minus of self.
2345
+ */
2625
2346
  rb_define_method(cT, "-@", uint8_minus, 0);
2347
+ /**
2348
+ * Unary reciprocal.
2349
+ * @overload reciprocal
2350
+ * @return [Numo::UInt8] reciprocal of self.
2351
+ */
2626
2352
  rb_define_method(cT, "reciprocal", uint8_reciprocal, 0);
2353
+ /**
2354
+ * Unary sign.
2355
+ * @overload sign
2356
+ * @return [Numo::UInt8] sign of self.
2357
+ */
2627
2358
  rb_define_method(cT, "sign", uint8_sign, 0);
2359
+ /**
2360
+ * Unary square.
2361
+ * @overload square
2362
+ * @return [Numo::UInt8] square of self.
2363
+ */
2628
2364
  rb_define_method(cT, "square", uint8_square, 0);
2629
2365
  rb_define_alias(cT, "conj", "view");
2630
2366
  rb_define_alias(cT, "im", "view");
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-narray-alt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
@@ -137,6 +137,7 @@ files:
137
137
  - ext/numo/narray/src/mh/min_index.h
138
138
  - ext/numo/narray/src/mh/minimum.h
139
139
  - ext/numo/narray/src/mh/minmax.h
140
+ - ext/numo/narray/src/mh/minus.h
140
141
  - ext/numo/narray/src/mh/mulsum.h
141
142
  - ext/numo/narray/src/mh/op/add.h
142
143
  - ext/numo/narray/src/mh/op/binary_func.h
@@ -144,9 +145,12 @@ files:
144
145
  - ext/numo/narray/src/mh/op/mod.h
145
146
  - ext/numo/narray/src/mh/op/mul.h
146
147
  - ext/numo/narray/src/mh/op/sub.h
148
+ - ext/numo/narray/src/mh/pow.h
147
149
  - ext/numo/narray/src/mh/prod.h
148
150
  - ext/numo/narray/src/mh/ptp.h
149
151
  - ext/numo/narray/src/mh/rand.h
152
+ - ext/numo/narray/src/mh/rand_norm.h
153
+ - ext/numo/narray/src/mh/reciprocal.h
150
154
  - ext/numo/narray/src/mh/rms.h
151
155
  - ext/numo/narray/src/mh/round/ceil.h
152
156
  - ext/numo/narray/src/mh/round/floor.h
@@ -155,6 +159,8 @@ files:
155
159
  - ext/numo/narray/src/mh/round/trunc.h
156
160
  - ext/numo/narray/src/mh/round/unary_func.h
157
161
  - ext/numo/narray/src/mh/seq.h
162
+ - ext/numo/narray/src/mh/sign.h
163
+ - ext/numo/narray/src/mh/square.h
158
164
  - ext/numo/narray/src/mh/stddev.h
159
165
  - ext/numo/narray/src/mh/sum.h
160
166
  - ext/numo/narray/src/mh/to_a.h
@@ -185,7 +191,7 @@ licenses:
185
191
  metadata:
186
192
  homepage_uri: https://github.com/yoshoku/numo-narray-alt
187
193
  changelog_uri: https://github.com/yoshoku/numo-narray-alt/blob/main/CHANGELOG.md
188
- documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.9.12/
194
+ documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.9.13/
189
195
  rubygems_mfa_required: 'true'
190
196
  post_install_message: |
191
197
  ===