|
| 1 | +//***************************************************************************** |
| 2 | +// Copyright 2017-2020 Intel Corporation |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +//***************************************************************************** |
| 16 | + |
| 17 | +#include "ngraph/op/util/binary_elementwise.hpp" |
| 18 | + |
| 19 | +using namespace ngraph; |
| 20 | +using namespace std; |
| 21 | + |
| 22 | +op::util::BinaryElementwise::BinaryElementwise() {} |
| 23 | + |
| 24 | +op::util::BinaryElementwise::BinaryElementwise(const Output<Node>& arg0, |
| 25 | + const Output<Node>& arg1, |
| 26 | + const AutoBroadcastSpec& autob) |
| 27 | + : Op({arg0, arg1}) |
| 28 | + , m_autob(autob) |
| 29 | +{ |
| 30 | +} |
| 31 | + |
| 32 | +bool op::util::BinaryElementwise::visit_attributes(AttributeVisitor& visitor) |
| 33 | +{ |
| 34 | + visitor.on_attribute("auto_broadcast", m_autob); |
| 35 | + return true; |
| 36 | +} |
| 37 | + |
| 38 | +Shape op::util::BinaryElementwise::compute_output_shape(const Shape& arg0_shape, |
| 39 | + const Shape& arg1_shape) const |
| 40 | +{ |
| 41 | + PartialShape arg0_partial_shape = arg0_shape; |
| 42 | + if (m_autob.m_type == op::AutoBroadcastType::NONE) |
| 43 | + { |
| 44 | + NGRAPH_CHECK(PartialShape::merge_into(arg0_partial_shape, arg1_shape), |
| 45 | + "Argument shapes are inconsistent."); |
| 46 | + } |
| 47 | + else if (m_autob.m_type == op::AutoBroadcastType::NUMPY || |
| 48 | + m_autob.m_type == op::AutoBroadcastType::PDPD) |
| 49 | + { |
| 50 | + NGRAPH_CHECK(PartialShape::broadcast_merge_into(arg0_partial_shape, arg1_shape, m_autob), |
| 51 | + "Argument shapes are inconsistent."); |
| 52 | + } |
| 53 | + else |
| 54 | + { |
| 55 | + NGRAPH_CHECK(false, "Unsupported auto broadcast specification"); |
| 56 | + } |
| 57 | + return arg0_partial_shape.get_shape(); |
| 58 | +} |
0 commit comments