This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Atan2 op
- Loading branch information
Showing
18 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//***************************************************************************** | ||
// Copyright 2017-2019 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" | ||
|
||
using namespace std; | ||
using namespace ngraph; | ||
|
||
const string op::Atan2::type_name{"Atan2"}; | ||
|
||
op::Atan2::Atan2(const Output<Node>& y, const Output<Node>& x, const AutoBroadcastSpec& autob) | ||
: BinaryElementwiseArithmetic(y, x, autob) | ||
{ | ||
constructor_validate_and_infer_types(); | ||
} | ||
|
||
shared_ptr<Node> op::Atan2::copy_with_new_args(const NodeVector& new_args) const | ||
{ | ||
check_new_args_count(this, new_args); | ||
return make_shared<Atan2>(new_args.at(0), new_args.at(1), this->get_autob()); | ||
} | ||
|
||
void op::Atan2::generate_adjoints(autodiff::Adjoints& adjoints, const NodeVector& deltas) | ||
{ | ||
if (get_autob().m_type != op::AutoBroadcastType::NONE) | ||
{ | ||
throw ngraph_error("Autodiff not supported with auto broadcasting"); | ||
} | ||
throw ngraph_error("Autodiff not supported for Atan2"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//***************************************************************************** | ||
// Copyright 2017-2019 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 <memory> | ||
|
||
#include "ngraph/op/util/binary_elementwise_arithmetic.hpp" | ||
|
||
namespace ngraph | ||
{ | ||
namespace op | ||
{ | ||
/// \brief Elementwise full arctan operation | ||
class Atan2 : public util::BinaryElementwiseArithmetic | ||
{ | ||
public: | ||
NGRAPH_API | ||
static const std::string type_name; | ||
const std::string& description() const override { return type_name; } | ||
Atan2() = default; | ||
|
||
/// \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<Node>& y, | ||
const Output<Node>& x, | ||
const AutoBroadcastSpec& autob = AutoBroadcastSpec()); | ||
std::shared_ptr<Node> copy_with_new_args(const NodeVector& new_args) const override; | ||
|
||
protected: | ||
virtual void generate_adjoints(autodiff::Adjoints& adjoints, | ||
const NodeVector& deltas) override; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//***************************************************************************** | ||
// Copyright 2017-2019 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 <cmath> | ||
|
||
#define EIGEN_USE_THREADS | ||
#include <unsupported/Eigen/CXX11/Tensor> | ||
|
||
#include "ngraph/runtime/cpu/cpu_executor.hpp" | ||
|
||
namespace ngraph | ||
{ | ||
namespace runtime | ||
{ | ||
namespace cpu | ||
{ | ||
namespace kernel | ||
{ | ||
template <typename ElementType> | ||
void atan2(void* input0, void* input1, void* output, size_t count, int arena) | ||
{ | ||
Eigen::array<Eigen::Index, 1> out_dims, in_dims; | ||
|
||
out_dims[0] = in_dims[0] = count; | ||
|
||
Eigen::TensorMap<Eigen::Tensor<ElementType, 1, Eigen::RowMajor>> out( | ||
static_cast<ElementType*>(output), out_dims); | ||
Eigen::TensorMap<Eigen::Tensor<ElementType, 1, Eigen::RowMajor>> in0( | ||
static_cast<ElementType*>(input0), in_dims); | ||
Eigen::TensorMap<Eigen::Tensor<ElementType, 1, Eigen::RowMajor>> in1( | ||
static_cast<ElementType*>(input1), in_dims); | ||
|
||
out.device(ngraph::runtime::cpu::executor::GetCPUExecutor().get_device(arena)) = | ||
in0.binaryExpr(in1, [](ElementType y, ElementType x) { | ||
return static_cast<ElementType>(std::atan2(y, x)); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//***************************************************************************** | ||
// Copyright 2017-2019 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 <cmath> | ||
#include <cstddef> | ||
|
||
namespace ngraph | ||
{ | ||
namespace runtime | ||
{ | ||
namespace reference | ||
{ | ||
template <typename X, typename Y, typename Z> | ||
void atan2(const X* py, const Y* px, Z* pout, size_t count) | ||
{ | ||
for (size_t i = 0; i < count; i++) | ||
{ | ||
*pout++ = static_cast<Z>(std::atan2(*py++, *px++)); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.