Eigen  3.3.3
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 namespace internal {
00016 template<typename ViewOp, typename MatrixType>
00017 struct traits<CwiseUnaryView<ViewOp, MatrixType> >
00018  : traits<MatrixType>
00019 {
00020   typedef typename result_of<
00021                      ViewOp(const typename traits<MatrixType>::Scalar&)
00022                    >::type Scalar;
00023   typedef typename MatrixType::Nested MatrixTypeNested;
00024   typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00025   enum {
00026     FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
00027     Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
00028     MatrixTypeInnerStride =  inner_stride_at_compile_time<MatrixType>::ret,
00029     // need to cast the sizeof's from size_t to int explicitly, otherwise:
00030     // "error: no integral type can represent all of the enumerator values
00031     InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
00032                              ? int(Dynamic)
00033                              : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
00034     OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
00035                              ? int(Dynamic)
00036                              : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
00037   };
00038 };
00039 }
00040 
00041 template<typename ViewOp, typename MatrixType, typename StorageKind>
00042 class CwiseUnaryViewImpl;
00043 
00057 template<typename ViewOp, typename MatrixType>
00058 class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
00059 {
00060   public:
00061 
00062     typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
00063     EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
00064     typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
00065     typedef typename internal::remove_all<MatrixType>::type NestedExpression;
00066 
00067     explicit inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
00068       : m_matrix(mat), m_functor(func) {}
00069 
00070     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
00071 
00072     EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); }
00073     EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); }
00074 
00076     const ViewOp& functor() const { return m_functor; }
00077 
00079     const typename internal::remove_all<MatrixTypeNested>::type&
00080     nestedExpression() const { return m_matrix; }
00081 
00083     typename internal::remove_reference<MatrixTypeNested>::type&
00084     nestedExpression() { return m_matrix.const_cast_derived(); }
00085 
00086   protected:
00087     MatrixTypeNested m_matrix;
00088     ViewOp m_functor;
00089 };
00090 
00091 // Generic API dispatcher
00092 template<typename ViewOp, typename XprType, typename StorageKind>
00093 class CwiseUnaryViewImpl
00094   : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
00095 {
00096 public:
00097   typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
00098 };
00099 
00100 template<typename ViewOp, typename MatrixType>
00101 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
00102   : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
00103 {
00104   public:
00105 
00106     typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
00107     typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
00108 
00109     EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
00110     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
00111     
00112     EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
00113     EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
00114 
00115     EIGEN_DEVICE_FUNC inline Index innerStride() const
00116     {
00117       return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
00118     }
00119 
00120     EIGEN_DEVICE_FUNC inline Index outerStride() const
00121     {
00122       return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
00123     }
00124 };
00125 
00126 } // end namespace Eigen
00127 
00128 #endif // EIGEN_CWISE_UNARY_VIEW_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends