Sum all rows into a single row. Args: M (Tensor): the input 2d tensor. Returns: a new Tensor as the resulted row.
(M)
| 1736 | |
| 1737 | |
| 1738 | def sum_rows(M): |
| 1739 | '''Sum all rows into a single row. |
| 1740 | |
| 1741 | Args: |
| 1742 | M (Tensor): the input 2d tensor. |
| 1743 | |
| 1744 | Returns: |
| 1745 | a new Tensor as the resulted row. |
| 1746 | ''' |
| 1747 | assert M.ndim() == 2, 'M.nDim() is supposed to be 2' |
| 1748 | ret = Tensor((1, M.shape[1]), M.data.device()) |
| 1749 | singa.SumRows(M.data, ret.data) |
| 1750 | return ret |
| 1751 | |
| 1752 | |
| 1753 | ''' private functions, internally used |