From 332e07f6b53c03e133c2e057e772e621ef5adffc Mon Sep 17 00:00:00 2001 From: yishiouchen Date: Fri, 5 Sep 2025 15:11:54 -0700 Subject: [PATCH] Update nearest_neighbours.py for weights=distance The Mul operator created in line 141 converts distances (node[0]) from OnnxTopK_11 to negative values. The Mul operator is followed by a Max operator, which turns any negative value to 1e-6, so distances lose their effect in the downstream operation. I think this Mul operator should be removed, and node[0] can be connected to the Max operator directly. Signed-off-by: yishiouchen --- skl2onnx/operator_converters/nearest_neighbours.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skl2onnx/operator_converters/nearest_neighbours.py b/skl2onnx/operator_converters/nearest_neighbours.py index f5f69b094..74378c840 100644 --- a/skl2onnx/operator_converters/nearest_neighbours.py +++ b/skl2onnx/operator_converters/nearest_neighbours.py @@ -138,7 +138,7 @@ def onnx_nearest_neighbors_indices_k( if keep_distances: return ( node[1], - OnnxMul(node[0], np.array([-1], dtype=dtype), op_version=op_version), + node[0] ) if keep_distances: return (node[1], node[0])