27 using Base::convert_index;
32 : m_matrix(
xpr), m_outerStart(convert_index(i)), m_outerSize(OuterSize)
35 inline BlockImpl(
const XprType&
xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
36 : m_matrix(
xpr), m_outerStart(convert_index(IsRowMajor ? startRow : startCol)), m_outerSize(convert_index(IsRowMajor ? blockRows : blockCols))
39 EIGEN_STRONG_INLINE Index rows()
const {
return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
40 EIGEN_STRONG_INLINE Index cols()
const {
return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
42 Index nonZeros()
const
45 EvaluatorType
matEval(m_matrix);
47 Index end = m_outerStart + m_outerSize.value();
48 for(Index
j=m_outerStart;
j<end; ++
j)
49 for(
typename EvaluatorType::InnerIterator it(
matEval,
j); it; ++it)
54 inline const Scalar coeff(Index row, Index col)
const
56 return m_matrix.coeff(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 : m_outerStart));
59 inline const Scalar coeff(Index index)
const
61 return m_matrix.coeff(IsRowMajor ? m_outerStart : index, IsRowMajor ? index : m_outerStart);
65 Index startRow()
const {
return IsRowMajor ? m_outerStart : 0; }
66 Index startCol()
const {
return IsRowMajor ? 0 : m_outerStart; }
67 Index blockRows()
const {
return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
68 Index blockCols()
const {
return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
72 typename XprType::Nested m_matrix;
77 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
BlockImpl)
94 using Base::convert_index;
104 : m_matrix(
xpr), m_outerStart(convert_index(i)), m_outerSize(OuterSize)
108 : m_matrix(
xpr), m_outerStart(convert_index(IsRowMajor ? startRow : startCol)), m_outerSize(convert_index(IsRowMajor ? blockRows : blockCols))
111 template<
typename OtherDerived>
121 eigen_internal_assert(tmp.outerSize()==m_outerSize.value());
124 Index nnz = tmp.nonZeros();
125 Index start = m_outerStart==0 ? 0 : matrix.outerIndexPtr()[m_outerStart];
126 Index end = m_matrix.outerIndexPtr()[m_outerStart+m_outerSize.value()];
128 Index
tail_size = m_matrix.outerIndexPtr()[m_matrix.outerSize()] - end;
130 Index
free_size = m_matrix.isCompressed()
138 typename SparseMatrixType::Storage
newdata(m_matrix.data().allocatedSize() -
block_size + nnz);
140 internal::smart_copy(&m_matrix.data().value(0), &m_matrix.data().value(0) + start, &
newdata.value(0));
141 internal::smart_copy(&m_matrix.data().index(0), &m_matrix.data().index(0) + start, &
newdata.index(0));
143 internal::smart_copy(tmp.valuePtr(), tmp.valuePtr() + nnz, &
newdata.value(start));
144 internal::smart_copy(tmp.innerIndexPtr(), tmp.innerIndexPtr() + nnz, &
newdata.index(start));
146 internal::smart_copy(&matrix.data().value(end), &matrix.data().value(end) +
tail_size, &
newdata.value(start+nnz));
147 internal::smart_copy(&matrix.data().index(end), &matrix.data().index(end) +
tail_size, &
newdata.index(start+nnz));
149 newdata.resize(m_matrix.outerIndexPtr()[m_matrix.outerSize()] -
block_size + nnz);
157 if(m_matrix.isCompressed())
160 matrix.data().resize(start + nnz +
tail_size);
162 internal::smart_memmove(&matrix.data().value(end), &matrix.data().value(end) +
tail_size, &matrix.data().value(start + nnz));
163 internal::smart_memmove(&matrix.data().index(end), &matrix.data().index(end) +
tail_size, &matrix.data().index(start + nnz));
168 internal::smart_copy(tmp.valuePtr(), tmp.valuePtr() + nnz, &matrix.data().value(start));
169 internal::smart_copy(tmp.innerIndexPtr(), tmp.innerIndexPtr() + nnz, &matrix.data().index(start));
175 if(!m_matrix.isCompressed())
176 matrix.innerNonZeroPtr()[m_outerStart] = StorageIndex(nnz);
177 matrix.outerIndexPtr()[m_outerStart] = StorageIndex(start);
181 StorageIndex p = StorageIndex(start);
182 for(Index k=0; k<m_outerSize.value(); ++k)
184 Index
nnz_k = tmp.innerVector(k).nonZeros();
185 if(!m_matrix.isCompressed())
186 matrix.innerNonZeroPtr()[m_outerStart+k] = StorageIndex(
nnz_k);
187 matrix.outerIndexPtr()[m_outerStart+k] = p;
194 StorageIndex offset = internal::convert_index<StorageIndex>(nnz -
block_size);
195 for(Index k = m_outerStart + m_outerSize.value(); k<=matrix.outerSize(); ++k)
197 matrix.outerIndexPtr()[k] += offset;
209 inline const Scalar* valuePtr()
const
210 {
return m_matrix.valuePtr(); }
211 inline Scalar* valuePtr()
212 {
return m_matrix.const_cast_derived().valuePtr(); }
214 inline const StorageIndex* innerIndexPtr()
const
215 {
return m_matrix.innerIndexPtr(); }
216 inline StorageIndex* innerIndexPtr()
217 {
return m_matrix.const_cast_derived().innerIndexPtr(); }
219 inline const StorageIndex* outerIndexPtr()
const
220 {
return m_matrix.outerIndexPtr() + m_outerStart; }
221 inline StorageIndex* outerIndexPtr()
222 {
return m_matrix.const_cast_derived().outerIndexPtr() + m_outerStart; }
224 inline const StorageIndex* innerNonZeroPtr()
const
225 {
return isCompressed() ? 0 : (m_matrix.innerNonZeroPtr()+m_outerStart); }
226 inline StorageIndex* innerNonZeroPtr()
227 {
return isCompressed() ? 0 : (m_matrix.const_cast_derived().innerNonZeroPtr()+m_outerStart); }
229 bool isCompressed()
const {
return m_matrix.innerNonZeroPtr()==0; }
231 inline Scalar& coeffRef(Index row, Index col)
233 return m_matrix.const_cast_derived().coeffRef(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 : m_outerStart));
236 inline const Scalar coeff(Index row, Index col)
const
238 return m_matrix.coeff(row + (IsRowMajor ? m_outerStart : 0), col + (IsRowMajor ? 0 : m_outerStart));
241 inline const Scalar coeff(Index index)
const
243 return m_matrix.coeff(IsRowMajor ? m_outerStart : index, IsRowMajor ? index : m_outerStart);
246 const Scalar& lastCoeff()
const
250 if(m_matrix.isCompressed())
251 return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart+1]-1];
253 return m_matrix.valuePtr()[m_matrix.outerIndexPtr()[m_outerStart]+m_matrix.innerNonZeroPtr()[m_outerStart]-1];
256 EIGEN_STRONG_INLINE Index rows()
const {
return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
257 EIGEN_STRONG_INLINE Index cols()
const {
return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
260 Index startRow()
const {
return IsRowMajor ? m_outerStart : 0; }
261 Index startCol()
const {
return IsRowMajor ? 0 : m_outerStart; }
262 Index blockRows()
const {
return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
263 Index blockCols()
const {
return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
267 typename SparseMatrixType::Nested m_matrix;