numo-narray-alt 0.9.5 → 0.9.6

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/README.md +13 -0
  4. data/ext/numo/narray/SFMT-params19937.h +12 -12
  5. data/ext/numo/narray/array.c +26 -2
  6. data/ext/numo/narray/data.c +70 -72
  7. data/ext/numo/narray/extconf.rb +0 -1
  8. data/ext/numo/narray/index.c +2 -2
  9. data/ext/numo/narray/kwargs.c +6 -6
  10. data/ext/numo/narray/math.c +10 -4
  11. data/ext/numo/narray/narray.c +80 -52
  12. data/ext/numo/narray/numo/narray.h +20 -20
  13. data/ext/numo/narray/numo/ndloop.h +1 -1
  14. data/ext/numo/narray/numo/template.h +80 -80
  15. data/ext/numo/narray/numo/types/bit.h +76 -0
  16. data/ext/numo/narray/numo/types/complex.h +2 -2
  17. data/ext/numo/narray/numo/types/complex_macro.h +27 -26
  18. data/ext/numo/narray/numo/types/float_macro.h +18 -17
  19. data/ext/numo/narray/numo/types/real_accum.h +22 -22
  20. data/ext/numo/narray/numo/types/robj_macro.h +15 -14
  21. data/ext/numo/narray/numo/types/xint_macro.h +50 -8
  22. data/ext/numo/narray/rand.c +7 -0
  23. data/ext/numo/narray/src/mh/mean.h +102 -0
  24. data/ext/numo/narray/src/mh/rms.h +102 -0
  25. data/ext/numo/narray/src/mh/stddev.h +103 -0
  26. data/ext/numo/narray/src/mh/var.h +102 -0
  27. data/ext/numo/narray/src/t_bit.c +121 -71
  28. data/ext/numo/narray/src/t_dcomplex.c +248 -387
  29. data/ext/numo/narray/src/t_dfloat.c +922 -1068
  30. data/ext/numo/narray/src/t_int16.c +282 -231
  31. data/ext/numo/narray/src/t_int32.c +282 -231
  32. data/ext/numo/narray/src/t_int64.c +281 -230
  33. data/ext/numo/narray/src/t_int8.c +282 -231
  34. data/ext/numo/narray/src/t_robject.c +278 -405
  35. data/ext/numo/narray/src/t_scomplex.c +246 -406
  36. data/ext/numo/narray/src/t_sfloat.c +916 -1058
  37. data/ext/numo/narray/src/t_uint16.c +282 -231
  38. data/ext/numo/narray/src/t_uint32.c +282 -231
  39. data/ext/numo/narray/src/t_uint64.c +282 -231
  40. data/ext/numo/narray/src/t_uint8.c +282 -231
  41. data/ext/numo/narray/struct.c +12 -7
  42. data/lib/numo/narray/extra.rb +8 -5
  43. metadata +6 -3
  44. data/ext/numo/narray/src/t_mean.c +0 -105
@@ -0,0 +1,103 @@
1
+ /*
2
+ stddev.h
3
+ Numo::NArray Alternative
4
+
5
+ created on: 2025-10-15
6
+ Copyright (C) 2025 Atsushi Tatsuma
7
+ */
8
+ #ifndef NUMO_NARRAY_MH_STDDEV_H
9
+ #define NUMO_NARRAY_MH_STDDEV_H 1
10
+
11
+ #define DEF_NARRAY_FLT_STDDEV_METHOD_FUNC(tDType, tRtDType, tNAryClass, tRtNAryClass) \
12
+ static void iter_##tDType##_stddev(na_loop_t* const lp) { \
13
+ size_t n; \
14
+ char* p1; \
15
+ char* p2; \
16
+ ssize_t s1; \
17
+ \
18
+ INIT_COUNTER(lp, n); \
19
+ INIT_PTR(lp, 0, p1, s1); \
20
+ p2 = NDL_PTR(lp, 1); \
21
+ \
22
+ *(tRtDType*)p2 = f_stddev(n, p1, s1); \
23
+ } \
24
+ \
25
+ static void iter_##tDType##_stddev_nan(na_loop_t* const lp) { \
26
+ size_t n; \
27
+ char* p1; \
28
+ char* p2; \
29
+ ssize_t s1; \
30
+ \
31
+ INIT_COUNTER(lp, n); \
32
+ INIT_PTR(lp, 0, p1, s1); \
33
+ p2 = NDL_PTR(lp, 1); \
34
+ \
35
+ *(tRtDType*)p2 = f_stddev_nan(n, p1, s1); \
36
+ } \
37
+ \
38
+ static VALUE tDType##_stddev(int argc, VALUE* argv, VALUE self) { \
39
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
40
+ ndfunc_arg_out_t aout[1] = { { tRtNAryClass, 0 } }; \
41
+ ndfunc_t ndf = { \
42
+ iter_##tDType##_stddev, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
43
+ }; \
44
+ VALUE reduce = \
45
+ na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_stddev_nan); \
46
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
47
+ \
48
+ return rb_funcall(v, rb_intern("extract"), 0); \
49
+ }
50
+
51
+ #define DEF_NARRAY_INT_STDDEV_METHOD_FUNC(tDType, tNAryClass) \
52
+ static void iter_##tDType##_stddev(na_loop_t* const lp) { \
53
+ size_t n; \
54
+ char* p1; \
55
+ char* p2; \
56
+ ssize_t s1; \
57
+ \
58
+ INIT_COUNTER(lp, n); \
59
+ INIT_PTR(lp, 0, p1, s1); \
60
+ p2 = NDL_PTR(lp, 1); \
61
+ \
62
+ *(double*)p2 = f_stddev(n, p1, s1); \
63
+ } \
64
+ \
65
+ static VALUE tDType##_stddev(int argc, VALUE* argv, VALUE self) { \
66
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
67
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
68
+ ndfunc_t ndf = { \
69
+ iter_##tDType##_stddev, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
70
+ }; \
71
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
72
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
73
+ \
74
+ return rb_funcall(v, rb_intern("extract"), 0); \
75
+ }
76
+
77
+ #define DEF_NARRAY_BIT_STDDEV_METHOD_FUNC() \
78
+ static void iter_bit_stddev(na_loop_t* const lp) { \
79
+ size_t n; \
80
+ BIT_DIGIT* p1; \
81
+ size_t ps1; \
82
+ ssize_t s1; \
83
+ size_t* idx1; \
84
+ char* p2; \
85
+ \
86
+ INIT_COUNTER(lp, n); \
87
+ INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1); \
88
+ p2 = NDL_PTR(lp, 1); \
89
+ \
90
+ *(double*)p2 = f_stddev(n, p1, ps1, s1, idx1); \
91
+ } \
92
+ \
93
+ static VALUE bit_stddev(int argc, VALUE* argv, VALUE self) { \
94
+ ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } }; \
95
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
96
+ ndfunc_t ndf = { iter_bit_stddev, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout }; \
97
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
98
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
99
+ \
100
+ return rb_funcall(v, rb_intern("extract"), 0); \
101
+ }
102
+
103
+ #endif // NUMO_NARRAY_MH_STDDEV_H
@@ -0,0 +1,102 @@
1
+ /*
2
+ var.h
3
+ Numo::NArray Alternative
4
+
5
+ created on: 2025-10-15
6
+ Copyright (C) 2025 Atsushi Tatsuma
7
+ */
8
+ #ifndef NUMO_NARRAY_MH_VAR_H
9
+ #define NUMO_NARRAY_MH_VAR_H 1
10
+
11
+ #define DEF_NARRAY_FLT_VAR_METHOD_FUNC(tDType, tRtDType, tNAryClass, tRtNAryClass) \
12
+ static void iter_##tDType##_var(na_loop_t* const lp) { \
13
+ size_t n; \
14
+ char* p1; \
15
+ char* p2; \
16
+ ssize_t s1; \
17
+ \
18
+ INIT_COUNTER(lp, n); \
19
+ INIT_PTR(lp, 0, p1, s1); \
20
+ p2 = NDL_PTR(lp, 1); \
21
+ \
22
+ *(tRtDType*)p2 = f_var(n, p1, s1); \
23
+ } \
24
+ \
25
+ static void iter_##tDType##_var_nan(na_loop_t* const lp) { \
26
+ size_t n; \
27
+ char* p1; \
28
+ char* p2; \
29
+ ssize_t s1; \
30
+ \
31
+ INIT_COUNTER(lp, n); \
32
+ INIT_PTR(lp, 0, p1, s1); \
33
+ p2 = NDL_PTR(lp, 1); \
34
+ \
35
+ *(tRtDType*)p2 = f_var_nan(n, p1, s1); \
36
+ } \
37
+ \
38
+ static VALUE tDType##_var(int argc, VALUE* argv, VALUE self) { \
39
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
40
+ ndfunc_arg_out_t aout[1] = { { tRtNAryClass, 0 } }; \
41
+ ndfunc_t ndf = { \
42
+ iter_##tDType##_var, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
43
+ }; \
44
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_var_nan); \
45
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
46
+ \
47
+ return rb_funcall(v, rb_intern("extract"), 0); \
48
+ }
49
+
50
+ #define DEF_NARRAY_INT_VAR_METHOD_FUNC(tDType, tNAryClass) \
51
+ static void iter_##tDType##_var(na_loop_t* const lp) { \
52
+ size_t n; \
53
+ char* p1; \
54
+ char* p2; \
55
+ ssize_t s1; \
56
+ \
57
+ INIT_COUNTER(lp, n); \
58
+ INIT_PTR(lp, 0, p1, s1); \
59
+ p2 = NDL_PTR(lp, 1); \
60
+ \
61
+ *(double*)p2 = f_var(n, p1, s1); \
62
+ } \
63
+ \
64
+ static VALUE tDType##_var(int argc, VALUE* argv, VALUE self) { \
65
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
66
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
67
+ ndfunc_t ndf = { \
68
+ iter_##tDType##_var, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
69
+ }; \
70
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
71
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
72
+ \
73
+ return rb_funcall(v, rb_intern("extract"), 0); \
74
+ }
75
+
76
+ #define DEF_NARRAY_BIT_VAR_METHOD_FUNC() \
77
+ static void iter_bit_var(na_loop_t* const lp) { \
78
+ size_t n; \
79
+ BIT_DIGIT* p1; \
80
+ size_t ps1; \
81
+ ssize_t s1; \
82
+ size_t* idx1; \
83
+ char* p2; \
84
+ \
85
+ INIT_COUNTER(lp, n); \
86
+ INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1); \
87
+ p2 = NDL_PTR(lp, 1); \
88
+ \
89
+ *(double*)p2 = f_var(n, p1, ps1, s1, idx1); \
90
+ } \
91
+ \
92
+ static VALUE bit_var(int argc, VALUE* argv, VALUE self) { \
93
+ ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } }; \
94
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
95
+ ndfunc_t ndf = { iter_bit_var, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout }; \
96
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
97
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
98
+ \
99
+ return rb_funcall(v, rb_intern("extract"), 0); \
100
+ }
101
+
102
+ #endif // NUMO_NARRAY_MH_VAR_H
@@ -31,11 +31,15 @@ static ID id_to_a;
31
31
  VALUE cT;
32
32
  extern VALUE cRT;
33
33
 
34
- /*
35
- class definition: Numo::Bit
36
- */
34
+ #include "mh/mean.h"
35
+ #include "mh/var.h"
36
+ #include "mh/stddev.h"
37
+ #include "mh/rms.h"
37
38
 
38
- VALUE cT;
39
+ DEF_NARRAY_BIT_MEAN_METHOD_FUNC()
40
+ DEF_NARRAY_BIT_VAR_METHOD_FUNC()
41
+ DEF_NARRAY_BIT_STDDEV_METHOD_FUNC()
42
+ DEF_NARRAY_BIT_RMS_METHOD_FUNC()
39
43
 
40
44
  static VALUE bit_store(VALUE, VALUE);
41
45
 
@@ -139,9 +143,9 @@ static VALUE bit_allocate(VALUE self) {
139
143
  /*
140
144
  Extract an element only if self is a dimensionless NArray.
141
145
  @overload extract
142
- @return [Numeric,Numo::NArray]
143
- --- Extract element value as Ruby Object if self is a dimensionless NArray,
144
- otherwise returns self.
146
+ @return [Numeric,Numo::NArray]
147
+ --- Extract element value as Ruby Object if self is a dimensionless NArray,
148
+ otherwise returns self.
145
149
  */
146
150
 
147
151
  static VALUE bit_extract(VALUE self) {
@@ -1000,8 +1004,8 @@ static VALUE bit_store_array(VALUE self, VALUE rary) {
1000
1004
  /*
1001
1005
  Store elements to Numo::Bit from other.
1002
1006
  @overload store(other)
1003
- @param [Object] other
1004
- @return [Numo::Bit] self
1007
+ @param [Object] other
1008
+ @return [Numo::Bit] self
1005
1009
  */
1006
1010
  static VALUE bit_store(VALUE self, VALUE obj) {
1007
1011
  VALUE r, klass;
@@ -1213,9 +1217,9 @@ static VALUE bit_cast_array(VALUE rary) {
1213
1217
  Cast object to Numo::Bit.
1214
1218
  @overload [](elements)
1215
1219
  @overload cast(array)
1216
- @param [Numeric,Array] elements
1217
- @param [Array] array
1218
- @return [Numo::Bit]
1220
+ @param [Numeric,Array] elements
1221
+ @param [Array] array
1222
+ @return [Numo::Bit]
1219
1223
  */
1220
1224
  static VALUE bit_s_cast(VALUE type, VALUE obj) {
1221
1225
  VALUE v;
@@ -1255,9 +1259,9 @@ static VALUE bit_s_cast(VALUE type, VALUE obj) {
1255
1259
  /*
1256
1260
  Multi-dimensional element reference.
1257
1261
  @overload [](dim0,...,dimL)
1258
- @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
1259
- dim0,...,dimL multi-dimensional indices.
1260
- @return [Numeric,Numo::Bit] an element or NArray view.
1262
+ @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
1263
+ dim0,...,dimL multi-dimensional indices.
1264
+ @return [Numeric,Numo::Bit] an element or NArray view.
1261
1265
  @see Numo::NArray#[]
1262
1266
  @see #[]=
1263
1267
 
@@ -1302,10 +1306,10 @@ static VALUE bit_aref(int argc, VALUE* argv, VALUE self) {
1302
1306
  /*
1303
1307
  Multi-dimensional element assignment.
1304
1308
  @overload []=(dim0,...,dimL,val)
1305
- @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
1306
- dim0,...,dimL multi-dimensional indices.
1307
- @param [Numeric,Numo::NArray,Array] val Value(s) to be set to self.
1308
- @return [Numeric,Numo::NArray,Array] returns `val` (last argument).
1309
+ @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
1310
+ dim0,...,dimL multi-dimensional indices.
1311
+ @param [Numeric,Numo::NArray,Array] val Value(s) to be set to self.
1312
+ @return [Numeric,Numo::NArray,Array] returns `val` (last argument).
1309
1313
  @see Numo::NArray#[]=
1310
1314
  @see #[]
1311
1315
 
@@ -1352,7 +1356,7 @@ static VALUE bit_aset(int argc, VALUE* argv, VALUE self) {
1352
1356
  /*
1353
1357
  return NArray with cast to the type of self.
1354
1358
  @overload coerce_cast(type)
1355
- @return [nil]
1359
+ @return [nil]
1356
1360
  */
1357
1361
  static VALUE bit_coerce_cast(VALUE self, VALUE type) {
1358
1362
  return Qnil;
@@ -1391,7 +1395,7 @@ static void iter_bit_to_a(na_loop_t* const lp) {
1391
1395
  /*
1392
1396
  Convert self to Array.
1393
1397
  @overload to_a
1394
- @return [Array]
1398
+ @return [Array]
1395
1399
  */
1396
1400
  static VALUE bit_to_a(VALUE self) {
1397
1401
  ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
@@ -1452,8 +1456,8 @@ static void iter_bit_fill(na_loop_t* const lp) {
1452
1456
  /*
1453
1457
  Fill elements with other.
1454
1458
  @overload fill other
1455
- @param [Numeric] other
1456
- @return [Numo::Bit] self.
1459
+ @param [Numeric] other
1460
+ @return [Numo::Bit] self.
1457
1461
  */
1458
1462
  static VALUE bit_fill(VALUE self, VALUE val) {
1459
1463
  ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
@@ -1507,8 +1511,8 @@ static void iter_bit_format(na_loop_t* const lp) {
1507
1511
  /*
1508
1512
  Format elements into strings.
1509
1513
  @overload format format
1510
- @param [String] format
1511
- @return [Numo::RObject] array of formatted strings.
1514
+ @param [String] format
1515
+ @return [Numo::RObject] array of formatted strings.
1512
1516
  */
1513
1517
  static VALUE bit_format(int argc, VALUE* argv, VALUE self) {
1514
1518
  VALUE fmt = Qnil;
@@ -1555,8 +1559,8 @@ static void iter_bit_format_to_a(na_loop_t* const lp) {
1555
1559
  /*
1556
1560
  Format elements into strings.
1557
1561
  @overload format_to_a format
1558
- @param [String] format
1559
- @return [Array] array of formatted strings.
1562
+ @param [String] format
1563
+ @return [Array] array of formatted strings.
1560
1564
  */
1561
1565
  static VALUE bit_format_to_a(int argc, VALUE* argv, VALUE self) {
1562
1566
  VALUE fmt = Qnil;
@@ -1577,7 +1581,7 @@ static VALUE iter_bit_inspect(char* ptr, size_t pos, VALUE fmt) {
1577
1581
  /*
1578
1582
  Returns a string containing a human-readable representation of NArray.
1579
1583
  @overload inspect
1580
- @return [String]
1584
+ @return [String]
1581
1585
  */
1582
1586
  static VALUE bit_inspect(VALUE ary) {
1583
1587
  return na_ndloop_inspect(ary, iter_bit_inspect, Qnil);
@@ -1614,9 +1618,9 @@ static void iter_bit_each(na_loop_t* const lp) {
1614
1618
  Calls the given block once for each element in self,
1615
1619
  passing that element as a parameter.
1616
1620
  @overload each
1617
- @return [Numo::NArray] self
1618
- For a block {|x| ... }
1619
- @yield [x] x is element of NArray.
1621
+ @return [Numo::NArray] self
1622
+ For a block {|x| ... }
1623
+ @yield [x] x is element of NArray.
1620
1624
  */
1621
1625
  static VALUE bit_each(VALUE self) {
1622
1626
  ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
@@ -1676,9 +1680,9 @@ static void iter_bit_each_with_index(na_loop_t* const lp) {
1676
1680
  Invokes the given block once for each element of self,
1677
1681
  passing that element and indices along each axis as parameters.
1678
1682
  @overload each_with_index
1679
- @return [Numo::NArray] self
1680
- For a block {|x,i,j,...| ... }
1681
- @yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
1683
+ @return [Numo::NArray] self
1684
+ For a block {|x,i,j,...| ... }
1685
+ @yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
1682
1686
  */
1683
1687
  static VALUE bit_each_with_index(VALUE self) {
1684
1688
  ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
@@ -1772,7 +1776,7 @@ static void iter_bit_copy(na_loop_t* const lp) {
1772
1776
  /*
1773
1777
  Unary copy.
1774
1778
  @overload copy
1775
- @return [Numo::Bit] copy of self.
1779
+ @return [Numo::Bit] copy of self.
1776
1780
  */
1777
1781
  static VALUE bit_copy(VALUE self) {
1778
1782
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
@@ -1866,7 +1870,7 @@ static void iter_bit_not(na_loop_t* const lp) {
1866
1870
  /*
1867
1871
  Unary not.
1868
1872
  @overload not
1869
- @return [Numo::Bit] not of self.
1873
+ @return [Numo::Bit] not of self.
1870
1874
  */
1871
1875
  static VALUE bit_not(VALUE self) {
1872
1876
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
@@ -1994,8 +1998,8 @@ static void iter_bit_and(na_loop_t* const lp) {
1994
1998
  /*
1995
1999
  Binary and.
1996
2000
  @overload & other
1997
- @param [Numo::NArray,Numeric] other
1998
- @return [Numo::NArray] and of self and other.
2001
+ @param [Numo::NArray,Numeric] other
2002
+ @return [Numo::NArray] and of self and other.
1999
2003
  */
2000
2004
  static VALUE bit_and(VALUE self, VALUE other) {
2001
2005
  ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
@@ -2123,8 +2127,8 @@ static void iter_bit_or(na_loop_t* const lp) {
2123
2127
  /*
2124
2128
  Binary or.
2125
2129
  @overload | other
2126
- @param [Numo::NArray,Numeric] other
2127
- @return [Numo::NArray] or of self and other.
2130
+ @param [Numo::NArray,Numeric] other
2131
+ @return [Numo::NArray] or of self and other.
2128
2132
  */
2129
2133
  static VALUE bit_or(VALUE self, VALUE other) {
2130
2134
  ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
@@ -2252,8 +2256,8 @@ static void iter_bit_xor(na_loop_t* const lp) {
2252
2256
  /*
2253
2257
  Binary xor.
2254
2258
  @overload ^ other
2255
- @param [Numo::NArray,Numeric] other
2256
- @return [Numo::NArray] xor of self and other.
2259
+ @param [Numo::NArray,Numeric] other
2260
+ @return [Numo::NArray] xor of self and other.
2257
2261
  */
2258
2262
  static VALUE bit_xor(VALUE self, VALUE other) {
2259
2263
  ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
@@ -2381,8 +2385,8 @@ static void iter_bit_eq(na_loop_t* const lp) {
2381
2385
  /*
2382
2386
  Binary eq.
2383
2387
  @overload eq other
2384
- @param [Numo::NArray,Numeric] other
2385
- @return [Numo::NArray] eq of self and other.
2388
+ @param [Numo::NArray,Numeric] other
2389
+ @return [Numo::NArray] eq of self and other.
2386
2390
  */
2387
2391
  static VALUE bit_eq(VALUE self, VALUE other) {
2388
2392
  ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
@@ -2459,10 +2463,10 @@ static void iter_bit_count_true(na_loop_t* const lp) {
2459
2463
  Returns the number of bits.
2460
2464
  If argument is supplied, return Int-array counted along the axes.
2461
2465
  @overload count_true(axis:nil, keepdims:false)
2462
- @param [Integer,Array,Range] axis (keyword) axes to be counted.
2463
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2464
- as dimensions with size one.
2465
- @return [Numo::Int64]
2466
+ @param [Integer,Array,Range] axis (keyword) axes to be counted.
2467
+ @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2468
+ as dimensions with size one.
2469
+ @return [Numo::Int64]
2466
2470
  */
2467
2471
  static VALUE bit_count_true(int argc, VALUE* argv, VALUE self) {
2468
2472
  VALUE v, reduce;
@@ -2547,10 +2551,10 @@ static void iter_bit_count_false(na_loop_t* const lp) {
2547
2551
  Returns the number of bits.
2548
2552
  If argument is supplied, return Int-array counted along the axes.
2549
2553
  @overload count_false(axis:nil, keepdims:false)
2550
- @param [Integer,Array,Range] axis (keyword) axes to be counted.
2551
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2552
- as dimensions with size one.
2553
- @return [Numo::Int64]
2554
+ @param [Integer,Array,Range] axis (keyword) axes to be counted.
2555
+ @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2556
+ as dimensions with size one.
2557
+ @return [Numo::Int64]
2554
2558
  */
2555
2559
  static VALUE bit_count_false(int argc, VALUE* argv, VALUE self) {
2556
2560
  VALUE v, reduce;
@@ -2662,10 +2666,10 @@ static void iter_bit_all_p(na_loop_t* const lp) {
2662
2666
  Return true if all of bits are one (true).
2663
2667
  If argument is supplied, return Bit-array reduced along the axes.
2664
2668
  @overload all?(axis:nil, keepdims:false)
2665
- @param [Integer,Array,Range] axis (keyword) axes to be reduced.
2666
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2667
- as dimensions with size one.
2668
- @return [Numo::Bit] .
2669
+ @param [Integer,Array,Range] axis (keyword) axes to be reduced.
2670
+ @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2671
+ as dimensions with size one.
2672
+ @return [Numo::Bit] .
2669
2673
  */
2670
2674
  static VALUE bit_all_p(int argc, VALUE* argv, VALUE self) {
2671
2675
  VALUE v, reduce;
@@ -2790,10 +2794,10 @@ static void iter_bit_any_p(na_loop_t* const lp) {
2790
2794
  Return true if any of bits is one (true).
2791
2795
  If argument is supplied, return Bit-array reduced along the axes.
2792
2796
  @overload any?(axis:nil, keepdims:false)
2793
- @param [Integer,Array,Range] axis (keyword) axes to be reduced.
2794
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2795
- as dimensions with size one.
2796
- @return [Numo::Bit] .
2797
+ @param [Integer,Array,Range] axis (keyword) axes to be reduced.
2798
+ @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
2799
+ as dimensions with size one.
2800
+ @return [Numo::Bit] .
2797
2801
  */
2798
2802
  static VALUE bit_any_p(int argc, VALUE* argv, VALUE self) {
2799
2803
  VALUE v, reduce;
@@ -2891,7 +2895,7 @@ static void iter_bit_where(na_loop_t* const lp) {
2891
2895
  /*
2892
2896
  Returns the array of index where the bit is one (true).
2893
2897
  @overload where
2894
- @return [Numo::Int32,Numo::Int64]
2898
+ @return [Numo::Int32,Numo::Int64]
2895
2899
  */
2896
2900
  static VALUE bit_where(VALUE self) {
2897
2901
  volatile VALUE idx_1;
@@ -2975,7 +2979,7 @@ static void iter_bit_where2(na_loop_t* const lp) {
2975
2979
  The first array contains index where the bit is one (true).
2976
2980
  The second array contains index where the bit is zero (false).
2977
2981
  @overload where2
2978
- @return [Numo::Int32,Numo::Int64]*2
2982
+ @return [Numo::Int32,Numo::Int64]*2
2979
2983
  */
2980
2984
  static VALUE bit_where2(VALUE self) {
2981
2985
  VALUE idx_1, idx_0;
@@ -3089,8 +3093,8 @@ static void shape_error(void) {
3089
3093
  /*
3090
3094
  Return subarray of argument masked with self bit array.
3091
3095
  @overload mask(array)
3092
- @param [Numo::NArray] array narray to be masked.
3093
- @return [Numo::NArray] view of masked array.
3096
+ @param [Numo::NArray] array narray to be masked.
3097
+ @return [Numo::NArray] view of masked array.
3094
3098
  */
3095
3099
  static VALUE bit_mask(VALUE mask, VALUE val) {
3096
3100
  int i;
@@ -3168,13 +3172,15 @@ void Init_numo_bit(void) {
3168
3172
  id_ne = rb_intern("ne");
3169
3173
  id_to_a = rb_intern("to_a");
3170
3174
 
3171
- /*
3172
- Document-class: Numo::Bit
3173
-
3174
- */
3175
+ /**
3176
+ * Document-class: Numo::Bit
3177
+ *
3178
+ * Binary digit (bit) N-dimensional array class.
3179
+ */
3175
3180
  cT = rb_define_class_under(mNumo, "Bit", cNArray);
3176
3181
 
3177
3182
  hCast = rb_hash_new();
3183
+ /* Upcasting rules of Bit. */
3178
3184
  rb_define_const(cT, "UPCAST", hCast);
3179
3185
  rb_hash_aset(hCast, rb_cArray, cT);
3180
3186
 
@@ -3201,11 +3207,11 @@ void Init_numo_bit(void) {
3201
3207
  rb_hash_aset(hCast, numo_cUInt8, numo_cUInt8);
3202
3208
  rb_obj_freeze(hCast);
3203
3209
 
3204
- /**/
3210
+ /* Element size of Bit in bits. */
3205
3211
  rb_define_const(cT, "ELEMENT_BIT_SIZE", INT2FIX(1));
3206
- /**/
3212
+ /* Element size of Bit in bytes. */
3207
3213
  rb_define_const(cT, "ELEMENT_BYTE_SIZE", rb_float_new(1.0 / 8));
3208
- /**/
3214
+ /* Stride size of contiguous Bit array. */
3209
3215
  rb_define_const(cT, "CONTIGUOUS_STRIDE", INT2FIX(1));
3210
3216
  rb_define_alloc_func(cT, bit_s_alloc_func);
3211
3217
  rb_define_method(cT, "allocate", bit_allocate, 0);
@@ -3242,4 +3248,48 @@ void Init_numo_bit(void) {
3242
3248
  rb_define_method(cT, "where2", bit_where2, 0);
3243
3249
  rb_define_method(cT, "mask", bit_mask, 1);
3244
3250
  rb_define_singleton_method(cT, "[]", bit_s_cast, -2);
3251
+ /**
3252
+ * mean of self.
3253
+ * @overload mean(axis: nil, keepdims: false, nan: false)
3254
+ * @param axis [Numeric, Array, Range] Performs mean along the axis.
3255
+ * @param keepdims [Boolean] If true, the reduced axes are left in the result array as
3256
+ * dimensions with size one.
3257
+ * @param nan [Boolean] If true, apply NaN-aware algorithm
3258
+ * (avoid NaN for sum/mean etc, or return NaN for min/max etc).
3259
+ * @return [Numo::DFloat] returns result of mean.
3260
+ */
3261
+ rb_define_method(cT, "mean", bit_mean, -1);
3262
+ /**
3263
+ * var of self.
3264
+ * @overload var(axis: nil, keepdims: false, nan: false)
3265
+ * @param axis [Numeric, Array, Range] Performs var along the axis.
3266
+ * @param keepdims [Boolean] If true, the reduced axes are left in the result array as
3267
+ * dimensions with size one.
3268
+ * @param nan [Boolean] If true, apply NaN-aware algorithm
3269
+ * (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
3270
+ * @return [Numo::DFloat] returns result of var.
3271
+ */
3272
+ rb_define_method(cT, "var", bit_var, -1);
3273
+ /**
3274
+ * stddev of self.
3275
+ * @overload stddev(axis: nil, keepdims: false, nan: false)
3276
+ * @param axis [Numeric, Array, Range] Performs stddev along the axis.
3277
+ * @param keepdims [Boolean] If true, the reduced axes are left in the result array as
3278
+ * dimensions with size one.
3279
+ * @param nan [Boolean] If true, apply NaN-aware algorithm
3280
+ * (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
3281
+ * @return [Numo::DFloat] returns result of stddev.
3282
+ */
3283
+ rb_define_method(cT, "stddev", bit_stddev, -1);
3284
+ /**
3285
+ * rms of self.
3286
+ * @overload rms(axis: nil, keepdims: false, nan: false)
3287
+ * @param axis [Numeric, Array, Range] Performs rms along the axis.
3288
+ * @param keepdims [Boolean] If true, the reduced axes are left in the result array as
3289
+ * dimensions with size one.
3290
+ * @param nan [Boolean] If true, apply NaN-aware algorithm
3291
+ * (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
3292
+ * @return [Numo::DFloat] returns result of rms.
3293
+ */
3294
+ rb_define_method(cT, "rms", bit_rms, -1);
3245
3295
  }