Path Tracer
CwiseUnaryView.h
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 
13 namespace Eigen {
14 
15 namespace internal {
16 template<typename ViewOp, typename MatrixType>
17 struct traits<CwiseUnaryView<ViewOp, MatrixType> >
18  : traits<MatrixType>
19 {
20  typedef typename result_of<
21  ViewOp(const typename traits<MatrixType>::Scalar&)
22  >::type Scalar;
23  typedef typename MatrixType::Nested MatrixTypeNested;
24  typedef typename remove_all<MatrixTypeNested>::type _MatrixTypeNested;
25  enum {
26  FlagsLvalueBit = is_lvalue<MatrixType>::value ? LvalueBit : 0,
27  Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions
28  MatrixTypeInnerStride = inner_stride_at_compile_time<MatrixType>::ret,
29  // need to cast the sizeof's from size_t to int explicitly, otherwise:
30  // "error: no integral type can represent all of the enumerator values
31  InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic
32  ? int(Dynamic)
33  : int(MatrixTypeInnerStride) * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar)),
34  OuterStrideAtCompileTime = outer_stride_at_compile_time<MatrixType>::ret == Dynamic
35  ? int(Dynamic)
36  : outer_stride_at_compile_time<MatrixType>::ret * int(sizeof(typename traits<MatrixType>::Scalar) / sizeof(Scalar))
37  };
38 };
39 }
40 
41 template<typename ViewOp, typename MatrixType, typename StorageKind>
42 class CwiseUnaryViewImpl;
43 
57 template<typename ViewOp, typename MatrixType>
58 class CwiseUnaryView : public CwiseUnaryViewImpl<ViewOp, MatrixType, typename internal::traits<MatrixType>::StorageKind>
59 {
60  public:
61 
63  EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView)
65  typedef typename internal::remove_all<MatrixType>::type NestedExpression;
66 
67  explicit inline CwiseUnaryView(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 
76  const ViewOp& functor() const { return m_functor; }
77 
79  const typename internal::remove_all<MatrixTypeNested>::type&
80  nestedExpression() const { return m_matrix; }
81 
83  typename internal::remove_reference<MatrixTypeNested>::type&
84  nestedExpression() { return m_matrix; }
85 
86  protected:
87  MatrixTypeNested m_matrix;
88  ViewOp m_functor;
89 };
90 
91 // Generic API dispatcher
92 template<typename ViewOp, typename XprType, typename StorageKind>
94  : public internal::generic_xpr_base<CwiseUnaryView<ViewOp, XprType> >::type
95 {
96 public:
98 };
99 
100 template<typename ViewOp, typename MatrixType>
101 class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
102  : public internal::dense_xpr_base< CwiseUnaryView<ViewOp, MatrixType> >::type
103 {
104  public:
105 
108 
109  EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
110  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl)
111 
112  EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); }
113  EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); }
114 
115  EIGEN_DEVICE_FUNC inline Index innerStride() const
116  {
117  return derived().nestedExpression().innerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
118  }
119 
120  EIGEN_DEVICE_FUNC inline Index outerStride() const
121  {
122  return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
123  }
124  protected:
125  EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
126 };
127 
128 } // end namespace Eigen
129 
130 #endif // EIGEN_CWISE_UNARY_VIEW_H
Eigen
Namespace containing all symbols from the Eigen library.
Definition: LDLT.h:16
Eigen::CwiseUnaryView::functor
const ViewOp & functor() const
Definition: CwiseUnaryView.h:76
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:492
Eigen::internal::is_lvalue
Definition: XprHelper.h:668
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:65
Eigen::CwiseUnaryViewImpl
Definition: CwiseUnaryView.h:95
Eigen::CwiseUnaryView
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition: CwiseUnaryView.h:59
Eigen::DirectAccessBit
const unsigned int DirectAccessBit
Definition: Constants.h:154
Eigen::internal::true_type
Definition: Meta.h:63
Eigen::CwiseUnaryView::nestedExpression
internal::remove_reference< MatrixTypeNested >::type & nestedExpression()
Definition: CwiseUnaryView.h:84
Eigen::LvalueBit
const unsigned int LvalueBit
Definition: Constants.h:143
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:21
Eigen::internal::generic_xpr_base
Definition: XprHelper.h:509
Eigen::internal::outer_stride_at_compile_time
Definition: DenseCoeffsBase.h:671
Eigen::internal::inner_stride_at_compile_time
Definition: DenseCoeffsBase.h:659
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::internal::result_of
Definition: Meta.h:458
Eigen::CwiseUnaryView::nestedExpression
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: CwiseUnaryView.h:80
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:42
Eigen::Dense
Definition: Constants.h:503