(self, input: SparseTensor)
| 66 | self.factor = tuple(factor) if isinstance(factor, (list, tuple)) else factor |
| 67 | |
| 68 | def forward(self, input: SparseTensor) -> SparseTensor: |
| 69 | DIM = input.coords.shape[-1] - 1 |
| 70 | factor = self.factor if isinstance(self.factor, tuple) else (self.factor,) * DIM |
| 71 | assert DIM == len(factor), 'Input coordinates must have the same dimension as the upsample factor.' |
| 72 | |
| 73 | new_coords = input.get_spatial_cache(f'upsample_{factor}_coords') |
| 74 | new_layout = input.get_spatial_cache(f'upsample_{factor}_layout') |
| 75 | idx = input.get_spatial_cache(f'upsample_{factor}_idx') |
| 76 | if any([x is None for x in [new_coords, new_layout, idx]]): |
| 77 | raise ValueError('Upsample cache not found. SparseUpsample must be paired with SparseDownsample.') |
| 78 | new_feats = input.feats[idx] |
| 79 | out = SparseTensor(new_feats, new_coords, input.shape, new_layout) |
| 80 | out._scale = tuple([s * f for s, f in zip(input._scale, factor)]) |
| 81 | out._spatial_cache = input._spatial_cache |
| 82 | return out |
| 83 | |
| 84 | class SparseSubdivide(nn.Module): |
| 85 | """ |
nothing calls this directly
no test coverage detected