Changeset 998

Show
Ignore:
Timestamp:
05/26/10 23:33:49 (14 years ago)
Author:
smidl
Message:

test of permutations in matrices

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/testsuite/square_mat_test.cpp

    r766 r998  
    2020        mat A = A0 * A0.T(); 
    2121 
     22        // ----------- SIZES --------- 
    2223        TMatrix sq_mat ( A ); 
    2324        CHECK_EQUAL ( sz, sq_mat.rows() ); 
    2425        CHECK_EQUAL ( sz, sq_mat.cols() ); 
    2526 
     27        // ----------- FULL MAT --------- 
    2628        mat res = sq_mat.to_mat(); 
    2729        CHECK_CLOSE ( A, res, epsilon ); 
    2830 
     31        // ----------- OUTER PRODUCT UPDATE --------- 
    2932        vec v = randu ( sz ); 
    3033        double w = randu(); 
     
    3538        CHECK_CLOSE ( res, sq_mat2.to_mat(), epsilon ); 
    3639 
     40        // ----------- INVERSION --------- 
    3741        TMatrix invmat ( sz ); 
    3842        sq_mat.inv ( invmat ); 
     
    4044        CHECK_CLOSE ( invA, invmat.to_mat(), epsilon ); 
    4145 
     46        // ----------- DETERMINANT --------- 
    4247        double d = det ( A ); 
    4348        CHECK_CLOSE ( log ( d ), sq_mat.logdet(), epsilon ); 
    4449 
     50        // ----------- QUADRATIC FORM --------- 
    4551        double q = sq_mat.qform ( ones ( sz ) ); 
    4652        CHECK_CLOSE ( sumsum ( A ), q, epsilon ); 
     
    5864        CHECK_EQUAL ( 0, sq_mat2.qform ( ones ( sz ) ) ); 
    5965 
     66        // ----------- + operator ---------      
    6067        TMatrix twice = sq_mat; 
    6168        twice += sq_mat; 
     
    6370        CHECK_CLOSE ( res, twice.to_mat(), epsilon ); 
    6471 
     72        // ----------- * operator ---------      
    6573        twice = sq_mat; 
    6674        twice *= 2; 
    6775        CHECK_CLOSE ( res, twice.to_mat(), epsilon ); 
    6876 
     77        // ----------- MULTIPLICATION ---------  
    6978        sq_mat2 = sq_mat; 
    7079        mat B = randu ( sz, sz ); 
     
    8392        res = ( B.T() * A ) * B; 
    8493        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); 
    85108} 
    86109