MCPcopy Create free account
hub / github.com/TinyMPC/TinyMPC / sparse_matrix_block_impl

Class sparse_matrix_block_impl

include/Eigen/Eigen/src/SparseCore/SparseBlock.h:98–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97template<typename SparseMatrixType, int BlockRows, int BlockCols>
98class sparse_matrix_block_impl
99 : public SparseCompressedBase<Block<SparseMatrixType,BlockRows,BlockCols,true> >
100{
101 typedef internal::remove_all_t<typename SparseMatrixType::Nested> MatrixTypeNested_;
102 typedef Block<SparseMatrixType, BlockRows, BlockCols, true> BlockType;
103 typedef SparseCompressedBase<Block<SparseMatrixType,BlockRows,BlockCols,true> > Base;
104 using Base::convert_index;
105public:
106 enum { IsRowMajor = internal::traits<BlockType>::IsRowMajor };
107 EIGEN_SPARSE_PUBLIC_INTERFACE(BlockType)
108protected:
109 typedef typename Base::IndexVector IndexVector;
110 enum { OuterSize = IsRowMajor ? BlockRows : BlockCols };
111public:
112
113 inline sparse_matrix_block_impl(SparseMatrixType& xpr, Index i)
114 : m_matrix(xpr), m_outerStart(convert_index(i)), m_outerSize(OuterSize)
115 {}
116
117 inline sparse_matrix_block_impl(SparseMatrixType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
118 : m_matrix(xpr), m_outerStart(convert_index(IsRowMajor ? startRow : startCol)), m_outerSize(convert_index(IsRowMajor ? blockRows : blockCols))
119 {}
120
121 template<typename OtherDerived>
122 inline BlockType& operator=(const SparseMatrixBase<OtherDerived>& other)
123 {
124 typedef internal::remove_all_t<typename SparseMatrixType::Nested> NestedMatrixType_;
125 NestedMatrixType_& matrix = m_matrix;
126 // This assignment is slow if this vector set is not empty
127 // and/or it is not at the end of the nonzeros of the underlying matrix.
128
129 // 1 - eval to a temporary to avoid transposition and/or aliasing issues
130 Ref<const SparseMatrix<Scalar, IsRowMajor ? RowMajor : ColMajor, StorageIndex> > tmp(other.derived());
131 eigen_internal_assert(tmp.outerSize()==m_outerSize.value());
132
133 // 2 - let's check whether there is enough allocated memory
134 Index nnz = tmp.nonZeros();
135 Index start = m_outerStart==0 ? 0 : m_matrix.outerIndexPtr()[m_outerStart]; // starting position of the current block
136 Index end = m_matrix.outerIndexPtr()[m_outerStart+m_outerSize.value()]; // ending position of the current block
137 Index block_size = end - start; // available room in the current block
138 Index tail_size = m_matrix.outerIndexPtr()[m_matrix.outerSize()] - end;
139
140 Index free_size = m_matrix.isCompressed()
141 ? Index(matrix.data().allocatedSize()) + block_size
142 : block_size;
143
144 Index tmp_start = tmp.outerIndexPtr()[0];
145
146 bool update_trailing_pointers = false;
147 if(nnz>free_size)
148 {
149 // realloc manually to reduce copies
150 typename SparseMatrixType::Storage newdata(m_matrix.data().allocatedSize() - block_size + nnz);
151
152 internal::smart_copy(m_matrix.valuePtr(), m_matrix.valuePtr() + start, newdata.valuePtr());
153 internal::smart_copy(m_matrix.innerIndexPtr(), m_matrix.innerIndexPtr() + start, newdata.indexPtr());
154
155 internal::smart_copy(tmp.valuePtr() + tmp_start, tmp.valuePtr() + tmp_start + nnz, newdata.valuePtr() + start);

Callers

nothing calls this directly

Calls 15

smart_copyFunction · 0.85
smart_memmoveFunction · 0.85
allocatedSizeMethod · 0.80
indexPtrMethod · 0.80
outerSizeMethod · 0.45
valueMethod · 0.45
nonZerosMethod · 0.45
outerIndexPtrMethod · 0.45
isCompressedMethod · 0.45
dataMethod · 0.45
valuePtrMethod · 0.45
innerIndexPtrMethod · 0.45

Tested by

no test coverage detected