mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-02-23 18:20:47 +08:00
Make Block<SparseMatrix> inherit SparseCompressedBase in the case of an inner-panels and fix valuePtr() innerIndexPtr()
This commit is contained in:
parent
554aa9b31d
commit
d4ec48575e
@ -87,7 +87,7 @@ struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprTyp
|
||||
// FIXME, this traits is rather specialized for dense object and it needs to be cleaned further
|
||||
FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
|
||||
FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
|
||||
Flags = (traits<XprType>::Flags & DirectAccessBit) | FlagsLvalueBit | FlagsRowMajorBit
|
||||
Flags = (traits<XprType>::Flags & (DirectAccessBit | (InnerPanel?CompressedAccessBit:0))) | FlagsLvalueBit | FlagsRowMajorBit
|
||||
// FIXME DirectAccessBit should not be handled by expressions
|
||||
};
|
||||
};
|
||||
|
@ -74,7 +74,7 @@ namespace internal {
|
||||
|
||||
template<typename SparseMatrixType, int BlockRows, int BlockCols>
|
||||
class sparse_matrix_block_impl
|
||||
: public SparseMatrixBase<Block<SparseMatrixType,BlockRows,BlockCols,true> >
|
||||
: public SparseCompressedBase<Block<SparseMatrixType,BlockRows,BlockCols,true> >
|
||||
{
|
||||
typedef typename internal::remove_all<typename SparseMatrixType::Nested>::type _MatrixTypeNested;
|
||||
typedef Block<SparseMatrixType, BlockRows, BlockCols, true> BlockType;
|
||||
@ -172,19 +172,24 @@ public:
|
||||
}
|
||||
|
||||
inline const Scalar* valuePtr() const
|
||||
{ return m_matrix.valuePtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
|
||||
{ return m_matrix.valuePtr(); }
|
||||
inline Scalar* valuePtr()
|
||||
{ return m_matrix.const_cast_derived().valuePtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
|
||||
{ return m_matrix.const_cast_derived().valuePtr(); }
|
||||
|
||||
inline const Index* innerIndexPtr() const
|
||||
{ return m_matrix.innerIndexPtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
|
||||
{ return m_matrix.innerIndexPtr(); }
|
||||
inline Index* innerIndexPtr()
|
||||
{ return m_matrix.const_cast_derived().innerIndexPtr() + m_matrix.outerIndexPtr()[m_outerStart]; }
|
||||
{ return m_matrix.const_cast_derived().innerIndexPtr(); }
|
||||
|
||||
inline const Index* outerIndexPtr() const
|
||||
{ return m_matrix.outerIndexPtr() + m_outerStart; }
|
||||
inline Index* outerIndexPtr()
|
||||
{ return m_matrix.const_cast_derived().outerIndexPtr() + m_outerStart; }
|
||||
|
||||
inline const Index* innerNonZeroPtr() const
|
||||
{ return isCompressed() ? 0 : m_matrix.innerNonZeroPtr(); }
|
||||
inline Index* innerNonZeroPtr()
|
||||
{ return isCompressed() ? 0 : m_matrix.const_cast_derived().innerNonZeroPtr(); }
|
||||
|
||||
Index nonZeros() const
|
||||
{
|
||||
@ -196,6 +201,8 @@ public:
|
||||
else
|
||||
return Map<const Matrix<Index,OuterSize,1> >(m_matrix.innerNonZeroPtr()+m_outerStart, m_outerSize.value()).sum();
|
||||
}
|
||||
|
||||
bool isCompressed() const { return m_matrix.innerNonZeroPtr()==0; }
|
||||
|
||||
const Scalar& lastCoeff() const
|
||||
{
|
||||
|
@ -51,8 +51,8 @@ void call_ref()
|
||||
{
|
||||
// SparseVector<std::complex<float> > ca = VectorXcf::Random(10).sparseView();
|
||||
// SparseVector<float> a = VectorXf::Random(10).sparseView();
|
||||
SparseMatrix<float> A = MatrixXf::Random(10,10).sparseView();
|
||||
SparseMatrix<float,RowMajor> B = MatrixXf::Random(10,10).sparseView();
|
||||
SparseMatrix<float> A = MatrixXf::Random(10,10).sparseView(0.5,1);
|
||||
SparseMatrix<float,RowMajor> B = MatrixXf::Random(10,10).sparseView(0.5,1);
|
||||
const SparseMatrix<float>& Ac(A);
|
||||
Block<SparseMatrix<float> > Ab(A,0,1, 3,3);
|
||||
const Block<SparseMatrix<float> > Abc(A,0,1,3,3);
|
||||
@ -82,7 +82,9 @@ void call_ref()
|
||||
// VERIFY_EVALUATION_COUNT( call_ref_1(Arc, Arc), 0); // does not compile on purpose
|
||||
VERIFY_EVALUATION_COUNT( call_ref_2(Arc, Arc), 0);
|
||||
|
||||
VERIFY_EVALUATION_COUNT( call_ref_2(A.middleCols(1,3), A.middleCols(1,3)), 1); // should be 0
|
||||
VERIFY_EVALUATION_COUNT( call_ref_2(A.middleCols(1,3), A.middleCols(1,3)), 0);
|
||||
|
||||
VERIFY_EVALUATION_COUNT( call_ref_2(A.col(2), A.col(2)), 0);
|
||||
|
||||
VERIFY_EVALUATION_COUNT( call_ref_2(A.block(1,1,3,3), A.block(1,1,3,3)), 1); // should be 0 (allocate starts/nnz only)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user