10 #ifndef EIGEN_DYNAMIC_SPARSEMATRIX_H 11 #define EIGEN_DYNAMIC_SPARSEMATRIX_H 36 template<
typename _Scalar,
int _Options,
typename _StorageIndex>
55 template<
typename _Scalar,
int _Options,
typename _StorageIndex>
57 :
public SparseMatrixBase<DynamicSparseMatrix<_Scalar, _Options, _StorageIndex> >
67 using Base::IsRowMajor;
68 using Base::operator=;
78 std::vector<internal::CompressedStorage<Scalar,StorageIndex> >
m_data;
82 inline Index rows()
const {
return IsRowMajor ? outerSize() : m_innerSize; }
83 inline Index cols()
const {
return IsRowMajor ? m_innerSize : outerSize(); }
88 std::vector<internal::CompressedStorage<Scalar,StorageIndex> >&
_data() {
return m_data; }
89 const std::vector<internal::CompressedStorage<Scalar,StorageIndex> >&
_data()
const {
return m_data; }
96 const Index outer = IsRowMajor ? row :
col;
97 const Index inner = IsRowMajor ? col :
row;
98 return m_data[outer].at(inner);
107 const Index outer = IsRowMajor ? row :
col;
108 const Index inner = IsRowMajor ? col :
row;
109 return m_data[outer].atWithInsertion(inner);
117 for (
Index j=0; j<outerSize(); ++j)
125 for (
Index j=0; j<outerSize(); ++j)
126 res += m_data[j].
size();
137 for (
Index j=0; j<outerSize(); ++j)
139 m_data[j].reserve(reserveSizePerVector);
154 return insertBackByOuterInner(IsRowMajor?row:col, IsRowMajor?col:row);
162 &&
"wrong sorted insertion");
163 m_data[outer].append(0, inner);
164 return m_data[outer].value(m_data[outer].
size()-1);
169 const Index outer = IsRowMajor ? row :
col;
170 const Index inner = IsRowMajor ? col :
row;
173 Index id =
static_cast<Index>(m_data[outer].size()) - 1;
174 m_data[outer].resize(
id+2,1);
176 while ( (
id >= startId) && (m_data[outer].index(
id) > inner) )
178 m_data[outer].index(
id+1) = m_data[outer].index(
id);
179 m_data[outer].value(
id+1) = m_data[outer].value(
id);
182 m_data[outer].index(
id+1) = inner;
183 m_data[outer].value(
id+1) = 0;
184 return m_data[outer].value(
id+1);
193 for (
Index j=0; j<outerSize(); ++j)
194 m_data[j].prune(reference,
epsilon);
201 const Index outerSize = IsRowMajor ? rows : cols;
204 if (
Index(m_data.size()) != outerSize)
206 m_data.resize(outerSize);
212 const Index outerSize = IsRowMajor ? rows : cols;
213 const Index innerSize = IsRowMajor ? cols : rows;
214 if (m_innerSize>innerSize)
221 if (m_data.size() != outerSize)
223 m_data.resize(outerSize);
229 : m_innerSize(0), m_data(0)
242 template<
typename OtherDerived>
246 Base::operator=(other.
derived());
250 : Base(), m_innerSize(0)
260 m_data.swap(other.
m_data);
287 reserve(reserveSize);
301 const Index outer = IsRowMajor ? row :
col;
302 const Index inner = IsRowMajor ? col :
row;
303 return insertBack(outer,inner);
313 return insert(row,col);
320 # ifdef EIGEN_DYNAMICSPARSEMATRIX_PLUGIN 321 # include EIGEN_DYNAMICSPARSEMATRIX_PLUGIN 325 template<
typename Scalar,
int _Options,
typename _StorageIndex>
331 : Base(mat.m_data[outer]), m_outer(outer)
334 inline Index row()
const {
return IsRowMajor ? m_outer : Base::index(); }
335 inline Index col()
const {
return IsRowMajor ? Base::index() : m_outer; }
342 template<
typename Scalar,
int _Options,
typename _StorageIndex>
348 : Base(mat.m_data[outer]), m_outer(outer)
351 inline Index row()
const {
return IsRowMajor ? m_outer : Base::index(); }
352 inline Index col()
const {
return IsRowMajor ? Base::index() : m_outer; }
361 template<
typename _Scalar,
int _Options,
typename _StorageIndex>
363 :
evaluator_base<DynamicSparseMatrix<_Scalar,_Options,_StorageIndex> >
372 Flags = SparseMatrixType::Flags
376 evaluator(
const SparseMatrixType &mat) : m_matrix(&mat) {}
378 operator SparseMatrixType&() {
return m_matrix->const_cast_derived(); }
379 operator const SparseMatrixType&()
const {
return *m_matrix; }
392 #endif // EIGEN_DYNAMIC_SPARSEMATRIX_H ReverseInnerIterator(const DynamicSparseMatrix &mat, Index outer)
DynamicSparseMatrix< Scalar,(Flags &~RowMajorBit)|(IsRowMajor?RowMajorBit:0), StorageIndex > TransposedSparseMatrix
Scalar & insertBackByOuterInner(Index outer, Index inner)
SparseMatrixType::ReverseInnerIterator ReverseInnerIterator
const int OuterRandomAccessPattern
std::vector< internal::CompressedStorage< Scalar, StorageIndex > > m_data
DynamicSparseMatrix(const DynamicSparseMatrix &other)
Scalar & insertBack(Index row, Index col)
void swap(DynamicSparseMatrix &other)
Scalar coeff(Index row, Index col) const
const unsigned int LvalueBit
evaluator(const SparseMatrixType &mat)
InnerIterator(const DynamicSparseMatrix &mat, Index outer)
std::vector< internal::CompressedStorage< Scalar, StorageIndex > > & _data()
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
void resize(Index rows, Index cols)
const SparseMatrixType * m_matrix
EIGEN_DEVICE_FUNC IndexDest convert_index(const IndexSrc &idx)
Eigen::Index Index
The interface type of indices.
DynamicSparseMatrix< _Scalar, _Options, _StorageIndex > SparseMatrixType
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
const std::vector< internal::CompressedStorage< Scalar, StorageIndex > > & _data() const
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
SparseVector< Scalar, _Options, _StorageIndex >::ReverseInnerIterator Base
Base class of any sparse matrices or sparse expressions.
SparseVector< Scalar, _Options, _StorageIndex >::InnerIterator Base
EIGEN_DEPRECATED void startFill(Index reserveSize=1000)
SparseMatrixBase< DynamicSparseMatrix > Base
internal::traits< DynamicSparseMatrix< _Scalar, _Options, _StorageIndex > >::Scalar Scalar
SparseMatrixType::InnerIterator InnerIterator
Scalar coeff(Index row, Index col) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEPRECATED Scalar & fillrand(Index row, Index col)
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
EIGEN_DEPRECATED void endFill()
EIGEN_DEPRECATED Scalar & fill(Index row, Index col)
A sparse matrix class designed for matrix assembly purpose.
void reserve(Index reserveSize=1000)
void resizeAndKeepData(Index rows, Index cols)
const unsigned int NestByRefBit
EIGEN_DEPRECATED DynamicSparseMatrix(Index rows, Index cols)
const Derived & derived() const
_StorageIndex StorageIndex
Index nonZerosEstimate() const
Index innerNonZeros(Index j) const
Scalar & coeffRef(Index row, Index col)
NumTraits< Scalar >::Real RealScalar
Scalar & insert(Index row, Index col)
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
EIGEN_DEPRECATED DynamicSparseMatrix()
void swap(scoped_array< T > &a, scoped_array< T > &b)
void prune(Scalar reference, RealScalar epsilon=NumTraits< RealScalar >::dummy_precision())
Derived & const_cast_derived() const
DynamicSparseMatrix & operator=(const DynamicSparseMatrix &other)
EIGEN_DEPRECATED DynamicSparseMatrix(const SparseMatrixBase< OtherDerived > &other)