This forum has been archived. All content is frozen. Please use KDE Discuss instead.

operator* in templated class inheriting from SparseMatrix

Tags: None
(comma "," separated)
smcduffee
Registered Member
Posts
3
Karma
0
I'm trying to inherit from SparseMatrix where the non-type template parameters determine the size of the matrix. These parameters are not the sizes themselves but instead are used to compute the size:

Code: Select all
typedef Eigen::SparseMatrix<double, Eigen::RowMajor> sparse_matrix;

template<enumT T1, size_t N1, enumT T2, size_t N2>
class myMatrix : public sparse_matrix {
   
public:
   
   static const enumT t1 = T1;
   static const size_t n1 = N1;
   static const enumT t2 = T2;
   static const size_t n2 = N2;
   
   myMatrix (const inputObj& input)
   :
      sparse_matrix ()
   {      
      size_t nCols (// compute num cols from templates and input);
      
      size_t nRows (// compute num rows from templates and input);
      
      this->resize (nRows, nCols);      
   }

template <typename derived>
   myMatrix& operator= (const Eigen::SparseMatrixBase<derived>& other) {
      this->sparse_matrix::operator= (other);
      return *this;
   }
}
;


I'm trying to get this class to multiply correctly but can't figure it out. I tried the following:

Code: Select all
template <typename derived>
myMatrix<derived::t1, derived::n1, T2, N2> operator* (const Eigen::SparseMatrixBase<derived>& rhs) {
   
   myMatrix<derived::t1, derived::n1, T2, N2> x  = this->sparse_matrix::operator * (rhs);
   return x;
}


And then tried calling:

Code: Select all
myMatrix<enumT::T0, 0, enumT::T0, 1> x;
myMatrix<enumT::T0, 1, enumT::T1, 1> y;
myMatrix<enumT:T0, 0, enumT::T1, 1> prod = x * y;


Anybody know how(if) this can be done?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
adding:
Code: Select all
using sparse_matrix::operator=;

in the public section might help.

btw, what's the purpose of having sizes determined from compile time parameters? for small dense matrices it does make sense, but not for sparse matrices.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]