| 1521 | } |
| 1522 | } |
| 1523 | void SumRows(const Tensor &M, Tensor *v) { |
| 1524 | if (M.transpose()) { |
| 1525 | Tensor X = Transpose(M); |
| 1526 | SumColumns(X, v); |
| 1527 | } else { |
| 1528 | CHECK_EQ(M.nDim(), 2u); |
| 1529 | // CHECK_EQ(v->nDim(), 1u); (chonho) shape of v is 2-element tuple |
| 1530 | size_t nb_row = M.shape(0), nb_col = M.shape(1); |
| 1531 | CHECK_EQ(nb_col, v->Size()); |
| 1532 | |
| 1533 | Tensor one(Shape{nb_row}, M.device(), M.data_type()); |
| 1534 | one.SetValue(1.0f); // TODO(wangwei) cast type |
| 1535 | Tensor X = Transpose(M); |
| 1536 | Mult(X, one, v); |
| 1537 | } |
| 1538 | } |
| 1539 | // ====================Random operations===================================== |
| 1540 | template <typename SType> |
| 1541 | void Bernoulli(const SType p, Tensor *out) { |