pad.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/coordinate_diff.hpp"
8 #include "ngraph/op/op.hpp"
9 #include "ngraph/op/util/attr_types.hpp"
10 
11 namespace ngraph
12 {
13  namespace op
14  {
15  namespace v1
16  {
17  /// \brief Generic padding operation.
18  class NGRAPH_API Pad : public Op
19  {
20  public:
21  static constexpr NodeTypeInfo type_info{"Pad", 1};
22  const NodeTypeInfo& get_type_info() const override { return type_info; }
23  /// \brief Constructs a generic padding operation.
24  ///
25  /// \param arg The output producing input tensor to be padded.
26  /// \param pads_begin The output which specifies the number of padding elements
27  /// added
28  /// before position 0 on each axis of arg.
29  /// \param pads_end The output which specifies the number of padding elements
30  /// after the last element on each axis.
31  /// \param arg_pad_value The scalar output with the value used for padding
32  /// if pad_mode is CONSTANT
33  /// \param pad_mode The padding mode: CONSTANT, EDGE, REFLECT or SYMMETRIC.
34  /// CONSTANT initializes new elements with arg_pad_value, EDGE uses the nearest
35  /// value from arg. REFLECT and SYMMETRIC tile the background by flipping arg
36  /// at the edge (SYMMETRIC) or on the last row/column/etc. (REFLECT).
37  Pad(const Output<Node>& arg,
38  const Output<Node>& pads_begin,
39  const Output<Node>& pads_end,
40  const Output<Node>& arg_pad_value,
41  PadMode pad_mode);
42 
43  /// \brief Constructs a generic padding operation.
44  ///
45  /// \param arg The output producing input tensor to be padded.
46  /// \param pads_begin The output which specifies the number of padding elements
47  /// added
48  /// \param pads_end The output which specifies the number of padding elements
49  /// after the last element on each axis.
50  /// \param pad_mode The padding mode: CONSTANT, EDGE, REFLECT or SYMMETRIC.
51  Pad(const Output<Node>& arg,
52  const Output<Node>& pads_begin,
53  const Output<Node>& pads_end,
54  PadMode pad_mode);
55 
56  /// \brief Constructs a generic padding operation.
57  Pad() = default;
58 
59  bool visit_attributes(AttributeVisitor& visitor) override;
60  size_t get_version() const override { return 1; }
61  void validate_and_infer_types() override;
62  virtual std::shared_ptr<Node>
63  clone_with_new_inputs(const OutputVector& new_args) const override;
64 
65  /// return The node which specifies the number of padding elements
66  /// added at the beginning of each axis
68  /// return The node which specifies the number of padding elements
69  /// added at the end of each axis
71 
72  /// \return The padding mode.
73  PadMode get_pad_mode() const { return m_pad_mode; }
74  void set_pad_mode(PadMode pad_mode) { m_pad_mode = pad_mode; }
75  bool evaluate(const HostTensorVector& outputs,
76  const HostTensorVector& inputs) const override;
77  bool has_evaluate() const override;
78 
79  private:
80  PadMode m_pad_mode;
81  bool evaluate_pad(const HostTensorVector& outputs,
82  const HostTensorVector& inputs) const;
83  };
84  } // namespace v1
85  } // namespace op
86 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A difference (signed) of tensor element coordinates.
Definition: coordinate_diff.hpp:18
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Generic padding operation.
Definition: pad.hpp:19
PadMode get_pad_mode() const
Definition: pad.hpp:73
size_t get_version() const override
Definition: pad.hpp:60
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
Pad()=default
Constructs a generic padding operation.
CoordinateDiff get_pads_end() const
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.
CoordinateDiff get_pads_begin() const
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
const NodeTypeInfo & get_type_info() const override
Definition: pad.hpp:22
Pad(const Output< Node > &arg, const Output< Node > &pads_begin, const Output< Node > &pads_end, PadMode pad_mode)
Constructs a generic padding operation.
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
PadMode
Modes for the Pad operator.
Definition: attr_types.hpp:20
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27