Skip to content

Commit a5bb475

Browse files
authored
Merge pull request #297 from nairihar/dev-js-nan
Improve: Add NaN related checks for the JavaScript layer
2 parents 28b3a6c + 985e595 commit a5bb475

File tree

12 files changed

+36
-14
lines changed

12 files changed

+36
-14
lines changed

CITATION.cff

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors:
55
given-names: "Ash"
66
orcid: "https://orcid.org/0000-0002-4882-1815"
77
title: "USearch by Unum Cloud"
8-
version: 2.8.1
8+
version: 2.8.2
99
doi: 10.5281/zenodo.7949416
1010
date-released: 2023-10-22
1111
url: "https://github.com/unum-cloud/usearch"

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "usearch"
3-
version = "2.8.1"
3+
version = "2.8.2"
44
authors = ["Ash Vardanian <[email protected]>"]
55
description = "Smaller & Faster Single-File Vector Search Engine from Unum"
66
edition = "2021"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ doi = {10.5281/zenodo.7949416},
392392
author = {Vardanian, Ash},
393393
title = {{USearch by Unum Cloud}},
394394
url = {https://github.com/unum-cloud/usearch},
395-
version = {2.8.1},
395+
version = {2.8.2},
396396
year = {2023},
397397
month = oct,
398398
}

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.8.1
1+
2.8.2

conanfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class USearchConan(ConanFile):
88

99
name = "usearch"
10-
version = '2.8.1'
10+
version = '2.8.2'
1111
license = "Apache-2.0"
1212
description = "Smaller & Faster Single-File Vector Search Engine from Unum"
1313
homepage = "https://github.com/unum-cloud/usearch"

csharp/nuget/nuget-package.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<PropertyGroup>
4-
<Version Condition="'$(Version)' == ''">2.8.1</Version>
4+
<Version Condition="'$(Version)' == ''">2.8.2</Version>
55

66
<Authors>Unum</Authors>
77
<Company>Unum</Company>

include/usearch/index.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define USEARCH_VERSION_MAJOR 2
1313
#define USEARCH_VERSION_MINOR 8
14-
#define USEARCH_VERSION_PATCH 1
14+
#define USEARCH_VERSION_PATCH 2
1515

1616
// Inferring C++ version
1717
// https://stackoverflow.com/a/61552074

javascript/usearch.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ class BatchMatches {
8484
}
8585

8686
function isOneKey(keys) {
87-
return typeof keys === 'number' || typeof keys === 'bigint';
87+
return (!Number.isNaN(keys) && typeof keys === 'number') || typeof keys === 'bigint';
8888
}
8989

9090
function normalizeKeys(keys) {
9191
if (isOneKey(keys)) {
9292
keys = BigUint64Array.of(BigInt(keys));
9393
} else if (Array.isArray(keys)) {
9494
keys = keys.map(key => {
95-
if (typeof key !== 'bigint' && typeof key !== 'number')
95+
if ((typeof key !== 'bigint' && typeof key !== 'number') || Number.isNaN(key))
9696
throw new Error("All keys must be integers or bigints.");
9797
return BigInt(key);
9898
});
@@ -151,7 +151,7 @@ class Index {
151151
if (typeof dimensionsOrConfigs === 'object' && dimensionsOrConfigs !== null) {
152152
// Parameters are provided as an object
153153
({ dimensions, metric = MetricKind.Cos, quantization = ScalarKind.F32, connectivity = 0, expansion_add = 0, expansion_search = 0, multi = false } = dimensionsOrConfigs);
154-
} else if (typeof dimensionsOrConfigs === 'number' || typeof dimensionsOrConfigs === 'bigint') {
154+
} else if ((typeof dimensionsOrConfigs === 'number' && !Number.isNaN(dimensionsOrConfigs)) || typeof dimensionsOrConfigs === 'bigint') {
155155
// Parameters are provided as individual arguments
156156
dimensions = dimensionsOrConfigs;
157157
} else {
@@ -238,7 +238,7 @@ class Index {
238238
* @throws Will throw an error if `vectors` is not a valid input type (TypedArray or an array of arrays) or if its flattened size is not a multiple of dimensions.
239239
*/
240240
search(vectors, k) {
241-
if (typeof k !== 'number' || k <= 0) {
241+
if ((!Number.isNaN(k) && typeof k !== 'number') || k <= 0) {
242242
throw new Error("`k` must be a positive integer representing the number of nearest neighbors to search for.");
243243
}
244244

javascript/usearch.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,25 @@ test('Batch operations', () => {
3535
assert.deepEqual(results.keys, new BigUint64Array([15n, 16n]), 'keys should be 15 and 16');
3636
assert.deepEqual(results.distances, new Float32Array([45, 130]), 'distances should be 45 and 130');
3737
});
38+
39+
40+
test('Operations with invalid values', () => {
41+
const indexBatch = new usearch.Index(2, 'l2sq');
42+
43+
const keys = [NaN, 16n];
44+
const vectors = [new Float32Array([10, 30]), new Float32Array([1, 5])];
45+
46+
try {
47+
indexBatch.add(keys, vectors);
48+
throw new Error('indexBatch.add should have thrown an error.');
49+
} catch (err) {
50+
assert.equal(err.message, 'All keys must be integers or bigints.');
51+
}
52+
53+
try {
54+
indexBatch.search(NaN, 2);
55+
throw new Error('indexBatch.search should have thrown an error.');
56+
} catch (err) {
57+
assert.equal(err.message, 'Vectors must be a TypedArray or an array of arrays.');
58+
}
59+
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "usearch",
3-
"version": "2.8.1",
3+
"version": "2.8.2",
44
"description": "Smaller & Faster Single-File Vector Search Engine from Unum",
55
"author": "Ash Vardanian (https://ashvardanian.com/)",
66
"license": "Apache 2.0",

wasmer.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name="unum/usearch"
3-
version="2.8.1"
3+
version="2.8.2"
44
description="Smaller & Faster Single-File Vector Search Engine from Unum"
55
license="Apache-2.0"
66
readme="README.md"

0 commit comments

Comments
 (0)