Clang-format tests, examples, libraries, benchmarks, etc.

This commit is contained in:
Antonio Sánchez
2023-12-05 21:22:55 +00:00
committed by Rasmus Munk Larsen
parent 3252ecc7a4
commit 46e9cdb7fe
876 changed files with 33453 additions and 37795 deletions

View File

@@ -1,5 +1,4 @@
Matrix3f m;
m = AngleAxisf(0.25*M_PI, Vector3f::UnitX())
* AngleAxisf(0.5*M_PI, Vector3f::UnitY())
* AngleAxisf(0.33*M_PI, Vector3f::UnitZ());
m = AngleAxisf(0.25 * M_PI, Vector3f::UnitX()) * AngleAxisf(0.5 * M_PI, Vector3f::UnitY()) *
AngleAxisf(0.33 * M_PI, Vector3f::UnitZ());
cout << m << endl << "is unitary: " << m.isUnitary() << endl;

View File

@@ -1,5 +1,2 @@
ArrayXXi a {
{1, 2, 3},
{3, 4, 5}
};
ArrayXXi a{{1, 2, 3}, {3, 4, 5}};
cout << a << endl;

View File

@@ -1,2 +1,2 @@
Array<int, Dynamic, 1> v {{1, 2, 3, 4, 5}};
Array<int, Dynamic, 1> v{{1, 2, 3, 4, 5}};
cout << v << endl;

View File

@@ -1,3 +1,3 @@
Array<int, 1, 6> a(1, 2, 3, 4, 5, 6);
Array<int, 3, 1> b {1, 2, 3};
Array<int, 3, 1> b{1, 2, 3};
cout << a << "\n\n" << b << endl;

View File

@@ -1,11 +1,11 @@
int n = 10000;
VectorXd x(n), b(n);
SparseMatrix<double> A(n,n);
/* ... fill A and b ... */
BiCGSTAB<SparseMatrix<double> > solver;
solver.compute(A);
x = solver.solve(b);
std::cout << "#iterations: " << solver.iterations() << std::endl;
std::cout << "estimated error: " << solver.error() << std::endl;
/* ... update b ... */
x = solver.solve(b); // solve again
int n = 10000;
VectorXd x(n), b(n);
SparseMatrix<double> A(n, n);
/* ... fill A and b ... */
BiCGSTAB<SparseMatrix<double> > solver;
solver.compute(A);
x = solver.solve(b);
std::cout << "#iterations: " << solver.iterations() << std::endl;
std::cout << "estimated error: " << solver.error() << std::endl;
/* ... update b ... */
x = solver.solve(b); // solve again

View File

@@ -1,14 +1,14 @@
int n = 10000;
VectorXd x(n), b(n);
SparseMatrix<double> A(n,n);
/* ... fill A and b ... */
BiCGSTAB<SparseMatrix<double> > solver(A);
// start from a random solution
x = VectorXd::Random(n);
solver.setMaxIterations(1);
int i = 0;
do {
x = solver.solveWithGuess(b,x);
std::cout << i << " : " << solver.error() << std::endl;
++i;
} while (solver.info()!=Success && i<100);
int n = 10000;
VectorXd x(n), b(n);
SparseMatrix<double> A(n, n);
/* ... fill A and b ... */
BiCGSTAB<SparseMatrix<double> > solver(A);
// start from a random solution
x = VectorXd::Random(n);
solver.setMaxIterations(1);
int i = 0;
do {
x = solver.solveWithGuess(b, x);
std::cout << i << " : " << solver.error() << std::endl;
++i;
} while (solver.info() != Success && i < 100);

View File

@@ -4,5 +4,5 @@ cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the matrix y:" << endl << y << endl;
Matrix3f x;
x = m.colPivHouseholderQr().solve(y);
assert(y.isApprox(m*x));
assert(y.isApprox(m* x));
cout << "Here is a solution x to the equation mx=y:" << endl << x << endl;

View File

@@ -1,4 +1,4 @@
MatrixXcf A = MatrixXcf::Random(4,4);
MatrixXcf A = MatrixXcf::Random(4, 4);
cout << "Here is a random 4x4 matrix, A:" << endl << A << endl << endl;
ComplexEigenSolver<MatrixXcf> ces;

View File

@@ -1,4 +1,3 @@
MatrixXcf ones = MatrixXcf::Ones(3,3);
MatrixXcf ones = MatrixXcf::Ones(3, 3);
ComplexEigenSolver<MatrixXcf> ces(ones, /* computeEigenvectors = */ false);
cout << "The eigenvalues of the 3x3 matrix of ones are:"
<< endl << ces.eigenvalues() << endl;
cout << "The eigenvalues of the 3x3 matrix of ones are:" << endl << ces.eigenvalues() << endl;

View File

@@ -1,4 +1,3 @@
MatrixXcf ones = MatrixXcf::Ones(3,3);
MatrixXcf ones = MatrixXcf::Ones(3, 3);
ComplexEigenSolver<MatrixXcf> ces(ones);
cout << "The first eigenvector of the 3x3 matrix of ones is:"
<< endl << ces.eigenvectors().col(0) << endl;
cout << "The first eigenvector of the 3x3 matrix of ones is:" << endl << ces.eigenvectors().col(0) << endl;

View File

@@ -1,4 +1,4 @@
MatrixXcf A = MatrixXcf::Random(4,4);
MatrixXcf A = MatrixXcf::Random(4, 4);
ComplexSchur<MatrixXcf> schur(4);
schur.compute(A);
cout << "The matrix T in the decomposition of A is:" << endl << schur.matrixT() << endl;

View File

@@ -1,4 +1,4 @@
MatrixXcf A = MatrixXcf::Random(4,4);
MatrixXcf A = MatrixXcf::Random(4, 4);
cout << "Here is a random 4x4 matrix, A:" << endl << A << endl << endl;
ComplexSchur<MatrixXcf> schurOfA(A, false); // false means do not compute U
ComplexSchur<MatrixXcf> schurOfA(A, false); // false means do not compute U
cout << "The triangular matrix T is:" << endl << schurOfA.matrixT() << endl;

View File

@@ -1,4 +1,4 @@
MatrixXcf A = MatrixXcf::Random(4,4);
MatrixXcf A = MatrixXcf::Random(4, 4);
cout << "Here is a random 4x4 matrix, A:" << endl << A << endl << endl;
ComplexSchur<MatrixXcf> schurOfA(A);
cout << "The unitary matrix U is:" << endl << schurOfA.matrixU() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,-2,-3);
Array3d v(1, -2, -3);
cout << v.abs() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,-2,-3);
Array3d v(1, -2, -3);
cout << v.abs2() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(0, sqrt(2.)/2, 1);
Array3d v(0, sqrt(2.) / 2, 1);
cout << v.acos() << endl;

View File

@@ -1,4 +1,3 @@
Array<double,1,3> x(8,-25,3),
y(1./3.,0.5,-2.);
cout << "atan2([" << x << "], [" << y << "]) = " << x.atan2(y) << endl; // using ArrayBase::pow
cout << "atan2([" << x << "], [" << y << "] = " << atan2(x,y) << endl; // using Eigen::pow
Array<double, 1, 3> x(8, -25, 3), y(1. / 3., 0.5, -2.);
cout << "atan2([" << x << "], [" << y << "]) = " << x.atan2(y) << endl; // using ArrayBase::pow
cout << "atan2([" << x << "], [" << y << "] = " << atan2(x, y) << endl; // using Eigen::pow

View File

@@ -1,4 +1,3 @@
Array<double,1,3> x(8,25,3),
e(1./3.,0.5,2.);
cout << "[" << x << "]^[" << e << "] = " << x.pow(e) << endl; // using ArrayBase::pow
cout << "[" << x << "]^[" << e << "] = " << pow(x,e) << endl; // using Eigen::pow
Array<double, 1, 3> x(8, 25, 3), e(1. / 3., 0.5, 2.);
cout << "[" << x << "]^[" << e << "] = " << x.pow(e) << endl; // using ArrayBase::pow
cout << "[" << x << "]^[" << e << "] = " << pow(x, e) << endl; // using Eigen::pow

View File

@@ -1,2 +1,2 @@
Array3d v(0, sqrt(2.)/2, 1);
Array3d v(0, sqrt(2.) / 2, 1);
cout << v.asin() << endl;

View File

@@ -1,2 +1,2 @@
ArrayXd v = ArrayXd::LinSpaced(5,0,1);
ArrayXd v = ArrayXd::LinSpaced(5, 0, 1);
cout << v.atan() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(-1,2,1), w(-3,2,3);
cout << ((v<w) && (v<0)) << endl;
Array3d v(-1, 2, 1), w(-3, 2, 3);
cout << ((v < w) && (v < 0)) << endl;

View File

@@ -1,5 +1,5 @@
Array3d v(1,2,3);
v(1) *= 0.0/0.0;
Array3d v(1, 2, 3);
v(1) *= 0.0 / 0.0;
v(2) /= 0.0;
cout << v << endl << endl;
cout << !isfinite(v) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(-1,2,1), w(-3,2,3);
cout << ((v<w) || (v<0)) << endl;
Array3d v(-1, 2, 1), w(-3, 2, 3);
cout << ((v < w) || (v < 0)) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,4);
Array3d v(1, 2, 4);
cout << v.cbrt() << endl;

View File

@@ -1,3 +1,3 @@
ArrayXd v = ArrayXd::LinSpaced(7,-2,2);
ArrayXd v = ArrayXd::LinSpaced(7, -2, 2);
cout << v << endl << endl;
cout << ceil(v) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(M_PI, M_PI/2, M_PI/3);
Array3d v(M_PI, M_PI / 2, M_PI / 3);
cout << v.cos() << endl;

View File

@@ -1,2 +1,2 @@
ArrayXd v = ArrayXd::LinSpaced(5,0,1);
ArrayXd v = ArrayXd::LinSpaced(5, 0, 1);
cout << cosh(v) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(2,3,4);
Array3d v(2, 3, 4);
cout << v.cube() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3), w(3,2,1);
cout << (v==w) << endl;
Array3d v(1, 2, 3), w(3, 2, 1);
cout << (v == w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3);
Array3d v(1, 2, 3);
cout << v.exp() << endl;

View File

@@ -1,3 +1,3 @@
ArrayXd v = ArrayXd::LinSpaced(7,-2,2);
ArrayXd v = ArrayXd::LinSpaced(7, -2, 2);
cout << v << endl << endl;
cout << floor(v) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3), w(3,2,1);
cout << (v>w) << endl;
Array3d v(1, 2, 3), w(3, 2, 1);
cout << (v > w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3), w(3,2,1);
cout << (v>=w) << endl;
Array3d v(1, 2, 3), w(3, 2, 1);
cout << (v >= w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(2,3,4);
Array3d v(2, 3, 4);
cout << v.inverse() << endl;

View File

@@ -1,5 +1,5 @@
Array3d v(1,2,3);
v(1) *= 0.0/0.0;
Array3d v(1, 2, 3);
v(1) *= 0.0 / 0.0;
v(2) /= 0.0;
cout << v << endl << endl;
cout << isfinite(v) << endl;

View File

@@ -1,5 +1,5 @@
Array3d v(1,2,3);
v(1) *= 0.0/0.0;
Array3d v(1, 2, 3);
v(1) *= 0.0 / 0.0;
v(2) /= 0.0;
cout << v << endl << endl;
cout << isinf(v) << endl;

View File

@@ -1,5 +1,5 @@
Array3d v(1,2,3);
v(1) *= 0.0/0.0;
Array3d v(1, 2, 3);
v(1) *= 0.0 / 0.0;
v(2) /= 0.0;
cout << v << endl << endl;
cout << isnan(v) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3), w(3,2,1);
cout << (v<w) << endl;
Array3d v(1, 2, 3), w(3, 2, 1);
cout << (v < w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3), w(3,2,1);
cout << (v<=w) << endl;
Array3d v(1, 2, 3), w(3, 2, 1);
cout << (v <= w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3);
Array3d v(1, 2, 3);
cout << v.log() << endl;

View File

@@ -1,2 +1,2 @@
Array4d v(-1,0,1,2);
Array4d v(-1, 0, 1, 2);
cout << log10(v) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(2,3,4), w(4,2,3);
Array3d v(2, 3, 4), w(4, 2, 3);
cout << v.max(w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(2,3,4), w(4,2,3);
Array3d v(2, 3, 4), w(4, 2, 3);
cout << v.min(w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3);
cout << v-5 << endl;
Array3d v(1, 2, 3);
cout << v - 5 << endl;

View File

@@ -1,3 +1,3 @@
Array3d v(1,2,3);
Array3d v(1, 2, 3);
v -= 5;
cout << v << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3), w(3,2,1);
cout << (v!=w) << endl;
Array3d v(1, 2, 3), w(3, 2, 1);
cout << (v != w) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,3);
cout << v+5 << endl;
Array3d v(1, 2, 3);
cout << v + 5 << endl;

View File

@@ -1,3 +1,3 @@
Array3d v(1,2,3);
Array3d v(1, 2, 3);
v += 5;
cout << v << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(8,27,64);
Array3d v(8, 27, 64);
cout << v.pow(0.333333) << endl;

View File

@@ -1,4 +1,3 @@
Array33i a = Array33i::Random(), b = Array33i::Random();
Array33i c = a * b;
cout << "a:\n" << a << "\nb:\n" << b << "\nc:\n" << c << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(2,3,4), w(4,2,3);
cout << v/w << endl;
Array3d v(2, 3, 4), w(4, 2, 3);
cout << v / w << endl;

View File

@@ -1,3 +1,3 @@
ArrayXd v = ArrayXd::LinSpaced(7,-2,2);
ArrayXd v = ArrayXd::LinSpaced(7, -2, 2);
cout << v << endl << endl;
cout << rint(v) << endl;

View File

@@ -1,3 +1,3 @@
ArrayXd v = ArrayXd::LinSpaced(7,-2,2);
ArrayXd v = ArrayXd::LinSpaced(7, -2, 2);
cout << v << endl << endl;
cout << round(v) << endl;

View File

@@ -1,2 +1,2 @@
Array<double,1,3> e(2,-3,1./3.);
cout << "10^[" << e << "] = " << pow(10,e) << endl;
Array<double, 1, 3> e(2, -3, 1. / 3.);
cout << "10^[" << e << "] = " << pow(10, e) << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(-3,5,0);
Array3d v(-3, 5, 0);
cout << v.sign() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(M_PI, M_PI/2, M_PI/3);
Array3d v(M_PI, M_PI / 2, M_PI / 3);
cout << v.sin() << endl;

View File

@@ -1,2 +1,2 @@
ArrayXd v = ArrayXd::LinSpaced(5,0,1);
ArrayXd v = ArrayXd::LinSpaced(5, 0, 1);
cout << sinh(v) << endl;

View File

@@ -1,3 +1,3 @@
Array3d v(3,2,4), w(5,4,2);
Array3d v(3, 2, 4), w(5, 4, 2);
v /= w;
cout << v << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(1,2,4);
Array3d v(1, 2, 4);
cout << v.sqrt() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(2,3,4);
Array3d v(2, 3, 4);
cout << v.square() << endl;

View File

@@ -1,2 +1,2 @@
Array3d v(M_PI, M_PI/2, M_PI/3);
Array3d v(M_PI, M_PI / 2, M_PI / 3);
cout << v.tan() << endl;

View File

@@ -1,2 +1,2 @@
ArrayXd v = ArrayXd::LinSpaced(5,0,1);
ArrayXd v = ArrayXd::LinSpaced(5, 0, 1);
cout << tanh(v) << endl;

View File

@@ -1,3 +1,3 @@
Array3d v(1,2,3), w(2,3,0);
Array3d v(1, 2, 3), w(2, 3, 0);
v *= w;
cout << v << endl;

View File

@@ -1,2 +1,2 @@
cout << VectorXi::LinSpaced(4,7,10).transpose() << endl;
cout << VectorXd::LinSpaced(5,0.0,1.0).transpose() << endl;
cout << VectorXi::LinSpaced(4, 7, 10).transpose() << endl;
cout << VectorXd::LinSpaced(5, 0.0, 1.0).transpose() << endl;

View File

@@ -1,8 +1,8 @@
cout << "Even spacing inputs:" << endl;
cout << VectorXi::LinSpaced(8,1,4).transpose() << endl;
cout << VectorXi::LinSpaced(8,1,8).transpose() << endl;
cout << VectorXi::LinSpaced(8,1,15).transpose() << endl;
cout << VectorXi::LinSpaced(8, 1, 4).transpose() << endl;
cout << VectorXi::LinSpaced(8, 1, 8).transpose() << endl;
cout << VectorXi::LinSpaced(8, 1, 15).transpose() << endl;
cout << "Uneven spacing inputs:" << endl;
cout << VectorXi::LinSpaced(8,1,7).transpose() << endl;
cout << VectorXi::LinSpaced(8,1,9).transpose() << endl;
cout << VectorXi::LinSpaced(8,1,16).transpose() << endl;
cout << VectorXi::LinSpaced(8, 1, 7).transpose() << endl;
cout << VectorXi::LinSpaced(8, 1, 9).transpose() << endl;
cout << VectorXi::LinSpaced(8, 1, 16).transpose() << endl;

View File

@@ -1,2 +1,2 @@
cout << VectorXi::LinSpaced(Sequential,4,7,10).transpose() << endl;
cout << VectorXd::LinSpaced(Sequential,5,0.0,1.0).transpose() << endl;
cout << VectorXi::LinSpaced(Sequential, 4, 7, 10).transpose() << endl;
cout << VectorXd::LinSpaced(Sequential, 5, 0.0, 1.0).transpose() << endl;

View File

@@ -1,3 +1,3 @@
VectorXf v;
v.setLinSpaced(5,0.5f,1.5f);
v.setLinSpaced(5, 0.5f, 1.5f);
cout << v << endl;

View File

@@ -1,6 +1,6 @@
Matrix4Xd M = Matrix4Xd::Random(4,5);
Matrix4Xd M = Matrix4Xd::Random(4, 5);
Projective3d P(Matrix4d::Random());
cout << "The matrix M is:" << endl << M << endl << endl;
cout << "M.colwise().hnormalized():" << endl << M.colwise().hnormalized() << endl << endl;
cout << "P*M:" << endl << P*M << endl << endl;
cout << "(P*M).colwise().hnormalized():" << endl << (P*M).colwise().hnormalized() << endl << endl;
cout << "P*M:" << endl << P * M << endl << endl;
cout << "(P*M).colwise().hnormalized():" << endl << (P * M).colwise().hnormalized() << endl << endl;

View File

@@ -1,4 +1,4 @@
MatrixXi m = MatrixXi::Random(2,3);
MatrixXi m = MatrixXi::Random(2, 3);
cout << "Here is the matrix m:" << endl << m << endl;
cout << "m.colwise().replicate<3>() = ..." << endl;
cout << m.colwise().replicate<3>() << endl;

View File

@@ -1,4 +1,4 @@
MatrixXd A = MatrixXd::Random(6,6);
MatrixXd A = MatrixXd::Random(6, 6);
cout << "Here is a random 6x6 matrix, A:" << endl << A << endl << endl;
EigenSolver<MatrixXd> es(A);

View File

@@ -1,6 +1,6 @@
EigenSolver<MatrixXf> es;
MatrixXf A = MatrixXf::Random(4,4);
MatrixXf A = MatrixXf::Random(4, 4);
es.compute(A, /* computeEigenvectors = */ false);
cout << "The eigenvalues of A are: " << es.eigenvalues().transpose() << endl;
es.compute(A + MatrixXf::Identity(4,4), false); // re-use es to compute eigenvalues of A+I
es.compute(A + MatrixXf::Identity(4, 4), false); // re-use es to compute eigenvalues of A+I
cout << "The eigenvalues of A+I are: " << es.eigenvalues().transpose() << endl;

View File

@@ -1,4 +1,3 @@
MatrixXd ones = MatrixXd::Ones(3,3);
MatrixXd ones = MatrixXd::Ones(3, 3);
EigenSolver<MatrixXd> es(ones, false);
cout << "The eigenvalues of the 3x3 matrix of ones are:"
<< endl << es.eigenvalues() << endl;
cout << "The eigenvalues of the 3x3 matrix of ones are:" << endl << es.eigenvalues() << endl;

View File

@@ -1,4 +1,3 @@
MatrixXd ones = MatrixXd::Ones(3,3);
MatrixXd ones = MatrixXd::Ones(3, 3);
EigenSolver<MatrixXd> es(ones);
cout << "The first eigenvector of the 3x3 matrix of ones is:"
<< endl << es.eigenvectors().col(0) << endl;
cout << "The first eigenvector of the 3x3 matrix of ones is:" << endl << es.eigenvectors().col(0) << endl;

View File

@@ -1,4 +1,4 @@
MatrixXd A = MatrixXd::Random(6,6);
MatrixXd A = MatrixXd::Random(6, 6);
cout << "Here is a random 6x6 matrix, A:" << endl << A << endl << endl;
EigenSolver<MatrixXd> es(A);

View File

@@ -4,5 +4,5 @@ cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the matrix y:" << endl << y << endl;
Matrix3f x;
x = m.fullPivHouseholderQr().solve(y);
assert(y.isApprox(m*x));
assert(y.isApprox(m* x));
cout << "Here is a solution x to the equation mx=y:" << endl << x << endl;

View File

@@ -1,9 +1,7 @@
Matrix3d m;
m << 1,1,0,
1,3,2,
0,1,1;
m << 1, 1, 0, 1, 3, 2, 0, 1, 1;
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Notice that the middle column is the sum of the two others, so the "
<< "columns are linearly dependent." << endl;
cout << "Here is a matrix whose columns have the same span but are linearly independent:"
<< endl << m.fullPivLu().image(m) << endl;
cout << "Here is a matrix whose columns have the same span but are linearly independent:" << endl
<< m.fullPivLu().image(m) << endl;

View File

@@ -1,7 +1,5 @@
MatrixXf m = MatrixXf::Random(3,5);
MatrixXf m = MatrixXf::Random(3, 5);
cout << "Here is the matrix m:" << endl << m << endl;
MatrixXf ker = m.fullPivLu().kernel();
cout << "Here is a matrix whose columns form a basis of the kernel of m:"
<< endl << ker << endl;
cout << "By definition of the kernel, m*ker is zero:"
<< endl << m*ker << endl;
cout << "Here is a matrix whose columns form a basis of the kernel of m:" << endl << ker << endl;
cout << "By definition of the kernel, m*ker is zero:" << endl << m * ker << endl;

View File

@@ -1,11 +1,9 @@
Matrix<float,2,3> m = Matrix<float,2,3>::Random();
Matrix<float, 2, 3> m = Matrix<float, 2, 3>::Random();
Matrix2f y = Matrix2f::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the matrix y:" << endl << y << endl;
Matrix<float,3,2> x = m.fullPivLu().solve(y);
if((m*x).isApprox(y))
{
Matrix<float, 3, 2> x = m.fullPivLu().solve(y);
if ((m * x).isApprox(y)) {
cout << "Here is a solution x to the equation mx=y:" << endl << x << endl;
}
else
} else
cout << "The equation mx=y does not have any solution." << endl;

View File

@@ -1,6 +1,6 @@
GeneralizedEigenSolver<MatrixXf> ges;
MatrixXf A = MatrixXf::Random(4,4);
MatrixXf B = MatrixXf::Random(4,4);
MatrixXf A = MatrixXf::Random(4, 4);
MatrixXf B = MatrixXf::Random(4, 4);
ges.compute(A, B);
cout << "The (complex) numerators of the generalzied eigenvalues are: " << ges.alphas().transpose() << endl;
cout << "The (real) denominatore of the generalzied eigenvalues are: " << ges.betas().transpose() << endl;

View File

@@ -1,6 +1,6 @@
MatrixXcf A = MatrixXcf::Random(4,4);
MatrixXcf A = MatrixXcf::Random(4, 4);
HessenbergDecomposition<MatrixXcf> hd(4);
hd.compute(A);
cout << "The matrix H in the decomposition of A is:" << endl << hd.matrixH() << endl;
hd.compute(2*A); // re-use hd to compute and store decomposition of 2A
hd.compute(2 * A); // re-use hd to compute and store decomposition of 2A
cout << "The matrix H in the decomposition of 2A is:" << endl << hd.matrixH() << endl;

View File

@@ -1,4 +1,4 @@
Matrix4f A = MatrixXf::Random(4,4);
Matrix4f A = MatrixXf::Random(4, 4);
cout << "Here is a random 4x4 matrix:" << endl << A << endl;
HessenbergDecomposition<MatrixXf> hessOfA(A);
MatrixXf H = hessOfA.matrixH();

View File

@@ -1,9 +1,8 @@
Matrix4d A = Matrix4d::Random(4,4);
Matrix4d A = Matrix4d::Random(4, 4);
cout << "Here is a random 4x4 matrix:" << endl << A << endl;
HessenbergDecomposition<Matrix4d> hessOfA(A);
Matrix4d pm = hessOfA.packedMatrix();
cout << "The packed matrix M is:" << endl << pm << endl;
cout << "The upper Hessenberg part corresponds to the matrix H, which is:"
<< endl << hessOfA.matrixH() << endl;
cout << "The upper Hessenberg part corresponds to the matrix H, which is:" << endl << hessOfA.matrixH() << endl;
Vector3d hc = hessOfA.householderCoefficients();
cout << "The vector of Householder coefficients is:" << endl << hc << endl;

View File

@@ -1,4 +1,4 @@
MatrixXf A(MatrixXf::Random(5,3)), thinQ(MatrixXf::Identity(5,3)), Q;
MatrixXf A(MatrixXf::Random(5, 3)), thinQ(MatrixXf::Identity(5, 3)), Q;
A.setRandom();
HouseholderQR<MatrixXf> qr(A);
Q = qr.householderQ();

View File

@@ -1,9 +1,9 @@
typedef Matrix<float,3,3> Matrix3x3;
typedef Matrix<float, 3, 3> Matrix3x3;
Matrix3x3 m = Matrix3x3::Random();
Matrix3f y = Matrix3f::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the matrix y:" << endl << y << endl;
Matrix3f x;
x = m.householderQr().solve(y);
assert(y.isApprox(m*x));
assert(y.isApprox(m* x));
cout << "Here is a solution x to the equation mx=y:" << endl << x << endl;

View File

@@ -2,10 +2,10 @@ Matrix3d v = Matrix3d::Random();
cout << "The matrix v is:" << endl;
cout << v << endl;
Vector3d v0(1, v(1,0), v(2,0));
Vector3d v0(1, v(1, 0), v(2, 0));
cout << "The first Householder vector is: v_0 = " << v0.transpose() << endl;
Vector3d v1(0, 1, v(2,1));
cout << "The second Householder vector is: v_1 = " << v1.transpose() << endl;
Vector3d v1(0, 1, v(2, 1));
cout << "The second Householder vector is: v_1 = " << v1.transpose() << endl;
Vector3d v2(0, 0, 1);
cout << "The third Householder vector is: v_2 = " << v2.transpose() << endl;

View File

@@ -1,4 +1,4 @@
MatrixXf m = MatrixXf::Random(3,2);
MatrixXf m = MatrixXf::Random(3, 2);
cout << "Here is the matrix m:" << endl << m << endl;
JacobiSVD<MatrixXf, ComputeThinU | ComputeThinV> svd(m);
cout << "Its singular values are:" << endl << svd.singularValues() << endl;

View File

@@ -1,9 +1,9 @@
MatrixXd A(3,3);
A << 4,-1,2, -1,6,0, 2,0,5;
MatrixXd A(3, 3);
A << 4, -1, 2, -1, 6, 0, 2, 0, 5;
cout << "The matrix A is" << endl << A << endl;
LLT<MatrixXd> lltOfA(A); // compute the Cholesky decomposition of A
MatrixXd L = lltOfA.matrixL(); // retrieve factor L in the decomposition
LLT<MatrixXd> lltOfA(A); // compute the Cholesky decomposition of A
MatrixXd L = lltOfA.matrixL(); // retrieve factor L in the decomposition
// The previous two lines can also be written as "L = A.llt().matrixL()"
cout << "The Cholesky factor L is" << endl << L << endl;

View File

@@ -1,8 +1,7 @@
typedef Matrix<float,Dynamic,2> DataMatrix;
typedef Matrix<float, Dynamic, 2> DataMatrix;
// let's generate some samples on the 3D plane of equation z = 2x+3y (with some noise)
DataMatrix samples = DataMatrix::Random(12,2);
VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::Random(12)*0.1;
DataMatrix samples = DataMatrix::Random(12, 2);
VectorXf elevations = 2 * samples.col(0) + 3 * samples.col(1) + VectorXf::Random(12) * 0.1;
// and let's solve samples * [x y]^T = elevations in least square sense:
Matrix<float,2,1> xy
= (samples.adjoint() * samples).llt().solve((samples.adjoint()*elevations));
Matrix<float, 2, 1> xy = (samples.adjoint() * samples).llt().solve((samples.adjoint() * elevations));
cout << xy << endl;

View File

@@ -1,4 +1,3 @@
MatrixXf A = MatrixXf::Random(3, 2);
VectorXf b = VectorXf::Random(3);
cout << "The solution using normal equations is:\n"
<< (A.transpose() * A).ldlt().solve(A.transpose() * b) << endl;
cout << "The solution using normal equations is:\n" << (A.transpose() * A).ldlt().solve(A.transpose() * b) << endl;

View File

@@ -1,4 +1,3 @@
MatrixXf A = MatrixXf::Random(3, 2);
VectorXf b = VectorXf::Random(3);
cout << "The solution using the QR decomposition is:\n"
<< A.colPivHouseholderQr().solve(b) << endl;
cout << "The solution using the QR decomposition is:\n" << A.colPivHouseholderQr().solve(b) << endl;

View File

@@ -1,5 +1,3 @@
int array[24];
for(int i = 0; i < 24; ++i) array[i] = i;
cout << Map<MatrixXi, 0, Stride<Dynamic,2> >
(array, 3, 3, Stride<Dynamic,2>(8, 2))
<< endl;
for (int i = 0; i < 24; ++i) array[i] = i;
cout << Map<MatrixXi, 0, Stride<Dynamic, 2> >(array, 3, 3, Stride<Dynamic, 2>(8, 2)) << endl;

View File

@@ -1,5 +1,4 @@
int array[12];
for(int i = 0; i < 12; ++i) array[i] = i;
cout << Map<VectorXi, 0, InnerStride<2> >
(array, 6) // the inner stride has already been passed as template parameter
for (int i = 0; i < 12; ++i) array[i] = i;
cout << Map<VectorXi, 0, InnerStride<2> >(array, 6) // the inner stride has already been passed as template parameter
<< endl;

View File

@@ -1,3 +1,3 @@
int array[12];
for(int i = 0; i < 12; ++i) array[i] = i;
for (int i = 0; i < 12; ++i) array[i] = i;
cout << Map<MatrixXi, 0, OuterStride<> >(array, 3, 3, OuterStride<>(4)) << endl;

View File

@@ -1,5 +1,5 @@
int data[] = {1,2,3,4,5,6,7,8,9};
Map<RowVectorXi> v(data,4);
int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
Map<RowVectorXi> v(data, 4);
cout << "The mapped vector v is: " << v << "\n";
new (&v) Map<RowVectorXi>(data+4,5);
new (&v) Map<RowVectorXi>(data + 4, 5);
cout << "Now v is: " << v << "\n";

View File

@@ -1,3 +1,3 @@
int array[9];
for(int i = 0; i < 9; ++i) array[i] = i;
for (int i = 0; i < 9; ++i) array[i] = i;
cout << Map<Matrix3i>(array) << endl;

View File

@@ -1,7 +1,7 @@
Vector3f boxMin(Vector3f::Zero()), boxMax(Vector3f::Ones());
Vector3f p0 = Vector3f::Random(), p1 = Vector3f::Random().cwiseAbs();
// let's check if p0 and p1 are inside the axis aligned box defined by the corners boxMin,boxMax:
cout << "Is (" << p0.transpose() << ") inside the box: "
<< ((boxMin.array()<p0.array()).all() && (boxMax.array()>p0.array()).all()) << endl;
cout << "Is (" << p1.transpose() << ") inside the box: "
<< ((boxMin.array()<p1.array()).all() && (boxMax.array()>p1.array()).all()) << endl;
cout << "Is (" << p0.transpose()
<< ") inside the box: " << ((boxMin.array() < p0.array()).all() && (boxMax.array() > p0.array()).all()) << endl;
cout << "Is (" << p1.transpose()
<< ") inside the box: " << ((boxMin.array() < p1.array()).all() && (boxMax.array() > p1.array()).all()) << endl;

View File

@@ -1,7 +1,5 @@
Matrix3f A = Matrix3f::Random(3,3), B;
B << 0,1,0,
0,0,1,
1,0,0;
Matrix3f A = Matrix3f::Random(3, 3), B;
B << 0, 1, 0, 0, 0, 1, 1, 0, 0;
cout << "At start, A = " << endl << A << endl;
A.applyOnTheLeft(B);
A.applyOnTheLeft(B);
cout << "After applyOnTheLeft, A = " << endl << A << endl;

View File

@@ -1,7 +1,5 @@
Matrix3f A = Matrix3f::Random(3,3), B;
B << 0,1,0,
0,0,1,
1,0,0;
Matrix3f A = Matrix3f::Random(3, 3), B;
B << 0, 1, 0, 0, 0, 1, 1, 0, 0;
cout << "At start, A = " << endl << A << endl;
A *= B;
cout << "After A *= B, A = " << endl << A << endl;

View File

@@ -1,4 +1,4 @@
Vector3d v(1,2,3);
Vector3d v(1, 2, 3);
v.array() += 3;
v.array() -= 2;
cout << v << endl;

View File

@@ -1,4 +1,4 @@
Vector3d v(-1,2,-3);
Vector3d v(-1, 2, -3);
cout << "the absolute values:" << endl << v.array().abs() << endl;
cout << "the absolute values plus one:" << endl << v.array().abs()+1 << endl;
cout << "the absolute values plus one:" << endl << v.array().abs() + 1 << endl;
cout << "sum of the squares: " << v.array().square().sum() << endl;

Some files were not shown because too many files have changed in this diff Show More