Skip to content

Commit

Permalink
Docs: Incorrect casting instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Aug 18, 2024
1 parent ff51434 commit a4b139b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ console.log('Squared Euclidean Distance:', distance);
```

Other numeric types and precision levels are supported as well.
For double-precsion floating-point numbers, use `Float64Array`:
For double-precision floating-point numbers, use `Float64Array`:

```js
const vectorA = new Float64Array([1.0, 2.0, 3.0]);
Expand All @@ -457,11 +457,11 @@ const distance = cosine(vectorA, vectorB);
```

When doing machine learning and vector search with high-dimensional vectors you may want to quantize them to 8-bit integers.
You may want to project values from the $[-1, 1]$ range to the $[-100, 100]$ range and then cast them to `Uint8Array`:
You may want to project values from the $[-1, 1]$ range to the $[-127, 127]$ range and then cast them to `Int8Array`:

```js
const quantizedVectorA = new Uint8Array(vectorA.map(v => (v * 100)));
const quantizedVectorB = new Uint8Array(vectorB.map(v => (v * 100)));
const quantizedVectorA = new Int8Array(vectorA.map(v => (v * 127)));
const quantizedVectorB = new Int8Array(vectorB.map(v => (v * 127)));
const distance = cosine(quantizedVectorA, quantizedVectorB);
```

Expand Down
8 changes: 4 additions & 4 deletions javascript/simsimd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ export const jaccard = (a: Uint8Array, b: Uint8Array): number => {
};

/**
* @brief Computes the kullbackleibler similarity coefficient between two vectors.
* @brief Computes the Kullback-Leibler divergence between two vectors.
* @param {Float64Array|Float32Array} a - The first vector.
* @param {Float64Array|Float32Array} b - The second vector.
* @returns {number} The Jaccard similarity coefficient between vectors a and b.
* @returns {number} The Kullback-Leibler divergence between vectors a and b.
*/
export const kullbackleibler = (a: Float64Array | Float32Array, b: Float64Array | Float32Array): number => {
return compiled.kullbackleibler(a, b);
};

/**
* @brief Computes the jensenshannon similarity coefficient between two vectors.
* @brief Computes the Jensen-Shannon divergence between two vectors.
* @param {Float64Array|Float32Array} a - The first vector.
* @param {Float64Array|Float32Array} b - The second vector.
* @returns {number} The Jaccard similarity coefficient between vectors a and b.
* @returns {number} The Jensen-Shannon divergence between vectors a and b.
*/
export const jensenshannon = (a: Float64Array | Float32Array, b: Float64Array | Float32Array): number => {
return compiled.jensenshannon(a, b);
Expand Down

0 comments on commit a4b139b

Please sign in to comment.