MCPcopy
hub / github.com/trekhleb/javascript-algorithms / validateSameShape

Function validateSameShape

src/algorithms/math/matrix/Matrix.js:61–77  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

59 * @trows {Error}
60 */
61export const validateSameShape = (a, b) => {
62 validateType(a);
63 validateType(b);
64
65 const aShape = shape(a);
66 const bShape = shape(b);
67
68 if (aShape.length !== bShape.length) {
69 throw new Error('Matrices have different dimensions');
70 }
71
72 while (aShape.length && bShape.length) {
73 if (aShape.pop() !== bShape.pop()) {
74 throw new Error('Matrices have different shapes');
75 }
76 }
77};
78
79/**
80 * Generates the matrix of specific shape with specific values.

Callers 3

addFunction · 0.85
mulFunction · 0.85
subFunction · 0.85

Calls 3

validateTypeFunction · 0.85
shapeFunction · 0.85
popMethod · 0.80

Tested by

no test coverage detected