Closed lakshya-4gp closed 1 year ago
def hard_quantize(input: Tensor): """Applies binary quantization to all elements of the input tensor. Args: input (Tensor): input tensor Shapes:
(*)
Output: :math:(*) Examples::
x = functional.random_hv(2, 3) y = functional.bundle(x[0], x[1]) y tensor([ 0., -2., -2.]) functional.hard_quantize(y) tensor([ 1., -1., -1.]) """ Make sure that the output tensor has the same dtype and device as the input tensor. positive = torch.tensor(1.0, dtype=input.dtype, device=input.device) negative = torch.tensor(-1.0, dtype=input.dtype, device=input.device)
x = functional.random_hv(2, 3) y = functional.bundle(x[0], x[1]) y tensor([ 0., -2., -2.]) functional.hard_quantize(y) tensor([ 1., -1., -1.]) """
positive = torch.tensor(1.0, dtype=input.dtype, device=input.device) negative = torch.tensor(-1.0, dtype=input.dtype, device=input.device)
return torch.where(input > 0, positive, negative)
The example given is wrong, since ( input > 0 ) is used the output of functional.hard_quantize(y) will be [-1, -1, -1]
Thank you @lakshya-4gp for reporting this issue. I will look into it in the coming days.
def hard_quantize(input: Tensor): """Applies binary quantization to all elements of the input tensor. Args: input (Tensor): input tensor Shapes:
(*)
Output: :math:
(*)
Examples::return torch.where(input > 0, positive, negative)
The example given is wrong, since ( input > 0 ) is used the output of functional.hard_quantize(y) will be [-1, -1, -1]