Clang-format tests, examples, libraries, benchmarks, etc.

This commit is contained in:
Antonio Sánchez
2023-12-05 21:22:55 +00:00
committed by Rasmus Munk Larsen
parent 3252ecc7a4
commit 46e9cdb7fe
876 changed files with 33453 additions and 37795 deletions

View File

@@ -3,7 +3,17 @@
#include <iostream>
#include <Eigen/Sparse>
// g++ -DSIZE=10000 -DDENSITY=0.001 sparse_cholesky.cpp -I.. -DDENSEMATRI -O3 -g0 -DNDEBUG -DNBTRIES=1 -I /home/gael/Coding/LinearAlgebra/taucs_full/src/ -I/home/gael/Coding/LinearAlgebra/taucs_full/build/linux/ -L/home/gael/Coding/LinearAlgebra/taucs_full/lib/linux/ -ltaucs /home/gael/Coding/LinearAlgebra/GotoBLAS/libgoto.a -lpthread -I /home/gael/Coding/LinearAlgebra/SuiteSparse/CHOLMOD/Include/ $CHOLLIB -I /home/gael/Coding/LinearAlgebra/SuiteSparse/UFconfig/ /home/gael/Coding/LinearAlgebra/SuiteSparse/CCOLAMD/Lib/libccolamd.a /home/gael/Coding/LinearAlgebra/SuiteSparse/CHOLMOD/Lib/libcholmod.a -lmetis /home/gael/Coding/LinearAlgebra/SuiteSparse/AMD/Lib/libamd.a /home/gael/Coding/LinearAlgebra/SuiteSparse/CAMD/Lib/libcamd.a /home/gael/Coding/LinearAlgebra/SuiteSparse/CCOLAMD/Lib/libccolamd.a /home/gael/Coding/LinearAlgebra/SuiteSparse/COLAMD/Lib/libcolamd.a -llapack && ./a.out
// g++ -DSIZE=10000 -DDENSITY=0.001 sparse_cholesky.cpp -I.. -DDENSEMATRI -O3 -g0 -DNDEBUG -DNBTRIES=1 -I
// /home/gael/Coding/LinearAlgebra/taucs_full/src/ -I/home/gael/Coding/LinearAlgebra/taucs_full/build/linux/
// -L/home/gael/Coding/LinearAlgebra/taucs_full/lib/linux/ -ltaucs /home/gael/Coding/LinearAlgebra/GotoBLAS/libgoto.a
// -lpthread -I /home/gael/Coding/LinearAlgebra/SuiteSparse/CHOLMOD/Include/ $CHOLLIB -I
// /home/gael/Coding/LinearAlgebra/SuiteSparse/UFconfig/
// /home/gael/Coding/LinearAlgebra/SuiteSparse/CCOLAMD/Lib/libccolamd.a
// /home/gael/Coding/LinearAlgebra/SuiteSparse/CHOLMOD/Lib/libcholmod.a -lmetis
// /home/gael/Coding/LinearAlgebra/SuiteSparse/AMD/Lib/libamd.a
// /home/gael/Coding/LinearAlgebra/SuiteSparse/CAMD/Lib/libcamd.a
// /home/gael/Coding/LinearAlgebra/SuiteSparse/CCOLAMD/Lib/libccolamd.a
// /home/gael/Coding/LinearAlgebra/SuiteSparse/COLAMD/Lib/libcolamd.a -llapack && ./a.out
#define NOGMM
#define NOMTL
@@ -30,52 +40,47 @@
#define NBTRIES 10
#endif
#define BENCH(X) \
timer.reset(); \
for (int _j=0; _j<NBTRIES; ++_j) { \
timer.start(); \
for (int _k=0; _k<REPEAT; ++_k) { \
X \
} timer.stop(); }
#define BENCH(X) \
timer.reset(); \
for (int _j = 0; _j < NBTRIES; ++_j) { \
timer.start(); \
for (int _k = 0; _k < REPEAT; ++_k) { \
X \
} \
timer.stop(); \
}
// typedef SparseMatrix<Scalar,UpperTriangular> EigenSparseTriMatrix;
typedef SparseMatrix<Scalar,SelfAdjoint|LowerTriangular> EigenSparseSelfAdjointMatrix;
typedef SparseMatrix<Scalar, SelfAdjoint | LowerTriangular> EigenSparseSelfAdjointMatrix;
void fillSpdMatrix(float density, int rows, int cols, EigenSparseSelfAdjointMatrix& dst)
{
dst.startFill(rows*cols*density);
for(int j = 0; j < cols; j++)
{
dst.fill(j,j) = internal::random<Scalar>(10,20);
for(int i = j+1; i < rows; i++)
{
Scalar v = (internal::random<float>(0,1) < density) ? internal::random<Scalar>() : 0;
if (v!=0)
dst.fill(i,j) = v;
void fillSpdMatrix(float density, int rows, int cols, EigenSparseSelfAdjointMatrix& dst) {
dst.startFill(rows * cols * density);
for (int j = 0; j < cols; j++) {
dst.fill(j, j) = internal::random<Scalar>(10, 20);
for (int i = j + 1; i < rows; i++) {
Scalar v = (internal::random<float>(0, 1) < density) ? internal::random<Scalar>() : 0;
if (v != 0) dst.fill(i, j) = v;
}
}
dst.endFill();
}
#include <Eigen/Cholesky>
template<int Backend>
void doEigen(const char* name, const EigenSparseSelfAdjointMatrix& sm1, int flags = 0)
{
template <int Backend>
void doEigen(const char* name, const EigenSparseSelfAdjointMatrix& sm1, int flags = 0) {
std::cout << name << "..." << std::flush;
BenchTimer timer;
timer.start();
SparseLLT<EigenSparseSelfAdjointMatrix,Backend> chol(sm1, flags);
SparseLLT<EigenSparseSelfAdjointMatrix, Backend> chol(sm1, flags);
timer.stop();
std::cout << ":\t" << timer.value() << endl;
std::cout << " nnz: " << sm1.nonZeros() << " => " << chol.matrixL().nonZeros() << "\n";
// std::cout << "sparse\n" << chol.matrixL() << "%\n";
// std::cout << "sparse\n" << chol.matrixL() << "%\n";
}
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
int rows = SIZE;
int cols = SIZE;
float density = DENSITY;
@@ -86,27 +91,26 @@ int main(int argc, char *argv[])
bool densedone = false;
//for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
// float density = 0.5;
// for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
// float density = 0.5;
{
EigenSparseSelfAdjointMatrix sm1(rows, cols);
std::cout << "Generate sparse matrix (might take a while)...\n";
fillSpdMatrix(density, rows, cols, sm1);
std::cout << "DONE\n\n";
// dense matrices
#ifdef DENSEMATRIX
if (!densedone)
{
// dense matrices
#ifdef DENSEMATRIX
if (!densedone) {
densedone = true;
std::cout << "Eigen Dense\t" << density*100 << "%\n";
DenseMatrix m1(rows,cols);
std::cout << "Eigen Dense\t" << density * 100 << "%\n";
DenseMatrix m1(rows, cols);
eiToDense(sm1, m1);
m1 = (m1 + m1.transpose()).eval();
m1.diagonal() *= 0.5;
// BENCH(LLT<DenseMatrix> chol(m1);)
// std::cout << "dense:\t" << timer.value() << endl;
// BENCH(LLT<DenseMatrix> chol(m1);)
// std::cout << "dense:\t" << timer.value() << endl;
BenchTimer timer;
timer.start();
@@ -114,27 +118,27 @@ int main(int argc, char *argv[])
timer.stop();
std::cout << "dense:\t" << timer.value() << endl;
int count = 0;
for (int j=0; j<cols; ++j)
for (int i=j; i<rows; ++i)
if (!internal::isMuchSmallerThan(internal::abs(chol.matrixL()(i,j)), 0.1))
count++;
std::cout << "dense: " << "nnz = " << count << "\n";
// std::cout << "dense:\n" << m1 << "\n\n" << chol.matrixL() << endl;
for (int j = 0; j < cols; ++j)
for (int i = j; i < rows; ++i)
if (!internal::isMuchSmallerThan(internal::abs(chol.matrixL()(i, j)), 0.1)) count++;
std::cout << "dense: "
<< "nnz = " << count << "\n";
// std::cout << "dense:\n" << m1 << "\n\n" << chol.matrixL() << endl;
}
#endif
#endif
// eigen sparse matrices
doEigen<Eigen::DefaultBackend>("Eigen/Sparse", sm1, Eigen::IncompleteFactorization);
#ifdef EIGEN_CHOLMOD_SUPPORT
#ifdef EIGEN_CHOLMOD_SUPPORT
doEigen<Eigen::Cholmod>("Eigen/Cholmod", sm1, Eigen::IncompleteFactorization);
#endif
#endif
#ifdef EIGEN_TAUCS_SUPPORT
#ifdef EIGEN_TAUCS_SUPPORT
doEigen<Eigen::Taucs>("Eigen/Taucs", sm1, Eigen::IncompleteFactorization);
#endif
#endif
#if 0
#if 0
// TAUCS
{
taucs_ccs_matrix A = sm1.asTaucsMatrix();
@@ -153,7 +157,7 @@ int main(int argc, char *argv[])
}
// CHOLMOD
#ifdef EIGEN_CHOLMOD_SUPPORT
#ifdef EIGEN_CHOLMOD_SUPPORT
{
cholmod_common c;
cholmod_start (&c);
@@ -202,15 +206,10 @@ int main(int argc, char *argv[])
// std::cout << chol->values.s[i] << " ";
// }
}
#endif
#endif
#endif
#endif
}
return 0;
}