mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
* fix bug in SwapWrapper : store the wrapped expression by reference
* optimize setIdentity: when the matrix is large enough it is better to setZero() and overwrite the diagonal * start of LU solver, disabled for now
This commit is contained in:
@@ -515,6 +515,27 @@ bool MatrixBase<Derived>::isIdentity
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)>
|
||||
struct ei_setIdentity_impl
|
||||
{
|
||||
static inline Derived& run(Derived& m)
|
||||
{
|
||||
return m = Derived::Identity(m.rows(), m.cols());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Derived>
|
||||
struct ei_setIdentity_impl<Derived, true>
|
||||
{
|
||||
static inline Derived& run(Derived& m)
|
||||
{
|
||||
m.setZero();
|
||||
const int size = std::min(m.rows(), m.cols());
|
||||
for(int i = 0; i < size; i++) m.coeffRef(i,i) = typename Derived::Scalar(1);
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
/** Writes the identity expression (not necessarily square) into *this.
|
||||
*
|
||||
* Example: \include MatrixBase_setIdentity.cpp
|
||||
@@ -525,7 +546,7 @@ bool MatrixBase<Derived>::isIdentity
|
||||
template<typename Derived>
|
||||
inline Derived& MatrixBase<Derived>::setIdentity()
|
||||
{
|
||||
return derived() = Identity(rows(), cols());
|
||||
return ei_setIdentity_impl<Derived>::run(derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the i-th unit (basis) vector.
|
||||
|
||||
@@ -53,7 +53,7 @@ template<typename ExpressionType> class SwapWrapper
|
||||
EIGEN_GENERIC_PUBLIC_INTERFACE(SwapWrapper)
|
||||
typedef typename ei_packet_traits<Scalar>::type Packet;
|
||||
|
||||
inline SwapWrapper(ExpressionType& matrix) : m_expression(matrix) {}
|
||||
inline SwapWrapper(ExpressionType& xpr) : m_expression(xpr) {}
|
||||
|
||||
inline int rows() const { return m_expression.rows(); }
|
||||
inline int cols() const { return m_expression.cols(); }
|
||||
@@ -106,7 +106,7 @@ template<typename ExpressionType> class SwapWrapper
|
||||
}
|
||||
|
||||
protected:
|
||||
ExpressionType m_expression;
|
||||
ExpressionType& m_expression;
|
||||
};
|
||||
|
||||
/** swaps *this with the expression \a other.
|
||||
|
||||
Reference in New Issue
Block a user