Ref.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2012 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_REF_H
11 #define EIGEN_REF_H
12 
13 namespace Eigen {
14 
15 template<typename Derived> class RefBase;
16 template<typename PlainObjectType, int Options = 0,
18 
88 namespace internal {
89 
90 template<typename _PlainObjectType, int _Options, typename _StrideType>
91 struct traits<Ref<_PlainObjectType, _Options, _StrideType> >
92  : public traits<Map<_PlainObjectType, _Options, _StrideType> >
93 {
94  typedef _PlainObjectType PlainObjectType;
95  typedef _StrideType StrideType;
96  enum {
97  Options = _Options
98  };
99 
100  template<typename Derived> struct match {
101  enum {
103  StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)),
104  InnerStrideMatch = int(StrideType::InnerStrideAtCompileTime)==int(Dynamic)
105  || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime)
106  || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1),
107  OuterStrideMatch = Derived::IsVectorAtCompileTime
108  || int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime),
109  AlignmentMatch = (_Options!=Aligned) || ((PlainObjectType::Flags&AlignedBit)==0) || ((traits<Derived>::Flags&AlignedBit)==AlignedBit),
110  MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch
111  };
113  };
114 
115 };
116 
117 template<typename Derived>
118 struct traits<RefBase<Derived> > : public traits<Derived> {};
119 
120 }
121 
122 template<typename Derived> class RefBase
123  : public MapBase<Derived>
124 {
127 
128 public:
129 
132 
133  inline Index innerStride() const
134  {
135  return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
136  }
137 
138  inline Index outerStride() const
139  {
140  return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
141  : IsVectorAtCompileTime ? this->size()
142  : int(Flags)&RowMajorBit ? this->cols()
143  : this->rows();
144  }
145 
147  : Base(0,RowsAtCompileTime==Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==Dynamic?0:ColsAtCompileTime),
148  // Stride<> does not allow default ctor for Dynamic strides, so let' initialize it with dummy values:
149  m_stride(StrideType::OuterStrideAtCompileTime==Dynamic?0:StrideType::OuterStrideAtCompileTime,
150  StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime)
151  {}
152 
154 
155 protected:
156 
158 
159  template<typename Expression>
160  void construct(Expression& expr)
161  {
162  if(PlainObjectType::RowsAtCompileTime==1)
163  {
164  eigen_assert(expr.rows()==1 || expr.cols()==1);
165  ::new (static_cast<Base*>(this)) Base(expr.data(), 1, expr.size());
166  }
167  else if(PlainObjectType::ColsAtCompileTime==1)
168  {
169  eigen_assert(expr.rows()==1 || expr.cols()==1);
170  ::new (static_cast<Base*>(this)) Base(expr.data(), expr.size(), 1);
171  }
172  else
173  ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols());
174  ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(),
175  StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride());
176  }
177 
178  StrideBase m_stride;
179 };
180 
181 
182 template<typename PlainObjectType, int Options, typename StrideType> class Ref
183  : public RefBase<Ref<PlainObjectType, Options, StrideType> >
184 {
186  public:
187 
190 
191 
192  #ifndef EIGEN_PARSED_BY_DOXYGEN
193  template<typename Derived>
195  typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0)
196  {
197  Base::construct(expr);
198  }
199  template<typename Derived>
200  inline Ref(const DenseBase<Derived>& expr,
201  typename internal::enable_if<bool(internal::is_lvalue<Derived>::value&&bool(Traits::template match<Derived>::MatchAtCompileTime)),Derived>::type* = 0,
202  int = Derived::ThisConstantIsPrivateInPlainObjectBase)
203  #else
204  template<typename Derived>
205  inline Ref(DenseBase<Derived>& expr)
206  #endif
207  {
208  Base::construct(expr.const_cast_derived());
209  }
210 
212 
213 };
214 
215 // this is the const ref version
216 template<typename TPlainObjectType, int Options, typename StrideType> class Ref<const TPlainObjectType, Options, StrideType>
217  : public RefBase<Ref<const TPlainObjectType, Options, StrideType> >
218 {
220  public:
221 
224 
225  template<typename Derived>
226  inline Ref(const DenseBase<Derived>& expr)
227  {
228 // std::cout << match_helper<Derived>::HasDirectAccess << "," << match_helper<Derived>::OuterStrideMatch << "," << match_helper<Derived>::InnerStrideMatch << "\n";
229 // std::cout << int(StrideType::OuterStrideAtCompileTime) << " - " << int(Derived::OuterStrideAtCompileTime) << "\n";
230 // std::cout << int(StrideType::InnerStrideAtCompileTime) << " - " << int(Derived::InnerStrideAtCompileTime) << "\n";
231  construct(expr.derived(), typename Traits::template match<Derived>::type());
232  }
233 
234  protected:
235 
236  template<typename Expression>
238  {
239  Base::construct(expr);
240  }
241 
242  template<typename Expression>
244  {
245  m_object.lazyAssign(expr);
246  Base::construct(m_object);
247  }
248 
249  protected:
250  TPlainObjectType m_object;
251 };
252 
253 } // end namespace Eigen
254 
255 #endif // EIGEN_REF_H
Ref(const DenseBase< Derived > &expr, typename internal::enable_if< bool(internal::is_lvalue< Derived >::value &&bool(Traits::template match< Derived >::MatchAtCompileTime)), Derived >::type *=0, int=Derived::ThisConstantIsPrivateInPlainObjectBase)
Definition: Ref.h:200
Stride< StrideType::OuterStrideAtCompileTime, StrideType::InnerStrideAtCompileTime > StrideBase
Definition: Ref.h:157
Base class for Map and Block expression with direct access.
Ref(PlainObjectBase< Derived > &expr, typename internal::enable_if< bool(Traits::template match< Derived >::MatchAtCompileTime), Derived >::type *=0)
Definition: Ref.h:194
#define inline
Definition: Types.h:109
MapBase< Derived > Base
Definition: Ref.h:130
internal::traits< Ref > Traits
Definition: Ref.h:185
internal::traits< Derived >::PlainObjectType PlainObjectType
Definition: Ref.h:125
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
const unsigned int RowMajorBit
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
const unsigned int AlignedBit
void construct(const Expression &expr, internal::false_type)
Definition: Ref.h:243
Base class for all variables within the symbolic expressions family.
Definition: expression.hpp:56
internal::conditional< MatchAtCompileTime, internal::true_type, internal::false_type >::type type
Definition: Ref.h:112
void construct(Expression &expr)
Definition: Ref.h:160
Dense storage base class for matrices and arrays.
Provides a generic way to set and pass user-specified options.
Definition: options.hpp:65
StrideBase m_stride
Definition: Ref.h:178
A matrix or vector expression mapping an existing expressions.
Definition: Ref.h:17
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Index outerStride() const
Definition: Ref.h:138
RefBase< Ref > Base
Definition: Ref.h:188
#define eigen_assert(x)
Convenience specialization of Stride to specify only an outer stride See class Map for some examples...
Definition: Stride.h:97
internal::traits< Ref< PlainObjectType, Options, StrideType > >::StrideType StrideType
Definition: Ref.h:126
void construct(const Expression &expr, internal::true_type)
Definition: Ref.h:237


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:03