| 1 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
|---|
| 2 | //-------------------------------------------------------------------------- |
|---|
| 3 | // Test for charpoly |
|---|
| 4 | // |
|---|
| 5 | //-------------------------------------------------------------------------- |
|---|
| 6 | // Clement Pernet |
|---|
| 7 | //------------------------------------------------------------------------- |
|---|
| 8 | |
|---|
| 9 | #include <iomanip> |
|---|
| 10 | #include <iostream> |
|---|
| 11 | #include "fflas-ffpack/modular-balanced.h" |
|---|
| 12 | #include "fflas-ffpack/modular-positive.h" |
|---|
| 13 | #include "fflas-ffpack/modular-int.h" |
|---|
| 14 | #include "timer.h" |
|---|
| 15 | #include "Matio.h" |
|---|
| 16 | #include "fflas-ffpack/ffpack.h" |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | using namespace std; |
|---|
| 22 | |
|---|
| 23 | //typedef ModularBalanced<double> Field; |
|---|
| 24 | //typedef ModularBalanced<float> Field; |
|---|
| 25 | //typedef Modular<double> Field; |
|---|
| 26 | //typedef Modular<float> Field; |
|---|
| 27 | typedef Modular<int> Field; |
|---|
| 28 | typedef vector<Field::Element> Polynomial; |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | template <class Field, class Polynomial> |
|---|
| 32 | void printPolynomial (const Field &F, const Polynomial &v) |
|---|
| 33 | { |
|---|
| 34 | for (int i = v.size () - 1; i >= 0; i--) { |
|---|
| 35 | F.write (cout, v[i]); |
|---|
| 36 | if (i > 0) |
|---|
| 37 | cout << " x^" << i << " + "; |
|---|
| 38 | } |
|---|
| 39 | cout << endl; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | int main(int argc, char** argv){ |
|---|
| 43 | |
|---|
| 44 | int n; |
|---|
| 45 | cerr<<setprecision(10); |
|---|
| 46 | if (argc != 4) { |
|---|
| 47 | cerr<<"Usage : test-charpoly <p> <A> <i>" |
|---|
| 48 | <<endl |
|---|
| 49 | <<" to compute the characteristic polynomial of A mod p (i computations)" |
|---|
| 50 | <<endl; |
|---|
| 51 | exit(-1); |
|---|
| 52 | } |
|---|
| 53 | int nbit=atoi(argv[3]); // number of times the product is performed |
|---|
| 54 | Field F((long unsigned int)atoi(argv[1])); |
|---|
| 55 | Field::Element * A; |
|---|
| 56 | A = read_field(F,argv[2],&n,&n); |
|---|
| 57 | |
|---|
| 58 | Timer tim,t; t.clear();tim.clear(); |
|---|
| 59 | list<Polynomial> P_list; |
|---|
| 60 | for(int i = 0;i<nbit;++i){ |
|---|
| 61 | P_list.clear(); |
|---|
| 62 | t.clear(); |
|---|
| 63 | t.start(); |
|---|
| 64 | |
|---|
| 65 | FFPACK::CharPoly (F, P_list, n, A, n); |
|---|
| 66 | t.stop(); |
|---|
| 67 | tim+=t; |
|---|
| 68 | delete[] A; |
|---|
| 69 | if (i+1<nbit){ |
|---|
| 70 | A = read_field(F,argv[2],&n,&n); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | double mflops = (2+(2.0/3.0))*(n*n/1000000.0)*nbit*n/tim.usertime(); |
|---|
| 75 | list<Polynomial>::iterator P_it = P_list.begin(); |
|---|
| 76 | for (;P_it!=P_list.end();++P_it) |
|---|
| 77 | printPolynomial ( F, *P_it); |
|---|
| 78 | |
|---|
| 79 | cerr<<"n = "<<n<<" #inv. fact = "<<P_list.size()<<" Charpoly (A) over Z/ "<<atoi(argv[1])<<"Z : t= " |
|---|
| 80 | << tim.usertime()/nbit |
|---|
| 81 | << " s, Mffops = "<<mflops |
|---|
| 82 | << endl; |
|---|
| 83 | |
|---|
| 84 | cout<<n<<" "<<P_list.size()<<" "<<mflops<<" "<<tim.usertime()/nbit<<endl; |
|---|
| 85 | } |
|---|