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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/ext/numo/narray/numo/narray.h +2 -2
  4. data/ext/numo/narray/numo/types/robject.h +1 -1
  5. data/ext/numo/narray/src/mh/argmax.h +154 -0
  6. data/ext/numo/narray/src/mh/argmin.h +154 -0
  7. data/ext/numo/narray/src/mh/clip.h +115 -0
  8. data/ext/numo/narray/src/mh/cumprod.h +98 -0
  9. data/ext/numo/narray/src/mh/cumsum.h +98 -0
  10. data/ext/numo/narray/src/mh/eye.h +82 -0
  11. data/ext/numo/narray/src/mh/logseq.h +69 -0
  12. data/ext/numo/narray/src/mh/max.h +69 -0
  13. data/ext/numo/narray/src/mh/max_index.h +184 -0
  14. data/ext/numo/narray/src/mh/maximum.h +116 -0
  15. data/ext/numo/narray/src/mh/min.h +69 -0
  16. data/ext/numo/narray/src/mh/min_index.h +184 -0
  17. data/ext/numo/narray/src/mh/minimum.h +116 -0
  18. data/ext/numo/narray/src/mh/minmax.h +77 -0
  19. data/ext/numo/narray/src/mh/mulsum.h +185 -0
  20. data/ext/numo/narray/src/mh/prod.h +69 -0
  21. data/ext/numo/narray/src/mh/ptp.h +69 -0
  22. data/ext/numo/narray/src/mh/rand.h +315 -0
  23. data/ext/numo/narray/src/mh/seq.h +130 -0
  24. data/ext/numo/narray/src/mh/sum.h +69 -0
  25. data/ext/numo/narray/src/t_dcomplex.c +131 -667
  26. data/ext/numo/narray/src/t_dfloat.c +40 -1288
  27. data/ext/numo/narray/src/t_int16.c +262 -1161
  28. data/ext/numo/narray/src/t_int32.c +263 -1161
  29. data/ext/numo/narray/src/t_int64.c +262 -1163
  30. data/ext/numo/narray/src/t_int8.c +262 -1159
  31. data/ext/numo/narray/src/t_robject.c +427 -1675
  32. data/ext/numo/narray/src/t_scomplex.c +131 -667
  33. data/ext/numo/narray/src/t_sfloat.c +40 -1288
  34. data/ext/numo/narray/src/t_uint16.c +262 -1161
  35. data/ext/numo/narray/src/t_uint32.c +262 -1161
  36. data/ext/numo/narray/src/t_uint64.c +262 -1163
  37. data/ext/numo/narray/src/t_uint8.c +262 -1161
  38. data/lib/numo/narray.rb +3 -1
  39. metadata +23 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac58b88ae88791564ef1153354e10da361bc4145961d5b14aa7d58a0f7eb810f
4
- data.tar.gz: c98b9b9ac97a1557f0497322d9eacfd9979a9a72949847b74448679bb5570aca
3
+ metadata.gz: 9f5745729ac9808d98856b30963b19d93cfec3ca0502b4b9db35023094ceb009
4
+ data.tar.gz: 38252691a0d86e3f7d3e5280bec28081effce8f40596e56b21d3e23205198350
5
5
  SHA512:
6
- metadata.gz: b62119454ea0c21d7ac79f5f24ade6fff1201ce1d91148856ab0a017d9d63acb1755d4c9aa1a159942d99b13a19b7f2d13611ec16ba039defb6498f0656f3264
7
- data.tar.gz: 154b2cc17b24d753e81f4f98b910bec75b698272463351dc0a38071037c420f565164231f94e270bfc41bbbb12829d7154632f3821dc89ce1c821e66b27e891f
6
+ metadata.gz: 94c876a77295498c07aea51465e193eb054d0b9936df76ff709ae6e6c677d908a705d9692595af6e60faaddd517b91cdb42356828bee6b40e8b3bcff1c9e114e
7
+ data.tar.gz: cf8005eff8efc53fc55641869cc18824dd11ae4be4f93618ba586e632f6aa94643b500fcdf4239b47eaec9b6870dcf080900e35484309101bb34557d9f289bec
data/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
1
  BSD 3-Clause License
2
2
 
3
3
  Copyright (c) 1999-2025, Masahiro TANAKA
4
- Copyright (c) 2025, Atsushi TATSUMA
4
+ Copyright (c) 2025-2026, Atsushi TATSUMA
5
5
  All rights reserved.
6
6
 
7
7
  Redistribution and use in source and binary forms, with or without
@@ -13,8 +13,8 @@ extern "C" {
13
13
  #endif
14
14
  #endif
15
15
 
16
- #define NARRAY_VERSION "0.9.9"
17
- #define NARRAY_VERSION_CODE 990
16
+ #define NARRAY_VERSION "0.9.11"
17
+ #define NARRAY_VERSION_CODE 9110
18
18
 
19
19
  #include <math.h>
20
20
  #include "numo/compat.h"
@@ -21,5 +21,5 @@ inline static int robj_nearly_eq(VALUE vx, VALUE vy) {
21
21
 
22
22
  /* generates a random number on [0,1)-real-interval */
23
23
  inline static dtype m_rand(dtype max) {
24
- return DBL2NUM(genrand_res53_mix() * max);
24
+ return DBL2NUM(genrand_res53_mix() * NUM2DBL(max));
25
25
  }
@@ -0,0 +1,154 @@
1
+ #ifndef NUMO_NARRAY_MH_ARGMAX_H
2
+ #define NUMO_NARRAY_MH_ARGMAX_H 1
3
+
4
+ #define DEF_NARRAY_FLT_ARGMAX_METHOD_FUNC(tDType) \
5
+ static void iter_##tDType##_argmax_arg64(na_loop_t* const lp) { \
6
+ size_t n; \
7
+ size_t idx; \
8
+ char* d_ptr; \
9
+ char* o_ptr; \
10
+ ssize_t d_step; \
11
+ \
12
+ INIT_COUNTER(lp, n); \
13
+ INIT_PTR(lp, 0, d_ptr, d_step); \
14
+ \
15
+ idx = f_max_index(n, d_ptr, d_step); \
16
+ \
17
+ o_ptr = NDL_PTR(lp, 1); \
18
+ *(int64_t*)o_ptr = (int64_t)idx; \
19
+ } \
20
+ \
21
+ static void iter_##tDType##_argmax_arg32(na_loop_t* const lp) { \
22
+ size_t n; \
23
+ size_t idx; \
24
+ char* d_ptr; \
25
+ char* o_ptr; \
26
+ ssize_t d_step; \
27
+ \
28
+ INIT_COUNTER(lp, n); \
29
+ INIT_PTR(lp, 0, d_ptr, d_step); \
30
+ \
31
+ idx = f_max_index(n, d_ptr, d_step); \
32
+ \
33
+ o_ptr = NDL_PTR(lp, 1); \
34
+ *(int32_t*)o_ptr = (int32_t)idx; \
35
+ } \
36
+ \
37
+ static void iter_##tDType##_argmax_arg64_nan(na_loop_t* const lp) { \
38
+ size_t n; \
39
+ size_t idx; \
40
+ char* d_ptr; \
41
+ char* o_ptr; \
42
+ ssize_t d_step; \
43
+ \
44
+ INIT_COUNTER(lp, n); \
45
+ INIT_PTR(lp, 0, d_ptr, d_step); \
46
+ \
47
+ idx = f_max_index_nan(n, d_ptr, d_step); \
48
+ \
49
+ o_ptr = NDL_PTR(lp, 1); \
50
+ *(int64_t*)o_ptr = (int64_t)idx; \
51
+ } \
52
+ \
53
+ static void iter_##tDType##_argmax_arg32_nan(na_loop_t* const lp) { \
54
+ size_t n; \
55
+ size_t idx; \
56
+ char* d_ptr; \
57
+ char* o_ptr; \
58
+ ssize_t d_step; \
59
+ \
60
+ INIT_COUNTER(lp, n); \
61
+ INIT_PTR(lp, 0, d_ptr, d_step); \
62
+ \
63
+ idx = f_max_index_nan(n, d_ptr, d_step); \
64
+ \
65
+ o_ptr = NDL_PTR(lp, 1); \
66
+ *(int32_t*)o_ptr = (int32_t)idx; \
67
+ } \
68
+ \
69
+ static VALUE tDType##_argmax(int argc, VALUE* argv, VALUE self) { \
70
+ narray_t* na; \
71
+ VALUE reduce; \
72
+ ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } }; \
73
+ ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } }; \
74
+ ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout }; \
75
+ \
76
+ GetNArray(self, na); \
77
+ if (na->ndim == 0) { \
78
+ return INT2FIX(0); \
79
+ } \
80
+ \
81
+ if (na->size > (~(u_int32_t)0)) { \
82
+ aout[0].type = numo_cInt64; \
83
+ ndf.func = iter_##tDType##_argmax_arg64; \
84
+ reduce = \
85
+ na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_argmax_arg64_nan); \
86
+ } else { \
87
+ aout[0].type = numo_cInt32; \
88
+ ndf.func = iter_##tDType##_argmax_arg32; \
89
+ reduce = \
90
+ na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_argmax_arg32_nan); \
91
+ } \
92
+ \
93
+ return na_ndloop(&ndf, 2, self, reduce); \
94
+ }
95
+
96
+ #define DEF_NARRAY_INT_ARGMAX_METHOD_FUNC(tDType) \
97
+ static void iter_##tDType##_argmax_arg64(na_loop_t* const lp) { \
98
+ size_t n; \
99
+ size_t idx; \
100
+ char* d_ptr; \
101
+ char* o_ptr; \
102
+ ssize_t d_step; \
103
+ \
104
+ INIT_COUNTER(lp, n); \
105
+ INIT_PTR(lp, 0, d_ptr, d_step); \
106
+ \
107
+ idx = f_max_index(n, d_ptr, d_step); \
108
+ \
109
+ o_ptr = NDL_PTR(lp, 1); \
110
+ *(int64_t*)o_ptr = (int64_t)idx; \
111
+ } \
112
+ \
113
+ static void iter_##tDType##_argmax_arg32(na_loop_t* const lp) { \
114
+ size_t n; \
115
+ size_t idx; \
116
+ char* d_ptr; \
117
+ char* o_ptr; \
118
+ ssize_t d_step; \
119
+ \
120
+ INIT_COUNTER(lp, n); \
121
+ INIT_PTR(lp, 0, d_ptr, d_step); \
122
+ \
123
+ idx = f_max_index(n, d_ptr, d_step); \
124
+ \
125
+ o_ptr = NDL_PTR(lp, 1); \
126
+ *(int32_t*)o_ptr = (int32_t)idx; \
127
+ } \
128
+ \
129
+ static VALUE tDType##_argmax(int argc, VALUE* argv, VALUE self) { \
130
+ narray_t* na; \
131
+ VALUE reduce; \
132
+ ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } }; \
133
+ ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } }; \
134
+ ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout }; \
135
+ \
136
+ GetNArray(self, na); \
137
+ if (na->ndim == 0) { \
138
+ return INT2FIX(0); \
139
+ } \
140
+ \
141
+ if (na->size > (~(u_int32_t)0)) { \
142
+ aout[0].type = numo_cInt64; \
143
+ ndf.func = iter_##tDType##_argmax_arg64; \
144
+ reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
145
+ } else { \
146
+ aout[0].type = numo_cInt32; \
147
+ ndf.func = iter_##tDType##_argmax_arg32; \
148
+ reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
149
+ } \
150
+ \
151
+ return na_ndloop(&ndf, 2, self, reduce); \
152
+ }
153
+
154
+ #endif /* NUMO_NARRAY_MH_ARGMAX_H */
@@ -0,0 +1,154 @@
1
+ #ifndef NUMO_NARRAY_MH_ARGMIN_H
2
+ #define NUMO_NARRAY_MH_ARGMIN_H 1
3
+
4
+ #define DEF_NARRAY_FLT_ARGMIN_METHOD_FUNC(tDType) \
5
+ static void iter_##tDType##_argmin_arg64(na_loop_t* const lp) { \
6
+ size_t n; \
7
+ size_t idx; \
8
+ char* d_ptr; \
9
+ char* o_ptr; \
10
+ ssize_t d_step; \
11
+ \
12
+ INIT_COUNTER(lp, n); \
13
+ INIT_PTR(lp, 0, d_ptr, d_step); \
14
+ \
15
+ idx = f_min_index(n, d_ptr, d_step); \
16
+ \
17
+ o_ptr = NDL_PTR(lp, 1); \
18
+ *(int64_t*)o_ptr = (int64_t)idx; \
19
+ } \
20
+ \
21
+ static void iter_##tDType##_argmin_arg32(na_loop_t* const lp) { \
22
+ size_t n; \
23
+ size_t idx; \
24
+ char* d_ptr; \
25
+ char* o_ptr; \
26
+ ssize_t d_step; \
27
+ \
28
+ INIT_COUNTER(lp, n); \
29
+ INIT_PTR(lp, 0, d_ptr, d_step); \
30
+ \
31
+ idx = f_min_index(n, d_ptr, d_step); \
32
+ \
33
+ o_ptr = NDL_PTR(lp, 1); \
34
+ *(int32_t*)o_ptr = (int32_t)idx; \
35
+ } \
36
+ \
37
+ static void iter_##tDType##_argmin_arg64_nan(na_loop_t* const lp) { \
38
+ size_t n; \
39
+ size_t idx; \
40
+ char* d_ptr; \
41
+ char* o_ptr; \
42
+ ssize_t d_step; \
43
+ \
44
+ INIT_COUNTER(lp, n); \
45
+ INIT_PTR(lp, 0, d_ptr, d_step); \
46
+ \
47
+ idx = f_min_index_nan(n, d_ptr, d_step); \
48
+ \
49
+ o_ptr = NDL_PTR(lp, 1); \
50
+ *(int64_t*)o_ptr = (int64_t)idx; \
51
+ } \
52
+ \
53
+ static void iter_##tDType##_argmin_arg32_nan(na_loop_t* const lp) { \
54
+ size_t n; \
55
+ size_t idx; \
56
+ char* d_ptr; \
57
+ char* o_ptr; \
58
+ ssize_t d_step; \
59
+ \
60
+ INIT_COUNTER(lp, n); \
61
+ INIT_PTR(lp, 0, d_ptr, d_step); \
62
+ \
63
+ idx = f_min_index_nan(n, d_ptr, d_step); \
64
+ \
65
+ o_ptr = NDL_PTR(lp, 1); \
66
+ *(int32_t*)o_ptr = (int32_t)idx; \
67
+ } \
68
+ \
69
+ static VALUE tDType##_argmin(int argc, VALUE* argv, VALUE self) { \
70
+ narray_t* na; \
71
+ VALUE reduce; \
72
+ ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } }; \
73
+ ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } }; \
74
+ ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout }; \
75
+ \
76
+ GetNArray(self, na); \
77
+ if (na->ndim == 0) { \
78
+ return INT2FIX(0); \
79
+ } \
80
+ \
81
+ if (na->size > (~(u_int32_t)0)) { \
82
+ aout[0].type = numo_cInt64; \
83
+ ndf.func = iter_##tDType##_argmin_arg64; \
84
+ reduce = \
85
+ na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_argmin_arg64_nan); \
86
+ } else { \
87
+ aout[0].type = numo_cInt32; \
88
+ ndf.func = iter_##tDType##_argmin_arg32; \
89
+ reduce = \
90
+ na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_##tDType##_argmin_arg32_nan); \
91
+ } \
92
+ \
93
+ return na_ndloop(&ndf, 2, self, reduce); \
94
+ }
95
+
96
+ #define DEF_NARRAY_INT_ARGMIN_METHOD_FUNC(tDType) \
97
+ static void iter_##tDType##_argmin_arg64(na_loop_t* const lp) { \
98
+ size_t n; \
99
+ size_t idx; \
100
+ char* d_ptr; \
101
+ char* o_ptr; \
102
+ ssize_t d_step; \
103
+ \
104
+ INIT_COUNTER(lp, n); \
105
+ INIT_PTR(lp, 0, d_ptr, d_step); \
106
+ \
107
+ idx = f_min_index(n, d_ptr, d_step); \
108
+ \
109
+ o_ptr = NDL_PTR(lp, 1); \
110
+ *(int64_t*)o_ptr = (int64_t)idx; \
111
+ } \
112
+ \
113
+ static void iter_##tDType##_argmin_arg32(na_loop_t* const lp) { \
114
+ size_t n; \
115
+ size_t idx; \
116
+ char* d_ptr; \
117
+ char* o_ptr; \
118
+ ssize_t d_step; \
119
+ \
120
+ INIT_COUNTER(lp, n); \
121
+ INIT_PTR(lp, 0, d_ptr, d_step); \
122
+ \
123
+ idx = f_min_index(n, d_ptr, d_step); \
124
+ \
125
+ o_ptr = NDL_PTR(lp, 1); \
126
+ *(int32_t*)o_ptr = (int32_t)idx; \
127
+ } \
128
+ \
129
+ static VALUE tDType##_argmin(int argc, VALUE* argv, VALUE self) { \
130
+ narray_t* na; \
131
+ VALUE reduce; \
132
+ ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } }; \
133
+ ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } }; \
134
+ ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout }; \
135
+ \
136
+ GetNArray(self, na); \
137
+ if (na->ndim == 0) { \
138
+ return INT2FIX(0); \
139
+ } \
140
+ \
141
+ if (na->size > (~(u_int32_t)0)) { \
142
+ aout[0].type = numo_cInt64; \
143
+ ndf.func = iter_##tDType##_argmin_arg64; \
144
+ reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
145
+ } else { \
146
+ aout[0].type = numo_cInt32; \
147
+ ndf.func = iter_##tDType##_argmin_arg32; \
148
+ reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0); \
149
+ } \
150
+ \
151
+ return na_ndloop(&ndf, 2, self, reduce); \
152
+ }
153
+
154
+ #endif /* NUMO_NARRAY_MH_ARGMIN_H */
@@ -0,0 +1,115 @@
1
+ #ifndef NUMO_NARRAY_MH_CLIP_H
2
+ #define NUMO_NARRAY_MH_CLIP_H 1
3
+
4
+ #define DEF_NARRAY_CLIP_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_clip(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
+ tDType x; \
16
+ tDType min; \
17
+ tDType max; \
18
+ \
19
+ INIT_COUNTER(lp, n); \
20
+ INIT_PTR(lp, 0, p1, s1); \
21
+ INIT_PTR(lp, 1, p2, s2); \
22
+ INIT_PTR(lp, 2, p3, s3); \
23
+ INIT_PTR(lp, 3, p4, s4); \
24
+ \
25
+ for (size_t i = 0; i < n; i++) { \
26
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
27
+ GET_DATA_STRIDE(p2, s2, tDType, min); \
28
+ GET_DATA_STRIDE(p3, s3, tDType, max); \
29
+ if (m_gt(min, max)) { \
30
+ rb_raise(nary_eOperationError, "min is greater than max"); \
31
+ } \
32
+ if (m_lt(x, min)) { \
33
+ x = min; \
34
+ } \
35
+ if (m_gt(x, max)) { \
36
+ x = max; \
37
+ } \
38
+ SET_DATA_STRIDE(p4, s4, tDType, x); \
39
+ } \
40
+ } \
41
+ \
42
+ static void iter_##tDType##_clip_min(na_loop_t* const lp) { \
43
+ size_t n; \
44
+ char* p1; \
45
+ char* p2; \
46
+ char* p3; \
47
+ ssize_t s1; \
48
+ ssize_t s2; \
49
+ ssize_t s3; \
50
+ tDType x; \
51
+ tDType min; \
52
+ \
53
+ INIT_COUNTER(lp, n); \
54
+ INIT_PTR(lp, 0, p1, s1); \
55
+ INIT_PTR(lp, 1, p2, s2); \
56
+ INIT_PTR(lp, 2, p3, s3); \
57
+ \
58
+ for (size_t i = 0; i < n; i++) { \
59
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
60
+ GET_DATA_STRIDE(p2, s2, tDType, min); \
61
+ if (m_lt(x, min)) { \
62
+ x = min; \
63
+ } \
64
+ SET_DATA_STRIDE(p3, s3, tDType, x); \
65
+ } \
66
+ } \
67
+ \
68
+ static void iter_##tDType##_clip_max(na_loop_t* const lp) { \
69
+ size_t n; \
70
+ char* p1; \
71
+ char* p2; \
72
+ char* p3; \
73
+ ssize_t s1; \
74
+ ssize_t s2; \
75
+ ssize_t s3; \
76
+ tDType x; \
77
+ tDType max; \
78
+ \
79
+ INIT_COUNTER(lp, n); \
80
+ INIT_PTR(lp, 0, p1, s1); \
81
+ INIT_PTR(lp, 1, p2, s2); \
82
+ INIT_PTR(lp, 2, p3, s3); \
83
+ \
84
+ for (size_t i = 0; i < n; i++) { \
85
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
86
+ GET_DATA_STRIDE(p2, s2, tDType, max); \
87
+ if (m_gt(x, max)) { \
88
+ x = max; \
89
+ } \
90
+ SET_DATA_STRIDE(p3, s3, tDType, x); \
91
+ } \
92
+ } \
93
+ \
94
+ static VALUE tDType##_clip(VALUE self, VALUE min, VALUE max) { \
95
+ ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { tNAryClass, 0 }, { tNAryClass, 0 } }; \
96
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
97
+ ndfunc_t ndf_min = { iter_##tDType##_clip_min, STRIDE_LOOP, 2, 1, ain, aout }; \
98
+ ndfunc_t ndf_max = { iter_##tDType##_clip_max, STRIDE_LOOP, 2, 1, ain, aout }; \
99
+ ndfunc_t ndf_both = { iter_##tDType##_clip, STRIDE_LOOP, 3, 1, ain, aout }; \
100
+ \
101
+ if (RTEST(min)) { \
102
+ if (RTEST(max)) { \
103
+ return na_ndloop(&ndf_both, 3, self, min, max); \
104
+ } \
105
+ return na_ndloop(&ndf_min, 2, self, min); \
106
+ } else { \
107
+ if (RTEST(max)) { \
108
+ return na_ndloop(&ndf_max, 2, self, max); \
109
+ } \
110
+ } \
111
+ rb_raise(rb_eArgError, "min and max are not given"); \
112
+ return Qnil; \
113
+ }
114
+
115
+ #endif /* NUMO_NARRAY_MH_CLIP_H */
@@ -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 */