Hi. I am trying to index a tensor using the following syntax
tensor = tensor.index(booleanIndexTensor);
This works before for some previous version of Torch c++. However, when I try with Pytorch 1.8, it throws the following error
error: no matching function for call to ‘at::Tensor::index(at::Tensor&)’
It seems like the API has changed, but I couldn’t find the new syntax anywhere else. Could you please let me know how I can adapt it for newer versions. Thanks a lot!
Thank you very much @tom. Indeed, it compiled fine when I changed to tensor.index({index}).
I copied the related note from the link you sent here, just for anyone having the same problem.
This will break backwards compatibility for the C++ API. There is no implicit conversion from ArrayRef (which was the old argument type) to List<optional>. One common call pattern is tensor.index({indices_tensor}), where indices_tensor is another Tensor, and that will continue working because the {} initializer_list constructor for List<optional> can take Tensor elements that are implicitly converted to optional, but another common call pattern was tensor.index(indices_tensor), where previously, the Tensor got implicitly converted to an ArrayRef, and to implicitly convert Tensor → optional → List<optional> would be two implicit conversions. C++ doesn’t allow chaining. two implicit conversions. So those call sites have to be rewritten to tensor.index({indices_tensor}).