Skip to content

Commit

Permalink
[core] Remove custom ov::optional
Browse files Browse the repository at this point in the history
As CPP17 is the default standard of OpenVINO, there is no need to use
the custom ov::optional struct anymore.

Note that the `bool` operator of std::optional is marked as `explicit`
while the original implementation is not.
  • Loading branch information
oToToT committed Feb 19, 2025
1 parent 18e97b6 commit 683cfc2
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "transformations/symbolic_transformations/symbol_optimization.hpp"

#include <optional>

#include "itt.hpp"
#include "openvino/core/bound_evaluation_util.hpp"
#include "openvino/core/rt_info.hpp"
Expand Down Expand Up @@ -379,7 +381,7 @@ struct OutputValue {
});
}

static ov::optional<OutputValue> make(const ov::Output<ov::Node>& output) {
static std::optional<OutputValue> make(const ov::Output<ov::Node>& output) {
auto symbols = output.get_tensor().get_value_symbol();
if (symbols.empty() || symbols.size() == 1)
return {};
Expand Down
9 changes: 5 additions & 4 deletions src/core/dev_api/openvino/core/tensor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#pragma once

#include <optional>

#include "openvino/op/constant.hpp"
#include "ov_optional.hpp"

namespace ov {
namespace util {
Expand All @@ -15,7 +16,7 @@ template <typename T>
OPENVINO_API Tensor greater_equal(const ov::Tensor& lhs, const T& element);
OPENVINO_API bool reduce_and(const ov::Tensor& t);
template <typename T>
OPENVINO_API ov::optional<std::vector<T>> to_vector(const ov::Tensor& t);
OPENVINO_API std::optional<std::vector<T>> to_vector(const ov::Tensor& t);

template <typename T>
Tensor make_tensor_of_value(const element::Type_t& et, const T& value, Shape shape = {}) {
Expand All @@ -34,8 +35,8 @@ Tensor greater_equal(const ov::Tensor& lhs, const T& element) {
}

template <typename T>
ov::optional<std::vector<T>> to_vector(const ov::Tensor& t) {
ov::optional<std::vector<T>> result;
std::optional<std::vector<T>> to_vector(const ov::Tensor& t) {
std::optional<std::vector<T>> result;
if (t)
result = ov::op::v0::Constant(t).cast_vector<T>();
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//
#pragma once

#include <optional>

#include "convolution_backprop_shape_inference_util.hpp"
#include "convolution_shape_inference_util.hpp"
#include "openvino/op/convolution.hpp"
Expand All @@ -22,7 +24,7 @@ std::vector<TRShape> shape_infer(const ConvolutionBackpropData* op,
NODE_VALIDATION_CHECK(op, inputs_count >= 2);
using namespace ov::util;

ov::optional<TRShape> out_spatial_shape;
std::optional<TRShape> out_spatial_shape;
if (has_spatial_shape) {
const auto& spatial_shape = input_shapes[2];
NODE_VALIDATION_CHECK(op,
Expand Down
4 changes: 3 additions & 1 deletion src/core/shape_inference/include/fft_common_validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include <optional>

#include "openvino/core/axis_vector.hpp"
#include "openvino/core/validation_util.hpp"
#include "openvino/op/util/fft_base.hpp"
Expand Down Expand Up @@ -99,7 +101,7 @@ void validate_signal_size(const ov::op::util::FFTBase* op,
template <class T>
void shape_validation(const ov::op::util::FFTBase* op,
const std::vector<T>& input_shapes,
ov::optional<std::vector<int64_t>>& axes,
std::optional<std::vector<int64_t>>& axes,
FFTKind fft_kind) {
const auto& input_shape = input_shapes[0];
const auto& axes_shape = input_shapes[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//
#pragma once

#include <optional>

#include "convolution_backprop_shape_inference.hpp"
#include "openvino/op/group_conv.hpp"
#include "utils.hpp"
Expand Down Expand Up @@ -33,7 +35,7 @@ std::vector<TRShape> shape_infer(const GroupConvolutionBackpropData* op,
NODE_VALIDATION_CHECK(op, inputs_count >= 2);
using namespace ov::util;

ov::optional<TRShape> out_spatial_shape;
std::optional<TRShape> out_spatial_shape;
if (has_spatial_shape) {
const auto& spatial_shape = input_shapes[2];
NODE_VALIDATION_CHECK(op,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#pragma once

#include <algorithm>
#include <openvino/op/interpolate.hpp>
#include <optional>

#include "dimension_util.hpp"
#include "pooling_shape_inference_util.hpp"
#include "openvino/op/interpolate.hpp"
#include "utils.hpp"

namespace ov {
Expand Down Expand Up @@ -153,8 +153,8 @@ TRShape make_padded_shape(const TShape& input, TInputIter pads_begin, TInputIter
* @return Not null pointer with axes values or null pointer if can't get axes from input.
*/
template <class TShape, class TRes = std::vector<int64_t>>
ov::optional<TRes> get_axes(const Node* const op, size_t port, bool has_axes, size_t rank, const ITensorAccessor& ta) {
ov::optional<TRes> axes;
std::optional<TRes> get_axes(const Node* const op, size_t port, bool has_axes, size_t rank, const ITensorAccessor& ta) {
std::optional<TRes> axes;
if (has_axes) {
using TAxis = typename TRes::value_type;
axes = std::move(get_input_const_data_as<TShape, TAxis, TRes>(op, port, ta));
Expand Down
139 changes: 0 additions & 139 deletions src/core/shape_inference/include/ov_optional.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/shape_inference/include/range_shape_inference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ std::vector<TRShape> range_shape_infer(const Node* op,

output_shapes[0] = TRShape{static_cast<uint32_t>(strided)};
} else {
symbol_propagation(op, output_shapes, start, step, start_val, step_val);
symbol_propagation(op, output_shapes, start, step, start_val.has_value(), step_val.has_value());
}
return output_shapes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <cmath>
#include <optional>

#include "openvino/op/segment_max.hpp"
#include "utils.hpp"
Expand Down Expand Up @@ -50,7 +51,7 @@ std::vector<TRShape> shape_infer(const SegmentMax* op,

// validate num_segments input
const auto num_segments_available = op->inputs().size() == 3;
ov::optional<TRShape> num_segments;
std::optional<TRShape> num_segments;
if (num_segments_available) {
num_segments = get_input_const_data_as_shape<TRShape>(op, 2, tensor_accessor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#pragma once

#include <array>
#include <openvino/op/strided_slice.hpp>
#include <optional>

#include "openvino/op/strided_slice.hpp"
#include "slice_shape_inference_utils.hpp"
#include "utils.hpp"

Expand Down Expand Up @@ -61,7 +62,7 @@ std::vector<TRShape> shape_infer(const StridedSlice* op,
const auto begin = get_input_bounds<TRShape, int64_t>(op, 1, ta);
const auto end = get_input_bounds<TRShape, int64_t>(op, 2, ta);

ov::optional<std::vector<int64_t>> strides;
std::optional<std::vector<int64_t>> strides;
if (input_shapes.size() > 3) {
strides = get_input_const_data_as<TRShape, int64_t>(op, 3, ta);
} else if (begin) {
Expand Down
Loading

0 comments on commit 683cfc2

Please sign in to comment.