From 75930ffbcf14cfbaccd8417c47c3598f56342926 Mon Sep 17 00:00:00 2001 From: "G. Ramalingam" Date: Wed, 30 Sep 2020 02:36:06 -0700 Subject: [PATCH] Fix substitution order in parse_type_str (#316) * Fix substitution order in parse_type_str Signed-off-by: Ganesan Ramalingam * add comment * Remove files added accidentally Co-authored-by: chentong319 Co-authored-by: Tian Jin --- utils/gen_onnx_mlir.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/gen_onnx_mlir.py b/utils/gen_onnx_mlir.py index ea1b452..2c5e36f 100644 --- a/utils/gen_onnx_mlir.py +++ b/utils/gen_onnx_mlir.py @@ -818,7 +818,11 @@ def parse_type_str(allowedType): 'complex128' : 'Complex', 'string' : 'StringType'} - for key, item in onnx_to_mlir_type_dict.items(): + # Apply substitutions in decreasing order of key-length, so that float16 is replaced + # before float, and uint16 is replaced before int16, etc. + mapping = list(onnx_to_mlir_type_dict.items()) + mapping.sort(key=lambda pair:len(pair[0]), reverse=True) + for key, item in mapping: allowedType = allowedType.replace(key, item) return allowedType