Debian Codegraph @

tutorials/fflas-101_1.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * Written by Philippe LEDENT <[email protected]>
3 *
4 * ========LICENCE========
5 * This file is part of the library FFLAS-FFPACK.
6 *
7 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * ========LICENCE========
21 */
22
23 #include <fflas-ffpack/fflas/fflas.h>
24 #include <givaro/modular.h>
25 #include <givaro/modular-balanced.h>
26 #include "fflas-ffpack/utils/fflas_io.h"
27 #include <iostream>
28
29 using namespace FFLAS;
30
31 int main(int argc, char** argv) {
32 std::cout << "" << std::endl;
33 typedef Givaro::Modular<float> Float_Field;
34 Float_Field F(101);
35 uint64_t seed = time(NULL);
36 typename Float_Field::RandIter G(F,seed);
37
38 // Let p and q be naturals
39 const size_t p = 7, q = 11, lda = q;
40 // Let A be a p times q random matrix
41 Float_Field::Element_ptr A;
42 A = fflas_new(F,p,q);
43 frand(F,G,p,q,A,lda);
44
45 // Let m and n be naturals such that (0 < m <= p && 0 < n <= q)
46 const size_t m = 5, n = 10;
47 // Let B be a m times n sub matrix of A where B[0][0] = A[1][2]
48 const size_t ldb = lda;
49 Float_Field::Element_ptr B = A + 1*lda + 2;
50
51 // Let C be a m times n random matrix
52 const size_t ldc = m;
53 Float_Field::Element_ptr C;
54 C = fflas_new(F,m,n);
55 frand(F,G,m,n,C,ldc);
56
57 // Let D be a m times n matrix
58 // where D := B - C
59 const size_t ldd = m;
60 Float_Field::Element_ptr D;
61 D = fflas_new(F,m,n);
62 fsub(F,m,n,B,ldb,C,ldc,D,ldd);
63
64 // Similar routines :
65 // add(F,m,n,B,ldb,C,ldc,D,ldd); // D := B + C
66 // subin(F,m,n,B,ldb,C,ldc); // C := B - C
67 // addin(F,m,n,B,ldc,C,ldc); // C := B + C
68
69 // if B == C then D == zeroMatrix
70 bool res = fiszero(F,m,n,D,ldd);
71
72
73 //Output
74 WriteMatrix(std::cout<<"A:="<<std::endl,F,p,q,A,lda)<<std::endl;
75 WriteMatrix(std::cout<<"B:="<<std::endl,F,m,n,B,ldb)<<std::endl;
76 WriteMatrix(std::cout<<"C:="<<std::endl,F,m,n,C,ldc)<<std::endl;
77 WriteMatrix(std::cout<<"D:="<<std::endl,F,m,n,D,ldd)<<std::endl;
78 std::cout<<"Is D the zero matrix ?"<< std::endl;
79 if(res)
80 std::cout<<"TRUE"<< std::endl;
81 else
82 std::cout<<"FALSE"<< std::endl;
83
84 // Clearing up the memory
85 fflas_delete(A);
86 fflas_delete(C);
87 fflas_delete(D);
88
89 }
90
91 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
92 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s