diff options
Diffstat (limited to 'eigen/doc/snippets')
44 files changed, 210 insertions, 42 deletions
diff --git a/eigen/doc/snippets/BiCGSTAB_simple.cpp b/eigen/doc/snippets/BiCGSTAB_simple.cpp new file mode 100644 index 0000000..5520f4f --- /dev/null +++ b/eigen/doc/snippets/BiCGSTAB_simple.cpp @@ -0,0 +1,11 @@ + int n = 10000; + VectorXd x(n), b(n); + SparseMatrix<double> A(n,n); + /* ... fill A and b ... */ + BiCGSTAB<SparseMatrix<double> > solver; + solver.compute(A); + x = solver.solve(b); + 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 diff --git a/eigen/doc/snippets/BiCGSTAB_step_by_step.cpp b/eigen/doc/snippets/BiCGSTAB_step_by_step.cpp new file mode 100644 index 0000000..06147bb --- /dev/null +++ b/eigen/doc/snippets/BiCGSTAB_step_by_step.cpp @@ -0,0 +1,14 @@ + int n = 10000; + VectorXd x(n), b(n); + SparseMatrix<double> A(n,n); + /* ... fill A and b ... */ + BiCGSTAB<SparseMatrix<double> > solver(A); + // start from a random solution + x = VectorXd::Random(n); + solver.setMaxIterations(1); + int i = 0; + do { + 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 diff --git a/eigen/doc/snippets/CMakeLists.txt b/eigen/doc/snippets/CMakeLists.txt index 1135900..1baf32f 100644 --- a/eigen/doc/snippets/CMakeLists.txt +++ b/eigen/doc/snippets/CMakeLists.txt @@ -24,5 +24,3 @@ foreach(snippet_src ${snippets_SRCS}) set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src} PROPERTIES OBJECT_DEPENDS ${snippet_src}) endforeach(snippet_src) - -ei_add_target_property(compile_tut_arithmetic_transpose_aliasing COMPILE_FLAGS -DEIGEN_NO_DEBUG) diff --git a/eigen/doc/snippets/Cwise_arg.cpp b/eigen/doc/snippets/Cwise_arg.cpp new file mode 100644 index 0000000..3f45133 --- /dev/null +++ b/eigen/doc/snippets/Cwise_arg.cpp @@ -0,0 +1,3 @@ +ArrayXcf v = ArrayXcf::Random(3); +cout << v << endl << endl; +cout << arg(v) << endl; diff --git a/eigen/doc/snippets/Cwise_array_power_array.cpp b/eigen/doc/snippets/Cwise_array_power_array.cpp new file mode 100644 index 0000000..432a76e --- /dev/null +++ b/eigen/doc/snippets/Cwise_array_power_array.cpp @@ -0,0 +1,4 @@ +Array<double,1,3> x(8,25,3), + e(1./3.,0.5,2.); +cout << "[" << x << "]^[" << e << "] = " << x.pow(e) << endl; // using ArrayBase::pow +cout << "[" << x << "]^[" << e << "] = " << pow(x,e) << endl; // using Eigen::pow diff --git a/eigen/doc/snippets/Cwise_atan.cpp b/eigen/doc/snippets/Cwise_atan.cpp new file mode 100644 index 0000000..4468447 --- /dev/null +++ b/eigen/doc/snippets/Cwise_atan.cpp @@ -0,0 +1,2 @@ +ArrayXd v = ArrayXd::LinSpaced(5,0,1); +cout << v.atan() << endl; diff --git a/eigen/doc/snippets/Cwise_boolean_not.cpp b/eigen/doc/snippets/Cwise_boolean_not.cpp new file mode 100644 index 0000000..40009f1 --- /dev/null +++ b/eigen/doc/snippets/Cwise_boolean_not.cpp @@ -0,0 +1,5 @@ +Array3d v(1,2,3); +v(1) *= 0.0/0.0; +v(2) /= 0.0; +cout << v << endl << endl; +cout << !isfinite(v) << endl; diff --git a/eigen/doc/snippets/Cwise_boolean_xor.cpp b/eigen/doc/snippets/Cwise_boolean_xor.cpp new file mode 100644 index 0000000..fafbec8 --- /dev/null +++ b/eigen/doc/snippets/Cwise_boolean_xor.cpp @@ -0,0 +1,2 @@ +Array3d v(-1,2,1), w(-3,2,3); +cout << ((v<w) ^ (v<0)) << endl; diff --git a/eigen/doc/snippets/Cwise_ceil.cpp b/eigen/doc/snippets/Cwise_ceil.cpp new file mode 100644 index 0000000..76cf661 --- /dev/null +++ b/eigen/doc/snippets/Cwise_ceil.cpp @@ -0,0 +1,3 @@ +ArrayXd v = ArrayXd::LinSpaced(7,-2,2); +cout << v << endl << endl; +cout << ceil(v) << endl; diff --git a/eigen/doc/snippets/Cwise_cosh.cpp b/eigen/doc/snippets/Cwise_cosh.cpp new file mode 100644 index 0000000..80ee75d --- /dev/null +++ b/eigen/doc/snippets/Cwise_cosh.cpp @@ -0,0 +1,2 @@ +ArrayXd v = ArrayXd::LinSpaced(5,0,1); +cout << cosh(v) << endl; diff --git a/eigen/doc/snippets/Cwise_floor.cpp b/eigen/doc/snippets/Cwise_floor.cpp new file mode 100644 index 0000000..73756b4 --- /dev/null +++ b/eigen/doc/snippets/Cwise_floor.cpp @@ -0,0 +1,3 @@ +ArrayXd v = ArrayXd::LinSpaced(7,-2,2); +cout << v << endl << endl; +cout << floor(v) << endl; diff --git a/eigen/doc/snippets/Cwise_isFinite.cpp b/eigen/doc/snippets/Cwise_isFinite.cpp new file mode 100644 index 0000000..1da55fd --- /dev/null +++ b/eigen/doc/snippets/Cwise_isFinite.cpp @@ -0,0 +1,5 @@ +Array3d v(1,2,3); +v(1) *= 0.0/0.0; +v(2) /= 0.0; +cout << v << endl << endl; +cout << isfinite(v) << endl; diff --git a/eigen/doc/snippets/Cwise_isInf.cpp b/eigen/doc/snippets/Cwise_isInf.cpp new file mode 100644 index 0000000..be79308 --- /dev/null +++ b/eigen/doc/snippets/Cwise_isInf.cpp @@ -0,0 +1,5 @@ +Array3d v(1,2,3); +v(1) *= 0.0/0.0; +v(2) /= 0.0; +cout << v << endl << endl; +cout << isinf(v) << endl; diff --git a/eigen/doc/snippets/Cwise_isNaN.cpp b/eigen/doc/snippets/Cwise_isNaN.cpp new file mode 100644 index 0000000..7b2a930 --- /dev/null +++ b/eigen/doc/snippets/Cwise_isNaN.cpp @@ -0,0 +1,5 @@ +Array3d v(1,2,3); +v(1) *= 0.0/0.0; +v(2) /= 0.0; +cout << v << endl << endl; +cout << isnan(v) << endl; diff --git a/eigen/doc/snippets/Cwise_log10.cpp b/eigen/doc/snippets/Cwise_log10.cpp new file mode 100644 index 0000000..b7ae4a8 --- /dev/null +++ b/eigen/doc/snippets/Cwise_log10.cpp @@ -0,0 +1,2 @@ +Array4d v(-1,0,1,2); +cout << log10(v) << endl; diff --git a/eigen/doc/snippets/Cwise_round.cpp b/eigen/doc/snippets/Cwise_round.cpp new file mode 100644 index 0000000..e5c8823 --- /dev/null +++ b/eigen/doc/snippets/Cwise_round.cpp @@ -0,0 +1,3 @@ +ArrayXd v = ArrayXd::LinSpaced(7,-2,2); +cout << v << endl << endl; +cout << round(v) << endl; diff --git a/eigen/doc/snippets/Cwise_scalar_power_array.cpp b/eigen/doc/snippets/Cwise_scalar_power_array.cpp new file mode 100644 index 0000000..c968b2c --- /dev/null +++ b/eigen/doc/snippets/Cwise_scalar_power_array.cpp @@ -0,0 +1,2 @@ +Array<double,1,3> e(2,-3,1./3.); +cout << "10^[" << e << "] = " << pow(10,e) << endl; diff --git a/eigen/doc/snippets/Cwise_sign.cpp b/eigen/doc/snippets/Cwise_sign.cpp new file mode 100644 index 0000000..49920e4 --- /dev/null +++ b/eigen/doc/snippets/Cwise_sign.cpp @@ -0,0 +1,2 @@ +Array3d v(-3,5,0); +cout << v.sign() << endl; diff --git a/eigen/doc/snippets/Cwise_sinh.cpp b/eigen/doc/snippets/Cwise_sinh.cpp new file mode 100644 index 0000000..fac9b19 --- /dev/null +++ b/eigen/doc/snippets/Cwise_sinh.cpp @@ -0,0 +1,2 @@ +ArrayXd v = ArrayXd::LinSpaced(5,0,1); +cout << sinh(v) << endl; diff --git a/eigen/doc/snippets/Cwise_tanh.cpp b/eigen/doc/snippets/Cwise_tanh.cpp new file mode 100644 index 0000000..30cd045 --- /dev/null +++ b/eigen/doc/snippets/Cwise_tanh.cpp @@ -0,0 +1,2 @@ +ArrayXd v = ArrayXd::LinSpaced(5,0,1); +cout << tanh(v) << endl; diff --git a/eigen/doc/snippets/DenseBase_LinSpacedInt.cpp b/eigen/doc/snippets/DenseBase_LinSpacedInt.cpp new file mode 100644 index 0000000..0d7ae06 --- /dev/null +++ b/eigen/doc/snippets/DenseBase_LinSpacedInt.cpp @@ -0,0 +1,8 @@ +cout << "Even spacing inputs:" << endl; +cout << VectorXi::LinSpaced(8,1,4).transpose() << endl; +cout << VectorXi::LinSpaced(8,1,8).transpose() << endl; +cout << VectorXi::LinSpaced(8,1,15).transpose() << endl; +cout << "Uneven spacing inputs:" << endl; +cout << VectorXi::LinSpaced(8,1,7).transpose() << endl; +cout << VectorXi::LinSpaced(8,1,9).transpose() << endl; +cout << VectorXi::LinSpaced(8,1,16).transpose() << endl; diff --git a/eigen/doc/snippets/DirectionWise_hnormalized.cpp b/eigen/doc/snippets/DirectionWise_hnormalized.cpp new file mode 100644 index 0000000..3410790 --- /dev/null +++ b/eigen/doc/snippets/DirectionWise_hnormalized.cpp @@ -0,0 +1,7 @@ +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 diff --git a/eigen/doc/snippets/EigenSolver_eigenvectors.cpp b/eigen/doc/snippets/EigenSolver_eigenvectors.cpp index 0fad4da..8355f76 100644 --- a/eigen/doc/snippets/EigenSolver_eigenvectors.cpp +++ b/eigen/doc/snippets/EigenSolver_eigenvectors.cpp @@ -1,4 +1,4 @@ MatrixXd ones = MatrixXd::Ones(3,3); EigenSolver<MatrixXd> es(ones); -cout << "The first eigenvector of the 3x3 matrix of ones is:" - << endl << es.eigenvectors().col(1) << endl; +cout << "The first eigenvector of the 3x3 matrix of ones is:" + << endl << es.eigenvectors().col(0) << endl; diff --git a/eigen/doc/snippets/LeastSquaresNormalEquations.cpp b/eigen/doc/snippets/LeastSquaresNormalEquations.cpp new file mode 100644 index 0000000..997cf17 --- /dev/null +++ b/eigen/doc/snippets/LeastSquaresNormalEquations.cpp @@ -0,0 +1,4 @@ +MatrixXf A = MatrixXf::Random(3, 2); +VectorXf b = VectorXf::Random(3); +cout << "The solution using normal equations is:\n" + << (A.transpose() * A).ldlt().solve(A.transpose() * b) << endl; diff --git a/eigen/doc/snippets/LeastSquaresQR.cpp b/eigen/doc/snippets/LeastSquaresQR.cpp new file mode 100644 index 0000000..6c97045 --- /dev/null +++ b/eigen/doc/snippets/LeastSquaresQR.cpp @@ -0,0 +1,4 @@ +MatrixXf A = MatrixXf::Random(3, 2); +VectorXf b = VectorXf::Random(3); +cout << "The solution using the QR decomposition is:\n" + << A.colPivHouseholderQr().solve(b) << endl; diff --git a/eigen/doc/snippets/MatrixBase_cwiseSign.cpp b/eigen/doc/snippets/MatrixBase_cwiseSign.cpp new file mode 100644 index 0000000..efd7179 --- /dev/null +++ b/eigen/doc/snippets/MatrixBase_cwiseSign.cpp @@ -0,0 +1,4 @@ +MatrixXd m(2,3); +m << 2, -4, 6, + -5, 1, 0; +cout << m.cwiseSign() << endl; diff --git a/eigen/doc/snippets/MatrixBase_hnormalized.cpp b/eigen/doc/snippets/MatrixBase_hnormalized.cpp new file mode 100644 index 0000000..652cd77 --- /dev/null +++ b/eigen/doc/snippets/MatrixBase_hnormalized.cpp @@ -0,0 +1,6 @@ +Vector4d v = Vector4d::Random(); +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 diff --git a/eigen/doc/snippets/MatrixBase_homogeneous.cpp b/eigen/doc/snippets/MatrixBase_homogeneous.cpp new file mode 100644 index 0000000..457c28f --- /dev/null +++ b/eigen/doc/snippets/MatrixBase_homogeneous.cpp @@ -0,0 +1,6 @@ +Vector3d v = Vector3d::Random(), w; +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 diff --git a/eigen/doc/snippets/MatrixBase_marked.cpp b/eigen/doc/snippets/MatrixBase_marked.cpp deleted file mode 100644 index f607121..0000000 --- a/eigen/doc/snippets/MatrixBase_marked.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _MSC_VER - #warning deprecated -#endif -/* -Matrix3d m = Matrix3d::Zero(); -m.part<Eigen::UpperTriangular>().setOnes(); -cout << "Here is the matrix m:" << endl << m << endl; -Matrix3d n = Matrix3d::Ones(); -n.part<Eigen::LowerTriangular>() *= 2; -cout << "Here is the matrix n:" << endl << n << endl; -cout << "And now here is m.inverse()*n, taking advantage of the fact that" - " m is upper-triangular:" << endl - << m.marked<Eigen::UpperTriangular>().solveTriangular(n); -*/
\ No newline at end of file diff --git a/eigen/doc/snippets/MatrixBase_part.cpp b/eigen/doc/snippets/MatrixBase_part.cpp deleted file mode 100644 index d3e7f48..0000000 --- a/eigen/doc/snippets/MatrixBase_part.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _MSC_VER - #warning deprecated -#endif -/* -Matrix3d m = Matrix3d::Zero(); -m.part<Eigen::StrictlyUpperTriangular>().setOnes(); -cout << "Here is the matrix m:" << endl << m << endl; -cout << "And let us now compute m*m.adjoint() in a very optimized way" << endl - << "taking advantage of the symmetry." << endl; -Matrix3d n; -n.part<Eigen::SelfAdjoint>() = (m*m.adjoint()).lazy(); -cout << "The result is:" << endl << n << endl; -*/
\ No newline at end of file diff --git a/eigen/doc/snippets/MatrixBase_selfadjointView.cpp b/eigen/doc/snippets/MatrixBase_selfadjointView.cpp new file mode 100644 index 0000000..4bd3c7e --- /dev/null +++ b/eigen/doc/snippets/MatrixBase_selfadjointView.cpp @@ -0,0 +1,6 @@ +Matrix3i m = Matrix3i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is the symmetric matrix extracted from the upper part of m:" << endl + << Matrix3i(m.selfadjointView<Upper>()) << endl; +cout << "Here is the symmetric matrix extracted from the lower part of m:" << endl + << Matrix3i(m.selfadjointView<Lower>()) << endl; diff --git a/eigen/doc/snippets/MatrixBase_extract.cpp b/eigen/doc/snippets/MatrixBase_triangularView.cpp index c96220f..03aa303 100644 --- a/eigen/doc/snippets/MatrixBase_extract.cpp +++ b/eigen/doc/snippets/MatrixBase_triangularView.cpp @@ -1,13 +1,9 @@ -#ifndef _MSC_VER - #warning deprecated -#endif -/* deprecated Matrix3i m = Matrix3i::Random(); cout << "Here is the matrix m:" << endl << m << endl; cout << "Here is the upper-triangular matrix extracted from m:" << endl - << m.part<Eigen::UpperTriangular>() << endl; + << Matrix3i(m.triangularView<Eigen::Upper>()) << endl; cout << "Here is the strictly-upper-triangular matrix extracted from m:" << endl - << m.part<Eigen::StrictlyUpperTriangular>() << endl; + << Matrix3i(m.triangularView<Eigen::StrictlyUpper>()) << endl; cout << "Here is the unit-lower-triangular matrix extracted from m:" << endl - << m.part<Eigen::UnitLowerTriangular>() << endl; -*/
\ No newline at end of file + << Matrix3i(m.triangularView<Eigen::UnitLower>()) << endl; +// FIXME need to implement output for triangularViews (Bug 885) diff --git a/eigen/doc/snippets/PartialRedux_count.cpp b/eigen/doc/snippets/PartialRedux_count.cpp index c7b3097..1c3b3a2 100644 --- a/eigen/doc/snippets/PartialRedux_count.cpp +++ b/eigen/doc/snippets/PartialRedux_count.cpp @@ -1,3 +1,5 @@ Matrix3d m = Matrix3d::Random(); cout << "Here is the matrix m:" << endl << m << endl; -cout << "Here is the count of elements larger or equal than 0.5 of each row:" << endl << (m.array() >= 0.5).rowwise().count() << endl; +Matrix<ptrdiff_t, 3, 1> res = (m.array() >= 0.5).rowwise().count(); +cout << "Here is the count of elements larger or equal than 0.5 of each row:" << endl; +cout << res << endl; diff --git a/eigen/doc/snippets/SparseMatrix_coeffs.cpp b/eigen/doc/snippets/SparseMatrix_coeffs.cpp new file mode 100644 index 0000000..f71a69b --- /dev/null +++ b/eigen/doc/snippets/SparseMatrix_coeffs.cpp @@ -0,0 +1,9 @@ +SparseMatrix<double> A(3,3); +A.insert(1,2) = 0; +A.insert(0,1) = 1; +A.insert(2,0) = 2; +A.makeCompressed(); +cout << "The matrix A is:" << endl << MatrixXd(A) << endl; +cout << "it has " << A.nonZeros() << " stored non zero coefficients that are: " << A.coeffs().transpose() << endl; +A.coeffs() += 10; +cout << "After adding 10 to every stored non zero coefficient, the matrix A is:" << endl << MatrixXd(A) << endl; diff --git a/eigen/doc/snippets/TopicAliasing_mult4.cpp b/eigen/doc/snippets/TopicAliasing_mult4.cpp new file mode 100644 index 0000000..8a8992f --- /dev/null +++ b/eigen/doc/snippets/TopicAliasing_mult4.cpp @@ -0,0 +1,5 @@ +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 diff --git a/eigen/doc/snippets/TopicAliasing_mult5.cpp b/eigen/doc/snippets/TopicAliasing_mult5.cpp new file mode 100644 index 0000000..1a36def --- /dev/null +++ b/eigen/doc/snippets/TopicAliasing_mult5.cpp @@ -0,0 +1,5 @@ +MatrixXf A(2,2), B(3,2); +B << 2, 0, 0, 3, 1, 1; +A << 2, 0, 0, -2; +A = (B * A).eval().cwiseAbs(); +cout << A; diff --git a/eigen/doc/snippets/Triangular_solve.cpp b/eigen/doc/snippets/Triangular_solve.cpp new file mode 100644 index 0000000..5484424 --- /dev/null +++ b/eigen/doc/snippets/Triangular_solve.cpp @@ -0,0 +1,11 @@ +Matrix3d m = Matrix3d::Zero(); +m.triangularView<Eigen::Upper>().setOnes(); +cout << "Here is the matrix m:\n" << m << endl; +Matrix3d n = Matrix3d::Ones(); +n.triangularView<Eigen::Lower>() *= 2; +cout << "Here is the matrix n:\n" << n << endl; +cout << "And now here is m.inverse()*n, taking advantage of the fact that" + " m is upper-triangular:\n" + << m.triangularView<Eigen::Upper>().solve(n) << endl; +cout << "And this is n*m.inverse():\n" + << m.triangularView<Eigen::Upper>().solve<Eigen::OnTheRight>(n); diff --git a/eigen/doc/snippets/Tutorial_AdvancedInitialization_Join.cpp b/eigen/doc/snippets/Tutorial_AdvancedInitialization_Join.cpp index 84e8715..55a2153 100644 --- a/eigen/doc/snippets/Tutorial_AdvancedInitialization_Join.cpp +++ b/eigen/doc/snippets/Tutorial_AdvancedInitialization_Join.cpp @@ -3,7 +3,7 @@ vec1 << 1, 2, 3; std::cout << "vec1 = " << vec1 << std::endl; RowVectorXd vec2(4); -vec2 << 1, 4, 9, 16;; +vec2 << 1, 4, 9, 16; std::cout << "vec2 = " << vec2 << std::endl; RowVectorXd joined(7); diff --git a/eigen/doc/snippets/Tutorial_ReshapeMat2Mat.cpp b/eigen/doc/snippets/Tutorial_ReshapeMat2Mat.cpp new file mode 100644 index 0000000..f84d6e7 --- /dev/null +++ b/eigen/doc/snippets/Tutorial_ReshapeMat2Mat.cpp @@ -0,0 +1,6 @@ +MatrixXf M1(2,6); // Column-major storage +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 diff --git a/eigen/doc/snippets/Tutorial_ReshapeMat2Vec.cpp b/eigen/doc/snippets/Tutorial_ReshapeMat2Vec.cpp new file mode 100644 index 0000000..95bd4e0 --- /dev/null +++ b/eigen/doc/snippets/Tutorial_ReshapeMat2Vec.cpp @@ -0,0 +1,11 @@ +MatrixXf M1(3,3); // Column-major storage +M1 << 1, 2, 3, + 4, 5, 6, + 7, 8, 9; + +Map<RowVectorXf> v1(M1.data(), M1.size()); +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 diff --git a/eigen/doc/snippets/Tutorial_SlicingCol.cpp b/eigen/doc/snippets/Tutorial_SlicingCol.cpp new file mode 100644 index 0000000..f667ff6 --- /dev/null +++ b/eigen/doc/snippets/Tutorial_SlicingCol.cpp @@ -0,0 +1,11 @@ +MatrixXf M1 = MatrixXf::Random(3,8); +cout << "Column major input:" << endl << M1 << "\n"; +Map<MatrixXf,0,OuterStride<> > M2(M1.data(), M1.rows(), (M1.cols()+2)/3, OuterStride<>(M1.outerStride()*3)); +cout << "1 column over 3:" << endl << M2 << "\n"; + +typedef Matrix<float,Dynamic,Dynamic,RowMajor> RowMajorMatrixXf; +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 diff --git a/eigen/doc/snippets/Tutorial_SlicingVec.cpp b/eigen/doc/snippets/Tutorial_SlicingVec.cpp new file mode 100644 index 0000000..07e10bf --- /dev/null +++ b/eigen/doc/snippets/Tutorial_SlicingVec.cpp @@ -0,0 +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 diff --git a/eigen/doc/snippets/VectorwiseOp_homogeneous.cpp b/eigen/doc/snippets/VectorwiseOp_homogeneous.cpp new file mode 100644 index 0000000..aba4fed --- /dev/null +++ b/eigen/doc/snippets/VectorwiseOp_homogeneous.cpp @@ -0,0 +1,7 @@ +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 diff --git a/eigen/doc/snippets/compile_snippet.cpp.in b/eigen/doc/snippets/compile_snippet.cpp.in index 894cd52..d63f371 100644 --- a/eigen/doc/snippets/compile_snippet.cpp.in +++ b/eigen/doc/snippets/compile_snippet.cpp.in @@ -1,5 +1,13 @@ -#include <Eigen/Dense> +static bool eigen_did_assert = false; +#define eigen_assert(X) if(!eigen_did_assert && !(X)){ std::cout << "### Assertion raised in " << __FILE__ << ":" << __LINE__ << ":\n" #X << "\n### The following would happen without assertions:\n"; eigen_did_assert = true;} + #include <iostream> +#include <Eigen/Eigen> + +#ifndef M_PI +#define M_PI 3.1415926535897932384626433832795 +#endif + using namespace Eigen; using namespace std; |