-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.h
More file actions
49 lines (40 loc) · 979 Bytes
/
matrix.h
File metadata and controls
49 lines (40 loc) · 979 Bytes
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
/*
author: De Wang
desc: mini matrix lib
*/
#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template<typename T>
class matrix {
private:
typedef vector<T> Vec;
typedef vector<vector<T> > Mat;
size_t rows;
size_t cols;
Mat M;
vector<string> fields;
public:
// Constructors & destructors
matrix(size_t _rows, size_t _cols, const T& elements=0.0,
const string str="col");
matrix(const matrix<T>& cp);
matrix(const string csv, const T& fill=0.0); // initialize from csv
~matrix();
// getter
size_t get_rows() const;
size_t get_cols() const;
// operator overload
matrix<T>& operator=(const matrix<T>& cp);
T& operator()(const size_t& _row, const size_t& _col);
// utility methods
void print();
bool rangeCheck(const size_t& _row, const size_t& _col) const;
// math functions
vector<T> sumOfAllCols();
vector<T> sumOfAllRows();
};
#endif /*MATRIX_H*/