shape_inference.cc 1.8 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
2

L
Luo Tao 已提交
3 4 5
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
6

L
Luo Tao 已提交
7
    http://www.apache.org/licenses/LICENSE-2.0
8

L
Luo Tao 已提交
9 10 11 12 13
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
14

Y
Yi Wang 已提交
15
#include "paddle/fluid/framework/shape_inference.h"
16 17 18 19
#include <algorithm>
#include <string>
#include <vector>
#include "paddle/fluid/framework/grad_op_desc_maker.h"
Y
Yi Wang 已提交
20
#include "paddle/fluid/framework/operator.h"
21 22 23 24

namespace paddle {
namespace framework {

F
fengjiayi 已提交
25 26 27
std::vector<DDim> InferShapeContext::GetReaderDims(
    const std::string &name) const {
  const std::vector<std::string> &arg_names = Inputs(name);
28 29 30 31 32
  PADDLE_ENFORCE_EQ(arg_names.size(), 1UL,
                    platform::errors::InvalidArgument(
                        "Reader input '%s' should hold one element, but now it "
                        "holds %d elements.",
                        name, arg_names.size()));
F
fengjiayi 已提交
33 34 35
  return this->GetRepeatedDims(arg_names[0]);
}

F
fengjiayi 已提交
36 37 38
void InferShapeContext::SetReaderDims(const std::string &name,
                                      const std::vector<DDim> &dims) {
  const std::vector<std::string> &arg_names = Outputs(name);
39 40 41 42 43
  PADDLE_ENFORCE_EQ(arg_names.size(), 1UL,
                    platform::errors::InvalidArgument(
                        "Reader output '%s' should hold one element, but now "
                        "it holds %d elements.",
                        name, arg_names.size()));
F
fengjiayi 已提交
44 45 46
  return this->SetRepeatedDims(arg_names[0], dims);
}

47 48
}  // namespace framework
}  // namespace paddle