CwiseUnaryView.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) 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 
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 = 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)
00048                                * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
00049     OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret
00050   };
00051 };
00052 }
00053 
00054 template<typename ViewOp, typename MatrixType, typename StorageKind>
00055 class CwiseUnaryViewImpl;
00056 
00057 template<typename ViewOp, typename MatrixType>
00058 class CwiseUnaryView : internal::no_assignment_operator,
00059   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 
00075     const ViewOp& functor() const { return m_functor; }
00076 
00078     const typename internal::remove_all<typename MatrixType::Nested>::type&
00079     nestedExpression() const { return m_matrix; }
00080 
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 
00102     inline Index innerStride() const
00103     {
00104       return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
00105     }
00106 
00107     inline Index outerStride() const
00108     {
00109       return derived().nestedExpression().outerStride();
00110     }
00111 
00112     EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
00113     {
00114       return derived().functor()(derived().nestedExpression().coeff(row, col));
00115     }
00116 
00117     EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
00118     {
00119       return derived().functor()(derived().nestedExpression().coeff(index));
00120     }
00121 
00122     EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
00123     {
00124       return derived().functor()(const_cast_derived().nestedExpression().coeffRef(row, col));
00125     }
00126 
00127     EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
00128     {
00129       return derived().functor()(const_cast_derived().nestedExpression().coeffRef(index));
00130     }
00131 };
00132 
00133 } // end namespace Eigen
00134 
00135 #endif // EIGEN_CWISE_UNARY_VIEW_H


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