aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/TutorialMatrixClass.dox
diff options
context:
space:
mode:
authorGravatar David Tellenbach <david.tellenbach@tellnotes.org>2019-01-21 16:25:57 +0100
committerGravatar David Tellenbach <david.tellenbach@tellnotes.org>2019-01-21 16:25:57 +0100
commitdb152b9ee6effd3799f70a621f495c427cb3c33f (patch)
tree25a9c96f0cdfbed28072ea7e2f8602412ce6de7f /doc/TutorialMatrixClass.dox
parent543529da6a1eabf415f4f8b56495fad76b57ba22 (diff)
PR 572: Add initializer list constructors to Matrix and Array (include unit tests and doc)
- {1,2,3,4,5,...} for fixed-size vectors only - {{1,2,3},{4,5,6}} for the general cases - {{1,2,3,4,5,....}} is allowed for both row and column-vector
Diffstat (limited to 'doc/TutorialMatrixClass.dox')
-rw-r--r--doc/TutorialMatrixClass.dox29
1 files changed, 28 insertions, 1 deletions
diff --git a/doc/TutorialMatrixClass.dox b/doc/TutorialMatrixClass.dox
index 7ea0cd789..fc0ce5b1e 100644
--- a/doc/TutorialMatrixClass.dox
+++ b/doc/TutorialMatrixClass.dox
@@ -101,13 +101,40 @@ Matrix3f a(3,3);
\endcode
and is a no-operation.
-Finally, we also offer some constructors to initialize the coefficients of small fixed-size vectors up to size 4:
+Additionally, we also offer some constructors to initialize the coefficients of small fixed-size vectors up to size 4:
\code
Vector2d a(5.0, 6.0);
Vector3d b(5.0, 6.0, 7.0);
Vector4d c(5.0, 6.0, 7.0, 8.0);
\endcode
+If C++11 is enabled, matrices can be constructed and initialized using initializer lists. In the case of fixed-sized vectors
+and rowvectors a simple initializer list can be passed:
+\code
+Vector2i a {1, 2}; // A vector containing the elements {1, 2}
+Matrix<int, 4, 1> b {1, 2, 3, 4}; // A row-vector containing the elements {1, 2, 3, 4}
+Matrix<int, 1, 4> c {1, 2, 3, 4}; // A vector containing the elements {1, 2, 3, 4}
+\endcode
+
+In the case of fixed or dynamically sized matrices an initializer list containing an initializer list for each row
+can be passed. If the matrix is fixed-sized, the number of elements that are passed must match the dimensions.
+\code
+MatrixXi a {
+ {1, 2}, // first row
+ {3, 4} // second row
+};
+Matrix<double, 2, 3> b {
+ {2.0, 3.0, 4.0},
+ {5.0, 6.0, 7.0},
+};
+\endcode
+
+In the case of vectors and rowvectors, the following shorthand notation can be used:
+\code
+VectorXd a {{1.5, 2.5, 3.5}}; // A vector with 3 rows
+RowVectorXd b {{1.0, 2.0, 3.0, 4.0}}; // A rowvector with 4 columns
+\endcode
+
\section TutorialMatrixCoeffAccessors Coefficient accessors
The primary coefficient accessors and mutators in Eigen are the overloaded parenthesis operators.