-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.cpp
109 lines (84 loc) · 1.9 KB
/
functions.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <cstdlib>
#include <random>
#include <fstream>
#include <algorithm>
#include <iostream>
#include "utils.hpp"
template<typename dtype>
func_ret_t create_matrix(dtype ** mp, int size){
dtype * m;
int i,j;
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_real_distribution<dtype> dist_uniform(0,1);
dtype lamda = -0.001;
dtype coe[2*size-1];
dtype coe_i =0.0;
for (i=0; i < size; i++)
{
coe_i = 10*exp(lamda*i);
j=size-1+i;
coe[j]=coe_i;
j=size-1-i;
coe[j]=coe_i;
}
time_t t;
srand((unsigned) time(&t));
m = (dtype*) malloc(sizeof(dtype)*size*size);
if ( m == NULL) {
return RET_FAILURE;
}
for (i=0; i < size; i++) {
for (j=i; j < size; j++) {
auto temp = (double)(rand()%10);
m[i*size+j] = temp;
m[j*size+i] = temp;
// m[i*size+j]=coe[size-1-i+j];
// m[j*size+i]=coe[size-1-i+j];
// m[j*size+i]=coe[size-1-i+j];
// dtype ran = dist_uniform(rng);
// m[i*size+j] = m[j*size+i] =ran;
}
}
*mp = m;
return RET_SUCCESS;
}
// create dense vector
template<typename dtype>
func_ret_t create_vector(dtype **vp, int size){
dtype *m;
int i,j;
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_real_distribution<dtype> dist_uniform(0,1);
dtype lamda = -0.001;
dtype coe[2*size-1];
dtype coe_i =0.0;
for (i=0; i < size; i++)
{
coe_i = 10*exp(lamda*i);
j=size-1+i;
coe[j]=coe_i;
j=size-1-i;
coe[j]=coe_i;
}
time_t t;
srand((unsigned) time(&t));
m = (dtype*) malloc(sizeof(dtype)*size);
if ( m == NULL) {
return RET_FAILURE;
}
for (i=0; i < size; i++) {
m[i]=(double)(rand()%10);
// m[i]=coe[size-1-i];
// dtype ran = dist_uniform(rng);
// m[i] = ran;
}
*vp = m;
return RET_SUCCESS;
}