From bada4d811ffd8b63b0d8eb945ea47f8a4874873f Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Mon, 31 Jul 2023 15:11:55 -0700 Subject: [PATCH] Fix RLDLT to live in the conex namespace Projects must not define classes in another project's namespace. When we fork code from another project, we need to switch it to our own namespace. --- conex/RLDLT.h | 40 ++++++++++--------- conex/block_triangular_operations.cc | 6 +-- conex/block_triangular_operations.h | 8 ++-- conex/kkt_solver.h | 2 +- .../test/block_triangular_operations_test.cc | 2 +- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/conex/RLDLT.h b/conex/RLDLT.h index d945e9a..afd4441 100644 --- a/conex/RLDLT.h +++ b/conex/RLDLT.h @@ -1,6 +1,6 @@ -#include "conex/debug_macros.h" -#include -// This file is part of Eigen, a lightweight C++ template library +#pragma once + +// This file was copied from Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008-2011 Gael Guennebaud @@ -12,19 +12,20 @@ // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef EIGEN_RLDLT_H -#define EIGEN_RLDLT_H +#include + +#include "conex/debug_macros.h" + +namespace conex { +namespace eigen_stuff { -namespace Eigen { +using namespace Eigen; +namespace internal = Eigen::internal; -namespace internal { +namespace detail { template struct RLDLT_Traits; - -// PositiveSemiDef means positive semi-definite and non-zero; same for -// NegativeSemiDef -// enum SignMatrix { PositiveSemiDef, NegativeSemiDef, ZeroSign, Indefinite }; -} // namespace internal +} // namespace detail /** \ingroup Cholesky_Module * @@ -78,7 +79,7 @@ class RLDLT { typedef PermutationMatrix PermutationType; - typedef internal::LDLT_Traits Traits; + typedef detail::RLDLT_Traits Traits; /** \brief Default Constructor. * @@ -289,7 +290,9 @@ class RLDLT { ComputationInfo m_info; }; -namespace internal { +namespace detail { + +using namespace Eigen::internal; template struct rldlt_inplace; @@ -564,7 +567,7 @@ RLDLT& RLDLT::compute( m_temporary.resize(size); m_sign = internal::ZeroSign; - m_regularization_used = !internal::rldlt_inplace::unblocked( + m_regularization_used = !detail::rldlt_inplace::unblocked( m_matrix, m_transpositions, m_temporary, m_sign); m_info = Success; @@ -598,7 +601,7 @@ RLDLT& RLDLT::rankUpdate( m_isInitialized = true; } - internal::rldlt_inplace::update(m_matrix, m_transpositions, m_temporary, + detail::rldlt_inplace::update(m_matrix, m_transpositions, m_temporary, w, sigma); return *this; @@ -696,6 +699,5 @@ MatrixType RLDLT::reconstructedMatrix() const { return res; } -} // end namespace Eigen - -#endif // EIGEN_RLDLT_H +} // namespace eigen_stuff +} // namespace conex diff --git a/conex/block_triangular_operations.cc b/conex/block_triangular_operations.cc index 3c84b31..2908b52 100644 --- a/conex/block_triangular_operations.cc +++ b/conex/block_triangular_operations.cc @@ -221,7 +221,7 @@ bool T::BlockCholeskyInPlace(TriangularMatrixWorkspace* C) { // Apply inv(M^T) = inv(L^T P) = P^T inv(L^T) void T::ApplyBlockInverseOfMTranspose( const TriangularMatrixWorkspace& mat, - const std::vector>> factorization, + const std::vector>> factorization, VectorXd* y) { PartitionVectorIterator ypart(*y, mat.N, mat.supernode_size); // mat.diagonal.back().triangularView().transpose().solveInPlace(ypart.b_i()); @@ -264,7 +264,7 @@ void T::ApplyBlockInverseOfMTranspose( void T::ApplyBlockInverseOfMD( const TriangularMatrixWorkspace& mat, - const std::vector>> factorization, + const std::vector>> factorization, VectorXd* y) { // Apply inv(M) = inv(P^T L) = inv(L) P PartitionVectorForwardIterator ypart(*y, mat.supernode_size); @@ -314,7 +314,7 @@ void T::ApplyBlockInverseOfMD( // = inv(D_1) inv(L) P * off_diag bool T::BlockLDLTInPlace( TriangularMatrixWorkspace* C, - std::vector>>* factorization) { + std::vector>>* factorization) { auto& llts = *factorization; llts.clear(); diff --git a/conex/block_triangular_operations.h b/conex/block_triangular_operations.h index 7fccc45..4affc17 100644 --- a/conex/block_triangular_operations.h +++ b/conex/block_triangular_operations.h @@ -14,22 +14,22 @@ struct BlockTriangularOperations { static bool BlockCholeskyInPlace(TriangularMatrixWorkspace* mat); static bool BlockLDLTInPlace( TriangularMatrixWorkspace* mat, - std::vector>>* factorization); + std::vector>>* factorization); static void ApplyBlockInverseOfMTranspose( const TriangularMatrixWorkspace& mat, - const std::vector>> + const std::vector>> factorization, Eigen::VectorXd* y); static void ApplyBlockInverseOfMD( const TriangularMatrixWorkspace& mat, - const std::vector>> + const std::vector>> factorization, Eigen::VectorXd* y); static void SolveInPlaceLDLT( const TriangularMatrixWorkspace& mat, - const std::vector>> + const std::vector>> factorization, Eigen::VectorXd* y) { ApplyBlockInverseOfMD(mat, factorization, y); diff --git a/conex/kkt_solver.h b/conex/kkt_solver.h index 9fcf9b9..38b3ce8 100644 --- a/conex/kkt_solver.h +++ b/conex/kkt_solver.h @@ -53,7 +53,7 @@ class SupernodalKKTSolver { const std::vector> dual_variables_; MatrixData data; SparseTriangularMatrix mat; - std::vector>> factorization; + std::vector>> factorization; Eigen::PermutationMatrix<-1> Pt; mutable Eigen::VectorXd b_permuted_; std::vector assembler; diff --git a/conex/test/block_triangular_operations_test.cc b/conex/test/block_triangular_operations_test.cc index 1277cff..1711d5b 100644 --- a/conex/test/block_triangular_operations_test.cc +++ b/conex/test/block_triangular_operations_test.cc @@ -202,7 +202,7 @@ void DoLDLTTest(bool diagonal, const std::vector& cliques) { Eigen::MatrixXd X = T::ToDense(mat).selfadjointView(); - std::vector>> factorization; + std::vector>> factorization; B::BlockLDLTInPlace(&mat.workspace_, &factorization); Eigen::VectorXd z = Eigen::VectorXd::Random(X.cols());