Skip to content

Commit

Permalink
Improve: JS JavaScript test
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Nov 17, 2024
1 parent 6850c9a commit 1bba6d0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions javascript/fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ export const jensenshannon = (a: Float64Array | Float32Array, b: Float64Array |
}

const m = a.map((value, index) => (value + b[index]) / 2);

const divergence = 0.5 * kullbackleibler(a, m) + 0.5 * kullbackleibler(b, m);
const divergence = (kullbackleibler(a, m) + kullbackleibler(b, m)) / 2;
return Math.sqrt(divergence);
};

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@types/bindings": "^1.5.5",
"@types/node": "^20.17.1",
"@types/node": "^20.17.6",
"node-gyp": "^10.0.1",
"prebuildify": "^6.0.0",
"typescript": "^5.3.3"
Expand Down
4 changes: 2 additions & 2 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ test("Kullback-Leibler C vs JS", () => {
});

test("Jensen-Shannon C vs JS", () => {
const f32sDistribution = new Float32Array([1.0, 0.0]);
const f32sDistribution2 = new Float32Array([0.5, 0.5]);
const f32sDistribution = new Float32Array([0.5, 0.0, 0.2, 0.3]);
const f32sDistribution2 = new Float32Array([0.5, 0.3, 0.0, 0.2]);
const result = simsimd.jensenshannon(f32sDistribution, f32sDistribution2);
const resultjs = fallback.jensenshannon(f32sDistribution, f32sDistribution2);
assertAlmostEqual(result, resultjs, 0.01);
Expand Down

0 comments on commit 1bba6d0

Please sign in to comment.