mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-15 21:26:00 +08:00
bugfix for a = a * b; when a has to be resized
(transplanted from a551107ccea8fe027d2672cb82f6b70e741bb996 )
This commit is contained in:
parent
8302ce6cdc
commit
fa44566305
@ -493,6 +493,9 @@ class Matrix
|
|||||||
else resize(other.rows(), other.cols());
|
else resize(other.rows(), other.cols());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename MatrixType, typename OtherDerived, bool EvalBeforeAssigning = (int(OtherDerived::Flags) & EvalBeforeAssigningBit) != 0>
|
||||||
|
struct ei_matrix_set_selector;
|
||||||
|
|
||||||
/** \internal Copies the value of the expression \a other into \c *this with automatic resizing.
|
/** \internal Copies the value of the expression \a other into \c *this with automatic resizing.
|
||||||
*
|
*
|
||||||
* *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
|
* *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized),
|
||||||
@ -507,8 +510,8 @@ class Matrix
|
|||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_STRONG_INLINE Matrix& _set(const MatrixBase<OtherDerived>& other)
|
EIGEN_STRONG_INLINE Matrix& _set(const MatrixBase<OtherDerived>& other)
|
||||||
{
|
{
|
||||||
_resize_to_match(other);
|
ei_matrix_set_selector<Matrix,OtherDerived>::run(*this,other.derived());
|
||||||
return Base::operator=(other);
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \internal Like _set() but additionally makes the assumption that no aliasing effect can happen (which
|
/** \internal Like _set() but additionally makes the assumption that no aliasing effect can happen (which
|
||||||
@ -536,6 +539,20 @@ class Matrix
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
||||||
|
template<typename MatrixType, typename OtherDerived>
|
||||||
|
struct Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ei_matrix_set_selector<MatrixType,OtherDerived,true>
|
||||||
|
{
|
||||||
|
static void run(MatrixType& dst, const OtherDerived& src) { dst._set_noalias(src.eval()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
|
||||||
|
template<typename MatrixType, typename OtherDerived>
|
||||||
|
struct Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ei_matrix_set_selector<MatrixType,OtherDerived,false>
|
||||||
|
{
|
||||||
|
static void run(MatrixType& dst, const OtherDerived& src) { dst._set_noalias(src); }
|
||||||
|
};
|
||||||
|
|
||||||
/** \defgroup matrixtypedefs Global matrix typedefs
|
/** \defgroup matrixtypedefs Global matrix typedefs
|
||||||
*
|
*
|
||||||
* \ingroup Core_Module
|
* \ingroup Core_Module
|
||||||
|
@ -42,4 +42,10 @@ void test_product_large()
|
|||||||
m = (v+v).asDiagonal() * m;
|
m = (v+v).asDiagonal() * m;
|
||||||
VERIFY_IS_APPROX(m, MatrixXf::Constant(N,3,2));
|
VERIFY_IS_APPROX(m, MatrixXf::Constant(N,3,2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// test deferred resizing in Matrix::operator=
|
||||||
|
MatrixXf a = MatrixXf::Random(10,4), b = MatrixXf::Random(4,10), c = a;
|
||||||
|
VERIFY_IS_APPROX((a = a * b), (c * b).eval());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user