Eigen::internal::conservative_resize_like_impl< Derived, OtherDerived, IsVector > Struct Template Reference

#include <PlainObjectBase.h>

Static Public Member Functions

static void run (DenseBase< Derived > &_this, Index rows, Index cols)
 
static void run (DenseBase< Derived > &_this, const DenseBase< OtherDerived > &other)
 

Static Public Attributes

static constexpr bool IsRelocatable = std::is_trivially_copyable<typename Derived::Scalar>::value
 

Member Function Documentation

◆ run() [1/2]

template<typename Derived , typename OtherDerived , bool IsVector>
static void Eigen::internal::conservative_resize_like_impl< Derived, OtherDerived, IsVector >::run ( DenseBase< Derived > &  _this,
const DenseBase< OtherDerived > &  other 
)
inlinestatic
956  {
957  if (_this.rows() == other.rows() && _this.cols() == other.cols()) return;
958 
959  // Note: Here is space for improvement. Basically, for conservativeResize(Index,Index),
960  // neither RowsAtCompileTime or ColsAtCompileTime must be Dynamic. If only one of the
961  // dimensions is dynamic, one could use either conservativeResize(Index rows, NoChange_t) or
962  // conservativeResize(NoChange_t, Index cols). For these methods new static asserts like
963  // EIGEN_STATIC_ASSERT_DYNAMIC_ROWS and EIGEN_STATIC_ASSERT_DYNAMIC_COLS would be good.
966 
967  if (IsRelocatable &&
968  ((Derived::IsRowMajor && _this.cols() == other.cols()) || // row-major and we change only the number of rows
969  (!Derived::IsRowMajor &&
970  _this.rows() == other.rows()))) // column-major and we change only the number of columns
971  {
972  const Index new_rows = other.rows() - _this.rows();
973  const Index new_cols = other.cols() - _this.cols();
974  _this.derived().m_storage.conservativeResize(other.size(), other.rows(), other.cols());
975  if (new_rows > 0)
976  _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows);
977  else if (new_cols > 0)
978  _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols);
979  } else {
980  // The storage order does not allow us to use reallocation.
981  Derived tmp(other);
982  const Index common_rows = numext::mini(tmp.rows(), _this.rows());
983  const Index common_cols = numext::mini(tmp.cols(), _this.cols());
984  tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols);
985  _this.derived().swap(tmp);
986  }
987  }
#define EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(TYPE)
Definition: StaticAssert.h:45
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseBase< OtherDerived > &other)
Override DenseBase::swap() since for dynamic-sized matrices of same type it is enough to swap the dat...
Definition: PlainObjectBase.h:898
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
Definition: MathFunctions.h:920
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
static constexpr bool IsRelocatable
Definition: PlainObjectBase.h:932

References Eigen::PlainObjectBase< Derived >::cols(), EIGEN_STATIC_ASSERT_DYNAMIC_SIZE, Eigen::internal::conservative_resize_like_impl< Derived, OtherDerived, IsVector >::IsRelocatable, Eigen::numext::mini(), Eigen::PlainObjectBase< Derived >::rows(), Eigen::DenseBase< Derived >::swap(), and tmp.

◆ run() [2/2]

template<typename Derived , typename OtherDerived , bool IsVector>
static void Eigen::internal::conservative_resize_like_impl< Derived, OtherDerived, IsVector >::run ( DenseBase< Derived > &  _this,
Index  rows,
Index  cols 
)
inlinestatic
933  {
934  if (_this.rows() == rows && _this.cols() == cols) return;
936 
937  if (IsRelocatable &&
938  ((Derived::IsRowMajor && _this.cols() == cols) || // row-major and we change only the number of rows
939  (!Derived::IsRowMajor && _this.rows() == rows))) // column-major and we change only the number of columns
940  {
941 #ifndef EIGEN_NO_DEBUG
942  internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime, Derived::MaxRowsAtCompileTime,
943  Derived::MaxColsAtCompileTime>::run(rows, cols);
944 #endif
945  _this.derived().m_storage.conservativeResize(rows * cols, rows, cols);
946  } else {
947  // The storage order does not allow us to use reallocation.
948  Derived tmp(rows, cols);
949  const Index common_rows = numext::mini(rows, _this.rows());
950  const Index common_cols = numext::mini(cols, _this.cols());
951  tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols);
952  _this.derived().swap(tmp);
953  }
954  }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
static void run(DenseBase< Derived > &_this, Index rows, Index cols)
Definition: PlainObjectBase.h:933

References cols, EIGEN_STATIC_ASSERT_DYNAMIC_SIZE, Eigen::internal::conservative_resize_like_impl< Derived, OtherDerived, IsVector >::IsRelocatable, Eigen::numext::mini(), rows, Eigen::DenseBase< Derived >::swap(), and tmp.

Referenced by Eigen::PlainObjectBase< Derived >::conservativeResize(), and Eigen::PlainObjectBase< Derived >::conservativeResizeLike().

Member Data Documentation

◆ IsRelocatable

template<typename Derived , typename OtherDerived , bool IsVector>
constexpr bool Eigen::internal::conservative_resize_like_impl< Derived, OtherDerived, IsVector >::IsRelocatable = std::is_trivially_copyable<typename Derived::Scalar>::value
staticconstexpr

The documentation for this struct was generated from the following file: