SparseTranspose.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef EIGEN_SPARSETRANSPOSE_H
  10. #define EIGEN_SPARSETRANSPOSE_H
  11. namespace Eigen {
  12. namespace internal {
  13. template<typename MatrixType,int CompressedAccess=int(MatrixType::Flags&CompressedAccessBit)>
  14. class SparseTransposeImpl
  15. : public SparseMatrixBase<Transpose<MatrixType> >
  16. {};
  17. template<typename MatrixType>
  18. class SparseTransposeImpl<MatrixType,CompressedAccessBit>
  19. : public SparseCompressedBase<Transpose<MatrixType> >
  20. {
  21. typedef SparseCompressedBase<Transpose<MatrixType> > Base;
  22. public:
  23. using Base::derived;
  24. typedef typename Base::Scalar Scalar;
  25. typedef typename Base::StorageIndex StorageIndex;
  26. inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); }
  27. inline const Scalar* valuePtr() const { return derived().nestedExpression().valuePtr(); }
  28. inline const StorageIndex* innerIndexPtr() const { return derived().nestedExpression().innerIndexPtr(); }
  29. inline const StorageIndex* outerIndexPtr() const { return derived().nestedExpression().outerIndexPtr(); }
  30. inline const StorageIndex* innerNonZeroPtr() const { return derived().nestedExpression().innerNonZeroPtr(); }
  31. inline Scalar* valuePtr() { return derived().nestedExpression().valuePtr(); }
  32. inline StorageIndex* innerIndexPtr() { return derived().nestedExpression().innerIndexPtr(); }
  33. inline StorageIndex* outerIndexPtr() { return derived().nestedExpression().outerIndexPtr(); }
  34. inline StorageIndex* innerNonZeroPtr() { return derived().nestedExpression().innerNonZeroPtr(); }
  35. };
  36. }
  37. template<typename MatrixType> class TransposeImpl<MatrixType,Sparse>
  38. : public internal::SparseTransposeImpl<MatrixType>
  39. {
  40. protected:
  41. typedef internal::SparseTransposeImpl<MatrixType> Base;
  42. };
  43. namespace internal {
  44. template<typename ArgType>
  45. struct unary_evaluator<Transpose<ArgType>, IteratorBased>
  46. : public evaluator_base<Transpose<ArgType> >
  47. {
  48. typedef typename evaluator<ArgType>::InnerIterator EvalIterator;
  49. public:
  50. typedef Transpose<ArgType> XprType;
  51. inline Index nonZerosEstimate() const {
  52. return m_argImpl.nonZerosEstimate();
  53. }
  54. class InnerIterator : public EvalIterator
  55. {
  56. public:
  57. EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& unaryOp, Index outer)
  58. : EvalIterator(unaryOp.m_argImpl,outer)
  59. {}
  60. Index row() const { return EvalIterator::col(); }
  61. Index col() const { return EvalIterator::row(); }
  62. };
  63. enum {
  64. CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
  65. Flags = XprType::Flags
  66. };
  67. explicit unary_evaluator(const XprType& op) :m_argImpl(op.nestedExpression()) {}
  68. protected:
  69. evaluator<ArgType> m_argImpl;
  70. };
  71. } // end namespace internal
  72. } // end namespace Eigen
  73. #endif // EIGEN_SPARSETRANSPOSE_H