<!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>linbox: examples/checksolve.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 --> <script type="text/javascript"> function hasClass(ele,cls) { return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); } function addClass(ele,cls) { if (!this.hasClass(ele,cls)) ele.className += " "+cls; } function removeClass(ele,cls) { if (hasClass(ele,cls)) { var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); ele.className=ele.className.replace(reg,' '); } } function toggleVisibility(linkObj) { var base = linkObj.getAttribute('id'); var summary = document.getElementById(base + '-summary'); var content = document.getElementById(base + '-content'); var trigger = document.getElementById(base + '-trigger'); if ( hasClass(linkObj,'closed') ) { summary.style.display = 'none'; content.style.display = 'block'; trigger.src = 'open.png'; removeClass(linkObj,'closed'); addClass(linkObj,'opened'); } else if ( hasClass(linkObj,'opened') ) { summary.style.display = 'block'; content.style.display = 'none'; trigger.src = 'closed.png'; removeClass(linkObj,'opened'); addClass(linkObj,'closed'); } return false; } </script> <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">linbox</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="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</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="dirs.html"><span>Directories</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">examples/checksolve.C</div> </div> </div> <div class="contents"> <p>Solving of sparse matrix over Z or Zp.</p> <div class="fragment"><pre class="fragment"><span class="comment">/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */</span> <span class="comment">// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s</span> <span class="comment">/*</span> <span class="comment"> * examples/checksolve.C</span> <span class="comment"> *</span> <span class="comment"> * Copyright (C) 2007 C. Pernet</span> <span class="comment"> *</span> <span class="comment"> * This file is part of LinBox.</span> <span class="comment"> *</span> <span class="comment"> * LinBox is free software: you can redistribute it and/or modify</span> <span class="comment"> * it under the terms of the GNU Lesser General Public License as</span> <span class="comment"> * published by the Free Software Foundation, either version 2 of</span> <span class="comment"> * the License, or (at your option) any later version.</span> <span class="comment"> *</span> <span class="comment"> * LinBox is distributed in the hope that it will be useful,</span> <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <span class="comment"> * GNU Lesser General Public License for more details.</span> <span class="comment"> *</span> <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span> <span class="comment"> * License along with LinBox. If not, see</span> <span class="comment"> * <http://www.gnu.org/licenses/>.</span> <span class="comment"> */</span> <span class="comment">//#include "linbox-config.h"</span> <span class="preprocessor">#include <iostream></span> <span class="preprocessor">#include "<a class="code" href="modular-double_8h.html" title="Standard representation of Z/mZ over double .">linbox/field/modular-double.h</a>"</span> <span class="preprocessor">#include "linbox/blackbox/blas-blackbox.h"</span> <span class="preprocessor">#include "linbox/solutions/solve.h"</span> <span class="preprocessor">#include "linbox/util/matrix-stream.h"</span> <span class="preprocessor">#include "<a class="code" href="methods_8h.html" title="NO DOC.">linbox/solutions/methods.h</a>"</span> <span class="keyword">using namespace </span>LinBox; <span class="keyword">using namespace </span>std; <span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) { <span class="comment">// commentator.setMaxDetailLevel (-1);</span> <span class="comment">// commentator.setMaxDepth (-1);</span> <span class="comment">// commentator.setReportStream (std::cerr);</span> <span class="keywordflow">if</span> (argc < 2 || argc > 4) { cerr << <span class="stringliteral">"Usage: checksolve <matrix-file-in-supported-format> <dense-vector-file> <p>"</span> << endl; <span class="keywordflow">return</span> 0; } std::ifstream input (argv[1]); <span class="keywordflow">if</span> (!input) { cerr << <span class="stringliteral">"Error opening matrix file "</span> << argv[1] << endl; <span class="keywordflow">return</span> -1; } std::ifstream invect(argv[2]); <span class="keywordflow">if</span> (!input) { cerr << <span class="stringliteral">"Error opening vector file "</span> << argv[2] << endl; <span class="keywordflow">return</span> -1; } <span class="keyword">typedef</span> <a name="_a0"></a><a class="code" href="class_lin_box_1_1_modular_3_01double_01_4.html" title="Standard representation of .">Modular<double></a> <a name="_a1"></a><a class="code" href="class_lin_box_1_1_modular_3_01uint32__t_01_4.html" title="Specialization of class Modular for uint32_t element type.">Field</a>; <span class="keywordtype">double</span> q = atof(argv[3]); Field F(q); <a name="_a2"></a><a class="code" href="class_lin_box_1_1_matrix_stream.html" title="MatrixStream.">MatrixStream< Field ></a> ms ( F, input ); <a name="_a3"></a><a class="code" href="class_lin_box_1_1_blas_blackbox.html" title="Dense matrix representation for BLAS based elimination.">BlasBlackbox<Field></a> A (ms); <span class="comment">// A.write(std::cout);</span> cout << <span class="stringliteral">"A is "</span> << A.<a name="a4"></a><a class="code" href="class_lin_box_1_1_blas_blackbox.html#a0fee90e6b8ef7fcd8d76a7f3e1f268e6" title="Get the number of rows in the matrix.">rowdim</a>() << <span class="stringliteral">" by "</span> << A.<a name="a5"></a><a class="code" href="class_lin_box_1_1_blas_blackbox.html#a32edb490d3597f5553152d14b102e227" title="Get the number of columns in the matrix.">coldim</a>() << endl; std::vector<Field::Element> X( A.<a class="code" href="class_lin_box_1_1_blas_blackbox.html#a32edb490d3597f5553152d14b102e227" title="Get the number of columns in the matrix.">coldim</a>()),B(A.<a class="code" href="class_lin_box_1_1_blas_blackbox.html#a0fee90e6b8ef7fcd8d76a7f3e1f268e6" title="Get the number of rows in the matrix.">rowdim</a>()); <span class="keywordflow">for</span>(std::vector<Field::Element>::iterator it=B.begin(); it != B.end(); ++it) invect >> *it; std::cout << <span class="stringliteral">"B is [ "</span><<B<< <span class="stringliteral">"]"</span> << std::endl; <a name="a6"></a><a class="code" href="namespace_lin_box.html#a353c2c55c4d1fd5b35e9b4e04c274982" title="Solve Ax=b over field F using Wiedemann's method, with inconsistency certificate.">solve</a> (X, A, B, <a class="code" href="struct_lin_box_1_1_method.html#ae72ae4bbae70adf0514c807be2037706" title="Method::BlasElimination : no doc.">Method::BlasElimination</a>()); std::cout << <span class="stringliteral">"(BlasElimination) Solution is [ "</span><<X<< <span class="stringliteral">"]"</span> << std::endl; std::vector<Field::Element> r(A.<a class="code" href="class_lin_box_1_1_blas_blackbox.html#a0fee90e6b8ef7fcd8d76a7f3e1f268e6" title="Get the number of rows in the matrix.">rowdim</a>()); <a name="_a7"></a><a class="code" href="class_lin_box_1_1_blas_matrix_domain.html" title="Interface for all functionnalities provided for BlasMatrix.">BlasMatrixDomain<Field></a> BMD(F); BMD.mul(r, <span class="keyword">static_cast<</span><a name="_a8"></a><a class="code" href="class_lin_box_1_1_blas_matrix.html" title="BlasMatrix.">BlasMatrix<Field::Element></a>& <span class="keyword">></span>(A), X); <span class="comment">//A.apply (r,X);</span> VectorDomain<Field> VD(F); <span class="keywordflow">if</span> (VD.areEqual (r,B)) std::cout<<<span class="stringliteral">"CHECK"</span><<endl; <span class="keywordflow">else</span>{ std::cout<<<span class="stringliteral">"FAIL"</span><<endl; cout<<<span class="stringliteral">"r = "</span><<r<<endl; cout<<<span class="stringliteral">"B = "</span><<B<<endl; } <span class="keywordflow">return</span> 0; } </pre></div> </div> </div> <hr class="footer"/><address class="footer"><small>Generated on Tue Aug 30 2011 for linbox 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>