MCPcopy Index your code
hub / github.com/microsoft/TRELLIS / __elemwise__

Method __elemwise__

trellis/modules/sparse/basic.py:305–318  ·  view source on GitHub ↗
(self, other: Union[torch.Tensor, 'SparseTensor'], op: callable)

Source from the content-addressed store, hash-verified

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)

Callers 8

__add__Method · 0.95
__radd__Method · 0.95
__sub__Method · 0.95
__rsub__Method · 0.95
__mul__Method · 0.95
__rmul__Method · 0.95
__truediv__Method · 0.95
__rtruediv__Method · 0.95

Calls 3

replaceMethod · 0.95
__merge_sparse_cacheMethod · 0.95
sparse_batch_broadcastFunction · 0.85

Tested by

no test coverage detected