xref: /aosp_15_r20/external/eigen/test/upperbidiagonalization.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2010 Benoit Jacob <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li 
10*bf2c3715SXin Li #include "main.h"
11*bf2c3715SXin Li #include <Eigen/SVD>
12*bf2c3715SXin Li 
upperbidiag(const MatrixType & m)13*bf2c3715SXin Li template<typename MatrixType> void upperbidiag(const MatrixType& m)
14*bf2c3715SXin Li {
15*bf2c3715SXin Li   const Index rows = m.rows();
16*bf2c3715SXin Li   const Index cols = m.cols();
17*bf2c3715SXin Li 
18*bf2c3715SXin Li   typedef Matrix<typename MatrixType::RealScalar, MatrixType::RowsAtCompileTime,  MatrixType::ColsAtCompileTime> RealMatrixType;
19*bf2c3715SXin Li   typedef Matrix<typename MatrixType::Scalar, MatrixType::ColsAtCompileTime,  MatrixType::RowsAtCompileTime> TransposeMatrixType;
20*bf2c3715SXin Li 
21*bf2c3715SXin Li   MatrixType a = MatrixType::Random(rows,cols);
22*bf2c3715SXin Li   internal::UpperBidiagonalization<MatrixType> ubd(a);
23*bf2c3715SXin Li   RealMatrixType b(rows, cols);
24*bf2c3715SXin Li   b.setZero();
25*bf2c3715SXin Li   b.block(0,0,cols,cols) = ubd.bidiagonal();
26*bf2c3715SXin Li   MatrixType c = ubd.householderU() * b * ubd.householderV().adjoint();
27*bf2c3715SXin Li   VERIFY_IS_APPROX(a,c);
28*bf2c3715SXin Li   TransposeMatrixType d = ubd.householderV() * b.adjoint() * ubd.householderU().adjoint();
29*bf2c3715SXin Li   VERIFY_IS_APPROX(a.adjoint(),d);
30*bf2c3715SXin Li }
31*bf2c3715SXin Li 
EIGEN_DECLARE_TEST(upperbidiagonalization)32*bf2c3715SXin Li EIGEN_DECLARE_TEST(upperbidiagonalization)
33*bf2c3715SXin Li {
34*bf2c3715SXin Li   for(int i = 0; i < g_repeat; i++) {
35*bf2c3715SXin Li    CALL_SUBTEST_1( upperbidiag(MatrixXf(3,3)) );
36*bf2c3715SXin Li    CALL_SUBTEST_2( upperbidiag(MatrixXd(17,12)) );
37*bf2c3715SXin Li    CALL_SUBTEST_3( upperbidiag(MatrixXcf(20,20)) );
38*bf2c3715SXin Li    CALL_SUBTEST_4( upperbidiag(Matrix<std::complex<double>,Dynamic,Dynamic,RowMajor>(16,15)) );
39*bf2c3715SXin Li    CALL_SUBTEST_5( upperbidiag(Matrix<float,6,4>()) );
40*bf2c3715SXin Li    CALL_SUBTEST_6( upperbidiag(Matrix<float,5,5>()) );
41*bf2c3715SXin Li    CALL_SUBTEST_7( upperbidiag(Matrix<double,4,3>()) );
42*bf2c3715SXin Li   }
43*bf2c3715SXin Li }
44