-
Notifications
You must be signed in to change notification settings - Fork 1
/
specialmat.cpp
35 lines (28 loc) · 774 Bytes
/
specialmat.cpp
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
#include "stdafx.h"
#include "specialmat.h"
#include <algorithm>
diagMatrix::diagMatrix(int r, double d):Matrix(r, r){
for (int i = 0; i < r; i++) {
this->set(i, i, d);
}
}
diagMatrix::diagMatrix(std::vector<double> vec):Matrix(vec.size(), vec.size()){
for (size_t i = 0; i < vec.size(); i++) {
this->set(i, i, vec[i]);
}
}
onesMatrix::onesMatrix(int r, int c):Matrix(r, c, 1.0){
}
zerosMatrix::zerosMatrix(int r, int c):Matrix(r, c, 0.0){
}
unitMatrix::unitMatrix(int r): diagMatrix(r, 1.0){
}
randomMatrix::randomMatrix(int r, int c):Matrix(r, c){
// C++11 new feature
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> dist(0.0, 1.0);
std::for_each(this->begin(), this->end(), [&](double& d) {
d = dist(mt);
});
}