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

Function add

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

Source from the content-addressed store, hash-verified

247 * @return {Matrix}
248 */
249export const add = (a, b) => {
250 validateSameShape(a, b);
251 const result = zeros(shape(a));
252
253 walk(a, (cellIndices, cellValue) => {
254 updateCellAtIndex(result, cellIndices, cellValue);
255 });
256
257 walk(b, (cellIndices, cellValue) => {
258 const currentCellValue = getCellAtIndex(result, cellIndices);
259 updateCellAtIndex(result, cellIndices, currentCellValue + cellValue);
260 });
261
262 return result;
263};
264
265/**
266 * Multiplies two matrices element-wise.

Callers

nothing calls this directly

Calls 6

validateSameShapeFunction · 0.85
zerosFunction · 0.85
shapeFunction · 0.85
walkFunction · 0.85
updateCellAtIndexFunction · 0.85
getCellAtIndexFunction · 0.85

Tested by

no test coverage detected