Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Eigen/Eigen/src/Core/CwiseUnaryView.h @ 10617

Last change on this file since 10617 was 9562, checked in by gkronber, 12 years ago

#1967 worked on Gaussian process evolution.

File size: 5.2 KB
Line 
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_CWISE_UNARY_VIEW_H
11#define EIGEN_CWISE_UNARY_VIEW_H
12
13namespace Eigen {
14
15/** \class CwiseUnaryView
16  * \ingroup Core_Module
17  *
18  * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector
19  *
20  * \param ViewOp template functor implementing the view
21  * \param MatrixType the type of the matrix we are applying the unary operator
22  *
23  * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector.
24  * It is the return type of real() and imag(), and most of the time this is the only way it is used.
25  *
26  * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp
27  */
28
29namespace internal {
30template<typename ViewOp, typename MatrixType>
31struct traits<CwiseUnaryView<ViewOp, MatrixType> >
32 : traits<MatrixType>
33{
34  typedef typename result_of<
35                     ViewOp(typename traits<MatrixType>::Scalar)
36                   >::type Scalar;
37  typedef typename MatrixType::Nested MatrixTypeNested;
38  typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
39  enum {
40    Flags = (traits<_MatrixTypeNested>::Flags & (HereditaryBits | LvalueBit | LinearAccessBit | DirectAccessBit)),
41    CoeffReadCost = traits<_MatrixTypeNested>::CoeffReadCost + functor_traits<ViewOp>::Cost,
42    MatrixTypeInnerStride =  inner_stride_at_compile_time<MatrixType>::ret,
43    // need to cast the sizeof's from size_t to int explicitly, otherwise:
44    // "error: no integral type can represent all of the enumerator values
45    InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
46                             ? int(Dynamic)
47                             : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
48    OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
49                             ? int(Dynamic)
50                             : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
51  };
52};
53}
54
55template<typename ViewOp, typename MatrixType, typename StorageKind>
56class CwiseUnaryViewImpl;
57
58template<typename ViewOp, typename MatrixType>
59class CwiseUnaryView : internal::no_assignment_operator,
60  public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
61{
62  public:
63
64    typedef typename CwiseUnaryViewImpl<ViewOp, MatrixType,typename internal::traits<MatrixType>::StorageKind>::Base Base;
65    EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
66
67    inline CwiseUnaryView(const MatrixType& mat, const ViewOp& func = ViewOp())
68      : m_matrix(mat), m_functor(func) {}
69
70    EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView)
71
72    EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); }
73    EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); }
74
75    /** \returns the functor representing unary operation */
76    const ViewOp& functor() const { return m_functor; }
77
78    /** \returns the nested expression */
79    const typename internal::remove_all<typename MatrixType::Nested>::type&
80    nestedExpression() const { return m_matrix; }
81
82    /** \returns the nested expression */
83    typename internal::remove_all<typename MatrixType::Nested>::type&
84    nestedExpression() { return m_matrix.const_cast_derived(); }
85
86  protected:
87    // FIXME changed from MatrixType::Nested because of a weird compilation error with sun CC
88    typename internal::nested<MatrixType>::type m_matrix;
89    ViewOp m_functor;
90};
91
92template<typename ViewOp, typename MatrixType>
93class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
94  : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
95{
96  public:
97
98    typedef CwiseUnaryView<ViewOp, MatrixType> Derived;
99    typedef typename internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type Base;
100
101    EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
102
103    inline Index innerStride() const
104    {
105      return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
106    }
107
108    inline Index outerStride() const
109    {
110      return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
111    }
112
113    EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
114    {
115      return derived().functor()(derived().nestedExpression().coeff(row, col));
116    }
117
118    EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
119    {
120      return derived().functor()(derived().nestedExpression().coeff(index));
121    }
122
123    EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
124    {
125      return derived().functor()(const_cast_derived().nestedExpression().coeffRef(row, col));
126    }
127
128    EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
129    {
130      return derived().functor()(const_cast_derived().nestedExpression().coeffRef(index));
131    }
132};
133
134} // end namespace Eigen
135
136#endif // EIGEN_CWISE_UNARY_VIEW_H
Note: See TracBrowser for help on using the repository browser.