trekhleb/javascript-algorithms · error · Error
Invalid matrix format
Error message
Invalid matrix format
What it means
Error "Invalid matrix format" thrown in trekhleb/javascript-algorithms.
Source
Thrown at src/algorithms/math/matrix/Matrix.js:36
const validateType = (m) => {
if (
!m
|| !Array.isArray(m)
|| !Array.isArray(m[0])
) {
throw new Error('Invalid matrix format');
}
};View on GitHub (pinned to 85293e3e2b)
Solutions
- Pass an array of arrays (or deeper nested arrays); the first element must itself be an array.
- Guard inputs with Array.isArray checks before calling matrix operations.
- Build matrices with the provided helpers (zeros / generate) instead of ad-hoc values.
When it happens
Trigger: A matrix helper that calls validateType receives a value m that is falsy, is not an array, or whose first element m[0] is not an array — e.g. a number, a flat 1D array, or undefined.
Common situations: Passing a flat array, scalar, null, or non-array value to matrix functions such as dot, t, add, mul, or sub.
AI-assisted analysis of trekhleb/javascript-algorithms@85293e3e2b (2026-08-24).
Data as JSON: /api/errors/e311a47101f87d0d.
Report an issue: GitHub.