BlockOfDynamicSparseMatrix.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H
11 #define EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H
12 
13 namespace Eigen {
14 
15 #if 0
16 
17 // NOTE Have to be reimplemented as a specialization of BlockImpl< DynamicSparseMatrix<_Scalar, _Options, _Index>, ... >
18 // See SparseBlock.h for an example
19 
20 
21 /***************************************************************************
22 * specialisation for DynamicSparseMatrix
23 ***************************************************************************/
24 
25 template<typename _Scalar, int _Options, typename _Index, int Size>
26 class SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size>
27  : public SparseMatrixBase<SparseInnerVectorSet<DynamicSparseMatrix<_Scalar, _Options, _Index>, Size> >
28 {
29  typedef DynamicSparseMatrix<_Scalar, _Options, _Index> MatrixType;
30  public:
31 
32  enum { IsRowMajor = internal::traits<SparseInnerVectorSet>::IsRowMajor };
33 
34  EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet)
35  class InnerIterator: public MatrixType::InnerIterator
36  {
37  public:
38  inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer)
39  : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer)
40  {}
41  inline Index row() const { return IsRowMajor ? m_outer : this->index(); }
42  inline Index col() const { return IsRowMajor ? this->index() : m_outer; }
43  protected:
44  Index m_outer;
45  };
46 
47  inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize)
48  : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize)
49  {
50  eigen_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) );
51  }
52 
53  inline SparseInnerVectorSet(const MatrixType& matrix, Index outer)
54  : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size)
55  {
56  eigen_assert(Size!=Dynamic);
57  eigen_assert( (outer>=0) && (outer<matrix.outerSize()) );
58  }
59 
60  template<typename OtherDerived>
61  inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other)
62  {
63  if (IsRowMajor != ((OtherDerived::Flags&RowMajorBit)==RowMajorBit))
64  {
65  // need to transpose => perform a block evaluation followed by a big swap
66  DynamicSparseMatrix<Scalar,IsRowMajor?RowMajorBit:0> aux(other);
67  *this = aux.markAsRValue();
68  }
69  else
70  {
71  // evaluate/copy vector per vector
72  for (Index j=0; j<m_outerSize.value(); ++j)
73  {
74  SparseVector<Scalar,IsRowMajor ? RowMajorBit : 0> aux(other.innerVector(j));
75  m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data());
76  }
77  }
78  return *this;
79  }
80 
81  inline SparseInnerVectorSet& operator=(const SparseInnerVectorSet& other)
82  {
83  return operator=<SparseInnerVectorSet>(other);
84  }
85 
86  Index nonZeros() const
87  {
88  Index count = 0;
89  for (Index j=0; j<m_outerSize.value(); ++j)
90  count += m_matrix._data()[m_outerStart+j].size();
91  return count;
92  }
93 
94  const Scalar& lastCoeff() const
95  {
96  EIGEN_STATIC_ASSERT_VECTOR_ONLY(SparseInnerVectorSet);
97  eigen_assert(m_matrix.data()[m_outerStart].size()>0);
98  return m_matrix.data()[m_outerStart].vale(m_matrix.data()[m_outerStart].size()-1);
99  }
100 
101 // template<typename Sparse>
102 // inline SparseInnerVectorSet& operator=(const SparseMatrixBase<OtherDerived>& other)
103 // {
104 // return *this;
105 // }
106 
107  EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
108  EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
109 
110  protected:
111 
112  const typename MatrixType::Nested m_matrix;
113  Index m_outerStart;
114  const internal::variable_if_dynamic<Index, Size> m_outerSize;
115 
116 };
117 
118 #endif
119 
120 } // end namespace Eigen
121 
122 #endif // EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
Definition: LDLT.h:16
const unsigned int RowMajorBit
Definition: Constants.h:61
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Definition: SparseUtil.h:43
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:838
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
#define eigen_assert(x)
Definition: Macros.h:577
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). */.
Definition: BlockMethods.h:859
const int Dynamic
Definition: Constants.h:21
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:137


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:02