From bcc1366d8626cb84c511ee5107a8ab68386909f2 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 25 Jul 2023 16:49:21 -0700 Subject: [PATCH] Added tests for large distances --- test/expected/functions.out | 24 ++++++++++++++++++++++++ test/sql/functions.sql | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/test/expected/functions.out b/test/expected/functions.out index 0cb7b3e..6e83da0 100644 --- a/test/expected/functions.out +++ b/test/expected/functions.out @@ -62,6 +62,12 @@ SELECT l2_distance('[0,0]', '[0,1]'); SELECT l2_distance('[1,2]', '[3]'); ERROR: different vector dimensions 2 and 1 +SELECT l2_distance('[3e38]', '[-3e38]'); + l2_distance +------------- + Infinity +(1 row) + SELECT inner_product('[1,2]', '[3,4]'); inner_product --------------- @@ -70,6 +76,12 @@ SELECT inner_product('[1,2]', '[3,4]'); SELECT inner_product('[1,2]', '[3]'); ERROR: different vector dimensions 2 and 1 +SELECT inner_product('[3e38]', '[3e38]'); + inner_product +--------------- + Infinity +(1 row) + SELECT cosine_distance('[1,2]', '[2,4]'); cosine_distance ----------------- @@ -108,6 +120,12 @@ SELECT cosine_distance('[1,1]', '[-1.1,-1.1]'); 2 (1 row) +SELECT cosine_distance('[3e38]', '[3e38]'); + cosine_distance +----------------- + NaN +(1 row) + SELECT l1_distance('[0,0]', '[3,4]'); l1_distance ------------- @@ -122,6 +140,12 @@ SELECT l1_distance('[0,0]', '[0,1]'); SELECT l1_distance('[1,2]', '[3]'); ERROR: different vector dimensions 2 and 1 +SELECT l1_distance('[3e38]', '[-3e38]'); + l1_distance +------------- + Infinity +(1 row) + SELECT avg(v) FROM unnest(ARRAY['[1,2,3]'::vector, '[3,5,7]']) v; avg ----------- diff --git a/test/sql/functions.sql b/test/sql/functions.sql index cd64a51..c71291a 100644 --- a/test/sql/functions.sql +++ b/test/sql/functions.sql @@ -15,9 +15,11 @@ SELECT vector_norm('[0,1]'); SELECT l2_distance('[0,0]', '[3,4]'); SELECT l2_distance('[0,0]', '[0,1]'); SELECT l2_distance('[1,2]', '[3]'); +SELECT l2_distance('[3e38]', '[-3e38]'); SELECT inner_product('[1,2]', '[3,4]'); SELECT inner_product('[1,2]', '[3]'); +SELECT inner_product('[3e38]', '[3e38]'); SELECT cosine_distance('[1,2]', '[2,4]'); SELECT cosine_distance('[1,2]', '[0,0]'); @@ -26,10 +28,12 @@ SELECT cosine_distance('[1,1]', '[-1,-1]'); SELECT cosine_distance('[1,2]', '[3]'); SELECT cosine_distance('[1,1]', '[1.1,1.1]'); SELECT cosine_distance('[1,1]', '[-1.1,-1.1]'); +SELECT cosine_distance('[3e38]', '[3e38]'); SELECT l1_distance('[0,0]', '[3,4]'); SELECT l1_distance('[0,0]', '[0,1]'); SELECT l1_distance('[1,2]', '[3]'); +SELECT l1_distance('[3e38]', '[-3e38]'); SELECT avg(v) FROM unnest(ARRAY['[1,2,3]'::vector, '[3,5,7]']) v; SELECT avg(v) FROM unnest(ARRAY['[1,2,3]'::vector, '[3,5,7]', NULL]) v;