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
@@ -43,12 +43,19 @@ static ID id_to_a;
43
43
  VALUE cT;
44
44
  extern VALUE cRT;
45
45
 
46
+ #include "mh/extract.h"
47
+ #include "mh/aref.h"
46
48
  #include "mh/coerce_cast.h"
47
49
  #include "mh/to_a.h"
48
50
  #include "mh/fill.h"
49
51
  #include "mh/format.h"
50
52
  #include "mh/format_to_a.h"
51
53
  #include "mh/inspect.h"
54
+ #include "mh/each.h"
55
+ #include "mh/map.h"
56
+ #include "mh/each_with_index.h"
57
+ #include "mh/map_with_index.h"
58
+ #include "mh/abs.h"
52
59
  #include "mh/op/add.h"
53
60
  #include "mh/op/sub.h"
54
61
  #include "mh/op/mul.h"
@@ -92,6 +99,7 @@ extern VALUE cRT;
92
99
  #include "mh/seq.h"
93
100
  #include "mh/eye.h"
94
101
  #include "mh/rand.h"
102
+ #include "mh/poly.h"
95
103
  #include "mh/mean.h"
96
104
  #include "mh/var.h"
97
105
  #include "mh/stddev.h"
@@ -99,12 +107,19 @@ extern VALUE cRT;
99
107
 
100
108
  typedef u_int16_t uint16; // Type aliases for shorter notation
101
109
  // following the codebase naming convention.
110
+ DEF_NARRAY_EXTRACT_METHOD_FUNC(uint16)
111
+ DEF_NARRAY_AREF_METHOD_FUNC(uint16)
102
112
  DEF_NARRAY_COERCE_CAST_METHOD_FUNC(uint16)
103
113
  DEF_NARRAY_TO_A_METHOD_FUNC(uint16)
104
114
  DEF_NARRAY_FILL_METHOD_FUNC(uint16)
105
115
  DEF_NARRAY_FORMAT_METHOD_FUNC(uint16)
106
116
  DEF_NARRAY_FORMAT_TO_A_METHOD_FUNC(uint16)
107
117
  DEF_NARRAY_INSPECT_METHOD_FUNC(uint16)
118
+ DEF_NARRAY_EACH_METHOD_FUNC(uint16)
119
+ DEF_NARRAY_MAP_METHOD_FUNC(uint16, numo_cUInt16)
120
+ DEF_NARRAY_EACH_WITH_INDEX_METHOD_FUNC(uint16)
121
+ DEF_NARRAY_MAP_WITH_INDEX_METHOD_FUNC(uint16, numo_cUInt16)
122
+ DEF_NARRAY_ABS_METHOD_FUNC(uint16, numo_cUInt16, uint16, numo_cUInt16)
108
123
  DEF_NARRAY_ADD_METHOD_FUNC(uint16, numo_cUInt16)
109
124
  DEF_NARRAY_SUB_METHOD_FUNC(uint16, numo_cUInt16)
110
125
  DEF_NARRAY_MUL_METHOD_FUNC(uint16, numo_cUInt16)
@@ -148,6 +163,7 @@ DEF_NARRAY_INT_MULSUM_METHOD_FUNC(uint16, numo_cUInt16)
148
163
  DEF_NARRAY_INT_SEQ_METHOD_FUNC(uint16)
149
164
  DEF_NARRAY_EYE_METHOD_FUNC(uint16)
150
165
  DEF_NARRAY_INT_RAND_METHOD_FUNC(uint16)
166
+ DEF_NARRAY_POLY_METHOD_FUNC(uint16, numo_cUInt16)
151
167
  DEF_NARRAY_INT_MEAN_METHOD_FUNC(uint16, numo_cUInt16)
152
168
  DEF_NARRAY_INT_VAR_METHOD_FUNC(uint16, numo_cUInt16)
153
169
  DEF_NARRAY_INT_STDDEV_METHOD_FUNC(uint16, numo_cUInt16)
@@ -256,28 +272,6 @@ static VALUE uint16_allocate(VALUE self) {
256
272
  return self;
257
273
  }
258
274
 
259
- /*
260
- Extract an element only if self is a dimensionless NArray.
261
- @overload extract
262
- @return [Numeric,Numo::NArray]
263
- --- Extract element value as Ruby Object if self is a dimensionless NArray,
264
- otherwise returns self.
265
- */
266
- static VALUE uint16_extract(VALUE self) {
267
- volatile VALUE v;
268
- char* ptr;
269
- narray_t* na;
270
- GetNArray(self, na);
271
-
272
- if (na->ndim == 0) {
273
- ptr = na_get_pointer_for_read(self) + na_get_offset(self);
274
- v = m_extract(ptr);
275
- na_release_lock(self);
276
- return v;
277
- }
278
- return self;
279
- }
280
-
281
275
  static VALUE uint16_new_dim0(dtype x) {
282
276
  VALUE v;
283
277
  dtype* ptr;
@@ -1255,29 +1249,6 @@ static VALUE uint16_s_cast(VALUE type, VALUE obj) {
1255
1249
  return Qnil;
1256
1250
  }
1257
1251
 
1258
- /*
1259
- Multi-dimensional element reference.
1260
- @overload [](dim0,...,dimL)
1261
- @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
1262
- dim0,...,dimL multi-dimensional indices.
1263
- @return [Numeric,Numo::UInt16] an element or NArray view.
1264
- @see Numo::NArray#[]
1265
- @see #[]=
1266
- */
1267
- static VALUE uint16_aref(int argc, VALUE* argv, VALUE self) {
1268
- int nd;
1269
- size_t pos;
1270
- char* ptr;
1271
-
1272
- nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
1273
- if (nd) {
1274
- return na_aref_main(argc, argv, self, 0, nd);
1275
- } else {
1276
- ptr = na_get_pointer_for_read(self) + pos;
1277
- return m_extract(ptr);
1278
- }
1279
- }
1280
-
1281
1252
  /*
1282
1253
  Multi-dimensional element assignment.
1283
1254
  @overload []=(dim0,...,dimL,val)
@@ -1312,378 +1283,6 @@ static VALUE uint16_aset(int argc, VALUE* argv, VALUE self) {
1312
1283
  return argv[argc];
1313
1284
  }
1314
1285
 
1315
- static void iter_uint16_each(na_loop_t* const lp) {
1316
- size_t i, s1;
1317
- char* p1;
1318
- size_t* idx1;
1319
- dtype x;
1320
- VALUE y;
1321
-
1322
- INIT_COUNTER(lp, i);
1323
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1324
- if (idx1) {
1325
- for (; i--;) {
1326
- GET_DATA_INDEX(p1, idx1, dtype, x);
1327
- y = m_data_to_num(x);
1328
- rb_yield(y);
1329
- }
1330
- } else {
1331
- for (; i--;) {
1332
- GET_DATA_STRIDE(p1, s1, dtype, x);
1333
- y = m_data_to_num(x);
1334
- rb_yield(y);
1335
- }
1336
- }
1337
- }
1338
-
1339
- /*
1340
- Calls the given block once for each element in self,
1341
- passing that element as a parameter.
1342
- @overload each
1343
- @return [Numo::NArray] self
1344
- For a block `{|x| ... }`,
1345
- @yieldparam [Numeric] x an element of NArray.
1346
- @see #each_with_index
1347
- @see #map
1348
- */
1349
- static VALUE uint16_each(VALUE self) {
1350
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
1351
- ndfunc_t ndf = { iter_uint16_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
1352
-
1353
- na_ndloop(&ndf, 1, self);
1354
- return self;
1355
- }
1356
-
1357
- static void iter_uint16_map(na_loop_t* const lp) {
1358
- size_t i, n;
1359
- char *p1, *p2;
1360
- ssize_t s1, s2;
1361
- size_t *idx1, *idx2;
1362
- dtype x;
1363
-
1364
- INIT_COUNTER(lp, n);
1365
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1366
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1367
-
1368
- if (idx1) {
1369
- if (idx2) {
1370
- for (i = 0; i < n; i++) {
1371
- GET_DATA_INDEX(p1, idx1, dtype, x);
1372
- x = m_map(x);
1373
- SET_DATA_INDEX(p2, idx2, dtype, x);
1374
- }
1375
- } else {
1376
- for (i = 0; i < n; i++) {
1377
- GET_DATA_INDEX(p1, idx1, dtype, x);
1378
- x = m_map(x);
1379
- SET_DATA_STRIDE(p2, s2, dtype, x);
1380
- }
1381
- }
1382
- } else {
1383
- if (idx2) {
1384
- for (i = 0; i < n; i++) {
1385
- GET_DATA_STRIDE(p1, s1, dtype, x);
1386
- x = m_map(x);
1387
- SET_DATA_INDEX(p2, idx2, dtype, x);
1388
- }
1389
- } else {
1390
- //
1391
- if (is_aligned(p1, sizeof(dtype)) && is_aligned(p2, sizeof(dtype))) {
1392
- if (s1 == sizeof(dtype) && s2 == sizeof(dtype)) {
1393
- for (i = 0; i < n; i++) {
1394
- ((dtype*)p2)[i] = m_map(((dtype*)p1)[i]);
1395
- }
1396
- return;
1397
- }
1398
- if (is_aligned_step(s1, sizeof(dtype)) && is_aligned_step(s2, sizeof(dtype))) {
1399
- //
1400
- for (i = 0; i < n; i++) {
1401
- *(dtype*)p2 = m_map(*(dtype*)p1);
1402
- p1 += s1;
1403
- p2 += s2;
1404
- }
1405
- return;
1406
- //
1407
- }
1408
- }
1409
- for (i = 0; i < n; i++) {
1410
- GET_DATA_STRIDE(p1, s1, dtype, x);
1411
- x = m_map(x);
1412
- SET_DATA_STRIDE(p2, s2, dtype, x);
1413
- }
1414
- //
1415
- }
1416
- }
1417
- }
1418
-
1419
- /*
1420
- Unary map.
1421
- @overload map
1422
- @return [Numo::UInt16] map of self.
1423
- */
1424
- static VALUE uint16_map(VALUE self) {
1425
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1426
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1427
- ndfunc_t ndf = { iter_uint16_map, FULL_LOOP, 1, 1, ain, aout };
1428
-
1429
- return na_ndloop(&ndf, 1, self);
1430
- }
1431
-
1432
- static inline void yield_each_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
1433
- int j;
1434
-
1435
- a[0] = m_data_to_num(x);
1436
- for (j = 0; j <= nd; j++) {
1437
- a[j + 1] = SIZET2NUM(c[j]);
1438
- }
1439
- rb_yield(rb_ary_new4(md, a));
1440
- }
1441
-
1442
- static void iter_uint16_each_with_index(na_loop_t* const lp) {
1443
- size_t i, s1;
1444
- char* p1;
1445
- size_t* idx1;
1446
- dtype x;
1447
- VALUE* a;
1448
- size_t* c;
1449
- int nd, md;
1450
-
1451
- c = (size_t*)(lp->opt_ptr);
1452
- nd = lp->ndim;
1453
- if (nd > 0) {
1454
- nd--;
1455
- }
1456
- md = nd + 2;
1457
- a = ALLOCA_N(VALUE, md);
1458
-
1459
- INIT_COUNTER(lp, i);
1460
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1461
- c[nd] = 0;
1462
- if (idx1) {
1463
- for (; i--;) {
1464
- GET_DATA_INDEX(p1, idx1, dtype, x);
1465
- yield_each_with_index(x, c, a, nd, md);
1466
- c[nd]++;
1467
- }
1468
- } else {
1469
- for (; i--;) {
1470
- GET_DATA_STRIDE(p1, s1, dtype, x);
1471
- yield_each_with_index(x, c, a, nd, md);
1472
- c[nd]++;
1473
- }
1474
- }
1475
- }
1476
-
1477
- /*
1478
- Invokes the given block once for each element of self,
1479
- passing that element and indices along each axis as parameters.
1480
- @overload each_with_index
1481
- For a block `{|x,i,j,...| ... }`,
1482
- @yieldparam [Numeric] x an element
1483
- @yieldparam [Integer] i,j,... multitimensional indices
1484
- @return [Numo::NArray] self
1485
- @see #each
1486
- @see #map_with_index
1487
- */
1488
- static VALUE uint16_each_with_index(VALUE self) {
1489
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
1490
- ndfunc_t ndf = { iter_uint16_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
1491
-
1492
- na_ndloop_with_index(&ndf, 1, self);
1493
- return self;
1494
- }
1495
-
1496
- static inline dtype yield_map_with_index(dtype x, size_t* c, VALUE* a, int nd, int md) {
1497
- int j;
1498
- VALUE y;
1499
-
1500
- a[0] = m_data_to_num(x);
1501
- for (j = 0; j <= nd; j++) {
1502
- a[j + 1] = SIZET2NUM(c[j]);
1503
- }
1504
- y = rb_yield(rb_ary_new4(md, a));
1505
- return m_num_to_data(y);
1506
- }
1507
-
1508
- static void iter_uint16_map_with_index(na_loop_t* const lp) {
1509
- size_t i;
1510
- char *p1, *p2;
1511
- ssize_t s1, s2;
1512
- size_t *idx1, *idx2;
1513
- dtype x;
1514
- VALUE* a;
1515
- size_t* c;
1516
- int nd, md;
1517
-
1518
- c = (size_t*)(lp->opt_ptr);
1519
- nd = lp->ndim;
1520
- if (nd > 0) {
1521
- nd--;
1522
- }
1523
- md = nd + 2;
1524
- a = ALLOCA_N(VALUE, md);
1525
-
1526
- INIT_COUNTER(lp, i);
1527
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1528
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1529
-
1530
- c[nd] = 0;
1531
- if (idx1) {
1532
- if (idx2) {
1533
- for (; i--;) {
1534
- GET_DATA_INDEX(p1, idx1, dtype, x);
1535
- x = yield_map_with_index(x, c, a, nd, md);
1536
- SET_DATA_INDEX(p2, idx2, dtype, x);
1537
- c[nd]++;
1538
- }
1539
- } else {
1540
- for (; i--;) {
1541
- GET_DATA_INDEX(p1, idx1, dtype, x);
1542
- x = yield_map_with_index(x, c, a, nd, md);
1543
- SET_DATA_STRIDE(p2, s2, dtype, x);
1544
- c[nd]++;
1545
- }
1546
- }
1547
- } else {
1548
- if (idx2) {
1549
- for (; i--;) {
1550
- GET_DATA_STRIDE(p1, s1, dtype, x);
1551
- x = yield_map_with_index(x, c, a, nd, md);
1552
- SET_DATA_INDEX(p2, idx2, dtype, x);
1553
- c[nd]++;
1554
- }
1555
- } else {
1556
- for (; i--;) {
1557
- GET_DATA_STRIDE(p1, s1, dtype, x);
1558
- x = yield_map_with_index(x, c, a, nd, md);
1559
- SET_DATA_STRIDE(p2, s2, dtype, x);
1560
- c[nd]++;
1561
- }
1562
- }
1563
- }
1564
- }
1565
-
1566
- /*
1567
- Invokes the given block once for each element of self,
1568
- passing that element and indices along each axis as parameters.
1569
- Creates a new NArray containing the values returned by the block.
1570
- Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
1571
- @overload map_with_index
1572
- For a block `{|x,i,j,...| ... }`,
1573
- @yieldparam [Numeric] x an element
1574
- @yieldparam [Integer] i,j,... multitimensional indices
1575
- @return [Numo::NArray] mapped array
1576
- @see #map
1577
- @see #each_with_index
1578
- */
1579
- static VALUE uint16_map_with_index(VALUE self) {
1580
- ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
1581
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1582
- ndfunc_t ndf = { iter_uint16_map_with_index, FULL_LOOP, 1, 1, ain, aout };
1583
-
1584
- return na_ndloop_with_index(&ndf, 1, self);
1585
- }
1586
-
1587
- static void iter_uint16_abs(na_loop_t* const lp) {
1588
- size_t i;
1589
- char *p1, *p2;
1590
- ssize_t s1, s2;
1591
- size_t *idx1, *idx2;
1592
- dtype x;
1593
- rtype y;
1594
- INIT_COUNTER(lp, i);
1595
- INIT_PTR_IDX(lp, 0, p1, s1, idx1);
1596
- INIT_PTR_IDX(lp, 1, p2, s2, idx2);
1597
- if (idx1) {
1598
- if (idx2) {
1599
- for (; i--;) {
1600
- GET_DATA_INDEX(p1, idx1, dtype, x);
1601
- y = m_abs(x);
1602
- SET_DATA_INDEX(p2, idx2, rtype, y);
1603
- }
1604
- } else {
1605
- for (; i--;) {
1606
- GET_DATA_INDEX(p1, idx1, dtype, x);
1607
- y = m_abs(x);
1608
- SET_DATA_STRIDE(p2, s2, rtype, y);
1609
- }
1610
- }
1611
- } else {
1612
- if (idx2) {
1613
- for (; i--;) {
1614
- GET_DATA_STRIDE(p1, s1, dtype, x);
1615
- y = m_abs(x);
1616
- SET_DATA_INDEX(p2, idx2, rtype, y);
1617
- }
1618
- } else {
1619
- for (; i--;) {
1620
- GET_DATA_STRIDE(p1, s1, dtype, x);
1621
- y = m_abs(x);
1622
- SET_DATA_STRIDE(p2, s2, rtype, y);
1623
- }
1624
- }
1625
- }
1626
- }
1627
-
1628
- /*
1629
- abs of self.
1630
- @overload abs
1631
- @return [Numo::UInt16] abs of self.
1632
- */
1633
- static VALUE uint16_abs(VALUE self) {
1634
- ndfunc_arg_in_t ain[1] = { { cT, 0 } };
1635
- ndfunc_arg_out_t aout[1] = { { cRT, 0 } };
1636
- ndfunc_t ndf = { iter_uint16_abs, FULL_LOOP, 1, 1, ain, aout };
1637
-
1638
- return na_ndloop(&ndf, 1, self);
1639
- }
1640
-
1641
- static void iter_uint16_poly(na_loop_t* const lp) {
1642
- size_t i;
1643
- dtype x, y, a;
1644
-
1645
- x = *(dtype*)(lp->args[0].ptr + lp->args[0].iter[0].pos);
1646
- i = lp->narg - 2;
1647
- y = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
1648
- for (; --i;) {
1649
- y = m_mul(x, y);
1650
- a = *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos);
1651
- y = m_add(y, a);
1652
- }
1653
- i = lp->narg - 1;
1654
- *(dtype*)(lp->args[i].ptr + lp->args[i].iter[0].pos) = y;
1655
- }
1656
-
1657
- /*
1658
- Calculate polynomial.
1659
- `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
1660
- @overload poly a0, a1, ..., an
1661
- @param [Numo::NArray,Numeric] a0,a1,...,an
1662
- @return [Numo::UInt16]
1663
- */
1664
- static VALUE uint16_poly(VALUE self, VALUE args) {
1665
- int argc, i;
1666
- VALUE* argv;
1667
- volatile VALUE v, a;
1668
- ndfunc_arg_out_t aout[1] = { { cT, 0 } };
1669
- ndfunc_t ndf = { iter_uint16_poly, NO_LOOP, 0, 1, 0, aout };
1670
-
1671
- argc = (int)RARRAY_LEN(args);
1672
- ndf.nin = argc + 1;
1673
- ndf.ain = ALLOCA_N(ndfunc_arg_in_t, argc + 1);
1674
- for (i = 0; i < argc + 1; i++) {
1675
- ndf.ain[i].type = cT;
1676
- }
1677
- argv = ALLOCA_N(VALUE, argc + 1);
1678
- argv[0] = self;
1679
- for (i = 0; i < argc; i++) {
1680
- argv[i + 1] = RARRAY_PTR(args)[i];
1681
- }
1682
- a = rb_ary_new4(argc + 1, argv);
1683
- v = na_ndloop2(&ndf, a);
1684
- return uint16_extract(v);
1685
- }
1686
-
1687
1286
  /*
1688
1287
  qsort.c
1689
1288
  Ruby/Numo::NArray - Numerical Array class for Ruby
@@ -2254,11 +1853,27 @@ void Init_numo_uint16(void) {
2254
1853
  rb_define_const(cT, "MIN", M_MIN);
2255
1854
  rb_define_alloc_func(cT, uint16_s_alloc_func);
2256
1855
  rb_define_method(cT, "allocate", uint16_allocate, 0);
1856
+ /**
1857
+ * Extract an element only if self is a dimensionless NArray.
1858
+ * @overload extract
1859
+ * @return [Numeric,Numo::NArray]
1860
+ * --- Extract element value as Ruby Object if self is a dimensionless NArray,
1861
+ * otherwise returns self.
1862
+ */
2257
1863
  rb_define_method(cT, "extract", uint16_extract, 0);
2258
1864
 
2259
1865
  rb_define_method(cT, "store", uint16_store, 1);
2260
1866
 
2261
1867
  rb_define_singleton_method(cT, "cast", uint16_s_cast, 1);
1868
+ /**
1869
+ * Multi-dimensional element reference.
1870
+ * @overload [](dim0,...,dimL)
1871
+ * @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,
1872
+ * Symbol] dim0,...,dimL multi-dimensional indices.
1873
+ * @return [Numeric,Numo::UInt16] an element or NArray view.
1874
+ * @see Numo::NArray#[]
1875
+ * @see #[]=
1876
+ */
2262
1877
  rb_define_method(cT, "[]", uint16_aref, -1);
2263
1878
  rb_define_method(cT, "[]=", uint16_aset, -1);
2264
1879
  /**
@@ -2300,10 +1915,54 @@ void Init_numo_uint16(void) {
2300
1915
  * @return [String]
2301
1916
  */
2302
1917
  rb_define_method(cT, "inspect", uint16_inspect, 0);
1918
+ /**
1919
+ * Calls the given block once for each element in self,
1920
+ * passing that element as a parameter.
1921
+ * @overload each
1922
+ * @return [Numo::NArray] self
1923
+ * For a block `{|x| ... }`,
1924
+ * @yieldparam [Numeric] x an element of NArray.
1925
+ * @see #each_with_index
1926
+ * @see #map
1927
+ */
2303
1928
  rb_define_method(cT, "each", uint16_each, 0);
1929
+ /**
1930
+ * Unary map.
1931
+ * @overload map
1932
+ * @return [Numo::UInt16] map of self.
1933
+ */
2304
1934
  rb_define_method(cT, "map", uint16_map, 0);
1935
+ /**
1936
+ * Invokes the given block once for each element of self,
1937
+ * passing that element and indices along each axis as parameters.
1938
+ * @overload each_with_index
1939
+ * For a block `{|x,i,j,...| ... }`,
1940
+ * @yieldparam [Numeric] x an element
1941
+ * @yieldparam [Integer] i,j,... multitimensional indices
1942
+ * @return [Numo::NArray] self
1943
+ * @see #each
1944
+ * @see #map_with_index
1945
+ */
2305
1946
  rb_define_method(cT, "each_with_index", uint16_each_with_index, 0);
1947
+ /**
1948
+ * Invokes the given block once for each element of self,
1949
+ * passing that element and indices along each axis as parameters.
1950
+ * Creates a new NArray containing the values returned by the block.
1951
+ * Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
1952
+ * @overload map_with_index
1953
+ * For a block `{|x,i,j,...| ... }`,
1954
+ * @yieldparam [Numeric] x an element
1955
+ * @yieldparam [Integer] i,j,... multitimensional indices
1956
+ * @return [Numo::NArray] mapped array
1957
+ * @see #map
1958
+ * @see #each_with_index
1959
+ */
2306
1960
  rb_define_method(cT, "map_with_index", uint16_map_with_index, 0);
1961
+ /**
1962
+ * abs of self.
1963
+ * @overload abs
1964
+ * @return [Numo::UInt16] abs of self.
1965
+ */
2307
1966
  rb_define_method(cT, "abs", uint16_abs, 0);
2308
1967
  /**
2309
1968
  * Binary add.
@@ -2764,6 +2423,13 @@ void Init_numo_uint16(void) {
2764
2423
  * # [4, 3, 3, 2, 4, 2]
2765
2424
  */
2766
2425
  rb_define_method(cT, "rand", uint16_rand, -1);
2426
+ /**
2427
+ * Calculate polynomial.
2428
+ * `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
2429
+ * @overload poly a0, a1, ..., an
2430
+ * @param [Numo::NArray,Numeric] a0,a1,...,an
2431
+ * @return [Numo::UInt16]
2432
+ */
2767
2433
  rb_define_method(cT, "poly", uint16_poly, -2);
2768
2434
 
2769
2435
  rb_define_method(cT, "sort", uint16_sort, -1);