10 #ifndef EIGEN_DYNAMIC_SPARSEMATRIX_H 11 #define EIGEN_DYNAMIC_SPARSEMATRIX_H 36 template<
typename _Scalar,
int _Options,
typename _Index>
55 template<
typename _Scalar,
int _Options,
typename _Index>
65 using
Base::IsRowMajor;
66 using
Base::operator=;
76 std::vector<internal::CompressedStorage<Scalar,Index> >
m_data;
80 inline Index rows()
const {
return IsRowMajor ? outerSize() : m_innerSize; }
81 inline Index cols()
const {
return IsRowMajor ? m_innerSize : outerSize(); }
86 std::vector<internal::CompressedStorage<Scalar,Index> >&
_data() {
return m_data; }
87 const std::vector<internal::CompressedStorage<Scalar,Index> >&
_data()
const {
return m_data; }
94 const Index outer = IsRowMajor ? row :
col;
95 const Index inner = IsRowMajor ? col :
row;
96 return m_data[outer].at(inner);
105 const Index outer = IsRowMajor ? row :
col;
106 const Index inner = IsRowMajor ? col :
row;
107 return m_data[outer].atWithInsertion(inner);
115 for (
Index j=0; j<outerSize(); ++j)
123 for (
Index j=0; j<outerSize(); ++j)
124 res += static_cast<Index>(m_data[j].size());
134 Index reserveSizePerVector = (std::max)(reserveSize/outerSize(),
Index(4));
135 for (
Index j=0; j<outerSize(); ++j)
137 m_data[j].reserve(reserveSizePerVector);
152 return insertBackByOuterInner(IsRowMajor?row:col, IsRowMajor?col:row);
159 eigen_assert(((m_data[outer].size()==0) || (m_data[outer].index(m_data[outer].size()-1)<inner))
160 &&
"wrong sorted insertion");
161 m_data[outer].append(0, inner);
162 return m_data[outer].value(m_data[outer].size()-1);
167 const Index outer = IsRowMajor ? row :
col;
168 const Index inner = IsRowMajor ? col :
row;
171 Index id =
static_cast<Index>(m_data[outer].size()) - 1;
172 m_data[outer].resize(
id+2,1);
174 while ( (
id >= startId) && (m_data[outer].index(
id) > inner) )
176 m_data[outer].index(
id+1) = m_data[outer].index(
id);
177 m_data[outer].value(
id+1) = m_data[outer].value(
id);
180 m_data[outer].index(
id+1) = inner;
181 m_data[outer].value(
id+1) = 0;
182 return m_data[outer].value(
id+1);
191 for (
Index j=0; j<outerSize(); ++j)
192 m_data[j].prune(reference,epsilon);
199 const Index outerSize = IsRowMajor ? rows : cols;
200 m_innerSize = IsRowMajor ? cols : rows;
202 if (
Index(m_data.size()) != outerSize)
204 m_data.resize(outerSize);
210 const Index outerSize = IsRowMajor ? rows : cols;
211 const Index innerSize = IsRowMajor ? cols : rows;
212 if (m_innerSize>innerSize)
219 if (m_data.size() != outerSize)
221 m_data.resize(outerSize);
227 : m_innerSize(0), m_data(0)
240 template<
typename OtherDerived>
244 Base::operator=(other.
derived());
248 :
Base(), m_innerSize(0)
258 m_data.swap(other.
m_data);
285 reserve(reserveSize);
299 const Index outer = IsRowMajor ? row :
col;
300 const Index inner = IsRowMajor ? col :
row;
301 return insertBack(outer,inner);
318 # ifdef EIGEN_DYNAMICSPARSEMATRIX_PLUGIN 319 # include EIGEN_DYNAMICSPARSEMATRIX_PLUGIN 323 template<
typename Scalar,
int _Options,
typename _Index>
329 : Base(mat.m_data[outer]), m_outer(outer)
332 inline Index
row()
const {
return IsRowMajor ? m_outer : Base::index(); }
333 inline Index
col()
const {
return IsRowMajor ? Base::index() : m_outer; }
339 template<
typename Scalar,
int _Options,
typename _Index>
345 : Base(mat.m_data[outer]), m_outer(outer)
348 inline Index row()
const {
return IsRowMajor ? m_outer : Base::index(); }
349 inline Index col()
const {
return IsRowMajor ? Base::index() : m_outer; }
357 #endif // EIGEN_DYNAMIC_SPARSEMATRIX_H Scalar & insertBackByOuterInner(Index outer, Index inner)
const int OuterRandomAccessPattern
Scalar coeff(Index row, Index col) const
void prune(Scalar reference, RealScalar epsilon=NumTraits< RealScalar >::dummy_precision())
DynamicSparseMatrix(const DynamicSparseMatrix &other)
void resize(Index rows, Index cols)
const unsigned int LvalueBit
iterative scaling algorithm to equilibrate rows and column norms in matrices
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
std::vector< internal::CompressedStorage< Scalar, Index > > m_data
EIGEN_DEPRECATED Scalar & fill(Index row, Index col)
Scalar & insert(Index row, Index col)
DynamicSparseMatrix & operator=(const DynamicSparseMatrix &other)
SparseVector< Scalar, _Options, _Index >::InnerIterator Base
ReverseInnerIterator(const DynamicSparseMatrix &mat, Index outer)
EIGEN_DEPRECATED Scalar & fillrand(Index row, Index col)
void reserve(Index reserveSize=1000)
Index innerNonZeros(Index j) const
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Base class of any sparse matrices or sparse expressions.
InnerIterator(const DynamicSparseMatrix &mat, Index outer)
internal::traits< DynamicSparseMatrix< _Scalar, _Options, _Index > >::Scalar Scalar
void swap(DynamicSparseMatrix &other)
const std::vector< internal::CompressedStorage< Scalar, Index > > & _data() const
Scalar & coeffRef(Index row, Index col)
Provides a generic way to set and pass user-specified options.
Scalar & insertBack(Index row, Index col)
A sparse matrix class designed for matrix assembly purpose.
EIGEN_DEPRECATED DynamicSparseMatrix()
internal::traits< Derived >::Index Index
EIGEN_DEPRECATED DynamicSparseMatrix(const SparseMatrixBase< OtherDerived > &other)
const unsigned int NestByRefBit
EIGEN_DEPRECATED void endFill()
EIGEN_DEPRECATED void startFill(Index reserveSize=1000)
const Derived & derived() const
DynamicSparseMatrix< Scalar,(Flags &~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix
std::vector< internal::CompressedStorage< Scalar, Index > > & _data()
NumTraits< Scalar >::Real RealScalar
SparseVector< Scalar, _Options, _Index >::ReverseInnerIterator Base
void resizeAndKeepData(Index rows, Index cols)
EIGEN_DEPRECATED DynamicSparseMatrix(Index rows, Index cols)
Derived & const_cast_derived() const
static void insert(double *xd, double *xa, double *u, double *p)