10 #ifndef EIGEN_SPARSEVECTOR_H 11 #define EIGEN_SPARSEVECTOR_H 29 template<
typename _Scalar,
int _Options,
typename _Index>
39 RowsAtCompileTime = IsColVector ?
Dynamic : 1,
40 ColsAtCompileTime = IsColVector ? 1 : Dynamic,
41 MaxRowsAtCompileTime = RowsAtCompileTime,
42 MaxColsAtCompileTime = ColsAtCompileTime,
56 template<
typename Dest,
typename Src,
58 : Src::InnerSizeAtCompileTime==1 ?
SVA_Outer 64 template<
typename _Scalar,
int _Options,
typename _Index>
100 eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size));
101 return coeff(IsColVector ? row : col);
111 eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size));
112 return coeff(IsColVector ? row : col);
124 return m_data.atWithInsertion(i);
135 inline Index
nonZeros()
const {
return static_cast<Index
>(m_data.size()); }
147 return insertBack(inner);
152 return m_data.value(m_data.size()-1);
157 eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size));
159 Index inner = IsColVector ? row :
col;
160 Index outer = IsColVector ? col :
row;
162 return insert(inner);
169 Index p = Index(m_data.size()) - 1;
171 m_data.resize(p+2,1);
173 while ( (p >= startId) && (m_data.index(p) > i) )
175 m_data.index(p+1) = m_data.index(p);
176 m_data.value(p+1) = m_data.value(p);
179 m_data.index(p+1) = i;
180 m_data.value(p+1) = 0;
181 return m_data.value(p+1);
186 inline void reserve(Index reserveSize) { m_data.reserve(reserveSize); }
193 m_data.prune(reference,
epsilon);
199 resize(IsColVector ? rows : cols);
210 inline SparseVector() : m_size(0) { check_template_parameters(); resize(0); }
212 inline SparseVector(Index size) : m_size(0) { check_template_parameters(); resize(size); }
214 inline SparseVector(Index rows, Index cols) : m_size(0) { check_template_parameters(); resize(rows,cols); }
216 template<
typename OtherDerived>
220 check_template_parameters();
225 : SparseBase(other), m_size(0)
227 check_template_parameters();
237 std::swap(m_size, other.
m_size);
238 m_data.swap(other.
m_data);
249 resize(other.
size());
255 template<
typename OtherDerived>
264 #ifndef EIGEN_PARSED_BY_DOXYGEN 265 template<
typename Lhs,
typename Rhs>
268 return Base::operator=(product);
272 friend std::ostream & operator << (std::ostream & s,
const SparseVector& m)
274 for (Index i=0; i<m.
nonZeros(); ++i)
292 m_data.reserve(reserve);
299 return fill(IsColVector ? r : c);
306 return m_data.value(m_data.size()-1);
313 return fillrand(IsColVector ? r : c);
331 # ifdef EIGEN_SPARSEVECTOR_PLUGIN 332 # include EIGEN_SPARSEVECTOR_PLUGIN 347 template<
typename Scalar,
int _Options,
typename _Index>
352 : m_data(vec.m_data), m_id(0), m_end(static_cast<
Index>(m_data.size()))
359 : m_data(data), m_id(0), m_end(static_cast<
Index>(m_data.size()))
368 inline Index row()
const {
return IsColVector ? index() : 0; }
369 inline Index col()
const {
return IsColVector ? 0 : index(); }
371 inline operator bool()
const {
return (m_id < m_end); }
379 template<
typename Scalar,
int _Options,
typename _Index>
384 : m_data(vec.m_data), m_id(static_cast<
Index>(m_data.size())), m_start(0)
391 : m_data(data), m_id(static_cast<
Index>(m_data.size())), m_start(0)
400 inline Index row()
const {
return IsColVector ? index() : 0; }
401 inline Index col()
const {
return IsColVector ? 0 : index(); }
403 inline operator bool()
const {
return (m_id > m_start); }
413 template<
typename Dest,
typename Src>
415 static void run(Dest& dst,
const Src& src) {
417 for(
typename Src::InnerIterator it(src, 0); it; ++it)
418 dst.insert(it.index()) = it.value();
422 template<
typename Dest,
typename Src>
424 static void run(Dest& dst,
const Src& src) {
426 for(
typename Dest::Index i=0; i<src.size(); ++i)
428 typename Src::InnerIterator it(src, i);
430 dst.insert(i) = it.value();
435 template<
typename Dest,
typename Src>
437 static void run(Dest& dst,
const Src& src) {
447 #endif // EIGEN_SPARSEVECTOR_H
SparseVector(const SparseMatrixBase< OtherDerived > &other)
Scalar & coeffRef(Index row, Index col)
SparseVector & operator=(const SparseVector &other)
EIGEN_DEPRECATED Scalar & fillrand(Index i)
void resize(Index newSize)
#define EIGEN_STRONG_INLINE
const internal::CompressedStorage< Scalar, Index > & m_data
Scalar & insertBack(Index i)
EIGEN_STRONG_INLINE Index cols() const
ReverseInnerIterator(const SparseVector &vec, Index outer=0)
void resize(Index rows, Index cols)
const int InnerRandomAccessPattern
static void run(Dest &dst, const Src &src)
InnerIterator(const internal::CompressedStorage< Scalar, Index > &data)
Scalar coeff(Index i) const
#define EIGEN_UNUSED_VARIABLE(var)
const unsigned int LvalueBit
void startVec(Index outer)
void swap(SparseVector &other)
Scalar & insert(Index row, Index col)
Scalar & insertBackByOuterInner(Index outer, Index inner)
SparseVector & operator=(const SparseSparseProduct< Lhs, Rhs > &product)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
EIGEN_DEPRECATED Scalar & fill(Index i)
#define eigen_internal_assert(x)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
EIGEN_DEPRECATED Storage & _data()
EIGEN_DEPRECATED void startFill(Index reserve)
const unsigned int RowMajorBit
SparseVector(Index rows, Index cols)
void resizeNonZeros(Index size)
EIGEN_DEPRECATED const Storage & _data() const
EIGEN_STRONG_INLINE Index rows() const
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Base class of any sparse matrices or sparse expressions.
void prune(const Scalar &reference, const RealScalar &epsilon=NumTraits< RealScalar >::dummy_precision())
static void check_template_parameters()
internal::traits< SparseVector< _Scalar, _Options, _Index > >::Scalar Scalar
ReverseInnerIterator(const internal::CompressedStorage< Scalar, Index > &data)
EIGEN_DEPRECATED void endFill()
static void run(Dest &dst, const Src &src)
EIGEN_DEPRECATED Scalar & fillrand(Index r, Index c)
EIGEN_STRONG_INLINE Index innerSize() const
EIGEN_STRONG_INLINE Index * innerIndexPtr()
EIGEN_STRONG_INLINE Index outerSize() const
#define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op)
SparseMatrixBase< SparseVector > SparseBase
EIGEN_STRONG_INLINE Scalar * valuePtr()
SparseVector & operator=(const SparseMatrixBase< OtherDerived > &other)
static void run(Dest &dst, const Src &src)
internal::traits< Derived >::Index Index
SparseVector(const SparseVector &other)
const unsigned int NestByRefBit
const internal::CompressedStorage< Scalar, Index > & m_data
const Derived & derived() const
EIGEN_DEPRECATED Scalar & fill(Index r, Index c)
void reserve(Index reserveSize)
EIGEN_STRONG_INLINE const Index * innerIndexPtr() const
EIGEN_STRONG_INLINE const Scalar * valuePtr() const
Scalar & coeffRef(Index i)
ReverseInnerIterator & operator--()
NumTraits< Scalar >::Real RealScalar
InnerIterator & operator++()
const Storage & data() const
InnerIterator(const SparseVector &vec, Index outer=0)
Derived & const_cast_derived() const
Scalar coeff(Index row, Index col) const