diff --git a/Eigen/src/Sparse/SparseSelfAdjointView.h b/Eigen/src/Sparse/SparseSelfAdjointView.h index 651daaa4d..a69682997 100644 --- a/Eigen/src/Sparse/SparseSelfAdjointView.h +++ b/Eigen/src/Sparse/SparseSelfAdjointView.h @@ -116,21 +116,21 @@ template class SparseSelfAdjointView SparseSelfAdjointView& rankUpdate(const SparseMatrixBase& u, Scalar alpha = Scalar(1)); /** \internal triggered by sparse_matrix = SparseSelfadjointView; */ - template void evalTo(SparseMatrix& _dest) const + template void evalTo(SparseMatrix& _dest) const { internal::permute_symm_to_fullsymm(m_matrix, _dest); } - template void evalTo(DynamicSparseMatrix& _dest) const + template void evalTo(DynamicSparseMatrix& _dest) const { // TODO directly evaluate into _dest; - SparseMatrix tmp(_dest.rows(),_dest.cols()); + SparseMatrix tmp(_dest.rows(),_dest.cols()); internal::permute_symm_to_fullsymm(m_matrix, tmp); _dest = tmp; } /** \returns an expression of P^-1 H P */ - SparseSymmetricPermutationProduct<_MatrixTypeNested,UpLo> twistedBy(const PermutationMatrix& perm) const + SparseSymmetricPermutationProduct<_MatrixTypeNested,UpLo> twistedBy(const PermutationMatrix& perm) const { return SparseSymmetricPermutationProduct<_MatrixTypeNested,UpLo>(m_matrix, perm); } @@ -419,10 +419,12 @@ template class SparseSymmetricPermutationProduct : public EigenBase > { - typedef PermutationMatrix Perm; public: typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Index Index; + protected: + typedef PermutationMatrix Perm; + public: typedef Matrix VectorI; typedef typename MatrixType::Nested MatrixTypeNested; typedef typename internal::remove_all::type _MatrixTypeNested; diff --git a/test/sparse.h b/test/sparse.h index 530ae30bc..9944a2934 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -58,15 +58,15 @@ enum { * \param zeroCoords and nonzeroCoords allows to get the coordinate lists of the non zero, * and zero coefficients respectively. */ -template void +template void initSparse(double density, Matrix& refMat, - SparseMatrix& sparseMat, + SparseMatrix& sparseMat, int flags = 0, std::vector* zeroCoords = 0, std::vector* nonzeroCoords = 0) { - enum { IsRowMajor = SparseMatrix::IsRowMajor }; + enum { IsRowMajor = SparseMatrix::IsRowMajor }; sparseMat.setZero(); sparseMat.reserve(int(refMat.rows()*refMat.cols()*density)); @@ -108,15 +108,15 @@ initSparse(double density, sparseMat.finalize(); } -template void +template void initSparse(double density, Matrix& refMat, - DynamicSparseMatrix& sparseMat, + DynamicSparseMatrix& sparseMat, int flags = 0, std::vector* zeroCoords = 0, std::vector* nonzeroCoords = 0) { - enum { IsRowMajor = DynamicSparseMatrix::IsRowMajor }; + enum { IsRowMajor = DynamicSparseMatrix::IsRowMajor }; sparseMat.setZero(); sparseMat.reserve(int(refMat.rows()*refMat.cols()*density)); for(int j=0; j -void minimum_degree_ordering(SparseMatrix& C, PermutationMatrix& perm) +void minimum_degree_ordering(SparseMatrix& C, PermutationMatrix& perm) { typedef SparseMatrix CCS; @@ -151,7 +151,7 @@ void minimum_degree_ordering(SparseMatrix& C, Permutation elen[i] = 0; // Ek of node i is empty degree[i] = len[i]; // degree of node i } - mark = cs_wclear (0, 0, w, n); /* clear w */ + mark = cs_wclear(0, 0, w, n); /* clear w */ elen[n] = -2; /* n is a dead element */ Cp[n] = -1; /* n is a root of assembly tree */ w[n] = 0; /* n is a dead element */ @@ -266,7 +266,7 @@ void minimum_degree_ordering(SparseMatrix& C, Permutation elen[k] = -2; /* k is now an element */ /* --- Find set differences ----------------------------------------- */ - mark = cs_wclear (mark, lemax, w, n); /* clear w if necessary */ + mark = cs_wclear(mark, lemax, w, n); /* clear w if necessary */ for(pk = pk1; pk < pk2; pk++) /* scan 1: find |Le\Lk| */ { i = Ci[pk]; @@ -349,7 +349,7 @@ void minimum_degree_ordering(SparseMatrix& C, Permutation } /* scan2 is done */ degree[k] = dk; /* finalize |Lk| */ lemax = std::max(lemax, dk); - mark = cs_wclear (mark+lemax, lemax, w, n); /* clear w */ + mark = cs_wclear(mark+lemax, lemax, w, n); /* clear w */ /* --- Supernode detection ------------------------------------------ */ for(pk = pk1; pk < pk2; pk++) @@ -435,7 +435,7 @@ void minimum_degree_ordering(SparseMatrix& C, Permutation } for(k = 0, i = 0; i <= n; i++) /* postorder the assembly tree */ { - if(Cp[i] == -1) k = cs_tdfs (i, k, head, next, perm.indices().data(), w); + if(Cp[i] == -1) k = cs_tdfs(i, k, head, next, perm.indices().data(), w); } perm.indices().conservativeResize(n); diff --git a/unsupported/Eigen/src/SparseExtra/SimplicialCholesky.h b/unsupported/Eigen/src/SparseExtra/SimplicialCholesky.h index 6af6407c7..dd13dc714 100644 --- a/unsupported/Eigen/src/SparseExtra/SimplicialCholesky.h +++ b/unsupported/Eigen/src/SparseExtra/SimplicialCholesky.h @@ -193,12 +193,12 @@ class SimplicialCholesky /** \returns the permutation P * \sa permutationPinv() */ - const PermutationMatrix& permutationP() const + const PermutationMatrix& permutationP() const { return m_P; } /** \returns the inverse P^-1 of the permutation P * \sa permutationP() */ - const PermutationMatrix& permutationPinv() const + const PermutationMatrix& permutationPinv() const { return m_Pinv; } #ifndef EIGEN_PARSED_BY_DOXYGEN @@ -282,8 +282,8 @@ class SimplicialCholesky VectorType m_diag; // the diagonal coefficients in case of a LDLt decomposition VectorXi m_parent; // elimination tree VectorXi m_nonZerosPerCol; - PermutationMatrix m_P; // the permutation - PermutationMatrix m_Pinv; // the inverse permutation + PermutationMatrix m_P; // the permutation + PermutationMatrix m_Pinv; // the inverse permutation }; template diff --git a/unsupported/Eigen/src/SparseExtra/SparseLDLTLegacy.h b/unsupported/Eigen/src/SparseExtra/SparseLDLTLegacy.h index 14283c117..6b240f169 100644 --- a/unsupported/Eigen/src/SparseExtra/SparseLDLTLegacy.h +++ b/unsupported/Eigen/src/SparseExtra/SparseLDLTLegacy.h @@ -90,10 +90,9 @@ class SparseLDLT }; public: - typedef SparseMatrix CholMatrixType; typedef _MatrixType MatrixType; typedef typename MatrixType::Index Index; - + typedef SparseMatrix CholMatrixType; /** Creates a dummy LDLT factorization object with flags \a flags. */ SparseLDLT(int flags = 0) @@ -187,8 +186,8 @@ class SparseLDLT VectorXi m_parent; // elimination tree VectorXi m_nonZerosPerCol; // VectorXi m_w; // workspace - PermutationMatrix m_P; - PermutationMatrix m_Pinv; + PermutationMatrix m_P; + PermutationMatrix m_Pinv; RealScalar m_precision; int m_flags; mutable int m_status; @@ -257,7 +256,7 @@ void SparseLDLT<_MatrixType,Backend>::_symbolic(const _MatrixType& a) if(P) { - m_P.indices() = VectorXi::Map(P,size); + m_P.indices() = Map >(P,size); m_Pinv = m_P.inverse(); Pinv = m_Pinv.indices().data(); } diff --git a/unsupported/test/sparse_ldlt.cpp b/unsupported/test/sparse_ldlt.cpp index 4ceda3188..43ff2682f 100644 --- a/unsupported/test/sparse_ldlt.cpp +++ b/unsupported/test/sparse_ldlt.cpp @@ -29,15 +29,16 @@ #include #endif -template void sparse_ldlt(int rows, int cols) +template void sparse_ldlt(int rows, int cols) { static bool odd = true; odd = !odd; double density = std::max(8./(rows*cols), 0.01); typedef Matrix DenseMatrix; typedef Matrix DenseVector; - - SparseMatrix m2(rows, cols); + typedef SparseMatrix SparseMatrixType; + + SparseMatrixType m2(rows, cols); DenseMatrix refMat2(rows, cols); DenseVector b = DenseVector::Random(cols); @@ -45,11 +46,11 @@ template void sparse_ldlt(int rows, int cols) initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular, 0, 0); - SparseMatrix m3 = m2 * m2.adjoint(), m3_lo(rows,rows), m3_up(rows,rows); + SparseMatrixType m3 = m2 * m2.adjoint(), m3_lo(rows,rows), m3_up(rows,rows); DenseMatrix refMat3 = refMat2 * refMat2.adjoint(); refX = refMat3.template selfadjointView().ldlt().solve(b); - typedef SparseMatrix SparseSelfAdjointMatrix; + typedef SparseMatrix SparseSelfAdjointMatrix; x = b; SparseLDLT ldlt(m3); if (ldlt.succeeded()) @@ -84,7 +85,7 @@ template void sparse_ldlt(int rows, int cols) // new API { - SparseMatrix m2(rows, cols); + SparseMatrixType m2(rows, cols); DenseMatrix refMat2(rows, cols); DenseVector b = DenseVector::Random(cols); @@ -98,7 +99,7 @@ template void sparse_ldlt(int rows, int cols) m2.coeffRef(i,i) = refMat2(i,i) = internal::abs(internal::real(refMat2(i,i))); - SparseMatrix m3 = m2 * m2.adjoint(), m3_lo(rows,rows), m3_up(rows,rows); + SparseMatrixType m3 = m2 * m2.adjoint(), m3_lo(rows,rows), m3_up(rows,rows); DenseMatrix refMat3 = refMat2 * refMat2.adjoint(); m3_lo.template selfadjointView().rankUpdate(m2,0); @@ -107,40 +108,40 @@ template void sparse_ldlt(int rows, int cols) // with a single vector as the rhs ref_x = refMat3.template selfadjointView().llt().solve(b); - x = SimplicialCholesky, Lower>().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(b); + x = SimplicialCholesky().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "SimplicialCholesky: solve, full storage, lower, single dense rhs"); - x = SimplicialCholesky, Upper>().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(b); + x = SimplicialCholesky().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "SimplicialCholesky: solve, full storage, upper, single dense rhs"); - x = SimplicialCholesky, Lower>(m3_lo).solve(b); + x = SimplicialCholesky(m3_lo).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "SimplicialCholesky: solve, lower only, single dense rhs"); - x = SimplicialCholesky, Upper>(m3_up).solve(b); + x = SimplicialCholesky(m3_up).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "SimplicialCholesky: solve, upper only, single dense rhs"); // with multiple rhs ref_X = refMat3.template selfadjointView().llt().solve(B); - X = SimplicialCholesky, Lower>().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(B); + X = SimplicialCholesky().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(B); VERIFY(ref_X.isApprox(X,test_precision()) && "SimplicialCholesky: solve, full storage, lower, multiple dense rhs"); - X = SimplicialCholesky, Upper>().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(B); + X = SimplicialCholesky().setMode(odd ? SimplicialCholeskyLLt : SimplicialCholeskyLDLt).compute(m3).solve(B); VERIFY(ref_X.isApprox(X,test_precision()) && "SimplicialCholesky: solve, full storage, upper, multiple dense rhs"); // with a sparse rhs -// SparseMatrix spB(rows,cols), spX(rows,cols); +// SparseMatrixType spB(rows,cols), spX(rows,cols); // B.diagonal().array() += 1; // spB = B.sparseView(0.5,1); // // ref_X = refMat3.template selfadjointView().llt().solve(DenseMatrix(spB)); // -// spX = SimplicialCholesky, Lower>(m3).solve(spB); +// spX = SimplicialCholesky(m3).solve(spB); // VERIFY(ref_X.isApprox(spX.toDense(),test_precision()) && "LLT: cholmod solve, multiple sparse rhs"); // -// spX = SimplicialCholesky, Upper>(m3).solve(spB); +// spX = SimplicialCholesky(m3).solve(spB); // VERIFY(ref_X.isApprox(spX.toDense(),test_precision()) && "LLT: cholmod solve, multiple sparse rhs"); } @@ -167,9 +168,10 @@ template void sparse_ldlt(int rows, int cols) void test_sparse_ldlt() { for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_1(sparse_ldlt(8, 8) ); + CALL_SUBTEST_1( (sparse_ldlt(8, 8)) ); + CALL_SUBTEST_1( (sparse_ldlt(8, 8)) ); int s = internal::random(1,300); - CALL_SUBTEST_2(sparse_ldlt >(s,s) ); - CALL_SUBTEST_1(sparse_ldlt(s,s) ); + CALL_SUBTEST_2( (sparse_ldlt,int>(s,s)) ); + CALL_SUBTEST_1( (sparse_ldlt(s,s)) ); } } diff --git a/unsupported/test/sparse_llt.cpp b/unsupported/test/sparse_llt.cpp index df198cd52..a997deb82 100644 --- a/unsupported/test/sparse_llt.cpp +++ b/unsupported/test/sparse_llt.cpp @@ -29,14 +29,15 @@ #include #endif -template void sparse_llt(int rows, int cols) +template void sparse_llt(int rows, int cols) { double density = std::max(8./(rows*cols), 0.01); typedef Matrix DenseMatrix; typedef Matrix DenseVector; + typedef SparseMatrix SparseMatrixType; // TODO fix the issue with complex (see SparseLLT::solveInPlace) - SparseMatrix m2(rows, cols); + SparseMatrixType m2(rows, cols); DenseMatrix refMat2(rows, cols); DenseVector b = DenseVector::Random(cols); @@ -53,7 +54,7 @@ template void sparse_llt(int rows, int cols) if (!NumTraits::IsComplex) { x = b; - SparseLLT > (m2).solveInPlace(x); + SparseLLT (m2).solveInPlace(x); VERIFY(ref_x.isApprox(x,test_precision()) && "LLT: default"); } @@ -61,23 +62,23 @@ template void sparse_llt(int rows, int cols) // legacy API { // Cholmod, as configured in CholmodSupport.h, only supports self-adjoint matrices - SparseMatrix m3 = m2.adjoint()*m2; + SparseMatrixType m3 = m2.adjoint()*m2; DenseMatrix refMat3 = refMat2.adjoint()*refMat2; ref_x = refMat3.template selfadjointView().llt().solve(b); x = b; - SparseLLT, Cholmod>(m3).solveInPlace(x); + SparseLLT(m3).solveInPlace(x); VERIFY((m3*x).isApprox(b,test_precision()) && "LLT legacy: cholmod solveInPlace"); - x = SparseLLT, Cholmod>(m3).solve(b); + x = SparseLLT(m3).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "LLT legacy: cholmod solve"); } // new API { // Cholmod, as configured in CholmodSupport.h, only supports self-adjoint matrices - SparseMatrix m3 = m2 * m2.adjoint(), m3_lo(rows,rows), m3_up(rows,rows); + SparseMatrixType m3 = m2 * m2.adjoint(), m3_lo(rows,rows), m3_up(rows,rows); DenseMatrix refMat3 = refMat2 * refMat2.adjoint(); m3_lo.template selfadjointView().rankUpdate(m2,0); @@ -86,16 +87,16 @@ template void sparse_llt(int rows, int cols) // with a single vector as the rhs ref_x = refMat3.template selfadjointView().llt().solve(b); - x = CholmodDecomposition, Lower>(m3).solve(b); + x = CholmodDecomposition(m3).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "LLT: cholmod solve, single dense rhs"); - x = CholmodDecomposition, Upper>(m3).solve(b); + x = CholmodDecomposition(m3).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "LLT: cholmod solve, single dense rhs"); - x = CholmodDecomposition, Lower>(m3_lo).solve(b); + x = CholmodDecomposition(m3_lo).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "LLT: cholmod solve, single dense rhs"); - x = CholmodDecomposition, Upper>(m3_up).solve(b); + x = CholmodDecomposition(m3_up).solve(b); VERIFY(ref_x.isApprox(x,test_precision()) && "LLT: cholmod solve, single dense rhs"); @@ -104,25 +105,25 @@ template void sparse_llt(int rows, int cols) #ifndef EIGEN_DEFAULT_TO_ROW_MAJOR // TODO make sure the API is properly documented about this fact - X = CholmodDecomposition, Lower>(m3).solve(B); + X = CholmodDecomposition(m3).solve(B); VERIFY(ref_X.isApprox(X,test_precision()) && "LLT: cholmod solve, multiple dense rhs"); - X = CholmodDecomposition, Upper>(m3).solve(B); + X = CholmodDecomposition(m3).solve(B); VERIFY(ref_X.isApprox(X,test_precision()) && "LLT: cholmod solve, multiple dense rhs"); #endif // with a sparse rhs - SparseMatrix spB(rows,cols), spX(rows,cols); + SparseMatrixType spB(rows,cols), spX(rows,cols); B.diagonal().array() += 1; spB = B.sparseView(0.5,1); ref_X = refMat3.template selfadjointView().llt().solve(DenseMatrix(spB)); - spX = CholmodDecomposition, Lower>(m3).solve(spB); + spX = CholmodDecomposition(m3).solve(spB); VERIFY(ref_X.isApprox(spX.toDense(),test_precision()) && "LLT: cholmod solve, multiple sparse rhs"); - spX = CholmodDecomposition, Upper>(m3).solve(spB); + spX = CholmodDecomposition(m3).solve(spB); VERIFY(ref_X.isApprox(spX.toDense(),test_precision()) && "LLT: cholmod solve, multiple sparse rhs"); } #endif @@ -132,9 +133,10 @@ template void sparse_llt(int rows, int cols) void test_sparse_llt() { for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST_1(sparse_llt(8, 8) ); + CALL_SUBTEST_1( (sparse_llt(8, 8)) ); int s = internal::random(1,300); - CALL_SUBTEST_2(sparse_llt >(s,s) ); - CALL_SUBTEST_1(sparse_llt(s,s) ); + CALL_SUBTEST_2( (sparse_llt,int>(s,s)) ); + CALL_SUBTEST_1( (sparse_llt(s,s)) ); + CALL_SUBTEST_1( (sparse_llt(s,s)) ); } }