sparse module:

- remove some useless stuff => let's focus on a single sparse matrix format
 - finalize the new RandomSetter
This commit is contained in:
Gael Guennebaud
2008-10-21 13:35:04 +00:00
parent 9e02e42ff6
commit cf0f82ecbe
12 changed files with 316 additions and 84 deletions

View File

@@ -13,14 +13,17 @@ if(TAUCS_FOUND)
add_definitions("-DEIGEN_TAUCS_SUPPORT")
include_directories(${TAUCS_INCLUDES})
set(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${TAUCS_LIBRARIES})
else(TAUCS_FOUND)
message("TAUCS not found, this optional backend won't be tested")
endif(TAUCS_FOUND)
find_package(Cholmod)
if(CHOLMOD_FOUND)
message("add EIGEN_CHOLMOD_SUPPORT " ${CHOLMOD_LIBRARIES})
add_definitions("-DEIGEN_CHOLMOD_SUPPORT")
include_directories(${CHOLMOD_INCLUDES})
set(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${CHOLMOD_LIBRARIES})
else(CHOLMOD_FOUND)
message("CHOLMOD not found, this optional backend won't be tested")
endif(CHOLMOD_FOUND)
find_package(Umfpack)
@@ -28,6 +31,8 @@ if(UMFPACK_FOUND)
add_definitions("-DEIGEN_UMFPACK_SUPPORT")
include_directories(${UMFPACK_INCLUDES})
set(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${UMFPACK_LIBRARIES})
else(UMFPACK_FOUND)
message("UMFPACK not found, this optional backend won't be tested")
endif(UMFPACK_FOUND)
find_package(SuperLU)
@@ -35,8 +40,18 @@ if(SUPERLU_FOUND)
add_definitions("-DEIGEN_SUPERLU_SUPPORT")
include_directories(${SUPERLU_INCLUDES})
set(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${SUPERLU_LIBRARIES})
else(SUPERLU_FOUND)
message("SUPERLU not found, this optional backend won't be tested")
endif(SUPERLU_FOUND)
find_package(GoogleHash)
if(GOOGLEHASH_FOUND)
add_definitions("-DEIGEN_GOOGLEHASH_SUPPORT")
include_directories(${GOOGLEHASH_INCLUDES})
else(GOOGLEHASH_FOUND)
message("Google's hash library not found, those map implementations won't be tested")
endif(GOOGLEHASH_FOUND)
if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_SYSTEM_NAME MATCHES Linux)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g2")
@@ -152,6 +167,6 @@ ei_add_test(geometry)
ei_add_test(hyperplane)
ei_add_test(parametrizedline)
ei_add_test(regression)
ei_add_test(sparse ${EI_OFLAG})
ei_add_test(sparse )
endif(BUILD_TESTS)

View File

@@ -22,6 +22,14 @@
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.
#ifdef __GNUC__
#include <ext/hash_map>
#endif
#ifdef EIGEN_GOOGLEHASH_SUPPORT
#include <google/sparse_hash_map>
#endif
#include "main.h"
#include <Eigen/Cholesky>
#include <Eigen/LU>
@@ -72,6 +80,24 @@ initSparse(double density,
sparseMat.endFill();
}
template<typename SetterType,typename DenseType, typename SparseType>
bool test_random_setter(SparseType& sm, const DenseType& ref, const std::vector<Vector2i>& nonzeroCoords)
{
{
sm.setZero();
SetterType w(sm);
std::vector<Vector2i> remaining = nonzeroCoords;
while(!remaining.empty())
{
int i = ei_random<int>(0,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 Scalar> void sparse(int rows, int cols)
{
double density = std::max(8./(rows*cols), 0.01);
@@ -157,20 +183,48 @@ template<typename Scalar> void sparse(int rows, int cols)
// VERIFY_IS_APPROX(m, refMat);
// random setter
{
m.setZero();
VERIFY_IS_NOT_APPROX(m, refMat);
SparseSetter<SparseMatrix<Scalar>, 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);
// {
// m.setZero();
// VERIFY_IS_NOT_APPROX(m, refMat);
// SparseSetter<SparseMatrix<Scalar>, 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<SparseMatrix<Scalar>, StdMapTraits> >(m,refMat,nonzeroCoords) ));
#ifdef _HASH_MAP
VERIFY(( test_random_setter<RandomSetter<SparseMatrix<Scalar>, GnuHashMapTraits> >(m,refMat,nonzeroCoords) ));
#endif
#ifdef _DENSE_HASH_MAP_H_
VERIFY(( test_random_setter<RandomSetter<SparseMatrix<Scalar>, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) ));
#endif
#ifdef _SPARSE_HASH_MAP_H_
VERIFY(( test_random_setter<RandomSetter<SparseMatrix<Scalar>, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) ));
#endif
// {
// m.setZero();
// VERIFY_IS_NOT_APPROX(m, refMat);
// // RandomSetter<SparseMatrix<Scalar> > w(m);
// RandomSetter<SparseMatrix<Scalar>, GoogleDenseHashMapTraits > w(m);
// // RandomSetter<SparseMatrix<Scalar>, GnuHashMapTraits > w(m);
// std::vector<Vector2i> remaining = nonzeroCoords;
// while(!remaining.empty())
// {
// int i = ei_random<int>(0,remaining.size()-1);
// w(remaining[i].x(),remaining[i].y()) = refMat.coeff(remaining[i].x(),remaining[i].y());
// remaining[i] = remaining.back();
// remaining.pop_back();
// }
// }
// std::cerr << m.transpose() << "\n\n" << refMat.transpose() << "\n\n";
// VERIFY_IS_APPROX(m, refMat);
// test transpose
{
@@ -180,7 +234,7 @@ template<typename Scalar> void sparse(int rows, int cols)
VERIFY_IS_APPROX(m2.transpose().eval(), refMat2.transpose().eval());
VERIFY_IS_APPROX(m2.transpose(), refMat2.transpose());
}
#if 0
// test matrix product
{
DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows);
@@ -306,7 +360,7 @@ template<typename Scalar> void sparse(int rows, int cols)
#endif
count++;
}
#endif
}
void test_sparse()