Skip to content
Snippets Groups Projects
Commit 7409bc8b authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Util] catch duplicate annotations in get_by_name

parent d31c45ee
No related branches found
No related tags found
No related merge requests found
...@@ -156,13 +156,19 @@ def make_build_dir(prefix=""): ...@@ -156,13 +156,19 @@ def make_build_dir(prefix=""):
def get_by_name(container, name, name_field="name"): def get_by_name(container, name, name_field="name"):
"""Return item from container by .name field if it exists, None otherwise""" """Return item from container by .name field if it exists, None otherwise.
Will throw an Exception if multiple items are found, since this violates the
ONNX standard."""
names = [getattr(x, name_field) for x in container] names = [getattr(x, name_field) for x in container]
try:
ind = names.index(name) inds = [i for i, e in enumerate(names) if e == name]
return container[ind] if len(inds) > 1:
except ValueError: raise Exception("Found multiple get_by_name matches, undefined behavior")
elif len(inds) == 0:
return None return None
else:
ind = inds[0]
return container[ind]
def remove_by_name(container, name, name_field="name"): def remove_by_name(container, name, name_field="name"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment