Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONNX] Extend ONNX Frontend with BlackmanWindow, HammingWindow and HannWindow operators #19428

Merged
merged 29 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3626da4
ONNX BlackManWindow enabled
siddhant-0707 Aug 10, 2023
799a68e
added a test periodic
siddhant-0707 Aug 10, 2023
48ddce8
Add the license statement
siddhant-0707 Aug 10, 2023
eb607ae
ONNX HammingWindow, HannWindow enabled
siddhant-0707 Aug 25, 2023
70c5d92
minor tests added
siddhant-0707 Aug 26, 2023
98ac0c6
Merge branch 'master' into onnx-new-windows
siddhant-0707 Aug 26, 2023
57925e1
Merge branch 'master' into onnx-new-windows
p-wysocki Aug 30, 2023
d1f763a
made reviewed changes
siddhant-0707 Sep 3, 2023
93f3092
Merge branch 'master' into onnx-new-windows
siddhant-0707 Sep 3, 2023
10b0a8c
made reviewed changes
siddhant-0707 Sep 6, 2023
997d07a
fixed clang-format
siddhant-0707 Sep 6, 2023
c084d3e
Merge branch 'master' into onnx-new-windows
siddhant-0707 Sep 6, 2023
228636f
Merge branch 'master' into onnx-new-windows
siddhant-0707 Sep 7, 2023
5d468a8
Merge branch 'openvinotoolkit:master' into onnx-new-windows
siddhant-0707 Sep 21, 2023
372d931
add OPENVINO_SUPPRESS_DEPRECATED_START
siddhant-0707 Sep 21, 2023
e5237a6
include math.h
siddhant-0707 Sep 22, 2023
80bf2fc
float fix
siddhant-0707 Sep 25, 2023
6d2801a
Merge branch 'openvinotoolkit:master' into onnx-new-windows
siddhant-0707 Sep 30, 2023
bf359ec
fix
siddhant-0707 Oct 2, 2023
8349725
fix namespace to set_1
siddhant-0707 Oct 3, 2023
e2287c1
test fixes
siddhant-0707 Oct 4, 2023
cf486ce
fix cast to output_datatype
siddhant-0707 Oct 6, 2023
898d691
fix, replace cast with ov::convert
siddhant-0707 Oct 11, 2023
081cc1c
fix, use element::f32
siddhant-0707 Oct 11, 2023
342ceb2
major fixes
siddhant-0707 Oct 18, 2023
cfbf2a5
Merge branch 'master' into onnx-new-windows
siddhant-0707 Oct 18, 2023
986629b
fixes
siddhant-0707 Oct 19, 2023
b63907e
Update onnx_import.in.cpp
siddhant-0707 Oct 20, 2023
898c94a
Update onnx_import.in.cpp
siddhant-0707 Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions src/frontends/onnx/frontend/src/op/blackmanwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "op/blackmanwindow.hpp"

#include <memory>

#include "utils/common.hpp"

Check warning on line 8 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:8:-#include "utils/common.hpp"
#include "default_opset.hpp"

Check warning on line 10 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:9:+#include "utils/common.hpp"
namespace ngraph {
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector blackmanwindow(const Node& node) {
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
const auto size = node.get_ng_inputs().at(0);
const auto output_datatype = node.get_attribute_value<int64_t>("output_datatype", 1);
siddhant-0707 marked this conversation as resolved.
Show resolved Hide resolved
const bool periodic = node.get_attribute_value<int64_t>("periodic", 1);

const int64_t a_0 = 0.42, a_1 = -0.5, a_2 = 0.08;
siddhant-0707 marked this conversation as resolved.
Show resolved Hide resolved
const ov::PartialShape shape = size.get_partial_shape();
const std::vector<size_t> axis_lengths = shape.to_shape();

element::Type tensor_type;
switch (output_datatype) {
case 1:

Check warning on line 26 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:26:- case 1: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:27:- tensor_type = element::f32; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:28:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:29:- case 2: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:30:- tensor_type = element::u8; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:31:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:32:- case 3: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:33:- tensor_type = element::i8; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:34:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:35:- case 4: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:36:- tensor_type = element::u16; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:37:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:38:- case 5: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:39:- tensor_type = element::i16; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:40:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:41:- case 6: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:42:- tensor_type = element::i32; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:43:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:44:- case 7: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:45:- tensor_type = element::i64; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:46:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:47:- case 10: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:48:- tensor_type = element::f16; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:49:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:50:- case 11: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:51:- tensor_type = element::f64; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:52:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:53:- case 12: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:54:- tensor_type = element::u32; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:55:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:56:- case 13: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:57:- tensor_type = element::u64; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:58:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:59:- case 16: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:60:- tensor_type = element::bf16; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:61:- break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:62:- default: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:63:- throw std::runtime_error("Unsupported output data type."); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:26:+ case 1: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:27:+ tensor_type = element::f32; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:28:+ break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:29:+ case 2: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:30:+ tensor_type = element::u8; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:31:+ break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:32:+ case 3: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:33:+ tensor_type = element::i8; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:34:+ break; src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:35:+ case 4: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:36:+
tensor_type = element::f32;
break;
case 2:
tensor_type = element::u8;
break;
case 3:
tensor_type = element::i8;
break;
case 4:
tensor_type = element::u16;
break;
case 5:
tensor_type = element::i16;
break;
case 6:
tensor_type = element::i32;
break;
case 7:
tensor_type = element::i64;
break;
case 10:
tensor_type = element::f16;
break;
case 11:
tensor_type = element::f64;
break;
case 12:
tensor_type = element::u32;
break;
case 13:
tensor_type = element::u64;
break;
case 16:
tensor_type = element::bf16;
break;
default:
throw std::runtime_error("Unsupported output data type.");
}

if (periodic) {
siddhant-0707 marked this conversation as resolved.
Show resolved Hide resolved
const auto range = std::make_shared<default_opset::Range>(tensor_type, size, 0, 1);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor_1 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), size));

Check warning on line 69 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:69:- const auto factor_1 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), size)); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:70:- const auto factor_2 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 4), size)); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:69:+ const auto factor_1 = std::make_shared<default_opset::Multiply>( src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:70:+ range, src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:71:+ std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), size)); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:72:+ const auto factor_2 = std::make_shared<default_opset::Multiply>( src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:73:+ range, src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:74:+ std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 4), size));
const auto factor_2 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 4), size));
const auto cos_1 = std::make_shared<default_opset::Cos>(factor_1);
const auto cos_2 = std::make_shared<default_opset::Cos>(factor_2);
const auto scaled_cos_1 = std::make_shared<default_opset::Multiply>(cos_1, a_1);
const auto scaled_cos_2 = std::make_shared<default_opset::Multiply>(cos_2, a_2);
const auto y_values = std::make_shared<default_opset::Add>(std::make_shared<default_opset::Add>(a_0, scaled_cos_1), scaled_cos_2);

Check warning on line 75 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:75:- const auto y_values = std::make_shared<default_opset::Add>(std::make_shared<default_opset::Add>(a_0, scaled_cos_1), scaled_cos_2); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:79:+ const auto y_values = src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:80:+ std::make_shared<default_opset::Add>(std::make_shared<default_opset::Add>(a_0, scaled_cos_1), scaled_cos_2);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);

Check warning on line 77 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:77:- src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:82:+
return {output};
} else {
const auto range = std::make_shared<default_opset::Range>(tensor_type, size, 0, 1);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor_1 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), std::make_shared<default_opset::Subtract>(size, 1)));

Check warning on line 82 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:82:- const auto factor_1 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), std::make_shared<default_opset::Subtract>(size, 1))); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:83:- const auto factor_2 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 4), std::make_shared<default_opset::Subtract>(size, 1))); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:87:+ const auto factor_1 = std::make_shared<default_opset::Multiply>( src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:88:+ range, src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:89:+ std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:90:+ std::make_shared<default_opset::Subtract>(size, 1))); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:91:+ const auto factor_2 = std::make_shared<default_opset::Multiply>( src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:92:+ range, src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:93:+ std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 4), src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:94:+ std::make_shared<default_opset::Subtract>(size, 1)));
const auto factor_2 = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 4), std::make_shared<default_opset::Subtract>(size, 1)));
const auto cos_1 = std::make_shared<default_opset::Cos>(factor_1);
const auto cos_2 = std::make_shared<default_opset::Cos>(factor_2);
const auto scaled_cos_1 = std::make_shared<default_opset::Multiply>(cos_1, a_1);
const auto scaled_cos_2 = std::make_shared<default_opset::Multiply>(cos_2, a_2);
const auto y_values = std::make_shared<default_opset::Add>(std::make_shared<default_opset::Add>(a_0, scaled_cos_1), scaled_cos_2);

Check warning on line 88 in src/frontends/onnx/frontend/src/op/blackmanwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:88:- const auto y_values = std::make_shared<default_opset::Add>(std::make_shared<default_opset::Add>(a_0, scaled_cos_1), scaled_cos_2); src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:99:+ const auto y_values = src/frontends/onnx/frontend/src/op/blackmanwindow.cpp:100:+ std::make_shared<default_opset::Add>(std::make_shared<default_opset::Add>(a_0, scaled_cos_1), scaled_cos_2);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);

return {output};
}
}
} // namespace set_1
} // namespace op
} // namespace onnx_import
} // namespace ngraph
siddhant-0707 marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions src/frontends/onnx/frontend/src/op/blackmanwindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
siddhant-0707 marked this conversation as resolved.
Show resolved Hide resolved

OutputVector blackmanwindow(const Node& node);

} // namespace set_1
} // namespace op
} // namespace onnx_import
} // namespace ngraph
93 changes: 93 additions & 0 deletions src/frontends/onnx/frontend/src/op/hammingwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "op/hammingwindow.hpp"

#include <memory>

#include "utils/common.hpp"

Check warning on line 8 in src/frontends/onnx/frontend/src/op/hammingwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/hammingwindow.cpp:8:-#include "utils/common.hpp"
#include "default_opset.hpp"

Check warning on line 10 in src/frontends/onnx/frontend/src/op/hammingwindow.cpp

View workflow job for this annotation

GitHub Actions / clang-format

[reviewdog-suggester] reported by reviewdog 🐶 Raw Output: src/frontends/onnx/frontend/src/op/hammingwindow.cpp:9:+#include "utils/common.hpp"
namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector hammingwindow(const Node& node) {
const auto size = node.get_ng_inputs().at(0);
const auto output_datatype = node.get_attribute_value<int64_t>("output_datatype", 1);
const bool periodic = node.get_attribute_value<int64_t>("periodic", 1);

const float a_0 = 25.0 / 46.0;
const float a_1 = 1.0 - a_0;

const ov::PartialShape shape = size.get_partial_shape();
const std::vector<size_t> axis_lengths = shape.to_shape();

element::Type tensor_type;
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
switch (output_datatype) {
case 1:
tensor_type = element::f32;
break;
case 2:
tensor_type = element::u8;
break;
case 3:
tensor_type = element::i8;
break;
case 4:
tensor_type = element::u16;
break;
case 5:
tensor_type = element::i16;
break;
case 6:
tensor_type = element::i32;
break;
case 7:
tensor_type = element::i64;
break;
case 10:
tensor_type = element::f16;
break;
case 11:
tensor_type = element::f64;
break;
case 12:
tensor_type = element::u32;
break;
case 13:
tensor_type = element::u64;
break;
case 16:
tensor_type = element::bf16;
break;
default:
throw std::runtime_error("Unsupported output data type.");
}

if (periodic) {
const auto range = std::make_shared<default_opset::Range>(tensor_type, size, 0, 1);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), size));
const auto cos = std::make_shared<default_opset::Cos>(factor);
const auto scaled_cos = std::make_shared<default_opset::Multiply>(cos, a_1);
const auto y_values = std::make_shared<default_opset::Subtract>(a_0, scaled_cos);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);

return {output};
} else {
const auto range = std::make_shared<default_opset::Range>(tensor_type, size, 0, 1);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), std::make_shared<default_opset::Subtract>(size, 1)));
const auto cos = std::make_shared<default_opset::Cos>(factor);
const auto scaled_cos = std::make_shared<default_opset::Multiply>(cos, a_1);
const auto y_values = std::make_shared<default_opset::Subtract>(a_0, scaled_cos);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);

return {output};
}
}
} // namespace set_1
} // namespace op
} // namespace onnx_import
} // namespace ngraph
19 changes: 19 additions & 0 deletions src/frontends/onnx/frontend/src/op/hammingwindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {

OutputVector hammingwindow(const Node& node);

} // namespace set_1
} // namespace op
} // namespace onnx_import
} // namespace ngraph
93 changes: 93 additions & 0 deletions src/frontends/onnx/frontend/src/op/hannwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "op/hannwindow.hpp"

#include <memory>

#include "utils/common.hpp"
#include "default_opset.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {
OutputVector hannwindow(const Node& node) {
const auto size = node.get_ng_inputs().at(0);
const auto output_datatype = node.get_attribute_value<int64_t>("output_datatype", 1);
const bool periodic = node.get_attribute_value<int64_t>("periodic", 1);

const float a_0 = 0.5;
const float a_1 = 0.5;

const ov::PartialShape shape = size.get_partial_shape();
const std::vector<size_t> axis_lengths = shape.to_shape();

element::Type tensor_type;
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
switch (output_datatype) {
case 1:
tensor_type = element::f32;
break;
case 2:
tensor_type = element::u8;
break;
case 3:
tensor_type = element::i8;
break;
case 4:
tensor_type = element::u16;
break;
case 5:
tensor_type = element::i16;
break;
case 6:
tensor_type = element::i32;
break;
case 7:
tensor_type = element::i64;
break;
case 10:
tensor_type = element::f16;
break;
case 11:
tensor_type = element::f64;
break;
case 12:
tensor_type = element::u32;
break;
case 13:
tensor_type = element::u64;
break;
case 16:
tensor_type = element::bf16;
break;
default:
throw std::runtime_error("Unsupported output data type.");
}

if (periodic) {
const auto range = std::make_shared<default_opset::Range>(tensor_type, size, 0, 1);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), size));
const auto cos = std::make_shared<default_opset::Cos>(factor);
const auto scaled_cos = std::make_shared<default_opset::Multiply>(cos, a_1);
const auto y_values = std::make_shared<default_opset::Subtract>(a_0, scaled_cos);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);

return {output};
} else {
const auto range = std::make_shared<default_opset::Range>(tensor_type, size, 0, 1);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor = std::make_shared<default_opset::Multiply>(range, std::make_shared<default_opset::Divide>(std::make_shared<default_opset::Multiply>(pi, 2), std::make_shared<default_opset::Subtract>(size, 1)));
const auto cos = std::make_shared<default_opset::Cos>(factor);
const auto scaled_cos = std::make_shared<default_opset::Multiply>(cos, a_1);
const auto y_values = std::make_shared<default_opset::Subtract>(a_0, scaled_cos);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);

return {output};
}
}
} // namespace set_1
} // namespace op
} // namespace onnx_import
} // namespace ngraph
19 changes: 19 additions & 0 deletions src/frontends/onnx/frontend/src/op/hannwindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_1 {

OutputVector hannwindow(const Node& node);

} // namespace set_1
} // namespace op
} // namespace onnx_import
} // namespace ngraph
6 changes: 6 additions & 0 deletions src/frontends/onnx/frontend/src/ops_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "op/average_pool.hpp"
#include "op/batch_norm.hpp"
#include "op/bitshift.hpp"
#include "op/blackmanwindow.hpp"
#include "op/cast.hpp"
#include "op/cast_like.hpp"
#include "op/ceil.hpp"
Expand Down Expand Up @@ -75,6 +76,8 @@
#include "op/greater.hpp"
#include "op/grid_sample.hpp"
#include "op/gru.hpp"
#include "op/hammingwindow.hpp"
#include "op/hannwindow.hpp"
#include "op/hard_sigmoid.hpp"
#include "op/hard_swish.hpp"
#include "op/hardmax.hpp"
Expand Down Expand Up @@ -343,6 +346,7 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("BatchNormalization", 1, batch_norm);
REGISTER_OPERATOR("BatchNormalization", 7, batch_norm);
REGISTER_OPERATOR("BitShift", 1, bitshift);
REGISTER_OPERATOR("BlackManWindow", 1, blackmanwindow);
siddhant-0707 marked this conversation as resolved.
Show resolved Hide resolved
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
REGISTER_OPERATOR("Cast", 1, cast);
REGISTER_OPERATOR("CastLike", 1, cast_like);
REGISTER_OPERATOR("Ceil", 1, ceil);
Expand Down Expand Up @@ -390,6 +394,8 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("Greater", 1, greater);
REGISTER_OPERATOR("GridSample", 1, grid_sample);
REGISTER_OPERATOR("GRU", 1, gru);
REGISTER_OPERATOR("HannWindow", 1, hannwindow);
REGISTER_OPERATOR("HammingWindow", 1, hammingwindow);
REGISTER_OPERATOR("Hardmax", 1, hardmax);
REGISTER_OPERATOR("Hardmax", 13, hardmax);
REGISTER_OPERATOR("HardSigmoid", 1, hard_sigmoid);
Expand Down
Loading
Loading