Eigne Matrix Class Library
Dependents: Eigen_test Odometry_test AttitudeEstimation_usingTicker MPU9250_Quaternion_Binary_Serial ... more
CwiseUnaryView.h
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_CWISE_UNARY_VIEW_H 00011 #define EIGEN_CWISE_UNARY_VIEW_H 00012 00013 namespace Eigen { 00014 00015 /** \class CwiseUnaryView 00016 * \ingroup Core_Module 00017 * 00018 * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector 00019 * 00020 * \param ViewOp template functor implementing the view 00021 * \param MatrixType the type of the matrix we are applying the unary operator 00022 * 00023 * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector. 00024 * It is the return type of real() and imag(), and most of the time this is the only way it is used. 00025 * 00026 * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp 00027 */ 00028 00029 namespace internal { 00030 template<typename ViewOp, typename MatrixType> 00031 struct traits<CwiseUnaryView<ViewOp, MatrixType> > 00032 : traits<MatrixType> 00033 { 00034 typedef typename result_of< 00035 ViewOp(typename traits<MatrixType>::Scalar) 00036 >::type Scalar; 00037 typedef typename MatrixType::Nested MatrixTypeNested; 00038 typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested; 00039 enum { 00040 Flags = (traits<_MatrixTypeNested>::Flags & (HereditaryBits | LvalueBit | LinearAccessBit | DirectAccessBit)), 00041 CoeffReadCost = EIGEN_ADD_COST(traits<_MatrixTypeNested>::CoeffReadCost, functor_traits<ViewOp>::Cost), 00042 MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret, 00043 // need to cast the sizeof's from size_t to int explicitly, otherwise: 00044 // "error: no integral type can represent all of the enumerator values 00045 InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic 00046 ? int(Dynamic) 00047 : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)), 00048 OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic 00049 ? int(Dynamic) 00050 : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)) 00051 }; 00052 }; 00053 } 00054 00055 template<typename ViewOp, typename MatrixType, typename StorageKind> 00056 class CwiseUnaryViewImpl; 00057 00058 template<typename ViewOp, typename MatrixType> 00059 class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind> 00060 { 00061 public: 00062 00063 typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base; 00064 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) 00065 00066 inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp()) 00067 : m_matrix(mat), m_functor(func) {} 00068 00069 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView) 00070 00071 EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); } 00072 EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); } 00073 00074 /** \returns the functor representing unary operation */ 00075 const ViewOp& functor() const { return m_functor; } 00076 00077 /** \returns the nested expression */ 00078 const typename internal::remove_all<typename MatrixType::Nested>::type& 00079 nestedExpression() const { return m_matrix; } 00080 00081 /** \returns the nested expression */ 00082 typename internal::remove_all<typename MatrixType::Nested>::type& 00083 nestedExpression() { return m_matrix.const_cast_derived(); } 00084 00085 protected: 00086 // FIXME changed from MatrixType::Nested because of a weird compilation error with sun CC 00087 typename internal::nested<MatrixType>::type m_matrix; 00088 ViewOp m_functor; 00089 }; 00090 00091 template<typename ViewOp, typename MatrixType> 00092 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense> 00093 : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type 00094 { 00095 public: 00096 00097 typedef CwiseUnaryView<ViewOp, MatrixType> Derived; 00098 typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base; 00099 00100 EIGEN_DENSE_PUBLIC_INTERFACE(Derived) 00101 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl) 00102 00103 inline Scalar* data() { return &coeffRef(0); } 00104 inline const Scalar* data() const { return &coeff(0); } 00105 00106 inline Index innerStride() const 00107 { 00108 return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar); 00109 } 00110 00111 inline Index outerStride() const 00112 { 00113 return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar); 00114 } 00115 00116 EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const 00117 { 00118 return derived().functor()(derived().nestedExpression().coeff(row, col)); 00119 } 00120 00121 EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const 00122 { 00123 return derived().functor()(derived().nestedExpression().coeff(index)); 00124 } 00125 00126 EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) 00127 { 00128 return derived().functor()(const_cast_derived().nestedExpression().coeffRef(row, col)); 00129 } 00130 00131 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) 00132 { 00133 return derived().functor()(const_cast_derived().nestedExpression().coeffRef(index)); 00134 } 00135 }; 00136 00137 } // end namespace Eigen 00138 00139 #endif // EIGEN_CWISE_UNARY_VIEW_H
Generated on Tue Jul 12 2022 17:46:51 by 1.7.2