Singular value decomposition of a rectangular matrix. The algorithm calculates the singular value decomposition of a matrix of size MxN: A = U * S * V^T The algorithm finds the singular values and, optionally, matrices U and V^T. The algorithm can find both first min(M,N) columns of matrix U and rows of matrix V^T (singular vectors), and matrices U and V^T wholly (of sizes MxM and NxN respective
| 74 | Copyright 2005 by Bochkanov Sergey |
| 75 | *************************************************************************/ |
| 76 | bool rmatrixsvd(ap::real_2d_array a, |
| 77 | int m, |
| 78 | int n, |
| 79 | int uneeded, |
| 80 | int vtneeded, |
| 81 | int additionalmemory, |
| 82 | ap::real_1d_array& w, |
| 83 | ap::real_2d_array& u, |
| 84 | ap::real_2d_array& vt) |
| 85 | { |
| 86 | bool result; |
| 87 | ap::real_1d_array tauq; |
| 88 | ap::real_1d_array taup; |
| 89 | ap::real_1d_array tau; |
| 90 | ap::real_1d_array e; |
| 91 | ap::real_1d_array work; |
| 92 | ap::real_2d_array t2; |
| 93 | bool isupper; |
| 94 | int minmn; |
| 95 | int ncu; |
| 96 | int nrvt; |
| 97 | int nru; |
| 98 | int ncvt; |
| 99 | int i; |
| 100 | int j; |
| 101 | |
| 102 | result = true; |
| 103 | if( m==0||n==0 ) |
| 104 | { |
| 105 | return result; |
| 106 | } |
| 107 | ap::ap_error::make_assertion(uneeded>=0&&uneeded<=2, "SVDDecomposition: wrong parameters!"); |
| 108 | ap::ap_error::make_assertion(vtneeded>=0&&vtneeded<=2, "SVDDecomposition: wrong parameters!"); |
| 109 | ap::ap_error::make_assertion(additionalmemory>=0&&additionalmemory<=2, "SVDDecomposition: wrong parameters!"); |
| 110 | |
| 111 | // |
| 112 | // initialize |
| 113 | // |
| 114 | minmn = ap::minint(m, n); |
| 115 | w.setbounds(1, minmn); |
| 116 | ncu = 0; |
| 117 | nru = 0; |
| 118 | if( uneeded==1 ) |
| 119 | { |
| 120 | nru = m; |
| 121 | ncu = minmn; |
| 122 | u.setbounds(0, nru-1, 0, ncu-1); |
| 123 | } |
| 124 | if( uneeded==2 ) |
| 125 | { |
| 126 | nru = m; |
| 127 | ncu = m; |
| 128 | u.setbounds(0, nru-1, 0, ncu-1); |
| 129 | } |
| 130 | nrvt = 0; |
| 131 | ncvt = 0; |
| 132 | if( vtneeded==1 ) |
| 133 | { |
no test coverage detected