fix(perception): preserve quaternion alignment across binary ingress

This commit is contained in:
DCCONSTRUCTIONS
2026-09-02 14:20:38 +03:00
parent f6d73d8bfb
commit 380b6eaba7
3 changed files with 182 additions and 2 deletions
+11 -2
View File
@@ -170,9 +170,18 @@ def normalized_sensor(modality: str, sequence: int, time_ns: int, raw: bytes) ->
if modality != "pose" or len(raw) != 56:
raise ValueError("normalized pose layout outside bound")
values = np.frombuffer(raw, "<f8")
if not np.isfinite(values).all() or abs(float(np.linalg.norm(values[3:])) - 1) > 0.01:
# The quaternion begins at byte 24 of the wire body. On the qualified x86
# NumPy runtime, its 8-mod-16 address selects a different dot/norm reduction
# and changes two downstream ranges by one ULP. Own a tiny aligned copy,
# matching the archive reader's numeric layout without changing any values
# or the projection/norm algorithm. Covered by the cache scratch allowance.
quaternion = np.array(values[3:], copy=True)
if quaternion.ctypes.data % 16:
raise ValueError("unqualified quaternion numeric buffer alignment")
quaternion.setflags(write=False)
if not np.isfinite(values).all() or abs(float(np.linalg.norm(quaternion)) - 1) > 0.01:
raise ValueError("invalid source pose")
return SensorEvent(time_ns, "pose", sequence, (values[:3], values[3:]))
return SensorEvent(time_ns, "pose", sequence, (values[:3], quaternion))
class CausalSensorWindow: