Elementi-wise addition. Args: lhs (Tensor): lhs tensor rhs (Tensor): rhs tensor ret (Tensor, optional): if not None, the result is stored in it; otherwise, a new Tensor would be created for the result. Returns: the result Tensor
(lhs, rhs, ret=None)
| 1230 | |
| 1231 | |
| 1232 | def add(lhs, rhs, ret=None): |
| 1233 | '''Elementi-wise addition. |
| 1234 | |
| 1235 | Args: |
| 1236 | lhs (Tensor): lhs tensor |
| 1237 | rhs (Tensor): rhs tensor |
| 1238 | ret (Tensor, optional): if not None, the result is stored in it; |
| 1239 | otherwise, a new Tensor would be created for the result. |
| 1240 | |
| 1241 | Returns: |
| 1242 | the result Tensor |
| 1243 | ''' |
| 1244 | if ret is None: |
| 1245 | # call Tensor.__add__() |
| 1246 | return lhs + rhs |
| 1247 | else: |
| 1248 | if isinstance(rhs, Tensor): |
| 1249 | singa.Add(lhs.data, rhs.data, ret.data) |
| 1250 | else: |
| 1251 | singa.AddFloatWithRet(lhs.data, rhs, ret.data) |
| 1252 | return ret |
| 1253 | |
| 1254 | |
| 1255 | def sub(lhs, rhs, ret=None): |
no test coverage detected