我正在使用 libtorch C++。在 python 版本中,我们可以通过调用其 numpy
值轻松检查张量的值,而在 numpy
中,我们有 np.isnan()
。我想知道 libtorch
C++
中是否有内置函数来检查张量是否有任何 NAN
值?
谢谢, 阿夫欣
最佳答案
添加 Fábio 的回答(我的声誉太低无法发表评论):
如果您真的想在 assert
或 if
条件中使用有关 NAN 的信息,您需要将其从 torch::Tensor
转换而来像这样的 C++ bool
torch::Tensor myTensor;
// do something
auto tensorIsNan = at::isnan(myTensor).any().item<bool>(); // will be of type bool
关于pytorch - 手电筒 C++ : API to check NAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54205116/