Registered Member
|
I have a class that internally holds a sparse matrix. I'm having issues writing a method that can take a generic dense or sparse matrix as input and return the output. Ideally, this would also allow for all the lazy evaluation, etc. that Eigen does for efficiency.
So I have two questions: 1) Is there a way to write a templated function that can take dense OR sparse matrices as inputs? I.e. something that unifies MatrixBase and SparseMatrixBase? 2) Is there a way to preserve the lazy evaluation easily? Ideally, my function would look like this and take in dense or sparse matrices: template<typename SparseOrDenseMatrix> inline SparseOrDenseMatrix ApplyLeft(const SparseOrDenseMatrix& x) const { return sparse_matrix_ * x; } The "inline" is there just to emphasize that I would like to keep the lazy evaluation traits, I do not necessarily need that in practice. I've tried a few different return types, including Eigen::Product but I can't get it to compile without lots of template errors. There are some reasons we have for not exposing the underlying matrix publicly. |
Moderator
|
Better let the compiler figure out the returned type for you and implement a fully generic function, in c++11:
with c++14 you can even omit the decltype thing. |
Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]