Tensor Slicing in C++

What will be the equivalent C++ implementation for the below tensor operation:

pe[:, 0::2] = torch.sin(position * div_term)

Assuming pe is a two-dimensional tensor.

Check out the Tensor Indexing API documentation. It contains tables showing how to translate both getter and setter constructs from Python to C++ using libtorch.

Thanks for the response; will be trying out the same

1 Like