int main(int argc, char *argv[]) { int rows = SIZE; int cols = SIZE; float density = DENSITY; EigenSparseMatrix sm1(rows,cols), sm3(rows,cols); BenchTimer timer; for (float density = DENSITY; density>=MINDENSITY; density*=0.5) { fillMatrix(density, rows, cols, sm1); // dense matrices #ifdef DENSEMATRIX { DenseMatrix m1(rows,cols), m3(rows,cols); eiToDense(sm1, m1); BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1.transpose();) std::cout << " Eigen dense:\t" << timer.value() << endl; } #endif 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();) std::cout << " Eigen:\t" << timer.value() << endl; }
int main(int argc, char *argv[]) { // bench_sort(); int rows = SIZE; int cols = SIZE; float density = DENSITY; EigenSparseMatrix sm1(rows,cols), sm2(rows,cols), sm3(rows,cols), sm4(rows,cols); BenchTimer timer; for (int nnzPerCol = NNZPERCOL; nnzPerCol>1; nnzPerCol/=1.1) { sm1.setZero(); sm2.setZero(); fillMatrix2(nnzPerCol, rows, cols, sm1); fillMatrix2(nnzPerCol, rows, cols, sm2); // std::cerr << "filling OK\n"; // dense matrices #ifdef DENSEMATRIX { std::cout << "Eigen Dense\t" << nnzPerCol << "%\n"; DenseMatrix m1(rows,cols), m2(rows,cols), m3(rows,cols); eiToDense(sm1, m1); eiToDense(sm2, m2); timer.reset(); timer.start(); for (int k=0; k<REPEAT; ++k) m3 = m1 * m2; timer.stop(); std::cout << " a * b:\t" << timer.value() << endl; timer.reset(); timer.start(); for (int k=0; k<REPEAT; ++k) m3 = m1.transpose() * m2; timer.stop(); std::cout << " a' * b:\t" << timer.value() << endl; timer.reset(); timer.start(); for (int k=0; k<REPEAT; ++k) m3 = m1.transpose() * m2.transpose(); timer.stop(); std::cout << " a' * b':\t" << timer.value() << endl; timer.reset(); timer.start(); for (int k=0; k<REPEAT; ++k) m3 = m1 * m2.transpose(); timer.stop(); std::cout << " a * b':\t" << timer.value() << endl; } #endif // eigen sparse matrices { std::cout << "Eigen sparse\t" << sm1.nonZeros()/(float(sm1.rows())*float(sm1.cols()))*100 << "% * " << sm2.nonZeros()/(float(sm2.rows())*float(sm2.cols()))*100 << "%\n"; BENCH(sm3 = sm1 * sm2; ) std::cout << " a * b:\t" << timer.value() << endl; // BENCH(sm3 = sm1.transpose() * sm2; ) // std::cout << " a' * b:\t" << timer.value() << endl; // // // BENCH(sm3 = sm1.transpose() * sm2.transpose(); ) // std::cout << " a' * b':\t" << timer.value() << endl; // // // BENCH(sm3 = sm1 * sm2.transpose(); ) // std::cout << " a * b' :\t" << timer.value() << endl; // std::cout << "\n"; // // BENCH( sm3._experimentalNewProduct(sm1, sm2); ) // std::cout << " a * b:\t" << timer.value() << endl; // // BENCH(sm3._experimentalNewProduct(sm1.transpose(),sm2); ) // std::cout << " a' * b:\t" << timer.value() << endl; // // // BENCH(sm3._experimentalNewProduct(sm1.transpose(),sm2.transpose()); ) // std::cout << " a' * b':\t" << timer.value() << endl; // // // BENCH(sm3._experimentalNewProduct(sm1, sm2.transpose());) // std::cout << " a * b' :\t" << timer.value() << endl; } // eigen dyn-sparse matrices /*{ DynamicSparseMatrix<Scalar> m1(sm1), m2(sm2), m3(sm3); std::cout << "Eigen dyn-sparse\t" << m1.nonZeros()/(float(m1.rows())*float(m1.cols()))*100 << "% * " << m2.nonZeros()/(float(m2.rows())*float(m2.cols()))*100 << "%\n"; // timer.reset(); // timer.start(); BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1 * m2;) // timer.stop(); std::cout << " a * b:\t" << timer.value() << endl; // std::cout << sm3 << "\n"; timer.reset(); timer.start(); // std::cerr << "transpose...\n"; // EigenSparseMatrix sm4 = sm1.transpose(); // std::cout << sm4.nonZeros() << " == " << sm1.nonZeros() << "\n"; // exit(1); // std::cerr << "transpose OK\n"; // std::cout << sm1 << "\n\n" << sm1.transpose() << "\n\n" << sm4.transpose() << "\n\n"; BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1.transpose() * m2;) // timer.stop(); std::cout << " a' * b:\t" << timer.value() << endl; // timer.reset(); // timer.start(); BENCH( for (int k=0; k<REPEAT; ++k) m3 = m1.transpose() * m2.transpose(); ) // timer.stop(); std::cout << " a' * b':\t" << timer.value() << endl; // timer.reset(); // timer.start(); BENCH( for (int k=0; k<REPEAT; ++k) m3 = m1 * m2.transpose(); ) // timer.stop(); std::cout << " a * b' :\t" << timer.value() << endl; }*/ // CSparse #ifdef CSPARSE { std::cout << "CSparse \t" << nnzPerCol << "%\n"; cs *m1, *m2, *m3; eiToCSparse(sm1, m1); eiToCSparse(sm2, m2); // timer.reset(); // timer.start(); // for (int k=0; k<REPEAT; ++k) BENCH( { m3 = cs_sorted_multiply(m1, m2); if (!m3) { std::cerr << "cs_multiply failed\n"; // break; } // cs_print(m3, 0); cs_spfree(m3); } ); // timer.stop(); std::cout << " a * b:\t" << timer.value() << endl; // BENCH( { m3 = cs_sorted_multiply2(m1, m2); cs_spfree(m3); } ); // std::cout << " a * b:\t" << timer.value() << endl; }
// unsigned char *pHV 计算所得的哈希值 // unsigned char *pSV 要计算其哈希值的输入。 // unsigned short SLen 输入的字节数。 void eccHash(unsigned char *pHV, unsigned char *pSV, unsigned short SLen) { sm3(pSV, SLen, pHV); }