简体   繁体   English

包装 Eigen::Vector 类型

[英]Wrapping Eigen::Vector type

I'm working on a Neural Network library and I want to use Eigen to handle the vector and matrix math behind the models but I've been told that I should't expose Eigen types in the final api so, since the network is basically going to get vectors as inputs and return vectors as outputs I was thinking about creating a class(maybe Tensor) which wraps Eigen::VectorXf but I don't really know how to this preserving the Eigen optimizations when operating on such Tensors.我正在开发一个神经网络库,我想使用 Eigen 来处理模型背后的向量和矩阵数学,但我被告知我不应该在最终的 api 中公开 Eigen 类型,因为网络基本上是将向量作为输入并返回向量作为输出我正在考虑创建一个包含 Eigen::VectorXf 的类(可能是 Tensor),但我真的不知道如何在对此类张量进行操作时保留本征优化。

Is there a way to do this or should I change my approach?有没有办法做到这一点,或者我应该改变我的方法?

For example the OpenNN library also uses Eigen(I think) and its Tensor type is inherited from an std::vector, I haven't found how it is converted to Eigen yet (maybe Map is involved?)例如 OpenNN 库也使用 Eigen(我认为)并且它的 Tensor 类型是从 std::vector 继承的,我还没有找到它是如何转换为 Eigen 的(也许涉及 Map?)

The only reason I see to write a thin wrapper around the Eigen types is if you need the flexibility to change the implementation at a later point.我认为围绕 Eigen 类型编写一个瘦包装器的唯一原因是您是否需要在以后更改实现的灵活性。

If you don't have this requirement, you should expose the Eigen types.如果您没有此要求,则应公开 Eigen 类型。 It is an API your users will be familiar with and you will avoid any unnecessary conversions (copies) between your type and the Eigen Tensors.它是您的用户将熟悉的 API,您将避免在您的类型和特征张量之间进行任何不必要的转换(副本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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