Tutorial_sparse_example.cpp
Go to the documentation of this file.
1 #include <Eigen/Sparse>
2 #include <vector>
3 #include <iostream>
4 
5 typedef Eigen::SparseMatrix<double> SpMat; // declares a column-major sparse matrix type of double
7 
8 void buildProblem(std::vector<T>& coefficients, Eigen::VectorXd& b, int n);
9 void saveAsBitmap(const Eigen::VectorXd& x, int n, const char* filename);
10 
11 int main(int argc, char** argv)
12 {
13  if(argc!=2) {
14  std::cerr << "Error: expected one and only one argument.\n";
15  return -1;
16  }
17 
18  int n = 300; // size of the image
19  int m = n*n; // number of unknowns (=number of pixels)
20 
21  // Assembly:
22  std::vector<T> coefficients; // list of non-zeros coefficients
23  Eigen::VectorXd b(m); // the right hand side-vector resulting from the constraints
24  buildProblem(coefficients, b, n);
25 
26  SpMat A(m,m);
27  A.setFromTriplets(coefficients.begin(), coefficients.end());
28 
29  // Solving:
30  Eigen::SimplicialCholesky<SpMat> chol(A); // performs a Cholesky factorization of A
31  Eigen::VectorXd x = chol.solve(b); // use the factorization to solve for the given right hand side
32 
33  // Export the result to a file:
34  saveAsBitmap(x, n, argv[1]);
35 
36  return 0;
37 }
38 
Eigen::SparseMatrix< double >
buildProblem
void buildProblem(std::vector< T > &coefficients, Eigen::VectorXd &b, int n)
Definition: Tutorial_sparse_example_details.cpp:19
b
Scalar * b
Definition: benchVecAdd.cpp:17
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
T
Eigen::Triplet< double > T
Definition: Tutorial_sparse_example.cpp:6
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
n
int n
Definition: BiCGSTAB_simple.cpp:1
A
Definition: test_numpy_dtypes.cpp:298
relicense.filename
filename
Definition: relicense.py:57
SpMat
Eigen::SparseMatrix< double > SpMat
Definition: Tutorial_sparse_example.cpp:5
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
Eigen::Triplet< double >
Eigen::SimplicialCholesky
Definition: SimplicialCholesky.h:276
saveAsBitmap
void saveAsBitmap(const Eigen::VectorXd &x, int n, const char *filename)
Definition: Tutorial_sparse_example_details.cpp:37
main
int main(int argc, char **argv)
Definition: Tutorial_sparse_example.cpp:11


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:18:19