(self, other: Union[torch.Tensor, 'SparseTensor'], op: callable)
| 303 | return self.replace(-self.feats) |
| 304 | |
| 305 | def __elemwise__(self, other: Union[torch.Tensor, 'SparseTensor'], op: callable) -> 'SparseTensor': |
| 306 | if isinstance(other, torch.Tensor): |
| 307 | try: |
| 308 | other = torch.broadcast_to(other, self.shape) |
| 309 | other = sparse_batch_broadcast(self, other) |
| 310 | except: |
| 311 | pass |
| 312 | if isinstance(other, SparseTensor): |
| 313 | other = other.feats |
| 314 | new_feats = op(self.feats, other) |
| 315 | new_tensor = self.replace(new_feats) |
| 316 | if isinstance(other, SparseTensor): |
| 317 | new_tensor._spatial_cache = self.__merge_sparse_cache(other) |
| 318 | return new_tensor |
| 319 | |
| 320 | def __add__(self, other: Union[torch.Tensor, 'SparseTensor', float]) -> 'SparseTensor': |
| 321 | return self.__elemwise__(other, torch.add) |
no test coverage detected