From 7f710d2394bc24d45c18fc07ed4f466199063c4a Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 15 Apr 2025 09:38:05 +0200 Subject: [PATCH] add a comment about the precomputed denominator --- src/nominatim_api/search/query.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nominatim_api/search/query.py b/src/nominatim_api/search/query.py index 4d8022b6..092bd586 100644 --- a/src/nominatim_api/search/query.py +++ b/src/nominatim_api/search/query.py @@ -12,7 +12,14 @@ from abc import ABC, abstractmethod from collections import defaultdict import dataclasses - +# Precomputed denominator for the computation of the linear regression slope +# used to determine the query direction. +# The x value for the regression computation will be the position of the +# token in the query. Thus we know the x values will be [0, query length). +# As the denominator only depends on the x values, we can pre-compute here +# the denominatior to use for a given query length. +# Note that query length of two or less is special cased and will not use +# the values from this array. Thus it is not a problem that they are 0. LINFAC = [i * (sum(si * si for si in range(i)) - (i - 1) * i * (i - 1) / 4) for i in range(50)] -- 2.39.5