1 /* Copyright (c) FFLAS-FFPACK
2  * Written by Philippe LEDENT
3  * philippe.ledent@etu.univ-grenoble-alpes.fr
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 "fflas-ffpack/utils/fflas_randommatrix.h"
28 #include <iostream>
29 
30 using namespace FFLAS;
31 
main(int argc,char ** argv)32 int main(int argc, char** argv) {
33     std::cout << "" << std::endl;
34     typedef Givaro::Modular<float> Float_Field;
35     Float_Field F(101);
36 
37     // Let m be a natural
38     const size_t m = 11, inca = 1;
39     // Let a be a m by 1 random vector
40     Float_Field::Element_ptr a;
41     a = fflas_new(F,m,1);
42     uint64_t seed = time(NULL);
43     typename Float_Field::RandIter G(F,0,seed);
44     frand(F,G,m,a,inca);
45 
46     // Let n be natural
47     // Let b be a 1 by n random vector
48     const size_t n = 13, incb = 1;
49     Float_Field::Element_ptr b;
50     b = fflas_new(F,1,n);
51 
52     frand(F,G,n,b,incb);
53 
54     // Let A be an m by n matrix obtained by the outer product between a and b
55     const size_t lda = n;
56     Float_Field::Element_ptr A;
57     A = fflas_new(F,m,n);
58     fger(F,m,n,F.one,a,inca,b,incb,A,lda);
59 
60 
61 
62     // Let C be an n by 1 vector such that C
63     const size_t incc = 1;
64     Float_Field::Element_ptr c;
65     c = fflas_new(F,m,1);
66 
67     frand(F,G,m,c,incc);
68 
69     // Let d be a scalar where d = b dot c
70     Float_Field::Element d;
71     d = fdot(F,n,b,incb,c,incc);
72 
73     // Let e be a copy of a
74     Float_Field::Element_ptr e;
75     e = fflas_new(F,m,1);
76     fassign(F,m,1,a,inca,e,inca);
77 
78     // Compute   e :=  (d scalar e) - (A times c)
79     // Therefore e := -(A times c)  + (d scalar e)
80     fgemv(F,FFLAS::FflasNoTrans,m,n,F.mOne,A,lda,c,incc,d,e,inca);
81 
82     // If e is the zero vector then
83 
84     // Is a the  zero vector ?
85     bool res = fiszero(F,m,e,inca);
86 
87 
88     //Output
89     WriteMatrix(std::cout<<"a:=\n",F,m,1,a,inca)<<std::endl;
90     WriteMatrix(std::cout<<"b:= ",F,1,n,b,incb)<<std::endl;
91     WriteMatrix(std::cout<<"A:=\n",F,m,n,A,lda)<<std::endl;
92     WriteMatrix(std::cout<<"c:=\n",F,m,1,c,incc)<<std::endl;
93     //WriteMatrix(std::cout<<"d:=",F,1,1,d,1)<<std::endl;
94     WriteMatrix(std::cout<<"e:=\n",F,m,1,e,inca)<<std::endl;
95     std::cout<<"Is e the zero vector ?"<< std::endl;
96     if(res)
97         std::cout<<"TRUE"<< std::endl;
98     else
99         std::cout<<"FALSE"<< std::endl;
100 
101     // note :
102     // There are many routines that create random matrices.
103     // They can be found in fflas-ffpack/utils/fflas_randommatrix.
104 
105 
106 
107 
108 
109     // Clearing up the memory
110     fflas_delete(a);
111     fflas_delete(b);
112     fflas_delete(A);
113     fflas_delete(c);
114     fflas_delete(e);
115 
116 }
117 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
118 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
119