| 54 | |
| 55 | template<typename _Scalar, int _Options, typename _StorageIndex> |
| 56 | class DynamicSparseMatrix |
| 57 | : public SparseMatrixBase<DynamicSparseMatrix<_Scalar, _Options, _StorageIndex> > |
| 58 | { |
| 59 | typedef SparseMatrixBase<DynamicSparseMatrix> Base; |
| 60 | using Base::convert_index; |
| 61 | public: |
| 62 | EIGEN_SPARSE_PUBLIC_INTERFACE(DynamicSparseMatrix) |
| 63 | // FIXME: why are these operator already alvailable ??? |
| 64 | // EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, +=) |
| 65 | // EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, -=) |
| 66 | typedef MappedSparseMatrix<Scalar,Flags> Map; |
| 67 | using Base::IsRowMajor; |
| 68 | using Base::operator=; |
| 69 | enum { |
| 70 | Options = _Options |
| 71 | }; |
| 72 | |
| 73 | protected: |
| 74 | |
| 75 | typedef DynamicSparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0), StorageIndex> TransposedSparseMatrix; |
| 76 | |
| 77 | Index m_innerSize; |
| 78 | std::vector<internal::CompressedStorage<Scalar,StorageIndex> > m_data; |
| 79 | |
| 80 | public: |
| 81 | |
| 82 | inline Index rows() const { return IsRowMajor ? outerSize() : m_innerSize; } |
| 83 | inline Index cols() const { return IsRowMajor ? m_innerSize : outerSize(); } |
| 84 | inline Index innerSize() const { return m_innerSize; } |
| 85 | inline Index outerSize() const { return convert_index(m_data.size()); } |
| 86 | inline Index innerNonZeros(Index j) const { return m_data[j].size(); } |
| 87 | |
| 88 | std::vector<internal::CompressedStorage<Scalar,StorageIndex> >& _data() { return m_data; } |
| 89 | const std::vector<internal::CompressedStorage<Scalar,StorageIndex> >& _data() const { return m_data; } |
| 90 | |
| 91 | /** \returns the coefficient value at given position \a row, \a col |
| 92 | * This operation involes a log(rho*outer_size) binary search. |
| 93 | */ |
| 94 | inline Scalar coeff(Index row, Index col) const |
| 95 | { |
| 96 | const Index outer = IsRowMajor ? row : col; |
| 97 | const Index inner = IsRowMajor ? col : row; |
| 98 | return m_data[outer].at(inner); |
| 99 | } |
| 100 | |
| 101 | /** \returns a reference to the coefficient value at given position \a row, \a col |
| 102 | * This operation involes a log(rho*outer_size) binary search. If the coefficient does not |
| 103 | * exist yet, then a sorted insertion into a sequential buffer is performed. |
| 104 | */ |
| 105 | inline Scalar& coeffRef(Index row, Index col) |
| 106 | { |
| 107 | const Index outer = IsRowMajor ? row : col; |
| 108 | const Index inner = IsRowMajor ? col : row; |
| 109 | return m_data[outer].atWithInsertion(inner); |
| 110 | } |
| 111 | |
| 112 | class InnerIterator; |
| 113 | class ReverseInnerIterator; |