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

Help with TriangularViewReturnType

Tags: None
(comma "," separated)
xerion
Registered Member
Posts
20
Karma
0

Help with TriangularViewReturnType

Sun Jan 18, 2015 10:38 am
I was wondering if the code that I am posting below is something that is worth doing and of course how can it be achieved as I 've tested a few different things with no success.
The purpose is to store 2 symmetric matrices in the upper and lower triangular parts of one matrix in order to save memory.
Am I going to run into any kinds of issues that possibly I am not aware of ?

Any ideas ?


Code: Select all

template<size_t N>
class Parameters
{
   using MatN = Eigen::MatrixXd;
   // I've experimented with a couple of things here and of course the compiler complained
   // about all kinds of different things so I was wondering how to achieve what I want
   using TriangMatN = ???;

public:
   Parameters() : mat(MatN(N + 1, N)) {}

   TriangMatN& Params1()
   {
      return mat.topRightCorner<N, N>().triangularView<Eigen::Upper>();
   }

   TriangMatN& Params2()
   {
      return mat.bottomLeftCorner<N, N>().triangularView<Eigen::Lower>();
   }

private:
   MatN mat;
};
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Note tested, but if you want symmetric views you can do:
Code: Select all
SelfAdjointView<Block<MatN,N,N>,Upper>  Params1()
{
  return mat.topRightCorner<N, N>().selfadjointView<Eigen::Upper>();
}
SelfAdjointView<Block<MatN,N,N>,Lower> Params2()
{
  return mat.bottomLeftCorner<N, N>().selfadjointView<Eigen::Lower>();
}


Bookmarks



Who is online

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