Tensor<T>.fromIterable constructor
Tensor<T>.fromIterable (})
Constructs an Tensor from an iterable
.
By default a 1-dimensional tensor with the values from the iterable
iterable
is returned. If a shape
is provided the data populates the
tensor in the specified format in row-major.
Implementation
factory Tensor.fromIterable(Iterable<T> iterable,
{List<int>? shape, List<int>? strides, DataType<T>? type}) {
final type_ = type ?? DataType.fromIterable(iterable);
final data_ = type_.copyList(iterable);
final layout_ = data_.isEmpty
? Layout.empty
: Layout(shape: shape ?? [data_.length], strides: strides);
return Tensor.internal(type: type_, layout: layout_, data: data_);
}