-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
137 lines (119 loc) · 3.35 KB
/
test.cpp
File metadata and controls
137 lines (119 loc) · 3.35 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "CMatrix.h"
void testMatrixMult() //Тест матричного умножения
{
vector<cl_float> a_data = {1, 0, 0, 1};
vector<cl_float> b_data = {1, 0, 0, 1};
Matrix a (a_data, 2);
Matrix b (b_data, 2);
ofstream fout("test.txt");
fout << a << '\n';
fout << b << '\n';
fout << a * b;
}
void testMatrixElMult() //Тест поэлементнового умножения
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
vector<cl_float> b_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a (a_data, 3);
Matrix b (b_data, 3);
ofstream fout("test.txt");
fout << a << '\n';
fout << b << '\n';
fout << a % b;
}
void testMatrixSum() //Тест сложения
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
vector<cl_float> b_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a (a_data, 3);
Matrix b (b_data, 3);
ofstream fout("test.txt");
fout << a << '\n';
fout << b << '\n';
fout << a + b;
}
void testMatrixTranspose() //Тест трансонирования
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a(a_data, 3);
ofstream fout("test.txt");
fout << a << '\n';
fout << T(a);
}
void testMatrixNumMult() //Тест умножения на число
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a(a_data, 3);
ofstream fout("test.txt");
fout << a << '\n';
fout << a * 5;
}
void testMatrixNumSum() //Тест сложения с числом
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a(a_data, 3);
ofstream fout("test.txt");
fout << a << '\n';
fout << a - 5;
}
void testMatrixDivision() //Тест деления на число (или деления числа на матрицу)
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a(a_data, 3);
ofstream fout("test.txt");
fout << a << '\n';
fout << a /5;
}
void testComplex() // Тест комплексных матриц
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a(a_data, 3);
ofstream fout("test.txt");
fout << compExp(a);
}
void testInsert()
{
vector<cl_float> a_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Matrix a(a_data, 3);
vector<cl_float> b_data = {13, 14, 15, 16};
Matrix b(b_data, 2);
ofstream fout("test.txt");
fout << a << '\n' << b << '\n';
a.InsertMat(1, 1, b);
fout << a;
}
void testAbs()
{
vector<cl_float> a_data = {-1, 2, -3, 4, 5, -6, -7, -8, 9};
Matrix a(a_data, 3);
ofstream fout("test.txt");
fout << abs(a) << '\n';
}
void testNorm()
{
vector<cl_float> a_data = {-50, 2, -3, 30, 5, -6, -7, -8, 9};
Matrix a(a_data, 3);
ofstream fout("test.txt");
fout << norm(a, "inf") << '\n' << norm(a, "1") << '\n' << norm(a, "sum") << '\n';
}
void testE()
{
ofstream fout("test.txt");
fout << E(5) <<'\n';
}
int main()
{
//Раскомментировать нужный тест
//testMatrixMult();
//testMatrixTranspose();
//testMatrixElMult();
//testMatrixSum();
//testMatrixNumMult();
//testComplex();
//testMatrixNumSum();
//testMatrixDivision();
//testInsert();
//testAbs();
//testNorm();
//testE();
}