numo-narray-alt 0.9.13 → 0.9.14

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/ext/numo/narray/numo/narray.h +2 -2
  3. data/ext/numo/narray/src/mh/abs.h +56 -0
  4. data/ext/numo/narray/src/mh/aref.h +28 -0
  5. data/ext/numo/narray/src/mh/arg.h +56 -0
  6. data/ext/numo/narray/src/mh/conj.h +71 -0
  7. data/ext/numo/narray/src/mh/copysign.h +97 -0
  8. data/ext/numo/narray/src/mh/each.h +71 -0
  9. data/ext/numo/narray/src/mh/each_with_index.h +98 -0
  10. data/ext/numo/narray/src/mh/extract.h +36 -0
  11. data/ext/numo/narray/src/mh/im.h +71 -0
  12. data/ext/numo/narray/src/mh/imag.h +56 -0
  13. data/ext/numo/narray/src/mh/kahan_sum.h +39 -0
  14. data/ext/numo/narray/src/mh/map.h +126 -0
  15. data/ext/numo/narray/src/mh/map_with_index.h +76 -0
  16. data/ext/numo/narray/src/mh/modf.h +35 -0
  17. data/ext/numo/narray/src/mh/poly.h +42 -0
  18. data/ext/numo/narray/src/mh/real.h +56 -0
  19. data/ext/numo/narray/src/mh/set_imag.h +60 -0
  20. data/ext/numo/narray/src/mh/set_real.h +60 -0
  21. data/ext/numo/narray/src/mh/signbit.h +42 -0
  22. data/ext/numo/narray/src/t_bit.c +63 -176
  23. data/ext/numo/narray/src/t_dcomplex.c +142 -1001
  24. data/ext/numo/narray/src/t_dfloat.c +24 -560
  25. data/ext/numo/narray/src/t_int16.c +83 -417
  26. data/ext/numo/narray/src/t_int32.c +83 -417
  27. data/ext/numo/narray/src/t_int64.c +83 -417
  28. data/ext/numo/narray/src/t_int8.c +83 -400
  29. data/ext/numo/narray/src/t_robject.c +83 -400
  30. data/ext/numo/narray/src/t_scomplex.c +130 -953
  31. data/ext/numo/narray/src/t_sfloat.c +22 -524
  32. data/ext/numo/narray/src/t_uint16.c +83 -417
  33. data/ext/numo/narray/src/t_uint32.c +83 -417
  34. data/ext/numo/narray/src/t_uint64.c +83 -417
  35. data/ext/numo/narray/src/t_uint8.c +83 -400
  36. metadata +21 -2
@@ -60,12 +60,19 @@ static ID id_truncate;
60
60
  VALUE cT;
61
61
  extern VALUE cRT;
62
62
 
63
+ #include "mh/extract.h"
64
+ #include "mh/aref.h"
63
65
  #include "mh/coerce_cast.h"
64
66
  #include "mh/to_a.h"
65
67
  #include "mh/fill.h"
66
68
  #include "mh/format.h"
67
69
  #include "mh/format_to_a.h"
68
70
  #include "mh/inspect.h"
71
+ #include "mh/each.h"
72
+ #include "mh/map.h"
73
+ #include "mh/each_with_index.h"
74
+ #include "mh/map_with_index.h"
75
+ #include "mh/abs.h"
69
76
  #include "mh/op/add.h"
70
77
  #include "mh/op/sub.h"
71
78
  #include "mh/op/mul.h"
@@ -123,15 +130,23 @@ extern VALUE cRT;
123
130
  #include "mh/logseq.h"
124
131
  #include "mh/eye.h"
125
132
  #include "mh/rand.h"
133
+ #include "mh/poly.h"
126
134
 
127
135
  typedef VALUE robject; // Type aliases for shorter notation
128
136
  // following the codebase naming convention.
137
+ DEF_NARRAY_EXTRACT_METHOD_FUNC(robject)
138
+ DEF_NARRAY_AREF_METHOD_FUNC(robject)
129
139
  DEF_NARRAY_COERCE_CAST_METHOD_FUNC(robject)
130
140
  DEF_NARRAY_TO_A_METHOD_FUNC(robject)
131
141
  DEF_NARRAY_FILL_METHOD_FUNC(robject)
132
142
  DEF_NARRAY_FORMAT_METHOD_FUNC(robject)
133
143
  DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(robject)
134
144
  DEF_NARRAY_ROBJ_INSPECT_METHOD_FUNC()
145
+ DEF_NARRAY_EACH_METHOD_FUNC(robject)
146
+ DEF_NARRAY_ROBJ_MAP_METHOD_FUNC()
147
+ DEF_NARRAY_EACH_WITH_INDEX_METHOD_FUNC(robject)
148
+ DEF_NARRAY_MAP_WITH_INDEX_METHOD_FUNC(robject, numo_cRObject)
149
+ DEF_NARRAY_ABS_METHOD_FUNC(robject, numo_cRObject, robject, numo_cRObject)
135
150
  DEF_NARRAY_ROBJ_ADD_METHOD_FUNC()
136
151
  DEF_NARRAY_ROBJ_SUB_METHOD_FUNC()
137
152
  DEF_NARRAY_ROBJ_MUL_METHOD_FUNC()
@@ -189,6 +204,7 @@ DEF_NARRAY_FLT_SEQ_METHOD_FUNC(robject)
189
204
  DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(robject)
190
205
  DEF_NARRAY_EYE_METHOD_FUNC(robject)
191
206
  DEF_NARRAY_FLT_RAND_METHOD_FUNC(robject)
207
+ DEF_NARRAY_POLY_METHOD_FUNC(robject, numo_cRObject)
192
208
 
193
209
  static VALUE robject_store(VALUE, VALUE);
194
210
 
@@ -315,28 +331,6 @@ static VALUE robject_allocate(VALUE self) {
315
331
  return self;
316
332
  }
317
333
 
318
- /*
319
- Extract an element only if self is a dimensionless NArray.
320
- @overload extract
321
- @return [Numeric,Numo::NArray]
322
- --- Extract element value as Ruby Object if self is a dimensionless NArray,
323
- otherwise returns self.
324
- */
325
- static VALUE robject_extract(VALUE self) {
326
- volatile VALUE v;
327
- char* ptr;
328
- narray_t* na;
329
- GetNArray(self, na);
330
-
331
- if (na->ndim == 0) {
332
- ptr = na_get_pointer_for_read(self) + na_get_offset(self);
333
- v = m_extract(ptr);
334
- na_release_lock(self);
335
- return v;
336
- }
337
- return self;
338
- }
339
-
340
334
  static VALUE robject_new_dim0(dtype x) {
341
335
  VALUE v;
342
336
  dtype* ptr;
@@ -1307,29 +1301,6 @@ static VALUE robject_s_cast(VALUE type, VALUE obj) {
1307
1301
  return robject_new_dim0(obj);
1308
1302
  }
1309
1303
 
1310
- /*
1311
- Multi-dimensional element reference.
1312
- @overload [](dim0,...,dimL)
1313
- @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
1314
- dim0,...,dimL multi-dimensional indices.
1315
- @return [Numeric,Numo::RObject] an element or NArray view.
1316
- @see Numo::NArray#[]
1317
- @see #[]=
1318
- */
1319
- static VALUE robject_aref(int argc, VALUE* argv, VALUE self) {
1320
- int nd;
1321
- size_t pos;
1322
- char* ptr;
1323
-
1324
- nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
1325
- if (nd) {
1326
- return na_aref_main(argc, argv, self, 0, nd);
1327
- } else {
1328
- ptr = na_get_pointer_for_read(self) + pos;
1329
- return m_extract(ptr);
1330
- }
1331
- }
1332
-
1333
1304
  /*
1334
1305
  Multi-dimensional element assignment.
1335
1306
  @overload []=(dim0,...,dimL,val)
@@ -1364,361 +1335,6 @@ static VALUE robject_aset(int argc, VALUE* argv, VALUE self) {
1364
1335
  return argv[argc];
1365
1336
  }
1366
1337
 
1367
- static void iter_robject_each(na_loop_t* const lp) {
1368
- size_t i, s1;
1369
- char* p1;
1370
- size_t* idx1;
1371
- dtype x;
1372
- VALUE y;
1373
-
1374
- INIT_COUNTER(lp, i);
1375
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1376
- if (idx1) {
1377
- for (; i--;) {
1378
- GET_DATA_INDEX(p1, idx1, dtype, x);
1379
- y = m_data_to_num(x);
1380
- rb_yield(y);
1381
- }
1382
- } else {
1383
- for (; i--;) {
1384
- GET_DATA_STRIDE(p1, s1, dtype, x);
1385
- y = m_data_to_num(x);
1386
- rb_yield(y);
1387
- }
1388
- }
1389
- }
1390
-
1391
- /*
1392
- Calls the given block once for each element in self,
1393
- passing that element as a parameter.
1394
- @overload each
1395
- @return [Numo::NArray] self
1396
- For a block `{|x| ... }`,
1397
- @yieldparam [Numeric] x an element of NArray.
1398
- @see #each_with_index
1399
- @see #map
1400
- */
1401
- static VALUE robject_each(VALUE self) {
1402
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
1403
- ndfunc_t ndf = { iter_robject_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
1404
-
1405
- na_ndloop(&ndf, 1, self);
1406
- return self;
1407
- }
1408
-
1409
- static void iter_robject_map(na_loop_t* const lp) {
1410
- size_t i, n;
1411
- char *p1, *p2;
1412
- ssize_t s1, s2;
1413
- size_t *idx1, *idx2;
1414
- dtype x;
1415
-
1416
- INIT_COUNTER(lp, n);
1417
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1418
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1419
-
1420
- if (idx1) {
1421
- if (idx2) {
1422
- for (i = 0; i < n; i++) {
1423
- GET_DATA_INDEX(p1, idx1, dtype, x);
1424
- x = m_map(x);
1425
- SET_DATA_INDEX(p2, idx2, dtype, x);
1426
- }
1427
- } else {
1428
- for (i = 0; i < n; i++) {
1429
- GET_DATA_INDEX(p1, idx1, dtype, x);
1430
- x = m_map(x);
1431
- SET_DATA_STRIDE(p2, s2, dtype, x);
1432
- }
1433
- }
1434
- } else {
1435
- if (idx2) {
1436
- for (i = 0; i < n; i++) {
1437
- GET_DATA_STRIDE(p1, s1, dtype, x);
1438
- x = m_map(x);
1439
- SET_DATA_INDEX(p2, idx2, dtype, x);
1440
- }
1441
- } else {
1442
- //
1443
- for (i = 0; i < n; i++) {
1444
- *(dtype*)p2 = m_map(*(dtype*)p1);
1445
- p1 += s1;
1446
- p2 += s2;
1447
- }
1448
- return;
1449
- //
1450
- }
1451
- }
1452
- }
1453
-
1454
- /*
1455
- Unary map.
1456
- @overload map
1457
- @return [Numo::RObject] map of self.
1458
- */
1459
- static VALUE robject_map(VALUE self) {
1460
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1461
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1462
- ndfunc_t ndf = { iter_robject_map, FULL_LOOP, 1, 1, ain, aout };
1463
-
1464
- return na_ndloop(&ndf, 1, self);
1465
- }
1466
-
1467
- static inline void yield_each_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
1468
- int j;
1469
-
1470
- a[0] = m_data_to_num(x);
1471
- for (j = 0; j <= nd; j++) {
1472
- a[j + 1] = SIZET2NUM(c[j]);
1473
- }
1474
- rb_yield(rb_ary_new4(md, a));
1475
- }
1476
-
1477
- static void iter_robject_each_with_index(na_loop_t* const lp) {
1478
- size_t i, s1;
1479
- char* p1;
1480
- size_t* idx1;
1481
- dtype x;
1482
- VALUE* a;
1483
- size_t* c;
1484
- int nd, md;
1485
-
1486
- c = (size_t*)(lp->opt_ptr);
1487
- nd = lp->ndim;
1488
- if (nd > 0) {
1489
- nd--;
1490
- }
1491
- md = nd + 2;
1492
- a = ALLOCA_N(VALUE, md);
1493
-
1494
- INIT_COUNTER(lp, i);
1495
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1496
- c[nd] = 0;
1497
- if (idx1) {
1498
- for (; i--;) {
1499
- GET_DATA_INDEX(p1, idx1, dtype, x);
1500
- yield_each_with_index(x, c, a, nd, md);
1501
- c[nd]++;
1502
- }
1503
- } else {
1504
- for (; i--;) {
1505
- GET_DATA_STRIDE(p1, s1, dtype, x);
1506
- yield_each_with_index(x, c, a, nd, md);
1507
- c[nd]++;
1508
- }
1509
- }
1510
- }
1511
-
1512
- /*
1513
- Invokes the given block once for each element of self,
1514
- passing that element and indices along each axis as parameters.
1515
- @overload each_with_index
1516
- For a block `{|x,i,j,...| ... }`,
1517
- @yieldparam [Numeric] x an element
1518
- @yieldparam [Integer] i,j,... multitimensional indices
1519
- @return [Numo::NArray] self
1520
- @see #each
1521
- @see #map_with_index
1522
- */
1523
- static VALUE robject_each_with_index(VALUE self) {
1524
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
1525
- ndfunc_t ndf = { iter_robject_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
1526
-
1527
- na_ndloop_with_index(&ndf, 1, self);
1528
- return self;
1529
- }
1530
-
1531
- static inline dtype yield_map_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
1532
- int j;
1533
- VALUE y;
1534
-
1535
- a[0] = m_data_to_num(x);
1536
- for (j = 0; j <= nd; j++) {
1537
- a[j + 1] = SIZET2NUM(c[j]);
1538
- }
1539
- y = rb_yield(rb_ary_new4(md, a));
1540
- return m_num_to_data(y);
1541
- }
1542
-
1543
- static void iter_robject_map_with_index(na_loop_t* const lp) {
1544
- size_t i;
1545
- char *p1, *p2;
1546
- ssize_t s1, s2;
1547
- size_t *idx1, *idx2;
1548
- dtype x;
1549
- VALUE* a;
1550
- size_t* c;
1551
- int nd, md;
1552
-
1553
- c = (size_t*)(lp->opt_ptr);
1554
- nd = lp->ndim;
1555
- if (nd > 0) {
1556
- nd--;
1557
- }
1558
- md = nd + 2;
1559
- a = ALLOCA_N(VALUE, md);
1560
-
1561
- INIT_COUNTER(lp, i);
1562
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1563
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1564
-
1565
- c[nd] = 0;
1566
- if (idx1) {
1567
- if (idx2) {
1568
- for (; i--;) {
1569
- GET_DATA_INDEX(p1, idx1, dtype, x);
1570
- x = yield_map_with_index(x, c, a, nd, md);
1571
- SET_DATA_INDEX(p2, idx2, dtype, x);
1572
- c[nd]++;
1573
- }
1574
- } else {
1575
- for (; i--;) {
1576
- GET_DATA_INDEX(p1, idx1, dtype, x);
1577
- x = yield_map_with_index(x, c, a, nd, md);
1578
- SET_DATA_STRIDE(p2, s2, dtype, x);
1579
- c[nd]++;
1580
- }
1581
- }
1582
- } else {
1583
- if (idx2) {
1584
- for (; i--;) {
1585
- GET_DATA_STRIDE(p1, s1, dtype, x);
1586
- x = yield_map_with_index(x, c, a, nd, md);
1587
- SET_DATA_INDEX(p2, idx2, dtype, x);
1588
- c[nd]++;
1589
- }
1590
- } else {
1591
- for (; i--;) {
1592
- GET_DATA_STRIDE(p1, s1, dtype, x);
1593
- x = yield_map_with_index(x, c, a, nd, md);
1594
- SET_DATA_STRIDE(p2, s2, dtype, x);
1595
- c[nd]++;
1596
- }
1597
- }
1598
- }
1599
- }
1600
-
1601
- /*
1602
- Invokes the given block once for each element of self,
1603
- passing that element and indices along each axis as parameters.
1604
- Creates a new NArray containing the values returned by the block.
1605
- Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
1606
- @overload map_with_index
1607
- For a block `{|x,i,j,...| ... }`,
1608
- @yieldparam [Numeric] x an element
1609
- @yieldparam [Integer] i,j,... multitimensional indices
1610
- @return [Numo::NArray] mapped array
1611
- @see #map
1612
- @see #each_with_index
1613
- */
1614
- static VALUE robject_map_with_index(VALUE self) {
1615
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
1616
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1617
- ndfunc_t ndf = { iter_robject_map_with_index, FULL_LOOP, 1, 1, ain, aout };
1618
-
1619
- return na_ndloop_with_index(&ndf, 1, self);
1620
- }
1621
-
1622
- static void iter_robject_abs(na_loop_t* const lp) {
1623
- size_t i;
1624
- char *p1, *p2;
1625
- ssize_t s1, s2;
1626
- size_t *idx1, *idx2;
1627
- dtype x;
1628
- rtype y;
1629
- INIT_COUNTER(lp, i);
1630
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1631
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1632
- if (idx1) {
1633
- if (idx2) {
1634
- for (; i--;) {
1635
- GET_DATA_INDEX(p1, idx1, dtype, x);
1636
- y = m_abs(x);
1637
- SET_DATA_INDEX(p2, idx2, rtype, y);
1638
- }
1639
- } else {
1640
- for (; i--;) {
1641
- GET_DATA_INDEX(p1, idx1, dtype, x);
1642
- y = m_abs(x);
1643
- SET_DATA_STRIDE(p2, s2, rtype, y);
1644
- }
1645
- }
1646
- } else {
1647
- if (idx2) {
1648
- for (; i--;) {
1649
- GET_DATA_STRIDE(p1, s1, dtype, x);
1650
- y = m_abs(x);
1651
- SET_DATA_INDEX(p2, idx2, rtype, y);
1652
- }
1653
- } else {
1654
- for (; i--;) {
1655
- GET_DATA_STRIDE(p1, s1, dtype, x);
1656
- y = m_abs(x);
1657
- SET_DATA_STRIDE(p2, s2, rtype, y);
1658
- }
1659
- }
1660
- }
1661
- }
1662
-
1663
- /*
1664
- abs of self.
1665
- @overload abs
1666
- @return [Numo::RObject] abs of self.
1667
- */
1668
- static VALUE robject_abs(VALUE self) {
1669
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1670
- ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
1671
- ndfunc_t ndf = { iter_robject_abs, FULL_LOOP, 1, 1, ain, aout };
1672
-
1673
- return na_ndloop(&ndf, 1, self);
1674
- }
1675
-
1676
- static void iter_robject_poly(na_loop_t* const lp) {
1677
- size_t i;
1678
- dtype x, y, a;
1679
-
1680
- x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
1681
- i = lp->narg - 2;
1682
- y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
1683
- for (; --i;) {
1684
- y = m_mul(x, y);
1685
- a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
1686
- y = m_add(y, a);
1687
- }
1688
- i = lp->narg - 1;
1689
- *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
1690
- }
1691
-
1692
- /*
1693
- Calculate polynomial.
1694
- `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
1695
- @overload poly a0, a1, ..., an
1696
- @param [Numo::NArray,Numeric] a0,a1,...,an
1697
- @return [Numo::RObject]
1698
- */
1699
- static VALUE robject_poly(VALUE self, VALUE args) {
1700
- int argc, i;
1701
- VALUE* argv;
1702
- volatile VALUE v, a;
1703
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1704
- ndfunc_t ndf = { iter_robject_poly, NO_LOOP, 0, 1, 0, aout };
1705
-
1706
- argc = (int)RARRAY_LEN(args);
1707
- ndf.nin = argc + 1;
1708
- ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
1709
- for (i = 0; i < argc + 1; i++) {
1710
- ndf.ain[i].type = cT;
1711
- }
1712
- argv = ALLOCA_N(VALUE, argc + 1);
1713
- argv[0] = self;
1714
- for (i = 0; i < argc; i++) {
1715
- argv[i + 1] = RARRAY_PTR(args)[i];
1716
- }
1717
- a = rb_ary_new4(argc + 1, argv);
1718
- v = na_ndloop2(&ndf, a);
1719
- return robject_extract(v);
1720
- }
1721
-
1722
1338
  void Init_numo_robject(void) {
1723
1339
  VALUE hCast, mNumo;
1724
1340
 
@@ -1806,11 +1422,27 @@ void Init_numo_robject(void) {
1806
1422
  rb_undef_method(cT, "to_swapped");
1807
1423
  rb_define_alloc_func(cT, robject_s_alloc_func);
1808
1424
  rb_define_method(cT, "allocate", robject_allocate, 0);
1425
+ /**
1426
+ * Extract an element only if self is a dimensionless NArray.
1427
+ * @overload extract
1428
+ * @return [Numeric,Numo::NArray]
1429
+ * --- Extract element value as Ruby Object if self is a dimensionless NArray,
1430
+ * otherwise returns self.
1431
+ */
1809
1432
  rb_define_method(cT, "extract", robject_extract, 0);
1810
1433
 
1811
1434
  rb_define_method(cT, "store", robject_store, 1);
1812
1435
 
1813
1436
  rb_define_singleton_method(cT, "cast", robject_s_cast, 1);
1437
+ /**
1438
+ * Multi-dimensional element reference.
1439
+ * @overload [](dim0,...,dimL)
1440
+ * @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,
1441
+ * Symbol] dim0,...,dimL multi-dimensional indices.
1442
+ * @return [Numeric,Numo::RObject] an element or NArray view.
1443
+ * @see Numo::NArray#[]
1444
+ * @see #[]=
1445
+ */
1814
1446
  rb_define_method(cT, "[]", robject_aref, -1);
1815
1447
  rb_define_method(cT, "[]=", robject_aset, -1);
1816
1448
  /**
@@ -1852,10 +1484,54 @@ void Init_numo_robject(void) {
1852
1484
  * @return [String]
1853
1485
  */
1854
1486
  rb_define_method(cT, "inspect", robject_inspect, 0);
1487
+ /**
1488
+ * Calls the given block once for each element in self,
1489
+ * passing that element as a parameter.
1490
+ * @overload each
1491
+ * @return [Numo::NArray] self
1492
+ * For a block `{|x| ... }`,
1493
+ * @yieldparam [Numeric] x an element of NArray.
1494
+ * @see #each_with_index
1495
+ * @see #map
1496
+ */
1855
1497
  rb_define_method(cT, "each", robject_each, 0);
1498
+ /**
1499
+ * Unary map.
1500
+ * @overload map
1501
+ * @return [Numo::RObject] map of self.
1502
+ */
1856
1503
  rb_define_method(cT, "map", robject_map, 0);
1504
+ /**
1505
+ * Invokes the given block once for each element of self,
1506
+ * passing that element and indices along each axis as parameters.
1507
+ * @overload each_with_index
1508
+ * For a block `{|x,i,j,...| ... }`,
1509
+ * @yieldparam [Numeric] x an element
1510
+ * @yieldparam [Integer] i,j,... multitimensional indices
1511
+ * @return [Numo::NArray] self
1512
+ * @see #each
1513
+ * @see #map_with_index
1514
+ */
1857
1515
  rb_define_method(cT, "each_with_index", robject_each_with_index, 0);
1516
+ /**
1517
+ * Invokes the given block once for each element of self,
1518
+ * passing that element and indices along each axis as parameters.
1519
+ * Creates a new NArray containing the values returned by the block.
1520
+ * Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
1521
+ * @overload map_with_index
1522
+ * For a block `{|x,i,j,...| ... }`,
1523
+ * @yieldparam [Numeric] x an element
1524
+ * @yieldparam [Integer] i,j,... multitimensional indices
1525
+ * @return [Numo::NArray] mapped array
1526
+ * @see #map
1527
+ * @see #each_with_index
1528
+ */
1858
1529
  rb_define_method(cT, "map_with_index", robject_map_with_index, 0);
1530
+ /**
1531
+ * abs of self.
1532
+ * @overload abs
1533
+ * @return [Numo::RObject] abs of self.
1534
+ */
1859
1535
  rb_define_method(cT, "abs", robject_abs, 0);
1860
1536
  /**
1861
1537
  * Binary add.
@@ -2429,6 +2105,13 @@ void Init_numo_robject(void) {
2429
2105
  * # [4, 3, 3, 2, 4, 2]
2430
2106
  */
2431
2107
  rb_define_method(cT, "rand", robject_rand, -1);
2108
+ /**
2109
+ * Calculate polynomial.
2110
+ * `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
2111
+ * @overload poly a0, a1, ..., an
2112
+ * @param [Numo::NArray,Numeric] a0,a1,...,an
2113
+ * @return [Numo::RObject]
2114
+ */
2432
2115
  rb_define_method(cT, "poly", robject_poly, -2);
2433
2116
  rb_define_singleton_method(cT, "[]", robject_s_cast, -2);
2434
2117
  }