ruvnet/ruflo · error
Matrix must be square
Error message
Matrix must be square
What it means
computeEigenvalues() was given a flattened Float32Array whose length is not a perfect square, so it cannot be reshaped into an n x n matrix. The squareness check runs before any eigenvalue computation; pass a square matrix or a correctly flattened one.
Source
Thrown at v3/plugins/prime-radiant/src/engines/SpectralEngine.ts:87
stabilityIndex
};
}
/**
* Compute eigenvalues of a matrix
*
* @param matrix - Square matrix (2D array or flattened Float32Array)
* @returns Sorted eigenvalues (descending)
*/
async computeEigenvalues(matrix: number[][] | Float32Array): Promise<number[]> {
let flat: Float32Array;
let n: number;
if (matrix instanceof Float32Array) {
flat = matrix;
n = Math.sqrt(matrix.length);
if (n !== Math.floor(n)) {
throw new Error('Matrix must be square');
}
} else {
n = matrix.length;
flat = new Float32Array(n * n);
for (let i = 0; i < n; i++) {
const row = matrix[i];
if (!row) continue;
for (let j = 0; j < n; j++) {
flat[i * n + j] = row[j] ?? 0;
}
}
}
if (n === 0) return [];
if (n === 1) return [flat[0] ?? 0];
if (this.wasmModule) {
// Use WASM for eigenvalue computationView on GitHub (pinned to fa13ee4ad6)
Solutions
- Provide a square matrix (equal row and column counts) as required by spectral operations.
- Validate matrix dimensions before invoking the engine and reject non-square input early.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at v3/plugins/prime-radiant/src/engines/SpectralEngine.ts:87 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/c38130ae9d788e6e.
Report an issue: GitHub.