eigen3,如何用密度和稀疏的矩阵实现多态性?
我想构建一个阵列,其中包含大型稀疏和密集矩阵的指针。然后,我希望使用多态性对它们进行操作,并避免复制/分配大部分内存。例如,
std::vector<UnkownType*> matrices;
matrices.emplace_back(get_large_dense_matrix_ptr());
matrices.emplace_back(get_large_sparse_matrix_ptr());
Eigen::MatrixXd result(known_size, known_size);
for(mat : matrices){
result+=*mat;
}
unkowntype
应该是什么? 我认为选择使用一系列参考文献或参考包装器,但这是禁止的。
I want to build an array which contains pointers to both large sparse and dense matrices. Then, I desire to operate on them using polymorphism and avoiding to copy/allocate large portions of memory. E.g.
std::vector<UnkownType*> matrices;
matrices.emplace_back(get_large_dense_matrix_ptr());
matrices.emplace_back(get_large_sparse_matrix_ptr());
Eigen::MatrixXd result(known_size, known_size);
for(mat : matrices){
result+=*mat;
}
What should be the UnkownType
type?
I thought in the alternative of using a variant of references or reference wrappers, but this is forbidden.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有C ++ 17,则可以使用
std :: variant
If you have C++17, you can use
std::variant