(self, x: torch.Tensor)
| 68 | self.centroids, self.boundaries = solve_lloyd_max(d, bits) |
| 69 | |
| 70 | def quantize(self, x: torch.Tensor) -> torch.Tensor: |
| 71 | diffs = x.unsqueeze(-1) - self.centroids.to(x.device) |
| 72 | return diffs.abs().argmin(dim=-1) |
| 73 | |
| 74 | def dequantize(self, indices: torch.Tensor) -> torch.Tensor: |
| 75 | return self.centroids.to(indices.device)[indices.long()] |
no outgoing calls