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

Function gray2binary

serialization/hilbert.py:69–88  ·  view source on GitHub ↗

Convert an array of Gray codes back into binary values. Parameters: ----------- gray: An ndarray of gray codes. axis: The axis along which to perform Gray decoding. Default=-1. Returns: -------- Returns an ndarray of binary values.

(gray, axis=-1)

Source from the content-addressed store, hash-verified

67
68
69def gray2binary(gray, axis=-1):
70 """Convert an array of Gray codes back into binary values.
71
72 Parameters:
73 -----------
74 gray: An ndarray of gray codes.
75
76 axis: The axis along which to perform Gray decoding. Default=-1.
77
78 Returns:
79 --------
80 Returns an ndarray of binary values.
81 """
82
83 # Loop the log2(bits) number of times necessary, with shift and xor.
84 shift = 2 ** (torch.Tensor([gray.shape[axis]]).log2().ceil().int() - 1)
85 while shift > 0:
86 gray = torch.logical_xor(gray, right_shift(gray, shift))
87 shift = torch.div(shift, 2, rounding_mode="floor")
88 return gray
89
90
91def encode(locs, num_dims, num_bits):

Callers 1

encodeFunction · 0.85

Calls 1

right_shiftFunction · 0.85

Tested by

no test coverage detected