Tapkee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sparse.hpp
Go to the documentation of this file.
1 /* This software is distributed under BSD 3-clause license (see LICENSE file).
2  *
3  * Copyright (c) 2012-2013 Vladyslav Gorbatiuk
4  */
5 
6 #ifndef TAPKEE_SPARSE_H_
7 #define TAPKEE_SPARSE_H_
8 
9 /* Tapkee includes */
10 #include <tapkee/defines.hpp>
11  /* End of Tapkee includes */
12 
13 namespace tapkee
14 {
15 namespace tapkee_internal
16 {
17 
19 {
20 #ifdef EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
21  Eigen::DynamicSparseMatrix<ScalarType> dynamic_weight_matrix(m, n);
22  dynamic_weight_matrix.reserve(sparse_triplets.size());
23  for (SparseTriplets::const_iterator it=sparse_triplets.begin(); it!=sparse_triplets.end(); ++it)
24  dynamic_weight_matrix.coeffRef(it->col(),it->row()) += it->value();
25  SparseMatrix matrix(dynamic_weight_matrix);
26 #else
27  SparseMatrix matrix(m, n);
28  matrix.setFromTriplets(sparse_triplets.begin(),sparse_triplets.end());
29 #endif
30  return matrix;
31 }
32 
33 }
34 }
35 
36 #endif
TAPKEE_INTERNAL_VECTOR< tapkee::tapkee_internal::SparseTriplet > SparseTriplets
Definition: synonyms.hpp:38
SparseMatrix sparse_matrix_from_triplets(const SparseTriplets &sparse_triplets, IndexType m, IndexType n)
Definition: sparse.hpp:18
int IndexType
indexing type (non-overridable) set to int for compatibility with OpenMP 2.0
Definition: types.hpp:19
Eigen::SparseMatrix< tapkee::ScalarType > SparseMatrix
sparse matrix type (non-overridable)
Definition: types.hpp:31