class ov::op::v0::Constant

Overview

Class for constants. More…

#include <constant.hpp>

class Constant: public ov::op::Op
{
public:
    // construction

    Constant();
    Constant(const std::shared_ptr<ngraph::runtime::Tensor>& tensor);

    template <typename T>
    Constant(
        const element::Type& type,
        const Shape& shape,
        const std::vector<T>& values
        );

    Constant(const element::Type& type, const Shape& shape);

    template <class T, class = typename std::enable_if<std::is_fundamental<T>::value>::type>
    Constant(
        const element::Type& type,
        const Shape& shape,
        T value
        );

    Constant(
        const element::Type& type,
        const Shape& shape,
        const std::vector<std::string>& values
        );

    Constant(const element::Type& type, const Shape& shape, const void \* data);

    template <typename T>
    Constant(
        const element::Type& type,
        const Shape& shape,
        std::shared_ptr<ngraph::runtime::SharedBuffer<T>> data
        );

    Constant(const Constant& other);
    Constant(const Constant& other, const Shape& new_shape);

    // methods

    OPENVINO_OP("Constant", "opset1");

    template <typename T>
    void fill_data(const element::Type& type, T value);

    Constant& operator = (const Constant&);
    virtual void validate_and_infer_types();
    virtual bool visit_attributes(AttributeVisitor& visitor);

    virtual OPENVINO_SUPPRESS_DEPRECATED_START bool evaluate(
        const HostTensorVector& output_values,
        const HostTensorVector& input_values
        ) const;

    virtual OPENVINO_SUPPRESS_DEPRECATED_END bool has_evaluate() const;
    virtual bool evaluate_lower(TensorVector& outputs) const;
    virtual bool evaluate_upper(TensorVector& outputs) const;
    virtual bool constant_fold(OutputVector& outputs, const OutputVector& inputs);
    Shape get_shape_val() const;
    Strides get_strides_val() const;
    Coordinate get_coordinate_val() const;
    CoordinateDiff get_coordinate_diff_val() const;
    AxisVector get_axis_vector_val() const;
    AxisSet get_axis_set_val() const;
    void set_data_shape(const Shape& shape);
    size_t get_byte_size() const;
    virtual std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const;
    std::vector<std::string> get_value_strings() const;

    template <typename T>
    std::vector<T> get_vector() const;

    template <typename T>
    std::vector<T> cast_vector() const;

    const void \* get_data_ptr() const;

    template <typename T>
    const T \* get_data_ptr() const;

    template <element::Type_t ET>
    const element_type_traits<ET>::value_type \* get_data_ptr() const;

    bool get_all_data_elements_bitwise_identical() const;
    std::string convert_value_to_string(size_t index) const;

    template <typename T>
    static std::shared_ptr<Constant> create(
        const element::Type& type,
        const Shape& shape,
        const std::vector<T>& values
        );

    template <typename T>
    static std::shared_ptr<Constant> create(
        const element::Type& type,
        const Shape& shape,
        std::initializer_list<T> values
        );

    static std::shared_ptr<Constant> create(
        const element::Type& type,
        const Shape& shape,
        const void \* memory
        );
};

Inherited Members

public:
    // typedefs

    typedef DiscreteTypeInfo type_info_t;
    typedef std::map<std::string, Any> RTMap;

    // methods

    virtual void validate_and_infer_types();
    void constructor_validate_and_infer_types();
    virtual bool visit_attributes(AttributeVisitor&);
    virtual const ov::op::AutoBroadcastSpec& get_autob() const;
    virtual bool has_evaluate() const;

    virtual bool evaluate(
        const ov::HostTensorVector& output_values,
        const ov::HostTensorVector& input_values
        ) const;

    virtual bool evaluate(
        const ov::HostTensorVector& output_values,
        const ov::HostTensorVector& input_values,
        const EvaluationContext& evaluationContext
        ) const;

    virtual bool evaluate(
        ov::TensorVector& output_values,
        const ov::TensorVector& input_values
        ) const;

    virtual bool evaluate(
        ov::TensorVector& output_values,
        const ov::TensorVector& input_values,
        const ov::EvaluationContext& evaluationContext
        ) const;

    virtual bool evaluate_lower(ov::TensorVector& output_values) const;
    virtual bool evaluate_upper(ov::TensorVector& output_values) const;
    virtual bool evaluate_label(TensorLabelVector& output_labels) const;

    virtual bool constant_fold(
        OutputVector& output_values,
        const OutputVector& inputs_values
        );

    virtual OutputVector decompose_op() const;
    virtual const type_info_t& get_type_info() const = 0;
    const char \* get_type_name() const;
    void set_arguments(const NodeVector& arguments);
    void set_arguments(const OutputVector& arguments);
    void set_argument(size_t position, const Output<Node>& argument);

    void set_output_type(
        size_t i,
        const element::Type& element_type,
        const PartialShape& pshape
        );

    void set_output_size(size_t output_size);
    void invalidate_values();
    virtual void revalidate_and_infer_types();
    virtual std::string description() const;
    const std::string& get_name() const;
    void set_friendly_name(const std::string& name);
    const std::string& get_friendly_name() const;
    virtual bool is_dynamic() const;
    size_t get_instance_id() const;
    virtual std::ostream& write_description(std::ostream& os, uint32_t depth = 0) const;
    const std::vector<std::shared_ptr<Node>>& get_control_dependencies() const;
    const std::vector<Node \*>& get_control_dependents() const;
    void add_control_dependency(std::shared_ptr<Node> node);
    void remove_control_dependency(std::shared_ptr<Node> node);
    void clear_control_dependencies();
    void clear_control_dependents();
    void add_node_control_dependencies(std::shared_ptr<Node> source_node);
    void add_node_control_dependents(std::shared_ptr<Node> source_node);
    void transfer_control_dependents(std::shared_ptr<Node> replacement);
    size_t get_output_size() const;
    const element::Type& get_output_element_type(size_t i) const;
    const element::Type& get_element_type() const;
    const Shape& get_output_shape(size_t i) const;
    const PartialShape& get_output_partial_shape(size_t i) const;
    Output<const Node> get_default_output() const;
    Output<Node> get_default_output();
    virtual size_t get_default_output_index() const;
    size_t no_default_index() const;
    const Shape& get_shape() const;
    descriptor::Tensor& get_output_tensor(size_t i) const;
    descriptor::Tensor& get_input_tensor(size_t i) const;
    std::set<Input<Node>> get_output_target_inputs(size_t i) const;
    size_t get_input_size() const;
    const element::Type& get_input_element_type(size_t i) const;
    const Shape& get_input_shape(size_t i) const;
    const PartialShape& get_input_partial_shape(size_t i) const;
    Node \* get_input_node_ptr(size_t index) const;
    std::shared_ptr<Node> get_input_node_shared_ptr(size_t index) const;
    Output<Node> get_input_source_output(size_t i) const;
    virtual std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& inputs) const = 0;
    std::shared_ptr<Node> copy_with_new_inputs(const OutputVector& new_args) const;

    std::shared_ptr<Node> copy_with_new_inputs(
        const OutputVector& inputs,
        const std::vector<std::shared_ptr<Node>>& control_dependencies
        ) const;

    bool has_same_type(std::shared_ptr<const Node> node) const;
    RTMap& get_rt_info();
    const RTMap& get_rt_info() const;
    NodeVector get_users(bool check_is_used = false) const;
    virtual size_t get_version() const;
    virtual std::shared_ptr<Node> get_default_value() const;
    bool operator < (const Node& other) const;
    std::vector<Input<Node>> inputs();
    std::vector<Input<const Node>> inputs() const;
    std::vector<Output<Node>> input_values() const;
    std::vector<Output<Node>> outputs();
    std::vector<Output<const Node>> outputs() const;
    Input<Node> input(size_t input_index);
    Input<const Node> input(size_t input_index) const;
    Output<Node> input_value(size_t input_index) const;
    Output<Node> output(size_t output_index);
    Output<const Node> output(size_t output_index) const;
    OPENVINO_SUPPRESS_DEPRECATED_START void set_op_annotations(std::shared_ptr<ngraph::op::util::OpAnnotations> op_annotations);
    std::shared_ptr<ngraph::op::util::OpAnnotations> get_op_annotations() const;

    virtual OPENVINO_SUPPRESS_DEPRECATED_END bool match_value(
        ov::pass::pattern::Matcher \* matcher,
        const Output<Node>& pattern_value,
        const Output<Node>& graph_value
        );

    virtual bool match_node(
        ov::pass::pattern::Matcher \* matcher,
        const Output<Node>& graph_value
        );

    static _OPENVINO_HIDDEN_METHODconst ::ov::Node::type_info_t& get_type_info_static();
    virtual const ::ov::Node::type_info_t& get_type_info() const;

Detailed Documentation

Class for constants.

Construction

Constant(const std::shared_ptr<ngraph::runtime::Tensor>& tensor)

Initialize a constant from tensor.

Parameters:

tensor

The tensor with data

template <typename T>
Constant(
    const element::Type& type,
    const Shape& shape,
    const std::vector<T>& values
    )

Constructs a tensor constant.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

values

A vector of literals for initializing the tensor constant. The size of values must match the size of the shape.

Constant(const element::Type& type, const Shape& shape)

Create uninitialized constant.

template <class T, class = typename std::enable_if<std::is_fundamental<T>::value>::type>
Constant(
    const element::Type& type,
    const Shape& shape,
    T value
    )

Constructs a uniform tensor constant.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

value

A scalar for initializing the uniform tensor constant. The value is broadcast to the specified shape.

Constant(
    const element::Type& type,
    const Shape& shape,
    const std::vector<std::string>& values
    )

Constructs a tensor constant This constructor is mainly to support deserialization of constants.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

values

A list of string values to use as the constant data.

Constant(const element::Type& type, const Shape& shape, const void \* data)

Constructs a tensor constant with the supplied data.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

data

A void* to constant data.

template <typename T>
Constant(
    const element::Type& type,
    const Shape& shape,
    std::shared_ptr<ngraph::runtime::SharedBuffer<T>> data
    )

Constructs a tensor constant with the supplied data.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

data

A pointer to pre-allocated shared data.

Methods

virtual void validate_and_infer_types()

Verifies that attributes and inputs are consistent and computes output shapes and element types. Must be implemented by concrete child classes so that it can be run any number of times.

Throws if the node is invalid.

virtual OPENVINO_SUPPRESS_DEPRECATED_START bool evaluate(
    const HostTensorVector& output_values,
    const HostTensorVector& input_values
    ) const

Evaluates the op on input_values putting results in output_values.

Deprecated Use evaluate with ov::Tensor instead

Parameters:

output_values

Tensors for the outputs to compute. One for each result

input_values

Tensors for the inputs. One for each inputs.

Returns:

true if successful

virtual OPENVINO_SUPPRESS_DEPRECATED_END bool has_evaluate() const

Allows to get information about availability of evaluate method for the current operation.

Shape get_shape_val() const

Returns the value of the constant node as a Shape object Can only be used on element::i64 nodes and interprets negative values as zeros.

Strides get_strides_val() const

Returns the value of the constant node as a Strides object Can only be used on element::i64 nodes and interprets negative values as zeros.

Coordinate get_coordinate_val() const

Returns the value of the constant node as a Coordinate object Can only be used on element::i64 nodes and interprets negative values as zeros.

CoordinateDiff get_coordinate_diff_val() const

Returns the value of the constant node as a CoordinateDiff object Can only be used on element::i64 nodes.

AxisVector get_axis_vector_val() const

Returns the value of the constant node as an AxisVector object Can only be used on element::i64 nodes and interprets negative values as zeros.

AxisSet get_axis_set_val() const

Returns the value of the constant node as an AxisSet object Can only be used on element::i64 nodes and interprets negative values as zeros. Repeated values are allowed.

void set_data_shape(const Shape& shape)

Update Constant shape. New shape size must equal to the data elements count.

Parameters:

shape

The shape of the tensor constant.

size_t get_byte_size() const

Return data size in bytes.

std::vector<std::string> get_value_strings() const

Returns:

The initialization literals for the tensor constant.

template <typename T>
std::vector<T> cast_vector() const

Return the Constant ‘s value as a vector cast to type T.

Parameters:

T

Type to which data vector’s entries will be cast.

Returns:

Constant ‘s data vector.

template <typename T>
static std::shared_ptr<Constant> create(
    const element::Type& type,
    const Shape& shape,
    const std::vector<T>& values
    )

Wrapper around constructing a shared_ptr of a Constant.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

values

A vector of values to use as the constant data.

template <typename T>
static std::shared_ptr<Constant> create(
    const element::Type& type,
    const Shape& shape,
    std::initializer_list<T> values
    )

Wrapper around constructing a shared_ptr of a Constant.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

values

An initializer_list of values to use as the constant data.

static std::shared_ptr<Constant> create(
    const element::Type& type,
    const Shape& shape,
    const void \* memory
    )

Wrapper around constructing a shared_ptr of a Constant.

Parameters:

type

The element type of the tensor constant.

shape

The shape of the tensor constant.

memory

An continues memory chunk which contains the constant data.