Problem to convert the return of torch::argmax to an int, in pytorch c++

Hello,

I am starting to use pytorch and I have a problem when I try to convert the return of torch::argmax to an int in pytorch c++.

For instance:

auto arrayCpu = torch::randint(1, 10, 10);

auto max = torch::argmax(arrayCpu);

auto maxNumber = *max.data<int>();

Error:

terminate called after throwing an instance of ‘c10::Error’
what(): expected scalar type Int but found Long (data at …

Thanks for any help!

auto maxNumber = max.data<int64_t>();

Usually, PyTorch uses int64_t / scalar type kLong for indices and indexing tensors.

Best regards

Thomas

Thanks for your quick reply! It works perfectly now!

Best regards,

Ivan