addition static method
Return elementwise addition of a
and b
Throw an exception
if dimension's condition not met
Implementation
static Matrix addition(Matrix a, Matrix b) {
if (a.n == b.n && a.m == b.m) {
var resultMatrix = Matrix.zero(n: a.n, m: b.m);
for (int i = 0; i < resultMatrix.n; i += 1) {
for (int j = 0; j < resultMatrix.m; j += 1) {
resultMatrix[i][j] = a[i][j] + b[i][j];
}
}
return resultMatrix;
} else {
throw Exception(
'Dimensions error: A.shape != B.shape |(${a.n}, ${a.m}) != (${b.n},${b.m})|');
}
}