event 723 solution
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
diff --git a/diarize.mjs b/diarize.mjs
|
||||
index 622b5267a17a6e3142931024ae45611ecb21b712..2aa9fbed605578f38dfd92864c955decdcf526b7 100644
|
||||
--- a/diarize.mjs
|
||||
+++ b/diarize.mjs
|
||||
@@ -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: vectors must have the same 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) {
|
||||
diff --git a/tests/acceptance/2/CRITERIA.json b/tests/acceptance/2/CRITERIA.json
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..549b0d2922786bef700cc17577b03902c42310e6
|
||||
--- /dev/null
|
||||
+++ b/tests/acceptance/2/CRITERIA.json
|
||||
@@ -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"
|
||||
+ ]
|
||||
+ }
|
||||
+ ]
|
||||
+}
|
||||
diff --git a/tests/acceptance/2/criteria.test.js b/tests/acceptance/2/criteria.test.js
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..f2a1b8aadf5fc7307ae731cec197a973b09c3651
|
||||
--- /dev/null
|
||||
+++ b/tests/acceptance/2/criteria.test.js
|
||||
@@ -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);
|
||||
+});
|
||||
1
events/0000000723.json
Normal file
1
events/0000000723.json
Normal file
@@ -0,0 +1 @@
|
||||
{"data":{"cites":[],"envelope":{"delegation":{"identity":"0x3c4b6c950e8bf72399a3f54c7141ed8c487a9daf","nonce":"1790933831","project":"0x0000000000000000000000000000000000000000000000000000000000000000","scopes":1,"sessionX":"0xf91fed4b7a8fa62d54f40ec6d7b1f6ab96c08b2a36be947c8233a8c94883a92d","sessionY":"0x7213b05f51ff8811f431c39083d43c917f18f2f59e3907aab850deb8180d0ecb","validFrom":"1790933771","validUntil":"1791106631"},"delegationSignature":"0x0af5fcaf1e6f5806b739225124112f5f2d25d78591bd255f5271c47ec2021f1435d4be229d6b82921609a4c2e69c69a9099d2526674982d231e9c7d7fa8eab861c","kind":"session","signature":"0xf05cacf12a334f7c30b1c0aabb63b27b5c6bf8b15571d4aca03718c4e8417a013fdec704c5e277b3904f83597de850f9e5ebf80cdeef33a683638108a9027f69"},"mainHead":null,"message":{"author":"0x3c4b6c950e8bf72399a3f54c7141ed8c487a9daf","baseCommit":"0x65e902c7c4640842ff3087a5a9aa3950d8d86679","basePartial":"0x0000000000000000000000000000000000000000000000000000000000000000","citesHash":"0x0000000000000000000000000000000000000000000000000000000000000000","issueId":"0x09060fd098e76bfb06be9362ac725843d1834d9218762843b41c83830b66a5c3","issuedAt":"1790933853","lines":2,"nonce":"1790933853260","patchHash":"0x763953cf5569a677bae939dc9c3a181c254cc4c6e32e002bd7bd65c35586a29f","project":"0x16d6e75341c5f21003a4d9e89b416a545f7335094d7df139fd20942c9b7fb2de","repo":"0xa1bb61fe185a9ec2921347a472a1d2f0ee4fb72bfb65d5be4fccd49e428ccf6a"},"pr":"elffuss/translator:item/0xe5e8732a047e9b487e856f47bfd4a96074d25264d0ab22897c8d7106fa6316da"},"eventHash":"0x1004543e95d6c4db1689e39e7ea078084425eeacf441aacc0058a5f03cd9f059","gatewaySignature":"0x0a42d843e46476708788c0f9261fb9c2d2f86c521c2842d7dc3eba8b8abd40bb0447514c3ab56c2c76397dc6dd1924771199c6bc1ab17ae72e532e1306af20201c","prev":"0xbc044c8084750d31162c8b4d05e91801e039c1ca6f96e7b4a6294e4504e8f8f1","seq":723,"ts":1790933853,"type":"solution","v":2}
|
||||
Reference in New Issue
Block a user