repeat method
Repeat along each dimension.
Implementation
Tensor repeat(List<int> times) {
assert(times.length == ndim);
final newShape = <int>[];
for (int i = 0; i < ndim; i++) {
newShape.add(shape[i] * times[i]);
}
final result = Tensor.zeros(newShape);
final indices = List<int>.filled(ndim, 0);
for (int flatIdx = 0; flatIdx < result.size; flatIdx++) {
int srcOffset = 0;
for (int d = 0; d < ndim; d++) {
srcOffset += (indices[d] % shape[d]) * strides[d];
}
result.data[flatIdx] = data[srcOffset];
for (int d = ndim - 1; d >= 0; d--) {
indices[d]++;
if (indices[d] < newShape[d]) break;
indices[d] = 0;
}
}
return result;
}