/** * The training payload handed to an algorithm, kept free of any numbl * import so the main thread can assemble it without pulling the whole * interpreter into its bundle; the worker turns it into runtime values. */ import type { SnippetLibrary } from './types.ts'; export interface TrainingArrays { names: string[]; pre: number; /** Per type: column-major [snipLen x count] snippet matrix. */ snips: { data: Float64Array; snipLen: number; count: number }[]; } /** Assemble per-type training matrices from a library and a train split. */ export function buildTraining(lib: SnippetLibrary, trainIndices: number[][]): TrainingArrays { const snipLen = lib.pre + lib.post; const snips = trainIndices.map((idx) => { const data = new Float64Array(snipLen * idx.length); idx.forEach((si, j) => { const s = lib.snippets[si].samples; for (let i = 0; i < snipLen; i++) data[j * snipLen + i] = s[i] ?? 0; }); return { data, snipLen, count: idx.length }; }); return { names: lib.names, pre: lib.pre, snips }; }