SparseTranspose.h 2.43 KB
Newer Older
LM's avatar
LM committed
1 2 3 4 5
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
//
Don Gagne's avatar
Don Gagne committed
6 7 8
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
LM's avatar
LM committed
9 10 11 12

#ifndef EIGEN_SPARSETRANSPOSE_H
#define EIGEN_SPARSETRANSPOSE_H

Don Gagne's avatar
Don Gagne committed
13 14
namespace Eigen { 

LM's avatar
LM committed
15 16 17 18 19 20
template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>
  : public SparseMatrixBase<Transpose<MatrixType> >
{
    typedef typename internal::remove_all<typename MatrixType::Nested>::type _MatrixTypeNested;
  public:

Don Gagne's avatar
Don Gagne committed
21
    EIGEN_SPARSE_PUBLIC_INTERFACE(Transpose<MatrixType> )
LM's avatar
LM committed
22 23 24 25 26 27 28

    class InnerIterator;
    class ReverseInnerIterator;

    inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); }
};

29
// NOTE: VC10 and VC11 trigger an ICE if don't put typename TransposeImpl<MatrixType,Sparse>:: in front of Index,
Don Gagne's avatar
Don Gagne committed
30 31 32
// a typedef typename TransposeImpl<MatrixType,Sparse>::Index Index;
// does not fix the issue.
// An alternative is to define the nested class in the parent class itself.
LM's avatar
LM committed
33 34 35 36
template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::InnerIterator
  : public _MatrixTypeNested::InnerIterator
{
    typedef typename _MatrixTypeNested::InnerIterator Base;
Don Gagne's avatar
Don Gagne committed
37
    typedef typename TransposeImpl::Index Index;
LM's avatar
LM committed
38 39
  public:

Don Gagne's avatar
Don Gagne committed
40
    EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, typename TransposeImpl<MatrixType,Sparse>::Index outer)
LM's avatar
LM committed
41 42
      : Base(trans.derived().nestedExpression(), outer)
    {}
43 44
    typename TransposeImpl<MatrixType,Sparse>::Index row() const { return Base::col(); }
    typename TransposeImpl<MatrixType,Sparse>::Index col() const { return Base::row(); }
LM's avatar
LM committed
45 46 47 48 49 50
};

template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>::ReverseInnerIterator
  : public _MatrixTypeNested::ReverseInnerIterator
{
    typedef typename _MatrixTypeNested::ReverseInnerIterator Base;
Don Gagne's avatar
Don Gagne committed
51
    typedef typename TransposeImpl::Index Index;
LM's avatar
LM committed
52 53
  public:

Don Gagne's avatar
Don Gagne committed
54
    EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, typename TransposeImpl<MatrixType,Sparse>::Index outer)
LM's avatar
LM committed
55 56
      : Base(xpr.derived().nestedExpression(), outer)
    {}
57 58
    typename TransposeImpl<MatrixType,Sparse>::Index row() const { return Base::col(); }
    typename TransposeImpl<MatrixType,Sparse>::Index col() const { return Base::row(); }
LM's avatar
LM committed
59 60
};

Don Gagne's avatar
Don Gagne committed
61 62
} // end namespace Eigen

LM's avatar
LM committed
63
#endif // EIGEN_SPARSETRANSPOSE_H