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

Method to_dense

trellis2/modules/sparse/basic.py:180–196  ·  view source on GitHub ↗

Convert a VarLenTensor to a dense representation without for-loop. Returns: dense (torch.Tensor): (N, L, C) dense tensor mask (torch.BoolTensor): (N, L) mask indicating valid positions

(self, max_length=None)

Source from the content-addressed store, hash-verified

178 return new_tensor
179
180 def to_dense(self, max_length=None) -> torch.Tensor:
181 """
182 Convert a VarLenTensor to a dense representation without for-loop.
183
184 Returns:
185 dense (torch.Tensor): (N, L, C) dense tensor
186 mask (torch.BoolTensor): (N, L) mask indicating valid positions
187 """
188 N = len(self)
189 L = max_length or self.seqlen.max().item()
190 spatial = self.feats.shape[1:]
191 idx = torch.arange(L, device=self.device).unsqueeze(0).expand(N, L)
192 mask = (idx < self.seqlen.unsqueeze(1))
193 mapping = mask.reshape(-1).cumsum(dim=0) - 1
194 dense = self.feats[mapping]
195 dense = dense.reshape(N, L, *spatial)
196 return dense, mask
197
198 def __neg__(self) -> 'VarLenTensor':
199 return self.replace(-self.feats)

Callers

nothing calls this directly

Calls 1

reshapeMethod · 0.45

Tested by

no test coverage detected