Changeset 468
- Timestamp:
- 08/04/09 08:29:50 (15 years ago)
- Location:
- library/tests
- Files:
-
- 2 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/CMakeLists.txt
r467 r468 7 7 link_directories (./unittest-cpp) 8 8 9 add_library(testutil egiw_harness.cpp egiw_harness.h epdf_harness.cpp epdf_harness.h mat_checks.cpp mat_checks.h mpdf_harness.cpp mpdf_harness.h test_util.cpp test_util.h)9 add_library(testutil egiw_harness.cpp egiw_harness.h epdf_harness.cpp epdf_harness.h mat_checks.cpp mat_checks.h mpdf_harness.cpp mpdf_harness.h square_mat_point.cpp square_mat_point.h test_util.cpp test_util.h) 10 10 target_link_libraries(testutil bdm itpp unittest) 11 11 -
library/tests/square_mat_prep.cpp
r467 r468 4 4 #include "additive_generator.h" 5 5 #include "size_generator.h" 6 #include "square_mat_point.h" 6 7 #include <iostream> 7 8 #include <iomanip> … … 15 16 UIREGISTER(size_generator); 16 17 UIREGISTER(additive_generator); 18 UIREGISTER(square_mat_point); 17 19 18 20 const char *generator_file_name = "generator.cfg"; … … 60 62 cerr << "usage: " << argv[0] << " [ -g generator.cfg ] [ -a agenda_output.cfg ] [ -l agenda_length ]" << endl; 61 63 } else { 62 Array< mat> mag(agenda_length);64 Array<square_mat_point *> mag(agenda_length); 63 65 64 66 UIFile gspec(generator_file_name); 65 67 auto_ptr<generator> gen(UI::build<generator>(gspec, "generator")); 66 68 for (int i = 0; i < agenda_length; ++i) { 67 mag(i) = gen->next(); 69 mat m = gen->next(); 70 square_mat_point *p = new square_mat_point(); 71 p->set_parameters(m, randu(m.rows()), randu()); 72 mag(i) = p; 68 73 } 69 74 … … 71 76 UI::save(mag, fag, "agenda"); 72 77 fag.save(agenda_file_name); 78 79 for (int i = 0; i < agenda_length; ++i) { 80 square_mat_point *p = mag(i); 81 mag(i) = 0; 82 delete p; 83 } 73 84 } 74 85 } -
library/tests/square_mat_stress.cpp
r467 r468 2 2 #include "../bdm/math/chmat.h" 3 3 #include "base/user_info.h" 4 #include "square_mat_point.h" 4 5 #include "UnitTest++.h" 5 6 #include "TestReporterStdout.h" … … 19 20 double epsilon = 0.00001; 20 21 bool fast = false; 22 23 namespace bdm { 24 UIREGISTER(square_mat_point); 25 } 21 26 22 27 namespace UnitTest … … 44 49 } 45 50 51 typedef void (*FTestMatrix)(int, square_mat_point *); 52 46 53 template<typename TMatrix> 47 void test_matrix(int index, const mat &A) {54 void test_matrix(int index, square_mat_point *point) { 48 55 Real_Timer tt; 49 56 50 cout << "agenda[" << index << ']' << endl; 57 cout << "agenda[" << index << "]:" << endl; 58 mat A = point->get_matrix(); 51 59 int sz = A.rows(); 52 60 CHECK_EQUAL(A.cols(), sz); … … 67 75 cout << "to_mat: " << elapsed << " s" << endl; 68 76 69 vec v = randu(sz);70 double w = randu();77 vec v = point->get_vector(); 78 double w = point->get_scalar(); 71 79 TMatrix sqmat2 = sqmat; 72 80 … … 88 96 elapsed = tt.toc(); 89 97 90 if (!fast) { 91 mat invA = inv(A); 98 mat invA; 99 if (!fast) { 100 invA = inv(A); 92 101 CHECK_CLOSE(invA, invmat.to_mat(), epsilon); 93 102 } … … 105 114 106 115 cout << "logdet: " << elapsed << " s" << endl; 107 } 108 109 template<typename TMatrix> 110 void test_agenda() { 116 117 tt.tic(); 118 double q = sqmat.qform(ones(sz)); 119 elapsed = tt.toc(); 120 121 if (!fast) { 122 CHECK_CLOSE(sumsum(A), q, epsilon); 123 } 124 125 cout << "qform(1): " << elapsed << " s" << endl; 126 127 tt.tic(); 128 q = sqmat.qform(v); 129 elapsed = tt.toc(); 130 131 if (!fast) { 132 double r = (A * v) * v; 133 CHECK_CLOSE(r, q, epsilon); 134 } 135 136 cout << "qform(v): " << elapsed << " s" << endl; 137 138 tt.tic(); 139 q = sqmat.invqform(v); 140 elapsed = tt.toc(); 141 142 if (!fast) { 143 double r = (invA * v) * v; 144 CHECK_CLOSE(r, q, epsilon); 145 } 146 147 cout << "invqform: " << elapsed << " s" << endl; 148 149 TMatrix twice = sqmat; 150 151 tt.tic(); 152 twice += sqmat; 153 elapsed = tt.toc(); 154 155 if (!fast) { 156 res = 2 * A; 157 CHECK_CLOSE(res, twice.to_mat(), epsilon); 158 } 159 160 cout << "+=: " << elapsed << " s" << endl; 161 162 sqmat2 = sqmat; 163 164 tt.tic(); 165 sqmat2.mult_sym(A); 166 elapsed = tt.toc(); 167 168 if (!fast) { 169 res = (A * A) * A.T(); 170 CHECK_CLOSE(res, sqmat2.to_mat(), epsilon); 171 } 172 173 cout << "^2: " << elapsed << " s" << endl; 174 } 175 176 void test_agenda(FTestMatrix test) { 111 177 UIFile fag(agenda_file_name); 112 Array< mat> mag;178 Array<square_mat_point *> mag; 113 179 UI::get(mag, fag, "agenda"); 114 180 int sz = mag.size(); 115 181 CHECK(sz > 0); 116 182 for (int i = 0; i < sz; ++i) { 117 test_matrix<TMatrix>(i, mag(i)); 183 test(i, mag(i)); 184 } 185 186 for (int i = 0; i < sz; ++i) { 187 square_mat_point *p = mag(i); 188 mag(i) = 0; 189 delete p; 118 190 } 119 191 } 120 192 121 193 SUITE(ldmat) { 122 TEST( cycle) {123 test_agenda <ldmat>();194 TEST(agenda) { 195 test_agenda(test_matrix<ldmat>); 124 196 } 125 197 } 126 198 127 199 SUITE(fsqmat) { 128 TEST( cycle) {129 test_agenda <fsqmat>();200 TEST(agenda) { 201 test_agenda(test_matrix<fsqmat>); 130 202 } 131 203 } 132 204 133 205 SUITE(chmat) { 134 TEST( cycle) {135 test_agenda <chmat>();206 TEST(agenda) { 207 test_agenda(test_matrix<chmat>); 136 208 } 137 209 } … … 159 231 update_next = 0; 160 232 } else { 161 if (!strcmp(*param, "-c")) { 233 if (!strcmp(*param, "-a")) { 234 update_next = 3; 235 } else if (!strcmp(*param, "-c")) { 162 236 update_next = 1; 163 237 } else if (!strcmp(*param, "-e")) { … … 174 248 175 249 if (unknown || update_next) { 176 cerr << "usage: " << argv[0] << " [ -f ] [ -e epsilon ] [ - c class ]" << endl;250 cerr << "usage: " << argv[0] << " [ -f ] [ -e epsilon ] [ -a agenda_input.cfg ] [ -c class ]" << endl; 177 251 } else { 178 252 UnitTest::TestReporterStdout reporter;