divScalar method Null safety

  1. @override
void divScalar(
  1. num value,
  2. {bool noNan = false,
  3. bool swapArguments = false}
)
override

Divides elements.

Example

// Element i will be:
//     y[i]=1/x[i]
tensor.divScalar(1, swapArguments:true);

Implementation

@override
void divScalar(num value, {bool noNan = false, bool swapArguments = false}) {
  value = value.toDouble();
  final elements = this.elements;
  final n = length;
  final nan = noNan ? 0.0 : double.nan;
  if (swapArguments) {
    for (var i = 0; i < n; i++) {
      final denominator = elements[i];
      elements[i] = denominator == 0.0 ? nan : value / denominator;
    }
  } else {
    if (value == 0.0) {
      fill(noNan ? 0.0 : double.nan);
    } else {
      for (var i = 0; i < n; i++) {
        elements[i] /= value;
      }
    }
  }
}