Hi,
You have access to the .select() and .narrow() functions in cpp that can be used for this.
You also have access to .index_select() and .index_copy_() to read and write given 1D indices
The python code equivalent to yours is:
x_slice = x.narrow(0, 3, 2)
x_slice.add_(win_sq.narrow(0, 0, 2))
new_val = tmp.index_select(-1, approx_nonzero_indices) / window.index_select(0, nonzero_indices)
tmp.index_copy_(-1, approx_nonzero_indices, new_val)