compbio
ArrayWrapper.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_ARRAYWRAPPER_H
11 #define EIGEN_ARRAYWRAPPER_H
12 
13 namespace Eigen {
14 
26 namespace internal {
27 template<typename ExpressionType>
28 struct traits<ArrayWrapper<ExpressionType> >
29  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
30 {
31  typedef ArrayXpr XprKind;
32  // Let's remove NestByRefBit
33  enum {
35  Flags = Flags0 & ~NestByRefBit
36  };
37 };
38 }
39 
40 template<typename ExpressionType>
41 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
42 {
43  public:
45  EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
46  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
47  typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
48 
49  typedef typename internal::conditional<
51  Scalar,
52  const Scalar
53  >::type ScalarWithConstIfNotLvalue;
54 
55  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
56 
57  using Base::coeffRef;
58 
59  EIGEN_DEVICE_FUNC
60  explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
61 
62  EIGEN_DEVICE_FUNC
63  inline Index rows() const { return m_expression.rows(); }
64  EIGEN_DEVICE_FUNC
65  inline Index cols() const { return m_expression.cols(); }
66  EIGEN_DEVICE_FUNC
67  inline Index outerStride() const { return m_expression.outerStride(); }
68  EIGEN_DEVICE_FUNC
69  inline Index innerStride() const { return m_expression.innerStride(); }
70 
71  EIGEN_DEVICE_FUNC
72  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
73  EIGEN_DEVICE_FUNC
74  inline const Scalar* data() const { return m_expression.data(); }
75 
76  EIGEN_DEVICE_FUNC
77  inline const Scalar& coeffRef(Index rowId, Index colId) const
78  {
79  return m_expression.coeffRef(rowId, colId);
80  }
81 
82  EIGEN_DEVICE_FUNC
83  inline const Scalar& coeffRef(Index index) const
84  {
85  return m_expression.coeffRef(index);
86  }
87 
88  template<typename Dest>
89  EIGEN_DEVICE_FUNC
90  inline void evalTo(Dest& dst) const { dst = m_expression; }
91 
92  const typename internal::remove_all<NestedExpressionType>::type&
93  EIGEN_DEVICE_FUNC
94  nestedExpression() const
95  {
96  return m_expression;
97  }
98 
101  EIGEN_DEVICE_FUNC
102  void resize(Index newSize) { m_expression.resize(newSize); }
105  EIGEN_DEVICE_FUNC
106  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
107 
108  protected:
109  NestedExpressionType m_expression;
110 };
111 
123 namespace internal {
124 template<typename ExpressionType>
125 struct traits<MatrixWrapper<ExpressionType> >
126  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
127 {
128  typedef MatrixXpr XprKind;
129  // Let's remove NestByRefBit
130  enum {
132  Flags = Flags0 & ~NestByRefBit
133  };
134 };
135 }
136 
137 template<typename ExpressionType>
138 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
139 {
140  public:
142  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
143  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
144  typedef typename internal::remove_all<ExpressionType>::type NestedExpression;
145 
146  typedef typename internal::conditional<
148  Scalar,
149  const Scalar
150  >::type ScalarWithConstIfNotLvalue;
151 
152  typedef typename internal::ref_selector<ExpressionType>::non_const_type NestedExpressionType;
153 
154  using Base::coeffRef;
155 
156  EIGEN_DEVICE_FUNC
157  explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {}
158 
159  EIGEN_DEVICE_FUNC
160  inline Index rows() const { return m_expression.rows(); }
161  EIGEN_DEVICE_FUNC
162  inline Index cols() const { return m_expression.cols(); }
163  EIGEN_DEVICE_FUNC
164  inline Index outerStride() const { return m_expression.outerStride(); }
165  EIGEN_DEVICE_FUNC
166  inline Index innerStride() const { return m_expression.innerStride(); }
167 
168  EIGEN_DEVICE_FUNC
169  inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
170  EIGEN_DEVICE_FUNC
171  inline const Scalar* data() const { return m_expression.data(); }
172 
173  EIGEN_DEVICE_FUNC
174  inline const Scalar& coeffRef(Index rowId, Index colId) const
175  {
176  return m_expression.derived().coeffRef(rowId, colId);
177  }
178 
179  EIGEN_DEVICE_FUNC
180  inline const Scalar& coeffRef(Index index) const
181  {
182  return m_expression.coeffRef(index);
183  }
184 
185  EIGEN_DEVICE_FUNC
187  nestedExpression() const
188  {
189  return m_expression;
190  }
191 
194  EIGEN_DEVICE_FUNC
195  void resize(Index newSize) { m_expression.resize(newSize); }
198  EIGEN_DEVICE_FUNC
199  void resize(Index rows, Index cols) { m_expression.resize(rows,cols); }
200 
201  protected:
202  NestedExpressionType m_expression;
203 };
204 
205 } // end namespace Eigen
206 
207 #endif // EIGEN_ARRAYWRAPPER_H
EIGEN_DEVICE_FUNC void resize(Index rows, Index cols)
Forwards the resizing request to the nested expression.
Definition: ArrayWrapper.h:106
internal::traits< Derived >::Scalar Scalar
The numeric type of the expression&#39; coefficients, e.g.
Definition: DenseBase.h:66
Expression of a mathematical vector or matrix as an array object.
Definition: ArrayWrapper.h:41
EIGEN_DEVICE_FUNC void resize(Index newSize)
Forwards the resizing request to the nested expression.
Definition: ArrayWrapper.h:102
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Definition: Meta.h:58
The type used to identify a matrix expression.
Definition: Constants.h:506
Expression of an array as a mathematical vector or matrix.
Definition: ArrayBase.h:15
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
EIGEN_DEVICE_FUNC void resize(Index newSize)
Forwards the resizing request to the nested expression.
Definition: ArrayWrapper.h:195
Definition: BandTriangularSolver.h:13
EIGEN_DEVICE_FUNC void resize(Index rows, Index cols)
Forwards the resizing request to the nested expression.
Definition: ArrayWrapper.h:199
The type used to identify an array expression.
Definition: Constants.h:509
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
Definition: XprHelper.h:630