From aaaade4b3d66d67d2c08af3372c3965e7255b2e8 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 30 May 2010 16:00:58 -0400 Subject: the Index types change. As discussed on the list (too long to explain here). --- Eigen/src/SVD/JacobiSVD.h | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'Eigen/src/SVD/JacobiSVD.h') diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index 9323c0180..292530657 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2009 Benoit Jacob +// Copyright (C) 2009-2010 Benoit Jacob // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -63,6 +63,7 @@ template class JacobiSVD private: typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; + typedef typename MatrixType::Index Index; enum { ComputeU = (Options & SkipU) == 0, ComputeV = (Options & SkipV) == 0, @@ -107,7 +108,7 @@ template class JacobiSVD * according to the specified problem \a size. * \sa JacobiSVD() */ - JacobiSVD(int rows, int cols) : m_matrixU(rows, rows), + JacobiSVD(Index rows, Index cols) : m_matrixU(rows, rows), m_matrixV(cols, cols), m_singularValues(std::min(rows, cols)), m_workMatrix(rows, cols), @@ -119,7 +120,7 @@ template class JacobiSVD m_workMatrix(), m_isInitialized(false) { - const int minSize = std::min(matrix.rows(), matrix.cols()); + const Index minSize = std::min(matrix.rows(), matrix.cols()); m_singularValues.resize(minSize); m_workMatrix.resize(minSize, minSize); compute(matrix); @@ -164,7 +165,8 @@ template struct ei_svd_precondition_2x2_block_to_be_real { typedef JacobiSVD SVD; - static void run(typename SVD::WorkMatrixType&, JacobiSVD&, int, int) {} + typedef typename SVD::Index Index; + static void run(typename SVD::WorkMatrixType&, JacobiSVD&, Index, Index) {} }; template @@ -173,8 +175,9 @@ struct ei_svd_precondition_2x2_block_to_be_real typedef JacobiSVD SVD; typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; + typedef typename SVD::Index Index; enum { ComputeU = SVD::ComputeU, ComputeV = SVD::ComputeV }; - static void run(typename SVD::WorkMatrixType& work_matrix, JacobiSVD& svd, int p, int q) + static void run(typename SVD::WorkMatrixType& work_matrix, JacobiSVD& svd, Index p, Index q) { Scalar z; PlanarRotation rot; @@ -210,8 +213,8 @@ struct ei_svd_precondition_2x2_block_to_be_real } }; -template -void ei_real_2x2_jacobi_svd(const MatrixType& matrix, int p, int q, +template +void ei_real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q, PlanarRotation *j_left, PlanarRotation *j_right) { @@ -250,12 +253,13 @@ struct ei_svd_precondition_if_more_rows_than_cols typedef JacobiSVD SVD; typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; + typedef typename MatrixType::Index Index; enum { ComputeU = SVD::ComputeU, ComputeV = SVD::ComputeV }; static bool run(const MatrixType& matrix, typename SVD::WorkMatrixType& work_matrix, SVD& svd) { - int rows = matrix.rows(); - int cols = matrix.cols(); - int diagSize = cols; + Index rows = matrix.rows(); + Index cols = matrix.cols(); + Index diagSize = cols; if(rows > cols) { FullPivHouseholderQR qr(matrix); @@ -282,6 +286,7 @@ struct ei_svd_precondition_if_more_cols_than_rows typedef JacobiSVD SVD; typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; + typedef typename MatrixType::Index Index; enum { ComputeU = SVD::ComputeU, ComputeV = SVD::ComputeV, @@ -294,9 +299,9 @@ struct ei_svd_precondition_if_more_cols_than_rows static bool run(const MatrixType& matrix, typename SVD::WorkMatrixType& work_matrix, SVD& svd) { - int rows = matrix.rows(); - int cols = matrix.cols(); - int diagSize = rows; + Index rows = matrix.rows(); + Index cols = matrix.cols(); + Index diagSize = rows; if(cols > rows) { typedef Matrix template JacobiSVD& JacobiSVD::compute(const MatrixType& matrix) { - int rows = matrix.rows(); - int cols = matrix.cols(); - int diagSize = std::min(rows, cols); + Index rows = matrix.rows(); + Index cols = matrix.cols(); + Index diagSize = std::min(rows, cols); m_singularValues.resize(diagSize); const RealScalar precision = 2 * NumTraits::epsilon(); @@ -333,9 +338,9 @@ JacobiSVD& JacobiSVD::compute(const Ma while(!finished) { finished = true; - for(int p = 1; p < diagSize; ++p) + for(Index p = 1; p < diagSize; ++p) { - for(int q = 0; q < p; ++q) + for(Index q = 0; q < p; ++q) { if(std::max(ei_abs(m_workMatrix.coeff(p,q)),ei_abs(m_workMatrix.coeff(q,p))) > std::max(ei_abs(m_workMatrix.coeff(p,p)),ei_abs(m_workMatrix.coeff(q,q)))*precision) @@ -356,16 +361,16 @@ JacobiSVD& JacobiSVD::compute(const Ma } } - for(int i = 0; i < diagSize; ++i) + for(Index i = 0; i < diagSize; ++i) { RealScalar a = ei_abs(m_workMatrix.coeff(i,i)); m_singularValues.coeffRef(i) = a; if(ComputeU && (a!=RealScalar(0))) m_matrixU.col(i) *= m_workMatrix.coeff(i,i)/a; } - for(int i = 0; i < diagSize; i++) + for(Index i = 0; i < diagSize; i++) { - int pos; + Index pos; m_singularValues.tail(diagSize-i).maxCoeff(&pos); if(pos) { -- cgit v1.2.3