Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
1.7 kB
2
Indexable
Never
#include "common_op_table.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/unsqueeze.hpp"

using namespace std;
using namespace ov::op;

namespace ov {
namespace frontend {
namespace tensorflow {
namespace op {

OutputVector translate_bias_add_op(const NodeContext& node) {
    default_op_checks(node, 2, {"BiasAdd"});
    auto value = node.get_input(0);
    auto bias = node.get_input(1);

    // Handle complex tensors
    if (value.get_element_type() == element::c64) {
        // Ensure that both value and bias tensors are complex
        TENSORFLOW_OP_VALIDATION(node,
                                 bias.get_element_type() == element::c64,
                                 "Bias tensor must be complex when the input tensor is complex.");

        // Add real and imaginary parts separately
        auto value_real = make_shared<op::Real>(value);
        auto value_imag = make_shared<op::Imag>(value);
        auto bias_real = make_shared<op::Real>(bias);
        auto bias_imag = make_shared<op::Imag>(bias);

        auto res_real = make_shared<v1::Add>(value_real, bias_real);
        auto res_imag = make_shared<v1::Add>(value_imag, bias_imag);

        // Combine real and imaginary parts to form the complex result
        auto res_complex = make_shared<op::Complex>(res_real, res_imag);

        set_node_name(node.get_name(), res_complex);
        return res_complex->outputs();
    }

    // For non-complex tensors, proceed with the existing logic
    auto res = make_shared<v1::Add>(value, bias);
    set_node_name(node.get_name(), res);
    return res->outputs();
}
}  // namespace op
}  // namespace tensorflow
}  // namespace frontend
}  // namespace ov
Leave a Comment