Tapkee
sparse.hpp
Go to the documentation of this file.
00001 /* This software is distributed under BSD 3-clause license (see LICENSE file).
00002  *
00003  * Copyright (c) 2012-2013 Vladyslav Gorbatiuk
00004  */
00005 
00006 #ifndef TAPKEE_SPARSE_H_
00007 #define TAPKEE_SPARSE_H_
00008 
00009 /* Tapkee includes */
00010 #include <tapkee/defines.hpp>
00011  /* End of Tapkee includes */
00012 
00013 namespace tapkee 
00014 {
00015 namespace tapkee_internal
00016 {
00017 
00018 SparseMatrix sparse_matrix_from_triplets(const SparseTriplets& sparse_triplets, IndexType m, IndexType n)
00019 {
00020 #ifdef EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
00021     Eigen::DynamicSparseMatrix<ScalarType> dynamic_weight_matrix(m, n);
00022     dynamic_weight_matrix.reserve(sparse_triplets.size());
00023     for (SparseTriplets::const_iterator it=sparse_triplets.begin(); it!=sparse_triplets.end(); ++it)
00024         dynamic_weight_matrix.coeffRef(it->col(),it->row()) += it->value();
00025     SparseMatrix matrix(dynamic_weight_matrix);
00026 #else
00027     SparseMatrix matrix(m, n);
00028     matrix.setFromTriplets(sparse_triplets.begin(),sparse_triplets.end());
00029 #endif
00030     return matrix;
00031 }
00032 
00033 }
00034 }
00035 
00036 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines