Commit bf74de2f authored by Robert Kimball's avatar Robert Kimball Committed by Michał Karzyński

remove the contains() funtion from util as it can lead to bad usage (#1771)

parent 51ad59d3
......@@ -298,7 +298,8 @@ void codegen::CompilerCore::add_header_search_path(const string& p)
vector<string> paths = split(p, ';');
for (const string& path : paths)
{
if (!contains(m_extra_search_path_list, path))
if (find(m_extra_search_path_list.begin(), m_extra_search_path_list.end(), path) ==
m_extra_search_path_list.end())
{
m_extra_search_path_list.push_back(path);
HeaderSearchOptions& hso = m_compiler->getInvocation().getHeaderSearchOpts();
......
......@@ -160,7 +160,7 @@ void pass::MemoryVisualize::draw_tensor_weight(ostream& file, const list<shared_
for (const descriptor::Tensor* tensor : tensor_set)
{
int generator_weight = compute_op_weight(generator_op[tensor]);
if (contains(largest_live_list, tensor))
if (largest_live_list.find(tensor) != largest_live_list.end())
{
file << " <tr style=\"background-color: #f0c0f0\">";
}
......
......@@ -73,7 +73,7 @@ pass::VisualizeTree::VisualizeTree(const string& file_name)
std::string pass::VisualizeTree::add_attributes(shared_ptr<Node> node)
{
string rc;
if (!contains(m_nodes_with_attributes, node))
if (m_nodes_with_attributes.find(node) == m_nodes_with_attributes.end())
{
m_nodes_with_attributes.insert(node);
rc = get_attributes(node);
......
......@@ -1680,7 +1680,7 @@ string runtime::cpu::CPU_ExternalFunction::emit_op_as_function(const Node& node,
const descriptor::Output& output = input.get_output();
shared_ptr<descriptor::Tensor> tv = output.get_tensor_ptr();
TensorViewWrapper tvw{tv, "_arg" + to_string(arg_index)};
if (!contains(arg_names, tvw.get_name()))
if (arg_names.find(tvw.get_name()) == arg_names.end())
{
arg_names.insert(tvw.get_name());
if (arg_index++ > 0)
......
......@@ -659,7 +659,7 @@ string runtime::gpu::GPU_ExternalFunction::emit_op_as_function(const Node& node,
const descriptor::Output& output = input.get_output();
shared_ptr<descriptor::Tensor> tv = output.get_tensor_ptr();
GPUTensorWrapper tvw{tv, "_arg" + to_string(arg_index)};
if (!contains(arg_names, tvw.get_name()))
if (arg_names.find(tvw.get_name()) == arg_names.end())
{
arg_names.insert(tvw.get_name());
if (arg_index++ > 0)
......
......@@ -69,21 +69,6 @@ namespace ngraph
return os.str();
}
template <typename U, typename T>
bool contains(const U& container, const T& obj)
{
bool rc = false;
for (auto o : container)
{
if (o == obj)
{
rc = true;
break;
}
}
return rc;
}
size_t hash_combine(const std::vector<size_t>& list);
void dump(std::ostream& out, const void*, size_t);
......
......@@ -27,7 +27,7 @@ TEST(backend_api, registered_devices)
vector<string> devices = runtime::Backend::get_registered_devices();
EXPECT_GE(devices.size(), 0);
EXPECT_TRUE(contains(devices, "INTERPRETER"));
EXPECT_TRUE(find(devices.begin(), devices.end(), "INTERPRETER") != devices.end());
}
TEST(backend_api, invalid_name)
......
......@@ -134,16 +134,6 @@ TEST(util, trim)
EXPECT_STREQ("test", trim(" \t test \t ").c_str());
}
TEST(util, contains)
{
vector<int> v1 = {1, 2, 3, 4, 5, 6};
EXPECT_TRUE(contains(v1, 1));
EXPECT_TRUE(contains(v1, 4));
EXPECT_TRUE(contains(v1, 6));
EXPECT_FALSE(contains(v1, 8));
}
#if defined(NGRAPH_INTERPRETER_ENABLE)
TEST(util, all_close)
{
......
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