Debian Codegraph @

tutorials/2x2-ftrsv.C

raw
1 /* Copyright (c) 2017 FFLAS-FFPACK
2 * Written by Jean-Guillaume Dumas <[email protected]>
3 * ========LICENCE========
4 * This file is part of the library FFLAS-FFPACK.
5 *
6 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * ========LICENCE========
20 */
21
22
23 #include <fflas-ffpack/fflas-ffpack-config.h>
24 #include <givaro/modular-balanced.h>
25 #include <fflas-ffpack/fflas/fflas.h>
26 #include <fflas-ffpack/utils/timer.h>
27 #include <fflas-ffpack/utils/fflas_io.h>
28 #include <fflas-ffpack/utils/args-parser.h>
29
30 #include <iostream>
31 #include <array>
32
33 using namespace FFLAS;
34
35 int main(int argc, char** argv) {
36
37 typedef Givaro::Modular<float> Ring;
38 Ring F(11);
39
40 Ring::Element L[4]{1,0,2,3};
41 Ring::Element B[2]{4,5};
42
43 size_t m(2);
44
45 FFLAS::WriteMatrix (std::cout << "L:=", F, m, m, L, m) << std::endl;
46 FFLAS::WriteMatrix (std::cout << "B:=", F, m, 1, B, 1) << std::endl;
47
48 // In place system solve
49 ftrsv (F, FflasLower,FflasNoTrans,FflasNonUnit, m, L, m, B, 1);
50
51 FFLAS::WriteMatrix (std::cout << "X:=", F, m, 1, B, 1) << std::endl;
52 std::cerr << "0 = L.X - B mod " << F.characteristic() << ';' << std::endl;
53
54 Ring::Element U[4]{3,2,0,5}, C[2]{4,7};
55
56
57 FFLAS::WriteMatrix (std::cout << "U:=", F, m, m, U, m) << std::endl;
58 FFLAS::WriteMatrix (std::cout << "C:=", F, m, 1, C, 1) << std::endl;
59
60 // In place system solve
61 ftrsv (F, FflasUpper, FflasNoTrans ,FflasNonUnit, m, U, m, B, 1);
62
63 FFLAS::WriteMatrix (std::cout << "X:=", F, m, 1, C, 1) << std::endl;
64 std::cerr << "0 = U.X - C mod " << F.characteristic() << ';' << std::endl;
65
66 Ring::Element D[2]{4,5};
67
68 FFLAS::WriteMatrix (std::cout << "L:=", F, m, m, L, m) << std::endl;
69 FFLAS::WriteMatrix (std::cout << "D:=", F, m, 1, D, 1) << std::endl;
70
71 // In place system solve
72 ftrsv (F, FflasLower,FflasTrans,FflasNonUnit, m, L, m, D, 1);
73
74 FFLAS::WriteMatrix (std::cout << "X:=", F, m, 1, D, 1) << std::endl;
75 std::cerr << "0 = Transpose(X).L - Transpose(D) mod " << F.characteristic() << ';' << std::endl;
76
77 Ring::Element E[2]{4,7};
78
79
80 FFLAS::WriteMatrix (std::cout << "U:=", F, m, m, U, m) << std::endl;
81 FFLAS::WriteMatrix (std::cout << "E:=", F, m, 1, E, 1) << std::endl;
82
83 // In place system solve
84 ftrsv (F, FflasUpper, FflasTrans ,FflasNonUnit, m, U, m, E, 1);
85
86 FFLAS::WriteMatrix (std::cout << "X:=", F, m, 1, E, 1) << std::endl;
87 std::cerr << "0 = Transpose(X).U - Transpose(E) mod " << F.characteristic() << ';' << std::endl;
88
89 return 0;
90 }
91
92 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
93 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s