I am using libtorch C++. In python version we can easily check the value of a tensor by calling its numpy value, and in numpy we have np.isnan(). I was wondering if there is a built in function in libtorch C++ to check whether a tensor has any NAN value?
Thanks, Afshin
Adding on to Fábio's answer (my reputation is too low to comment):
If you actually want to use the information about NANs in an assert or if condition you need convert it from a torch::Tensor to a C++ bool like so
torch::Tensor myTensor;
// do something
auto tensorIsNan = at::isnan(myTensor).any().item<bool>(); // will be of type bool
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With