root / tests / test-colechelon.C

Revision 26, 4.0 kB (checked in by pernet, 2 years ago)

New row echelon form and reduced row echelon form

Line 
1/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2//--------------------------------------------------------------------------
3//          Test for the column echelon factorisation
4//--------------------------------------------------------------------------
5// usage: test-colechelon p A n, for n computations
6// of A over Z/pZ
7//-------------------------------------------------------------------------
8
9//-------------------------------------------------------------------------
10#define DEBUG 1
11// Debug option  0: no debug
12//               1: check A = LQUP
13//-------------------------------------------------------------------------
14using namespace std;
15
16
17//#define __LUDIVINE_CUTOFF 1
18#include <iostream>
19#include <iomanip>
20#include "Matio.h"
21#include "timer.h"
22#include "fflas-ffpack/modular-balanced.h"
23#include "fflas-ffpack/ffpack.h"
24
25typedef Modular<double> Field;
26
27int main(int argc, char** argv){
28        cerr<<setprecision(20);
29        int i,j,nbf,m,n;
30        int R=0;
31
32        if (argc!=4){
33                cerr<<"usage : test-colechelon <p> <A> <i>"<<endl
34                    <<"        to do i Column Echelon factorisation of A"
35                    <<endl;
36                exit(-1);
37        }
38        Field F((unsigned long)atoi(argv[1]));
39        Field::Element * A;
40       
41        A = read_field(F,argv[2],&m,&n);
42       
43        size_t *P = new size_t[n];
44        size_t *Q = new size_t[m];
45               
46        //      size_t cutoff = atoi(argv[3]);
47        nbf = atoi(argv[3]);
48       
49        Timer tim,timc;
50        timc.clear();
51
52
53        for ( i=0;i<nbf;i++){
54                if (i) {               
55                        delete[] A;
56                        A = read_field(F,argv[2],&m,&n);
57                }
58                for (j=0;j<n;j++)
59                        P[j]=0;
60                for (j=0;j<m;j++)
61                        Q[j]=0;
62                tim.clear();     
63                tim.start();   
64                R = FFPACK::ColumnEchelonForm (F, m, n, A, n, P, Q);
65                tim.stop();
66                timc+=tim;
67        }
68        //write_field (F,cerr<<"Result = "<<endl, A, m,n,n);
69
70//      cerr<<"P = [";
71//      for (size_t i=0; i<n; ++i)
72//              cerr<<P[i]<<" ";
73//      cerr<<"]"<<endl;
74//      cerr<<"Q = [";
75//      for (size_t i=0; i<m; ++i)
76//              cerr<<Q[i]<<" ";
77//      cerr<<"]"<<endl;
78#if DEBUG
79        Field::Element * L = new Field::Element[m*n];
80        Field::Element * U = new Field::Element[n*n];
81        Field::Element * X = new Field::Element[m*n];
82       
83        Field::Element zero,one;
84        F.init(zero,0.0);
85        F.init(one,1.0);
86        for (int i=0; i<R; ++i){
87                for (int j=0; j<=i; ++j)
88                        F.assign ( *(U + i*n + j), zero);
89                F.init (*(U+i*(n+1)),one);
90                for (int j=i+1; j<n; ++j)
91                        F.assign (*(U + i*n + j), *(A+ i*n+j));
92        }
93        for (int i=R;i<n; ++i){
94                for (int j=0; j<n; ++j)
95                        F.assign(*(U+i*n+j), zero);
96                F.init(*(U+i*(n+1)),one);
97        }
98        FFPACK::applyP( F, FFLAS::FflasLeft, FFLAS::FflasTrans, n, 0, R, U, n, P);     
99
100        for ( int i=0; i<m; ++i ){
101                int j=0;
102                for (; j <= ((i<R)?i:R) ; ++j )
103                        F.assign( *(L + i*m+j), *(A+i*n+j));
104                for (; j<m; ++j )
105                        F.assign( *(L+i*m+j), zero);
106        }
107//      cerr<<"P = ";
108//      for (size_t i=0; i<n;++i)
109//              cerr<<" "<<P[i];
110//      cerr<<endl;
111//      cerr<<"Q = ";
112//      for (size_t i=0; i<m;++i)
113//              cerr<<" "<<Q[i];
114//      cerr<<endl;
115       
116//      write_field(F,cerr<<"A = "<<endl,A,m,n,n);
117//      write_field(F,cerr<<"L = "<<endl,L,m,n,n);
118//      write_field(F,cerr<<"U = "<<endl,U,m,n,n);
119
120        Field::Element * B =  read_field(F,argv[2],&m,&n);
121       
122        FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, m,n,n, 1.0,
123                      B, n, U, n, 0.0, X,n);
124        //delete[] A;
125
126        bool fail = false;
127        for (int i=0; i<m; ++i)
128                for (int j=0; j<n; ++j)
129                        if (!F.areEqual (*(L+i*n+j), *(X+i*n+j)))
130                                fail=true;
131       
132        // write_field(F,cerr<<"X = "<<endl,X,m,n,n);
133//      write_field(F,cerr<<"L = "<<endl,L,m,n,n);
134       
135        delete[] B;
136        if (fail)
137                cerr<<"FAIL"<<endl;
138
139
140        else
141                cerr<<"PASS"<<endl;
142               
143//      cout<<m<<" "<<n<<" M"<<endl;
144//      for (size_t i=0; i<m; ++i)
145//              for (size_t j=0; j<n; ++j)
146//                      if (!F.isZero(*(A+i*n+j)))
147//                              cout<<i+1<<" "<<j+1<<" "<<(*(A+i*n+j))<<endl;
148//      cout<<"0 0 0"<<endl;
149
150        delete[] U;
151        delete[] L;
152        delete[] X;
153#endif
154        delete[] A;
155        delete[] P;
156        delete[] Q;
157
158        double t = timc.usertime();
159        double numops = m*m/1000.0*(n-m/3.0);
160       
161        cerr<<m<<"x"<< n 
162            << " : rank = " << R << "  ["
163            << ((double)nbf/1000.0*(double)numops / t) 
164            << " MFops "
165            << " in "
166            << t/nbf<<"s"
167            <<"]"<< endl;
168//      cout<<m
169//          <<" "<<((double)nbf/1000.0*(double)numops / t)
170//          <<" "<<t/nbf
171//          <<endl;
172
173        return 0;
174}
Note: See TracBrowser for help on using the browser.