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)
| 390 | |
| 391 | |
| 392 | def 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 | |
| 408 | def sparse_batch_op(input: SparseTensor, other: torch.Tensor, op: callable = torch.add) -> SparseTensor: |
no outgoing calls
no test coverage detected