Closed
Description
def hard_quantize(input: Tensor):
"""Applies binary quantization to all elements of the input tensor.
Args:
input (Tensor): input tensor
Shapes:
- Input: :math:(*)
- 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)
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]
Metadata
Metadata
Assignees
Labels
No labels