numo-narray-alt 0.9.9 → 0.9.11

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/ext/numo/narray/numo/narray.h +2 -2
  4. data/ext/numo/narray/numo/types/robject.h +1 -1
  5. data/ext/numo/narray/src/mh/argmax.h +154 -0
  6. data/ext/numo/narray/src/mh/argmin.h +154 -0
  7. data/ext/numo/narray/src/mh/clip.h +115 -0
  8. data/ext/numo/narray/src/mh/cumprod.h +98 -0
  9. data/ext/numo/narray/src/mh/cumsum.h +98 -0
  10. data/ext/numo/narray/src/mh/eye.h +82 -0
  11. data/ext/numo/narray/src/mh/logseq.h +69 -0
  12. data/ext/numo/narray/src/mh/max.h +69 -0
  13. data/ext/numo/narray/src/mh/max_index.h +184 -0
  14. data/ext/numo/narray/src/mh/maximum.h +116 -0
  15. data/ext/numo/narray/src/mh/min.h +69 -0
  16. data/ext/numo/narray/src/mh/min_index.h +184 -0
  17. data/ext/numo/narray/src/mh/minimum.h +116 -0
  18. data/ext/numo/narray/src/mh/minmax.h +77 -0
  19. data/ext/numo/narray/src/mh/mulsum.h +185 -0
  20. data/ext/numo/narray/src/mh/prod.h +69 -0
  21. data/ext/numo/narray/src/mh/ptp.h +69 -0
  22. data/ext/numo/narray/src/mh/rand.h +315 -0
  23. data/ext/numo/narray/src/mh/seq.h +130 -0
  24. data/ext/numo/narray/src/mh/sum.h +69 -0
  25. data/ext/numo/narray/src/t_dcomplex.c +131 -667
  26. data/ext/numo/narray/src/t_dfloat.c +40 -1288
  27. data/ext/numo/narray/src/t_int16.c +262 -1161
  28. data/ext/numo/narray/src/t_int32.c +263 -1161
  29. data/ext/numo/narray/src/t_int64.c +262 -1163
  30. data/ext/numo/narray/src/t_int8.c +262 -1159
  31. data/ext/numo/narray/src/t_robject.c +427 -1675
  32. data/ext/numo/narray/src/t_scomplex.c +131 -667
  33. data/ext/numo/narray/src/t_sfloat.c +40 -1288
  34. data/ext/numo/narray/src/t_uint16.c +262 -1161
  35. data/ext/numo/narray/src/t_uint32.c +262 -1161
  36. data/ext/numo/narray/src/t_uint64.c +262 -1163
  37. data/ext/numo/narray/src/t_uint8.c +262 -1161
  38. data/lib/numo/narray.rb +3 -1
  39. metadata +23 -3
@@ -0,0 +1,185 @@
1
+ #ifndef NUMO_NARRAY_MH_MULSUM_H
2
+ #define NUMO_NARRAY_MH_MULSUM_H 1
3
+
4
+ #define DEF_NARRAY_FLT_MULSUM_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_mulsum(na_loop_t* const lp) { \
6
+ size_t n; \
7
+ char* p1; \
8
+ char* p2; \
9
+ char* p3; \
10
+ ssize_t s1; \
11
+ ssize_t s2; \
12
+ ssize_t s3; \
13
+ \
14
+ INIT_COUNTER(lp, n); \
15
+ INIT_PTR(lp, 0, p1, s1); \
16
+ INIT_PTR(lp, 1, p2, s2); \
17
+ INIT_PTR(lp, 2, p3, s3); \
18
+ \
19
+ if (s3 == 0) { \
20
+ tDType z; \
21
+ GET_DATA(p3, tDType, z); \
22
+ for (size_t i = 0; i < n; i++) { \
23
+ tDType x; \
24
+ tDType y; \
25
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
26
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
27
+ m_mulsum(x, y, z); \
28
+ } \
29
+ SET_DATA(p3, tDType, z); \
30
+ } else { \
31
+ for (size_t i = 0; i < n; i++) { \
32
+ tDType x; \
33
+ tDType y; \
34
+ tDType z; \
35
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
36
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
37
+ GET_DATA(p3, tDType, z); \
38
+ m_mulsum(x, y, z); \
39
+ SET_DATA_STRIDE(p3, s3, tDType, z); \
40
+ } \
41
+ } \
42
+ } \
43
+ \
44
+ static void iter_##tDType##_mulsum_nan(na_loop_t* const lp) { \
45
+ size_t n; \
46
+ char* p1; \
47
+ char* p2; \
48
+ char* p3; \
49
+ ssize_t s1; \
50
+ ssize_t s2; \
51
+ ssize_t s3; \
52
+ \
53
+ INIT_COUNTER(lp, n); \
54
+ INIT_PTR(lp, 0, p1, s1); \
55
+ INIT_PTR(lp, 1, p2, s2); \
56
+ INIT_PTR(lp, 2, p3, s3); \
57
+ \
58
+ if (s3 == 0) { \
59
+ tDType z; \
60
+ GET_DATA(p3, tDType, z); \
61
+ for (size_t i = 0; i < n; i++) { \
62
+ tDType x; \
63
+ tDType y; \
64
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
65
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
66
+ m_mulsum_nan(x, y, z); \
67
+ } \
68
+ SET_DATA(p3, tDType, z); \
69
+ } else { \
70
+ for (size_t i = 0; i < n; i++) { \
71
+ tDType x; \
72
+ tDType y; \
73
+ tDType z; \
74
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
75
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
76
+ GET_DATA(p3, tDType, z); \
77
+ m_mulsum_nan(x, y, z); \
78
+ SET_DATA_STRIDE(p3, s3, tDType, z); \
79
+ } \
80
+ } \
81
+ } \
82
+ \
83
+ static VALUE tDType##_mulsum_self(int argc, VALUE* argv, VALUE self) { \
84
+ if (argc < 1) { \
85
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc); \
86
+ } \
87
+ \
88
+ ndfunc_arg_in_t ain[4] = { \
89
+ { tNAryClass, 0 }, { tNAryClass, 0 }, { sym_reduce, 0 }, { sym_init, 0 } \
90
+ }; \
91
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
92
+ ndfunc_t ndf = { iter_##tDType##_mulsum, STRIDE_LOOP_NIP, 4, 1, ain, aout }; \
93
+ VALUE naryv[2] = { self, argv[0] }; \
94
+ VALUE reduce = \
95
+ na_reduce_dimension(argc - 1, argv + 1, 2, naryv, &ndf, iter_##tDType##_mulsum_nan); \
96
+ VALUE v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_mulsum_init); \
97
+ \
98
+ return rb_funcall(v, rb_intern("extract"), 0); \
99
+ } \
100
+ \
101
+ static VALUE tDType##_mulsum(int argc, VALUE* argv, VALUE self) { \
102
+ if (argc < 1) { \
103
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc); \
104
+ } \
105
+ \
106
+ VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(argv[0])); \
107
+ if (klass == tNAryClass) { \
108
+ return tDType##_mulsum_self(argc, argv, self); \
109
+ } \
110
+ \
111
+ VALUE v = rb_funcall(klass, id_cast, 1, self); \
112
+ \
113
+ return rb_funcallv_kw(v, rb_intern("mulsum"), argc, argv, RB_PASS_CALLED_KEYWORDS); \
114
+ }
115
+
116
+ #define DEF_NARRAY_INT_MULSUM_METHOD_FUNC(tDType, tNAryClass) \
117
+ static void iter_##tDType##_mulsum(na_loop_t* const lp) { \
118
+ size_t n; \
119
+ char* p1; \
120
+ char* p2; \
121
+ char* p3; \
122
+ ssize_t s1; \
123
+ ssize_t s2; \
124
+ ssize_t s3; \
125
+ \
126
+ INIT_COUNTER(lp, n); \
127
+ INIT_PTR(lp, 0, p1, s1); \
128
+ INIT_PTR(lp, 1, p2, s2); \
129
+ INIT_PTR(lp, 2, p3, s3); \
130
+ \
131
+ if (s3 == 0) { \
132
+ tDType z; \
133
+ GET_DATA(p3, tDType, z); \
134
+ for (size_t i = 0; i < n; i++) { \
135
+ tDType x, y; \
136
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
137
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
138
+ m_mulsum(x, y, z); \
139
+ } \
140
+ SET_DATA(p3, tDType, z); \
141
+ } else { \
142
+ for (size_t i = 0; i < n; i++) { \
143
+ tDType x, y, z; \
144
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
145
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
146
+ GET_DATA(p3, tDType, z); \
147
+ m_mulsum(x, y, z); \
148
+ SET_DATA_STRIDE(p3, s3, tDType, z); \
149
+ } \
150
+ } \
151
+ } \
152
+ \
153
+ static VALUE tDType##_mulsum_self(int argc, VALUE* argv, VALUE self) { \
154
+ if (argc < 1) { \
155
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc); \
156
+ } \
157
+ \
158
+ ndfunc_arg_in_t ain[4] = { \
159
+ { tNAryClass, 0 }, { tNAryClass, 0 }, { sym_reduce, 0 }, { sym_init, 0 } \
160
+ }; \
161
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
162
+ ndfunc_t ndf = { iter_##tDType##_mulsum, STRIDE_LOOP_NIP, 4, 1, ain, aout }; \
163
+ VALUE naryv[2] = { self, argv[0] }; \
164
+ VALUE reduce = na_reduce_dimension(argc - 1, argv + 1, 2, naryv, &ndf, 0); \
165
+ VALUE v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_mulsum_init); \
166
+ \
167
+ return rb_funcall(v, rb_intern("extract"), 0); \
168
+ } \
169
+ \
170
+ static VALUE tDType##_mulsum(int argc, VALUE* argv, VALUE self) { \
171
+ if (argc < 1) { \
172
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc); \
173
+ } \
174
+ \
175
+ VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(argv[0])); \
176
+ if (klass == tNAryClass) { \
177
+ return tDType##_mulsum_self(argc, argv, self); \
178
+ } \
179
+ \
180
+ VALUE v = rb_funcall(klass, id_cast, 1, self); \
181
+ \
182
+ return rb_funcallv_kw(v, rb_intern("mulsum"), argc, argv, RB_PASS_CALLED_KEYWORDS); \
183
+ }
184
+
185
+ #endif /* NUMO_NARRAY_MH_MULSUM_H */
@@ -0,0 +1,69 @@
1
+ #ifndef NUMO_NARRAY_MH_PROD_H
2
+ #define NUMO_NARRAY_MH_PROD_H 1
3
+
4
+ #define DEF_NARRAY_FLT_PROD_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_prod(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_prod(n, p1, s1); \
16
+ } \
17
+ \
18
+ static void iter_##tDType##_prod_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_prod_nan(n, p1, s1); \
29
+ } \
30
+ \
31
+ static VALUE tDType##_prod(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##_prod, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
36
+ }; \
37
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_prod_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_PROD_METHOD_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass) \
44
+ static void iter_##tDType##_prod(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_prod(n, p1, s1); \
55
+ } \
56
+ \
57
+ static VALUE tDType##_prod(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##_prod, 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_PROD_H */
@@ -0,0 +1,69 @@
1
+ #ifndef NUMO_NARRAY_MH_PTP_H
2
+ #define NUMO_NARRAY_MH_PTP_H 1
3
+
4
+ #define DEF_NARRAY_FLT_PTP_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_ptp(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_ptp(n, p1, s1); \
16
+ } \
17
+ \
18
+ static void iter_##tDType##_ptp_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_ptp_nan(n, p1, s1); \
29
+ } \
30
+ \
31
+ static VALUE tDType##_ptp(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##_ptp, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
36
+ }; \
37
+ VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_ptp_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_PTP_METHOD_FUNC(tDType, tNAryClass) \
44
+ static void iter_##tDType##_ptp(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
+ *(tDType*)p2 = f_ptp(n, p1, s1); \
55
+ } \
56
+ \
57
+ static VALUE tDType##_ptp(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] = { { tNAryClass, 0 } }; \
60
+ ndfunc_t ndf = { \
61
+ iter_##tDType##_ptp, 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_PTP_H */