From 86ca35ccff0837f1d55efe2043ef330b98bba259 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Tue, 7 Jun 2011 14:32:16 +0100 Subject: [PATCH] Fix and test MatrixSquareRoot for 1-by-1 matrices. --- unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h | 4 ++-- unsupported/test/matrix_square_root.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h b/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h index 892e6a0a5..1a569a2df 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h @@ -179,7 +179,7 @@ void MatrixSquareRoot::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::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)); } diff --git a/unsupported/test/matrix_square_root.cpp b/unsupported/test/matrix_square_root.cpp index 83b130c9a..8e701aac6 100644 --- a/unsupported/test/matrix_square_root.cpp +++ b/unsupported/test/matrix_square_root.cpp @@ -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(9, 9))); + CALL_SUBTEST_5(testMatrixSqrt(Matrix())); + CALL_SUBTEST_5(testMatrixSqrt(Matrix,1,1>())); } }