From: Ilya Churaev Date: Mon, 6 Jul 2020 03:18:45 +0000 (+0300) Subject: Remove atan2 (#1184) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84f7cd2c02546a343a7e16965c8889ba4e43c489;p=platform%2Fupstream%2Fdldt.git Remove atan2 (#1184) --- diff --git a/ngraph/src/ngraph/CMakeLists.txt b/ngraph/src/ngraph/CMakeLists.txt index 723e7e463..c11a6f81d 100644 --- a/ngraph/src/ngraph/CMakeLists.txt +++ b/ngraph/src/ngraph/CMakeLists.txt @@ -143,8 +143,6 @@ set (SRC op/atan.hpp op/atanh.cpp op/atanh.hpp - op/atan2.cpp - op/atan2.hpp op/avg_pool.cpp op/avg_pool.hpp op/batch_norm.cpp diff --git a/ngraph/src/ngraph/op/atan2.cpp b/ngraph/src/ngraph/op/atan2.cpp deleted file mode 100644 index a2900e763..000000000 --- a/ngraph/src/ngraph/op/atan2.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//***************************************************************************** - -#include "ngraph/op/atan2.hpp" -#include "ngraph/op/add.hpp" -#include "ngraph/op/divide.hpp" -#include "ngraph/op/multiply.hpp" -#include "ngraph/op/negative.hpp" -#include "ngraph/op/sqrt.hpp" -#include "ngraph/op/subtract.hpp" - -using namespace std; -using namespace ngraph; - -constexpr NodeTypeInfo op::Atan2::type_info; - -op::v0::Atan2::Atan2(const Output& y, const Output& x, const AutoBroadcastSpec& autob) - : BinaryElementwiseArithmetic(y, x, autob) -{ - constructor_validate_and_infer_types(); -} - -shared_ptr op::v0::Atan2::clone_with_new_inputs(const OutputVector& new_args) const -{ - check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), this->get_autob()); -} - -void op::v0::Atan2::generate_adjoints(autodiff::Adjoints& adjoints, const OutputVector& deltas) -{ - if (get_autob().m_type != op::AutoBroadcastType::NONE) - { - throw ngraph_error("Autodiff not supported with auto broadcasting"); - } - auto y = input_value(0); - auto x = input_value(1); - auto delta_over_r = deltas.at(0) / (x * x + y * y); - adjoints.add_delta(y, x * delta_over_r); - adjoints.add_delta(x, -y * delta_over_r); -} - -bool op::v0::Atan2::visit_attributes(AttributeVisitor& visitor) -{ - BinaryElementwiseArithmetic::visit_attributes(visitor); - return true; -} diff --git a/ngraph/src/ngraph/op/atan2.hpp b/ngraph/src/ngraph/op/atan2.hpp deleted file mode 100644 index 067e92b12..000000000 --- a/ngraph/src/ngraph/op/atan2.hpp +++ /dev/null @@ -1,59 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//***************************************************************************** - -#pragma once - -#include - -#include "ngraph/op/util/binary_elementwise_arithmetic.hpp" - -namespace ngraph -{ - namespace op - { - namespace v0 - { - /// \brief Elementwise full arctan operation - class NGRAPH_API Atan2 : public util::BinaryElementwiseArithmetic - { - public: - static constexpr NodeTypeInfo type_info{"Atan2", 0}; - const NodeTypeInfo& get_type_info() const override { return type_info; } - Atan2() - : util::BinaryElementwiseArithmetic(AutoBroadcastSpec::NONE) - { - } - - /// \brief atan2(y,x) is the angle from the origin to the point (x,y) (note reversed - /// order). - /// - /// \param y - /// \param x - Atan2(const Output& y, - const Output& x, - const AutoBroadcastSpec& autob = AutoBroadcastSpec()); - std::shared_ptr - clone_with_new_inputs(const OutputVector& new_args) const override; - bool visit_attributes(AttributeVisitor& visitor) override; - - protected: - virtual void generate_adjoints(autodiff::Adjoints& adjoints, - const OutputVector& deltas) override; - }; - } - using v0::Atan2; - } -} diff --git a/ngraph/src/ngraph/op/op_version_tbl.hpp b/ngraph/src/ngraph/op/op_version_tbl.hpp index 0838c5ca4..0a95bf6ca 100644 --- a/ngraph/src/ngraph/op/op_version_tbl.hpp +++ b/ngraph/src/ngraph/op/op_version_tbl.hpp @@ -41,7 +41,6 @@ NGRAPH_OP(Asin, ngraph::op::v0, 0) NGRAPH_OP(Asinh, ngraph::op::v3, 3) NGRAPH_OP(Atan, ngraph::op::v0, 0) NGRAPH_OP(Atanh, ngraph::op::v3, 3) -NGRAPH_OP(Atan2, ngraph::op::v0, 0) NGRAPH_OP(AvgPool, ngraph::op::v1, 1) NGRAPH_OP(BatchMatMul, ngraph::op::v0, 0) NGRAPH_OP(BatchMatMulTranspose, ngraph::op::v0, 0) diff --git a/ngraph/src/ngraph/ops.hpp b/ngraph/src/ngraph/ops.hpp index fbe0f29a2..3c107da91 100644 --- a/ngraph/src/ngraph/ops.hpp +++ b/ngraph/src/ngraph/ops.hpp @@ -32,7 +32,6 @@ #include "ngraph/op/asinh.hpp" #include "ngraph/op/assign.hpp" #include "ngraph/op/atan.hpp" -#include "ngraph/op/atan2.hpp" #include "ngraph/op/atanh.hpp" #include "ngraph/op/avg_pool.hpp" #include "ngraph/op/batch_norm.hpp" diff --git a/ngraph/src/ngraph/pass/cse.cpp b/ngraph/src/ngraph/pass/cse.cpp index 56550f8b9..d25f403ac 100644 --- a/ngraph/src/ngraph/pass/cse.cpp +++ b/ngraph/src/ngraph/pass/cse.cpp @@ -29,7 +29,6 @@ #include "ngraph/op/add.hpp" #include "ngraph/op/asin.hpp" #include "ngraph/op/atan.hpp" -#include "ngraph/op/atan2.hpp" #include "ngraph/op/broadcast.hpp" #include "ngraph/op/ceiling.hpp" #include "ngraph/op/constant.hpp" @@ -176,7 +175,6 @@ static unordered_map, shared_ptr JSONDeserializer::deserialize_node(json node_js) node = make_shared(args[0]); break; } - case OP_TYPEID::Atan2: - { - node = make_shared(args[0], args[1], read_auto_broadcast(node_js, "autob")); - break; - } case OP_TYPEID::BatchMatMul: { @@ -2553,15 +2548,6 @@ json JSONSerializer::serialize_node(const Node& n) } case OP_TYPEID::Atan: { break; } - case OP_TYPEID::Atan2: - { - auto tmp = dynamic_cast(&n); - if (tmp->get_autob().m_type != op::AutoBroadcastType::NONE) - { - node["autob"] = write_auto_broadcast(tmp->get_autob()); - } - break; - } case OP_TYPEID::BatchMatMul: { break; } case OP_TYPEID::BatchMatMulTranspose: diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index f4c377c23..f67f8bf3b 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -298,7 +298,6 @@ set(MULTI_TEST_SRC backend/asin.in.cpp backend/asinh.in.cpp backend/atan.in.cpp - backend/atan2.in.cpp backend/atanh.in.cpp backend/auto_broadcast.in.cpp backend/autodiff.in.cpp diff --git a/ngraph/test/backend/atan2.in.cpp b/ngraph/test/backend/atan2.in.cpp deleted file mode 100644 index d76914a5a..000000000 --- a/ngraph/test/backend/atan2.in.cpp +++ /dev/null @@ -1,85 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2020 Intel Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//***************************************************************************** - -#include -#include -#include -#include -#include -#include - -// clang-format off -#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS -#endif - -#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS -#endif -// clang-format on - -#include "gtest/gtest.h" -#include "ngraph/ngraph.hpp" -#include "runtime/backend.hpp" -#include "ngraph/runtime/tensor.hpp" -#include "util/all_close.hpp" -#include "util/all_close_f.hpp" -#include "util/ndarray.hpp" -#include "util/test_control.hpp" -#include "util/test_tools.hpp" - -using namespace std; -using namespace ngraph; - -static string s_manifest = "${MANIFEST}"; - -NGRAPH_TEST(${BACKEND_NAME}, atan2) -{ - Shape shape{30}; - auto X = make_shared(element::f32, shape); - auto Y = make_shared(element::f32, shape); - auto f = make_shared(make_shared(Y, X), ParameterVector{X, Y}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - shared_ptr x = backend->create_tensor(element::f32, shape); - shared_ptr y = backend->create_tensor(element::f32, shape); - shared_ptr result = backend->create_tensor(element::f32, shape); - - std::vector xref; - std::vector yref; - std::vector zref; - int halfelts = shape.at(0) / 2; - float scale = 1.0 / (halfelts * 4.0 * std::atan(1.0)); - for (int i = 0; i < halfelts; ++i) - { - float theta = i * scale; - zref.push_back(theta); - xref.push_back(static_cast((i + 1) * std::cos(theta))); - yref.push_back(static_cast((i + 1) * std::sin(theta))); - zref.push_back(-theta); - xref.push_back(static_cast((i + 1) * std::cos(-theta))); - yref.push_back(static_cast((i + 1) * std::sin(-theta))); - } - - copy_data(x, xref); - copy_data(y, yref); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {x, y}); - EXPECT_TRUE(test::all_close_f(read_vector(result), (zref))); -} diff --git a/ngraph/test/backend/autodiff.in.cpp b/ngraph/test/backend/autodiff.in.cpp index 02a100043..c4ef9707a 100644 --- a/ngraph/test/backend/autodiff.in.cpp +++ b/ngraph/test/backend/autodiff.in.cpp @@ -152,23 +152,6 @@ NGRAPH_TEST(${BACKEND_NAME}, backwards_atan) EXPECT_TRUE(autodiff_numeric_compare(backend.get(), make_graph, {x0}, .01f, .01f)); } -NGRAPH_TEST(${BACKEND_NAME}, backwards_atan2) -{ - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - Shape shape{30}; - - test::Uniform rng(-5.0f, 5.0f); - auto y = rng.initialize(backend->create_tensor(shape)); - auto x = rng.initialize(backend->create_tensor(shape)); - - auto make_graph = [shape]() { - auto X = make_shared(element::f32, shape); - auto Y = make_shared(element::f32, shape); - return make_shared(make_shared(Y, X), ParameterVector{Y, X}); - }; - EXPECT_TRUE(autodiff_numeric_compare(backend.get(), make_graph, {y, x}, .01f, .01f)); -} - NGRAPH_TEST(${BACKEND_NAME}, backwards_broadcast0) { auto backend = runtime::Backend::create("${BACKEND_NAME}"); diff --git a/ngraph/test/copy.cpp b/ngraph/test/copy.cpp index c627553d0..04fd7199a 100644 --- a/ngraph/test/copy.cpp +++ b/ngraph/test/copy.cpp @@ -79,11 +79,6 @@ TEST(copy, atan) ASSERT_TRUE(check_unary()); } -TEST(copy, atan2) -{ - ASSERT_TRUE(check_binary()); -} - TEST(copy, broadcast) { Shape shape1{1}; diff --git a/ngraph/test/op_is.cpp b/ngraph/test/op_is.cpp index 57ad6036f..4f699789a 100644 --- a/ngraph/test/op_is.cpp +++ b/ngraph/test/op_is.cpp @@ -18,6 +18,7 @@ #include "ngraph/ngraph.hpp" #include "ngraph/validation_util.hpp" +#include "op/atan2.hpp" #include "util/test_tools.hpp" using namespace ngraph; @@ -125,7 +126,7 @@ namespace void op_is_Atan2() { - op::Atan2 node; + op::v0::Atan2 node; EXPECT_FALSE(node.is_unary_elementwise_arithmetic()); EXPECT_TRUE(node.is_binary_elementwise_arithmetic()); EXPECT_FALSE(node.is_binary_elementwise_comparison()); diff --git a/ngraph/test/runtime/CMakeLists.txt b/ngraph/test/runtime/CMakeLists.txt index 71e45a117..8e48236e6 100644 --- a/ngraph/test/runtime/CMakeLists.txt +++ b/ngraph/test/runtime/CMakeLists.txt @@ -31,6 +31,8 @@ set (SRC performance_counter.hpp dynamic/dynamic_backend.cpp dynamic/dynamic_backend.hpp + op/atan2.cpp + op/atan2.hpp op/avg_pool.cpp op/avg_pool.hpp ) diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 68bbdb69a..b8206de28 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -1032,9 +1032,6 @@ batch_mat_mul_forward # Incorrect dimensions for broadcasting for Add auto_bcast_binary_elementwise_pdpd_dynamic -# Unsupported primitive of type: Atan2 -atan2 - # Unsupported primitive of type: ArgMin argmin_trivial argmin_2D_i32 @@ -1161,7 +1158,6 @@ backwards_add backwards_add_nested backwards_asin backwards_atan -backwards_atan2 backwards_broadcast0 backwards_broadcast1 backwards_concat_vector diff --git a/ngraph/test/runtime/interpreter/int_executable.cpp b/ngraph/test/runtime/interpreter/int_executable.cpp index 47ff9eef8..422f3fbd0 100644 --- a/ngraph/test/runtime/interpreter/int_executable.cpp +++ b/ngraph/test/runtime/interpreter/int_executable.cpp @@ -29,6 +29,7 @@ #include "ngraph/pass/manager.hpp" #include "ngraph/serializer.hpp" #include "ngraph/util.hpp" +#include "op/atan2.hpp" #include "opset0_downgrade.hpp" #include "opset1_downgrade.hpp" diff --git a/ngraph/test/runtime/op/atan2.cpp b/ngraph/test/runtime/op/atan2.cpp new file mode 100644 index 000000000..2f54c4a8c --- /dev/null +++ b/ngraph/test/runtime/op/atan2.cpp @@ -0,0 +1,59 @@ +//***************************************************************************** +// Copyright 2017-2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#include "atan2.hpp" +#include "ngraph/op/add.hpp" +#include "ngraph/op/divide.hpp" +#include "ngraph/op/multiply.hpp" +#include "ngraph/op/negative.hpp" +#include "ngraph/op/sqrt.hpp" +#include "ngraph/op/subtract.hpp" + +using namespace std; +using namespace ngraph; + +constexpr NodeTypeInfo op::v0::Atan2::type_info; + +op::v0::Atan2::Atan2(const Output& y, const Output& x, const AutoBroadcastSpec& autob) + : BinaryElementwiseArithmetic(y, x, autob) +{ + constructor_validate_and_infer_types(); +} + +shared_ptr op::v0::Atan2::clone_with_new_inputs(const OutputVector& new_args) const +{ + check_new_args_count(this, new_args); + return make_shared(new_args.at(0), new_args.at(1), this->get_autob()); +} + +void op::v0::Atan2::generate_adjoints(autodiff::Adjoints& adjoints, const OutputVector& deltas) +{ + if (get_autob().m_type != op::AutoBroadcastType::NONE) + { + throw ngraph_error("Autodiff not supported with auto broadcasting"); + } + auto y = input_value(0); + auto x = input_value(1); + auto delta_over_r = deltas.at(0) / (x * x + y * y); + adjoints.add_delta(y, x * delta_over_r); + adjoints.add_delta(x, -y * delta_over_r); +} + +bool op::v0::Atan2::visit_attributes(AttributeVisitor& visitor) +{ + BinaryElementwiseArithmetic::visit_attributes(visitor); + return true; +} diff --git a/ngraph/test/runtime/op/atan2.hpp b/ngraph/test/runtime/op/atan2.hpp new file mode 100644 index 000000000..bf500b63e --- /dev/null +++ b/ngraph/test/runtime/op/atan2.hpp @@ -0,0 +1,59 @@ +//***************************************************************************** +// Copyright 2017-2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#pragma once + +#include + +#include "backend_visibility.hpp" +#include "ngraph/op/util/binary_elementwise_arithmetic.hpp" + +namespace ngraph +{ + namespace op + { + namespace v0 + { + /// \brief Elementwise full arctan operation + class BACKEND_API Atan2 : public util::BinaryElementwiseArithmetic + { + public: + static constexpr NodeTypeInfo type_info{"Atan2", 0}; + const NodeTypeInfo& get_type_info() const override { return type_info; } + Atan2() + : util::BinaryElementwiseArithmetic(AutoBroadcastSpec::NONE) + { + } + + /// \brief atan2(y,x) is the angle from the origin to the point (x,y) (note reversed + /// order). + /// + /// \param y + /// \param x + Atan2(const Output& y, + const Output& x, + const AutoBroadcastSpec& autob = AutoBroadcastSpec()); + std::shared_ptr + clone_with_new_inputs(const OutputVector& new_args) const override; + bool visit_attributes(AttributeVisitor& visitor) override; + + protected: + virtual void generate_adjoints(autodiff::Adjoints& adjoints, + const OutputVector& deltas) override; + }; + } + } +} diff --git a/ngraph/test/runtime/opset0.hpp b/ngraph/test/runtime/opset0.hpp index e46665bbc..60f2dae1b 100644 --- a/ngraph/test/runtime/opset0.hpp +++ b/ngraph/test/runtime/opset0.hpp @@ -17,6 +17,7 @@ #pragma once #include "ngraph/ops.hpp" +#include "op/atan2.hpp" #include "op/avg_pool.hpp" namespace ngraph diff --git a/ngraph/test/runtime/opset0_tbl.hpp b/ngraph/test/runtime/opset0_tbl.hpp index bf7c71a0d..efbead3cb 100644 --- a/ngraph/test/runtime/opset0_tbl.hpp +++ b/ngraph/test/runtime/opset0_tbl.hpp @@ -61,7 +61,7 @@ NGRAPH_OP(ArgMax, ngraph::op) NGRAPH_OP(ArgMin, ngraph::op) NGRAPH_OP(Asin, ngraph::op) NGRAPH_OP(Atan, ngraph::op) -NGRAPH_OP(Atan2, ngraph::op) +NGRAPH_OP(Atan2, ngraph::op::v0) NGRAPH_OP(AvgPool, ngraph::op::v0) NGRAPH_OP(BatchMatMul, ngraph::op) NGRAPH_OP(BatchMatMulTranspose, ngraph::op) diff --git a/ngraph/test/runtime/opset1_upgrade.cpp b/ngraph/test/runtime/opset1_upgrade.cpp index 2bd0dcdbf..42c9e4e7b 100644 --- a/ngraph/test/runtime/opset1_upgrade.cpp +++ b/ngraph/test/runtime/opset1_upgrade.cpp @@ -25,6 +25,7 @@ #include "ngraph/graph_util.hpp" #include "ngraph/ops.hpp" #include "ngraph/provenance.hpp" +#include "op/atan2.hpp" #include "op/avg_pool.hpp" using namespace std;