-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmatrix.cpp
More file actions
60 lines (50 loc) · 1.3 KB
/
Cmatrix.cpp
File metadata and controls
60 lines (50 loc) · 1.3 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
#include "Cmatrix.h"
Cmatrix operator* (const Cmatrix& a, const Cmatrix& b)
{
Cmatrix res;
res.real = (a.real * b.real) - (a.imag * b.imag);
res.imag = (a.real * b.imag) + (a.imag * b.real);
return res;
}
Cmatrix operator+ (const Cmatrix& a, const Cmatrix& b)
{
Cmatrix res;
res.real = a.real + b.real;
res.imag = a.imag + b.imag;
return res;
}
Cmatrix operator% (const Cmatrix& a, const Cmatrix& b)
{
Cmatrix res;
res.real = a.real % b.real - a.imag % b.imag;
res.imag = a.real % b.imag + a.imag % b.real;
return res;
}
Cmatrix compExp(const Matrix& a)
{
Cmatrix res;
function<cl_float(cl_float)> Msin = [] (cl_float x) { return (cl_float) sin(x); };
function<cl_float(cl_float)> Mcos = [] (cl_float x) { return (cl_float) cos(x); };;
res.imag = applyFuncToMatrix(Msin, a);
res.real = applyFuncToMatrix(Mcos, a);
return res;
}
ostream& operator<< (ostream &os, const Cmatrix &a)
{
for (int i = 0; i < a.real.h; i++)
{
for (int j = 0; j < a.real.w; j++)
{
os << a.real.data[i * a.real.w + j] << "+i*" << a.imag.data[i * a.real.w + j] << " ";
}
os << '\n';
}
return os;
}
Cmatrix T(const Cmatrix& a)
{
Cmatrix res;
res.real = T(a.real);
res.imag = T(a.imag);
return res;
}