range.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/node.hpp"
8 #include "ngraph/op/op.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace v4
15  {
16  /// \brief Range operation, analogous to `arange()` in Numpy.
17  class NGRAPH_API Range : public Op
18  {
19  public:
20  NGRAPH_RTTI_DECLARATION;
21  /// \brief Constructs an unitialized range operation.
22  Range() = default;
23 
24  /// \brief Constructs a range operation.
25  ///
26  /// \param start The tensor producing the start value. Must be a scalar of numeric
27  /// element type.
28  /// \param stop The tensor producing the stop value. Must be a scalar of numeric
29  /// element type.
30  /// \param step The tensor producing the step value. Must be a scalar of numeric
31  /// element type.
32  /// \param output_type The type of the output.
33  Range(const Output<Node>& start,
34  const Output<Node>& stop,
35  const Output<Node>& step,
36  element::Type output_type);
37 
38  bool visit_attributes(AttributeVisitor& visitor) override;
39  void validate_and_infer_types() override;
40 
41  virtual std::shared_ptr<Node>
42  clone_with_new_inputs(const OutputVector& new_args) const override;
43  bool evaluate(const HostTensorVector& outputs,
44  const HostTensorVector& inputs) const override;
45  bool has_evaluate() const override;
46 
47  private:
48  element::Type m_output_type;
49  };
50  } // namespace v4
51  namespace v0
52  {
53  /// \brief Range operation, analogous to `range()` in Python.
54  class NGRAPH_API Range : public Op
55  {
56  public:
57  static constexpr NodeTypeInfo type_info{"Range", 0};
58  const NodeTypeInfo& get_type_info() const override { return type_info; }
59  /// \brief Constructs an unitialized range operation.
60  Range() = default;
61 
62  /// \brief Constructs a range operation.
63  ///
64  /// \param start The tensor producing the start value. Must be a scalar of integer
65  /// element type, and same element type as `stop` and `step`.
66  /// \param stop The tensor producing the stop value. Must be a scalar of integer
67  /// element type, and same element type as `start` and `step`.
68  /// \param step The tensor producing the step value. Must be a scalar of integer
69  /// element type, and same element type as `start` and `stop`.
70  Range(const Output<Node>& start,
71  const Output<Node>& stop,
72  const Output<Node>& step);
73 
74  bool visit_attributes(AttributeVisitor& visitor) override;
75  void validate_and_infer_types() override;
76 
77  virtual std::shared_ptr<Node>
78  clone_with_new_inputs(const OutputVector& new_args) const override;
79  bool evaluate(const HostTensorVector& outputs,
80  const HostTensorVector& inputs) const override;
81  bool has_evaluate() const override;
82  };
83  } // namespace v0
84  using v0::Range;
85  } // namespace op
86 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Definition: element_type.hpp:51
Root of all actual ops.
Definition: op.hpp:17
Range operation, analogous to range() in Python.
Definition: range.hpp:55
const NodeTypeInfo & get_type_info() const override
Definition: range.hpp:58
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
Range(const Output< Node > &start, const Output< Node > &stop, const Output< Node > &step)
Constructs a range operation.
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
Range()=default
Constructs an unitialized range operation.
Range operation, analogous to arange() in Numpy.
Definition: range.hpp:18
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
Range()=default
Constructs an unitialized range operation.
Range(const Output< Node > &start, const Output< Node > &stop, const Output< Node > &step, element::Type output_type)
Constructs a range operation.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27