-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.hpp
88 lines (62 loc) · 2.54 KB
/
matrix.hpp
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_HPP__
#define __MATRIX_HPP__
#include<iostream>
#include<iomanip>
#include<sstream>
#include<fstream>
using std::cout;
using std::cerr;
using std::ios;
using std::fill;
using std::endl;
using std::ifstream;
template<typename T>
class Matrix{
private:
size_t nRows;
size_t nCols;
size_t * refCount;
T * data;
const Matrix<T>* parent_matrix;
public:
Matrix(size_t nrows=1, size_t ncols=1, T fillVal=0);
Matrix(const Matrix<T> &other);
Matrix<T>& operator =(const Matrix<T> &other);
~Matrix();
size_t getRows() const;
size_t getCols() const;
size_t* shape() const;
void print_shape() const;
bool shape_equals(const Matrix<T> & other) const;
Matrix<T> & operator *= (const Matrix<T> & other);
template <typename U>
friend Matrix<U> operator+(const Matrix<U> &left, const Matrix<U> &right);
template <typename U>
friend Matrix<U> operator-(const Matrix<U> &left, const Matrix<U> &right);
template <typename U>
friend Matrix<U> matrixMaultiply(const Matrix<U> &left, const Matrix<U> &right);
template <typename U>
friend Matrix<U> multiply_elements(const Matrix<U> &left, const Matrix<U> &right);
template <typename U>
friend Matrix<U> operator * (const Matrix<U> & left, const Matrix<U> &right);
template <typename U>
friend std::ostream & operator <<(std::ostream & os, const Matrix<U> & rhs);
Matrix<T> copy() const;
T* operator[](size_t i);
T* operator[](size_t i) const;
T operator()(size_t i, size_t j) const;
bool operator == (const Matrix & other) const;
Matrix<T> operator^(int expo);
static Matrix<T> createDiagonal(size_t nrows, T fillVal);
static Matrix<T> readMat(const char*filename);
void info()const;
void printMat() const;
void printMat(const char * filename);
Matrix<T> submatrix_ROI(size_t row_start, size_t row_end, size_t col_start, size_t col_end);
Matrix<T> submatrix(size_t row_start, size_t row_end, size_t col_start, size_t col_end);
Matrix<T> submatrix_cpy(size_t row_start, size_t row_end, size_t col_start, size_t col_end);
void adjust_ROI(size_t row_start, size_t row_end, size_t col_start, size_t col_end);
};
size_t getFileRowsCols(const char *fileName, size_t & rows, size_t & cols);
#include"matrixIplt.hpp"
#endif