Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:56:12

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_CWISE_UNARY_VIEW_H
0011 #define EIGEN_CWISE_UNARY_VIEW_H
0012 
0013 namespace Eigen {
0014 
0015 namespace internal {
0016 template<typename ViewOp, typename MatrixType>
0017 struct traits<CwiseUnaryView<ViewOp, MatrixType> >
0018  : traits<MatrixType>
0019 {
0020   typedef typename result_of<
0021                      ViewOp(const typename traits<MatrixType>::Scalar&)
0022                    >::type Scalar;
0023   typedef typename MatrixType::Nested MatrixTypeNested;
0024   typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
0025   enum {
0026     FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
0027     Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
0028     MatrixTypeInnerStride =  inner_stride_at_compile_time<MatrixType>::ret,
0029     // need to cast the sizeof's from size_t to int explicitly, otherwise:
0030     // "error: no integral type can represent all of the enumerator values
0031     InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
0032                              ? int(Dynamic)
0033                              : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
0034     OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
0035                              ? int(Dynamic)
0036                              : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
0037   };
0038 };
0039 }
0040 
0041 template<typename ViewOp, typename MatrixType, typename StorageKind>
0042 class CwiseUnaryViewImpl;
0043 
0044 /** \class CwiseUnaryView
0045   * \ingroup Core_Module
0046   *
0047   * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector
0048   *
0049   * \tparam ViewOp template functor implementing the view
0050   * \tparam MatrixType the type of the matrix we are applying the unary operator
0051   *
0052   * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector.
0053   * It is the return type of real() and imag(), and most of the time this is the only way it is used.
0054   *
0055   * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp
0056   */
0057 template<typename ViewOp, typename MatrixType>
0058 class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
0059 {
0060   public:
0061 
0062     typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
0063     EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
0064     typedef typename internal::ref_selector<MatrixType>::non_const_type MatrixTypeNested;
0065     typedef typename internal::remove_all<MatrixType>::type NestedExpression;
0066 
0067     explicit EIGEN_DEVICE_FUNC inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
0068       : m_matrix(mat), m_functor(func) {}
0069 
0070     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
0071 
0072     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0073     Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); }
0074     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0075     Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); }
0076 
0077     /** \returns the functor representing unary operation */
0078     EIGEN_DEVICE_FUNC const ViewOp& functor() const { return m_functor; }
0079 
0080     /** \returns the nested expression */
0081     EIGEN_DEVICE_FUNC const typename internal::remove_all<MatrixTypeNested>::type&
0082     nestedExpression() const { return m_matrix; }
0083 
0084     /** \returns the nested expression */
0085     EIGEN_DEVICE_FUNC typename internal::remove_reference<MatrixTypeNested>::type&
0086     nestedExpression() { return m_matrix; }
0087 
0088   protected:
0089     MatrixTypeNested m_matrix;
0090     ViewOp m_functor;
0091 };
0092 
0093 // Generic API dispatcher
0094 template<typename ViewOp, typename XprType, typename StorageKind>
0095 class CwiseUnaryViewImpl
0096   : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
0097 {
0098 public:
0099   typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
0100 };
0101 
0102 template<typename ViewOp, typename MatrixType>
0103 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
0104   : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
0105 {
0106   public:
0107 
0108     typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
0109     typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
0110 
0111     EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
0112     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
0113 
0114     EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
0115     EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
0116 
0117     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const
0118     {
0119       return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
0120     }
0121 
0122     EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const
0123     {
0124       return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
0125     }
0126   protected:
0127     EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
0128 };
0129 
0130 } // end namespace Eigen
0131 
0132 #endif // EIGEN_CWISE_UNARY_VIEW_H