static bool testSingularPreconditionedSolve (const Field &F, VectorStream<SparseVector> &stream1, VectorStream<Vector> &stream2, const char *text, Method::Wiedemann::Preconditioner preconditioner) { ostringstream str; str << "Testing singular preconditioned solve (" << text << ")"; commentator().start (str.str ().c_str (), "testSingularPreconditionedSolve", stream1.m ()); VectorDomain<Field> VD (F); typename WiedemannSolver<Field>::ReturnStatus status; bool ret = true; SparseVector d1; typename Field::Element uTb; typename LinBox::Vector<Field>::Dense d; Vector b, x, y, u; VectorWrapper::ensureDim (d, stream2.dim ()); VectorWrapper::ensureDim (b, stream2.dim ()); VectorWrapper::ensureDim (x, stream2.dim ()); VectorWrapper::ensureDim (y, stream2.dim ()); Method::Wiedemann traits; traits.preconditioner (preconditioner); while (stream1 && stream2) { commentator().startIteration ((unsigned)stream1.j ()); stream1.next (d1); stream2.next (b); VD.copy (d, d1); ostream &report = commentator().report (Commentator::LEVEL_UNIMPORTANT, INTERNAL_DESCRIPTION); report << "Diagonal entries: "; VD.write (report, d); report << endl; report << "Right-hand side: "; VD.write (report, b); report << endl; BlasVector<Field> dd(F,d); Diagonal<Field> A (dd); //Diagonal<Field> A (F, d); status = solve (A, x, b, u, F, traits); if (status == WiedemannSolver<Field>::INCONSISTENT) { A.applyTranspose (y, u); report << "Certificate of inconsistency found." << endl; report << "Certificate is: "; VD.write (report, u) << endl; report << "u^T A = "; VD.write (report, y) << endl; VD.dot (uTb, u, b); report << "u^T b = "; F.write (report, uTb) << endl; if (!VD.isZero (y)) { commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: u is not in the right nullspace of D" << endl; ret = false; } if (F.isZero (uTb)) { commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: u^T b = 0" << endl; ret = false; } } else if (status == WiedemannSolver<Field>::FAILED) { commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Solver refused to certify inconsistency" << endl; ret = false; } else { commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Solver gave solution even though system is inconsistent" << endl; ret = false; } commentator().stop ("done"); commentator().progress (); } stream1.reset (); stream2.reset (); commentator().stop (MSG_STATUS (ret), (const char *) 0, "testSingularPreconditionedSolve"); return ret; }
static bool testRandomSolve (const Field &F, VectorStream<Vector1> &A_stream, VectorStream<Vector2> &b_stream, const char *text, MethodTraits method) { ostringstream str; str << "Testing random solve (" << text << ")"; commentator().start (str.str ().c_str (), "testRandomSolve", b_stream.size ()); bool ret = true; VectorDomain<Field> VD (F); MatrixDomain<Field> MD (F); Vector2 b, x, ATAx, ATb; VectorWrapper::ensureDim (b, b_stream.dim ()); VectorWrapper::ensureDim (x, A_stream.dim ()); VectorWrapper::ensureDim (ATAx, A_stream.dim ()); VectorWrapper::ensureDim (ATb, A_stream.dim ()); SparseMatrix<Field> A (F, A_stream); SparseMatrix<Field> AT (F,A.coldim (), A.rowdim ()); BlasMatrix<Field> ATA (A.coldim (), A.coldim ()); A.transpose (AT); MD.mul (ATA, AT, A); ostream &report = commentator().report (Commentator::LEVEL_UNIMPORTANT, INTERNAL_DESCRIPTION); report << "Input matrix A:" << endl; A.write (report); report << "Matrix A^T A:" << endl; MD.write (report, ATA); MethodTraits traits (method); while (b_stream) { commentator().startIteration ((unsigned)b_stream.pos ()); bool iter_passed = true; b_stream >> b; ostream &Report = commentator().report (Commentator::LEVEL_UNIMPORTANT, INTERNAL_DESCRIPTION); Report << "Right-hand side b:"; VD.write (Report, b) << endl; try { solve (A, x, b, F, traits); } catch (SolveFailed) { commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Solve failed to solve system" << endl; ret = iter_passed = false; } catch (InconsistentSystem<Vector2> e) { commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Solve reported an inconsistent system" << endl; ret = iter_passed = false; } if (iter_passed) { Report << "Output vector x: "; VD.write (Report, x) << endl; MD.vectorMul (ATAx, ATA, x); MD.vectorMul (ATb, AT, b); if (!VD.areEqual (ATAx, ATb)) { commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: A^T Ax != A^T b" << endl; ret = iter_passed = false; } } commentator().stop ("done"); commentator().progress (); } A_stream.reset (); b_stream.reset (); commentator().stop (MSG_STATUS (ret), (const char *) 0, "testRandomSolve"); return ret; }
static bool testZeroApply (Field1 &F1, Field2 &F2, VectorStream<Vector> &stream1, VectorStream<Vector> &stream2) { commentator().start ("Testing zero apply", "testZeroApply", stream1.m ()); bool ret = true; bool iter_passed = true; Vector d1, d2, v, w, zero; VectorDomain<Field1> VD (F1); typename Field1::Element neg_one; VectorWrapper::ensureDim (zero, stream1.dim ()); VectorWrapper::ensureDim (d1, stream1.dim ()); VectorWrapper::ensureDim (d2, stream1.dim ()); VectorWrapper::ensureDim (v, stream1.dim ()); VectorWrapper::ensureDim (w, stream2.dim ()); // F.init (neg_one, 1); // F.negin (neg_one); F1.init (neg_one, -1); while (stream1) { commentator().startIteration ((unsigned)stream1.j ()); iter_passed = true; stream1.next (d1); VD.mul (d2, d1, neg_one); Diagonal <Field1> D1 (F1, d1), D2 (F1, d2); Sum <Diagonal<Field1>,Diagonal <Field1> > A (&D1, &D2); ostream &report = commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_DESCRIPTION); report << "Diagonal matrix: "; VD.write (report, d1); report << endl; report << "Negative diagonal matrix: "; VD.write (report, d2); report << endl; stream2.reset (); while (stream2) { stream2.next (w); report << "Input vector: "; VD.write (report, w); report << endl; A.apply (v, w); report << "Output vector: "; VD.write (report, v); report << endl; if (!VD.isZero (v)) ret = iter_passed = false; } if (!iter_passed) commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Vector is not zero" << endl; commentator().stop ("done"); commentator().progress (); ret = ret && testBBrebind(F2, A); } commentator().stop (MSG_STATUS (ret), (const char *) 0, "testZeroApply"); return ret; }