aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/AsciiQuickReference.txt
diff options
context:
space:
mode:
authorGravatar Keir Mierle <mierle@gmail.com>2009-02-19 16:46:35 +0000
committerGravatar Keir Mierle <mierle@gmail.com>2009-02-19 16:46:35 +0000
commit22b9de1849a94aad958ca097088cdef9646d1233 (patch)
tree838dad57e12e420d3d031ebab105613b7d64f6c2 /doc/AsciiQuickReference.txt
parente2ee7a6a5818154b0ea8baeea159bfe4622fd437 (diff)
Fix some formatting in quick ref. Add references to headers.
Diffstat (limited to 'doc/AsciiQuickReference.txt')
-rw-r--r--doc/AsciiQuickReference.txt273
1 files changed, 138 insertions, 135 deletions
diff --git a/doc/AsciiQuickReference.txt b/doc/AsciiQuickReference.txt
index bcf402186..b868741f3 100644
--- a/doc/AsciiQuickReference.txt
+++ b/doc/AsciiQuickReference.txt
@@ -1,11 +1,17 @@
- Matrix<double, 3, 3> A; // Fixed rows and cols. Same as Matrix3d.
- Matrix<double, 3, Dynamic> B; // Fixed rows, dynamic cols.
- Matrix<double, Dynamic, Dynamic> C; // Full dynamic. Same as MatrixXd.
- Matrix<double, 3, 3, RowMajor> E; // Row major; default is column-major.
- Matrix3f P, Q, R; // 3x3 float matrix.
- Vector3f x, y, z; // 3x1 float matrix.
- RowVector3f a, b, c; // 1x3 float matrix.
- double s;
+// A simple quickref for Eigen. Add anything that's missing.
+// Main author: Keir Mierle
+
+#include <Eigen/Core>
+#include <Eigen/Array>
+
+Matrix<double, 3, 3> A; // Fixed rows and cols. Same as Matrix3d.
+Matrix<double, 3, Dynamic> B; // Fixed rows, dynamic cols.
+Matrix<double, Dynamic, Dynamic> C; // Full dynamic. Same as MatrixXd.
+Matrix<double, 3, 3, RowMajor> E; // Row major; default is column-major.
+Matrix3f P, Q, R; // 3x3 float matrix.
+Vector3f x, y, z; // 3x1 float matrix.
+RowVector3f a, b, c; // 1x3 float matrix.
+double s;
// Basic usage
// Eigen // Matlab // comments
@@ -15,145 +21,142 @@ C.cols() // size(C)(2) // number of columns
x(i) // x(i+1) // Matlab is 1-based
C(i,j) // C(i+1,j+1) //
- A.resize(4, 4); // Runtime error if assertions are on.
- B.resize(4, 9); // Runtime error if assertions are on.
- A.resize(3, 3); // Ok; size didn't change.
- B.resize(3, 9); // Ok; only dynamic cols changed.
-
- A << 1, 2, 3, // Initialize A. The elements can also be
- 4, 5, 6, // matrices, which are stacked along cols
- 7, 8, 9; // and then the rows are stacked.
- B << A, A, A; // B is three horizontally stacked A's.
- A.fill(10); // Fill A with all 10's.
- A.setRandom(); // Fill A with uniform random numbers in (-1, 1).
+A.resize(4, 4); // Runtime error if assertions are on.
+B.resize(4, 9); // Runtime error if assertions are on.
+A.resize(3, 3); // Ok; size didn't change.
+B.resize(3, 9); // Ok; only dynamic cols changed.
+
+A << 1, 2, 3, // Initialize A. The elements can also be
+ 4, 5, 6, // matrices, which are stacked along cols
+ 7, 8, 9; // and then the rows are stacked.
+B << A, A, A; // B is three horizontally stacked A's.
+A.fill(10); // Fill A with all 10's.
+A.setRandom(); // Fill A with uniform random numbers in (-1, 1).
// Requires #include <Eigen/Array>.
- A.setIdentity(); // Fill A with the identity.
+A.setIdentity(); // Fill A with the identity.
- // Matrix slicing and blocks. All expressions listed here are read/write.
- // Templated size versions are faster. Note that Matlab is 1-based (a size N
- // vector is x(1)...x(N)).
- // Eigen // Matlab
- x.start(n) // x(1:n)
- x.start<n>() // x(1:n)
- x.end(n) // N = rows(x); x(N - n: N)
- x.end<n>() // N = rows(x); x(N - n: N)
- x.segment(i, n) // x(i+1 : i+n)
- x.segment<n>(i) // x(i+1 : i+n)
- P.block(i, j, rows, cols) // P(i+1 : i+rows, j+1 : j+cols)
- P.block<rows, cols>(i, j) // P(i+1 : i+rows, j+1 : j+cols)
- P.corner(TopLeft, rows, cols) // P(1:rows, 1:cols)
- P.corner(TopRight, rows, cols) // [m n]=size(P); P(1:rows, n-cols+1:n)
- P.corner(BottomLeft, rows, cols) // [m n]=size(P); P(m-rows+1:m, 1:cols)
- P.corner(BottomRight, rows, cols) // [m n]=size(P); P(m-rows+1:m, n-cols+1:n)
- P.corner<rows,cols>(TopLeft) // P(1:rows, 1:cols)
- P.corner<rows,cols>(TopRight) // [m n]=size(P); P(1:rows, n-cols+1:n)
- P.corner<rows,cols>(BottomLeft) // [m n]=size(P); P(m-rows+1:m, 1:cols)
- P.corner<rows,cols>(BottomRight) // [m n]=size(P); P(m-rows+1:m, n-cols+1:n)
- P.minor(i, j) // Something nasty.
+// Matrix slicing and blocks. All expressions listed here are read/write.
+// Templated size versions are faster. Note that Matlab is 1-based (a size N
+// vector is x(1)...x(N)).
+// Eigen // Matlab
+x.start(n) // x(1:n)
+x.start<n>() // x(1:n)
+x.end(n) // N = rows(x); x(N - n: N)
+x.end<n>() // N = rows(x); x(N - n: N)
+x.segment(i, n) // x(i+1 : i+n)
+x.segment<n>(i) // x(i+1 : i+n)
+P.block(i, j, rows, cols) // P(i+1 : i+rows, j+1 : j+cols)
+P.block<rows, cols>(i, j) // P(i+1 : i+rows, j+1 : j+cols)
+P.corner(TopLeft, rows, cols) // P(1:rows, 1:cols)
+P.corner(TopRight, rows, cols) // [m n]=size(P); P(1:rows, n-cols+1:n)
+P.corner(BottomLeft, rows, cols) // [m n]=size(P); P(m-rows+1:m, 1:cols)
+P.corner(BottomRight, rows, cols) // [m n]=size(P); P(m-rows+1:m, n-cols+1:n)
+P.corner<rows,cols>(TopLeft) // P(1:rows, 1:cols)
+P.corner<rows,cols>(TopRight) // [m n]=size(P); P(1:rows, n-cols+1:n)
+P.corner<rows,cols>(BottomLeft) // [m n]=size(P); P(m-rows+1:m, 1:cols)
+P.corner<rows,cols>(BottomRight) // [m n]=size(P); P(m-rows+1:m, n-cols+1:n)
+P.minor(i, j) // Something nasty.
- // Of particular note is Eigen's swap function which is highly optimized.
- // Eigen // Matlab
- R.row(i) = P.col(j); // R(i, :) = P(:, i)
- R.col(j1).swap(mat1.col(j2)); // R(:, [j1 j2]) = R(:, [j2, j1])
+// Of particular note is Eigen's swap function which is highly optimized.
+// Eigen // Matlab
+R.row(i) = P.col(j); // R(i, :) = P(:, i)
+R.col(j1).swap(mat1.col(j2)); // R(:, [j1 j2]) = R(:, [j2, j1])
- // Views, transpose, etc; all read-write except for .adjoint().
- // Eigen // Matlab
- R.adjoint() // R'
- R.transpose() // R.' or conj(R')
- R.diagonal() // diag(R)
- x.asDiagonal() // diag(x)
+// Views, transpose, etc; all read-write except for .adjoint().
+// Eigen // Matlab
+R.adjoint() // R'
+R.transpose() // R.' or conj(R')
+R.diagonal() // diag(R)
+x.asDiagonal() // diag(x)
- // All the same as Matlab, but matlab doesn't have *= style operators.
- // Matrix-vector. Matrix-matrix. Matrix-scalar.
- y = M*x; R = P*Q; R = P*s;
- a = b*M; R = P - Q; R = s*P;
- a *= M; R = P + Q; R = P/s;
- R *= Q; R = s*P;
- R += Q; R *= s;
- R -= Q; R /= s;
+// All the same as Matlab, but matlab doesn't have *= style operators.
+// Matrix-vector. Matrix-matrix. Matrix-scalar.
+y = M*x; R = P*Q; R = P*s;
+a = b*M; R = P - Q; R = s*P;
+a *= M; R = P + Q; R = P/s;
+ R *= Q; R = s*P;
+ R += Q; R *= s;
+ R -= Q; R /= s;
// Vectorized operations on each element independently
// (most require #include <Eigen/Array>)
- // Eigen // Matlab
- R = P.cwise() * Q; // R = P .* Q
- R = P.cwise() / Q; // R = P ./ Q
- R = P.cwise() + s; // R = P + s
- R = P.cwise() - s; // R = P - s
- R.cwise() += s; // R = R + s
- R.cwise() -= s; // R = R - s
- R.cwise() *= s; // R = R * s
- R.cwise() /= s; // R = R / s
- R.cwise() < Q; // R < Q
- R.cwise() <= Q; // R <= Q
- R.cwise().inverse(); // 1 ./ P
- R.cwise().sin() // sin(P)
- R.cwise().cos() // cos(P)
- R.cwise().pow(s) // P .^ s
- R.cwise().square() // P .^ 2
- R.cwise().cube() // P .^ 3
- R.cwise().sqrt() // sqrt(P)
- R.cwise().exp() // exp(P)
- R.cwise().log() // log(P)
- R.cwise().max(P) // max(R, P)
- R.cwise().min(P) // min(R, P)
- R.cwise().abs() // abs(P)
- R.cwise().abs2() // abs(P.^2)
- (R.cwise() < s).select(P,Q); // (R < s ? P : Q)
+// Eigen // Matlab
+R = P.cwise() * Q; // R = P .* Q
+R = P.cwise() / Q; // R = P ./ Q
+R = P.cwise() + s; // R = P + s
+R = P.cwise() - s; // R = P - s
+R.cwise() += s; // R = R + s
+R.cwise() -= s; // R = R - s
+R.cwise() *= s; // R = R * s
+R.cwise() /= s; // R = R / s
+R.cwise() < Q; // R < Q
+R.cwise() <= Q; // R <= Q
+R.cwise().inverse(); // 1 ./ P
+R.cwise().sin() // sin(P)
+R.cwise().cos() // cos(P)
+R.cwise().pow(s) // P .^ s
+R.cwise().square() // P .^ 2
+R.cwise().cube() // P .^ 3
+R.cwise().sqrt() // sqrt(P)
+R.cwise().exp() // exp(P)
+R.cwise().log() // log(P)
+R.cwise().max(P) // max(R, P)
+R.cwise().min(P) // min(R, P)
+R.cwise().abs() // abs(P)
+R.cwise().abs2() // abs(P.^2)
+(R.cwise() < s).select(P,Q); // (R < s ? P : Q)
- // Reductions.
- int r, c;
- // Eigen // Matlab
- R.minCoeff() // min(R(:))
- R.maxCoeff() // max(R(:))
- s = R.minCoeff(&r, &c) // [aa, bb] = min(R); [cc, dd] = min(aa);
+// Reductions.
+int r, c;
+// Eigen // Matlab
+R.minCoeff() // min(R(:))
+R.maxCoeff() // max(R(:))
+s = R.minCoeff(&r, &c) // [aa, bb] = min(R); [cc, dd] = min(aa);
// r = bb(dd); c = dd; s = cc
- s = R.maxCoeff(&r, &c) // [aa, bb] = max(R); [cc, dd] = max(aa);
+s = R.maxCoeff(&r, &c) // [aa, bb] = max(R); [cc, dd] = max(aa);
// row = bb(dd); col = dd; s = cc
- R.sum() // sum(R(:))
- R.colwise.sum() // sum(R)
- R.rowwise.sum() // sum(R, 2) or sum(R')'
- R.trace() // trace(R)
- R.all() // all(R(:))
- R.colwise().all() // all(R)
- R.rowwise().all() // all(R, 2)
- R.any() // any(R(:))
- R.colwise().any() // any(R)
- R.rowwise().any() // any(R, 2)
-
- // Dot products, norms, etc.
- // Eigen // Matlab
- x.norm() // norm(x). Note that norm(R) doesn't work in Eigen.
- x.squaredNorm() // dot(x, x) Note the equivalence is not true for complex
- x.dot(y) // dot(x, y)
- x.cross(y) // cross(x, y) Requires #include <Eigen/Geometry>
+R.sum() // sum(R(:))
+R.colwise.sum() // sum(R)
+R.rowwise.sum() // sum(R, 2) or sum(R')'
+R.trace() // trace(R)
+R.all() // all(R(:))
+R.colwise().all() // all(R)
+R.rowwise().all() // all(R, 2)
+R.any() // any(R(:))
+R.colwise().any() // any(R)
+R.rowwise().any() // any(R, 2)
- // Eigen can map existing memory into Eigen matrices.
- float array[3];
- Map<Vector3f>(array, 3).fill(10);
- int data[4] = 1, 2, 3, 4;
- Matrix2i mat2x2(data);
- MatrixXi mat2x2 = Map<Matrix2i>(data);
- MatrixXi mat2x2 = Map<MatrixXi>(data, 2, 2);
+// Dot products, norms, etc.
+// Eigen // Matlab
+x.norm() // norm(x). Note that norm(R) doesn't work in Eigen.
+x.squaredNorm() // dot(x, x) Note the equivalence is not true for complex
+x.dot(y) // dot(x, y)
+x.cross(y) // cross(x, y) Requires #include <Eigen/Geometry>
- // Solve Ax = b. Result stored in x. Matlab: x = A \ b.
- bool solved;
- solved = A.ldlt().solve(b, &x)); // A symmetric p.s.d.
- solved = A.llt() .solve(b, &x)); // A symmetric p.d.
- solved = A.lu() .solve(b, &x)); // Stable and fast.
- solved = A.qr() .solve(b, &x)); // No pivoting.
- solved = A.svd() .solve(b, &x)); // Most stable, slowest.
- // .ldlt() -> .matrixL() and .matrixD()
- // .llt() -> .matrixL()
- // .lu() -> .matrixL() and .matrixU()
- // .qr() -> .matrixQ() and .matrixR()
- // .svd() -> .matrixU(), .singularValues(), and .matrixV()
+// Eigen can map existing memory into Eigen matrices.
+float array[3];
+Map<Vector3f>(array, 3).fill(10);
+int data[4] = 1, 2, 3, 4;
+Matrix2i mat2x2(data);
+MatrixXi mat2x2 = Map<Matrix2i>(data);
+MatrixXi mat2x2 = Map<MatrixXi>(data, 2, 2);
- // Eigenvalue problems
- // Eigen // Matlab
- A.eigenvalues(); // eig(A);
- EigenSolver<Matrix3d> eig(A); // [vec val] = eig(A)
- eig.eigenvalues(); // diag(val)
- eig.eigenvectors(); // vec
+// Solve Ax = b. Result stored in x. Matlab: x = A \ b.
+bool solved;
+solved = A.ldlt().solve(b, &x)); // A sym. p.s.d. #include <Eigen/Cholesky>
+solved = A.llt() .solve(b, &x)); // A sym. p.d. #include <Eigen/Cholesky>
+solved = A.lu() .solve(b, &x)); // Stable and fast. #include <Eigen/LU>
+solved = A.qr() .solve(b, &x)); // No pivoting. #include <Eigen/QR>
+solved = A.svd() .solve(b, &x)); // Stable, slowest. #include <Eigen/SVD>
+// .ldlt() -> .matrixL() and .matrixD()
+// .llt() -> .matrixL()
+// .lu() -> .matrixL() and .matrixU()
+// .qr() -> .matrixQ() and .matrixR()
+// .svd() -> .matrixU(), .singularValues(), and .matrixV()
-__________
-Main author: Keir Mierle \ No newline at end of file
+// Eigenvalue problems
+// Eigen // Matlab
+A.eigenvalues(); // eig(A);
+EigenSolver<Matrix3d> eig(A); // [vec val] = eig(A)
+eig.eigenvalues(); // diag(val)
+eig.eigenvectors(); // vec