-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b544ddb
commit a45fc40
Showing
7 changed files
with
172 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set(USEARCH_PUNNED_INCLUDE_DIRS | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../include" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../fp16/include" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../robin-map/include" | ||
) | ||
|
||
add_executable(usearch lib.cpp) | ||
target_include_directories(usearch PRIVATE ${USEARCH_PUNNED_INCLUDE_DIRS}) | ||
set_target_properties(usearch PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/c) | ||
set_target_properties(usearch PROPERTIES CXX_STANDARD 11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
var assert = require('assert'); | ||
var usearch = require('bindings')('usearch'); | ||
|
||
var index = new usearch.Index({ metric: 'l2sq', connectivity: 16n, dimensions: 2n }) | ||
assert.equal(index.connectivity(), 16) | ||
assert.equal(index.dimensions(), 2) | ||
assert.equal(index.size(), 0) | ||
// Single-entry operations | ||
|
||
index.add(15n, new Float32Array([10, 20])) | ||
index.add(16n, new Float32Array([10, 25])) | ||
assert.equal(index.size(), 2) | ||
var index = new usearch.Index({ metric: 'l2sq', connectivity: 16n, dimensions: 2n }); | ||
assert.equal(index.connectivity(), 16n, 'connectivity should be 16'); | ||
assert.equal(index.dimensions(), 2n, 'dimensions should be 2'); | ||
assert.equal(index.size(), 0n, 'initial size should be 0'); | ||
|
||
var results = index.search(new Float32Array([13, 14]), 2n) | ||
assert.deepEqual(results.keys, new BigUint64Array([15n, 16n])) | ||
assert.deepEqual(results.distances, new Float32Array([45, 130])) | ||
index.add(15n, new Float32Array([10, 20])); | ||
index.add(16n, new Float32Array([10, 25])); | ||
assert.equal(index.size(), 2n, 'size after adding elements should be 2'); | ||
|
||
// Batch | ||
var results = index.search(new Float32Array([13, 14]), 2n); | ||
assert.deepEqual(results.keys, new BigUint64Array([15n, 16n]), 'keys should be 15 and 16'); | ||
assert.deepEqual(results.distances, new Float32Array([45, 130]), 'distances should be 45 and 130'); | ||
|
||
var index2 = new usearch.Index({ metric: 'l2sq', connectivity: 16n, dimensions: 2n }) | ||
// Batch operations | ||
|
||
const keys = [15n, 16n] | ||
const vectors = [new Float32Array([10, 20]), new Float32Array([10, 25])] | ||
index2.add(keys, vectors) | ||
assert.equal(index.size(), 2) | ||
var indexBatch = new usearch.Index({ metric: 'l2sq', connectivity: 16n, dimensions: 2n }); | ||
const keys = [15n, 16n]; | ||
const vectors = [new Float32Array([10, 20]), new Float32Array([10, 25])]; | ||
indexBatch.add(keys, vectors); | ||
assert.equal(indexBatch.size(), 2, 'size after adding batch should be 2'); | ||
|
||
var results = index.search(new Float32Array([13, 14]), 2n) | ||
assert.deepEqual(results.keys, new BigUint64Array([15n, 16n])) | ||
assert.deepEqual(results.distances, new Float32Array([45, 130])) | ||
results = indexBatch.search(new Float32Array([13, 14]), 2n); | ||
assert.deepEqual(results.keys, new BigUint64Array([15n, 16n]), 'keys should be 15 and 16'); | ||
assert.deepEqual(results.distances, new Float32Array([45, 130]), 'distances should be 45 and 130'); | ||
|
||
console.log('JavaScript tests passed!') | ||
console.log('JavaScript tests passed!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters