operator + method
Element-wise addition.
Supports:
- Scalar addition: adds a number to all elements
- Array addition: element-wise addition with broadcasting
Example:
var arr = NDArray([[1, 2], [3, 4]]);
// Scalar addition
var result1 = arr + 10;
print(result1.toNestedList()); // [[11, 12], [13, 14]]
// Array addition
var arr2 = NDArray([[10, 20], [30, 40]]);
var result2 = arr + arr2;
print(result2.toNestedList()); // [[11, 22], [33, 44]]
// Broadcasting - add row to matrix
var row = NDArray([100, 200]);
var result3 = arr + row; // Broadcasting
Implementation
NDArray operator +(dynamic other) {
if (other is num) {
return map((x) => x + other);
} else if (other is NDArray) {
return _elementWise(other, (a, b) => a + b);
}
throw ArgumentError('Cannot add ${other.runtimeType} to NDArray');
}