MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / collate_tensors

Function collate_tensors

datasets/dataloader.py:170–180  ·  view source on GitHub ↗
(batch: list)

Source from the content-addressed store, hash-verified

168
169
170def collate_tensors(batch: list) -> torch.Tensor:
171 dims = batch[0].dim()
172 max_size = [max([b.size(i) for b in batch]) for i in range(dims)]
173 size = (len(batch), ) + tuple(max_size)
174 canvas = batch[0].new_zeros(size=size)
175 for i, b in enumerate(batch):
176 sub_tensor = canvas[i]
177 for d in range(dims):
178 sub_tensor = sub_tensor.narrow(d, 0, b.size(d))
179 sub_tensor.add_(b)
180 return canvas
181
182
183def lengths_to_mask(lengths: list[int],

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected