$treeview $search $mathjax
Eigen-unsupported
3.2.5
$projectbrief
|
$projectbrief
|
$searchbox |
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H 00011 #define EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H 00012 00013 namespace Eigen { 00014 00015 #if 0 00016 00017 // NOTE Have to be reimplemented as a specialization of BlockImpl< DynamicSparseMatrix<_Scalar, _Options, _Index>, ... > 00018 // See SparseBlock.h for an example 00019 00020 00021 /*************************************************************************** 00022 * specialisation for DynamicSparseMatrix 00023 ***************************************************************************/ 00024 00025 template<typename _Scalar, int _Options, typename _Index, int Size> 00026 class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size> 00027 : public SparseMatrixBase<SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size> > 00028 { 00029 typedef DynamicSparseMatrix<_Scalar, _Options, _Index> MatrixType; 00030 public: 00031 00032 enum { IsRowMajor = internal::traits<SparseInnerVectorSet>::IsRowMajor }; 00033 00034 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet) 00035 class InnerIterator: public MatrixType::InnerIterator 00036 { 00037 public: 00038 inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer) 00039 : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) 00040 {} 00041 inline Index row() const { return IsRowMajor ? m_outer : this->index(); } 00042 inline Index col() const { return IsRowMajor ? this->index() : m_outer; } 00043 protected: 00044 Index m_outer; 00045 }; 00046 00047 inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize) 00048 : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize) 00049 { 00050 eigen_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) ); 00051 } 00052 00053 inline SparseInnerVectorSet(const MatrixType& matrix, Index outer) 00054 : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size) 00055 { 00056 eigen_assert(Size!=Dynamic); 00057 eigen_assert( (outer>=0) && (outer<matrix.outerSize()) ); 00058 } 00059 00060 template<typename OtherDerived> 00061 inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other) 00062 { 00063 if (IsRowMajor != ((OtherDerived::Flags&RowMajorBit)==RowMajorBit)) 00064 { 00065 // need to transpose => perform a block evaluation followed by a big swap 00066 DynamicSparseMatrix<Scalar,IsRowMajor?RowMajorBit:0> aux(other); 00067 *this = aux.markAsRValue(); 00068 } 00069 else 00070 { 00071 // evaluate/copy vector per vector 00072 for (Index j=0; j<m_outerSize.value(); ++j) 00073 { 00074 SparseVector<Scalar,IsRowMajor ? RowMajorBit : 0> aux(other.innerVector(j)); 00075 m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data()); 00076 } 00077 } 00078 return *this; 00079 } 00080 00081 inline SparseInnerVectorSet& operator=(const SparseInnerVectorSet& other) 00082 { 00083 return operator=<SparseInnerVectorSet>(other); 00084 } 00085 00086 Index nonZeros() const 00087 { 00088 Index count = 0; 00089 for (Index j=0; j<m_outerSize.value(); ++j) 00090 count += m_matrix._data()[m_outerStart+j].size(); 00091 return count; 00092 } 00093 00094 const Scalar& lastCoeff() const 00095 { 00096 EIGEN_STATIC_ASSERT_VECTOR_ONLY(SparseInnerVectorSet); 00097 eigen_assert(m_matrix.data()[m_outerStart].size()>0); 00098 return m_matrix.data()[m_outerStart].vale(m_matrix.data()[m_outerStart].size()-1); 00099 } 00100 00101 // template<typename Sparse> 00102 // inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other) 00103 // { 00104 // return *this; 00105 // } 00106 00107 EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } 00108 EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } 00109 00110 protected: 00111 00112 const typename MatrixType::Nested m_matrix; 00113 Index m_outerStart; 00114 const internal::variable_if_dynamic<Index, Size> m_outerSize; 00115 00116 }; 00117 00118 #endif 00119 00120 } // end namespace Eigen 00121 00122 #endif // EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H