Skip to content

Commit

Permalink
strings attribute support added to CustomOp
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaniowi committed Jul 30, 2024
1 parent db969e6 commit 5414416
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/qonnx/custom_op/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def get_nodeattr(self, name):
if dtype == "s":
# decode string attributes
ret = ret.decode("utf-8")
elif dtype == "strings":
ret = [x.decode("utf-8") for x in ret]
elif dtype == "t":
# use numpy helper to convert TensorProto -> np array
ret = np_helper.to_array(ret)
Expand Down Expand Up @@ -123,13 +125,15 @@ def set_nodeattr(self, name, value):
# encode string attributes
value = value.encode("utf-8")
attr.__setattr__(dtype, value)
elif dtype == "strings":
attr.strings[:] = [x.encode("utf-8") for x in value]
elif dtype == "floats": # list of floats
attr.floats[:] = value
elif dtype == "ints": # list of integers
attr.ints[:] = value
elif dtype == "t": # single tensor
attr.t.CopyFrom(value)
elif dtype in ["strings", "tensors", "graphs", "sparse_tensors"]:
elif dtype in ["tensors", "graphs", "sparse_tensors"]:
# untested / unsupported attribute types
# add testcases & appropriate getters before enabling
raise Exception("Attribute type %s not yet supported" % dtype)
Expand Down

0 comments on commit 5414416

Please sign in to comment.