-
Notifications
You must be signed in to change notification settings - Fork 8
/
tensor.cpp
42 lines (34 loc) · 892 Bytes
/
tensor.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
#include <iostream>
#include <string>
#include <random>
#include <math.h>
#include <fstream>
#include "dais_exc.h"
#include "tensor.h"
#define PI 3.141592654
#define FLT_MAX 3.402823466e+38F /* max value */
#define FLT_MIN 1.175494351e-38F /* min positive value */
using namespace std;
/**
* Random Initialization
*
* Perform a random initialization of the tensor
*
* @param mean The mean
* @param std Standard deviation
*/
void Tensor::init_random(float mean, float std){
if(data){
std::default_random_engine generator;
std::normal_distribution<float> distribution(mean,std);
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
for(int k=0;k<d;k++){
this->operator()(i,j,k)= distribution(generator);
}
}
}
}else{
throw(tensor_not_initialized());
}
}