Changeset 998 for library/tests/testsuite
- Timestamp:
- 05/26/10 23:33:49 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/testsuite/square_mat_test.cpp
r766 r998 20 20 mat A = A0 * A0.T(); 21 21 22 // ----------- SIZES --------- 22 23 TMatrix sq_mat ( A ); 23 24 CHECK_EQUAL ( sz, sq_mat.rows() ); 24 25 CHECK_EQUAL ( sz, sq_mat.cols() ); 25 26 27 // ----------- FULL MAT --------- 26 28 mat res = sq_mat.to_mat(); 27 29 CHECK_CLOSE ( A, res, epsilon ); 28 30 31 // ----------- OUTER PRODUCT UPDATE --------- 29 32 vec v = randu ( sz ); 30 33 double w = randu(); … … 35 38 CHECK_CLOSE ( res, sq_mat2.to_mat(), epsilon ); 36 39 40 // ----------- INVERSION --------- 37 41 TMatrix invmat ( sz ); 38 42 sq_mat.inv ( invmat ); … … 40 44 CHECK_CLOSE ( invA, invmat.to_mat(), epsilon ); 41 45 46 // ----------- DETERMINANT --------- 42 47 double d = det ( A ); 43 48 CHECK_CLOSE ( log ( d ), sq_mat.logdet(), epsilon ); 44 49 50 // ----------- QUADRATIC FORM --------- 45 51 double q = sq_mat.qform ( ones ( sz ) ); 46 52 CHECK_CLOSE ( sumsum ( A ), q, epsilon ); … … 58 64 CHECK_EQUAL ( 0, sq_mat2.qform ( ones ( sz ) ) ); 59 65 66 // ----------- + operator --------- 60 67 TMatrix twice = sq_mat; 61 68 twice += sq_mat; … … 63 70 CHECK_CLOSE ( res, twice.to_mat(), epsilon ); 64 71 72 // ----------- * operator --------- 65 73 twice = sq_mat; 66 74 twice *= 2; 67 75 CHECK_CLOSE ( res, twice.to_mat(), epsilon ); 68 76 77 // ----------- MULTIPLICATION --------- 69 78 sq_mat2 = sq_mat; 70 79 mat B = randu ( sz, sz ); … … 83 92 res = ( B.T() * A ) * B; 84 93 CHECK_CLOSE ( res, sq_mat2.to_mat(), epsilon ); 94 95 // ----------- PERMUTATION --------- 96 mat M1 = randu (sz,sz); 97 mat M = M1*M1.T(); 98 vec perm_v_rand = randu(sz); 99 ivec perm_v_ids = sort_index(perm_v_rand); 100 101 mat Mperm_c=M.get_cols(perm_v_ids); 102 mat Mperm=Mperm_c.get_rows(perm_v_ids); 103 104 TMatrix T(M); 105 TMatrix Tperm(T,perm_v_ids); 106 107 CHECK_CLOSE(Tperm.to_mat(), Mperm, epsilon); 85 108 } 86 109