From fece382c15b43f732ae56e729b9fd92a87367339 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Fri, 4 Sep 2026 00:26:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=5Fbhattacharyya=5Fcoefficient=20?= =?UTF-8?q?=E7=94=A8=20x**0.5=20=E6=9B=BF=E4=BB=A3=20np.sqrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 回应 AI Code Review:虽然 numpy 已在模块顶部导入(第21行), 但该方法是纯标量计算,改用 Python 原生 ** 0.5 更清晰且无额外依赖。 直方图值均为非负,与 math.sqrt 数学等价。 --- apps/worker/video_processing/dedup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/worker/video_processing/dedup.py b/apps/worker/video_processing/dedup.py index d5f389095..469a9cc30 100755 --- a/apps/worker/video_processing/dedup.py +++ b/apps/worker/video_processing/dedup.py @@ -277,6 +277,9 @@ class VideoDeduplicator: def _bhattacharyya_coefficient(hist_a: list[float], hist_b: list[float]) -> float: """Bhattacharyya 系数:Σ √(a[i] * b[i]),范围 [0, 1],1=完全相同。 + 直方图值均为非负浮点数,用 ``x ** 0.5`` 替代 ``np.sqrt``, + 避免在此纯标量计算中引入对 numpy 的额外依赖。 + Args: hist_a: 第一组直方图数据 hist_b: 第二组直方图数据 @@ -287,7 +290,7 @@ class VideoDeduplicator: min_len = min(len(hist_a), len(hist_b)) a = hist_a[:min_len] b = hist_b[:min_len] - return float(sum(np.sqrt(ai * bi) for ai, bi in zip(a, b))) + return float(sum((ai * bi) ** 0.5 for ai, bi in zip(a, b))) @staticmethod def _compute_histogram_similarity(