// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2015 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/.
template<typename Derived, int Level = internal::accessors_level<Derived>::has_write_access ? WriteAccessors : ReadOnlyAccessors
> class SparseMapBase;
/** \ingroup SparseCore_Module * class SparseMapBase * \brief Common base class for Map and Ref instance of sparse matrix and vector.
*/ template<typename Derived> class SparseMapBase<Derived,ReadOnlyAccessors>
: public SparseCompressedBase<Derived>
{ public: typedef SparseCompressedBase<Derived> Base; typedeftypename Base::Scalar Scalar; typedeftypename Base::StorageIndex StorageIndex; enum { IsRowMajor = Base::IsRowMajor }; using Base::operator=; protected:
/** \copydoc SparseMatrix::coeff */ inline Scalar coeff(Index row, Index col) const
{ const Index outer = IsRowMajor ? row : col; const Index inner = IsRowMajor ? col : row;
Index start = m_outerIndex[outer];
Index end = isCompressed() ? m_outerIndex[outer+1] : start + m_innerNonZeros[outer]; if (start==end) return Scalar(0); elseif (end>0 && inner==m_innerIndices[end-1]) return m_values[end-1]; // ^^ optimization: let's first check if it is the last coefficient // (very common in high level algorithms)
const StorageIndex* r = std::lower_bound(&m_innerIndices[start],&m_innerIndices[end-1],inner); const Index id = r-&m_innerIndices[0]; return ((*r==inner) && (id<end)) ? m_values[id] : Scalar(0);
}
/** \ingroup SparseCore_Module * class SparseMapBase * \brief Common base class for writable Map and Ref instance of sparse matrix and vector.
*/ template<typename Derived> class SparseMapBase<Derived,WriteAccessors>
: public SparseMapBase<Derived,ReadOnlyAccessors>
{ typedef MapBase<Derived, ReadOnlyAccessors> ReadOnlyMapBase;
/** \copydoc SparseMatrix::coeffRef */ inline Scalar& coeffRef(Index row, Index col)
{ const Index outer = IsRowMajor ? row : col; const Index inner = IsRowMajor ? col : row;
Index start = Base::m_outerIndex[outer];
Index end = Base::isCompressed() ? Base::m_outerIndex[outer+1] : start + Base::m_innerNonZeros[outer];
eigen_assert(end>=start && "you probably called coeffRef on a non finalized matrix");
eigen_assert(end>start && "coeffRef cannot be called on a zero coefficient");
StorageIndex* r = std::lower_bound(&Base::m_innerIndices[start],&Base::m_innerIndices[end],inner); const Index id = r - &Base::m_innerIndices[0];
eigen_assert((*r==inner) && (id<end) && "coeffRef cannot be called on a zero coefficient"); returnconst_cast<Scalar*>(Base::m_values)[id];
}
/** \ingroup SparseCore_Module * * \brief Specialization of class Map for SparseMatrix-like storage. * * \tparam SparseMatrixType the equivalent sparse matrix type of the referenced data, it must be a template instance of class SparseMatrix. * * \sa class Map, class SparseMatrix, class Ref<SparseMatrixType,Options>
*/ #ifndef EIGEN_PARSED_BY_DOXYGEN template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> class Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
: public SparseMapBase<Map<SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> > #else template<typename SparseMatrixType> class Map<SparseMatrixType>
: public SparseMapBase<Derived,WriteAccessors> #endif
{ public: typedef SparseMapBase<Map> Base;
EIGEN_SPARSE_PUBLIC_INTERFACE(Map) enum { IsRowMajor = Base::IsRowMajor };
public:
/** Constructs a read-write Map to a sparse matrix of size \a rows x \a cols, containing \a nnz non-zero coefficients, * stored as a sparse format as defined by the pointers \a outerIndexPtr, \a innerIndexPtr, and \a valuePtr. * If the optional parameter \a innerNonZerosPtr is the null pointer, then a standard compressed format is assumed. * * This constructor is available only if \c SparseMatrixType is non-const. * * More details on the expected storage schemes are given in the \ref TutorialSparse "manual pages".
*/ inline Map(Index rows, Index cols, Index nnz, StorageIndex* outerIndexPtr,
StorageIndex* innerIndexPtr, Scalar* valuePtr, StorageIndex* innerNonZerosPtr = 0)
: Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
{} #ifndef EIGEN_PARSED_BY_DOXYGEN /** Empty destructor */ inline ~Map() {}
};
template<typename MatScalar, int MatOptions, typename MatIndex, int Options, typename StrideType> class Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType>
: public SparseMapBase<Map<const SparseMatrix<MatScalar,MatOptions,MatIndex>, Options, StrideType> >
{ public: typedef SparseMapBase<Map> Base;
EIGEN_SPARSE_PUBLIC_INTERFACE(Map) enum { IsRowMajor = Base::IsRowMajor };
public: #endif /** This is the const version of the above constructor. * * This constructor is available only if \c SparseMatrixType is const, e.g.: * \code Map<const SparseMatrix<double> > \endcode
*/ inline Map(Index rows, Index cols, Index nnz, const StorageIndex* outerIndexPtr, const StorageIndex* innerIndexPtr, const Scalar* valuePtr, const StorageIndex* innerNonZerosPtr = 0)
: Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZerosPtr)
{}
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.