Torch.narrow vs slicing

What’s the use for torch.narrow? When should it be used over slicing?

tensor.narrow(0, 0, 2)
# same as?
tensor[0:2, ...]

narrow appears in lang.modelling example and does not print deprec warning, so I thought I’d ask here.

3 Likes

It’s the same thing. You can use either.

7 Likes

In my limited tests, when used inside a .forward method, I found .narrow to be way faster than slicing.
I might be wrong, but I believe it’s worth mentioning performance when asked about the difference between the two.

3 Likes