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,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 */
@@ -0,0 +1,197 @@
1
+ #ifndef NUMO_NARRAY_MH_POW_H
2
+ #define NUMO_NARRAY_MH_POW_H 1
3
+
4
+ #define DEF_NARRAY_POW_METHOD_FUNC(tDType, tNAryClass) \
5
+ static void iter_##tDType##_pow(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
+ tDType x; \
18
+ tDType y; \
19
+ for (size_t i = 0; i < n; i++) { \
20
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
21
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
22
+ x = m_pow(x, y); \
23
+ SET_DATA_STRIDE(p3, s3, tDType, x); \
24
+ } \
25
+ } \
26
+ \
27
+ static void iter_##tDType##_pow_int32(na_loop_t* const lp) { \
28
+ size_t n; \
29
+ char* p1; \
30
+ char* p2; \
31
+ char* p3; \
32
+ ssize_t s1; \
33
+ ssize_t s2; \
34
+ ssize_t s3; \
35
+ INIT_COUNTER(lp, n); \
36
+ INIT_PTR(lp, 0, p1, s1); \
37
+ INIT_PTR(lp, 1, p2, s2); \
38
+ INIT_PTR(lp, 2, p3, s3); \
39
+ tDType x; \
40
+ int32_t y; \
41
+ for (size_t i = 0; i < n; i++) { \
42
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
43
+ GET_DATA_STRIDE(p2, s2, int32_t, y); \
44
+ x = m_pow_int(x, y); \
45
+ SET_DATA_STRIDE(p3, s3, tDType, x); \
46
+ } \
47
+ } \
48
+ \
49
+ static VALUE tDType##_pow_self(VALUE self, VALUE other) { \
50
+ ndfunc_arg_in_t ain_i[2] = { { tNAryClass, 0 }, { numo_cInt32, 0 } }; \
51
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
52
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
53
+ ndfunc_t ndf_i = { iter_##tDType##_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout }; \
54
+ ndfunc_t ndf = { iter_##tDType##_pow, STRIDE_LOOP, 2, 1, ain, aout }; \
55
+ if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) { \
56
+ return na_ndloop(&ndf_i, 2, self, other); \
57
+ } \
58
+ return na_ndloop(&ndf, 2, self, other); \
59
+ } \
60
+ \
61
+ static VALUE tDType##_pow(VALUE self, VALUE other) { \
62
+ VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
63
+ if (klass == tNAryClass) { \
64
+ return tDType##_pow_self(self, other); \
65
+ } \
66
+ VALUE v = rb_funcall(klass, id_cast, 1, self); \
67
+ return rb_funcall(v, id_pow, 1, other); \
68
+ }
69
+
70
+ #define DEF_NARRAY_INT64_POW_METHOD_FUNC(tDType, tNAryClass) \
71
+ static void iter_##tDType##_pow(na_loop_t* const lp) { \
72
+ size_t n; \
73
+ char* p1; \
74
+ char* p2; \
75
+ char* p3; \
76
+ ssize_t s1; \
77
+ ssize_t s2; \
78
+ ssize_t s3; \
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
+ tDType x; \
84
+ tDType y; \
85
+ for (size_t i = 0; i < n; i++) { \
86
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
87
+ GET_DATA_STRIDE(p2, s2, tDType, y); \
88
+ x = m_pow(x, (int)y); \
89
+ SET_DATA_STRIDE(p3, s3, tDType, x); \
90
+ } \
91
+ } \
92
+ \
93
+ static void iter_##tDType##_pow_int32(na_loop_t* const lp) { \
94
+ size_t n; \
95
+ char* p1; \
96
+ char* p2; \
97
+ char* p3; \
98
+ ssize_t s1; \
99
+ ssize_t s2; \
100
+ ssize_t s3; \
101
+ INIT_COUNTER(lp, n); \
102
+ INIT_PTR(lp, 0, p1, s1); \
103
+ INIT_PTR(lp, 1, p2, s2); \
104
+ INIT_PTR(lp, 2, p3, s3); \
105
+ tDType x; \
106
+ int32_t y; \
107
+ for (size_t i = 0; i < n; i++) { \
108
+ GET_DATA_STRIDE(p1, s1, tDType, x); \
109
+ GET_DATA_STRIDE(p2, s2, int32_t, y); \
110
+ x = m_pow_int(x, y); \
111
+ SET_DATA_STRIDE(p3, s3, tDType, x); \
112
+ } \
113
+ } \
114
+ \
115
+ static VALUE tDType##_pow_self(VALUE self, VALUE other) { \
116
+ ndfunc_arg_in_t ain_i[2] = { { tNAryClass, 0 }, { numo_cInt32, 0 } }; \
117
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 0 }, { tNAryClass, 0 } }; \
118
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0 } }; \
119
+ ndfunc_t ndf_i = { iter_##tDType##_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout }; \
120
+ ndfunc_t ndf = { iter_##tDType##_pow, STRIDE_LOOP, 2, 1, ain, aout }; \
121
+ if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) { \
122
+ return na_ndloop(&ndf_i, 2, self, other); \
123
+ } \
124
+ return na_ndloop(&ndf, 2, self, other); \
125
+ } \
126
+ \
127
+ static VALUE tDType##_pow(VALUE self, VALUE other) { \
128
+ VALUE klass = na_upcast(rb_obj_class(self), rb_obj_class(other)); \
129
+ if (klass == tNAryClass) { \
130
+ return tDType##_pow_self(self, other); \
131
+ } \
132
+ VALUE v = rb_funcall(klass, id_cast, 1, self); \
133
+ return rb_funcall(v, id_pow, 1, other); \
134
+ }
135
+
136
+ #define DEF_NARRAY_ROBJ_POW_METHOD_FUNC() \
137
+ static void iter_robject_pow(na_loop_t* const lp) { \
138
+ size_t n; \
139
+ char* p1; \
140
+ char* p2; \
141
+ char* p3; \
142
+ ssize_t s1; \
143
+ ssize_t s2; \
144
+ ssize_t s3; \
145
+ INIT_COUNTER(lp, n); \
146
+ INIT_PTR(lp, 0, p1, s1); \
147
+ INIT_PTR(lp, 1, p2, s2); \
148
+ INIT_PTR(lp, 2, p3, s3); \
149
+ robject x; \
150
+ robject y; \
151
+ for (size_t i = 0; i < n; i++) { \
152
+ GET_DATA_STRIDE(p1, s1, robject, x); \
153
+ GET_DATA_STRIDE(p2, s2, robject, y); \
154
+ x = m_pow(x, y); \
155
+ SET_DATA_STRIDE(p3, s3, robject, x); \
156
+ } \
157
+ } \
158
+ \
159
+ static void iter_robject_pow_int32(na_loop_t* const lp) { \
160
+ size_t n; \
161
+ char* p1; \
162
+ char* p2; \
163
+ char* p3; \
164
+ ssize_t s1; \
165
+ ssize_t s2; \
166
+ ssize_t s3; \
167
+ INIT_COUNTER(lp, n); \
168
+ INIT_PTR(lp, 0, p1, s1); \
169
+ INIT_PTR(lp, 1, p2, s2); \
170
+ INIT_PTR(lp, 2, p3, s3); \
171
+ robject x; \
172
+ int32_t y; \
173
+ for (size_t i = 0; i < n; i++) { \
174
+ GET_DATA_STRIDE(p1, s1, robject, x); \
175
+ GET_DATA_STRIDE(p2, s2, int32_t, y); \
176
+ x = m_pow_int(x, y); \
177
+ SET_DATA_STRIDE(p3, s3, robject, x); \
178
+ } \
179
+ } \
180
+ \
181
+ static VALUE robject_pow_self(VALUE self, VALUE other) { \
182
+ ndfunc_arg_in_t ain_i[2] = { { numo_cRObject, 0 }, { numo_cInt32, 0 } }; \
183
+ ndfunc_arg_in_t ain[2] = { { numo_cRObject, 0 }, { numo_cRObject, 0 } }; \
184
+ ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } }; \
185
+ ndfunc_t ndf_i = { iter_robject_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout }; \
186
+ ndfunc_t ndf = { iter_robject_pow, STRIDE_LOOP, 2, 1, ain, aout }; \
187
+ if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) { \
188
+ return na_ndloop(&ndf_i, 2, self, other); \
189
+ } \
190
+ return na_ndloop(&ndf, 2, self, other); \
191
+ } \
192
+ \
193
+ static VALUE robject_pow(VALUE self, VALUE other) { \
194
+ return robject_pow_self(self, other); \
195
+ }
196
+
197
+ #endif /* NUMO_NARRAY_MH_POW_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,125 @@
1
+ #ifndef NUMO_NARRAY_MH_RAND_NORM_H
2
+ #define NUMO_NARRAY_MH_RAND_NORM_H 1
3
+
4
+ #define DEF_NARRAY_CMP_RAND_NORM_METHOD_FUNC(tDType, tRType) \
5
+ typedef struct { \
6
+ tDType mu; \
7
+ tRType sigma; \
8
+ } randn_opt_t; \
9
+ \
10
+ static void iter_##tDType##_rand_norm(na_loop_t* const lp) { \
11
+ size_t n; \
12
+ char* p1; \
13
+ ssize_t s1; \
14
+ size_t* idx1; \
15
+ INIT_COUNTER(lp, n); \
16
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
17
+ tDType mu; \
18
+ tRType sigma; \
19
+ randn_opt_t* g = (randn_opt_t*)(lp->opt_ptr); \
20
+ mu = g->mu; \
21
+ sigma = g->sigma; \
22
+ tDType* a0; \
23
+ if (idx1) { \
24
+ for (size_t i = 0; i < n; i++) { \
25
+ a0 = (tDType*)(p1 + *idx1); \
26
+ m_rand_norm(mu, sigma, a0); \
27
+ idx1 += 1; \
28
+ } \
29
+ } else { \
30
+ for (size_t i = 0; i < n; i++) { \
31
+ a0 = (tDType*)(p1); \
32
+ m_rand_norm(mu, sigma, a0); \
33
+ p1 += s1; \
34
+ } \
35
+ } \
36
+ } \
37
+ \
38
+ static VALUE tDType##_rand_norm(int argc, VALUE* argv, VALUE self) { \
39
+ VALUE v1 = Qnil; \
40
+ VALUE v2 = Qnil; \
41
+ const int n = rb_scan_args(argc, argv, "02", &v1, &v2); \
42
+ randn_opt_t g; \
43
+ if (n == 0) { \
44
+ g.mu = m_zero; \
45
+ } else { \
46
+ g.mu = m_num_to_data(v1); \
47
+ } \
48
+ if (n == 2) { \
49
+ g.sigma = NUM2DBL(v2); \
50
+ } else { \
51
+ g.sigma = 1; \
52
+ } \
53
+ ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
54
+ ndfunc_t ndf = { iter_##tDType##_rand_norm, FULL_LOOP, 1, 0, ain, 0 }; \
55
+ na_ndloop3(&ndf, &g, 1, self); \
56
+ return self; \
57
+ }
58
+
59
+ #define DEF_NARRAY_FLT_RAND_NORM_METHOD_FUNC(tDType) \
60
+ typedef struct { \
61
+ tDType mu; \
62
+ tDType sigma; \
63
+ } randn_opt_t; \
64
+ \
65
+ static void iter_##tDType##_rand_norm(na_loop_t* const lp) { \
66
+ size_t i; \
67
+ char* p1; \
68
+ ssize_t s1; \
69
+ size_t* idx1; \
70
+ INIT_COUNTER(lp, i); \
71
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
72
+ tDType mu; \
73
+ tDType sigma; \
74
+ randn_opt_t* g = (randn_opt_t*)(lp->opt_ptr); \
75
+ mu = g->mu; \
76
+ sigma = g->sigma; \
77
+ tDType* a0; \
78
+ tDType* a1; \
79
+ if (idx1) { \
80
+ for (; i > 1; i -= 2) { \
81
+ a0 = (tDType*)(p1 + *idx1); \
82
+ a1 = (tDType*)(p1 + *(idx1 + 1)); \
83
+ m_rand_norm(mu, sigma, a0, a1); \
84
+ idx1 += 2; \
85
+ } \
86
+ if (i > 0) { \
87
+ a0 = (tDType*)(p1 + *idx1); \
88
+ m_rand_norm(mu, sigma, a0, 0); \
89
+ } \
90
+ } else { \
91
+ for (; i > 1; i -= 2) { \
92
+ a0 = (tDType*)(p1); \
93
+ a1 = (tDType*)(p1 + s1); \
94
+ m_rand_norm(mu, sigma, a0, a1); \
95
+ p1 += s1 * 2; \
96
+ } \
97
+ if (i > 0) { \
98
+ a0 = (tDType*)(p1); \
99
+ m_rand_norm(mu, sigma, a0, 0); \
100
+ } \
101
+ } \
102
+ } \
103
+ \
104
+ static VALUE tDType##_rand_norm(int argc, VALUE* args, VALUE self) { \
105
+ VALUE v1 = Qnil; \
106
+ VALUE v2 = Qnil; \
107
+ const int n = rb_scan_args(argc, args, "02", &v1, &v2); \
108
+ randn_opt_t g; \
109
+ if (n == 0) { \
110
+ g.mu = m_zero; \
111
+ } else { \
112
+ g.mu = m_num_to_data(v1); \
113
+ } \
114
+ if (n == 2) { \
115
+ g.sigma = NUM2DBL(v2); \
116
+ } else { \
117
+ g.sigma = 1; \
118
+ } \
119
+ ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } }; \
120
+ ndfunc_t ndf = { iter_##tDType##_rand_norm, FULL_LOOP, 1, 0, ain, 0 }; \
121
+ na_ndloop3(&ndf, &g, 1, self); \
122
+ return self; \
123
+ }
124
+
125
+ #endif /* NUMO_NARRAY_MH_RAND_NORM_H */