Frobby 0.10.0
Loading...
Searching...
No Matches
Matrix.h
1/* Frobby: Software for monomial ideal computations.
2 Copyright (C) 2010 University of Aarhus
3 Contact Bjarke Hammersholt Roune for license information (www.broune.com)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see http://www.gnu.org/licenses/.
17*/
18#ifndef MATRIX_GUARD
19#define MATRIX_GUARD
20
21#include <vector>
22
23class BigIntVector;
24class ColumnPrinter;
25
26class Matrix {
27 public:
28 Matrix(size_t rowCount = 0, size_t colCount = 0);
29
30 size_t getRowCount() const {return _rowCount;}
31 size_t getColCount() const {return _colCount;}
32
37 void resize(size_t rowCount, size_t colCount);
38
39 const mpq_class& operator()(size_t row, size_t col) const
40 {return _entries[toIndex(row, col)];}
41 mpq_class& operator()(size_t row, size_t col)
42 {return _entries[toIndex(row, col)];}
43
44 void swap(Matrix& mat);
45
46 private:
47 size_t toIndex(size_t row, size_t col) const {
48 ASSERT(row < _rowCount);
49 ASSERT(col < _colCount);
50 ASSERT(_entries.size() == _rowCount * _colCount);
51 size_t index = col + row * _colCount;
52 ASSERT(index < _entries.size());
53 return index;
54 }
55
56 size_t _rowCount;
57 size_t _colCount;
58 vector<mpq_class> _entries;
59};
60
61bool operator==(const Matrix& a, const Matrix& b);
62ostream& operator<<(ostream& out, const Matrix& mat);
63
64void print(FILE* file, const Matrix& mat);
65void print(ColumnPrinter& printer, const Matrix& mat);
66
68void product(Matrix& prod, const Matrix& a, const Matrix& b);
69
71void transpose(Matrix& trans, const Matrix& mat);
72
74void transpose(Matrix& mat);
75
77void addMultiplyRow(Matrix& mat, size_t resultRow,
78 size_t sourceRow, const mpq_class& mult);
79
81void multiplyRow(Matrix& mat, size_t row, const mpq_class& mult);
82
84void swapRows(Matrix& mat, size_t row1, size_t row2);
85
89bool rowReduce(Matrix& mat);
90
92size_t matrixRank(const Matrix& mat);
93
98void rowReduceFully(Matrix& mat);
99
102void subMatrix(Matrix& sub, const Matrix& mat,
103 size_t rowBegin, size_t rowEnd,
104 size_t colBegin, size_t colEnd);
105
108void copyRow(Matrix& target, size_t targetRow,
109 const Matrix& source, size_t sourceRow);
110
116bool inverse(Matrix& inv, const Matrix& mat);
117
119void nullSpace(Matrix& basis, const Matrix& mat);
120
124bool solve(Matrix& sol, const Matrix& lhs, const Matrix& rhs);
125
127bool hasSameColSpace(const Matrix& a, const Matrix& b);
128
130bool hasSameRowSpace(const Matrix& a, const Matrix& b);
131
133mpq_class determinant(const Matrix& mat);
134
136bool isParallelogram(const Matrix& mat);
137
142mpq_class getParallelogramAreaSq(const Matrix& mat);
143
144#endif
Definition BigIntVector.h:24
Definition ColumnPrinter.h:27
Definition Matrix.h:26
void resize(size_t rowCount, size_t colCount)
Definition Matrix.cpp:61