Avoid one extra call to Tensor::end().
Simplified change_dimension()