00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_SPARSE_BLOCK_H
00027 #define EIGEN_SPARSE_BLOCK_H
00028
00029 template<typename MatrixType, int Size>
00030 struct ei_traits<SparseInnerVectorSet<MatrixType, Size> >
00031 {
00032 typedef typename ei_traits<MatrixType>::Scalar Scalar;
00033 enum {
00034 IsRowMajor = (int(MatrixType::Flags)&RowMajorBit)==RowMajorBit,
00035 Flags = MatrixType::Flags,
00036 RowsAtCompileTime = IsRowMajor ? Size : MatrixType::RowsAtCompileTime,
00037 ColsAtCompileTime = IsRowMajor ? MatrixType::ColsAtCompileTime : Size,
00038 CoeffReadCost = MatrixType::CoeffReadCost
00039 };
00040 };
00041
00042 template<typename MatrixType, int Size>
00043 class SparseInnerVectorSet : ei_no_assignment_operator,
00044 public SparseMatrixBase<SparseInnerVectorSet<MatrixType, Size> >
00045 {
00046 enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor };
00047 public:
00048
00049 EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseInnerVectorSet)
00050 class InnerIterator: public MatrixType::InnerIterator
00051 {
00052 public:
00053 inline InnerIterator(const SparseInnerVectorSet& xpr, int outer)
00054 : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer)
00055 {}
00056
00057 private:
00058 InnerIterator& operator=(const InnerIterator&);
00059 };
00060
00061 inline SparseInnerVectorSet(const MatrixType& matrix, int outerStart, int outerSize)
00062 : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize)
00063 {
00064 ei_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) );
00065 }
00066
00067 inline SparseInnerVectorSet(const MatrixType& matrix, int outer)
00068 : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size)
00069 {
00070 ei_assert(Size!=Dynamic);
00071 ei_assert( (outer>=0) && (outer<matrix.outerSize()) );
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 EIGEN_STRONG_INLINE int rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
00087 EIGEN_STRONG_INLINE int cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
00088
00089 protected:
00090
00091 const typename MatrixType::Nested m_matrix;
00092 int m_outerStart;
00093 const ei_int_if_dynamic<Size> m_outerSize;
00094
00095 };
00096
00097
00098
00099
00100
00101 template<typename _Scalar, int _Options, int Size>
00102 class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options>, Size>
00103 : public SparseMatrixBase<SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options>, Size> >
00104 {
00105 typedef DynamicSparseMatrix<_Scalar, _Options> MatrixType;
00106 enum { IsRowMajor = ei_traits<SparseInnerVectorSet>::IsRowMajor };
00107 public:
00108
00109 EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseInnerVectorSet)
00110 class InnerIterator: public MatrixType::InnerIterator
00111 {
00112 public:
00113 inline InnerIterator(const SparseInnerVectorSet& xpr, int outer)
00114 : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer)
00115 {}
00116 private:
00117 InnerIterator& operator=(const InnerIterator&);
00118 };
00119
00120 inline SparseInnerVectorSet(const MatrixType& matrix, int outerStart, int outerSize)
00121 : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize)
00122 {
00123 ei_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) );
00124 }
00125
00126 inline SparseInnerVectorSet(const MatrixType& matrix, int outer)
00127 : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size)
00128 {
00129 ei_assert(Size!=Dynamic);
00130 ei_assert( (outer>=0) && (outer<matrix.outerSize()) );
00131 }
00132
00133 template<typename OtherDerived>
00134 inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other)
00135 {
00136 if (IsRowMajor != ((OtherDerived::Flags&RowMajorBit)==RowMajorBit))
00137 {
00138
00139 DynamicSparseMatrix<Scalar,IsRowMajor?RowMajorBit:0> aux(other);
00140 *this = aux.markAsRValue();
00141 }
00142 else
00143 {
00144
00145 for (int j=0; j<m_outerSize.value(); ++j)
00146 {
00147 SparseVector<Scalar,IsRowMajor ? RowMajorBit : 0> aux(other.innerVector(j));
00148 m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data());
00149 }
00150 }
00151 return *this;
00152 }
00153
00154 inline SparseInnerVectorSet& operator=(const SparseInnerVectorSet& other)
00155 {
00156 return operator=<SparseInnerVectorSet>(other);
00157 }
00158
00159
00160
00161
00162
00163
00164
00165 EIGEN_STRONG_INLINE int rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
00166 EIGEN_STRONG_INLINE int cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
00167
00168 protected:
00169
00170 const typename MatrixType::Nested m_matrix;
00171 int m_outerStart;
00172 const ei_int_if_dynamic<Size> m_outerSize;
00173
00174 };
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00263 template<typename Derived>
00264 SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(int i)
00265 {
00266 EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES);
00267 return innerVector(i);
00268 }
00269
00272 template<typename Derived>
00273 const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::row(int i) const
00274 {
00275 EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES);
00276 return innerVector(i);
00277 }
00278
00280 template<typename Derived>
00281 SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(int i)
00282 {
00283 EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
00284 return innerVector(i);
00285 }
00286
00289 template<typename Derived>
00290 const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::col(int i) const
00291 {
00292 EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
00293 return innerVector(i);
00294 }
00295
00299 template<typename Derived>
00300 SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::innerVector(int outer)
00301 { return SparseInnerVectorSet<Derived,1>(derived(), outer); }
00302
00306 template<typename Derived>
00307 const SparseInnerVectorSet<Derived,1> SparseMatrixBase<Derived>::innerVector(int outer) const
00308 { return SparseInnerVectorSet<Derived,1>(derived(), outer); }
00309
00310
00311
00313 template<typename Derived>
00314 SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(int start, int size)
00315 {
00316 EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES);
00317 return innerVectors(start, size);
00318 }
00319
00322 template<typename Derived>
00323 const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subrows(int start, int size) const
00324 {
00325 EIGEN_STATIC_ASSERT(IsRowMajor,THIS_METHOD_IS_ONLY_FOR_ROW_MAJOR_MATRICES);
00326 return innerVectors(start, size);
00327 }
00328
00330 template<typename Derived>
00331 SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(int start, int size)
00332 {
00333 EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
00334 return innerVectors(start, size);
00335 }
00336
00339 template<typename Derived>
00340 const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::subcols(int start, int size) const
00341 {
00342 EIGEN_STATIC_ASSERT(!IsRowMajor,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
00343 return innerVectors(start, size);
00344 }
00345
00349 template<typename Derived>
00350 SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::innerVectors(int outerStart, int outerSize)
00351 { return SparseInnerVectorSet<Derived,Dynamic>(derived(), outerStart, outerSize); }
00352
00356 template<typename Derived>
00357 const SparseInnerVectorSet<Derived,Dynamic> SparseMatrixBase<Derived>::innerVectors(int outerStart, int outerSize) const
00358 { return SparseInnerVectorSet<Derived,Dynamic>(derived(), outerStart, outerSize); }
00359
00360 # if 0
00361 template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess>
00362 class Block<MatrixType,BlockRows,BlockCols,PacketAccess,IsSparse>
00363 : public SparseMatrixBase<Block<MatrixType,BlockRows,BlockCols,PacketAccess,IsSparse> >
00364 {
00365 public:
00366
00367 _EIGEN_GENERIC_PUBLIC_INTERFACE(Block, SparseMatrixBase<Block>)
00368 class InnerIterator;
00369
00372 inline Block(const MatrixType& matrix, int i)
00373 : m_matrix(matrix),
00374
00375
00376
00377
00378 m_startRow( (BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) ? i : 0),
00379 m_startCol( (BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
00380 m_blockRows(matrix.rows()),
00381 m_blockCols(matrix.cols())
00382 {
00383 ei_assert( (i>=0) && (
00384 ((BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) && i<matrix.rows())
00385 ||((BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) && i<matrix.cols())));
00386 }
00387
00390 inline Block(const MatrixType& matrix, int startRow, int startCol)
00391 : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol),
00392 m_blockRows(matrix.rows()), m_blockCols(matrix.cols())
00393 {
00394 EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && RowsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
00395 ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows()
00396 && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols());
00397 }
00398
00401 inline Block(const MatrixType& matrix,
00402 int startRow, int startCol,
00403 int blockRows, int blockCols)
00404 : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol),
00405 m_blockRows(blockRows), m_blockCols(blockCols)
00406 {
00407 ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
00408 && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
00409 ei_assert(startRow >= 0 && blockRows >= 1 && startRow + blockRows <= matrix.rows()
00410 && startCol >= 0 && blockCols >= 1 && startCol + blockCols <= matrix.cols());
00411 }
00412
00413 inline int rows() const { return m_blockRows.value(); }
00414 inline int cols() const { return m_blockCols.value(); }
00415
00416 inline int stride(void) const { return m_matrix.stride(); }
00417
00418 inline Scalar& coeffRef(int row, int col)
00419 {
00420 return m_matrix.const_cast_derived()
00421 .coeffRef(row + m_startRow.value(), col + m_startCol.value());
00422 }
00423
00424 inline const Scalar coeff(int row, int col) const
00425 {
00426 return m_matrix.coeff(row + m_startRow.value(), col + m_startCol.value());
00427 }
00428
00429 inline Scalar& coeffRef(int index)
00430 {
00431 return m_matrix.const_cast_derived()
00432 .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
00433 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
00434 }
00435
00436 inline const Scalar coeff(int index) const
00437 {
00438 return m_matrix
00439 .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
00440 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
00441 }
00442
00443 protected:
00444
00445 const typename MatrixType::Nested m_matrix;
00446 const ei_int_if_dynamic<MatrixType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
00447 const ei_int_if_dynamic<MatrixType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
00448 const ei_int_if_dynamic<RowsAtCompileTime> m_blockRows;
00449 const ei_int_if_dynamic<ColsAtCompileTime> m_blockCols;
00450
00451 };
00452 #endif
00453
00454 #endif // EIGEN_SPARSE_BLOCK_H