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,98 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_CUMPROD_H
|
|
2
|
+
#define NUMO_NARRAY_MH_CUMPROD_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_CUMPROD_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_cumprod(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
ssize_t s1; \
|
|
10
|
+
ssize_t s2; \
|
|
11
|
+
tDType x; \
|
|
12
|
+
tDType y; \
|
|
13
|
+
\
|
|
14
|
+
INIT_COUNTER(lp, n); \
|
|
15
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
16
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
17
|
+
\
|
|
18
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
19
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
20
|
+
for (size_t i = 0; i < n - 1; i++) { \
|
|
21
|
+
GET_DATA_STRIDE(p1, s1, tDType, y); \
|
|
22
|
+
m_cumprod(x, y); \
|
|
23
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
24
|
+
} \
|
|
25
|
+
} \
|
|
26
|
+
\
|
|
27
|
+
static void iter_##tDType##_cumprod_nan(na_loop_t* const lp) { \
|
|
28
|
+
size_t n; \
|
|
29
|
+
char* p1; \
|
|
30
|
+
char* p2; \
|
|
31
|
+
ssize_t s1; \
|
|
32
|
+
ssize_t s2; \
|
|
33
|
+
tDType x; \
|
|
34
|
+
tDType y; \
|
|
35
|
+
\
|
|
36
|
+
INIT_COUNTER(lp, n); \
|
|
37
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
38
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
39
|
+
\
|
|
40
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
41
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
42
|
+
for (size_t i = 0; i < n - 1; i++) { \
|
|
43
|
+
GET_DATA_STRIDE(p1, s1, tDType, y); \
|
|
44
|
+
m_cumprod_nan(x, y); \
|
|
45
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
46
|
+
} \
|
|
47
|
+
} \
|
|
48
|
+
\
|
|
49
|
+
static VALUE tDType##_cumprod(int argc, VALUE* argv, VALUE self) { \
|
|
50
|
+
VALUE reduce; \
|
|
51
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
52
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
53
|
+
ndfunc_t ndf = { \
|
|
54
|
+
iter_##tDType##_cumprod, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout \
|
|
55
|
+
}; \
|
|
56
|
+
\
|
|
57
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_cumprod_nan); \
|
|
58
|
+
\
|
|
59
|
+
return na_ndloop(&ndf, 2, self, reduce); \
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#define DEF_NARRAY_INT_CUMPROD_METHOD_FUNC(tDType, tNAryClass) \
|
|
63
|
+
static void iter_##tDType##_cumprod(na_loop_t* const lp) { \
|
|
64
|
+
size_t n; \
|
|
65
|
+
char* p1; \
|
|
66
|
+
char* p2; \
|
|
67
|
+
ssize_t s1; \
|
|
68
|
+
ssize_t s2; \
|
|
69
|
+
tDType x; \
|
|
70
|
+
tDType y; \
|
|
71
|
+
\
|
|
72
|
+
INIT_COUNTER(lp, n); \
|
|
73
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
74
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
75
|
+
\
|
|
76
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
77
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
78
|
+
for (size_t i = 0; i < n - 1; i++) { \
|
|
79
|
+
GET_DATA_STRIDE(p1, s1, tDType, y); \
|
|
80
|
+
m_cumprod(x, y); \
|
|
81
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
82
|
+
} \
|
|
83
|
+
} \
|
|
84
|
+
\
|
|
85
|
+
static VALUE tDType##_cumprod(int argc, VALUE* argv, VALUE self) { \
|
|
86
|
+
VALUE reduce; \
|
|
87
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
88
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
89
|
+
ndfunc_t ndf = { \
|
|
90
|
+
iter_##tDType##_cumprod, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout \
|
|
91
|
+
}; \
|
|
92
|
+
\
|
|
93
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
|
|
94
|
+
\
|
|
95
|
+
return na_ndloop(&ndf, 2, self, reduce); \
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#endif /* NUMO_NARRAY_MH_CUMPROD_H */
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_CUMSUM_H
|
|
2
|
+
#define NUMO_NARRAY_MH_CUMSUM_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_CUMSUM_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_cumsum(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
ssize_t s1; \
|
|
10
|
+
ssize_t s2; \
|
|
11
|
+
tDType x; \
|
|
12
|
+
tDType y; \
|
|
13
|
+
\
|
|
14
|
+
INIT_COUNTER(lp, n); \
|
|
15
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
16
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
17
|
+
\
|
|
18
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
19
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
20
|
+
for (size_t i = 0; i < n - 1; i++) { \
|
|
21
|
+
GET_DATA_STRIDE(p1, s1, tDType, y); \
|
|
22
|
+
m_cumsum(x, y); \
|
|
23
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
24
|
+
} \
|
|
25
|
+
} \
|
|
26
|
+
\
|
|
27
|
+
static void iter_##tDType##_cumsum_nan(na_loop_t* const lp) { \
|
|
28
|
+
size_t n; \
|
|
29
|
+
char* p1; \
|
|
30
|
+
char* p2; \
|
|
31
|
+
ssize_t s1; \
|
|
32
|
+
ssize_t s2; \
|
|
33
|
+
tDType x; \
|
|
34
|
+
tDType y; \
|
|
35
|
+
\
|
|
36
|
+
INIT_COUNTER(lp, n); \
|
|
37
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
38
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
39
|
+
\
|
|
40
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
41
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
42
|
+
for (size_t i = 0; i < n - 1; i++) { \
|
|
43
|
+
GET_DATA_STRIDE(p1, s1, tDType, y); \
|
|
44
|
+
m_cumsum_nan(x, y); \
|
|
45
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
46
|
+
} \
|
|
47
|
+
} \
|
|
48
|
+
\
|
|
49
|
+
static VALUE tDType##_cumsum(int argc, VALUE* argv, VALUE self) { \
|
|
50
|
+
VALUE reduce; \
|
|
51
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
52
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
53
|
+
ndfunc_t ndf = { \
|
|
54
|
+
iter_##tDType##_cumsum, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout \
|
|
55
|
+
}; \
|
|
56
|
+
\
|
|
57
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_cumsum_nan); \
|
|
58
|
+
\
|
|
59
|
+
return na_ndloop(&ndf, 2, self, reduce); \
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#define DEF_NARRAY_INT_CUMSUM_METHOD_FUNC(tDType, tNAryClass) \
|
|
63
|
+
static void iter_##tDType##_cumsum(na_loop_t* const lp) { \
|
|
64
|
+
size_t n; \
|
|
65
|
+
char* p1; \
|
|
66
|
+
char* p2; \
|
|
67
|
+
ssize_t s1; \
|
|
68
|
+
ssize_t s2; \
|
|
69
|
+
tDType x; \
|
|
70
|
+
tDType y; \
|
|
71
|
+
\
|
|
72
|
+
INIT_COUNTER(lp, n); \
|
|
73
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
74
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
75
|
+
\
|
|
76
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
77
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
78
|
+
for (size_t i = 0; i < n - 1; i++) { \
|
|
79
|
+
GET_DATA_STRIDE(p1, s1, tDType, y); \
|
|
80
|
+
m_cumsum(x, y); \
|
|
81
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
82
|
+
} \
|
|
83
|
+
} \
|
|
84
|
+
\
|
|
85
|
+
static VALUE tDType##_cumsum(int argc, VALUE* argv, VALUE self) { \
|
|
86
|
+
VALUE reduce; \
|
|
87
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
88
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
89
|
+
ndfunc_t ndf = { \
|
|
90
|
+
iter_##tDType##_cumsum, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout \
|
|
91
|
+
}; \
|
|
92
|
+
\
|
|
93
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
|
|
94
|
+
\
|
|
95
|
+
return na_ndloop(&ndf, 2, self, reduce); \
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#endif /* NUMO_NARRAY_MH_CUMSUM_H */
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_DIVMOD_H
|
|
2
|
+
#define NUMO_NARRAY_MH_DIVMOD_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_DIVMOD_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_divmod(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
char* p3; \
|
|
10
|
+
char* p4; \
|
|
11
|
+
ssize_t s1; \
|
|
12
|
+
ssize_t s2; \
|
|
13
|
+
ssize_t s3; \
|
|
14
|
+
ssize_t s4; \
|
|
15
|
+
INIT_COUNTER(lp, n); \
|
|
16
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
17
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
18
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
19
|
+
INIT_PTR(lp, 3, p4, s4); \
|
|
20
|
+
tDType x; \
|
|
21
|
+
tDType y; \
|
|
22
|
+
tDType a; \
|
|
23
|
+
tDType b; \
|
|
24
|
+
for (size_t i = 0; i < n; i++) { \
|
|
25
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
26
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
27
|
+
m_divmod(x, y, a, b); \
|
|
28
|
+
SET_DATA_STRIDE(p3, s3, tDType, a); \
|
|
29
|
+
SET_DATA_STRIDE(p4, s4, tDType, b); \
|
|
30
|
+
} \
|
|
31
|
+
} \
|
|
32
|
+
\
|
|
33
|
+
static VALUE tDType##_divmod_self(VALUE self, VALUE other) { \
|
|
34
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
35
|
+
ndfunc_arg_out_t aout[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
36
|
+
ndfunc_t ndf = { iter_##tDType##_divmod, STRIDE_LOOP, 2, 2, ain, aout }; \
|
|
37
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
38
|
+
} \
|
|
39
|
+
\
|
|
40
|
+
static VALUE tDType##_divmod(VALUE self, VALUE other) { \
|
|
41
|
+
VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
|
|
42
|
+
if (klass == tNAryClass) { \
|
|
43
|
+
return tDType##_divmod_self(self, other); \
|
|
44
|
+
} \
|
|
45
|
+
VALUE v = rb_funcall(klass, id_cast, 1, self); \
|
|
46
|
+
return rb_funcall(v, id_divmod, 1, other); \
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#define DEF_NARRAY_INT_DIVMOD_METHOD_FUNC(tDType, tNAryClass) \
|
|
50
|
+
static void iter_##tDType##_divmod(na_loop_t* const lp) { \
|
|
51
|
+
size_t n; \
|
|
52
|
+
char* p1; \
|
|
53
|
+
char* p2; \
|
|
54
|
+
char* p3; \
|
|
55
|
+
char* p4; \
|
|
56
|
+
ssize_t s1; \
|
|
57
|
+
ssize_t s2; \
|
|
58
|
+
ssize_t s3; \
|
|
59
|
+
ssize_t s4; \
|
|
60
|
+
INIT_COUNTER(lp, n); \
|
|
61
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
62
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
63
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
64
|
+
INIT_PTR(lp, 3, p4, s4); \
|
|
65
|
+
tDType x; \
|
|
66
|
+
tDType y; \
|
|
67
|
+
tDType a; \
|
|
68
|
+
tDType b; \
|
|
69
|
+
for (size_t i = 0; i < n; i++) { \
|
|
70
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
71
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
72
|
+
if (y == 0) { \
|
|
73
|
+
lp->err_type = rb_eZeroDivError; \
|
|
74
|
+
return; \
|
|
75
|
+
} \
|
|
76
|
+
m_divmod(x, y, a, b); \
|
|
77
|
+
SET_DATA_STRIDE(p3, s3, tDType, a); \
|
|
78
|
+
SET_DATA_STRIDE(p4, s4, tDType, b); \
|
|
79
|
+
} \
|
|
80
|
+
} \
|
|
81
|
+
\
|
|
82
|
+
static VALUE tDType##_divmod_self(VALUE self, VALUE other) { \
|
|
83
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
84
|
+
ndfunc_arg_out_t aout[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
85
|
+
ndfunc_t ndf = { iter_##tDType##_divmod, STRIDE_LOOP, 2, 2, ain, aout }; \
|
|
86
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
87
|
+
} \
|
|
88
|
+
\
|
|
89
|
+
static VALUE tDType##_divmod(VALUE self, VALUE other) { \
|
|
90
|
+
VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
|
|
91
|
+
if (klass == tNAryClass) { \
|
|
92
|
+
return tDType##_divmod_self(self, other); \
|
|
93
|
+
} \
|
|
94
|
+
VALUE v = rb_funcall(klass, id_cast, 1, self); \
|
|
95
|
+
return rb_funcall(v, id_divmod, 1, other); \
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#define DEF_NARRAY_ROBJ_DIVMOD_METHOD_FUNC() \
|
|
99
|
+
static void iter_robject_divmod(na_loop_t* const lp) { \
|
|
100
|
+
size_t n; \
|
|
101
|
+
char* p1; \
|
|
102
|
+
char* p2; \
|
|
103
|
+
char* p3; \
|
|
104
|
+
char* p4; \
|
|
105
|
+
ssize_t s1; \
|
|
106
|
+
ssize_t s2; \
|
|
107
|
+
ssize_t s3; \
|
|
108
|
+
ssize_t s4; \
|
|
109
|
+
INIT_COUNTER(lp, n); \
|
|
110
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
111
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
112
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
113
|
+
INIT_PTR(lp, 3, p4, s4); \
|
|
114
|
+
robject x; \
|
|
115
|
+
robject y; \
|
|
116
|
+
robject a; \
|
|
117
|
+
robject b; \
|
|
118
|
+
for (size_t i = 0; i < n; i++) { \
|
|
119
|
+
GET_DATA_STRIDE(p1, s1, robject, x); \
|
|
120
|
+
GET_DATA_STRIDE(p2, s2, robject, y); \
|
|
121
|
+
if (y == 0) { \
|
|
122
|
+
lp->err_type = rb_eZeroDivError; \
|
|
123
|
+
return; \
|
|
124
|
+
} \
|
|
125
|
+
m_divmod(x, y, a, b); \
|
|
126
|
+
SET_DATA_STRIDE(p3, s3, robject, a); \
|
|
127
|
+
SET_DATA_STRIDE(p4, s4, robject, b); \
|
|
128
|
+
} \
|
|
129
|
+
} \
|
|
130
|
+
\
|
|
131
|
+
static VALUE robject_divmod_self(VALUE self, VALUE other) { \
|
|
132
|
+
ndfunc_arg_in_t ain[2] = { { numo_cRObject, 0 }, { numo_cRObject, 0 } }; \
|
|
133
|
+
ndfunc_arg_out_t aout[2] = { { numo_cRObject, 0 }, { numo_cRObject, 0 } }; \
|
|
134
|
+
ndfunc_t ndf = { iter_robject_divmod, STRIDE_LOOP, 2, 2, ain, aout }; \
|
|
135
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
136
|
+
} \
|
|
137
|
+
\
|
|
138
|
+
static VALUE robject_divmod(VALUE self, VALUE other) { \
|
|
139
|
+
return robject_divmod_self(self, other); \
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#endif /* NUMO_NARRAY_MH_DIVMOD_H */
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_EYE_H
|
|
2
|
+
#define NUMO_NARRAY_MH_EYE_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_EYE_METHOD_FUNC(tDType) \
|
|
5
|
+
static void iter_##tDType##_eye(na_loop_t* const lp) { \
|
|
6
|
+
char* g = (char*)(lp->opt_ptr); \
|
|
7
|
+
ssize_t kofs = *(ssize_t*)g; \
|
|
8
|
+
tDType data = *(tDType*)(g + sizeof(ssize_t)); \
|
|
9
|
+
\
|
|
10
|
+
size_t n0 = lp->args[0].shape[0]; \
|
|
11
|
+
size_t n1 = lp->args[0].shape[1]; \
|
|
12
|
+
ssize_t s0 = lp->args[0].iter[0].step; \
|
|
13
|
+
ssize_t s1 = lp->args[0].iter[1].step; \
|
|
14
|
+
char* p0 = NDL_PTR(lp, 0); \
|
|
15
|
+
\
|
|
16
|
+
for (size_t i0 = 0; i0 < n0; i0++) { \
|
|
17
|
+
char* p1 = p0; \
|
|
18
|
+
for (size_t i1 = 0; i1 < n1; i1++) { \
|
|
19
|
+
*(tDType*)p1 = (i0 + kofs == i1) ? data : m_zero; \
|
|
20
|
+
p1 += s1; \
|
|
21
|
+
} \
|
|
22
|
+
p0 += s0; \
|
|
23
|
+
} \
|
|
24
|
+
} \
|
|
25
|
+
\
|
|
26
|
+
static VALUE tDType##_eye(int argc, VALUE* argv, VALUE self) { \
|
|
27
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } }; \
|
|
28
|
+
ndfunc_t ndf = { iter_##tDType##_eye, NO_LOOP, 1, 0, ain, 0 }; \
|
|
29
|
+
ssize_t kofs; \
|
|
30
|
+
tDType data; \
|
|
31
|
+
char* g; \
|
|
32
|
+
int nd; \
|
|
33
|
+
narray_t* na; \
|
|
34
|
+
\
|
|
35
|
+
if (argc > 2) { \
|
|
36
|
+
rb_raise(rb_eArgError, "too many arguments (%d for 0..2)", argc); \
|
|
37
|
+
} else if (argc == 2) { \
|
|
38
|
+
data = m_num_to_data(argv[0]); \
|
|
39
|
+
kofs = NUM2SSIZET(argv[1]); \
|
|
40
|
+
} else if (argc == 1) { \
|
|
41
|
+
data = m_num_to_data(argv[0]); \
|
|
42
|
+
kofs = 0; \
|
|
43
|
+
} else { \
|
|
44
|
+
data = m_one; \
|
|
45
|
+
kofs = 0; \
|
|
46
|
+
} \
|
|
47
|
+
\
|
|
48
|
+
GetNArray(self, na); \
|
|
49
|
+
nd = na->ndim; \
|
|
50
|
+
if (nd < 2) { \
|
|
51
|
+
rb_raise(nary_eDimensionError, "less than 2-d array"); \
|
|
52
|
+
} \
|
|
53
|
+
\
|
|
54
|
+
if (kofs >= 0) { \
|
|
55
|
+
if ((size_t)(kofs) >= na->shape[nd - 1]) { \
|
|
56
|
+
rb_raise( \
|
|
57
|
+
rb_eArgError, \
|
|
58
|
+
"invalid diagonal offset(%" SZF "d) for " \
|
|
59
|
+
"last dimension size(%" SZF "d)", \
|
|
60
|
+
kofs, na->shape[nd - 1] \
|
|
61
|
+
); \
|
|
62
|
+
} \
|
|
63
|
+
} else { \
|
|
64
|
+
if ((size_t)(-kofs) >= na->shape[nd - 2]) { \
|
|
65
|
+
rb_raise( \
|
|
66
|
+
rb_eArgError, \
|
|
67
|
+
"invalid diagonal offset(%" SZF "d) for " \
|
|
68
|
+
"last-1 dimension size(%" SZF "d)", \
|
|
69
|
+
kofs, na->shape[nd - 2] \
|
|
70
|
+
); \
|
|
71
|
+
} \
|
|
72
|
+
} \
|
|
73
|
+
\
|
|
74
|
+
g = ALLOCA_N(char, sizeof(ssize_t) + sizeof(tDType)); \
|
|
75
|
+
*(ssize_t*)g = kofs; \
|
|
76
|
+
*(tDType*)(g + sizeof(ssize_t)) = data; \
|
|
77
|
+
\
|
|
78
|
+
na_ndloop3(&ndf, g, 1, self); \
|
|
79
|
+
return self; \
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#endif /* NUMO_NARRAY_MH_EYE_H */
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_FILL_H
|
|
2
|
+
#define NUMO_NARRAY_MH_FILL_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FILL_METHOD_FUNC(tDType) \
|
|
5
|
+
static void iter_##tDType##_fill(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
ssize_t s1; \
|
|
9
|
+
size_t* idx1; \
|
|
10
|
+
VALUE x = lp->option; \
|
|
11
|
+
tDType y; \
|
|
12
|
+
\
|
|
13
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
y = m_num_to_data(x); \
|
|
16
|
+
\
|
|
17
|
+
if (idx1) { \
|
|
18
|
+
for (size_t i = 0; i < n; i++) { \
|
|
19
|
+
SET_DATA_INDEX(p1, idx1, tDType, y); \
|
|
20
|
+
} \
|
|
21
|
+
} else { \
|
|
22
|
+
for (size_t i = 0; i < n; i++) { \
|
|
23
|
+
SET_DATA_STRIDE(p1, s1, tDType, y); \
|
|
24
|
+
} \
|
|
25
|
+
} \
|
|
26
|
+
} \
|
|
27
|
+
\
|
|
28
|
+
static VALUE tDType##_fill(VALUE self, VALUE val) { \
|
|
29
|
+
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } }; \
|
|
30
|
+
ndfunc_t ndf = { iter_##tDType##_fill, FULL_LOOP, 2, 0, ain, 0 }; \
|
|
31
|
+
na_ndloop(&ndf, 2, self, val); \
|
|
32
|
+
return self; \
|
|
33
|
+
}
|
|
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
|
+
#endif /* NUMO_NARRAY_MH_FILL_H */
|