Skip to content

Instantly share code, notes, and snippets.

@bchretien
Last active August 29, 2015 14:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
#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