imperative.h 1.3 KB
Newer Older
X
Xin Pan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

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 <Python.h>
X
Xin Pan 已提交
17
#include <vector>
X
Xin Pan 已提交
18 19
#include "paddle/fluid/imperative/layer.h"
#include "pybind11/pybind11.h"
X
Xin Pan 已提交
20
#include "pybind11/stl.h"
X
Xin Pan 已提交
21 22 23 24

namespace paddle {
namespace pybind {

X
Xin Pan 已提交
25
class PyLayer : public imperative::Layer {
X
Xin Pan 已提交
26
 public:
X
Xin Pan 已提交
27
  using imperative::Layer::Layer;  // Inherit constructors
X
Xin Pan 已提交
28

X
Xin Pan 已提交
29 30 31 32
  std::vector<imperative::VariableBase> Forward(
      const std::vector<imperative::VariableBase>& inputs) override {
    PYBIND11_OVERLOAD(std::vector<imperative::VariableBase>, Layer, Forward,
                      inputs);  // NOLINT
X
Xin Pan 已提交
33 34 35 36 37 38 39
  }

  void Backward() override {
    PYBIND11_OVERLOAD(void, Layer, Backward, );  // NOLINT
  }
};

X
Xin Pan 已提交
40
void BindTracer(pybind11::module* m);
X
Xin Pan 已提交
41

X
Xin Pan 已提交
42 43
}  // namespace pybind
}  // namespace paddle