aboutsummaryrefslogtreecommitdiff
path: root/doc/snippets
diff options
context:
space:
mode:
Diffstat (limited to 'doc/snippets')
-rw-r--r--doc/snippets/Array_initializer_list_23_cxx11.cpp5
-rw-r--r--doc/snippets/Array_initializer_list_vector_cxx11.cpp2
-rw-r--r--doc/snippets/Array_variadic_ctor_cxx11.cpp3
-rw-r--r--doc/snippets/BiCGSTAB_simple.cpp2
-rw-r--r--doc/snippets/BiCGSTAB_step_by_step.cpp2
-rw-r--r--doc/snippets/CMakeLists.txt44
-rw-r--r--doc/snippets/ComplexEigenSolver_eigenvectors.cpp2
-rw-r--r--doc/snippets/Cwise_rint.cpp3
-rw-r--r--doc/snippets/DenseBase_LinSpaced_seq_deprecated.cpp (renamed from doc/snippets/DenseBase_LinSpaced_seq.cpp)0
-rw-r--r--doc/snippets/DirectionWise_hnormalized.cpp3
-rw-r--r--doc/snippets/Jacobi_makeGivens.cpp2
-rw-r--r--doc/snippets/Jacobi_makeJacobi.cpp2
-rw-r--r--doc/snippets/Map_placement_new.cpp2
-rw-r--r--doc/snippets/MatrixBase_colwise_iterator_cxx11.cpp12
-rw-r--r--doc/snippets/MatrixBase_cwiseArg.cpp3
-rw-r--r--doc/snippets/MatrixBase_cwiseEqual.cpp2
-rw-r--r--doc/snippets/MatrixBase_cwiseNotEqual.cpp2
-rw-r--r--doc/snippets/MatrixBase_hnormalized.cpp2
-rw-r--r--doc/snippets/MatrixBase_homogeneous.cpp2
-rw-r--r--doc/snippets/MatrixBase_reshaped_auto.cpp4
-rw-r--r--doc/snippets/MatrixBase_reshaped_fixed.cpp3
-rw-r--r--doc/snippets/MatrixBase_reshaped_int_int.cpp3
-rw-r--r--doc/snippets/MatrixBase_reshaped_to_vector.cpp4
-rw-r--r--doc/snippets/Matrix_Map_stride.cpp7
-rw-r--r--doc/snippets/Matrix_initializer_list_23_cxx11.cpp5
-rw-r--r--doc/snippets/Matrix_initializer_list_vector_cxx11.cpp2
-rw-r--r--doc/snippets/Matrix_variadic_ctor_cxx11.cpp3
-rw-r--r--doc/snippets/SelfAdjointEigenSolver_eigenvectors.cpp2
-rw-r--r--doc/snippets/Slicing_arrayexpr.cpp4
-rw-r--r--doc/snippets/Slicing_custom_padding_cxx11.cpp12
-rw-r--r--doc/snippets/Slicing_rawarray_cxx11.cpp5
-rw-r--r--doc/snippets/Slicing_stdvector_cxx11.cpp4
-rw-r--r--doc/snippets/TopicAliasing_mult4.cpp2
-rw-r--r--doc/snippets/Tridiagonalization_decomposeInPlace.cpp3
-rw-r--r--doc/snippets/Tutorial_ReshapeMat2Mat.cpp2
-rw-r--r--doc/snippets/Tutorial_ReshapeMat2Vec.cpp2
-rw-r--r--doc/snippets/Tutorial_SlicingCol.cpp2
-rw-r--r--doc/snippets/Tutorial_SlicingVec.cpp2
-rw-r--r--doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp4
-rw-r--r--doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp5
-rw-r--r--doc/snippets/Tutorial_reshaped_vs_resize_1.cpp5
-rw-r--r--doc/snippets/Tutorial_reshaped_vs_resize_2.cpp6
-rw-r--r--doc/snippets/Tutorial_std_sort.cpp4
-rw-r--r--doc/snippets/Tutorial_std_sort_rows_cxx11.cpp5
-rw-r--r--doc/snippets/VectorwiseOp_homogeneous.cpp3
-rw-r--r--doc/snippets/compile_snippet.cpp.in5
-rw-r--r--doc/snippets/tut_arithmetic_transpose_aliasing.cpp2
-rw-r--r--doc/snippets/tut_arithmetic_transpose_inplace.cpp2
48 files changed, 166 insertions, 41 deletions
diff --git a/doc/snippets/Array_initializer_list_23_cxx11.cpp b/doc/snippets/Array_initializer_list_23_cxx11.cpp
new file mode 100644
index 000000000..2c2166eab
--- /dev/null
+++ b/doc/snippets/Array_initializer_list_23_cxx11.cpp
@@ -0,0 +1,5 @@
+ArrayXXi a {
+ {1, 2, 3},
+ {3, 4, 5}
+};
+cout << a << endl;
diff --git a/doc/snippets/Array_initializer_list_vector_cxx11.cpp b/doc/snippets/Array_initializer_list_vector_cxx11.cpp
new file mode 100644
index 000000000..a668d84ac
--- /dev/null
+++ b/doc/snippets/Array_initializer_list_vector_cxx11.cpp
@@ -0,0 +1,2 @@
+Array<int, Dynamic, 1> v {{1, 2, 3, 4, 5}};
+cout << v << endl;
diff --git a/doc/snippets/Array_variadic_ctor_cxx11.cpp b/doc/snippets/Array_variadic_ctor_cxx11.cpp
new file mode 100644
index 000000000..0e4ec4469
--- /dev/null
+++ b/doc/snippets/Array_variadic_ctor_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;
diff --git a/doc/snippets/BiCGSTAB_simple.cpp b/doc/snippets/BiCGSTAB_simple.cpp
index 5520f4f1f..8c8829fd3 100644
--- a/doc/snippets/BiCGSTAB_simple.cpp
+++ b/doc/snippets/BiCGSTAB_simple.cpp
@@ -8,4 +8,4 @@
std::cout << "#iterations: " << solver.iterations() << std::endl;
std::cout << "estimated error: " << solver.error() << std::endl;
/* ... update b ... */
- x = solver.solve(b); // solve again \ No newline at end of file
+ x = solver.solve(b); // solve again
diff --git a/doc/snippets/BiCGSTAB_step_by_step.cpp b/doc/snippets/BiCGSTAB_step_by_step.cpp
index 06147bb81..6c95d5a9c 100644
--- a/doc/snippets/BiCGSTAB_step_by_step.cpp
+++ b/doc/snippets/BiCGSTAB_step_by_step.cpp
@@ -11,4 +11,4 @@
x = solver.solveWithGuess(b,x);
std::cout << i << " : " << solver.error() << std::endl;
++i;
- } while (solver.info()!=Success && i<100); \ No newline at end of file
+ } while (solver.info()!=Success && i<100);
diff --git a/doc/snippets/CMakeLists.txt b/doc/snippets/CMakeLists.txt
index 1baf32fba..65f195a31 100644
--- a/doc/snippets/CMakeLists.txt
+++ b/doc/snippets/CMakeLists.txt
@@ -6,21 +6,31 @@ foreach(snippet_src ${snippets_SRCS})
get_filename_component(snippet ${snippet_src} NAME_WE)
set(compile_snippet_target compile_${snippet})
set(compile_snippet_src ${compile_snippet_target}.cpp)
- file(READ ${snippet_src} snippet_source_code)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile_snippet.cpp.in
- ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
- add_executable(${compile_snippet_target}
- ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
- if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
- target_link_libraries(${compile_snippet_target} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
+ if((NOT ${snippet_src} MATCHES "cxx11") OR EIGEN_COMPILER_SUPPORT_CPP11)
+ file(READ ${snippet_src} snippet_source_code)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile_snippet.cpp.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
+ add_executable(${compile_snippet_target}
+ ${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src})
+ if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
+ target_link_libraries(${compile_snippet_target} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
+ endif()
+ if(${snippet_src} MATCHES "cxx11")
+ set_target_properties(${compile_snippet_target} PROPERTIES COMPILE_FLAGS "-std=c++11")
+ endif()
+ if(${snippet_src} MATCHES "deprecated")
+ set_target_properties(${compile_snippet_target} PROPERTIES COMPILE_FLAGS "-DEIGEN_NO_DEPRECATED_WARNING")
+ endif()
+ add_custom_command(
+ TARGET ${compile_snippet_target}
+ POST_BUILD
+ COMMAND ${compile_snippet_target}
+ ARGS >${CMAKE_CURRENT_BINARY_DIR}/${snippet}.out
+ )
+ add_dependencies(all_snippets ${compile_snippet_target})
+ set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src}
+ PROPERTIES OBJECT_DEPENDS ${snippet_src})
+ else()
+ message("skip snippet ${snippet_src} because compiler does not support C++11")
endif()
- add_custom_command(
- TARGET ${compile_snippet_target}
- POST_BUILD
- COMMAND ${compile_snippet_target}
- ARGS >${CMAKE_CURRENT_BINARY_DIR}/${snippet}.out
- )
- add_dependencies(all_snippets ${compile_snippet_target})
- set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src}
- PROPERTIES OBJECT_DEPENDS ${snippet_src})
-endforeach(snippet_src)
+endforeach()
diff --git a/doc/snippets/ComplexEigenSolver_eigenvectors.cpp b/doc/snippets/ComplexEigenSolver_eigenvectors.cpp
index bb1c2ccf1..adeed9af6 100644
--- a/doc/snippets/ComplexEigenSolver_eigenvectors.cpp
+++ b/doc/snippets/ComplexEigenSolver_eigenvectors.cpp
@@ -1,4 +1,4 @@
MatrixXcf ones = MatrixXcf::Ones(3,3);
ComplexEigenSolver<MatrixXcf> ces(ones);
cout << "The first eigenvector of the 3x3 matrix of ones is:"
- << endl << ces.eigenvectors().col(1) << endl;
+ << endl << ces.eigenvectors().col(0) << endl;
diff --git a/doc/snippets/Cwise_rint.cpp b/doc/snippets/Cwise_rint.cpp
new file mode 100644
index 000000000..1dc7b2fd1
--- /dev/null
+++ b/doc/snippets/Cwise_rint.cpp
@@ -0,0 +1,3 @@
+ArrayXd v = ArrayXd::LinSpaced(7,-2,2);
+cout << v << endl << endl;
+cout << rint(v) << endl;
diff --git a/doc/snippets/DenseBase_LinSpaced_seq.cpp b/doc/snippets/DenseBase_LinSpaced_seq_deprecated.cpp
index f55c5085d..f55c5085d 100644
--- a/doc/snippets/DenseBase_LinSpaced_seq.cpp
+++ b/doc/snippets/DenseBase_LinSpaced_seq_deprecated.cpp
diff --git a/doc/snippets/DirectionWise_hnormalized.cpp b/doc/snippets/DirectionWise_hnormalized.cpp
index 3410790a8..2451f6e7b 100644
--- a/doc/snippets/DirectionWise_hnormalized.cpp
+++ b/doc/snippets/DirectionWise_hnormalized.cpp
@@ -1,7 +1,6 @@
-typedef Matrix<double,4,Dynamic> Matrix4Xd;
Matrix4Xd M = Matrix4Xd::Random(4,5);
Projective3d P(Matrix4d::Random());
cout << "The matrix M is:" << endl << M << endl << endl;
cout << "M.colwise().hnormalized():" << endl << M.colwise().hnormalized() << endl << endl;
cout << "P*M:" << endl << P*M << endl << endl;
-cout << "(P*M).colwise().hnormalized():" << endl << (P*M).colwise().hnormalized() << endl << endl; \ No newline at end of file
+cout << "(P*M).colwise().hnormalized():" << endl << (P*M).colwise().hnormalized() << endl << endl;
diff --git a/doc/snippets/Jacobi_makeGivens.cpp b/doc/snippets/Jacobi_makeGivens.cpp
index 4b733c306..6f8ec054a 100644
--- a/doc/snippets/Jacobi_makeGivens.cpp
+++ b/doc/snippets/Jacobi_makeGivens.cpp
@@ -3,4 +3,4 @@ JacobiRotation<float> G;
G.makeGivens(v.x(), v.y());
cout << "Here is the vector v:" << endl << v << endl;
v.applyOnTheLeft(0, 1, G.adjoint());
-cout << "Here is the vector J' * v:" << endl << v << endl; \ No newline at end of file
+cout << "Here is the vector J' * v:" << endl << v << endl;
diff --git a/doc/snippets/Jacobi_makeJacobi.cpp b/doc/snippets/Jacobi_makeJacobi.cpp
index 0cc331d9f..a86e80a62 100644
--- a/doc/snippets/Jacobi_makeJacobi.cpp
+++ b/doc/snippets/Jacobi_makeJacobi.cpp
@@ -5,4 +5,4 @@ J.makeJacobi(m, 0, 1);
cout << "Here is the matrix m:" << endl << m << endl;
m.applyOnTheLeft(0, 1, J.adjoint());
m.applyOnTheRight(0, 1, J);
-cout << "Here is the matrix J' * m * J:" << endl << m << endl; \ No newline at end of file
+cout << "Here is the matrix J' * m * J:" << endl << m << endl;
diff --git a/doc/snippets/Map_placement_new.cpp b/doc/snippets/Map_placement_new.cpp
index 2e40eca32..83b83a893 100644
--- a/doc/snippets/Map_placement_new.cpp
+++ b/doc/snippets/Map_placement_new.cpp
@@ -2,4 +2,4 @@ int data[] = {1,2,3,4,5,6,7,8,9};
Map<RowVectorXi> v(data,4);
cout << "The mapped vector v is: " << v << "\n";
new (&v) Map<RowVectorXi>(data+4,5);
-cout << "Now v is: " << v << "\n"; \ No newline at end of file
+cout << "Now v is: " << v << "\n";
diff --git a/doc/snippets/MatrixBase_colwise_iterator_cxx11.cpp b/doc/snippets/MatrixBase_colwise_iterator_cxx11.cpp
new file mode 100644
index 000000000..116063fb1
--- /dev/null
+++ b/doc/snippets/MatrixBase_colwise_iterator_cxx11.cpp
@@ -0,0 +1,12 @@
+Matrix3i m = Matrix3i::Random();
+cout << "Here is the initial matrix m:" << endl << m << endl;
+int i = -1;
+for(auto c: m.colwise()) {
+ c *= i;
+ ++i;
+}
+cout << "Here is the matrix m after the for-range-loop:" << endl << m << endl;
+auto cols = m.colwise();
+auto it = std::find_if(cols.cbegin(), cols.cend(),
+ [](Matrix3i::ConstColXpr x) { return x.squaredNorm() == 0; });
+cout << "The first empty column is: " << distance(cols.cbegin(),it) << endl;
diff --git a/doc/snippets/MatrixBase_cwiseArg.cpp b/doc/snippets/MatrixBase_cwiseArg.cpp
new file mode 100644
index 000000000..e0857cf97
--- /dev/null
+++ b/doc/snippets/MatrixBase_cwiseArg.cpp
@@ -0,0 +1,3 @@
+MatrixXcf v = MatrixXcf::Random(2, 3);
+cout << v << endl << endl;
+cout << v.cwiseArg() << endl; \ No newline at end of file
diff --git a/doc/snippets/MatrixBase_cwiseEqual.cpp b/doc/snippets/MatrixBase_cwiseEqual.cpp
index eb3656f4c..469af642c 100644
--- a/doc/snippets/MatrixBase_cwiseEqual.cpp
+++ b/doc/snippets/MatrixBase_cwiseEqual.cpp
@@ -3,5 +3,5 @@ m << 1, 0,
1, 1;
cout << "Comparing m with identity matrix:" << endl;
cout << m.cwiseEqual(MatrixXi::Identity(2,2)) << endl;
-int count = m.cwiseEqual(MatrixXi::Identity(2,2)).count();
+Index count = m.cwiseEqual(MatrixXi::Identity(2,2)).count();
cout << "Number of coefficients that are equal: " << count << endl;
diff --git a/doc/snippets/MatrixBase_cwiseNotEqual.cpp b/doc/snippets/MatrixBase_cwiseNotEqual.cpp
index 6a2e4fb6c..7f0a105d6 100644
--- a/doc/snippets/MatrixBase_cwiseNotEqual.cpp
+++ b/doc/snippets/MatrixBase_cwiseNotEqual.cpp
@@ -3,5 +3,5 @@ m << 1, 0,
1, 1;
cout << "Comparing m with identity matrix:" << endl;
cout << m.cwiseNotEqual(MatrixXi::Identity(2,2)) << endl;
-int count = m.cwiseNotEqual(MatrixXi::Identity(2,2)).count();
+Index count = m.cwiseNotEqual(MatrixXi::Identity(2,2)).count();
cout << "Number of coefficients that are not equal: " << count << endl;
diff --git a/doc/snippets/MatrixBase_hnormalized.cpp b/doc/snippets/MatrixBase_hnormalized.cpp
index 652cd77c0..b714adcc3 100644
--- a/doc/snippets/MatrixBase_hnormalized.cpp
+++ b/doc/snippets/MatrixBase_hnormalized.cpp
@@ -3,4 +3,4 @@ Projective3d P(Matrix4d::Random());
cout << "v = " << v.transpose() << "]^T" << endl;
cout << "v.hnormalized() = " << v.hnormalized().transpose() << "]^T" << endl;
cout << "P*v = " << (P*v).transpose() << "]^T" << endl;
-cout << "(P*v).hnormalized() = " << (P*v).hnormalized().transpose() << "]^T" << endl; \ No newline at end of file
+cout << "(P*v).hnormalized() = " << (P*v).hnormalized().transpose() << "]^T" << endl;
diff --git a/doc/snippets/MatrixBase_homogeneous.cpp b/doc/snippets/MatrixBase_homogeneous.cpp
index 457c28f91..263196097 100644
--- a/doc/snippets/MatrixBase_homogeneous.cpp
+++ b/doc/snippets/MatrixBase_homogeneous.cpp
@@ -3,4 +3,4 @@ Projective3d P(Matrix4d::Random());
cout << "v = [" << v.transpose() << "]^T" << endl;
cout << "h.homogeneous() = [" << v.homogeneous().transpose() << "]^T" << endl;
cout << "(P * v.homogeneous()) = [" << (P * v.homogeneous()).transpose() << "]^T" << endl;
-cout << "(P * v.homogeneous()).hnormalized() = [" << (P * v.homogeneous()).eval().hnormalized().transpose() << "]^T" << endl; \ No newline at end of file
+cout << "(P * v.homogeneous()).hnormalized() = [" << (P * v.homogeneous()).eval().hnormalized().transpose() << "]^T" << endl;
diff --git a/doc/snippets/MatrixBase_reshaped_auto.cpp b/doc/snippets/MatrixBase_reshaped_auto.cpp
new file mode 100644
index 000000000..59f9d3f60
--- /dev/null
+++ b/doc/snippets/MatrixBase_reshaped_auto.cpp
@@ -0,0 +1,4 @@
+Matrix4i m = Matrix4i::Random();
+cout << "Here is the matrix m:" << endl << m << endl;
+cout << "Here is m.reshaped(2, AutoSize):" << endl << m.reshaped(2, AutoSize) << endl;
+cout << "Here is m.reshaped<RowMajor>(AutoSize, fix<8>):" << endl << m.reshaped<RowMajor>(AutoSize, fix<8>) << endl;
diff --git a/doc/snippets/MatrixBase_reshaped_fixed.cpp b/doc/snippets/MatrixBase_reshaped_fixed.cpp
new file mode 100644
index 000000000..3e9e2cfb6
--- /dev/null
+++ b/doc/snippets/MatrixBase_reshaped_fixed.cpp
@@ -0,0 +1,3 @@
+Matrix4i m = Matrix4i::Random();
+cout << "Here is the matrix m:" << endl << m << endl;
+cout << "Here is m.reshaped(fix<2>,fix<8>):" << endl << m.reshaped(fix<2>,fix<8>) << endl;
diff --git a/doc/snippets/MatrixBase_reshaped_int_int.cpp b/doc/snippets/MatrixBase_reshaped_int_int.cpp
new file mode 100644
index 000000000..af4ca592f
--- /dev/null
+++ b/doc/snippets/MatrixBase_reshaped_int_int.cpp
@@ -0,0 +1,3 @@
+Matrix4i 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;
diff --git a/doc/snippets/MatrixBase_reshaped_to_vector.cpp b/doc/snippets/MatrixBase_reshaped_to_vector.cpp
new file mode 100644
index 000000000..37f65f7c6
--- /dev/null
+++ b/doc/snippets/MatrixBase_reshaped_to_vector.cpp
@@ -0,0 +1,4 @@
+Matrix4i m = Matrix4i::Random();
+cout << "Here is the matrix m:" << endl << m << endl;
+cout << "Here is m.reshaped().transpose():" << endl << m.reshaped().transpose() << endl;
+cout << "Here is m.reshaped<RowMajor>().transpose(): " << endl << m.reshaped<RowMajor>().transpose() << endl;
diff --git a/doc/snippets/Matrix_Map_stride.cpp b/doc/snippets/Matrix_Map_stride.cpp
new file mode 100644
index 000000000..ae42a127a
--- /dev/null
+++ b/doc/snippets/Matrix_Map_stride.cpp
@@ -0,0 +1,7 @@
+Matrix4i A;
+A << 1, 2, 3, 4,
+ 5, 6, 7, 8,
+ 9, 10, 11, 12,
+ 13, 14, 15, 16;
+
+std::cout << Matrix2i::Map(&A(1,1),Stride<8,2>()) << std::endl;
diff --git a/doc/snippets/Matrix_initializer_list_23_cxx11.cpp b/doc/snippets/Matrix_initializer_list_23_cxx11.cpp
new file mode 100644
index 000000000..60280ab58
--- /dev/null
+++ b/doc/snippets/Matrix_initializer_list_23_cxx11.cpp
@@ -0,0 +1,5 @@
+MatrixXd m {
+ {1, 2, 3},
+ {4, 5, 6}
+};
+cout << m << endl;
diff --git a/doc/snippets/Matrix_initializer_list_vector_cxx11.cpp b/doc/snippets/Matrix_initializer_list_vector_cxx11.cpp
new file mode 100644
index 000000000..325257cb0
--- /dev/null
+++ b/doc/snippets/Matrix_initializer_list_vector_cxx11.cpp
@@ -0,0 +1,2 @@
+VectorXi v {{1, 2}};
+cout << v << endl;
diff --git a/doc/snippets/Matrix_variadic_ctor_cxx11.cpp b/doc/snippets/Matrix_variadic_ctor_cxx11.cpp
new file mode 100644
index 000000000..06d33f571
--- /dev/null
+++ b/doc/snippets/Matrix_variadic_ctor_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;
diff --git a/doc/snippets/SelfAdjointEigenSolver_eigenvectors.cpp b/doc/snippets/SelfAdjointEigenSolver_eigenvectors.cpp
index cfc8b0d54..94b0d6ebd 100644
--- a/doc/snippets/SelfAdjointEigenSolver_eigenvectors.cpp
+++ b/doc/snippets/SelfAdjointEigenSolver_eigenvectors.cpp
@@ -1,4 +1,4 @@
MatrixXd ones = MatrixXd::Ones(3,3);
SelfAdjointEigenSolver<MatrixXd> es(ones);
cout << "The first eigenvector of the 3x3 matrix of ones is:"
- << endl << es.eigenvectors().col(1) << endl;
+ << endl << es.eigenvectors().col(0) << endl;
diff --git a/doc/snippets/Slicing_arrayexpr.cpp b/doc/snippets/Slicing_arrayexpr.cpp
new file mode 100644
index 000000000..2df818098
--- /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";
diff --git a/doc/snippets/Slicing_custom_padding_cxx11.cpp b/doc/snippets/Slicing_custom_padding_cxx11.cpp
new file mode 100644
index 000000000..24db98b7d
--- /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<Index>(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";
diff --git a/doc/snippets/Slicing_rawarray_cxx11.cpp b/doc/snippets/Slicing_rawarray_cxx11.cpp
new file mode 100644
index 000000000..1087131ab
--- /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
diff --git a/doc/snippets/Slicing_stdvector_cxx11.cpp b/doc/snippets/Slicing_stdvector_cxx11.cpp
new file mode 100644
index 000000000..555f6625f
--- /dev/null
+++ b/doc/snippets/Slicing_stdvector_cxx11.cpp
@@ -0,0 +1,4 @@
+std::vector<int> 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";
diff --git a/doc/snippets/TopicAliasing_mult4.cpp b/doc/snippets/TopicAliasing_mult4.cpp
index 8a8992f6c..01c1c6d77 100644
--- a/doc/snippets/TopicAliasing_mult4.cpp
+++ b/doc/snippets/TopicAliasing_mult4.cpp
@@ -2,4 +2,4 @@ MatrixXf A(2,2), B(3,2);
B << 2, 0, 0, 3, 1, 1;
A << 2, 0, 0, -2;
A = (B * A).cwiseAbs();
-cout << A; \ No newline at end of file
+cout << A;
diff --git a/doc/snippets/Tridiagonalization_decomposeInPlace.cpp b/doc/snippets/Tridiagonalization_decomposeInPlace.cpp
index 93dcfca1d..3cdce679b 100644
--- a/doc/snippets/Tridiagonalization_decomposeInPlace.cpp
+++ b/doc/snippets/Tridiagonalization_decomposeInPlace.cpp
@@ -4,7 +4,8 @@ cout << "Here is a random symmetric 5x5 matrix:" << endl << A << endl << endl;
VectorXd diag(5);
VectorXd subdiag(4);
-internal::tridiagonalization_inplace(A, diag, subdiag, true);
+VectorXd hcoeffs(4); // Scratch space for householder reflector.
+internal::tridiagonalization_inplace(A, diag, subdiag, hcoeffs, true);
cout << "The orthogonal matrix Q is:" << endl << A << endl;
cout << "The diagonal of the tridiagonal matrix T is:" << endl << diag << endl;
cout << "The subdiagonal of the tridiagonal matrix T is:" << endl << subdiag << endl;
diff --git a/doc/snippets/Tutorial_ReshapeMat2Mat.cpp b/doc/snippets/Tutorial_ReshapeMat2Mat.cpp
index f84d6e76d..737afecb8 100644
--- a/doc/snippets/Tutorial_ReshapeMat2Mat.cpp
+++ b/doc/snippets/Tutorial_ReshapeMat2Mat.cpp
@@ -3,4 +3,4 @@ M1 << 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12;
Map<MatrixXf> M2(M1.data(), 6,2);
-cout << "M2:" << endl << M2 << endl; \ No newline at end of file
+cout << "M2:" << endl << M2 << endl;
diff --git a/doc/snippets/Tutorial_ReshapeMat2Vec.cpp b/doc/snippets/Tutorial_ReshapeMat2Vec.cpp
index 95bd4e0e6..32980a790 100644
--- a/doc/snippets/Tutorial_ReshapeMat2Vec.cpp
+++ b/doc/snippets/Tutorial_ReshapeMat2Vec.cpp
@@ -8,4 +8,4 @@ cout << "v1:" << endl << v1 << endl;
Matrix<float,Dynamic,Dynamic,RowMajor> M2(M1);
Map<RowVectorXf> v2(M2.data(), M2.size());
-cout << "v2:" << endl << v2 << endl; \ No newline at end of file
+cout << "v2:" << endl << v2 << endl;
diff --git a/doc/snippets/Tutorial_SlicingCol.cpp b/doc/snippets/Tutorial_SlicingCol.cpp
index f667ff689..695d13014 100644
--- a/doc/snippets/Tutorial_SlicingCol.cpp
+++ b/doc/snippets/Tutorial_SlicingCol.cpp
@@ -8,4 +8,4 @@ RowMajorMatrixXf M3(M1);
cout << "Row major input:" << endl << M3 << "\n";
Map<RowMajorMatrixXf,0,Stride<Dynamic,3> > M4(M3.data(), M3.rows(), (M3.cols()+2)/3,
Stride<Dynamic,3>(M3.outerStride(),3));
-cout << "1 column over 3:" << endl << M4 << "\n"; \ No newline at end of file
+cout << "1 column over 3:" << endl << M4 << "\n";
diff --git a/doc/snippets/Tutorial_SlicingVec.cpp b/doc/snippets/Tutorial_SlicingVec.cpp
index 07e10bf69..9b822464d 100644
--- a/doc/snippets/Tutorial_SlicingVec.cpp
+++ b/doc/snippets/Tutorial_SlicingVec.cpp
@@ -1,4 +1,4 @@
RowVectorXf v = RowVectorXf::LinSpaced(20,0,19);
cout << "Input:" << endl << v << endl;
Map<RowVectorXf,0,InnerStride<2> > v2(v.data(), v.size()/2);
-cout << "Even:" << v2 << endl; \ No newline at end of file
+cout << "Even:" << v2 << endl;
diff --git a/doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp b/doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp
new file mode 100644
index 000000000..e72e715d8
--- /dev/null
+++ b/doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp
@@ -0,0 +1,4 @@
+VectorXi v = VectorXi::Random(4);
+cout << "Here is the vector v:\n";
+for(auto x : v) cout << x << " ";
+cout << "\n";
diff --git a/doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp b/doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp
new file mode 100644
index 000000000..4a12d26c7
--- /dev/null
+++ b/doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp
@@ -0,0 +1,5 @@
+Matrix2i A = Matrix2i::Random();
+cout << "Here are the coeffs of the 2x2 matrix A:\n";
+for(auto x : A.reshaped())
+ cout << x << " ";
+cout << "\n";
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..e520e8e6b
--- /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;
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<int,Dynamic,Dynamic,RowMajor> 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<AutoOrder>(2, 8):" << endl << m.reshaped<AutoOrder>(2, 8) << endl;
+m.resize(2,8);
+cout << "Here is the matrix m after m.resize(2,8):" << endl << m << endl;
diff --git a/doc/snippets/Tutorial_std_sort.cpp b/doc/snippets/Tutorial_std_sort.cpp
new file mode 100644
index 000000000..cde2a6f1b
--- /dev/null
+++ b/doc/snippets/Tutorial_std_sort.cpp
@@ -0,0 +1,4 @@
+Array4i v = Array4i::Random().abs();
+cout << "Here is the initial vector v:\n" << v.transpose() << "\n";
+std::sort(v.begin(), v.end());
+cout << "Here is the sorted vector v:\n" << v.transpose() << "\n";
diff --git a/doc/snippets/Tutorial_std_sort_rows_cxx11.cpp b/doc/snippets/Tutorial_std_sort_rows_cxx11.cpp
new file mode 100644
index 000000000..03641603d
--- /dev/null
+++ b/doc/snippets/Tutorial_std_sort_rows_cxx11.cpp
@@ -0,0 +1,5 @@
+ArrayXXi A = ArrayXXi::Random(4,4).abs();
+cout << "Here is the initial matrix A:\n" << A << "\n";
+for(auto row : A.rowwise())
+ std::sort(row.begin(), row.end());
+cout << "Here is the sorted matrix A:\n" << A << "\n";
diff --git a/doc/snippets/VectorwiseOp_homogeneous.cpp b/doc/snippets/VectorwiseOp_homogeneous.cpp
index aba4fed0e..67cf5737d 100644
--- a/doc/snippets/VectorwiseOp_homogeneous.cpp
+++ b/doc/snippets/VectorwiseOp_homogeneous.cpp
@@ -1,7 +1,6 @@
-typedef Matrix<double,3,Dynamic> Matrix3Xd;
Matrix3Xd M = Matrix3Xd::Random(3,5);
Projective3d P(Matrix4d::Random());
cout << "The matrix M is:" << endl << M << endl << endl;
cout << "M.colwise().homogeneous():" << endl << M.colwise().homogeneous() << endl << endl;
cout << "P * M.colwise().homogeneous():" << endl << P * M.colwise().homogeneous() << endl << endl;
-cout << "P * M.colwise().homogeneous().hnormalized(): " << endl << (P * M.colwise().homogeneous()).colwise().hnormalized() << endl << endl; \ No newline at end of file
+cout << "P * M.colwise().homogeneous().hnormalized(): " << endl << (P * M.colwise().homogeneous()).colwise().hnormalized() << endl << endl;
diff --git a/doc/snippets/compile_snippet.cpp.in b/doc/snippets/compile_snippet.cpp.in
index d63f371a3..c11457a3f 100644
--- a/doc/snippets/compile_snippet.cpp.in
+++ b/doc/snippets/compile_snippet.cpp.in
@@ -15,6 +15,9 @@ using namespace std;
int main(int, char**)
{
cout.precision(3);
- ${snippet_source_code}
+// intentionally remove indentation of snippet
+{
+${snippet_source_code}
+}
return 0;
}
diff --git a/doc/snippets/tut_arithmetic_transpose_aliasing.cpp b/doc/snippets/tut_arithmetic_transpose_aliasing.cpp
index c8e4746d0..f82e6f2ac 100644
--- a/doc/snippets/tut_arithmetic_transpose_aliasing.cpp
+++ b/doc/snippets/tut_arithmetic_transpose_aliasing.cpp
@@ -2,4 +2,4 @@ Matrix2i a; a << 1, 2, 3, 4;
cout << "Here is the matrix a:\n" << a << endl;
a = a.transpose(); // !!! do NOT do this !!!
-cout << "and the result of the aliasing effect:\n" << a << endl; \ No newline at end of file
+cout << "and the result of the aliasing effect:\n" << a << endl;
diff --git a/doc/snippets/tut_arithmetic_transpose_inplace.cpp b/doc/snippets/tut_arithmetic_transpose_inplace.cpp
index 7a069ff23..5c81c9e02 100644
--- a/doc/snippets/tut_arithmetic_transpose_inplace.cpp
+++ b/doc/snippets/tut_arithmetic_transpose_inplace.cpp
@@ -3,4 +3,4 @@ cout << "Here is the initial matrix a:\n" << a << endl;
a.transposeInPlace();
-cout << "and after being transposed:\n" << a << endl; \ No newline at end of file
+cout << "and after being transposed:\n" << a << endl;