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

Generic function implementation

Tags: None
(comma "," separated)
mextron
Registered Member
Posts
3
Karma
0

Generic function implementation

Sun Apr 22, 2012 12:40 pm
I am new to Eigen and not so experienced in c++ so go slow on me.

I am trying to implement a generic kronecker product function but the compiler is throwing an error. It seems to have a problem using a local templated matrix.

So my code is
Code: Select all
template<typename T>
MatrixBase<T> kron(const MatrixBase<T>& A, const MatrixBase<T>& B)
{
   MatrixBase<T> C(A.rows()*B.rows(),A.cols()*B.cols());
   
   for(int i=0; i<A.cols(); i++)
   {
      for(int j=0; j<A.rows(); j++)
      {
         C.block(i*B.rows(),j*B.cols(),B.rows(),B.cols())=A(i,j)*B;
      }
   }
}


and the error is pointing at the instantiation of C:

/usr/local/include/Eigen/src/Core/MatrixBase.h:513:5: error: ‘Eigen::MatrixBase<Derived>::MatrixBase(int, int) [with Derived = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>]’ is private


Can someone help me get this working?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
a MAtrixBase<> is more like an abstract class, you have to return a Matrix<> object. Note that there is a kronecker product implementation in unsupported/Eigen/KroneckerProduct
mextron
Registered Member
Posts
3
Karma
0

Re: Generic function implementation

Tue Apr 24, 2012 8:26 am
Thanks, will check out the implementation and if I understand this correctly MatrixBase<> cannot be instantiated but Matrix<> can.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]