generate method Null safety

Tensor<double> generate(
  1. TensorShape shape,
  2. double generator(
    1. TensorShape shape,
    2. int i
    )
)

Implementation

static Tensor<double> generate(
  TensorShape shape,
  double Function(TensorShape shape, int i) generator,
) {
  final builder = Float32TensorBuilder();
  builder.tensorShape = shape;
  final n = shape.numberOfElements;
  for (var i = 0; i < n; i++) {
    builder.elements[i] = generator(shape, i);
  }
  return builder.build();
}