Class ov::op::v0::Constant#

class Constant : public ov::op::Op#

Class for constants.

Public Functions

Constant(const ov::Tensor &tensor)#

Initialize a constant from ov::Tensor.

Parameters:

tensor – The ov::Tensor with data

template<typename T>
inline 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>
inline 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.

virtual void validate_and_infer_types() override#

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 bool evaluate(ov::TensorVector &outputs, const ov::TensorVector &inputs) const override#

Evaluates the op on input_values putting results in output_values.

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 bool has_evaluate() const override#

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.

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>
inline std::vector<T> cast_vector(int64_t num_elements = -1) const#

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

Template Parameters:

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

Parameters:

num_elements – (Optional) Number of elements to cast. In default case returns all elements

Returns:

Constant’s data vector.

const Tensor get_tensor_view() const#

Get view on constant data as tensor.

Returns:

OV::Tensor with constant data.

const Strides &get_strides() const#
Returns:

Constant’s strides in bytes.

Public Static Functions

template<typename T>
static inline 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 inline 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 inline 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.