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

@@ -1,7 +1,9 @@
//g++ -O3 -g0 -DNDEBUG sparse_transpose.cpp -I.. -I/home/gael/Coding/LinearAlgebra/mtl4/ -DDENSITY=0.005 -DSIZE=10000 && ./a.out
// -DNOGMM -DNOMTL
// -DCSPARSE -I /home/gael/Coding/LinearAlgebra/CSparse/Include/ /home/gael/Coding/LinearAlgebra/CSparse/Lib/libcsparse.a
// g++ -O3 -g0 -DNDEBUG sparse_transpose.cpp -I.. -I/home/gael/Coding/LinearAlgebra/mtl4/ -DDENSITY=0.005 -DSIZE=10000
// && ./a.out
// -DNOGMM -DNOMTL
// -DCSPARSE -I /home/gael/Coding/LinearAlgebra/CSparse/Include/
// /home/gael/Coding/LinearAlgebra/CSparse/Lib/libcsparse.a
#ifndef SIZE
#define SIZE 10000
@@ -25,80 +27,82 @@
#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(); \
}
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
int rows = SIZE;
int cols = SIZE;
float density = DENSITY;
EigenSparseMatrix sm1(rows,cols), sm3(rows,cols);
EigenSparseMatrix sm1(rows, cols), sm3(rows, cols);
BenchTimer timer;
for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
{
for (float density = DENSITY; density >= MINDENSITY; density *= 0.5) {
fillMatrix(density, rows, cols, sm1);
// dense matrices
#ifdef DENSEMATRIX
// dense matrices
#ifdef DENSEMATRIX
{
DenseMatrix m1(rows,cols), m3(rows,cols);
DenseMatrix m1(rows, cols), m3(rows, cols);
eiToDense(sm1, m1);
BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1.transpose();)
BENCH(for (int k = 0; k < REPEAT; ++k) m3 = m1.transpose();)
std::cout << " Eigen dense:\t" << timer.value() << endl;
}
#endif
#endif
std::cout << "Non zeros: " << sm1.nonZeros()/float(sm1.rows()*sm1.cols())*100 << "%\n";
std::cout << "Non zeros: " << sm1.nonZeros() / float(sm1.rows() * sm1.cols()) * 100 << "%\n";
// eigen sparse matrices
{
BENCH(for (int k=0; k<REPEAT; ++k) sm3 = sm1.transpose();)
BENCH(for (int k = 0; k < REPEAT; ++k) sm3 = sm1.transpose();)
std::cout << " Eigen:\t" << timer.value() << endl;
}
// CSparse
#ifdef CSPARSE
// CSparse
#ifdef CSPARSE
{
cs *m1, *m3;
eiToCSparse(sm1, m1);
BENCH(for (int k=0; k<REPEAT; ++k) { m3 = cs_transpose(m1,1); cs_spfree(m3);})
BENCH(for (int k = 0; k < REPEAT; ++k) {
m3 = cs_transpose(m1, 1);
cs_spfree(m3);
})
std::cout << " CSparse:\t" << timer.value() << endl;
}
#endif
#endif
// GMM++
#ifndef NOGMM
// GMM++
#ifndef NOGMM
{
GmmDynSparse gmmT3(rows,cols);
GmmSparse m1(rows,cols), m3(rows,cols);
GmmDynSparse gmmT3(rows, cols);
GmmSparse m1(rows, cols), m3(rows, cols);
eiToGmm(sm1, m1);
BENCH(for (int k=0; k<REPEAT; ++k) gmm::copy(gmm::transposed(m1),m3);)
BENCH(for (int k = 0; k < REPEAT; ++k) gmm::copy(gmm::transposed(m1), m3);)
std::cout << " GMM:\t\t" << timer.value() << endl;
}
#endif
#endif
// MTL4
#ifndef NOMTL
// MTL4
#ifndef NOMTL
{
MtlSparse m1(rows,cols), m3(rows,cols);
MtlSparse m1(rows, cols), m3(rows, cols);
eiToMtl(sm1, m1);
BENCH(for (int k=0; k<REPEAT; ++k) m3 = trans(m1);)
BENCH(for (int k = 0; k < REPEAT; ++k) m3 = trans(m1);)
std::cout << " MTL4:\t\t" << timer.value() << endl;
}
#endif
#endif
std::cout << "\n\n";
}
return 0;
}