-
Notifications
You must be signed in to change notification settings - Fork 3
/
Node.cpp
46 lines (40 loc) · 1.09 KB
/
Node.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
#include "Node.h"
Node::Node(lbfgsfloatval_t* vector, int dim, bool isLeaf){
this -> isLeaf = isLeaf;
this -> dim = dim;
this -> id = OOV;
this -> lChild = NULL;
this -> rChild = NULL;
this -> is_root = false;
this -> span.first = 0, this -> span.second = 0; // initial [0,0]
//{ allocate memory
__LBFGSALLOC__(v_vector, dim);
__LBFGSALLOC__(v_cerror, dim);
__LBFGSALLOC__(v_deriva, dim * dim);
__LBFGSALLOC__(v_oerror, 2 * dim);
__LBFGSALLOC__(v_perror, 2 * dim);
//}
//{ deal with leaves
if(isLeaf){// for leaves, the gradient set to be I
Map<VectorLBFGS>(v_vector, dim) =
Map<VectorLBFGS>(vector, dim);
Map<MatrixLBFGS>(v_deriva, dim, dim).setIdentity();
}else{
Map<VectorLBFGS>(v_vector, dim)
= Map<VectorLBFGS>(vector, dim);
Map<MatrixLBFGS>(v_deriva, dim, dim).setZero();
}
//}
}
Node::~Node(){
// recusive deleting
if(this -> lChild != NULL) delete this -> lChild;
if(this -> rChild != NULL) delete this -> rChild;
//{ free memory
__LBFGSFREE__(v_vector);
__LBFGSFREE__(v_cerror);
__LBFGSFREE__(v_deriva);
__LBFGSFREE__(v_oerror);
__LBFGSFREE__(v_perror);
//}
}