Eigen  3.3.0
SparseTranspose.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2015 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_SPARSETRANSPOSE_H
11 #define EIGEN_SPARSETRANSPOSE_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16  template<typename MatrixType,int CompressedAccess=int(MatrixType::Flags&CompressedAccessBit)>
17  class SparseTransposeImpl
18  : public SparseMatrixBase<Transpose<MatrixType> >
19  {};
20 
21  template<typename MatrixType>
22  class SparseTransposeImpl<MatrixType,CompressedAccessBit>
23  : public SparseCompressedBase<Transpose<MatrixType> >
24  {
25  typedef SparseCompressedBase<Transpose<MatrixType> > Base;
26  public:
27  using Base::derived;
28  typedef typename Base::Scalar Scalar;
29  typedef typename Base::StorageIndex StorageIndex;
30 
31  inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); }
32 
33  inline const Scalar* valuePtr() const { return derived().nestedExpression().valuePtr(); }
34  inline const StorageIndex* innerIndexPtr() const { return derived().nestedExpression().innerIndexPtr(); }
35  inline const StorageIndex* outerIndexPtr() const { return derived().nestedExpression().outerIndexPtr(); }
36  inline const StorageIndex* innerNonZeroPtr() const { return derived().nestedExpression().innerNonZeroPtr(); }
37 
38  inline Scalar* valuePtr() { return derived().nestedExpression().valuePtr(); }
39  inline StorageIndex* innerIndexPtr() { return derived().nestedExpression().innerIndexPtr(); }
40  inline StorageIndex* outerIndexPtr() { return derived().nestedExpression().outerIndexPtr(); }
41  inline StorageIndex* innerNonZeroPtr() { return derived().nestedExpression().innerNonZeroPtr(); }
42  };
43 }
44 
45 template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>
46  : public internal::SparseTransposeImpl<MatrixType>
47 {
48  protected:
49  typedef internal::SparseTransposeImpl<MatrixType> Base;
50 };
51 
52 namespace internal {
53 
54 template<typename ArgType>
55 struct unary_evaluator<Transpose<ArgType>, IteratorBased>
56  : public evaluator_base<Transpose<ArgType> >
57 {
58  typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
59  typedef typename evaluator<ArgType>::ReverseInnerIterator EvalReverseIterator;
60  public:
61  typedef Transpose<ArgType> XprType;
62 
63  inline Index nonZerosEstimate() const {
64  return m_argImpl.nonZerosEstimate();
65  }
66 
67  class InnerIterator : public EvalIterator
68  {
69  public:
70  EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& unaryOp, Index outer)
71  : EvalIterator(unaryOp.m_argImpl,outer)
72  {}
73 
74  Index row() const { return EvalIterator::col(); }
75  Index col() const { return EvalIterator::row(); }
76  };
77 
78  class ReverseInnerIterator : public EvalReverseIterator
79  {
80  public:
81  EIGEN_STRONG_INLINE ReverseInnerIterator(const unary_evaluator& unaryOp, Index outer)
82  : EvalReverseIterator(unaryOp.m_argImpl,outer)
83  {}
84 
85  Index row() const { return EvalReverseIterator::col(); }
86  Index col() const { return EvalReverseIterator::row(); }
87  };
88 
89  enum {
90  CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
91  Flags = XprType::Flags
92  };
93 
94  explicit unary_evaluator(const XprType& op) :m_argImpl(op.nestedExpression()) {}
95 
96  protected:
97  evaluator<ArgType> m_argImpl;
98 };
99 
100 } // end namespace internal
101 
102 } // end namespace Eigen
103 
104 #endif // EIGEN_SPARSETRANSPOSE_H
const unsigned int CompressedAccessBit
Definition: Constants.h:186
Namespace containing all symbols from the Eigen library.
Definition: Core:287
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Eigen_Colamd.h:50