forked from codeplaysoftware/portBLAS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.hpp
46 lines (42 loc) · 1.44 KB
/
util.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
#include <iostream>
#include <random>
#include <string>
#include <vector>
template <typename index_t, typename matrix_t>
static inline void print_matrix(const matrix_t& M, index_t rows, index_t cols,
index_t ld) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
std::string print_friendly = std::to_string(M[j * ld + i]).substr(0, 6);
std::cout << print_friendly << ((j < cols - 1) ? ' ' : '\n');
}
}
}
template <typename index_t, typename matrix_t>
static inline void fill_matrix(matrix_t& M, index_t rows, index_t cols,
index_t ld) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(-10.0, 10.0);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
M[j * ld + i] = dis(gen);
}
}
}
template <typename index_t, typename vector_t>
static inline void print_vector(const vector_t& V, index_t size, index_t inc) {
for (int i = 0; i < (size - 1) * inc + 1; i += inc) {
std::string print_friendly = std::to_string(V[i]).substr(0, 6);
std::cout << print_friendly << '\n';
}
}
template <typename index_t, typename vector_t>
static inline void fill_vector(vector_t& V, index_t size, index_t inc) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(-10.0, 10.0);
for (int i = 0; i < (size - 1) * inc + 1; i += inc) {
V[i] = dis(gen);
}
}