2009-05-20 15:41:23 +02:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 23:54:52 +02:00
|
|
|
// for linear algebra.
|
2009-05-20 15:41:23 +02:00
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-05-20 15:41:23 +02: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/.
|
2009-05-20 15:41:23 +02:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_CWISE_UNARY_VIEW_H
|
|
|
|
|
#define EIGEN_CWISE_UNARY_VIEW_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2009-05-20 15:41:23 +02:00
|
|
|
/** \class CwiseUnaryView
|
2010-07-06 13:10:08 +01:00
|
|
|
* \ingroup Core_Module
|
2009-05-20 15:41:23 +02:00
|
|
|
*
|
|
|
|
|
* \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector
|
|
|
|
|
*
|
|
|
|
|
* \param ViewOp template functor implementing the view
|
|
|
|
|
* \param MatrixType the type of the matrix we are applying the unary operator
|
|
|
|
|
*
|
|
|
|
|
* This class represents a lvalue expression of a generic unary view operator of a matrix or a vector.
|
|
|
|
|
* It is the return type of real() and imag(), and most of the time this is the only way it is used.
|
|
|
|
|
*
|
|
|
|
|
* \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp
|
|
|
|
|
*/
|
2010-10-25 10:15:22 -04:00
|
|
|
|
|
|
|
|
namespace internal {
|
2009-05-20 15:41:23 +02:00
|
|
|
template<typename ViewOp, typename MatrixType>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct traits<CwiseUnaryView<ViewOp, MatrixType> >
|
|
|
|
|
: traits<MatrixType>
|
2009-05-20 15:41:23 +02:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename result_of<
|
|
|
|
|
ViewOp(typename traits<MatrixType>::Scalar)
|
2009-05-20 15:41:23 +02:00
|
|
|
>::type Scalar;
|
|
|
|
|
typedef typename MatrixType::Nested MatrixTypeNested;
|
2010-10-26 16:47:01 +02:00
|
|
|
typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
|
2009-05-20 15:41:23 +02:00
|
|
|
enum {
|
2014-10-07 18:29:28 +02:00
|
|
|
FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
|
|
|
|
|
Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
|
2010-10-25 10:15:22 -04:00
|
|
|
MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
|
2010-06-11 07:56:50 -04:00
|
|
|
// need to cast the sizeof's from size_t to int explicitly, otherwise:
|
|
|
|
|
// "error: no integral type can represent all of the enumerator values
|
2010-05-08 13:42:41 -04:00
|
|
|
InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
|
2010-06-11 07:56:50 -04:00
|
|
|
? int(Dynamic)
|
2013-02-26 15:08:50 +01:00
|
|
|
: int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
|
|
|
|
|
OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
|
|
|
|
|
? int(Dynamic)
|
|
|
|
|
: outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
|
2009-05-20 15:41:23 +02:00
|
|
|
};
|
|
|
|
|
};
|
2010-10-25 10:15:22 -04:00
|
|
|
}
|
2009-05-20 15:41:23 +02:00
|
|
|
|
2010-04-16 10:13:32 -04:00
|
|
|
template<typename ViewOp, typename MatrixType, typename StorageKind>
|
2009-11-16 19:39:29 +01:00
|
|
|
class CwiseUnaryViewImpl;
|
|
|
|
|
|
2009-05-20 15:41:23 +02:00
|
|
|
template<typename ViewOp, typename MatrixType>
|
2013-06-24 13:45:33 +02:00
|
|
|
class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
|
2009-05-20 15:41:23 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
|
2010-06-03 08:41:11 +02:00
|
|
|
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
|
2014-06-20 15:39:38 +02:00
|
|
|
typedef typename internal::remove_all<MatrixType>::type NestedExpression;
|
2009-05-20 15:41:23 +02:00
|
|
|
|
2014-10-07 18:29:28 +02:00
|
|
|
explicit inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp())
|
2009-05-20 15:41:23 +02:00
|
|
|
: m_matrix(mat), m_functor(func) {}
|
2009-07-10 16:10:03 +02:00
|
|
|
|
2009-05-20 15:41:23 +02:00
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
|
|
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); }
|
|
|
|
|
EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); }
|
2009-05-20 15:41:23 +02:00
|
|
|
|
2010-01-22 10:15:41 +01:00
|
|
|
/** \returns the functor representing unary operation */
|
|
|
|
|
const ViewOp& 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 */
|
2010-10-26 16:47:01 +02:00
|
|
|
const typename internal::remove_all<typename MatrixType::Nested>::type&
|
2009-11-16 19:39:29 +01:00
|
|
|
nestedExpression() const { return m_matrix; }
|
|
|
|
|
|
2010-01-22 10:15:41 +01:00
|
|
|
/** \returns the nested expression */
|
2010-10-26 16:47:01 +02:00
|
|
|
typename internal::remove_all<typename MatrixType::Nested>::type&
|
2009-11-16 19:39:29 +01:00
|
|
|
nestedExpression() { return m_matrix.const_cast_derived(); }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// FIXME changed from MatrixType::Nested because of a weird compilation error with sun CC
|
2012-02-03 23:18:26 +01:00
|
|
|
typename internal::nested<MatrixType>::type m_matrix;
|
2010-05-08 16:00:05 -04:00
|
|
|
ViewOp m_functor;
|
2009-11-16 19:39:29 +01:00
|
|
|
};
|
|
|
|
|
|
2014-06-25 17:21:04 +02:00
|
|
|
// Generic API dispatcher
|
|
|
|
|
template<typename ViewOp, typename XprType, typename StorageKind>
|
|
|
|
|
class CwiseUnaryViewImpl
|
|
|
|
|
: public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef typename internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type Base;
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-16 19:39:29 +01:00
|
|
|
template<typename ViewOp, typename MatrixType>
|
2010-01-22 10:15:41 +01:00
|
|
|
class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
|
2010-10-25 10:15:22 -04:00
|
|
|
: public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
|
2009-11-16 19:39:29 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
|
2010-05-08 16:00:05 -04:00
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
|
2013-06-24 13:45:33 +02:00
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
|
2013-02-07 17:44:24 +01:00
|
|
|
|
2014-10-13 17:18:26 +02:00
|
|
|
EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
|
|
|
|
|
EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
|
2010-05-30 16:00:58 -04:00
|
|
|
|
2014-10-13 17:18:26 +02:00
|
|
|
EIGEN_DEVICE_FUNC inline Index innerStride() const
|
2010-05-08 13:42:41 -04:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
|
2010-05-08 13:42:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-10-13 17:18:26 +02:00
|
|
|
EIGEN_DEVICE_FUNC inline Index outerStride() const
|
2010-05-08 13:42:41 -04:00
|
|
|
{
|
2013-02-26 15:08:50 +01:00
|
|
|
return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
|
2010-05-08 13:42:41 -04:00
|
|
|
}
|
2009-05-20 15:41:23 +02:00
|
|
|
};
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
2009-05-20 15:41:23 +02:00
|
|
|
|
|
|
|
|
#endif // EIGEN_CWISE_UNARY_VIEW_H
|