PlainObjectBase.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) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_DENSESTORAGEBASE_H
12 #define EIGEN_DENSESTORAGEBASE_H
13 
14 #if defined(EIGEN_INITIALIZE_MATRICES_BY_ZERO)
15 # define EIGEN_INITIALIZE_COEFFS
16 # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=Scalar(0);
17 #elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN)
18 # define EIGEN_INITIALIZE_COEFFS
19 # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=std::numeric_limits<Scalar>::quiet_NaN();
20 #else
21 # undef EIGEN_INITIALIZE_COEFFS
22 # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
23 #endif
24 
25 namespace Eigen {
26 
27 namespace internal {
28 
29 template<int MaxSizeAtCompileTime> struct check_rows_cols_for_overflow {
30  template<typename Index>
31  static EIGEN_ALWAYS_INLINE void run(Index, Index)
32  {
33  }
34 };
35 
37  template<typename Index>
38  static EIGEN_ALWAYS_INLINE void run(Index rows, Index cols)
39  {
40  // http://hg.mozilla.org/mozilla-central/file/6c8a909977d3/xpcom/ds/CheckedInt.h#l242
41  // we assume Index is signed
42  Index max_index = (size_t(1) << (8 * sizeof(Index) - 1)) - 1; // assume Index is signed
43  bool error = (rows == 0 || cols == 0) ? false
44  : (rows > max_index / cols);
45  if (error)
47  }
48 };
49 
50 template <typename Derived, typename OtherDerived = Derived, bool IsVector = bool(Derived::IsVectorAtCompileTime)> struct conservative_resize_like_impl;
51 
52 template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> struct matrix_swap_impl;
53 
54 } // end namespace internal
55 
64 #ifdef EIGEN_PARSED_BY_DOXYGEN
65 namespace internal {
66 
67 // this is a warkaround to doxygen not being able to understand the inheritence logic
68 // when it is hidden by the dense_xpr_base helper struct.
69 template<typename Derived> struct dense_xpr_base_dispatcher_for_doxygen;// : public MatrixBase<Derived> {};
71 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
72 struct dense_xpr_base_dispatcher_for_doxygen<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
73  : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
75 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
76 struct dense_xpr_base_dispatcher_for_doxygen<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
77  : public ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {};
78 
79 } // namespace internal
80 
81 template<typename Derived>
82 class PlainObjectBase : public internal::dense_xpr_base_dispatcher_for_doxygen<Derived>
83 #else
84 template<typename Derived>
85 class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
86 #endif
87 {
88  public:
91 
97  typedef Derived DenseType;
98 
99  using Base::RowsAtCompileTime;
100  using Base::ColsAtCompileTime;
101  using Base::SizeAtCompileTime;
102  using Base::MaxRowsAtCompileTime;
103  using Base::MaxColsAtCompileTime;
104  using Base::MaxSizeAtCompileTime;
105  using Base::IsVectorAtCompileTime;
106  using Base::Flags;
107 
108  template<typename PlainObjectType, int MapOptions, typename StrideType> friend class Eigen::Map;
109  friend class Eigen::Map<Derived, Unaligned>;
111  friend class Eigen::Map<const Derived, Unaligned>;
113  friend class Eigen::Map<Derived, Aligned>;
115  friend class Eigen::Map<const Derived, Aligned>;
117  template<typename StrideType> struct StridedMapType { typedef Eigen::Map<Derived, Unaligned, StrideType> type; };
118  template<typename StrideType> struct StridedConstMapType { typedef Eigen::Map<const Derived, Unaligned, StrideType> type; };
119  template<typename StrideType> struct StridedAlignedMapType { typedef Eigen::Map<Derived, Aligned, StrideType> type; };
120  template<typename StrideType> struct StridedConstAlignedMapType { typedef Eigen::Map<const Derived, Aligned, StrideType> type; };
121 
122  protected:
124 
125  public:
126  enum { NeedsToAlign = SizeAtCompileTime != Dynamic && (internal::traits<Derived>::Flags & AlignedBit) != 0 };
128 
129  Base& base() { return *static_cast<Base*>(this); }
130  const Base& base() const { return *static_cast<const Base*>(this); }
131 
132  EIGEN_STRONG_INLINE Index rows() const { return m_storage.rows(); }
133  EIGEN_STRONG_INLINE Index cols() const { return m_storage.cols(); }
134 
135  EIGEN_STRONG_INLINE const Scalar& coeff(Index rowId, Index colId) const
136  {
137  if(Flags & RowMajorBit)
138  return m_storage.data()[colId + rowId * m_storage.cols()];
139  else // column-major
140  return m_storage.data()[rowId + colId * m_storage.rows()];
141  }
142 
143  EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const
144  {
145  return m_storage.data()[index];
146  }
147 
149  {
150  if(Flags & RowMajorBit)
151  return m_storage.data()[colId + rowId * m_storage.cols()];
152  else // column-major
153  return m_storage.data()[rowId + colId * m_storage.rows()];
154  }
155 
157  {
158  return m_storage.data()[index];
159  }
160 
161  EIGEN_STRONG_INLINE const Scalar& coeffRef(Index rowId, Index colId) const
162  {
163  if(Flags & RowMajorBit)
164  return m_storage.data()[colId + rowId * m_storage.cols()];
165  else // column-major
166  return m_storage.data()[rowId + colId * m_storage.rows()];
167  }
168 
170  {
171  return m_storage.data()[index];
172  }
173 
175  template<int LoadMode>
177  {
178  return internal::ploadt<PacketScalar, LoadMode>
179  (m_storage.data() + (Flags & RowMajorBit
180  ? colId + rowId * m_storage.cols()
181  : rowId + colId * m_storage.rows()));
182  }
183 
185  template<int LoadMode>
187  {
188  return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index);
189  }
190 
192  template<int StoreMode>
193  EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar& val)
194  {
195  internal::pstoret<Scalar, PacketScalar, StoreMode>
196  (m_storage.data() + (Flags & RowMajorBit
197  ? colId + rowId * m_storage.cols()
198  : rowId + colId * m_storage.rows()), val);
199  }
200 
202  template<int StoreMode>
204  {
205  internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val);
206  }
207 
210  { return m_storage.data(); }
211 
214  { return m_storage.data(); }
215 
232  EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
233  {
234  eigen_assert( EIGEN_IMPLIES(RowsAtCompileTime!=Dynamic,nbRows==RowsAtCompileTime)
235  && EIGEN_IMPLIES(ColsAtCompileTime!=Dynamic,nbCols==ColsAtCompileTime)
236  && EIGEN_IMPLIES(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic,nbRows<=MaxRowsAtCompileTime)
237  && EIGEN_IMPLIES(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic,nbCols<=MaxColsAtCompileTime)
238  && nbRows>=0 && nbCols>=0 && "Invalid sizes when resizing a matrix or array.");
240  #ifdef EIGEN_INITIALIZE_COEFFS
241  Index size = nbRows*nbCols;
242  bool size_changed = size != this->size();
243  m_storage.resize(size, nbRows, nbCols);
245  #else
247  m_storage.resize(nbRows*nbCols, nbRows, nbCols);
248  #endif
249  }
250 
262  inline void resize(Index size)
263  {
265  eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime==Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0);
266  #ifdef EIGEN_INITIALIZE_COEFFS
267  bool size_changed = size != this->size();
268  #endif
269  if(RowsAtCompileTime == 1)
270  m_storage.resize(size, 1, size);
271  else
272  m_storage.resize(size, size, 1);
273  #ifdef EIGEN_INITIALIZE_COEFFS
275  #endif
276  }
277 
286  inline void resize(NoChange_t, Index nbCols)
287  {
288  resize(rows(), nbCols);
289  }
290 
299  inline void resize(Index nbRows, NoChange_t)
300  {
301  resize(nbRows, cols());
302  }
303 
311  template<typename OtherDerived>
313  {
314  const OtherDerived& other = _other.derived();
316  const Index othersize = other.rows()*other.cols();
317  if(RowsAtCompileTime == 1)
318  {
319  eigen_assert(other.rows() == 1 || other.cols() == 1);
320  resize(1, othersize);
321  }
322  else if(ColsAtCompileTime == 1)
323  {
324  eigen_assert(other.rows() == 1 || other.cols() == 1);
325  resize(othersize, 1);
326  }
327  else resize(other.rows(), other.cols());
328  }
329 
340  {
342  }
343 
352  {
353  // Note: see the comment in conservativeResize(Index,Index)
354  conservativeResize(nbRows, cols());
355  }
356 
365  {
366  // Note: see the comment in conservativeResize(Index,Index)
367  conservativeResize(rows(), nbCols);
368  }
369 
379  {
381  }
382 
392  template<typename OtherDerived>
394  {
396  }
397 
402  {
403  return _set(other);
404  }
405 
407  template<typename OtherDerived>
409  {
410  _resize_to_match(other);
411  return Base::lazyAssign(other.derived());
412  }
413 
414  template<typename OtherDerived>
416  {
417  resize(func.rows(), func.cols());
418  return Base::operator=(func);
419  }
420 
422  {
423 // _check_template_params();
424 // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
425  }
426 
427 #ifndef EIGEN_PARSED_BY_DOXYGEN
428  // FIXME is it still needed ?
431  : m_storage(internal::constructor_without_unaligned_array_assert())
432  {
433 // _check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
434  }
435 #endif
436 
438  : m_storage(a_size, nbRows, nbCols)
439  {
440 // _check_template_params();
441 // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
442  }
443 
446  template<typename OtherDerived>
448  {
449  _resize_to_match(other);
450  Base::operator=(other.derived());
451  return this->derived();
452  }
453 
455  template<typename OtherDerived>
457  : m_storage(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
458  {
459  _check_template_params();
461  Base::operator=(other.derived());
462  }
463 
472  static inline ConstMapType Map(const Scalar* data)
473  { return ConstMapType(data); }
474  static inline MapType Map(Scalar* data)
475  { return MapType(data); }
476  static inline ConstMapType Map(const Scalar* data, Index size)
477  { return ConstMapType(data, size); }
478  static inline MapType Map(Scalar* data, Index size)
479  { return MapType(data, size); }
480  static inline ConstMapType Map(const Scalar* data, Index rows, Index cols)
481  { return ConstMapType(data, rows, cols); }
482  static inline MapType Map(Scalar* data, Index rows, Index cols)
483  { return MapType(data, rows, cols); }
484 
485  static inline ConstAlignedMapType MapAligned(const Scalar* data)
486  { return ConstAlignedMapType(data); }
487  static inline AlignedMapType MapAligned(Scalar* data)
488  { return AlignedMapType(data); }
489  static inline ConstAlignedMapType MapAligned(const Scalar* data, Index size)
490  { return ConstAlignedMapType(data, size); }
491  static inline AlignedMapType MapAligned(Scalar* data, Index size)
492  { return AlignedMapType(data, size); }
493  static inline ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols)
494  { return ConstAlignedMapType(data, rows, cols); }
495  static inline AlignedMapType MapAligned(Scalar* data, Index rows, Index cols)
496  { return AlignedMapType(data, rows, cols); }
497 
498  template<int Outer, int Inner>
499  static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, const Stride<Outer, Inner>& stride)
500  { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); }
501  template<int Outer, int Inner>
502  static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, const Stride<Outer, Inner>& stride)
503  { return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); }
504  template<int Outer, int Inner>
505  static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index size, const Stride<Outer, Inner>& stride)
506  { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); }
507  template<int Outer, int Inner>
508  static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index size, const Stride<Outer, Inner>& stride)
509  { return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
510  template<int Outer, int Inner>
511  static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
512  { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
513  template<int Outer, int Inner>
514  static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
515  { return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
516 
517  template<int Outer, int Inner>
518  static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, const Stride<Outer, Inner>& stride)
519  { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
520  template<int Outer, int Inner>
521  static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, const Stride<Outer, Inner>& stride)
522  { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); }
523  template<int Outer, int Inner>
524  static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index size, const Stride<Outer, Inner>& stride)
525  { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
526  template<int Outer, int Inner>
527  static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index size, const Stride<Outer, Inner>& stride)
528  { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); }
529  template<int Outer, int Inner>
530  static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
531  { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
532  template<int Outer, int Inner>
533  static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride)
534  { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); }
536 
537  using Base::setConstant;
538  Derived& setConstant(Index size, const Scalar& value);
539  Derived& setConstant(Index rows, Index cols, const Scalar& value);
540 
541  using Base::setZero;
542  Derived& setZero(Index size);
543  Derived& setZero(Index rows, Index cols);
544 
545  using Base::setOnes;
546  Derived& setOnes(Index size);
547  Derived& setOnes(Index rows, Index cols);
548 
549  using Base::setRandom;
550  Derived& setRandom(Index size);
551  Derived& setRandom(Index rows, Index cols);
552 
553  #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN
554  #include EIGEN_PLAINOBJECTBASE_PLUGIN
555  #endif
556 
557  protected:
565  template<typename OtherDerived>
567  {
568  #ifdef EIGEN_NO_AUTOMATIC_RESIZING
569  eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.size())
570  : (rows() == other.rows() && cols() == other.cols())))
571  && "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined");
573  #else
574  resizeLike(other);
575  #endif
576  }
577 
592  template<typename OtherDerived>
594  {
595  _set_selector(other.derived(), typename internal::conditional<static_cast<bool>(int(OtherDerived::Flags) & EvalBeforeAssigningBit), internal::true_type, internal::false_type>::type());
596  return this->derived();
597  }
598 
599  template<typename OtherDerived>
600  EIGEN_STRONG_INLINE void _set_selector(const OtherDerived& other, const internal::true_type&) { _set_noalias(other.eval()); }
601 
602  template<typename OtherDerived>
603  EIGEN_STRONG_INLINE void _set_selector(const OtherDerived& other, const internal::false_type&) { _set_noalias(other); }
604 
610  template<typename OtherDerived>
612  {
613  // I don't think we need this resize call since the lazyAssign will anyways resize
614  // and lazyAssign will be called by the assign selector.
615  //_resize_to_match(other);
616  // the 'false' below means to enforce lazy evaluation. We don't use lazyAssign() because
617  // it wouldn't allow to copy a row-vector into a column-vector.
618  return internal::assign_selector<Derived,OtherDerived,false>::run(this->derived(), other.derived());
619  }
620 
621  template<typename T0, typename T1>
623  {
626  FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
627  resize(nbRows,nbCols);
628  }
629  template<typename T0, typename T1>
631  {
633  m_storage.data()[0] = val0;
634  m_storage.data()[1] = val1;
635  }
636 
637  template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
639 
643  template<typename OtherDerived>
644  void _swap(DenseBase<OtherDerived> const & other)
645  {
646  enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic };
647  internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.const_cast_derived());
648  }
649 
650  public:
651 #ifndef EIGEN_PARSED_BY_DOXYGEN
653  {
654  EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&RowMajor)==RowMajor)
655  && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (Options&RowMajor)==0)
656  && ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0))
657  && ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0))
658  && ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0))
659  && ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0))
660  && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic)
661  && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic)
662  && (Options & (DontAlign|RowMajor)) == Options),
663  INVALID_MATRIX_TEMPLATE_PARAMETERS)
664  }
665 #endif
666 
667 private:
668  enum { ThisConstantIsPrivateInPlainObjectBase };
669 };
670 
671 template <typename Derived, typename OtherDerived, bool IsVector>
673 {
674  typedef typename Derived::Index Index;
675  static void run(DenseBase<Derived>& _this, Index rows, Index cols)
676  {
677  if (_this.rows() == rows && _this.cols() == cols) return;
679 
680  if ( ( Derived::IsRowMajor && _this.cols() == cols) || // row-major and we change only the number of rows
681  (!Derived::IsRowMajor && _this.rows() == rows) ) // column-major and we change only the number of columns
682  {
684  _this.derived().m_storage.conservativeResize(rows*cols,rows,cols);
685  }
686  else
687  {
688  // The storage order does not allow us to use reallocation.
689  typename Derived::PlainObject tmp(rows,cols);
690  const Index common_rows = (std::min)(rows, _this.rows());
691  const Index common_cols = (std::min)(cols, _this.cols());
692  tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
693  _this.derived().swap(tmp);
694  }
695  }
696 
697  static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other)
698  {
699  if (_this.rows() == other.rows() && _this.cols() == other.cols()) return;
700 
701  // Note: Here is space for improvement. Basically, for conservativeResize(Index,Index),
702  // neither RowsAtCompileTime or ColsAtCompileTime must be Dynamic. If only one of the
703  // dimensions is dynamic, one could use either conservativeResize(Index rows, NoChange_t) or
704  // conservativeResize(NoChange_t, Index cols). For these methods new static asserts like
705  // EIGEN_STATIC_ASSERT_DYNAMIC_ROWS and EIGEN_STATIC_ASSERT_DYNAMIC_COLS would be good.
708 
709  if ( ( Derived::IsRowMajor && _this.cols() == other.cols()) || // row-major and we change only the number of rows
710  (!Derived::IsRowMajor && _this.rows() == other.rows()) ) // column-major and we change only the number of columns
711  {
712  const Index new_rows = other.rows() - _this.rows();
713  const Index new_cols = other.cols() - _this.cols();
714  _this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols());
715  if (new_rows>0)
716  _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
717  else if (new_cols>0)
718  _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
719  }
720  else
721  {
722  // The storage order does not allow us to use reallocation.
723  typename Derived::PlainObject tmp(other);
724  const Index common_rows = (std::min)(tmp.rows(), _this.rows());
725  const Index common_cols = (std::min)(tmp.cols(), _this.cols());
726  tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols);
727  _this.derived().swap(tmp);
728  }
729  }
730 };
731 
732 namespace internal {
733 
734 template <typename Derived, typename OtherDerived>
735 struct conservative_resize_like_impl<Derived,OtherDerived,true>
736 {
737  typedef typename Derived::Index Index;
738  static void run(DenseBase<Derived>& _this, Index size)
739  {
740  const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size;
741  const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1;
742  _this.derived().m_storage.conservativeResize(size,new_rows,new_cols);
743  }
744 
745  static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other)
746  {
747  if (_this.rows() == other.rows() && _this.cols() == other.cols()) return;
748 
749  const Index num_new_elements = other.size() - _this.size();
750 
751  const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows();
752  const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1;
753  _this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols);
754 
755  if (num_new_elements > 0)
756  _this.tail(num_new_elements) = other.tail(num_new_elements);
757  }
758 };
759 
760 template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers>
761 struct matrix_swap_impl
762 {
763  static inline void run(MatrixTypeA& a, MatrixTypeB& b)
764  {
765  a.base().swap(b);
766  }
767 };
768 
769 template<typename MatrixTypeA, typename MatrixTypeB>
770 struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true>
771 {
772  static inline void run(MatrixTypeA& a, MatrixTypeB& b)
773  {
774  static_cast<typename MatrixTypeA::Base&>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage);
775  }
776 };
777 
778 } // end namespace internal
779 
780 } // end namespace Eigen
781 
782 #endif // EIGEN_DENSESTORAGEBASE_H
Eigen::Map< const Derived, Unaligned, StrideType > type
EIGEN_STRONG_INLINE void conservativeResize(Index size)
Block< Derived > block(Index startRow, Index startCol, Index blockRows, Index blockCols)
Definition: DenseBase.h:57
static MapType Map(Scalar *data)
internal::traits< Derived >::Scalar Scalar
static void run(MatrixTypeA &a, MatrixTypeB &b)
RowsBlockXpr bottomRows(Index n)
Definition: DenseBase.h:425
EIGEN_STRONG_INLINE Scalar * data()
#define EIGEN_STRONG_INLINE
static StridedConstAlignedMapType< Stride< Outer, Inner > >::type MapAligned(const Scalar *data, const Stride< Outer, Inner > &stride)
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
EIGEN_STRONG_INLINE Derived & operator=(const PlainObjectBase &other)
static StridedAlignedMapType< Stride< Outer, Inner > >::type MapAligned(Scalar *data, Index size, const Stride< Outer, Inner > &stride)
Eigen::Map< Derived, Unaligned, StrideType > type
EIGEN_STRONG_INLINE void conservativeResize(Index nbRows, Index nbCols)
SegmentReturnType tail(Index vecSize)
Definition: DenseBase.h:811
EIGEN_STRONG_INLINE void _init2(Index nbRows, Index nbCols, typename internal::enable_if< Base::SizeAtCompileTime!=2, T0 >::type *=0)
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:104
EIGEN_STRONG_INLINE PlainObjectBase(Index a_size, Index nbRows, Index nbCols)
EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
static void run(DenseBase< Derived > &_this, Index rows, Index cols)
static ConstMapType Map(const Scalar *data, Index size)
void resize(Index nbRows, NoChange_t)
internal::traits< Derived >::Index Index
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
Holds strides information for Map.
Definition: Stride.h:44
EIGEN_STRONG_INLINE PlainObjectBase(const EigenBase< OtherDerived > &other)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
Derived & derived()
Definition: EigenBase.h:34
static AlignedMapType MapAligned(Scalar *data)
Eigen::Map< const Derived, Aligned, StrideType > type
const unsigned int RowMajorBit
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
static ConstAlignedMapType MapAligned(const Scalar *data, Index size)
Index rows() const
Definition: EigenBase.h:44
const Base & base() const
static MapType Map(Scalar *data, Index rows, Index cols)
Eigen::Map< Derived, Aligned, StrideType > type
EIGEN_STRONG_INLINE void conservativeResize(NoChange_t, Index nbCols)
EIGEN_STRONG_INLINE void _set_selector(const OtherDerived &other, const internal::false_type &)
internal::dense_xpr_base< Derived >::type Base
EIGEN_STRONG_INLINE Index rows() const
const unsigned int AlignedBit
Index cols() const
Definition: ReturnByValue.h:63
EIGEN_STRONG_INLINE void writePacket(Index index, const PacketScalar &val)
Index rows() const
Definition: ReturnByValue.h:62
static EIGEN_ALWAYS_INLINE void run(Index rows, Index cols)
static ConstMapType Map(const Scalar *data, Index rows, Index cols)
Eigen::Map< Derived, Aligned > AlignedMapType
void throw_std_bad_alloc()
EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
EIGEN_STRONG_INLINE const Scalar & coeff(Index index) const
const Eigen::Map< const Derived, Aligned > ConstAlignedMapType
EIGEN_STRONG_INLINE void _set_selector(const OtherDerived &other, const internal::true_type &)
static StridedConstMapType< Stride< Outer, Inner > >::type Map(const Scalar *data, const Stride< Outer, Inner > &stride)
static AlignedMapType MapAligned(Scalar *data, Index size)
EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
static StridedConstMapType< Stride< Outer, Inner > >::type Map(const Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
Dense storage base class for matrices and arrays.
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
Provides a generic way to set and pass user-specified options.
Definition: options.hpp:65
EIGEN_STRONG_INLINE const Scalar & coeffRef(Index index) const
static AlignedMapType MapAligned(Scalar *data, Index rows, Index cols)
void _swap(DenseBase< OtherDerived > const &other)
static StridedAlignedMapType< Stride< Outer, Inner > >::type MapAligned(Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
const unsigned int EvalBeforeAssigningBit
EIGEN_STRONG_INLINE void _resize_to_match(const EigenBase< OtherDerived > &other)
EIGEN_STRONG_INLINE void _init2(const Scalar &val0, const Scalar &val1, typename internal::enable_if< Base::SizeAtCompileTime==2, T0 >::type *=0)
internal::traits< Derived >::StorageKind StorageKind
static void run(DenseBase< Derived > &_this, const DenseBase< OtherDerived > &other)
PlainObjectBase(internal::constructor_without_unaligned_array_assert)
static StridedAlignedMapType< Stride< Outer, Inner > >::type MapAligned(Scalar *data, const Stride< Outer, Inner > &stride)
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
static ConstAlignedMapType MapAligned(const Scalar *data, Index rows, Index cols)
static StridedMapType< Stride< Outer, Inner > >::type Map(Scalar *data, const Stride< Outer, Inner > &stride)
EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
EIGEN_STRONG_INLINE Derived & operator=(const EigenBase< OtherDerived > &other)
static EIGEN_ALWAYS_INLINE void run(Index, Index)
EIGEN_STRONG_INLINE const Scalar * data() const
EIGEN_STRONG_INLINE void conservativeResizeLike(const DenseBase< OtherDerived > &other)
void resize(Index size)
static EIGEN_STRONG_INLINE void _check_template_params()
static StridedMapType< Stride< Outer, Inner > >::type Map(Scalar *data, Index size, const Stride< Outer, Inner > &stride)
EIGEN_STRONG_INLINE PlainObjectBase()
EIGEN_STRONG_INLINE void conservativeResize(Index nbRows, NoChange_t)
static StridedMapType< Stride< Outer, Inner > >::type Map(Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
Index cols() const
Definition: EigenBase.h:46
EIGEN_STRONG_INLINE Derived & _set_noalias(const DenseBase< OtherDerived > &other)
EIGEN_STRONG_INLINE Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
static StridedConstMapType< Stride< Outer, Inner > >::type Map(const Scalar *data, Index size, const Stride< Outer, Inner > &stride)
EIGEN_STRONG_INLINE Derived & lazyAssign(const DenseBase< OtherDerived > &other)
#define EIGEN_ALWAYS_INLINE
const Eigen::Map< const Derived, Unaligned > ConstMapType
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:42
void resize(NoChange_t, Index nbCols)
static ConstMapType Map(const Scalar *data)
EIGEN_STRONG_INLINE const Scalar & coeffRef(Index rowId, Index colId) const
static StridedConstAlignedMapType< Stride< Outer, Inner > >::type MapAligned(const Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride)
static MapType Map(Scalar *data, Index size)
void swap(const DenseBase< OtherDerived > &other, int=OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
Definition: DenseBase.h:374
#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
EIGEN_STRONG_INLINE Derived & operator=(const ReturnByValue< OtherDerived > &func)
#define EIGEN_IMPLIES(a, b)
EIGEN_STRONG_INLINE void resizeLike(const EigenBase< OtherDerived > &_other)
#define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE)
Definition: StaticAssert.h:136
EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar &val)
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
EIGEN_STRONG_INLINE Index cols() const
#define eigen_assert(x)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:126
NumTraits< Scalar >::Real RealScalar
Eigen::Map< Derived, Unaligned > MapType
ColsBlockXpr rightCols(Index n)
Definition: DenseBase.h:559
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Block< Derived > bottomRightCorner(Index cRows, Index cCols)
Definition: DenseBase.h:232
static void run(DenseBase< Derived > &_this, const DenseBase< OtherDerived > &other)
static StridedConstAlignedMapType< Stride< Outer, Inner > >::type MapAligned(const Scalar *data, Index size, const Stride< Outer, Inner > &stride)
static ConstAlignedMapType MapAligned(const Scalar *data)
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:141
EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const
internal::packet_traits< Scalar >::type PacketScalar
Index size() const
Definition: EigenBase.h:49


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