numo-narray-alt 0.9.12 → 0.9.13
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/minus.h +125 -0
- data/ext/numo/narray/src/mh/pow.h +197 -0
- data/ext/numo/narray/src/mh/rand_norm.h +125 -0
- data/ext/numo/narray/src/mh/reciprocal.h +125 -0
- data/ext/numo/narray/src/mh/sign.h +125 -0
- data/ext/numo/narray/src/mh/square.h +125 -0
- data/ext/numo/narray/src/t_dcomplex.c +69 -462
- data/ext/numo/narray/src/t_dfloat.c +12 -415
- data/ext/numo/narray/src/t_int16.c +36 -368
- data/ext/numo/narray/src/t_int32.c +36 -368
- data/ext/numo/narray/src/t_int64.c +36 -368
- data/ext/numo/narray/src/t_int8.c +36 -300
- data/ext/numo/narray/src/t_robject.c +36 -292
- data/ext/numo/narray/src/t_scomplex.c +47 -440
- data/ext/numo/narray/src/t_sfloat.c +13 -416
- data/ext/numo/narray/src/t_uint16.c +36 -368
- data/ext/numo/narray/src/t_uint32.c +36 -368
- data/ext/numo/narray/src/t_uint64.c +36 -368
- data/ext/numo/narray/src/t_uint8.c +36 -300
- metadata +8 -2
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_SIGN_H
|
|
2
|
+
#define NUMO_NARRAY_MH_SIGN_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_SIGN_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_sign(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_sign(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_sign(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_sign(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_sign(((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_sign(*(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_sign(x); \
|
|
58
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
59
|
+
} \
|
|
60
|
+
} \
|
|
61
|
+
} \
|
|
62
|
+
} \
|
|
63
|
+
\
|
|
64
|
+
static VALUE tDType##_sign(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##_sign, FULL_LOOP, 1, 1, ain, aout }; \
|
|
68
|
+
return na_ndloop(&ndf, 1, self); \
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#define DEF_NARRAY_INT8_SIGN_METHOD_FUNC(tDType, tNAryClass) \
|
|
72
|
+
static void iter_##tDType##_sign(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_sign(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_sign(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_sign(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_sign(*(tDType*)p1); \
|
|
108
|
+
p1 += s1; \
|
|
109
|
+
p2 += s2; \
|
|
110
|
+
} \
|
|
111
|
+
} \
|
|
112
|
+
} \
|
|
113
|
+
} \
|
|
114
|
+
\
|
|
115
|
+
static VALUE tDType##_sign(VALUE self) { \
|
|
116
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
117
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
118
|
+
ndfunc_t ndf = { iter_##tDType##_sign, FULL_LOOP, 1, 1, ain, aout }; \
|
|
119
|
+
return na_ndloop(&ndf, 1, self); \
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#define DEF_NARRAY_ROBJ_SIGN_METHOD_FUNC() \
|
|
123
|
+
DEF_NARRAY_INT8_SIGN_METHOD_FUNC(robject, numo_cRObject)
|
|
124
|
+
|
|
125
|
+
#endif /* NUMO_NARRAY_MH_SIGN_H */
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_SQUARE_H
|
|
2
|
+
#define NUMO_NARRAY_MH_SQUARE_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_SQUARE_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_square(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_square(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_square(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_square(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_square(((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_square(*(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_square(x); \
|
|
58
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
59
|
+
} \
|
|
60
|
+
} \
|
|
61
|
+
} \
|
|
62
|
+
} \
|
|
63
|
+
\
|
|
64
|
+
static VALUE tDType##_square(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##_square, FULL_LOOP, 1, 1, ain, aout }; \
|
|
68
|
+
return na_ndloop(&ndf, 1, self); \
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#define DEF_NARRAY_INT8_SQUARE_METHOD_FUNC(tDType, tNAryClass) \
|
|
72
|
+
static void iter_##tDType##_square(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_square(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_square(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_square(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_square(*(tDType*)p1); \
|
|
108
|
+
p1 += s1; \
|
|
109
|
+
p2 += s2; \
|
|
110
|
+
} \
|
|
111
|
+
} \
|
|
112
|
+
} \
|
|
113
|
+
} \
|
|
114
|
+
\
|
|
115
|
+
static VALUE tDType##_square(VALUE self) { \
|
|
116
|
+
ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
|
|
117
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
118
|
+
ndfunc_t ndf = { iter_##tDType##_square, FULL_LOOP, 1, 1, ain, aout }; \
|
|
119
|
+
return na_ndloop(&ndf, 1, self); \
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#define DEF_NARRAY_ROBJ_SQUARE_METHOD_FUNC() \
|
|
123
|
+
DEF_NARRAY_INT8_SQUARE_METHOD_FUNC(robject, numo_cRObject)
|
|
124
|
+
|
|
125
|
+
#endif /* NUMO_NARRAY_MH_SQUARE_H */
|