-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.hpp
More file actions
42 lines (32 loc) · 1.93 KB
/
Matrix.hpp
File metadata and controls
42 lines (32 loc) · 1.93 KB
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
#pragma once
#include "Vector.hpp"
//TODO: Implement operators for complex multiplication
template<typename T>
class Matrix
{
private:
T** data_; // A pointer to an array of pointers, each to an array of type T
size_t num_rows_; // Vertical dimension
size_t num_cols_; // Horizontal dimension
public:
// Constructors
Matrix<T>(); // Initialize empty matrix, data_ is nullptr
Matrix<T>(size_t num_rows, size_t num_cols); // Initialize with dimensions, entries are all 0
// Fails to construct: Matrix<T>(const T** data, size_t num_rows, size_t num_cols); // Given a vector of vectors, assert all are equal length
Matrix<T>(const Matrix& m1); // Copy Constructor
// Destructor
~Matrix<T>(); // Need to deallocate heap memory
// Member functions
int GetNumRows();
int GetNumCols();
void AppendRow(const Vector<T>& v); // Append to bottom of matrix (assert vector length == num_cols)
void AppendCol(const Vector<T>& v); // Append to right of matrix (assert vector length == num_rows)
// Operators
T& operator()(int i, int j); // 1-based indexing operator
Matrix<T>& operator=(const Matrix<T>& m1); // Copy assignment
Matrix<T> operator+(const Matrix<T>& m1) const; // Binary addition, checks if matrices are equal size
Matrix<T> operator-(const Matrix<T>& m1) const; // Binary subtraction
Matrix<T> operator*(double scalar) const; // Scalar multiplication
Vector<T> operator*(const Vector<T>& v) const; // Multiply a matrix and vector
};
#include "Matrix.hxx"