コード例 #1
0
bool testEchelonizeReduced (const Ring &F, const char *text, Matrix &A)
{
	std::ostringstream str;
	str << "Testing Elimination::echelonize_reduced for " << text << " matrices" << std::ends;
	commentator.start (str.str ().c_str (), __FUNCTION__);

	std::ostream &report = commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION);
	std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR);

	bool pass = true;

	Context<Ring> ctx (F);
	Elimination<Ring> elim (ctx);

	typename Matrix::ContainerType Acopy (A.rowdim (), A.coldim ()), LPA (A.rowdim (), A.coldim ()), L (A.rowdim (), A.rowdim ());

	BLAS3::copy (ctx, A, Acopy);

	typename Elimination<Ring>::Permutation P;

	size_t rank;
	typename Ring::Element det;

	report << "A = " << std::endl;
	BLAS3::write (ctx, report, A, FORMAT_PRETTY);

	elim.echelonize_reduced (A, L, P, rank, det, true);

	report << "R = " << std::endl;
	BLAS3::write (ctx, report, A, FORMAT_PRETTY);

	report << "L = " << std::endl;
	BLAS3::write (ctx, report, L, FORMAT_PRETTY);

	report << "P = ";
	BLAS1::write_permutation (report, P.begin (), P.end ()) << std::endl;

	BLAS3::permute_rows (ctx, P.begin (), P.end (), Acopy);
	report << "PA = " << std::endl;
	BLAS3::write (ctx, report, Acopy, FORMAT_PRETTY);

	BLAS3::scal (ctx, F.zero (), LPA);
	BLAS3::gemm (ctx, F.one (), L, Acopy, F.zero (), LPA);

	report << "LPA = " << std::endl;
	BLAS3::write (ctx, report, LPA);

	report << "Computed rank = " << rank << std::endl;
	report << "Computed det = ";
	F.write (report, det);
	report << std::endl;

	if (!BLAS3::equal (ctx, LPA, A)) {
		error << "LPA != R, not okay" << std::endl;
		pass = false;
	}

	commentator.stop (MSG_STATUS (pass));

	return pass;
}