2008-03-03 10:52:44 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-03-03 10:52:44 +00:00
|
|
|
//
|
2014-06-23 10:40:03 +02:00
|
|
|
// Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-11-24 13:40:43 +00:00
|
|
|
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2008-03-03 10:52:44 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-03-03 10:52:44 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_CWISE_UNARY_OP_H
|
|
|
|
|
#define EIGEN_CWISE_UNARY_OP_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
2010-04-18 22:14:55 -04:00
|
|
|
template<typename UnaryOp, typename XprType>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct traits<CwiseUnaryOp<UnaryOp, XprType> >
|
|
|
|
|
: traits<XprType>
|
2008-03-12 17:17:36 +00:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename result_of<
|
2016-01-28 12:12:06 +01:00
|
|
|
UnaryOp(const typename XprType::Scalar&)
|
2008-03-12 17:17:36 +00:00
|
|
|
>::type Scalar;
|
2010-04-18 22:14:55 -04:00
|
|
|
typedef typename XprType::Nested XprTypeNested;
|
2010-10-25 22:13:49 +02:00
|
|
|
typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
|
2008-03-12 17:17:36 +00:00
|
|
|
enum {
|
2014-03-12 13:34:11 +01:00
|
|
|
Flags = _XprTypeNested::Flags & RowMajorBit
|
2008-03-12 17:17:36 +00:00
|
|
|
};
|
|
|
|
|
};
|
2010-10-25 10:15:22 -04:00
|
|
|
}
|
2008-03-10 17:23:11 +00:00
|
|
|
|
2010-04-18 22:14:55 -04:00
|
|
|
template<typename UnaryOp, typename XprType, typename StorageKind>
|
2009-11-16 19:39:29 +01:00
|
|
|
class CwiseUnaryOpImpl;
|
|
|
|
|
|
2016-01-01 21:45:06 +01:00
|
|
|
/** \class CwiseUnaryOp
|
|
|
|
|
* \ingroup Core_Module
|
|
|
|
|
*
|
|
|
|
|
* \brief Generic expression where a coefficient-wise unary operator is applied to an expression
|
|
|
|
|
*
|
|
|
|
|
* \tparam UnaryOp template functor implementing the operator
|
|
|
|
|
* \tparam XprType the type of the expression to which we are applying the unary operator
|
|
|
|
|
*
|
|
|
|
|
* This class represents an expression where a unary operator is applied to an expression.
|
|
|
|
|
* It is the return type of all operations taking exactly 1 input expression, regardless of the
|
|
|
|
|
* presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix
|
|
|
|
|
* is considered unary, because only the right-hand side is an expression, and its
|
|
|
|
|
* return type is a specialization of CwiseUnaryOp.
|
|
|
|
|
*
|
|
|
|
|
* Most of the time, this is the only way that it is used, so you typically don't have to name
|
|
|
|
|
* CwiseUnaryOp types explicitly.
|
|
|
|
|
*
|
|
|
|
|
* \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp
|
|
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
template<typename UnaryOp, typename XprType>
|
2014-12-02 14:40:19 +01:00
|
|
|
class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator
|
2008-03-03 10:52:44 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
|
2010-06-03 08:41:11 +02:00
|
|
|
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
|
2016-01-28 21:43:20 +01:00
|
|
|
typedef typename internal::ref_selector<XprType>::type XprTypeNested;
|
2014-06-20 15:39:38 +02:00
|
|
|
typedef typename internal::remove_all<XprType>::type NestedExpression;
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
2016-01-31 10:48:49 -08:00
|
|
|
explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
|
2010-04-18 22:14:55 -04:00
|
|
|
: m_xpr(xpr), m_functor(func) {}
|
2008-03-03 10:52:44 +00:00
|
|
|
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
|
|
|
|
Index rows() const { return m_xpr.rows(); }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
|
|
|
|
Index cols() const { return m_xpr.cols(); }
|
2008-03-03 10:52:44 +00:00
|
|
|
|
2010-01-22 10:15:41 +01:00
|
|
|
/** \returns the functor representing the unary operation */
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
2010-01-22 10:15:41 +01:00
|
|
|
const UnaryOp& functor() const { return m_functor; }
|
2009-11-16 19:39:29 +01:00
|
|
|
|
2010-01-22 10:15:41 +01:00
|
|
|
/** \returns the nested expression */
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
2016-01-28 21:43:20 +01:00
|
|
|
const typename internal::remove_all<XprTypeNested>::type&
|
2010-04-18 22:14:55 -04:00
|
|
|
nestedExpression() const { return m_xpr; }
|
2009-11-16 19:39:29 +01:00
|
|
|
|
2010-01-22 10:15:41 +01:00
|
|
|
/** \returns the nested expression */
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
2016-01-28 21:43:20 +01:00
|
|
|
typename internal::remove_all<XprTypeNested>::type&
|
|
|
|
|
nestedExpression() { return m_xpr; }
|
2009-11-16 19:39:29 +01:00
|
|
|
|
|
|
|
|
protected:
|
2016-01-28 21:43:20 +01:00
|
|
|
XprTypeNested m_xpr;
|
2009-11-16 19:39:29 +01:00
|
|
|
const UnaryOp m_functor;
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-20 15:39:38 +02:00
|
|
|
// Generic API dispatcher
|
|
|
|
|
template<typename UnaryOp, typename XprType, typename StorageKind>
|
|
|
|
|
class CwiseUnaryOpImpl
|
|
|
|
|
: public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
|
|
|
|
|
};
|
2008-03-03 10:52:44 +00:00
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2008-03-03 10:52:44 +00:00
|
|
|
#endif // EIGEN_CWISE_UNARY_OP_H
|