PaddlePaddle 飞桨 FAQ合集 - 训练问题19
Question:
C++ 如何把std::vector转换成 lodtensor的方法?
Answer:
可以参考如下示例
cpp
std::vector<int64_t> ids{1918, 117, 55, 97, 1352, 4272, 1656, 903};
framework::LoDTensor words;
auto size = static_cast<int>(ids.size());
framework::LoD lod{{0, ids.size()}};
DDim dims{size, 1};
words.Resize(dims);
words.set_lod(lod);
auto *pdata = words.mutable_data<int64_t>();
size_t n = words.numel() * sizeof(int64_t);
memcpy(pdata, ids.data(), n);