mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
split the Sparse module into multiple ones, and move non stable parts to unsupported/
(see the ML for details)
This commit is contained in:
@@ -16,56 +16,6 @@ else(GSL_FOUND)
|
||||
set(GSL_LIBRARIES " ")
|
||||
endif(GSL_FOUND)
|
||||
|
||||
set(SPARSE_LIBS "")
|
||||
|
||||
find_package(Taucs)
|
||||
if(TAUCS_FOUND)
|
||||
add_definitions("-DEIGEN_TAUCS_SUPPORT")
|
||||
include_directories(${TAUCS_INCLUDES})
|
||||
set(SPARSE_LIBS ${SPARSE_LIBS} ${TAUCS_LIBRARIES})
|
||||
ei_add_property(EIGEN_TESTED_BACKENDS "Taucs, ")
|
||||
else(TAUCS_FOUND)
|
||||
ei_add_property(EIGEN_MISSING_BACKENDS "Taucs, ")
|
||||
endif(TAUCS_FOUND)
|
||||
|
||||
find_package(Cholmod)
|
||||
if(CHOLMOD_FOUND)
|
||||
add_definitions("-DEIGEN_CHOLMOD_SUPPORT")
|
||||
include_directories(${CHOLMOD_INCLUDES})
|
||||
set(SPARSE_LIBS ${SPARSE_LIBS} ${CHOLMOD_LIBRARIES})
|
||||
ei_add_property(EIGEN_TESTED_BACKENDS "Cholmod, ")
|
||||
else(CHOLMOD_FOUND)
|
||||
ei_add_property(EIGEN_MISSING_BACKENDS "Cholmod, ")
|
||||
endif(CHOLMOD_FOUND)
|
||||
|
||||
find_package(Umfpack)
|
||||
if(UMFPACK_FOUND)
|
||||
add_definitions("-DEIGEN_UMFPACK_SUPPORT")
|
||||
include_directories(${UMFPACK_INCLUDES})
|
||||
set(SPARSE_LIBS ${SPARSE_LIBS} ${UMFPACK_LIBRARIES})
|
||||
ei_add_property(EIGEN_TESTED_BACKENDS "UmfPack, ")
|
||||
else(UMFPACK_FOUND)
|
||||
ei_add_property(EIGEN_MISSING_BACKENDS "UmfPack, ")
|
||||
endif(UMFPACK_FOUND)
|
||||
|
||||
find_package(SuperLU)
|
||||
if(SUPERLU_FOUND)
|
||||
add_definitions("-DEIGEN_SUPERLU_SUPPORT")
|
||||
include_directories(${SUPERLU_INCLUDES})
|
||||
set(SPARSE_LIBS ${SPARSE_LIBS} ${SUPERLU_LIBRARIES})
|
||||
ei_add_property(EIGEN_TESTED_BACKENDS "SuperLU, ")
|
||||
else(SUPERLU_FOUND)
|
||||
ei_add_property(EIGEN_MISSING_BACKENDS "SuperLU, ")
|
||||
endif(SUPERLU_FOUND)
|
||||
|
||||
find_package(GoogleHash)
|
||||
if(GOOGLEHASH_FOUND)
|
||||
add_definitions("-DEIGEN_GOOGLEHASH_SUPPORT")
|
||||
include_directories(${GOOGLEHASH_INCLUDES})
|
||||
ei_add_property(EIGEN_TESTED_BACKENDS "GoogleHash, ")
|
||||
else(GOOGLEHASH_FOUND)
|
||||
ei_add_property(EIGEN_MISSING_BACKENDS "GoogleHash, ")
|
||||
endif(GOOGLEHASH_FOUND)
|
||||
|
||||
option(EIGEN_TEST_NOQT "Disable Qt support in unit tests" OFF)
|
||||
if(NOT EIGEN_TEST_NOQT)
|
||||
|
||||
@@ -24,40 +24,6 @@
|
||||
|
||||
#include "sparse.h"
|
||||
|
||||
template<typename SetterType,typename DenseType, typename Scalar, int Options>
|
||||
bool test_random_setter(SparseMatrix<Scalar,Options>& sm, const DenseType& ref, const std::vector<Vector2i>& nonzeroCoords)
|
||||
{
|
||||
typedef SparseMatrix<Scalar,Options> SparseType;
|
||||
{
|
||||
sm.setZero();
|
||||
SetterType w(sm);
|
||||
std::vector<Vector2i> remaining = nonzeroCoords;
|
||||
while(!remaining.empty())
|
||||
{
|
||||
int i = ei_random<int>(0,static_cast<int>(remaining.size())-1);
|
||||
w(remaining[i].x(),remaining[i].y()) = ref.coeff(remaining[i].x(),remaining[i].y());
|
||||
remaining[i] = remaining.back();
|
||||
remaining.pop_back();
|
||||
}
|
||||
}
|
||||
return sm.isApprox(ref);
|
||||
}
|
||||
|
||||
template<typename SetterType,typename DenseType, typename T>
|
||||
bool test_random_setter(DynamicSparseMatrix<T>& sm, const DenseType& ref, const std::vector<Vector2i>& nonzeroCoords)
|
||||
{
|
||||
sm.setZero();
|
||||
std::vector<Vector2i> remaining = nonzeroCoords;
|
||||
while(!remaining.empty())
|
||||
{
|
||||
int i = ei_random<int>(0,static_cast<int>(remaining.size())-1);
|
||||
sm.coeffRef(remaining[i].x(),remaining[i].y()) = ref.coeff(remaining[i].x(),remaining[i].y());
|
||||
remaining[i] = remaining.back();
|
||||
remaining.pop_back();
|
||||
}
|
||||
return sm.isApprox(ref);
|
||||
}
|
||||
|
||||
template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& ref)
|
||||
{
|
||||
const int rows = ref.rows();
|
||||
@@ -136,47 +102,6 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
}
|
||||
*/
|
||||
|
||||
// test SparseSetters
|
||||
// coherent setter
|
||||
// TODO extend the MatrixSetter
|
||||
// {
|
||||
// m.setZero();
|
||||
// VERIFY_IS_NOT_APPROX(m, refMat);
|
||||
// SparseSetter<SparseMatrixType, FullyCoherentAccessPattern> w(m);
|
||||
// for (int i=0; i<nonzeroCoords.size(); ++i)
|
||||
// {
|
||||
// w->coeffRef(nonzeroCoords[i].x(),nonzeroCoords[i].y()) = refMat.coeff(nonzeroCoords[i].x(),nonzeroCoords[i].y());
|
||||
// }
|
||||
// }
|
||||
// VERIFY_IS_APPROX(m, refMat);
|
||||
|
||||
// random setter
|
||||
// {
|
||||
// m.setZero();
|
||||
// VERIFY_IS_NOT_APPROX(m, refMat);
|
||||
// SparseSetter<SparseMatrixType, RandomAccessPattern> w(m);
|
||||
// std::vector<Vector2i> remaining = nonzeroCoords;
|
||||
// while(!remaining.empty())
|
||||
// {
|
||||
// int i = ei_random<int>(0,remaining.size()-1);
|
||||
// w->coeffRef(remaining[i].x(),remaining[i].y()) = refMat.coeff(remaining[i].x(),remaining[i].y());
|
||||
// remaining[i] = remaining.back();
|
||||
// remaining.pop_back();
|
||||
// }
|
||||
// }
|
||||
// VERIFY_IS_APPROX(m, refMat);
|
||||
|
||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||
#ifdef EIGEN_UNORDERED_MAP_SUPPORT
|
||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||
#endif
|
||||
#ifdef _DENSE_HASH_MAP_H_
|
||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||
#endif
|
||||
#ifdef _SPARSE_HASH_MAP_H_
|
||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||
#endif
|
||||
|
||||
// test insert (inner random)
|
||||
{
|
||||
DenseMatrix m1(rows,cols);
|
||||
@@ -213,22 +138,6 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
VERIFY_IS_APPROX(m2,m1);
|
||||
}
|
||||
|
||||
// test RandomSetter
|
||||
/*{
|
||||
SparseMatrixType m1(rows,cols), m2(rows,cols);
|
||||
DenseMatrix refM1 = DenseMatrix::Zero(rows, rows);
|
||||
initSparse<Scalar>(density, refM1, m1);
|
||||
{
|
||||
Eigen::RandomSetter<SparseMatrixType > setter(m2);
|
||||
for (int j=0; j<m1.outerSize(); ++j)
|
||||
for (typename SparseMatrixType::InnerIterator i(m1,j); i; ++i)
|
||||
setter(i.index(), j) = i.value();
|
||||
}
|
||||
VERIFY_IS_APPROX(m1, m2);
|
||||
}*/
|
||||
// std::cerr << m.transpose() << "\n\n" << refMat.transpose() << "\n\n";
|
||||
// VERIFY_IS_APPROX(m, refMat);
|
||||
|
||||
// test basic computations
|
||||
{
|
||||
DenseMatrix refM1 = DenseMatrix::Zero(rows, rows);
|
||||
@@ -263,6 +172,17 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
// VERIFY_IS_APPROX(m3.cwise()/refM4, refM3.cwise()/refM4);
|
||||
}
|
||||
|
||||
// test transpose
|
||||
{
|
||||
DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows);
|
||||
SparseMatrixType m2(rows, rows);
|
||||
initSparse<Scalar>(density, refMat2, m2);
|
||||
VERIFY_IS_APPROX(m2.transpose().eval(), refMat2.transpose().eval());
|
||||
VERIFY_IS_APPROX(m2.transpose(), refMat2.transpose());
|
||||
|
||||
VERIFY_IS_APPROX(SparseMatrixType(m2.adjoint()), refMat2.adjoint());
|
||||
}
|
||||
|
||||
// test innerVector()
|
||||
{
|
||||
DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows);
|
||||
@@ -292,17 +212,6 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
//refMat2.block(0,j0,rows,n0) = refMat2.block(0,j0,rows,n0) + refMat2.block(0,j1,rows,n0);
|
||||
}
|
||||
|
||||
// test transpose
|
||||
{
|
||||
DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows);
|
||||
SparseMatrixType m2(rows, rows);
|
||||
initSparse<Scalar>(density, refMat2, m2);
|
||||
VERIFY_IS_APPROX(m2.transpose().eval(), refMat2.transpose().eval());
|
||||
VERIFY_IS_APPROX(m2.transpose(), refMat2.transpose());
|
||||
|
||||
VERIFY_IS_APPROX(SparseMatrixType(m2.adjoint()), refMat2.adjoint());
|
||||
}
|
||||
|
||||
// test prune
|
||||
{
|
||||
SparseMatrixType m2(rows, rows);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2008 Daniel Gomez Ferro <dgomezferro@gmail.com>
|
||||
// Copyright (C) 2008-2010 Gael Guennebaud <g.gael@free.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
@@ -105,139 +105,6 @@ template<typename Scalar> void sparse_solvers(int rows, int cols)
|
||||
VERIFY_IS_APPROX(refMat2.template triangularView<Lower>().solve(vec2),
|
||||
m2.template triangularView<Lower>().solve(vec3));
|
||||
}
|
||||
|
||||
// test LLT
|
||||
{
|
||||
// TODO fix the issue with complex (see SparseLLT::solveInPlace)
|
||||
SparseMatrix<Scalar> m2(rows, cols);
|
||||
DenseMatrix refMat2(rows, cols);
|
||||
|
||||
DenseVector b = DenseVector::Random(cols);
|
||||
DenseVector refX(cols), x(cols);
|
||||
|
||||
initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular, 0, 0);
|
||||
for(int i=0; i<rows; ++i)
|
||||
m2.coeffRef(i,i) = refMat2(i,i) = ei_abs(ei_real(refMat2(i,i)));
|
||||
|
||||
refX = refMat2.template selfadjointView<Lower>().llt().solve(b);
|
||||
if (!NumTraits<Scalar>::IsComplex)
|
||||
{
|
||||
x = b;
|
||||
SparseLLT<SparseMatrix<Scalar> > (m2).solveInPlace(x);
|
||||
VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LLT: default");
|
||||
}
|
||||
#ifdef EIGEN_CHOLMOD_SUPPORT
|
||||
x = b;
|
||||
SparseLLT<SparseMatrix<Scalar> ,Cholmod>(m2).solveInPlace(x);
|
||||
VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LLT: cholmod");
|
||||
#endif
|
||||
|
||||
#ifdef EIGEN_TAUCS_SUPPORT
|
||||
// TODO fix TAUCS with complexes
|
||||
if (!NumTraits<Scalar>::IsComplex)
|
||||
{
|
||||
x = b;
|
||||
// SparseLLT<SparseMatrix<Scalar> ,Taucs>(m2,IncompleteFactorization).solveInPlace(x);
|
||||
// VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LLT: taucs (IncompleteFactorization)");
|
||||
|
||||
x = b;
|
||||
SparseLLT<SparseMatrix<Scalar> ,Taucs>(m2,SupernodalMultifrontal).solveInPlace(x);
|
||||
VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LLT: taucs (SupernodalMultifrontal)");
|
||||
x = b;
|
||||
SparseLLT<SparseMatrix<Scalar> ,Taucs>(m2,SupernodalLeftLooking).solveInPlace(x);
|
||||
VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LLT: taucs (SupernodalLeftLooking)");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// test LDLT
|
||||
{
|
||||
SparseMatrix<Scalar> m2(rows, cols);
|
||||
DenseMatrix refMat2(rows, cols);
|
||||
|
||||
DenseVector b = DenseVector::Random(cols);
|
||||
DenseVector refX(cols), x(cols);
|
||||
|
||||
initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular, 0, 0);
|
||||
for(int i=0; i<rows; ++i)
|
||||
m2.coeffRef(i,i) = refMat2(i,i) = ei_abs(ei_real(refMat2(i,i)));
|
||||
|
||||
refX = refMat2.template selfadjointView<Upper>().ldlt().solve(b);
|
||||
typedef SparseMatrix<Scalar,Upper|SelfAdjoint> SparseSelfAdjointMatrix;
|
||||
x = b;
|
||||
SparseLDLT<SparseSelfAdjointMatrix> ldlt(m2);
|
||||
if (ldlt.succeeded())
|
||||
ldlt.solveInPlace(x);
|
||||
else
|
||||
std::cerr << "warning LDLT failed\n";
|
||||
|
||||
VERIFY_IS_APPROX(refMat2.template selfadjointView<Upper>() * x, b);
|
||||
VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LDLT: default");
|
||||
}
|
||||
|
||||
// test LU
|
||||
{
|
||||
static int count = 0;
|
||||
SparseMatrix<Scalar> m2(rows, cols);
|
||||
DenseMatrix refMat2(rows, cols);
|
||||
|
||||
DenseVector b = DenseVector::Random(cols);
|
||||
DenseVector refX(cols), x(cols);
|
||||
|
||||
initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag, &zeroCoords, &nonzeroCoords);
|
||||
|
||||
FullPivLU<DenseMatrix> refLu(refMat2);
|
||||
refX = refLu.solve(b);
|
||||
#if defined(EIGEN_SUPERLU_SUPPORT) || defined(EIGEN_UMFPACK_SUPPORT)
|
||||
Scalar refDet = refLu.determinant();
|
||||
#endif
|
||||
x.setZero();
|
||||
// // SparseLU<SparseMatrix<Scalar> > (m2).solve(b,&x);
|
||||
// // VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LU: default");
|
||||
#ifdef EIGEN_SUPERLU_SUPPORT
|
||||
{
|
||||
x.setZero();
|
||||
SparseLU<SparseMatrix<Scalar>,SuperLU> slu(m2);
|
||||
if (slu.succeeded())
|
||||
{
|
||||
if (slu.solve(b,&x)) {
|
||||
VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LU: SuperLU");
|
||||
}
|
||||
// std::cerr << refDet << " == " << slu.determinant() << "\n";
|
||||
if (slu.solve(b, &x, SvTranspose)) {
|
||||
VERIFY(b.isApprox(m2.transpose() * x, test_precision<Scalar>()));
|
||||
}
|
||||
|
||||
if (slu.solve(b, &x, SvAdjoint)) {
|
||||
VERIFY(b.isApprox(m2.adjoint() * x, test_precision<Scalar>()));
|
||||
}
|
||||
|
||||
if (count==0) {
|
||||
VERIFY_IS_APPROX(refDet,slu.determinant()); // FIXME det is not very stable for complex
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef EIGEN_UMFPACK_SUPPORT
|
||||
{
|
||||
// check solve
|
||||
x.setZero();
|
||||
SparseLU<SparseMatrix<Scalar>,UmfPack> slu(m2);
|
||||
if (slu.succeeded()) {
|
||||
if (slu.solve(b,&x)) {
|
||||
if (count==0) {
|
||||
VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LU: umfpack"); // FIXME solve is not very stable for complex
|
||||
}
|
||||
}
|
||||
VERIFY_IS_APPROX(refDet,slu.determinant());
|
||||
// TODO check the extracted data
|
||||
//std::cerr << slu.matrixL() << "\n";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
count++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void test_sparse_solvers()
|
||||
|
||||
Reference in New Issue
Block a user