This repository has been archived by the owner on Aug 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix.h
executable file
·88 lines (70 loc) · 2.19 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
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
#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "NamedObject.h"
#include "SubMatrix.h"
class SubMatrix;
using namespace std;
// Matrix class provides data storage and manipulation like a mathematical matrix.
// Current support:
// - Basic class functionality (copying, assigning, printing, etc.).
// - Generate matrices from vector<vector<double>>
// - Extract value from index
// - Insert value at index
// - Set all elements to a number
// - Extract SubMatrices
// - Construct new Matrices from SubMatrices
// - Query the matrix size
class Matrix : public NamedObject {
public:
// --- Constructors --- //
Matrix();
Matrix(int, int);
Matrix(int, int, double);
Matrix(const vector<vector<double>>&);
Matrix(const Matrix&);
Matrix(SubMatrix&);
// --- Destructor --- //
~Matrix();
// --- Assignment Operators --- //
Matrix& operator=(const vector<vector<double>>&);
Matrix& operator=(const Matrix&);
Matrix& operator=(SubMatrix&);
// --- Accessors & Mutators --- //
const string& getName() const;
void setName(const string&);
// --- Functions and Operators --- //
double& operator()(int, int);
const double& operator()(int, int) const;
void operator=(double);
SubMatrix& operator()(int, int, int, int);
int length() const;
int size(int dim = 0) const;
Matrix& operator*(const Matrix&) const;
Matrix& operator+(const Matrix&) const;
Matrix& operator-(const Matrix&) const;
Matrix& operator*(SubMatrix&) const;
Matrix& operator*(double) const;
double norm() const;
// --- Printing --- //
void Print(ostream&) const;
friend ostream& operator<<(ostream&, const Matrix&);
void Print(ofstream&) const;
friend ofstream& operator<<(ofstream&, const Matrix&);
private:
// --- Helper Functions --- //
void setFields(int r = 0, int c = 0, double value = 0);
void setFields(const vector<vector<double>>&);
void setFields(const Matrix&);
void setFields(SubMatrix&);
void deleteFields();
bool checkCols(const vector<vector<double>>&);
// --- Underlying Data --- //
vector<vector<double>> data;
int nRows;
int nCols;
};
#endif