SparseTranspose.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 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_SPARSETRANSPOSE_H
26 #define EIGEN_SPARSETRANSPOSE_H
27 
28 namespace Eigen {
29 
30 template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>
31  : public SparseMatrixBase<Transpose<MatrixType> >
32 {
33  typedef typename internal::remove_all<typename MatrixType::Nested>::type _MatrixTypeNested;
34  public:
35 
37 
38  class InnerIterator;
39  class ReverseInnerIterator;
40 
41  inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); }
42 };
43 
44 // NOTE: VC10 trigger an ICE if don't put typename TransposeImpl<MatrixType,Sparse>:: in front of Index,
45 // a typedef typename TransposeImpl<MatrixType,Sparse>::Index Index;
46 // does not fix the issue.
47 // An alternative is to define the nested class in the parent class itself.
48 template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::InnerIterator
49  : public _MatrixTypeNested::InnerIterator
50 {
51  typedef typename _MatrixTypeNested::InnerIterator Base;
52  public:
53 
54  EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, typename TransposeImpl<MatrixType,Sparse>::Index outer)
55  : Base(trans.derived().nestedExpression(), outer)
56  {}
57  inline typename TransposeImpl<MatrixType,Sparse>::Index row() const { return Base::col(); }
58  inline typename TransposeImpl<MatrixType,Sparse>::Index col() const { return Base::row(); }
59 };
60 
61 template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::ReverseInnerIterator
62  : public _MatrixTypeNested::ReverseInnerIterator
63 {
64  typedef typename _MatrixTypeNested::ReverseInnerIterator Base;
65  public:
66 
67  EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, typename TransposeImpl<MatrixType,Sparse>::Index outer)
68  : Base(xpr.derived().nestedExpression(), outer)
69  {}
70  inline typename TransposeImpl<MatrixType,Sparse>::Index row() const { return Base::col(); }
71  inline typename TransposeImpl<MatrixType,Sparse>::Index col() const { return Base::row(); }
72 };
73 
74 } // end namespace Eigen
75 
76 #endif // EIGEN_SPARSETRANSPOSE_H