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
@@ -31,11 +31,23 @@ static ID id_to_a;
31
31
  VALUE cT;
32
32
  extern VALUE cRT;
33
33
 
34
+ #include "mh/coerce_cast.h"
35
+ #include "mh/to_a.h"
36
+ #include "mh/fill.h"
37
+ #include "mh/format.h"
38
+ #include "mh/format_to_a.h"
39
+ #include "mh/inspect.h"
34
40
  #include "mh/mean.h"
35
41
  #include "mh/var.h"
36
42
  #include "mh/stddev.h"
37
43
  #include "mh/rms.h"
38
44
 
45
+ DEF_NARRAY_COERCE_CAST_METHOD_FUNC(bit)
46
+ DEF_NARRAY_BIT_TO_A_METHOD_FUNC()
47
+ DEF_NARRAY_BIT_FILL_METHOD_FUNC()
48
+ DEF_NARRAY_BIT_FORMAT_METHOD_FUNC()
49
+ DEF_NARRAY_BIT_FORMAT_TO_A_METHOD_FUNC()
50
+ DEF_NARRAY_BIT_INSPECT_METHOD_FUNC()
39
51
  DEF_NARRAY_BIT_MEAN_METHOD_FUNC()
40
52
  DEF_NARRAY_BIT_VAR_METHOD_FUNC()
41
53
  DEF_NARRAY_BIT_STDDEV_METHOD_FUNC()
@@ -1353,240 +1365,6 @@ static VALUE bit_aset(int argc, VALUE* argv, VALUE self) {
1353
1365
  return argv[argc];
1354
1366
  }
1355
1367
 
1356
- /*
1357
- return NArray with cast to the type of self.
1358
- @overload coerce_cast(type)
1359
- @return [nil]
1360
- */
1361
- static VALUE bit_coerce_cast(VALUE self, VALUE type) {
1362
- return Qnil;
1363
- }
1364
-
1365
- static void iter_bit_to_a(na_loop_t* const lp) {
1366
- size_t i;
1367
- BIT_DIGIT* a1;
1368
- size_t p1;
1369
- ssize_t s1;
1370
- size_t* idx1;
1371
- BIT_DIGIT x = 0;
1372
- VALUE a, y;
1373
-
1374
- INIT_COUNTER(lp, i);
1375
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
1376
- a = rb_ary_new2(i);
1377
- rb_ary_push(lp->args[1].value, a);
1378
- if (idx1) {
1379
- for (; i--;) {
1380
- LOAD_BIT(a1, p1 + *idx1, x);
1381
- idx1++;
1382
- y = m_data_to_num(x);
1383
- rb_ary_push(a, y);
1384
- }
1385
- } else {
1386
- for (; i--;) {
1387
- LOAD_BIT(a1, p1, x);
1388
- p1 += s1;
1389
- y = m_data_to_num(x);
1390
- rb_ary_push(a, y);
1391
- }
1392
- }
1393
- }
1394
-
1395
- /*
1396
- Convert self to Array.
1397
- @overload to_a
1398
- @return [Array]
1399
- */
1400
- static VALUE bit_to_a(VALUE self) {
1401
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1402
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1403
- ndfunc_t ndf = { iter_bit_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1404
- return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
1405
- }
1406
-
1407
- static void iter_bit_fill(na_loop_t* const lp) {
1408
- size_t n;
1409
- size_t p3;
1410
- ssize_t s3;
1411
- size_t* idx3;
1412
- int len;
1413
- BIT_DIGIT* a3;
1414
- BIT_DIGIT y;
1415
- VALUE x = lp->option;
1416
-
1417
- if (x == INT2FIX(0) || x == Qfalse) {
1418
- y = 0;
1419
- } else if (x == INT2FIX(1) || x == Qtrue) {
1420
- y = ~(BIT_DIGIT)0;
1421
- } else {
1422
- rb_raise(rb_eArgError, "invalid value for Bit");
1423
- }
1424
-
1425
- INIT_COUNTER(lp, n);
1426
- INIT_PTR_BIT_IDX(lp, 0, a3, p3, s3, idx3);
1427
- if (idx3) {
1428
- y = y & 1;
1429
- for (; n--;) {
1430
- STORE_BIT(a3, p3 + *idx3, y);
1431
- idx3++;
1432
- }
1433
- } else if (s3 != 1) {
1434
- y = y & 1;
1435
- for (; n--;) {
1436
- STORE_BIT(a3, p3, y);
1437
- p3 += s3;
1438
- }
1439
- } else {
1440
- if (p3 > 0 || n < NB) {
1441
- len = (int)(NB - p3);
1442
- if ((int)n < len) len = (int)n;
1443
- *a3 = (y & (SLB(len) << p3)) | (*a3 & ~(SLB(len) << p3));
1444
- a3++;
1445
- n -= len;
1446
- }
1447
- for (; n >= NB; n -= NB) {
1448
- *(a3++) = y;
1449
- }
1450
- if (n > 0) {
1451
- *a3 = (y & SLB(n)) | (*a3 & BALL << n);
1452
- }
1453
- }
1454
- }
1455
-
1456
- /*
1457
- Fill elements with other.
1458
- @overload fill other
1459
- @param [Numeric] other
1460
- @return [Numo::Bit] self.
1461
- */
1462
- static VALUE bit_fill(VALUE self, VALUE val) {
1463
- ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
1464
- ndfunc_t ndf = { iter_bit_fill, FULL_LOOP, 2, 0, ain, 0 };
1465
-
1466
- na_ndloop(&ndf, 2, self, val);
1467
- return self;
1468
- }
1469
-
1470
- static VALUE format_bit(VALUE fmt, dtype x) {
1471
- if (NIL_P(fmt)) {
1472
- char s[4];
1473
- int n;
1474
- n = m_sprintf(s, x);
1475
- return rb_str_new(s, n);
1476
- }
1477
- return rb_funcall(fmt, '%', 1, m_data_to_num(x));
1478
- }
1479
-
1480
- static void iter_bit_format(na_loop_t* const lp) {
1481
- size_t i;
1482
- BIT_DIGIT *a1, x = 0;
1483
- size_t p1;
1484
- char* p2;
1485
- ssize_t s1, s2;
1486
- size_t* idx1;
1487
- VALUE y;
1488
- VALUE fmt = lp->option;
1489
-
1490
- INIT_COUNTER(lp, i);
1491
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
1492
- INIT_PTR(lp, 1, p2, s2);
1493
-
1494
- if (idx1) {
1495
- for (; i--;) {
1496
- LOAD_BIT(a1, p1 + *idx1, x);
1497
- idx1++;
1498
- y = format_bit(fmt, x);
1499
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1500
- }
1501
- } else {
1502
- for (; i--;) {
1503
- LOAD_BIT(a1, p1, x);
1504
- p1 += s1;
1505
- y = format_bit(fmt, x);
1506
- SET_DATA_STRIDE(p2, s2, VALUE, y);
1507
- }
1508
- }
1509
- }
1510
-
1511
- /*
1512
- Format elements into strings.
1513
- @overload format format
1514
- @param [String] format
1515
- @return [Numo::RObject] array of formatted strings.
1516
- */
1517
- static VALUE bit_format(int argc, VALUE* argv, VALUE self) {
1518
- VALUE fmt = Qnil;
1519
-
1520
- ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_option } };
1521
- ndfunc_arg_out_t aout[1] = { { numo_cRObject, 0 } };
1522
- ndfunc_t ndf = { iter_bit_format, FULL_LOOP_NIP, 2, 1, ain, aout };
1523
-
1524
- rb_scan_args(argc, argv, "01", &fmt);
1525
- return na_ndloop(&ndf, 2, self, fmt);
1526
- }
1527
-
1528
- static void iter_bit_format_to_a(na_loop_t* const lp) {
1529
- size_t i;
1530
- BIT_DIGIT *a1, x = 0;
1531
- size_t p1;
1532
- ssize_t s1;
1533
- size_t* idx1;
1534
- VALUE y;
1535
- VALUE fmt = lp->option;
1536
- volatile VALUE a;
1537
-
1538
- INIT_COUNTER(lp, i);
1539
- INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
1540
- a = rb_ary_new2(i);
1541
- rb_ary_push(lp->args[1].value, a);
1542
- if (idx1) {
1543
- for (; i--;) {
1544
- LOAD_BIT(a1, p1 + *idx1, x);
1545
- idx1++;
1546
- y = format_bit(fmt, x);
1547
- rb_ary_push(a, y);
1548
- }
1549
- } else {
1550
- for (; i--;) {
1551
- LOAD_BIT(a1, p1, x);
1552
- p1 += s1;
1553
- y = format_bit(fmt, x);
1554
- rb_ary_push(a, y);
1555
- }
1556
- }
1557
- }
1558
-
1559
- /*
1560
- Format elements into strings.
1561
- @overload format_to_a format
1562
- @param [String] format
1563
- @return [Array] array of formatted strings.
1564
- */
1565
- static VALUE bit_format_to_a(int argc, VALUE* argv, VALUE self) {
1566
- VALUE fmt = Qnil;
1567
- ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
1568
- ndfunc_arg_out_t aout[1] = { { rb_cArray, 0 } }; // dummy?
1569
- ndfunc_t ndf = { iter_bit_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
1570
-
1571
- rb_scan_args(argc, argv, "01", &fmt);
1572
- return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
1573
- }
1574
-
1575
- static VALUE iter_bit_inspect(char* ptr, size_t pos, VALUE fmt) {
1576
- dtype x;
1577
- LOAD_BIT(ptr, pos, x);
1578
- return format_bit(fmt, x);
1579
- }
1580
-
1581
- /*
1582
- Returns a string containing a human-readable representation of NArray.
1583
- @overload inspect
1584
- @return [String]
1585
- */
1586
- static VALUE bit_inspect(VALUE ary) {
1587
- return na_ndloop_inspect(ary, iter_bit_inspect, Qnil);
1588
- }
1589
-
1590
1368
  static void iter_bit_each(na_loop_t* const lp) {
1591
1369
  size_t i;
1592
1370
  BIT_DIGIT *a1, x = 0;
@@ -3222,11 +3000,44 @@ void Init_numo_bit(void) {
3222
3000
  rb_define_singleton_method(cT, "cast", bit_s_cast, 1);
3223
3001
  rb_define_method(cT, "[]", bit_aref, -1);
3224
3002
  rb_define_method(cT, "[]=", bit_aset, -1);
3003
+ /**
3004
+ * return NArray with cast to the type of self.
3005
+ * @overload coerce_cast(type)
3006
+ * @return [nil]
3007
+ */
3225
3008
  rb_define_method(cT, "coerce_cast", bit_coerce_cast, 1);
3009
+ /**
3010
+ * Convert self to Array.
3011
+ * @overload to_a
3012
+ * @return [Array]
3013
+ */
3226
3014
  rb_define_method(cT, "to_a", bit_to_a, 0);
3015
+ /**
3016
+ * Fill elements with other.
3017
+ * @overload fill other
3018
+ * @param [Numeric] other
3019
+ * @return [Numo::Bit] self.
3020
+ */
3227
3021
  rb_define_method(cT, "fill", bit_fill, 1);
3022
+ /**
3023
+ * Format elements into strings.
3024
+ * @overload format format
3025
+ * @param [String] format
3026
+ * @return [Numo::RObject] array of formatted strings.
3027
+ */
3228
3028
  rb_define_method(cT, "format", bit_format, -1);
3029
+ /**
3030
+ * Format elements into strings.
3031
+ * @overload format_to_a format
3032
+ * @param [String] format
3033
+ * @return [Array] array of formatted strings.
3034
+ */
3229
3035
  rb_define_method(cT, "format_to_a", bit_format_to_a, -1);
3036
+ /**
3037
+ * Returns a string containing a human-readable representation of NArray.
3038
+ * @overload inspect
3039
+ * @return [String]
3040
+ */
3230
3041
  rb_define_method(cT, "inspect", bit_inspect, 0);
3231
3042
  rb_define_method(cT, "each", bit_each, 0);
3232
3043
  rb_define_method(cT, "each_with_index", bit_each_with_index, 0);