numo-narray-alt 0.9.10 → 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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/LICENSE +1 -1
  4. data/README.md +7 -0
  5. data/ext/numo/narray/numo/narray.h +2 -2
  6. data/ext/numo/narray/numo/types/robj_macro.h +1 -1
  7. data/ext/numo/narray/numo/types/robject.h +1 -1
  8. data/ext/numo/narray/src/mh/argmax.h +154 -0
  9. data/ext/numo/narray/src/mh/argmin.h +154 -0
  10. data/ext/numo/narray/src/mh/bincount.h +233 -0
  11. data/ext/numo/narray/src/mh/bit/and.h +225 -0
  12. data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
  13. data/ext/numo/narray/src/mh/bit/not.h +173 -0
  14. data/ext/numo/narray/src/mh/bit/or.h +225 -0
  15. data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
  16. data/ext/numo/narray/src/mh/bit/xor.h +225 -0
  17. data/ext/numo/narray/src/mh/clip.h +115 -0
  18. data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
  19. data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
  20. data/ext/numo/narray/src/mh/comp/eq.h +26 -0
  21. data/ext/numo/narray/src/mh/comp/ge.h +26 -0
  22. data/ext/numo/narray/src/mh/comp/gt.h +26 -0
  23. data/ext/numo/narray/src/mh/comp/le.h +26 -0
  24. data/ext/numo/narray/src/mh/comp/lt.h +26 -0
  25. data/ext/numo/narray/src/mh/comp/ne.h +26 -0
  26. data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
  27. data/ext/numo/narray/src/mh/cumprod.h +98 -0
  28. data/ext/numo/narray/src/mh/cumsum.h +98 -0
  29. data/ext/numo/narray/src/mh/divmod.h +142 -0
  30. data/ext/numo/narray/src/mh/eye.h +82 -0
  31. data/ext/numo/narray/src/mh/fill.h +94 -0
  32. data/ext/numo/narray/src/mh/format.h +108 -0
  33. data/ext/numo/narray/src/mh/format_to_a.h +89 -0
  34. data/ext/numo/narray/src/mh/inspect.h +33 -0
  35. data/ext/numo/narray/src/mh/isfinite.h +42 -0
  36. data/ext/numo/narray/src/mh/isinf.h +42 -0
  37. data/ext/numo/narray/src/mh/isnan.h +42 -0
  38. data/ext/numo/narray/src/mh/isneginf.h +42 -0
  39. data/ext/numo/narray/src/mh/isposinf.h +42 -0
  40. data/ext/numo/narray/src/mh/logseq.h +69 -0
  41. data/ext/numo/narray/src/mh/math/acos.h +2 -2
  42. data/ext/numo/narray/src/mh/math/acosh.h +2 -2
  43. data/ext/numo/narray/src/mh/math/asin.h +2 -2
  44. data/ext/numo/narray/src/mh/math/asinh.h +2 -2
  45. data/ext/numo/narray/src/mh/math/atan.h +2 -2
  46. data/ext/numo/narray/src/mh/math/atan2.h +3 -3
  47. data/ext/numo/narray/src/mh/math/atanh.h +2 -2
  48. data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
  49. data/ext/numo/narray/src/mh/math/cos.h +2 -2
  50. data/ext/numo/narray/src/mh/math/cosh.h +2 -2
  51. data/ext/numo/narray/src/mh/math/erf.h +2 -2
  52. data/ext/numo/narray/src/mh/math/erfc.h +2 -2
  53. data/ext/numo/narray/src/mh/math/exp.h +2 -2
  54. data/ext/numo/narray/src/mh/math/exp10.h +2 -2
  55. data/ext/numo/narray/src/mh/math/exp2.h +2 -2
  56. data/ext/numo/narray/src/mh/math/expm1.h +2 -2
  57. data/ext/numo/narray/src/mh/math/frexp.h +3 -3
  58. data/ext/numo/narray/src/mh/math/hypot.h +3 -3
  59. data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
  60. data/ext/numo/narray/src/mh/math/log.h +2 -2
  61. data/ext/numo/narray/src/mh/math/log10.h +2 -2
  62. data/ext/numo/narray/src/mh/math/log1p.h +2 -2
  63. data/ext/numo/narray/src/mh/math/log2.h +2 -2
  64. data/ext/numo/narray/src/mh/math/sin.h +2 -2
  65. data/ext/numo/narray/src/mh/math/sinc.h +2 -2
  66. data/ext/numo/narray/src/mh/math/sinh.h +2 -2
  67. data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
  68. data/ext/numo/narray/src/mh/math/tan.h +2 -2
  69. data/ext/numo/narray/src/mh/math/tanh.h +2 -2
  70. data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
  71. data/ext/numo/narray/src/mh/max.h +69 -0
  72. data/ext/numo/narray/src/mh/max_index.h +184 -0
  73. data/ext/numo/narray/src/mh/maximum.h +116 -0
  74. data/ext/numo/narray/src/mh/min.h +69 -0
  75. data/ext/numo/narray/src/mh/min_index.h +184 -0
  76. data/ext/numo/narray/src/mh/minimum.h +116 -0
  77. data/ext/numo/narray/src/mh/minmax.h +77 -0
  78. data/ext/numo/narray/src/mh/mulsum.h +185 -0
  79. data/ext/numo/narray/src/mh/op/add.h +78 -0
  80. data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
  81. data/ext/numo/narray/src/mh/op/div.h +118 -0
  82. data/ext/numo/narray/src/mh/op/mod.h +108 -0
  83. data/ext/numo/narray/src/mh/op/mul.h +78 -0
  84. data/ext/numo/narray/src/mh/op/sub.h +78 -0
  85. data/ext/numo/narray/src/mh/prod.h +69 -0
  86. data/ext/numo/narray/src/mh/ptp.h +69 -0
  87. data/ext/numo/narray/src/mh/rand.h +315 -0
  88. data/ext/numo/narray/src/mh/round/ceil.h +11 -0
  89. data/ext/numo/narray/src/mh/round/floor.h +11 -0
  90. data/ext/numo/narray/src/mh/round/rint.h +9 -0
  91. data/ext/numo/narray/src/mh/round/round.h +11 -0
  92. data/ext/numo/narray/src/mh/round/trunc.h +11 -0
  93. data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
  94. data/ext/numo/narray/src/mh/seq.h +130 -0
  95. data/ext/numo/narray/src/mh/sum.h +69 -0
  96. data/ext/numo/narray/src/mh/to_a.h +78 -0
  97. data/ext/numo/narray/src/t_bit.c +45 -234
  98. data/ext/numo/narray/src/t_dcomplex.c +608 -2369
  99. data/ext/numo/narray/src/t_dfloat.c +485 -3736
  100. data/ext/numo/narray/src/t_int16.c +743 -3444
  101. data/ext/numo/narray/src/t_int32.c +745 -3445
  102. data/ext/numo/narray/src/t_int64.c +743 -3446
  103. data/ext/numo/narray/src/t_int8.c +678 -3040
  104. data/ext/numo/narray/src/t_robject.c +771 -3548
  105. data/ext/numo/narray/src/t_scomplex.c +607 -2368
  106. data/ext/numo/narray/src/t_sfloat.c +440 -3693
  107. data/ext/numo/narray/src/t_uint16.c +743 -3440
  108. data/ext/numo/narray/src/t_uint32.c +743 -3440
  109. data/ext/numo/narray/src/t_uint64.c +743 -3442
  110. data/ext/numo/narray/src/t_uint8.c +678 -3038
  111. data/lib/numo/narray.rb +2 -3
  112. metadata +62 -3
@@ -0,0 +1,130 @@
1
+ #ifndef NUMO_NARRAY_MH_SEQ_H
2
+ #define NUMO_NARRAY_MH_SEQ_H 1
3
+
4
+ #define DEF_NARRAY_FLT_SEQ_METHOD_FUNC(tDType) \
5
+ typedef struct { \
6
+ tDType beg; \
7
+ tDType step; \
8
+ double count; \
9
+ } seq_opt_t; \
10
+ \
11
+ static void iter_##tDType##_seq(na_loop_t* const lp) { \
12
+ size_t n; \
13
+ char* p1; \
14
+ ssize_t s1; \
15
+ size_t* idx1; \
16
+ tDType x; \
17
+ tDType beg; \
18
+ tDType step; \
19
+ double c; \
20
+ seq_opt_t* g; \
21
+ \
22
+ INIT_COUNTER(lp, n); \
23
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
24
+ g = (seq_opt_t*)(lp->opt_ptr); \
25
+ beg = g->beg; \
26
+ step = g->step; \
27
+ c = g->count; \
28
+ if (idx1) { \
29
+ for (size_t i = 0; i < n; i++) { \
30
+ x = f_seq(beg, step, c++); \
31
+ *(tDType*)(p1 + *idx1) = x; \
32
+ idx1++; \
33
+ } \
34
+ } else { \
35
+ for (size_t i = 0; i < n; i++) { \
36
+ x = f_seq(beg, step, c++); \
37
+ *(tDType*)(p1) = x; \
38
+ p1 += s1; \
39
+ } \
40
+ } \
41
+ g->count = c; \
42
+ } \
43
+ \
44
+ static VALUE tDType##_seq(int argc, VALUE* args, VALUE self) { \
45
+ seq_opt_t* g; \
46
+ VALUE vbeg = Qnil; \
47
+ VALUE vstep = Qnil; \
48
+ ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
49
+ ndfunc_t ndf = { iter_##tDType##_seq, FULL_LOOP, 1, 0, ain, 0 }; \
50
+ \
51
+ g = ALLOCA_N(seq_opt_t, 1); \
52
+ g->beg = m_zero; \
53
+ g->step = m_one; \
54
+ g->count = 0; \
55
+ rb_scan_args(argc, args, "02", &vbeg, &vstep); \
56
+ if (vbeg != Qnil) { \
57
+ g->beg = m_num_to_data(vbeg); \
58
+ } \
59
+ if (vstep != Qnil) { \
60
+ g->step = m_num_to_data(vstep); \
61
+ } \
62
+ \
63
+ na_ndloop3(&ndf, g, 1, self); \
64
+ return self; \
65
+ }
66
+
67
+ #define DEF_NARRAY_INT_SEQ_METHOD_FUNC(tDType) \
68
+ typedef struct { \
69
+ double beg; \
70
+ double step; \
71
+ double count; \
72
+ } seq_opt_t; \
73
+ \
74
+ static void iter_##tDType##_seq(na_loop_t* const lp) { \
75
+ size_t n; \
76
+ char* p1; \
77
+ ssize_t s1; \
78
+ size_t* idx1; \
79
+ tDType x; \
80
+ double beg; \
81
+ double step; \
82
+ double c; \
83
+ seq_opt_t* g; \
84
+ \
85
+ INIT_COUNTER(lp, n); \
86
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
87
+ g = (seq_opt_t*)(lp->opt_ptr); \
88
+ beg = g->beg; \
89
+ step = g->step; \
90
+ c = g->count; \
91
+ if (idx1) { \
92
+ for (size_t i = 0; i < n; i++) { \
93
+ x = f_seq(beg, step, c++); \
94
+ *(tDType*)(p1 + *idx1) = x; \
95
+ idx1++; \
96
+ } \
97
+ } else { \
98
+ for (size_t i = 0; i < n; i++) { \
99
+ x = f_seq(beg, step, c++); \
100
+ *(tDType*)(p1) = x; \
101
+ p1 += s1; \
102
+ } \
103
+ } \
104
+ g->count = c; \
105
+ } \
106
+ \
107
+ static VALUE tDType##_seq(int argc, VALUE* argv, VALUE self) { \
108
+ seq_opt_t* g; \
109
+ VALUE vbeg = Qnil; \
110
+ VALUE vstep = Qnil; \
111
+ ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
112
+ ndfunc_t ndf = { iter_##tDType##_seq, FULL_LOOP, 1, 0, ain, 0 }; \
113
+ \
114
+ g = ALLOCA_N(seq_opt_t, 1); \
115
+ g->beg = m_zero; \
116
+ g->step = m_one; \
117
+ g->count = 0; \
118
+ rb_scan_args(argc, argv, "02", &vbeg, &vstep); \
119
+ if (vbeg != Qnil) { \
120
+ g->beg = NUM2DBL(vbeg); \
121
+ } \
122
+ if (vstep != Qnil) { \
123
+ g->step = NUM2DBL(vstep); \
124
+ } \
125
+ \
126
+ na_ndloop3(&ndf, g, 1, self); \
127
+ return self; \
128
+ }
129
+
130
+ #endif /* NUMO_NARRAY_MH_SEQ_H */
@@ -0,0 +1,69 @@
1
+ #ifndef NUMO_NARRAY_MH_SUM_H
2
+ #define NUMO_NARRAY_MH_SUM_H 1
3
+
4
+ #define DEF_NARRAY_FLT_SUM_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_sum(na_loop_t* const lp) { \
6
+ size_t n; \
7
+ char* p1; \
8
+ char* p2; \
9
+ ssize_t s1; \
10
+ \
11
+ INIT_COUNTER(lp, n); \
12
+ INIT_PTR(lp, 0, p1, s1); \
13
+ p2 = NDL_PTR(lp, 1); \
14
+ \
15
+ *(tDType*)p2 = f_sum(n, p1, s1); \
16
+ } \
17
+ \
18
+ static void iter_##tDType##_sum_nan(na_loop_t* const lp) { \
19
+ size_t n; \
20
+ char* p1; \
21
+ char* p2; \
22
+ ssize_t s1; \
23
+ \
24
+ INIT_COUNTER(lp, n); \
25
+ INIT_PTR(lp, 0, p1, s1); \
26
+ p2 = NDL_PTR(lp, 1); \
27
+ \
28
+ *(tDType*)p2 = f_sum_nan(n, p1, s1); \
29
+ } \
30
+ \
31
+ static VALUE tDType##_sum(int argc, VALUE* argv, VALUE self) { \
32
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
33
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
34
+ ndfunc_t ndf = { \
35
+ iter_##tDType##_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
36
+ }; \
37
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_sum_nan); \
38
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
39
+ \
40
+ return rb_funcall(v, rb_intern("extract"), 0); \
41
+ }
42
+
43
+ #define DEF_NARRAY_INT_SUM_METHOD_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass) \
44
+ static void iter_##tDType##_sum(na_loop_t* const lp) { \
45
+ size_t n; \
46
+ char* p1; \
47
+ char* p2; \
48
+ ssize_t s1; \
49
+ \
50
+ INIT_COUNTER(lp, n); \
51
+ INIT_PTR(lp, 0, p1, s1); \
52
+ p2 = NDL_PTR(lp, 1); \
53
+ \
54
+ *(tRtDType*)p2 = f_sum(n, p1, s1); \
55
+ } \
56
+ \
57
+ static VALUE tDType##_sum(int argc, VALUE* argv, VALUE self) { \
58
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
59
+ ndfunc_arg_out_t aout[1] = { { tRtNAryClass, 0 } }; \
60
+ ndfunc_t ndf = { \
61
+ iter_##tDType##_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
62
+ }; \
63
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
64
+ VALUE v = na_ndloop(&ndf, 2, self, reduce); \
65
+ \
66
+ return rb_funcall(v, rb_intern("extract"), 0); \
67
+ }
68
+
69
+ #endif /* NUMO_NARRAY_MH_SUM_H */
@@ -0,0 +1,78 @@
1
+ #ifndef NUMO_NARRAY_MH_TO_A_H
2
+ #define NUMO_NARRAY_MH_TO_A_H 1
3
+
4
+ #define DEF_NARRAY_TO_A_METHOD_FUNC(tDType) \
5
+ static void iter_##tDType##_to_a(na_loop_t* const lp) { \
6
+ size_t n; \
7
+ size_t s1; \
8
+ char* p1; \
9
+ size_t* idx1; \
10
+ tDType x; \
11
+ volatile VALUE a, y; \
12
+ \
13
+ INIT_COUNTER(lp, n); \
14
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
15
+ a = rb_ary_new2(n); \
16
+ rb_ary_push(lp->args[1].value, a); \
17
+ if (idx1) { \
18
+ for (size_t i = 0; i < n; i++) { \
19
+ GET_DATA_INDEX(p1, idx1, tDType, x); \
20
+ y = m_data_to_num(x); \
21
+ rb_ary_push(a, y); \
22
+ } \
23
+ } else { \
24
+ for (size_t i = 0; i < n; i++) { \
25
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
26
+ y = m_data_to_num(x); \
27
+ rb_ary_push(a, y); \
28
+ } \
29
+ } \
30
+ } \
31
+ \
32
+ static VALUE tDType##_to_a(VALUE self) { \
33
+ ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } }; \
34
+ ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; \
35
+ ndfunc_t ndf = { iter_##tDType##_to_a, FULL_LOOP_NIP, 3, 1, ain, aout }; \
36
+ return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil); \
37
+ }
38
+
39
+ #define DEF_NARRAY_BIT_TO_A_METHOD_FUNC() \
40
+ static void iter_bit_to_a(na_loop_t* const lp) { \
41
+ size_t n; \
42
+ BIT_DIGIT* a1; \
43
+ size_t p1; \
44
+ ssize_t s1; \
45
+ size_t* idx1; \
46
+ BIT_DIGIT x = 0; \
47
+ VALUE a; \
48
+ VALUE y; \
49
+ \
50
+ INIT_COUNTER(lp, n); \
51
+ INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
52
+ a = rb_ary_new2(n); \
53
+ rb_ary_push(lp->args[1].value, a); \
54
+ if (idx1) { \
55
+ for (size_t i = 0; i < n; i++) { \
56
+ LOAD_BIT(a1, p1 + *idx1, x); \
57
+ idx1++; \
58
+ y = m_data_to_num(x); \
59
+ rb_ary_push(a, y); \
60
+ } \
61
+ } else { \
62
+ for (size_t i = 0; i < n; i++) { \
63
+ LOAD_BIT(a1, p1, x); \
64
+ p1 += s1; \
65
+ y = m_data_to_num(x); \
66
+ rb_ary_push(a, y); \
67
+ } \
68
+ } \
69
+ } \
70
+ \
71
+ static VALUE bit_to_a(VALUE self) { \
72
+ ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } }; \
73
+ ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; \
74
+ ndfunc_t ndf = { iter_bit_to_a, FULL_LOOP_NIP, 3, 1, ain, aout }; \
75
+ return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil); \
76
+ }
77
+
78
+ #endif /* NUMO_NARRAY_MH_TO_A_H */
@@ -31,11 +31,23 @@ static ID id_to_a;
31
31
  VALUE cT;
32
32
  extern VALUE cRT;
33
33
 
34
+ #include "mh/coerce_cast.h"
35
+ #include "mh/to_a.h"
36
+ #include "mh/fill.h"
37
+ #include "mh/format.h"
38
+ #include "mh/format_to_a.h"
39
+ #include "mh/inspect.h"
34
40
  #include "mh/mean.h"
35
41
  #include "mh/var.h"
36
42
  #include "mh/stddev.h"
37
43
  #include "mh/rms.h"
38
44
 
45
+ DEF_NARRAY_COERCE_CAST_METHOD_FUNC(bit)
46
+ DEF_NARRAY_BIT_TO_A_METHOD_FUNC()
47
+ DEF_NARRAY_BIT_FILL_METHOD_FUNC()
48
+ DEF_NARRAY_BIT_FORMAT_METHOD_FUNC()
49
+ DEF_NARRAY_BIT_FORMAT_TO_A_METHOD_FUNC()
50
+ DEF_NARRAY_BIT_INSPECT_METHOD_FUNC()
39
51
  DEF_NARRAY_BIT_MEAN_METHOD_FUNC()
40
52
  DEF_NARRAY_BIT_VAR_METHOD_FUNC()
41
53
  DEF_NARRAY_BIT_STDDEV_METHOD_FUNC()
@@ -1353,240 +1365,6 @@ static VALUE bit_aset(int argc, VALUE* argv, VALUE self) {
1353
1365
  return argv[argc];
1354
1366
  }
1355
1367
 
1356
- /*
1357
- return NArray with cast to the type of self.
1358
- @overload coerce_cast(type)
1359
- @return [nil]
1360
- */
1361
- static VALUE bit_coerce_cast(VALUE self, VALUE type) {
1362
- return Qnil;
1363
- }
1364
-
1365
- static void iter_bit_to_a(na_loop_t* const lp) {
1366
- size_t i;
1367
- BIT_DIGIT* a1;
1368
- size_t p1;
1369
- ssize_t s1;
1370
- size_t* idx1;
1371
- BIT_DIGIT x = 0;
1372
- VALUE a, y;
1373
-
1374
- INIT_COUNTER(lp, i);
1375
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
1376
- a = rb_ary_new2(i);
1377
- rb_ary_push(lp->args[1].value, a);
1378
- if (idx1) {
1379
- for (; i--;) {
1380
- LOAD_BIT(a1, p1 + *idx1, x);
1381
- idx1++;
1382
- y = m_data_to_num(x);
1383
- rb_ary_push(a, y);
1384
- }
1385
- } else {
1386
- for (; i--;) {
1387
- LOAD_BIT(a1, p1, x);
1388
- p1 += s1;
1389
- y = m_data_to_num(x);
1390
- rb_ary_push(a, y);
1391
- }
1392
- }
1393
- }
1394
-
1395
- /*
1396
- Convert self to Array.
1397
- @overload to_a
1398
- @return [Array]
1399
- */
1400
- static VALUE bit_to_a(VALUE self) {
1401
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1402
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1403
- ndfunc_t ndf = { iter_bit_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1404
- return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
1405
- }
1406
-
1407
- static void iter_bit_fill(na_loop_t* const lp) {
1408
- size_t n;
1409
- size_t p3;
1410
- ssize_t s3;
1411
- size_t* idx3;
1412
- int len;
1413
- BIT_DIGIT* a3;
1414
- BIT_DIGIT y;
1415
- VALUE x = lp->option;
1416
-
1417
- if (x == INT2FIX(0) || x == Qfalse) {
1418
- y = 0;
1419
- } else if (x == INT2FIX(1) || x == Qtrue) {
1420
- y = ~(BIT_DIGIT)0;
1421
- } else {
1422
- rb_raise(rb_eArgError, "invalid value for Bit");
1423
- }
1424
-
1425
- INIT_COUNTER(lp, n);
1426
- INIT_PTR_BIT_IDX(lp, 0, a3, p3, s3, idx3);
1427
- if (idx3) {
1428
- y = y & 1;
1429
- for (; n--;) {
1430
- STORE_BIT(a3, p3 + *idx3, y);
1431
- idx3++;
1432
- }
1433
- } else if (s3 != 1) {
1434
- y = y & 1;
1435
- for (; n--;) {
1436
- STORE_BIT(a3, p3, y);
1437
- p3 += s3;
1438
- }
1439
- } else {
1440
- if (p3 > 0 || n < NB) {
1441
- len = (int)(NB - p3);
1442
- if ((int)n < len) len = (int)n;
1443
- *a3 = (y & (SLB(len) << p3)) | (*a3 & ~(SLB(len) << p3));
1444
- a3++;
1445
- n -= len;
1446
- }
1447
- for (; n >= NB; n -= NB) {
1448
- *(a3++) = y;
1449
- }
1450
- if (n > 0) {
1451
- *a3 = (y & SLB(n)) | (*a3 & BALL << n);
1452
- }
1453
- }
1454
- }
1455
-
1456
- /*
1457
- Fill elements with other.
1458
- @overload fill other
1459
- @param [Numeric] other
1460
- @return [Numo::Bit] self.
1461
- */
1462
- static VALUE bit_fill(VALUE self, VALUE val) {
1463
- ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
1464
- ndfunc_t ndf = { iter_bit_fill, FULL_LOOP, 2, 0, ain, 0 };
1465
-
1466
- na_ndloop(&ndf, 2, self, val);
1467
- return self;
1468
- }
1469
-
1470
- static VALUE format_bit(VALUE fmt, dtype x) {
1471
- if (NIL_P(fmt)) {
1472
- char s[4];
1473
- int n;
1474
- n = m_sprintf(s, x);
1475
- return rb_str_new(s, n);
1476
- }
1477
- return rb_funcall(fmt, '%', 1, m_data_to_num(x));
1478
- }
1479
-
1480
- static void iter_bit_format(na_loop_t* const lp) {
1481
- size_t i;
1482
- BIT_DIGIT *a1, x = 0;
1483
- size_t p1;
1484
- char* p2;
1485
- ssize_t s1, s2;
1486
- size_t* idx1;
1487
- VALUE y;
1488
- VALUE fmt = lp->option;
1489
-
1490
- INIT_COUNTER(lp, i);
1491
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
1492
- INIT_PTR(lp, 1, p2, s2);
1493
-
1494
- if (idx1) {
1495
- for (; i--;) {
1496
- LOAD_BIT(a1, p1 + *idx1, x);
1497
- idx1++;
1498
- y = format_bit(fmt, x);
1499
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1500
- }
1501
- } else {
1502
- for (; i--;) {
1503
- LOAD_BIT(a1, p1, x);
1504
- p1 += s1;
1505
- y = format_bit(fmt, x);
1506
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1507
- }
1508
- }
1509
- }
1510
-
1511
- /*
1512
- Format elements into strings.
1513
- @overload format format
1514
- @param [String] format
1515
- @return [Numo::RObject] array of formatted strings.
1516
- */
1517
- static VALUE bit_format(int argc, VALUE* argv, VALUE self) {
1518
- VALUE fmt = Qnil;
1519
-
1520
- ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
1521
- ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
1522
- ndfunc_t ndf = { iter_bit_format, FULL_LOOP_NIP, 2, 1, ain, aout };
1523
-
1524
- rb_scan_args(argc, argv, "01", &fmt);
1525
- return na_ndloop(&ndf, 2, self, fmt);
1526
- }
1527
-
1528
- static void iter_bit_format_to_a(na_loop_t* const lp) {
1529
- size_t i;
1530
- BIT_DIGIT *a1, x = 0;
1531
- size_t p1;
1532
- ssize_t s1;
1533
- size_t* idx1;
1534
- VALUE y;
1535
- VALUE fmt = lp->option;
1536
- volatile VALUE a;
1537
-
1538
- INIT_COUNTER(lp, i);
1539
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
1540
- a = rb_ary_new2(i);
1541
- rb_ary_push(lp->args[1].value, a);
1542
- if (idx1) {
1543
- for (; i--;) {
1544
- LOAD_BIT(a1, p1 + *idx1, x);
1545
- idx1++;
1546
- y = format_bit(fmt, x);
1547
- rb_ary_push(a, y);
1548
- }
1549
- } else {
1550
- for (; i--;) {
1551
- LOAD_BIT(a1, p1, x);
1552
- p1 += s1;
1553
- y = format_bit(fmt, x);
1554
- rb_ary_push(a, y);
1555
- }
1556
- }
1557
- }
1558
-
1559
- /*
1560
- Format elements into strings.
1561
- @overload format_to_a format
1562
- @param [String] format
1563
- @return [Array] array of formatted strings.
1564
- */
1565
- static VALUE bit_format_to_a(int argc, VALUE* argv, VALUE self) {
1566
- VALUE fmt = Qnil;
1567
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1568
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1569
- ndfunc_t ndf = { iter_bit_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1570
-
1571
- rb_scan_args(argc, argv, "01", &fmt);
1572
- return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
1573
- }
1574
-
1575
- static VALUE iter_bit_inspect(char* ptr, size_t pos, VALUE fmt) {
1576
- dtype x;
1577
- LOAD_BIT(ptr, pos, x);
1578
- return format_bit(fmt, x);
1579
- }
1580
-
1581
- /*
1582
- Returns a string containing a human-readable representation of NArray.
1583
- @overload inspect
1584
- @return [String]
1585
- */
1586
- static VALUE bit_inspect(VALUE ary) {
1587
- return na_ndloop_inspect(ary, iter_bit_inspect, Qnil);
1588
- }
1589
-
1590
1368
  static void iter_bit_each(na_loop_t* const lp) {
1591
1369
  size_t i;
1592
1370
  BIT_DIGIT *a1, x = 0;
@@ -3222,11 +3000,44 @@ void Init_numo_bit(void) {
3222
3000
  rb_define_singleton_method(cT, "cast", bit_s_cast, 1);
3223
3001
  rb_define_method(cT, "[]", bit_aref, -1);
3224
3002
  rb_define_method(cT, "[]=", bit_aset, -1);
3003
+ /**
3004
+ * return NArray with cast to the type of self.
3005
+ * @overload coerce_cast(type)
3006
+ * @return [nil]
3007
+ */
3225
3008
  rb_define_method(cT, "coerce_cast", bit_coerce_cast, 1);
3009
+ /**
3010
+ * Convert self to Array.
3011
+ * @overload to_a
3012
+ * @return [Array]
3013
+ */
3226
3014
  rb_define_method(cT, "to_a", bit_to_a, 0);
3015
+ /**
3016
+ * Fill elements with other.
3017
+ * @overload fill other
3018
+ * @param [Numeric] other
3019
+ * @return [Numo::Bit] self.
3020
+ */
3227
3021
  rb_define_method(cT, "fill", bit_fill, 1);
3022
+ /**
3023
+ * Format elements into strings.
3024
+ * @overload format format
3025
+ * @param [String] format
3026
+ * @return [Numo::RObject] array of formatted strings.
3027
+ */
3228
3028
  rb_define_method(cT, "format", bit_format, -1);
3029
+ /**
3030
+ * Format elements into strings.
3031
+ * @overload format_to_a format
3032
+ * @param [String] format
3033
+ * @return [Array] array of formatted strings.
3034
+ */
3229
3035
  rb_define_method(cT, "format_to_a", bit_format_to_a, -1);
3036
+ /**
3037
+ * Returns a string containing a human-readable representation of NArray.
3038
+ * @overload inspect
3039
+ * @return [String]
3040
+ */
3230
3041
  rb_define_method(cT, "inspect", bit_inspect, 0);
3231
3042
  rb_define_method(cT, "each", bit_each, 0);
3232
3043
  rb_define_method(cT, "each_with_index", bit_each_with_index, 0);