MCPcopy Create free account
hub / github.com/microsoft/TRELLIS.2 / sparse_cat

Function sparse_cat

trellis2/modules/sparse/basic.py:797–821  ·  view source on GitHub ↗

Concatenate a list of sparse tensors. Args: inputs (List[SparseTensor]): List of sparse tensors to concatenate.

(inputs: List[SparseTensor], dim: int = 0)

Source from the content-addressed store, hash-verified

795 return f"SparseTensor(shape={self.shape}, dtype={self.dtype}, device={self.device})"
796
797def sparse_cat(inputs: List[SparseTensor], dim: int = 0) -> SparseTensor:
798 """
799 Concatenate a list of sparse tensors.
800
801 Args:
802 inputs (List[SparseTensor]): List of sparse tensors to concatenate.
803 """
804 if dim == 0:
805 start = 0
806 coords = []
807 for input in inputs:
808 coords.append(input.coords.clone())
809 coords[-1][:, 0] += start
810 start += input.shape[0]
811 coords = torch.cat(coords, dim=0)
812 feats = torch.cat([input.feats for input in inputs], dim=0)
813 output = SparseTensor(
814 coords=coords,
815 feats=feats,
816 )
817 else:
818 feats = torch.cat([input.feats for input in inputs], dim=dim)
819 output = inputs[0].replace(feats)
820
821 return output
822
823
824def sparse_unbind(input: SparseTensor, dim: int) -> List[SparseTensor]:

Callers 1

collate_fnMethod · 0.85

Calls 2

SparseTensorClass · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected