6 #ifndef TURI_UTIL_SPMAT_H_ 7 #define TURI_UTIL_SPMAT_H_ 11 #include <core/random/alias.hpp> 29 m = std::vector<std::map<size_t, size_t>>(
num_rows);
35 const std::map<size_t, size_t>&
get_row(
size_t i) {
42 size_t get(
const size_t i,
const size_t j) {
43 if (m[i].count(j) == 0) {
58 void trim(
const size_t i) {
59 auto it = m[i].begin();
60 for( ; it != m[i].end();) {
61 if (it->second == 0) {
72 void increment(
const size_t& a,
const size_t& b,
const size_t& v) {
73 auto it = m[a].find(b);
74 if (it == m[a].end()) {
85 size_t nrows = m.size();
87 for (
size_t i = 0; i < nrows; ++i) {
89 for (
auto it = row.begin(); it != row.end(); ++it) {
91 if (col >= ncols) ncols = col+1;
94 auto ret = Eigen::MatrixXi(nrows, ncols);
95 for (
size_t i = 0; i < nrows; ++i) {
97 for (
auto it = row.begin(); it != row.end(); ++it) {
100 ret(i, j) =
static_cast<int>(v);
107 std::vector<std::map<size_t, size_t>> m;
void trim(const size_t i)
const std::map< size_t, size_t > & get_row(size_t i)
Eigen::MatrixXi as_matrix()
void increment(const size_t &a, const size_t &b, const size_t &v)