numo-narray-alt 0.10.3 → 0.10.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3add9ba11a05a8f7e149d5cc4f00b15b870cedc1ae8dd20a603213c9fa9f87bc
4
- data.tar.gz: d2faa61ca233802311b7a77ec70bf1049cde822123d177274f27d667a5aa570b
3
+ metadata.gz: b00e8da08175d2c19b50dc634303140c251a2139c223b2c8f3ef515858314da0
4
+ data.tar.gz: 484a78cdd0959d3d2a09e438c8eaeef953964612590c3c44050d5ca906e65a75
5
5
  SHA512:
6
- metadata.gz: aceb6275928c5da4b8b2d2ca47faada75eec985ff762740954f76c9620fe73b7edc2346359336c2dd79ad9433998fdf425fbe5ceef8d760fd5d9f0718e2aa653
7
- data.tar.gz: ef431dd49b3470c4ffdf5c4eeafa8faee4d2e66b9167c4d0dd4a5816ed8e83ad3e8590701cba491a6265453e9bcbfb6f2612d9f8ef3495a833b79736e08d5aa6
6
+ metadata.gz: 58600b9b39c99a28f4ec6df40d1dfba22db1c1aa38dc50d61fa905f31cdb3dcd623a0b07b81519d8341d0afa644b4ec3695c5ddf9889ffbb82decca415b34959
7
+ data.tar.gz: e0112d66a2bd84afb953ab911119884969fb6004815313c2d85e8898963393de4434d7ca0286bc9da84a4d880dfc16f5c609c218fcfd61fc65add01186e10d8c
data/README.md CHANGED
@@ -74,6 +74,9 @@ Numo::NArray Alternative is used in the following projects:
74
74
  - [numo-linalg-randsvd](https://github.com/yoshoku/numo-linalg-randsvd): Randomized SVD library for numo-linalg-alt.
75
75
  - [rumale](https://github.com/yoshoku/rumale): Machine learning library.
76
76
 
77
+ For a full list of gems using numo-narray-alt, see
78
+ [reverse dependencies on RubyGems.org](https://rubygems.org/gems/numo-narray-alt/reverse_dependencies).
79
+
77
80
  ## Development
78
81
 
79
82
  preparation:
@@ -13,10 +13,10 @@ extern "C" {
13
13
  #endif
14
14
  #endif
15
15
 
16
- #define NARRAY_VERSION "0.10.3"
16
+ #define NARRAY_VERSION "0.10.4"
17
17
  #define NARRAY_VERSION_MAJOR 0
18
18
  #define NARRAY_VERSION_MINOR 10
19
- #define NARRAY_VERSION_PATCH 3
19
+ #define NARRAY_VERSION_PATCH 4
20
20
  #define NARRAY_VERSION_CODE \
21
21
  (NARRAY_VERSION_MAJOR * 10000 + NARRAY_VERSION_MINOR * 100 + NARRAY_VERSION_PATCH)
22
22
 
@@ -12,17 +12,4 @@
12
12
  return m_extract(ptr); \
13
13
  }
14
14
 
15
- #define DEF_NARRAY_BIT_AREF_METHOD_FUNC() \
16
- static VALUE bit_aref(int argc, VALUE* argv, VALUE self) { \
17
- size_t pos; \
18
- int nd = na_get_result_dimension(self, argc, argv, 1, &pos); \
19
- if (nd) { \
20
- return na_aref_main(argc, argv, self, 0, nd); \
21
- } \
22
- char* ptr = na_get_pointer_for_read(self); \
23
- BIT_DIGIT x; \
24
- LOAD_BIT(ptr, pos, x); \
25
- return m_data_to_num(x); \
26
- }
27
-
28
15
  #endif /* NUMO_NARRAY_MH_AREF_H */
@@ -33,39 +33,4 @@
33
33
  return self; \
34
34
  }
35
35
 
36
- #define DEF_NARRAY_BIT_EACH_METHOD_FUNC() \
37
- static void iter_bit_each(na_loop_t* const lp) { \
38
- size_t n; \
39
- BIT_DIGIT* a1; \
40
- size_t p1; \
41
- ssize_t s1; \
42
- size_t* idx1; \
43
- INIT_COUNTER(lp, n); \
44
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
45
- BIT_DIGIT x = 0; \
46
- VALUE y; \
47
- if (idx1) { \
48
- for (size_t i = 0; i < n; i++) { \
49
- LOAD_BIT(a1, p1 + *idx1, x); \
50
- idx1++; \
51
- y = m_data_to_num(x); \
52
- rb_yield(y); \
53
- } \
54
- } else { \
55
- for (size_t i = 0; i < n; i++) { \
56
- LOAD_BIT(a1, p1, x); \
57
- p1 += s1; \
58
- y = m_data_to_num(x); \
59
- rb_yield(y); \
60
- } \
61
- } \
62
- } \
63
- \
64
- static VALUE bit_each(VALUE self) { \
65
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } }; \
66
- ndfunc_t ndf = { iter_bit_each, FULL_LOOP_NIP, 1, 0, ain, 0 }; \
67
- na_ndloop(&ndf, 1, self); \
68
- return self; \
69
- }
70
-
71
36
  #endif /* NUMO_NARRAY_MH_EACH_H */
@@ -48,51 +48,4 @@
48
48
  return self; \
49
49
  }
50
50
 
51
- #define DEF_NARRAY_BIT_EACH_WITH_INDEX_METHOD_FUNC() \
52
- static inline void yield_each_with_index(BIT_DIGIT x, size_t* c, VALUE* a, int nd, int md) { \
53
- a[0] = m_data_to_num(x); \
54
- for (int j = 0; j <= nd; j++) { \
55
- a[j + 1] = SIZET2NUM(c[j]); \
56
- } \
57
- rb_yield(rb_ary_new4(md, a)); \
58
- } \
59
- \
60
- static void iter_bit_each_with_index(na_loop_t* const lp) { \
61
- size_t* c = (size_t*)(lp->opt_ptr); \
62
- int nd = lp->ndim - 1; \
63
- int md = lp->ndim + 1; \
64
- VALUE* a = ALLOCA_N(VALUE, md); \
65
- size_t n; \
66
- BIT_DIGIT* a1; \
67
- size_t p1; \
68
- ssize_t s1; \
69
- size_t* idx1; \
70
- INIT_COUNTER(lp, n); \
71
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
72
- BIT_DIGIT x = 0; \
73
- c[nd] = 0; \
74
- if (idx1) { \
75
- for (size_t i = 0; i < n; i++) { \
76
- LOAD_BIT(a1, p1 + *idx1, x); \
77
- idx1++; \
78
- yield_each_with_index(x, c, a, nd, md); \
79
- c[nd]++; \
80
- } \
81
- } else { \
82
- for (size_t i = 0; i < n; i++) { \
83
- LOAD_BIT(a1, p1, x); \
84
- p1 += s1; \
85
- yield_each_with_index(x, c, a, nd, md); \
86
- c[nd]++; \
87
- } \
88
- } \
89
- } \
90
- \
91
- static VALUE bit_each_with_index(VALUE self) { \
92
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } }; \
93
- ndfunc_t ndf = { iter_bit_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 }; \
94
- na_ndloop_with_index(&ndf, 1, self); \
95
- return self; \
96
- }
97
-
98
51
  #endif /* NUMO_NARRAY_MH_EACH_WITH_INDEX_H */
@@ -16,21 +16,4 @@
16
16
  return self; \
17
17
  }
18
18
 
19
- #define DEF_NARRAY_BIT_EXTRACT_METHOD_FUNC() \
20
- static VALUE bit_extract(VALUE self) { \
21
- BIT_DIGIT* ptr; \
22
- BIT_DIGIT val; \
23
- size_t pos; \
24
- narray_t* na; \
25
- GetNArray(self, na); \
26
- if (na->ndim == 0) { \
27
- pos = na_get_offset(self); \
28
- ptr = (BIT_DIGIT*)na_get_pointer_for_read(self); \
29
- val = ((*((ptr) + (pos) / NB)) >> ((pos) % NB)) & 1u; \
30
- na_release_lock(self); \
31
- return INT2FIX(val); \
32
- } \
33
- return self; \
34
- }
35
-
36
19
  #endif /* NUMO_NARRAY_MH_EXTRACT_H */
@@ -32,63 +32,4 @@
32
32
  return self; \
33
33
  }
34
34
 
35
- #define DEF_NARRAY_BIT_FILL_METHOD_FUNC() \
36
- static void iter_bit_fill(na_loop_t* const lp) { \
37
- size_t n; \
38
- size_t p3; \
39
- ssize_t s3; \
40
- size_t* idx3; \
41
- int len; \
42
- BIT_DIGIT* a3; \
43
- BIT_DIGIT y; \
44
- VALUE x = lp->option; \
45
- \
46
- if (x == INT2FIX(0) || x == Qfalse) { \
47
- y = 0; \
48
- } else if (x == INT2FIX(1) || x == Qtrue) { \
49
- y = ~(BIT_DIGIT)0; \
50
- } else { \
51
- rb_raise(rb_eArgError, "invalid value for Bit"); \
52
- } \
53
- \
54
- INIT_COUNTER(lp, n); \
55
- INIT_PTR_BIT_IDX(lp, 0, a3, p3, s3, idx3); \
56
- if (idx3) { \
57
- y = y & 1; \
58
- for (size_t i = 0; i < n; i++) { \
59
- STORE_BIT(a3, p3 + *idx3, y); \
60
- idx3++; \
61
- } \
62
- } else if (s3 != 1) { \
63
- y = y & 1; \
64
- for (size_t i = 0; i < n; i++) { \
65
- STORE_BIT(a3, p3, y); \
66
- p3 += s3; \
67
- } \
68
- } else { \
69
- if (p3 > 0 || n < NB) { \
70
- len = (int)(NB - p3); \
71
- if ((int)n < len) { \
72
- len = (int)n; \
73
- } \
74
- *a3 = (y & (SLB(len) << p3)) | (*a3 & ~(SLB(len) << p3)); \
75
- a3++; \
76
- n -= len; \
77
- } \
78
- for (; n >= NB; n -= NB) { \
79
- *(a3++) = y; \
80
- } \
81
- if (n > 0) { \
82
- *a3 = (y & SLB(n)) | (*a3 & BALL << n); \
83
- } \
84
- } \
85
- } \
86
- \
87
- static VALUE bit_fill(VALUE self, VALUE val) { \
88
- ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } }; \
89
- ndfunc_t ndf = { iter_bit_fill, FULL_LOOP, 2, 0, ain, 0 }; \
90
- na_ndloop(&ndf, 2, self, val); \
91
- return self; \
92
- }
93
-
94
35
  #endif /* NUMO_NARRAY_MH_FILL_H */
@@ -52,57 +52,4 @@
52
52
  return na_ndloop(&ndf, 2, self, fmt); \
53
53
  }
54
54
 
55
- #define DEF_NARRAY_BIT_FORMAT_METHOD_FUNC() \
56
- static VALUE format_bit(VALUE fmt, BIT_DIGIT x) { \
57
- if (NIL_P(fmt)) { \
58
- char s[4]; \
59
- int n; \
60
- n = m_sprintf(s, x); \
61
- return rb_str_new(s, n); \
62
- } \
63
- return rb_funcall(fmt, '%', 1, m_data_to_num(x)); \
64
- } \
65
- \
66
- static void iter_bit_format(na_loop_t* const lp) { \
67
- size_t n; \
68
- BIT_DIGIT* a1; \
69
- BIT_DIGIT x = 0; \
70
- size_t p1; \
71
- char* p2; \
72
- ssize_t s1; \
73
- ssize_t s2; \
74
- size_t* idx1; \
75
- VALUE y; \
76
- VALUE fmt = lp->option; \
77
- \
78
- INIT_COUNTER(lp, n); \
79
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
80
- INIT_PTR(lp, 1, p2, s2); \
81
- \
82
- if (idx1) { \
83
- for (size_t i = 0; i < n; i++) { \
84
- LOAD_BIT(a1, p1 + *idx1, x); \
85
- idx1++; \
86
- y = format_bit(fmt, x); \
87
- SET_DATA_STRIDE(p2, s2, VALUE, y); \
88
- } \
89
- } else { \
90
- for (size_t i = 0; i < n; i++) { \
91
- LOAD_BIT(a1, p1, x); \
92
- p1 += s1; \
93
- y = format_bit(fmt, x); \
94
- SET_DATA_STRIDE(p2, s2, VALUE, y); \
95
- } \
96
- } \
97
- } \
98
- \
99
- static VALUE bit_format(int argc, VALUE* argv, VALUE self) { \
100
- VALUE fmt = Qnil; \
101
- ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } }; \
102
- ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } }; \
103
- ndfunc_t ndf = { iter_bit_format, FULL_LOOP_NIP, 2, 1, ain, aout }; \
104
- rb_scan_args(argc, argv, "01", &fmt); \
105
- return na_ndloop(&ndf, 2, self, fmt); \
106
- }
107
-
108
55
  #endif /* NUMO_NARRAY_MH_FORMAT_H */
@@ -43,47 +43,4 @@
43
43
  return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt); \
44
44
  }
45
45
 
46
- #define DEF_NARRAY_BIT_FORMAT_TO_A_METHOD_FUNC() \
47
- static void iter_bit_format_to_a(na_loop_t* const lp) { \
48
- size_t n; \
49
- BIT_DIGIT* a1; \
50
- BIT_DIGIT x = 0; \
51
- size_t p1; \
52
- ssize_t s1; \
53
- size_t* idx1; \
54
- VALUE y; \
55
- VALUE fmt = lp->option; \
56
- volatile VALUE a; \
57
- \
58
- INIT_COUNTER(lp, n); \
59
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
60
- \
61
- a = rb_ary_new2(n); \
62
- rb_ary_push(lp->args[1].value, a); \
63
- if (idx1) { \
64
- for (size_t i = 0; i < n; i++) { \
65
- LOAD_BIT(a1, p1 + *idx1, x); \
66
- idx1++; \
67
- y = format_bit(fmt, x); \
68
- rb_ary_push(a, y); \
69
- } \
70
- } else { \
71
- for (size_t i = 0; i < n; i++) { \
72
- LOAD_BIT(a1, p1, x); \
73
- p1 += s1; \
74
- y = format_bit(fmt, x); \
75
- rb_ary_push(a, y); \
76
- } \
77
- } \
78
- } \
79
- \
80
- static VALUE bit_format_to_a(int argc, VALUE* argv, VALUE self) { \
81
- VALUE fmt = Qnil; \
82
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } }; \
83
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; \
84
- ndfunc_t ndf = { iter_bit_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout }; \
85
- rb_scan_args(argc, argv, "01", &fmt); \
86
- return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt); \
87
- }
88
-
89
46
  #endif /* NUMO_NARRAY_MH_FORMAT_TO_A_H */
@@ -19,15 +19,4 @@
19
19
  return na_ndloop_inspect(ary, iter_robject_inspect, Qnil); \
20
20
  }
21
21
 
22
- #define DEF_NARRAY_BIT_INSPECT_METHOD_FUNC() \
23
- static VALUE iter_bit_inspect(char* ptr, size_t pos, VALUE fmt) { \
24
- BIT_DIGIT x; \
25
- LOAD_BIT(ptr, pos, x); \
26
- return format_bit(fmt, x); \
27
- } \
28
- \
29
- static VALUE bit_inspect(VALUE ary) { \
30
- return na_ndloop_inspect(ary, iter_bit_inspect, Qnil); \
31
- }
32
-
33
22
  #endif /* NUMO_NARRAY_MH_INSPECT_H */
@@ -66,30 +66,4 @@
66
66
  return rb_funcall(v, rb_intern("extract"), 0); \
67
67
  }
68
68
 
69
- #define DEF_NARRAY_BIT_MEAN_METHOD_FUNC() \
70
- static void iter_bit_mean(na_loop_t* const lp) { \
71
- size_t n; \
72
- BIT_DIGIT* p1; \
73
- size_t ps1; \
74
- ssize_t s1; \
75
- size_t* idx1; \
76
- char* p2; \
77
- \
78
- INIT_COUNTER(lp, n); \
79
- INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1); \
80
- p2 = NDL_PTR(lp, 1); \
81
- \
82
- *(double*)p2 = f_mean(n, p1, ps1, s1, idx1); \
83
- } \
84
- \
85
- static VALUE bit_mean(int argc, VALUE* argv, VALUE self) { \
86
- ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } }; \
87
- ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
88
- ndfunc_t ndf = { iter_bit_mean, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout }; \
89
- VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
90
- VALUE v = na_ndloop(&ndf, 2, self, reduce); \
91
- \
92
- return rb_funcall(v, rb_intern("extract"), 0); \
93
- }
94
-
95
69
  #endif // NUMO_NARRAY_MH_MEAN_H
@@ -66,30 +66,4 @@
66
66
  return rb_funcall(v, rb_intern("extract"), 0); \
67
67
  }
68
68
 
69
- #define DEF_NARRAY_BIT_RMS_METHOD_FUNC() \
70
- static void iter_bit_rms(na_loop_t* const lp) { \
71
- size_t n; \
72
- BIT_DIGIT* p1; \
73
- size_t ps1; \
74
- ssize_t s1; \
75
- size_t* idx1; \
76
- char* p2; \
77
- \
78
- INIT_COUNTER(lp, n); \
79
- INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1); \
80
- p2 = NDL_PTR(lp, 1); \
81
- \
82
- *(double*)p2 = f_rms(n, p1, ps1, s1, idx1); \
83
- } \
84
- \
85
- static VALUE bit_rms(int argc, VALUE* argv, VALUE self) { \
86
- ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } }; \
87
- ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
88
- ndfunc_t ndf = { iter_bit_rms, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout }; \
89
- VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
90
- VALUE v = na_ndloop(&ndf, 2, self, reduce); \
91
- \
92
- return rb_funcall(v, rb_intern("extract"), 0); \
93
- }
94
-
95
69
  #endif // NUMO_NARRAY_MH_RMS_H
@@ -67,30 +67,4 @@
67
67
  return rb_funcall(v, rb_intern("extract"), 0); \
68
68
  }
69
69
 
70
- #define DEF_NARRAY_BIT_STDDEV_METHOD_FUNC() \
71
- static void iter_bit_stddev(na_loop_t* const lp) { \
72
- size_t n; \
73
- BIT_DIGIT* p1; \
74
- size_t ps1; \
75
- ssize_t s1; \
76
- size_t* idx1; \
77
- char* p2; \
78
- \
79
- INIT_COUNTER(lp, n); \
80
- INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1); \
81
- p2 = NDL_PTR(lp, 1); \
82
- \
83
- *(double*)p2 = f_stddev(n, p1, ps1, s1, idx1); \
84
- } \
85
- \
86
- static VALUE bit_stddev(int argc, VALUE* argv, VALUE self) { \
87
- ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } }; \
88
- ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
89
- ndfunc_t ndf = { iter_bit_stddev, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout }; \
90
- VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
91
- VALUE v = na_ndloop(&ndf, 2, self, reduce); \
92
- \
93
- return rb_funcall(v, rb_intern("extract"), 0); \
94
- }
95
-
96
70
  #endif // NUMO_NARRAY_MH_STDDEV_H
@@ -36,43 +36,4 @@
36
36
  return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil); \
37
37
  }
38
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
39
  #endif /* NUMO_NARRAY_MH_TO_A_H */
@@ -66,30 +66,4 @@
66
66
  return rb_funcall(v, rb_intern("extract"), 0); \
67
67
  }
68
68
 
69
- #define DEF_NARRAY_BIT_VAR_METHOD_FUNC() \
70
- static void iter_bit_var(na_loop_t* const lp) { \
71
- size_t n; \
72
- BIT_DIGIT* p1; \
73
- size_t ps1; \
74
- ssize_t s1; \
75
- size_t* idx1; \
76
- char* p2; \
77
- \
78
- INIT_COUNTER(lp, n); \
79
- INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1); \
80
- p2 = NDL_PTR(lp, 1); \
81
- \
82
- *(double*)p2 = f_var(n, p1, ps1, s1, idx1); \
83
- } \
84
- \
85
- static VALUE bit_var(int argc, VALUE* argv, VALUE self) { \
86
- ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } }; \
87
- ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } }; \
88
- ndfunc_t ndf = { iter_bit_var, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout }; \
89
- VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
90
- VALUE v = na_ndloop(&ndf, 2, self, reduce); \
91
- \
92
- return rb_funcall(v, rb_intern("extract"), 0); \
93
- }
94
-
95
69
  #endif // NUMO_NARRAY_MH_VAR_H
@@ -31,35 +31,413 @@ static ID id_to_a;
31
31
  VALUE cT;
32
32
  extern VALUE cRT;
33
33
 
34
- #include "mh/extract.h"
35
- #include "mh/aref.h"
36
- #include "mh/coerce_cast.h"
37
- #include "mh/to_a.h"
38
- #include "mh/fill.h"
39
- #include "mh/format.h"
40
- #include "mh/format_to_a.h"
41
- #include "mh/inspect.h"
42
- #include "mh/each.h"
43
- #include "mh/each_with_index.h"
44
- #include "mh/mean.h"
45
- #include "mh/var.h"
46
- #include "mh/stddev.h"
47
- #include "mh/rms.h"
48
-
49
- DEF_NARRAY_BIT_EXTRACT_METHOD_FUNC()
50
- DEF_NARRAY_BIT_AREF_METHOD_FUNC()
51
- DEF_NARRAY_COERCE_CAST_METHOD_FUNC(bit)
52
- DEF_NARRAY_BIT_TO_A_METHOD_FUNC()
53
- DEF_NARRAY_BIT_FILL_METHOD_FUNC()
54
- DEF_NARRAY_BIT_FORMAT_METHOD_FUNC()
55
- DEF_NARRAY_BIT_FORMAT_TO_A_METHOD_FUNC()
56
- DEF_NARRAY_BIT_INSPECT_METHOD_FUNC()
57
- DEF_NARRAY_BIT_EACH_METHOD_FUNC()
58
- DEF_NARRAY_BIT_EACH_WITH_INDEX_METHOD_FUNC()
59
- DEF_NARRAY_BIT_MEAN_METHOD_FUNC()
60
- DEF_NARRAY_BIT_VAR_METHOD_FUNC()
61
- DEF_NARRAY_BIT_STDDEV_METHOD_FUNC()
62
- DEF_NARRAY_BIT_RMS_METHOD_FUNC()
34
+ static VALUE bit_extract(VALUE self) {
35
+ BIT_DIGIT* ptr;
36
+ BIT_DIGIT val;
37
+ size_t pos;
38
+ narray_t* na;
39
+ GetNArray(self, na);
40
+ if (na->ndim == 0) {
41
+ pos = na_get_offset(self);
42
+ ptr = (BIT_DIGIT*)na_get_pointer_for_read(self);
43
+ val = ((*((ptr) + (pos) / NB)) >> ((pos) % NB)) & 1u;
44
+ na_release_lock(self);
45
+ return INT2FIX(val);
46
+ }
47
+ return self;
48
+ }
49
+
50
+ static VALUE bit_aref(int argc, VALUE* argv, VALUE self) {
51
+ size_t pos;
52
+ int nd = na_get_result_dimension(self, argc, argv, 1, &pos);
53
+ if (nd) {
54
+ return na_aref_main(argc, argv, self, 0, nd);
55
+ }
56
+ char* ptr = na_get_pointer_for_read(self);
57
+ BIT_DIGIT x;
58
+ LOAD_BIT(ptr, pos, x);
59
+ return m_data_to_num(x);
60
+ }
61
+
62
+ static VALUE bit_coerce_cast(VALUE self, VALUE type) {
63
+ return Qnil;
64
+ }
65
+
66
+ static void iter_bit_to_a(na_loop_t* const lp) {
67
+ size_t n;
68
+ BIT_DIGIT* a1;
69
+ size_t p1;
70
+ ssize_t s1;
71
+ size_t* idx1;
72
+ BIT_DIGIT x = 0;
73
+ VALUE a;
74
+ VALUE y;
75
+
76
+ INIT_COUNTER(lp, n);
77
+ INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
78
+ a = rb_ary_new2(n);
79
+ rb_ary_push(lp->args[1].value, a);
80
+ if (idx1) {
81
+ for (size_t i = 0; i < n; i++) {
82
+ LOAD_BIT(a1, p1 + *idx1, x);
83
+ idx1++;
84
+ y = m_data_to_num(x);
85
+ rb_ary_push(a, y);
86
+ }
87
+ } else {
88
+ for (size_t i = 0; i < n; i++) {
89
+ LOAD_BIT(a1, p1, x);
90
+ p1 += s1;
91
+ y = m_data_to_num(x);
92
+ rb_ary_push(a, y);
93
+ }
94
+ }
95
+ }
96
+
97
+ static VALUE bit_to_a(VALUE self) {
98
+ ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
99
+ ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } };
100
+ ndfunc_t ndf = { iter_bit_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
101
+ return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
102
+ }
103
+
104
+ static void iter_bit_fill(na_loop_t* const lp) {
105
+ size_t n;
106
+ size_t p3;
107
+ ssize_t s3;
108
+ size_t* idx3;
109
+ int len;
110
+ BIT_DIGIT* a3;
111
+ BIT_DIGIT y;
112
+ VALUE x = lp->option;
113
+
114
+ if (x == INT2FIX(0) || x == Qfalse) {
115
+ y = 0;
116
+ } else if (x == INT2FIX(1) || x == Qtrue) {
117
+ y = ~(BIT_DIGIT)0;
118
+ } else {
119
+ rb_raise(rb_eArgError, "invalid value for Bit");
120
+ }
121
+
122
+ INIT_COUNTER(lp, n);
123
+ INIT_PTR_BIT_IDX(lp, 0, a3, p3, s3, idx3);
124
+ if (idx3) {
125
+ y = y & 1;
126
+ for (size_t i = 0; i < n; i++) {
127
+ STORE_BIT(a3, p3 + *idx3, y);
128
+ idx3++;
129
+ }
130
+ } else if (s3 != 1) {
131
+ y = y & 1;
132
+ for (size_t i = 0; i < n; i++) {
133
+ STORE_BIT(a3, p3, y);
134
+ p3 += s3;
135
+ }
136
+ } else {
137
+ if (p3 > 0 || n < NB) {
138
+ len = (int)(NB - p3);
139
+ if ((int)n < len) {
140
+ len = (int)n;
141
+ }
142
+ *a3 = (y & (SLB(len) << p3)) | (*a3 & ~(SLB(len) << p3));
143
+ a3++;
144
+ n -= len;
145
+ }
146
+ for (; n >= NB; n -= NB) {
147
+ *(a3++) = y;
148
+ }
149
+ if (n > 0) {
150
+ *a3 = (y & SLB(n)) | (*a3 & BALL << n);
151
+ }
152
+ }
153
+ }
154
+
155
+ static VALUE bit_fill(VALUE self, VALUE val) {
156
+ ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
157
+ ndfunc_t ndf = { iter_bit_fill, FULL_LOOP, 2, 0, ain, 0 };
158
+ na_ndloop(&ndf, 2, self, val);
159
+ return self;
160
+ }
161
+
162
+ static VALUE format_bit(VALUE fmt, BIT_DIGIT x) {
163
+ if (NIL_P(fmt)) {
164
+ char s[4];
165
+ int n;
166
+ n = m_sprintf(s, x);
167
+ return rb_str_new(s, n);
168
+ }
169
+ return rb_funcall(fmt, '%', 1, m_data_to_num(x));
170
+ }
171
+
172
+ static void iter_bit_format(na_loop_t* const lp) {
173
+ size_t n;
174
+ BIT_DIGIT* a1;
175
+ BIT_DIGIT x = 0;
176
+ size_t p1;
177
+ char* p2;
178
+ ssize_t s1;
179
+ ssize_t s2;
180
+ size_t* idx1;
181
+ VALUE y;
182
+ VALUE fmt = lp->option;
183
+
184
+ INIT_COUNTER(lp, n);
185
+ INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
186
+ INIT_PTR(lp, 1, p2, s2);
187
+
188
+ if (idx1) {
189
+ for (size_t i = 0; i < n; i++) {
190
+ LOAD_BIT(a1, p1 + *idx1, x);
191
+ idx1++;
192
+ y = format_bit(fmt, x);
193
+ SET_DATA_STRIDE(p2, s2, VALUE, y);
194
+ }
195
+ } else {
196
+ for (size_t i = 0; i < n; i++) {
197
+ LOAD_BIT(a1, p1, x);
198
+ p1 += s1;
199
+ y = format_bit(fmt, x);
200
+ SET_DATA_STRIDE(p2, s2, VALUE, y);
201
+ }
202
+ }
203
+ }
204
+
205
+ static VALUE bit_format(int argc, VALUE* argv, VALUE self) {
206
+ VALUE fmt = Qnil;
207
+ ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
208
+ ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
209
+ ndfunc_t ndf = { iter_bit_format, FULL_LOOP_NIP, 2, 1, ain, aout };
210
+ rb_scan_args(argc, argv, "01", &fmt);
211
+ return na_ndloop(&ndf, 2, self, fmt);
212
+ }
213
+
214
+ static void iter_bit_format_to_a(na_loop_t* const lp) {
215
+ size_t n;
216
+ BIT_DIGIT* a1;
217
+ BIT_DIGIT x = 0;
218
+ size_t p1;
219
+ ssize_t s1;
220
+ size_t* idx1;
221
+ VALUE y;
222
+ VALUE fmt = lp->option;
223
+ volatile VALUE a;
224
+
225
+ INIT_COUNTER(lp, n);
226
+ INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
227
+
228
+ a = rb_ary_new2(n);
229
+ rb_ary_push(lp->args[1].value, a);
230
+ if (idx1) {
231
+ for (size_t i = 0; i < n; i++) {
232
+ LOAD_BIT(a1, p1 + *idx1, x);
233
+ idx1++;
234
+ y = format_bit(fmt, x);
235
+ rb_ary_push(a, y);
236
+ }
237
+ } else {
238
+ for (size_t i = 0; i < n; i++) {
239
+ LOAD_BIT(a1, p1, x);
240
+ p1 += s1;
241
+ y = format_bit(fmt, x);
242
+ rb_ary_push(a, y);
243
+ }
244
+ }
245
+ }
246
+
247
+ static VALUE bit_format_to_a(int argc, VALUE* argv, VALUE self) {
248
+ VALUE fmt = Qnil;
249
+ ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
250
+ ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } };
251
+ ndfunc_t ndf = { iter_bit_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
252
+ rb_scan_args(argc, argv, "01", &fmt);
253
+ return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
254
+ }
255
+
256
+ static VALUE iter_bit_inspect(char* ptr, size_t pos, VALUE fmt) {
257
+ BIT_DIGIT x;
258
+ LOAD_BIT(ptr, pos, x);
259
+ return format_bit(fmt, x);
260
+ }
261
+
262
+ static VALUE bit_inspect(VALUE ary) {
263
+ return na_ndloop_inspect(ary, iter_bit_inspect, Qnil);
264
+ }
265
+
266
+ static void iter_bit_each(na_loop_t* const lp) {
267
+ size_t n;
268
+ BIT_DIGIT* a1;
269
+ size_t p1;
270
+ ssize_t s1;
271
+ size_t* idx1;
272
+ INIT_COUNTER(lp, n);
273
+ INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
274
+ BIT_DIGIT x = 0;
275
+ VALUE y;
276
+ if (idx1) {
277
+ for (size_t i = 0; i < n; i++) {
278
+ LOAD_BIT(a1, p1 + *idx1, x);
279
+ idx1++;
280
+ y = m_data_to_num(x);
281
+ rb_yield(y);
282
+ }
283
+ } else {
284
+ for (size_t i = 0; i < n; i++) {
285
+ LOAD_BIT(a1, p1, x);
286
+ p1 += s1;
287
+ y = m_data_to_num(x);
288
+ rb_yield(y);
289
+ }
290
+ }
291
+ }
292
+
293
+ static VALUE bit_each(VALUE self) {
294
+ ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
295
+ ndfunc_t ndf = { iter_bit_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
296
+ na_ndloop(&ndf, 1, self);
297
+ return self;
298
+ }
299
+
300
+ static inline void yield_each_with_index(BIT_DIGIT x, size_t* c, VALUE* a, int nd, int md) {
301
+ a[0] = m_data_to_num(x);
302
+ for (int j = 0; j <= nd; j++) {
303
+ a[j + 1] = SIZET2NUM(c[j]);
304
+ }
305
+ rb_yield(rb_ary_new4(md, a));
306
+ }
307
+
308
+ static void iter_bit_each_with_index(na_loop_t* const lp) {
309
+ size_t* c = (size_t*)(lp->opt_ptr);
310
+ int nd = lp->ndim - 1;
311
+ int md = lp->ndim + 1;
312
+ VALUE* a = ALLOCA_N(VALUE, md);
313
+ size_t n;
314
+ BIT_DIGIT* a1;
315
+ size_t p1;
316
+ ssize_t s1;
317
+ size_t* idx1;
318
+ INIT_COUNTER(lp, n);
319
+ INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
320
+ BIT_DIGIT x = 0;
321
+ c[nd] = 0;
322
+ if (idx1) {
323
+ for (size_t i = 0; i < n; i++) {
324
+ LOAD_BIT(a1, p1 + *idx1, x);
325
+ idx1++;
326
+ yield_each_with_index(x, c, a, nd, md);
327
+ c[nd]++;
328
+ }
329
+ } else {
330
+ for (size_t i = 0; i < n; i++) {
331
+ LOAD_BIT(a1, p1, x);
332
+ p1 += s1;
333
+ yield_each_with_index(x, c, a, nd, md);
334
+ c[nd]++;
335
+ }
336
+ }
337
+ }
338
+
339
+ static VALUE bit_each_with_index(VALUE self) {
340
+ ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
341
+ ndfunc_t ndf = { iter_bit_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
342
+ na_ndloop_with_index(&ndf, 1, self);
343
+ return self;
344
+ }
345
+
346
+ static void iter_bit_mean(na_loop_t* const lp) {
347
+ size_t n;
348
+ BIT_DIGIT* p1;
349
+ size_t ps1;
350
+ ssize_t s1;
351
+ size_t* idx1;
352
+ char* p2;
353
+
354
+ INIT_COUNTER(lp, n);
355
+ INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1);
356
+ p2 = NDL_PTR(lp, 1);
357
+
358
+ *(double*)p2 = f_mean(n, p1, ps1, s1, idx1);
359
+ }
360
+
361
+ static VALUE bit_mean(int argc, VALUE* argv, VALUE self) {
362
+ ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
363
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
364
+ ndfunc_t ndf = { iter_bit_mean, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
365
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
366
+ VALUE v = na_ndloop(&ndf, 2, self, reduce);
367
+ return rb_funcall(v, rb_intern("extract"), 0);
368
+ }
369
+
370
+ static void iter_bit_var(na_loop_t* const lp) {
371
+ size_t n;
372
+ BIT_DIGIT* p1;
373
+ size_t ps1;
374
+ ssize_t s1;
375
+ size_t* idx1;
376
+ char* p2;
377
+
378
+ INIT_COUNTER(lp, n);
379
+ INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1);
380
+ p2 = NDL_PTR(lp, 1);
381
+
382
+ *(double*)p2 = f_var(n, p1, ps1, s1, idx1);
383
+ }
384
+
385
+ static VALUE bit_var(int argc, VALUE* argv, VALUE self) {
386
+ ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
387
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
388
+ ndfunc_t ndf = { iter_bit_var, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
389
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
390
+ VALUE v = na_ndloop(&ndf, 2, self, reduce);
391
+ return rb_funcall(v, rb_intern("extract"), 0);
392
+ }
393
+
394
+ static void iter_bit_stddev(na_loop_t* const lp) {
395
+ size_t n;
396
+ BIT_DIGIT* p1;
397
+ size_t ps1;
398
+ ssize_t s1;
399
+ size_t* idx1;
400
+ char* p2;
401
+
402
+ INIT_COUNTER(lp, n);
403
+ INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1);
404
+ p2 = NDL_PTR(lp, 1);
405
+
406
+ *(double*)p2 = f_stddev(n, p1, ps1, s1, idx1);
407
+ }
408
+
409
+ static VALUE bit_stddev(int argc, VALUE* argv, VALUE self) {
410
+ ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
411
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
412
+ ndfunc_t ndf = { iter_bit_stddev, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
413
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
414
+ VALUE v = na_ndloop(&ndf, 2, self, reduce);
415
+ return rb_funcall(v, rb_intern("extract"), 0);
416
+ }
417
+
418
+ static void iter_bit_rms(na_loop_t* const lp) {
419
+ size_t n;
420
+ BIT_DIGIT* p1;
421
+ size_t ps1;
422
+ ssize_t s1;
423
+ size_t* idx1;
424
+ char* p2;
425
+
426
+ INIT_COUNTER(lp, n);
427
+ INIT_PTR_BIT_IDX(lp, 0, p1, ps1, s1, idx1);
428
+ p2 = NDL_PTR(lp, 1);
429
+
430
+ *(double*)p2 = f_rms(n, p1, ps1, s1, idx1);
431
+ }
432
+
433
+ static VALUE bit_rms(int argc, VALUE* argv, VALUE self) {
434
+ ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
435
+ ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
436
+ ndfunc_t ndf = { iter_bit_rms, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
437
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
438
+ VALUE v = na_ndloop(&ndf, 2, self, reduce);
439
+ return rb_funcall(v, rb_intern("extract"), 0);
440
+ }
63
441
 
64
442
  static VALUE bit_store(VALUE, VALUE);
65
443
 
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.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
@@ -214,7 +214,7 @@ licenses:
214
214
  metadata:
215
215
  homepage_uri: https://github.com/yoshoku/numo-narray-alt
216
216
  changelog_uri: https://github.com/yoshoku/numo-narray-alt/blob/main/CHANGELOG.md
217
- documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.10.3/
217
+ documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.10.4/
218
218
  rubygems_mfa_required: 'true'
219
219
  post_install_message: |
220
220
  ===
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  - !ruby/object:Gem::Version
239
239
  version: '0'
240
240
  requirements: []
241
- rubygems_version: 4.0.3
241
+ rubygems_version: 4.0.6
242
242
  specification_version: 4
243
243
  summary: Numo::NArray Alternative is a project forked from Numo::NArray.
244
244
  test_files: []