27 #define EIGEN_GOOGLEHASH_SUPPORT 28 #include <google/sparse_hash_map> 38 for (int _j=0; _j<NBTRIES; ++_j) { \ 40 for (int _k=0; _k<REPEAT; ++_k) { \ 61 int main(
int argc,
char *argv[])
65 bool fullyrand =
true;
74 std::cerr <<
"fill pool" <<
"\n";
78 Vector2i ij(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1));
87 std::cerr <<
"pool ok" <<
"\n";
88 int n = cols*NBPERROW*
KK;
91 for (
int i=0;
i<
n; ++
i)
93 int i = internal::random<int>(0,pool.size());
94 coords.push_back(pool[i]);
95 values.push_back(internal::random<Scalar>());
103 coords.push_back(Vector2i(internal::random<int>(0,rows-1),
j));
104 values.push_back(internal::random<Scalar>());
107 std::cout <<
"nnz = " << coords.size() <<
"\n";
113 BENCH(setrand_eigen_dense(coords,values);)
114 std::cout <<
"Eigen Dense\t" << timer.
value() <<
"\n";
126 std::cout <<
"Eigen dynamic\t" << timer.
value() <<
"\n";
134 std::cout <<
"Eigen sumeq\t" << timer.
value() <<
"\n";
142 std::cout <<
"scipy\t" << timer.
value() <<
"\n";
147 std::cout <<
"Eigen google dense\t" << timer.
value() <<
"\n";
151 std::cout <<
"Eigen google sparse\t" << timer.
value() <<
"\n";
162 std::cout <<
"ublas vecofvec\t" << timer.
value() <<
"\n";
187 std::cout <<
"MTL\t" << timer.
value() <<
"\n";
196 using namespace Eigen;
199 for (
int i=0;
i<coords.size(); ++
i)
201 mat.
insert(coords[
i].
x(), coords[
i].
y()) = vals[
i];
210 using namespace Eigen;
213 for (
int i=0;
i<coords.size(); ++
i)
219 return &mat.
coeffRef(coords[0].
x(), coords[0].
y());
224 using namespace Eigen;
225 int n = coords.size()/
KK;
227 for (
int j=0;
j<
KK; ++
j)
231 for (
int i=
j*n;
i<(
j+1)*n; ++
i)
233 aux.
insert(coords[
i].
x(), coords[
i].
y()) += vals[
i];
238 return &mat.
coeffRef(coords[0].
x(), coords[0].
y());
243 using namespace Eigen;
245 setter.
reserve(coords.size()/10);
246 for (
int i=0;
i<coords.size(); ++
i)
252 return &mat.
coeffRef(coords[0].
x(), coords[0].
y());
257 using namespace Eigen;
261 for (
int i=0;
i<coords.size(); ++
i)
263 setter(coords[
i].
x(), coords[
i].
y()) += vals[
i];
267 return &mat.
coeffRef(coords[0].
x(), coords[0].
y());
273 using namespace Eigen;
277 for (
int i=0;
i<coords.size(); ++
i)
278 setter(coords[
i].
x(), coords[
i].y()) += vals[
i];
281 return &mat.
coeffRef(coords[0].
x(), coords[0].
y());
286 using namespace Eigen;
290 for (
int i=0;
i<coords.size(); ++
i)
291 setter(coords[
i].
x(), coords[
i].y()) += vals[
i];
294 return &mat.
coeffRef(coords[0].
x(), coords[0].
y());
310 std::fill(Bp, Bp + n_row, 0);
312 for (
int n = 0;
n < nnz;
n++){
317 for(
int i = 0, cumsum = 0;
i < n_row;
i++){
325 for(
int n = 0;
n < nnz;
n++){
326 int row = Aij[
n].x();
329 Bj[dest] = Aij[
n].y();
335 for(
int i = 0,
last = 0;
i <= n_row;
i++){
344 template<
class T1,
class T2 >
346 return x.first < y.first;
350 template<
class I,
class T>
356 std::vector< std::pair<I,T> > temp;
358 for(
I i = 0;
i < n_row;
i++){
364 for(
I jj = row_start; jj < row_end; jj++){
365 temp.push_back(std::make_pair(Aj[jj],Ax[jj]));
368 std::sort(temp.begin(),temp.end(),kv_pair_less<I,T>);
370 for(
I jj = row_start,
n = 0; jj < row_end; jj++,
n++){
371 Aj[jj] = temp[
n].first;
372 Ax[jj] = temp[
n].second;
377 template <
class I,
class T>
386 for(
I i = 0;
i < n_row;
i++){
389 while( jj < row_end ){
393 while( jj < row_end && Aj[jj] == j ){
407 using namespace Eigen;
411 coo_tocsr<Scalar>(
SIZE,
SIZE, coords.size(), coords, vals, mat._outerIndexPtr(), mat._innerIndexPtr(), mat._valuePtr());
414 csr_sort_indices(SIZE, mat._outerIndexPtr(), mat._innerIndexPtr(), mat._valuePtr());
416 csr_sum_duplicates(SIZE, SIZE, mat._outerIndexPtr(), mat._innerIndexPtr(), mat._valuePtr());
420 return &mat.
coeffRef(coords[0].
x(), coords[0].
y());
427 using namespace boost;
429 using namespace boost::numeric::ublas;
430 mapped_matrix<Scalar> aux(
SIZE,
SIZE);
431 for (
int i=0;
i<coords.size(); ++
i)
433 aux(coords[
i].
x(), coords[
i].
y()) += vals[
i];
436 compressed_matrix<Scalar>
mat(aux);
466 using namespace boost;
468 using namespace boost::numeric::ublas;
471 generalized_vector_of_vector<Scalar, row_major, ublas::vector<coordinate_vector<Scalar> > > aux(
SIZE,
SIZE);
472 for (
int i=0;
i<coords.size(); ++
i)
474 aux(coords[
i].
x(), coords[
i].
y()) += vals[
i];
477 compressed_matrix<Scalar,row_major>
mat(aux);
EIGEN_DONT_INLINE Scalar * setrand_ublas_compressed(const Coordinates &coords, const Values &vals)
EIGEN_DONT_INLINE Scalar * setrand_eigen_compact(const Coordinates &coords, const Values &vals)
EIGEN_DONT_INLINE Scalar * setinnerrand_eigen(const Coordinates &coords, const Values &vals)
EIGEN_DONT_INLINE Scalar * setrand_ublas_genvec(const Coordinates &coords, const Values &vals)
void coo_tocsr(const int n_row, const int n_col, const int nnz, const Coordinates Aij, const Values Ax, int Bp[], int Bj[], T Bx[])
bool kv_pair_less(const std::pair< T1, T2 > &x, const std::pair< T1, T2 > &y)
EIGEN_DONT_INLINE Scalar * setrand_ublas_mapped(const Coordinates &coords, const Values &vals)
double value(int TIMER=CPU_TIMER) const
Namespace containing all symbols from the Eigen library.
EIGEN_DONT_INLINE Scalar * setrand_eigen_google_dense(const Coordinates &coords, const Values &vals)
EIGEN_DONT_INLINE Scalar * setrand_eigen_google_sparse(const Coordinates &coords, const Values &vals)
void resizeNonZeros(Index size)
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
EIGEN_DONT_INLINE Scalar * setrand_eigen_sumeq(const Coordinates &coords, const Values &vals)
#define EIGEN_DONT_INLINE
EIGEN_DONT_INLINE Scalar * setrand_ublas_coord(const Coordinates &coords, const Values &vals)
EIGEN_DONT_INLINE Scalar * setrand_eigen_gnu_hash(const Coordinates &coords, const Values &vals)
Scalar & insert(Index row, Index col)
EIGEN_DONT_INLINE Scalar * setrand_mtl(const Coordinates &coords, const Values &vals)
A sparse matrix class designed for matrix assembly purpose.
void reserve(Index reserveSize=1000)
int main(int argc, char *argv[])
Scalar & coeffRef(Index row, Index col)
std::vector< float > Values
void csr_sort_indices(const I n_row, const I Ap[], I Aj[], T Ax[])
std::vector< Vector2i > Coordinates
The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access...
EIGEN_DONT_INLINE Scalar * setrand_scipy(const Coordinates &coords, const Values &vals)
Scalar & coeffRef(Index row, Index col)
Scalar & insert(Index row, Index col)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
void csr_sum_duplicates(const I n_row, const I n_col, I Ap[], I Aj[], T Ax[])
EIGEN_DONT_INLINE Scalar * setrand_eigen_dynamic(const Coordinates &coords, const Values &vals)