Commit b28ed620 authored by Adam Procter's avatar Adam Procter Committed by Scott Cyphers

Fix corner case where op::Constant ctor is called with a zero-element shape and…

Fix corner case where op::Constant ctor is called with a zero-element shape and a vector of one string (#3082)
parent af7c81a3
...@@ -102,10 +102,7 @@ namespace ngraph ...@@ -102,10 +102,7 @@ namespace ngraph
std::vector<int64_t> dvalues = parse_string<int64_t>(values); std::vector<int64_t> dvalues = parse_string<int64_t>(values);
if (values.size() == 1 && shape_size(m_shape) != 1) if (values.size() == 1 && shape_size(m_shape) != 1)
{ {
for (size_t i = 1; i < shape_size(m_shape); i++) dvalues = std::vector<int64_t>(shape_size(m_shape), dvalues[0]);
{
dvalues.push_back(dvalues[0]);
}
} }
write_values(dvalues); write_values(dvalues);
} }
...@@ -114,10 +111,7 @@ namespace ngraph ...@@ -114,10 +111,7 @@ namespace ngraph
std::vector<uint64_t> dvalues = parse_string<uint64_t>(values); std::vector<uint64_t> dvalues = parse_string<uint64_t>(values);
if (values.size() == 1 && shape_size(m_shape) != 1) if (values.size() == 1 && shape_size(m_shape) != 1)
{ {
for (size_t i = 1; i < shape_size(m_shape); i++) dvalues = std::vector<uint64_t>(shape_size(m_shape), dvalues[0]);
{
dvalues.push_back(dvalues[0]);
}
} }
write_values(dvalues); write_values(dvalues);
} }
...@@ -127,10 +121,7 @@ namespace ngraph ...@@ -127,10 +121,7 @@ namespace ngraph
std::vector<double> dvalues = parse_string<double>(values); std::vector<double> dvalues = parse_string<double>(values);
if (values.size() == 1 && shape_size(m_shape) != 1) if (values.size() == 1 && shape_size(m_shape) != 1)
{ {
for (size_t i = 1; i < shape_size(m_shape); i++) dvalues = std::vector<double>(shape_size(m_shape), dvalues[0]);
{
dvalues.push_back(dvalues[0]);
}
} }
write_values(dvalues); write_values(dvalues);
} }
......
...@@ -3635,6 +3635,14 @@ TEST(type_prop, tensor_constant_bad_count) ...@@ -3635,6 +3635,14 @@ TEST(type_prop, tensor_constant_bad_count)
} }
} }
TEST(type_prop, constant_zero_elements_one_string)
{
auto c =
make_shared<op::Constant>(element::i64, Shape{2, 0, 2, 2}, std::vector<std::string>{"42"});
ASSERT_EQ(c->get_element_type(), element::i64);
ASSERT_EQ(c->get_shape(), (Shape{2, 0, 2, 2}));
}
TEST(type_prop, replace_slice_deduce_vector) TEST(type_prop, replace_slice_deduce_vector)
{ {
auto param0 = make_shared<op::Parameter>(element::f32, Shape{6}); auto param0 = make_shared<op::Parameter>(element::f32, Shape{6});
......
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