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
@@ -60,7 +60,41 @@ static ID id_truncate;
60
60
  VALUE cT;
61
61
  extern VALUE cRT;
62
62
 
63
+ #include "mh/coerce_cast.h"
64
+ #include "mh/to_a.h"
65
+ #include "mh/fill.h"
66
+ #include "mh/format.h"
67
+ #include "mh/format_to_a.h"
68
+ #include "mh/inspect.h"
69
+ #include "mh/op/add.h"
70
+ #include "mh/op/sub.h"
71
+ #include "mh/op/mul.h"
72
+ #include "mh/op/div.h"
73
+ #include "mh/op/mod.h"
74
+ #include "mh/divmod.h"
75
+ #include "mh/round/floor.h"
76
+ #include "mh/round/round.h"
77
+ #include "mh/round/ceil.h"
78
+ #include "mh/round/trunc.h"
79
+ #include "mh/comp/eq.h"
80
+ #include "mh/comp/ne.h"
81
+ #include "mh/comp/nearly_eq.h"
82
+ #include "mh/comp/gt.h"
83
+ #include "mh/comp/ge.h"
84
+ #include "mh/comp/lt.h"
85
+ #include "mh/comp/le.h"
86
+ #include "mh/bit/and.h"
87
+ #include "mh/bit/or.h"
88
+ #include "mh/bit/xor.h"
89
+ #include "mh/bit/not.h"
90
+ #include "mh/bit/left_shift.h"
91
+ #include "mh/bit/right_shift.h"
63
92
  #include "mh/clip.h"
93
+ #include "mh/isnan.h"
94
+ #include "mh/isinf.h"
95
+ #include "mh/isposinf.h"
96
+ #include "mh/isneginf.h"
97
+ #include "mh/isfinite.h"
64
98
  #include "mh/sum.h"
65
99
  #include "mh/prod.h"
66
100
  #include "mh/mean.h"
@@ -87,7 +121,41 @@ extern VALUE cRT;
87
121
 
88
122
  typedef VALUE robject; // Type aliases for shorter notation
89
123
  // following the codebase naming convention.
124
+ DEF_NARRAY_COERCE_CAST_METHOD_FUNC(robject)
125
+ DEF_NARRAY_TO_A_METHOD_FUNC(robject)
126
+ DEF_NARRAY_FILL_METHOD_FUNC(robject)
127
+ DEF_NARRAY_FORMAT_METHOD_FUNC(robject)
128
+ DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(robject)
129
+ DEF_NARRAY_ROBJ_INSPECT_METHOD_FUNC()
130
+ DEF_NARRAY_ROBJ_ADD_METHOD_FUNC()
131
+ DEF_NARRAY_ROBJ_SUB_METHOD_FUNC()
132
+ DEF_NARRAY_ROBJ_MUL_METHOD_FUNC()
133
+ DEF_NARRAY_ROBJ_DIV_METHOD_FUNC()
134
+ DEF_NARRAY_ROBJ_MOD_METHOD_FUNC()
135
+ DEF_NARRAY_ROBJ_DIVMOD_METHOD_FUNC()
136
+ DEF_NARRAY_ROBJ_FLOOR_METHOD_FUNC()
137
+ DEF_NARRAY_ROBJ_ROUND_METHOD_FUNC()
138
+ DEF_NARRAY_ROBJ_CEIL_METHOD_FUNC()
139
+ DEF_NARRAY_ROBJ_TRUNC_METHOD_FUNC()
140
+ DEF_NARRAY_ROBJ_EQ_METHOD_FUNC()
141
+ DEF_NARRAY_ROBJ_NE_METHOD_FUNC()
142
+ DEF_NARRAY_ROBJ_NEARLY_EQ_METHOD_FUNC()
143
+ DEF_NARRAY_ROBJ_GT_METHOD_FUNC()
144
+ DEF_NARRAY_ROBJ_GE_METHOD_FUNC()
145
+ DEF_NARRAY_ROBJ_LT_METHOD_FUNC()
146
+ DEF_NARRAY_ROBJ_LE_METHOD_FUNC()
147
+ DEF_NARRAY_ROBJ_BIT_AND_METHOD_FUNC()
148
+ DEF_NARRAY_ROBJ_BIT_OR_METHOD_FUNC()
149
+ DEF_NARRAY_ROBJ_BIT_XOR_METHOD_FUNC()
150
+ DEF_NARRAY_ROBJ_BIT_NOT_METHOD_FUNC()
151
+ DEF_NARRAY_ROBJ_LEFT_SHIFT_METHOD_FUNC()
152
+ DEF_NARRAY_ROBJ_RIGHT_SHIFT_METHOD_FUNC()
90
153
  DEF_NARRAY_CLIP_METHOD_FUNC(robject, numo_cRObject)
154
+ DEF_NARRAY_FLT_ISNAN_METHOD_FUNC(robject, numo_cRObject)
155
+ DEF_NARRAY_FLT_ISINF_METHOD_FUNC(robject, numo_cRObject)
156
+ DEF_NARRAY_FLT_ISPOSINF_METHOD_FUNC(robject, numo_cRObject)
157
+ DEF_NARRAY_FLT_ISNEGINF_METHOD_FUNC(robject, numo_cRObject)
158
+ DEF_NARRAY_FLT_ISFINITE_METHOD_FUNC(robject, numo_cRObject)
91
159
  DEF_NARRAY_FLT_SUM_METHOD_FUNC(robject, numo_cRObject)
92
160
  DEF_NARRAY_FLT_PROD_METHOD_FUNC(robject, numo_cRObject)
93
161
  DEF_NARRAY_FLT_MEAN_METHOD_FUNC(robject, numo_cRObject, VALUE, numo_cRObject)
@@ -1286,204 +1354,6 @@ static VALUE robject_aset(int argc, VALUE* argv, VALUE self) {
1286
1354
  return argv[argc];
1287
1355
  }
1288
1356
 
1289
- /*
1290
- return NArray with cast to the type of self.
1291
- @overload coerce_cast(type)
1292
- @return [nil]
1293
- */
1294
- static VALUE robject_coerce_cast(VALUE self, VALUE type) {
1295
- return Qnil;
1296
- }
1297
-
1298
- static void iter_robject_to_a(na_loop_t* const lp) {
1299
- size_t i, s1;
1300
- char* p1;
1301
- size_t* idx1;
1302
- dtype x;
1303
- volatile VALUE a, y;
1304
-
1305
- INIT_COUNTER(lp, i);
1306
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1307
- a = rb_ary_new2(i);
1308
- rb_ary_push(lp->args[1].value, a);
1309
- if (idx1) {
1310
- for (; i--;) {
1311
- GET_DATA_INDEX(p1, idx1, dtype, x);
1312
- y = m_data_to_num(x);
1313
- rb_ary_push(a, y);
1314
- }
1315
- } else {
1316
- for (; i--;) {
1317
- GET_DATA_STRIDE(p1, s1, dtype, x);
1318
- y = m_data_to_num(x);
1319
- rb_ary_push(a, y);
1320
- }
1321
- }
1322
- }
1323
-
1324
- /*
1325
- Convert self to Array.
1326
- @overload to_a
1327
- @return [Array]
1328
- */
1329
- static VALUE robject_to_a(VALUE self) {
1330
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1331
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1332
- ndfunc_t ndf = { iter_robject_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1333
- return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
1334
- }
1335
-
1336
- static void iter_robject_fill(na_loop_t* const lp) {
1337
- size_t i;
1338
- char* p1;
1339
- ssize_t s1;
1340
- size_t* idx1;
1341
- VALUE x = lp->option;
1342
- dtype y;
1343
- INIT_COUNTER(lp, i);
1344
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1345
- y = m_num_to_data(x);
1346
- if (idx1) {
1347
- for (; i--;) {
1348
- SET_DATA_INDEX(p1, idx1, dtype, y);
1349
- }
1350
- } else {
1351
- for (; i--;) {
1352
- SET_DATA_STRIDE(p1, s1, dtype, y);
1353
- }
1354
- }
1355
- }
1356
-
1357
- /*
1358
- Fill elements with other.
1359
- @overload fill other
1360
- @param [Numeric] other
1361
- @return [Numo::RObject] self.
1362
- */
1363
- static VALUE robject_fill(VALUE self, VALUE val) {
1364
- ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
1365
- ndfunc_t ndf = { iter_robject_fill, FULL_LOOP, 2, 0, ain, 0 };
1366
-
1367
- na_ndloop(&ndf, 2, self, val);
1368
- return self;
1369
- }
1370
-
1371
- static VALUE format_robject(VALUE fmt, dtype* x) {
1372
- // fix-me
1373
- char s[48];
1374
- int n;
1375
-
1376
- if (NIL_P(fmt)) {
1377
- n = m_sprintf(s, *x);
1378
- return rb_str_new(s, n);
1379
- }
1380
- return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
1381
- }
1382
-
1383
- static void iter_robject_format(na_loop_t* const lp) {
1384
- size_t i;
1385
- char *p1, *p2;
1386
- ssize_t s1, s2;
1387
- size_t* idx1;
1388
- dtype* x;
1389
- VALUE y;
1390
- VALUE fmt = lp->option;
1391
- INIT_COUNTER(lp, i);
1392
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1393
- INIT_PTR(lp, 1, p2, s2);
1394
- if (idx1) {
1395
- for (; i--;) {
1396
- x = (dtype*)(p1 + *idx1);
1397
- idx1++;
1398
- y = format_robject(fmt, x);
1399
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1400
- }
1401
- } else {
1402
- for (; i--;) {
1403
- x = (dtype*)p1;
1404
- p1 += s1;
1405
- y = format_robject(fmt, x);
1406
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1407
- }
1408
- }
1409
- }
1410
-
1411
- /*
1412
- Format elements into strings.
1413
- @overload format format
1414
- @param [String] format
1415
- @return [Numo::RObject] array of formatted strings.
1416
- */
1417
- static VALUE robject_format(int argc, VALUE* argv, VALUE self) {
1418
- VALUE fmt = Qnil;
1419
-
1420
- ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
1421
- ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
1422
- ndfunc_t ndf = { iter_robject_format, FULL_LOOP_NIP, 2, 1, ain, aout };
1423
-
1424
- rb_scan_args(argc, argv, "01", &fmt);
1425
- return na_ndloop(&ndf, 2, self, fmt);
1426
- }
1427
-
1428
- static void iter_robject_format_to_a(na_loop_t* const lp) {
1429
- size_t i;
1430
- char* p1;
1431
- ssize_t s1;
1432
- size_t* idx1;
1433
- dtype* x;
1434
- VALUE y;
1435
- volatile VALUE a;
1436
- VALUE fmt = lp->option;
1437
- INIT_COUNTER(lp, i);
1438
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1439
- a = rb_ary_new2(i);
1440
- rb_ary_push(lp->args[1].value, a);
1441
- if (idx1) {
1442
- for (; i--;) {
1443
- x = (dtype*)(p1 + *idx1);
1444
- idx1++;
1445
- y = format_robject(fmt, x);
1446
- rb_ary_push(a, y);
1447
- }
1448
- } else {
1449
- for (; i--;) {
1450
- x = (dtype*)p1;
1451
- p1 += s1;
1452
- y = format_robject(fmt, x);
1453
- rb_ary_push(a, y);
1454
- }
1455
- }
1456
- }
1457
-
1458
- /*
1459
- Format elements into strings.
1460
- @overload format_to_a format
1461
- @param [String] format
1462
- @return [Array] array of formatted strings.
1463
- */
1464
- static VALUE robject_format_to_a(int argc, VALUE* argv, VALUE self) {
1465
- VALUE fmt = Qnil;
1466
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1467
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1468
- ndfunc_t ndf = { iter_robject_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1469
-
1470
- rb_scan_args(argc, argv, "01", &fmt);
1471
- return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
1472
- }
1473
-
1474
- static VALUE iter_robject_inspect(char* ptr, size_t pos, VALUE fmt) {
1475
- return rb_inspect(*(VALUE*)(ptr + pos));
1476
- }
1477
-
1478
- /*
1479
- Returns a string containing a human-readable representation of NArray.
1480
- @overload inspect
1481
- @return [String]
1482
- */
1483
- static VALUE robject_inspect(VALUE ary) {
1484
- return na_ndloop_inspect(ary, iter_robject_inspect, Qnil);
1485
- }
1486
-
1487
1357
  static void iter_robject_each(na_loop_t* const lp) {
1488
1358
  size_t i, s1;
1489
1359
  char* p1;
@@ -1793,1884 +1663,294 @@ static VALUE robject_abs(VALUE self) {
1793
1663
  return na_ndloop(&ndf, 1, self);
1794
1664
  }
1795
1665
 
1796
- #define check_intdivzero(y) \
1797
- {}
1798
-
1799
- static void iter_robject_add(na_loop_t* const lp) {
1800
- size_t i = 0;
1801
- size_t n;
1666
+ static void iter_robject_pow(na_loop_t* const lp) {
1667
+ size_t i;
1802
1668
  char *p1, *p2, *p3;
1803
1669
  ssize_t s1, s2, s3;
1804
-
1805
- INIT_COUNTER(lp, n);
1670
+ dtype x, y;
1671
+ INIT_COUNTER(lp, i);
1806
1672
  INIT_PTR(lp, 0, p1, s1);
1807
1673
  INIT_PTR(lp, 1, p2, s2);
1808
1674
  INIT_PTR(lp, 2, p3, s3);
1809
-
1810
- //
1811
-
1812
- if (s2 == 0) { // Broadcasting from scalar value.
1813
- check_intdivzero(*(dtype*)p2);
1814
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
1815
- if (p1 == p3) { // inplace case
1816
- for (; i < n; i++) {
1817
- ((dtype*)p1)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
1818
- }
1819
- } else {
1820
- for (; i < n; i++) {
1821
- ((dtype*)p3)[i] = m_add(((dtype*)p1)[i], *(dtype*)p2);
1822
- }
1823
- }
1824
- } else {
1825
- for (i = 0; i < n; i++) {
1826
- *(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
1827
- p1 += s1;
1828
- p3 += s3;
1829
- }
1830
- }
1831
- } else {
1832
- if (p1 == p3) { // inplace case
1833
- for (i = 0; i < n; i++) {
1834
- check_intdivzero(*(dtype*)p2);
1835
- *(dtype*)p1 = m_add(*(dtype*)p1, *(dtype*)p2);
1836
- p1 += s1;
1837
- p2 += s2;
1838
- }
1839
- } else {
1840
- for (i = 0; i < n; i++) {
1841
- check_intdivzero(*(dtype*)p2);
1842
- *(dtype*)p3 = m_add(*(dtype*)p1, *(dtype*)p2);
1843
- p1 += s1;
1844
- p2 += s2;
1845
- p3 += s3;
1846
- }
1847
- }
1675
+ for (; i--;) {
1676
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1677
+ GET_DATA_STRIDE(p2, s2, dtype, y);
1678
+ x = m_pow(x, y);
1679
+ SET_DATA_STRIDE(p3, s3, dtype, x);
1848
1680
  }
1681
+ }
1849
1682
 
1850
- return;
1851
- //
1683
+ static void iter_robject_pow_int32(na_loop_t* const lp) {
1684
+ size_t i;
1685
+ char *p1, *p2, *p3;
1686
+ ssize_t s1, s2, s3;
1687
+ dtype x;
1688
+ int32_t y;
1689
+ INIT_COUNTER(lp, i);
1690
+ INIT_PTR(lp, 0, p1, s1);
1691
+ INIT_PTR(lp, 1, p2, s2);
1692
+ INIT_PTR(lp, 2, p3, s3);
1693
+ for (; i--;) {
1694
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1695
+ GET_DATA_STRIDE(p2, s2, int32_t, y);
1696
+ x = m_pow_int(x, y);
1697
+ SET_DATA_STRIDE(p3, s3, dtype, x);
1698
+ }
1852
1699
  }
1853
- #undef check_intdivzero
1854
1700
 
1855
- static VALUE robject_add_self(VALUE self, VALUE other) {
1701
+ static VALUE robject_pow_self(VALUE self, VALUE other) {
1856
1702
  ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
1703
+ ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
1857
1704
  ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1858
- ndfunc_t ndf = { iter_robject_add, STRIDE_LOOP, 2, 1, ain, aout };
1705
+ ndfunc_t ndf = { iter_robject_pow, STRIDE_LOOP, 2, 1, ain, aout };
1706
+ ndfunc_t ndf_i = { iter_robject_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
1859
1707
 
1860
- return na_ndloop(&ndf, 2, self, other);
1708
+ // fixme : use na.integer?
1709
+ if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
1710
+ return na_ndloop(&ndf_i, 2, self, other);
1711
+ } else {
1712
+ return na_ndloop(&ndf, 2, self, other);
1713
+ }
1861
1714
  }
1862
1715
 
1863
1716
  /*
1864
- Binary add.
1865
- @overload + other
1717
+ Binary power.
1718
+ @overload ** other
1866
1719
  @param [Numo::NArray,Numeric] other
1867
- @return [Numo::NArray] self + other
1720
+ @return [Numo::NArray] self to the other-th power.
1868
1721
  */
1869
- static VALUE robject_add(VALUE self, VALUE other) {
1870
- return robject_add_self(self, other);
1722
+ static VALUE robject_pow(VALUE self, VALUE other) {
1723
+ return robject_pow_self(self, other);
1871
1724
  }
1872
1725
 
1873
- #define check_intdivzero(y) \
1874
- {}
1875
-
1876
- static void iter_robject_sub(na_loop_t* const lp) {
1877
- size_t i = 0;
1878
- size_t n;
1879
- char *p1, *p2, *p3;
1880
- ssize_t s1, s2, s3;
1726
+ static void iter_robject_minus(na_loop_t* const lp) {
1727
+ size_t i, n;
1728
+ char *p1, *p2;
1729
+ ssize_t s1, s2;
1730
+ size_t *idx1, *idx2;
1731
+ dtype x;
1881
1732
 
1882
1733
  INIT_COUNTER(lp, n);
1883
- INIT_PTR(lp, 0, p1, s1);
1884
- INIT_PTR(lp, 1, p2, s2);
1885
- INIT_PTR(lp, 2, p3, s3);
1886
-
1887
- //
1734
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1735
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1888
1736
 
1889
- if (s2 == 0) { // Broadcasting from scalar value.
1890
- check_intdivzero(*(dtype*)p2);
1891
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
1892
- if (p1 == p3) { // inplace case
1893
- for (; i < n; i++) {
1894
- ((dtype*)p1)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
1895
- }
1896
- } else {
1897
- for (; i < n; i++) {
1898
- ((dtype*)p3)[i] = m_sub(((dtype*)p1)[i], *(dtype*)p2);
1899
- }
1737
+ if (idx1) {
1738
+ if (idx2) {
1739
+ for (i = 0; i < n; i++) {
1740
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1741
+ x = m_minus(x);
1742
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1900
1743
  }
1901
1744
  } else {
1902
1745
  for (i = 0; i < n; i++) {
1903
- *(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
1904
- p1 += s1;
1905
- p3 += s3;
1746
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1747
+ x = m_minus(x);
1748
+ SET_DATA_STRIDE(p2, s2, dtype, x);
1906
1749
  }
1907
1750
  }
1908
1751
  } else {
1909
- if (p1 == p3) { // inplace case
1752
+ if (idx2) {
1910
1753
  for (i = 0; i < n; i++) {
1911
- check_intdivzero(*(dtype*)p2);
1912
- *(dtype*)p1 = m_sub(*(dtype*)p1, *(dtype*)p2);
1913
- p1 += s1;
1914
- p2 += s2;
1754
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1755
+ x = m_minus(x);
1756
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1915
1757
  }
1916
1758
  } else {
1759
+ //
1917
1760
  for (i = 0; i < n; i++) {
1918
- check_intdivzero(*(dtype*)p2);
1919
- *(dtype*)p3 = m_sub(*(dtype*)p1, *(dtype*)p2);
1761
+ *(dtype*)p2 = m_minus(*(dtype*)p1);
1920
1762
  p1 += s1;
1921
1763
  p2 += s2;
1922
- p3 += s3;
1923
1764
  }
1765
+ return;
1766
+ //
1924
1767
  }
1925
1768
  }
1926
-
1927
- return;
1928
- //
1929
- }
1930
- #undef check_intdivzero
1931
-
1932
- static VALUE robject_sub_self(VALUE self, VALUE other) {
1933
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
1934
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1935
- ndfunc_t ndf = { iter_robject_sub, STRIDE_LOOP, 2, 1, ain, aout };
1936
-
1937
- return na_ndloop(&ndf, 2, self, other);
1938
1769
  }
1939
1770
 
1940
1771
  /*
1941
- Binary sub.
1942
- @overload - other
1943
- @param [Numo::NArray,Numeric] other
1944
- @return [Numo::NArray] self - other
1772
+ Unary minus.
1773
+ @overload -@
1774
+ @return [Numo::RObject] minus of self.
1945
1775
  */
1946
- static VALUE robject_sub(VALUE self, VALUE other) {
1947
- return robject_sub_self(self, other);
1948
- }
1776
+ static VALUE robject_minus(VALUE self) {
1777
+ ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1778
+ ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1779
+ ndfunc_t ndf = { iter_robject_minus, FULL_LOOP, 1, 1, ain, aout };
1949
1780
 
1950
- #define check_intdivzero(y) \
1951
- {}
1781
+ return na_ndloop(&ndf, 1, self);
1782
+ }
1952
1783
 
1953
- static void iter_robject_mul(na_loop_t* const lp) {
1954
- size_t i = 0;
1955
- size_t n;
1956
- char *p1, *p2, *p3;
1957
- ssize_t s1, s2, s3;
1784
+ static void iter_robject_reciprocal(na_loop_t* const lp) {
1785
+ size_t i, n;
1786
+ char *p1, *p2;
1787
+ ssize_t s1, s2;
1788
+ size_t *idx1, *idx2;
1789
+ dtype x;
1958
1790
 
1959
1791
  INIT_COUNTER(lp, n);
1960
- INIT_PTR(lp, 0, p1, s1);
1961
- INIT_PTR(lp, 1, p2, s2);
1962
- INIT_PTR(lp, 2, p3, s3);
1963
-
1964
- //
1792
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1793
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1965
1794
 
1966
- if (s2 == 0) { // Broadcasting from scalar value.
1967
- check_intdivzero(*(dtype*)p2);
1968
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
1969
- if (p1 == p3) { // inplace case
1970
- for (; i < n; i++) {
1971
- ((dtype*)p1)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
1972
- }
1973
- } else {
1974
- for (; i < n; i++) {
1975
- ((dtype*)p3)[i] = m_mul(((dtype*)p1)[i], *(dtype*)p2);
1976
- }
1795
+ if (idx1) {
1796
+ if (idx2) {
1797
+ for (i = 0; i < n; i++) {
1798
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1799
+ x = m_reciprocal(x);
1800
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1977
1801
  }
1978
1802
  } else {
1979
1803
  for (i = 0; i < n; i++) {
1980
- *(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
1981
- p1 += s1;
1982
- p3 += s3;
1804
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1805
+ x = m_reciprocal(x);
1806
+ SET_DATA_STRIDE(p2, s2, dtype, x);
1983
1807
  }
1984
1808
  }
1985
1809
  } else {
1986
- if (p1 == p3) { // inplace case
1810
+ if (idx2) {
1987
1811
  for (i = 0; i < n; i++) {
1988
- check_intdivzero(*(dtype*)p2);
1989
- *(dtype*)p1 = m_mul(*(dtype*)p1, *(dtype*)p2);
1990
- p1 += s1;
1991
- p2 += s2;
1812
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1813
+ x = m_reciprocal(x);
1814
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1992
1815
  }
1993
1816
  } else {
1817
+ //
1994
1818
  for (i = 0; i < n; i++) {
1995
- check_intdivzero(*(dtype*)p2);
1996
- *(dtype*)p3 = m_mul(*(dtype*)p1, *(dtype*)p2);
1997
- p1 += s1;
1998
- p2 += s2;
1999
- p3 += s3;
2000
- }
2001
- }
2002
- }
2003
-
2004
- return;
2005
- //
2006
- }
2007
- #undef check_intdivzero
2008
-
2009
- static VALUE robject_mul_self(VALUE self, VALUE other) {
2010
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2011
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2012
- ndfunc_t ndf = { iter_robject_mul, STRIDE_LOOP, 2, 1, ain, aout };
2013
-
2014
- return na_ndloop(&ndf, 2, self, other);
2015
- }
2016
-
2017
- /*
2018
- Binary mul.
2019
- @overload * other
2020
- @param [Numo::NArray,Numeric] other
2021
- @return [Numo::NArray] self * other
2022
- */
2023
- static VALUE robject_mul(VALUE self, VALUE other) {
2024
- return robject_mul_self(self, other);
2025
- }
2026
-
2027
- #define check_intdivzero(y) \
2028
- if ((y) == 0) { \
2029
- lp->err_type = rb_eZeroDivError; \
2030
- return; \
2031
- }
2032
-
2033
- static void iter_robject_div(na_loop_t* const lp) {
2034
- size_t i = 0;
2035
- size_t n;
2036
- char *p1, *p2, *p3;
2037
- ssize_t s1, s2, s3;
2038
-
2039
- INIT_COUNTER(lp, n);
2040
- INIT_PTR(lp, 0, p1, s1);
2041
- INIT_PTR(lp, 1, p2, s2);
2042
- INIT_PTR(lp, 2, p3, s3);
2043
-
2044
- //
2045
-
2046
- if (s2 == 0) { // Broadcasting from scalar value.
2047
- check_intdivzero(*(dtype*)p2);
2048
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2049
- if (p1 == p3) { // inplace case
2050
- for (; i < n; i++) {
2051
- ((dtype*)p1)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
2052
- }
2053
- } else {
2054
- for (; i < n; i++) {
2055
- ((dtype*)p3)[i] = m_div(((dtype*)p1)[i], *(dtype*)p2);
2056
- }
2057
- }
2058
- } else {
2059
- for (i = 0; i < n; i++) {
2060
- *(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
2061
- p1 += s1;
2062
- p3 += s3;
2063
- }
2064
- }
2065
- } else {
2066
- if (p1 == p3) { // inplace case
2067
- for (i = 0; i < n; i++) {
2068
- check_intdivzero(*(dtype*)p2);
2069
- *(dtype*)p1 = m_div(*(dtype*)p1, *(dtype*)p2);
2070
- p1 += s1;
2071
- p2 += s2;
2072
- }
2073
- } else {
2074
- for (i = 0; i < n; i++) {
2075
- check_intdivzero(*(dtype*)p2);
2076
- *(dtype*)p3 = m_div(*(dtype*)p1, *(dtype*)p2);
2077
- p1 += s1;
2078
- p2 += s2;
2079
- p3 += s3;
2080
- }
2081
- }
2082
- }
2083
-
2084
- return;
2085
- //
2086
- }
2087
- #undef check_intdivzero
2088
-
2089
- static VALUE robject_div_self(VALUE self, VALUE other) {
2090
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2091
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2092
- ndfunc_t ndf = { iter_robject_div, STRIDE_LOOP, 2, 1, ain, aout };
2093
-
2094
- return na_ndloop(&ndf, 2, self, other);
2095
- }
2096
-
2097
- /*
2098
- Binary div.
2099
- @overload / other
2100
- @param [Numo::NArray,Numeric] other
2101
- @return [Numo::NArray] self / other
2102
- */
2103
- static VALUE robject_div(VALUE self, VALUE other) {
2104
- return robject_div_self(self, other);
2105
- }
2106
-
2107
- #define check_intdivzero(y) \
2108
- if ((y) == 0) { \
2109
- lp->err_type = rb_eZeroDivError; \
2110
- return; \
2111
- }
2112
-
2113
- static void iter_robject_mod(na_loop_t* const lp) {
2114
- size_t i = 0;
2115
- size_t n;
2116
- char *p1, *p2, *p3;
2117
- ssize_t s1, s2, s3;
2118
-
2119
- INIT_COUNTER(lp, n);
2120
- INIT_PTR(lp, 0, p1, s1);
2121
- INIT_PTR(lp, 1, p2, s2);
2122
- INIT_PTR(lp, 2, p3, s3);
2123
-
2124
- //
2125
-
2126
- if (s2 == 0) { // Broadcasting from scalar value.
2127
- check_intdivzero(*(dtype*)p2);
2128
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2129
- if (p1 == p3) { // inplace case
2130
- for (; i < n; i++) {
2131
- ((dtype*)p1)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
2132
- }
2133
- } else {
2134
- for (; i < n; i++) {
2135
- ((dtype*)p3)[i] = m_mod(((dtype*)p1)[i], *(dtype*)p2);
2136
- }
2137
- }
2138
- } else {
2139
- for (i = 0; i < n; i++) {
2140
- *(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
2141
- p1 += s1;
2142
- p3 += s3;
2143
- }
2144
- }
2145
- } else {
2146
- if (p1 == p3) { // inplace case
2147
- for (i = 0; i < n; i++) {
2148
- check_intdivzero(*(dtype*)p2);
2149
- *(dtype*)p1 = m_mod(*(dtype*)p1, *(dtype*)p2);
2150
- p1 += s1;
2151
- p2 += s2;
2152
- }
2153
- } else {
2154
- for (i = 0; i < n; i++) {
2155
- check_intdivzero(*(dtype*)p2);
2156
- *(dtype*)p3 = m_mod(*(dtype*)p1, *(dtype*)p2);
2157
- p1 += s1;
2158
- p2 += s2;
2159
- p3 += s3;
2160
- }
2161
- }
2162
- }
2163
-
2164
- return;
2165
- //
2166
- }
2167
- #undef check_intdivzero
2168
-
2169
- static VALUE robject_mod_self(VALUE self, VALUE other) {
2170
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2171
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2172
- ndfunc_t ndf = { iter_robject_mod, STRIDE_LOOP, 2, 1, ain, aout };
2173
-
2174
- return na_ndloop(&ndf, 2, self, other);
2175
- }
2176
-
2177
- /*
2178
- Binary mod.
2179
- @overload % other
2180
- @param [Numo::NArray,Numeric] other
2181
- @return [Numo::NArray] self % other
2182
- */
2183
- static VALUE robject_mod(VALUE self, VALUE other) {
2184
- return robject_mod_self(self, other);
2185
- }
2186
-
2187
- static void iter_robject_divmod(na_loop_t* const lp) {
2188
- size_t i, n;
2189
- char *p1, *p2, *p3, *p4;
2190
- ssize_t s1, s2, s3, s4;
2191
- dtype x, y, a, b;
2192
- INIT_COUNTER(lp, n);
2193
- INIT_PTR(lp, 0, p1, s1);
2194
- INIT_PTR(lp, 1, p2, s2);
2195
- INIT_PTR(lp, 2, p3, s3);
2196
- INIT_PTR(lp, 3, p4, s4);
2197
- for (i = n; i--;) {
2198
- GET_DATA_STRIDE(p1, s1, dtype, x);
2199
- GET_DATA_STRIDE(p2, s2, dtype, y);
2200
- if (y == 0) {
2201
- lp->err_type = rb_eZeroDivError;
2202
- return;
2203
- }
2204
- m_divmod(x, y, a, b);
2205
- SET_DATA_STRIDE(p3, s3, dtype, a);
2206
- SET_DATA_STRIDE(p4, s4, dtype, b);
2207
- }
2208
- }
2209
-
2210
- static VALUE robject_divmod_self(VALUE self, VALUE other) {
2211
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2212
- ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
2213
- ndfunc_t ndf = { iter_robject_divmod, STRIDE_LOOP, 2, 2, ain, aout };
2214
-
2215
- return na_ndloop(&ndf, 2, self, other);
2216
- }
2217
-
2218
- /*
2219
- Binary divmod.
2220
- @overload divmod other
2221
- @param [Numo::NArray,Numeric] other
2222
- @return [Numo::NArray] divmod of self and other.
2223
- */
2224
- static VALUE robject_divmod(VALUE self, VALUE other) {
2225
- return robject_divmod_self(self, other);
2226
- }
2227
-
2228
- static void iter_robject_pow(na_loop_t* const lp) {
2229
- size_t i;
2230
- char *p1, *p2, *p3;
2231
- ssize_t s1, s2, s3;
2232
- dtype x, y;
2233
- INIT_COUNTER(lp, i);
2234
- INIT_PTR(lp, 0, p1, s1);
2235
- INIT_PTR(lp, 1, p2, s2);
2236
- INIT_PTR(lp, 2, p3, s3);
2237
- for (; i--;) {
2238
- GET_DATA_STRIDE(p1, s1, dtype, x);
2239
- GET_DATA_STRIDE(p2, s2, dtype, y);
2240
- x = m_pow(x, y);
2241
- SET_DATA_STRIDE(p3, s3, dtype, x);
2242
- }
2243
- }
2244
-
2245
- static void iter_robject_pow_int32(na_loop_t* const lp) {
2246
- size_t i;
2247
- char *p1, *p2, *p3;
2248
- ssize_t s1, s2, s3;
2249
- dtype x;
2250
- int32_t y;
2251
- INIT_COUNTER(lp, i);
2252
- INIT_PTR(lp, 0, p1, s1);
2253
- INIT_PTR(lp, 1, p2, s2);
2254
- INIT_PTR(lp, 2, p3, s3);
2255
- for (; i--;) {
2256
- GET_DATA_STRIDE(p1, s1, dtype, x);
2257
- GET_DATA_STRIDE(p2, s2, int32_t, y);
2258
- x = m_pow_int(x, y);
2259
- SET_DATA_STRIDE(p3, s3, dtype, x);
2260
- }
2261
- }
2262
-
2263
- static VALUE robject_pow_self(VALUE self, VALUE other) {
2264
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2265
- ndfunc_arg_in_t ain_i[2] = { { cT, 0 }, { numo_cInt32, 0 } };
2266
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2267
- ndfunc_t ndf = { iter_robject_pow, STRIDE_LOOP, 2, 1, ain, aout };
2268
- ndfunc_t ndf_i = { iter_robject_pow_int32, STRIDE_LOOP, 2, 1, ain_i, aout };
2269
-
2270
- // fixme : use na.integer?
2271
- if (FIXNUM_P(other) || rb_obj_is_kind_of(other, numo_cInt32)) {
2272
- return na_ndloop(&ndf_i, 2, self, other);
2273
- } else {
2274
- return na_ndloop(&ndf, 2, self, other);
2275
- }
2276
- }
2277
-
2278
- /*
2279
- Binary power.
2280
- @overload ** other
2281
- @param [Numo::NArray,Numeric] other
2282
- @return [Numo::NArray] self to the other-th power.
2283
- */
2284
- static VALUE robject_pow(VALUE self, VALUE other) {
2285
- return robject_pow_self(self, other);
2286
- }
2287
-
2288
- static void iter_robject_minus(na_loop_t* const lp) {
2289
- size_t i, n;
2290
- char *p1, *p2;
2291
- ssize_t s1, s2;
2292
- size_t *idx1, *idx2;
2293
- dtype x;
2294
-
2295
- INIT_COUNTER(lp, n);
2296
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2297
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2298
-
2299
- if (idx1) {
2300
- if (idx2) {
2301
- for (i = 0; i < n; i++) {
2302
- GET_DATA_INDEX(p1, idx1, dtype, x);
2303
- x = m_minus(x);
2304
- SET_DATA_INDEX(p2, idx2, dtype, x);
2305
- }
2306
- } else {
2307
- for (i = 0; i < n; i++) {
2308
- GET_DATA_INDEX(p1, idx1, dtype, x);
2309
- x = m_minus(x);
2310
- SET_DATA_STRIDE(p2, s2, dtype, x);
2311
- }
2312
- }
2313
- } else {
2314
- if (idx2) {
2315
- for (i = 0; i < n; i++) {
2316
- GET_DATA_STRIDE(p1, s1, dtype, x);
2317
- x = m_minus(x);
2318
- SET_DATA_INDEX(p2, idx2, dtype, x);
2319
- }
2320
- } else {
2321
- //
2322
- for (i = 0; i < n; i++) {
2323
- *(dtype*)p2 = m_minus(*(dtype*)p1);
2324
- p1 += s1;
2325
- p2 += s2;
2326
- }
2327
- return;
2328
- //
2329
- }
2330
- }
2331
- }
2332
-
2333
- /*
2334
- Unary minus.
2335
- @overload -@
2336
- @return [Numo::RObject] minus of self.
2337
- */
2338
- static VALUE robject_minus(VALUE self) {
2339
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2340
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2341
- ndfunc_t ndf = { iter_robject_minus, FULL_LOOP, 1, 1, ain, aout };
2342
-
2343
- return na_ndloop(&ndf, 1, self);
2344
- }
2345
-
2346
- static void iter_robject_reciprocal(na_loop_t* const lp) {
2347
- size_t i, n;
2348
- char *p1, *p2;
2349
- ssize_t s1, s2;
2350
- size_t *idx1, *idx2;
2351
- dtype x;
2352
-
2353
- INIT_COUNTER(lp, n);
2354
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2355
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2356
-
2357
- if (idx1) {
2358
- if (idx2) {
2359
- for (i = 0; i < n; i++) {
2360
- GET_DATA_INDEX(p1, idx1, dtype, x);
2361
- x = m_reciprocal(x);
2362
- SET_DATA_INDEX(p2, idx2, dtype, x);
2363
- }
2364
- } else {
2365
- for (i = 0; i < n; i++) {
2366
- GET_DATA_INDEX(p1, idx1, dtype, x);
2367
- x = m_reciprocal(x);
2368
- SET_DATA_STRIDE(p2, s2, dtype, x);
2369
- }
2370
- }
2371
- } else {
2372
- if (idx2) {
2373
- for (i = 0; i < n; i++) {
2374
- GET_DATA_STRIDE(p1, s1, dtype, x);
2375
- x = m_reciprocal(x);
2376
- SET_DATA_INDEX(p2, idx2, dtype, x);
2377
- }
2378
- } else {
2379
- //
2380
- for (i = 0; i < n; i++) {
2381
- *(dtype*)p2 = m_reciprocal(*(dtype*)p1);
2382
- p1 += s1;
2383
- p2 += s2;
2384
- }
2385
- return;
2386
- //
2387
- }
2388
- }
2389
- }
2390
-
2391
- /*
2392
- Unary reciprocal.
2393
- @overload reciprocal
2394
- @return [Numo::RObject] reciprocal of self.
2395
- */
2396
- static VALUE robject_reciprocal(VALUE self) {
2397
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2398
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2399
- ndfunc_t ndf = { iter_robject_reciprocal, FULL_LOOP, 1, 1, ain, aout };
2400
-
2401
- return na_ndloop(&ndf, 1, self);
2402
- }
2403
-
2404
- static void iter_robject_sign(na_loop_t* const lp) {
2405
- size_t i, n;
2406
- char *p1, *p2;
2407
- ssize_t s1, s2;
2408
- size_t *idx1, *idx2;
2409
- dtype x;
2410
-
2411
- INIT_COUNTER(lp, n);
2412
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2413
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2414
-
2415
- if (idx1) {
2416
- if (idx2) {
2417
- for (i = 0; i < n; i++) {
2418
- GET_DATA_INDEX(p1, idx1, dtype, x);
2419
- x = m_sign(x);
2420
- SET_DATA_INDEX(p2, idx2, dtype, x);
2421
- }
2422
- } else {
2423
- for (i = 0; i < n; i++) {
2424
- GET_DATA_INDEX(p1, idx1, dtype, x);
2425
- x = m_sign(x);
2426
- SET_DATA_STRIDE(p2, s2, dtype, x);
2427
- }
2428
- }
2429
- } else {
2430
- if (idx2) {
2431
- for (i = 0; i < n; i++) {
2432
- GET_DATA_STRIDE(p1, s1, dtype, x);
2433
- x = m_sign(x);
2434
- SET_DATA_INDEX(p2, idx2, dtype, x);
2435
- }
2436
- } else {
2437
- //
2438
- for (i = 0; i < n; i++) {
2439
- *(dtype*)p2 = m_sign(*(dtype*)p1);
2440
- p1 += s1;
2441
- p2 += s2;
2442
- }
2443
- return;
2444
- //
2445
- }
2446
- }
2447
- }
2448
-
2449
- /*
2450
- Unary sign.
2451
- @overload sign
2452
- @return [Numo::RObject] sign of self.
2453
- */
2454
- static VALUE robject_sign(VALUE self) {
2455
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2456
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2457
- ndfunc_t ndf = { iter_robject_sign, FULL_LOOP, 1, 1, ain, aout };
2458
-
2459
- return na_ndloop(&ndf, 1, self);
2460
- }
2461
-
2462
- static void iter_robject_square(na_loop_t* const lp) {
2463
- size_t i, n;
2464
- char *p1, *p2;
2465
- ssize_t s1, s2;
2466
- size_t *idx1, *idx2;
2467
- dtype x;
2468
-
2469
- INIT_COUNTER(lp, n);
2470
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2471
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2472
-
2473
- if (idx1) {
2474
- if (idx2) {
2475
- for (i = 0; i < n; i++) {
2476
- GET_DATA_INDEX(p1, idx1, dtype, x);
2477
- x = m_square(x);
2478
- SET_DATA_INDEX(p2, idx2, dtype, x);
2479
- }
2480
- } else {
2481
- for (i = 0; i < n; i++) {
2482
- GET_DATA_INDEX(p1, idx1, dtype, x);
2483
- x = m_square(x);
2484
- SET_DATA_STRIDE(p2, s2, dtype, x);
2485
- }
2486
- }
2487
- } else {
2488
- if (idx2) {
2489
- for (i = 0; i < n; i++) {
2490
- GET_DATA_STRIDE(p1, s1, dtype, x);
2491
- x = m_square(x);
2492
- SET_DATA_INDEX(p2, idx2, dtype, x);
2493
- }
2494
- } else {
2495
- //
2496
- for (i = 0; i < n; i++) {
2497
- *(dtype*)p2 = m_square(*(dtype*)p1);
2498
- p1 += s1;
2499
- p2 += s2;
2500
- }
2501
- return;
2502
- //
2503
- }
2504
- }
2505
- }
2506
-
2507
- /*
2508
- Unary square.
2509
- @overload square
2510
- @return [Numo::RObject] square of self.
2511
- */
2512
- static VALUE robject_square(VALUE self) {
2513
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2514
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2515
- ndfunc_t ndf = { iter_robject_square, FULL_LOOP, 1, 1, ain, aout };
2516
-
2517
- return na_ndloop(&ndf, 1, self);
2518
- }
2519
-
2520
- static void iter_robject_eq(na_loop_t* const lp) {
2521
- size_t i;
2522
- char *p1, *p2;
2523
- BIT_DIGIT* a3;
2524
- size_t p3;
2525
- ssize_t s1, s2, s3;
2526
- dtype x, y;
2527
- BIT_DIGIT b;
2528
- INIT_COUNTER(lp, i);
2529
- INIT_PTR(lp, 0, p1, s1);
2530
- INIT_PTR(lp, 1, p2, s2);
2531
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
2532
- for (; i--;) {
2533
- GET_DATA_STRIDE(p1, s1, dtype, x);
2534
- GET_DATA_STRIDE(p2, s2, dtype, y);
2535
- b = (m_eq(x, y)) ? 1 : 0;
2536
- STORE_BIT(a3, p3, b);
2537
- p3 += s3;
2538
- }
2539
- }
2540
-
2541
- static VALUE robject_eq_self(VALUE self, VALUE other) {
2542
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2543
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
2544
- ndfunc_t ndf = { iter_robject_eq, STRIDE_LOOP, 2, 1, ain, aout };
2545
-
2546
- return na_ndloop(&ndf, 2, self, other);
2547
- }
2548
-
2549
- /*
2550
- Comparison eq other.
2551
- @overload eq other
2552
- @param [Numo::NArray,Numeric] other
2553
- @return [Numo::Bit] result of self eq other.
2554
- */
2555
- static VALUE robject_eq(VALUE self, VALUE other) {
2556
- return robject_eq_self(self, other);
2557
- }
2558
-
2559
- static void iter_robject_ne(na_loop_t* const lp) {
2560
- size_t i;
2561
- char *p1, *p2;
2562
- BIT_DIGIT* a3;
2563
- size_t p3;
2564
- ssize_t s1, s2, s3;
2565
- dtype x, y;
2566
- BIT_DIGIT b;
2567
- INIT_COUNTER(lp, i);
2568
- INIT_PTR(lp, 0, p1, s1);
2569
- INIT_PTR(lp, 1, p2, s2);
2570
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
2571
- for (; i--;) {
2572
- GET_DATA_STRIDE(p1, s1, dtype, x);
2573
- GET_DATA_STRIDE(p2, s2, dtype, y);
2574
- b = (m_ne(x, y)) ? 1 : 0;
2575
- STORE_BIT(a3, p3, b);
2576
- p3 += s3;
2577
- }
2578
- }
2579
-
2580
- static VALUE robject_ne_self(VALUE self, VALUE other) {
2581
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2582
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
2583
- ndfunc_t ndf = { iter_robject_ne, STRIDE_LOOP, 2, 1, ain, aout };
2584
-
2585
- return na_ndloop(&ndf, 2, self, other);
2586
- }
2587
-
2588
- /*
2589
- Comparison ne other.
2590
- @overload ne other
2591
- @param [Numo::NArray,Numeric] other
2592
- @return [Numo::Bit] result of self ne other.
2593
- */
2594
- static VALUE robject_ne(VALUE self, VALUE other) {
2595
- return robject_ne_self(self, other);
2596
- }
2597
-
2598
- static void iter_robject_nearly_eq(na_loop_t* const lp) {
2599
- size_t i;
2600
- char *p1, *p2;
2601
- BIT_DIGIT* a3;
2602
- size_t p3;
2603
- ssize_t s1, s2, s3;
2604
- dtype x, y;
2605
- BIT_DIGIT b;
2606
- INIT_COUNTER(lp, i);
2607
- INIT_PTR(lp, 0, p1, s1);
2608
- INIT_PTR(lp, 1, p2, s2);
2609
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
2610
- for (; i--;) {
2611
- GET_DATA_STRIDE(p1, s1, dtype, x);
2612
- GET_DATA_STRIDE(p2, s2, dtype, y);
2613
- b = (m_nearly_eq(x, y)) ? 1 : 0;
2614
- STORE_BIT(a3, p3, b);
2615
- p3 += s3;
2616
- }
2617
- }
2618
-
2619
- static VALUE robject_nearly_eq_self(VALUE self, VALUE other) {
2620
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2621
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
2622
- ndfunc_t ndf = { iter_robject_nearly_eq, STRIDE_LOOP, 2, 1, ain, aout };
2623
-
2624
- return na_ndloop(&ndf, 2, self, other);
2625
- }
2626
-
2627
- /*
2628
- Comparison nearly_eq other.
2629
- @overload nearly_eq other
2630
- @param [Numo::NArray,Numeric] other
2631
- @return [Numo::Bit] result of self nearly_eq other.
2632
- */
2633
- static VALUE robject_nearly_eq(VALUE self, VALUE other) {
2634
- return robject_nearly_eq_self(self, other);
2635
- }
2636
-
2637
- #define check_intdivzero(y) \
2638
- {}
2639
-
2640
- static void iter_robject_bit_and(na_loop_t* const lp) {
2641
- size_t i = 0;
2642
- size_t n;
2643
- char *p1, *p2, *p3;
2644
- ssize_t s1, s2, s3;
2645
-
2646
- INIT_COUNTER(lp, n);
2647
- INIT_PTR(lp, 0, p1, s1);
2648
- INIT_PTR(lp, 1, p2, s2);
2649
- INIT_PTR(lp, 2, p3, s3);
2650
-
2651
- //
2652
-
2653
- if (s2 == 0) { // Broadcasting from scalar value.
2654
- check_intdivzero(*(dtype*)p2);
2655
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2656
- if (p1 == p3) { // inplace case
2657
- for (; i < n; i++) {
2658
- ((dtype*)p1)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
2659
- }
2660
- } else {
2661
- for (; i < n; i++) {
2662
- ((dtype*)p3)[i] = m_bit_and(((dtype*)p1)[i], *(dtype*)p2);
2663
- }
2664
- }
2665
- } else {
2666
- for (i = 0; i < n; i++) {
2667
- *(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
2668
- p1 += s1;
2669
- p3 += s3;
2670
- }
2671
- }
2672
- } else {
2673
- if (p1 == p3) { // inplace case
2674
- for (i = 0; i < n; i++) {
2675
- check_intdivzero(*(dtype*)p2);
2676
- *(dtype*)p1 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
2677
- p1 += s1;
2678
- p2 += s2;
2679
- }
2680
- } else {
2681
- for (i = 0; i < n; i++) {
2682
- check_intdivzero(*(dtype*)p2);
2683
- *(dtype*)p3 = m_bit_and(*(dtype*)p1, *(dtype*)p2);
2684
- p1 += s1;
2685
- p2 += s2;
2686
- p3 += s3;
2687
- }
2688
- }
2689
- }
2690
-
2691
- return;
2692
- //
2693
- }
2694
- #undef check_intdivzero
2695
-
2696
- static VALUE robject_bit_and_self(VALUE self, VALUE other) {
2697
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2698
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2699
- ndfunc_t ndf = { iter_robject_bit_and, STRIDE_LOOP, 2, 1, ain, aout };
2700
-
2701
- return na_ndloop(&ndf, 2, self, other);
2702
- }
2703
-
2704
- /*
2705
- Binary bit_and.
2706
- @overload & other
2707
- @param [Numo::NArray,Numeric] other
2708
- @return [Numo::NArray] self & other
2709
- */
2710
- static VALUE robject_bit_and(VALUE self, VALUE other) {
2711
- return robject_bit_and_self(self, other);
2712
- }
2713
-
2714
- #define check_intdivzero(y) \
2715
- {}
2716
-
2717
- static void iter_robject_bit_or(na_loop_t* const lp) {
2718
- size_t i = 0;
2719
- size_t n;
2720
- char *p1, *p2, *p3;
2721
- ssize_t s1, s2, s3;
2722
-
2723
- INIT_COUNTER(lp, n);
2724
- INIT_PTR(lp, 0, p1, s1);
2725
- INIT_PTR(lp, 1, p2, s2);
2726
- INIT_PTR(lp, 2, p3, s3);
2727
-
2728
- //
2729
-
2730
- if (s2 == 0) { // Broadcasting from scalar value.
2731
- check_intdivzero(*(dtype*)p2);
2732
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2733
- if (p1 == p3) { // inplace case
2734
- for (; i < n; i++) {
2735
- ((dtype*)p1)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
2736
- }
2737
- } else {
2738
- for (; i < n; i++) {
2739
- ((dtype*)p3)[i] = m_bit_or(((dtype*)p1)[i], *(dtype*)p2);
2740
- }
2741
- }
2742
- } else {
2743
- for (i = 0; i < n; i++) {
2744
- *(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
2745
- p1 += s1;
2746
- p3 += s3;
2747
- }
2748
- }
2749
- } else {
2750
- if (p1 == p3) { // inplace case
2751
- for (i = 0; i < n; i++) {
2752
- check_intdivzero(*(dtype*)p2);
2753
- *(dtype*)p1 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
2754
- p1 += s1;
2755
- p2 += s2;
2756
- }
2757
- } else {
2758
- for (i = 0; i < n; i++) {
2759
- check_intdivzero(*(dtype*)p2);
2760
- *(dtype*)p3 = m_bit_or(*(dtype*)p1, *(dtype*)p2);
2761
- p1 += s1;
2762
- p2 += s2;
2763
- p3 += s3;
2764
- }
2765
- }
2766
- }
2767
-
2768
- return;
2769
- //
2770
- }
2771
- #undef check_intdivzero
2772
-
2773
- static VALUE robject_bit_or_self(VALUE self, VALUE other) {
2774
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2775
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2776
- ndfunc_t ndf = { iter_robject_bit_or, STRIDE_LOOP, 2, 1, ain, aout };
2777
-
2778
- return na_ndloop(&ndf, 2, self, other);
2779
- }
2780
-
2781
- /*
2782
- Binary bit_or.
2783
- @overload | other
2784
- @param [Numo::NArray,Numeric] other
2785
- @return [Numo::NArray] self | other
2786
- */
2787
- static VALUE robject_bit_or(VALUE self, VALUE other) {
2788
- return robject_bit_or_self(self, other);
2789
- }
2790
-
2791
- #define check_intdivzero(y) \
2792
- {}
2793
-
2794
- static void iter_robject_bit_xor(na_loop_t* const lp) {
2795
- size_t i = 0;
2796
- size_t n;
2797
- char *p1, *p2, *p3;
2798
- ssize_t s1, s2, s3;
2799
-
2800
- INIT_COUNTER(lp, n);
2801
- INIT_PTR(lp, 0, p1, s1);
2802
- INIT_PTR(lp, 1, p2, s2);
2803
- INIT_PTR(lp, 2, p3, s3);
2804
-
2805
- //
2806
-
2807
- if (s2 == 0) { // Broadcasting from scalar value.
2808
- check_intdivzero(*(dtype*)p2);
2809
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2810
- if (p1 == p3) { // inplace case
2811
- for (; i < n; i++) {
2812
- ((dtype*)p1)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
2813
- }
2814
- } else {
2815
- for (; i < n; i++) {
2816
- ((dtype*)p3)[i] = m_bit_xor(((dtype*)p1)[i], *(dtype*)p2);
2817
- }
2818
- }
2819
- } else {
2820
- for (i = 0; i < n; i++) {
2821
- *(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
2822
- p1 += s1;
2823
- p3 += s3;
2824
- }
2825
- }
2826
- } else {
2827
- if (p1 == p3) { // inplace case
2828
- for (i = 0; i < n; i++) {
2829
- check_intdivzero(*(dtype*)p2);
2830
- *(dtype*)p1 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
2831
- p1 += s1;
2832
- p2 += s2;
2833
- }
2834
- } else {
2835
- for (i = 0; i < n; i++) {
2836
- check_intdivzero(*(dtype*)p2);
2837
- *(dtype*)p3 = m_bit_xor(*(dtype*)p1, *(dtype*)p2);
2838
- p1 += s1;
2839
- p2 += s2;
2840
- p3 += s3;
2841
- }
2842
- }
2843
- }
2844
-
2845
- return;
2846
- //
2847
- }
2848
- #undef check_intdivzero
2849
-
2850
- static VALUE robject_bit_xor_self(VALUE self, VALUE other) {
2851
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2852
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2853
- ndfunc_t ndf = { iter_robject_bit_xor, STRIDE_LOOP, 2, 1, ain, aout };
2854
-
2855
- return na_ndloop(&ndf, 2, self, other);
2856
- }
2857
-
2858
- /*
2859
- Binary bit_xor.
2860
- @overload ^ other
2861
- @param [Numo::NArray,Numeric] other
2862
- @return [Numo::NArray] self ^ other
2863
- */
2864
- static VALUE robject_bit_xor(VALUE self, VALUE other) {
2865
- return robject_bit_xor_self(self, other);
2866
- }
2867
-
2868
- static void iter_robject_bit_not(na_loop_t* const lp) {
2869
- size_t i, n;
2870
- char *p1, *p2;
2871
- ssize_t s1, s2;
2872
- size_t *idx1, *idx2;
2873
- dtype x;
2874
-
2875
- INIT_COUNTER(lp, n);
2876
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
2877
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
2878
-
2879
- if (idx1) {
2880
- if (idx2) {
2881
- for (i = 0; i < n; i++) {
2882
- GET_DATA_INDEX(p1, idx1, dtype, x);
2883
- x = m_bit_not(x);
2884
- SET_DATA_INDEX(p2, idx2, dtype, x);
2885
- }
2886
- } else {
2887
- for (i = 0; i < n; i++) {
2888
- GET_DATA_INDEX(p1, idx1, dtype, x);
2889
- x = m_bit_not(x);
2890
- SET_DATA_STRIDE(p2, s2, dtype, x);
2891
- }
2892
- }
2893
- } else {
2894
- if (idx2) {
2895
- for (i = 0; i < n; i++) {
2896
- GET_DATA_STRIDE(p1, s1, dtype, x);
2897
- x = m_bit_not(x);
2898
- SET_DATA_INDEX(p2, idx2, dtype, x);
2899
- }
2900
- } else {
2901
- //
2902
- for (i = 0; i < n; i++) {
2903
- *(dtype*)p2 = m_bit_not(*(dtype*)p1);
2904
- p1 += s1;
2905
- p2 += s2;
2906
- }
2907
- return;
2908
- //
2909
- }
2910
- }
2911
- }
2912
-
2913
- /*
2914
- Unary bit_not.
2915
- @overload ~
2916
- @return [Numo::RObject] bit_not of self.
2917
- */
2918
- static VALUE robject_bit_not(VALUE self) {
2919
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
2920
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2921
- ndfunc_t ndf = { iter_robject_bit_not, FULL_LOOP, 1, 1, ain, aout };
2922
-
2923
- return na_ndloop(&ndf, 1, self);
2924
- }
2925
-
2926
- #define check_intdivzero(y) \
2927
- {}
2928
-
2929
- static void iter_robject_left_shift(na_loop_t* const lp) {
2930
- size_t i = 0;
2931
- size_t n;
2932
- char *p1, *p2, *p3;
2933
- ssize_t s1, s2, s3;
2934
-
2935
- INIT_COUNTER(lp, n);
2936
- INIT_PTR(lp, 0, p1, s1);
2937
- INIT_PTR(lp, 1, p2, s2);
2938
- INIT_PTR(lp, 2, p3, s3);
2939
-
2940
- //
2941
-
2942
- if (s2 == 0) { // Broadcasting from scalar value.
2943
- check_intdivzero(*(dtype*)p2);
2944
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
2945
- if (p1 == p3) { // inplace case
2946
- for (; i < n; i++) {
2947
- ((dtype*)p1)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
2948
- }
2949
- } else {
2950
- for (; i < n; i++) {
2951
- ((dtype*)p3)[i] = m_left_shift(((dtype*)p1)[i], *(dtype*)p2);
2952
- }
2953
- }
2954
- } else {
2955
- for (i = 0; i < n; i++) {
2956
- *(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
2957
- p1 += s1;
2958
- p3 += s3;
2959
- }
2960
- }
2961
- } else {
2962
- if (p1 == p3) { // inplace case
2963
- for (i = 0; i < n; i++) {
2964
- check_intdivzero(*(dtype*)p2);
2965
- *(dtype*)p1 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
2966
- p1 += s1;
2967
- p2 += s2;
2968
- }
2969
- } else {
2970
- for (i = 0; i < n; i++) {
2971
- check_intdivzero(*(dtype*)p2);
2972
- *(dtype*)p3 = m_left_shift(*(dtype*)p1, *(dtype*)p2);
2973
- p1 += s1;
2974
- p2 += s2;
2975
- p3 += s3;
2976
- }
2977
- }
2978
- }
2979
-
2980
- return;
2981
- //
2982
- }
2983
- #undef check_intdivzero
2984
-
2985
- static VALUE robject_left_shift_self(VALUE self, VALUE other) {
2986
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
2987
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
2988
- ndfunc_t ndf = { iter_robject_left_shift, STRIDE_LOOP, 2, 1, ain, aout };
2989
-
2990
- return na_ndloop(&ndf, 2, self, other);
2991
- }
2992
-
2993
- /*
2994
- Binary left_shift.
2995
- @overload << other
2996
- @param [Numo::NArray,Numeric] other
2997
- @return [Numo::NArray] self << other
2998
- */
2999
- static VALUE robject_left_shift(VALUE self, VALUE other) {
3000
- return robject_left_shift_self(self, other);
3001
- }
3002
-
3003
- #define check_intdivzero(y) \
3004
- {}
3005
-
3006
- static void iter_robject_right_shift(na_loop_t* const lp) {
3007
- size_t i = 0;
3008
- size_t n;
3009
- char *p1, *p2, *p3;
3010
- ssize_t s1, s2, s3;
3011
-
3012
- INIT_COUNTER(lp, n);
3013
- INIT_PTR(lp, 0, p1, s1);
3014
- INIT_PTR(lp, 1, p2, s2);
3015
- INIT_PTR(lp, 2, p3, s3);
3016
-
3017
- //
3018
-
3019
- if (s2 == 0) { // Broadcasting from scalar value.
3020
- check_intdivzero(*(dtype*)p2);
3021
- if (s1 == sizeof(dtype) && s3 == sizeof(dtype)) {
3022
- if (p1 == p3) { // inplace case
3023
- for (; i < n; i++) {
3024
- ((dtype*)p1)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
3025
- }
3026
- } else {
3027
- for (; i < n; i++) {
3028
- ((dtype*)p3)[i] = m_right_shift(((dtype*)p1)[i], *(dtype*)p2);
3029
- }
3030
- }
3031
- } else {
3032
- for (i = 0; i < n; i++) {
3033
- *(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
3034
- p1 += s1;
3035
- p3 += s3;
3036
- }
3037
- }
3038
- } else {
3039
- if (p1 == p3) { // inplace case
3040
- for (i = 0; i < n; i++) {
3041
- check_intdivzero(*(dtype*)p2);
3042
- *(dtype*)p1 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
3043
- p1 += s1;
3044
- p2 += s2;
3045
- }
3046
- } else {
3047
- for (i = 0; i < n; i++) {
3048
- check_intdivzero(*(dtype*)p2);
3049
- *(dtype*)p3 = m_right_shift(*(dtype*)p1, *(dtype*)p2);
3050
- p1 += s1;
3051
- p2 += s2;
3052
- p3 += s3;
3053
- }
3054
- }
3055
- }
3056
-
3057
- return;
3058
- //
3059
- }
3060
- #undef check_intdivzero
3061
-
3062
- static VALUE robject_right_shift_self(VALUE self, VALUE other) {
3063
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3064
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3065
- ndfunc_t ndf = { iter_robject_right_shift, STRIDE_LOOP, 2, 1, ain, aout };
3066
-
3067
- return na_ndloop(&ndf, 2, self, other);
3068
- }
3069
-
3070
- /*
3071
- Binary right_shift.
3072
- @overload >> other
3073
- @param [Numo::NArray,Numeric] other
3074
- @return [Numo::NArray] self >> other
3075
- */
3076
- static VALUE robject_right_shift(VALUE self, VALUE other) {
3077
- return robject_right_shift_self(self, other);
3078
- }
3079
-
3080
- static void iter_robject_floor(na_loop_t* const lp) {
3081
- size_t i, n;
3082
- char *p1, *p2;
3083
- ssize_t s1, s2;
3084
- size_t *idx1, *idx2;
3085
- dtype x;
3086
-
3087
- INIT_COUNTER(lp, n);
3088
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3089
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3090
-
3091
- if (idx1) {
3092
- if (idx2) {
3093
- for (i = 0; i < n; i++) {
3094
- GET_DATA_INDEX(p1, idx1, dtype, x);
3095
- x = m_floor(x);
3096
- SET_DATA_INDEX(p2, idx2, dtype, x);
3097
- }
3098
- } else {
3099
- for (i = 0; i < n; i++) {
3100
- GET_DATA_INDEX(p1, idx1, dtype, x);
3101
- x = m_floor(x);
3102
- SET_DATA_STRIDE(p2, s2, dtype, x);
3103
- }
3104
- }
3105
- } else {
3106
- if (idx2) {
3107
- for (i = 0; i < n; i++) {
3108
- GET_DATA_STRIDE(p1, s1, dtype, x);
3109
- x = m_floor(x);
3110
- SET_DATA_INDEX(p2, idx2, dtype, x);
3111
- }
3112
- } else {
3113
- //
3114
- for (i = 0; i < n; i++) {
3115
- *(dtype*)p2 = m_floor(*(dtype*)p1);
3116
- p1 += s1;
3117
- p2 += s2;
3118
- }
3119
- return;
3120
- //
3121
- }
3122
- }
3123
- }
3124
-
3125
- /*
3126
- Unary floor.
3127
- @overload floor
3128
- @return [Numo::RObject] floor of self.
3129
- */
3130
- static VALUE robject_floor(VALUE self) {
3131
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3132
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3133
- ndfunc_t ndf = { iter_robject_floor, FULL_LOOP, 1, 1, ain, aout };
3134
-
3135
- return na_ndloop(&ndf, 1, self);
3136
- }
3137
-
3138
- static void iter_robject_round(na_loop_t* const lp) {
3139
- size_t i, n;
3140
- char *p1, *p2;
3141
- ssize_t s1, s2;
3142
- size_t *idx1, *idx2;
3143
- dtype x;
3144
-
3145
- INIT_COUNTER(lp, n);
3146
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3147
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3148
-
3149
- if (idx1) {
3150
- if (idx2) {
3151
- for (i = 0; i < n; i++) {
3152
- GET_DATA_INDEX(p1, idx1, dtype, x);
3153
- x = m_round(x);
3154
- SET_DATA_INDEX(p2, idx2, dtype, x);
3155
- }
3156
- } else {
3157
- for (i = 0; i < n; i++) {
3158
- GET_DATA_INDEX(p1, idx1, dtype, x);
3159
- x = m_round(x);
3160
- SET_DATA_STRIDE(p2, s2, dtype, x);
3161
- }
3162
- }
3163
- } else {
3164
- if (idx2) {
3165
- for (i = 0; i < n; i++) {
3166
- GET_DATA_STRIDE(p1, s1, dtype, x);
3167
- x = m_round(x);
3168
- SET_DATA_INDEX(p2, idx2, dtype, x);
3169
- }
3170
- } else {
3171
- //
3172
- for (i = 0; i < n; i++) {
3173
- *(dtype*)p2 = m_round(*(dtype*)p1);
3174
- p1 += s1;
3175
- p2 += s2;
3176
- }
3177
- return;
3178
- //
3179
- }
3180
- }
3181
- }
3182
-
3183
- /*
3184
- Unary round.
3185
- @overload round
3186
- @return [Numo::RObject] round of self.
3187
- */
3188
- static VALUE robject_round(VALUE self) {
3189
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3190
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3191
- ndfunc_t ndf = { iter_robject_round, FULL_LOOP, 1, 1, ain, aout };
3192
-
3193
- return na_ndloop(&ndf, 1, self);
3194
- }
3195
-
3196
- static void iter_robject_ceil(na_loop_t* const lp) {
3197
- size_t i, n;
3198
- char *p1, *p2;
3199
- ssize_t s1, s2;
3200
- size_t *idx1, *idx2;
3201
- dtype x;
3202
-
3203
- INIT_COUNTER(lp, n);
3204
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3205
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3206
-
3207
- if (idx1) {
3208
- if (idx2) {
3209
- for (i = 0; i < n; i++) {
3210
- GET_DATA_INDEX(p1, idx1, dtype, x);
3211
- x = m_ceil(x);
3212
- SET_DATA_INDEX(p2, idx2, dtype, x);
3213
- }
3214
- } else {
3215
- for (i = 0; i < n; i++) {
3216
- GET_DATA_INDEX(p1, idx1, dtype, x);
3217
- x = m_ceil(x);
3218
- SET_DATA_STRIDE(p2, s2, dtype, x);
3219
- }
3220
- }
3221
- } else {
3222
- if (idx2) {
3223
- for (i = 0; i < n; i++) {
3224
- GET_DATA_STRIDE(p1, s1, dtype, x);
3225
- x = m_ceil(x);
3226
- SET_DATA_INDEX(p2, idx2, dtype, x);
3227
- }
3228
- } else {
3229
- //
3230
- for (i = 0; i < n; i++) {
3231
- *(dtype*)p2 = m_ceil(*(dtype*)p1);
3232
- p1 += s1;
3233
- p2 += s2;
3234
- }
3235
- return;
3236
- //
3237
- }
3238
- }
3239
- }
3240
-
3241
- /*
3242
- Unary ceil.
3243
- @overload ceil
3244
- @return [Numo::RObject] ceil of self.
3245
- */
3246
- static VALUE robject_ceil(VALUE self) {
3247
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3248
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3249
- ndfunc_t ndf = { iter_robject_ceil, FULL_LOOP, 1, 1, ain, aout };
3250
-
3251
- return na_ndloop(&ndf, 1, self);
3252
- }
3253
-
3254
- static void iter_robject_trunc(na_loop_t* const lp) {
3255
- size_t i, n;
3256
- char *p1, *p2;
3257
- ssize_t s1, s2;
3258
- size_t *idx1, *idx2;
3259
- dtype x;
3260
-
3261
- INIT_COUNTER(lp, n);
3262
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3263
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3264
-
3265
- if (idx1) {
3266
- if (idx2) {
3267
- for (i = 0; i < n; i++) {
3268
- GET_DATA_INDEX(p1, idx1, dtype, x);
3269
- x = m_trunc(x);
3270
- SET_DATA_INDEX(p2, idx2, dtype, x);
3271
- }
3272
- } else {
3273
- for (i = 0; i < n; i++) {
3274
- GET_DATA_INDEX(p1, idx1, dtype, x);
3275
- x = m_trunc(x);
3276
- SET_DATA_STRIDE(p2, s2, dtype, x);
3277
- }
3278
- }
3279
- } else {
3280
- if (idx2) {
3281
- for (i = 0; i < n; i++) {
3282
- GET_DATA_STRIDE(p1, s1, dtype, x);
3283
- x = m_trunc(x);
3284
- SET_DATA_INDEX(p2, idx2, dtype, x);
3285
- }
3286
- } else {
3287
- //
3288
- for (i = 0; i < n; i++) {
3289
- *(dtype*)p2 = m_trunc(*(dtype*)p1);
3290
- p1 += s1;
3291
- p2 += s2;
3292
- }
3293
- return;
3294
- //
3295
- }
3296
- }
3297
- }
3298
-
3299
- /*
3300
- Unary trunc.
3301
- @overload trunc
3302
- @return [Numo::RObject] trunc of self.
3303
- */
3304
- static VALUE robject_trunc(VALUE self) {
3305
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3306
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
3307
- ndfunc_t ndf = { iter_robject_trunc, FULL_LOOP, 1, 1, ain, aout };
3308
-
3309
- return na_ndloop(&ndf, 1, self);
3310
- }
3311
-
3312
- static void iter_robject_gt(na_loop_t* const lp) {
3313
- size_t i;
3314
- char *p1, *p2;
3315
- BIT_DIGIT* a3;
3316
- size_t p3;
3317
- ssize_t s1, s2, s3;
3318
- dtype x, y;
3319
- BIT_DIGIT b;
3320
- INIT_COUNTER(lp, i);
3321
- INIT_PTR(lp, 0, p1, s1);
3322
- INIT_PTR(lp, 1, p2, s2);
3323
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
3324
- for (; i--;) {
3325
- GET_DATA_STRIDE(p1, s1, dtype, x);
3326
- GET_DATA_STRIDE(p2, s2, dtype, y);
3327
- b = (m_gt(x, y)) ? 1 : 0;
3328
- STORE_BIT(a3, p3, b);
3329
- p3 += s3;
3330
- }
3331
- }
3332
-
3333
- static VALUE robject_gt_self(VALUE self, VALUE other) {
3334
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3335
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3336
- ndfunc_t ndf = { iter_robject_gt, STRIDE_LOOP, 2, 1, ain, aout };
3337
-
3338
- return na_ndloop(&ndf, 2, self, other);
3339
- }
3340
-
3341
- /*
3342
- Comparison gt other.
3343
- @overload gt other
3344
- @param [Numo::NArray,Numeric] other
3345
- @return [Numo::Bit] result of self gt other.
3346
- */
3347
- static VALUE robject_gt(VALUE self, VALUE other) {
3348
- return robject_gt_self(self, other);
3349
- }
3350
-
3351
- static void iter_robject_ge(na_loop_t* const lp) {
3352
- size_t i;
3353
- char *p1, *p2;
3354
- BIT_DIGIT* a3;
3355
- size_t p3;
3356
- ssize_t s1, s2, s3;
3357
- dtype x, y;
3358
- BIT_DIGIT b;
3359
- INIT_COUNTER(lp, i);
3360
- INIT_PTR(lp, 0, p1, s1);
3361
- INIT_PTR(lp, 1, p2, s2);
3362
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
3363
- for (; i--;) {
3364
- GET_DATA_STRIDE(p1, s1, dtype, x);
3365
- GET_DATA_STRIDE(p2, s2, dtype, y);
3366
- b = (m_ge(x, y)) ? 1 : 0;
3367
- STORE_BIT(a3, p3, b);
3368
- p3 += s3;
3369
- }
3370
- }
3371
-
3372
- static VALUE robject_ge_self(VALUE self, VALUE other) {
3373
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3374
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3375
- ndfunc_t ndf = { iter_robject_ge, STRIDE_LOOP, 2, 1, ain, aout };
3376
-
3377
- return na_ndloop(&ndf, 2, self, other);
3378
- }
3379
-
3380
- /*
3381
- Comparison ge other.
3382
- @overload ge other
3383
- @param [Numo::NArray,Numeric] other
3384
- @return [Numo::Bit] result of self ge other.
3385
- */
3386
- static VALUE robject_ge(VALUE self, VALUE other) {
3387
- return robject_ge_self(self, other);
3388
- }
3389
-
3390
- static void iter_robject_lt(na_loop_t* const lp) {
3391
- size_t i;
3392
- char *p1, *p2;
3393
- BIT_DIGIT* a3;
3394
- size_t p3;
3395
- ssize_t s1, s2, s3;
3396
- dtype x, y;
3397
- BIT_DIGIT b;
3398
- INIT_COUNTER(lp, i);
3399
- INIT_PTR(lp, 0, p1, s1);
3400
- INIT_PTR(lp, 1, p2, s2);
3401
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
3402
- for (; i--;) {
3403
- GET_DATA_STRIDE(p1, s1, dtype, x);
3404
- GET_DATA_STRIDE(p2, s2, dtype, y);
3405
- b = (m_lt(x, y)) ? 1 : 0;
3406
- STORE_BIT(a3, p3, b);
3407
- p3 += s3;
3408
- }
3409
- }
3410
-
3411
- static VALUE robject_lt_self(VALUE self, VALUE other) {
3412
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3413
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3414
- ndfunc_t ndf = { iter_robject_lt, STRIDE_LOOP, 2, 1, ain, aout };
3415
-
3416
- return na_ndloop(&ndf, 2, self, other);
3417
- }
3418
-
3419
- /*
3420
- Comparison lt other.
3421
- @overload lt other
3422
- @param [Numo::NArray,Numeric] other
3423
- @return [Numo::Bit] result of self lt other.
3424
- */
3425
- static VALUE robject_lt(VALUE self, VALUE other) {
3426
- return robject_lt_self(self, other);
3427
- }
3428
-
3429
- static void iter_robject_le(na_loop_t* const lp) {
3430
- size_t i;
3431
- char *p1, *p2;
3432
- BIT_DIGIT* a3;
3433
- size_t p3;
3434
- ssize_t s1, s2, s3;
3435
- dtype x, y;
3436
- BIT_DIGIT b;
3437
- INIT_COUNTER(lp, i);
3438
- INIT_PTR(lp, 0, p1, s1);
3439
- INIT_PTR(lp, 1, p2, s2);
3440
- INIT_PTR_BIT(lp, 2, a3, p3, s3);
3441
- for (; i--;) {
3442
- GET_DATA_STRIDE(p1, s1, dtype, x);
3443
- GET_DATA_STRIDE(p2, s2, dtype, y);
3444
- b = (m_le(x, y)) ? 1 : 0;
3445
- STORE_BIT(a3, p3, b);
3446
- p3 += s3;
3447
- }
3448
- }
3449
-
3450
- static VALUE robject_le_self(VALUE self, VALUE other) {
3451
- ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
3452
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3453
- ndfunc_t ndf = { iter_robject_le, STRIDE_LOOP, 2, 1, ain, aout };
3454
-
3455
- return na_ndloop(&ndf, 2, self, other);
3456
- }
3457
-
3458
- /*
3459
- Comparison le other.
3460
- @overload le other
3461
- @param [Numo::NArray,Numeric] other
3462
- @return [Numo::Bit] result of self le other.
3463
- */
3464
- static VALUE robject_le(VALUE self, VALUE other) {
3465
- return robject_le_self(self, other);
3466
- }
3467
-
3468
- static void iter_robject_isnan(na_loop_t* const lp) {
3469
- size_t i;
3470
- char* p1;
3471
- BIT_DIGIT* a2;
3472
- size_t p2;
3473
- ssize_t s1, s2;
3474
- size_t* idx1;
3475
- dtype x;
3476
- BIT_DIGIT b;
3477
- INIT_COUNTER(lp, i);
3478
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3479
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3480
- if (idx1) {
3481
- for (; i--;) {
3482
- GET_DATA_INDEX(p1, idx1, dtype, x);
3483
- b = (m_isnan(x)) ? 1 : 0;
3484
- STORE_BIT(a2, p2, b);
3485
- p2 += s2;
3486
- }
3487
- } else {
3488
- for (; i--;) {
3489
- GET_DATA_STRIDE(p1, s1, dtype, x);
3490
- b = (m_isnan(x)) ? 1 : 0;
3491
- STORE_BIT(a2, p2, b);
3492
- p2 += s2;
1819
+ *(dtype*)p2 = m_reciprocal(*(dtype*)p1);
1820
+ p1 += s1;
1821
+ p2 += s2;
1822
+ }
1823
+ return;
1824
+ //
3493
1825
  }
3494
1826
  }
3495
1827
  }
3496
1828
 
3497
1829
  /*
3498
- Condition of isnan.
3499
- @overload isnan
3500
- @return [Numo::Bit] Condition of isnan.
1830
+ Unary reciprocal.
1831
+ @overload reciprocal
1832
+ @return [Numo::RObject] reciprocal of self.
3501
1833
  */
3502
- static VALUE robject_isnan(VALUE self) {
1834
+ static VALUE robject_reciprocal(VALUE self) {
3503
1835
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3504
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3505
- ndfunc_t ndf = { iter_robject_isnan, FULL_LOOP, 1, 1, ain, aout };
1836
+ ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1837
+ ndfunc_t ndf = { iter_robject_reciprocal, FULL_LOOP, 1, 1, ain, aout };
3506
1838
 
3507
1839
  return na_ndloop(&ndf, 1, self);
3508
1840
  }
3509
1841
 
3510
- static void iter_robject_isinf(na_loop_t* const lp) {
3511
- size_t i;
3512
- char* p1;
3513
- BIT_DIGIT* a2;
3514
- size_t p2;
1842
+ static void iter_robject_sign(na_loop_t* const lp) {
1843
+ size_t i, n;
1844
+ char *p1, *p2;
3515
1845
  ssize_t s1, s2;
3516
- size_t* idx1;
1846
+ size_t *idx1, *idx2;
3517
1847
  dtype x;
3518
- BIT_DIGIT b;
3519
- INIT_COUNTER(lp, i);
3520
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3521
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3522
- if (idx1) {
3523
- for (; i--;) {
3524
- GET_DATA_INDEX(p1, idx1, dtype, x);
3525
- b = (m_isinf(x)) ? 1 : 0;
3526
- STORE_BIT(a2, p2, b);
3527
- p2 += s2;
3528
- }
3529
- } else {
3530
- for (; i--;) {
3531
- GET_DATA_STRIDE(p1, s1, dtype, x);
3532
- b = (m_isinf(x)) ? 1 : 0;
3533
- STORE_BIT(a2, p2, b);
3534
- p2 += s2;
3535
- }
3536
- }
3537
- }
3538
-
3539
- /*
3540
- Condition of isinf.
3541
- @overload isinf
3542
- @return [Numo::Bit] Condition of isinf.
3543
- */
3544
- static VALUE robject_isinf(VALUE self) {
3545
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3546
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3547
- ndfunc_t ndf = { iter_robject_isinf, FULL_LOOP, 1, 1, ain, aout };
3548
-
3549
- return na_ndloop(&ndf, 1, self);
3550
- }
3551
1848
 
3552
- static void iter_robject_isposinf(na_loop_t* const lp) {
3553
- size_t i;
3554
- char* p1;
3555
- BIT_DIGIT* a2;
3556
- size_t p2;
3557
- ssize_t s1, s2;
3558
- size_t* idx1;
3559
- dtype x;
3560
- BIT_DIGIT b;
3561
- INIT_COUNTER(lp, i);
1849
+ INIT_COUNTER(lp, n);
3562
1850
  INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3563
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3564
- if (idx1) {
3565
- for (; i--;) {
3566
- GET_DATA_INDEX(p1, idx1, dtype, x);
3567
- b = (m_isposinf(x)) ? 1 : 0;
3568
- STORE_BIT(a2, p2, b);
3569
- p2 += s2;
3570
- }
3571
- } else {
3572
- for (; i--;) {
3573
- GET_DATA_STRIDE(p1, s1, dtype, x);
3574
- b = (m_isposinf(x)) ? 1 : 0;
3575
- STORE_BIT(a2, p2, b);
3576
- p2 += s2;
3577
- }
3578
- }
3579
- }
3580
-
3581
- /*
3582
- Condition of isposinf.
3583
- @overload isposinf
3584
- @return [Numo::Bit] Condition of isposinf.
3585
- */
3586
- static VALUE robject_isposinf(VALUE self) {
3587
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3588
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3589
- ndfunc_t ndf = { iter_robject_isposinf, FULL_LOOP, 1, 1, ain, aout };
3590
-
3591
- return na_ndloop(&ndf, 1, self);
3592
- }
1851
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
3593
1852
 
3594
- static void iter_robject_isneginf(na_loop_t* const lp) {
3595
- size_t i;
3596
- char* p1;
3597
- BIT_DIGIT* a2;
3598
- size_t p2;
3599
- ssize_t s1, s2;
3600
- size_t* idx1;
3601
- dtype x;
3602
- BIT_DIGIT b;
3603
- INIT_COUNTER(lp, i);
3604
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3605
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
3606
1853
  if (idx1) {
3607
- for (; i--;) {
3608
- GET_DATA_INDEX(p1, idx1, dtype, x);
3609
- b = (m_isneginf(x)) ? 1 : 0;
3610
- STORE_BIT(a2, p2, b);
3611
- p2 += s2;
1854
+ if (idx2) {
1855
+ for (i = 0; i < n; i++) {
1856
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1857
+ x = m_sign(x);
1858
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1859
+ }
1860
+ } else {
1861
+ for (i = 0; i < n; i++) {
1862
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1863
+ x = m_sign(x);
1864
+ SET_DATA_STRIDE(p2, s2, dtype, x);
1865
+ }
3612
1866
  }
3613
1867
  } else {
3614
- for (; i--;) {
3615
- GET_DATA_STRIDE(p1, s1, dtype, x);
3616
- b = (m_isneginf(x)) ? 1 : 0;
3617
- STORE_BIT(a2, p2, b);
3618
- p2 += s2;
1868
+ if (idx2) {
1869
+ for (i = 0; i < n; i++) {
1870
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1871
+ x = m_sign(x);
1872
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1873
+ }
1874
+ } else {
1875
+ //
1876
+ for (i = 0; i < n; i++) {
1877
+ *(dtype*)p2 = m_sign(*(dtype*)p1);
1878
+ p1 += s1;
1879
+ p2 += s2;
1880
+ }
1881
+ return;
1882
+ //
3619
1883
  }
3620
1884
  }
3621
1885
  }
3622
1886
 
3623
1887
  /*
3624
- Condition of isneginf.
3625
- @overload isneginf
3626
- @return [Numo::Bit] Condition of isneginf.
1888
+ Unary sign.
1889
+ @overload sign
1890
+ @return [Numo::RObject] sign of self.
3627
1891
  */
3628
- static VALUE robject_isneginf(VALUE self) {
1892
+ static VALUE robject_sign(VALUE self) {
3629
1893
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3630
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3631
- ndfunc_t ndf = { iter_robject_isneginf, FULL_LOOP, 1, 1, ain, aout };
1894
+ ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1895
+ ndfunc_t ndf = { iter_robject_sign, FULL_LOOP, 1, 1, ain, aout };
3632
1896
 
3633
1897
  return na_ndloop(&ndf, 1, self);
3634
1898
  }
3635
1899
 
3636
- static void iter_robject_isfinite(na_loop_t* const lp) {
3637
- size_t i;
3638
- char* p1;
3639
- BIT_DIGIT* a2;
3640
- size_t p2;
1900
+ static void iter_robject_square(na_loop_t* const lp) {
1901
+ size_t i, n;
1902
+ char *p1, *p2;
3641
1903
  ssize_t s1, s2;
3642
- size_t* idx1;
1904
+ size_t *idx1, *idx2;
3643
1905
  dtype x;
3644
- BIT_DIGIT b;
3645
- INIT_COUNTER(lp, i);
1906
+
1907
+ INIT_COUNTER(lp, n);
3646
1908
  INIT_PTR_IDX(lp, 0, p1, s1, idx1);
3647
- INIT_PTR_BIT(lp, 1, a2, p2, s2);
1909
+ INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1910
+
3648
1911
  if (idx1) {
3649
- for (; i--;) {
3650
- GET_DATA_INDEX(p1, idx1, dtype, x);
3651
- b = (m_isfinite(x)) ? 1 : 0;
3652
- STORE_BIT(a2, p2, b);
3653
- p2 += s2;
1912
+ if (idx2) {
1913
+ for (i = 0; i < n; i++) {
1914
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1915
+ x = m_square(x);
1916
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1917
+ }
1918
+ } else {
1919
+ for (i = 0; i < n; i++) {
1920
+ GET_DATA_INDEX(p1, idx1, dtype, x);
1921
+ x = m_square(x);
1922
+ SET_DATA_STRIDE(p2, s2, dtype, x);
1923
+ }
3654
1924
  }
3655
1925
  } else {
3656
- for (; i--;) {
3657
- GET_DATA_STRIDE(p1, s1, dtype, x);
3658
- b = (m_isfinite(x)) ? 1 : 0;
3659
- STORE_BIT(a2, p2, b);
3660
- p2 += s2;
1926
+ if (idx2) {
1927
+ for (i = 0; i < n; i++) {
1928
+ GET_DATA_STRIDE(p1, s1, dtype, x);
1929
+ x = m_square(x);
1930
+ SET_DATA_INDEX(p2, idx2, dtype, x);
1931
+ }
1932
+ } else {
1933
+ //
1934
+ for (i = 0; i < n; i++) {
1935
+ *(dtype*)p2 = m_square(*(dtype*)p1);
1936
+ p1 += s1;
1937
+ p2 += s2;
1938
+ }
1939
+ return;
1940
+ //
3661
1941
  }
3662
1942
  }
3663
1943
  }
3664
1944
 
3665
1945
  /*
3666
- Condition of isfinite.
3667
- @overload isfinite
3668
- @return [Numo::Bit] Condition of isfinite.
1946
+ Unary square.
1947
+ @overload square
1948
+ @return [Numo::RObject] square of self.
3669
1949
  */
3670
- static VALUE robject_isfinite(VALUE self) {
1950
+ static VALUE robject_square(VALUE self) {
3671
1951
  ndfunc_arg_in_t ain[1] = { { cT, 0 } };
3672
- ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
3673
- ndfunc_t ndf = { iter_robject_isfinite, FULL_LOOP, 1, 1, ain, aout };
1952
+ ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1953
+ ndfunc_t ndf = { iter_robject_square, FULL_LOOP, 1, 1, ain, aout };
3674
1954
 
3675
1955
  return na_ndloop(&ndf, 1, self);
3676
1956
  }
@@ -3815,22 +2095,91 @@ void Init_numo_robject(void) {
3815
2095
  rb_define_singleton_method(cT, "cast", robject_s_cast, 1);
3816
2096
  rb_define_method(cT, "[]", robject_aref, -1);
3817
2097
  rb_define_method(cT, "[]=", robject_aset, -1);
2098
+ /**
2099
+ * return NArray with cast to the type of self.
2100
+ * @overload coerce_cast(type)
2101
+ * @return [nil]
2102
+ */
3818
2103
  rb_define_method(cT, "coerce_cast", robject_coerce_cast, 1);
2104
+ /**
2105
+ * Convert self to Array.
2106
+ * @overload to_a
2107
+ * @return [Array]
2108
+ */
3819
2109
  rb_define_method(cT, "to_a", robject_to_a, 0);
2110
+ /**
2111
+ * Fill elements with other.
2112
+ * @overload fill other
2113
+ * @param [Numeric] other
2114
+ * @return [Numo::RObject] self.
2115
+ */
3820
2116
  rb_define_method(cT, "fill", robject_fill, 1);
2117
+ /**
2118
+ * Format elements into strings.
2119
+ * @overload format format
2120
+ * @param [String] format
2121
+ * @return [Numo::RObject] array of formatted strings.
2122
+ */
3821
2123
  rb_define_method(cT, "format", robject_format, -1);
2124
+ /**
2125
+ * Format elements into strings.
2126
+ * @overload format_to_a format
2127
+ * @param [String] format
2128
+ * @return [Array] array of formatted strings.
2129
+ */
3822
2130
  rb_define_method(cT, "format_to_a", robject_format_to_a, -1);
2131
+ /**
2132
+ * Returns a string containing a human-readable representation of NArray.
2133
+ * @overload inspect
2134
+ * @return [String]
2135
+ */
3823
2136
  rb_define_method(cT, "inspect", robject_inspect, 0);
3824
2137
  rb_define_method(cT, "each", robject_each, 0);
3825
2138
  rb_define_method(cT, "map", robject_map, 0);
3826
2139
  rb_define_method(cT, "each_with_index", robject_each_with_index, 0);
3827
2140
  rb_define_method(cT, "map_with_index", robject_map_with_index, 0);
3828
2141
  rb_define_method(cT, "abs", robject_abs, 0);
2142
+ /**
2143
+ * Binary add.
2144
+ * @overload + other
2145
+ * @param [Numo::NArray,Numeric] other
2146
+ * @return [Numo::NArray] self + other
2147
+ */
3829
2148
  rb_define_method(cT, "+", robject_add, 1);
2149
+ /**
2150
+ * Binary sub.
2151
+ * @overload - other
2152
+ * @param [Numo::NArray,Numeric] other
2153
+ * @return [Numo::NArray] self - other
2154
+ */
3830
2155
  rb_define_method(cT, "-", robject_sub, 1);
2156
+ /**
2157
+ * Binary mul.
2158
+ * @overload * other
2159
+ * @param [Numo::NArray,Numeric] other
2160
+ * @return [Numo::NArray] self * other
2161
+ */
3831
2162
  rb_define_method(cT, "*", robject_mul, 1);
2163
+ /**
2164
+ * Binary div.
2165
+ * @overload / other
2166
+ * @param [Numo::NArray,Numeric] other
2167
+ * @return [Numo::NArray] self / other
2168
+ */
3832
2169
  rb_define_method(cT, "/", robject_div, 1);
2170
+ /**
2171
+ * Binary mod.
2172
+ * @overload % other
2173
+ * @param [Numo::NArray,Numeric] other
2174
+ * @return [Numo::NArray] self % other
2175
+ */
3833
2176
  rb_define_method(cT, "%", robject_mod, 1);
2177
+ /**
2178
+ * Binary divmod.
2179
+ * @overload divmod other
2180
+ * @param [Numo::NArray,Numeric] other
2181
+ * @return [Numo::NArray] divmod of self and other.
2182
+ */
3834
2183
  rb_define_method(cT, "divmod", robject_divmod, 1);
3835
2184
  rb_define_method(cT, "**", robject_pow, 1);
3836
2185
  rb_define_alias(cT, "pow", "**");
@@ -3841,23 +2190,120 @@ void Init_numo_robject(void) {
3841
2190
  rb_define_alias(cT, "conj", "view");
3842
2191
  rb_define_alias(cT, "im", "view");
3843
2192
  rb_define_alias(cT, "conjugate", "conj");
2193
+ /**
2194
+ * Comparison eq other.
2195
+ * @overload eq other
2196
+ * @param [Numo::NArray,Numeric] other
2197
+ * @return [Numo::Bit] result of self eq other.
2198
+ */
3844
2199
  rb_define_method(cT, "eq", robject_eq, 1);
2200
+ /**
2201
+ * Comparison ne other.
2202
+ * @overload ne other
2203
+ * @param [Numo::NArray,Numeric] other
2204
+ * @return [Numo::Bit] result of self ne other.
2205
+ */
3845
2206
  rb_define_method(cT, "ne", robject_ne, 1);
2207
+ /**
2208
+ * Comparison nearly_eq other.
2209
+ * @overload nearly_eq other
2210
+ * @param [Numo::NArray,Numeric] other
2211
+ * @return [Numo::Bit] result of self nearly_eq other.
2212
+ */
3846
2213
  rb_define_method(cT, "nearly_eq", robject_nearly_eq, 1);
3847
2214
  rb_define_alias(cT, "close_to", "nearly_eq");
2215
+ /**
2216
+ * Binary bit_and.
2217
+ * @overload & other
2218
+ * @param [Numo::NArray,Numeric] other
2219
+ * @return [Numo::NArray] self & other
2220
+ */
3848
2221
  rb_define_method(cT, "&", robject_bit_and, 1);
2222
+ /**
2223
+ * Binary bit_or.
2224
+ * @overload | other
2225
+ * @param [Numo::NArray,Numeric] other
2226
+ * @return [Numo::NArray] self | other
2227
+ */
3849
2228
  rb_define_method(cT, "|", robject_bit_or, 1);
2229
+ /**
2230
+ * Binary bit_xor.
2231
+ * @overload ^ other
2232
+ * @param [Numo::NArray,Numeric] other
2233
+ * @return [Numo::NArray] self ^ other
2234
+ */
3850
2235
  rb_define_method(cT, "^", robject_bit_xor, 1);
2236
+ /**
2237
+ * Unary bit_not.
2238
+ * @overload ~
2239
+ * @return [Numo::RObject] bit_not of self.
2240
+ */
3851
2241
  rb_define_method(cT, "~", robject_bit_not, 0);
2242
+ /**
2243
+ * Binary left_shift.
2244
+ * @overload << other
2245
+ * @param [Numo::NArray,Numeric] other
2246
+ * @return [Numo::NArray] self << other
2247
+ */
3852
2248
  rb_define_method(cT, "<<", robject_left_shift, 1);
2249
+ /**
2250
+ * Binary right_shift.
2251
+ * @overload >> other
2252
+ * @param [Numo::NArray,Numeric] other
2253
+ * @return [Numo::NArray] self >> other
2254
+ */
3853
2255
  rb_define_method(cT, ">>", robject_right_shift, 1);
2256
+ /**
2257
+ * Unary floor.
2258
+ * @overload floor
2259
+ * @return [Numo::RObject] floor of self.
2260
+ */
3854
2261
  rb_define_method(cT, "floor", robject_floor, 0);
2262
+ /**
2263
+ * Unary round.
2264
+ * @overload round
2265
+ * @return [Numo::RObject] round of self.
2266
+ */
3855
2267
  rb_define_method(cT, "round", robject_round, 0);
2268
+ /**
2269
+ * Unary ceil.
2270
+ * @overload ceil
2271
+ * @return [Numo::RObject] ceil of self.
2272
+ */
3856
2273
  rb_define_method(cT, "ceil", robject_ceil, 0);
2274
+ /**
2275
+ * Unary trunc.
2276
+ * @overload trunc
2277
+ * @return [Numo::RObject] trunc of self.
2278
+ */
3857
2279
  rb_define_method(cT, "trunc", robject_trunc, 0);
2280
+ /**
2281
+ * Comparison gt other.
2282
+ * @overload gt other
2283
+ * @param [Numo::NArray,Numeric] other
2284
+ * @return [Numo::Bit] result of self gt other.
2285
+ */
3858
2286
  rb_define_method(cT, "gt", robject_gt, 1);
2287
+ /**
2288
+ * Comparison ge other.
2289
+ * @overload ge other
2290
+ * @param [Numo::NArray,Numeric] other
2291
+ * @return [Numo::Bit] result of self ge other.
2292
+ */
3859
2293
  rb_define_method(cT, "ge", robject_ge, 1);
2294
+ /**
2295
+ * Comparison lt other.
2296
+ * @overload lt other
2297
+ * @param [Numo::NArray,Numeric] other
2298
+ * @return [Numo::Bit] result of self lt other.
2299
+ */
3860
2300
  rb_define_method(cT, "lt", robject_lt, 1);
2301
+ /**
2302
+ * Comparison le other.
2303
+ * @overload le other
2304
+ * @param [Numo::NArray,Numeric] other
2305
+ * @return [Numo::Bit] result of self le other.
2306
+ */
3861
2307
  rb_define_method(cT, "le", robject_le, 1);
3862
2308
  rb_define_alias(cT, ">", "gt");
3863
2309
  rb_define_alias(cT, ">=", "ge");
@@ -3894,10 +2340,35 @@ void Init_numo_robject(void) {
3894
2340
  * # [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
3895
2341
  */
3896
2342
  rb_define_method(cT, "clip", robject_clip, 2);
2343
+ /**
2344
+ * Condition of isnan.
2345
+ * @overload isnan
2346
+ * @return [Numo::Bit] Condition of isnan.
2347
+ */
3897
2348
  rb_define_method(cT, "isnan", robject_isnan, 0);
2349
+ /**
2350
+ * Condition of isinf.
2351
+ * @overload isinf
2352
+ * @return [Numo::Bit] Condition of isinf.
2353
+ */
3898
2354
  rb_define_method(cT, "isinf", robject_isinf, 0);
2355
+ /**
2356
+ * Condition of isposinf.
2357
+ * @overload isposinf
2358
+ * @return [Numo::Bit] Condition of isposinf.
2359
+ */
3899
2360
  rb_define_method(cT, "isposinf", robject_isposinf, 0);
2361
+ /**
2362
+ * Condition of isneginf.
2363
+ * @overload isneginf
2364
+ * @return [Numo::Bit] Condition of isneginf.
2365
+ */
3900
2366
  rb_define_method(cT, "isneginf", robject_isneginf, 0);
2367
+ /**
2368
+ * Condition of isfinite.
2369
+ * @overload isfinite
2370
+ * @return [Numo::Bit] Condition of isfinite.
2371
+ */
3901
2372
  rb_define_method(cT, "isfinite", robject_isfinite, 0);
3902
2373
  /**
3903
2374
  * sum of self.