[英]C++ function that takes args Eigen sparse matrices
Eigen library provides/suggests numerous ways to pass a dense matrix in a function, so that it works for a different types that share the same base, and avoids copying (ie Ref<>, template expressions). 特征库提供/建议了许多方法来传递函数中的密集矩阵,因此它适用于共享相同基数的不同类型,并避免复制(即Ref <>,模板表达式)。
However, I haven't found anything equivalent for sparse matrices in either eigen documentation or online. 但是,我没有在本征文档或在线中找到与稀疏矩阵等价的东西。
I basically have the following question: How can I write a function with a generic interface so it can be called with both SparseMatrix or MappedSparseMatrix objects, of potentially different template arguments, without copying? 我基本上有以下问题:如何使用通用接口编写函数,以便可以使用SparseMatrix或MappedSparseMatrix对象调用可能不同的模板参数,而无需复制?
I have tried template expression of SparseMatrixBase withe derived arguments but I couldn't make it work. 我已经尝试了派生参数的SparseMatrixBase模板表达式,但我无法使其工作。
A simple example code will be appreciated. 一个简单的示例代码将不胜感激。
Simply write a template function taking any SparseMatrixBase<Derived>
, for instance: 只需编写一个采用任何
SparseMatrixBase<Derived>
的模板函数,例如:
template<typename Derived>
void foo(const SparseMatrixBase<Derived> &a_mat) {
const Derived &mat(a_mat.derived());
SparseMatrix<typename Derived::Scalar> tr_mat = mat.transpose();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.