Debian Codegraph @

examples/solve.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
23 #include "fflas-ffpack/fflas-ffpack.h"
24
25 /**
26 * This example solve the quare system defined by the input
27 * over a defined finite field.
28 *
29 */
30 int main(int argc, char** argv)
31 {
32 if (argc != 4) {
33 std::cerr << "Usage: solve <p> <matrixA> <matrixB>" << std::endl;
34 return -1;
35 }
36
37 int p = atoi(argv[1]);
38 std::string fileA = argv[2];
39 std::string fileB = argv[3];
40
41 // Creating the finite field Z/pZ (assuming p>2, use Modular<float> for p=2)
42 Givaro::ModularBalanced<double> F(p);
43
44 // Reading the matrices
45 double* A, *B, *X;
46 size_t mA, nA, mB, nB;
47 int info = 0;
48 FFLAS::ReadMatrix(fileA.c_str(), F, mA, nA, A);
49 FFLAS::ReadMatrix(fileB.c_str(), F, mB, nB, B);
50 X = FFLAS::fflas_new(F, nA, nB);
51
52 if (mA != nA || mA != mB) {
53 std::cerr << "At least one input matrix has not the right dimension";
54 std::cerr << std::endl;
55 return -1;
56 }
57
58 size_t rank = FFPACK::fgesv(F, FFLAS::FflasLeft, mA, nA, nB, A, nA, X, nB,
59 B, nB, &info);
60
61 if (info){
62 std::cout << "System is inconsistent" << std::endl;
63 return -1;
64 }
65
66 std::cout << "rank: " << rank << std::endl;
67
68 FFLAS::WriteMatrix(std::cout << "debug B" << std::endl, F, mB, nB, B, nB) << std::endl;
69 FFLAS::WriteMatrix(std::cout << "solution" << std::endl, F, nA, nB, X, nB) << std::endl;
70
71 FFLAS::fflas_delete(A);
72 FFLAS::fflas_delete(B);
73 FFLAS::fflas_delete(X);
74
75 return 0;
76 }
77 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
78 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s