Skip to content

Wrong Example #100

Closed
Closed
@lakshya-4gp

Description

@lakshya-4gp

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions