root / tests / test-redcolechelon.C

Revision 26, 4.2 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 reduced column echelon factorisation
4//--------------------------------------------------------------------------
5// usage: test-redcolechelon p A n, for n reduced column echelon 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-redcolechelon <p> <A> <i>"<<endl
34                    <<"        to do i reduced column  echelon computations 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::ReducedColumnEchelonForm (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       
87        for (int i=0; i<R; ++i){
88                for (int j=0; j<n; ++j)
89                        F.assign (*(U + i*n + j), *(A+ i*n+j));
90        }
91        for (int i=R;i<n; ++i){
92                for (int j=0; j<n; ++j)
93                        F.assign(*(U+i*n+j), zero);
94                F.init(*(U+i*(n+1)),one);
95        }
96        FFPACK::applyP( F, FFLAS::FflasLeft, FFLAS::FflasTrans, n, 0, R, U, n, P);     
97
98        for ( int i=0; i<R; ++i ){
99                for (int j=0; j < n ; ++j)
100                        F.assign( *(L + i*n+j),zero);
101                F.assign(*(L+i*(n+1)), one);
102        }
103        for ( int i=R; i<m; ++i ){
104                for (int j=0; j<R; ++j )
105                        F.assign (*(L+i*n+j), *(A+i*n+j));
106                for (int j=R; j<n; ++j)
107                        F.assign (*(L+i*n+j), zero);
108        }
109        FFPACK::applyP( F, FFLAS::FflasLeft, FFLAS::FflasTrans, n, 0, R, L, n, Q);
110
111//      cerr<<"P = ";
112//      for (size_t i=0; i<n;++i)
113//              cerr<<" "<<P[i];
114//      cerr<<endl;
115//      cerr<<"Q = ";
116//      for (size_t i=0; i<m;++i)
117//              cerr<<" "<<Q[i];
118//      cerr<<endl;
119       
120        // write_field(F,cerr<<"A = "<<endl,A,m,n,n);
121        //      write_field(F,cerr<<"R = "<<endl,L,m,n,n);
122        //write_field(F,cerr<<"U = "<<endl,U,m,n,n);
123
124        Field::Element * B =  read_field(F,argv[2],&m,&n);
125       
126        FFLAS::fgemm (F, FFLAS::FflasNoTrans, FFLAS::FflasNoTrans, m,n,n, 1.0,
127                      B, n, U, n, 0.0, X,n);
128        //delete[] A;
129
130        bool fail = false;
131        for (int i=0; i<m; ++i)
132                for (int j=0; j<n; ++j)
133                        if (!F.areEqual (*(L+i*n+j), *(X+i*n+j)))
134                                fail=true;
135       
136//      write_field(F,cerr<<"X = "<<endl,X,m,n,n);
137//      write_field(F,cerr<<"R = "<<endl,L,m,n,n);
138       
139        delete[] B;
140        if (fail)
141                cerr<<"FAIL"<<endl;
142
143
144        else
145                cerr<<"PASS"<<endl;
146               
147//      cout<<m<<" "<<n<<" M"<<endl;
148//      for (size_t i=0; i<m; ++i)
149//              for (size_t j=0; j<n; ++j)
150//                      if (!F.isZero(*(A+i*n+j)))
151//                              cout<<i+1<<" "<<j+1<<" "<<(*(A+i*n+j))<<endl;
152//      cout<<"0 0 0"<<endl;
153
154        delete[] U;
155        delete[] L;
156        delete[] X;
157#endif
158        delete[] A;
159        delete[] P;
160        delete[] Q;
161
162        double t = timc.usertime();
163        double numops = 2*m*m/1000.0*n;
164       
165        cerr<<m<<"x"<< n 
166            << " : rank = " << R << "  ["
167            << ((double)nbf/1000.0*(double)numops / t) 
168            << " MFops "
169            << " in "
170            << t/nbf<<"s"
171            <<"]"<< endl;
172//      cout<<m
173//          <<" "<<((double)nbf/1000.0*(double)numops / t)
174//          <<" "<<t/nbf
175//          <<endl;
176
177        return 0;
178}
Note: See TracBrowser for help on using the browser.