From d7c644213cbf548f67aeb7ed6f872aef96c1dbd2 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 9 Nov 2018 11:35:27 +0100 Subject: Add and update manual pages for slicing, indexing, and reshaping. --- doc/snippets/Slicing_arrayexpr.cpp | 4 ++++ doc/snippets/Slicing_custom_padding_cxx11.cpp | 12 ++++++++++++ doc/snippets/Slicing_rawarray_cxx11.cpp | 5 +++++ doc/snippets/Slicing_stdvector_cxx11.cpp | 4 ++++ doc/snippets/Tutorial_reshaped_vs_resize_1.cpp | 5 +++++ doc/snippets/Tutorial_reshaped_vs_resize_2.cpp | 6 ++++++ 6 files changed, 36 insertions(+) create mode 100644 doc/snippets/Slicing_arrayexpr.cpp create mode 100644 doc/snippets/Slicing_custom_padding_cxx11.cpp create mode 100644 doc/snippets/Slicing_rawarray_cxx11.cpp create mode 100644 doc/snippets/Slicing_stdvector_cxx11.cpp create mode 100644 doc/snippets/Tutorial_reshaped_vs_resize_1.cpp create mode 100644 doc/snippets/Tutorial_reshaped_vs_resize_2.cpp (limited to 'doc/snippets') diff --git a/doc/snippets/Slicing_arrayexpr.cpp b/doc/snippets/Slicing_arrayexpr.cpp new file mode 100644 index 000000000..00b689b90 --- /dev/null +++ b/doc/snippets/Slicing_arrayexpr.cpp @@ -0,0 +1,4 @@ +ArrayXi ind(5); ind<<4,2,5,5,3; +MatrixXi A = MatrixXi::Random(4,6); +cout << "Initial matrix A:\n" << A << "\n\n"; +cout << "A(all,ind-1):\n" << A(all,ind-1) << "\n\n"; \ No newline at end of file diff --git a/doc/snippets/Slicing_custom_padding_cxx11.cpp b/doc/snippets/Slicing_custom_padding_cxx11.cpp new file mode 100644 index 000000000..5dac3d7c9 --- /dev/null +++ b/doc/snippets/Slicing_custom_padding_cxx11.cpp @@ -0,0 +1,12 @@ +struct pad { + Index size() const { return out_size; } + Index operator[] (Index i) const { return std::max(0,i-(out_size-in_size)); } + Index in_size, out_size; +}; + +Matrix3i A; +A.reshaped() = VectorXi::LinSpaced(9,1,9); +cout << "Initial matrix A:\n" << A << "\n\n"; +MatrixXi B(5,5); +B = A(pad{3,5}, pad{3,5}); +cout << "A(pad{3,N}, pad{3,N}):\n" << B << "\n\n"; \ No newline at end of file diff --git a/doc/snippets/Slicing_rawarray_cxx11.cpp b/doc/snippets/Slicing_rawarray_cxx11.cpp new file mode 100644 index 000000000..0d3287a42 --- /dev/null +++ b/doc/snippets/Slicing_rawarray_cxx11.cpp @@ -0,0 +1,5 @@ +#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE +MatrixXi A = MatrixXi::Random(4,6); +cout << "Initial matrix A:\n" << A << "\n\n"; +cout << "A(all,{4,2,5,5,3}):\n" << A(all,{4,2,5,5,3}) << "\n\n"; +#endif \ No newline at end of file diff --git a/doc/snippets/Slicing_stdvector_cxx11.cpp b/doc/snippets/Slicing_stdvector_cxx11.cpp new file mode 100644 index 000000000..469651e38 --- /dev/null +++ b/doc/snippets/Slicing_stdvector_cxx11.cpp @@ -0,0 +1,4 @@ +std::vector ind{4,2,5,5,3}; +MatrixXi A = MatrixXi::Random(4,6); +cout << "Initial matrix A:\n" << A << "\n\n"; +cout << "A(all,ind):\n" << A(all,ind) << "\n\n"; \ No newline at end of file diff --git a/doc/snippets/Tutorial_reshaped_vs_resize_1.cpp b/doc/snippets/Tutorial_reshaped_vs_resize_1.cpp new file mode 100644 index 000000000..686b96c38 --- /dev/null +++ b/doc/snippets/Tutorial_reshaped_vs_resize_1.cpp @@ -0,0 +1,5 @@ +MatrixXi m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.reshaped(2, 8):" << endl << m.reshaped(2, 8) << endl; +m.resize(2,8); +cout << "Here is the matrix m after m.resize(2,8):" << endl << m << endl; \ No newline at end of file diff --git a/doc/snippets/Tutorial_reshaped_vs_resize_2.cpp b/doc/snippets/Tutorial_reshaped_vs_resize_2.cpp new file mode 100644 index 000000000..50dc45488 --- /dev/null +++ b/doc/snippets/Tutorial_reshaped_vs_resize_2.cpp @@ -0,0 +1,6 @@ +Matrix m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.reshaped(2, 8):" << endl << m.reshaped(2, 8) << endl; +cout << "Here is m.reshaped(2, 8):" << endl << m.reshaped(2, 8) << endl; +m.resize(2,8); +cout << "Here is the matrix m after m.resize(2,8):" << endl << m << endl; -- cgit v1.2.3