mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-23 06:43:13 +08:00
initialize-by-zero: remember that when the newsize==oldsize, resize() must remain a NOP
This commit is contained in:
parent
307898e84b
commit
8a1bada43d
@ -259,8 +259,14 @@ class Matrix
|
|||||||
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
|
&& (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
|
||||||
&& (MaxColsAtCompileTime == Dynamic || MaxColsAtCompileTime >= cols)
|
&& (MaxColsAtCompileTime == Dynamic || MaxColsAtCompileTime >= cols)
|
||||||
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
|
&& (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
|
||||||
m_storage.resize(rows * cols, rows, cols);
|
#ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
|
||||||
EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
|
int size = rows*cols;
|
||||||
|
bool size_changed = size != this->size();
|
||||||
|
m_storage.resize(size, rows, cols);
|
||||||
|
if(size_changed) EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
|
||||||
|
#else
|
||||||
|
m_storage.resize(rows*cols, rows, cols);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resizes \c *this to a vector of length \a size
|
/** Resizes \c *this to a vector of length \a size
|
||||||
@ -278,11 +284,16 @@ class Matrix
|
|||||||
{
|
{
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix)
|
||||||
ei_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == size);
|
ei_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == size);
|
||||||
|
#ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
|
||||||
|
bool size_changed = size != this->size();
|
||||||
|
#endif
|
||||||
if(RowsAtCompileTime == 1)
|
if(RowsAtCompileTime == 1)
|
||||||
m_storage.resize(size, 1, size);
|
m_storage.resize(size, 1, size);
|
||||||
else
|
else
|
||||||
m_storage.resize(size, size, 1);
|
m_storage.resize(size, size, 1);
|
||||||
EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
|
#ifdef EIGEN_INITIALIZE_MATRICES_BY_ZERO
|
||||||
|
if(size_changed) EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the special value \c NoChange
|
/** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the special value \c NoChange
|
||||||
|
Loading…
x
Reference in New Issue
Block a user