Re: [eigen] combine matrix blocks

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]



I don't really get it, but it seems you want to add a MatrixBase member returning an IndirectView. Then the correct way to write it is:

template<typename Derived>
class MatrixBase : ......
{
 // ......

  template<typename A, typename B>
  IndirectView<Derived,A,B> view(const A& a, const B& b) { return  IndirectView<Derived,A,B>(derived(), a, b); }

};

Does that help ?

Also in your code you are mixing IndirectView and MatrixView, but I guess that's just a copy paste typo.

gael.

On Thu, Nov 26, 2009 at 6:27 PM, Stefan Ulbrich <s.ulbrich@xxxxxxxxxxxxxx> wrote:
Hello,

sorry for the very long delay, I could not find the time to continue the work on my project with Eigen.

The matrix view/proxy works quite well (addressing of elements via two lists of indices). I only have still one problem. I want to hide the creation of a 
matrixview object within a member:

MatrixView<MatrixXd,Dynamic,Dynamic> getView(){
return m_matrix(range1,range2);
}

But it seems that this does not work .. for instance cout<<getView() 
gives me an exception in malloc.

Do you have any idea what could go wrong? 

Thank you very much!

Best,
Stefan



template<typename MatrixType, typename RowType, typename ColType> class MatrixView
: public MatrixBase<MatrixView<MatrixType, RowType, ColType> >
{
public:

EIGEN_GENERIC_PUBLIC_INTERFACE(IndirectMatrix)

inline IndirectMatrix(const MatrixType& matrix, const RowType &rows, const ColType &cols)
: m_matrix(matrix), m_rows(rows), m_cols(cols)
{
//std::cout << "Debug: " << m_rows.minCoeff() << "," << m_rows.maxCoeff() << "," << matrix.rows() << std::endl;
//std::cout << "Debug: " << m_cols.minCoeff() << "," << m_cols.maxCoeff() << "," << matrix.cols() << std::endl << matrix << std::endl << m_matrix << std::endl;
ei_assert(m_rows.minCoeff() >= 0 && m_rows.maxCoeff() < matrix.rows()
&& m_cols.minCoeff() >= 0 && m_cols.maxCoeff() < matrix.cols());
}


EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndirectMatrix)

inline int rows() const { return m_rows.rows(); }
inline int cols() const { return m_cols.rows(); }

inline Scalar& coeffRef(int row, int col)
{
return m_matrix.const_cast_derived().coeffRef(m_rows(row), m_cols(col));
}

inline const Scalar coeff(int row, int col) const
{
return m_matrix.coeff(m_rows(row), m_cols(col));
}

protected:
const typename MatrixType::Nested m_matrix;
const typename RowType::Nested m_rows;
const typename ColType::Nested m_cols;
};











Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/