16 using namespace Eigen;
25 "EigenSparseUtil::toEigenSparse(): \
26 Number of rows must be positive!\n");
28 "EigenSparseUtil::toEigenSparse(): \
29 Number of cols must be positive!\n");
31 "EigenSparseUtil::toEigenSparse(): \
32 sg_matrix is not initialized!\n");
37 typedef Eigen::Triplet<T> SparseTriplet;
39 std::vector<SparseTriplet> tripletList;
40 for (
index_t i=0; i<num_rows; ++i)
42 for (
index_t k=0; k<sg_matrix[i].num_feat_entries; ++k)
45 index_t &index_j=sg_matrix[i].features[k].feat_index;
46 T &val=sg_matrix[i].features[k].entry;
47 tripletList.push_back(SparseTriplet(index_i, index_j, val));
51 #ifdef EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
52 DynamicSparseMatrix<T> dM(num_rows, num_cols);
53 dM.reserve(tripletList.size());
55 for (
typename std::vector<SparseTriplet>::iterator it=tripletList.begin();
56 it!=tripletList.end(); ++it )
57 dM.coeffRef(it->row(), it->col())+=it->value();
59 SparseMatrix<T> M(dM);
60 #else // EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
61 SparseMatrix<T> M(num_rows, num_cols);
62 M.setFromTriplets(tripletList.begin(), tripletList.end());
63 #endif // EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
template class SGSparseMatrix
index_t num_features
total number of features
SGSparseVector< T > * sparse_matrix
array of sparse vectors of size num_vectors
This class contains some utilities for Eigen3 Sparse Matrix integration with shogun. Currently it provides a method for converting SGSparseMatrix to Eigen3 SparseMatrix.
all of classes and functions are contained in the shogun namespace
index_t num_vectors
total number of vectors