mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-24 02:29:33 +08:00
Fix and test MatrixSquareRoot for 1-by-1 matrices.
This commit is contained in:
parent
91fe1507d1
commit
86ca35ccff
@ -179,7 +179,7 @@ void MatrixSquareRoot<MatrixType, 0>::compute1x1offDiagonalBlock(MatrixType& sqr
|
||||
typename MatrixType::Index i,
|
||||
typename MatrixType::Index j)
|
||||
{
|
||||
Scalar tmp = sqrtT.row(i).segment(i+1,j-i-1) * sqrtT.col(j).segment(i+1,j-i-1);
|
||||
Scalar tmp = (sqrtT.row(i).segment(i+1,j-i-1) * sqrtT.col(j).segment(i+1,j-i-1)).value();
|
||||
sqrtT.coeffRef(i,j) = (T.coeff(i,j) - tmp) / (sqrtT.coeff(i,i) + sqrtT.coeff(j,j));
|
||||
}
|
||||
|
||||
@ -308,7 +308,7 @@ void MatrixSquareRoot<MatrixType, 1>::compute(ResultType &result)
|
||||
for (Index i = j-1; i >= 0; i--) {
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
// if i = j-1, then segment has length 0 so tmp = 0
|
||||
Scalar tmp = result.row(i).segment(i+1,j-i-1) * result.col(j).segment(i+1,j-i-1);
|
||||
Scalar tmp = (result.row(i).segment(i+1,j-i-1) * result.col(j).segment(i+1,j-i-1)).value();
|
||||
// denominator may be zero if original matrix is singular
|
||||
result.coeffRef(i,j) = (T.coeff(i,j) - tmp) / (result.coeff(i,i) + result.coeff(j,j));
|
||||
}
|
||||
|
@ -71,5 +71,7 @@ void test_matrix_square_root()
|
||||
CALL_SUBTEST_2(testMatrixSqrt(MatrixXcd(12,12)));
|
||||
CALL_SUBTEST_3(testMatrixSqrt(Matrix4f()));
|
||||
CALL_SUBTEST_4(testMatrixSqrt(Matrix<double,Dynamic,Dynamic,RowMajor>(9, 9)));
|
||||
CALL_SUBTEST_5(testMatrixSqrt(Matrix<float,1,1>()));
|
||||
CALL_SUBTEST_5(testMatrixSqrt(Matrix<std::complex<float>,1,1>()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user