00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "svd_common.h"
00014 #include <iostream>
00015 #include <Eigen/LU>
00016
00017
00018 template<typename MatrixType>
00019 void bdcsvd_check_full(const MatrixType& m, const BDCSVD<MatrixType>& svd)
00020 {
00021 svd_check_full< MatrixType, BDCSVD< MatrixType > >(m, svd);
00022 }
00023
00024
00025 template<typename MatrixType>
00026 void bdcsvd_compare_to_full(const MatrixType& m,
00027 unsigned int computationOptions,
00028 const BDCSVD<MatrixType>& referenceSvd)
00029 {
00030 svd_compare_to_full< MatrixType, BDCSVD< MatrixType > >(m, computationOptions, referenceSvd);
00031 }
00032
00033
00034 template<typename MatrixType>
00035 void bdcsvd_solve(const MatrixType& m, unsigned int computationOptions)
00036 {
00037 svd_solve< MatrixType, BDCSVD< MatrixType > >(m, computationOptions);
00038 }
00039
00040
00041
00042 template<typename MatrixType>
00043 void bdcsvd_test_all_computation_options(const MatrixType& m)
00044 {
00045 BDCSVD<MatrixType> fullSvd(m, ComputeFullU|ComputeFullV);
00046 svd_test_computation_options_1< MatrixType, BDCSVD< MatrixType > >(m, fullSvd);
00047 svd_test_computation_options_2< MatrixType, BDCSVD< MatrixType > >(m, fullSvd);
00048 }
00049
00050
00051
00052 template<typename MatrixType>
00053 void bdcsvd(const MatrixType& a = MatrixType(), bool pickrandom = true)
00054 {
00055 MatrixType m = pickrandom ? MatrixType::Random(a.rows(), a.cols()) : a;
00056 bdcsvd_test_all_computation_options<MatrixType>(m);
00057 }
00058
00059
00060
00061 template<typename MatrixType>
00062 void bdcsvd_verify_assert(const MatrixType& m)
00063 {
00064 svd_verify_assert< MatrixType, BDCSVD< MatrixType > >(m);
00065 }
00066
00067
00068
00069 template<typename MatrixType>
00070 void bdcsvd_inf_nan()
00071 {
00072 svd_inf_nan< MatrixType, BDCSVD< MatrixType > >();
00073 }
00074
00075
00076
00077 void bdcsvd_preallocate()
00078 {
00079 svd_preallocate< BDCSVD< MatrixXf > >();
00080 }
00081
00082
00083
00084 template<typename MatrixType>
00085 void compare_bdc_jacobi(const MatrixType& a = MatrixType(), unsigned int computationOptions = 0)
00086 {
00087 std::cout << "debut compare" << std::endl;
00088 MatrixType m = MatrixType::Random(a.rows(), a.cols());
00089 BDCSVD<MatrixType> bdc_svd(m);
00090 JacobiSVD<MatrixType> jacobi_svd(m);
00091 VERIFY_IS_APPROX(bdc_svd.singularValues(), jacobi_svd.singularValues());
00092 if(computationOptions & ComputeFullU)
00093 VERIFY_IS_APPROX(bdc_svd.matrixU(), jacobi_svd.matrixU());
00094 if(computationOptions & ComputeThinU)
00095 VERIFY_IS_APPROX(bdc_svd.matrixU(), jacobi_svd.matrixU());
00096 if(computationOptions & ComputeFullV)
00097 VERIFY_IS_APPROX(bdc_svd.matrixV(), jacobi_svd.matrixV());
00098 if(computationOptions & ComputeThinV)
00099 VERIFY_IS_APPROX(bdc_svd.matrixV(), jacobi_svd.matrixV());
00100 std::cout << "fin compare" << std::endl;
00101 }
00102
00103
00104
00105 void test_bdcsvd()
00106 {
00107
00108 CALL_SUBTEST_11(( bdcsvd_verify_assert<Matrix<float,Dynamic,Dynamic> >
00109 (Matrix<float,Dynamic,Dynamic>(42,42)) ));
00110 CALL_SUBTEST_11(( compare_bdc_jacobi<Matrix<float,Dynamic,Dynamic> >
00111 (Matrix<float,Dynamic,Dynamic>(42,42), 0) ));
00112 CALL_SUBTEST_11(( bdcsvd<Matrix<float,Dynamic,Dynamic> >
00113 (Matrix<float,Dynamic,Dynamic>(42,42)) ));
00114
00115
00116 CALL_SUBTEST_13(( bdcsvd_verify_assert<Matrix<double,Dynamic,Dynamic> >
00117 (Matrix<double,Dynamic,Dynamic>(50,50)) ));
00118 CALL_SUBTEST_13(( compare_bdc_jacobi<Matrix<double,Dynamic,Dynamic> >
00119 (Matrix<double,Dynamic,Dynamic>(50,50), 0) ));
00120 CALL_SUBTEST_13(( bdcsvd<Matrix<double,Dynamic,Dynamic> >
00121 (Matrix<double,Dynamic,Dynamic>(50, 50)) ));
00122
00123
00124 CALL_SUBTEST_14(( bdcsvd_verify_assert<Matrix<std::complex<double>,Dynamic,Dynamic> >
00125 (Matrix<std::complex<double>,Dynamic,Dynamic>(22,22)) ));
00126 CALL_SUBTEST_14(( compare_bdc_jacobi<Matrix<std::complex<double>,Dynamic,Dynamic> >
00127 (Matrix<std::complex<double>, Dynamic, Dynamic> (22,22), 0) ));
00128 CALL_SUBTEST_14(( bdcsvd<Matrix<std::complex<double>,Dynamic,Dynamic> >
00129 (Matrix<std::complex<double>,Dynamic,Dynamic>(22, 22)) ));
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 CALL_SUBTEST_16(( bdcsvd_verify_assert<Matrix<double,Dynamic,Dynamic> >
00143 (Matrix<double,Dynamic,Dynamic>(8,6)) ));
00144 CALL_SUBTEST_16(( compare_bdc_jacobi<Matrix<double,Dynamic,Dynamic> >
00145 (Matrix<double,Dynamic,Dynamic>(8, 6), 0) ));
00146 CALL_SUBTEST_16(( bdcsvd<Matrix<double,Dynamic,Dynamic> >
00147 (Matrix<double,Dynamic,Dynamic>(8, 6)) ));
00148
00149
00150
00151
00152 CALL_SUBTEST_17(( compare_bdc_jacobi<Matrix<float,Dynamic,Dynamic> >
00153 (Matrix<float,Dynamic,Dynamic>(36, 12), 0) ));
00154 CALL_SUBTEST_17(( bdcsvd<Matrix<float,Dynamic,Dynamic> >
00155 (Matrix<float,Dynamic,Dynamic>(36, 12)) ));
00156
00157
00158 CALL_SUBTEST_18(( compare_bdc_jacobi<Matrix<double,Dynamic,Dynamic> >
00159 (Matrix<double,Dynamic,Dynamic>(5, 8), 0) ));
00160 CALL_SUBTEST_18(( bdcsvd<Matrix<double,Dynamic,Dynamic> >
00161 (Matrix<double,Dynamic,Dynamic>(5, 8)) ));
00162
00163
00164
00165 CALL_SUBTEST_3(( bdcsvd_verify_assert(Matrix3f()) ));
00166 CALL_SUBTEST_4(( bdcsvd_verify_assert(Matrix4d()) ));
00167 CALL_SUBTEST_7(( bdcsvd_verify_assert(MatrixXf(10,12)) ));
00168 CALL_SUBTEST_8(( bdcsvd_verify_assert(MatrixXcd(7,5)) ));
00169
00170
00171 for(int i = 0; i < g_repeat; i++) {
00172 Matrix2cd m;
00173 m << 0, 1,
00174 0, 1;
00175 CALL_SUBTEST_1(( bdcsvd(m, false) ));
00176 m << 1, 0,
00177 1, 0;
00178 CALL_SUBTEST_1(( bdcsvd(m, false) ));
00179
00180 Matrix2d n;
00181 n << 0, 0,
00182 0, 0;
00183 CALL_SUBTEST_2(( bdcsvd(n, false) ));
00184 n << 0, 0,
00185 0, 1;
00186 CALL_SUBTEST_2(( bdcsvd(n, false) ));
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 int r = internal::random<int>(1, 30),
00197 c = internal::random<int>(1, 30);
00198 CALL_SUBTEST_7(( bdcsvd<MatrixXf>(MatrixXf(r,c)) ));
00199 CALL_SUBTEST_8(( bdcsvd<MatrixXcd>(MatrixXcd(r,c)) ));
00200 (void) r;
00201 (void) c;
00202
00203
00204 CALL_SUBTEST_7( bdcsvd_inf_nan<MatrixXf>() );
00205 }
00206
00207 CALL_SUBTEST_7(( bdcsvd<MatrixXf>(MatrixXf(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) ));
00208 CALL_SUBTEST_8(( bdcsvd<MatrixXcd>(MatrixXcd(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/3), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/3))) ));
00209
00210
00211 CALL_SUBTEST_7( BDCSVD<MatrixXf>(10,10) );
00212
00213 }