Exemplo n.º 1
0
int TestField(const Field& F, const uint64_t seed)
{
    typename Field::Element x;
    typename Field::RandIter g(F, 0, seed);
    
    F.init(x, 1);
    JEONETESTE(F,x);
    
    for (size_t i = 0; i< NBITER; ++i) {
	while (F.isZero(g.random(x)));
        JEONETESTE(F,x);
    }
    
    return 0;
}
Exemplo n.º 2
0
int main (int argc, char **argv)
{
	bool pass = true;

	static size_t n = 10;
	static size_t m = 10;
	static integer q = 11;
	static size_t N = m+n;

	static Argument args[] = {
		{ 'm', "-m m", "Set row dimension of test matrices to m.", TYPE_INT,     &m },
		{ 'n', "-n n", "Set column dimension of test matrices to n.", TYPE_INT,     &n },
		{ 'N', "-N N", "Set number of nonzeros in test matrices.", TYPE_INT,     &N },
		{ 'q', "-q Q", "Operate over the \"field\" GF(Q) [1].", TYPE_INTEGER, &q },
		END_OF_ARGUMENTS
	};
	parseArguments (argc, argv, args);

	//typedef	Givaro::Modular<uint32_t> Field;
	typedef	Givaro::Modular<double> Field;

	Field F (q);

	commentator().getMessageClass (INTERNAL_DESCRIPTION).setMaxDepth (5);
	commentator().getMessageClass (INTERNAL_DESCRIPTION).setMaxDetailLevel (Commentator::LEVEL_UNIMPORTANT);

	commentator().start("Sparse matrix black box test suite", "Sparse");
	MatrixDomain<Field> MD(F) ;
	typename Field::RandIter r(F,0,1);
	srand(0);

	 /*  default case */
	commentator().start("SparseMatrix<Field>", "Field");

	SparseMatrix<Field> S1(F, m, n);
	typename Field::Element x;
	for (size_t k = 0; k < N; ++k)
	{
		size_t i = rand() % m;
		size_t j = rand() % n;
		while (S1.field().isZero(r.random(x)));
		S1.setEntry(i,j,x);
	}
	S1.finalize();

	//if ( testBlackbox(S1, true, N != 0))
	if ( testBlackbox(S1, false, N != 0))
		commentator().stop("SparseMatrix<Field> pass");
	else {
		commentator().stop("SparseMatrix<Field> FAIL");
		pass = false;
	}

	/* other formats */
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::COO>("COO",S1);
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::CSR>("CSR",S1);
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::ELL>("ELL",S1);
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::ELL_R>("ELL_R",S1);
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::TPL>("TPL",S1);
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::SparseSeq>("SparseSeq",S1);
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::SparsePar>("SparsePar",S1);
	pass = pass and 
		testSparseFormat<Field, SparseMatrixFormat::SparseMap>("SparseMap",S1);
#if 0 // doesn't compile
	commentator().start("SparseMatrix<Field, SparseMatrixFormat::HYB>", "HYB");
	SparseMatrix<Field, SparseMatrixFormat::HYB> S6(F, m, n);
	buildBySetGetEntry(S6, S1);
	S6.optimise();
	if ( testBlackbox(S6,false)  && MD.areEqual(S1,S6))
		commentator().stop("Format HYB pass");
	else {
		commentator().stop("Format HYB FAIL");
		pass = false;
	}
#endif

	{ /*  Default OLD */
		commentator().start("SparseMatrix<Field>", "Field");
		Protected::SparseMatrixGeneric<Field> S11(F, m, n);
		buildBySetGetEntry(S11, S1);
		if ( testBlackbox(S11,true)  && MD.areEqual(S1,S11))
			commentator().stop("SparseMatrix<Field> pass");
		else {
			commentator().stop("SparseMatrix<Field> FAIL");
			pass = false;
		}
	}

	commentator().stop( MSG_STATUS(pass), "Sparse matrix black box test suite pass");


	return pass ? 0 : -1;
}