numo-narray-alt 0.9.9 → 0.9.11
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/LICENSE +1 -1
- data/ext/numo/narray/numo/narray.h +2 -2
- 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/clip.h +115 -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/eye.h +82 -0
- data/ext/numo/narray/src/mh/logseq.h +69 -0
- 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/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/seq.h +130 -0
- data/ext/numo/narray/src/mh/sum.h +69 -0
- data/ext/numo/narray/src/t_dcomplex.c +131 -667
- data/ext/numo/narray/src/t_dfloat.c +40 -1288
- data/ext/numo/narray/src/t_int16.c +262 -1161
- data/ext/numo/narray/src/t_int32.c +263 -1161
- data/ext/numo/narray/src/t_int64.c +262 -1163
- data/ext/numo/narray/src/t_int8.c +262 -1159
- data/ext/numo/narray/src/t_robject.c +427 -1675
- data/ext/numo/narray/src/t_scomplex.c +131 -667
- data/ext/numo/narray/src/t_sfloat.c +40 -1288
- data/ext/numo/narray/src/t_uint16.c +262 -1161
- data/ext/numo/narray/src/t_uint32.c +262 -1161
- data/ext/numo/narray/src/t_uint64.c +262 -1163
- data/ext/numo/narray/src/t_uint8.c +262 -1161
- data/lib/numo/narray.rb +3 -1
- metadata +23 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MAXIMUM_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MAXIMUM_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_MAXIMUM_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_s_maximum(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
|
+
\
|
|
14
|
+
INIT_COUNTER(lp, n); \
|
|
15
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
16
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
17
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
18
|
+
\
|
|
19
|
+
for (size_t i = 0; i < n; i++) { \
|
|
20
|
+
tDType x; \
|
|
21
|
+
tDType y; \
|
|
22
|
+
tDType z; \
|
|
23
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
24
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
25
|
+
GET_DATA(p3, tDType, z); \
|
|
26
|
+
z = f_maximum(x, y); \
|
|
27
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
28
|
+
} \
|
|
29
|
+
} \
|
|
30
|
+
\
|
|
31
|
+
static void iter_##tDType##_s_maximum_nan(na_loop_t* const lp) { \
|
|
32
|
+
size_t n; \
|
|
33
|
+
char* p1; \
|
|
34
|
+
char* p2; \
|
|
35
|
+
char* p3; \
|
|
36
|
+
ssize_t s1; \
|
|
37
|
+
ssize_t s2; \
|
|
38
|
+
ssize_t s3; \
|
|
39
|
+
\
|
|
40
|
+
INIT_COUNTER(lp, n); \
|
|
41
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
42
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
43
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
44
|
+
\
|
|
45
|
+
for (size_t i = 0; i < n; i++) { \
|
|
46
|
+
tDType x; \
|
|
47
|
+
tDType y; \
|
|
48
|
+
tDType z; \
|
|
49
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
50
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
51
|
+
GET_DATA(p3, tDType, z); \
|
|
52
|
+
z = f_maximum_nan(x, y); \
|
|
53
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
54
|
+
} \
|
|
55
|
+
} \
|
|
56
|
+
\
|
|
57
|
+
static VALUE tDType##_s_maximum(int argc, VALUE* argv, VALUE mod) { \
|
|
58
|
+
VALUE a1 = Qnil; \
|
|
59
|
+
VALUE a2 = Qnil; \
|
|
60
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
61
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
62
|
+
ndfunc_t ndf = { iter_##tDType##_s_maximum, STRIDE_LOOP_NIP, 2, 1, ain, aout }; \
|
|
63
|
+
\
|
|
64
|
+
VALUE kw_hash = Qnil; \
|
|
65
|
+
ID kw_table[1] = { id_nan }; \
|
|
66
|
+
VALUE opts[1] = { Qundef }; \
|
|
67
|
+
\
|
|
68
|
+
rb_scan_args(argc, argv, "20:", &a1, &a2, &kw_hash); \
|
|
69
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 1, opts); \
|
|
70
|
+
if (opts[0] != Qundef) { \
|
|
71
|
+
ndf.func = iter_##tDType##_s_maximum_nan; \
|
|
72
|
+
} \
|
|
73
|
+
\
|
|
74
|
+
return na_ndloop(&ndf, 2, a1, a2); \
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#define DEF_NARRAY_INT_MAXIMUM_METHOD_FUNC(tDType, tNAryClass) \
|
|
78
|
+
static void iter_##tDType##_s_maximum(na_loop_t* const lp) { \
|
|
79
|
+
size_t n; \
|
|
80
|
+
char* p1; \
|
|
81
|
+
char* p2; \
|
|
82
|
+
char* p3; \
|
|
83
|
+
ssize_t s1; \
|
|
84
|
+
ssize_t s2; \
|
|
85
|
+
ssize_t s3; \
|
|
86
|
+
\
|
|
87
|
+
INIT_COUNTER(lp, n); \
|
|
88
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
89
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
90
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
91
|
+
\
|
|
92
|
+
for (size_t i = 0; i < n; i++) { \
|
|
93
|
+
tDType x; \
|
|
94
|
+
tDType y; \
|
|
95
|
+
tDType z; \
|
|
96
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
97
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
98
|
+
GET_DATA(p3, tDType, z); \
|
|
99
|
+
z = f_maximum(x, y); \
|
|
100
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
101
|
+
} \
|
|
102
|
+
} \
|
|
103
|
+
\
|
|
104
|
+
static VALUE tDType##_s_maximum(int argc, VALUE* argv, VALUE mod) { \
|
|
105
|
+
VALUE a1 = Qnil; \
|
|
106
|
+
VALUE a2 = Qnil; \
|
|
107
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
108
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
109
|
+
ndfunc_t ndf = { iter_##tDType##_s_maximum, STRIDE_LOOP_NIP, 2, 1, ain, aout }; \
|
|
110
|
+
\
|
|
111
|
+
rb_scan_args(argc, argv, "20", &a1, &a2); \
|
|
112
|
+
\
|
|
113
|
+
return na_ndloop(&ndf, 2, a1, a2); \
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#endif /* NUMO_NARRAY_MH_MAXIMUM_H */
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MIN_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MIN_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_MIN_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_min(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
char* p2; \
|
|
9
|
+
ssize_t s1; \
|
|
10
|
+
\
|
|
11
|
+
INIT_COUNTER(lp, n); \
|
|
12
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
13
|
+
p2 = NDL_PTR(lp, 1); \
|
|
14
|
+
\
|
|
15
|
+
*(tDType*)p2 = f_min(n, p1, s1); \
|
|
16
|
+
} \
|
|
17
|
+
\
|
|
18
|
+
static void iter_##tDType##_min_nan(na_loop_t* const lp) { \
|
|
19
|
+
size_t n; \
|
|
20
|
+
char* p1; \
|
|
21
|
+
char* p2; \
|
|
22
|
+
ssize_t s1; \
|
|
23
|
+
\
|
|
24
|
+
INIT_COUNTER(lp, n); \
|
|
25
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
26
|
+
p2 = NDL_PTR(lp, 1); \
|
|
27
|
+
\
|
|
28
|
+
*(tDType*)p2 = f_min_nan(n, p1, s1); \
|
|
29
|
+
} \
|
|
30
|
+
\
|
|
31
|
+
static VALUE tDType##_min(int argc, VALUE* argv, VALUE self) { \
|
|
32
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
33
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
34
|
+
ndfunc_t ndf = { \
|
|
35
|
+
iter_##tDType##_min, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
|
|
36
|
+
}; \
|
|
37
|
+
VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_min_nan); \
|
|
38
|
+
VALUE v = na_ndloop(&ndf, 2, self, reduce); \
|
|
39
|
+
\
|
|
40
|
+
return rb_funcall(v, rb_intern("extract"), 0); \
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#define DEF_NARRAY_INT_MIN_METHOD_FUNC(tDType, tNAryClass) \
|
|
44
|
+
static void iter_##tDType##_min(na_loop_t* const lp) { \
|
|
45
|
+
size_t n; \
|
|
46
|
+
char* p1; \
|
|
47
|
+
char* p2; \
|
|
48
|
+
ssize_t s1; \
|
|
49
|
+
\
|
|
50
|
+
INIT_COUNTER(lp, n); \
|
|
51
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
52
|
+
p2 = NDL_PTR(lp, 1); \
|
|
53
|
+
\
|
|
54
|
+
*(tDType*)p2 = f_min(n, p1, s1); \
|
|
55
|
+
} \
|
|
56
|
+
\
|
|
57
|
+
static VALUE tDType##_min(int argc, VALUE* argv, VALUE self) { \
|
|
58
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
59
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
60
|
+
ndfunc_t ndf = { \
|
|
61
|
+
iter_##tDType##_min, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout \
|
|
62
|
+
}; \
|
|
63
|
+
VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
|
|
64
|
+
VALUE v = na_ndloop(&ndf, 2, self, reduce); \
|
|
65
|
+
\
|
|
66
|
+
return rb_funcall(v, rb_intern("extract"), 0); \
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#endif /* NUMO_NARRAY_MH_MIN_H */
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MIN_INDEX_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MIN_INDEX_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_MIN_INDEX_METHOD_FUNC(tDType) \
|
|
5
|
+
static void iter_##tDType##_min_index_index64(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
size_t idx; \
|
|
8
|
+
char* d_ptr; \
|
|
9
|
+
char* i_ptr; \
|
|
10
|
+
char* o_ptr; \
|
|
11
|
+
ssize_t d_step; \
|
|
12
|
+
ssize_t i_step; \
|
|
13
|
+
\
|
|
14
|
+
INIT_COUNTER(lp, n); \
|
|
15
|
+
INIT_PTR(lp, 0, d_ptr, d_step); \
|
|
16
|
+
\
|
|
17
|
+
idx = f_min_index(n, d_ptr, d_step); \
|
|
18
|
+
\
|
|
19
|
+
INIT_PTR(lp, 1, i_ptr, i_step); \
|
|
20
|
+
o_ptr = NDL_PTR(lp, 2); \
|
|
21
|
+
*(int64_t*)o_ptr = *(int64_t*)(i_ptr + i_step * idx); \
|
|
22
|
+
} \
|
|
23
|
+
\
|
|
24
|
+
static void iter_##tDType##_min_index_index32(na_loop_t* const lp) { \
|
|
25
|
+
size_t n; \
|
|
26
|
+
size_t idx; \
|
|
27
|
+
char* d_ptr; \
|
|
28
|
+
char* i_ptr; \
|
|
29
|
+
char* o_ptr; \
|
|
30
|
+
ssize_t d_step; \
|
|
31
|
+
ssize_t i_step; \
|
|
32
|
+
\
|
|
33
|
+
INIT_COUNTER(lp, n); \
|
|
34
|
+
INIT_PTR(lp, 0, d_ptr, d_step); \
|
|
35
|
+
\
|
|
36
|
+
idx = f_min_index(n, d_ptr, d_step); \
|
|
37
|
+
\
|
|
38
|
+
INIT_PTR(lp, 1, i_ptr, i_step); \
|
|
39
|
+
o_ptr = NDL_PTR(lp, 2); \
|
|
40
|
+
*(int32_t*)o_ptr = *(int32_t*)(i_ptr + i_step * idx); \
|
|
41
|
+
} \
|
|
42
|
+
\
|
|
43
|
+
static void iter_##tDType##_min_index_index64_nan(na_loop_t* const lp) { \
|
|
44
|
+
size_t n; \
|
|
45
|
+
size_t idx; \
|
|
46
|
+
char* d_ptr; \
|
|
47
|
+
char* i_ptr; \
|
|
48
|
+
char* o_ptr; \
|
|
49
|
+
ssize_t d_step; \
|
|
50
|
+
ssize_t i_step; \
|
|
51
|
+
\
|
|
52
|
+
INIT_COUNTER(lp, n); \
|
|
53
|
+
INIT_PTR(lp, 0, d_ptr, d_step); \
|
|
54
|
+
\
|
|
55
|
+
idx = f_min_index_nan(n, d_ptr, d_step); \
|
|
56
|
+
\
|
|
57
|
+
INIT_PTR(lp, 1, i_ptr, i_step); \
|
|
58
|
+
o_ptr = NDL_PTR(lp, 2); \
|
|
59
|
+
*(int64_t*)o_ptr = *(int64_t*)(i_ptr + i_step * idx); \
|
|
60
|
+
} \
|
|
61
|
+
\
|
|
62
|
+
static void iter_##tDType##_min_index_index32_nan(na_loop_t* const lp) { \
|
|
63
|
+
size_t n; \
|
|
64
|
+
size_t idx; \
|
|
65
|
+
char* d_ptr; \
|
|
66
|
+
char* i_ptr; \
|
|
67
|
+
char* o_ptr; \
|
|
68
|
+
ssize_t d_step; \
|
|
69
|
+
ssize_t i_step; \
|
|
70
|
+
\
|
|
71
|
+
INIT_COUNTER(lp, n); \
|
|
72
|
+
INIT_PTR(lp, 0, d_ptr, d_step); \
|
|
73
|
+
\
|
|
74
|
+
idx = f_min_index_nan(n, d_ptr, d_step); \
|
|
75
|
+
\
|
|
76
|
+
INIT_PTR(lp, 1, i_ptr, i_step); \
|
|
77
|
+
o_ptr = NDL_PTR(lp, 2); \
|
|
78
|
+
*(int32_t*)o_ptr = *(int32_t*)(i_ptr + i_step * idx); \
|
|
79
|
+
} \
|
|
80
|
+
\
|
|
81
|
+
static VALUE tDType##_min_index(int argc, VALUE* argv, VALUE self) { \
|
|
82
|
+
narray_t* na; \
|
|
83
|
+
VALUE idx; \
|
|
84
|
+
VALUE reduce; \
|
|
85
|
+
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { Qnil, 0 }, { sym_reduce, 0 } }; \
|
|
86
|
+
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } }; \
|
|
87
|
+
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 3, 1, ain, aout }; \
|
|
88
|
+
\
|
|
89
|
+
GetNArray(self, na); \
|
|
90
|
+
if (na->ndim == 0) { \
|
|
91
|
+
return INT2FIX(0); \
|
|
92
|
+
} \
|
|
93
|
+
\
|
|
94
|
+
if (na->size > (~(u_int32_t)0)) { \
|
|
95
|
+
aout[0].type = numo_cInt64; \
|
|
96
|
+
idx = nary_new(numo_cInt64, na->ndim, na->shape); \
|
|
97
|
+
ndf.func = iter_##tDType##_min_index_index64; \
|
|
98
|
+
reduce = na_reduce_dimension( \
|
|
99
|
+
argc, argv, 1, &self, &ndf, iter_##tDType##_min_index_index64_nan \
|
|
100
|
+
); \
|
|
101
|
+
} else { \
|
|
102
|
+
aout[0].type = numo_cInt32; \
|
|
103
|
+
idx = nary_new(numo_cInt32, na->ndim, na->shape); \
|
|
104
|
+
ndf.func = iter_##tDType##_min_index_index32; \
|
|
105
|
+
reduce = na_reduce_dimension( \
|
|
106
|
+
argc, argv, 1, &self, &ndf, iter_##tDType##_min_index_index32_nan \
|
|
107
|
+
); \
|
|
108
|
+
} \
|
|
109
|
+
\
|
|
110
|
+
rb_funcall(idx, rb_intern("seq"), 0); \
|
|
111
|
+
\
|
|
112
|
+
return na_ndloop(&ndf, 3, self, idx, reduce); \
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#define DEF_NARRAY_INT_MIN_INDEX_METHOD_FUNC(tDType) \
|
|
116
|
+
static void iter_##tDType##_min_index_index64(na_loop_t* const lp) { \
|
|
117
|
+
size_t n; \
|
|
118
|
+
size_t idx; \
|
|
119
|
+
char* d_ptr; \
|
|
120
|
+
char* i_ptr; \
|
|
121
|
+
char* o_ptr; \
|
|
122
|
+
ssize_t d_step; \
|
|
123
|
+
ssize_t i_step; \
|
|
124
|
+
\
|
|
125
|
+
INIT_COUNTER(lp, n); \
|
|
126
|
+
INIT_PTR(lp, 0, d_ptr, d_step); \
|
|
127
|
+
\
|
|
128
|
+
idx = f_min_index(n, d_ptr, d_step); \
|
|
129
|
+
\
|
|
130
|
+
INIT_PTR(lp, 1, i_ptr, i_step); \
|
|
131
|
+
o_ptr = NDL_PTR(lp, 2); \
|
|
132
|
+
*(int64_t*)o_ptr = *(int64_t*)(i_ptr + i_step * idx); \
|
|
133
|
+
} \
|
|
134
|
+
\
|
|
135
|
+
static void iter_##tDType##_min_index_index32(na_loop_t* const lp) { \
|
|
136
|
+
size_t n; \
|
|
137
|
+
size_t idx; \
|
|
138
|
+
char* d_ptr; \
|
|
139
|
+
char* i_ptr; \
|
|
140
|
+
char* o_ptr; \
|
|
141
|
+
ssize_t d_step; \
|
|
142
|
+
ssize_t i_step; \
|
|
143
|
+
\
|
|
144
|
+
INIT_COUNTER(lp, n); \
|
|
145
|
+
INIT_PTR(lp, 0, d_ptr, d_step); \
|
|
146
|
+
\
|
|
147
|
+
idx = f_min_index(n, d_ptr, d_step); \
|
|
148
|
+
\
|
|
149
|
+
INIT_PTR(lp, 1, i_ptr, i_step); \
|
|
150
|
+
o_ptr = NDL_PTR(lp, 2); \
|
|
151
|
+
*(int32_t*)o_ptr = *(int32_t*)(i_ptr + i_step * idx); \
|
|
152
|
+
} \
|
|
153
|
+
\
|
|
154
|
+
static VALUE tDType##_min_index(int argc, VALUE* argv, VALUE self) { \
|
|
155
|
+
narray_t* na; \
|
|
156
|
+
VALUE idx; \
|
|
157
|
+
VALUE reduce; \
|
|
158
|
+
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { Qnil, 0 }, { sym_reduce, 0 } }; \
|
|
159
|
+
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } }; \
|
|
160
|
+
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 3, 1, ain, aout }; \
|
|
161
|
+
\
|
|
162
|
+
GetNArray(self, na); \
|
|
163
|
+
if (na->ndim == 0) { \
|
|
164
|
+
return INT2FIX(0); \
|
|
165
|
+
} \
|
|
166
|
+
\
|
|
167
|
+
if (na->size > (~(u_int32_t)0)) { \
|
|
168
|
+
aout[0].type = numo_cInt64; \
|
|
169
|
+
idx = nary_new(numo_cInt64, na->ndim, na->shape); \
|
|
170
|
+
ndf.func = iter_##tDType##_min_index_index64; \
|
|
171
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
|
|
172
|
+
} else { \
|
|
173
|
+
aout[0].type = numo_cInt32; \
|
|
174
|
+
idx = nary_new(numo_cInt32, na->ndim, na->shape); \
|
|
175
|
+
ndf.func = iter_##tDType##_min_index_index32; \
|
|
176
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
|
|
177
|
+
} \
|
|
178
|
+
\
|
|
179
|
+
rb_funcall(idx, rb_intern("seq"), 0); \
|
|
180
|
+
\
|
|
181
|
+
return na_ndloop(&ndf, 3, self, idx, reduce); \
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
#endif /* NUMO_NARRAY_MH_MIN_INDEX_H */
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MINIMUM_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MINIMUM_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_MINIMUM_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_s_minimum(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
|
+
\
|
|
14
|
+
INIT_COUNTER(lp, n); \
|
|
15
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
16
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
17
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
18
|
+
\
|
|
19
|
+
for (size_t i = 0; i < n; i++) { \
|
|
20
|
+
tDType x; \
|
|
21
|
+
tDType y; \
|
|
22
|
+
tDType z; \
|
|
23
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
24
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
25
|
+
GET_DATA(p3, tDType, z); \
|
|
26
|
+
z = f_minimum(x, y); \
|
|
27
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
28
|
+
} \
|
|
29
|
+
} \
|
|
30
|
+
\
|
|
31
|
+
static void iter_##tDType##_s_minimum_nan(na_loop_t* const lp) { \
|
|
32
|
+
size_t n; \
|
|
33
|
+
char* p1; \
|
|
34
|
+
char* p2; \
|
|
35
|
+
char* p3; \
|
|
36
|
+
ssize_t s1; \
|
|
37
|
+
ssize_t s2; \
|
|
38
|
+
ssize_t s3; \
|
|
39
|
+
\
|
|
40
|
+
INIT_COUNTER(lp, n); \
|
|
41
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
42
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
43
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
44
|
+
\
|
|
45
|
+
for (size_t i = 0; i < n; i++) { \
|
|
46
|
+
tDType x; \
|
|
47
|
+
tDType y; \
|
|
48
|
+
tDType z; \
|
|
49
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
50
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
51
|
+
GET_DATA(p3, tDType, z); \
|
|
52
|
+
z = f_minimum_nan(x, y); \
|
|
53
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
54
|
+
} \
|
|
55
|
+
} \
|
|
56
|
+
\
|
|
57
|
+
static VALUE tDType##_s_minimum(int argc, VALUE* argv, VALUE mod) { \
|
|
58
|
+
VALUE a1 = Qnil; \
|
|
59
|
+
VALUE a2 = Qnil; \
|
|
60
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
61
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
62
|
+
ndfunc_t ndf = { iter_##tDType##_s_minimum, STRIDE_LOOP_NIP, 2, 1, ain, aout }; \
|
|
63
|
+
\
|
|
64
|
+
VALUE kw_hash = Qnil; \
|
|
65
|
+
ID kw_table[1] = { id_nan }; \
|
|
66
|
+
VALUE opts[1] = { Qundef }; \
|
|
67
|
+
\
|
|
68
|
+
rb_scan_args(argc, argv, "20:", &a1, &a2, &kw_hash); \
|
|
69
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 1, opts); \
|
|
70
|
+
if (opts[0] != Qundef) { \
|
|
71
|
+
ndf.func = iter_##tDType##_s_minimum_nan; \
|
|
72
|
+
} \
|
|
73
|
+
\
|
|
74
|
+
return na_ndloop(&ndf, 2, a1, a2); \
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#define DEF_NARRAY_INT_MINIMUM_METHOD_FUNC(tDType, tNAryClass) \
|
|
78
|
+
static void iter_##tDType##_s_minimum(na_loop_t* const lp) { \
|
|
79
|
+
size_t n; \
|
|
80
|
+
char* p1; \
|
|
81
|
+
char* p2; \
|
|
82
|
+
char* p3; \
|
|
83
|
+
ssize_t s1; \
|
|
84
|
+
ssize_t s2; \
|
|
85
|
+
ssize_t s3; \
|
|
86
|
+
\
|
|
87
|
+
INIT_COUNTER(lp, n); \
|
|
88
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
89
|
+
INIT_PTR(lp, 1, p2, s2); \
|
|
90
|
+
INIT_PTR(lp, 2, p3, s3); \
|
|
91
|
+
\
|
|
92
|
+
for (size_t i = 0; i < n; i++) { \
|
|
93
|
+
tDType x; \
|
|
94
|
+
tDType y; \
|
|
95
|
+
tDType z; \
|
|
96
|
+
GET_DATA_STRIDE(p1, s1, tDType, x); \
|
|
97
|
+
GET_DATA_STRIDE(p2, s2, tDType, y); \
|
|
98
|
+
GET_DATA(p3, tDType, z); \
|
|
99
|
+
z = f_minimum(x, y); \
|
|
100
|
+
SET_DATA_STRIDE(p3, s3, tDType, z); \
|
|
101
|
+
} \
|
|
102
|
+
} \
|
|
103
|
+
\
|
|
104
|
+
static VALUE tDType##_s_minimum(int argc, VALUE* argv, VALUE mod) { \
|
|
105
|
+
VALUE a1 = Qnil; \
|
|
106
|
+
VALUE a2 = Qnil; \
|
|
107
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
108
|
+
ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
|
|
109
|
+
ndfunc_t ndf = { iter_##tDType##_s_minimum, STRIDE_LOOP_NIP, 2, 1, ain, aout }; \
|
|
110
|
+
\
|
|
111
|
+
rb_scan_args(argc, argv, "20", &a1, &a2); \
|
|
112
|
+
\
|
|
113
|
+
return na_ndloop(&ndf, 2, a1, a2); \
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#endif /* NUMO_NARRAY_MH_MINIMUM_H */
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#ifndef NUMO_NARRAY_MH_MINMAX_H
|
|
2
|
+
#define NUMO_NARRAY_MH_MINMAX_H 1
|
|
3
|
+
|
|
4
|
+
#define DEF_NARRAY_FLT_MINMAX_METHOD_FUNC(tDType, tNAryClass) \
|
|
5
|
+
static void iter_##tDType##_minmax(na_loop_t* const lp) { \
|
|
6
|
+
size_t n; \
|
|
7
|
+
char* p1; \
|
|
8
|
+
ssize_t s1; \
|
|
9
|
+
tDType xmin; \
|
|
10
|
+
tDType xmax; \
|
|
11
|
+
\
|
|
12
|
+
INIT_COUNTER(lp, n); \
|
|
13
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
14
|
+
\
|
|
15
|
+
f_minmax(n, p1, s1, &xmin, &xmax); \
|
|
16
|
+
\
|
|
17
|
+
*(tDType*)NDL_PTR(lp, 1) = xmin; \
|
|
18
|
+
*(tDType*)NDL_PTR(lp, 2) = xmax; \
|
|
19
|
+
} \
|
|
20
|
+
\
|
|
21
|
+
static void iter_##tDType##_minmax_nan(na_loop_t* const lp) { \
|
|
22
|
+
size_t n; \
|
|
23
|
+
char* p1; \
|
|
24
|
+
ssize_t s1; \
|
|
25
|
+
tDType xmin; \
|
|
26
|
+
tDType xmax; \
|
|
27
|
+
\
|
|
28
|
+
INIT_COUNTER(lp, n); \
|
|
29
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
30
|
+
\
|
|
31
|
+
f_minmax_nan(n, p1, s1, &xmin, &xmax); \
|
|
32
|
+
\
|
|
33
|
+
*(tDType*)NDL_PTR(lp, 1) = xmin; \
|
|
34
|
+
*(tDType*)NDL_PTR(lp, 2) = xmax; \
|
|
35
|
+
} \
|
|
36
|
+
\
|
|
37
|
+
static VALUE tDType##_minmax(int argc, VALUE* argv, VALUE self) { \
|
|
38
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
39
|
+
ndfunc_arg_out_t aout[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
40
|
+
ndfunc_t ndf = { \
|
|
41
|
+
iter_##tDType##_minmax, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 2, ain, aout \
|
|
42
|
+
}; \
|
|
43
|
+
VALUE reduce = \
|
|
44
|
+
na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_minmax_nan); \
|
|
45
|
+
\
|
|
46
|
+
return na_ndloop(&ndf, 2, self, reduce); \
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#define DEF_NARRAY_INT_MINMAX_METHOD_FUNC(tDType, tNAryClass) \
|
|
50
|
+
static void iter_##tDType##_minmax(na_loop_t* const lp) { \
|
|
51
|
+
size_t n; \
|
|
52
|
+
char* p1; \
|
|
53
|
+
ssize_t s1; \
|
|
54
|
+
tDType xmin; \
|
|
55
|
+
tDType xmax; \
|
|
56
|
+
\
|
|
57
|
+
INIT_COUNTER(lp, n); \
|
|
58
|
+
INIT_PTR(lp, 0, p1, s1); \
|
|
59
|
+
\
|
|
60
|
+
f_minmax(n, p1, s1, &xmin, &xmax); \
|
|
61
|
+
\
|
|
62
|
+
*(tDType*)NDL_PTR(lp, 1) = xmin; \
|
|
63
|
+
*(tDType*)NDL_PTR(lp, 2) = xmax; \
|
|
64
|
+
} \
|
|
65
|
+
\
|
|
66
|
+
static VALUE tDType##_minmax(int argc, VALUE* argv, VALUE self) { \
|
|
67
|
+
ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { sym_reduce, 0 } }; \
|
|
68
|
+
ndfunc_arg_out_t aout[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
|
|
69
|
+
ndfunc_t ndf = { \
|
|
70
|
+
iter_##tDType##_minmax, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 2, ain, aout \
|
|
71
|
+
}; \
|
|
72
|
+
VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
|
|
73
|
+
\
|
|
74
|
+
return na_ndloop(&ndf, 2, self, reduce); \
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#endif /* NUMO_NARRAY_MH_MINMAX_H */
|