MCPcopy Create free account
hub / github.com/OpenMined/SyMPC / encode

Method encode

src/sympc/encoder/fp_encoder.py:47–62  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

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.

Callers 9

test_fixed_pointFunction · 0.95
test_private_compareFunction · 0.95
test_fp_encodingFunction · 0.95
_encodeMethod · 0.80
_encodeMethod · 0.80
test_share_printFunction · 0.80
test_share_reprFunction · 0.80
test_truedivFunction · 0.80
test_rshiftFunction · 0.80

Calls

no outgoing calls

Tested by 7

test_fixed_pointFunction · 0.76
test_private_compareFunction · 0.76
test_fp_encodingFunction · 0.76
test_share_printFunction · 0.64
test_share_reprFunction · 0.64
test_truedivFunction · 0.64
test_rshiftFunction · 0.64