slice method
Slice: returns a sub-tensor from start to end along dimension 0.
Implementation
Tensor slice(int start, int end, [int dim = 0]) {
if (dim == 0) {
final stride = strides[0];
final s = start * stride;
final e = end * stride;
final newData = Float32List.fromList(data.sublist(s, e));
final newShape = List<int>.from(shape);
newShape[0] = end - start;
return Tensor(newData, newShape);
}
// General dim slicing — build by iterating
return _sliceGeneral(start, end, dim);
}