-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtensor_manipulate.h
103 lines (86 loc) · 2.11 KB
/
tensor_manipulate.h
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
#ifndef __TENSOR_MANIPULATE_H__
#define __TENSOR_MANIPULATE_H__
namespace tensor_lib {
// FLATTEN
template<typename T>
void flatten(
const std::vector<std::vector<std::vector<T> > >& tensor,
std::vector<T>& array
);
template<typename T>
void flatten(
const std::vector<std::vector<std::vector<std::vector<T> > > >& tensor,
std::vector<std::vector<T> >& array
);
template<typename T>
void flatten(
const std::vector<std::vector<std::vector<std::vector<std::vector<T> > > > >& tensor,
std::vector<std::vector<std::vector<T> > >& array
);
// ROLLBACK
template<typename T>
void rollback(
const std::vector<T>& array,
std::vector<std::vector<std::vector<T> > >& tensor
);
template<typename T>
void tensor_lib::rollback(
const std::vector<T>& array,
std::vector<std::vector<std::vector<std::vector<T> > > >& tensor
);
template<typename T>
void rollback(
const std::vector<std::vector<T> >& array,
std::vector<std::vector<std::vector<std::vector<T> > > >& tensor
);
template<typename T>
void rollback(
const std::vector<std::vector<std::vector<T> > >& array,
std::vector<std::vector<std::vector<std::vector<std::vector<T> > > > >& tensor
);
// RESHAPE
template<typename T>
void reshape(
std::vector<T>& Tensor,
const size_t len
)
{
Tensor.clear();
Tensor.resize(len, 0);
}
template<typename T>
void reshape(
std::vector<std::vector<T> >& Tensor,
const size_t W,
const size_t H
)
{
Tensor.clear();
Tensor.resize(H, std::vector<T>(W, 0));
}
template<typename T>
void reshape(
std::vector<std::vector<std::vector<T> > >& Tensor,
const size_t W,
const size_t H,
const size_t C
)
{
Tensor.clear();
Tensor.resize(C, std::vector<std::vector<T> >(H, std::vector<T>(W, 0)));
}
template<typename T>
void reshape(
std::vector<std::vector<std::vector<std::vector<T> > > >& Tensor,
const size_t W,
const size_t H,
const size_t C,
const size_t K
)
{
Tensor.clear();
Tensor.resize(K, std::vector<std::vector<std::vector<T> > >(C, std::vector<std::vector<T> >(H, std::vector<T>(W, 0))));
}
}
#include "tpp/tensor_manipulate.cpp"
#endif