通行列表需要std :: prinitizer_list< std :: prinitizer_list<类型> >

发布于 2025-02-13 10:26:14 字数 1220 浏览 0 评论 0原文

我现在使用OpenNN来写概念验证,并且我对张量的输入有问题。

来自Opennn negets 我们看到神经网络

Tensor<type, 2> inputs(1,9);
inputs.setValues({{type(4),type(3),type(3),type(2),type(3),type(4),type(3),type(2),type(1)}});
neural_network.calculate_outputs(inputs);

我确实 接受了张量的输入,将矢量转换为张量的解决方法,但它很长,有点乏味。

然后,我试图通过向量的向量,一个括号封闭的向量,一个括号封闭的数组,一个动态分配值列表的数组。

错误:

cannot convert '<brace-enclosed initializer list>' to 'const Eigen::internal::Initializer<Eigen::Tensor<long long unsigned int, 2>, 2>::InitList&' {aka 'const std::initializer_list<std::initializer_list<long long unsigned int> >&'}

错误继续只是一个变体(类型不匹配类型) 重现错误的代码(假设您已经获得了OpenNN库设置。

Tensor<uint64_t, 2> createFilledTensor(int index)
{ 
   uint64_t * inList = new uint64_t[index]();
    for(int i = 0; i < index; i++)
    {
        inList[i] = 356534563546356;
    }

    Tensor<uint64_t, 2> inputs(1, index);

    inputs.setValues({inList});
    return inputs;
}

此外,值得注意的是,现在数据无关紧要,因为我试图弄清楚如何将其获取张量。

I'm using OpenNN to write a proof of concept right now, and I'm having an issue with declaring inputs for a Tensor.

From the OpenNN website we see that the neural net accepts a Tensor input

Tensor<type, 2> inputs(1,9);
inputs.setValues({{type(4),type(3),type(3),type(2),type(3),type(4),type(3),type(2),type(1)}});
neural_network.calculate_outputs(inputs);

I did figure out a workaround to convert a vector to a tensor, but it's long and a little tedious.

I then attempted to pass a vector of a vector, a brace enclosed vector, a brace enclosed array, a dynamically allocated array of the list of values.

The error:

cannot convert '<brace-enclosed initializer list>' to 'const Eigen::internal::Initializer<Eigen::Tensor<long long unsigned int, 2>, 2>::InitList&' {aka 'const std::initializer_list<std::initializer_list<long long unsigned int> >&'}

The error continues to just be a variation of (Type does not match type)
The code to reproduce the error (assuming you've gotten the OpenNN library setup.

Tensor<uint64_t, 2> createFilledTensor(int index)
{ 
   uint64_t * inList = new uint64_t[index]();
    for(int i = 0; i < index; i++)
    {
        inList[i] = 356534563546356;
    }

    Tensor<uint64_t, 2> inputs(1, index);

    inputs.setValues({inList});
    return inputs;
}

Also, feel it's worth noting, right now the data doesn't matter as I am trying to figure out HOW to get it to the tensor.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾城如夢未必闌珊 2025-02-20 10:26:14

编辑:

找到相关帖子在这里

解决方案更适合其他任何人,我的问题无法回答。

我解决了此问题如下:

namespace Eigen {
  template < typename T >
  decltype(auto) TensorLayoutSwap(T&& t)
  {
    return Eigen::TensorLayoutSwapOp<typename std::remove_reference<T>::type>(t);
  }
}

Eigen::Tensor<uint64_t, 2> createDataSetFromPair(std::pair<std::vector<uint64_t>, int> data)
{
    Eigen::Tensor<uint64_t, 2> dataTensor(1,data.second);
    auto mapped_t = Eigen::TensorMap<Eigen::Tensor<uint64_t, 2, Eigen::RowMajor>>(&(data.first)[0], data.first.size(), 1);

    return Eigen::TensorLayoutSwap(mapped_t);
}

PAIR(VEC是数据列表,INT是正在处理的数据量。我这样做是为了个人用途,因为它具有特殊的应用程序,但我相信您可以使用vec.size(),只需要向量作为param

EDIT:

Found a relevant post here

This solution is more for anyone else that comes around and my question can't be answered;

I solved this problem as follows:

namespace Eigen {
  template < typename T >
  decltype(auto) TensorLayoutSwap(T&& t)
  {
    return Eigen::TensorLayoutSwapOp<typename std::remove_reference<T>::type>(t);
  }
}

Eigen::Tensor<uint64_t, 2> createDataSetFromPair(std::pair<std::vector<uint64_t>, int> data)
{
    Eigen::Tensor<uint64_t, 2> dataTensor(1,data.second);
    auto mapped_t = Eigen::TensorMap<Eigen::Tensor<uint64_t, 2, Eigen::RowMajor>>(&(data.first)[0], data.first.size(), 1);

    return Eigen::TensorLayoutSwap(mapped_t);
}

where pair(vec is the data list, and int is the amount of data being processed. I did this for my personal use as it has special application for what I'm doing, but I believe you could use vec.size() and only need a vector as a param

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文