From e8cdbedefb1913b5a0e2f2b7d38470f081cb8d29 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Thu, 4 Dec 2014 22:48:53 +0100 Subject: bug #877, bug #572: Introduce a global Index typedef. Rename Sparse*::Index to StorageIndex, make Dense*::StorageIndex an alias to DenseIndex. Overall this commit gets rid of all Index conversion warnings. --- Eigen/src/SparseLU/SparseLU.h | 55 ++++++++++----------- Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h | 66 +++++++++++++------------- 2 files changed, 59 insertions(+), 62 deletions(-) (limited to 'Eigen/src/SparseLU') diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index d72d7f150..0c48fef3e 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -14,7 +14,7 @@ namespace Eigen { -template > class SparseLU; +template > class SparseLU; template struct SparseLUMatrixLReturnType; template struct SparseLUMatrixUReturnType; @@ -70,7 +70,7 @@ template struct SparseLUMatrixURetu * \sa \ref OrderingMethods_Module */ template -class SparseLU : public SparseSolverBase >, public internal::SparseLUImpl +class SparseLU : public SparseSolverBase >, public internal::SparseLUImpl { protected: typedef SparseSolverBase > APIBase; @@ -82,13 +82,13 @@ class SparseLU : public SparseSolverBase >, typedef _OrderingType OrderingType; typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; - typedef typename MatrixType::Index Index; - typedef SparseMatrix NCMatrix; - typedef internal::MappedSuperNodalMatrix SCMatrix; + typedef typename MatrixType::StorageIndex StorageIndex; + typedef SparseMatrix NCMatrix; + typedef internal::MappedSuperNodalMatrix SCMatrix; typedef Matrix ScalarVector; - typedef Matrix IndexVector; - typedef PermutationMatrix PermutationType; - typedef internal::SparseLUImpl Base; + typedef Matrix IndexVector; + typedef PermutationMatrix PermutationType; + typedef internal::SparseLUImpl Base; public: SparseLU():m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0),m_detPermR(1) @@ -122,8 +122,8 @@ class SparseLU : public SparseSolverBase >, factorize(matrix); } - inline Index rows() const { return m_mat.rows(); } - inline Index cols() const { return m_mat.cols(); } + inline StorageIndex rows() const { return m_mat.rows(); } + inline StorageIndex cols() const { return m_mat.cols(); } /** Indicate that the pattern of the input matrix is symmetric */ void isSymmetric(bool sym) { @@ -146,9 +146,9 @@ class SparseLU : public SparseSolverBase >, * y = b; matrixU().solveInPlace(y); * \endcode */ - SparseLUMatrixUReturnType > matrixU() const + SparseLUMatrixUReturnType > matrixU() const { - return SparseLUMatrixUReturnType >(m_Lstore, m_Ustore); + return SparseLUMatrixUReturnType >(m_Lstore, m_Ustore); } /** @@ -324,7 +324,7 @@ class SparseLU : public SparseSolverBase >, std::string m_lastError; NCMatrix m_mat; // The input (permuted ) matrix SCMatrix m_Lstore; // The lower triangular matrix (supernodal) - MappedSparseMatrix m_Ustore; // The upper triangular matrix + MappedSparseMatrix m_Ustore; // The upper triangular matrix PermutationType m_perm_c; // Column permutation PermutationType m_perm_r ; // Row permutation IndexVector m_etree; // Column elimination tree @@ -334,10 +334,10 @@ class SparseLU : public SparseSolverBase >, // SparseLU options bool m_symmetricmode; // values for performance - internal::perfvalues m_perfv; + internal::perfvalues m_perfv; RealScalar m_diagpivotthresh; // Specifies the threshold used for a diagonal entry to be an acceptable pivot - Index m_nnzL, m_nnzU; // Nonzeros in L and U factors - Index m_detPermR; // Determinant of the coefficient matrix + StorageIndex m_nnzL, m_nnzU; // Nonzeros in L and U factors + StorageIndex m_detPermR; // Determinant of the coefficient matrix private: // Disable copy constructor SparseLU (const SparseLU& ); @@ -375,7 +375,7 @@ void SparseLU::analyzePattern(const MatrixType& mat) { m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. FIXME : This vector is filled but not subsequently used. // Then, permute only the column pointers - ei_declare_aligned_stack_constructed_variable(Index,outerIndexPtr,mat.cols()+1,mat.isCompressed()?const_cast(mat.outerIndexPtr()):0); + ei_declare_aligned_stack_constructed_variable(StorageIndex,outerIndexPtr,mat.cols()+1,mat.isCompressed()?const_cast(mat.outerIndexPtr()):0); // If the input matrix 'mat' is uncompressed, then the outer-indices do not match the ones of m_mat, and a copy is thus needed. if(!mat.isCompressed()) @@ -640,7 +640,7 @@ void SparseLU::factorize(const MatrixType& matrix) // Create supernode matrix L m_Lstore.setInfos(m, n, m_glu.lusup, m_glu.xlusup, m_glu.lsub, m_glu.xlsub, m_glu.supno, m_glu.xsup); // Create the column major upper sparse matrix U; - new (&m_Ustore) MappedSparseMatrix ( m, n, m_nnzU, m_glu.xusub.data(), m_glu.usub.data(), m_glu.ucol.data() ); + new (&m_Ustore) MappedSparseMatrix ( m, n, m_nnzU, m_glu.xusub.data(), m_glu.usub.data(), m_glu.ucol.data() ); m_info = Success; m_factorizationIsOk = true; @@ -649,12 +649,12 @@ void SparseLU::factorize(const MatrixType& matrix) template struct SparseLUMatrixLReturnType : internal::no_assignment_operator { - typedef typename MappedSupernodalType::Index Index; + typedef typename MappedSupernodalType::StorageIndex StorageIndex; typedef typename MappedSupernodalType::Scalar Scalar; explicit SparseLUMatrixLReturnType(const MappedSupernodalType& mapL) : m_mapL(mapL) { } - Index rows() { return m_mapL.rows(); } - Index cols() { return m_mapL.cols(); } + StorageIndex rows() { return m_mapL.rows(); } + StorageIndex cols() { return m_mapL.cols(); } template void solveInPlace( MatrixBase &X) const { @@ -666,21 +666,18 @@ struct SparseLUMatrixLReturnType : internal::no_assignment_operator template struct SparseLUMatrixUReturnType : internal::no_assignment_operator { - typedef typename MatrixLType::Index Index; + typedef typename MatrixLType::StorageIndex StorageIndex; typedef typename MatrixLType::Scalar Scalar; explicit SparseLUMatrixUReturnType(const MatrixLType& mapL, const MatrixUType& mapU) : m_mapL(mapL),m_mapU(mapU) { } - Index rows() { return m_mapL.rows(); } - Index cols() { return m_mapL.cols(); } + StorageIndex rows() { return m_mapL.rows(); } + StorageIndex cols() { return m_mapL.cols(); } template void solveInPlace(MatrixBase &X) const { - /* Explicit type conversion as the Index type of MatrixBase may be wider than Index */ - eigen_assert(X.rows() <= NumTraits::highest()); - eigen_assert(X.cols() <= NumTraits::highest()); - Index nrhs = Index(X.cols()); - Index n = Index(X.rows()); + Index nrhs = X.cols(); + Index n = X.rows(); // Backward solve with U for (Index k = m_mapL.nsuper(); k >= 0; k--) { diff --git a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h index e8ee35a94..098763765 100644 --- a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +++ b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h @@ -29,20 +29,20 @@ namespace internal { * SuperInnerIterator to iterate through all supernodes * Function for triangular solve */ -template +template class MappedSuperNodalMatrix { public: typedef _Scalar Scalar; - typedef _Index Index; - typedef Matrix IndexVector; + typedef _StorageIndex StorageIndex; + typedef Matrix IndexVector; typedef Matrix ScalarVector; public: MappedSuperNodalMatrix() { } - MappedSuperNodalMatrix(Index m, Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind, + MappedSuperNodalMatrix(StorageIndex m, StorageIndex n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind, IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col ) { setInfos(m, n, nzval, nzval_colptr, rowind, rowind_colptr, col_to_sup, sup_to_col); @@ -58,7 +58,7 @@ class MappedSuperNodalMatrix * FIXME This class will be modified such that it can be use in the course * of the factorization. */ - void setInfos(Index m, Index n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind, + void setInfos(StorageIndex m, StorageIndex n, ScalarVector& nzval, IndexVector& nzval_colptr, IndexVector& rowind, IndexVector& rowind_colptr, IndexVector& col_to_sup, IndexVector& sup_to_col ) { m_row = m; @@ -75,12 +75,12 @@ class MappedSuperNodalMatrix /** * Number of rows */ - Index rows() { return m_row; } + StorageIndex rows() { return m_row; } /** * Number of columns */ - Index cols() { return m_col; } + StorageIndex cols() { return m_col; } /** * Return the array of nonzero values packed by column @@ -96,12 +96,12 @@ class MappedSuperNodalMatrix /** * Return the pointers to the beginning of each column in \ref valuePtr() */ - Index* colIndexPtr() + StorageIndex* colIndexPtr() { return m_nzval_colptr; } - const Index* colIndexPtr() const + const StorageIndex* colIndexPtr() const { return m_nzval_colptr; } @@ -109,9 +109,9 @@ class MappedSuperNodalMatrix /** * Return the array of compressed row indices of all supernodes */ - Index* rowIndex() { return m_rowind; } + StorageIndex* rowIndex() { return m_rowind; } - const Index* rowIndex() const + const StorageIndex* rowIndex() const { return m_rowind; } @@ -119,9 +119,9 @@ class MappedSuperNodalMatrix /** * Return the location in \em rowvaluePtr() which starts each column */ - Index* rowIndexPtr() { return m_rowind_colptr; } + StorageIndex* rowIndexPtr() { return m_rowind_colptr; } - const Index* rowIndexPtr() const + const StorageIndex* rowIndexPtr() const { return m_rowind_colptr; } @@ -129,18 +129,18 @@ class MappedSuperNodalMatrix /** * Return the array of column-to-supernode mapping */ - Index* colToSup() { return m_col_to_sup; } + StorageIndex* colToSup() { return m_col_to_sup; } - const Index* colToSup() const + const StorageIndex* colToSup() const { return m_col_to_sup; } /** * Return the array of supernode-to-column mapping */ - Index* supToCol() { return m_sup_to_col; } + StorageIndex* supToCol() { return m_sup_to_col; } - const Index* supToCol() const + const StorageIndex* supToCol() const { return m_sup_to_col; } @@ -148,7 +148,7 @@ class MappedSuperNodalMatrix /** * Return the number of supernodes */ - Index nsuper() const + StorageIndex nsuper() const { return m_nsuper; } @@ -161,15 +161,15 @@ class MappedSuperNodalMatrix protected: - Index m_row; // Number of rows - Index m_col; // Number of columns - Index m_nsuper; // Number of supernodes + StorageIndex m_row; // Number of rows + StorageIndex m_col; // Number of columns + StorageIndex m_nsuper; // Number of supernodes Scalar* m_nzval; //array of nonzero values packed by column - Index* m_nzval_colptr; //nzval_colptr[j] Stores the location in nzval[] which starts column j - Index* m_rowind; // Array of compressed row indices of rectangular supernodes - Index* m_rowind_colptr; //rowind_colptr[j] stores the location in rowind[] which starts column j - Index* m_col_to_sup; // col_to_sup[j] is the supernode number to which column j belongs - Index* m_sup_to_col; //sup_to_col[s] points to the starting column of the s-th supernode + StorageIndex* m_nzval_colptr; //nzval_colptr[j] Stores the location in nzval[] which starts column j + StorageIndex* m_rowind; // Array of compressed row indices of rectangular supernodes + StorageIndex* m_rowind_colptr; //rowind_colptr[j] stores the location in rowind[] which starts column j + StorageIndex* m_col_to_sup; // col_to_sup[j] is the supernode number to which column j belongs + StorageIndex* m_sup_to_col; //sup_to_col[s] points to the starting column of the s-th supernode private : }; @@ -182,9 +182,9 @@ template class MappedSuperNodalMatrix::InnerIterator { public: - InnerIterator(const MappedSuperNodalMatrix& mat, Index outer) + InnerIterator(const MappedSuperNodalMatrix& mat, Eigen::Index outer) : m_matrix(mat), - m_outer(outer), + m_outer(convert_index(outer)), m_supno(mat.colToSup()[outer]), m_idval(mat.colIndexPtr()[outer]), m_startidval(m_idval), @@ -229,14 +229,14 @@ class MappedSuperNodalMatrix::InnerIterator * \brief Solve with the supernode triangular matrix * */ -template +template template -void MappedSuperNodalMatrix::solveInPlace( MatrixBase&X) const +void MappedSuperNodalMatrix::solveInPlace( MatrixBase&X) const { /* Explicit type conversion as the Index type of MatrixBase may be wider than Index */ - eigen_assert(X.rows() <= NumTraits::highest()); - eigen_assert(X.cols() <= NumTraits::highest()); - Index n = Index(X.rows()); +// eigen_assert(X.rows() <= NumTraits::highest()); +// eigen_assert(X.cols() <= NumTraits::highest()); + Index n = int(X.rows()); Index nrhs = Index(X.cols()); const Scalar * Lval = valuePtr(); // Nonzero values Matrix work(n, nrhs); // working vector -- cgit v1.2.3