简体   繁体   中英

no member named 'KInt16' in namespace 'torch'

I am working on a cpp extension for pytorch, and followed the official tutorial, using libtorch and cmake to compile the program. But I met the problem of creating tensor. This code can work.

#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;
}

But this code can't work.

int main(){
    auto option = torch::TensorOptions().dtype(torch::KInt16);
    auto b = torch::zeros({2,3}, option);
    std::cout << "test case pass" << std::endl;
}

and the compile error log is here.

error: no member named 'KInt16' in namespace 'torch'; did you mean 'kInt16'?

As explicitly stated by the error message, you made a typo: you should have written torch::kInt16 instead of torch::KInt16 . The k should not be capitalized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM