mirror of
https://github.com/opencv/opencv.git
synced 2025-07-26 07:07:37 +08:00
core: add iterations limit check in eigenNonSymmetric()
This commit is contained in:
parent
ec25689b42
commit
a7c4ee9ae1
@ -322,6 +322,8 @@ private:
|
|||||||
// Fortran subroutine in EISPACK.
|
// Fortran subroutine in EISPACK.
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
|
const int max_iters_count = 1000 * this->n;
|
||||||
|
|
||||||
int nn = this->n;
|
int nn = this->n;
|
||||||
int n1 = nn - 1;
|
int n1 = nn - 1;
|
||||||
int low = 0;
|
int low = 0;
|
||||||
@ -487,7 +489,9 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iter = iter + 1; // (Could check iteration count here.)
|
iter = iter + 1;
|
||||||
|
if (iter > max_iters_count)
|
||||||
|
CV_Error(Error::StsNoConv, "Algorithm doesn't converge (complex eigen values?)");
|
||||||
|
|
||||||
// Look for two consecutive small sub-diagonal elements
|
// Look for two consecutive small sub-diagonal elements
|
||||||
int m = n1 - 2;
|
int m = n1 - 2;
|
||||||
|
@ -519,4 +519,15 @@ TEST_P(Core_EigenZero, double)
|
|||||||
}
|
}
|
||||||
INSTANTIATE_TEST_CASE_P(/**/, Core_EigenZero, testing::Values(2, 3, 5));
|
INSTANTIATE_TEST_CASE_P(/**/, Core_EigenZero, testing::Values(2, 3, 5));
|
||||||
|
|
||||||
|
TEST(Core_EigenNonSymmetric, convergence)
|
||||||
|
{
|
||||||
|
Matx33d m(
|
||||||
|
0, -1, 0,
|
||||||
|
1, 0, 1,
|
||||||
|
0, -1, 0);
|
||||||
|
Mat eigenvalues, eigenvectors;
|
||||||
|
// eigen values are complex, algorithm doesn't converge
|
||||||
|
EXPECT_THROW(cv::eigenNonSymmetric(m, eigenvalues, eigenvectors), cv::Exception); // exception instead of hang
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user