Solution 0xa95f32ea03bfe95df656140edb88432fac22efa32917418f73d0f29ce155ecd0
All checks were successful
elffuss/validation Validation passed
All checks were successful
elffuss/validation Validation passed
T2T-Item: 0xa95f32ea03bfe95df656140edb88432fac22efa32917418f73d0f29ce155ecd0 T2T-Issue: 0xc0ae452fd36bac337ec3f451e6383702e4d49a1fb1113ea26024dff8f4d296c1
This commit is contained in:
@@ -25,7 +25,7 @@ export async function loadDiarizer(TF, { device = 'wasm' } = {}) {
|
||||
return { seg, segP, emb, embP };
|
||||
}
|
||||
|
||||
const cos = (a, b) => { let dt = 0, na = 0, nb = 0; for (let i = 0; i < a.length; i++) { dt += a[i]*b[i]; na += a[i]*a[i]; nb += b[i]*b[i]; } return dt / (Math.sqrt(na)*Math.sqrt(nb) || 1); };
|
||||
const cos = (a, b) => { if (a.length !== b.length) throw new Error(`cosine: length mismatch (${a.length} vs ${b.length})`); let dt = 0, na = 0, nb = 0; for (let i = 0; i < a.length; i++) { dt += a[i]*b[i]; na += a[i]*a[i]; nb += b[i]*b[i]; } return dt / (Math.sqrt(na)*Math.sqrt(nb) || 1); };
|
||||
const rms = (a) => { let s = 0; for (const v of a) s += v*v; return Math.sqrt(s/a.length); };
|
||||
|
||||
async function embed(D, slice) {
|
||||
|
||||
18
tests/acceptance/2/CRITERIA.json
Normal file
18
tests/acceptance/2/CRITERIA.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"schema": "elffuss-t2t/criteria@2",
|
||||
"issue": 2,
|
||||
"criteria": [
|
||||
{
|
||||
"index": 1,
|
||||
"tests": [
|
||||
"tests/acceptance/2/criteria.test.js::criterion 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"index": 2,
|
||||
"tests": [
|
||||
"tests/acceptance/2/criteria.test.js::criterion 2"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
13
tests/acceptance/2/criteria.test.js
Normal file
13
tests/acceptance/2/criteria.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
const mod = await import('../../../diarize.mjs');
|
||||
|
||||
test('criterion 1', () => {
|
||||
assert.throws(() => mod.cosine([1, 2, 3], [1, 2]), (err) => err instanceof Error && err.message.startsWith('cosine:'));
|
||||
assert.equal(mod.cosine([1, 0], [1, 0]), 1);
|
||||
});
|
||||
|
||||
test('criterion 2', () => {
|
||||
assert.throws(() => mod.cosine([1, 0], [1, 0, 5]), (err) => err instanceof Error && err.message.startsWith('cosine:'));
|
||||
assert.equal(mod.cosine([0, 0], [0, 0]), 0);
|
||||
});
|
||||
Reference in New Issue
Block a user