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

Function sparse_batch_broadcast

trellis/modules/sparse/basic.py:392–405  ·  view source on GitHub ↗

Broadcast a 1D tensor to a sparse tensor along the batch dimension then perform an operation. Args: input (torch.Tensor): 1D tensor to broadcast. target (SparseTensor): Sparse tensor to broadcast to. op (callable): Operation to perform after broadcasting. Defaul

(input: SparseTensor, other: torch.Tensor)

Source from the content-addressed store, hash-verified

390
391
392def sparse_batch_broadcast(input: SparseTensor, other: torch.Tensor) -> torch.Tensor:
393 """
394 Broadcast a 1D tensor to a sparse tensor along the batch dimension then perform an operation.
395
396 Args:
397 input (torch.Tensor): 1D tensor to broadcast.
398 target (SparseTensor): Sparse tensor to broadcast to.
399 op (callable): Operation to perform after broadcasting. Defaults to torch.add.
400 """
401 coords, feats = input.coords, input.feats
402 broadcasted = torch.zeros_like(feats)
403 for k in range(input.shape[0]):
404 broadcasted[input.layout[k]] = other[k]
405 return broadcasted
406
407
408def sparse_batch_op(input: SparseTensor, other: torch.Tensor, op: callable = torch.add) -> SparseTensor:

Callers 2

__elemwise__Method · 0.85
sparse_batch_opFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected