Changeset 467
- Timestamp:
- 08/03/09 16:22:41 (15 years ago)
- Location:
- library/tests
- Files:
-
- 8 added
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/CMakeLists.txt
r462 r467 12 12 add_executable(square_mat_stress square_mat_stress.cpp) 13 13 target_link_libraries(square_mat_stress bdm itpp testutil unittest) 14 15 add_executable(square_mat_prep additive_generator.cpp additive_generator.h generator.cpp generator.h size_generator.cpp size_generator.h square_mat_prep.cpp) 16 target_link_libraries(square_mat_prep bdm itpp testutil) 14 17 15 18 EXEC(emix_test) -
library/tests/square_mat_stress.cpp
r456 r467 1 1 #include "../bdm/math/square_mat.h" 2 2 #include "../bdm/math/chmat.h" 3 #include "base/user_info.h" 3 4 #include "UnitTest++.h" 4 5 #include "TestReporterStdout.h" … … 12 13 using std::endl; 13 14 15 using bdm::UIFile; 16 using bdm::UI; 17 18 const char *agenda_file_name = "agenda.cfg"; 14 19 double epsilon = 0.00001; 15 16 20 bool fast = false; 17 21 … … 41 45 42 46 template<typename TMatrix> 43 void test_ until_overflow() {47 void test_matrix(int index, const mat &A) { 44 48 Real_Timer tt; 45 int sz = 7;46 while (true) {47 mat A0 = randu(sz, sz);48 mat A = A0 * A0.T();49 49 50 tt.tic(); 51 TMatrix sqmat(A); 52 double elapsed = tt.toc(); 53 cout << "ctor(" << sz << " x " << sz << "): " << elapsed << " s" << endl; 50 cout << "agenda[" << index << ']' << endl; 51 int sz = A.rows(); 52 CHECK_EQUAL(A.cols(), sz); 54 53 55 tt.tic(); 56 mat res = sqmat.to_mat(); 57 elapsed = tt.toc(); 54 tt.tic(); 55 TMatrix sqmat(A); 56 double elapsed = tt.toc(); 57 cout << "ctor(" << sz << " x " << sz << "): " << elapsed << " s" << endl; 58 58 59 if (!fast) { 60 CHECK_CLOSE(A, res, epsilon);61 } 59 tt.tic(); 60 mat res = sqmat.to_mat(); 61 elapsed = tt.toc(); 62 62 63 cout << "to_mat: " << elapsed << " s" << endl; 63 if (!fast) { 64 CHECK_CLOSE(A, res, epsilon); 65 } 64 66 65 vec v = randu(sz); 66 double w = randu(); 67 TMatrix sqmat2 = sqmat; 67 cout << "to_mat: " << elapsed << " s" << endl; 68 69 vec v = randu(sz); 70 double w = randu(); 71 TMatrix sqmat2 = sqmat; 68 72 69 70 71 73 tt.tic(); 74 sqmat2.opupdt(v, w); 75 elapsed = tt.toc(); 72 76 73 74 75 76 77 if (!fast) { 78 mat expA = A + w * outer_product(v, v); 79 CHECK_CLOSE(expA, sqmat2.to_mat(), epsilon); 80 } 77 81 78 82 cout << "opupdt: " << elapsed << " s" << endl; 79 83 80 84 TMatrix invmat(sz); 81 85 82 83 84 86 tt.tic(); 87 sqmat.inv(invmat); 88 elapsed = tt.toc(); 85 89 86 87 88 89 90 if (!fast) { 91 mat invA = inv(A); 92 CHECK_CLOSE(invA, invmat.to_mat(), epsilon); 93 } 90 94 91 95 cout << "inv: " << elapsed << " s" << endl; 92 96 93 sz *= 7; 97 tt.tic(); 98 double ld = sqmat.logdet(); 99 elapsed = tt.toc(); 100 101 if (!fast) { 102 double d = det(A); 103 CHECK_CLOSE(log(d), ld, epsilon); 104 } 105 106 cout << "logdet: " << elapsed << " s" << endl; 107 } 108 109 template<typename TMatrix> 110 void test_agenda() { 111 UIFile fag(agenda_file_name); 112 Array<mat> mag; 113 UI::get(mag, fag, "agenda"); 114 int sz = mag.size(); 115 CHECK(sz > 0); 116 for (int i = 0; i < sz; ++i) { 117 test_matrix<TMatrix>(i, mag(i)); 94 118 } 95 119 } … … 97 121 SUITE(ldmat) { 98 122 TEST(cycle) { 99 test_ until_overflow<ldmat>();123 test_agenda<ldmat>(); 100 124 } 101 125 } … … 103 127 SUITE(fsqmat) { 104 128 TEST(cycle) { 105 test_ until_overflow<fsqmat>();129 test_agenda<fsqmat>(); 106 130 } 107 131 } … … 109 133 SUITE(chmat) { 110 134 TEST(cycle) { 111 test_ until_overflow<chmat>();135 test_agenda<chmat>(); 112 136 } 113 137 } … … 115 139 int main(int argc, char const *argv[]) { 116 140 bool unknown = false; 117 int update_next = 0; // 1 suite, 2 epsilon 141 int update_next = 0; // 1 suite, 2 epsilon, 3 agenda file 118 142 const char *suite = "ldmat"; 119 143 const char **param = argv + 1; … … 122 146 if (update_next == 1) { 123 147 suite = *param; 124 } else {148 } else if (update_next == 2) { 125 149 double eps = atof(*param); 126 150 if (eps > 0) { … … 129 153 cerr << "invalid epsilon value ignored" << endl; 130 154 } 155 } else { 156 agenda_file_name = *param; 131 157 } 132 158