Medial Code Documentation
Loading...
Searching...
No Matches
MedSparseMat.h
1#pragma once
2
3//
4// A small lib to handle sparse matrices
5// Mainly as input and use for embedding algorithms
6//
7
9
11 int pid;
12 int time;
13 ADD_CLASS_NAME(SparseMatRowMetaData)
15};
16
17// MedSparseMat is not templated ... currently float only
18// Assuming the sparsness is on the cols dimension
20
21public:
22 int n_rows = 0;
23 int n_cols = 0;
24
25 // actual data
26 vector<vector<pair<int, float>>> lines;
27
28 // line meta data
29 vector<SparseMatRowMetaData> meta;
30
31 // dictionary for categories values
32 map<int, string> dict;
33
34 void clear() { lines.clear(); meta.clear(); dict.clear(); n_rows=0; n_cols=0; }
35
36 void init(int _n_rows, int _n_cols) { n_rows = _n_rows; n_cols = _n_cols; lines.resize(n_rows); }
37
38 // line_num < 0 is a signal to add as the next available line
39 void insert_line(SparseMatRowMetaData &_meta, int line_num, vector<pair<int, float>> &line);
40 void insert_line(SparseMatRowMetaData &_meta, map<int, float> &line);
41 void insert_line(SparseMatRowMetaData &_meta, map<int, int> &line);
42
43 static void convert_map_to_line(map<int, float> &_map, vector<pair<int, float>> &line);
44 static void convert_map_to_line(map<int, int> &_map, vector<pair<int, float>> &line);
45
46
47 void get_col_stat(int &nrows, int &ncols, vector<int> &nonz_counts);
48 int write_col_stat_file(string f_stat);
49
50 void insert_dict_item(int _val, string &_name) { dict[_val] = _name; }
51
52 int write_to_files(string mat_file, string meta_file, string dict_file);
53
54 int read_from_files(string mat_file, string meta_file);
55
56 // the following writes only the mat to a bin file with len at the start and then 3 arrays of length len for row , col and val.
57 // this allows for an easier and faster transfer to python.
58 int write_to_bin_file(string bin_file);
59
60 ADD_CLASS_NAME(MedSparseMat)
61 ADD_SERIALIZATION_FUNCS(n_rows, n_cols, lines, meta, dict)
62};
63
An Abstract class that can be serialized and written/read from file.
#define ADD_SERIALIZATION_FUNCS(...)
Definition SerializableObject.h:122
#define MEDSERIALIZE_SUPPORT(Type)
Definition SerializableObject.h:108
Definition MedSparseMat.h:19
Definition SerializableObject.h:32
Definition MedSparseMat.h:10