Debian Codegraph @

examples/pluq.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * ========LICENCE========
3 * This file is part of the library FFLAS-FFPACK.
4 *
5 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * ========LICENCE========
19 */
20
21 #include <iostream>
22 #include <givaro/modular.h>
23 #include "fflas-ffpack/fflas-ffpack-config.h"
24 #include "fflas-ffpack/fflas-ffpack.h"
25 #include "fflas-ffpack/utils/fflas_io.h"
26
27 using namespace std;
28
29 int main(int argc, char** argv) {
30
31 if (argc != 3){
32 std::cerr<<"Usage: pluq <p> <matrix>"<<std::endl;
33 return -1;
34 }
35
36 int p = atoi(argv[1]);
37 std::string file = argv[2];
38 size_t m,n;
39
40 // Creating the finite field Z/qZ
41 Givaro::Modular<double> F(p);
42
43 // Reading the matrix from a file
44 double *A;
45 FFLAS::ReadMatrix (file.c_str(),F,m,n,A);
46
47 size_t * P = FFLAS::fflas_new<size_t>(m);
48 size_t * Q = FFLAS::fflas_new<size_t>(n);
49
50 size_t r = FFPACK::PLUQ (F, FFLAS::FflasNonUnit, m, n, A, n, P, Q);
51
52
53 FFLAS::WritePermutation (std::cout<<"P = "<<std::endl,P,m);
54
55 // Displays L and U separately
56 double * L = FFLAS::fflas_new<double>(m * r);
57 double * U = FFLAS::fflas_new<double>(r * n);
58 FFPACK::getTriangular(F, FFLAS::FflasLower, FFLAS::FflasUnit, m, n, r, A, n, L, r, true);
59 FFPACK::getTriangular(F, FFLAS::FflasUpper, FFLAS::FflasNonUnit, m, n, r, A, n, U, n, true);
60 FFLAS::WriteMatrix(std::cout<<"L = "<<std::endl, F, m, r, L, r);
61 std::cout<<"modulo "<<p<<std::endl;
62 FFLAS::WriteMatrix(std::cout<<"U = "<<std::endl, F, r, n, U, n);
63 std::cout<<"modulo "<<p<<std::endl;
64
65 FFLAS::WritePermutation (std::cout<<"Q = "<<std::endl,Q,n);
66
67 FFLAS::fflas_delete( P);
68 FFLAS::fflas_delete( Q);
69 FFLAS::fflas_delete( A);
70 FFLAS::fflas_delete( L);
71 FFLAS::fflas_delete( U);
72
73 return 0;
74 }
75
76 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
77 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s