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.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/LICENSE +1 -1
- data/README.md +7 -0
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/numo/types/robj_macro.h +1 -1
- data/ext/numo/narray/numo/types/robject.h +1 -1
- data/ext/numo/narray/src/mh/argmax.h +154 -0
- data/ext/numo/narray/src/mh/argmin.h +154 -0
- data/ext/numo/narray/src/mh/bincount.h +233 -0
- data/ext/numo/narray/src/mh/bit/and.h +225 -0
- data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/not.h +173 -0
- data/ext/numo/narray/src/mh/bit/or.h +225 -0
- data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
- data/ext/numo/narray/src/mh/bit/xor.h +225 -0
- data/ext/numo/narray/src/mh/clip.h +115 -0
- data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
- data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
- data/ext/numo/narray/src/mh/comp/eq.h +26 -0
- data/ext/numo/narray/src/mh/comp/ge.h +26 -0
- data/ext/numo/narray/src/mh/comp/gt.h +26 -0
- data/ext/numo/narray/src/mh/comp/le.h +26 -0
- data/ext/numo/narray/src/mh/comp/lt.h +26 -0
- data/ext/numo/narray/src/mh/comp/ne.h +26 -0
- data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
- data/ext/numo/narray/src/mh/cumprod.h +98 -0
- data/ext/numo/narray/src/mh/cumsum.h +98 -0
- data/ext/numo/narray/src/mh/divmod.h +142 -0
- data/ext/numo/narray/src/mh/eye.h +82 -0
- data/ext/numo/narray/src/mh/fill.h +94 -0
- data/ext/numo/narray/src/mh/format.h +108 -0
- data/ext/numo/narray/src/mh/format_to_a.h +89 -0
- data/ext/numo/narray/src/mh/inspect.h +33 -0
- data/ext/numo/narray/src/mh/isfinite.h +42 -0
- data/ext/numo/narray/src/mh/isinf.h +42 -0
- data/ext/numo/narray/src/mh/isnan.h +42 -0
- data/ext/numo/narray/src/mh/isneginf.h +42 -0
- data/ext/numo/narray/src/mh/isposinf.h +42 -0
- data/ext/numo/narray/src/mh/logseq.h +69 -0
- data/ext/numo/narray/src/mh/math/acos.h +2 -2
- data/ext/numo/narray/src/mh/math/acosh.h +2 -2
- data/ext/numo/narray/src/mh/math/asin.h +2 -2
- data/ext/numo/narray/src/mh/math/asinh.h +2 -2
- data/ext/numo/narray/src/mh/math/atan.h +2 -2
- data/ext/numo/narray/src/mh/math/atan2.h +3 -3
- data/ext/numo/narray/src/mh/math/atanh.h +2 -2
- data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
- data/ext/numo/narray/src/mh/math/cos.h +2 -2
- data/ext/numo/narray/src/mh/math/cosh.h +2 -2
- data/ext/numo/narray/src/mh/math/erf.h +2 -2
- data/ext/numo/narray/src/mh/math/erfc.h +2 -2
- data/ext/numo/narray/src/mh/math/exp.h +2 -2
- data/ext/numo/narray/src/mh/math/exp10.h +2 -2
- data/ext/numo/narray/src/mh/math/exp2.h +2 -2
- data/ext/numo/narray/src/mh/math/expm1.h +2 -2
- data/ext/numo/narray/src/mh/math/frexp.h +3 -3
- data/ext/numo/narray/src/mh/math/hypot.h +3 -3
- data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
- data/ext/numo/narray/src/mh/math/log.h +2 -2
- data/ext/numo/narray/src/mh/math/log10.h +2 -2
- data/ext/numo/narray/src/mh/math/log1p.h +2 -2
- data/ext/numo/narray/src/mh/math/log2.h +2 -2
- data/ext/numo/narray/src/mh/math/sin.h +2 -2
- data/ext/numo/narray/src/mh/math/sinc.h +2 -2
- data/ext/numo/narray/src/mh/math/sinh.h +2 -2
- data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
- data/ext/numo/narray/src/mh/math/tan.h +2 -2
- data/ext/numo/narray/src/mh/math/tanh.h +2 -2
- data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
- data/ext/numo/narray/src/mh/max.h +69 -0
- data/ext/numo/narray/src/mh/max_index.h +184 -0
- data/ext/numo/narray/src/mh/maximum.h +116 -0
- data/ext/numo/narray/src/mh/min.h +69 -0
- data/ext/numo/narray/src/mh/min_index.h +184 -0
- data/ext/numo/narray/src/mh/minimum.h +116 -0
- data/ext/numo/narray/src/mh/minmax.h +77 -0
- data/ext/numo/narray/src/mh/mulsum.h +185 -0
- data/ext/numo/narray/src/mh/op/add.h +78 -0
- data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
- data/ext/numo/narray/src/mh/op/div.h +118 -0
- data/ext/numo/narray/src/mh/op/mod.h +108 -0
- data/ext/numo/narray/src/mh/op/mul.h +78 -0
- data/ext/numo/narray/src/mh/op/sub.h +78 -0
- data/ext/numo/narray/src/mh/prod.h +69 -0
- data/ext/numo/narray/src/mh/ptp.h +69 -0
- data/ext/numo/narray/src/mh/rand.h +315 -0
- data/ext/numo/narray/src/mh/round/ceil.h +11 -0
- data/ext/numo/narray/src/mh/round/floor.h +11 -0
- data/ext/numo/narray/src/mh/round/rint.h +9 -0
- data/ext/numo/narray/src/mh/round/round.h +11 -0
- data/ext/numo/narray/src/mh/round/trunc.h +11 -0
- data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
- data/ext/numo/narray/src/mh/seq.h +130 -0
- data/ext/numo/narray/src/mh/sum.h +69 -0
- data/ext/numo/narray/src/mh/to_a.h +78 -0
- data/ext/numo/narray/src/t_bit.c +45 -234
- data/ext/numo/narray/src/t_dcomplex.c +608 -2369
- data/ext/numo/narray/src/t_dfloat.c +485 -3736
- data/ext/numo/narray/src/t_int16.c +743 -3444
- data/ext/numo/narray/src/t_int32.c +745 -3445
- data/ext/numo/narray/src/t_int64.c +743 -3446
- data/ext/numo/narray/src/t_int8.c +678 -3040
- data/ext/numo/narray/src/t_robject.c +771 -3548
- data/ext/numo/narray/src/t_scomplex.c +607 -2368
- data/ext/numo/narray/src/t_sfloat.c +440 -3693
- data/ext/numo/narray/src/t_uint16.c +743 -3440
- data/ext/numo/narray/src/t_uint32.c +743 -3440
- data/ext/numo/narray/src/t_uint64.c +743 -3442
- data/ext/numo/narray/src/t_uint8.c +678 -3038
- data/lib/numo/narray.rb +2 -3
- metadata +62 -3
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_RAND_H
|
|
2
|
+
#define NUMO_NARRAY_MH_RAND_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_CMP_RAND_METHOD_FUNC(tDType) \
|
|
5
|
+
typedef struct { \
|
|
6
|
+
tDType low; \
|
|
7
|
+
tDType max; \
|
|
8
|
+
} rand_opt_t; \
|
|
9
|
+
\
|
|
10
|
+
static void iter_##tDType##_rand(na_loop_t* const lp) { \
|
|
11
|
+
size_t n; \
|
|
12
|
+
char* p1; \
|
|
13
|
+
ssize_t s1; \
|
|
14
|
+
size_t* idx1; \
|
|
15
|
+
tDType x; \
|
|
16
|
+
rand_opt_t* g; \
|
|
17
|
+
tDType low; \
|
|
18
|
+
tDType max; \
|
|
19
|
+
\
|
|
20
|
+
INIT_COUNTER(lp, n); \
|
|
21
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
22
|
+
g = (rand_opt_t*)(lp->opt_ptr); \
|
|
23
|
+
low = g->low; \
|
|
24
|
+
max = g->max; \
|
|
25
|
+
\
|
|
26
|
+
if (idx1) { \
|
|
27
|
+
for (size_t i = 0; i < n; i++) { \
|
|
28
|
+
x = m_add(m_rand(max), low); \
|
|
29
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
30
|
+
} \
|
|
31
|
+
} else { \
|
|
32
|
+
for (size_t i = 0; i < n; i++) { \
|
|
33
|
+
x = m_add(m_rand(max), low); \
|
|
34
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
35
|
+
} \
|
|
36
|
+
} \
|
|
37
|
+
} \
|
|
38
|
+
\
|
|
39
|
+
static VALUE tDType##_rand(int argc, VALUE* argv, VALUE self) { \
|
|
40
|
+
rand_opt_t g; \
|
|
41
|
+
VALUE v1 = Qnil; \
|
|
42
|
+
VALUE v2 = Qnil; \
|
|
43
|
+
tDType high; \
|
|
44
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
|
|
45
|
+
ndfunc_t ndf = { iter_##tDType##_rand, FULL_LOOP, 1, 0, ain, 0 }; \
|
|
46
|
+
\
|
|
47
|
+
rb_scan_args(argc, argv, "02", &v1, &v2); \
|
|
48
|
+
if (v2 == Qnil) { \
|
|
49
|
+
g.low = m_zero; \
|
|
50
|
+
if (v1 == Qnil) { \
|
|
51
|
+
g.max = high = c_new(1, 1); \
|
|
52
|
+
} else { \
|
|
53
|
+
g.max = high = m_num_to_data(v1); \
|
|
54
|
+
} \
|
|
55
|
+
} else { \
|
|
56
|
+
g.low = m_num_to_data(v1); \
|
|
57
|
+
high = m_num_to_data(v2); \
|
|
58
|
+
g.max = m_sub(high, g.low); \
|
|
59
|
+
} \
|
|
60
|
+
\
|
|
61
|
+
na_ndloop3(&ndf, &g, 1, self); \
|
|
62
|
+
return self; \
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#define DEF_NARRAY_FLT_RAND_METHOD_FUNC(tDType) \
|
|
66
|
+
typedef struct { \
|
|
67
|
+
tDType low; \
|
|
68
|
+
tDType max; \
|
|
69
|
+
} rand_opt_t; \
|
|
70
|
+
\
|
|
71
|
+
static void iter_##tDType##_rand(na_loop_t* const lp) { \
|
|
72
|
+
size_t n; \
|
|
73
|
+
char* p1; \
|
|
74
|
+
ssize_t s1; \
|
|
75
|
+
size_t* idx1; \
|
|
76
|
+
tDType x; \
|
|
77
|
+
rand_opt_t* g; \
|
|
78
|
+
tDType low; \
|
|
79
|
+
tDType max; \
|
|
80
|
+
\
|
|
81
|
+
INIT_COUNTER(lp, n); \
|
|
82
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
83
|
+
g = (rand_opt_t*)(lp->opt_ptr); \
|
|
84
|
+
low = g->low; \
|
|
85
|
+
max = g->max; \
|
|
86
|
+
\
|
|
87
|
+
if (idx1) { \
|
|
88
|
+
for (size_t i = 0; i < n; i++) { \
|
|
89
|
+
x = m_add(m_rand(max), low); \
|
|
90
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
91
|
+
} \
|
|
92
|
+
} else { \
|
|
93
|
+
for (size_t i = 0; i < n; i++) { \
|
|
94
|
+
x = m_add(m_rand(max), low); \
|
|
95
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
96
|
+
} \
|
|
97
|
+
} \
|
|
98
|
+
} \
|
|
99
|
+
\
|
|
100
|
+
static VALUE tDType##_rand(int argc, VALUE* args, VALUE self) { \
|
|
101
|
+
rand_opt_t g; \
|
|
102
|
+
VALUE v1 = Qnil; \
|
|
103
|
+
VALUE v2 = Qnil; \
|
|
104
|
+
tDType high; \
|
|
105
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
|
|
106
|
+
ndfunc_t ndf = { iter_##tDType##_rand, FULL_LOOP, 1, 0, ain, 0 }; \
|
|
107
|
+
\
|
|
108
|
+
rb_scan_args(argc, args, "02", &v1, &v2); \
|
|
109
|
+
if (v2 == Qnil) { \
|
|
110
|
+
g.low = m_zero; \
|
|
111
|
+
if (v1 == Qnil) { \
|
|
112
|
+
g.max = high = m_one; \
|
|
113
|
+
} else { \
|
|
114
|
+
g.max = high = m_num_to_data(v1); \
|
|
115
|
+
} \
|
|
116
|
+
} else { \
|
|
117
|
+
g.low = m_num_to_data(v1); \
|
|
118
|
+
high = m_num_to_data(v2); \
|
|
119
|
+
g.max = m_sub(high, g.low); \
|
|
120
|
+
} \
|
|
121
|
+
\
|
|
122
|
+
na_ndloop3(&ndf, &g, 1, self); \
|
|
123
|
+
return self; \
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#define DEF_NARRAY_INT_RAND_METHOD_FUNC(tDType) \
|
|
127
|
+
static int msb_pos(uint32_t a) { \
|
|
128
|
+
const int hwid = 4 * sizeof(tDType); \
|
|
129
|
+
int width = hwid; \
|
|
130
|
+
int pos = 0; \
|
|
131
|
+
uint32_t mask = (((tDType)1 << hwid) - 1) << hwid; \
|
|
132
|
+
\
|
|
133
|
+
if (a == 0) { \
|
|
134
|
+
return -1; \
|
|
135
|
+
} \
|
|
136
|
+
\
|
|
137
|
+
while (width) { \
|
|
138
|
+
if (a & mask) { \
|
|
139
|
+
pos += width; \
|
|
140
|
+
} else { \
|
|
141
|
+
mask >>= width; \
|
|
142
|
+
} \
|
|
143
|
+
width >>= 1; \
|
|
144
|
+
mask &= mask << width; \
|
|
145
|
+
} \
|
|
146
|
+
return pos; \
|
|
147
|
+
} \
|
|
148
|
+
\
|
|
149
|
+
inline static tDType m_rand(uint32_t max, int shift) { \
|
|
150
|
+
uint32_t x; \
|
|
151
|
+
do { \
|
|
152
|
+
x = gen_rand32(); \
|
|
153
|
+
x >>= shift; \
|
|
154
|
+
} while (x >= max); \
|
|
155
|
+
return x; \
|
|
156
|
+
} \
|
|
157
|
+
\
|
|
158
|
+
typedef struct { \
|
|
159
|
+
tDType low; \
|
|
160
|
+
uint32_t max; \
|
|
161
|
+
} rand_opt_t; \
|
|
162
|
+
\
|
|
163
|
+
static void iter_##tDType##_rand(na_loop_t* const lp) { \
|
|
164
|
+
size_t n; \
|
|
165
|
+
char* p1; \
|
|
166
|
+
ssize_t s1; \
|
|
167
|
+
size_t* idx1; \
|
|
168
|
+
tDType x; \
|
|
169
|
+
rand_opt_t* g; \
|
|
170
|
+
tDType low; \
|
|
171
|
+
uint32_t max; \
|
|
172
|
+
int shift; \
|
|
173
|
+
\
|
|
174
|
+
INIT_COUNTER(lp, n); \
|
|
175
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
176
|
+
g = (rand_opt_t*)(lp->opt_ptr); \
|
|
177
|
+
low = g->low; \
|
|
178
|
+
max = g->max; \
|
|
179
|
+
shift = 31 - msb_pos(max); \
|
|
180
|
+
\
|
|
181
|
+
if (idx1) { \
|
|
182
|
+
for (size_t i = 0; i < n; i++) { \
|
|
183
|
+
x = m_add(m_rand(max, shift), low); \
|
|
184
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
185
|
+
} \
|
|
186
|
+
} else { \
|
|
187
|
+
for (size_t i = 0; i < n; i++) { \
|
|
188
|
+
x = m_add(m_rand(max, shift), low); \
|
|
189
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
190
|
+
} \
|
|
191
|
+
} \
|
|
192
|
+
} \
|
|
193
|
+
\
|
|
194
|
+
static VALUE tDType##_rand(int argc, VALUE* argv, VALUE self) { \
|
|
195
|
+
rand_opt_t g; \
|
|
196
|
+
VALUE v1 = Qnil; \
|
|
197
|
+
VALUE v2 = Qnil; \
|
|
198
|
+
tDType high; \
|
|
199
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
|
|
200
|
+
ndfunc_t ndf = { iter_##tDType##_rand, FULL_LOOP, 1, 0, ain, 0 }; \
|
|
201
|
+
\
|
|
202
|
+
rb_scan_args(argc, argv, "11", &v1, &v2); \
|
|
203
|
+
if (v2 == Qnil) { \
|
|
204
|
+
g.low = m_zero; \
|
|
205
|
+
g.max = high = m_num_to_data(v1); \
|
|
206
|
+
} else { \
|
|
207
|
+
g.low = m_num_to_data(v1); \
|
|
208
|
+
high = m_num_to_data(v2); \
|
|
209
|
+
g.max = m_sub(high, g.low); \
|
|
210
|
+
} \
|
|
211
|
+
\
|
|
212
|
+
if (high <= g.low) { \
|
|
213
|
+
rb_raise(rb_eArgError, "high must be larger than low"); \
|
|
214
|
+
} \
|
|
215
|
+
\
|
|
216
|
+
na_ndloop3(&ndf, &g, 1, self); \
|
|
217
|
+
return self; \
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
#define DEF_NARRAY_INT64_RAND_METHOD_FUNC(tDType) \
|
|
221
|
+
static int msb_pos(uint64_t a) { \
|
|
222
|
+
const int hwid = 4 * sizeof(tDType); \
|
|
223
|
+
int width = hwid; \
|
|
224
|
+
int pos = 0; \
|
|
225
|
+
uint64_t mask = (((tDType)1 << hwid) - 1) << hwid; \
|
|
226
|
+
\
|
|
227
|
+
if (a == 0) { \
|
|
228
|
+
return -1; \
|
|
229
|
+
} \
|
|
230
|
+
\
|
|
231
|
+
while (width) { \
|
|
232
|
+
if (a & mask) { \
|
|
233
|
+
pos += width; \
|
|
234
|
+
} else { \
|
|
235
|
+
mask >>= width; \
|
|
236
|
+
} \
|
|
237
|
+
width >>= 1; \
|
|
238
|
+
mask &= mask << width; \
|
|
239
|
+
} \
|
|
240
|
+
return pos; \
|
|
241
|
+
} \
|
|
242
|
+
\
|
|
243
|
+
inline static tDType m_rand(uint64_t max, int shift) { \
|
|
244
|
+
uint64_t x; \
|
|
245
|
+
do { \
|
|
246
|
+
x = gen_rand32(); \
|
|
247
|
+
x = (x << 32) | gen_rand32(); \
|
|
248
|
+
x >>= shift; \
|
|
249
|
+
} while (x >= max); \
|
|
250
|
+
return x; \
|
|
251
|
+
} \
|
|
252
|
+
\
|
|
253
|
+
typedef struct { \
|
|
254
|
+
tDType low; \
|
|
255
|
+
uint64_t max; \
|
|
256
|
+
} rand_opt_t; \
|
|
257
|
+
\
|
|
258
|
+
static void iter_##tDType##_rand(na_loop_t* const lp) { \
|
|
259
|
+
size_t n; \
|
|
260
|
+
char* p1; \
|
|
261
|
+
ssize_t s1; \
|
|
262
|
+
size_t* idx1; \
|
|
263
|
+
tDType x; \
|
|
264
|
+
rand_opt_t* g; \
|
|
265
|
+
tDType low; \
|
|
266
|
+
uint64_t max; \
|
|
267
|
+
int shift; \
|
|
268
|
+
\
|
|
269
|
+
INIT_COUNTER(lp, n); \
|
|
270
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
271
|
+
g = (rand_opt_t*)(lp->opt_ptr); \
|
|
272
|
+
low = g->low; \
|
|
273
|
+
max = g->max; \
|
|
274
|
+
shift = 63 - msb_pos(max); \
|
|
275
|
+
\
|
|
276
|
+
if (idx1) { \
|
|
277
|
+
for (size_t i = 0; i < n; i++) { \
|
|
278
|
+
x = m_add(m_rand(max, shift), low); \
|
|
279
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
280
|
+
} \
|
|
281
|
+
} else { \
|
|
282
|
+
for (size_t i = 0; i < n; i++) { \
|
|
283
|
+
x = m_add(m_rand(max, shift), low); \
|
|
284
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
285
|
+
} \
|
|
286
|
+
} \
|
|
287
|
+
} \
|
|
288
|
+
\
|
|
289
|
+
static VALUE tDType##_rand(int argc, VALUE* argv, VALUE self) { \
|
|
290
|
+
rand_opt_t g; \
|
|
291
|
+
VALUE v1 = Qnil; \
|
|
292
|
+
VALUE v2 = Qnil; \
|
|
293
|
+
tDType high; \
|
|
294
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
|
|
295
|
+
ndfunc_t ndf = { iter_##tDType##_rand, FULL_LOOP, 1, 0, ain, 0 }; \
|
|
296
|
+
\
|
|
297
|
+
rb_scan_args(argc, argv, "11", &v1, &v2); \
|
|
298
|
+
if (v2 == Qnil) { \
|
|
299
|
+
g.low = m_zero; \
|
|
300
|
+
g.max = high = m_num_to_data(v1); \
|
|
301
|
+
} else { \
|
|
302
|
+
g.low = m_num_to_data(v1); \
|
|
303
|
+
high = m_num_to_data(v2); \
|
|
304
|
+
g.max = m_sub(high, g.low); \
|
|
305
|
+
} \
|
|
306
|
+
\
|
|
307
|
+
if (high <= g.low) { \
|
|
308
|
+
rb_raise(rb_eArgError, "high must be larger than low"); \
|
|
309
|
+
} \
|
|
310
|
+
\
|
|
311
|
+
na_ndloop3(&ndf, &g, 1, self); \
|
|
312
|
+
return self; \
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
#endif /* NUMO_NARRAY_MH_RAND_H */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_ROUND_CEIL_H
|
|
2
|
+
#define NUMO_NARRAY_MH_ROUND_CEIL_H 1
|
|
3
|
+
|
|
4
|
+
#include "unary_func.h"
|
|
5
|
+
|
|
6
|
+
#define DEF_NARRAY_FLT_CEIL_METHOD_FUNC(tDType, tNAryClass) \
|
|
7
|
+
DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(ceil, tDType, tNAryClass)
|
|
8
|
+
|
|
9
|
+
#define DEF_NARRAY_ROBJ_CEIL_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(ceil)
|
|
10
|
+
|
|
11
|
+
#endif /* NUMO_NARRAY_MH_ROUND_CEIL_H */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_ROUND_FLOOR_H
|
|
2
|
+
#define NUMO_NARRAY_MH_ROUND_FLOOR_H 1
|
|
3
|
+
|
|
4
|
+
#include "unary_func.h"
|
|
5
|
+
|
|
6
|
+
#define DEF_NARRAY_FLT_FLOOR_METHOD_FUNC(tDType, tNAryClass) \
|
|
7
|
+
DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(floor, tDType, tNAryClass)
|
|
8
|
+
|
|
9
|
+
#define DEF_NARRAY_ROBJ_FLOOR_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(floor)
|
|
10
|
+
|
|
11
|
+
#endif /* NUMO_NARRAY_MH_ROUND_FLOOR_H */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_ROUND_RINT_H
|
|
2
|
+
#define NUMO_NARRAY_MH_ROUND_RINT_H 1
|
|
3
|
+
|
|
4
|
+
#include "unary_func.h"
|
|
5
|
+
|
|
6
|
+
#define DEF_NARRAY_FLT_RINT_METHOD_FUNC(tDType, tNAryClass) \
|
|
7
|
+
DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(rint, tDType, tNAryClass)
|
|
8
|
+
|
|
9
|
+
#endif /* NUMO_NARRAY_MH_ROUND_RINT_H */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_ROUND_ROUND_H
|
|
2
|
+
#define NUMO_NARRAY_MH_ROUND_ROUND_H 1
|
|
3
|
+
|
|
4
|
+
#include "unary_func.h"
|
|
5
|
+
|
|
6
|
+
#define DEF_NARRAY_FLT_ROUND_METHOD_FUNC(tDType, tNAryClass) \
|
|
7
|
+
DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(round, tDType, tNAryClass)
|
|
8
|
+
|
|
9
|
+
#define DEF_NARRAY_ROBJ_ROUND_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(round)
|
|
10
|
+
|
|
11
|
+
#endif /* NUMO_NARRAY_MH_ROUND_ROUND_H */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_ROUND_TRUNC_H
|
|
2
|
+
#define NUMO_NARRAY_MH_ROUND_TRUNC_H 1
|
|
3
|
+
|
|
4
|
+
#include "unary_func.h"
|
|
5
|
+
|
|
6
|
+
#define DEF_NARRAY_FLT_TRUNC_METHOD_FUNC(tDType, tNAryClass) \
|
|
7
|
+
DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(trunc, tDType, tNAryClass)
|
|
8
|
+
|
|
9
|
+
#define DEF_NARRAY_ROBJ_TRUNC_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(trunc)
|
|
10
|
+
|
|
11
|
+
#endif /* NUMO_NARRAY_MH_ROUND_TRUNC_H */
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_ROUND_UNARY_FUNC_H
|
|
2
|
+
#define NUMO_NARRAY_MH_ROUND_UNARY_FUNC_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(fRoundFunc, tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_##fRoundFunc(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
ssize_t s1; \
|
|
10
|
+
ssize_t s2; \
|
|
11
|
+
size_t* idx1; \
|
|
12
|
+
size_t* idx2; \
|
|
13
|
+
tDType x; \
|
|
14
|
+
\
|
|
15
|
+
INIT_COUNTER(lp, n); \
|
|
16
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
17
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
18
|
+
\
|
|
19
|
+
if (idx1) { \
|
|
20
|
+
if (idx2) { \
|
|
21
|
+
for (size_t i = 0; i < n; i++) { \
|
|
22
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
23
|
+
x = m_##fRoundFunc(x); \
|
|
24
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
25
|
+
} \
|
|
26
|
+
} else { \
|
|
27
|
+
for (size_t i = 0; i < n; i++) { \
|
|
28
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
29
|
+
x = m_##fRoundFunc(x); \
|
|
30
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
31
|
+
} \
|
|
32
|
+
} \
|
|
33
|
+
} else { \
|
|
34
|
+
if (idx2) { \
|
|
35
|
+
for (size_t i = 0; i < n; i++) { \
|
|
36
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
37
|
+
x = m_##fRoundFunc(x); \
|
|
38
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
39
|
+
} \
|
|
40
|
+
} else { \
|
|
41
|
+
if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType))) { \
|
|
42
|
+
if (s1 == sizeof(tDType) && s2 == sizeof(tDType)) { \
|
|
43
|
+
for (size_t i = 0; i < n; i++) { \
|
|
44
|
+
((tDType*)p2)[i] = m_##fRoundFunc(((tDType*)p1)[i]); \
|
|
45
|
+
} \
|
|
46
|
+
return; \
|
|
47
|
+
} \
|
|
48
|
+
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType))) { \
|
|
49
|
+
for (size_t i = 0; i < n; i++) { \
|
|
50
|
+
*(tDType*)p2 = m_##fRoundFunc(*(tDType*)p1); \
|
|
51
|
+
p1 += s1; \
|
|
52
|
+
p2 += s2; \
|
|
53
|
+
} \
|
|
54
|
+
return; \
|
|
55
|
+
} \
|
|
56
|
+
} \
|
|
57
|
+
for (size_t i = 0; i < n; i++) { \
|
|
58
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
59
|
+
x = m_##fRoundFunc(x); \
|
|
60
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
61
|
+
} \
|
|
62
|
+
} \
|
|
63
|
+
} \
|
|
64
|
+
} \
|
|
65
|
+
\
|
|
66
|
+
static VALUE tDType##_##fRoundFunc(VALUE self) { \
|
|
67
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
68
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
69
|
+
ndfunc_t ndf = { iter_##tDType##_##fRoundFunc, FULL_LOOP, 1, 1, ain, aout }; \
|
|
70
|
+
return na_ndloop(&ndf, 1, self); \
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#define DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(fRoundFunc) \
|
|
74
|
+
static void iter_robject_##fRoundFunc(na_loop_t* const lp) { \
|
|
75
|
+
size_t n; \
|
|
76
|
+
char* p1; \
|
|
77
|
+
char* p2; \
|
|
78
|
+
ssize_t s1; \
|
|
79
|
+
ssize_t s2; \
|
|
80
|
+
size_t* idx1; \
|
|
81
|
+
size_t* idx2; \
|
|
82
|
+
robject x; \
|
|
83
|
+
\
|
|
84
|
+
INIT_COUNTER(lp, n); \
|
|
85
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
86
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
87
|
+
\
|
|
88
|
+
if (idx1) { \
|
|
89
|
+
if (idx2) { \
|
|
90
|
+
for (size_t i = 0; i < n; i++) { \
|
|
91
|
+
GET_DATA_INDEX(p1, idx1, robject, x); \
|
|
92
|
+
x = m_##fRoundFunc(x); \
|
|
93
|
+
SET_DATA_INDEX(p2, idx2, robject, x); \
|
|
94
|
+
} \
|
|
95
|
+
} else { \
|
|
96
|
+
for (size_t i = 0; i < n; i++) { \
|
|
97
|
+
GET_DATA_INDEX(p1, idx1, robject, x); \
|
|
98
|
+
x = m_##fRoundFunc(x); \
|
|
99
|
+
SET_DATA_STRIDE(p2, s2, robject, x); \
|
|
100
|
+
} \
|
|
101
|
+
} \
|
|
102
|
+
} else { \
|
|
103
|
+
if (idx2) { \
|
|
104
|
+
for (size_t i = 0; i < n; i++) { \
|
|
105
|
+
GET_DATA_STRIDE(p1, s1, robject, x); \
|
|
106
|
+
x = m_##fRoundFunc(x); \
|
|
107
|
+
SET_DATA_INDEX(p2, idx2, robject, x); \
|
|
108
|
+
} \
|
|
109
|
+
} else { \
|
|
110
|
+
for (size_t i = 0; i < n; i++) { \
|
|
111
|
+
*(robject*)p2 = m_##fRoundFunc(*(robject*)p1); \
|
|
112
|
+
p1 += s1; \
|
|
113
|
+
p2 += s2; \
|
|
114
|
+
} \
|
|
115
|
+
return; \
|
|
116
|
+
} \
|
|
117
|
+
} \
|
|
118
|
+
} \
|
|
119
|
+
\
|
|
120
|
+
static VALUE robject_##fRoundFunc(VALUE self) { \
|
|
121
|
+
ndfunc_arg_in_t ain[1] = { { numo_cRObject, 0 } }; \
|
|
122
|
+
ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } }; \
|
|
123
|
+
ndfunc_t ndf = { iter_robject_##fRoundFunc, FULL_LOOP, 1, 1, ain, aout }; \
|
|
124
|
+
return na_ndloop(&ndf, 1, self); \
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#endif /* NUMO_NARRAY_MH_ROUND_UNARY_FUNC_H */
|