pad.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include "ngraph/coordinate_diff.hpp"
20 #include "ngraph/op/op.hpp"
21 #include "ngraph/op/util/attr_types.hpp"
22 
23 namespace ngraph
24 {
25  namespace op
26  {
27  namespace v1
28  {
29  /// \brief Generic padding operation.
30  class NGRAPH_API Pad : public Op
31  {
32  public:
33  static constexpr NodeTypeInfo type_info{"Pad", 1};
34  const NodeTypeInfo& get_type_info() const override { return type_info; }
35  /// \brief Constructs a generic padding operation.
36  ///
37  /// \param arg The output producing input tensor to be padded.
38  /// \param pads_begin The output which specifies the number of padding elements
39  /// added
40  /// before position 0 on each axis of arg.
41  /// \param pads_end The output which specifies the number of padding elements
42  /// after the last element on each axis.
43  /// \param arg_pad_value The scalar output with the value used for padding
44  /// if pad_mode is CONSTANT
45  /// \param pad_mode The padding mode: CONSTANT, EDGE, REFLECT or SYMMETRIC.
46  /// CONSTANT initializes new elements with arg_pad_value, EDGE uses the nearest
47  /// value from arg. REFLECT and SYMMETRIC tile the background by flipping arg
48  /// at the edge (SYMMETRIC) or on the last row/column/etc. (REFLECT).
49  Pad(const Output<Node>& arg,
50  const Output<Node>& pads_begin,
51  const Output<Node>& pads_end,
52  const Output<Node>& arg_pad_value,
53  PadMode pad_mode);
54 
55  /// \brief Constructs a generic padding operation.
56  ///
57  /// \param arg The output producing input tensor to be padded.
58  /// \param pads_begin The output which specifies the number of padding elements
59  /// added
60  /// \param pads_end The output which specifies the number of padding elements
61  /// after the last element on each axis.
62  /// \param pad_mode The padding mode: CONSTANT, EDGE, REFLECT or SYMMETRIC.
63  Pad(const Output<Node>& arg,
64  const Output<Node>& pads_begin,
65  const Output<Node>& pads_end,
66  PadMode pad_mode);
67 
68  /// \brief Constructs a generic padding operation.
69  Pad() = default;
70 
71  bool visit_attributes(AttributeVisitor& visitor) override;
72  size_t get_version() const override { return 1; }
73  void validate_and_infer_types() override;
74  virtual std::shared_ptr<Node>
75  clone_with_new_inputs(const OutputVector& new_args) const override;
76 
77  /// return The node which specifies the number of padding elements
78  /// added at the beginning of each axis
79  CoordinateDiff get_pads_begin() const;
80  /// return The node which specifies the number of padding elements
81  /// added at the end of each axis
82  CoordinateDiff get_pads_end() const;
83 
84  /// \return The padding mode.
85  PadMode get_pad_mode() const { return m_pad_mode; }
86  void set_pad_mode(PadMode pad_mode) { m_pad_mode = pad_mode; }
87  bool evaluate(const HostTensorVector& outputs,
88  const HostTensorVector& inputs) const override;
89 
90  private:
91  PadMode m_pad_mode;
92  };
93  }
94  }
95 }
ngraph::op::v1::Pad
Generic padding operation.
Definition: pad.hpp:31
ngraph::op::v1::Pad::get_pads_begin
CoordinateDiff get_pads_begin() const
ngraph::op::v1::Pad::get_version
size_t get_version() const override
Definition: pad.hpp:72
ngraph::op::v1::Pad::get_pad_mode
PadMode get_pad_mode() const
Definition: pad.hpp:85
ngraph::op::v1::Pad::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph::op::v1::Pad::Pad
Pad(const Output< Node > &arg, const Output< Node > &pads_begin, const Output< Node > &pads_end, PadMode pad_mode)
Constructs a generic padding operation.
ngraph::op::v1::Pad::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: pad.hpp:34
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v1::Pad::Pad
Pad(const Output< Node > &arg, const Output< Node > &pads_begin, const Output< Node > &pads_end, const Output< Node > &arg_pad_value, PadMode pad_mode)
Constructs a generic padding operation.
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v1::Pad::get_pads_end
CoordinateDiff get_pads_end() const
ngraph::op::PadMode
PadMode
Modes for the Pad operator.
Definition: attr_types.hpp:32
ngraph::op::v1::Pad::Pad
Pad()=default
Constructs a generic padding operation.
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29