interplane.Get Omega
Read in your language

ggml-omega

aien-dev/ggml-omega

Brought by drakestapleton

branch main Branches Tags History

ggml-omega / tests / test-cmp.mjs

64 lines · 3200 bytes Raw Blame History
1// Verification-only controls. No model, GPU, Python or production runtime.
2// Byte fixtures sourced with WolframLanguageEvaluator, 2026-10-29:
3// Reverse[IntegerDigits[h,256,4]] for h=16^^3F800000,16^^40000000,
4// 16^^7FC00000,16^^7F800000 -> [0,0,128,63],[0,0,0,64],
5// [0,0,192,127],[0,0,128,127]. First[Ordering[{1.,2.},-1]]-1 -> 1.
6import assert from 'node:assert/strict';
7import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
8import { tmpdir } from 'node:os';
9import { join, resolve } from 'node:path';
10import { spawnSync } from 'node:child_process';
11
12const binary = resolve(process.argv[2] ?? 'build/cmp');
13const dir = mkdtempSync(join(tmpdir(), 'omega-cmp-'));
14let count = 0;
15try {
16 const one = Buffer.from([0, 0, 128, 63]), two = Buffer.from([0, 0, 0, 64]);
17 const nan = Buffer.from([0, 0, 192, 127]), inf = Buffer.from([0, 0, 128, 127]);
18 const row = Buffer.concat([one, two]);
19 const files = {};
20 for (const [name, bytes] of Object.entries({
21 same: row, shifted: Buffer.concat([two, one]), empty: Buffer.alloc(0),
22 short: row.subarray(0, 7), trailing: Buffer.concat([row, Buffer.from([0])]),
23 twice: Buffer.concat([row, row]), nan: Buffer.concat([nan, two]), inf: Buffer.concat([one, inf]),
24 })) {
25 files[name] = join(dir, name);
26 writeFileSync(files[name], bytes);
27 }
28 function check(label, a, b, pass, nv = '2', expected) {
29 const args = [nv, a, b];
30 if (expected !== undefined) args.push(expected);
31 const r = spawnSync(binary, args, { encoding: 'utf8' });
32 assert.equal(r.error, undefined, label);
33 assert.equal(r.signal, null, `${label}: process died`);
34 assert.equal(r.status === 0, pass, `${label}: exit ${r.status} ${r.stderr} ${r.stdout}`);
35 if (pass) {
36 const report = JSON.parse(r.stdout);
37 assert.ok(report.steps > 0);
38 assert.equal(report.top1_agree, report.steps);
39 assert.equal(report.first_divergence, -1);
40 }
41 console.log(`PASS ${label}`);
42 count++;
43 }
44 check('equal nonempty rows', files.same, files.same, true);
45 check('explicit expected rows', files.twice, files.twice, true, '2', '2');
46 check('changed greedy token', files.same, files.shifted, false);
47 check('empty pair', files.empty, files.empty, false);
48 check('short float row', files.short, files.short, false);
49 check('trailing partial float', files.trailing, files.trailing, false);
50 check('unequal complete rows', files.same, files.twice, false);
51 check('equally truncated rows', files.same, files.same, false, '2', '2');
52 check('extra rows', files.twice, files.twice, false, '2', '1');
53 check('NaN', files.nan, files.nan, false);
54 check('Infinity', files.inf, files.inf, false);
55 check('missing file', join(dir, 'missing'), files.same, false);
56 check('directory read error', dir, dir, false);
57 for (const nv of ['0', '-1', '2junk', '', '999999999999999999999999999999'])
58 check(`invalid vocabulary ${JSON.stringify(nv)}`, files.same, files.same, false, nv);
59 for (const n of ['0', '-1', '1junk'])
60 check(`invalid expected steps ${JSON.stringify(n)}`, files.same, files.same, false, '2', n);
61 console.log(`${count} comparator controls PASS`);
62} finally {
63 rmSync(dir, { recursive: true, force: true });
64}