-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymbolicMatrix.h
174 lines (121 loc) · 4.44 KB
/
SymbolicMatrix.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#ifndef SYMBOLICMATRIX_H
#define SYMBOLICMATRIX_H
#include "PolynomialFraction.h"
#include "PolynomialIdeal.h"
class SymbolicMatrix
{
private:
vector<vector <PolynomialFraction> > A;
public:
SymbolicMatrix();
SymbolicMatrix(string s, int numberOfCols, int numberOfRows, bool mode){
setDims(numberOfCols,numberOfRows);
fillSymbolicMatrix(s, mode);
}
void setDims(unsigned int cols, unsigned int rows);
//Begin getters
unsigned int getNumberOfCols() const {
return A.size();
}
unsigned int getNumberOfRows() const {
if(A.size()>0)
return A[0].size();
else return 0;
}
SymbolicMatrix getRow(int rowNumber){
SymbolicMatrix res;
if(rowNumber<getNumberOfRows()){
res.setDims(getNumberOfCols(),1);
for(int i=0;i<getNumberOfCols();i++){
res.setEntry(rowNumber,i,A[rowNumber][i]);
}
}
return res;
}
SymbolicMatrix getCol(int colNumber){
SymbolicMatrix res;
if(colNumber<getNumberOfCols()){
res.setDims(1,getNumberOfRows());
for(int i=0;i<getNumberOfRows();i++){
res.setEntry(i,colNumber,A[i][colNumber]);
}
}
return res;
}
//End getters
void setEntry(unsigned int cols,unsigned int row, const PolynomialFraction &elem);
PolynomialFraction getEntry(unsigned int col,unsigned int row) const{
return A[col][row];
}
SymbolicMatrix operator+(const SymbolicMatrix& a) const;
SymbolicMatrix operator-(const SymbolicMatrix& a) const;
SymbolicMatrix operator*(const SymbolicMatrix& a) const;
void operator*=(const SymbolicMatrix& a);
void operator+=(const SymbolicMatrix& a);
SymbolicMatrix operator-() const;
PolynomialFraction determinant() const;
SymbolicMatrix submatrix(int i, int j) const;
SymbolicMatrix adjugate() const;
bool isIdent();
void fillSymbolicMatrix(string s, bool mode){
//mode =0 means one-dimensional indexing, mode =1 means bi-dimensional
int k = 0;
for(unsigned int i = 0; i<getNumberOfCols();i++){
for(unsigned int j = 0;j<getNumberOfRows();j++){
stringstream currentEntry;
if(mode==0){
currentEntry<<s<<"_"<<(i*getNumberOfRows()+j);
}
else{
currentEntry<<s<<"_"<<i<<"_"<<j;
}
PolynomialFraction currentPolynomialFraction(currentEntry.str());
setEntry(i,j,currentPolynomialFraction);
k++;
}
}
}
void fillWithUniformlyRandomConstants(){
//mode =0 means one-dimensional indexing, mode =1 means bi-dimensional
for(unsigned int i = 0; i<getNumberOfCols();i++){
for(unsigned int j = 0;j<getNumberOfRows();j++){
stringstream currentEntry;
currentEntry<< random_ZZ_p();
PolynomialFraction currentPolynomialFraction(currentEntry.str());
setEntry(i,j,currentPolynomialFraction);
}
}
}
bool operator == (SymbolicMatrix const &B) const{
if ((this->getNumberOfRows() == B.getNumberOfRows()) && (this->getNumberOfCols() == B.getNumberOfCols())){
for(unsigned int i = 0;i<getNumberOfCols();i++){
for(unsigned int j = 0;j<getNumberOfRows();j++){
if (this->getEntry(i,j) != B.getEntry(i,j)) return false;
}
}
return true;
}
else return false;
}
bool operator != (SymbolicMatrix const &B) const{
return !((*this)==B);
}
// Output stream
friend ostream &operator<<(ostream &os, const SymbolicMatrix &inSymbolicMatrix){
os <<"["<<endl;
for(unsigned int i=0;i<inSymbolicMatrix.getNumberOfRows();i++){
for(unsigned int j=0;j<inSymbolicMatrix.getNumberOfCols();j++){
os<<inSymbolicMatrix.getEntry(i,j)<<"\t";
}
os<<endl;
}
os << "]"<<endl;
return os;
}
bool unitTest(unsigned int maxDimension);
};
SymbolicMatrix inv(const SymbolicMatrix& a);
SymbolicMatrix transpose(const SymbolicMatrix& a);
SymbolicMatrix singleGauss(const SymbolicMatrix& a,const SymbolicMatrix& b);
SymbolicMatrix batchGauss(const SymbolicMatrix& a,const SymbolicMatrix& b);
#endif // SYMBOLICMATRIX_H