-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdim.cc
More file actions
61 lines (52 loc) · 1.11 KB
/
dim.cc
File metadata and controls
61 lines (52 loc) · 1.11 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
#include "dynet/dim.h"
#include <iostream>
using namespace std;
namespace dynet {
ostream& operator<<(ostream& os, const Dim& d) {
os << '{';
for (unsigned i = 0; i < d.nd; ++i) {
if (i) os << ',';
os << d.d[i];
}
if(d.bd != 1) os << 'X' << d.bd;
return os << '}';
}
void Dim::print_profile(ostream& os) const {
os << '{';
for (unsigned i = 0; i < nd; ++i) {
if (i) os << ',';
os << d[i];
}
os << '}';
}
ostream& operator<<(ostream& os, const vector<Dim>& ds) {
os << '[';
for (unsigned i = 0; i < ds.size(); ++i)
os << (i ? " " : "") << ds[i];
return os << ']';
}
istream& operator>>(istream& is, Dim& d) {
char place_holder;
is >> place_holder;
d.resize(DYNET_MAX_TENSOR_DIM);
bool batch_flag = false;
unsigned i = 0;
for (; i < DYNET_MAX_TENSOR_DIM + 1; ++i) {
if (i) {
is >> place_holder;
if (place_holder == 'X') {
batch_flag = true;
break;
} else if (place_holder == '}') {
break;
}
}
is >> d.d[i];
}
d.resize(i);
if (batch_flag) {
is >> d.bd >> place_holder;
}
return is;
}
} // namespace dynet