// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
inline sparse_matrix_block_impl(SparseMatrixType& xpr, Index i)
: m_matrix(xpr), m_outerStart(convert_index(i)), m_outerSize(OuterSize)
{}
inline sparse_matrix_block_impl(SparseMatrixType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
: m_matrix(xpr), m_outerStart(convert_index(IsRowMajor ? startRow : startCol)), m_outerSize(convert_index(IsRowMajor ? blockRows : blockCols))
{}
template<typename OtherDerived> inline BlockType& operator=(const SparseMatrixBase<OtherDerived>& other)
{ typedeftypename internal::remove_all<typename SparseMatrixType::Nested>::type _NestedMatrixType;
_NestedMatrixType& matrix = m_matrix; // This assignment is slow if this vector set is not empty // and/or it is not at the end of the nonzeros of the underlying matrix.
// 1 - eval to a temporary to avoid transposition and/or aliasing issues
Ref<const SparseMatrix<Scalar, IsRowMajor ? RowMajor : ColMajor, StorageIndex> > tmp(other.derived());
eigen_internal_assert(tmp.outerSize()==m_outerSize.value());
// 2 - let's check whether there is enough allocated memory
Index nnz = tmp.nonZeros();
Index start = m_outerStart==0 ? 0 : m_matrix.outerIndexPtr()[m_outerStart]; // starting position of the current block
Index end = m_matrix.outerIndexPtr()[m_outerStart+m_outerSize.value()]; // ending position of the current block
Index block_size = end - start; // available room in the current block
Index tail_size = m_matrix.outerIndexPtr()[m_matrix.outerSize()] - end;
Index free_size = m_matrix.isCompressed()
? Index(matrix.data().allocatedSize()) + block_size
: block_size;
update_trailing_pointers = true;
} else
{ if(m_matrix.isCompressed() && nnz!=block_size)
{ // no need to realloc, simply copy the tail at its respective position and insert tmp
matrix.data().resize(start + nnz + tail_size);
typename internal::ref_selector<SparseMatrixType>::non_const_type m_matrix;
Index m_outerStart; const internal::variable_if_dynamic<Index, OuterSize> m_outerSize;
};
} // namespace internal
template<typename _Scalar, int _Options, typename _StorageIndex, int BlockRows, int BlockCols> class BlockImpl<SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true,Sparse>
: public internal::sparse_matrix_block_impl<SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols>
{ public: typedef _StorageIndex StorageIndex; typedef SparseMatrix<_Scalar, _Options, _StorageIndex> SparseMatrixType; typedef internal::sparse_matrix_block_impl<SparseMatrixType,BlockRows,BlockCols> Base; inline BlockImpl(SparseMatrixType& xpr, Index i)
: Base(xpr, i)
{}
inline BlockImpl(SparseMatrixType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
: Base(xpr, startRow, startCol, blockRows, blockCols)
{}
using Base::operator=;
};
template<typename _Scalar, int _Options, typename _StorageIndex, int BlockRows, int BlockCols> class BlockImpl<const SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols,true,Sparse>
: public internal::sparse_matrix_block_impl<const SparseMatrix<_Scalar, _Options, _StorageIndex>,BlockRows,BlockCols>
{ public: typedef _StorageIndex StorageIndex; typedefconst SparseMatrix<_Scalar, _Options, _StorageIndex> SparseMatrixType; typedef internal::sparse_matrix_block_impl<SparseMatrixType,BlockRows,BlockCols> Base; inline BlockImpl(SparseMatrixType& xpr, Index i)
: Base(xpr, i)
{}
inline BlockImpl(SparseMatrixType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
: Base(xpr, startRow, startCol, blockRows, blockCols)
{}
using Base::operator=; private: template<typename Derived> BlockImpl(const SparseMatrixBase<Derived>& xpr, Index i); template<typename Derived> BlockImpl(const SparseMatrixBase<Derived>& xpr);
};
//----------
/** Generic implementation of sparse Block expression. * Real-only.
*/ template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> class BlockImpl<XprType,BlockRows,BlockCols,InnerPanel,Sparse>
: public SparseMatrixBase<Block<XprType,BlockRows,BlockCols,InnerPanel> >, internal::no_assignment_operator
{ typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType; typedef SparseMatrixBase<BlockType> Base; using Base::convert_index; public: enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor };
EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType)
protected: // Disable assignment with clear error message. // Note that simply removing operator= yields compilation errors with ICC+MSVC template<typename T>
BlockImpl& operator=(const T&)
{
EIGEN_STATIC_ASSERT(sizeof(T)==0, THIS_SPARSE_BLOCK_SUBEXPRESSION_IS_READ_ONLY); return *this;
}
};
namespace internal {
template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> struct unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBased >
: public evaluator_base<Block<ArgType,BlockRows,BlockCols,InnerPanel> >
{ class InnerVectorInnerIterator; class OuterVectorInnerIterator; public: typedef Block<ArgType,BlockRows,BlockCols,InnerPanel> XprType; typedeftypename XprType::StorageIndex StorageIndex; typedeftypename XprType::Scalar Scalar;
enum {
IsRowMajor = XprType::IsRowMajor,
OuterVector = (BlockCols==1 && ArgType::IsRowMajor)
| // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&". // revert to || as soon as not needed anymore.
(BlockRows==1 && !ArgType::IsRowMajor),
template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> class unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBased>::InnerVectorInnerIterator
: public EvalIterator
{ // NOTE MSVC fails to compile if we don't explicitely "import" IsRowMajor from unary_evaluator // because the base class EvalIterator has a private IsRowMajor enum too. (bug #1786) // NOTE We cannot call it IsRowMajor because it would shadow unary_evaluator::IsRowMajor enum { XprIsRowMajor = unary_evaluator::IsRowMajor }; const XprType& m_block;
Index m_end; public:
template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel> class unary_evaluator<Block<ArgType,BlockRows,BlockCols,InnerPanel>, IteratorBased>::OuterVectorInnerIterator
{ // NOTE see above enum { XprIsRowMajor = unary_evaluator::IsRowMajor }; const unary_evaluator& m_eval;
Index m_outerPos; const Index m_innerIndex;
Index m_end;
EvalIterator m_it; public:
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.