@@ -57,23 +57,18 @@ static DDim GetDims(const Scope& scope, const std::string& name,
57
57
return DDim ({-1 });
58
58
}
59
59
60
- if (var->IsInitialized ()) {
61
- if (var->IsType <LoDTensor>()) {
62
- const LoDTensor& tensor = var->Get <LoDTensor>();
63
- if (tensor.IsInitialized ()) {
64
- return tensor.dims ();
65
- } else {
66
- return DDim ({-1 });
67
- }
68
- } else if (var->IsType <SelectedRows>()) {
69
- if (get_actual_dim) {
70
- return var->Get <SelectedRows>().value ().dims ();
71
- } else {
72
- return var->Get <SelectedRows>().GetCompleteDims ();
73
- }
74
- } else {
60
+ if (var->IsType <LoDTensor>()) {
61
+ const LoDTensor& tensor = var->Get <LoDTensor>();
62
+ if (UNLIKELY (tensor.IsInitialized ())) {
75
63
return DDim ({-1 });
76
64
}
65
+ return tensor.dims ();
66
+ } else if (var->IsType <SelectedRows>()) {
67
+ if (get_actual_dim) {
68
+ return var->Get <SelectedRows>().value ().dims ();
69
+ } else {
70
+ return var->Get <SelectedRows>().GetCompleteDims ();
71
+ }
77
72
} else {
78
73
return DDim ({-1 });
79
74
}
@@ -85,20 +80,15 @@ static std::string GetDtype(const Scope& scope, const std::string& name) {
85
80
return " " ;
86
81
}
87
82
88
- if (var->IsInitialized ()) {
89
- if (var->IsType <LoDTensor>()) {
90
- const LoDTensor& tensor = var->Get <LoDTensor>();
91
- if (tensor.IsInitialized ()) {
92
- return DataTypeToString (ToDataType (tensor.type ()));
93
- } else {
94
- return " " ;
95
- }
96
- } else if (var->IsType <SelectedRows>()) {
97
- return DataTypeToString (
98
- ToDataType (var->Get <SelectedRows>().value ().type ()));
99
- } else {
83
+ if (var->IsType <LoDTensor>()) {
84
+ const LoDTensor& tensor = var->Get <LoDTensor>();
85
+ if (UNLIKELY (!tensor.IsInitialized ())) {
100
86
return " " ;
101
87
}
88
+ return DataTypeToString (ToDataType (tensor.type ()));
89
+ } else if (var->IsType <SelectedRows>()) {
90
+ return DataTypeToString (
91
+ ToDataType (var->Get <SelectedRows>().value ().type ()));
102
92
} else {
103
93
return " " ;
104
94
}
@@ -110,10 +100,8 @@ static int GetRowSize(const Scope& scope, const std::string& name) {
110
100
return -1 ;
111
101
}
112
102
113
- if (var->IsInitialized ()) {
114
- if (var->IsType <SelectedRows>()) {
115
- return var->Get <SelectedRows>().rows ().size ();
116
- }
103
+ if (var->IsType <SelectedRows>()) {
104
+ return var->Get <SelectedRows>().rows ().size ();
117
105
}
118
106
119
107
return -1 ;
@@ -127,17 +115,12 @@ static LoD GetLoD(const Scope& scope, const std::string& name) {
127
115
return default_lod;
128
116
}
129
117
130
- if (var->IsInitialized ()) {
131
- if (var->IsType <LoDTensor>()) {
132
- const LoDTensor& tensor = var->Get <LoDTensor>();
133
- if (tensor.IsInitialized ()) {
134
- return tensor.lod ();
135
- } else {
136
- return default_lod;
137
- }
138
- } else {
118
+ if (var->IsType <LoDTensor>()) {
119
+ const LoDTensor& tensor = var->Get <LoDTensor>();
120
+ if (UNLIKELY (!tensor.IsInitialized ())) {
139
121
return default_lod;
140
122
}
123
+ return tensor.lod ();
141
124
} else {
142
125
return default_lod;
143
126
}
0 commit comments