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 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_CWISE_UNARY_VIEW_H
00026 #define EIGEN_CWISE_UNARY_VIEW_H
00027 
00042 namespace internal {
00043 template<typename ViewOp, typename MatrixType>
00044 struct traits<CwiseUnaryView<ViewOp, MatrixType> >
00045  : traits<MatrixType>
00046 {
00047   typedef typename result_of<
00048                      ViewOp(typename traits<MatrixType>::Scalar)
00049                    >::type Scalar;
00050   typedef typename MatrixType::Nested MatrixTypeNested;
00051   typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
00052   enum {
00053     Flags = (traits<_MatrixTypeNested>::Flags & (HereditaryBits | LvalueBit | LinearAccessBit | DirectAccessBit)),
00054     CoeffReadCost = traits<_MatrixTypeNested>::CoeffReadCost + functor_traits<ViewOp>::Cost,
00055     MatrixTypeInnerStride =  inner_stride_at_compile_time<MatrixType>::ret,
00056     // need to cast the sizeof's from size_t to int explicitly, otherwise:
00057     // "error: no integral type can represent all of the enumerator values
00058     InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
00059                              ? int(Dynamic)
00060                              : int(MatrixTypeInnerStride)
00061                                * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
00062     OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret
00063   };
00064 };
00065 }
00066 
00067 template<typename ViewOp, typename MatrixType, typename StorageKind>
00068 class CwiseUnaryViewImpl;
00069 
00070 template<typename ViewOp, typename MatrixType>
00071 class CwiseUnaryView : internal::no_assignment_operator,
00072   public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
00073 {
00074   public:
00075 
00076     typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
00077     EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
00078 
00079     inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp())
00080       : m_matrix(mat), m_functor(func) {}
00081 
00082     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
00083 
00084     EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); }
00085     EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); }
00086 
00088     const ViewOp& functor() const { return m_functor; }
00089 
00091     const typename internal::remove_all<typename MatrixType::Nested>::type&
00092     nestedExpression() const { return m_matrix; }
00093 
00095     typename internal::remove_all<typename MatrixType::Nested>::type&
00096     nestedExpression() { return m_matrix.const_cast_derived(); }
00097 
00098   protected:
00099     // FIXME changed from MatrixType::Nested because of a weird compilation error with sun CC
00100     const typename internal::nested<MatrixType>::type m_matrix;
00101     ViewOp m_functor;
00102 };
00103 
00104 template<typename ViewOp, typename MatrixType>
00105 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
00106   : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
00107 {
00108   public:
00109 
00110     typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
00111     typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
00112 
00113     EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
00114 
00115     inline Index innerStride() const
00116     {
00117       return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
00118     }
00119 
00120     inline Index outerStride() const
00121     {
00122       return derived().nestedExpression().outerStride();
00123     }
00124 
00125     EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
00126     {
00127       return derived().functor()(derived().nestedExpression().coeff(row, col));
00128     }
00129 
00130     EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
00131     {
00132       return derived().functor()(derived().nestedExpression().coeff(index));
00133     }
00134 
00135     EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
00136     {
00137       return derived().functor()(const_cast_derived().nestedExpression().coeffRef(row, col));
00138     }
00139 
00140     EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
00141     {
00142       return derived().functor()(const_cast_derived().nestedExpression().coeffRef(index));
00143     }
00144 };
00145 
00146 
00147 
00148 #endif // EIGEN_CWISE_UNARY_VIEW_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:00