Sum all columns into a single column. Args: M (Tensor): the input 2d tensor. Returns: a new Tensor as the resulted column.
(M)
| 1721 | |
| 1722 | |
| 1723 | def sum_columns(M): |
| 1724 | '''Sum all columns into a single column. |
| 1725 | |
| 1726 | Args: |
| 1727 | M (Tensor): the input 2d tensor. |
| 1728 | |
| 1729 | Returns: |
| 1730 | a new Tensor as the resulted column. |
| 1731 | ''' |
| 1732 | assert M.ndim() == 2, 'M.nDim() is supposed to be 2' |
| 1733 | ret = Tensor((M.shape[0], 1), M.data.device()) |
| 1734 | singa.SumColumns(M.data, ret.data) |
| 1735 | return ret |
| 1736 | |
| 1737 | |
| 1738 | def sum_rows(M): |