extend the sparse matrix assembly benchmark

This commit is contained in:
Gael Guennebaud
2009-10-07 14:25:53 +02:00
parent af31345df3
commit 8f3e33581e
2 changed files with 260 additions and 72 deletions

View File

@@ -27,23 +27,23 @@ typedef SparseMatrix<Scalar> EigenSparseMatrix;
void fillMatrix(float density, int rows, int cols, EigenSparseMatrix& dst)
{
dst.startFill(rows*cols*density);
dst.reserve(rows*cols*density);
for(int j = 0; j < cols; j++)
{
for(int i = 0; i < rows; i++)
{
Scalar v = (ei_random<float>(0,1) < density) ? ei_random<Scalar>() : 0;
if (v!=0)
dst.fillrand(i,j) = v;
dst.insert(i,j) = v;
}
}
dst.endFill();
dst.finalize();
}
void fillMatrix2(int nnzPerCol, int rows, int cols, EigenSparseMatrix& dst)
{
std::cout << "alloc " << nnzPerCol*cols << "\n";
dst.startFill(nnzPerCol*cols);
dst.reserve(nnzPerCol*cols);
for(int j = 0; j < cols; j++)
{
std::set<int> aux;
@@ -54,10 +54,10 @@ void fillMatrix2(int nnzPerCol, int rows, int cols, EigenSparseMatrix& dst)
k = ei_random<int>(0,rows-1);
aux.insert(k);
dst.fillrand(k,j) = ei_random<Scalar>();
dst.insert(k,j) = ei_random<Scalar>();
}
}
dst.endFill();
dst.finalize();
}
void eiToDense(const EigenSparseMatrix& src, DenseMatrix& dst)