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) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0010 
0011 #ifndef EIGEN_CWISE_UNARY_OP_H
0012 #define EIGEN_CWISE_UNARY_OP_H
0013 
0014 namespace Eigen {
0015 
0016 namespace internal {
0017 template<typename UnaryOp, typename XprType>
0018 struct traits<CwiseUnaryOp<UnaryOp, XprType> >
0019  : traits<XprType>
0020 {
0021   typedef typename result_of<
0022                      UnaryOp(const typename XprType::Scalar&)
0023                    >::type Scalar;
0024   typedef typename XprType::Nested XprTypeNested;
0025   typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
0026   enum {
0027     Flags = _XprTypeNested::Flags & RowMajorBit
0028   };
0029 };
0030 }
0031 
0032 template<typename UnaryOp, typename XprType, typename StorageKind>
0033 class CwiseUnaryOpImpl;
0034 
0035 /** \class CwiseUnaryOp
0036   * \ingroup Core_Module
0037   *
0038   * \brief Generic expression where a coefficient-wise unary operator is applied to an expression
0039   *
0040   * \tparam UnaryOp template functor implementing the operator
0041   * \tparam XprType the type of the expression to which we are applying the unary operator
0042   *
0043   * This class represents an expression where a unary operator is applied to an expression.
0044   * It is the return type of all operations taking exactly 1 input expression, regardless of the
0045   * presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix
0046   * is considered unary, because only the right-hand side is an expression, and its
0047   * return type is a specialization of CwiseUnaryOp.
0048   *
0049   * Most of the time, this is the only way that it is used, so you typically don't have to name
0050   * CwiseUnaryOp types explicitly.
0051   *
0052   * \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp
0053   */
0054 template<typename UnaryOp, typename XprType>
0055 class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator
0056 {
0057   public:
0058 
0059     typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
0060     EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
0061     typedef typename internal::ref_selector<XprType>::type XprTypeNested;
0062     typedef typename internal::remove_all<XprType>::type NestedExpression;
0063 
0064     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0065     explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
0066       : m_xpr(xpr), m_functor(func) {}
0067 
0068     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0069     Index rows() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
0070     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
0071     Index cols() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
0072 
0073     /** \returns the functor representing the unary operation */
0074     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0075     const UnaryOp& functor() const { return m_functor; }
0076 
0077     /** \returns the nested expression */
0078     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0079     const typename internal::remove_all<XprTypeNested>::type&
0080     nestedExpression() const { return m_xpr; }
0081 
0082     /** \returns the nested expression */
0083     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0084     typename internal::remove_all<XprTypeNested>::type&
0085     nestedExpression() { return m_xpr; }
0086 
0087   protected:
0088     XprTypeNested m_xpr;
0089     const UnaryOp m_functor;
0090 };
0091 
0092 // Generic API dispatcher
0093 template<typename UnaryOp, typename XprType, typename StorageKind>
0094 class CwiseUnaryOpImpl
0095   : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
0096 {
0097 public:
0098   typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
0099 };
0100 
0101 } // end namespace Eigen
0102 
0103 #endif // EIGEN_CWISE_UNARY_OP_H