-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTensor.h
More file actions
61 lines (46 loc) · 1.43 KB
/
CTensor.h
File metadata and controls
61 lines (46 loc) · 1.43 KB
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
#pragma once
#include "Imagelib.h"
// Tensor3D는 크기가 (nH x nW x nC)인 3차원 tensor를 관리함
class Tensor3D {
private:
double*** tensor;
int nH; // height
int nW; // width
int nC; // channel
public:
Tensor3D(int _nH, int _nW, int _nC) : nH(_nH), nW(_nW), nC(_nC) {
// 동작: 1)3차원 행렬을 동적할당하여, tensor에 시작 주소값을 저장
// 2)그 후 모든 element의 값을 0으로 초기화
// 사용함수: dmatrix3D(): 3차원 행렬을 동적 할당해서 pointer를 반환하는 함수
tensor = dmatrix3D(_nH, _nW, _nC);
for (int c = 0; c < _nC; c++) {
for (int h = 0; h < _nH; h++) {
for (int w = 0; w < _nW; w++) {
tensor[h][w][c] = 0;
}
}
}
}
~Tensor3D() {
// 동작: 3차원 동적 배열인 tensor를 할당 해제
// 사용함수: free_dmatrix3D(): 3차원 동적 할당된 행렬을 할당 해제하는 함수
free_dmatrix3D(tensor, nH, nW, nC);
}
void set_elem(int _h, int _w, int _c, double _val) { tensor[_h][_w][_c] = _val; }
double get_elem(int _h, int _w, int _c) const {
// 동작: 행=_h, 열= _w, 채널= _c 위치 element를 반환
return tensor[_h][_w][_c];
}
void get_info(int& _nH, int& _nW, int& _nC) const {
// 동작: 행렬의 차원(nH, nW, nC)을 pass by reference로 반환
_nH = nH;
_nW = nW;
_nC = nC;
}
void set_tensor(double*** _tensor) { tensor = _tensor; }
double*** get_tensor() const { return tensor; }
void print() const {
// 동작: 행렬의 크기 (nH*nW*nC)를 화면에 출력
cout << nH << "*" << nW << "*" << nC << endl;
}
};