mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-24 14:45:14 +08:00
fix Taucs support (it appears Taucs does not return sorted matrices)
This commit is contained in:
parent
1b7b538e05
commit
3499f6eccd
@ -62,7 +62,7 @@ class SparseMatrix
|
|||||||
// FIXME: why are these operator already alvailable ???
|
// FIXME: why are these operator already alvailable ???
|
||||||
// EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, *=)
|
// EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, *=)
|
||||||
// EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, /=)
|
// EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, /=)
|
||||||
|
|
||||||
typedef MappedSparseMatrix<Scalar,Flags> Map;
|
typedef MappedSparseMatrix<Scalar,Flags> Map;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -79,7 +79,7 @@ class SparseMatrix
|
|||||||
|
|
||||||
inline int rows() const { return IsRowMajor ? m_outerSize : m_innerSize; }
|
inline int rows() const { return IsRowMajor ? m_outerSize : m_innerSize; }
|
||||||
inline int cols() const { return IsRowMajor ? m_innerSize : m_outerSize; }
|
inline int cols() const { return IsRowMajor ? m_innerSize : m_outerSize; }
|
||||||
|
|
||||||
inline int innerSize() const { return m_innerSize; }
|
inline int innerSize() const { return m_innerSize; }
|
||||||
inline int outerSize() const { return m_outerSize; }
|
inline int outerSize() const { return m_outerSize; }
|
||||||
inline int innerNonZeros(int j) const { return m_outerIndex[j+1]-m_outerIndex[j]; }
|
inline int innerNonZeros(int j) const { return m_outerIndex[j+1]-m_outerIndex[j]; }
|
||||||
@ -195,7 +195,7 @@ class SparseMatrix
|
|||||||
// FIXME let's make sure sizeof(long int) == sizeof(size_t)
|
// FIXME let's make sure sizeof(long int) == sizeof(size_t)
|
||||||
size_t id = m_outerIndex[outer+1];
|
size_t id = m_outerIndex[outer+1];
|
||||||
++m_outerIndex[outer+1];
|
++m_outerIndex[outer+1];
|
||||||
|
|
||||||
float reallocRatio = 1;
|
float reallocRatio = 1;
|
||||||
if (m_data.allocatedSize()<id+1)
|
if (m_data.allocatedSize()<id+1)
|
||||||
{
|
{
|
||||||
@ -217,7 +217,7 @@ class SparseMatrix
|
|||||||
m_data.value(id) = m_data.value(id-1);
|
m_data.value(id) = m_data.value(id-1);
|
||||||
--id;
|
--id;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data.index(id) = inner;
|
m_data.index(id) = inner;
|
||||||
return (m_data.value(id) = 0);
|
return (m_data.value(id) = 0);
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ class SparseMatrix
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void prune(Scalar reference, RealScalar epsilon = precision<RealScalar>())
|
void prune(Scalar reference, RealScalar epsilon = precision<RealScalar>())
|
||||||
{
|
{
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
@ -224,6 +224,7 @@ SluMatrix SparseMatrixBase<Derived>::asSluMatrix()
|
|||||||
return SluMatrix::Map(derived());
|
return SluMatrix::Map(derived());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** View a Super LU matrix as an Eigen expression */
|
||||||
template<typename Scalar, int Flags>
|
template<typename Scalar, int Flags>
|
||||||
MappedSparseMatrix<Scalar,Flags>::MappedSparseMatrix(SluMatrix& sluMat)
|
MappedSparseMatrix<Scalar,Flags>::MappedSparseMatrix(SluMatrix& sluMat)
|
||||||
{
|
{
|
||||||
|
@ -129,7 +129,10 @@ void SparseLLT<MatrixType,Taucs>::compute(const MatrixType& a)
|
|||||||
{
|
{
|
||||||
taucs_ccs_matrix taucsMatA = const_cast<MatrixType&>(a).asTaucsMatrix();
|
taucs_ccs_matrix taucsMatA = const_cast<MatrixType&>(a).asTaucsMatrix();
|
||||||
taucs_ccs_matrix* taucsRes = taucs_ccs_factor_llt(&taucsMatA, Base::m_precision, 0);
|
taucs_ccs_matrix* taucsRes = taucs_ccs_factor_llt(&taucsMatA, Base::m_precision, 0);
|
||||||
m_matrix = MappedSparseMatrix<Scalar>(*taucsRes);
|
// the matrix returned by Taucs is not necessarily sorted,
|
||||||
|
// so let's copy it in two steps
|
||||||
|
DynamicSparseMatrix<Scalar,RowMajor> tmp = MappedSparseMatrix<Scalar>(*taucsRes);
|
||||||
|
m_matrix = tmp;
|
||||||
free(taucsRes);
|
free(taucsRes);
|
||||||
m_status = (m_status & ~(CompleteFactorization|MatrixLIsDirty))
|
m_status = (m_status & ~(CompleteFactorization|MatrixLIsDirty))
|
||||||
| IncompleteFactorization
|
| IncompleteFactorization
|
||||||
@ -161,7 +164,11 @@ SparseLLT<MatrixType,Taucs>::matrixL() const
|
|||||||
ei_assert(!(m_status & SupernodalFactorIsDirty));
|
ei_assert(!(m_status & SupernodalFactorIsDirty));
|
||||||
|
|
||||||
taucs_ccs_matrix* taucsL = taucs_supernodal_factor_to_ccs(m_taucsSupernodalFactor);
|
taucs_ccs_matrix* taucsL = taucs_supernodal_factor_to_ccs(m_taucsSupernodalFactor);
|
||||||
const_cast<typename Base::CholMatrixType&>(m_matrix) = MappedSparseMatrix<Scalar>(*taucsL);
|
|
||||||
|
// the matrix returned by Taucs is not necessarily sorted,
|
||||||
|
// so let's copy it in two steps
|
||||||
|
DynamicSparseMatrix<Scalar,RowMajor> tmp = MappedSparseMatrix<Scalar>(*taucsL);
|
||||||
|
const_cast<typename Base::CholMatrixType&>(m_matrix) = tmp;
|
||||||
free(taucsL);
|
free(taucsL);
|
||||||
m_status = (m_status & ~MatrixLIsDirty);
|
m_status = (m_status & ~MatrixLIsDirty);
|
||||||
}
|
}
|
||||||
@ -172,22 +179,32 @@ template<typename MatrixType>
|
|||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
void SparseLLT<MatrixType,Taucs>::solveInPlace(MatrixBase<Derived> &b) const
|
void SparseLLT<MatrixType,Taucs>::solveInPlace(MatrixBase<Derived> &b) const
|
||||||
{
|
{
|
||||||
if (m_status & MatrixLIsDirty)
|
bool inputIsCompatibleWithTaucs = (Derived::Flags&RowMajorBit)==0;
|
||||||
|
|
||||||
|
if (!inputIsCompatibleWithTaucs)
|
||||||
{
|
{
|
||||||
// TODO use taucs's supernodal solver, in particular check types, storage order, etc.
|
|
||||||
// VectorXb x(b.rows());
|
|
||||||
// for (int j=0; j<b.cols(); ++j)
|
|
||||||
// {
|
|
||||||
// taucs_supernodal_solve_llt(m_taucsSupernodalFactor,x.data(),&b.col(j).coeffRef(0));
|
|
||||||
// b.col(j) = x;
|
|
||||||
// }
|
|
||||||
matrixL();
|
matrixL();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
Base::solveInPlace(b);
|
Base::solveInPlace(b);
|
||||||
}
|
}
|
||||||
|
else if (m_flags & IncompleteFactorization)
|
||||||
|
{
|
||||||
|
taucs_ccs_matrix taucsLLT = const_cast<typename Base::CholMatrixType&>(m_matrix).asTaucsMatrix();
|
||||||
|
typename ei_plain_matrix_type<Derived>::type x(b.rows());
|
||||||
|
for (int j=0; j<b.cols(); ++j)
|
||||||
|
{
|
||||||
|
taucs_ccs_solve_llt(&taucsLLT,x.data(),&b.col(j).coeffRef(0));
|
||||||
|
b.col(j) = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
typename ei_plain_matrix_type<Derived>::type x(b.rows());
|
||||||
|
for (int j=0; j<b.cols(); ++j)
|
||||||
|
{
|
||||||
|
taucs_supernodal_solve_llt(m_taucsSupernodalFactor,x.data(),&b.col(j).coeffRef(0));
|
||||||
|
b.col(j) = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_TAUCSSUPPORT_H
|
#endif // EIGEN_TAUCSSUPPORT_H
|
||||||
|
Loading…
Reference in New Issue
Block a user