namespace ov::op::util

Overview

namespace util {

// namespaces

namespace ov::op::util::detail;
namespace ov::op::util::embedding;
namespace ov::op::util::error;
namespace ov::op::util::rfft_common_validation;

// typedefs

typedef std::shared_ptr<Node>(\*)(const std::shared_ptr<Node>&, float, float) ActivationFunctionType;
typedef std::vector<util::SubGraphOp::InputDescription::Ptr> InputDescriptionVector;
typedef std::vector<util::SubGraphOp::OutputDescription::Ptr> OutputDescriptionVector;
typedef std::vector<Variable::Ptr> VariableVector;
typedef std::unordered_map<Variable::Ptr, VariableValue::Ptr> VariableMap;

// enums

enum LSTMPeepholesFormat;
enum LSTMWeightsFormat;

// structs

struct ClipNegative;
template <class T>
struct GetK;
struct VariableInfo;

// classes

class ActivationFunction;
class ArithmeticReduction;
class ArithmeticReductionKeepDims;
class AssignBase;
class BinaryElementwiseArithmetic;
class BinaryElementwiseComparison;
class BinaryElementwiseLogical;
class BroadcastBase;
class ConvertColorI420Base;
class ConvertColorNV12Base;
class ConvolutionBackPropBase;
class ConvolutionBase;
class ConvolutionFwdPropBase;
class DeformableConvolutionBase;
class DetectionOutputBase;
class EmbeddingBagOffsetsBase;
class EmbeddingBagPackedBase;
class FFTBase;
class FrameworkNode;
class FrameworkNodeAttrs;
class GatherBase;
class GatherNDBase;
class IndexReduction;
class InterpolateBase;
class LogicalReduction;
class LogicalReductionKeepDims;
class MaxPoolBase;
class MultiSubGraphOp;
class MulticlassNmsBase;
class RNNCellBase;
class ReadValueBase;
class ReductionBase;
class ScatterBase;
class ScatterNDBase;
class ShapeOfBase;
class SubGraphOp;
class TopKBase;
class UnaryElementwiseArithmetic;
class Variable;
class VariableContext;
class VariableExtension;
class VariableValue;

// global variables

constexpr size_t num_spatial_undefined = std::numeric_limits<size_t>::max();
constexpr size_t spatial_dim_offset = 2;

// global functions

template <class T>
bool normalize_single_value(
    std::vector<T> vec,
    float& value
    );

template <class T>
bool has_op_with_type(const std::shared_ptr<const ov::Model>& function);

bool has_decompression_converts(const std::shared_ptr<const ov::Model>& function);
std::string create_ie_output_name(const Output<const Node>& output);
std::string create_ie_output_name(const Output<Node>& output);
std::string get_ie_output_name(const Output<const Node>& output);
std::string get_ie_output_name(const Output<Node>& output);

template <typename T>
bool has_constant_value(
    const std::shared_ptr<Node>& node,
    const T value,
    T epsilon = std::numeric_limits<T>::epsilon()
    );

template <typename T>
bool has_constant_value(
    const std::shared_ptr<Node>& node,
    const std::vector<T> values,
    T epsilon = std::numeric_limits<T>::epsilon()
    );

bool get_single_value(
    const std::shared_ptr<opset4::Constant>& const_node,
    float& value
    );

std::shared_ptr<Node> normalize_constant(
    const std::shared_ptr<opset4::Constant>& constant,
    const PartialShape& shape
    );

std::shared_ptr<Node> broadcastTo(const Output<Node>& input, const Shape& shape);
std::shared_ptr<Node> reshapeTo(const Output<Node>& input, const Shape& shape);

bool constantIsEqualTo(
    const std::shared_ptr<opset4::Constant>& const_node,
    float value,
    float eps = 1e-5
    );

bool has_f16_constants(const std::shared_ptr<const ov::Model>& function);

bool check_for_broadcast(
    const PartialShape& ref_shape,
    const PartialShape& other_shape
    );

std::shared_ptr<Node> activation(
    const std::string& activation_name,
    const Output<Node>& apply_to
    );

bool is_seq_len_provided(
    const std::shared_ptr<Node>& seq_len_input,
    int64_t max_seq_len
    );

std::shared_ptr<Node> try_fold_unary_output(const std::shared_ptr<Node>& node);

std::shared_ptr<Node> clone_try_fold(
    const std::shared_ptr<Node>& node,
    const OutputVector& inputs
    );

bool shapes_equal_except_dynamic_expected_batch(
    const PartialShape& expected,
    const PartialShape& actual
    );

void visit_shape_path(
    ov::Node \* node,
    std::unordered_set<ov::Node \*>& visited,
    std::function<void(ov::Node \*)> func
    );

template <typename T, typename... Args>
std::shared_ptr<Node> make_try_fold(Args&&... args);

template <class T>
Output<Node> eltwise_fold(
    const Output<Node>& input0,
    const Output<Node>& input1
    );

std::vector<Input<Node>> get_node_target_inputs(const std::shared_ptr<Node>& node);

std::shared_ptr<Node> node_to_get_shape_value_of_indices_from_shape_node(
    const std::shared_ptr<Node>& shape_node,
    const std::vector<size_t>& indices
    );

std::shared_ptr<Node> node_to_get_shape_value_of_indices_from_shape_source(
    const Output<Node>& shape_source,
    const std::vector<size_t>& indices
    );

bool is_dequantization_subgraph(const Output<Node>& node);

bool can_eliminate_eltwise_node(
    const std::shared_ptr<Node>& eltwise,
    const Output<Node>& constant,
    const Output<Node>& non_constant_input
    );

ActivationFunction get_activation_func_by_name(const std::string& func_name);
std::tuple<element::Type, PartialShape> validate_and_infer_elementwise_args(Node \* node);
OPENVINO_API bool is_unary_elementwise_arithmetic(const Node \* node);
OPENVINO_API bool is_binary_elementwise_arithmetic(const Node \* node);
OPENVINO_API bool is_binary_elementwise_comparison(const Node \* node);
OPENVINO_API bool is_binary_elementwise_logical(const Node \* node);
OPENVINO_API bool supports_auto_broadcast(const Node \* node);
OPENVINO_API bool is_op(const Node \* node);
OPENVINO_API bool is_parameter(const Node \* node);
OPENVINO_API bool is_output(const Node \* node);
OPENVINO_API bool is_sink(const Node \* node);
OPENVINO_API bool is_constant(const Node \* node);
OPENVINO_API bool is_commutative(const Node \* node);
OPENVINO_API bool is_unary_elementwise_arithmetic(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_binary_elementwise_arithmetic(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_binary_elementwise_comparison(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_binary_elementwise_logical(const std::shared_ptr<Node>& node);
OPENVINO_API bool supports_auto_broadcast(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_op(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_parameter(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_output(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_sink(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_constant(const std::shared_ptr<Node>& node);
OPENVINO_API bool is_commutative(const std::shared_ptr<Node>& node);

std::shared_ptr<Node> OPENVINO_API convert_lstm_node_format(
    const Output<Node>& node,
    LSTMWeightsFormat from_format,
    LSTMWeightsFormat to_format = LSTMWeightsFormat::FICO,
    int64_t axis = 0
    );

std::shared_ptr<Node> OPENVINO_API convert_lstm_peepholes_format(
    const Output<Node>& node,
    LSTMPeepholesFormat from_format,
    LSTMPeepholesFormat to_format = LSTMPeepholesFormat::FIO,
    int64_t axis = 0
    );

template <typename T>
void validate_target_shape_none(
    const ov::Node \* op,
    const T& arg_shape,
    const AxisVector& axes_mapping_val,
    const T& target_input_shape
    );

template <typename T>
void validate_target_shape_numpy(
    const ov::Node \* op,
    const T& arg_shape,
    const T& target_input_shape
    );

template <typename T>
void set_result_shape_pdpd(
    const ov::Node \* op,
    const T& arg0_shape,
    const T& target_input_shape,
    T& result_shape,
    const ov::op::BroadcastModeSpec& broadcast_spec
    );

template <typename T>
void set_result_shape_bidirectional(
    const ov::Node \* op,
    const T& arg_shape,
    T& target_input_shape,
    T& result_shape
    );

template <class T>
void broadcast_base_shape_infer(
    const ov::op::util::BroadcastBase \* op,
    const std::vector<T>& input_shapes,
    std::vector<T>& output_shapes,
    const std::map<size_t, std::shared_ptr<ngraph::runtime::HostTensor>>& constant_data = {}
    );

template <class TShape>
size_t num_spatial_from_shapes(
    const TShape& data_shape,
    const TShape& filter_shape,
    const size_t filter_non_spatial_dims_count
    );

bool is_attr_validation_required(const ConvolutionBase \* op);
size_t get_num_spatial(const ConvolutionBase \* op);

template <class TShape>
std::vector<TShape> shape_infer(
    const DeformableConvolutionBase \* op,
    const std::vector<TShape>& input_shapes,
    CoordinateDiff& pads_begin,
    CoordinateDiff& pads_end,
    const std::map<size_t, HostTensorPtr>& constant_data = {}
    );

template <
    typename T,
    typename V = typename std::iterator_traits<typename T::iterator>::value_type::value_type
    >
void compute_num_classes(
    const DetectionOutputBase \* op,
    const DetectionOutputBase::AttributesBase& attrs,
    const std::vector<T>& input_shapes,
    V& num_classes,
    V& num_prior_boxes
    );

template <class T>
void shape_infer_base(
    const DetectionOutputBase \* op,
    const DetectionOutputBase::AttributesBase& attrs,
    const std::vector<T>& input_shapes,
    std::vector<T>& output_shapes,
    int64_t attribute_num_classes
    );

template <class TShape>
std::vector<TShape> shape_infer(
    const ov::op::util::EmbeddingBagOffsetsBase \* op,
    const std::vector<TShape>& input_shapes
    );

template <class TShape>
void shape_infer(
    const ov::op::util::EmbeddingBagOffsetsBase \* op,
    const std::vector<TShape>& input_shapes,
    std::vector<TShape>& output_shapes
    );

template <class TShape>
std::vector<TShape> shape_infer(
    const ov::op::util::EmbeddingBagPackedBase \* op,
    const std::vector<TShape>& input_shapes
    );

template <class TShape>
void shape_infer(
    const ov::op::util::EmbeddingBagPackedBase \* op,
    const std::vector<TShape>& input_shapes,
    std::vector<TShape>& output_shapes
    );

template <class T>
void check_1D_or_scalar_shape(
    const ov::op::v9::Eye \* op,
    const T& input_shape,
    const std::string& name
    );

template <class T>
void shape_infer(
    const ov::op::util::FFTBase \* op,
    const std::vector<T>& input_shapes,
    std::vector<T>& output_shapes,
    const std::map<size_t, std::shared_ptr<ngraph::runtime::HostTensor>>& constant_data = {}
    );

template <class T>
void shape_infer(
    const GatherBase \* op,
    const std::vector<T>& input_shapes,
    std::vector<T>& output_shapes,
    const std::map<size_t, std::shared_ptr<ngraph::runtime::HostTensor>>& constant_data = {}
    );

template <typename T>
void correct_pads_attr(
    const util::InterpolateBase \* op,
    std::vector<size_t>& pads_begin,
    std::vector<size_t>& pads_end,
    const std::vector<T>& input_shapes
    );

int64_t multiply_bound_and_scale(int64_t bound, float scale);

template <typename T>
void infer_using_scales(
    T& output_shape,
    const std::vector<int64_t>& axes,
    const std::vector<float>& scales
    );

template <class T>
void shape_infer(
    const ov::op::util::MulticlassNmsBase \* op,
    const std::vector<T>& input_shapes,
    std::vector<T>& output_shapes,
    bool static_output = false,
    bool ignore_bg_class = false
    );

template <class TShape>
std::vector<TShape> shape_infer(
    const util::TopKBase \* op,
    const std::vector<TShape>& input_shapes,
    const std::map<size_t, HostTensorPtr>& constant_data = {}
    );

} // namespace util

Detailed Documentation

Global Functions

ActivationFunction get_activation_func_by_name(const std::string& func_name)

Gets the activation function by name.

Parameters:

func_name

The function name

UnknownActivationFunction

When provided func_name is unknown.

Returns:

The activation function object.

std::shared_ptr<Node> OPENVINO_API convert_lstm_node_format(
    const Output<Node>& node,
    LSTMWeightsFormat from_format,
    LSTMWeightsFormat to_format = LSTMWeightsFormat::FICO,
    int64_t axis = 0
    )

Change data format of provided node.

Parameters:

node

The input node to be permuted.

from_format

Original node weights format.

to_format

Weights format to convert to.

Returns:

Node representing reshaped tensor according to to_format weights format.

template <class TShape>
size_t num_spatial_from_shapes(
    const TShape& data_shape,
    const TShape& filter_shape,
    const size_t filter_non_spatial_dims_count
    )

Get num of spatial form convolution operator.

Tries get value from operator member if is not deduced (has -1 value) then tries evaluate it from input shapes.

Parameters:

TConv

Convolution type (this function must be a friend of TConv to access private member).

TShape

Shape type.

op

Pointer to convolution operator.

data_shape

Input data shape.

flter_shape

Input filter shape.

Returns:

Value of spatial dimension number or infinite bound (-1) if cannot evaluate.

bool is_attr_validation_required(const ConvolutionBase \* op)

Checks if validation attributes is required.

Parameters:

op

Pointer to convolution base operator.

Returns:

True if internal number of spatial dimension not defined otherwise false.

size_t get_num_spatial(const ConvolutionBase \* op)

Get the num spatil object.

Parameters:

op

Returns:

size_t

template <class TShape>
std::vector<TShape> shape_infer(
    const util::TopKBase \* op,
    const std::vector<TShape>& input_shapes,
    const std::map<size_t, HostTensorPtr>& constant_data = {}
    )

TopK shape inference.

Parameters:

TShape

Type of shape.

op

Pointer to TopK operator.

input_shapes

Input shapes of TopK.

constant_data

Map of constant data. DEfault empty.

Returns:

Vector of output shapes for