Libtorch how to add operation while slicing similar to Python?


i’m making some test between pytorch and libtorch.
In python you can make something like this: (for example tensor is size(1000,4))

tensor[:, :2] -= tensor[:, 2:] / 2

how can i achive this using libtorch.

I know that with .index and torch::indexing::Slice i can do slice, but how to add operation while slicing. There is a proper way of doing this in libtorch, without using a for loop on all tensor elements after slicing? Thanks