Encode a value using the FixedPoint Encoder. Args: value (Union[torch.Tensor, float, int]): value to encode Returns: torch.LongTensor: encoded value
(self, value: Union[torch.Tensor, float, int])
| 45 | self._scale = base ** precision |
| 46 | |
| 47 | def encode(self, value: Union[torch.Tensor, float, int]) -> torch.LongTensor: |
| 48 | """Encode a value using the FixedPoint Encoder. |
| 49 | |
| 50 | Args: |
| 51 | value (Union[torch.Tensor, float, int]): value to encode |
| 52 | |
| 53 | Returns: |
| 54 | torch.LongTensor: encoded value |
| 55 | """ |
| 56 | if not isinstance(value, torch.Tensor): |
| 57 | value = torch.tensor(data=[value]) |
| 58 | |
| 59 | # Use the largest type |
| 60 | long_value = (value * self._scale).long() |
| 61 | |
| 62 | return long_value |
| 63 | |
| 64 | def decode(self, value: Union[int, torch.Tensor]) -> torch.Tensor: |
| 65 | """Decode a value using the FixedPoint Encoder. |
no outgoing calls