numo-narray-alt 0.9.13 → 0.10.0
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 +1 -1
- data/ext/numo/narray/array.c +1 -9
- data/ext/numo/narray/extconf.rb +0 -11
- data/ext/numo/narray/index.c +5 -39
- data/ext/numo/narray/math.c +0 -5
- data/ext/numo/narray/narray.c +13 -19
- data/ext/numo/narray/numo/narray.h +6 -8
- 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/aset.h +169 -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/median.h +85 -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/s_cast.h +80 -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/mh/sort.h +484 -0
- data/ext/numo/narray/src/mh/store.h +496 -0
- data/ext/numo/narray/src/t_bit.c +65 -195
- data/ext/numo/narray/src/t_dcomplex.c +244 -2216
- data/ext/numo/narray/src/t_dfloat.c +74 -2435
- data/ext/numo/narray/src/t_int16.c +225 -2015
- data/ext/numo/narray/src/t_int32.c +225 -2015
- data/ext/numo/narray/src/t_int64.c +225 -2015
- data/ext/numo/narray/src/t_int8.c +225 -1998
- data/ext/numo/narray/src/t_robject.c +114 -1413
- data/ext/numo/narray/src/t_scomplex.c +232 -2168
- data/ext/numo/narray/src/t_sfloat.c +72 -2399
- data/ext/numo/narray/src/t_uint16.c +225 -2015
- data/ext/numo/narray/src/t_uint32.c +225 -2015
- data/ext/numo/narray/src/t_uint64.c +225 -2015
- data/ext/numo/narray/src/t_uint8.c +225 -1998
- data/ext/numo/narray/step.c +2 -59
- data/numo-narray-alt.gemspec +1 -1
- metadata +27 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_CONJ_H
|
|
2
|
+
#define NUMO_NARRAY_MH_CONJ_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_CONJ_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_conj(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_conj(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_conj(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_conj(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_conj(((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_conj(*(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_conj(x); \
|
|
58
|
+
SET_DATA_STRIDE(p2, s2, tDType, x); \
|
|
59
|
+
} \
|
|
60
|
+
} \
|
|
61
|
+
} \
|
|
62
|
+
} \
|
|
63
|
+
\
|
|
64
|
+
static VALUE tDType##_conj(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##_conj, FULL_LOOP, 1, 1, ain, aout }; \
|
|
68
|
+
return na_ndloop(&ndf, 1, self); \
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#endif /* NUMO_NARRAY_MH_CONJ_H */
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_COPYSIGN_H
|
|
2
|
+
#define NUMO_NARRAY_MH_COPYSIGN_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_COPYSIGN_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_copysign(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
|
+
if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType)) && \
|
|
18
|
+
is_aligned(p3, sizeof(tDType))) { \
|
|
19
|
+
if (s1 == sizeof(tDType) && s2 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
20
|
+
if (p1 == p3) { \
|
|
21
|
+
for (size_t i = 0; i < n; i++) { \
|
|
22
|
+
((tDType*)p1)[i] = m_copysign(((tDType*)p1)[i], ((tDType*)p2)[i]); \
|
|
23
|
+
} \
|
|
24
|
+
} else { \
|
|
25
|
+
for (size_t i = 0; i < n; i++) { \
|
|
26
|
+
((tDType*)p3)[i] = m_copysign(((tDType*)p1)[i], ((tDType*)p2)[i]); \
|
|
27
|
+
} \
|
|
28
|
+
} \
|
|
29
|
+
return; \
|
|
30
|
+
} \
|
|
31
|
+
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
|
|
32
|
+
is_aligned_step(s3, sizeof(tDType))) { \
|
|
33
|
+
if (s2 == 0) { \
|
|
34
|
+
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
35
|
+
if (p1 == p3) { \
|
|
36
|
+
for (size_t i = 0; i < n; i++) { \
|
|
37
|
+
((tDType*)p1)[i] = m_copysign(((tDType*)p1)[i], *(tDType*)p2); \
|
|
38
|
+
} \
|
|
39
|
+
} else { \
|
|
40
|
+
for (size_t i = 0; i < n; i++) { \
|
|
41
|
+
((tDType*)p3)[i] = m_copysign(((tDType*)p1)[i], *(tDType*)p2); \
|
|
42
|
+
} \
|
|
43
|
+
} \
|
|
44
|
+
} else { \
|
|
45
|
+
for (size_t i = 0; i < n; i++) { \
|
|
46
|
+
*(tDType*)p3 = m_copysign(*(tDType*)p1, *(tDType*)p2); \
|
|
47
|
+
p1 += s1; \
|
|
48
|
+
p3 += s3; \
|
|
49
|
+
} \
|
|
50
|
+
} \
|
|
51
|
+
} else { \
|
|
52
|
+
if (p1 == p3) { \
|
|
53
|
+
for (size_t i = 0; i < n; i++) { \
|
|
54
|
+
*(tDType*)p1 = m_copysign(*(tDType*)p1, *(tDType*)p2); \
|
|
55
|
+
p1 += s1; \
|
|
56
|
+
p2 += s2; \
|
|
57
|
+
} \
|
|
58
|
+
} else { \
|
|
59
|
+
for (size_t i = 0; i < n; i++) { \
|
|
60
|
+
*(tDType*)p3 = m_copysign(*(tDType*)p1, *(tDType*)p2); \
|
|
61
|
+
p1 += s1; \
|
|
62
|
+
p2 += s2; \
|
|
63
|
+
p3 += s3; \
|
|
64
|
+
} \
|
|
65
|
+
} \
|
|
66
|
+
} \
|
|
67
|
+
return; \
|
|
68
|
+
} \
|
|
69
|
+
} \
|
|
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
|
+
z = m_copysign(x, y); \
|
|
77
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
78
|
+
} \
|
|
79
|
+
} \
|
|
80
|
+
\
|
|
81
|
+
static VALUE tDType##_copysign_self(VALUE self, VALUE other) { \
|
|
82
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
83
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
84
|
+
ndfunc_t ndf = { iter_##tDType##_copysign, STRIDE_LOOP, 2, 1, ain, aout }; \
|
|
85
|
+
return na_ndloop(&ndf, 2, self, other); \
|
|
86
|
+
} \
|
|
87
|
+
\
|
|
88
|
+
static VALUE tDType##_copysign(VALUE self, VALUE other) { \
|
|
89
|
+
VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
|
|
90
|
+
if (klass == tNAryClass) { \
|
|
91
|
+
return tDType##_copysign_self(self, other); \
|
|
92
|
+
} \
|
|
93
|
+
VALUE v = rb_funcall(klass, id_cast, 1, self); \
|
|
94
|
+
return rb_funcall(v, id_copysign, 1, other); \
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#endif /* NUMO_NARRAY_MH_COPYSIGN_H */
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_EACH_H
|
|
2
|
+
#define NUMO_NARRAY_MH_EACH_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_EACH_METHOD_FUNC(tDType) \
|
|
5
|
+
static void iter_##tDType##_each(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
size_t s1; \
|
|
8
|
+
char* p1; \
|
|
9
|
+
size_t* idx1; \
|
|
10
|
+
INIT_COUNTER(lp, n); \
|
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
12
|
+
tDType x; \
|
|
13
|
+
VALUE y; \
|
|
14
|
+
if (idx1) { \
|
|
15
|
+
for (size_t i = 0; i < n; i++) { \
|
|
16
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
17
|
+
y = m_data_to_num(x); \
|
|
18
|
+
rb_yield(y); \
|
|
19
|
+
} \
|
|
20
|
+
} else { \
|
|
21
|
+
for (size_t i = 0; i < n; i++) { \
|
|
22
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
23
|
+
y = m_data_to_num(x); \
|
|
24
|
+
rb_yield(y); \
|
|
25
|
+
} \
|
|
26
|
+
} \
|
|
27
|
+
} \
|
|
28
|
+
\
|
|
29
|
+
static VALUE tDType##_each(VALUE self) { \
|
|
30
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } }; \
|
|
31
|
+
ndfunc_t ndf = { iter_##tDType##_each, FULL_LOOP_NIP, 1, 0, ain, 0 }; \
|
|
32
|
+
na_ndloop(&ndf, 1, self); \
|
|
33
|
+
return self; \
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#define DEF_NARRAY_BIT_EACH_METHOD_FUNC() \
|
|
37
|
+
static void iter_bit_each(na_loop_t* const lp) { \
|
|
38
|
+
size_t n; \
|
|
39
|
+
BIT_DIGIT* a1; \
|
|
40
|
+
size_t p1; \
|
|
41
|
+
ssize_t s1; \
|
|
42
|
+
size_t* idx1; \
|
|
43
|
+
INIT_COUNTER(lp, n); \
|
|
44
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
|
|
45
|
+
BIT_DIGIT x = 0; \
|
|
46
|
+
VALUE y; \
|
|
47
|
+
if (idx1) { \
|
|
48
|
+
for (size_t i = 0; i < n; i++) { \
|
|
49
|
+
LOAD_BIT(a1, p1 + *idx1, x); \
|
|
50
|
+
idx1++; \
|
|
51
|
+
y = m_data_to_num(x); \
|
|
52
|
+
rb_yield(y); \
|
|
53
|
+
} \
|
|
54
|
+
} else { \
|
|
55
|
+
for (size_t i = 0; i < n; i++) { \
|
|
56
|
+
LOAD_BIT(a1, p1, x); \
|
|
57
|
+
p1 += s1; \
|
|
58
|
+
y = m_data_to_num(x); \
|
|
59
|
+
rb_yield(y); \
|
|
60
|
+
} \
|
|
61
|
+
} \
|
|
62
|
+
} \
|
|
63
|
+
\
|
|
64
|
+
static VALUE bit_each(VALUE self) { \
|
|
65
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } }; \
|
|
66
|
+
ndfunc_t ndf = { iter_bit_each, FULL_LOOP_NIP, 1, 0, ain, 0 }; \
|
|
67
|
+
na_ndloop(&ndf, 1, self); \
|
|
68
|
+
return self; \
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#endif /* NUMO_NARRAY_MH_EACH_H */
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_EACH_WITH_INDEX_H
|
|
2
|
+
#define NUMO_NARRAY_MH_EACH_WITH_INDEX_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_EACH_WITH_INDEX_METHOD_FUNC(tDType) \
|
|
5
|
+
static inline void yield_each_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
|
+
rb_yield(rb_ary_new4(md, a)); \
|
|
11
|
+
} \
|
|
12
|
+
\
|
|
13
|
+
static void iter_##tDType##_each_with_index(na_loop_t* const lp) { \
|
|
14
|
+
size_t* c = (size_t*)(lp->opt_ptr); \
|
|
15
|
+
int nd = lp->ndim; \
|
|
16
|
+
if (nd > 0) { \
|
|
17
|
+
nd--; \
|
|
18
|
+
} \
|
|
19
|
+
int md = nd + 2; \
|
|
20
|
+
VALUE* a = ALLOCA_N(VALUE, md); \
|
|
21
|
+
size_t n; \
|
|
22
|
+
char* p1; \
|
|
23
|
+
size_t s1; \
|
|
24
|
+
size_t* idx1; \
|
|
25
|
+
INIT_COUNTER(lp, n); \
|
|
26
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
27
|
+
tDType x; \
|
|
28
|
+
c[nd] = 0; \
|
|
29
|
+
if (idx1) { \
|
|
30
|
+
for (size_t i = 0; i < n; i++) { \
|
|
31
|
+
GET_DATA_INDEX(p1, idx1, tDType, x); \
|
|
32
|
+
yield_each_with_index(x, c, a, nd, md); \
|
|
33
|
+
c[nd]++; \
|
|
34
|
+
} \
|
|
35
|
+
} else { \
|
|
36
|
+
for (size_t i = 0; i < n; i++) { \
|
|
37
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
38
|
+
yield_each_with_index(x, c, a, nd, md); \
|
|
39
|
+
c[nd]++; \
|
|
40
|
+
} \
|
|
41
|
+
} \
|
|
42
|
+
} \
|
|
43
|
+
\
|
|
44
|
+
static VALUE tDType##_each_with_index(VALUE self) { \
|
|
45
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } }; \
|
|
46
|
+
ndfunc_t ndf = { iter_##tDType##_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 }; \
|
|
47
|
+
na_ndloop_with_index(&ndf, 1, self); \
|
|
48
|
+
return self; \
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#define DEF_NARRAY_BIT_EACH_WITH_INDEX_METHOD_FUNC() \
|
|
52
|
+
static inline void yield_each_with_index(BIT_DIGIT x, size_t* c, VALUE* a, int nd, int md) { \
|
|
53
|
+
a[0] = m_data_to_num(x); \
|
|
54
|
+
for (int j = 0; j <= nd; j++) { \
|
|
55
|
+
a[j + 1] = SIZET2NUM(c[j]); \
|
|
56
|
+
} \
|
|
57
|
+
rb_yield(rb_ary_new4(md, a)); \
|
|
58
|
+
} \
|
|
59
|
+
\
|
|
60
|
+
static void iter_bit_each_with_index(na_loop_t* const lp) { \
|
|
61
|
+
size_t* c = (size_t*)(lp->opt_ptr); \
|
|
62
|
+
int nd = lp->ndim - 1; \
|
|
63
|
+
int md = lp->ndim + 1; \
|
|
64
|
+
VALUE* a = ALLOCA_N(VALUE, md); \
|
|
65
|
+
size_t n; \
|
|
66
|
+
BIT_DIGIT* a1; \
|
|
67
|
+
size_t p1; \
|
|
68
|
+
ssize_t s1; \
|
|
69
|
+
size_t* idx1; \
|
|
70
|
+
INIT_COUNTER(lp, n); \
|
|
71
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
|
|
72
|
+
BIT_DIGIT x = 0; \
|
|
73
|
+
c[nd] = 0; \
|
|
74
|
+
if (idx1) { \
|
|
75
|
+
for (size_t i = 0; i < n; i++) { \
|
|
76
|
+
LOAD_BIT(a1, p1 + *idx1, x); \
|
|
77
|
+
idx1++; \
|
|
78
|
+
yield_each_with_index(x, c, a, nd, md); \
|
|
79
|
+
c[nd]++; \
|
|
80
|
+
} \
|
|
81
|
+
} else { \
|
|
82
|
+
for (size_t i = 0; i < n; i++) { \
|
|
83
|
+
LOAD_BIT(a1, p1, x); \
|
|
84
|
+
p1 += s1; \
|
|
85
|
+
yield_each_with_index(x, c, a, nd, md); \
|
|
86
|
+
c[nd]++; \
|
|
87
|
+
} \
|
|
88
|
+
} \
|
|
89
|
+
} \
|
|
90
|
+
\
|
|
91
|
+
static VALUE bit_each_with_index(VALUE self) { \
|
|
92
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } }; \
|
|
93
|
+
ndfunc_t ndf = { iter_bit_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 }; \
|
|
94
|
+
na_ndloop_with_index(&ndf, 1, self); \
|
|
95
|
+
return self; \
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#endif /* NUMO_NARRAY_MH_EACH_WITH_INDEX_H */
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_EXTRACT_H
|
|
2
|
+
#define NUMO_NARRAY_MH_EXTRACT_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_EXTRACT_METHOD_FUNC(tDType) \
|
|
5
|
+
static VALUE tDType##_extract(VALUE self) { \
|
|
6
|
+
volatile VALUE v; \
|
|
7
|
+
char* ptr; \
|
|
8
|
+
narray_t* na; \
|
|
9
|
+
GetNArray(self, na); \
|
|
10
|
+
if (na->ndim == 0) { \
|
|
11
|
+
ptr = na_get_pointer_for_read(self) + na_get_offset(self); \
|
|
12
|
+
v = m_extract(ptr); \
|
|
13
|
+
na_release_lock(self); \
|
|
14
|
+
return v; \
|
|
15
|
+
} \
|
|
16
|
+
return self; \
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#define DEF_NARRAY_BIT_EXTRACT_METHOD_FUNC() \
|
|
20
|
+
static VALUE bit_extract(VALUE self) { \
|
|
21
|
+
BIT_DIGIT* ptr; \
|
|
22
|
+
BIT_DIGIT val; \
|
|
23
|
+
size_t pos; \
|
|
24
|
+
narray_t* na; \
|
|
25
|
+
GetNArray(self, na); \
|
|
26
|
+
if (na->ndim == 0) { \
|
|
27
|
+
pos = na_get_offset(self); \
|
|
28
|
+
ptr = (BIT_DIGIT*)na_get_pointer_for_read(self); \
|
|
29
|
+
val = ((*((ptr) + (pos) / NB)) >> ((pos) % NB)) & 1u; \
|
|
30
|
+
na_release_lock(self); \
|
|
31
|
+
return INT2FIX(val); \
|
|
32
|
+
} \
|
|
33
|
+
return self; \
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#endif /* NUMO_NARRAY_MH_EXTRACT_H */
|
|
@@ -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 */
|