mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Revert "Update SVD Module to allow specifying computation options with a...
This commit is contained in:
committed by
David Tellenbach
parent
4dd126c630
commit
085c2fc5d5
@@ -19,11 +19,26 @@
|
||||
#include <iostream>
|
||||
#include <Eigen/LU>
|
||||
|
||||
|
||||
#define SVD_DEFAULT(M) BDCSVD<M>
|
||||
#define SVD_FOR_MIN_NORM(M) BDCSVD<M>
|
||||
#define SVD_STATIC_OPTIONS(M, O) BDCSVD<M, O>
|
||||
#include "svd_common.h"
|
||||
|
||||
// Check all variants of JacobiSVD
|
||||
template<typename MatrixType>
|
||||
void bdcsvd(const MatrixType& a = MatrixType(), bool pickrandom = true)
|
||||
{
|
||||
MatrixType m;
|
||||
if(pickrandom) {
|
||||
m.resizeLike(a);
|
||||
svd_fill_random(m);
|
||||
}
|
||||
else
|
||||
m = a;
|
||||
|
||||
CALL_SUBTEST(( svd_test_all_computation_options<BDCSVD<MatrixType> >(m, false) ));
|
||||
}
|
||||
|
||||
template<typename MatrixType>
|
||||
void bdcsvd_method()
|
||||
{
|
||||
@@ -34,23 +49,28 @@ void bdcsvd_method()
|
||||
VERIFY_IS_APPROX(m.bdcSvd().singularValues(), RealVecType::Ones());
|
||||
VERIFY_RAISES_ASSERT(m.bdcSvd().matrixU());
|
||||
VERIFY_RAISES_ASSERT(m.bdcSvd().matrixV());
|
||||
VERIFY_IS_APPROX(m.template bdcSvd<ComputeFullU|ComputeFullV>().solve(m), m);
|
||||
VERIFY_IS_APPROX(m.template bdcSvd<ComputeFullU|ComputeFullV>().transpose().solve(m), m);
|
||||
VERIFY_IS_APPROX(m.template bdcSvd<ComputeFullU|ComputeFullV>().adjoint().solve(m), m);
|
||||
VERIFY_IS_APPROX(m.bdcSvd(ComputeFullU|ComputeFullV).solve(m), m);
|
||||
VERIFY_IS_APPROX(m.bdcSvd(ComputeFullU|ComputeFullV).transpose().solve(m), m);
|
||||
VERIFY_IS_APPROX(m.bdcSvd(ComputeFullU|ComputeFullV).adjoint().solve(m), m);
|
||||
}
|
||||
|
||||
// compare the Singular values returned with Jacobi and Bdc
|
||||
// Compare the Singular values returned with Jacobi and Bdc.
|
||||
template<typename MatrixType>
|
||||
void compare_bdc_jacobi(const MatrixType& a = MatrixType(), int algoswap = 16, bool random = true)
|
||||
void compare_bdc_jacobi(const MatrixType& a = MatrixType(), unsigned int computationOptions = 0, int algoswap = 16, bool random = true)
|
||||
{
|
||||
MatrixType m = random ? MatrixType::Random(a.rows(), a.cols()) : a;
|
||||
|
||||
BDCSVD<MatrixType> bdc_svd(m.rows(), m.cols());
|
||||
BDCSVD<MatrixType> bdc_svd(m.rows(), m.cols(), computationOptions);
|
||||
bdc_svd.setSwitchSize(algoswap);
|
||||
bdc_svd.compute(m);
|
||||
|
||||
|
||||
JacobiSVD<MatrixType> jacobi_svd(m);
|
||||
VERIFY_IS_APPROX(bdc_svd.singularValues(), jacobi_svd.singularValues());
|
||||
|
||||
if(computationOptions & ComputeFullU) VERIFY_IS_APPROX(bdc_svd.matrixU(), jacobi_svd.matrixU());
|
||||
if(computationOptions & ComputeThinU) VERIFY_IS_APPROX(bdc_svd.matrixU(), jacobi_svd.matrixU());
|
||||
if(computationOptions & ComputeFullV) VERIFY_IS_APPROX(bdc_svd.matrixV(), jacobi_svd.matrixV());
|
||||
if(computationOptions & ComputeThinV) VERIFY_IS_APPROX(bdc_svd.matrixV(), jacobi_svd.matrixV());
|
||||
}
|
||||
|
||||
// Verifies total deflation is **not** triggered.
|
||||
@@ -71,59 +91,41 @@ void compare_bdc_jacobi_instance(bool structure_as_m, int algoswap = 16)
|
||||
-20.794, 8.68496, -4.83103,
|
||||
-8.4981, -10.5451, 23.9072;
|
||||
}
|
||||
compare_bdc_jacobi(m, algoswap, false);
|
||||
}
|
||||
|
||||
template<typename MatrixType>
|
||||
void bdcsvd_all_options(const MatrixType& input = MatrixType())
|
||||
{
|
||||
MatrixType m = input;
|
||||
svd_fill_random(m);
|
||||
svd_option_checks<MatrixType, 0>(m);
|
||||
compare_bdc_jacobi(m, 0, algoswap, false);
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(bdcsvd)
|
||||
{
|
||||
CALL_SUBTEST_3(( svd_verify_assert<Matrix3f>() ));
|
||||
CALL_SUBTEST_4(( svd_verify_assert<Matrix4d>() ));
|
||||
CALL_SUBTEST_7(( svd_verify_assert<Matrix<float, 30, 21> >() ));
|
||||
CALL_SUBTEST_7(( svd_verify_assert<Matrix<float, 21, 30> >() ));
|
||||
CALL_SUBTEST_9(( svd_verify_assert<Matrix<std::complex<double>, 20, 27> >() ));
|
||||
CALL_SUBTEST_3(( svd_verify_assert<BDCSVD<Matrix3f> >(Matrix3f()) ));
|
||||
CALL_SUBTEST_4(( svd_verify_assert<BDCSVD<Matrix4d> >(Matrix4d()) ));
|
||||
CALL_SUBTEST_7(( svd_verify_assert<BDCSVD<MatrixXf> >(MatrixXf(10,12)) ));
|
||||
CALL_SUBTEST_8(( svd_verify_assert<BDCSVD<MatrixXcd> >(MatrixXcd(7,5)) ));
|
||||
|
||||
CALL_SUBTEST_101(( svd_all_trivial_2x2(bdcsvd_all_options<Matrix2cd>) ));
|
||||
CALL_SUBTEST_102(( svd_all_trivial_2x2(bdcsvd_all_options<Matrix2d>) ));
|
||||
CALL_SUBTEST_101(( svd_all_trivial_2x2(bdcsvd<Matrix2cd>) ));
|
||||
CALL_SUBTEST_102(( svd_all_trivial_2x2(bdcsvd<Matrix2d>) ));
|
||||
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST_3(( bdcsvd<Matrix3f>() ));
|
||||
CALL_SUBTEST_4(( bdcsvd<Matrix4d>() ));
|
||||
CALL_SUBTEST_5(( bdcsvd<Matrix<float,3,5> >() ));
|
||||
|
||||
int r = internal::random<int>(1, EIGEN_TEST_MAX_SIZE/2),
|
||||
c = internal::random<int>(1, EIGEN_TEST_MAX_SIZE/2);
|
||||
|
||||
TEST_SET_BUT_UNUSED_VARIABLE(r)
|
||||
TEST_SET_BUT_UNUSED_VARIABLE(c)
|
||||
|
||||
CALL_SUBTEST_7(( compare_bdc_jacobi<MatrixXf>(MatrixXf(r,c)) ));
|
||||
CALL_SUBTEST_10(( compare_bdc_jacobi<MatrixXd>(MatrixXd(r,c)) ));
|
||||
CALL_SUBTEST_8(( compare_bdc_jacobi<MatrixXcd>(MatrixXcd(r,c)) ));
|
||||
CALL_SUBTEST_6(( bdcsvd(Matrix<double,Dynamic,2>(r,2)) ));
|
||||
CALL_SUBTEST_7(( bdcsvd(MatrixXf(r,c)) ));
|
||||
CALL_SUBTEST_7(( compare_bdc_jacobi(MatrixXf(r,c)) ));
|
||||
CALL_SUBTEST_10(( bdcsvd(MatrixXd(r,c)) ));
|
||||
CALL_SUBTEST_10(( compare_bdc_jacobi(MatrixXd(r,c)) ));
|
||||
CALL_SUBTEST_8(( bdcsvd(MatrixXcd(r,c)) ));
|
||||
CALL_SUBTEST_8(( compare_bdc_jacobi(MatrixXcd(r,c)) ));
|
||||
|
||||
// Test on inf/nan matrix
|
||||
CALL_SUBTEST_7( (svd_inf_nan<MatrixXf>()) );
|
||||
CALL_SUBTEST_10( (svd_inf_nan<MatrixXd>()) );
|
||||
|
||||
// Verify some computations using all combinations of the Options template parameter.
|
||||
CALL_SUBTEST_3(( bdcsvd_all_options<Matrix3f>() ));
|
||||
CALL_SUBTEST_3(( bdcsvd_all_options<Matrix<float, 2, 3> >() ));
|
||||
CALL_SUBTEST_4(( bdcsvd_all_options<Matrix<double, 20, 17> >() ));
|
||||
CALL_SUBTEST_4(( bdcsvd_all_options<Matrix<double, 17, 20> >() ));
|
||||
CALL_SUBTEST_5(( bdcsvd_all_options<Matrix<double, Dynamic, 30> >(Matrix<double, Dynamic, 30>(r, 30)) ));
|
||||
CALL_SUBTEST_5(( bdcsvd_all_options<Matrix<double, 20, Dynamic> >(Matrix<double, 20, Dynamic>(20, c)) ));
|
||||
CALL_SUBTEST_7(( bdcsvd_all_options<MatrixXf>(MatrixXf(r, c)) ));
|
||||
CALL_SUBTEST_8(( bdcsvd_all_options<MatrixXcd>(MatrixXcd(r, c)) ));
|
||||
CALL_SUBTEST_10(( bdcsvd_all_options<MatrixXd>(MatrixXd(r, c)) ));
|
||||
CALL_SUBTEST_14(( bdcsvd_all_options<Matrix<double, 20, 27, RowMajor>>() ));
|
||||
CALL_SUBTEST_14(( bdcsvd_all_options<Matrix<double, 27, 20, RowMajor>>() ));
|
||||
|
||||
CALL_SUBTEST_15(( svd_check_max_size_matrix<Matrix<float, Dynamic, Dynamic, ColMajor, 20, 35>, ColPivHouseholderQRPreconditioner>(r, c) ));
|
||||
CALL_SUBTEST_15(( svd_check_max_size_matrix<Matrix<float, Dynamic, Dynamic, ColMajor, 35, 20>, HouseholderQRPreconditioner>(r, c) ));
|
||||
CALL_SUBTEST_15(( svd_check_max_size_matrix<Matrix<float, Dynamic, Dynamic, RowMajor, 20, 35>, ColPivHouseholderQRPreconditioner>(r, c) ));
|
||||
CALL_SUBTEST_15(( svd_check_max_size_matrix<Matrix<float, Dynamic, Dynamic, RowMajor, 35, 20>, HouseholderQRPreconditioner>(r, c) ));
|
||||
CALL_SUBTEST_7( (svd_inf_nan<BDCSVD<MatrixXf>, MatrixXf>()) );
|
||||
CALL_SUBTEST_10( (svd_inf_nan<BDCSVD<MatrixXd>, MatrixXd>()) );
|
||||
}
|
||||
|
||||
// test matrixbase method
|
||||
|
||||
Reference in New Issue
Block a user