numo-narray-alt 0.9.11 → 0.9.12

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 (91) 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/op/add.h +78 -0
  64. data/ext/numo/narray/src/mh/op/binary_func.h +423 -0
  65. data/ext/numo/narray/src/mh/op/div.h +118 -0
  66. data/ext/numo/narray/src/mh/op/mod.h +108 -0
  67. data/ext/numo/narray/src/mh/op/mul.h +78 -0
  68. data/ext/numo/narray/src/mh/op/sub.h +78 -0
  69. data/ext/numo/narray/src/mh/rand.h +2 -2
  70. data/ext/numo/narray/src/mh/round/ceil.h +11 -0
  71. data/ext/numo/narray/src/mh/round/floor.h +11 -0
  72. data/ext/numo/narray/src/mh/round/rint.h +9 -0
  73. data/ext/numo/narray/src/mh/round/round.h +11 -0
  74. data/ext/numo/narray/src/mh/round/trunc.h +11 -0
  75. data/ext/numo/narray/src/mh/round/unary_func.h +127 -0
  76. data/ext/numo/narray/src/mh/to_a.h +78 -0
  77. data/ext/numo/narray/src/t_bit.c +45 -234
  78. data/ext/numo/narray/src/t_dcomplex.c +584 -1809
  79. data/ext/numo/narray/src/t_dfloat.c +429 -2432
  80. data/ext/numo/narray/src/t_int16.c +481 -2283
  81. data/ext/numo/narray/src/t_int32.c +481 -2283
  82. data/ext/numo/narray/src/t_int64.c +481 -2283
  83. data/ext/numo/narray/src/t_int8.c +408 -1873
  84. data/ext/numo/narray/src/t_robject.c +448 -1977
  85. data/ext/numo/narray/src/t_scomplex.c +584 -1809
  86. data/ext/numo/narray/src/t_sfloat.c +429 -2434
  87. data/ext/numo/narray/src/t_uint16.c +480 -2278
  88. data/ext/numo/narray/src/t_uint32.c +480 -2278
  89. data/ext/numo/narray/src/t_uint64.c +480 -2278
  90. data/ext/numo/narray/src/t_uint8.c +407 -1868
  91. metadata +41 -2
@@ -0,0 +1,108 @@
1
+ #ifndef NUMO_NARRAY_MH_OP_MOD_H
2
+ #define NUMO_NARRAY_MH_OP_MOD_H 1
3
+
4
+ #include "binary_func.h"
5
+
6
+ #define DEF_NARRAY_FLT_MOD_METHOD_FUNC(tDType, tNAryClass) \
7
+ static void iter_##tDType##_mod(na_loop_t* const lp) { \
8
+ ITER_BINARY_INIT_VARS() \
9
+ if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType)) && \
10
+ is_aligned(p3, sizeof(tDType))) { \
11
+ if (s1 == sizeof(tDType) && s2 == sizeof(tDType) && s3 == sizeof(tDType)) { \
12
+ ITER_BINARY_INPLACE_OR_NEW_ARY(mod, tDType) \
13
+ return; \
14
+ } \
15
+ if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
16
+ is_aligned_step(s3, sizeof(tDType))) { \
17
+ if (s2 == 0) { \
18
+ if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
19
+ ITER_BINARY_INPLACE_OR_NEW_SCL(mod, tDType) \
20
+ } else { \
21
+ ITER_BINARY_NEW_PTR_SCL(mod, tDType) \
22
+ } \
23
+ } else { \
24
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY(mod, tDType) \
25
+ } \
26
+ return; \
27
+ } \
28
+ } \
29
+ ITER_BINARY_FALLBACK_LOOP(mod, tDType) \
30
+ } \
31
+ DEF_BINARY_SELF_FUNC(mod, tDType, tNAryClass) \
32
+ DEF_BINARY_FUNC(mod, '%', tDType, tNAryClass)
33
+
34
+ #define DEF_NARRAY_INT_MOD_METHOD_FUNC(tDType, tNAryClass) \
35
+ static void iter_##tDType##_mod(na_loop_t* const lp) { \
36
+ ITER_BINARY_INIT_VARS() \
37
+ if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType)) && \
38
+ is_aligned(p3, sizeof(tDType))) { \
39
+ if (s1 == sizeof(tDType) && s2 == sizeof(tDType) && s3 == sizeof(tDType)) { \
40
+ ITER_BINARY_INPLACE_OR_NEW_ARY_ZERODIV(mod, tDType) \
41
+ return; \
42
+ } \
43
+ if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
44
+ is_aligned_step(s3, sizeof(tDType))) { \
45
+ if (s2 == 0) { \
46
+ if ((*(tDType*)p2) == 0) { \
47
+ lp->err_type = rb_eZeroDivError; \
48
+ return; \
49
+ } \
50
+ if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
51
+ ITER_BINARY_INPLACE_OR_NEW_SCL(mod, tDType) \
52
+ } else { \
53
+ ITER_BINARY_NEW_PTR_SCL(mod, tDType) \
54
+ } \
55
+ } else { \
56
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY_ZERODIV(mod, tDType) \
57
+ } \
58
+ return; \
59
+ } \
60
+ } \
61
+ ITER_BINARY_FALLBACK_LOOP(mod, tDType) \
62
+ } \
63
+ DEF_BINARY_SELF_FUNC(mod, tDType, tNAryClass) \
64
+ DEF_BINARY_FUNC(mod, '%', tDType, tNAryClass)
65
+
66
+ #define DEF_NARRAY_INT8_MOD_METHOD_FUNC(tDType, tNAryClass) \
67
+ static void iter_##tDType##_mod(na_loop_t* const lp) { \
68
+ ITER_BINARY_INIT_VARS() \
69
+ if (s2 == 0) { \
70
+ if ((*(tDType*)p2) == 0) { \
71
+ lp->err_type = rb_eZeroDivError; \
72
+ return; \
73
+ } \
74
+ if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
75
+ ITER_BINARY_INPLACE_OR_NEW_SCL(mod, tDType) \
76
+ } else { \
77
+ ITER_BINARY_NEW_PTR_SCL(mod, tDType) \
78
+ } \
79
+ } else { \
80
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY_ZERODIV(mod, tDType) \
81
+ } \
82
+ } \
83
+ DEF_BINARY_SELF_FUNC(mod, tDType, tNAryClass) \
84
+ DEF_BINARY_FUNC(mod, '%', tDType, tNAryClass)
85
+
86
+ #define DEF_NARRAY_ROBJ_MOD_METHOD_FUNC() \
87
+ static void iter_robject_mod(na_loop_t* const lp) { \
88
+ ITER_BINARY_INIT_VARS() \
89
+ if (s2 == 0) { \
90
+ if ((*(robject*)p2) == 0) { \
91
+ lp->err_type = rb_eZeroDivError; \
92
+ return; \
93
+ } \
94
+ if (s1 == sizeof(robject) && s3 == sizeof(robject)) { \
95
+ ITER_BINARY_INPLACE_OR_NEW_SCL(mod, robject) \
96
+ } else { \
97
+ ITER_BINARY_NEW_PTR_SCL(mod, robject) \
98
+ } \
99
+ } else { \
100
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY_ZERODIV(mod, robject) \
101
+ } \
102
+ } \
103
+ DEF_BINARY_SELF_FUNC(mod, robject, numo_cRObject) \
104
+ static VALUE robject_mod(VALUE self, VALUE other) { \
105
+ return robject_mod_self(self, other); \
106
+ }
107
+
108
+ #endif /* NUMO_NARRAY_MH_OP_MOD_H */
@@ -0,0 +1,78 @@
1
+ #ifndef NUMO_NARRAY_MH_OP_MUL_H
2
+ #define NUMO_NARRAY_MH_OP_MUL_H 1
3
+
4
+ #include "binary_func.h"
5
+
6
+ #define DEF_NARRAY_MUL_METHOD_FUNC(tDType, tNAryClass) \
7
+ static void iter_##tDType##_mul(na_loop_t* const lp) { \
8
+ ITER_BINARY_INIT_VARS() \
9
+ if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType)) && \
10
+ is_aligned(p3, sizeof(tDType))) { \
11
+ if (s1 == sizeof(tDType) && s2 == sizeof(tDType) && s3 == sizeof(tDType)) { \
12
+ ITER_BINARY_INPLACE_OR_NEW_ARY(mul, tDType) \
13
+ return; \
14
+ } \
15
+ if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
16
+ is_aligned_step(s3, sizeof(tDType))) { \
17
+ if (s2 == 0) { \
18
+ if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
19
+ ITER_BINARY_INPLACE_OR_NEW_SCL(mul, tDType) \
20
+ } else { \
21
+ ITER_BINARY_NEW_PTR_SCL(mul, tDType) \
22
+ } \
23
+ } else { \
24
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY(mul, tDType) \
25
+ } \
26
+ return; \
27
+ } \
28
+ } \
29
+ ITER_BINARY_FALLBACK_LOOP(mul, tDType) \
30
+ } \
31
+ DEF_BINARY_SELF_FUNC(mul, tDType, tNAryClass) \
32
+ DEF_BINARY_FUNC(mul, '*', tDType, tNAryClass)
33
+
34
+ #define DEF_NARRAY_INT8_MUL_METHOD_FUNC(tDType, tNAryClass) \
35
+ static void iter_##tDType##_mul(na_loop_t* const lp) { \
36
+ ITER_BINARY_INIT_VARS() \
37
+ if (s2 == 0) { \
38
+ if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
39
+ ITER_BINARY_INPLACE_OR_NEW_SCL(mul, tDType) \
40
+ } else { \
41
+ ITER_BINARY_NEW_PTR_SCL(mul, tDType) \
42
+ } \
43
+ } else { \
44
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY(mul, tDType) \
45
+ } \
46
+ } \
47
+ DEF_BINARY_SELF_FUNC(mul, tDType, tNAryClass) \
48
+ DEF_BINARY_FUNC(mul, '*', tDType, tNAryClass)
49
+
50
+ #define DEF_NARRAY_ROBJ_MUL_METHOD_FUNC() \
51
+ static void iter_robject_mul(na_loop_t* const lp) { \
52
+ ITER_BINARY_INIT_VARS() \
53
+ if (s2 == 0) { \
54
+ if (s1 == sizeof(robject) && s3 == sizeof(robject)) { \
55
+ ITER_BINARY_INPLACE_OR_NEW_SCL(mul, robject) \
56
+ } else { \
57
+ ITER_BINARY_NEW_PTR_SCL(mul, robject) \
58
+ } \
59
+ } else { \
60
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY(mul, robject) \
61
+ } \
62
+ } \
63
+ DEF_BINARY_SELF_FUNC(mul, robject, numo_cRObject) \
64
+ static VALUE robject_mul(VALUE self, VALUE other) { \
65
+ return robject_mul_self(self, other); \
66
+ }
67
+
68
+ #define DEF_NARRAY_SFLT_MUL_SSE2_METHOD_FUNC() \
69
+ DEF_BINARY_SFLT_SSE2_ITER_FUNC(mul, _mm_mul_ps) \
70
+ DEF_BINARY_SELF_FUNC(mul, sfloat, numo_cSFloat) \
71
+ DEF_BINARY_FUNC(mul, '*', sfloat, numo_cSFloat)
72
+
73
+ #define DEF_NARRAY_DFLT_MUL_SSE2_METHOD_FUNC() \
74
+ DEF_BINARY_DFLT_SSE2_ITER_FUNC(mul, _mm_mul_pd) \
75
+ DEF_BINARY_SELF_FUNC(mul, dfloat, numo_cDFloat) \
76
+ DEF_BINARY_FUNC(mul, '*', dfloat, numo_cDFloat)
77
+
78
+ #endif /* NUMO_NARRAY_MH_OP_MUL_H */
@@ -0,0 +1,78 @@
1
+ #ifndef NUMO_NARRAY_MH_OP_SUB_H
2
+ #define NUMO_NARRAY_MH_OP_SUB_H 1
3
+
4
+ #include "binary_func.h"
5
+
6
+ #define DEF_NARRAY_SUB_METHOD_FUNC(tDType, tNAryClass) \
7
+ static void iter_##tDType##_sub(na_loop_t* const lp) { \
8
+ ITER_BINARY_INIT_VARS() \
9
+ if (is_aligned(p1, sizeof(tDType)) && is_aligned(p2, sizeof(tDType)) && \
10
+ is_aligned(p3, sizeof(tDType))) { \
11
+ if (s1 == sizeof(tDType) && s2 == sizeof(tDType) && s3 == sizeof(tDType)) { \
12
+ ITER_BINARY_INPLACE_OR_NEW_ARY(sub, tDType) \
13
+ return; \
14
+ } \
15
+ if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
16
+ is_aligned_step(s3, sizeof(tDType))) { \
17
+ if (s2 == 0) { \
18
+ if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
19
+ ITER_BINARY_INPLACE_OR_NEW_SCL(sub, tDType) \
20
+ } else { \
21
+ ITER_BINARY_NEW_PTR_SCL(sub, tDType) \
22
+ } \
23
+ } else { \
24
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY(sub, tDType) \
25
+ } \
26
+ return; \
27
+ } \
28
+ } \
29
+ ITER_BINARY_FALLBACK_LOOP(sub, tDType) \
30
+ } \
31
+ DEF_BINARY_SELF_FUNC(sub, tDType, tNAryClass) \
32
+ DEF_BINARY_FUNC(sub, '-', tDType, tNAryClass)
33
+
34
+ #define DEF_NARRAY_INT8_SUB_METHOD_FUNC(tDType, tNAryClass) \
35
+ static void iter_##tDType##_sub(na_loop_t* const lp) { \
36
+ ITER_BINARY_INIT_VARS() \
37
+ if (s2 == 0) { \
38
+ if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
39
+ ITER_BINARY_INPLACE_OR_NEW_SCL(sub, tDType) \
40
+ } else { \
41
+ ITER_BINARY_NEW_PTR_SCL(sub, tDType) \
42
+ } \
43
+ } else { \
44
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY(sub, tDType) \
45
+ } \
46
+ } \
47
+ DEF_BINARY_SELF_FUNC(sub, tDType, tNAryClass) \
48
+ DEF_BINARY_FUNC(sub, '-', tDType, tNAryClass)
49
+
50
+ #define DEF_NARRAY_ROBJ_SUB_METHOD_FUNC() \
51
+ static void iter_robject_sub(na_loop_t* const lp) { \
52
+ ITER_BINARY_INIT_VARS() \
53
+ if (s2 == 0) { \
54
+ if (s1 == sizeof(robject) && s3 == sizeof(robject)) { \
55
+ ITER_BINARY_INPLACE_OR_NEW_SCL(sub, robject) \
56
+ } else { \
57
+ ITER_BINARY_NEW_PTR_SCL(sub, robject) \
58
+ } \
59
+ } else { \
60
+ ITER_BINARY_INPLACE_OR_NEW_PTR_ARY(sub, robject) \
61
+ } \
62
+ } \
63
+ DEF_BINARY_SELF_FUNC(sub, robject, numo_cRObject) \
64
+ static VALUE robject_sub(VALUE self, VALUE other) { \
65
+ return robject_sub_self(self, other); \
66
+ }
67
+
68
+ #define DEF_NARRAY_SFLT_SUB_SSE2_METHOD_FUNC() \
69
+ DEF_BINARY_SFLT_SSE2_ITER_FUNC(sub, _mm_sub_ps) \
70
+ DEF_BINARY_SELF_FUNC(sub, sfloat, numo_cSFloat) \
71
+ DEF_BINARY_FUNC(sub, '-', sfloat, numo_cSFloat)
72
+
73
+ #define DEF_NARRAY_DFLT_SUB_SSE2_METHOD_FUNC() \
74
+ DEF_BINARY_DFLT_SSE2_ITER_FUNC(sub, _mm_sub_pd) \
75
+ DEF_BINARY_SELF_FUNC(sub, dfloat, numo_cDFloat) \
76
+ DEF_BINARY_FUNC(sub, '-', dfloat, numo_cDFloat)
77
+
78
+ #endif /* NUMO_NARRAY_MH_OP_SUB_H */
@@ -26,12 +26,12 @@
26
26
  if (idx1) { \
27
27
  for (size_t i = 0; i < n; i++) { \
28
28
  x = m_add(m_rand(max), low); \
29
- SET_DATA_INDEX(p1, idx1, dtype, x); \
29
+ SET_DATA_INDEX(p1, idx1, tDType, x); \
30
30
  } \
31
31
  } else { \
32
32
  for (size_t i = 0; i < n; i++) { \
33
33
  x = m_add(m_rand(max), low); \
34
- SET_DATA_STRIDE(p1, s1, dtype, x); \
34
+ SET_DATA_STRIDE(p1, s1, tDType, x); \
35
35
  } \
36
36
  } \
37
37
  } \
@@ -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,78 @@
1
+ #ifndef NUMO_NARRAY_MH_TO_A_H
2
+ #define NUMO_NARRAY_MH_TO_A_H 1
3
+
4
+ #define DEF_NARRAY_TO_A_METHOD_FUNC(tDType) \
5
+ static void iter_##tDType##_to_a(na_loop_t* const lp) { \
6
+ size_t n; \
7
+ size_t s1; \
8
+ char* p1; \
9
+ size_t* idx1; \
10
+ tDType x; \
11
+ volatile VALUE a, y; \
12
+ \
13
+ INIT_COUNTER(lp, n); \
14
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
15
+ a = rb_ary_new2(n); \
16
+ rb_ary_push(lp->args[1].value, a); \
17
+ if (idx1) { \
18
+ for (size_t i = 0; i < n; i++) { \
19
+ GET_DATA_INDEX(p1, idx1, tDType, x); \
20
+ y = m_data_to_num(x); \
21
+ rb_ary_push(a, y); \
22
+ } \
23
+ } else { \
24
+ for (size_t i = 0; i < n; i++) { \
25
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
26
+ y = m_data_to_num(x); \
27
+ rb_ary_push(a, y); \
28
+ } \
29
+ } \
30
+ } \
31
+ \
32
+ static VALUE tDType##_to_a(VALUE self) { \
33
+ ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } }; \
34
+ ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; \
35
+ ndfunc_t ndf = { iter_##tDType##_to_a, FULL_LOOP_NIP, 3, 1, ain, aout }; \
36
+ return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil); \
37
+ }
38
+
39
+ #define DEF_NARRAY_BIT_TO_A_METHOD_FUNC() \
40
+ static void iter_bit_to_a(na_loop_t* const lp) { \
41
+ size_t n; \
42
+ BIT_DIGIT* a1; \
43
+ size_t p1; \
44
+ ssize_t s1; \
45
+ size_t* idx1; \
46
+ BIT_DIGIT x = 0; \
47
+ VALUE a; \
48
+ VALUE y; \
49
+ \
50
+ INIT_COUNTER(lp, n); \
51
+ INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1); \
52
+ a = rb_ary_new2(n); \
53
+ rb_ary_push(lp->args[1].value, a); \
54
+ if (idx1) { \
55
+ for (size_t i = 0; i < n; i++) { \
56
+ LOAD_BIT(a1, p1 + *idx1, x); \
57
+ idx1++; \
58
+ y = m_data_to_num(x); \
59
+ rb_ary_push(a, y); \
60
+ } \
61
+ } else { \
62
+ for (size_t i = 0; i < n; i++) { \
63
+ LOAD_BIT(a1, p1, x); \
64
+ p1 += s1; \
65
+ y = m_data_to_num(x); \
66
+ rb_ary_push(a, y); \
67
+ } \
68
+ } \
69
+ } \
70
+ \
71
+ static VALUE bit_to_a(VALUE self) { \
72
+ ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } }; \
73
+ ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; \
74
+ ndfunc_t ndf = { iter_bit_to_a, FULL_LOOP_NIP, 3, 1, ain, aout }; \
75
+ return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil); \
76
+ }
77
+
78
+ #endif /* NUMO_NARRAY_MH_TO_A_H */