Unverified Commit 7f9b6b84 authored by Adam Procter's avatar Adam Procter Committed by GitHub

Allow boolean comparisons; update element::Type::operator== to also compare m_cname (#214)

This adds support for > < >= <= on bool, which by the type checker's standards should have been allowed anyway.

Also, this bug had presenting in a different way from expected (should have thrown "unhandled element type" from external_function, instead bonked because it incorrectly dispatched on int8_t). This was due to element::Type::operator== comparing only size, signedness, and floatiness, meaning that char and signed char (aka int8_t) look the same. Fixed by adding a test for m_cname equality.
parent 2a3f3e16
...@@ -367,10 +367,6 @@ ExternalFunction::OpMap& ExternalFunction::get_op_map() ...@@ -367,10 +367,6 @@ ExternalFunction::OpMap& ExternalFunction::get_op_map()
REGISTER_NUMERIC_BINOP(op::Add, eigen::AddInstruction); REGISTER_NUMERIC_BINOP(op::Add, eigen::AddInstruction);
REGISTER_NUMERIC_BINOP(op::Divide, eigen::DivideInstruction); REGISTER_NUMERIC_BINOP(op::Divide, eigen::DivideInstruction);
REGISTER_NUMERIC_BINOP(op::Greater, eigen::GreaterThanInstruction);
REGISTER_NUMERIC_BINOP(op::GreaterEq, eigen::GreaterEqInstruction);
REGISTER_NUMERIC_BINOP(op::Less, eigen::LessThanInstruction);
REGISTER_NUMERIC_BINOP(op::LessEq, eigen::LessEqInstruction);
REGISTER_NUMERIC_BINOP(op::Maximum, eigen::MaximumInstruction); REGISTER_NUMERIC_BINOP(op::Maximum, eigen::MaximumInstruction);
REGISTER_NUMERIC_BINOP(op::Minimum, eigen::MinimumInstruction); REGISTER_NUMERIC_BINOP(op::Minimum, eigen::MinimumInstruction);
REGISTER_NUMERIC_BINOP(op::Multiply, eigen::MultiplyInstruction); REGISTER_NUMERIC_BINOP(op::Multiply, eigen::MultiplyInstruction);
...@@ -395,6 +391,10 @@ ExternalFunction::OpMap& ExternalFunction::get_op_map() ...@@ -395,6 +391,10 @@ ExternalFunction::OpMap& ExternalFunction::get_op_map()
REGISTER_POLYMORPHIC_BINOP(op::Equal, eigen::EqualInstruction); REGISTER_POLYMORPHIC_BINOP(op::Equal, eigen::EqualInstruction);
REGISTER_POLYMORPHIC_BINOP(op::NotEqual, eigen::NotEqualInstruction); REGISTER_POLYMORPHIC_BINOP(op::NotEqual, eigen::NotEqualInstruction);
REGISTER_POLYMORPHIC_BINOP(op::Greater, eigen::GreaterThanInstruction);
REGISTER_POLYMORPHIC_BINOP(op::GreaterEq, eigen::GreaterEqInstruction);
REGISTER_POLYMORPHIC_BINOP(op::Less, eigen::LessThanInstruction);
REGISTER_POLYMORPHIC_BINOP(op::LessEq, eigen::LessEqInstruction);
REGISTER_POLYMORPHIC_TERNOP(op::Select, eigen::SelectInstruction); REGISTER_POLYMORPHIC_TERNOP(op::Select, eigen::SelectInstruction);
......
...@@ -41,7 +41,7 @@ const std::string& ngraph::element::Type::c_type_string() const ...@@ -41,7 +41,7 @@ const std::string& ngraph::element::Type::c_type_string() const
bool ngraph::element::Type::operator==(const element::Type& other) const bool ngraph::element::Type::operator==(const element::Type& other) const
{ {
return m_bitwidth == other.m_bitwidth && m_is_float == other.m_is_float && return m_bitwidth == other.m_bitwidth && m_is_float == other.m_is_float &&
m_is_signed == other.m_is_signed; m_is_signed == other.m_is_signed && m_cname == other.m_cname;
} }
size_t ngraph::element::Type::size() const size_t ngraph::element::Type::size() const
......
...@@ -848,6 +848,30 @@ TEST(execute, lesseq) ...@@ -848,6 +848,30 @@ TEST(execute, lesseq)
ASSERT_EQ((vector<char>{1, 0, 1, 0, 1, 1, 0, 1}), result->get_vector()); ASSERT_EQ((vector<char>{1, 0, 1, 0, 1, 1, 0, 1}), result->get_vector());
} }
TEST(execute, lesseq_bool)
{
auto shape = Shape{2, 2, 2};
auto A = make_shared<op::Parameter>(element::Bool::element_type(), shape);
auto B = make_shared<op::Parameter>(element::Bool::element_type(), shape);
auto rt = make_shared<TensorViewType>(element::Bool::element_type(), shape);
auto f = make_shared<Function>(make_shared<op::LessEq>(A, B), rt, op::Parameters{A, B});
auto manager = runtime::Manager::get("NGVM");
auto external = manager->compile(f);
auto backend = manager->allocate_backend();
auto cf = backend->make_call_frame(external);
// Create some tensors for input/output
auto a = backend->make_parameterized_tensor_view<element::Bool>(shape);
*a = vector<char>{1, 1, 1, 1, 1, 1, 1, 1};
auto b = backend->make_parameterized_tensor_view<element::Bool>(shape);
*b = vector<char>{0, 0, 0, 0, 0, 0, 0, 0};
auto result = backend->make_parameterized_tensor_view<element::Bool>(shape);
(*cf)({a, b}, {result});
ASSERT_EQ((vector<char>{0, 0, 0, 0, 0, 0, 0, 0}), result->get_vector());
}
TEST(execute, log) TEST(execute, log)
{ {
auto shape = Shape{2, 2, 2}; auto shape = Shape{2, 2, 2};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment