int main (int argc, char **argv) { static size_t n = 10000; static unsigned int iterations = 1; static Argument args[] = { { 'n', "-n N", "Set dimension of test vectors to NxN.", TYPE_INT, &n }, { 'i', "-i I", "Perform each test for I iterations.", TYPE_INT, &iterations }, END_OF_ARGUMENTS }; parseArguments (argc, argv, args); commentator().start("Givaro::Modular<float> field test suite", "Givaro::Modular<float>"); bool pass = true; Givaro::Modular<float> F2 (2); Givaro::Modular<float> F5 (5); Givaro::Modular<float> F7 (7); Givaro::IntPrimeDom IPD; integer k = Givaro::Modular<float>::maxCardinality()+1; IPD.prevprime(k, k); Givaro::Modular<float> Fmax(k); IPD.prevprime(k, k/2); Givaro::Modular<float> Fmid(k); // Make sure some more detailed messages get printed commentator().getMessageClass (INTERNAL_DESCRIPTION).setMaxDepth (4); commentator().getMessageClass (INTERNAL_DESCRIPTION).setMaxDetailLevel (Commentator::LEVEL_UNIMPORTANT); std::ostream& report = commentator().report(); report << "Field F2" << std::endl; if (!runFieldTests (F2, "Givaro::Modular<float>", iterations, n, false)) pass = false; report << "Field F5" << std::endl; if (!runFieldTests (F5, "Givaro::Modular<float>", iterations, n, false)) pass = false; report << "Field F7" << std::endl; if (!runFieldTests (F7, "Givaro::Modular<float>", iterations, n, false)) pass = false; report << "Field Fmax" << std::endl; if (!runFieldTests (Fmax, "Givaro::Modular<float>", iterations, n, false)) pass = false; report << "Field Fmid" << std::endl; if (!runFieldTests (Fmid, "Givaro::Modular<float>", iterations, n, false)) pass = false; commentator().stop("Givaro::Modular<float> field test suite"); return pass ? 0 : -1; }
int main(int argc, char** argv){ FFLAS::Timer tim; Givaro::IntPrimeDom IPD; uint64_t p; size_t M, N ; bool keepon = true; Givaro::Integer _p,tmp; Field::Element zero,one; cerr<<setprecision(10); size_t TMAX = 100; size_t PRIMESIZE = 23; if (argc > 1 ) TMAX = atoi(argv[1]); if (argc > 2 ) PRIMESIZE = atoi(argv[2]); FFLAS::FFLAS_TRANSPOSE ta; FFLAS::FFLAS_DIAG diag; size_t lda; Field::Element * A, *Abis, *X,* U, *L; size_t *P, *Q; while (keepon){ srandom(_p); do{ // max = Integer::random(2); _p = random();//max % (2<<30); IPD.prevprime( tmp, (_p% (1<<PRIMESIZE)) ); p = tmp; }while( (p <= 2) ); Field F( p); F.init(zero,0.0); F.init(one,1.0); Field::RandIter RValue( F ); do{ M = (size_t) random() % TMAX; N = (size_t) random() % TMAX; } while ((M == 0) || (N == 0)); lda = N; if (random()%2) diag = FFLAS::FflasUnit; else diag = FFLAS::FflasNonUnit; if (random()%2){ ta = FFLAS::FflasTrans; L = FFLAS::fflas_new<Field::Element>(M*N); U = FFLAS::fflas_new<Field::Element>(N*N); P = FFLAS::fflas_new<size_t>(M); Q = FFLAS::fflas_new<size_t>(N); for (size_t i=0; i<M; ++i) P[i] = 0; for (size_t i=0; i<N; ++i) Q[i] = 0; } else{ ta = FFLAS::FflasNoTrans; L = FFLAS::fflas_new<Field::Element>(M*M); U = FFLAS::fflas_new<Field::Element>(M*N); P = FFLAS::fflas_new<size_t>(N); Q = FFLAS::fflas_new<size_t>(M); for (size_t i=0; i<N; ++i) P[i] = 0; for (size_t i=0; i<M; ++i) Q[i] = 0; } size_t R=0; Field::Element * G = FFLAS::fflas_new<Field::Element>(M*M); Field::Element * H = FFLAS::fflas_new<Field::Element>(M*N); size_t t; do{ t = (size_t) random() % 10; } while ((!t)||(t==1)); for (size_t i=0; i<M; ++i) if (!(random() % t)) for (size_t j=0; j < M; ++j) RValue.random (*(G+i*M+j)); else for (size_t j=0; j < M; ++j) F.assign(*(G+i*M+j), zero); for (size_t j=0; j < N; ++j) if (!(random() % t)) for (size_t i=0; i<M; ++i) RValue.random (*(H+i*N+j)); else for (size_t i=0; i<M; ++i) F.assign(*(H+i*N+j), zero); // write_field(F,cerr<<"G = "<<endl,G,M,M,M); // write_field(F,cerr<<"H = "<<endl,H,M,N,N); A = FFLAS::fflas_new<Field::Element>(M*N); FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, M, N, M, one, G, M, H, N, zero, A, N); FFLAS::fflas_delete( G); FFLAS::fflas_delete( H); Abis = FFLAS::fflas_new<Field::Element>(M*N); for (size_t i=0; i<M*N; ++i) *(Abis+i) = *(A+i); X = FFLAS::fflas_new<Field::Element>(M*N); cout <<"p = "<<(size_t)p<<" M = "<<M <<" N = "<<N <<((diag==FFLAS::FflasUnit)?" Unit ":" Non Unit ") <<((ta==FFLAS::FflasNoTrans)?"LQUP ( A ) ":"LQUP ( A^T ) ") <<"...."; tim.clear(); tim.start(); R = FFPACK::LUdivine (F, diag, ta, M, N, A, lda, P, Q); tim.stop(); //write_field(F,cerr<<"Result = "<<endl,Abis,M,N,lda); if (ta == FFLAS::FflasNoTrans){ for (size_t i=0; i<R; ++i){ for (size_t j=0; j<i; ++j) F.assign ( *(U + i*N + j), zero); for (size_t j=i+1; j<N; ++j) F.assign (*(U + i*N + j), *(A+ i*N+j)); } for (size_t i=R;i<M; ++i) for (size_t j=0; j<N; ++j) F.assign(*(U+i*N+j), zero); for ( size_t i=0; i<M; ++i ){ size_t j=0; for (; j< ((i<R)?i:R) ; ++j ) F.assign( *(L + i*M+j), *(A+i*N+j)); for (; j<M; ++j ) F.assign( *(L+i*M+j), zero); } //write_field(F,cerr<<"L = "<<endl,L,M,M,M); //write_field(F,cerr<<"U = "<<endl,U,M,N,N); FFPACK::applyP( F, FFLAS::FflasRight, FFLAS::FflasNoTrans, M,0,(int) R, L, M, Q); for ( size_t i=0; i<M; ++i ) F.assign(*(L+i*(M+1)), one); if (diag == FFLAS::FflasNonUnit) for ( size_t i=0; i<R; ++i ) F.assign (*(U+i*(N+1)), *(A+i*(lda+1))); else{ for (size_t i=0; i<R; ++i ){ *(L+Q[i]*(M+1)) = *(A+Q[i]*lda+i); F.assign (*(U+i*(N+1)),one); } } FFPACK::applyP (F, FFLAS::FflasRight, FFLAS::FflasNoTrans, M,0,(int) R, U, N, P); FFPACK::applyP (F, FFLAS::FflasLeft, FFLAS::FflasTrans, N,0,(int) R, U, N, Q); FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, M,N,M, 1.0, L,M, U,N, 0.0, X,N); //FFLAS::fflas_delete( A); } else { for (size_t i=0; i<R; ++i){ for (size_t j=0; j<i; ++j) F.assign ( *(L + i + j*N), zero); for (size_t j=i+1; j<M; ++j) F.assign (*(L + i + j*N), *(A+ i+j*N)); } for (size_t i=R;i<N; ++i) for (size_t j=0; j<M; ++j) F.assign(*(L+i+j*N), zero); for ( size_t i=0; i<N; ++i ){ size_t j=0; for (; j< ((i<R)?i:R) ; ++j ) F.assign( *(U + i+j*N), *(A+i+j*N)); for (; j<N; ++j ) F.assign( *(U+i+j*N), zero); } FFPACK::applyP( F, FFLAS::FflasLeft, FFLAS::FflasTrans, N,0,(int) R, U, N, Q); for (size_t i=0; i<N; ++i) F.assign (*(U+i*(N+1)),one); if (diag == FFLAS::FflasNonUnit) for ( size_t i=0; i<R; ++i ) F.assign (*(L+i*(N+1)), *(A+i*(lda+1))); else{ for ( size_t i=0; i<R; ++i ){ *(U+Q[i]*(N+1)) = *(A+Q[i]+i*N); F.assign (*(L+i*(N+1)),one); } } // write_field(F,cerr<<"L = "<<endl,L,M,N,N); // write_field(F,cerr<<"U = "<<endl,U,N,N,N); FFPACK::applyP (F, FFLAS::FflasLeft, FFLAS::FflasTrans, N,0,(int) R, L, N, P); FFPACK::applyP (F, FFLAS::FflasRight, FFLAS::FflasNoTrans, M,0,(int) R, L, N, Q); FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, M,N,N, 1.0, L,N, U,N, 0.0, X,N); } for (size_t i=0; i<M; ++i) for (size_t j=0; j<N; ++j) if (!F.areEqual (*(Abis+i*N+j), *(X+i*N+j))){ cerr<<"error for i,j="<<i<<" "<<j<<" "<<*(Abis+i*N+j)<<" "<<*(X+i*N+j)<<endl; keepon = false; } //write_field(F,cerr<<"X = "<<endl,X,m,n,n); //write_field(F,cerr<<"B = "<<endl,B,m,n,n); if (keepon){ cout<<"R = "<<R <<" Passed " <<(double(M*M)/1000.0*(double(N)-double(M)/3.0)/tim.usertime()/1000.0)<<"Mfops"<<endl; FFLAS::fflas_delete( A); FFLAS::fflas_delete( L); FFLAS::fflas_delete( U); FFLAS::fflas_delete( Abis); FFLAS::fflas_delete( X); FFLAS::fflas_delete( P); FFLAS::fflas_delete( Q); } else{ cerr<<"Abis = "<<endl; write_field( F, cerr, Abis, (int) M, (int) N, (int) N ); cerr<<"X = "<<endl; write_field( F, cerr, X, (int) M, (int) N, (int) N ); } } cout<<endl; cerr<<"FAILED with p = "<<(size_t)p<<" M = "<<M<<" N = "<<N <<" trans = "<<ta<<" diag = "<<diag<<endl; cerr<<"A:"<<endl; cerr<<M<<" "<<N<<" M"<<endl; for (size_t i=0; i<M; ++i) for (size_t j=0; j<N; ++j) if (*(Abis+i*lda+j)) cerr<<i+1<<" "<<j+1<<" "<<((int) *(Abis+i*lda+j) )<<endl; cerr<<"0 0 0"<<endl<<endl; FFLAS::fflas_delete( A); FFLAS::fflas_delete( Abis); FFLAS::fflas_delete( L); FFLAS::fflas_delete( U); FFLAS::fflas_delete( X); FFLAS::fflas_delete( P); FFLAS::fflas_delete( Q); }
int main(int argc, char** argv){ FFLAS::Timer tim; Givaro::IntPrimeDom IPD; uint64_t p; size_t M, N, K ; bool keepon = true; Givaro::Integer _p,tmp; Field::Element zero,one; cerr<<setprecision(10); size_t TMAX = 300; size_t PRIMESIZE = 23; if (argc > 1 ) TMAX = atoi(argv[1]); if (argc > 2 ) PRIMESIZE = atoi(argv[2]); FFLAS::FFLAS_TRANSPOSE trans; FFLAS::FFLAS_SIDE side; FFLAS::FFLAS_UPLO uplo; FFLAS::FFLAS_DIAG diag; size_t lda, ldb; Field::Element * A, *Abis, *B,* Bbis; Field::Element alpha; while (keepon){ srandom(_p); do{ // max = Integer::random(2); _p = random();//max % (2<<30); IPD.prevprime( tmp, (_p% (1<<PRIMESIZE)) ); p = tmp; }while( (p <= 2) ); Field F (p); F.init (zero,0.0); F.init (one,1.0); Field::RandIter RValue (F); do{ M = (size_t) random() % TMAX; N = (size_t) random() % TMAX; } while ((M == 0) || (N == 0)); ldb = N; if (random()%2) trans = FFLAS::FflasNoTrans; else trans = FFLAS::FflasTrans; if (random()%2) diag = FFLAS::FflasUnit; else diag = FFLAS::FflasNonUnit; if (random()%2){ side = FFLAS::FflasLeft; K = M; lda = M; } else { side = FFLAS::FflasRight; K = N; lda = N; } if (random()%2) uplo = FFLAS::FflasUpper; else uplo = FFLAS::FflasLower; while (F.isZero(RValue.random (alpha))); A = FFLAS::fflas_new<Field::Element>(K*K); B = FFLAS::fflas_new<Field::Element>(M*N); Abis = FFLAS::fflas_new<Field::Element>(K*K); Bbis = FFLAS::fflas_new<Field::Element>(M*N); for (size_t i = 0; i < M; ++i) for (size_t j = 0; j < N; ++j){ RValue.random (*(B + i*N + j)); *(Bbis + i*N + j) = *(B + i*N + j); } for (size_t i = 0; i < K; ++i) for (size_t j = 0; j < K; ++j) *(Abis + i*K + j) = RValue.random (*(A + i*K + j)); for (size_t i = 0; i < K; ++i){ while (F.isZero(RValue.random (*(A + i*(K+1))))); *(Abis + i*(K +1)) = *(A + i*(K+1)); } cout <<"p = "<<(size_t)p <<" M = "<<M <<" N = "<<N <<((side==FFLAS::FflasLeft)?" Left ":" Right ") <<((uplo==FFLAS::FflasLower)?" Lower ":" Upper ") <<((trans==FFLAS::FflasTrans)?" Trans ":" NoTrans ") <<((diag==FFLAS::FflasUnit)?" Unit ":" NonUnit ") <<"...."; tim.clear(); tim.start(); FFLAS::ftrsm (F, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb); tim.stop(); // Verification Field::Element invalpha; F.inv(invalpha, alpha); FFLAS::ftrmm (F, side, uplo, trans, diag, M, N, invalpha, A, K, B, N); for (size_t i = 0;i < M;++i) for (size_t j = 0;j < N; ++j) if ( !F.areEqual (*(Bbis + i*N+ j ), *(B + i*N + j))){ cerr<<endl <<"Bbis ["<<i<<", "<<j<<"] = "<<(*(Bbis + i*N + j)) <<" ; B ["<<i<<", "<<j<<"] = "<<(*(B + i*N + j)); keepon = false; } for (size_t i = 0;i < K; ++i) for (size_t j = 0;j < K; ++j) if ( !F.areEqual (*(A + i*K + j), *(Abis + i*K + j))){ cerr<<endl <<"A ["<<i<<", "<<j<<"] = "<<(*(A + i*K + j)) <<" ; Abis ["<<i<<", "<<j<<"] = "<<(*(Abis + i*K + j)); keepon = false; } if (keepon) { cout<<" Passed " <<double(M*N)/1000000.0*double(K)/tim.usertime()<<" Mfops"<<endl; FFLAS::fflas_delete( B); FFLAS::fflas_delete( Bbis); FFLAS::fflas_delete( A); FFLAS::fflas_delete( Abis); } else { cerr<<endl; write_field (F, cerr<<"A = "<<endl, Abis, (int) K,(int) K,(int) K); write_field (F, cerr<<"B = "<<endl, Bbis, (int) M,(int) N,(int) N); } } cout<<endl; cerr<<"FAILED with p = "<<(size_t)p <<" M = "<<M <<" N = "<<N <<" alpha = "<<alpha <<((side==FFLAS::FflasLeft)?" Left ":" Right ") <<((uplo==FFLAS::FflasLower)?" Lower ":" Upper ") <<((trans==FFLAS::FflasTrans)?" Trans ":" NoTrans ") <<((diag==FFLAS::FflasUnit)?" Unit ":" NonUnit ") <<endl; cerr<<"A:"<<endl; cerr<<K<<" "<<K<<" M"<<endl; for (size_t i=0; i<K; ++i) for (size_t j=0; j<K; ++j) if ((*(Abis + i*lda + j))) cerr<<i+1<<" "<<j+1<<" " <<((int) *(Abis+i*lda+j) ) <<endl; cerr<<"0 0 0"<<endl<<endl; cerr<<"B:"<<endl; cerr<<M<<" "<<N<<" M"<<endl; for (size_t i=0; i<M; ++i) for (size_t j=0; j<N; ++j) if ((*(Bbis + i*ldb + j))) cerr<<i+1<<" "<<j+1<<" " <<((int) *(Bbis+i*ldb+j) ) <<endl; cerr<<"0 0 0"<<endl<<endl; FFLAS::fflas_delete( A); FFLAS::fflas_delete( Abis); FFLAS::fflas_delete( B); FFLAS::fflas_delete( Bbis); }