Strange! One tensor can slice while same size another can not!

I got some weired things in C++ pytorch. Simply I got 2 tensor with same size, but one can slice, the other can not.

I got a tensor of priors which using in SSD, and a tensor of loc which is prediction of network. They are same size, and program checked exactly same size:

origin prior: [2976, 4] origin loc: [2976, 4]
loc slice: [2976, 2]

As you can see, the loc can slice using:

loc.slice(1, 0, 2)

which gets the first 2 columns.

But when slice pirors, it was throwing an error:

terminate called after throwing an instance of 'std::runtime_error'
  what():  invalid argument 0: Sizes of tensors must match except in dimension 0. Got 1 and 2 in dimension 1 at /media/jintain/sg/ai/libs/pytorch/aten/src/THC/generic/

Both tensor are contiguous, and I checked it. Why they are not same behaviour?

Are you sure that you’re getting the error from slice? That isn’t an error slice would throw…

Best regards


Sorry, I have figure it out.
this works exactly.