File: solve.C

package info (click to toggle)
fflas-ffpack 2.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,200 kB
  • sloc: cpp: 26,712; makefile: 784; sh: 430; csh: 95; ansic: 20
file content (78 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Copyright (c) FFLAS-FFPACK
 * ========LICENCE========
 * This file is part of the library FFLAS-FFPACK.
 *
 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
 * it under the terms of the  GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * ========LICENCE========
 */

#include <iostream>

#include "fflas-ffpack/fflas-ffpack.h"

/**
 * This example solve the quare system defined by the input
 * over a defined finite field.
 *
 */
int main(int argc, char** argv)
{
    if (argc != 4) {
        std::cerr << "Usage: solve <p> <matrixA> <matrixB>" << std::endl;
        return -1;
    }

    int p = atoi(argv[1]);
    std::string fileA = argv[2];
    std::string fileB = argv[3];

    // Creating the finite field Z/pZ (assuming p>2, use Modular<float> for p=2)
    Givaro::ModularBalanced<double> F(p);

    // Reading the matrices
    double* A, *B, *X;
    size_t mA, nA, mB, nB;
    int info = 0;
    FFLAS::ReadMatrix(fileA.c_str(), F, mA, nA, A);
    FFLAS::ReadMatrix(fileB.c_str(), F, mB, nB, B);
    X = FFLAS::fflas_new(F, nA, nB);

    if (mA != nA || mA != mB) {
        std::cerr << "At least one input matrix has not the right dimension";
        std::cerr  << std::endl;
        return -1;
    }

    size_t rank = FFPACK::fgesv(F, FFLAS::FflasLeft, mA, nA, nB, A, nA, X, nB,
                                B, nB, &info);

    if (info){
        std::cout << "System is inconsistent" << std::endl;
        return -1;
    }

    std::cout << "rank: " << rank << std::endl;

    FFLAS::WriteMatrix(std::cout << "debug B" << std::endl, F, mB, nB, B, nB) << std::endl;
    FFLAS::WriteMatrix(std::cout << "solution" << std::endl, F, nA, nB, X, nB) << std::endl;

    FFLAS::fflas_delete(A);
    FFLAS::fflas_delete(B);
    FFLAS::fflas_delete(X);

    return 0;
}
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s