@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
31 lines (30 loc) • 681 B
JavaScript
function multiplyMatrices(A, B) {
let m = A.length;
if (!Array.isArray(A[0])) {
A = [A];
}
if (!Array.isArray(B[0])) {
B = B.map((x) => [x]);
}
let p = B[0].length;
let B_cols = B[0].map((_, i) => B.map((x) => x[i]));
let product = A.map(
(row) => B_cols.map((col) => {
if (!Array.isArray(row)) {
return col.reduce((a, c) => a + c * row, 0);
}
return row.reduce((a, c, i) => a + c * (col[i] || 0), 0);
})
);
if (m === 1) {
product = product[0];
}
if (p === 1) {
return product.map((x) => x[0]);
}
return product;
}
export {
multiplyMatrices as default
};
//# sourceMappingURL=multiply-matrices.js.map