-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (54 loc) · 2.19 KB
/
main.cpp
File metadata and controls
65 lines (54 loc) · 2.19 KB
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
#include <iostream>
#include "algebra.hpp"
#include <complex>
#include "chrono.hpp"
int main(){
//operations with the matrix imported from MatrixMarket and comparison between compressed and
//uncompressed state multiplication with a vector of random values between 0 and 10
//the column vector is stored as a 131x1 matrix, we could also have used a normal std::vector
//by using the function algebra::generate_vector().
//You can also easily check the column_wise case by changing the declaration of M
std::cout << "Multiplication operation: comparison between compressed and uncompressed case:" << std::endl;
Timings::Chrono clock;
algebra::Matrix<double, algebra::row_wise> M;
M.read("lnsp_131.mtx");
algebra::Matrix<double, algebra::row_wise> v= algebra::generate_column_vector<double, algebra::row_wise>(131,0,10);
//v.print();
clock.start();
auto a=M*v;
clock.stop();
//algebra::print(a);
double t1=clock.wallTime();
std::cout << "Uncompressed matrix: " << clock;
M.compress();
clock.start();
auto b=M*v;
clock.stop();
//algebra::print(b);
double t2=clock.wallTime();
std::cout << "Compressed matrix: " << clock;
std::cout << "Compressed multiplication is " << t1/t2 << " times faster!" << std::endl << std::endl;
double normM = M.norm<algebra::frobenius>();
std::cout << "Frobenius norm of M: " << normM << std::endl;
M.uncompress();
//Everything works also with complex numbers! Below I provide a simple example, you can uncomment
//the output lines to check the results:
std::complex<double> z1(0,3);
std::complex<double> z2(2,1);
std::complex<double> z3(5,4);
std::complex<double> z4(1,3);
std::complex<double> z0(0,0);
algebra::Matrix<std::complex<double>, algebra::column_wise> N({{z1, z0, z0}, {z2, z0, z3}, {z0, z0, z2}});
N(2,1)=z4;
//N.print();
//double normN = N.norm<algebra::infinity>();
//std::cout << "Infinity norm of the matrix: " << normN << std::endl;
std::vector<std::complex<double>> v2({z1, z3, z4});
//algebra::print(v2);
auto c=N*v2;
//algebra::print(c);
N.compress();
//N.print();
N.uncompress();
//N.print();
}