17 using namespace Eigen;
26 "EigenSparseUtil::toEigenSparse(): \
27 Number of rows must be positive!\n");
29 "EigenSparseUtil::toEigenSparse(): \
30 Number of cols must be positive!\n");
32 "EigenSparseUtil::toEigenSparse(): \
33 sg_matrix is not initialized!\n");
38 typedef Eigen::Triplet<T> SparseTriplet;
40 std::vector<SparseTriplet> tripletList;
41 for (
index_t i=0; i<num_rows; ++i)
43 for (
index_t k=0; k<sg_matrix[i].num_feat_entries; ++k)
46 index_t &index_j=sg_matrix[i].features[k].feat_index;
47 T &val=sg_matrix[i].features[k].entry;
48 tripletList.push_back(SparseTriplet(index_i, index_j, val));
52 #ifdef EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
53 DynamicSparseMatrix<T> dM(num_rows, num_cols);
54 dM.reserve(tripletList.size());
56 for (
typename std::vector<SparseTriplet>::iterator it=tripletList.begin();
57 it!=tripletList.end(); ++it )
58 dM.coeffRef(it->row(), it->col())+=it->value();
60 SparseMatrix<T> M(dM);
61 #else // EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
62 SparseMatrix<T> M(num_rows, num_cols);
63 M.setFromTriplets(tripletList.begin(), tripletList.end());
64 #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