Diagonal.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_DIAGONAL_H
00012 #define EIGEN_DIAGONAL_H
00013 
00014 namespace Eigen { 
00015 
00035 namespace internal {
00036 template<typename MatrixType, int DiagIndex>
00037 struct traits<Diagonal<MatrixType,DiagIndex> >
00038  : traits<MatrixType>
00039 {
00040   typedef typename nested<MatrixType>::type MatrixTypeNested;
00041   typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
00042   typedef typename MatrixType::StorageKind StorageKind;
00043   enum {
00044     RowsAtCompileTime = (int(DiagIndex) == Dynamic || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic
00045     : (EIGEN_PLAIN_ENUM_MIN(MatrixType::RowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
00046                             MatrixType::ColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
00047     ColsAtCompileTime = 1,
00048     MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic
00049                          : DiagIndex == Dynamic ? EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime,
00050                                                                               MatrixType::MaxColsAtCompileTime)
00051                          : (EIGEN_PLAIN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime - EIGEN_PLAIN_ENUM_MAX(-DiagIndex, 0),
00052                                                  MatrixType::MaxColsAtCompileTime - EIGEN_PLAIN_ENUM_MAX( DiagIndex, 0))),
00053     MaxColsAtCompileTime = 1,
00054     MaskLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
00055     Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit,
00056     CoeffReadCost = _MatrixTypeNested::CoeffReadCost,
00057     MatrixTypeOuterStride = outer_stride_at_compile_time<MatrixType>::ret,
00058     InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
00059     OuterStrideAtCompileTime = 0
00060   };
00061 };
00062 }
00063 
00064 template<typename MatrixType, int DiagIndex> class Diagonal
00065    : public internal::dense_xpr_base< Diagonal<MatrixType,DiagIndex> >::type
00066 {
00067   public:
00068 
00069     typedef typename internal::dense_xpr_base<Diagonal>::type Base;
00070     EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal)
00071 
00072     inline Diagonal(MatrixType& matrix, Index index = DiagIndex) : m_matrix(matrix), m_index(index) {}
00073 
00074     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal)
00075 
00076     inline Index rows() const
00077     { return m_index.value()<0 ? (std::min)(m_matrix.cols(),m_matrix.rows()+m_index.value()) : (std::min)(m_matrix.rows(),m_matrix.cols()-m_index.value()); }
00078 
00079     inline Index cols() const { return 1; }
00080 
00081     inline Index innerStride() const
00082     {
00083       return m_matrix.outerStride() + 1;
00084     }
00085 
00086     inline Index outerStride() const
00087     {
00088       return 0;
00089     }
00090 
00091     typedef typename internal::conditional<
00092                        internal::is_lvalue<MatrixType>::value,
00093                        Scalar,
00094                        const Scalar
00095                      >::type ScalarWithConstIfNotLvalue;
00096 
00097     inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
00098     inline const Scalar* data() const { return &(m_matrix.const_cast_derived().coeffRef(rowOffset(), colOffset())); }
00099 
00100     inline Scalar& coeffRef(Index row, Index)
00101     {
00102       EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
00103       return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
00104     }
00105 
00106     inline const Scalar& coeffRef(Index row, Index) const
00107     {
00108       return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset());
00109     }
00110 
00111     inline CoeffReturnType coeff(Index row, Index) const
00112     {
00113       return m_matrix.coeff(row+rowOffset(), row+colOffset());
00114     }
00115 
00116     inline Scalar& coeffRef(Index index)
00117     {
00118       EIGEN_STATIC_ASSERT_LVALUE(MatrixType)
00119       return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
00120     }
00121 
00122     inline const Scalar& coeffRef(Index index) const
00123     {
00124       return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset());
00125     }
00126 
00127     inline CoeffReturnType coeff(Index index) const
00128     {
00129       return m_matrix.coeff(index+rowOffset(), index+colOffset());
00130     }
00131 
00132     const typename internal::remove_all<typename MatrixType::Nested>::type& 
00133     nestedExpression() const 
00134     {
00135       return m_matrix;
00136     }
00137 
00138     int index() const
00139     {
00140       return m_index.value();
00141     }
00142 
00143   protected:
00144     typename MatrixType::Nested m_matrix;
00145     const internal::variable_if_dynamic<Index, DiagIndex> m_index;
00146 
00147   private:
00148     // some compilers may fail to optimize std::max etc in case of compile-time constants...
00149     EIGEN_STRONG_INLINE Index absDiagIndex() const { return m_index.value()>0 ? m_index.value() : -m_index.value(); }
00150     EIGEN_STRONG_INLINE Index rowOffset() const { return m_index.value()>0 ? 0 : -m_index.value(); }
00151     EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value()>0 ? m_index.value() : 0; }
00152     // triger a compile time error is someone try to call packet
00153     template<int LoadMode> typename MatrixType::PacketReturnType packet(Index) const;
00154     template<int LoadMode> typename MatrixType::PacketReturnType packet(Index,Index) const;
00155 };
00156 
00165 template<typename Derived>
00166 inline typename MatrixBase<Derived>::DiagonalReturnType
00167 MatrixBase<Derived>::diagonal()
00168 {
00169   return derived();
00170 }
00171 
00173 template<typename Derived>
00174 inline const typename MatrixBase<Derived>::ConstDiagonalReturnType
00175 MatrixBase<Derived>::diagonal() const
00176 {
00177   return ConstDiagonalReturnType(derived());
00178 }
00179 
00191 template<typename Derived>
00192 inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Dynamic>::Type
00193 MatrixBase<Derived>::diagonal(Index index)
00194 {
00195   return typename DiagonalIndexReturnType<Dynamic>::Type(derived(), index);
00196 }
00197 
00199 template<typename Derived>
00200 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Dynamic>::Type
00201 MatrixBase<Derived>::diagonal(Index index) const
00202 {
00203   return typename ConstDiagonalIndexReturnType<Dynamic>::Type(derived(), index);
00204 }
00205 
00217 template<typename Derived>
00218 template<int Index>
00219 inline typename MatrixBase<Derived>::template DiagonalIndexReturnType<Index>::Type
00220 MatrixBase<Derived>::diagonal()
00221 {
00222   return derived();
00223 }
00224 
00226 template<typename Derived>
00227 template<int Index>
00228 inline typename MatrixBase<Derived>::template ConstDiagonalIndexReturnType<Index>::Type
00229 MatrixBase<Derived>::diagonal() const
00230 {
00231   return derived();
00232 }
00233 
00234 } // end namespace Eigen
00235 
00236 #endif // EIGEN_DIAGONAL_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:10:30