Skip to content

Instantly share code, notes, and snippets.

@bchretien
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bchretien/29827af68edae49cd6d7 to your computer and use it in GitHub Desktop.
Save bchretien/29827af68edae49cd6d7 to your computer and use it in GitHub Desktop.
#include <Eigen/Sparse>
#include <iostream>
using namespace Eigen;
typedef SparseMatrix<double> sparseMatrix_t;
typedef SparseVector<double> sparseVector_t;
typedef MatrixXd denseMatrix_t;
typedef VectorXd denseVector_t;
int main(int argc, char *argv[])
{
IOFormat ioformat = IOFormat (StreamPrecision,
DontAlignCols,
",", ",", "", "", "(", ")");
ioformat.rowSpacer = "";
sparseMatrix_t m1 (1, 2);
m1.insert (0, 0) = 1.;
m1.insert (0, 1) = 2.;
sparseMatrix_t m2 (2, 1);
m2.insert (0, 0) = 1.;
m2.insert (1, 0) = 2.;
sparseVector_t v (2);
v.insert (0) = 1.;
v.insert (1) = 2.;
std::cout << denseMatrix_t (m1).format (ioformat) << std::endl;
std::cout << denseMatrix_t (m2).format (ioformat) << std::endl;
std::cout << denseVector_t (v).format (ioformat) << std::endl;
v += m1.transpose ();
std::cout << denseVector_t (v).format (ioformat) << std::endl;
v += m2;
std::cout << denseVector_t (v).format (ioformat) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment