numo-narray-alt 0.9.11 → 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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/README.md +7 -0
  4. data/ext/numo/narray/numo/narray.h +2 -2
  5. data/ext/numo/narray/numo/types/robj_macro.h +1 -1
  6. data/ext/numo/narray/src/mh/bincount.h +233 -0
  7. data/ext/numo/narray/src/mh/bit/and.h +225 -0
  8. data/ext/numo/narray/src/mh/bit/left_shift.h +225 -0
  9. data/ext/numo/narray/src/mh/bit/not.h +173 -0
  10. data/ext/numo/narray/src/mh/bit/or.h +225 -0
  11. data/ext/numo/narray/src/mh/bit/right_shift.h +225 -0
  12. data/ext/numo/narray/src/mh/bit/xor.h +225 -0
  13. data/ext/numo/narray/src/mh/coerce_cast.h +9 -0
  14. data/ext/numo/narray/src/mh/comp/binary_func.h +37 -0
  15. data/ext/numo/narray/src/mh/comp/eq.h +26 -0
  16. data/ext/numo/narray/src/mh/comp/ge.h +26 -0
  17. data/ext/numo/narray/src/mh/comp/gt.h +26 -0
  18. data/ext/numo/narray/src/mh/comp/le.h +26 -0
  19. data/ext/numo/narray/src/mh/comp/lt.h +26 -0
  20. data/ext/numo/narray/src/mh/comp/ne.h +26 -0
  21. data/ext/numo/narray/src/mh/comp/nearly_eq.h +26 -0
  22. data/ext/numo/narray/src/mh/divmod.h +142 -0
  23. data/ext/numo/narray/src/mh/eye.h +1 -1
  24. data/ext/numo/narray/src/mh/fill.h +94 -0
  25. data/ext/numo/narray/src/mh/format.h +108 -0
  26. data/ext/numo/narray/src/mh/format_to_a.h +89 -0
  27. data/ext/numo/narray/src/mh/inspect.h +33 -0
  28. data/ext/numo/narray/src/mh/isfinite.h +42 -0
  29. data/ext/numo/narray/src/mh/isinf.h +42 -0
  30. data/ext/numo/narray/src/mh/isnan.h +42 -0
  31. data/ext/numo/narray/src/mh/isneginf.h +42 -0
  32. data/ext/numo/narray/src/mh/isposinf.h +42 -0
  33. data/ext/numo/narray/src/mh/math/acos.h +2 -2
  34. data/ext/numo/narray/src/mh/math/acosh.h +2 -2
  35. data/ext/numo/narray/src/mh/math/asin.h +2 -2
  36. data/ext/numo/narray/src/mh/math/asinh.h +2 -2
  37. data/ext/numo/narray/src/mh/math/atan.h +2 -2
  38. data/ext/numo/narray/src/mh/math/atan2.h +3 -3
  39. data/ext/numo/narray/src/mh/math/atanh.h +2 -2
  40. data/ext/numo/narray/src/mh/math/cbrt.h +2 -2
  41. data/ext/numo/narray/src/mh/math/cos.h +2 -2
  42. data/ext/numo/narray/src/mh/math/cosh.h +2 -2
  43. data/ext/numo/narray/src/mh/math/erf.h +2 -2
  44. data/ext/numo/narray/src/mh/math/erfc.h +2 -2
  45. data/ext/numo/narray/src/mh/math/exp.h +2 -2
  46. data/ext/numo/narray/src/mh/math/exp10.h +2 -2
  47. data/ext/numo/narray/src/mh/math/exp2.h +2 -2
  48. data/ext/numo/narray/src/mh/math/expm1.h +2 -2
  49. data/ext/numo/narray/src/mh/math/frexp.h +3 -3
  50. data/ext/numo/narray/src/mh/math/hypot.h +3 -3
  51. data/ext/numo/narray/src/mh/math/ldexp.h +3 -3
  52. data/ext/numo/narray/src/mh/math/log.h +2 -2
  53. data/ext/numo/narray/src/mh/math/log10.h +2 -2
  54. data/ext/numo/narray/src/mh/math/log1p.h +2 -2
  55. data/ext/numo/narray/src/mh/math/log2.h +2 -2
  56. data/ext/numo/narray/src/mh/math/sin.h +2 -2
  57. data/ext/numo/narray/src/mh/math/sinc.h +2 -2
  58. data/ext/numo/narray/src/mh/math/sinh.h +2 -2
  59. data/ext/numo/narray/src/mh/math/sqrt.h +8 -8
  60. data/ext/numo/narray/src/mh/math/tan.h +2 -2
  61. data/ext/numo/narray/src/mh/math/tanh.h +2 -2
  62. data/ext/numo/narray/src/mh/math/unary_func.h +3 -3
  63. data/ext/numo/narray/src/mh/minus.h +125 -0
  64. data/ext/numo/narray/src/mh/op/add.h +78 -0
  65. data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
  66. data/ext/numo/narray/src/mh/op/div.h +118 -0
  67. data/ext/numo/narray/src/mh/op/mod.h +108 -0
  68. data/ext/numo/narray/src/mh/op/mul.h +78 -0
  69. data/ext/numo/narray/src/mh/op/sub.h +78 -0
  70. data/ext/numo/narray/src/mh/pow.h +197 -0
  71. data/ext/numo/narray/src/mh/rand.h +2 -2
  72. data/ext/numo/narray/src/mh/rand_norm.h +125 -0
  73. data/ext/numo/narray/src/mh/reciprocal.h +125 -0
  74. data/ext/numo/narray/src/mh/round/ceil.h +11 -0
  75. data/ext/numo/narray/src/mh/round/floor.h +11 -0
  76. data/ext/numo/narray/src/mh/round/rint.h +9 -0
  77. data/ext/numo/narray/src/mh/round/round.h +11 -0
  78. data/ext/numo/narray/src/mh/round/trunc.h +11 -0
  79. data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
  80. data/ext/numo/narray/src/mh/sign.h +125 -0
  81. data/ext/numo/narray/src/mh/square.h +125 -0
  82. data/ext/numo/narray/src/mh/to_a.h +78 -0
  83. data/ext/numo/narray/src/t_bit.c +45 -234
  84. data/ext/numo/narray/src/t_dcomplex.c +457 -2075
  85. data/ext/numo/narray/src/t_dfloat.c +154 -2560
  86. data/ext/numo/narray/src/t_int16.c +408 -2542
  87. data/ext/numo/narray/src/t_int32.c +408 -2542
  88. data/ext/numo/narray/src/t_int64.c +408 -2542
  89. data/ext/numo/narray/src/t_int8.c +409 -2138
  90. data/ext/numo/narray/src/t_robject.c +376 -2161
  91. data/ext/numo/narray/src/t_scomplex.c +435 -2053
  92. data/ext/numo/narray/src/t_sfloat.c +149 -2557
  93. data/ext/numo/narray/src/t_uint16.c +407 -2537
  94. data/ext/numo/narray/src/t_uint32.c +407 -2537
  95. data/ext/numo/narray/src/t_uint64.c +407 -2537
  96. data/ext/numo/narray/src/t_uint8.c +407 -2132
  97. metadata +47 -2
@@ -0,0 +1,125 @@
1
+ #ifndef NUMO_NARRAY_MH_RECIPROCAL_H
2
+ #define NUMO_NARRAY_MH_RECIPROCAL_H 1
3
+
4
+ #define DEF_NARRAY_RECIPROCAL_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_reciprocal(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_reciprocal(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_reciprocal(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_reciprocal(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_reciprocal(((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_reciprocal(*(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_reciprocal(x); \
58
+ SET_DATA_STRIDE(p2, s2, tDType, x); \
59
+ } \
60
+ } \
61
+ } \
62
+ } \
63
+ \
64
+ static VALUE tDType##_reciprocal(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##_reciprocal, FULL_LOOP, 1, 1, ain, aout }; \
68
+ return na_ndloop(&ndf, 1, self); \
69
+ }
70
+
71
+ #define DEF_NARRAY_INT8_RECIPROCAL_METHOD_FUNC(tDType, tNAryClass) \
72
+ static void iter_##tDType##_reciprocal(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_reciprocal(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_reciprocal(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_reciprocal(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_reciprocal(*(tDType*)p1); \
108
+ p1 += s1; \
109
+ p2 += s2; \
110
+ } \
111
+ } \
112
+ } \
113
+ } \
114
+ \
115
+ static VALUE tDType##_reciprocal(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##_reciprocal, FULL_LOOP, 1, 1, ain, aout }; \
119
+ return na_ndloop(&ndf, 1, self); \
120
+ }
121
+
122
+ #define DEF_NARRAY_ROBJ_RECIPROCAL_METHOD_FUNC() \
123
+ DEF_NARRAY_INT8_RECIPROCAL_METHOD_FUNC(robject, numo_cRObject)
124
+
125
+ #endif /* NUMO_NARRAY_MH_RECIPROCAL_H */
@@ -0,0 +1,11 @@
1
+ #ifndef NUMO_NARRAY_MH_ROUND_CEIL_H
2
+ #define NUMO_NARRAY_MH_ROUND_CEIL_H 1
3
+
4
+ #include "unary_func.h"
5
+
6
+ #define DEF_NARRAY_FLT_CEIL_METHOD_FUNC(tDType, tNAryClass) \
7
+ DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(ceil, tDType, tNAryClass)
8
+
9
+ #define DEF_NARRAY_ROBJ_CEIL_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(ceil)
10
+
11
+ #endif /* NUMO_NARRAY_MH_ROUND_CEIL_H */
@@ -0,0 +1,11 @@
1
+ #ifndef NUMO_NARRAY_MH_ROUND_FLOOR_H
2
+ #define NUMO_NARRAY_MH_ROUND_FLOOR_H 1
3
+
4
+ #include "unary_func.h"
5
+
6
+ #define DEF_NARRAY_FLT_FLOOR_METHOD_FUNC(tDType, tNAryClass) \
7
+ DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(floor, tDType, tNAryClass)
8
+
9
+ #define DEF_NARRAY_ROBJ_FLOOR_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(floor)
10
+
11
+ #endif /* NUMO_NARRAY_MH_ROUND_FLOOR_H */
@@ -0,0 +1,9 @@
1
+ #ifndef NUMO_NARRAY_MH_ROUND_RINT_H
2
+ #define NUMO_NARRAY_MH_ROUND_RINT_H 1
3
+
4
+ #include "unary_func.h"
5
+
6
+ #define DEF_NARRAY_FLT_RINT_METHOD_FUNC(tDType, tNAryClass) \
7
+ DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(rint, tDType, tNAryClass)
8
+
9
+ #endif /* NUMO_NARRAY_MH_ROUND_RINT_H */
@@ -0,0 +1,11 @@
1
+ #ifndef NUMO_NARRAY_MH_ROUND_ROUND_H
2
+ #define NUMO_NARRAY_MH_ROUND_ROUND_H 1
3
+
4
+ #include "unary_func.h"
5
+
6
+ #define DEF_NARRAY_FLT_ROUND_METHOD_FUNC(tDType, tNAryClass) \
7
+ DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(round, tDType, tNAryClass)
8
+
9
+ #define DEF_NARRAY_ROBJ_ROUND_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(round)
10
+
11
+ #endif /* NUMO_NARRAY_MH_ROUND_ROUND_H */
@@ -0,0 +1,11 @@
1
+ #ifndef NUMO_NARRAY_MH_ROUND_TRUNC_H
2
+ #define NUMO_NARRAY_MH_ROUND_TRUNC_H 1
3
+
4
+ #include "unary_func.h"
5
+
6
+ #define DEF_NARRAY_FLT_TRUNC_METHOD_FUNC(tDType, tNAryClass) \
7
+ DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(trunc, tDType, tNAryClass)
8
+
9
+ #define DEF_NARRAY_ROBJ_TRUNC_METHOD_FUNC() DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(trunc)
10
+
11
+ #endif /* NUMO_NARRAY_MH_ROUND_TRUNC_H */
@@ -0,0 +1,127 @@
1
+ #ifndef NUMO_NARRAY_MH_ROUND_UNARY_FUNC_H
2
+ #define NUMO_NARRAY_MH_ROUND_UNARY_FUNC_H 1
3
+
4
+ #define DEF_NARRAY_FLT_UNARY_ROUND_METHOD_FUNC(fRoundFunc, tDType, tNAryClass) \
5
+ static void iter_##tDType##_##fRoundFunc(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
+ tDType x; \
14
+ \
15
+ INIT_COUNTER(lp, n); \
16
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
17
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
18
+ \
19
+ if (idx1) { \
20
+ if (idx2) { \
21
+ for (size_t i = 0; i < n; i++) { \
22
+ GET_DATA_INDEX(p1, idx1, tDType, x); \
23
+ x = m_##fRoundFunc(x); \
24
+ SET_DATA_INDEX(p2, idx2, tDType, x); \
25
+ } \
26
+ } else { \
27
+ for (size_t i = 0; i < n; i++) { \
28
+ GET_DATA_INDEX(p1, idx1, tDType, x); \
29
+ x = m_##fRoundFunc(x); \
30
+ SET_DATA_STRIDE(p2, s2, tDType, x); \
31
+ } \
32
+ } \
33
+ } else { \
34
+ if (idx2) { \
35
+ for (size_t i = 0; i < n; i++) { \
36
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
37
+ x = m_##fRoundFunc(x); \
38
+ SET_DATA_INDEX(p2, idx2, tDType, x); \
39
+ } \
40
+ } else { \
41
+ if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType))) { \
42
+ if (s1 == sizeof(tDType) && s2 == sizeof(tDType)) { \
43
+ for (size_t i = 0; i < n; i++) { \
44
+ ((tDType*)p2)[i] = m_##fRoundFunc(((tDType*)p1)[i]); \
45
+ } \
46
+ return; \
47
+ } \
48
+ if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType))) { \
49
+ for (size_t i = 0; i < n; i++) { \
50
+ *(tDType*)p2 = m_##fRoundFunc(*(tDType*)p1); \
51
+ p1 += s1; \
52
+ p2 += s2; \
53
+ } \
54
+ return; \
55
+ } \
56
+ } \
57
+ for (size_t i = 0; i < n; i++) { \
58
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
59
+ x = m_##fRoundFunc(x); \
60
+ SET_DATA_STRIDE(p2, s2, tDType, x); \
61
+ } \
62
+ } \
63
+ } \
64
+ } \
65
+ \
66
+ static VALUE tDType##_##fRoundFunc(VALUE self) { \
67
+ ndfunc_arg_in_t ain[1] = { { tNAryClass, 0 } }; \
68
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
69
+ ndfunc_t ndf = { iter_##tDType##_##fRoundFunc, FULL_LOOP, 1, 1, ain, aout }; \
70
+ return na_ndloop(&ndf, 1, self); \
71
+ }
72
+
73
+ #define DEF_NARRAY_ROBJ_UNARY_ROUND_METHOD_FUNC(fRoundFunc) \
74
+ static void iter_robject_##fRoundFunc(na_loop_t* const lp) { \
75
+ size_t n; \
76
+ char* p1; \
77
+ char* p2; \
78
+ ssize_t s1; \
79
+ ssize_t s2; \
80
+ size_t* idx1; \
81
+ size_t* idx2; \
82
+ robject x; \
83
+ \
84
+ INIT_COUNTER(lp, n); \
85
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
86
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
87
+ \
88
+ if (idx1) { \
89
+ if (idx2) { \
90
+ for (size_t i = 0; i < n; i++) { \
91
+ GET_DATA_INDEX(p1, idx1, robject, x); \
92
+ x = m_##fRoundFunc(x); \
93
+ SET_DATA_INDEX(p2, idx2, robject, x); \
94
+ } \
95
+ } else { \
96
+ for (size_t i = 0; i < n; i++) { \
97
+ GET_DATA_INDEX(p1, idx1, robject, x); \
98
+ x = m_##fRoundFunc(x); \
99
+ SET_DATA_STRIDE(p2, s2, robject, x); \
100
+ } \
101
+ } \
102
+ } else { \
103
+ if (idx2) { \
104
+ for (size_t i = 0; i < n; i++) { \
105
+ GET_DATA_STRIDE(p1, s1, robject, x); \
106
+ x = m_##fRoundFunc(x); \
107
+ SET_DATA_INDEX(p2, idx2, robject, x); \
108
+ } \
109
+ } else { \
110
+ for (size_t i = 0; i < n; i++) { \
111
+ *(robject*)p2 = m_##fRoundFunc(*(robject*)p1); \
112
+ p1 += s1; \
113
+ p2 += s2; \
114
+ } \
115
+ return; \
116
+ } \
117
+ } \
118
+ } \
119
+ \
120
+ static VALUE robject_##fRoundFunc(VALUE self) { \
121
+ ndfunc_arg_in_t ain[1] = { { numo_cRObject, 0 } }; \
122
+ ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } }; \
123
+ ndfunc_t ndf = { iter_robject_##fRoundFunc, FULL_LOOP, 1, 1, ain, aout }; \
124
+ return na_ndloop(&ndf, 1, self); \
125
+ }
126
+
127
+ #endif /* NUMO_NARRAY_MH_ROUND_UNARY_FUNC_H */
@@ -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 */