gpt4 book ai didi

pytorch - 手电筒 C++ : API to check NAN

转载 作者:行者123 更新时间:2023-12-02 20:08:05 28 4
gpt4 key购买 nike

我正在使用 libtorch C++。在 python 版本中,我们可以通过调用其 numpy 值轻松检查张量的值,而在 numpy 中,我们有 np.isnan()。我想知道 libtorch C++ 中是否有内置函数来检查张量是否有任何 NAN 值?

谢谢,阿夫欣

最佳答案

添加 Fábio 的回答(我的声誉太低无法发表评论):

如果您真的想在 assertif 条件中使用有关 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com