Constant¶

Constant // Literal constant tensor


Description¶

The output is a tensor initialized from the values attribute.

Attributes¶

Name Type Notes
type ngraph::element::type The element type of the value in the computation
shape ngraph::Shape The shape of the constant
values const std::vector<T>& Constant elements in row-major order. T must be compatible with the element type

Outputs¶

Name Element Type Shape
output type shape

C++ Interface¶

class Constant : public ngraph::op::Op

Class for constants.

Subclassed by ngraph::op::ScalarConstantLikeBase

Public Functions

const NodeTypeInfo &get_type_info() const

Returns the NodeTypeInfo for the node’s class. During transition to type_info, returns a dummy type_info for Node if the class has not been updated yet.

template<typename T>
Constant(const element::Type &type, 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, 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 same initialization value copied across.

Parameters
• type: The element type of the tensor constant.
• shape: The shape of the tensor constant.
• data: A void* to constant data.

void validate_and_infer_types()

Throws if the node is invalid.

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.

vector<string> get_value_strings() const

Return
The initialization literals for the tensor constant.

Public Static Functions

template<typename T>
static std::shared_ptr<op::Constant> create(const element::Type &type, 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<op::Constant> create(const element::Type &type, 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.