From bd369c357579f0f60fb717e83e3c0109e9f31a70 Mon Sep 17 00:00:00 2001 From: dongzhihong Date: Mon, 7 Aug 2017 16:12:39 +0800 Subject: [PATCH] "remove type alias header file" --- paddle/operators/fc_op.cc | 7 ++- paddle/operators/recurrent_op.cc | 13 +++-- paddle/operators/rnn/recurrent_op_utils.cc | 15 +++--- paddle/operators/rnn/recurrent_op_utils.h | 5 +- paddle/operators/softmax_op.cc | 4 +- paddle/operators/softmax_op.h | 4 +- paddle/operators/type_alias.h | 55 ---------------------- 7 files changed, 28 insertions(+), 75 deletions(-) delete mode 100644 paddle/operators/type_alias.h diff --git a/paddle/operators/fc_op.cc b/paddle/operators/fc_op.cc index 162528bc1fb..01a1a81206f 100644 --- a/paddle/operators/fc_op.cc +++ b/paddle/operators/fc_op.cc @@ -12,14 +12,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -#pragma once +#include "paddle/operators/net_op.h" + #include "paddle/framework/eigen.h" #include "paddle/framework/op_registry.h" namespace paddle { namespace operators { -class FullyConnectedOp : public framework::NetOp { +using OpRegistry = framework::OpRegistry; + +class FullyConnectedOp : public NetOp { public: void Init() override { AddOp(OpRegistry::CreateOp("mul", diff --git a/paddle/operators/recurrent_op.cc b/paddle/operators/recurrent_op.cc index 5e9c15ca0e6..24383742056 100644 --- a/paddle/operators/recurrent_op.cc +++ b/paddle/operators/recurrent_op.cc @@ -14,17 +14,19 @@ #include "paddle/operators/recurrent_op.h" -#include #include #include #include "paddle/framework/op_registry.h" #include "paddle/operators/net_op.h" -#include "paddle/platform/enforce.h" namespace paddle { namespace operators { +using Scope = framework::Scope; +using Variable = framework::Variable; +using Tensor = framework::Tensor; + void RecurrentAlgorithm::InferShape(const Scope& scope) const { seq_len_ = scope.FindVar((arg_->inlinks[0]).external) ->GetMutable() @@ -135,10 +137,11 @@ void RecurrentOp::Init() { alg_.Init(std::move(arg)); } -class RecurrentAlgorithmProtoAndCheckerMaker : public OpProtoAndCheckerMaker { +class RecurrentAlgorithmProtoAndCheckerMaker + : public framework::OpProtoAndCheckerMaker { public: - RecurrentAlgorithmProtoAndCheckerMaker(OpProto* proto, - OpAttrChecker* op_checker) + RecurrentAlgorithmProtoAndCheckerMaker(framework::OpProto* proto, + framework::OpAttrChecker* op_checker) : OpProtoAndCheckerMaker(proto, op_checker) { const auto& name = RecurrentOp::kArgName; // inputs and outputs stored in proto diff --git a/paddle/operators/rnn/recurrent_op_utils.cc b/paddle/operators/rnn/recurrent_op_utils.cc index 32c6c2dd4ef..7e4770630ed 100644 --- a/paddle/operators/rnn/recurrent_op_utils.cc +++ b/paddle/operators/rnn/recurrent_op_utils.cc @@ -18,7 +18,9 @@ namespace paddle { namespace operators { namespace rnn { -namespace fmw = paddle::framework; +namespace f = paddle::framework; + +using Tensor = framework::Tensor; void SegmentInputs(const std::vector& step_scopes, const std::vector& inlinks, const size_t seq_len, @@ -30,10 +32,10 @@ void SegmentInputs(const std::vector& step_scopes, inlinks[i].external); Tensor* input = input_var->GetMutable(); - fmw::DDim dims = input->dims(); + f::DDim dims = input->dims(); PADDLE_ENFORCE(static_cast(dims[0]) == seq_len, "all the inlinks must have same length"); - fmw::DDim step_dims = slice_ddim(dims, 1, dims.size()); + f::DDim step_dims = slice_ddim(dims, 1, dims.size()); for (size_t j = 0; j < seq_len; j++) { Tensor* step_input = step_scopes[j]->NewVar(inlinks[i].internal)->GetMutable(); @@ -58,11 +60,10 @@ void ConcatOutputs(const std::vector& step_scopes, auto step_scope_var = step_scopes[0]->FindVar(outlinks[i].internal); PADDLE_ENFORCE(step_scope_var != nullptr, "%s not in scope", outlinks[i].internal); - fmw::DDim step_dims = - step_scope_var->template GetMutable()->dims(); + f::DDim step_dims = step_scope_var->template GetMutable()->dims(); std::vector dims_vec = vectorize(step_dims); dims_vec.insert(dims_vec.begin(), seq_len); - output->Resize(fmw::make_ddim(dims_vec)); + output->Resize(f::make_ddim(dims_vec)); } else { output->mutable_data(platform::CPUPlace()); for (size_t j = 0; j < seq_len; j++) { @@ -104,7 +105,7 @@ void LinkMemories(const std::vector& scopes, } void InitArgument(const ArgumentName& name, Argument* arg, - const OperatorBase& op) { + const framework::OperatorBase& op) { arg->step_net = op.Input(name.step_net); arg->step_scopes = op.Output(name.step_scopes); diff --git a/paddle/operators/rnn/recurrent_op_utils.h b/paddle/operators/rnn/recurrent_op_utils.h index 379754b98fc..17941c503cf 100644 --- a/paddle/operators/rnn/recurrent_op_utils.h +++ b/paddle/operators/rnn/recurrent_op_utils.h @@ -17,12 +17,13 @@ #include #include "paddle/framework/operator.h" -#include "paddle/operators/type_alias.h" namespace paddle { namespace operators { namespace rnn { +using Scope = framework::Scope; + /** * Memory of a RNN (same as the role of `Momory` in PaddlePaddle). * @@ -86,7 +87,7 @@ void LinkMemories(const std::vector& step_scopes, const int offset, bool infer_shape_mode); void InitArgument(const ArgumentName& name, Argument* arg, - const OperatorBase& op); + const framework::OperatorBase& op); } // namespace rnn } // namespace operators diff --git a/paddle/operators/softmax_op.cc b/paddle/operators/softmax_op.cc index e24e595732e..801faea7385 100644 --- a/paddle/operators/softmax_op.cc +++ b/paddle/operators/softmax_op.cc @@ -41,9 +41,9 @@ class SoftmaxOpMaker : public framework::OpProtoAndCheckerMaker { } }; -class SoftmaxOpGrad : public OperatorWithKernel { +class SoftmaxOpGrad : public framework::OperatorWithKernel { protected: - void InferShape(const InferShapeContext &ctx) const override { + void InferShape(const framework::InferShapeContext &ctx) const override { PADDLE_ENFORCE(ctx.InputSize() == 3UL, "Input of SoftmaxOpGrad should be 3, X, Y, YG"); PADDLE_ENFORCE(ctx.OutputSize() == 1UL, diff --git a/paddle/operators/softmax_op.h b/paddle/operators/softmax_op.h index 0484555485a..f90056e1e47 100644 --- a/paddle/operators/softmax_op.h +++ b/paddle/operators/softmax_op.h @@ -62,9 +62,9 @@ class SoftmaxKernel : public framework::OpKernel { }; template -class SoftmaxGradKernel : public OpKernel { +class SoftmaxGradKernel : public framework::OpKernel { public: - void Compute(const ExecutionContext& context) const override { + void Compute(const framework::ExecutionContext& context) const override { std::shared_ptr scale_ = std::make_shared(); auto Y = context.Input("Y"); diff --git a/paddle/operators/type_alias.h b/paddle/operators/type_alias.h deleted file mode 100644 index eac12d35dd8..00000000000 --- a/paddle/operators/type_alias.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. - - 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 - - http://www.apache.org/licenses/LICENSE-2.0 - - 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. */ - -#pragma once - -#include "paddle/framework/eigen.h" -#include "paddle/framework/op_registry.h" -#include "paddle/operators/net_op.h" - -namespace paddle { -namespace operators { - -using OpKernel = framework::OpKernel; -using OperatorBase = framework::OperatorBase; -using InferShapeContext = framework::InferShapeContext; -using ExecutionContext = framework::ExecutionContext; -using Variable = framework::Variable; -template -using EigenScalar = framework::EigenScalar; -template -using EigenVector = framework::EigenVector; -template -using EigenMatrix = framework::EigenMatrix; -template -using EigenTensor = framework::EigenTensor; -using Tensor = framework::Tensor; -using Scope = framework::Scope; -using OperatorWithKernel = framework::OperatorWithKernel; -using OperatorBase = framework::OperatorBase; -using OpProtoAndCheckerMaker = framework::OpProtoAndCheckerMaker; -using OpProto = framework::OpProto; -using OpAttrChecker = framework::OpAttrChecker; -using CPUPlace = platform::CPUPlace; -using GPUPlace = platform::GPUPlace; -using OpRegistry = framework::OpRegistry; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -- GitLab