Skip to content

Commit

Permalink
Remove negative distance check. (#80)
Browse files Browse the repository at this point in the history
* Remove negative distance check.

* Add E4M3 warning to Javadoc.

* Format.
  • Loading branch information
psobot authored Jul 31, 2024
1 parent e2f232e commit effb901
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 214 deletions.
29 changes: 2 additions & 27 deletions cpp/TypedIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,6 @@ template <> const std::string storageDataTypeName<int8_t>() { return "Float8"; }
template <> const std::string storageDataTypeName<float>() { return "Float32"; }
template <> const std::string storageDataTypeName<E4M3>() { return "E4M3"; }

template <typename dist_t, typename data_t>
dist_t ensureNotNegative(dist_t distance, hnswlib::labeltype label) {
if constexpr (std::is_same_v<data_t, E4M3>) {
// Allow for a very slight negative distance if using E4M3
if (distance < 0 && distance >= -0.14) {
return 0;
}
}

if (distance < 0) {
if (distance >= -0.00001) {
return 0;
}

throw std::runtime_error(
"Potential candidate (with label '" + std::to_string(label) +
"') had negative distance " + std::to_string(distance) +
". This may indicate a corrupted index file.");
}

return distance;
}

/**
* A C++ wrapper class for a typed HNSW index.
*
Expand Down Expand Up @@ -629,8 +606,7 @@ class TypedIndex : public Index {
dist_t distance = result_tuple.first;
hnswlib::labeltype label = result_tuple.second;

distancePointer[row * k + i] =
ensureNotNegative<dist_t, data_t>(distance, label);
distancePointer[row * k + i] = distance;
labelPointer[row * k + i] = label;
result.pop();
}
Expand Down Expand Up @@ -704,8 +680,7 @@ class TypedIndex : public Index {
for (int i = k - 1; i >= 0; i--) {
auto &result_tuple = result.top();

distancePointer[i] = ensureNotNegative<dist_t, data_t>(
result_tuple.first, result_tuple.second);
distancePointer[i] = result_tuple.first;
labelPointer[i] = result_tuple.second;
result.pop();
}
Expand Down
27 changes: 1 addition & 26 deletions docs/python/_static/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Sphinx stylesheet -- basic theme.
*
* :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS.
* :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
Expand Down Expand Up @@ -237,10 +237,6 @@ a.headerlink {
visibility: hidden;
}

a:visited {
color: #551A8B;
}

h1:hover > a.headerlink,
h2:hover > a.headerlink,
h3:hover > a.headerlink,
Expand Down Expand Up @@ -328,15 +324,13 @@ aside.sidebar {
p.sidebar-title {
font-weight: bold;
}

nav.contents,
aside.topic,
div.admonition, div.topic, blockquote {
clear: left;
}

/* -- topics ---------------------------------------------------------------- */

nav.contents,
aside.topic,
div.topic {
Expand Down Expand Up @@ -612,7 +606,6 @@ ol.simple p,
ul.simple p {
margin-bottom: 0;
}

aside.footnote > span,
div.citation > span {
float: left;
Expand Down Expand Up @@ -674,16 +667,6 @@ dd {
margin-left: 30px;
}

.sig dd {
margin-top: 0px;
margin-bottom: 0px;
}

.sig dl {
margin-top: 0px;
margin-bottom: 0px;
}

dl > dd:last-child,
dl > dd:last-child > :last-child {
margin-bottom: 0;
Expand Down Expand Up @@ -752,14 +735,6 @@ abbr, acronym {
cursor: help;
}

.translated {
background-color: rgba(207, 255, 207, 0.2)
}

.untranslated {
background-color: rgba(255, 207, 207, 0.2)
}

/* -- code displays --------------------------------------------------------- */

pre {
Expand Down
4 changes: 2 additions & 2 deletions docs/python/_static/copybutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const messages = {
},
'fr' : {
'copy': 'Copier',
'copy_to_clipboard': 'Copier dans le presse-papier',
'copy_to_clipboard': 'Copié dans le presse-papier',
'copy_success': 'Copié !',
'copy_failure': 'Échec de la copie',
},
Expand Down Expand Up @@ -224,7 +224,7 @@ var copyTargetText = (trigger) => {
var target = document.querySelector(trigger.attributes['data-clipboard-target'].value);

// get filtered text
let exclude = '.linenos';
let exclude = '.linenos, .gp';

let text = filterText(target, exclude);
return formatCopyText(text, '', false, true, true, true, '', '')
Expand Down
2 changes: 1 addition & 1 deletion docs/python/_static/debug.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ body {
.sb-footer__inner {
background: salmon;
}
.sb-article {
[role="main"] {
background: white;
}
2 changes: 1 addition & 1 deletion docs/python/_static/doctools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Base JavaScript utilities for all Sphinx HTML documentation.
*
* :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS.
* :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
Expand Down
3 changes: 2 additions & 1 deletion docs/python/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const DOCUMENTATION_OPTIONS = {
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '2.0.8',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
Expand Down
2 changes: 1 addition & 1 deletion docs/python/_static/language_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This script contains the language-specific data used by searchtools.js,
* namely the list of stopwords, stemmer, scorer and splitter.
*
* :copyright: Copyright 2007-2023 by the Sphinx team, see AUTHORS.
* :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
Expand Down
7 changes: 2 additions & 5 deletions docs/python/_static/pygments.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
.highlight .cs { color: #8f5902; font-style: italic } /* Comment.Special */
.highlight .gd { color: #a40000 } /* Generic.Deleted */
.highlight .ge { color: #000000; font-style: italic } /* Generic.Emph */
.highlight .ges { color: #000000; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #ef2929 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
Expand Down Expand Up @@ -102,13 +101,12 @@ body[data-theme="dark"] .highlight .x { color: #d0d0d0 } /* Other */
body[data-theme="dark"] .highlight .p { color: #d0d0d0 } /* Punctuation */
body[data-theme="dark"] .highlight .ch { color: #ababab; font-style: italic } /* Comment.Hashbang */
body[data-theme="dark"] .highlight .cm { color: #ababab; font-style: italic } /* Comment.Multiline */
body[data-theme="dark"] .highlight .cp { color: #ff3a3a; font-weight: bold } /* Comment.Preproc */
body[data-theme="dark"] .highlight .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
body[data-theme="dark"] .highlight .cpf { color: #ababab; font-style: italic } /* Comment.PreprocFile */
body[data-theme="dark"] .highlight .c1 { color: #ababab; font-style: italic } /* Comment.Single */
body[data-theme="dark"] .highlight .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
body[data-theme="dark"] .highlight .gd { color: #d22323 } /* Generic.Deleted */
body[data-theme="dark"] .highlight .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
body[data-theme="dark"] .highlight .ges { color: #d0d0d0; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
body[data-theme="dark"] .highlight .gr { color: #d22323 } /* Generic.Error */
body[data-theme="dark"] .highlight .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
body[data-theme="dark"] .highlight .gi { color: #589819 } /* Generic.Inserted */
Expand Down Expand Up @@ -188,13 +186,12 @@ body:not([data-theme="light"]) .highlight .x { color: #d0d0d0 } /* Other */
body:not([data-theme="light"]) .highlight .p { color: #d0d0d0 } /* Punctuation */
body:not([data-theme="light"]) .highlight .ch { color: #ababab; font-style: italic } /* Comment.Hashbang */
body:not([data-theme="light"]) .highlight .cm { color: #ababab; font-style: italic } /* Comment.Multiline */
body:not([data-theme="light"]) .highlight .cp { color: #ff3a3a; font-weight: bold } /* Comment.Preproc */
body:not([data-theme="light"]) .highlight .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */
body:not([data-theme="light"]) .highlight .cpf { color: #ababab; font-style: italic } /* Comment.PreprocFile */
body:not([data-theme="light"]) .highlight .c1 { color: #ababab; font-style: italic } /* Comment.Single */
body:not([data-theme="light"]) .highlight .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
body:not([data-theme="light"]) .highlight .gd { color: #d22323 } /* Generic.Deleted */
body:not([data-theme="light"]) .highlight .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */
body:not([data-theme="light"]) .highlight .ges { color: #d0d0d0; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
body:not([data-theme="light"]) .highlight .gr { color: #d22323 } /* Generic.Error */
body:not([data-theme="light"]) .highlight .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */
body:not([data-theme="light"]) .highlight .gi { color: #589819 } /* Generic.Inserted */
Expand Down
2 changes: 1 addition & 1 deletion docs/python/_static/scripts/furo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/python/_static/scripts/furo.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit effb901

Please sign in to comment.