operator [] method

Tensor operator [](
  1. int index
)

Get a sub-tensor along the first dimension.

Implementation

Tensor operator [](int index) {
  if (ndim == 1) {
    return Tensor(Float32List.fromList([data[index]]), [1]);
  }
  final newShape = shape.sublist(1);
  final stride = strides[0];
  final start = index * stride;
  final newData = Float32List.sublistView(data, start, start + stride);
  return Tensor(Float32List.fromList(newData), List<int>.from(newShape));
}