value_to_index

torchhd.value_to_index(input: Tensor, in_min: float, in_max: float, index_length: int) LongTensor[source]

Maps the input real value range to an index range.

Note

Input values outside the min-max range are not clamped.

Parameters:
  • input (torch.LongTensor) – The values to map

  • in_min (float) – the minimum value of the input range

  • in_max (float) – the maximum value of the input range

  • index_length (int) – The length of the output index, i.e., one more than the maximum output

Shapes:
  • Input: \((*)\)

  • Output: \((*)\)

Examples:

>>> x = torch.rand(2, 3)
>>> x
tensor([[0.2211, 0.1291, 0.3081],
        [0.7654, 0.2155, 0.4381]])
>>> functional.value_to_index(x, 0, 1, 10)
tensor([[2, 1, 3],
        [7, 2, 4]])