numo-narray-alt 0.9.13 → 0.9.14
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/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/src/mh/abs.h +56 -0
- data/ext/numo/narray/src/mh/aref.h +28 -0
- data/ext/numo/narray/src/mh/arg.h +56 -0
- data/ext/numo/narray/src/mh/conj.h +71 -0
- data/ext/numo/narray/src/mh/copysign.h +97 -0
- data/ext/numo/narray/src/mh/each.h +71 -0
- data/ext/numo/narray/src/mh/each_with_index.h +98 -0
- data/ext/numo/narray/src/mh/extract.h +36 -0
- data/ext/numo/narray/src/mh/im.h +71 -0
- data/ext/numo/narray/src/mh/imag.h +56 -0
- data/ext/numo/narray/src/mh/kahan_sum.h +39 -0
- data/ext/numo/narray/src/mh/map.h +126 -0
- data/ext/numo/narray/src/mh/map_with_index.h +76 -0
- data/ext/numo/narray/src/mh/modf.h +35 -0
- data/ext/numo/narray/src/mh/poly.h +42 -0
- data/ext/numo/narray/src/mh/real.h +56 -0
- data/ext/numo/narray/src/mh/set_imag.h +60 -0
- data/ext/numo/narray/src/mh/set_real.h +60 -0
- data/ext/numo/narray/src/mh/signbit.h +42 -0
- data/ext/numo/narray/src/t_bit.c +63 -176
- data/ext/numo/narray/src/t_dcomplex.c +142 -1001
- data/ext/numo/narray/src/t_dfloat.c +24 -560
- data/ext/numo/narray/src/t_int16.c +83 -417
- data/ext/numo/narray/src/t_int32.c +83 -417
- data/ext/numo/narray/src/t_int64.c +83 -417
- data/ext/numo/narray/src/t_int8.c +83 -400
- data/ext/numo/narray/src/t_robject.c +83 -400
- data/ext/numo/narray/src/t_scomplex.c +130 -953
- data/ext/numo/narray/src/t_sfloat.c +22 -524
- data/ext/numo/narray/src/t_uint16.c +83 -417
- data/ext/numo/narray/src/t_uint32.c +83 -417
- data/ext/numo/narray/src/t_uint64.c +83 -417
- data/ext/numo/narray/src/t_uint8.c +83 -400
- metadata +21 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_IM_H
|
|
2
|
+
#define NUMO_NARRAY_MH_IM_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_IM_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_im(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
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
16
|
+
tDType x; \
|
|
17
|
+
if (idx1) { \
|
|
18
|
+
if (idx2) { \
|
|
19
|
+
for (size_t i = 0; i < n; i++) { \
|
|
20
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
21
|
+
x = m_im(x); \
|
|
22
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
23
|
+
} \
|
|
24
|
+
} else { \
|
|
25
|
+
for (size_t i = 0; i < n; i++) { \
|
|
26
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
27
|
+
x = m_im(x); \
|
|
28
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
29
|
+
} \
|
|
30
|
+
} \
|
|
31
|
+
} else { \
|
|
32
|
+
if (idx2) { \
|
|
33
|
+
for (size_t i = 0; i < n; i++) { \
|
|
34
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
35
|
+
x = m_im(x); \
|
|
36
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
37
|
+
} \
|
|
38
|
+
} else { \
|
|
39
|
+
if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType))) { \
|
|
40
|
+
if (s1 == sizeof(tDType) && s2 == sizeof(tDType)) { \
|
|
41
|
+
for (size_t i = 0; i < n; i++) { \
|
|
42
|
+
((tDType*)p2)[i] = m_im(((tDType*)p1)[i]); \
|
|
43
|
+
} \
|
|
44
|
+
return; \
|
|
45
|
+
} \
|
|
46
|
+
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType))) { \
|
|
47
|
+
for (size_t i = 0; i < n; i++) { \
|
|
48
|
+
*(tDType*)p2 = m_im(*(tDType*)p1); \
|
|
49
|
+
p1 += s1; \
|
|
50
|
+
p2 += s2; \
|
|
51
|
+
} \
|
|
52
|
+
return; \
|
|
53
|
+
} \
|
|
54
|
+
} \
|
|
55
|
+
for (size_t i = 0; i < n; i++) { \
|
|
56
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
57
|
+
x = m_im(x); \
|
|
58
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
59
|
+
} \
|
|
60
|
+
} \
|
|
61
|
+
} \
|
|
62
|
+
} \
|
|
63
|
+
\
|
|
64
|
+
static VALUE tDType##_im(VALUE self) { \
|
|
65
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
66
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
67
|
+
ndfunc_t ndf = { iter_##tDType##_im, FULL_LOOP, 1, 1, ain, aout }; \
|
|
68
|
+
return na_ndloop(&ndf, 1, self); \
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#endif /* NUMO_NARRAY_MH_IM_H */
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_IMAG_H
|
|
2
|
+
#define NUMO_NARRAY_MH_IMAG_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_IMAG_METHOD_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass) \
|
|
5
|
+
static void iter_##tDType##_imag(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
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
16
|
+
tDType x; \
|
|
17
|
+
tRtDType y; \
|
|
18
|
+
if (idx1) { \
|
|
19
|
+
if (idx2) { \
|
|
20
|
+
for (size_t i = 0; i < n; i++) { \
|
|
21
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
22
|
+
y = m_imag(x); \
|
|
23
|
+
SET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
24
|
+
} \
|
|
25
|
+
} else { \
|
|
26
|
+
for (size_t i = 0; i < n; i++) { \
|
|
27
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
28
|
+
y = m_imag(x); \
|
|
29
|
+
SET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
30
|
+
} \
|
|
31
|
+
} \
|
|
32
|
+
} else { \
|
|
33
|
+
if (idx2) { \
|
|
34
|
+
for (size_t i = 0; i < n; i++) { \
|
|
35
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
36
|
+
y = m_imag(x); \
|
|
37
|
+
SET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
38
|
+
} \
|
|
39
|
+
} else { \
|
|
40
|
+
for (size_t i = 0; i < n; i++) { \
|
|
41
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
42
|
+
y = m_imag(x); \
|
|
43
|
+
SET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
44
|
+
} \
|
|
45
|
+
} \
|
|
46
|
+
} \
|
|
47
|
+
} \
|
|
48
|
+
\
|
|
49
|
+
static VALUE tDType##_imag(VALUE self) { \
|
|
50
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
51
|
+
ndfunc_arg_out_t aout[1] = { { tRtNAryClass, 0 } }; \
|
|
52
|
+
ndfunc_t ndf = { iter_##tDType##_imag, FULL_LOOP, 1, 1, ain, aout }; \
|
|
53
|
+
return na_ndloop(&ndf, 1, self); \
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#endif /* NUMO_NARRAY_MH_IMAG_H */
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_KAHAN_SUM_H
|
|
2
|
+
#define NUMO_NARRAY_MH_KAHAN_SUM_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_KAHAN_SUM_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_kahan_sum(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
ssize_t s1; \
|
|
10
|
+
INIT_COUNTER(lp, n); \
|
|
11
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
12
|
+
p2 = NDL_PTR(lp, 1); \
|
|
13
|
+
*(tDType*)p2 = f_kahan_sum(n, p1, s1); \
|
|
14
|
+
} \
|
|
15
|
+
\
|
|
16
|
+
static void iter_##tDType##_kahan_sum_nan(na_loop_t* const lp) { \
|
|
17
|
+
size_t n; \
|
|
18
|
+
char* p1; \
|
|
19
|
+
char* p2; \
|
|
20
|
+
ssize_t s1; \
|
|
21
|
+
INIT_COUNTER(lp, n); \
|
|
22
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
23
|
+
p2 = NDL_PTR(lp, 1); \
|
|
24
|
+
*(tDType*)p2 = f_kahan_sum_nan(n, p1, s1); \
|
|
25
|
+
} \
|
|
26
|
+
\
|
|
27
|
+
static VALUE tDType##_kahan_sum(int argc, VALUE* argv, VALUE self) { \
|
|
28
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
29
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
30
|
+
ndfunc_t ndf = { \
|
|
31
|
+
iter_##tDType##_kahan_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
|
|
32
|
+
}; \
|
|
33
|
+
VALUE reduce = \
|
|
34
|
+
na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_kahan_sum_nan); \
|
|
35
|
+
VALUE v = na_ndloop(&ndf, 2, self, reduce); \
|
|
36
|
+
return rb_funcall(v, rb_intern("extract"), 0); \
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#endif /* NUMO_NARRAY_MH_KAHAN_SUM_H */
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MAP_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MAP_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_MAP_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_map(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
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
16
|
+
tDType x; \
|
|
17
|
+
if (idx1) { \
|
|
18
|
+
if (idx2) { \
|
|
19
|
+
for (size_t i = 0; i < n; i++) { \
|
|
20
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
21
|
+
x = m_map(x); \
|
|
22
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
23
|
+
} \
|
|
24
|
+
} else { \
|
|
25
|
+
for (size_t i = 0; i < n; i++) { \
|
|
26
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
27
|
+
x = m_map(x); \
|
|
28
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
29
|
+
} \
|
|
30
|
+
} \
|
|
31
|
+
} else { \
|
|
32
|
+
if (idx2) { \
|
|
33
|
+
for (size_t i = 0; i < n; i++) { \
|
|
34
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
35
|
+
x = m_map(x); \
|
|
36
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
37
|
+
} \
|
|
38
|
+
} else { \
|
|
39
|
+
if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType))) { \
|
|
40
|
+
if (s1 == sizeof(tDType) && s2 == sizeof(tDType)) { \
|
|
41
|
+
for (size_t i = 0; i < n; i++) { \
|
|
42
|
+
((tDType*)p2)[i] = m_map(((tDType*)p1)[i]); \
|
|
43
|
+
} \
|
|
44
|
+
return; \
|
|
45
|
+
} \
|
|
46
|
+
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType))) { \
|
|
47
|
+
for (size_t i = 0; i < n; i++) { \
|
|
48
|
+
*(tDType*)p2 = m_map(*(tDType*)p1); \
|
|
49
|
+
p1 += s1; \
|
|
50
|
+
p2 += s2; \
|
|
51
|
+
} \
|
|
52
|
+
return; \
|
|
53
|
+
} \
|
|
54
|
+
} \
|
|
55
|
+
for (size_t i = 0; i < n; i++) { \
|
|
56
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
57
|
+
x = m_map(x); \
|
|
58
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
59
|
+
} \
|
|
60
|
+
} \
|
|
61
|
+
} \
|
|
62
|
+
} \
|
|
63
|
+
\
|
|
64
|
+
static VALUE tDType##_map(VALUE self) { \
|
|
65
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
66
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
67
|
+
ndfunc_t ndf = { iter_##tDType##_map, FULL_LOOP, 1, 1, ain, aout }; \
|
|
68
|
+
return na_ndloop(&ndf, 1, self); \
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#define DEF_NARRAY_INT8_MAP_METHOD_FUNC(tDType, tNAryClass) \
|
|
72
|
+
static void iter_##tDType##_map(na_loop_t* const lp) { \
|
|
73
|
+
size_t n; \
|
|
74
|
+
char* p1; \
|
|
75
|
+
char* p2; \
|
|
76
|
+
ssize_t s1; \
|
|
77
|
+
ssize_t s2; \
|
|
78
|
+
size_t* idx1; \
|
|
79
|
+
size_t* idx2; \
|
|
80
|
+
INIT_COUNTER(lp, n); \
|
|
81
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
82
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
83
|
+
tDType x; \
|
|
84
|
+
if (idx1) { \
|
|
85
|
+
if (idx2) { \
|
|
86
|
+
for (size_t i = 0; i < n; i++) { \
|
|
87
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
88
|
+
x = m_map(x); \
|
|
89
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
90
|
+
} \
|
|
91
|
+
} else { \
|
|
92
|
+
for (size_t i = 0; i < n; i++) { \
|
|
93
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
94
|
+
x = m_map(x); \
|
|
95
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
96
|
+
} \
|
|
97
|
+
} \
|
|
98
|
+
} else { \
|
|
99
|
+
if (idx2) { \
|
|
100
|
+
for (size_t i = 0; i < n; i++) { \
|
|
101
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
102
|
+
x = m_map(x); \
|
|
103
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
104
|
+
} \
|
|
105
|
+
} else { \
|
|
106
|
+
for (size_t i = 0; i < n; i++) { \
|
|
107
|
+
*(tDType*)p2 = m_map(*(tDType*)p1); \
|
|
108
|
+
p1 += s1; \
|
|
109
|
+
p2 += s2; \
|
|
110
|
+
} \
|
|
111
|
+
return; \
|
|
112
|
+
} \
|
|
113
|
+
} \
|
|
114
|
+
} \
|
|
115
|
+
\
|
|
116
|
+
static VALUE tDType##_map(VALUE self) { \
|
|
117
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
118
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
119
|
+
ndfunc_t ndf = { iter_##tDType##_map, FULL_LOOP, 1, 1, ain, aout }; \
|
|
120
|
+
return na_ndloop(&ndf, 1, self); \
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
#define DEF_NARRAY_ROBJ_MAP_METHOD_FUNC() \
|
|
124
|
+
DEF_NARRAY_INT8_MAP_METHOD_FUNC(robject, numo_cRObject)
|
|
125
|
+
|
|
126
|
+
#endif /* NUMO_NARRAY_MH_MAP_H */
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MAP_WITH_INDEX_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MAP_WITH_INDEX_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_MAP_WITH_INDEX_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static inline tDType yield_map_with_index(tDType x, size_t* c, VALUE* a, int nd, int md) { \
|
|
6
|
+
a[0] = m_data_to_num(x); \
|
|
7
|
+
for (int j = 0; j <= nd; j++) { \
|
|
8
|
+
a[j + 1] = SIZET2NUM(c[j]); \
|
|
9
|
+
} \
|
|
10
|
+
VALUE y = rb_yield(rb_ary_new4(md, a)); \
|
|
11
|
+
return m_num_to_data(y); \
|
|
12
|
+
} \
|
|
13
|
+
\
|
|
14
|
+
static void iter_##tDType##_map_with_index(na_loop_t* const lp) { \
|
|
15
|
+
size_t* c = (size_t*)(lp->opt_ptr); \
|
|
16
|
+
int nd = lp->ndim; \
|
|
17
|
+
if (nd > 0) { \
|
|
18
|
+
nd--; \
|
|
19
|
+
} \
|
|
20
|
+
int md = nd + 2; \
|
|
21
|
+
VALUE* a = ALLOCA_N(VALUE, md); \
|
|
22
|
+
size_t n; \
|
|
23
|
+
char* p1; \
|
|
24
|
+
char* p2; \
|
|
25
|
+
ssize_t s1; \
|
|
26
|
+
ssize_t s2; \
|
|
27
|
+
size_t* idx1; \
|
|
28
|
+
size_t* idx2; \
|
|
29
|
+
INIT_COUNTER(lp, n); \
|
|
30
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
31
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
32
|
+
tDType x; \
|
|
33
|
+
c[nd] = 0; \
|
|
34
|
+
if (idx1) { \
|
|
35
|
+
if (idx2) { \
|
|
36
|
+
for (size_t i = 0; i < n; i++) { \
|
|
37
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
38
|
+
x = yield_map_with_index(x, c, a, nd, md); \
|
|
39
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
40
|
+
c[nd]++; \
|
|
41
|
+
} \
|
|
42
|
+
} else { \
|
|
43
|
+
for (size_t i = 0; i < n; i++) { \
|
|
44
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
45
|
+
x = yield_map_with_index(x, c, a, nd, md); \
|
|
46
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
47
|
+
c[nd]++; \
|
|
48
|
+
} \
|
|
49
|
+
} \
|
|
50
|
+
} else { \
|
|
51
|
+
if (idx2) { \
|
|
52
|
+
for (size_t i = 0; i < n; i++) { \
|
|
53
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
54
|
+
x = yield_map_with_index(x, c, a, nd, md); \
|
|
55
|
+
SET_DATA_INDEX(p2, idx2, tDType, x); \
|
|
56
|
+
c[nd]++; \
|
|
57
|
+
} \
|
|
58
|
+
} else { \
|
|
59
|
+
for (size_t i = 0; i < n; i++) { \
|
|
60
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
61
|
+
x = yield_map_with_index(x, c, a, nd, md); \
|
|
62
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
63
|
+
c[nd]++; \
|
|
64
|
+
} \
|
|
65
|
+
} \
|
|
66
|
+
} \
|
|
67
|
+
} \
|
|
68
|
+
\
|
|
69
|
+
static VALUE tDType##_map_with_index(VALUE self) { \
|
|
70
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } }; \
|
|
71
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
72
|
+
ndfunc_t ndf = { iter_##tDType##_map_with_index, FULL_LOOP, 1, 1, ain, aout }; \
|
|
73
|
+
return na_ndloop_with_index(&ndf, 1, self); \
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#endif /* NUMO_NARRAY_MH_MAP_WITH_INDEX_H */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MODF_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MODF_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_MODF_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_modf(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
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
15
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
16
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
17
|
+
tDType x; \
|
|
18
|
+
tDType y; \
|
|
19
|
+
tDType z; \
|
|
20
|
+
for (size_t i = 0; i < n; i++) { \
|
|
21
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
22
|
+
m_modf(x, y, z); \
|
|
23
|
+
SET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
24
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
25
|
+
} \
|
|
26
|
+
} \
|
|
27
|
+
\
|
|
28
|
+
static VALUE tDType##_modf(VALUE self) { \
|
|
29
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
30
|
+
ndfunc_arg_out_t aout[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
31
|
+
ndfunc_t ndf = { iter_##tDType##_modf, STRIDE_LOOP, 1, 2, ain, aout }; \
|
|
32
|
+
return na_ndloop(&ndf, 1, self); \
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#endif /* NUMO_NARRAY_MH_MODF_H */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_POLY_H
|
|
2
|
+
#define NUMO_NARRAY_MH_POLY_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_POLY_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_poly(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
tDType x; \
|
|
8
|
+
tDType y; \
|
|
9
|
+
tDType a; \
|
|
10
|
+
n = lp->narg - 2; \
|
|
11
|
+
x = *(tDType*)NDL_PTR(lp, 0); \
|
|
12
|
+
y = *(tDType*)NDL_PTR(lp, n); \
|
|
13
|
+
for (size_t i = 1; i < n; i++) { \
|
|
14
|
+
y = m_mul(x, y); \
|
|
15
|
+
a = *(tDType*)NDL_PTR(lp, n - i); \
|
|
16
|
+
y = m_add(y, a); \
|
|
17
|
+
} \
|
|
18
|
+
n = lp->narg - 1; \
|
|
19
|
+
*(tDType*)NDL_PTR(lp, n) = y; \
|
|
20
|
+
} \
|
|
21
|
+
\
|
|
22
|
+
static VALUE tDType##_poly(VALUE self, VALUE args) { \
|
|
23
|
+
const int argc = (int)RARRAY_LEN(args); \
|
|
24
|
+
const int n_in = argc + 1; \
|
|
25
|
+
ndfunc_arg_in_t* ain = ALLOCA_N(ndfunc_arg_in_t, n_in); \
|
|
26
|
+
for (int i = 0; i < n_in; i++) { \
|
|
27
|
+
ain[i].type = tNAryClass; \
|
|
28
|
+
ain[i].dim = 0; \
|
|
29
|
+
} \
|
|
30
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
31
|
+
ndfunc_t ndf = { iter_##tDType##_poly, NO_LOOP, n_in, 1, ain, aout }; \
|
|
32
|
+
VALUE* argv = ALLOCA_N(VALUE, n_in); \
|
|
33
|
+
argv[0] = self; \
|
|
34
|
+
for (int i = 0; i < argc; i++) { \
|
|
35
|
+
argv[i + 1] = RARRAY_AREF(args, i); \
|
|
36
|
+
} \
|
|
37
|
+
volatile VALUE a = rb_ary_new4(n_in, argv); \
|
|
38
|
+
volatile VALUE v = na_ndloop2(&ndf, a); \
|
|
39
|
+
return tDType##_extract(v); \
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#endif /* NUMO_NARRAY_MH_POLY_H */
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_REAL_H
|
|
2
|
+
#define NUMO_NARRAY_MH_REAL_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_REAL_METHOD_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass) \
|
|
5
|
+
static void iter_##tDType##_real(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
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
16
|
+
tDType x; \
|
|
17
|
+
tRtDType y; \
|
|
18
|
+
if (idx1) { \
|
|
19
|
+
if (idx2) { \
|
|
20
|
+
for (size_t i = 0; i < n; i++) { \
|
|
21
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
22
|
+
y = m_real(x); \
|
|
23
|
+
SET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
24
|
+
} \
|
|
25
|
+
} else { \
|
|
26
|
+
for (size_t i = 0; i < n; i++) { \
|
|
27
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
28
|
+
y = m_real(x); \
|
|
29
|
+
SET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
30
|
+
} \
|
|
31
|
+
} \
|
|
32
|
+
} else { \
|
|
33
|
+
if (idx2) { \
|
|
34
|
+
for (size_t i = 0; i < n; i++) { \
|
|
35
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
36
|
+
y = m_real(x); \
|
|
37
|
+
SET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
38
|
+
} \
|
|
39
|
+
} else { \
|
|
40
|
+
for (size_t i = 0; i < n; i++) { \
|
|
41
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
42
|
+
y = m_real(x); \
|
|
43
|
+
SET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
44
|
+
} \
|
|
45
|
+
} \
|
|
46
|
+
} \
|
|
47
|
+
} \
|
|
48
|
+
\
|
|
49
|
+
static VALUE tDType##_real(VALUE self) { \
|
|
50
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
51
|
+
ndfunc_arg_out_t aout[1] = { { tRtNAryClass, 0 } }; \
|
|
52
|
+
ndfunc_t ndf = { iter_##tDType##_real, FULL_LOOP, 1, 1, ain, aout }; \
|
|
53
|
+
return na_ndloop(&ndf, 1, self); \
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#endif /* NUMO_NARRAY_MH_REAL_H */
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_SET_IMAG_H
|
|
2
|
+
#define NUMO_NARRAY_MH_SET_IMAG_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_SET_IMAG_METHOD_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass) \
|
|
5
|
+
static void iter_##tDType##_set_imag(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
|
+
INIT_COUNTER(lp, n); \
|
|
14
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
15
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
|
16
|
+
tDType x; \
|
|
17
|
+
tRtDType y; \
|
|
18
|
+
if (idx1) { \
|
|
19
|
+
if (idx2) { \
|
|
20
|
+
for (size_t i = 0; i < n; i++) { \
|
|
21
|
+
GET_DATA(p1 + *idx1, tDType, x); \
|
|
22
|
+
GET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
23
|
+
x = m_set_imag(x, y); \
|
|
24
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
25
|
+
} \
|
|
26
|
+
} else { \
|
|
27
|
+
for (size_t i = 0; i < n; i++) { \
|
|
28
|
+
GET_DATA(p1 + *idx1, tDType, x); \
|
|
29
|
+
GET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
30
|
+
x = m_set_imag(x, y); \
|
|
31
|
+
SET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
32
|
+
} \
|
|
33
|
+
} \
|
|
34
|
+
} else { \
|
|
35
|
+
if (idx2) { \
|
|
36
|
+
for (size_t i = 0; i < n; i++) { \
|
|
37
|
+
GET_DATA(p1, tDType, x); \
|
|
38
|
+
GET_DATA_INDEX(p2, idx2, tRtDType, y); \
|
|
39
|
+
x = m_set_imag(x, y); \
|
|
40
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
41
|
+
} \
|
|
42
|
+
} else { \
|
|
43
|
+
for (size_t i = 0; i < n; i++) { \
|
|
44
|
+
GET_DATA(p1, tDType, x); \
|
|
45
|
+
GET_DATA_STRIDE(p2, s2, tRtDType, y); \
|
|
46
|
+
x = m_set_imag(x, y); \
|
|
47
|
+
SET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
48
|
+
} \
|
|
49
|
+
} \
|
|
50
|
+
} \
|
|
51
|
+
} \
|
|
52
|
+
\
|
|
53
|
+
static VALUE tDType##_set_imag(VALUE self, VALUE a1) { \
|
|
54
|
+
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { tRtNAryClass, 0 } }; \
|
|
55
|
+
ndfunc_t ndf = { iter_##tDType##_set_imag, FULL_LOOP, 2, 0, ain, 0 }; \
|
|
56
|
+
na_ndloop(&ndf, 2, self, a1); \
|
|
57
|
+
return a1; \
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#endif /* NUMO_NARRAY_MH_SET_IMAG_H */
|