// Run a numbl script with the bp_* helpers on its path, and turn its `sys` // struct into a BeadSystem. Shared by the browser worker and the tests. import { executeCode, RTV } from "numbl"; import { parseSystem } from "./parse"; import type { SymEig } from "./modes"; import type { BeadSystem } from "./types"; export interface HelperFile { name: string; source: string; } export function runScript( source: string, helpers: HelperFile[], onOutput: (text: string) => void ): { sys: BeadSystem; warnings: string[] } { const result = executeCode(source, { onOutput, displayResults: true }, helpers, "script.m"); return parseSystem(result.variableValues.sys); } // Symmetric eigendecomposition through numbl's eig. export const numblEig: SymEig = (A, n) => { const r = executeCode("[V, D] = eig(A); d = diag(D);", { initialVariableValues: { A: RTV.tensor(A, [n, n]) }, }); const V = r.variableValues.V as unknown as { data: Float64Array }; const d = r.variableValues.d as unknown as { data: Float64Array } | number; const values = typeof d === "number" ? Float64Array.of(d) : d.data; return { values, vectors: V.data ?? Float64Array.of(1) }; };