命名空间 'torch' 中没有名为 'KInt16' 的成员
no member named 'KInt16' in namespace 'torch'
我正在做pytorch的cpp扩展,按照官方教程,使用libtorch和cmake编译程序。但是我遇到了创建张量的问题。
此代码可以工作。
#include <torch/torch.h>
#include <iostream>
int main(){
std::vector<int64_t> test_data = {1, 2, 3, 4, 5, 6, 7, 8, 9};
torch::Tensor s = torch::from_blob(test_data.data(), {3, 3}, torch::kInt64);
std::cout << "test case pass" << std::endl;
}
但此代码无法运行。
int main(){
auto option = torch::TensorOptions().dtype(torch::KInt16);
auto b = torch::zeros({2,3}, option);
std::cout << "test case pass" << std::endl;
}
编译错误日志在这里。
error: no member named 'KInt16' in namespace 'torch'; did you mean 'kInt16'?
正如错误消息中明确指出的那样,您打错了字:您应该写成
torch::kInt16
而不是 torch::KInt16
。 k
不应大写。
我正在做pytorch的cpp扩展,按照官方教程,使用libtorch和cmake编译程序。但是我遇到了创建张量的问题。 此代码可以工作。
#include <torch/torch.h>
#include <iostream>
int main(){
std::vector<int64_t> test_data = {1, 2, 3, 4, 5, 6, 7, 8, 9};
torch::Tensor s = torch::from_blob(test_data.data(), {3, 3}, torch::kInt64);
std::cout << "test case pass" << std::endl;
}
但此代码无法运行。
int main(){
auto option = torch::TensorOptions().dtype(torch::KInt16);
auto b = torch::zeros({2,3}, option);
std::cout << "test case pass" << std::endl;
}
编译错误日志在这里。
error: no member named 'KInt16' in namespace 'torch'; did you mean 'kInt16'?
正如错误消息中明确指出的那样,您打错了字:您应该写成
torch::kInt16
而不是 torch::KInt16
。 k
不应大写。