bool testRandomApply1 (Field &F, const char *text, unsigned int iterations, VectorStream<Row> &A_stream) { typedef SparseMatrix <Field, Row> Blackbox; ostringstream str; str << "Testing sparse random apply (1, " << text << ")" << ends; commentator().start (str.str ().c_str (), "testRandomApply1", iterations); bool ret = true; bool iter_passed; size_t i, k; VectorDomain<Field> VD (F); StandardBasisStream<Field, Vector> stream (F, A_stream.n ()); Vector e_j, w; VectorWrapper::ensureDim (e_j, A_stream.n ()); VectorWrapper::ensureDim (w, A_stream.m ()); for (i = 0; i < iterations; i++) { commentator().startIteration ((unsigned)i); iter_passed = true; Blackbox A (F, A_stream); A_stream.reset (); ostream &report = commentator().report (Commentator::LEVEL_UNIMPORTANT, INTERNAL_DESCRIPTION); report << "Matrix:" << endl; A.write (report, FORMAT_PRETTY); stream.reset (); while (stream) { stream.next (e_j); A.apply (w, e_j); for (k = 0; k < A_stream.m (); k++) if (!F.areEqual (A.getEntry (k, stream.j () - 1), VectorWrapper::constRef<Field> (w, k))) ret = iter_passed = false; report << "Output vector " << stream.j () << ": "; VD.write (report, w) << endl; } if (!iter_passed) commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Output vectors were incorrect" << endl; commentator().stop ("done"); commentator().progress (); } commentator().stop (MSG_STATUS (ret), (const char *) 0, "testRandomApply1"); return ret; }
bool testRandomApply2 (Field &F, const char *text, unsigned int iterations, VectorStream<Row> &A_stream) { typedef SparseMatrix <Field, Row> Blackbox; ostringstream str; str << "Testing sparse random apply (2, " << text << ")" << ends; commentator().start (str.str ().c_str (), "testRandomApply2", iterations); bool ret = true; bool iter_passed; size_t i, j, k; VectorDomain<Field> VD (F); typename Field::RandIter r (F); typename Field::Element sum; integer c; // long width; F.characteristic (c); // width = logp (c, 10) + 1; Vector v, w; VectorWrapper::ensureDim (v, A_stream.n ()); VectorWrapper::ensureDim (w, A_stream.m ()); for (k = 0; k < A_stream.n (); k++) F.init (VectorWrapper::ref<Field> (v, k), 1); for (i = 0; i < iterations; i++) { commentator().startIteration ((unsigned)i); iter_passed = true; Blackbox A (F, A_stream); A_stream.reset (); ostream &report = commentator().report (Commentator::LEVEL_UNIMPORTANT, INTERNAL_DESCRIPTION); report << "Matrix:" << endl; A.write (report, FORMAT_PRETTY); A.apply (w, v); for (j = 0; j < A_stream.m (); j++) { F.init (sum, 0); for (k = 0; k < A_stream.n (); k++) F.addin (sum, A.getEntry (j, k)); if (!F.areEqual (sum, VectorWrapper::constRef<Field> (w, j))) ret = iter_passed = false; } report << "Output vector: "; VD.write (report, w) << endl; if (!iter_passed) commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Output vector was incorrect" << endl; commentator().stop ("done"); commentator().progress (); } commentator().stop (MSG_STATUS (ret), (const char *) 0, "testRandomApply2"); return ret; }