aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Eigen/src/Core/MatrixBase.h2
-rw-r--r--Eigen/src/SVD/JacobiSVD.h9
-rw-r--r--doc/examples/TutorialLinAlgSVDSolve.cpp4
-rw-r--r--test/jacobisvd.cpp17
4 files changed, 30 insertions, 2 deletions
diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h
index f324a0870..e6091313d 100644
--- a/Eigen/src/Core/MatrixBase.h
+++ b/Eigen/src/Core/MatrixBase.h
@@ -331,6 +331,8 @@ template<typename Derived> class MatrixBase
/////////// SVD module ///////////
+ JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
+
/////////// Geometry module ///////////
template<typename OtherDerived>
diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h
index f12494dbc..b130ed4db 100644
--- a/Eigen/src/SVD/JacobiSVD.h
+++ b/Eigen/src/SVD/JacobiSVD.h
@@ -657,4 +657,13 @@ struct ei_solve_retval<JacobiSVD<_MatrixType, QRPreconditioner>, Rhs>
}
};
+template<typename Derived>
+JacobiSVD<typename MatrixBase<Derived>::PlainObject>
+MatrixBase<Derived>::jacobiSvd(unsigned int computationOptions) const
+{
+ return JacobiSVD<PlainObject>(*this, computationOptions);
+}
+
+
+
#endif // EIGEN_JACOBISVD_H
diff --git a/doc/examples/TutorialLinAlgSVDSolve.cpp b/doc/examples/TutorialLinAlgSVDSolve.cpp
index c75779d5f..9fbc031de 100644
--- a/doc/examples/TutorialLinAlgSVDSolve.cpp
+++ b/doc/examples/TutorialLinAlgSVDSolve.cpp
@@ -10,6 +10,6 @@ int main()
cout << "Here is the matrix A:\n" << A << endl;
VectorXf b = VectorXf::Random(3);
cout << "Here is the right hand side b:\n" << b << endl;
- JacobiSVD<MatrixXf> svd(A, ComputeThinU | ComputeThinV);
- cout << "The least-squares solution is:\n" << svd.solve(b) << endl;
+ cout << "The least-squares solution is:\n"
+ << A.jacobiSvd(ComputeThinU | ComputeThinV).solve(b) << endl;
}
diff --git a/test/jacobisvd.cpp b/test/jacobisvd.cpp
index 7d8c36308..212f7f1d7 100644
--- a/test/jacobisvd.cpp
+++ b/test/jacobisvd.cpp
@@ -197,6 +197,19 @@ template<typename MatrixType> void jacobisvd_verify_assert(const MatrixType& m)
}
template<typename MatrixType>
+void jacobisvd_method()
+{
+ enum { Size = MatrixType::RowsAtCompileTime };
+ typedef typename MatrixType::RealScalar RealScalar;
+ typedef Matrix<RealScalar, Size, 1> RealVecType;
+ MatrixType m = MatrixType::Identity();
+ VERIFY_IS_APPROX(m.jacobiSvd().singularValues(), RealVecType::Ones());
+ VERIFY_RAISES_ASSERT(m.jacobiSvd().matrixU());
+ VERIFY_RAISES_ASSERT(m.jacobiSvd().matrixV());
+ VERIFY_IS_APPROX(m.jacobiSvd(ComputeFullU|ComputeFullV).solve(m), m);
+}
+
+template<typename MatrixType>
void jacobisvd_inf_nan()
{
JacobiSVD<MatrixType> svd;
@@ -256,6 +269,10 @@ void test_jacobisvd()
CALL_SUBTEST_7(( jacobisvd<MatrixXf>(MatrixXf(ei_random<int>(100, 150), ei_random<int>(100, 150))) ));
CALL_SUBTEST_8(( jacobisvd<MatrixXcd>(MatrixXcd(ei_random<int>(80, 100), ei_random<int>(80, 100))) ));
+ // test matrixbase method
+ CALL_SUBTEST_1(( jacobisvd_method<Matrix2cd>() ));
+ CALL_SUBTEST_3(( jacobisvd_method<Matrix3f>() ));
+
// Test problem size constructors
CALL_SUBTEST_7( JacobiSVD<MatrixXf>(10,10) );
}