Apply clang-format

This commit is contained in:
Tobias Wood
2023-11-29 11:12:48 +00:00
parent 9ea520fc45
commit f38e16c193
534 changed files with 103368 additions and 116934 deletions

View File

@@ -36,78 +36,68 @@ namespace Eigen {
* \sa class LeastSquareDiagonalPreconditioner, class ConjugateGradient
*/
template <typename Scalar_>
class DiagonalPreconditioner
{
typedef Scalar_ Scalar;
typedef Matrix<Scalar,Dynamic,1> Vector;
public:
typedef typename Vector::StorageIndex StorageIndex;
enum {
ColsAtCompileTime = Dynamic,
MaxColsAtCompileTime = Dynamic
};
class DiagonalPreconditioner {
typedef Scalar_ Scalar;
typedef Matrix<Scalar, Dynamic, 1> Vector;
DiagonalPreconditioner() : m_isInitialized(false) {}
public:
typedef typename Vector::StorageIndex StorageIndex;
enum { ColsAtCompileTime = Dynamic, MaxColsAtCompileTime = Dynamic };
template<typename MatType>
explicit DiagonalPreconditioner(const MatType& mat) : m_invdiag(mat.cols())
{
compute(mat);
DiagonalPreconditioner() : m_isInitialized(false) {}
template <typename MatType>
explicit DiagonalPreconditioner(const MatType& mat) : m_invdiag(mat.cols()) {
compute(mat);
}
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_invdiag.size(); }
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_invdiag.size(); }
template <typename MatType>
DiagonalPreconditioner& analyzePattern(const MatType&) {
return *this;
}
template <typename MatType>
DiagonalPreconditioner& factorize(const MatType& mat) {
m_invdiag.resize(mat.cols());
for (int j = 0; j < mat.outerSize(); ++j) {
typename MatType::InnerIterator it(mat, j);
while (it && it.index() != j) ++it;
if (it && it.index() == j && it.value() != Scalar(0))
m_invdiag(j) = Scalar(1) / it.value();
else
m_invdiag(j) = Scalar(1);
}
m_isInitialized = true;
return *this;
}
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_invdiag.size(); }
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_invdiag.size(); }
template <typename MatType>
DiagonalPreconditioner& compute(const MatType& mat) {
return factorize(mat);
}
template<typename MatType>
DiagonalPreconditioner& analyzePattern(const MatType& )
{
return *this;
}
/** \internal */
template <typename Rhs, typename Dest>
void _solve_impl(const Rhs& b, Dest& x) const {
x = m_invdiag.array() * b.array();
}
template<typename MatType>
DiagonalPreconditioner& factorize(const MatType& mat)
{
m_invdiag.resize(mat.cols());
for(int j=0; j<mat.outerSize(); ++j)
{
typename MatType::InnerIterator it(mat,j);
while(it && it.index()!=j) ++it;
if(it && it.index()==j && it.value()!=Scalar(0))
m_invdiag(j) = Scalar(1)/it.value();
else
m_invdiag(j) = Scalar(1);
}
m_isInitialized = true;
return *this;
}
template <typename Rhs>
inline const Solve<DiagonalPreconditioner, Rhs> solve(const MatrixBase<Rhs>& b) const {
eigen_assert(m_isInitialized && "DiagonalPreconditioner is not initialized.");
eigen_assert(m_invdiag.size() == b.rows() &&
"DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b");
return Solve<DiagonalPreconditioner, Rhs>(*this, b.derived());
}
template<typename MatType>
DiagonalPreconditioner& compute(const MatType& mat)
{
return factorize(mat);
}
ComputationInfo info() { return Success; }
/** \internal */
template<typename Rhs, typename Dest>
void _solve_impl(const Rhs& b, Dest& x) const
{
x = m_invdiag.array() * b.array() ;
}
template<typename Rhs> inline const Solve<DiagonalPreconditioner, Rhs>
solve(const MatrixBase<Rhs>& b) const
{
eigen_assert(m_isInitialized && "DiagonalPreconditioner is not initialized.");
eigen_assert(m_invdiag.size()==b.rows()
&& "DiagonalPreconditioner::solve(): invalid number of rows of the right hand side matrix b");
return Solve<DiagonalPreconditioner, Rhs>(*this, b.derived());
}
ComputationInfo info() { return Success; }
protected:
Vector m_invdiag;
bool m_isInitialized;
protected:
Vector m_invdiag;
bool m_isInitialized;
};
/** \ingroup IterativeLinearSolvers_Module
@@ -128,102 +118,96 @@ class DiagonalPreconditioner
* \sa class LeastSquaresConjugateGradient, class DiagonalPreconditioner
*/
template <typename Scalar_>
class LeastSquareDiagonalPreconditioner : public DiagonalPreconditioner<Scalar_>
{
typedef Scalar_ Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef DiagonalPreconditioner<Scalar_> Base;
using Base::m_invdiag;
public:
class LeastSquareDiagonalPreconditioner : public DiagonalPreconditioner<Scalar_> {
typedef Scalar_ Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef DiagonalPreconditioner<Scalar_> Base;
using Base::m_invdiag;
LeastSquareDiagonalPreconditioner() : Base() {}
public:
LeastSquareDiagonalPreconditioner() : Base() {}
template<typename MatType>
explicit LeastSquareDiagonalPreconditioner(const MatType& mat) : Base()
{
compute(mat);
}
template <typename MatType>
explicit LeastSquareDiagonalPreconditioner(const MatType& mat) : Base() {
compute(mat);
}
template<typename MatType>
LeastSquareDiagonalPreconditioner& analyzePattern(const MatType& )
{
return *this;
}
template <typename MatType>
LeastSquareDiagonalPreconditioner& analyzePattern(const MatType&) {
return *this;
}
template<typename MatType>
LeastSquareDiagonalPreconditioner& factorize(const MatType& mat)
{
// Compute the inverse squared-norm of each column of mat
m_invdiag.resize(mat.cols());
if(MatType::IsRowMajor)
{
m_invdiag.setZero();
for(Index j=0; j<mat.outerSize(); ++j)
{
for(typename MatType::InnerIterator it(mat,j); it; ++it)
m_invdiag(it.index()) += numext::abs2(it.value());
}
for(Index j=0; j<mat.cols(); ++j)
if(numext::real(m_invdiag(j))>RealScalar(0))
m_invdiag(j) = RealScalar(1)/numext::real(m_invdiag(j));
template <typename MatType>
LeastSquareDiagonalPreconditioner& factorize(const MatType& mat) {
// Compute the inverse squared-norm of each column of mat
m_invdiag.resize(mat.cols());
if (MatType::IsRowMajor) {
m_invdiag.setZero();
for (Index j = 0; j < mat.outerSize(); ++j) {
for (typename MatType::InnerIterator it(mat, j); it; ++it) m_invdiag(it.index()) += numext::abs2(it.value());
}
else
{
for(Index j=0; j<mat.outerSize(); ++j)
{
RealScalar sum = mat.col(j).squaredNorm();
if(sum>RealScalar(0))
m_invdiag(j) = RealScalar(1)/sum;
else
m_invdiag(j) = RealScalar(1);
}
for (Index j = 0; j < mat.cols(); ++j)
if (numext::real(m_invdiag(j)) > RealScalar(0)) m_invdiag(j) = RealScalar(1) / numext::real(m_invdiag(j));
} else {
for (Index j = 0; j < mat.outerSize(); ++j) {
RealScalar sum = mat.col(j).squaredNorm();
if (sum > RealScalar(0))
m_invdiag(j) = RealScalar(1) / sum;
else
m_invdiag(j) = RealScalar(1);
}
Base::m_isInitialized = true;
return *this;
}
Base::m_isInitialized = true;
return *this;
}
template<typename MatType>
LeastSquareDiagonalPreconditioner& compute(const MatType& mat)
{
return factorize(mat);
}
template <typename MatType>
LeastSquareDiagonalPreconditioner& compute(const MatType& mat) {
return factorize(mat);
}
ComputationInfo info() { return Success; }
ComputationInfo info() { return Success; }
protected:
protected:
};
/** \ingroup IterativeLinearSolvers_Module
* \brief A naive preconditioner which approximates any matrix as the identity matrix
*
* \implsparsesolverconcept
*
* \sa class DiagonalPreconditioner
*/
class IdentityPreconditioner
{
public:
* \brief A naive preconditioner which approximates any matrix as the identity matrix
*
* \implsparsesolverconcept
*
* \sa class DiagonalPreconditioner
*/
class IdentityPreconditioner {
public:
IdentityPreconditioner() {}
IdentityPreconditioner() {}
template <typename MatrixType>
explicit IdentityPreconditioner(const MatrixType&) {}
template<typename MatrixType>
explicit IdentityPreconditioner(const MatrixType& ) {}
template <typename MatrixType>
IdentityPreconditioner& analyzePattern(const MatrixType&) {
return *this;
}
template<typename MatrixType>
IdentityPreconditioner& analyzePattern(const MatrixType& ) { return *this; }
template <typename MatrixType>
IdentityPreconditioner& factorize(const MatrixType&) {
return *this;
}
template<typename MatrixType>
IdentityPreconditioner& factorize(const MatrixType& ) { return *this; }
template <typename MatrixType>
IdentityPreconditioner& compute(const MatrixType&) {
return *this;
}
template<typename MatrixType>
IdentityPreconditioner& compute(const MatrixType& ) { return *this; }
template <typename Rhs>
inline const Rhs& solve(const Rhs& b) const {
return b;
}
template<typename Rhs>
inline const Rhs& solve(const Rhs& b) const { return b; }
ComputationInfo info() { return Success; }
ComputationInfo info() { return Success; }
};
} // end namespace Eigen
} // end namespace Eigen
#endif // EIGEN_BASIC_PRECONDITIONERS_H
#endif // EIGEN_BASIC_PRECONDITIONERS_H