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_SPARSETRANSPOSE_H
11 #define EIGEN_SPARSETRANSPOSE_H
12 
13 namespace Eigen {
14 
15 template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>
16   : public SparseMatrixBase<Transpose<MatrixType> >
17 {
18     typedef typename internal::remove_all<typename MatrixType::Nested>::type _MatrixTypeNested;
19   public:
20 
21     EIGEN_SPARSE_PUBLIC_INTERFACE(Transpose<MatrixType> )
22 
23     class InnerIterator;
24     class ReverseInnerIterator;
25 
nonZeros()26     inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); }
27 };
28 
29 // NOTE: VC10 and VC11 trigger an ICE if don't put typename TransposeImpl<MatrixType,Sparse>:: in front of Index,
30 // a typedef typename TransposeImpl<MatrixType,Sparse>::Index Index;
31 // does not fix the issue.
32 // An alternative is to define the nested class in the parent class itself.
33 template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::InnerIterator
34   : public _MatrixTypeNested::InnerIterator
35 {
36     typedef typename _MatrixTypeNested::InnerIterator Base;
37     typedef typename TransposeImpl::Index Index;
38   public:
39 
InnerIterator(const TransposeImpl & trans,typename TransposeImpl<MatrixType,Sparse>::Index outer)40     EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, typename TransposeImpl<MatrixType,Sparse>::Index outer)
41       : Base(trans.derived().nestedExpression(), outer)
42     {}
row()43     typename TransposeImpl<MatrixType,Sparse>::Index row() const { return Base::col(); }
col()44     typename TransposeImpl<MatrixType,Sparse>::Index col() const { return Base::row(); }
45 };
46 
47 template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::ReverseInnerIterator
48   : public _MatrixTypeNested::ReverseInnerIterator
49 {
50     typedef typename _MatrixTypeNested::ReverseInnerIterator Base;
51     typedef typename TransposeImpl::Index Index;
52   public:
53 
ReverseInnerIterator(const TransposeImpl & xpr,typename TransposeImpl<MatrixType,Sparse>::Index outer)54     EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, typename TransposeImpl<MatrixType,Sparse>::Index outer)
55       : Base(xpr.derived().nestedExpression(), outer)
56     {}
row()57     typename TransposeImpl<MatrixType,Sparse>::Index row() const { return Base::col(); }
col()58     typename TransposeImpl<MatrixType,Sparse>::Index col() const { return Base::row(); }
59 };
60 
61 } // end namespace Eigen
62 
63 #endif // EIGEN_SPARSETRANSPOSE_H
64