forked from Cryoris/matplotlib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspy.cpp
More file actions
41 lines (34 loc) · 748 Bytes
/
spy.cpp
File metadata and controls
41 lines (34 loc) · 748 Bytes
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
#include <vector>
#include <Eigen/Dense>
#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
const unsigned n = 100;
Eigen::MatrixXd A(n / 2, n);
std::vector<std::vector<double>> B;
for (unsigned i = 0; i < n / 2; ++i) {
A(i, i) = 1;
std::vector<double> row(n);
row[i] = 1;
if (i < n / 2) {
A(i, i + n / 2) = 1;
row[i + n / 2] = 1;
}
B.push_back(row);
}
for (unsigned i = 0; i < n / 2; ++i) {
for (unsigned j = 0; j < n; ++j) {
if (A(i, j) != B[i][j]) {
std::cout << i << "," << j << " differ!\n";
}
}
}
plt::figure();
plt::title("Eigen");
plt::spy(A);
plt::figure();
plt::title("vector");
plt::spy(B);
plt::show();
return 0;
}