// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008-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/.
/** \ingroup SparseCore_Module * \class SparseVector * * \brief a sparse vector class * * \tparam _Scalar the scalar type, i.e. the type of the coefficients * * See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme. * * This class can be extended with the help of the plugin mechanism described on the page * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_SPARSEVECTOR_PLUGIN.
*/
/** \returns a reference to the coefficient value at given index \a i * This operation involes a log(rho*size) binary search. If the coefficient does not * exist yet, then a sorted insertion into a sequential buffer is performed. * * This insertion might be very costly if the number of nonzeros above \a i is large.
*/ inline Scalar& coeffRef(Index i)
{
eigen_assert(i>=0 && i<m_size);
/** Resizes the sparse vector to \a rows x \a cols * * This method is provided for compatibility with matrices. * For a column vector, \a cols must be equal to 1. * For a row vector, \a rows must be equal to 1. * * \sa resize(Index)
*/ void resize(Index rows, Index cols)
{
eigen_assert((IsColVector ? cols : rows)==1 && "Outer dimension must equal 1");
resize(IsColVector ? rows : cols);
}
/** Resizes the sparse vector to \a newSize * This method deletes all entries, thus leaving an empty sparse vector *
* \sa conservativeResize(), setZero() */ void resize(Index newSize)
{
m_size = newSize;
m_data.clear();
}
/** Resizes the sparse vector to \a newSize, while leaving old values untouched. * * If the size of the vector is decreased, then the storage of the out-of bounds coefficients is kept and reserved. * Call .data().squeeze() to free extra memory. * * \sa reserve(), setZero()
*/ void conservativeResize(Index newSize)
{ if (newSize < m_size)
{
Index i = 0; while (i<m_data.size() && m_data.index(i)<newSize) ++i;
m_data.resize(i);
}
m_size = newSize;
}
/** Swaps the values of \c *this and \a other. * Overloaded for performance: this version performs a \em shallow swap by swapping pointers and attributes only. * \sa SparseMatrixBase::swap()
*/ inlinevoid swap(SparseVector& other)
{
std::swap(m_size, other.m_size);
m_data.swap(other.m_data);
}
/** \internal \deprecated use finalize() */
EIGEN_DEPRECATED void endFill() {}
// These two functions were here in the 3.1 release, so let's keep them in case some code rely on them. /** \internal \deprecated use data() */
EIGEN_DEPRECATED Storage& _data() { return m_data; } /** \internal \deprecated use data() */
EIGEN_DEPRECATED const Storage& _data() const { return m_data; }
# ifdef EIGEN_SPARSEVECTOR_PLUGIN # include EIGEN_SPARSEVECTOR_PLUGIN # endif
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.