From db152b9ee6effd3799f70a621f495c427cb3c33f Mon Sep 17 00:00:00 2001 From: David Tellenbach Date: Mon, 21 Jan 2019 16:25:57 +0100 Subject: 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 --- doc/TutorialMatrixClass.dox | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'doc/TutorialMatrixClass.dox') 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 b {1, 2, 3, 4}; // A row-vector containing the elements {1, 2, 3, 4} +Matrix 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 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. -- cgit v1.2.3