68 using Base::convert_index;
71 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(
SparseVector, +=)
72 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(
SparseVector, -=)
81 EIGEN_STRONG_INLINE Index rows()
const {
return IsColVector ? m_size : 1; }
82 EIGEN_STRONG_INLINE Index cols()
const {
return IsColVector ? 1 : m_size; }
83 EIGEN_STRONG_INLINE Index innerSize()
const {
return m_size; }
84 EIGEN_STRONG_INLINE Index outerSize()
const {
return 1; }
86 EIGEN_STRONG_INLINE
const Scalar* valuePtr()
const {
return &m_data.value(0); }
87 EIGEN_STRONG_INLINE Scalar* valuePtr() {
return &m_data.value(0); }
89 EIGEN_STRONG_INLINE
const StorageIndex* innerIndexPtr()
const {
return &m_data.index(0); }
90 EIGEN_STRONG_INLINE StorageIndex* innerIndexPtr() {
return &m_data.index(0); }
92 inline const StorageIndex* outerIndexPtr()
const {
return 0; }
93 inline StorageIndex* outerIndexPtr() {
return 0; }
94 inline const StorageIndex* innerNonZeroPtr()
const {
return 0; }
95 inline StorageIndex* innerNonZeroPtr() {
return 0; }
98 inline Storage& data() {
return m_data; }
100 inline const Storage& data()
const {
return m_data; }
102 inline Scalar coeff(Index row, Index col)
const
104 eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size));
105 return coeff(IsColVector ? row : col);
107 inline Scalar coeff(Index i)
const
109 eigen_assert(i>=0 && i<m_size);
110 return m_data.
at(StorageIndex(i));
113 inline Scalar& coeffRef(Index row, Index col)
115 eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size));
116 return coeffRef(IsColVector ? row : col);
127 eigen_assert(i>=0 && i<m_size);
134 typedef typename Base::ReverseInnerIterator ReverseInnerIterator;
136 inline void setZero() { m_data.clear(); }
139 inline Index
nonZeros()
const {
return m_data.size(); }
141 inline void startVec(Index outer)
143 EIGEN_UNUSED_VARIABLE(outer);
144 eigen_assert(outer==0);
147 inline Scalar& insertBackByOuterInner(Index outer, Index inner)
149 EIGEN_UNUSED_VARIABLE(outer);
150 eigen_assert(outer==0);
151 return insertBack(inner);
153 inline Scalar& insertBack(Index i)
156 return m_data.value(m_data.size()-1);
159 Scalar& insertBackByOuterInnerUnordered(Index outer, Index inner)
161 EIGEN_UNUSED_VARIABLE(outer);
162 eigen_assert(outer==0);
163 return insertBackUnordered(inner);
165 inline Scalar& insertBackUnordered(Index i)
168 return m_data.value(m_data.size()-1);
171 inline Scalar& insert(Index row, Index col)
173 eigen_assert(IsColVector ? (col==0 && row>=0 && row<m_size) : (row==0 && col>=0 && col<m_size));
175 Index inner = IsColVector ? row : col;
176 Index outer = IsColVector ? col : row;
177 EIGEN_ONLY_USED_FOR_DEBUG(outer);
178 eigen_assert(outer==0);
179 return insert(inner);
181 Scalar& insert(Index i)
183 eigen_assert(i>=0 && i<m_size);
188 m_data.resize(p+2,1);
190 while ( (p >= startId) && (m_data.index(p) > i) )
192 m_data.index(p+1) = m_data.index(p);
193 m_data.value(p+1) = m_data.value(p);
196 m_data.index(p+1) = convert_index(i);
197 m_data.value(p+1) = 0;
198 return m_data.value(p+1);
203 inline void reserve(Index reserveSize) { m_data.reserve(reserveSize); }
206 inline void finalize() {}
208 void prune(
const Scalar& reference,
const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision())
210 m_data.prune(reference,epsilon);
213 void resize(Index rows, Index cols)
215 eigen_assert((IsColVector ? cols : rows)==1 &&
"Outer dimension must equal 1");
216 resize(IsColVector ? rows : cols);
219 void resize(Index newSize)
225 void resizeNonZeros(Index
size) { m_data.resize(
size); }
227 inline SparseVector() : m_size(0) { check_template_parameters(); resize(0); }
229 explicit inline SparseVector(Index
size) : m_size(0) { check_template_parameters(); resize(
size); }
231 inline SparseVector(Index rows, Index cols) : m_size(0) { check_template_parameters(); resize(rows,cols); }
233 template<
typename OtherDerived>
234 inline SparseVector(
const SparseMatrixBase<OtherDerived>& other)
237 #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
238 EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
240 check_template_parameters();
241 *
this = other.derived();
244 inline SparseVector(
const SparseVector& other)
245 : Base(other), m_size(0)
247 check_template_parameters();
248 *
this = other.derived();
258 m_data.swap(other.m_data);
263 if (other.isRValue())
265 swap(other.const_cast_derived());
269 resize(other.
size());
270 m_data = other.m_data;
275 template<
typename OtherDerived>
276 inline SparseVector& operator=(
const SparseMatrixBase<OtherDerived>& other)
278 SparseVector tmp(other.size());
279 internal::sparse_vector_assign_selector<SparseVector,OtherDerived>::run(tmp,other.derived());
284 #ifndef EIGEN_PARSED_BY_DOXYGEN
285 template<
typename Lhs,
typename Rhs>
286 inline SparseVector& operator=(
const SparseSparseProduct<Lhs,Rhs>& product)
288 return Base::operator=(product);
292 friend std::ostream & operator << (std::ostream & s,
const SparseVector& m)
294 for (Index i=0; i<m.nonZeros(); ++i)
295 s <<
"(" << m.m_data.value(i) <<
"," << m.m_data.index(i) <<
") ";
309 EIGEN_DEPRECATED
void startFill(Index reserve)
312 m_data.reserve(reserve);
316 EIGEN_DEPRECATED Scalar& fill(Index r, Index c)
318 eigen_assert(r==0 || c==0);
319 return fill(IsColVector ? r : c);
323 EIGEN_DEPRECATED Scalar& fill(Index i)
326 return m_data.value(m_data.size()-1);
330 EIGEN_DEPRECATED Scalar& fillrand(Index r, Index c)
332 eigen_assert(r==0 || c==0);
333 return fillrand(IsColVector ? r : c);
337 EIGEN_DEPRECATED Scalar& fillrand(Index i)
343 EIGEN_DEPRECATED
void endFill() {}
347 EIGEN_DEPRECATED Storage& _data() {
return m_data; }
349 EIGEN_DEPRECATED
const Storage& _data()
const {
return m_data; }
351# ifdef EIGEN_SPARSEVECTOR_PLUGIN
352# include EIGEN_SPARSEVECTOR_PLUGIN
357 static void check_template_parameters()
359 EIGEN_STATIC_ASSERT(NumTraits<StorageIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE);
360 EIGEN_STATIC_ASSERT((_Options&(
ColMajor|
RowMajor))==Options,INVALID_MATRIX_TEMPLATE_PARAMETERS);