Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions mysql-test/main/vector_small_cosine.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# MDEV-41639 VEC_DISTANCE_COSINE returns 0 for small-magnitude vectors
#
SELECT ROUND(VEC_DISTANCE_COSINE(VEC_FromText('[1e-23,0]'), VEC_FromText('[0,1e-23]')), 6) AS orth;
orth
1.000000
SELECT ROUND(VEC_DISTANCE_COSINE(VEC_FromText('[1e-23,0]'), VEC_FromText('[-1e-23,0]')), 6) AS opp;
opp
2.000000
SELECT ROUND(VEC_DISTANCE_COSINE(VEC_FromText('[1e-30,1e-30]'), VEC_FromText('[1e-30,1e-30]')), 6) AS same;
same
0.000000
6 changes: 6 additions & 0 deletions mysql-test/main/vector_small_cosine.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--echo #
--echo # MDEV-41639 VEC_DISTANCE_COSINE returns 0 for small-magnitude vectors
--echo #
SELECT ROUND(VEC_DISTANCE_COSINE(VEC_FromText('[1e-23,0]'), VEC_FromText('[0,1e-23]')), 6) AS orth;
SELECT ROUND(VEC_DISTANCE_COSINE(VEC_FromText('[1e-23,0]'), VEC_FromText('[-1e-23,0]')), 6) AS opp;
SELECT ROUND(VEC_DISTANCE_COSINE(VEC_FromText('[1e-30,1e-30]'), VEC_FromText('[1e-30,1e-30]')), 6) AS same;
2 changes: 1 addition & 1 deletion sql/item_vectorfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static double calc_distance_cosine(float *v1, float *v2, size_t v_len)
double dotp=0, abs1=0, abs2=0;
for (size_t i= 0; i < v_len; i++, v1++, v2++)
{
float f1= get_float(v1), f2= get_float(v2);
double f1= get_float(v1), f2= get_float(v2);
abs1+= f1 * f1;
abs2+= f2 * f2;
dotp+= f1 * f2;
Expand Down