Show
Ignore:
Timestamp:
08/04/09 08:29:50 (15 years ago)
Author:
vbarta
Message:

added supplementary random test data to agenda

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/square_mat_stress.cpp

    r467 r468  
    22#include "../bdm/math/chmat.h" 
    33#include "base/user_info.h" 
     4#include "square_mat_point.h" 
    45#include "UnitTest++.h" 
    56#include "TestReporterStdout.h" 
     
    1920double epsilon = 0.00001; 
    2021bool fast = false; 
     22 
     23namespace bdm { 
     24UIREGISTER(square_mat_point); 
     25} 
    2126 
    2227namespace UnitTest 
     
    4449} 
    4550 
     51typedef void (*FTestMatrix)(int, square_mat_point *); 
     52 
    4653template<typename TMatrix> 
    47 void test_matrix(int index, const mat &A) { 
     54void test_matrix(int index, square_mat_point *point) { 
    4855    Real_Timer tt; 
    4956         
    50     cout << "agenda[" << index << ']' << endl; 
     57    cout << "agenda[" << index << "]:" << endl; 
     58    mat A = point->get_matrix(); 
    5159    int sz = A.rows(); 
    5260    CHECK_EQUAL(A.cols(), sz); 
     
    6775    cout << "to_mat: " << elapsed << " s" << endl; 
    6876 
    69     vec v = randu(sz); 
    70     double w = randu(); 
     77    vec v = point->get_vector(); 
     78    double w = point->get_scalar(); 
    7179    TMatrix sqmat2 = sqmat; 
    7280         
     
    8896    elapsed = tt.toc(); 
    8997 
    90     if (!fast) { 
    91         mat invA = inv(A); 
     98    mat invA; 
     99    if (!fast) { 
     100        invA = inv(A); 
    92101        CHECK_CLOSE(invA, invmat.to_mat(), epsilon); 
    93102    } 
     
    105114 
    106115    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 
     176void test_agenda(FTestMatrix test) { 
    111177    UIFile fag(agenda_file_name); 
    112     Array<mat> mag; 
     178    Array<square_mat_point *> mag; 
    113179    UI::get(mag, fag, "agenda"); 
    114180    int sz = mag.size(); 
    115181    CHECK(sz > 0); 
    116182    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; 
    118190    } 
    119191} 
    120192 
    121193SUITE(ldmat) { 
    122     TEST(cycle) { 
    123         test_agenda<ldmat>(); 
     194    TEST(agenda) { 
     195        test_agenda(test_matrix<ldmat>); 
    124196    } 
    125197} 
    126198 
    127199SUITE(fsqmat) { 
    128     TEST(cycle) { 
    129         test_agenda<fsqmat>(); 
     200    TEST(agenda) { 
     201        test_agenda(test_matrix<fsqmat>); 
    130202    } 
    131203} 
    132204 
    133205SUITE(chmat) { 
    134     TEST(cycle) { 
    135         test_agenda<chmat>(); 
     206    TEST(agenda) { 
     207        test_agenda(test_matrix<chmat>); 
    136208    } 
    137209} 
     
    159231            update_next = 0; 
    160232        } else { 
    161             if (!strcmp(*param, "-c")) { 
     233            if (!strcmp(*param, "-a")) { 
     234                update_next = 3; 
     235            } else if (!strcmp(*param, "-c")) { 
    162236                update_next = 1; 
    163237            } else if (!strcmp(*param, "-e")) { 
     
    174248 
    175249    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; 
    177251    } else { 
    178252        UnitTest::TestReporterStdout reporter;