From ce1d5f3cf790bee2c24669cfab9a97573c45e4b8 Mon Sep 17 00:00:00 2001 From: crosstyan Date: Tue, 29 Apr 2025 13:05:52 +0800 Subject: [PATCH] refactor: Improve timestamp handling in camera affinity matrix calculation - Replaced direct access to tracking and detection timestamps with a more efficient use of `itertools.chain` to gather timestamps, enhancing readability and performance in `calculate_camera_affinity_matrix_jax`. - Maintained precision in timestamp calculations to ensure accurate results in affinity computations. --- playground.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/playground.py b/playground.py index 9ff3b69..10431c2 100644 --- a/playground.py +++ b/playground.py @@ -20,6 +20,7 @@ from copy import deepcopy as deep_copy from dataclasses import dataclass from datetime import datetime, timedelta from functools import partial, reduce +from itertools import chain from pathlib import Path from typing import ( Any, @@ -1055,10 +1056,11 @@ def calculate_camera_affinity_matrix_jax( # sub‑second detail (resolution ≈ 200 ms). Keep them in float64 until # after subtraction so we preserve Δt‑on‑the‑order‑of‑milliseconds. # --- timestamps ---------- - tracking0 = next(iter(trackings)) - detection0 = next(iter(camera_detections)) t0 = min( - tracking0.last_active_timestamp, detection0.timestamp + chain( + (trk.last_active_timestamp for trk in trackings), + (det.timestamp for det in camera_detections), + ) ).timestamp() # common origin (float) ts_trk = jnp.array( [trk.last_active_timestamp.timestamp() - t0 for trk in trackings],