in src/webgpu/util/compare.ts [271:333]
function compareMatrix(got: Value, expected: FPInterval[][]): Comparison {
// Check got type
if (!(got instanceof MatrixValue)) {
return {
matched: false,
got: `${Colors.red((typeof got).toString())}(${got})`,
expected: `Matrix`,
};
}
// Check element type
{
const gTy = got.type.elementType;
if (!isFloatValue(got.elements[0][0])) {
return {
matched: false,
got: `${Colors.red(gTy.toString())}(${got})`,
expected: `floating point elements`,
};
}
}
// Check matrix dimensions
{
const gCols = got.elements.length;
const gRows = got.elements[0].length;
const eCols = expected.length;
const eRows = expected[0].length;
if (gCols !== eCols || gRows !== eRows) {
assert(false);
return {
matched: false,
got: `Matrix of ${gCols}x${gRows} elements`,
expected: `Matrix of ${eCols}x${eRows} elements`,
};
}
}
// Check that got values fall in expected intervals
let matched = true;
const expected_strings: string[][] = [...Array(got.elements.length)].map(_ => [
...Array(got.elements[0].length),
]);
got.elements.forEach((c, i) => {
c.forEach((r, j) => {
const g = r.value as number;
if (expected[i][j].contains(g)) {
expected_strings[i][j] = Colors.green(`[${expected[i][j]}]`);
} else {
matched = false;
expected_strings[i][j] = Colors.red(`[${expected[i][j]}]`);
}
});
});
return {
matched,
got: convertArrayToString(got.elements.map(convertArrayToString)),
expected: convertArrayToString(expected_strings.map(convertArrayToString)),
};
}