Commit ab8ba444 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Adjust NEWMAT::SVD to explicitly fail if passed a matrix with less rows

than columns (for compatibility with newmat behavuiour). Remove U truncation,
as arma::svd_econ does it for us (whereas arma::svd does not)
parent e46fb93a
......@@ -6,24 +6,35 @@
*/
namespace armawrap {
template<typename T1, typename T2, typename T3, typename T4>
inline void SVD(const T1 &A,
inline void SVD(const T1 &A,
T2 &D,
T3 &U,
T3 &U,
T4 &V,
bool withU=true,
bool withV=true) {
arma::Col<typename T1::elem_type> s;
arma::Mat<typename T1::elem_type> Ut;
arma::Mat<typename T1::elem_type> At(A);
/*
* NEWMAT::SVD does not support decomposition on
* matrices with more columns than rows, and
* raises a ProgramException. In armawrap/newmat.h,
* ProgramException is aliased to runtime_error,
* so that's what we raise here.
*/
if (At.n_rows < At.n_cols) {
throw std::runtime_error("SVD requires that m >= n for a m*n matrix");
}
arma::svd_econ(Ut, s, V, At);
if (!withV) V = 0;
if ( withU) U = Ut.submat(0, 0, At.n_rows-1, At.n_cols-1);
if ( withU) U = Ut;
D = s;
}
......@@ -37,7 +48,7 @@ namespace armawrap {
}
template<typename T1, typename T2, typename T3>
inline void SVD(const T1 &A,
inline void SVD(const T1 &A,
T2 &D,
T3 &U,
bool withU=true) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment