- Remove legacy compute-worker monolith under `src/compute/`, including PDF and Whisper inference, control-plane, and runtime orchestration - Move PDF and Whisper inference logic to new `src/inference/` module - Move control-plane, orchestrator, and state machine logic to `src/operations/` - Move NATS/JetStream adapters to `src/infrastructure/` - Move job orchestration, progress, and artifact persistence to `src/jobs/` - Update imports throughout tests and main app to reference new module structure - Update Dockerfile and scripts to use new asset paths - Add new entrypoints: `src/api/app.ts` and `src/api/contracts.ts` - Remove obsolete files and update `.gitignore` for new dev artifacts This refactor modularizes the compute-worker, improving maintainability and separation of concerns. No functional changes to inference or orchestration logic. BREAKING CHANGE: compute-worker internal APIs, directory structure, and imports have changed; downstream code must update imports and integration points.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { buildGoertzelCoefficients, goertzelPower } from '../../../src/inference';
|
|
|
|
function dftPower(samples: Float32Array, k: number): number {
|
|
const n = samples.length;
|
|
let re = 0;
|
|
let im = 0;
|
|
for (let i = 0; i < n; i += 1) {
|
|
const angle = (-2 * Math.PI * k * i) / n;
|
|
re += samples[i] * Math.cos(angle);
|
|
im += samples[i] * Math.sin(angle);
|
|
}
|
|
return (re * re) + (im * im);
|
|
}
|
|
|
|
describe('whisper spectral helpers', () => {
|
|
test('goertzel power matches direct DFT for non-power-of-two frame size', () => {
|
|
const frameSize = 400;
|
|
const bins = 201;
|
|
const coeffs = buildGoertzelCoefficients(bins, frameSize);
|
|
const samples = new Float32Array(frameSize);
|
|
for (let i = 0; i < frameSize; i += 1) {
|
|
samples[i] = Math.sin((2 * Math.PI * 37 * i) / frameSize) + (0.2 * Math.cos((2 * Math.PI * 91 * i) / frameSize));
|
|
}
|
|
|
|
const testBins = [0, 7, 37, 91, 150, 200];
|
|
for (const k of testBins) {
|
|
const expected = dftPower(samples, k);
|
|
const actual = goertzelPower(samples, coeffs[k]);
|
|
const rel = Math.abs(actual - expected) / Math.max(1, Math.abs(expected));
|
|
expect(rel).toBeLessThan(1e-5);
|
|
}
|
|
});
|
|
});
|