10 #ifndef EIGEN_SPARSEMATRIX_H 11 #define EIGEN_SPARSEMATRIX_H 42 template<
typename _Scalar,
int _Options,
typename _Index>
47 typedef Sparse StorageKind;
54 Flags = _Options | NestByRefBit |
LvalueBit,
56 SupportedAccessPatterns = InnerRandomAccessPattern
60 template<
typename _Scalar,
int _Options,
typename _Index,
int DiagIndex>
74 ColsAtCompileTime = 1,
76 MaxColsAtCompileTime = 1,
78 CoeffReadCost = _MatrixTypeNested::CoeffReadCost*10
84 template<
typename _Scalar,
int _Options,
typename _Index>
90 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(
SparseMatrix, +=)
91 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(
SparseMatrix, -=)
94 using Base::IsRowMajor;
107 Index* m_innerNonZeros;
119 inline Index
rows()
const {
return IsRowMajor ? m_outerSize : m_innerSize; }
121 inline Index
cols()
const {
return IsRowMajor ? m_innerSize : m_outerSize; }
131 inline const Scalar*
valuePtr()
const {
return &m_data.value(0); }
135 inline Scalar*
valuePtr() {
return &m_data.value(0); }
165 inline Storage& data() {
return m_data; }
167 inline const Storage& data()
const {
return m_data; }
171 inline Scalar
coeff(Index row, Index col)
const 173 eigen_assert(row>=0 && row<rows() && col>=0 && col<cols());
175 const Index outer = IsRowMajor ? row : col;
176 const Index inner = IsRowMajor ? col : row;
177 Index end = m_innerNonZeros ? m_outerIndex[outer] + m_innerNonZeros[outer] : m_outerIndex[outer+1];
178 return m_data.
atInRange(m_outerIndex[outer], end, inner);
191 eigen_assert(row>=0 && row<rows() && col>=0 && col<cols());
193 const Index outer = IsRowMajor ? row : col;
194 const Index inner = IsRowMajor ? col : row;
196 Index start = m_outerIndex[outer];
197 Index end = m_innerNonZeros ? m_outerIndex[outer] + m_innerNonZeros[outer] : m_outerIndex[outer+1];
198 eigen_assert(end>=start &&
"you probably called coeffRef on a non finalized matrix");
200 return insert(row,col);
202 if((p<end) && (m_data.index(p)==inner))
203 return m_data.value(p);
205 return insert(row,col);
222 eigen_assert(row>=0 && row<rows() && col>=0 && col<cols());
228 return insertUncompressed(row,col);
234 class ReverseInnerIterator;
240 memset(m_outerIndex, 0, (m_outerSize+1)*
sizeof(Index));
242 memset(m_innerNonZeros, 0, (m_outerSize)*
sizeof(Index));
249 return innerNonZeros().sum();
250 return static_cast<Index
>(m_data.size());
258 eigen_assert(isCompressed() &&
"This function does not make sense in non compressed mode.");
259 m_data.reserve(reserveSize);
262 #ifdef EIGEN_PARSED_BY_DOXYGEN 266 template<
class SizesType>
267 inline void reserve(
const SizesType& reserveSizes);
269 template<
class SizesType>
270 inline void reserve(
const SizesType& reserveSizes,
const typename SizesType::value_type& enableif =
typename SizesType::value_type())
272 EIGEN_UNUSED_VARIABLE(enableif);
273 reserveInnerVectors(reserveSizes);
275 template<
class SizesType>
276 inline void reserve(
const SizesType& reserveSizes,
const typename SizesType::Scalar& enableif =
277 #
if (!defined(_MSC_VER)) || (_MSC_VER>=1500)
282 EIGEN_UNUSED_VARIABLE(enableif);
283 reserveInnerVectors(reserveSizes);
285 #endif // EIGEN_PARSED_BY_DOXYGEN 287 template<
class SizesType>
288 inline void reserveInnerVectors(
const SizesType& reserveSizes)
292 std::size_t totalReserveSize = 0;
294 m_innerNonZeros =
static_cast<Index*
>(std::malloc(m_outerSize *
sizeof(Index)));
295 if (!m_innerNonZeros) internal::throw_std_bad_alloc();
298 Index* newOuterIndex = m_innerNonZeros;
301 for(Index j=0; j<m_outerSize; ++j)
303 newOuterIndex[j] = count;
304 count += reserveSizes[j] + (m_outerIndex[j+1]-m_outerIndex[j]);
305 totalReserveSize += reserveSizes[j];
307 m_data.reserve(totalReserveSize);
308 Index previousOuterIndex = m_outerIndex[m_outerSize];
309 for(Index j=m_outerSize-1; j>=0; --j)
311 Index innerNNZ = previousOuterIndex - m_outerIndex[j];
312 for(Index i=innerNNZ-1; i>=0; --i)
314 m_data.index(newOuterIndex[j]+i) = m_data.index(m_outerIndex[j]+i);
315 m_data.value(newOuterIndex[j]+i) = m_data.value(m_outerIndex[j]+i);
317 previousOuterIndex = m_outerIndex[j];
318 m_outerIndex[j] = newOuterIndex[j];
319 m_innerNonZeros[j] = innerNNZ;
321 m_outerIndex[m_outerSize] = m_outerIndex[m_outerSize-1] + m_innerNonZeros[m_outerSize-1] + reserveSizes[m_outerSize-1];
323 m_data.resize(m_outerIndex[m_outerSize]);
327 Index* newOuterIndex =
static_cast<Index*
>(std::malloc((m_outerSize+1)*
sizeof(Index)));
328 if (!newOuterIndex) internal::throw_std_bad_alloc();
331 for(Index j=0; j<m_outerSize; ++j)
333 newOuterIndex[j] = count;
334 Index alreadyReserved = (m_outerIndex[j+1]-m_outerIndex[j]) - m_innerNonZeros[j];
335 Index toReserve = std::max<Index>(reserveSizes[j], alreadyReserved);
336 count += toReserve + m_innerNonZeros[j];
338 newOuterIndex[m_outerSize] = count;
340 m_data.resize(count);
341 for(Index j=m_outerSize-1; j>=0; --j)
343 Index offset = newOuterIndex[j] - m_outerIndex[j];
346 Index innerNNZ = m_innerNonZeros[j];
347 for(Index i=innerNNZ-1; i>=0; --i)
349 m_data.index(newOuterIndex[j]+i) = m_data.index(m_outerIndex[j]+i);
350 m_data.value(newOuterIndex[j]+i) = m_data.value(m_outerIndex[j]+i);
355 std::swap(m_outerIndex, newOuterIndex);
356 std::free(newOuterIndex);
374 inline Scalar& insertBack(Index row, Index col)
376 return insertBackByOuterInner(IsRowMajor?row:col, IsRowMajor?col:row);
381 inline Scalar& insertBackByOuterInner(Index outer, Index inner)
383 eigen_assert(
size_t(m_outerIndex[outer+1]) == m_data.size() &&
"Invalid ordered insertion (invalid outer index)");
384 eigen_assert( (m_outerIndex[outer+1]-m_outerIndex[outer]==0 || m_data.index(m_data.size()-1)<inner) &&
"Invalid ordered insertion (invalid inner index)");
385 Index p = m_outerIndex[outer+1];
386 ++m_outerIndex[outer+1];
387 m_data.append(0, inner);
388 return m_data.value(p);
393 inline Scalar& insertBackByOuterInnerUnordered(Index outer, Index inner)
395 Index p = m_outerIndex[outer+1];
396 ++m_outerIndex[outer+1];
397 m_data.append(0, inner);
398 return m_data.value(p);
403 inline void startVec(Index outer)
405 eigen_assert(m_outerIndex[outer]==Index(m_data.size()) &&
"You must call startVec for each inner vector sequentially");
406 eigen_assert(m_outerIndex[outer+1]==0 &&
"You must call startVec for each inner vector sequentially");
407 m_outerIndex[outer+1] = m_outerIndex[outer];
413 inline void finalize()
417 Index
size =
static_cast<Index
>(m_data.size());
418 Index i = m_outerSize;
420 while (i>=0 && m_outerIndex[i]==0)
423 while (i<=m_outerSize)
425 m_outerIndex[i] =
size;
433 template<
typename InputIterators>
434 void setFromTriplets(
const InputIterators& begin,
const InputIterators& end);
436 void sumupDuplicates();
442 Scalar& insertByOuterInner(Index j, Index i)
444 return insert(IsRowMajor ? j : i, IsRowMajor ? i : j);
454 Index oldStart = m_outerIndex[1];
455 m_outerIndex[1] = m_innerNonZeros[0];
456 for(Index j=1; j<m_outerSize; ++j)
458 Index nextOldStart = m_outerIndex[j+1];
459 Index offset = oldStart - m_outerIndex[j];
462 for(Index k=0; k<m_innerNonZeros[j]; ++k)
464 m_data.index(m_outerIndex[j]+k) = m_data.index(oldStart+k);
465 m_data.value(m_outerIndex[j]+k) = m_data.value(oldStart+k);
468 m_outerIndex[j+1] = m_outerIndex[j] + m_innerNonZeros[j];
469 oldStart = nextOldStart;
471 std::free(m_innerNonZeros);
473 m_data.resize(m_outerIndex[m_outerSize]);
480 if(m_innerNonZeros != 0)
482 m_innerNonZeros =
static_cast<Index*
>(std::malloc(m_outerSize *
sizeof(Index)));
483 for (Index i = 0; i < m_outerSize; i++)
485 m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i];
492 prune(default_prunning_func(reference,epsilon));
502 template<
typename KeepFunc>
503 void prune(
const KeepFunc& keep = KeepFunc())
510 for(Index j=0; j<m_outerSize; ++j)
512 Index previousStart = m_outerIndex[j];
514 Index end = m_outerIndex[j+1];
515 for(Index i=previousStart; i<end; ++i)
517 if(keep(IsRowMajor?j:m_data.index(i), IsRowMajor?m_data.index(i):j, m_data.value(i)))
519 m_data.value(k) = m_data.value(i);
520 m_data.index(k) = m_data.index(i);
525 m_outerIndex[m_outerSize] = k;
535 if (this->rows() == rows && this->cols() == cols)
return;
538 if(rows==0 || cols==0)
return resize(rows,cols);
540 Index innerChange = IsRowMajor ? cols - this->cols() : rows - this->rows();
541 Index outerChange = IsRowMajor ? rows - this->rows() : cols - this->cols();
542 Index newInnerSize = IsRowMajor ? cols : rows;
548 Index *newInnerNonZeros =
static_cast<Index*
>(std::realloc(m_innerNonZeros, (m_outerSize + outerChange) *
sizeof(Index)));
549 if (!newInnerNonZeros) internal::throw_std_bad_alloc();
550 m_innerNonZeros = newInnerNonZeros;
552 for(Index i=m_outerSize; i<m_outerSize+outerChange; i++)
553 m_innerNonZeros[i] = 0;
555 else if (innerChange < 0)
558 m_innerNonZeros =
static_cast<Index*
>(std::malloc((m_outerSize+outerChange+1) *
sizeof(Index)));
559 if (!m_innerNonZeros) internal::throw_std_bad_alloc();
560 for(Index i = 0; i < m_outerSize; i++)
561 m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i];
565 if (m_innerNonZeros && innerChange < 0)
567 for(Index i = 0; i < m_outerSize + (std::min)(outerChange, Index(0)); i++)
569 Index &n = m_innerNonZeros[i];
570 Index start = m_outerIndex[i];
571 while (n > 0 && m_data.index(start+n-1) >= newInnerSize) --n;
575 m_innerSize = newInnerSize;
578 if (outerChange == 0)
581 Index *newOuterIndex =
static_cast<Index*
>(std::realloc(m_outerIndex, (m_outerSize + outerChange + 1) *
sizeof(Index)));
582 if (!newOuterIndex) internal::throw_std_bad_alloc();
583 m_outerIndex = newOuterIndex;
586 Index last = m_outerSize == 0 ? 0 : m_outerIndex[m_outerSize];
587 for(Index i=m_outerSize; i<m_outerSize+outerChange+1; i++)
588 m_outerIndex[i] = last;
590 m_outerSize += outerChange;
598 const Index outerSize = IsRowMajor ? rows : cols;
599 m_innerSize = IsRowMajor ? cols : rows;
601 if (m_outerSize != outerSize || m_outerSize==0)
603 std::free(m_outerIndex);
604 m_outerIndex =
static_cast<Index*
>(std::malloc((outerSize + 1) *
sizeof(Index)));
605 if (!m_outerIndex) internal::throw_std_bad_alloc();
607 m_outerSize = outerSize;
611 std::free(m_innerNonZeros);
614 memset(m_outerIndex, 0, (m_outerSize+1)*
sizeof(Index));
619 void resizeNonZeros(Index
size)
630 : m_outerSize(-1), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
632 check_template_parameters();
638 : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
640 check_template_parameters();
645 template<
typename OtherDerived>
647 : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
650 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
651 check_template_parameters();
652 *
this = other.derived();
656 template<
typename OtherDerived,
unsigned int UpLo>
658 : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
660 check_template_parameters();
666 :
Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
668 check_template_parameters();
669 *
this = other.derived();
673 template<
typename OtherDerived>
675 :
Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
677 check_template_parameters();
678 initAssignment(other);
687 std::swap(m_outerIndex, other.m_outerIndex);
688 std::swap(m_innerSize, other.m_innerSize);
689 std::swap(m_outerSize, other.m_outerSize);
690 std::swap(m_innerNonZeros, other.m_innerNonZeros);
691 m_data.swap(other.m_data);
698 eigen_assert(rows() == cols() &&
"ONLY FOR SQUARED MATRICES");
699 this->m_data.resize(rows());
703 std::free(m_innerNonZeros);
708 if (other.isRValue())
710 swap(other.const_cast_derived());
712 else if(
this!=&other)
714 initAssignment(other);
717 memcpy(m_outerIndex, other.m_outerIndex, (m_outerSize+1)*
sizeof(Index));
718 m_data = other.m_data;
722 Base::operator=(other);
728 #ifndef EIGEN_PARSED_BY_DOXYGEN 729 template<
typename Lhs,
typename Rhs>
731 {
return Base::operator=(product); }
733 template<
typename OtherDerived>
736 initAssignment(other);
737 return Base::operator=(other.derived());
740 template<
typename OtherDerived>
742 {
return Base::operator=(other.
derived()); }
745 template<
typename OtherDerived>
748 friend std::ostream & operator << (std::ostream & s,
const SparseMatrix& m)
751 s <<
"Nonzero entries:\n";
753 for (Index i=0; i<m.
nonZeros(); ++i)
754 s <<
"(" << m.m_data.value(i) <<
"," << m.m_data.index(i) <<
") ";
758 Index p = m.m_outerIndex[i];
759 Index pe = m.m_outerIndex[i]+m.m_innerNonZeros[i];
762 s <<
"(" << m.m_data.value(k) <<
"," << m.m_data.index(k) <<
") ";
763 for (; k<m.m_outerIndex[i+1]; ++k)
768 s <<
"Outer pointers:\n";
770 s << m.m_outerIndex[i] <<
" ";
771 s <<
" $" << std::endl;
774 s <<
"Inner non zeros:\n";
776 s << m.m_innerNonZeros[i] <<
" ";
777 s <<
" $" << std::endl;
781 s << static_cast<const SparseMatrixBase<SparseMatrix>&>(m);
788 std::free(m_outerIndex);
789 std::free(m_innerNonZeros);
792 #ifndef EIGEN_PARSED_BY_DOXYGEN 797 # ifdef EIGEN_SPARSEMATRIX_PLUGIN 798 # include EIGEN_SPARSEMATRIX_PLUGIN 803 template<
typename Other>
804 void initAssignment(
const Other& other)
806 resize(other.rows(), other.cols());
809 std::free(m_innerNonZeros);
816 EIGEN_DONT_INLINE Scalar& insertCompressed(Index row, Index col);
825 typedef Index value_type;
827 : m_index(i), m_value(v)
830 Index operator[](Index i)
const {
return i==m_index ? m_value : 0; }
835 EIGEN_DONT_INLINE Scalar& insertUncompressed(Index row, Index col);
840 EIGEN_STRONG_INLINE Scalar& insertBackUncompressed(Index row, Index col)
842 const Index outer = IsRowMajor ? row : col;
843 const Index inner = IsRowMajor ? col : row;
845 eigen_assert(!isCompressed());
846 eigen_assert(m_innerNonZeros[outer]<=(m_outerIndex[outer+1] - m_outerIndex[outer]));
848 Index p = m_outerIndex[outer] + m_innerNonZeros[outer]++;
849 m_data.index(p) = inner;
850 return (m_data.value(p) = 0);
854 static void check_template_parameters()
860 struct default_prunning_func {
861 default_prunning_func(
const Scalar& ref,
const RealScalar& eps) : reference(ref), epsilon(eps) {}
862 inline bool operator() (
const Index&,
const Index&,
const Scalar& value)
const 864 return !internal::isMuchSmallerThan(value, reference, epsilon);
871 template<
typename Scalar,
int _Options,
typename _Index>
876 : m_values(mat.
valuePtr()), m_indices(mat.
innerIndexPtr()), m_outer(outer), m_id(mat.m_outerIndex[outer])
879 m_end = mat.m_outerIndex[outer+1];
881 m_end = m_id + mat.m_innerNonZeros[outer];
886 inline const Scalar& value()
const {
return m_values[m_id]; }
887 inline Scalar& valueRef() {
return const_cast<Scalar&
>(m_values[m_id]); }
889 inline Index index()
const {
return m_indices[m_id]; }
890 inline Index outer()
const {
return m_outer; }
891 inline Index row()
const {
return IsRowMajor ? m_outer : index(); }
892 inline Index col()
const {
return IsRowMajor ? index() : m_outer; }
894 inline operator bool()
const {
return (m_id < m_end); }
897 const Scalar* m_values;
898 const Index* m_indices;
904 template<
typename Scalar,
int _Options,
typename _Index>
909 : m_values(mat.
valuePtr()), m_indices(mat.
innerIndexPtr()), m_outer(outer), m_start(mat.m_outerIndex[outer])
912 m_id = mat.m_outerIndex[outer+1];
914 m_id = m_start + mat.m_innerNonZeros[outer];
919 inline const Scalar& value()
const {
return m_values[m_id-1]; }
920 inline Scalar& valueRef() {
return const_cast<Scalar&
>(m_values[m_id-1]); }
922 inline Index index()
const {
return m_indices[m_id-1]; }
923 inline Index outer()
const {
return m_outer; }
924 inline Index row()
const {
return IsRowMajor ? m_outer : index(); }
925 inline Index col()
const {
return IsRowMajor ? index() : m_outer; }
927 inline operator bool()
const {
return (m_id > m_start); }
930 const Scalar* m_values;
931 const Index* m_indices;
939 template<
typename InputIterator,
typename SparseMatrixType>
940 void set_from_triplets(
const InputIterator& begin,
const InputIterator& end, SparseMatrixType& mat,
int Options = 0)
942 EIGEN_UNUSED_VARIABLE(
Options);
943 enum { IsRowMajor = SparseMatrixType::IsRowMajor };
945 typedef typename SparseMatrixType::Index Index;
953 for(InputIterator it(begin); it!=end; ++it)
955 eigen_assert(it->row()>=0 && it->row()<mat.rows() && it->col()>=0 && it->col()<mat.cols());
956 wi(IsRowMajor ? it->col() : it->row())++;
961 for(InputIterator it(begin); it!=end; ++it)
962 trMat.insertBackUncompressed(it->row(),it->col()) = it->value();
965 trMat.sumupDuplicates();
1012 template<
typename Scalar,
int _Options,
typename _Index>
1013 template<
typename InputIterators>
1016 internal::set_from_triplets(begin, end, *
this);
1020 template<
typename Scalar,
int _Options,
typename _Index>
1023 eigen_assert(!isCompressed());
1029 for(Index j=0; j<outerSize(); ++j)
1031 Index start = count;
1032 Index oldEnd = m_outerIndex[j]+m_innerNonZeros[j];
1033 for(Index k=m_outerIndex[j]; k<oldEnd; ++k)
1035 Index i = m_data.index(k);
1039 m_data.value(wi(i)) += m_data.value(k);
1043 m_data.value(count) = m_data.value(k);
1044 m_data.index(count) = m_data.index(k);
1049 m_outerIndex[j] = start;
1051 m_outerIndex[m_outerSize] = count;
1054 std::free(m_innerNonZeros);
1055 m_innerNonZeros = 0;
1056 m_data.resize(m_outerIndex[m_outerSize]);
1059 template<
typename Scalar,
int _Options,
typename _Index>
1060 template<
typename OtherDerived>
1064 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
1067 if (needToTranspose)
1075 OtherCopy otherCopy(other.derived());
1082 for (Index j=0; j<otherCopy.outerSize(); ++j)
1083 for (
typename _OtherCopy::InnerIterator it(otherCopy, j); it; ++it)
1084 ++dest.m_outerIndex[it.index()];
1089 for (Index j=0; j<dest.outerSize(); ++j)
1091 Index tmp = dest.m_outerIndex[j];
1092 dest.m_outerIndex[j] = count;
1093 positions[j] = count;
1096 dest.m_outerIndex[dest.outerSize()] = count;
1098 dest.m_data.
resize(count);
1100 for (Index j=0; j<otherCopy.outerSize(); ++j)
1102 for (
typename _OtherCopy::InnerIterator it(otherCopy, j); it; ++it)
1104 Index pos = positions[it.index()]++;
1105 dest.m_data.index(pos) = j;
1106 dest.m_data.value(pos) = it.value();
1114 if(other.isRValue())
1115 initAssignment(other.derived());
1117 return Base::operator=(other.derived());
1121 template<
typename _Scalar,
int _Options,
typename _Index>
1124 eigen_assert(!isCompressed());
1126 const Index outer = IsRowMajor ? row : col;
1127 const Index inner = IsRowMajor ? col : row;
1129 Index room = m_outerIndex[outer+1] - m_outerIndex[outer];
1130 Index innerNNZ = m_innerNonZeros[outer];
1134 reserve(SingletonVector(outer,std::max<Index>(2,innerNNZ)));
1137 Index startId = m_outerIndex[outer];
1138 Index p = startId + m_innerNonZeros[outer];
1139 while ( (p > startId) && (m_data.index(p-1) > inner) )
1141 m_data.index(p) = m_data.index(p-1);
1142 m_data.value(p) = m_data.value(p-1);
1145 eigen_assert((p<=startId || m_data.index(p-1)!=inner) &&
"you cannot insert an element that already exist, you must call coeffRef to this end");
1147 m_innerNonZeros[outer]++;
1149 m_data.index(p) = inner;
1150 return (m_data.value(p) = 0);
1153 template<
typename _Scalar,
int _Options,
typename _Index>
1156 eigen_assert(isCompressed());
1158 const Index outer = IsRowMajor ? row : col;
1159 const Index inner = IsRowMajor ? col : row;
1161 Index previousOuter = outer;
1162 if (m_outerIndex[outer+1]==0)
1165 while (previousOuter>=0 && m_outerIndex[previousOuter]==0)
1167 m_outerIndex[previousOuter] =
static_cast<Index
>(m_data.size());
1170 m_outerIndex[outer+1] = m_outerIndex[outer];
1176 bool isLastVec = (!(previousOuter==-1 && m_data.size()!=0))
1177 && (size_t(m_outerIndex[outer+1]) == m_data.size());
1179 size_t startId = m_outerIndex[outer];
1181 size_t p = m_outerIndex[outer+1];
1182 ++m_outerIndex[outer+1];
1184 double reallocRatio = 1;
1185 if (m_data.allocatedSize()<=m_data.size())
1188 if (m_data.size()==0)
1197 double nnzEstimate = double(m_outerIndex[outer])*double(m_outerSize)/double(outer+1);
1198 reallocRatio = (nnzEstimate-double(m_data.size()))/double(m_data.size());
1202 reallocRatio = (std::min)((std::max)(reallocRatio,1.5),8.);
1205 m_data.resize(m_data.size()+1,reallocRatio);
1209 if (previousOuter==-1)
1213 for (Index k=0; k<=(outer+1); ++k)
1214 m_outerIndex[k] = 0;
1216 while(m_outerIndex[k]==0)
1217 m_outerIndex[k++] = 1;
1218 while (k<=m_outerSize && m_outerIndex[k]!=0)
1219 m_outerIndex[k++]++;
1222 k = m_outerIndex[k]-1;
1225 m_data.index(k) = m_data.index(k-1);
1226 m_data.value(k) = m_data.value(k-1);
1235 while (j<=m_outerSize && m_outerIndex[j]!=0)
1236 m_outerIndex[j++]++;
1239 Index k = m_outerIndex[j]-1;
1242 m_data.index(k) = m_data.index(k-1);
1243 m_data.value(k) = m_data.value(k-1);
1249 while ( (p > startId) && (m_data.index(p-1) > inner) )
1251 m_data.index(p) = m_data.index(p-1);
1252 m_data.value(p) = m_data.value(p-1);
1256 m_data.index(p) = inner;
1257 return (m_data.value(p) = 0);
1262 #endif // EIGEN_SPARSEMATRIX_H Index cols() const
Definition: SparseMatrixBase.h:161
void conservativeResize(Index rows, Index cols)
Resizes the matrix to a rows x cols matrix leaving old values untouched.
Definition: SparseMatrix.h:532
Definition: SparseProduct.h:80
const Scalar * valuePtr() const
Definition: SparseMatrix.h:131
A versatible sparse matrix representation.
Definition: SparseMatrix.h:85
void uncompress()
Turns the matrix into the uncompressed mode.
Definition: SparseMatrix.h:478
void prune(const KeepFunc &keep=KeepFunc())
Turns the matrix into compressed format, and suppresses all nonzeros which do not satisfy the predica...
Definition: SparseMatrix.h:503
~SparseMatrix()
Destructor.
Definition: SparseMatrix.h:786
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:104
const Diagonal< const SparseMatrix > diagonal() const
Definition: SparseMatrix.h:626
Index searchLowerIndex(Index key) const
Definition: CompressedStorage.h:121
Scalar & coeffRef(Index row, Index col)
Definition: SparseMatrix.h:189
const unsigned int LvalueBit
Means the expression has a coeffRef() method, i.e.
Definition: Constants.h:131
SparseMatrix(const SparseMatrix &other)
Copy constructor (it performs a deep copy)
Definition: SparseMatrix.h:665
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition: SparseSelfAdjointView.h:49
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Index cols() const
Definition: SparseMatrix.h:121
Derived & derived()
Definition: EigenBase.h:34
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Index innerSize() const
Definition: SparseMatrix.h:124
const Index * outerIndexPtr() const
Definition: SparseMatrix.h:149
Definition: SparseMatrix.h:820
Scalar * valuePtr()
Definition: SparseMatrix.h:135
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:26
The type used to identify a matrix expression.
Definition: Constants.h:431
Definition: ReturnByValue.h:50
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
void setFromTriplets(const InputIterators &begin, const InputIterators &end)
Fill the matrix *this with the list of triplets defined by the iterator range begin - end...
Definition: SparseMatrix.h:1014
Index nonZeros() const
Definition: SparseMatrix.h:246
Index rows() const
Definition: SparseMatrixBase.h:159
void setIdentity()
Sets *this to the identity matrix.
Definition: SparseMatrix.h:696
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:239
void prune(const Scalar &reference, const RealScalar &epsilon=NumTraits< RealScalar >::dummy_precision())
Suppresses all nonzeros which are much smaller than reference under the tolerence epsilon...
Definition: SparseMatrix.h:490
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:264
Scalar atInRange(size_t start, size_t end, Index key, const Scalar &defaultValue=Scalar(0)) const
Like at(), but the search is performed in the range [start,end)
Definition: CompressedStorage.h:155
Scalar & insert(Index row, Index col)
Definition: SparseMatrix.h:220
Definition: XprHelper.h:371
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:235
void swap(SparseMatrix &other)
Swaps the content of two sparse matrices of the same type.
Definition: SparseMatrix.h:684
Index rows() const
Definition: SparseMatrix.h:119
const Index * innerNonZeroPtr() const
Definition: SparseMatrix.h:158
void resize(Index rows, Index cols)
Resizes the matrix to a rows x cols matrix and initializes it to zero.
Definition: SparseMatrix.h:596
void reserve(Index reserveSize)
Preallocates reserveSize non zeros.
Definition: SparseMatrix.h:256
Definition: SparseMatrix.h:872
SparseMatrix(Index rows, Index cols)
Constructs a rows x cols empty matrix.
Definition: SparseMatrix.h:637
Derived & setZero(Index size)
Resizes to the given size, and sets all coefficients in this expression to zero.
Definition: CwiseNullaryOp.h:515
void makeCompressed()
Turns the matrix into the compressed format.
Definition: SparseMatrix.h:449
SparseMatrix(const SparseMatrixBase< OtherDerived > &other)
Constructs a sparse matrix from the sparse expression other.
Definition: SparseMatrix.h:646
SparseMatrix(const ReturnByValue< OtherDerived > &other)
Copy constructor with in-place evaluation.
Definition: SparseMatrix.h:674
Index * outerIndexPtr()
Definition: SparseMatrix.h:153
SparseMatrix()
Default constructor yielding an empty 0 x 0 matrix.
Definition: SparseMatrix.h:629
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:266
An InnerIterator allows to loop over the element of a sparse (or dense) matrix or expression...
const Index * innerIndexPtr() const
Definition: SparseMatrix.h:140
bool isCompressed() const
Definition: SparseMatrix.h:116
Scalar coeff(Index row, Index col) const
Definition: SparseMatrix.h:171
The type used to identify a dense storage.
Definition: Constants.h:428
Index * innerIndexPtr()
Definition: SparseMatrix.h:144
void setZero()
Removes all non zeros but keep allocated memory.
Definition: SparseMatrix.h:237
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:64
Definition: SparseMatrix.h:905
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Index outerSize() const
Definition: SparseMatrix.h:126
SparseMatrix(const SparseSelfAdjointView< OtherDerived, UpLo > &other)
Constructs a sparse matrix from the sparse selfadjoint view other.
Definition: SparseMatrix.h:657
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
NumTraits< Scalar >::Real RealScalar
This is the "real scalar" type; if the Scalar type is already real numbers (e.g.
Definition: SparseMatrixBase.h:124
Sparse matrix.
Definition: MappedSparseMatrix.h:31
Index * innerNonZeroPtr()
Definition: SparseMatrix.h:162
Definition: ForwardDeclarations.h:17
Definition: osvr_print_tree.cpp:52
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48