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
@@ -16,7 +16,6 @@
|
||||
#include <bench/BenchTimer.h>
|
||||
#include <unsupported/Eigen/SVD>
|
||||
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
@@ -30,94 +29,83 @@ using namespace std;
|
||||
#define NUMBER_SAMPLE 2
|
||||
#endif
|
||||
|
||||
template<typename MatrixType>
|
||||
void bench_svd(const MatrixType& a = MatrixType())
|
||||
{
|
||||
template <typename MatrixType>
|
||||
void bench_svd(const MatrixType& a = MatrixType()) {
|
||||
MatrixType m = MatrixType::Random(a.rows(), a.cols());
|
||||
BenchTimer timerJacobi;
|
||||
BenchTimer timerBDC;
|
||||
timerJacobi.reset();
|
||||
timerBDC.reset();
|
||||
|
||||
cout << " Only compute Singular Values" <<endl;
|
||||
for (int k=1; k<=NUMBER_SAMPLE; ++k)
|
||||
{
|
||||
cout << " Only compute Singular Values" << endl;
|
||||
for (int k = 1; k <= NUMBER_SAMPLE; ++k) {
|
||||
timerBDC.start();
|
||||
for (int i=0; i<REPEAT; ++i)
|
||||
{
|
||||
for (int i = 0; i < REPEAT; ++i) {
|
||||
BDCSVD<MatrixType> bdc_matrix(m);
|
||||
}
|
||||
timerBDC.stop();
|
||||
|
||||
|
||||
timerJacobi.start();
|
||||
for (int i=0; i<REPEAT; ++i)
|
||||
{
|
||||
for (int i = 0; i < REPEAT; ++i) {
|
||||
JacobiSVD<MatrixType> jacobi_matrix(m);
|
||||
}
|
||||
timerJacobi.stop();
|
||||
|
||||
|
||||
cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s ";
|
||||
cout << " || " << " BDC : " << timerBDC.value() << "s " <<endl <<endl;
|
||||
|
||||
if (timerBDC.value() >= timerJacobi.value())
|
||||
cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
|
||||
else
|
||||
cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
|
||||
|
||||
cout << " || "
|
||||
<< " BDC : " << timerBDC.value() << "s " << endl
|
||||
<< endl;
|
||||
|
||||
if (timerBDC.value() >= timerJacobi.value())
|
||||
cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
|
||||
else
|
||||
cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
|
||||
}
|
||||
cout << " =================" <<endl;
|
||||
std::cout<< std::endl;
|
||||
cout << " =================" << endl;
|
||||
std::cout << std::endl;
|
||||
timerJacobi.reset();
|
||||
timerBDC.reset();
|
||||
cout << " Computes rotation matrix" <<endl;
|
||||
for (int k=1; k<=NUMBER_SAMPLE; ++k)
|
||||
{
|
||||
cout << " Computes rotation matrix" << endl;
|
||||
for (int k = 1; k <= NUMBER_SAMPLE; ++k) {
|
||||
timerBDC.start();
|
||||
for (int i=0; i<REPEAT; ++i)
|
||||
{
|
||||
BDCSVD<MatrixType> bdc_matrix(m, ComputeFullU|ComputeFullV);
|
||||
for (int i = 0; i < REPEAT; ++i) {
|
||||
BDCSVD<MatrixType> bdc_matrix(m, ComputeFullU | ComputeFullV);
|
||||
}
|
||||
timerBDC.stop();
|
||||
|
||||
|
||||
timerJacobi.start();
|
||||
for (int i=0; i<REPEAT; ++i)
|
||||
{
|
||||
JacobiSVD<MatrixType> jacobi_matrix(m, ComputeFullU|ComputeFullV);
|
||||
for (int i = 0; i < REPEAT; ++i) {
|
||||
JacobiSVD<MatrixType> jacobi_matrix(m, ComputeFullU | ComputeFullV);
|
||||
}
|
||||
timerJacobi.stop();
|
||||
|
||||
|
||||
cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s ";
|
||||
cout << " || " << " BDC : " << timerBDC.value() << "s " <<endl <<endl;
|
||||
|
||||
if (timerBDC.value() >= timerJacobi.value())
|
||||
cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
|
||||
else
|
||||
cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
|
||||
|
||||
cout << " || "
|
||||
<< " BDC : " << timerBDC.value() << "s " << endl
|
||||
<< endl;
|
||||
|
||||
if (timerBDC.value() >= timerJacobi.value())
|
||||
cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
|
||||
else
|
||||
cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
|
||||
}
|
||||
std::cout<< std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "On a (Dynamic, Dynamic) (6, 6) Matrix" << std::endl;
|
||||
bench_svd<Matrix<double, Dynamic, Dynamic> >(Matrix<double, Dynamic, Dynamic>(6, 6));
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::cout<< std::endl;
|
||||
std::cout << "On a (Dynamic, Dynamic) (32, 32) Matrix" << std::endl;
|
||||
bench_svd<Matrix<double, Dynamic, Dynamic> >(Matrix<double, Dynamic, Dynamic>(32, 32));
|
||||
|
||||
std::cout<<"On a (Dynamic, Dynamic) (6, 6) Matrix" <<std::endl;
|
||||
bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(6, 6));
|
||||
|
||||
std::cout<<"On a (Dynamic, Dynamic) (32, 32) Matrix" <<std::endl;
|
||||
bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(32, 32));
|
||||
// std::cout<<"On a (Dynamic, Dynamic) (128, 128) Matrix" <<std::endl;
|
||||
// bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(128, 128));
|
||||
|
||||
//std::cout<<"On a (Dynamic, Dynamic) (128, 128) Matrix" <<std::endl;
|
||||
//bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(128, 128));
|
||||
std::cout << "On a (Dynamic, Dynamic) (160, 160) Matrix" << std::endl;
|
||||
bench_svd<Matrix<double, Dynamic, Dynamic> >(Matrix<double, Dynamic, Dynamic>(160, 160));
|
||||
|
||||
std::cout<<"On a (Dynamic, Dynamic) (160, 160) Matrix" <<std::endl;
|
||||
bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(160, 160));
|
||||
|
||||
std::cout<< "--------------------------------------------------------------------"<< std::endl;
|
||||
|
||||
std::cout << "--------------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user