root / tests / test-krylov-elim.C

Revision 1, 2.2 kB (checked in by pernet, 2 years ago)

Import de fflas-ffpack

Line 
1/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2//--------------------------------------------------------------------------
3//          Test for the krylov-elimination
4//--------------------------------------------------------------------------
5// usage: test-krylov-elim p A, to compute the rank profile of the (n+m)xn matrix B
6// formed by the n identity vectors and the mxn matrix A over Z/pZ
7//-------------------------------------------------------------------------
8
9//-------------------------------------------------------------------------
10#define DEBUG 0
11
12#include <iostream>
13#include "Matio.h"
14#include "timer.h"
15using namespace std;
16#include "fflas-ffpack/modular-balanced.h"
17#include "fflas-ffpack/ffpack.h"
18
19
20typedef Modular<double> Field;
21
22template<class T>
23std::ostream& printvect(std::ostream& o, T* vect, size_t dim){
24        for(size_t i=0; i<dim; ++i)
25                o << vect[i] << " " ;
26        return o << std::endl;
27}
28
29int main(int argc, char** argv){
30
31        int m,n;
32
33       
34        if (argc!=3){
35                cerr<<"usage : test-lqup <p> <A>"<<endl
36                    <<"         to compute the rank profile of the (n+m)xn matrix B formed by the n identity vectors and the mxn matrix A over Z/pZ"
37                    <<endl;
38                exit(-1);
39        }
40        Field F(atoi(argv[1]));
41        Field::Element one;
42        F.init(one, 1UL);
43        Field::Element * A = read_field<Field> (F,argv[2],&m,&n);
44
45        Field::Element * B = new Field::Element[(m+n)*n];
46        for (size_t i=0; i<(n+m)*n;++i) *(B+i)=0;
47
48        size_t deg = (n-1)/m+1;
49        size_t curr_row = 0;
50        size_t it_idx = 0;
51        size_t bk_idx = 0;
52        for (size_t i=0; i<m; ++i){
53                for (size_t j=0; j<deg; ++j){
54                        if (curr_row < n+m -1){
55                                F.assign( *(B + curr_row*n + n-1 - it_idx), one);
56                                curr_row++;
57                                it_idx++;
58                        }
59                }
60                for (size_t j=0; j<n; ++j)
61                        *(B + curr_row*n + j) = *(A + bk_idx*n + j);
62                bk_idx++;
63                curr_row++;
64        }
65        write_field (F, cout<<"A = "<<endl, A, m,n,n);
66        write_field (F, cout<<"B = "<<endl, B, m+n,n,n);
67
68        size_t *rp = new size_t[n];
69
70        FFPACK::SpecRankProfile(F, m, n, A, n, deg,rp);
71
72        size_t * P = new size_t[n];
73        size_t * Q = new size_t[n+m];
74        FFPACK::LUdivine(F, FFLAS::FflasNonUnit, m+n, n, B, n, P, Q, FFPACK::FfpackLQUP);
75
76        printvect (cout<<"RankProfile (A) = "<<endl, rp, n)<<endl;
77
78        printvect (cout<<"RankProfile (B) = "<<endl, Q, n)<<endl;
79
80
81       
82       
83        return 0;             
84}
Note: See TracBrowser for help on using the browser.