SparseTriangularView.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) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_SPARSE_TRIANGULARVIEW_H
12 #define EIGEN_SPARSE_TRIANGULARVIEW_H
13 
14 namespace Eigen {
15 
25 template<typename MatrixType, unsigned int Mode> class TriangularViewImpl<MatrixType,Mode,Sparse>
26  : public SparseMatrixBase<TriangularView<MatrixType,Mode> >
27 {
28  enum { SkipFirst = ((Mode&Lower) && !(MatrixType::Flags&RowMajorBit))
29  || ((Mode&Upper) && (MatrixType::Flags&RowMajorBit)),
30  SkipLast = !SkipFirst,
31  SkipDiag = (Mode&ZeroDiag) ? 1 : 0,
32  HasUnitDiag = (Mode&UnitDiag) ? 1 : 0
33  };
34 
36 
37  protected:
38  // dummy solve function to make TriangularView happy.
39  void solve() const;
40 
42  public:
43 
45 
46  typedef typename MatrixType::Nested MatrixTypeNested;
47  typedef typename internal::remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef;
48  typedef typename internal::remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
49 
50  template<typename RhsType, typename DstType>
52  EIGEN_STRONG_INLINE void _solve_impl(const RhsType &rhs, DstType &dst) const {
54  dst = rhs;
55  this->solveInPlace(dst);
56  }
57 
59  template<typename OtherDerived> void solveInPlace(MatrixBase<OtherDerived>& other) const;
60 
62  template<typename OtherDerived> void solveInPlace(SparseMatrixBase<OtherDerived>& other) const;
63 
64 };
65 
66 namespace internal {
67 
68 template<typename ArgType, unsigned int Mode>
70  : evaluator_base<TriangularView<ArgType,Mode> >
71 {
73 
74 protected:
75 
76  typedef typename XprType::Scalar Scalar;
77  typedef typename XprType::StorageIndex StorageIndex;
79 
80  enum { SkipFirst = ((Mode&Lower) && !(ArgType::Flags&RowMajorBit))
81  || ((Mode&Upper) && (ArgType::Flags&RowMajorBit)),
82  SkipLast = !SkipFirst,
83  SkipDiag = (Mode&ZeroDiag) ? 1 : 0,
84  HasUnitDiag = (Mode&UnitDiag) ? 1 : 0
85  };
86 
87 public:
88 
89  enum {
91  Flags = XprType::Flags
92  };
93 
94  explicit unary_evaluator(const XprType &xpr) : m_argImpl(xpr.nestedExpression()), m_arg(xpr.nestedExpression()) {}
95 
96  inline Index nonZerosEstimate() const {
97  return m_argImpl.nonZerosEstimate();
98  }
99 
101  {
103  public:
104 
106  : Base(xprEval.m_argImpl,outer), m_returnOne(false), m_containsDiag(Base::outer()<xprEval.m_arg.innerSize())
107  {
108  if(SkipFirst)
109  {
110  while((*this) && ((HasUnitDiag||SkipDiag) ? this->index()<=outer : this->index()<outer))
112  if(HasUnitDiag)
113  m_returnOne = m_containsDiag;
114  }
115  else if(HasUnitDiag && ((!Base::operator bool()) || Base::index()>=Base::outer()))
116  {
117  if((!SkipFirst) && Base::operator bool())
119  m_returnOne = m_containsDiag;
120  }
121  }
122 
124  {
125  if(HasUnitDiag && m_returnOne)
126  m_returnOne = false;
127  else
128  {
130  if(HasUnitDiag && (!SkipFirst) && ((!Base::operator bool()) || Base::index()>=Base::outer()))
131  {
132  if((!SkipFirst) && Base::operator bool())
134  m_returnOne = m_containsDiag;
135  }
136  }
137  return *this;
138  }
139 
140  EIGEN_STRONG_INLINE operator bool() const
141  {
142  if(HasUnitDiag && m_returnOne)
143  return true;
144  if(SkipFirst) return Base::operator bool();
145  else
146  {
147  if (SkipDiag) return (Base::operator bool() && this->index() < this->outer());
148  else return (Base::operator bool() && this->index() <= this->outer());
149  }
150  }
151 
152 // inline Index row() const { return (ArgType::Flags&RowMajorBit ? Base::outer() : this->index()); }
153 // inline Index col() const { return (ArgType::Flags&RowMajorBit ? this->index() : Base::outer()); }
154  inline StorageIndex index() const
155  {
156  if(HasUnitDiag && m_returnOne) return internal::convert_index<StorageIndex>(Base::outer());
157  else return Base::index();
158  }
159  inline Scalar value() const
160  {
161  if(HasUnitDiag && m_returnOne) return Scalar(1);
162  else return Base::value();
163  }
164 
165  protected:
168  private:
169  Scalar& valueRef();
170  };
171 
172 protected:
174  const ArgType& m_arg;
175 };
176 
177 } // end namespace internal
178 
179 template<typename Derived>
180 template<int Mode>
183 {
184  return TriangularView<const Derived, Mode>(derived());
185 }
186 
187 } // end namespace Eigen
188 
189 #endif // EIGEN_SPARSE_TRIANGULARVIEW_H
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::TriangularViewImpl< MatrixType, Mode, Sparse >::MatrixTypeNested
MatrixType::Nested MatrixTypeNested
Definition: SparseTriangularView.h:46
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Eigen::Sparse
Definition: Constants.h:510
Eigen::TriangularViewImpl< MatrixType, Mode, Sparse >::Base
SparseMatrixBase< TriangularViewType > Base
Definition: SparseTriangularView.h:41
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::InnerIterator::InnerIterator
EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator &xprEval, Index outer)
Definition: SparseTriangularView.h:105
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
Eigen::Upper
@ Upper
Definition: Constants.h:211
type
Definition: pytypes.h:1525
Eigen::internal::evaluator_base
Definition: CoreEvaluators.h:110
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::InnerIterator::index
StorageIndex index() const
Definition: SparseTriangularView.h:154
EIGEN_SPARSE_PUBLIC_INTERFACE
#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived)
Definition: SparseUtil.h:43
Eigen::SparseMatrixBase::triangularView
const TriangularView< const Derived, Mode > triangularView() const
Definition: SparseTriangularView.h:182
Eigen::TriangularView::Scalar
internal::traits< TriangularView >::Scalar Scalar
Definition: TriangularMatrix.h:193
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::InnerIterator::m_containsDiag
bool m_containsDiag
Definition: SparseTriangularView.h:167
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::Scalar
XprType::Scalar Scalar
Definition: SparseTriangularView.h:76
Eigen::ZeroDiag
@ ZeroDiag
Definition: Constants.h:215
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::unary_evaluator
unary_evaluator(const XprType &xpr)
Definition: SparseTriangularView.h:94
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::m_arg
const ArgType & m_arg
Definition: SparseTriangularView.h:174
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::internal::IteratorBased
Definition: Constants.h:545
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::StorageIndex
XprType::StorageIndex StorageIndex
Definition: SparseTriangularView.h:77
Eigen::Triplet< double >
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::bfloat16_impl::operator++
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator++(bfloat16 &a)
Definition: BFloat16.h:200
Eigen::Lower
@ Lower
Definition: Constants.h:209
Eigen::InnerIterator
An InnerIterator allows to loop over the element of any matrix expression.
Definition: CoreIterators.h:33
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::XprType
TriangularView< ArgType, Mode > XprType
Definition: SparseTriangularView.h:72
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::nonZerosEstimate
Index nonZerosEstimate() const
Definition: SparseTriangularView.h:96
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::InnerIterator::operator++
EIGEN_STRONG_INLINE InnerIterator & operator++()
Definition: SparseTriangularView.h:123
Eigen::TriangularViewImpl< MatrixType, Mode, Sparse >::TriangularViewType
TriangularView< MatrixType, Mode > TriangularViewType
Definition: SparseTriangularView.h:35
Eigen::internal::extract_data
EIGEN_DEVICE_FUNC const EIGEN_ALWAYS_INLINE T::Scalar * extract_data(const T &m)
Definition: BlasUtil.h:533
Eigen::TriangularViewImpl
Definition: TriangularMatrix.h:185
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::InnerIterator::m_returnOne
bool m_returnOne
Definition: SparseTriangularView.h:166
Eigen::internal::unary_evaluator
Definition: CoreEvaluators.h:65
Eigen::SparseMatrixBase
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:301
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::InnerIterator::value
Scalar value() const
Definition: SparseTriangularView.h:159
Eigen::internal::is_same
Definition: Meta.h:148
internal
Definition: BandTriangularSolver.h:13
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::m_argImpl
evaluator< ArgType > m_argImpl
Definition: SparseTriangularView.h:173
Base
Definition: test_virtual_functions.cpp:156
Eigen::TriangularView
Expression of a triangular part in a matrix.
Definition: TriangularMatrix.h:187
test_callbacks.value
value
Definition: test_callbacks.py:160
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::EvalIterator
evaluator< ArgType >::InnerIterator EvalIterator
Definition: SparseTriangularView.h:78
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::UnitDiag
@ UnitDiag
Definition: Constants.h:213
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::internal::unary_evaluator< TriangularView< ArgType, Mode >, IteratorBased >::InnerIterator::Base
EvalIterator Base
Definition: SparseTriangularView.h:102


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:03:46