mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Another big refactoring change:
* add a new Eigen2Support module including Cwise, Flagged, and some other deprecated stuff * add a few cwiseXxx functions * adapt a few modules to use cwiseXxx instead of the .cwise() prefix
This commit is contained in:
@@ -89,7 +89,7 @@ template<typename _MatrixType> class FullPivLU
|
||||
* \returns a reference to *this
|
||||
*/
|
||||
FullPivLU& compute(const MatrixType& matrix);
|
||||
|
||||
|
||||
/** \returns the LU decomposition matrix: the upper-triangular part is U, the
|
||||
* unit-lower-triangular part is L (at least for square matrices; in the non-square
|
||||
* case, special care is needed, see the documentation of class FullPivLU).
|
||||
@@ -101,7 +101,7 @@ template<typename _MatrixType> class FullPivLU
|
||||
ei_assert(m_isInitialized && "LU is not initialized.");
|
||||
return m_lu;
|
||||
}
|
||||
|
||||
|
||||
/** \returns the number of nonzero pivots in the LU decomposition.
|
||||
* Here nonzero is meant in the exact sense, not in a fuzzy sense.
|
||||
* So that notion isn't really intrinsically interesting, but it is
|
||||
@@ -114,12 +114,12 @@ template<typename _MatrixType> class FullPivLU
|
||||
ei_assert(m_isInitialized && "LU is not initialized.");
|
||||
return m_nonzero_pivots;
|
||||
}
|
||||
|
||||
|
||||
/** \returns the absolute value of the biggest pivot, i.e. the biggest
|
||||
* diagonal coefficient of U.
|
||||
*/
|
||||
RealScalar maxPivot() const { return m_maxpivot; }
|
||||
|
||||
|
||||
/** \returns a vector of integers, whose size is the number of rows of the matrix being decomposed,
|
||||
* representing the P permutation i.e. the permutation of the rows. For its precise meaning,
|
||||
* see the examples given in the documentation of class FullPivLU.
|
||||
@@ -255,7 +255,7 @@ template<typename _MatrixType> class FullPivLU
|
||||
m_usePrescribedThreshold = true;
|
||||
m_prescribedThreshold = threshold;
|
||||
}
|
||||
|
||||
|
||||
/** Allows to come back to the default behavior, letting Eigen use its default formula for
|
||||
* determining the threshold.
|
||||
*
|
||||
@@ -268,7 +268,7 @@ template<typename _MatrixType> class FullPivLU
|
||||
{
|
||||
m_usePrescribedThreshold = false;
|
||||
}
|
||||
|
||||
|
||||
/** Returns the threshold that will be used by certain methods such as rank().
|
||||
*
|
||||
* See the documentation of setThreshold(const RealScalar&).
|
||||
@@ -281,7 +281,7 @@ template<typename _MatrixType> class FullPivLU
|
||||
// and turns out to be identical to Higham's formula used already in LDLt.
|
||||
: epsilon<Scalar>() * m_lu.diagonalSize();
|
||||
}
|
||||
|
||||
|
||||
/** \returns the rank of the matrix of which *this is the LU decomposition.
|
||||
*
|
||||
* \note This method has to determine which pivots should be considered nonzero.
|
||||
@@ -297,7 +297,7 @@ template<typename _MatrixType> class FullPivLU
|
||||
result += (ei_abs(m_lu.coeff(i,i)) > premultiplied_threshold);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** \returns the dimension of the kernel of the matrix of which *this is the LU decomposition.
|
||||
*
|
||||
* \note This method has to determine which pivots should be considered nonzero.
|
||||
@@ -365,7 +365,7 @@ template<typename _MatrixType> class FullPivLU
|
||||
|
||||
inline int rows() const { return m_lu.rows(); }
|
||||
inline int cols() const { return m_lu.cols(); }
|
||||
|
||||
|
||||
protected:
|
||||
MatrixType m_lu;
|
||||
IntColVectorType m_p;
|
||||
@@ -416,7 +416,7 @@ FullPivLU<MatrixType>& FullPivLU<MatrixType>::compute(const MatrixType& matrix)
|
||||
int row_of_biggest_in_corner, col_of_biggest_in_corner;
|
||||
RealScalar biggest_in_corner;
|
||||
biggest_in_corner = m_lu.corner(Eigen::BottomRight, rows-k, cols-k)
|
||||
.cwise().abs()
|
||||
.cwiseAbs()
|
||||
.maxCoeff(&row_of_biggest_in_corner, &col_of_biggest_in_corner);
|
||||
row_of_biggest_in_corner += k; // correct the values! since they were computed in the corner,
|
||||
col_of_biggest_in_corner += k; // need to add k to them.
|
||||
@@ -453,7 +453,7 @@ FullPivLU<MatrixType>& FullPivLU<MatrixType>::compute(const MatrixType& matrix)
|
||||
|
||||
// Now that the pivot is at the right location, we update the remaining
|
||||
// bottom-right corner by Gaussian elimination.
|
||||
|
||||
|
||||
if(k<rows-1)
|
||||
m_lu.col(k).end(rows-k-1) /= m_lu.coeff(k,k);
|
||||
if(k<size-1)
|
||||
@@ -507,7 +507,7 @@ struct ei_kernel_retval<FullPivLU<_MatrixType> >
|
||||
dst.setZero();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Let us use the following lemma:
|
||||
*
|
||||
* Lemma: If the matrix A has the LU decomposition PAQ = LU,
|
||||
@@ -575,7 +575,7 @@ struct ei_image_retval<FullPivLU<_MatrixType> >
|
||||
: ei_image_retval_base<FullPivLU<_MatrixType> >
|
||||
{
|
||||
EIGEN_MAKE_IMAGE_HELPERS(FullPivLU<_MatrixType>)
|
||||
|
||||
|
||||
enum { MaxSmallDimAtCompileTime = EIGEN_ENUM_MIN(
|
||||
MatrixType::MaxColsAtCompileTime,
|
||||
MatrixType::MaxRowsAtCompileTime)
|
||||
@@ -591,7 +591,7 @@ struct ei_image_retval<FullPivLU<_MatrixType> >
|
||||
dst.setZero();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Matrix<int, Dynamic, 1, 0, MaxSmallDimAtCompileTime, 1> pivots(rank());
|
||||
RealScalar premultiplied_threshold = dec().maxPivot() * dec().threshold();
|
||||
int p = 0;
|
||||
@@ -599,7 +599,7 @@ struct ei_image_retval<FullPivLU<_MatrixType> >
|
||||
if(ei_abs(dec().matrixLU().coeff(i,i)) > premultiplied_threshold)
|
||||
pivots.coeffRef(p++) = i;
|
||||
ei_internal_assert(p == rank());
|
||||
|
||||
|
||||
for(int i = 0; i < rank(); ++i)
|
||||
dst.col(i) = originalMatrix().col(dec().permutationQ().coeff(pivots.coeff(i)));
|
||||
}
|
||||
@@ -612,7 +612,7 @@ struct ei_solve_retval<FullPivLU<_MatrixType>, Rhs>
|
||||
: ei_solve_retval_base<FullPivLU<_MatrixType>, Rhs>
|
||||
{
|
||||
EIGEN_MAKE_SOLVE_HELPERS(FullPivLU<_MatrixType>,Rhs)
|
||||
|
||||
|
||||
template<typename Dest> void evalTo(Dest& dst) const
|
||||
{
|
||||
/* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}.
|
||||
|
||||
@@ -148,7 +148,7 @@ struct ei_compute_inverse<MatrixType, ResultType, 3>
|
||||
cofactors_col0.coeffRef(0) = matrix.minor(0,0).determinant();
|
||||
cofactors_col0.coeffRef(1) = -matrix.minor(1,0).determinant();
|
||||
cofactors_col0.coeffRef(2) = matrix.minor(2,0).determinant();
|
||||
const Scalar det = (cofactors_col0.cwise()*matrix.col(0)).sum();
|
||||
const Scalar det = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
|
||||
const Scalar invdet = Scalar(1) / det;
|
||||
ei_compute_inverse_size3_helper(matrix, invdet, cofactors_col0, result);
|
||||
}
|
||||
@@ -170,7 +170,7 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 3>
|
||||
cofactors_col0.coeffRef(0) = matrix.minor(0,0).determinant();
|
||||
cofactors_col0.coeffRef(1) = -matrix.minor(1,0).determinant();
|
||||
cofactors_col0.coeffRef(2) = matrix.minor(2,0).determinant();
|
||||
determinant = (cofactors_col0.cwise()*matrix.col(0)).sum();
|
||||
determinant = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
|
||||
invertible = ei_abs(determinant) > absDeterminantThreshold;
|
||||
if(!invertible) return;
|
||||
const Scalar invdet = Scalar(1) / determinant;
|
||||
@@ -256,7 +256,7 @@ struct ei_compute_inverse<MatrixType, ResultType, 4>
|
||||
|
||||
// now good_row0 and good_row1 are correctly set
|
||||
good:
|
||||
|
||||
|
||||
// do row permutations to move this 2x2 block to the top
|
||||
matrix.row(0).swap(matrix.row(good_row0));
|
||||
matrix.row(1).swap(matrix.row(good_row1));
|
||||
|
||||
@@ -233,7 +233,7 @@ struct ei_partial_lu_impl
|
||||
{
|
||||
int row_of_biggest_in_col;
|
||||
RealScalar biggest_in_corner
|
||||
= lu.col(k).end(rows-k).cwise().abs().maxCoeff(&row_of_biggest_in_col);
|
||||
= lu.col(k).end(rows-k).cwiseAbs().maxCoeff(&row_of_biggest_in_col);
|
||||
row_of_biggest_in_col += k;
|
||||
|
||||
if(biggest_in_corner == 0) // the pivot is exactly zero: the matrix is singular
|
||||
@@ -412,7 +412,7 @@ struct ei_solve_retval<PartialPivLU<_MatrixType>, Rhs>
|
||||
: ei_solve_retval_base<PartialPivLU<_MatrixType>, Rhs>
|
||||
{
|
||||
EIGEN_MAKE_SOLVE_HELPERS(PartialPivLU<_MatrixType>,Rhs)
|
||||
|
||||
|
||||
template<typename Dest> void evalTo(Dest& dst) const
|
||||
{
|
||||
/* The decomposition PA = LU can be rewritten as A = P^{-1} L U.
|
||||
@@ -421,7 +421,7 @@ struct ei_solve_retval<PartialPivLU<_MatrixType>, Rhs>
|
||||
* Step 2: replace c by the solution x to Lx = c.
|
||||
* Step 3: replace c by the solution x to Ux = c.
|
||||
*/
|
||||
|
||||
|
||||
const int size = dec().matrixLU().rows();
|
||||
ei_assert(rhs().rows() == size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user