<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>M4RI: testsuite/test_pluq.c</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.4 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">M4RI <span id="projectnumber">1.0.1</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <div class="title">testsuite/test_pluq.c</div> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <stdlib.h></span> <span class="preprocessor">#include "m4ri/m4ri.h"</span> <span class="keywordtype">int</span> test_pluq_full_rank (<span class="keywordtype">size_t</span> m, <span class="keywordtype">size_t</span> n){ printf(<span class="stringliteral">"pluq: testing full rank m: %5zu, n: %5zu"</span>,m,n); <a name="_a0"></a><a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* U = <a name="a1"></a>mzd_init (m,n); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* L = mzd_init (m,m); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* U2 = mzd_init (m,n); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* L2 = mzd_init (m,m); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* A = mzd_init (m,n); <a name="a2"></a>mzd_randomize (U); mzd_randomize (L); <span class="keywordtype">size_t</span> i,j; <span class="keywordflow">for</span> (i=0; i<m; ++i){ <span class="keywordflow">for</span> (j=0; j<i && j<n;++j) <a name="a3"></a><a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U,i,j, 0); <span class="keywordflow">for</span> (j=i+1; j<m;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L,i,j, 0); <span class="keywordflow">if</span>(i<n) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U,i,i, 1); <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L,i,i, 1); } <a name="a4"></a>mzd_mul(A, L, U, 2048); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* Acopy = <a name="a5"></a>mzd_copy (NULL,A); <a name="_a6"></a><a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* P = <a name="a7"></a>mzp_init(m); <a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* Q = mzp_init(n); <a name="a8"></a>mzd_pluq(A, P, Q, 2048); <span class="keywordflow">for</span> (i=0; i<m; ++i){ <span class="keywordflow">for</span> (j=0; j<i && j <n;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a> (L2, i, j, <a name="a9"></a><a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); <span class="keywordflow">for</span> (j=i+1; j<n;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a> (U2, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); } <span class="keywordflow">for</span> (i=0; i<n && i<m; ++i){ <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L2,i,i, 1); <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U2,i,i, 1); } <a name="a10"></a>mzd_addmul(Acopy,L2,U2,0); <span class="keywordtype">int</span> status = 0; <span class="keywordflow">for</span> ( i=0; i<m; ++i) <span class="keywordflow">for</span> ( j=0; j<n; ++j){ <span class="keywordflow">if</span> (<a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a> (Acopy,i,j)){ status = 1; } } <span class="keywordflow">if</span> (status){ printf(<span class="stringliteral">" ... FAILED\n"</span>); } <span class="keywordflow">else</span> printf (<span class="stringliteral">" ... passed\n"</span>); <a name="a11"></a>mzd_free(U); mzd_free(L); mzd_free(U2); mzd_free(L2); mzd_free(A); mzd_free(Acopy); <a name="a12"></a>mzp_free(P); mzp_free(Q); <span class="keywordflow">return</span> status; } <span class="keywordtype">int</span> test_pluq_half_rank(<span class="keywordtype">size_t</span> m, <span class="keywordtype">size_t</span> n) { printf(<span class="stringliteral">"pluq: testing half rank m: %5zd, n: %5zd"</span>,m,n); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* U = mzd_init(m, n); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* L = mzd_init(m, m); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* U2 = mzd_init(m, n); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* L2 = mzd_init(m, m); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* A = mzd_init(m, n); mzd_randomize (U); mzd_randomize (L); <span class="keywordtype">size_t</span> i,j; <span class="keywordflow">for</span> (i=0; i<m && i<n; ++i){ <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U,i,i, 1); <span class="keywordflow">for</span> (j=0; j<i;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U,i,j, 0); <span class="keywordflow">if</span> (i%2) <span class="keywordflow">for</span> (j=i; j<n;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U,i,j, 0); <span class="keywordflow">for</span> (j=i+1; j<m;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L,i,j, 0); <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L,i,i, 1); } mzd_mul(A, L, U, 0); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* Acopy = mzd_copy (NULL,A); <a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* Pt = mzp_init(m); <a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* Q = mzp_init(n); <span class="keywordtype">int</span> r = mzd_pluq(A, Pt, Q, 0); <span class="keywordflow">for</span> (i=0; i<r; ++i){ <span class="keywordflow">for</span> (j=0; j<i;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a> (L2, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); <span class="keywordflow">for</span> (j=i+1; j<n;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a> (U2, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); } <span class="keywordflow">for</span> (i=r; i<m; i++) <span class="keywordflow">for</span> (j=0; j<r;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a> (L2, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); <span class="keywordflow">for</span> (i=0; i<r; ++i){ <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L2,i,i, 1); <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U2,i,i, 1); } <a name="a13"></a>mzd_apply_p_left(Acopy, Pt); <a name="a14"></a>mzd_apply_p_right_trans(Acopy, Q); mzd_addmul(Acopy,L2,U2,0); <span class="keywordtype">int</span> status = 0; <span class="keywordflow">for</span> ( i=0; i<m; ++i) { <span class="keywordflow">for</span> ( j=0; j<n; ++j){ <span class="keywordflow">if</span> (<a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(Acopy,i,j)){ status = 1; } } <span class="keywordflow">if</span>(status) <span class="keywordflow">break</span>; } <span class="keywordflow">if</span> (status) printf(<span class="stringliteral">" ... FAILED\n"</span>); <span class="keywordflow">else</span> printf (<span class="stringliteral">" ... passed\n"</span>); mzd_free(U); mzd_free(L); mzd_free(U2); mzd_free(L2); mzd_free(A); mzd_free(Acopy); mzp_free(Pt); mzp_free(Q); <span class="keywordflow">return</span> status; } <span class="keywordtype">int</span> test_pluq_structured(<span class="keywordtype">size_t</span> m, <span class="keywordtype">size_t</span> n) { printf(<span class="stringliteral">"pluq: testing structured m: %5zd, n: %5zd"</span>, m, n); <span class="keywordtype">size_t</span> i,j; <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* A = mzd_init(m, n); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* L = mzd_init(m, m); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* U = mzd_init(m, n); <span class="keywordflow">for</span>(i=0; i<m; i+=2) <span class="keywordflow">for</span> (j=i; j<n; j++) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(A, i, j, 1); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* Acopy = mzd_copy (NULL,A); <a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* P = mzp_init(m); <a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* Q = mzp_init(n); <span class="keywordtype">int</span> r; r=mzd_pluq(A, P, Q, 0); printf(<span class="stringliteral">", rank: %5d "</span>,r); <span class="keywordflow">for</span> (i=0; i<r; ++i){ <span class="keywordflow">for</span> (j=0; j<i;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); <span class="keywordflow">for</span> (j=i+1; j<n;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); } <span class="keywordflow">for</span> (i=r; i<m; i++) <span class="keywordflow">for</span> (j=0; j<r;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); <span class="keywordflow">for</span> (i=0; i<r; ++i){ <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L,i,i, 1); <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U,i,i, 1); } mzd_apply_p_left(Acopy, P); mzd_apply_p_right_trans(Acopy, Q); mzd_addmul(Acopy, L, U, 0); <span class="keywordtype">int</span> status = 0; <span class="keywordflow">for</span> ( i=0; i<m; ++i) <span class="keywordflow">for</span> ( j=0; j<n; ++j){ <span class="keywordflow">if</span> (<a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a> (Acopy,i,j)){ status = 1; <span class="keywordflow">break</span>; } } <span class="keywordflow">if</span> (status) { printf(<span class="stringliteral">"\n"</span>); printf(<span class="stringliteral">" ... FAILED\n"</span>); } <span class="keywordflow">else</span> printf (<span class="stringliteral">" ... passed\n"</span>); mzd_free(U); mzd_free(L); mzd_free(A); mzd_free(Acopy); mzp_free(P); mzp_free(Q); <span class="keywordflow">return</span> status; } <span class="keywordtype">int</span> test_pluq_random(<span class="keywordtype">size_t</span> m, <span class="keywordtype">size_t</span> n) { printf(<span class="stringliteral">"pluq: testing random m: %5zd, n: %5zd"</span>,m,n); <span class="keywordtype">size_t</span> i,j; <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* U = mzd_init(m, n); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* L = mzd_init(m, m); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* A = mzd_init(m, n); mzd_randomize(A); <a class="code" href="structmzd__t.html" title="Dense matrices over GF(2).">mzd_t</a>* Acopy = mzd_copy (NULL,A); <a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* P = mzp_init(m); <a class="code" href="structmzp__t.html" title="Permutations.">mzp_t</a>* Q = mzp_init(n); <span class="keywordtype">int</span> r; r=mzd_pluq(A, P, Q, 0); printf(<span class="stringliteral">", rank: %5d "</span>,r); <span class="keywordflow">for</span> (i=0; i<r; ++i){ <span class="keywordflow">for</span> (j=0; j<i;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); <span class="keywordflow">for</span> (j=i+1; j<n;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); } <span class="keywordflow">for</span> (i=r; i<m; i++) <span class="keywordflow">for</span> (j=0; j<r;++j) <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L, i, j, <a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a>(A,i,j)); <span class="keywordflow">for</span> (i=0; i<r; ++i){ <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(L,i,i, 1); <a class="code" href="packedmatrix_8h.html#a279d49adacd0f08fbcf9d3936c1774a4" title="Write the bit value to position M[row,col].">mzd_write_bit</a>(U,i,i, 1); } mzd_apply_p_left(Acopy, P); mzd_apply_p_right_trans(Acopy, Q); mzd_addmul(Acopy, L, U, 0); <span class="keywordtype">int</span> status = 0; <span class="keywordflow">for</span> ( i=0; i<m; ++i) <span class="keywordflow">for</span> ( j=0; j<n; ++j){ <span class="keywordflow">if</span> (<a class="code" href="packedmatrix_8h.html#a8b092ba6fad1336b5baa5c018fd35d62" title="Read the bit at position M[row,col].">mzd_read_bit</a> (Acopy,i,j)){ status = 1; <span class="keywordflow">break</span>; } } <span class="keywordflow">if</span> (status) { printf(<span class="stringliteral">" ... FAILED\n"</span>); } <span class="keywordflow">else</span> printf (<span class="stringliteral">" ... passed\n"</span>); mzd_free(U); mzd_free(L); mzd_free(A); mzd_free(Acopy); mzp_free(P); mzp_free(Q); <span class="keywordflow">return</span> status; } <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) { <span class="keywordtype">int</span> status = 0; status += test_pluq_structured(37, 37); status += test_pluq_structured(63, 63); status += test_pluq_structured(64, 64); status += test_pluq_structured(65, 65); status += test_pluq_structured(128, 128); status += test_pluq_structured(37, 137); status += test_pluq_structured(65, 5); status += test_pluq_structured(128, 18); status += test_pluq_full_rank(13,13); status += test_pluq_full_rank(37,37); status += test_pluq_full_rank(63,63); status += test_pluq_full_rank(64,64); status += test_pluq_full_rank(65,65); status += test_pluq_full_rank(97,97); status += test_pluq_full_rank(128,128); status += test_pluq_full_rank(150,150); status += test_pluq_full_rank(256,256); status += test_pluq_full_rank(1024,1024); status += test_pluq_full_rank(13,11); status += test_pluq_full_rank(37,39); status += test_pluq_full_rank(64,164); status += test_pluq_full_rank(97,92); status += test_pluq_full_rank(128,121); status += test_pluq_full_rank(150,153); status += test_pluq_full_rank(256,258); status += test_pluq_full_rank(1024,1023); status += test_pluq_half_rank(64,64); status += test_pluq_half_rank(65,65); status += test_pluq_half_rank(66,66); status += test_pluq_half_rank(127,127); status += test_pluq_half_rank(129,129); status += test_pluq_half_rank(148,148); status += test_pluq_half_rank(132,132); status += test_pluq_half_rank(256,256); status += test_pluq_half_rank(1024,1024); status += test_pluq_half_rank(129,127); status += test_pluq_half_rank(132,136); status += test_pluq_half_rank(256,251); status += test_pluq_half_rank(1024,2100); status += test_pluq_random(63,63); status += test_pluq_random(64,64); status += test_pluq_random(65,65); status += test_pluq_random(128,128); status += test_pluq_random(128, 131); status += test_pluq_random(132, 731); status += test_pluq_random(150,150); status += test_pluq_random(252, 24); status += test_pluq_random(256,256); status += test_pluq_random(1024,1022); status += test_pluq_random(1024,1024); status += test_pluq_random(128,1280); status += test_pluq_random(128, 130); status += test_pluq_random(132, 132); status += test_pluq_random(150,151); status += test_pluq_random(252, 2); status += test_pluq_random(256,251); status += test_pluq_random(1024,1025); status += test_pluq_random(1024,1021); <span class="keywordflow">if</span> (!status) { printf(<span class="stringliteral">"All tests passed.\n"</span>); <span class="keywordflow">return</span> 0; } <span class="keywordflow">else</span> { <span class="keywordflow">return</span> -1; } } </pre></div> </div> </div> <hr class="footer"/><address class="footer"><small>Generated on Sat Apr 23 2011 for M4RI by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address> </body> </html>