-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix.h
62 lines (52 loc) · 1.3 KB
/
Matrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include <stdio.h>
#include <string>
#define WORDSIZE 8
enum class MatrixFormat {
Unknown,
Dense,
SparseAsDense,
COO,
CSR
};
struct Temp_cooFormat {
int i;
int j;
int p; // permutation
};
class Matrix
{
public:
Matrix(int rows, int columns);
Matrix(std::string Filename);
~Matrix();
//Matrix(int rows, int columns, MatrixFormat format);
double* getDataPtr() { return data; }
int getNrows() { return nrows; }
int getNcols() { return ncols; }
void FillRandom(MatrixFormat format);
void FillConstant(double c);
int AddInSubmatrix(int strow, int stcolumn, int nrows, int ncols, double *indata);
int AddPartialRow(int strow, int stcol, int nvals, double* indata);
int AddVal(int iloc, int jloc, double val);
void Clear();
int ClearRow(int rownum);
int ClearCol(int rownum);
int FreeDenseSpace();
int ConvertDensetoCOO();
void ConvertCooToCrs();
int StoreCOOAsDense(int* row, int* col, double* vals, int nr, int nc, int nz, int base);
double* data;
int* loci;
int* locj;
double* vals;
private:
MatrixFormat MFormat;
size_t m; // rows -- row major
size_t n; // columns
int nrows;
int ncols;
int numnz; // number of non zeros
int ReadMatrix(std::string filename, int* n, double*& mp,
bool allocateNew);
};