MCPcopy
hub / github.com/Pointcept/PointTransformerV3 / binary2gray

Function binary2gray

serialization/hilbert.py:46–66  ·  view source on GitHub ↗

Convert an array of binary values into Gray codes. This uses the classic X ^ (X >> 1) trick to compute the Gray code. Parameters: ----------- binary: An ndarray of binary values. axis: The axis along which to compute the gray code. Default=-1. Returns: --

(binary, axis=-1)

Source from the content-addressed store, hash-verified

44
45
46def binary2gray(binary, axis=-1):
47 """Convert an array of binary values into Gray codes.
48
49 This uses the classic X ^ (X >> 1) trick to compute the Gray code.
50
51 Parameters:
52 -----------
53 binary: An ndarray of binary values.
54
55 axis: The axis along which to compute the gray code. Default=-1.
56
57 Returns:
58 --------
59 Returns an ndarray of Gray codes.
60 """
61 shifted = right_shift(binary, axis=axis)
62
63 # Do the X ^ (X >> 1) trick.
64 gray = torch.logical_xor(binary, shifted)
65
66 return gray
67
68
69def gray2binary(gray, axis=-1):

Callers 1

decodeFunction · 0.85

Calls 1

right_shiftFunction · 0.85

Tested by

no test coverage detected