mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Sparse module: add row/col methods to the iterators
This commit is contained in:
@@ -33,12 +33,12 @@
|
||||
*
|
||||
* todo
|
||||
*/
|
||||
// template<typename XprType> InnerIterator;
|
||||
|
||||
// generic version for dense matrix and expressions
|
||||
template<typename Derived> class MatrixBase<Derived>::InnerIterator
|
||||
{
|
||||
typedef typename Derived::Scalar Scalar;
|
||||
enum { IsRowMajor = (Derived::Flags&RowMajorBit)==RowMajorBit };
|
||||
public:
|
||||
EIGEN_STRONG_INLINE InnerIterator(const Derived& expr, int outer)
|
||||
: m_expression(expr), m_inner(0), m_outer(outer), m_end(expr.rows())
|
||||
@@ -46,13 +46,15 @@ template<typename Derived> class MatrixBase<Derived>::InnerIterator
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar value() const
|
||||
{
|
||||
return (Derived::Flags&RowMajorBit) ? m_expression.coeff(m_outer, m_inner)
|
||||
: m_expression.coeff(m_inner, m_outer);
|
||||
return (IsRowMajor) ? m_expression.coeff(m_outer, m_inner)
|
||||
: m_expression.coeff(m_inner, m_outer);
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE InnerIterator& operator++() { m_inner++; return *this; }
|
||||
|
||||
EIGEN_STRONG_INLINE int index() const { return m_inner; }
|
||||
inline int row() const { return IsRowMajor ? m_outer : index(); }
|
||||
inline int col() const { return IsRowMajor ? index() : m_outer; }
|
||||
|
||||
EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; }
|
||||
|
||||
@@ -63,230 +65,4 @@ template<typename Derived> class MatrixBase<Derived>::InnerIterator
|
||||
const int m_end;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess, int _DirectAccessStatus>
|
||||
class Block<MatrixType, BlockRows, BlockCols, PacketAccess, _DirectAccessStatus>::InnerIterator
|
||||
{
|
||||
typedef typename Block::Scalar Scalar;
|
||||
typedef typename ei_traits<Block>::_MatrixTypeNested _MatrixTypeNested;
|
||||
typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
|
||||
public:
|
||||
|
||||
EIGEN_STRONG_INLINE InnerIterator(const Block& block, int outer)
|
||||
: m_iter(block.m_matrix,(Block::Flags&RowMajor) ? block.m_startRow.value() + outer : block.m_startCol.value() + outer),
|
||||
m_start( (Block::Flags&RowMajor) ? block.m_startCol.value() : block.m_startRow.value()),
|
||||
m_end(m_start + ((Block::Flags&RowMajor) ? block.m_blockCols.value() : block.m_blockRows.value())),
|
||||
m_offset( (Block::Flags&RowMajor) ? block.m_startCol.value() : block.m_startRow.value())
|
||||
{
|
||||
while (m_iter.index()>=0 && m_iter.index()<m_start)
|
||||
++m_iter;
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE InnerIterator& operator++()
|
||||
{
|
||||
++m_iter;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
|
||||
|
||||
EIGEN_STRONG_INLINE int index() const { return m_iter.index() - m_offset; }
|
||||
|
||||
EIGEN_STRONG_INLINE operator bool() const { return m_iter && m_iter.index()<m_end; }
|
||||
|
||||
protected:
|
||||
MatrixTypeIterator m_iter;
|
||||
int m_start;
|
||||
int m_end;
|
||||
int m_offset;
|
||||
};
|
||||
|
||||
template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess>
|
||||
class Block<MatrixType, BlockRows, BlockCols, PacketAccess, IsSparse>::InnerIterator
|
||||
{
|
||||
typedef typename Block::Scalar Scalar;
|
||||
typedef typename ei_traits<Block>::_MatrixTypeNested _MatrixTypeNested;
|
||||
typedef typename _MatrixTypeNested::InnerIterator MatrixTypeIterator;
|
||||
public:
|
||||
|
||||
EIGEN_STRONG_INLINE InnerIterator(const Block& block, int outer)
|
||||
: m_iter(block.m_matrix,(Block::Flags&RowMajor) ? block.m_startRow.value() + outer : block.m_startCol.value() + outer),
|
||||
m_start( (Block::Flags&RowMajor) ? block.m_startCol.value() : block.m_startRow.value()),
|
||||
m_end(m_start + ((Block::Flags&RowMajor) ? block.m_blockCols.value() : block.m_blockRows.value())),
|
||||
m_offset( (Block::Flags&RowMajor) ? block.m_startCol.value() : block.m_startRow.value())
|
||||
{
|
||||
while (m_iter.index()>=0 && m_iter.index()<m_start)
|
||||
++m_iter;
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE InnerIterator& operator++()
|
||||
{
|
||||
++m_iter;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); }
|
||||
|
||||
EIGEN_STRONG_INLINE int index() const { return m_iter.index() - m_offset; }
|
||||
|
||||
EIGEN_STRONG_INLINE operator bool() const { return m_iter && m_iter.index()<m_end; }
|
||||
|
||||
protected:
|
||||
MatrixTypeIterator m_iter;
|
||||
int m_start;
|
||||
int m_end;
|
||||
int m_offset;
|
||||
};*/
|
||||
|
||||
/*
|
||||
template<typename T> struct ei_is_scalar_product { enum { ret = false }; };
|
||||
template<typename T> struct ei_is_scalar_product<ei_scalar_product_op<T> > { enum { ret = true }; };
|
||||
|
||||
template<typename BinaryOp, typename Lhs, typename Rhs, typename Derived>
|
||||
class CwiseBinaryOpInnerIterator;
|
||||
|
||||
template<typename BinaryOp, typename Lhs, typename Rhs>
|
||||
class CwiseBinaryOp<BinaryOp,Lhs,Rhs>::InnerIterator
|
||||
: public CwiseBinaryOpInnerIterator<BinaryOp,Lhs,Rhs, typename CwiseBinaryOp<BinaryOp,Lhs,Rhs>::InnerIterator>
|
||||
{
|
||||
typedef CwiseBinaryOpInnerIterator<
|
||||
BinaryOp,Lhs,Rhs, typename CwiseBinaryOp<BinaryOp,Lhs,Rhs>::InnerIterator> Base;
|
||||
public:
|
||||
typedef typename CwiseBinaryOp::Scalar Scalar;
|
||||
typedef typename ei_traits<CwiseBinaryOp>::_LhsNested _LhsNested;
|
||||
typedef typename _LhsNested::InnerIterator LhsIterator;
|
||||
typedef typename ei_traits<CwiseBinaryOp>::_RhsNested _RhsNested;
|
||||
typedef typename _RhsNested::InnerIterator RhsIterator;
|
||||
// public:
|
||||
EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOp& binOp, int outer)
|
||||
: Base(binOp.m_lhs,binOp.m_rhs,binOp.m_functor,outer)
|
||||
{}
|
||||
};*/
|
||||
/*
|
||||
template<typename BinaryOp, typename Lhs, typename Rhs, typename Derived>
|
||||
class CwiseBinaryOpInnerIterator
|
||||
{
|
||||
typedef CwiseBinaryOp<BinaryOp,Lhs,Rhs> ExpressionType;
|
||||
typedef typename ExpressionType::Scalar Scalar;
|
||||
typedef typename ei_traits<ExpressionType>::_LhsNested _LhsNested;
|
||||
// typedef typename ei_traits<ExpressionType>::LhsIterator LhsIterator;
|
||||
typedef typename ei_traits<ExpressionType>::_RhsNested _RhsNested;
|
||||
// typedef typename ei_traits<ExpressionType>::RhsIterator RhsIterator;
|
||||
// typedef typename ei_traits<CwiseBinaryOp>::_LhsNested _LhsNested;
|
||||
typedef typename _LhsNested::InnerIterator LhsIterator;
|
||||
// typedef typename ei_traits<CwiseBinaryOp>::_RhsNested _RhsNested;
|
||||
typedef typename _RhsNested::InnerIterator RhsIterator;
|
||||
// enum { IsProduct = ei_is_scalar_product<BinaryOp>::ret };
|
||||
public:
|
||||
|
||||
EIGEN_STRONG_INLINE CwiseBinaryOpInnerIterator(const _LhsNested& lhs, const _RhsNested& rhs,
|
||||
const BinaryOp& functor, int outer)
|
||||
: m_lhsIter(lhs,outer), m_rhsIter(rhs,outer), m_functor(functor), m_id(-1)
|
||||
{
|
||||
this->operator++();
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Derived& operator++()
|
||||
{
|
||||
if (m_lhsIter && m_rhsIter && (m_lhsIter.index() == m_rhsIter.index()))
|
||||
{
|
||||
m_id = m_lhsIter.index();
|
||||
m_value = m_functor(m_lhsIter.value(), m_rhsIter.value());
|
||||
++m_lhsIter;
|
||||
++m_rhsIter;
|
||||
}
|
||||
else if (m_lhsIter && (!m_rhsIter || (m_lhsIter.index() < m_rhsIter.index())))
|
||||
{
|
||||
m_id = m_lhsIter.index();
|
||||
m_value = m_functor(m_lhsIter.value(), Scalar(0));
|
||||
++m_lhsIter;
|
||||
}
|
||||
else if (m_rhsIter && (!m_lhsIter || (m_lhsIter.index() > m_rhsIter.index())))
|
||||
{
|
||||
m_id = m_rhsIter.index();
|
||||
m_value = m_functor(Scalar(0), m_rhsIter.value());
|
||||
++m_rhsIter;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_id = -1;
|
||||
}
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar value() const { return m_value; }
|
||||
|
||||
EIGEN_STRONG_INLINE int index() const { return m_id; }
|
||||
|
||||
EIGEN_STRONG_INLINE operator bool() const { return m_id>=0; }
|
||||
|
||||
protected:
|
||||
LhsIterator m_lhsIter;
|
||||
RhsIterator m_rhsIter;
|
||||
const BinaryOp& m_functor;
|
||||
Scalar m_value;
|
||||
int m_id;
|
||||
};
|
||||
|
||||
template<typename T, typename Lhs, typename Rhs, typename Derived>
|
||||
class CwiseBinaryOpInnerIterator<ei_scalar_product_op<T>,Lhs,Rhs,Derived>
|
||||
{
|
||||
typedef typename CwiseBinaryOp::Scalar Scalar;
|
||||
typedef typename ei_traits<CwiseBinaryOp>::_LhsNested _LhsNested;
|
||||
typedef typename _LhsNested::InnerIterator LhsIterator;
|
||||
typedef typename ei_traits<CwiseBinaryOp>::_RhsNested _RhsNested;
|
||||
typedef typename _RhsNested::InnerIterator RhsIterator;
|
||||
public:
|
||||
|
||||
EIGEN_STRONG_INLINE CwiseBinaryOpInnerIterator(const CwiseBinaryOp& binOp, int outer)
|
||||
: m_lhsIter(binOp.m_lhs,outer), m_rhsIter(binOp.m_rhs,outer), m_functor(binOp.m_functor)//, m_id(-1)
|
||||
{
|
||||
//this->operator++();
|
||||
while (m_lhsIter && m_rhsIter && m_lhsIter.index() != m_rhsIter.index())
|
||||
{
|
||||
if (m_lhsIter.index() < m_rhsIter.index())
|
||||
++m_lhsIter;
|
||||
else
|
||||
++m_rhsIter;
|
||||
}
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Derived& operator++()
|
||||
{
|
||||
// m_id = -1;
|
||||
asm("#beginwhile");
|
||||
while (m_lhsIter && m_rhsIter)
|
||||
{
|
||||
if (m_lhsIter.index() == m_rhsIter.index())
|
||||
{
|
||||
// m_id = m_lhsIter.index();
|
||||
//m_value = m_functor(m_lhsIter.value(), m_rhsIter.value());
|
||||
++m_lhsIter;
|
||||
++m_rhsIter;
|
||||
break;
|
||||
}
|
||||
else if (m_lhsIter.index() < m_rhsIter.index())
|
||||
++m_lhsIter;
|
||||
else
|
||||
++m_rhsIter;
|
||||
}
|
||||
asm("#endwhile");
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar value() const { return m_functor(m_lhsIter.value(), m_rhsIter.value()); }
|
||||
|
||||
EIGEN_STRONG_INLINE int index() const { return m_lhsIter.index(); }
|
||||
|
||||
EIGEN_STRONG_INLINE operator bool() const { return m_lhsIter && m_rhsIter; }
|
||||
|
||||
protected:
|
||||
LhsIterator m_lhsIter;
|
||||
RhsIterator m_rhsIter;
|
||||
const BinaryOp& m_functor;
|
||||
// Scalar m_value;
|
||||
// int m_id;
|
||||
};*/
|
||||
|
||||
#endif // EIGEN_COREITERATORS_H
|
||||
|
||||
Reference in New Issue
Block a user