add_ function
Implementation
Tensor add_(dynamic a, dynamic b, {double alpha = 1}) {
if (a is num) {
return add_(b, a, alpha: alpha);
} else if (a is Tensor) {
if (b is Tensor) {
final alphaScalar = float64_to_scalar(alpha);
Tensor_add_(a._tensorPtr, b._tensorPtr, alphaScalar.scalarPtr);
final errorMsg = _get_and_reset_last_err();
if (errorMsg != nullptr) {
final errorString = errorMsg.cast<Utf8>().toDartString();
throw Exception(errorString);
}
final tensor = Tensor._internal(a._tensorPtr);
return tensor;
} else if (b is num) {
if (b is int) {
final alphaScalar = float64_to_scalar(alpha);
final rightScalar = int32_to_scalar(b);
Tensor_add_scalar_(
a._tensorPtr, rightScalar.scalarPtr, alphaScalar.scalarPtr);
final errorMsg = _get_and_reset_last_err();
if (errorMsg != nullptr) {
final errorString = errorMsg.cast<Utf8>().toDartString();
throw Exception(errorString);
}
final tensor = Tensor._internal(a._tensorPtr);
return tensor;
} else if (b is double) {
final alphaScalar = float64_to_scalar(alpha);
final rightScalar = float64_to_scalar(b);
Tensor_add_scalar_(
a._tensorPtr, rightScalar.scalarPtr, alphaScalar.scalarPtr);
final errorMsg = _get_and_reset_last_err();
if (errorMsg != nullptr) {
final errorString = errorMsg.cast<Utf8>().toDartString();
throw Exception(errorString);
}
final tensor = Tensor._internal(a._tensorPtr);
return tensor;
} else {
throw Exception("wrong data type");
}
} else {
throw Exception("wrong data type.");
}
} else {
throw Exception("wrong data type");
}
}