|
|
|
@ -18,10 +18,18 @@ limitations under the License. */
|
|
|
|
|
namespace paddle {
|
|
|
|
|
namespace framework {
|
|
|
|
|
|
|
|
|
|
std::vector<framework::DDim> InferShapeContext::GetInputsDim(
|
|
|
|
|
DDim InferShapeContext::GetInputDim(const std::string &name) const {
|
|
|
|
|
const std::vector<std::string> &arg_names = Inputs(name);
|
|
|
|
|
PADDLE_ENFORCE_EQ(arg_names.size(), 1UL,
|
|
|
|
|
"Input(%s) should hold one element, but now it holds %d",
|
|
|
|
|
name, arg_names.size());
|
|
|
|
|
return this->GetDim(arg_names[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<DDim> InferShapeContext::GetInputsDim(
|
|
|
|
|
const std::string &name) const {
|
|
|
|
|
const std::vector<std::string> &names = Inputs(name);
|
|
|
|
|
return GetDims(names);
|
|
|
|
|
const std::vector<std::string> &arg_names = Inputs(name);
|
|
|
|
|
return GetDims(arg_names);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DDim InferShapeContext::GetInputsElementDim(const std::string &name,
|
|
|
|
@ -30,24 +38,31 @@ DDim InferShapeContext::GetInputsElementDim(const std::string &name,
|
|
|
|
|
return this->GetDim(names[idx]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InferShapeContext::SetOutputsDim(
|
|
|
|
|
const std::string &name, const std::vector<framework::DDim> &dims) {
|
|
|
|
|
void InferShapeContext::SetOutputDim(const std::string &name, const DDim &dim) {
|
|
|
|
|
auto &arg_names = Outputs(name);
|
|
|
|
|
PADDLE_ENFORCE_EQ(arg_names.size(), 1UL,
|
|
|
|
|
"Output(%s) should hold one element, but now it holds %d",
|
|
|
|
|
name, arg_names.size());
|
|
|
|
|
SetDim(arg_names[0], dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InferShapeContext::SetOutputsDim(const std::string &name,
|
|
|
|
|
const std::vector<DDim> &dims) {
|
|
|
|
|
auto &names = Outputs(name);
|
|
|
|
|
SetDims(names, dims);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<framework::DDim> InferShapeContext::GetDims(
|
|
|
|
|
std::vector<DDim> InferShapeContext::GetDims(
|
|
|
|
|
const std::vector<std::string> &names) const {
|
|
|
|
|
std::vector<framework::DDim> ret;
|
|
|
|
|
std::vector<DDim> ret;
|
|
|
|
|
ret.reserve(names.size());
|
|
|
|
|
std::transform(
|
|
|
|
|
names.begin(), names.end(), std::back_inserter(ret),
|
|
|
|
|
[this](const std::string &name) { return this->GetDim(name); });
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InferShapeContext::SetDims(const std::vector<std::string> &names,
|
|
|
|
|
const std::vector<framework::DDim> &dims) {
|
|
|
|
|
const std::vector<DDim> &dims) {
|
|
|
|
|
size_t length = names.size();
|
|
|
|
|
PADDLE_ENFORCE_EQ(length, dims.size());
|
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
|
|
|
|