Skip to content

Commit

Permalink
Fix D&C SVD wrt zero matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
ggael committed Oct 17, 2014
1 parent 113540a commit f1ffb35
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions unsupported/Eigen/src/BDCSVD/BDCSVD.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class BDCSVD : public SVDBase<BDCSVD<_MatrixType> >
}; //end class BDCSVD


// Methode to allocate ans initialize matrix and attributes
// Method to allocate and initialize matrix and attributes
template<typename MatrixType>
void BDCSVD<MatrixType>::allocate(Index rows, Index cols, unsigned int computationOptions)
{
Expand All @@ -215,24 +215,6 @@ void BDCSVD<MatrixType>::allocate(Index rows, Index cols, unsigned int computati
if (m_compV) m_naiveV = MatrixXr::Zero(m_diagSize, m_diagSize);
}// end allocate

// Methode which compute the BDCSVD for the int
template<>
BDCSVD<Matrix<int, Dynamic, Dynamic> >& BDCSVD<Matrix<int, Dynamic, Dynamic> >::compute(const MatrixType& matrix, unsigned int computationOptions)
{
allocate(matrix.rows(), matrix.cols(), computationOptions);
m_nonzeroSingularValues = 0;
m_computed = Matrix<int, Dynamic, Dynamic>::Zero(rows(), cols());

m_singularValues.head(m_diagSize).setZero();

if (m_computeFullU) m_matrixU.setZero(rows(), rows());
if (m_computeFullV) m_matrixV.setZero(cols(), cols());
m_isInitialized = true;
return *this;
}


// Methode which compute the BDCSVD
template<typename MatrixType>
BDCSVD<MatrixType>& BDCSVD<MatrixType>::compute(const MatrixType& matrix, unsigned int computationOptions)
{
Expand Down Expand Up @@ -612,6 +594,8 @@ void BDCSVD<MatrixType>::computeSVDofM(Index firstCol, Index n, MatrixXr& U, Vec
#endif

#ifdef EIGEN_BDCSVD_SANITY_CHECKS
assert(U.allFinite());
assert(V.allFinite());
assert((U.transpose() * U - MatrixXr(MatrixXr::Identity(U.cols(),U.cols()))).norm() < 1e-14 * n);
assert((V.transpose() * V - MatrixXr(MatrixXr::Identity(V.cols(),V.cols()))).norm() < 1e-14 * n);
assert(m_naiveU.allFinite());
Expand Down Expand Up @@ -836,8 +820,12 @@ void BDCSVD<MatrixType>::perturbCol0
using std::sqrt;
Index n = col0.size();
Index m = perm.size();
Index last = perm(m-1);

if(m==0)
{
zhat.setZero();
return;
}
Index last = last = perm(m-1);
// The offset permits to skip deflated entries while computing zhat
for (Index k = 0; k < n; ++k)
{
Expand Down

0 comments on commit f1ffb35

Please sign in to comment.