root / tests / test-rowechelon.C

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