diff options
author | David Tellenbach <david.tellenbach@tellnotes.org> | 2019-01-21 16:25:57 +0100 |
---|---|---|
committer | David Tellenbach <david.tellenbach@tellnotes.org> | 2019-01-21 16:25:57 +0100 |
commit | db152b9ee6effd3799f70a621f495c427cb3c33f (patch) | |
tree | 25a9c96f0cdfbed28072ea7e2f8602412ce6de7f /doc | |
parent | 543529da6a1eabf415f4f8b56495fad76b57ba22 (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')
-rw-r--r-- | doc/TutorialMatrixClass.dox | 29 | ||||
-rw-r--r-- | doc/snippets/Array_initializer_list2_cxx11.cpp | 3 | ||||
-rw-r--r-- | doc/snippets/Array_initializer_list_cxx11.cpp | 6 | ||||
-rw-r--r-- | doc/snippets/Matrix_initializer_list2_cxx11.cpp | 3 | ||||
-rw-r--r-- | doc/snippets/Matrix_initializer_list_cxx11.cpp | 6 | ||||
-rw-r--r-- | doc/snippets/Tutorial_std_sort_rows_cxx11.cpp (renamed from doc/snippets/Tutorial_std_sort_rows.cpp) | 0 |
6 files changed, 46 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. diff --git a/doc/snippets/Array_initializer_list2_cxx11.cpp b/doc/snippets/Array_initializer_list2_cxx11.cpp new file mode 100644 index 000000000..20e74546a --- /dev/null +++ b/doc/snippets/Array_initializer_list2_cxx11.cpp @@ -0,0 +1,3 @@ +Array<int, 1, 6> a {1, 2, 3, 4, 5, 6}; +Array<int, 3, 1> b {1, 2, 3}; +cout << a << "\n\n" << b << endl;
\ No newline at end of file diff --git a/doc/snippets/Array_initializer_list_cxx11.cpp b/doc/snippets/Array_initializer_list_cxx11.cpp new file mode 100644 index 000000000..d2f46e268 --- /dev/null +++ b/doc/snippets/Array_initializer_list_cxx11.cpp @@ -0,0 +1,6 @@ +Array<int, 2, 3> a { + {1, 2, 3}, + {3, 4, 5} +}; +Array<int, Dynamic, 1> v {{1, 2, 3, 4, 5}}; +cout << a << "\n\n" << v << endl;
\ No newline at end of file diff --git a/doc/snippets/Matrix_initializer_list2_cxx11.cpp b/doc/snippets/Matrix_initializer_list2_cxx11.cpp new file mode 100644 index 000000000..2fde52b8d --- /dev/null +++ b/doc/snippets/Matrix_initializer_list2_cxx11.cpp @@ -0,0 +1,3 @@ +Matrix<int, 1, 6> a {1, 2, 3, 4, 5, 6}; +Matrix<int, 3, 1> b {1, 2, 3}; +cout << a << "\n\n" << b << endl;
\ No newline at end of file diff --git a/doc/snippets/Matrix_initializer_list_cxx11.cpp b/doc/snippets/Matrix_initializer_list_cxx11.cpp new file mode 100644 index 000000000..d68787ab6 --- /dev/null +++ b/doc/snippets/Matrix_initializer_list_cxx11.cpp @@ -0,0 +1,6 @@ +Matrix<int, 2, 3> m { + {1, 2, 3}, + {4, 5, 6} +}; +VectorXi v {{1, 2}}; +cout << m << "\n\n" << v << endl;
\ No newline at end of file diff --git a/doc/snippets/Tutorial_std_sort_rows.cpp b/doc/snippets/Tutorial_std_sort_rows_cxx11.cpp index fdd850d13..fdd850d13 100644 --- a/doc/snippets/Tutorial_std_sort_rows.cpp +++ b/doc/snippets/Tutorial_std_sort_rows_cxx11.cpp |