-
Notifications
You must be signed in to change notification settings - Fork 3
/
Constant.h
101 lines (84 loc) · 3.29 KB
/
Constant.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
#ifndef __CONSTANT_H__
#define __CONSTANT_H__
#include <iostream>
#include <lbfgs.h>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;
/* some constant definations */
// symbol defination
const string MOSES_SEP = " ||| "; // Moses seperator
const string SPACE = " "; // Space symbol
const string TAB = "\t"; // Tab symbol
const string OOV = "<<OOV>>"; // oov symbol
const string LFLAG = "("; // (
const string MFLAG = ","; // ,
const string RFLAG = ")"; // )
const string SRC = "1S_"; // source flag
const string TGT = "2T_"; // target flag
// type defination
// define the vector and matrix for lbfgs
typedef Matrix<lbfgsfloatval_t,Eigen::Dynamic,Eigen::Dynamic> MatrixLBFGS;
typedef Matrix<lbfgsfloatval_t,Eigen::Dynamic,1> VectorLBFGS;
typedef pair<int, int> Span; // alignment span
// utility marco
#define __FILE_MSG__(msg) \
{ \
cerr << "mesg:\t" << msg << endl; \
cerr << "file:\t" << __FILE__ << endl; \
cerr << "line:\t" << __LINE__ << endl; \
cerr << "func:\t" << __FUNCTION__ << endl; \
}
#define __LBFGSALLOC__(name, size) \
name = lbfgs_malloc(size); \
if(name == NULL){ \
__FILE_MSG__( \
"memory malloc failed!" \
); \
exit(1); \
} \
memset(name, 0, sizeof(lbfgsfloatval_t) * size);
#define __LBFGSFREE__(name) \
if(name != NULL) lbfgs_free(name);
#define __MEMALLOC__(type, name, size) \
type* name = \
(type*)malloc(sizeof(type) * size); \
if(name == NULL){ \
__FILE_MSG__( \
"memory malloc failed!" \
); \
exit(1); \
} \
memset(name, 0, sizeof(type) * size);
#define __MEMFREE__(name) \
if(name != NULL) free(name);
// for extracting some parameters
#define __DEFINE_WBS__(x, n) \
Map<MatrixLBFGS> m_W_1(x, n, 2 * n); \
Map<MatrixLBFGS> m_W_2(x + n * 2 * n, 2 * n, n); \
Map<VectorLBFGS> m_B_1(x + n * 2 * n + 2 * n * n, n); \
Map<VectorLBFGS> m_B_2(x + n * 2 * n + 2 * n * n + n, 2 * n);
#define __DEFINE_DWBS__(x, n) \
Map<MatrixLBFGS> m_Dw_1(x, n, 2 * n); \
Map<MatrixLBFGS> m_Dw_2(x + n * 2 * n, 2 * n, n); \
Map<VectorLBFGS> m_Db_1(x + n * 2 * n + 2 * n * n, n); \
Map<VectorLBFGS> m_Db_2(x + n * 2 * n + 2 * n * n + n, 2 * n);
#define __DEFINE_ATT_WBS__(x, n1, n2, n, s) \
Map<MatrixLBFGS> m_Aw_s(x, n, n1); \
Map<MatrixLBFGS> m_Aw_t(x + n * n1, n, n2); \
Map<VectorLBFGS> m_Aw_b(x + n * n1 + n * n2, n); \
Map<MatrixLBFGS> m_Sw_s(x + n * n1 + n * n2 + n, s, n1); \
Map<MatrixLBFGS> m_Sw_t(x + n * n1 + n * n2 + n + s * n1, s, n2); \
Map<VectorLBFGS> m_Sw_b(x + n * n1 + n * n2 + n + s * n1 + s * n2, s); \
Map<MatrixLBFGS> m_Sw(x + n * n1 + n * n2 + n + s * n1 + s * n2 + s, s, s); \
Map<VectorLBFGS> m_Sb(x + n * n1 + n * n2 + n + s * n1 + s * n2 + s + s * s, 1);
#define __DEFINE_ATT_DWBS__(x, n1, n2, n, s) \
Map<MatrixLBFGS> m_DAw_s(x, n, n1); \
Map<MatrixLBFGS> m_DAw_t(x + n * n1, n, n2); \
Map<VectorLBFGS> m_DAw_b(x + n * n1 + n * n2, n); \
Map<MatrixLBFGS> m_DSw_s(x + n * n1 + n * n2 + n, s, n1); \
Map<MatrixLBFGS> m_DSw_t(x + n * n1 + n * n2 + n + s * n1, s, n2); \
Map<VectorLBFGS> m_DSw_b(x + n * n1 + n * n2 + n + s * n1 + s * n2, s); \
Map<MatrixLBFGS> m_DSw(x + n * n1 + n * n2 + n + s * n1 + s * n2 + s, s, s); \
Map<VectorLBFGS> m_DSb(x + n * n1 + n * n2 + n + s * n1 + s * n2 + s + s * s, 1);
#endif