mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -19,17 +19,16 @@
|
||||
|
||||
#include <Eigen/SparseExtra>
|
||||
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
{
|
||||
sm.setZero();
|
||||
SetterType w(sm);
|
||||
std::vector<Vector2i> remaining = nonzeroCoords;
|
||||
while(!remaining.empty())
|
||||
{
|
||||
int i = internal::random<int>(0,static_cast<int>(remaining.size())-1);
|
||||
w(remaining[i].x(),remaining[i].y()) = ref.coeff(remaining[i].x(),remaining[i].y());
|
||||
while (!remaining.empty()) {
|
||||
int i = internal::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();
|
||||
}
|
||||
@@ -37,16 +36,16 @@ bool test_random_setter(SparseMatrix<Scalar,Options>& sm, const DenseType& ref,
|
||||
return sm.isApprox(ref);
|
||||
}
|
||||
|
||||
template<typename SparseMatrixType> void sparse_extra(const SparseMatrixType& ref)
|
||||
{
|
||||
template <typename SparseMatrixType>
|
||||
void sparse_extra(const SparseMatrixType& ref) {
|
||||
const Index rows = ref.rows();
|
||||
const Index cols = ref.cols();
|
||||
typedef typename SparseMatrixType::Scalar Scalar;
|
||||
enum { Flags = SparseMatrixType::Flags };
|
||||
|
||||
double density = (std::max)(8./(rows*cols), 0.01);
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
|
||||
typedef Matrix<Scalar,Dynamic,1> DenseVector;
|
||||
double density = (std::max)(8. / (rows * cols), 0.01);
|
||||
typedef Matrix<Scalar, Dynamic, Dynamic> DenseMatrix;
|
||||
typedef Matrix<Scalar, Dynamic, 1> DenseVector;
|
||||
Scalar eps = 1e-6;
|
||||
|
||||
SparseMatrixType m(rows, cols);
|
||||
@@ -57,15 +56,13 @@ template<typename SparseMatrixType> void sparse_extra(const SparseMatrixType& re
|
||||
std::vector<Vector2i> nonzeroCoords;
|
||||
initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords);
|
||||
|
||||
if (zeroCoords.size()==0 || nonzeroCoords.size()==0)
|
||||
return;
|
||||
if (zeroCoords.size() == 0 || nonzeroCoords.size() == 0) return;
|
||||
|
||||
// test coeff and coeffRef
|
||||
for (int i=0; i<(int)zeroCoords.size(); ++i)
|
||||
{
|
||||
VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(zeroCoords[i].x(),zeroCoords[i].y()), eps );
|
||||
if(internal::is_same<SparseMatrixType,SparseMatrix<Scalar,Flags> >::value)
|
||||
VERIFY_RAISES_ASSERT( m.coeffRef(zeroCoords[0].x(),zeroCoords[0].y()) = 5 );
|
||||
for (int i = 0; i < (int)zeroCoords.size(); ++i) {
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(m.coeff(zeroCoords[i].x(), zeroCoords[i].y()), eps);
|
||||
if (internal::is_same<SparseMatrixType, SparseMatrix<Scalar, Flags> >::value)
|
||||
VERIFY_RAISES_ASSERT(m.coeffRef(zeroCoords[0].x(), zeroCoords[0].y()) = 5);
|
||||
}
|
||||
VERIFY_IS_APPROX(m, refMat);
|
||||
|
||||
@@ -75,28 +72,27 @@ template<typename SparseMatrixType> void sparse_extra(const SparseMatrixType& re
|
||||
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 = internal::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) ));
|
||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||
#ifdef EIGEN_GOOGLEHASH_SUPPORT
|
||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||
#endif
|
||||
// {
|
||||
// m.setZero();
|
||||
// VERIFY_IS_NOT_APPROX(m, refMat);
|
||||
// SparseSetter<SparseMatrixType, RandomAccessPattern> w(m);
|
||||
// std::vector<Vector2i> remaining = nonzeroCoords;
|
||||
// while(!remaining.empty())
|
||||
// {
|
||||
// int i = internal::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)));
|
||||
VERIFY((test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m, refMat, nonzeroCoords)));
|
||||
#ifdef EIGEN_GOOGLEHASH_SUPPORT
|
||||
VERIFY((test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m, refMat, nonzeroCoords)));
|
||||
VERIFY((test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m, refMat, nonzeroCoords)));
|
||||
#endif
|
||||
|
||||
// test RandomSetter
|
||||
/*{
|
||||
@@ -111,63 +107,57 @@ template<typename SparseMatrixType> void sparse_extra(const SparseMatrixType& re
|
||||
}
|
||||
VERIFY_IS_APPROX(m1, m2);
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<typename SparseMatrixType>
|
||||
void check_marketio()
|
||||
{
|
||||
template <typename SparseMatrixType>
|
||||
void check_marketio() {
|
||||
typedef Matrix<typename SparseMatrixType::Scalar, Dynamic, Dynamic> DenseMatrix;
|
||||
Index rows = internal::random<Index>(1,100);
|
||||
Index cols = internal::random<Index>(1,100);
|
||||
Index rows = internal::random<Index>(1, 100);
|
||||
Index cols = internal::random<Index>(1, 100);
|
||||
SparseMatrixType m1, m2;
|
||||
m1 = DenseMatrix::Random(rows, cols).sparseView();
|
||||
saveMarket(m1, "sparse_extra.mtx");
|
||||
loadMarket(m2, "sparse_extra.mtx");
|
||||
VERIFY_IS_EQUAL(DenseMatrix(m1),DenseMatrix(m2));
|
||||
VERIFY_IS_EQUAL(DenseMatrix(m1), DenseMatrix(m2));
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void check_marketio_vector()
|
||||
{
|
||||
Index size = internal::random<Index>(1,100);
|
||||
template <typename VectorType>
|
||||
void check_marketio_vector() {
|
||||
Index size = internal::random<Index>(1, 100);
|
||||
VectorType v1, v2;
|
||||
v1 = VectorType::Random(size);
|
||||
saveMarketVector(v1, "vector_extra.mtx");
|
||||
loadMarketVector(v2, "vector_extra.mtx");
|
||||
VERIFY_IS_EQUAL(v1,v2);
|
||||
VERIFY_IS_EQUAL(v1, v2);
|
||||
}
|
||||
|
||||
template<typename DenseMatrixType>
|
||||
void check_marketio_dense()
|
||||
{
|
||||
Index rows=DenseMatrixType::MaxRowsAtCompileTime;
|
||||
if (DenseMatrixType::MaxRowsAtCompileTime==Dynamic){
|
||||
rows=internal::random<Index>(1,100);
|
||||
}else if(DenseMatrixType::RowsAtCompileTime==Dynamic){
|
||||
rows=internal::random<Index>(1,DenseMatrixType::MaxRowsAtCompileTime);
|
||||
template <typename DenseMatrixType>
|
||||
void check_marketio_dense() {
|
||||
Index rows = DenseMatrixType::MaxRowsAtCompileTime;
|
||||
if (DenseMatrixType::MaxRowsAtCompileTime == Dynamic) {
|
||||
rows = internal::random<Index>(1, 100);
|
||||
} else if (DenseMatrixType::RowsAtCompileTime == Dynamic) {
|
||||
rows = internal::random<Index>(1, DenseMatrixType::MaxRowsAtCompileTime);
|
||||
}
|
||||
|
||||
Index cols =DenseMatrixType::MaxColsAtCompileTime;
|
||||
if (DenseMatrixType::MaxColsAtCompileTime==Dynamic){
|
||||
cols=internal::random<Index>(1,100);
|
||||
}else if(DenseMatrixType::ColsAtCompileTime==Dynamic){
|
||||
cols=internal::random<Index>(1,DenseMatrixType::MaxColsAtCompileTime);
|
||||
Index cols = DenseMatrixType::MaxColsAtCompileTime;
|
||||
if (DenseMatrixType::MaxColsAtCompileTime == Dynamic) {
|
||||
cols = internal::random<Index>(1, 100);
|
||||
} else if (DenseMatrixType::ColsAtCompileTime == Dynamic) {
|
||||
cols = internal::random<Index>(1, DenseMatrixType::MaxColsAtCompileTime);
|
||||
}
|
||||
|
||||
DenseMatrixType m1, m2;
|
||||
m1= DenseMatrixType::Random(rows,cols);
|
||||
m1 = DenseMatrixType::Random(rows, cols);
|
||||
saveMarketDense(m1, "dense_extra.mtx");
|
||||
loadMarketDense(m2, "dense_extra.mtx");
|
||||
VERIFY_IS_EQUAL(m1,m2);
|
||||
VERIFY_IS_EQUAL(m1, m2);
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
void check_sparse_inverse() {
|
||||
typedef SparseMatrix<Scalar> MatrixType;
|
||||
|
||||
|
||||
Matrix<Scalar, -1, -1> A;
|
||||
A.resize(1000, 1000);
|
||||
A.fill(0);
|
||||
@@ -206,41 +196,40 @@ void check_sparse_inverse() {
|
||||
VERIFY_IS_APPROX_OR_LESS_THAN(sumdiff, 1e-10);
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(sparse_extra)
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
int s = Eigen::internal::random<int>(1,50);
|
||||
CALL_SUBTEST_1( sparse_extra(SparseMatrix<double>(8, 8)) );
|
||||
CALL_SUBTEST_2( sparse_extra(SparseMatrix<std::complex<double> >(s, s)) );
|
||||
CALL_SUBTEST_1( sparse_extra(SparseMatrix<double>(s, s)) );
|
||||
EIGEN_DECLARE_TEST(sparse_extra) {
|
||||
for (int i = 0; i < g_repeat; i++) {
|
||||
int s = Eigen::internal::random<int>(1, 50);
|
||||
CALL_SUBTEST_1(sparse_extra(SparseMatrix<double>(8, 8)));
|
||||
CALL_SUBTEST_2(sparse_extra(SparseMatrix<std::complex<double> >(s, s)));
|
||||
CALL_SUBTEST_1(sparse_extra(SparseMatrix<double>(s, s)));
|
||||
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<float,ColMajor,int> >()) );
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<double,ColMajor,int> >()) );
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<std::complex<float>,ColMajor,int> >()) );
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<std::complex<double>,ColMajor,int> >()) );
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<float,ColMajor,long int> >()) );
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<double,ColMajor,long int> >()) );
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<std::complex<float>,ColMajor,long int> >()) );
|
||||
CALL_SUBTEST_3( (check_marketio<SparseMatrix<std::complex<double>,ColMajor,long int> >()) );
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<float, ColMajor, int> >()));
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<double, ColMajor, int> >()));
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<float>, ColMajor, int> >()));
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<double>, ColMajor, int> >()));
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<float, ColMajor, long int> >()));
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<double, ColMajor, long int> >()));
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<float>, ColMajor, long int> >()));
|
||||
CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<double>, ColMajor, long int> >()));
|
||||
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<float,Dynamic,Dynamic> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<float,Dynamic,Dynamic,RowMajor> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<double,Dynamic,Dynamic> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<std::complex<float>,Dynamic,Dynamic> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<std::complex<double>,Dynamic,Dynamic> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<float,Dynamic,3> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<double,3,Dynamic> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<double,3,4> >()) );
|
||||
CALL_SUBTEST_4( (check_marketio_dense<Matrix<double,Dynamic,Dynamic,ColMajor,5,5> >()) );
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<float, Dynamic, Dynamic> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<float, Dynamic, Dynamic, RowMajor> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<double, Dynamic, Dynamic> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<std::complex<float>, Dynamic, Dynamic> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<std::complex<double>, Dynamic, Dynamic> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<float, Dynamic, 3> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<double, 3, Dynamic> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<double, 3, 4> >()));
|
||||
CALL_SUBTEST_4((check_marketio_dense<Matrix<double, Dynamic, Dynamic, ColMajor, 5, 5> >()));
|
||||
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<float,1,Dynamic> >()) );
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<double,1,Dynamic> >()) );
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<std::complex<float>,1,Dynamic> >()) );
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<std::complex<double>,1,Dynamic> >()) );
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<float,Dynamic,1> >()) );
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<double,Dynamic,1> >()) );
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<std::complex<float>,Dynamic,1> >()) );
|
||||
CALL_SUBTEST_5( (check_marketio_vector<Matrix<std::complex<double>,Dynamic,1> >()) );
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<float, 1, Dynamic> >()));
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<double, 1, Dynamic> >()));
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<float>, 1, Dynamic> >()));
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<double>, 1, Dynamic> >()));
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<float, Dynamic, 1> >()));
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<double, Dynamic, 1> >()));
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<float>, Dynamic, 1> >()));
|
||||
CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<double>, Dynamic, 1> >()));
|
||||
|
||||
CALL_SUBTEST_6((check_sparse_inverse<double>()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user