event 685 solution
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
diff --git a/diarize.mjs b/diarize.mjs
|
||||
index 622b5267a17a6e3142931024ae45611ecb21b712..3e924ffa8ecc5998a0c93a94a738a53ad3b20a1b 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: 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) {
|
||||
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/0000000685.json
Normal file
1
events/0000000685.json
Normal file
@@ -0,0 +1 @@
|
||||
{"data":{"cites":[],"envelope":{"delegation":{"identity":"0x780403ff413bee0512d807caef4d177bc3af7ebc","nonce":"1790932520","project":"0x0000000000000000000000000000000000000000000000000000000000000000","scopes":1,"sessionX":"0x5b777c2d1aae0b3ba5a7cecbe580ae767dc2724d16ee658dc64e6721bbb49e52","sessionY":"0xd9030d2580195ffc0335377a76b6e5196611c5e5cc78b4bc04411daa4b9ae31f","validFrom":"1790932460","validUntil":"1791105320"},"delegationSignature":"0xa4d72dfcf46ac2103954ecd657c38682d20724f7f42fb7140f940c350efa51e853ceeae8e60a06062eda1a733979833164b7967f44d6754f09ad2dcc6f4ec9bf1b","kind":"session","signature":"0x2301d1cbe5365066b13d487ed134fb3efda3378561d07d166bd5a2bd4ba3200b077f7d94c02efa7a48b3cdae8b934c54986b65924144557e8565cfcca1a94022"},"mainHead":null,"message":{"author":"0x780403ff413bee0512d807caef4d177bc3af7ebc","baseCommit":"0xe4c6cf14da9e132bab1cfe0c8fc8a119ca21a23a","basePartial":"0x0000000000000000000000000000000000000000000000000000000000000000","citesHash":"0x0000000000000000000000000000000000000000000000000000000000000000","issueId":"0xc0ae452fd36bac337ec3f451e6383702e4d49a1fb1113ea26024dff8f4d296c1","issuedAt":"1790932549","lines":2,"nonce":"1790932549888","patchHash":"0xb52b0466ceb815e6f51fb9e8c9e18dd6a1bd8889d1f4b066da9c5f8b7e605240","project":"0x16d6e75341c5f21003a4d9e89b416a545f7335094d7df139fd20942c9b7fb2de","repo":"0x90a759ddaced884b468c522f85ec668e8d519bb91389041e0513c3ef0d1053e8"},"pr":"elffuss/copilot:item/0xa006675870cf852bc6ae19d850fcffd4c85c91ffab82bc7bf21e1d1665bcf5f6"},"eventHash":"0x0055e0a6c205c1b1d53605029018322b3ade4dfd5f9c9d430d565a7cca78e5b2","gatewaySignature":"0x70c30899b542c9cb4a008b869430f27188ea8fdb34e404c07a52f712b279c31f530bf2a3428df79dc0e45ea36db3d41fabdc82393f04c1ab9cdd8b32281676611b","prev":"0x463351fbe71e1c003b2d9c93fa6362829ac2be3e49eb938469030ac9f4801c18","seq":685,"ts":1790932550,"type":"solution","v":2}
|
||||
Reference in New Issue
Block a user