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.
@@ -48,6 +48,11 @@ extern VALUE cRT;
48
48
  #include "mh/op/sub.h"
49
49
  #include "mh/op/mul.h"
50
50
  #include "mh/op/div.h"
51
+ #include "mh/pow.h"
52
+ #include "mh/minus.h"
53
+ #include "mh/reciprocal.h"
54
+ #include "mh/sign.h"
55
+ #include "mh/square.h"
51
56
  #include "mh/comp/eq.h"
52
57
  #include "mh/comp/ne.h"
53
58
  #include "mh/comp/nearly_eq.h"
@@ -74,6 +79,7 @@ extern VALUE cRT;
74
79
  #include "mh/logseq.h"
75
80
  #include "mh/eye.h"
76
81
  #include "mh/rand.h"
82
+ #include "mh/rand_norm.h"
77
83
  #include "mh/math/sqrt.h"
78
84
  #include "mh/math/cbrt.h"
79
85
  #include "mh/math/log.h"
@@ -106,6 +112,11 @@ DEF_NARRAY_ADD_METHOD_FUNC(dcomplex, numo_cDComplex)
106
112
  DEF_NARRAY_SUB_METHOD_FUNC(dcomplex, numo_cDComplex)
107
113
  DEF_NARRAY_MUL_METHOD_FUNC(dcomplex, numo_cDComplex)
108
114
  DEF_NARRAY_FLT_DIV_METHOD_FUNC(dcomplex, numo_cDComplex)
115
+ DEF_NARRAY_POW_METHOD_FUNC(dcomplex, numo_cDComplex)
116
+ DEF_NARRAY_MINUS_METHOD_FUNC(dcomplex, numo_cDComplex)
117
+ DEF_NARRAY_RECIPROCAL_METHOD_FUNC(dcomplex, numo_cDComplex)
118
+ DEF_NARRAY_SIGN_METHOD_FUNC(dcomplex, numo_cDComplex)
119
+ DEF_NARRAY_SQUARE_METHOD_FUNC(dcomplex, numo_cDComplex)
109
120
  DEF_NARRAY_EQ_METHOD_FUNC(dcomplex, numo_cDComplex)
110
121
  DEF_NARRAY_NE_METHOD_FUNC(dcomplex, numo_cDComplex)
111
122
  DEF_NARRAY_NEARLY_EQ_METHOD_FUNC(dcomplex, numo_cDComplex)
@@ -131,7 +142,8 @@ DEF_NARRAY_FLT_MULSUM_METHOD_FUNC(dcomplex, numo_cDComplex)
131
142
  DEF_NARRAY_FLT_SEQ_METHOD_FUNC(dcomplex)
132
143
  DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(dcomplex)
133
144
  DEF_NARRAY_EYE_METHOD_FUNC(dcomplex)
134
- DEF_NARRAY_FLT_RAND_METHOD_FUNC(dcomplex)
145
+ DEF_NARRAY_CMP_RAND_METHOD_FUNC(dcomplex)
146
+ DEF_NARRAY_CMP_RAND_NORM_METHOD_FUNC(dcomplex, double)
135
147
  DEF_NARRAY_FLT_SQRT_METHOD_FUNC(dcomplex, numo_cDComplex)
136
148
  DEF_NARRAY_FLT_CBRT_METHOD_FUNC(dcomplex, numo_cDComplex)
137
149
  DEF_NARRAY_FLT_LOG_METHOD_FUNC(dcomplex, numo_cDComplex)
@@ -1763,374 +1775,6 @@ static VALUE dcomplex_abs(VALUE self) {
1763
1775
  return na_ndloop(&ndf, 1, self);
1764
1776
  }
1765
1777
 
1766
- static void iter_dcomplex_pow(na_loop_t* const lp) {
1767
- size_t i;
1768
- char *p1, *p2, *p3;
1769
- ssize_t s1, s2, s3;
1770
- dtype x, y;
1771
- INIT_COUNTER(lp, i);
1772
- INIT_PTR(lp, 0, p1, s1);
1773
- INIT_PTR(lp, 1, p2, s2);
1774
- INIT_PTR(lp, 2, p3, s3);
1775
- for (; i--;) {
1776
- GET_DATA_STRIDE(p1, s1, dtype, x);
1777
- GET_DATA_STRIDE(p2, s2, dtype, y);
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);
1798
- }
1799
- }
1800
-
1801
- static VALUE dcomplex_pow_self(VALUE self, VALUE other) {
1802
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
1803
- ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
1804
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
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 };
1807
-
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
- }
1814
- }
1815
-
1816
- /*
1817
- Binary power.
1818
- @overload ** other
1819
- @param [Numo::NArray,Numeric] other
1820
- @return [Numo::NArray] self to the other-th power.
1821
- */
1822
- static VALUE dcomplex_pow(VALUE self, VALUE other) {
1823
-
1824
- VALUE klass, v;
1825
- klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
1826
- if (klass == cT) {
1827
- return dcomplex_pow_self(self, other);
1828
- } else {
1829
- v = rb_funcall(klass, id_cast, 1, self);
1830
- return rb_funcall(v, id_pow, 1, other);
1831
- }
1832
- }
1833
-
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;
1840
-
1841
- INIT_COUNTER(lp, n);
1842
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1843
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1844
-
1845
- if (idx1) {
1846
- if (idx2) {
1847
- for (i = 0; i < n; i++) {
1848
- GET_DATA_INDEX(p1, idx1, dtype, x);
1849
- x = m_minus(x);
1850
- SET_DATA_INDEX(p2, idx2, dtype, x);
1851
- }
1852
- } else {
1853
- for (i = 0; i < n; i++) {
1854
- GET_DATA_INDEX(p1, idx1, dtype, x);
1855
- x = m_minus(x);
1856
- SET_DATA_STRIDE(p2, s2, dtype, x);
1857
- }
1858
- }
1859
- } else {
1860
- if (idx2) {
1861
- for (i = 0; i < n; i++) {
1862
- GET_DATA_STRIDE(p1, s1, dtype, x);
1863
- x = m_minus(x);
1864
- SET_DATA_INDEX(p2, idx2, dtype, x);
1865
- }
1866
- } else {
1867
- //
1868
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
1869
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
1870
- for (i = 0; i < n; i++) {
1871
- ((dtype*)p2)[i] = m_minus(((dtype*)p1)[i]);
1872
- }
1873
- return;
1874
- }
1875
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
1876
- //
1877
- for (i = 0; i < n; i++) {
1878
- *(dtype*)p2 = m_minus(*(dtype*)p1);
1879
- p1 += s1;
1880
- p2 += s2;
1881
- }
1882
- return;
1883
- //
1884
- }
1885
- }
1886
- for (i = 0; i < n; i++) {
1887
- GET_DATA_STRIDE(p1, s1, dtype, x);
1888
- x = m_minus(x);
1889
- SET_DATA_STRIDE(p2, s2, dtype, x);
1890
- }
1891
- //
1892
- }
1893
- }
1894
- }
1895
-
1896
- /*
1897
- Unary minus.
1898
- @overload -@
1899
- @return [Numo::DComplex] minus of self.
1900
- */
1901
- static VALUE dcomplex_minus(VALUE self) {
1902
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1903
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1904
- ndfunc_t ndf = { iter_dcomplex_minus, FULL_LOOP, 1, 1, ain, aout };
1905
-
1906
- return na_ndloop(&ndf, 1, self);
1907
- }
1908
-
1909
- static void iter_dcomplex_reciprocal(na_loop_t* const lp) {
1910
- size_t i, n;
1911
- char *p1, *p2;
1912
- ssize_t s1, s2;
1913
- size_t *idx1, *idx2;
1914
- dtype x;
1915
-
1916
- INIT_COUNTER(lp, n);
1917
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1918
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1919
-
1920
- if (idx1) {
1921
- if (idx2) {
1922
- for (i = 0; i < n; i++) {
1923
- GET_DATA_INDEX(p1, idx1, dtype, x);
1924
- x = m_reciprocal(x);
1925
- SET_DATA_INDEX(p2, idx2, dtype, x);
1926
- }
1927
- } else {
1928
- for (i = 0; i < n; i++) {
1929
- GET_DATA_INDEX(p1, idx1, dtype, x);
1930
- x = m_reciprocal(x);
1931
- SET_DATA_STRIDE(p2, s2, dtype, x);
1932
- }
1933
- }
1934
- } else {
1935
- if (idx2) {
1936
- for (i = 0; i < n; i++) {
1937
- GET_DATA_STRIDE(p1, s1, dtype, x);
1938
- x = m_reciprocal(x);
1939
- SET_DATA_INDEX(p2, idx2, dtype, x);
1940
- }
1941
- } else {
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);
1965
- }
1966
- //
1967
- }
1968
- }
1969
- }
1970
-
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 };
1980
-
1981
- return na_ndloop(&ndf, 1, self);
1982
- }
1983
-
1984
- static void iter_dcomplex_sign(na_loop_t* const lp) {
1985
- size_t i, n;
1986
- char *p1, *p2;
1987
- ssize_t s1, s2;
1988
- size_t *idx1, *idx2;
1989
- dtype x;
1990
-
1991
- INIT_COUNTER(lp, n);
1992
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1993
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1994
-
1995
- if (idx1) {
1996
- if (idx2) {
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);
2001
- }
2002
- } else {
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);
2007
- }
2008
- }
2009
- } else {
2010
- if (idx2) {
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);
2015
- }
2016
- } else {
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);
2040
- }
2041
- //
2042
- }
2043
- }
2044
- }
2045
-
2046
- /*
2047
- Unary sign.
2048
- @overload sign
2049
- @return [Numo::DComplex] sign of self.
2050
- */
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 };
2055
-
2056
- return na_ndloop(&ndf, 1, self);
2057
- }
2058
-
2059
- static void iter_dcomplex_square(na_loop_t* const lp) {
2060
- size_t i, n;
2061
- char *p1, *p2;
2062
- ssize_t s1, s2;
2063
- size_t *idx1, *idx2;
2064
- dtype x;
2065
-
2066
- INIT_COUNTER(lp, n);
2067
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2068
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2069
-
2070
- if (idx1) {
2071
- if (idx2) {
2072
- for (i = 0; i < n; i++) {
2073
- GET_DATA_INDEX(p1, idx1, dtype, x);
2074
- x = m_square(x);
2075
- SET_DATA_INDEX(p2, idx2, dtype, x);
2076
- }
2077
- } else {
2078
- for (i = 0; i < n; i++) {
2079
- GET_DATA_INDEX(p1, idx1, dtype, x);
2080
- x = m_square(x);
2081
- SET_DATA_STRIDE(p2, s2, dtype, x);
2082
- }
2083
- }
2084
- } else {
2085
- if (idx2) {
2086
- for (i = 0; i < n; i++) {
2087
- GET_DATA_STRIDE(p1, s1, dtype, x);
2088
- x = m_square(x);
2089
- SET_DATA_INDEX(p2, idx2, dtype, x);
2090
- }
2091
- } else {
2092
- //
2093
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
2094
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
2095
- for (i = 0; i < n; i++) {
2096
- ((dtype*)p2)[i] = m_square(((dtype*)p1)[i]);
2097
- }
2098
- return;
2099
- }
2100
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
2101
- //
2102
- for (i = 0; i < n; i++) {
2103
- *(dtype*)p2 = m_square(*(dtype*)p1);
2104
- p1 += s1;
2105
- p2 += s2;
2106
- }
2107
- return;
2108
- //
2109
- }
2110
- }
2111
- for (i = 0; i < n; i++) {
2112
- GET_DATA_STRIDE(p1, s1, dtype, x);
2113
- x = m_square(x);
2114
- SET_DATA_STRIDE(p2, s2, dtype, x);
2115
- }
2116
- //
2117
- }
2118
- }
2119
- }
2120
-
2121
- /*
2122
- Unary square.
2123
- @overload square
2124
- @return [Numo::DComplex] square of self.
2125
- */
2126
- static VALUE dcomplex_square(VALUE self) {
2127
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2128
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2129
- ndfunc_t ndf = { iter_dcomplex_square, FULL_LOOP, 1, 1, ain, aout };
2130
-
2131
- return na_ndloop(&ndf, 1, self);
2132
- }
2133
-
2134
1778
  static void iter_dcomplex_conj(na_loop_t* const lp) {
2135
1779
  size_t i, n;
2136
1780
  char *p1, *p2;
@@ -2715,99 +2359,6 @@ static VALUE dcomplex_kahan_sum(int argc, VALUE* argv, VALUE self) {
2715
2359
  return dcomplex_extract(v);
2716
2360
  }
2717
2361
 
2718
- typedef struct {
2719
- dtype mu;
2720
- rtype sigma;
2721
- } randn_opt_t;
2722
-
2723
- static void iter_dcomplex_rand_norm(na_loop_t* const lp) {
2724
- size_t i;
2725
- char* p1;
2726
- ssize_t s1;
2727
- size_t* idx1;
2728
-
2729
- dtype* a0;
2730
-
2731
- dtype mu;
2732
- rtype sigma;
2733
- randn_opt_t* g;
2734
-
2735
- INIT_COUNTER(lp, i);
2736
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2737
- g = (randn_opt_t*)(lp->opt_ptr);
2738
- mu = g->mu;
2739
- sigma = g->sigma;
2740
-
2741
- if (idx1) {
2742
-
2743
- for (; i--;) {
2744
- a0 = (dtype*)(p1 + *idx1);
2745
- m_rand_norm(mu, sigma, a0);
2746
- idx1 += 1;
2747
- }
2748
-
2749
- } else {
2750
-
2751
- for (; i--;) {
2752
- a0 = (dtype*)(p1);
2753
- m_rand_norm(mu, sigma, a0);
2754
- p1 += s1;
2755
- }
2756
- }
2757
- }
2758
-
2759
- /*
2760
- Generates random numbers from the normal distribution on self narray
2761
- using Box-Muller Transformation.
2762
- @overload rand_norm([mu,[sigma]])
2763
- @param [Numeric] mu mean of normal distribution. (default=0)
2764
- @param [Numeric] sigma standard deviation of normal distribution. (default=1)
2765
- @return [Numo::DComplex] self.
2766
- @example
2767
- Numo::DFloat.new(5,5).rand_norm
2768
- # => Numo::DFloat#shape=[5,5]
2769
- # [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
2770
- # [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
2771
- # [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
2772
- # [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
2773
- # [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
2774
-
2775
- Numo::DFloat.new(5,5).rand_norm(10,0.1)
2776
- # => Numo::DFloat#shape=[5,5]
2777
- # [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
2778
- # [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
2779
- # [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
2780
- # [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
2781
- # [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
2782
-
2783
- Numo::DComplex.new(3,3).rand_norm(5+5i)
2784
- # => Numo::DComplex#shape=[3,3]
2785
- # [[5.84303+4.40052i, 4.00984+6.08982i, 5.10979+5.13215i],
2786
- # [4.26477+3.99655i, 4.90052+5.00763i, 4.46607+2.3444i],
2787
- # [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]
2788
- */
2789
- static VALUE dcomplex_rand_norm(int argc, VALUE* argv, VALUE self) {
2790
- int n;
2791
- randn_opt_t g;
2792
- VALUE v1 = Qnil, v2 = Qnil;
2793
- ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
2794
- ndfunc_t ndf = { iter_dcomplex_rand_norm, FULL_LOOP, 1, 0, ain, 0 };
2795
-
2796
- n = rb_scan_args(argc, argv, "02", &v1, &v2);
2797
- if (n == 0) {
2798
- g.mu = m_zero;
2799
- } else {
2800
- g.mu = m_num_to_data(v1);
2801
- }
2802
- if (n == 2) {
2803
- g.sigma = NUM2DBL(v2);
2804
- } else {
2805
- g.sigma = 1;
2806
- }
2807
- na_ndloop3(&ndf, &g, 1, self);
2808
- return self;
2809
- }
2810
-
2811
2362
  static void iter_dcomplex_poly(na_loop_t* const lp) {
2812
2363
  size_t i;
2813
2364
  dtype x, y, a;
@@ -3003,11 +2554,37 @@ void Init_numo_dcomplex(void) {
3003
2554
  * @return [Numo::NArray] self / other
3004
2555
  */
3005
2556
  rb_define_method(cT, "/", dcomplex_div, 1);
2557
+ /**
2558
+ * Binary power.
2559
+ * @overload ** other
2560
+ * @param [Numo::NArray,Numeric] other
2561
+ * @return [Numo::NArray] self to the other-th power.
2562
+ */
3006
2563
  rb_define_method(cT, "**", dcomplex_pow, 1);
3007
2564
  rb_define_alias(cT, "pow", "**");
2565
+ /**
2566
+ * Unary minus.
2567
+ * @overload -@
2568
+ * @return [Numo::DComplex] minus of self.
2569
+ */
3008
2570
  rb_define_method(cT, "-@", dcomplex_minus, 0);
2571
+ /**
2572
+ * Unary reciprocal.
2573
+ * @overload reciprocal
2574
+ * @return [Numo::DComplex] reciprocal of self.
2575
+ */
3009
2576
  rb_define_method(cT, "reciprocal", dcomplex_reciprocal, 0);
2577
+ /**
2578
+ * Unary sign.
2579
+ * @overload sign
2580
+ * @return [Numo::DComplex] sign of self.
2581
+ */
3010
2582
  rb_define_method(cT, "sign", dcomplex_sign, 0);
2583
+ /**
2584
+ * Unary square.
2585
+ * @overload square
2586
+ * @return [Numo::DComplex] square of self.
2587
+ */
3011
2588
  rb_define_method(cT, "square", dcomplex_square, 0);
3012
2589
  rb_define_method(cT, "conj", dcomplex_conj, 0);
3013
2590
  rb_define_method(cT, "im", dcomplex_im, 0);
@@ -3271,6 +2848,36 @@ void Init_numo_dcomplex(void) {
3271
2848
  * # [4, 3, 3, 2, 4, 2]
3272
2849
  */
3273
2850
  rb_define_method(cT, "rand", dcomplex_rand, -1);
2851
+ /**
2852
+ * Generates random numbers from the normal distribution on self narray
2853
+ * using Box-Muller Transformation.
2854
+ * @overload rand_norm([mu,[sigma]])
2855
+ * @param [Numeric] mu mean of normal distribution. (default=0)
2856
+ * @param [Numeric] sigma standard deviation of normal distribution. (default=1)
2857
+ * @return [Numo::DComplex] self.
2858
+ * @example
2859
+ * Numo::DFloat.new(5,5).rand_norm
2860
+ * # => Numo::DFloat#shape=[5,5]
2861
+ * # [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
2862
+ * # [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
2863
+ * # [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
2864
+ * # [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
2865
+ * # [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
2866
+ *
2867
+ * Numo::DFloat.new(5,5).rand_norm(10,0.1)
2868
+ * # => Numo::DFloat#shape=[5,5]
2869
+ * # [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
2870
+ * # [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
2871
+ * # [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
2872
+ * # [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
2873
+ * # [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
2874
+ *
2875
+ * Numo::DComplex.new(3,3).rand_norm(5+5i)
2876
+ * # => Numo::DComplex#shape=[3,3]
2877
+ * # [[5.84303+4.40052i, 4.00984+6.08982i, 5.10979+5.13215i],
2878
+ * # [4.26477+3.99655i, 4.90052+5.00763i, 4.46607+2.3444i],
2879
+ * # [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]
2880
+ */
3274
2881
  rb_define_method(cT, "rand_norm", dcomplex_rand_norm, -1);
3275
2882
  rb_define_method(cT, "poly", dcomplex_poly, -2);
3276
2883
  rb_define_singleton_method(cT, "[]", dcomplex_s_cast, -2);