From 00844e38650a03086fdebf3e5e55ee1b3688ba04 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Thu, 23 Feb 2023 18:44:53 +0000 Subject: [PATCH] Fix a number of MSAN failures in SVD tests. --- test/bdcsvd.cpp | 4 +--- test/jacobisvd.cpp | 4 +++- test/svd_common.h | 28 +++++++++++++++++++--------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/test/bdcsvd.cpp b/test/bdcsvd.cpp index 539494b21..b21479e20 100644 --- a/test/bdcsvd.cpp +++ b/test/bdcsvd.cpp @@ -95,9 +95,7 @@ void compare_bdc_jacobi_instance(bool structure_as_m, int algoswap = 16) template void bdcsvd_all_options(const MatrixType& input = MatrixType()) { - MatrixType m(input.rows(), input.cols()); - svd_fill_random(m); - svd_option_checks(m); + svd_option_checks(input); } template diff --git a/test/jacobisvd.cpp b/test/jacobisvd.cpp index 401adf0ba..0c04235b4 100644 --- a/test/jacobisvd.cpp +++ b/test/jacobisvd.cpp @@ -75,9 +75,11 @@ void jacobisvd_verify_assert(const MatrixType& input = MatrixType()) { } template -void jacobisvd_verify_inputs(const MatrixType& m = MatrixType()) { +void jacobisvd_verify_inputs(const MatrixType& input = MatrixType()) { // check defaults typedef JacobiSVD DefaultSVD; + MatrixType m(input.rows(), input.cols()); + svd_fill_random(m); DefaultSVD defaultSvd(m); VERIFY((int)DefaultSVD::QRPreconditioner == (int)ColPivHouseholderQRPreconditioner); VERIFY(!defaultSvd.computeU()); diff --git a/test/svd_common.h b/test/svd_common.h index 9822595bf..84551f340 100644 --- a/test/svd_common.h +++ b/test/svd_common.h @@ -392,12 +392,14 @@ void svd_preallocate() } template -void svd_verify_assert_full_only(const MatrixType& m = MatrixType()) { +void svd_verify_assert_full_only(const MatrixType& input = MatrixType()) { enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime }; - + typedef Matrix RhsType; - RhsType rhs = RhsType::Zero(m.rows()); - + RhsType rhs = RhsType::Zero(input.rows()); + MatrixType m(input.rows(), input.cols()); + svd_fill_random(m); + SVD_STATIC_OPTIONS(MatrixType, QRPreconditioner) svd0; VERIFY_RAISES_ASSERT((svd0.matrixU())); VERIFY_RAISES_ASSERT((svd0.singularValues())); @@ -420,11 +422,12 @@ void svd_verify_assert_full_only(const MatrixType& m = MatrixType()) { } template -void svd_verify_assert(const MatrixType& m = MatrixType()) { +void svd_verify_assert(const MatrixType& input = MatrixType()) { enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime }; - typedef Matrix RhsType; - RhsType rhs = RhsType::Zero(m.rows()); + RhsType rhs = RhsType::Zero(input.rows()); + MatrixType m(input.rows(), input.cols()); + svd_fill_random(m); SVD_STATIC_OPTIONS(MatrixType, QRPreconditioner | ComputeThinU) svdThinU(m); VERIFY_RAISES_ASSERT((svdThinU.matrixV())); @@ -509,7 +512,9 @@ void svd_check_runtime_options(const MatrixType& m, unsigned int computationOpti } template -void svd_option_checks(const MatrixType& m) { +void svd_option_checks(const MatrixType& input) { + MatrixType m(input.rows(), input.cols()); + svd_fill_random(m); svd_compute_checks(m); svd_compute_checks(m); svd_compute_checks(m); @@ -543,7 +548,9 @@ void svd_option_checks(const MatrixType& m) { } template -void svd_option_checks_full_only(const MatrixType& m) { +void svd_option_checks_full_only(const MatrixType& input) { + MatrixType m(input.rows(), input.cols()); + svd_fill_random(m); svd_compute_checks(m); svd_compute_checks(m); svd_compute_checks(m); @@ -563,12 +570,14 @@ void svd_check_max_size_matrix(int initialRows, int initialCols) { int cols = MaxColsAtCompileTime == Dynamic ? initialCols : (std::min)(initialCols, (int)MaxColsAtCompileTime); MatrixType m(rows, cols); + svd_fill_random(m); SVD_STATIC_OPTIONS(MatrixType, QRPreconditioner | ComputeThinU | ComputeThinV) thinSvd(m); SVD_STATIC_OPTIONS(MatrixType, QRPreconditioner | ComputeThinU | ComputeFullV) mixedSvd1(m); SVD_STATIC_OPTIONS(MatrixType, QRPreconditioner | ComputeFullU | ComputeThinV) mixedSvd2(m); SVD_STATIC_OPTIONS(MatrixType, QRPreconditioner | ComputeFullU | ComputeFullV) fullSvd(m); MatrixType n(MaxRowsAtCompileTime, MaxColsAtCompileTime); + svd_fill_random(n); thinSvd.compute(n); mixedSvd1.compute(n); mixedSvd2.compute(n); @@ -595,6 +604,7 @@ void svd_verify_constructor_options_assert(const MatrixType& m, bool fullOnly = typedef Matrix RhsType; RhsType rhs(rows); + svd_fill_random(rhs); SvdType svd; VERIFY_RAISES_ASSERT(svd.matrixU()) VERIFY_RAISES_ASSERT(svd.singularValues())