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.
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.
It’s the same thing. You can use either.
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.