コード例 #1
0
bool testPLUQ (const Ring &F, const char *text, Matrix &A)
{
	std::ostringstream str;
	str << "Testing Elimination::pluq 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 ()), L (A.rowdim (), A.rowdim ());

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

	typename Elimination<Ring>::Permutation P, Q;

	size_t rank;
	typename Ring::Element det;

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

	elim.pluq (A, P, Q, rank, det);

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

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

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

	BLAS3::scal (ctx, ctx.F.zero (), L);
	elim.move_L (L, A);

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

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

	BLAS3::trmm (ctx, F.one (), L, A, LowerTriangular, true);

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

	BLAS3::permute_rows (ctx, P.begin (), P.end (), A);

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

	BLAS3::permute_cols (ctx, Q.begin (), Q.end (), A);

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

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

	if (!BLAS3::equal (ctx, A, Acopy)) {
		error << "PLUQ != A, not okay" << std::endl;

		BLAS3::axpy (ctx, ctx.F.minusOne (), A, Acopy);

		error << "Difference is:" << std::endl;
		BLAS3::write (ctx, error, Acopy);

		pass = false;
	}

	commentator.stop (MSG_STATUS (pass));

	return pass;
}