// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2017 Kyle Macfarlan <kyle.macfarlan@gmail.com> // // This Source Code Form is subject to the terms of the Mozilla // 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/.
/* TODO extract L, extract U, compute det, etc... */
/** \ingroup KLUSupport_Module * \brief A sparse LU factorization and solver based on KLU * * This class allows to solve for A.X = B sparse linear problems via a LU factorization * using the KLU library. The sparse matrix A must be squared and full rank. * The vectors or matrices X and B can be either dense or sparse. * * \warning The input matrix A should be in a \b compressed and \b column-major form. * Otherwise an expensive copy will be made. You can call the inexpensive makeCompressed() to get a compressed matrix. * \tparam _MatrixType the type of the sparse matrix A, it must be a SparseMatrix<> * * \implsparsesolverconcept * * \sa \ref TutorialSparseSolverConcept, class UmfPackLU, class SparseLU
*/
inlineint klu_solve(klu_symbolic *Symbolic, klu_numeric *Numeric, Index ldim, Index nrhs, double B [ ], klu_common *Common, double) { return klu_solve(Symbolic, Numeric, internal::convert_index<int>(ldim), internal::convert_index<int>(nrhs), B, Common);
}
inlineconst IntRowVectorType& permutationQ() const
{ if (m_extractedDataAreDirty) extractData(); return m_q;
} #endif /** Computes the sparse Cholesky decomposition of \a matrix * Note that the matrix should be column-major, and in compressed format for best performance. * \sa SparseMatrix::makeCompressed().
*/ template<typename InputMatrixType> void compute(const InputMatrixType& matrix)
{ if(m_symbolic) klu_free_symbolic(&m_symbolic, &m_common); if(m_numeric) klu_free_numeric(&m_numeric, &m_common);
grab(matrix.derived());
analyzePattern_impl();
factorize_impl();
}
/** Performs a symbolic decomposition on the sparcity of \a matrix. * * This function is particularly useful when solving for several problems having the same structure. * * \sa factorize(), compute()
*/ template<typename InputMatrixType> void analyzePattern(const InputMatrixType& matrix)
{ if(m_symbolic) klu_free_symbolic(&m_symbolic, &m_common); if(m_numeric) klu_free_numeric(&m_numeric, &m_common);
grab(matrix.derived());
analyzePattern_impl();
}
/** Provides access to the control settings array used by KLU. * * See KLU documentation for details.
*/ inlineconst klu_common& kluCommon() const
{ return m_common;
}
/** Provides access to the control settings array used by UmfPack. * * If this array contains NaN's, the default values are used. * * See KLU documentation for details.
*/ inline klu_common& kluCommon()
{ return m_common;
}
/** Performs a numeric decomposition of \a matrix * * The given matrix must has the same sparcity than the matrix on which the pattern anylysis has been performed. * * \sa analyzePattern(), compute()
*/ template<typename InputMatrixType> void factorize(const InputMatrixType& matrix)
{
eigen_assert(m_analysisIsOk && "KLU: you must first call analyzePattern()"); if(m_numeric)
klu_free_numeric(&m_numeric,&m_common);
template<typename MatrixType> template<typename BDerived,typename XDerived> bool KLU<MatrixType>::_solve_impl(const MatrixBase<BDerived> &b, MatrixBase<XDerived> &x) const
{
Index rhsCols = b.cols();
EIGEN_STATIC_ASSERT((XDerived::Flags&RowMajorBit)==0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or analyzePattern()/factorize()");
x = b; int info = klu_solve(m_symbolic, m_numeric, b.rows(), rhsCols, x.const_cast_derived().data(), const_cast<klu_common*>(&m_common), Scalar());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.