ones method Null safety

List ones(
  1. List shape,
  2. {String? dtype = 'int'}
)

Implementation

List ones(List shape, {String? dtype = 'int'}) {
  int mult = 1;
  for (int i = 0; i < shape.length; i++) {
    mult = mult * shape[i] as int;
  }
  List temp;
  if (dtype == 'int') {
    temp = List.generate(mult, (_) => 1);
  } else if (dtype == 'double') {
    temp = List.generate(mult, (_) => 1.0);
  } else {
    throw new Exception(
        "DartTensorException : Undefined dtype. Choose 'int' or 'double'.");
  }
  temp = generate(temp, shape);
  return temp;
}